fix member sync and menu json
This commit is contained in:
@@ -91,41 +91,50 @@ class Customer < ApplicationRecord
|
|||||||
auth_token = memberaction.auth_token.to_s
|
auth_token = memberaction.auth_token.to_s
|
||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||||
|
|
||||||
@customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL")
|
@customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL")
|
||||||
|
|
||||||
@customers.each do |customer|
|
@customers.each do |customer|
|
||||||
begin
|
member_params = { name: customer.name,phone: customer.contact_no,
|
||||||
response = HTTParty.post(url,
|
email: customer.email,dob: customer.date_of_birth,
|
||||||
:body =>
|
address: customer.address,nrc:customer.nrc_no,
|
||||||
{ name: customer.name,phone: customer.contact_no,
|
card_no:customer.card_no,member_group_id: customer.membership_type,
|
||||||
email: customer.email,dob: customer.date_of_birth,
|
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||||
address: customer.address,nrc:customer.nrc_no,
|
|
||||||
card_no:customer.card_no,member_group_id: customer.membership_type,
|
|
||||||
merchant_uid:merchant_uid,auth_token:auth_token
|
|
||||||
}.to_json,
|
|
||||||
:headers => {
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Accept' => 'application/json'
|
|
||||||
})
|
|
||||||
rescue Net::OpenTimeout
|
|
||||||
response = { status: false, message: "Server Time out" }
|
|
||||||
|
|
||||||
rescue OpenURI::HTTPError
|
|
||||||
response = { status: false, message: "Can't connect server"}
|
|
||||||
|
|
||||||
rescue SocketError
|
# Check for paypar account exists
|
||||||
response = { status: false, message: "Can't connect server"}
|
# if paypar_account_no != nil || paypar_account_no != ''
|
||||||
end
|
if paypar_account_no.present?
|
||||||
|
member_params = { name: customer.name,phone: customer.contact_no,
|
||||||
|
email: customer.email,dob: customer.date_of_birth,
|
||||||
|
address: customer.address,nrc:customer.nrc_no,
|
||||||
|
paypar_account_no: customer.paypar_account_no,
|
||||||
|
card_no:customer.card_no,member_group_id: customer.membership_type,
|
||||||
|
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
if response["status"] == true
|
begin
|
||||||
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
|
response = HTTParty.post(url,
|
||||||
end
|
:body => member_params,
|
||||||
|
:headers => {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json'
|
||||||
|
})
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
response = { status: false, message: "Server Time out" }
|
||||||
|
|
||||||
|
rescue OpenURI::HTTPError
|
||||||
|
response = { status: false, message: "Can't connect server"}
|
||||||
|
|
||||||
|
rescue SocketError
|
||||||
|
response = { status: false, message: "Can't connect server"}
|
||||||
|
end
|
||||||
|
|
||||||
|
if response["status"] == true
|
||||||
|
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_rebate
|
def self.update_rebate
|
||||||
|
|
||||||
sales = Sale.where("rebate_status = 'false'")
|
sales = Sale.where("rebate_status = 'false'")
|
||||||
sales.each do |sale|
|
sales.each do |sale|
|
||||||
if sale.customer.membership_id
|
if sale.customer.membership_id
|
||||||
|
|||||||
@@ -22,23 +22,59 @@ item.item_attributes.each do|attr_id|
|
|||||||
param_count -= 1
|
param_count -= 1
|
||||||
end
|
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, value: [] })
|
||||||
|
end
|
||||||
|
|
||||||
|
opt_format.each do |af|
|
||||||
|
if menu_opt.option_type == af[:type]
|
||||||
|
af[:value].push(menu_opt.value)
|
||||||
|
else
|
||||||
|
new_attr = {type: menu_opt.option_type, value: [ menu_opt.value ] }
|
||||||
|
opt_format.push(new_attr)
|
||||||
|
end
|
||||||
|
|
||||||
|
break if opt_format.count > param_count
|
||||||
|
end
|
||||||
|
|
||||||
|
param_count -= 1
|
||||||
|
end
|
||||||
|
|
||||||
#Menu Item Information
|
#Menu Item Information
|
||||||
json.id item.id
|
json.id item.id
|
||||||
json.item_code item.item_code
|
json.code item.item_code
|
||||||
json.name item.name
|
json.name item.name
|
||||||
json.alt_name item.alt_name
|
json.alt_name item.alt_name
|
||||||
json.image item.image_path.url
|
json.image item.image_path.url
|
||||||
json.description item.description
|
json.description item.description
|
||||||
json.Information item.information
|
json.information item.information
|
||||||
json.type item.type
|
json.type item.type
|
||||||
json.account_id item.account_id
|
json.account_id item.account_id
|
||||||
json.min_qty item.min_qty
|
json.min_qty item.min_qty
|
||||||
json.is_available item.is_available
|
json.is_available item.is_available
|
||||||
json.is_sub_item item.is_sub_item
|
json.is_sub_item item.is_sub_item
|
||||||
json.unit item.unit
|
json.unit item.unit
|
||||||
json.item_sets item.item_sets
|
|
||||||
|
# Item Sets of Menu Item
|
||||||
|
json.item_sets item.item_sets do |its|
|
||||||
|
json.id its.id
|
||||||
|
json.name its.name
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
json.attributes attr_format
|
json.attributes attr_format
|
||||||
json.options item.item_options
|
json.options opt_format
|
||||||
# json.min_selectable_item item.min_selectable_item
|
# json.min_selectable_item item.min_selectable_item
|
||||||
# json.max_selectable_item item.max_selectable_item
|
# json.max_selectable_item item.max_selectable_item
|
||||||
|
|
||||||
@@ -52,6 +88,7 @@ json.options item.item_options
|
|||||||
# json.item_attributes = item_instance.item_attributes
|
# json.item_attributes = item_instance.item_attributes
|
||||||
|
|
||||||
json.instances item.menu_item_instances do |is|
|
json.instances item.menu_item_instances do |is|
|
||||||
|
json.id is.id
|
||||||
json.code is.item_instance_code
|
json.code is.item_instance_code
|
||||||
json.name is.item_instance_name
|
json.name is.item_instance_name
|
||||||
json.price is.price
|
json.price is.price
|
||||||
@@ -59,8 +96,8 @@ json.options item.item_options
|
|||||||
json.is_default is.is_default
|
json.is_default is.is_default
|
||||||
json.is_on_promotion is.is_on_promotion
|
json.is_on_promotion is.is_on_promotion
|
||||||
json.promotion_price is.promotion_price
|
json.promotion_price is.promotion_price
|
||||||
json.item_attributes is.item_attributes
|
json.values is.item_attributes
|
||||||
json.item_sets is.item_sets
|
# json.item_sets is.item_sets
|
||||||
end
|
end
|
||||||
|
|
||||||
#Child Menu items
|
#Child Menu items
|
||||||
|
|||||||
Reference in New Issue
Block a user