我正在尝试为电子商务商店设置一些动态促销(在管理区域中管理)。
例如:如果客户的购物车中有棒球帽和棒球面具,并且购物车总金额大于 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 和购物车总和。我需要获得合适的促销折扣。
谢谢大家的帮助!
最佳答案
这不是您问题的直接答案,但我可能会选择捆绑产品本身并在捆绑价格中打折它们的总值(value)。
编辑:
画了一个小草图,可能会帮助或引导您找到某个方向。
//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.
}
}
还建议您检查现有的电子商务平台,看看他们是如何做到的。
关于php - SQL 升级和规则表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51961518/