merge with r-19
This commit is contained in:
@@ -2,56 +2,25 @@
|
||||
attr_format = []
|
||||
# Format for attributes json
|
||||
if item.is_available
|
||||
# Format for attributes json
|
||||
attr_format = []
|
||||
# Format for attributes json
|
||||
if item.item_attributes.count > 0
|
||||
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: [menu_attr.name] })
|
||||
next
|
||||
end
|
||||
|
||||
attr_format.each do |af|
|
||||
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)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
item_attributes = item.item_attributes.map(&:to_s)
|
||||
attr_format = @item_attributes.select { |x| item_attributes.include?(x.id.to_s) }.group_by {|att| att.attribute_type.strip }.map { |type, values| {type: type, values: values.map { |x| x.name.strip } } }
|
||||
end
|
||||
|
||||
# Format for option json
|
||||
opt_format = []
|
||||
# Format for attributes json
|
||||
if item.item_options.count > 0
|
||||
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
|
||||
item_options = item.item_options.map(&:to_s)
|
||||
opt_format = @item_options.select { |x| item_options.include?(x.id.to_s) }.group_by {|opt| opt.option_type.strip }.map { |type, values| {type: type, values: values.map { |x| x.name.strip } } }
|
||||
end
|
||||
|
||||
#Menu Item Information
|
||||
json.id item.id
|
||||
json.code item.item_code
|
||||
json.code item.item_code
|
||||
json.name item.name
|
||||
json.alt_name item.alt_name
|
||||
if !request_url.nil? && request_url != '' && !item.image_path.nil?
|
||||
@@ -75,9 +44,7 @@ if item.is_available
|
||||
json.alt_name its.alt_name
|
||||
json.min_selectable_qty its.min_selectable_qty
|
||||
json.max_selectable_qty its.max_selectable_qty
|
||||
json.instances its.menu_item_instances do |i|
|
||||
json.id i.id
|
||||
end
|
||||
json.instances its.menu_item_instances.map { |i| {id: i.id} }
|
||||
end
|
||||
|
||||
json.attributes attr_format
|
||||
@@ -97,7 +64,8 @@ if item.is_available
|
||||
json.instances item.menu_item_instances do |is|
|
||||
if is.is_available
|
||||
# Convert id to name for attributes
|
||||
instance_attr = []
|
||||
item_attributes = is.item_attributes.map(&:to_s)
|
||||
instance_attr = @item_attributes.select{ |x| item_attributes.include?(x.id.to_s) }.pluck(:name)
|
||||
|
||||
is.item_attributes.each do |ia|
|
||||
# mItemAttr = MenuItemAttribute.find(is)
|
||||
|
||||
Reference in New Issue
Block a user