【发布时间】:2015-12-18 05:22:57
【问题描述】:
我想更新spree_products_taxons 表,但它显示了上面的错误。我做错了什么?
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
【问题讨论】:
-
发布错误日志和相关代码
标签: ruby-on-rails ruby rubygems spree