Promotion over two promotion products
This commit is contained in:
@@ -63,10 +63,17 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.check_promo_type(promo, orderitem, sale_id)
|
def self.check_promo_type(promo, orderitem, sale_id)
|
||||||
same, promo_product = check_giveaway_product(promo, orderitem[0])
|
promo.promotion_products.each do |promo_product|
|
||||||
|
if promo_product.item_code == orderitem[0]
|
||||||
|
same = true
|
||||||
|
else
|
||||||
|
# return false, promo_product
|
||||||
|
same = false
|
||||||
|
end
|
||||||
|
# same, promo_product = check_giveaway_product(promo, orderitem[0])
|
||||||
if promo.promo_type == Promotion::PROMO_TYPE1
|
if promo.promo_type == Promotion::PROMO_TYPE1
|
||||||
if same
|
if same
|
||||||
give_promotion_same_product(orderitem[1], promo.min_qty, promo_product.min_qty, orderitem, sale_id)
|
give_promotion_same_product(orderitem[1], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code)
|
||||||
else
|
else
|
||||||
give_promotion_second_product(orderitem[1], promo.min_qty, promo_product.item_code, orderitem, sale_id)
|
give_promotion_second_product(orderitem[1], promo.min_qty, promo_product.item_code, orderitem, sale_id)
|
||||||
end
|
end
|
||||||
@@ -80,19 +87,23 @@ class Promotion < ApplicationRecord
|
|||||||
elsif promo.promo_type == Promotion::PROMO_TYPE4
|
elsif promo.promo_type == Promotion::PROMO_TYPE4
|
||||||
give_promotion_discount(same,promo_product,promo.min_qty, orderitem, sale_id)
|
give_promotion_discount(same,promo_product,promo.min_qty, orderitem, sale_id)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_giveaway_product(promo, orderitem)
|
def self.check_giveaway_product(promo, orderitem)
|
||||||
promo.promotion_products.each do |promo_product|
|
# promo_pp = []
|
||||||
if promo_product.item_code == orderitem
|
# flag = false
|
||||||
return true, promo_product
|
# promo.promotion_products.each do |promo_product|
|
||||||
else
|
# if promo_product.item_code == orderitem
|
||||||
return false, promo_product
|
# # return true, promo_product
|
||||||
end
|
# promo_pp.push(promo_product)
|
||||||
end
|
# else
|
||||||
|
# # return false, promo_product
|
||||||
|
# end
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, sale_id)
|
def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, sale_id,promo_product)
|
||||||
puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s
|
puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s
|
||||||
multiple = qty.to_i / promoqty.to_i # loop count
|
multiple = qty.to_i / promoqty.to_i # loop count
|
||||||
charge_qty = 0
|
charge_qty = 0
|
||||||
@@ -120,7 +131,7 @@ class Promotion < ApplicationRecord
|
|||||||
charge_qty += qty
|
charge_qty += qty
|
||||||
end
|
end
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_instance_code
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
else
|
else
|
||||||
item = OrderItem.find_by_item_code(promo_product)
|
item = OrderItem.find_by_item_code(promo_product)
|
||||||
|
|||||||
Reference in New Issue
Block a user