2017-05-06 56 views
1

您好首先我想說的是,這個社會是我的聖經,我欠了很多債,非常感謝你,cartrule程序不起作用折扣的Prestashop 1.7

現在關於我的問題,並一直在研究一個折扣產品和客戶都通過在購物車格時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();  

的代碼創建成功的產品折扣規則我可以​​在折扣部分檢查它在管理,該規則已創建,但在訂單結束時,我在管理員中看到該訂單沒有任何折扣,並且在沒有地方我用戶有一個購物車規則可以扣除規則的百分比。

在此先感謝

回答

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