update api/resturant/menu
This commit is contained in:
@@ -56,6 +56,8 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
else
|
else
|
||||||
render :json => { :status => false, :error_message => "No current booking!" }
|
render :json => { :status => false, :error_message => "No current booking!" }
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
render :json => { :status => false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ class Api::Restaurant::MenuController < Api::ApiController
|
|||||||
param_checksum = params[:checksum]
|
param_checksum = params[:checksum]
|
||||||
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
|
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
|
||||||
|
|
||||||
all_menu = Menu.active.all
|
all_menu = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
|
||||||
|
|
||||||
@request_url = ''
|
@request_url = ''
|
||||||
if ENV["SERVER_MODE"] == "cloud"
|
if ENV["SERVER_MODE"] == "cloud"
|
||||||
@request_url = request.base_url
|
@request_url = request.base_url
|
||||||
@@ -14,10 +15,7 @@ class Api::Restaurant::MenuController < Api::ApiController
|
|||||||
# to hash
|
# to hash
|
||||||
menu_array = []
|
menu_array = []
|
||||||
all_menu.each do |m|
|
all_menu.each do |m|
|
||||||
menu_array.push(m.to_json(:include => {:menu_categories =>
|
menu_array.push(m.to_json(:include => { :menu_categories => { :include => { :menu_items => { :include => [ :item_sets, :menu_item_instances => { :include => :menu_instance_item_sets } ] } } } } ))
|
||||||
{ :include => { :menu_items =>
|
|
||||||
{ :include => [:menu_item_sets, :menu_item_instances =>
|
|
||||||
{ :include => :menu_instance_item_sets}]} } }}))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#export Checksum file generate by md5
|
#export Checksum file generate by md5
|
||||||
@@ -26,6 +24,10 @@ class Api::Restaurant::MenuController < Api::ApiController
|
|||||||
if menu_checksum != param_checksum
|
if menu_checksum != param_checksum
|
||||||
response.headers['CHECKSUM'] = menu_checksum
|
response.headers['CHECKSUM'] = menu_checksum
|
||||||
@menus = all_menu
|
@menus = all_menu
|
||||||
|
@item_attributes = MenuItemAttribute.all.load
|
||||||
|
@item_options = MenuItemOption.all.load
|
||||||
|
else
|
||||||
|
render :json => nil
|
||||||
end
|
end
|
||||||
# @current_menu = Menu.current_menu
|
# @current_menu = Menu.current_menu
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Origami::DashboardController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_all_menu
|
def get_all_menu
|
||||||
@menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.all
|
@menus = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
|
||||||
@item_attributes = MenuItemAttribute.all.load
|
@item_attributes = MenuItemAttribute.all.load
|
||||||
@item_options = MenuItemOption.all.load
|
@item_options = MenuItemOption.all.load
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,51 +2,20 @@
|
|||||||
attr_format = []
|
attr_format = []
|
||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
if item.is_available
|
if item.is_available
|
||||||
|
# Format for attributes json
|
||||||
|
attr_format = []
|
||||||
|
# Format for attributes json
|
||||||
if item.item_attributes.count > 0
|
if item.item_attributes.count > 0
|
||||||
item.item_attributes.each do|attr_id|
|
item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) }
|
||||||
menu_attr = MenuItemAttribute.find(attr_id)
|
attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Format for option json
|
# Format for option json
|
||||||
opt_format = []
|
opt_format = []
|
||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
if item.item_options.count > 0
|
if item.item_options.count > 0
|
||||||
item.item_options.each do|opt|
|
item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) }
|
||||||
menu_opt = MenuItemOption.find(opt)
|
opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#Menu Item Information
|
#Menu Item Information
|
||||||
@@ -75,9 +44,7 @@ if item.is_available
|
|||||||
json.alt_name its.alt_name
|
json.alt_name its.alt_name
|
||||||
json.min_selectable_qty its.min_selectable_qty
|
json.min_selectable_qty its.min_selectable_qty
|
||||||
json.max_selectable_qty its.max_selectable_qty
|
json.max_selectable_qty its.max_selectable_qty
|
||||||
json.instances its.menu_item_instances do |i|
|
json.instances its.menu_item_instances.map { |i| {id: i.id} }
|
||||||
json.id i.id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
json.attributes attr_format
|
json.attributes attr_format
|
||||||
@@ -97,14 +64,7 @@ if item.is_available
|
|||||||
json.instances item.menu_item_instances do |is|
|
json.instances item.menu_item_instances do |is|
|
||||||
if is.is_available
|
if is.is_available
|
||||||
# Convert id to name for attributes
|
# Convert id to name for attributes
|
||||||
instance_attr = []
|
instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name)
|
||||||
|
|
||||||
is.item_attributes.each do |ia|
|
|
||||||
# mItemAttr = MenuItemAttribute.find(is)
|
|
||||||
# instance_attr.push(ia)
|
|
||||||
mItemAttr = MenuItemAttribute.find(ia).name
|
|
||||||
instance_attr.push(mItemAttr)
|
|
||||||
end
|
|
||||||
|
|
||||||
json.id is.id
|
json.id is.id
|
||||||
json.code is.item_instance_code
|
json.code is.item_instance_code
|
||||||
|
|||||||
Reference in New Issue
Block a user