prestadev001 Posted October 15, 2013 Share Posted October 15, 2013 Hi, I am using prestashop 1.5.4. When creating cart rule dynamically using below code, it create the code but on applying it on cart it is not showing the code row in cart and also not applying discount on total. If I simply update (open that cart rule in edit mode and just click on update) the cart rule from back office and refresh the cart page in front office , it start displaying. how can I fix it? $cart_rule = new CartRule(); $languages = Language::getLanguages(); foreach ($languages as $key => $language) {$array[$language['id_lang']]= "TestCode";} $cart_rule->name=$array; $cart_rule->description = "Test Code"; $cart_rule->code = '123456789'; $cart_rule->id_currency = $this->context->currency->id; $cart_rule->active = 1; $cart_rule->date_from = date('Y-m-d 00:00:00'); $cart_rule->date_to = date('Y-m-d h:i:s', mktime(0, 0, 0, date("m"), date("d")+1, date("Y"))); $cart_rule->minimum_amount = '1'; $cart_rule->minimum_amount_currency = 1; $cart_rule->quantity = 1; $cart_rule->quantity_per_user = 1; $cart_rule->reduction_amount = 10; $cart_rule->add(); Best Regards, Link to comment Share on other sites More sharing options...
vekia Posted October 15, 2013 Share Posted October 15, 2013 hello you must change one variable in ps_configuration table: Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', '1'); Link to comment Share on other sites More sharing options...
prestadev001 Posted October 16, 2013 Author Share Posted October 16, 2013 hello you must change one variable in ps_configuration table: Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', '1'); Hello Vekia, I tried but still not found any luck. Best regards, Link to comment Share on other sites More sharing options...
prestadev001 Posted October 16, 2013 Author Share Posted October 16, 2013 (edited) Hi, I figured it out. Just to add : $cart_rule->reduction_currency = 1; Actually I want to generate cart rule at the submission of voucher by user in cart page. Is their any hook in prestashop that solve my purpose or I have to override order controller. Thanks for help! Best Regards, Edited October 16, 2013 by prestadev001 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 16, 2013 Share Posted October 16, 2013 hello thank you for solution of your issue im convinced taht this will be helpful for all merchants & developers here. topic marked as solved regards Link to comment Share on other sites More sharing options...
savvato Posted April 21, 2015 Share Posted April 21, 2015 and how to add a gift using this method? I try, but it does not work. $cart_rule = new CartRule(); $languages = Language::getLanguages(); foreach($languages as $key => $language){ $array[$language['id_lang']] = "Gift"; } $cart_rule->name = $array; $cart_rule->description = "Gift"; $cart_rule->partial_use = 1; $cart_rule->reduction_currency = intval(Configuration::get('PS_CURRENCY_DEFAULT')); $cart_rule->active = 1; $cart_rule->date_from = "$startdate"; $cart_rule->date_to = "$enddate"; $cart_rule->minimum_amount = '1'; $cart_rule->minimum_amount_currency = '1'; $cart_rule->quantity = '1'; $cart_rule->quantity_per_user = '1'; $cart_rule->product_restriction = '1'; $cart_rule->reduction_percent = ''; $cart_rule->priority = '1'; $cart_rule->reduction_product = ''; $cart_rule->gift_product = $id_gift; $cart_rule->date_add = 'NOW()'; $cart_rule->date_upd = 'NOW()'; //d($cart_rule); $cart_rule->add(); variables $startdate, $enddate, $id_gift are defined Link to comment Share on other sites More sharing options...
Recommended Posts