| Class | MenuService |
| In: |
lib/design_api.rb
|
| Parent: | DesignSubService |
book として与えられるデータで products テーブルの内容を置き換える。
# File lib/design_api.rb, line 840
840: def export(book)
841: root = Product.root
842: raise MissingProductRoot unless root
843: items = book.main_sheet.menu_items
844: items.inject([false, false, false]) do |(x, y, z),item|
845: if item.product_id && item.product_id > 0
846: product = Product.find(item.product_id)
847: else
848: product = ProductPseudo.create!(:domain_id => book.client_identifier_y,
849: :code => item.product_code,
850: :name_po => 0)
851: Language.all.each do |lang|
852: product.__send__("name_#{lang.code}=", item.product_name)
853: end
854: product.save!
855: end
856: if item.menu_hierarchy_level_1 == 1
857: if x
858: product.move_to_right_of(x)
859: else
860: product.move_to_child_of(root)
861: end
862: [product, false, false]
863: elsif item.menu_hierarchy_level_2 == 1
864: if y
865: product.move_to_right_of(y)
866: else
867: product.move_to_child_of(x)
868: end
869: [x, product, false]
870: elsif item.menu_hierarchy_level_3 == 1
871: if z
872: product.move_to_rigth_of(z)
873: else
874: product.move_to_child_of(y)
875: end
876: [x, y, product]
877: else
878: raise InvalidHierarchyLevel
879: end
880: end
881: # NOTE: keep a product responding to no menu items.
882: return Product.to_menu_book(book.client_identifier_y).succeed
883: end
products テーブルの内容を Book にして返す。
# File lib/design_api.rb, line 829
829: def import(book)
830: domain_id = book.client_identifier_y
831: unless Product.root
832: ProductRoot.create!(:domain_id => domain_id,
833: :code => "product_root_#{domain_id}",
834: :name_po => 0)
835: end
836: return Product.to_menu_book(domain_id).succeed
837: end