简体   繁体   English

在 spree 中更新 spree_products_taxons 表时显示错误“未初始化的常量 Spree::ProductTaxon”

[英]showing error "uninitialized constant Spree::ProductTaxon" while updating spree_products_taxons table in spree

I want to update spree_products_taxons table, but it is showing the error above.我想更新spree_products_taxons表,但它显示了上面的错误。 What am I am doing wrong?我做错了什么?

def import_update

require 'csv'
file = params[:file]
CSV.foreach(file.path, headers: true) do |row|

@prod = Spree::Product.find(row["id"])
@var = Spree::Variant.find_by(product_id: @prod.id)

Spree::Product.where(:id => row["id"]).update_all(:name => row["name"], :meta_description => row["meta_description"], :shipping_category_id => row["shipping_category_id"], :description => row["description"], :meta_keywords => row["meta_keywords"], :tax_category_id => row["tax_category_id"], :available_on => row["available_on"], :deleted_at => row["deleted_at"], :promotionable => row["promotionable"], :meta_title => row["meta_title"], :featured => row["featured"], :supplier_id => row["supplier_id"])

Spree::Variant.find_by(id: @var.id).update(:cost_price => row["cost_price"], :depth => row["depth"], :height => row["height"], :width => row["width"], :weight => row["weight"], :tax_category_id => row["tax_category_id"], :is_master => row["is_master"], :position => row["position"], :cost_currency => row["cost_currency"], :deleted_at => row["deleted_at"], :track_inventory => row["track_inventory"], :tax_category_id => row["tax_category_id"])

Spree::Price.find_by(variant_id: @var.id).update(:amount => row["master_price"], :currency => row["cost_currency"], :deleted_at => row["deleted_at"])

Spree::ProductTaxon.find_by(product_id: @prod.id).update(:taxon_id => row["taxon_id"])

@prop = Spree::ProductProperty.find_by(product_id: @prod.id)
Spree::Property.find_by(id: @prop.property_id).update(:name => row["name"], :presentation => row["presentation"])
Spree::ProductProperty.find_by(product_id: @prod.id).update(value => row["value"])

stock_loc = Spree::StockLocation.find_by(supplier_id: @prod.supplier_id)
Spree::StockItem.where(:variant_id => @variants.id, :stock_location_id => stock_loc.id).update_all(:count_on_hand => row["count_on_hand"], :backorderable => row["backorderable"])

end

redirect_to admin_products_path, notice: "Products Updated."

end

尽管由于某种原因该表被称为 spree_products_taxons(参见 schema.rb),但模型是 Spree::Classification。

You table is spree_products_taxons so it's expecting Spree::ProductsTaxon (mind that its Products NOT Product ) model class.你的表是spree_products_taxons所以它期待Spree::ProductsTaxon (注意它的Products NOT Product )模型类。 Make sure your model should be named as Spree::ProductsTaxon确保您的模型应命名为 Spree::ProductsTaxon

I can see you are using Spree::ProductTaxon in your code.我可以看到您在代码中使用了Spree::ProductTaxon Please update and try.请更新并尝试。

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM