univers3 Posted June 7, 2016 Share Posted June 7, 2016 Hi there, I have just made a script to create a new CartRule programmatically. The problem is that I don't know how to make it incompatible to all the existing ones. This is mi script: $coupon = new CartRule(); //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=>"Voucher ".$_GET['valore']."€",2=>"Voucher ".$_GET['valore']."€"); //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 = "2019-08-21"; //Make a random code $exist = true; while ($exist){ $coupon->code = strtoupper("FNZ-".Tools::passwdGen(5)); $exist = $coupon->cartRuleExists($coupon->code); } //Partial Use $coupon->partial_use = 0; $coupon->reduction_tax = 1; //set value of voucher $coupon->reduction_amount = $_GET['valore']; //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(); The only function in the CartRule class that seems interesting is: public static function copyConditions($id_cart_rule_source, $id_cart_rule_destination) The problem is that will copy only the existing conditions of another CartRule, if in future I will add more Vouchers they will not incompatibles. Anyone can help me o have the solution to make a CartRule incompatible with ALL EXISTING cart rules? Thank you very much. Link to comment Share on other sites More sharing options...
rocky Posted June 8, 2016 Share Posted June 8, 2016 If I understand correctly, you want to make it so the cart rule cannot be used with any other cart rules? Try setting $coupon->cart_rule_restriction to 0. If that doesn't work, try setting it to 1. Reading the code, I'm having trouble understanding which is for "Cumulable" and which is for "Not cumulable", so you'll have to test and let us know. 2 Link to comment Share on other sites More sharing options...
univers3 Posted June 8, 2016 Author Share Posted June 8, 2016 If I understand correctly, you want to make it so the cart rule cannot be used with any other cart rules? Try setting $coupon->cart_rule_restriction to 0. If that doesn't work, try setting it to 1. Reading the code, I'm having trouble understanding which is for "Cumulable" and which is for "Not cumulable", so you'll have to test and let us know. Yeah you understood the problem! And you are right too! After setting the $coupon->cart_rule_restriction to 1 the new CartRule will be incompatible with any other existing cart rule in the shop. Thank you very much Rocky! Link to comment Share on other sites More sharing options...
superskyman100 Posted July 6, 2020 Share Posted July 6, 2020 Hi guys, I have same problem (On prestashop 1.7.6.4) but i don't know where and how i could put this code. Should i put this code i some specific file ? Where do i write $coupon->cart_rule_restriction = 1 in the code ? Thanks 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