fix menu item json format

This commit is contained in:
Yan
2017-08-24 12:48:10 +06:30
parent 18dc0300c4
commit d36a633134

View File

@@ -1,49 +1,47 @@
# Format for attributes json
attr_format = []
param_count = item.item_attributes.count
# Format for attributes json
item.item_attributes.each do|attr_id|
menu_attr = MenuItemAttribute.find(attr_id)
if attr_format.count == 0
attr_format.push({ type: menu_attr.attribute_type, values: [] })
attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] })
next
end
attr_format.each do |af|
if menu_attr.attribute_type == af[:type]
af[:values].push(menu_attr.name)
if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]}
if menu_attr.attribute_type == af[:type]
af[:values].push(menu_attr.name)
end
else
new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] }
attr_format.push(new_attr)
end
break if attr_format.count > param_count
break
end
end
param_count -= 1
end
# Format for option json
opt_format = []
param_count = item.item_options.count
# Format for attributes json
item.item_options.each do|opt|
menu_opt = MenuItemOption.find(opt)
if opt_format.count == 0
opt_format.push({ type: menu_opt.option_type, values: [] })
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
next
end
opt_format.each do |af|
if menu_opt.option_type == af[:type]
af[:values].push(menu_opt.name)
opt_format.each do |of|
if menu_opt.option_type.in? opt_format.map {|k| k[:type]}
if menu_opt.option_type == of[:type]
of[:values].push(menu_opt.name)
end
else
new_attr = {type: menu_opt.option_type, values: [ menu_opt.name ] }
opt_format.push(new_attr)
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
opt_format.push(new_opt)
break
end
break if opt_format.count > param_count
end
param_count -= 1
end
end
#Menu Item Information