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