I want to update spree_products_taxons
table, but it is showing the error above. 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. Make sure your model should be named as Spree::ProductsTaxon
I can see you are using Spree::ProductTaxon
in your code. Please update and try.
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.