Jump to content

How to prevent using coupon when specific product category is in cart?


Recommended Posts

Hello there,
I'm in a bit of a pickle. Iḿ creating sale coupon with CartRule class, but I want to prevent using coupons on specific kind of products (it has its own product category). The problem is that the documentation (https://devdocs.prestashop.com/1.7/webservice/resources/cart_rules/) around CartRule is not good. There is very little explanation around parameters, so if you could help me find what I need to set to prevent using coupons when a specific product category is present, I would be very glad.
Here is my current code:

$cartRuleObj = new CartRule();
$cartRuleObj->cart_rule_restriction = true;
$cartRuleObj->date_from = date('Y-m-d H:i:s');
$cartRuleObj->date_to = $kupon->datum;
$cartRuleObj->name[Configuration::get('PS_LANG_DEFAULT')] = $kupon->jmeno;
$cartRuleObj->quantity = 1;
$code = Tools::strtoupper(Tools::passwdGen());
while (CartRule::cartRuleExists($code)) { // let's make sure there is no duplicate
$code = Tools::strtoupper(Tools::passwdGen());
}
$coupon = $code;
$cartRuleObj->code = $code;
$idcoupon = $kupon->class;
$cartRuleObj->reduction_percent = $kupon->sleva;
$cartRuleObj->free_shipping = 0;
$cartRuleObj->active = 1;
$cartRuleObj->minimum_amount_currency = $kupon->minCena;
$cartRuleObj->add();

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...