2017-05-06 3 views
1

Hallo erstmal möchte ich sagen, dass diese Gemeinschaft meine Bibel ist und ich verdanke viel, ich danke Ihnen sehr,cartrule programmatisch nicht funktioniert Rabatt PrestaShop 1.7

Nun meine Frage in Bezug auf und wurde auf einem Rabatt für Arbeits Produkt- und Kunden alle durch ajax zum Zeitpunkt des Einkaufswagens Raster, ist der Code wie folgt:

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

der Code erfolgreich den Rabatt-Regel für das Produkt erstellt ich es in den Admin in der Rabatte Teil zu überprüfen, die regel ist erstellt, aber am ende der bestellung, sehe ich in der admin und die bestellung hat nichts zugewiesen rabatt, und in keinem ort ich ce, dass der Benutzer eine Einkaufswagenregel hat, die den Prozentsatz der Regel abzieht.

Dank im Voraus

Antwort

1

ich nicht die Regel mit dem Wagen assoziieren habe, habe ich es mit diesen Zeilen, es funktionierte perfekt

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