cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 Apply discount to cart programmatically

Magento 1.9 Apply discount to cart programmatically

Hello all,

I'm stuck with this: I have to set a discount on specific items (identified by sku) and based on the quantity of these items in the cart.

 

For example: 

  1. Case 1: only 1 items in the cart, the discount will be 20% on this item
  2. Case 2: 2 items in the cart, the discount will be 30% on these items
  3. Case 3: the items are equal or greater than 3 items, the discount will be 50% on these items.

 

I tried to do this by creating rules in the cart, by I can't do this behaviour.

 

 

So I think that I can do this only by code, maybe by an observer (when i count the items in the cart and then apply the right discount)? By I don't know to modify the discount in the cart (I can loop on the items in the cart and get the price, but i don't know how to modify the discount or the grand total).

 

 

Can anyone help me??

 

I take into in account also to install a extension but i didn't find nothing doing that