16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/we_chat/product.rb', line 16
def to_we_chat_data
we_chat_data = {}
we_chat_data[:product_id] = self.we_chat_id
we_chat_data[:product_base] = {}
we_chat_data[:product_base][:name] = self.name
we_chat_data[:product_base][:buy_limit] = self.buy_limit
we_chat_data[:product_base][:main_img] = self.main_image_url
we_chat_data[:product_base][:detail_html] = self.description
we_chat_data[:product_base][:category_id] = []
self.categories.each { |category| we_chat_data[:product_base][:category_id] << category.we_chat_id }
we_chat_data[:product_base][:property] = []
self.category_property_items.each { |property_item| we_chat_data[:product_base][:property] << { id: property_item.category_property.we_chat_id, vid: property_item.we_chat_id } }
we_chat_data[:product_base][:sku_list] = []
we_chat_data[:product_base][:sku_info] = []
self.skus.each do |sku|
we_chat_data[:product_base][:sku_list] << sku.to_we_chat_data
if sku.sku_definition_items.length > 0
sku.sku_definition_items.each do |sku_definition_item|
index = we_chat_data[:product_base][:sku_info].index { |item| item[:id] == sku_definition_item.sku_definition.we_chat_id }
sku_info_data = {id: sku_definition_item.sku_definition.we_chat_id, vid: []}
if index && index >= 0
sku_info_data = we_chat_data[:product_base][:sku_info][index]
else
we_chat_data[:product_base][:sku_info] << sku_info_data
end
sku_info_data[:vid] << sku_definition_item.we_chat_id unless sku_info_data[:vid].include?(sku_definition_item.we_chat_id)
end
end
end
we_chat_data
end
|