Class | ProductService |
In: |
lib/design_api.rb
|
Parent: | DesignSubService |
book として与えられたデータで products テーブルの内容を置き換える。
# File lib/design_api.rb, line 936 936: def export(book) 937: domain_id = book.client_identifier_y 938: hash = Language.to_h 939: ids = [] 940: book.main_sheet.product_items.each do |product_item| 941: product_id = product_item.product_id 942: proc = lambda do |product| 943: product.domain_id = domain_id 944: product.code = product_item.product_code 945: product.model_name = product_item.product_model 946: ProductStruct::ProductItem::REGULAR_MEMBER.each do |k,| 947: product.__send__("#{k}=", product_item.__send__(k)) 948: end 949: product.save! if product.new_record? 950: product_item.product_names.each do |pn| 951: language_id = pn.language_id 952: product.__send__("name_#{hash[language_id]}=", pn.product_name) 953: end 954: product.save! 955: ids << product.id 956: end 957: if product_id && product_id != 0 958: # update the existing one 959: product = Product.find(product_id) 960: proc.call(product) 961: else 962: # add a new one 963: # TODO: other subclasses of Product should be available. 964: product = ProductSingle.new(:name_po => 0) 965: proc.call(product) 966: end 967: end 968: eids = Product.find(:all, :order => "id").map(&:id) 969: Product.delete(eids - ids) 970: return Product.to_product_book(domain_id).succeed 971: end
products テーブルの内容を返す。
# File lib/design_api.rb, line 925 925: def import(book) 926: domain_id = book.client_identifier_y 927: unless Product.root 928: ProductRoot.create!(:domain_id => domain_id, 929: :code => "product_root_#{domain_id}", 930: :name_po => 0) 931: end 932: return Product.to_product_book(domain_id).succeed 933: end