首先我想说这个社区是我的圣经,我欠了很多,非常感谢,
现在关于我的问题,并且在购物车网格时通过ajax一直在为产品和客户打折,代码如下:
$context = Context::getContext();
$cod_prod = Tools::getValue('id_data');
$qty = Tools::getValue('qty');
$descuento = Tools::getValue('descuento');
$time_original = strtotime(date("Y-m-d H:i:s"));
$time_add = $time_original + (3600*24);
$r = new CartRule();
$r->name = array(1=>"descuento".$context->cookie->id_customer.date("Ymd_His"));
$r->id_customer = $context->cookie->id_customer;
$r->date_from = date("Y-m-d H:i:s");
$r->date_to = date("Y-m-d H:i:s", $time_add);
$r->description = "desc";
$r->quantity = $qty;
$r->quantity_per_user = $qty;
$r->priority = 1;
$r->partial_use = 1;
$r->minimum_amount = 0.00;
$r->minimum_amount_tax = 0;
$r->minimum_amount_currency = 1;
$r->minimum_amount_shipping = 1;
$r->country_restriction = 0;
$r->carrier_restriction = 0;
$r->group_restriction = 0;
$r->cart_rule_restriction = 0;
$r->product_restriction = 1;
$r->shop_restriction = 0;
$r->free_shipping = 0;
$r->reduction_percent = $descuento;
$r->reduction_amount = 0.00;
$r->reduction_tax = 0;
$r->reduction_currency = 1;
$r->reduction_product = $cod_prod;
$r->reduction_exclude_special = 0;
$r->gift_product = 0;
$r->gift_product_attribute = 0;
$r->highlight = 0;
$r->active = 1;
$r->date_add = date("YY-mm-dd");
$r->date_upd = date("YY-mm-dd");
//this creates the coupon
$r->add();
代码成功创建了产品的折扣规则我可以在折扣部分的管理员中检查它,规则已创建,但在订单的最后,我在管理员中看到,订单没有任何分配任何折扣,并且在没有地方冰,用户有购物车规则将扣除规则的百分比。
提前致谢
答案 0 :(得分:1)
我没有将规则与购物车联系起来,我用这些线条做了,它完美地运作了
$values = array(
'tax_incl' => $r->getContextualValue(true),
'tax_excl' => $r->getContextualValue(false)
);
$context->cart->addCartRule($r->id, $r->name[Configuration::get('PS_LANG_DEFAULT')], $values);