我正在尝试为电子商务商店设置一些动态促销(在管理区域中管理)。
例如:如果客户的购物车中有一个棒球帽和一个棒球面罩,且购物车总和大于100美元,则可以给他20美元的折扣
我具有以下表格结构(可以更改):
PROMOTIONS (id, discount)
PROMOTIONS_RULES (id, promotions_id, variable, operator, value)
我已经用以下伪数据填充了表:
PROMOTIONS
1, 20$
PROMOTIONS_RULES
1, 1, product_id, =, 2
1, 1, product_id, =, 3
1, 1, cart_sum, >, 100
我的问题是:如何针对特定的购物车组合有效地寻找合适的促销活动?
我有一组产品ID和购物车金额。而且我需要获得正确的促销折扣。
感谢帮助人员!
答案 0 :(得分:0)
这并不是您问题的直接答案,但我可能会把产品本身捆绑在一起,并以捆绑价格将其总价值打折。
编辑:
制作一些草图,可能会帮助您或引导您前进。
//table structure something like this
discounts
id_discount, amount, name
discount_rules
id_rule, id_discount, combination (bool), min_cart_total_value, active (bool)
discount_combination
id_combination, id_rule
discount_combination_products
id_combination, id_product
// query for combination discounts when in shopping cart
Select d.id_discount
From discounts d
Left Join discount_rules dr on d.id_discount = dr.id_discount
Where dr.active = 1, dr.combination = 1
//sort the cart products
sort($cartproducts);
foreach($queried_ids as $discount_id){
//query for products in those combination discounts
Select dcp.id_product
From discount_rules dr
Left Join discount_combination dc on dr.id_rule = dc.id_rule
Left Join discount_combination_products dcp on dc.id_combination = dcp.id_combination
Where dr.id_discount = $discount_id
//match the cart with possible discounts
sort($result_array);
if($cartproducts == $result_array){
//match apply this discount to the cart and so on.
}
}
还建议您检查现有的电子商务平台,并查看他们的工作方式。