Stéphane1405 Posted August 20, 2015 Share Posted August 20, 2015 The following script will create a new cart rule that can for instance be used for coupon code (voucher). This is drawn from cart rule object model definition (classes/CartRule.php L78). $coupon = new Discount(); //put here the coupon name + translations //ex: if your website is in french (id language = 1) and english (id language = 2) $coupon->name = array(1=>"mon coupon",2=>"my coupon"); //by default cart rule is valid for one client that can use it one time //validity $coupon->date_from = "2015-08-20"; $coupon->date_to = "2015-08-21"; //code $coupon->code = "789456"; //50 % off $coupon->reduction_percent = "50"; //conditions //ex: rule only applies if the order is 100 or more including taxes and exluding shipping $coupon->minimum_amount = 100; $coupon->minimum_amount_tax = 1; $coupon->minimum_amount_currency = 1; $coupon->minimum_amount_shipping = 0; //this creates the coupon $coupon->add(); Hope this will help 4 1 Link to comment Share on other sites More sharing options...
univers3 Posted May 17, 2016 Share Posted May 17, 2016 From the bottom of my heart: I love you stranger. Link to comment Share on other sites More sharing options...
Jose Bttcr Posted December 10, 2019 Share Posted December 10, 2019 Thank you!! (4 years later 😂). There is a little change you have to do if you use newer versions of prestashop, replace: $coupon = new Discount(); With: $coupon = new CartRule(); 1 Link to comment Share on other sites More sharing options...
Daniel_HernandezR Posted January 12, 2022 Share Posted January 12, 2022 Hello @Stéphane1405 Excuse me, can I create a cart rule in a Module front controller?? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now