Jump to content

Cart rule / voucher on the go


Recommended Posts

Hello, 

 

I'm developing a small module that add discount on the cart when certain conditions are ok.

 

Currently I use cart rule but i don't like this way : 

 

If the cart rule exist, I have to update it to set quantity and new percentage

otherwise I have to create it and it stay in the "My vouvher" block.

 

I want to know if there is a way to create a discount on the go (on the "hookShoppingCart" I guess) without really creating it.

 

I already tried (not the fulle code) : 

$c = $params['cart'];
$cart = new Cart($c->id, $c->id_lang);

$cart_rule = new CartRule();
//Setting the cart rule

$cart->addCartRule($cart_rule->id);
$cart->update();

But it doens't work without 

$cart_rule->add();

Thanks for your help !

 

EDIT : 

$cart->addCartRule($cart_rule->id);

return false

 

Edit 2 

$cart_rule->checkValidity($context, false, true)

return null

Edited by Quentin Goinaud (see edit history)
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...