Php cartrule不以编程方式';t工作折扣优惠1.7

Php cartrule不以编程方式';t工作折扣优惠1.7,php,e-commerce,prestashop,prestashop-1.7,Php,E Commerce,Prestashop,Prestashop 1.7,您好首先我想说这个社区是我的圣经,我欠了很多,非常感谢 现在,关于我的问题,在使用购物车网格时,我一直在通过ajax为产品和客户提供折扣,代码如下: $context = Context::getContext(); $cod_prod = Tools::getValue('id_data'); $qty = Tools::getValue('qty'); $descuento = Tools::getValue('descuento'); $t

您好首先我想说这个社区是我的圣经,我欠了很多,非常感谢

现在,关于我的问题,在使用购物车网格时,我一直在通过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();    
代码成功地为产品创建了折扣规则。我可以在“折扣”部分的“管理员”中检查该规则,该规则已创建,但在订单结束时,我在“管理员”中看到,订单未分配任何折扣,并且在任何地方,用户都没有将扣除该规则百分比的购物车规则


提前感谢

我没有将规则与购物车联系起来,我是用这些行来做的,它工作得非常完美

    $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);