Files
sx-fc/app/views/settings/menu_item_instances/get_instance.json.jbuilder
2017-10-23 11:38:10 +06:30

40 lines
978 B
Ruby
Executable File

if(@id)
menu_item = MenuItem.find(@id.menu_item_id)
# Format for option json
opt_format = []
# Format for attributes json
menu_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: [menu_opt.name] })
next
end
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_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
opt_format.push(new_opt)
break
end
end
end
json.success true
json.id @id.id
json.name @id.item_instance_name
json.code @id.item_instance_code
json.item_id @id.menu_item_id
json.attributes @id.item_attributes
json.price @id.price
json.is_default @id.is_default
json.options opt_format
else
json.success false
end