1

I am trying to set up a shopping cart rule like this, but I am not able to think of the best solution. This is the scenario:

I have a product X. If user buys 2 quantities of X, he should get 5% on the second X. If user buys 3 quantities of X, he should get 5% on the second X and 10% on the third X.

Is there an easy way to do this via code or extension ?

I have tried setting up 2 rules for this purpose. It works almost with a little problem.

Rule #1 (5% on 2nd X):

Condition:
SKU is X
Qty in cart greater than or equal to 2
Action:
Discount Amount: 5%
Max Qty to Apply Discount: 1
Apply on Condition: SKU is X

This is working fine. The problem is with the 2nd rule:

Rule #2 (10% on 3rd X):

Condition:
SKU is X
Qty in cart greater than or equal to 3
Action:
Discount Amount: 10%
Max Qty to Apply Discount: 1
Apply on Condition: SKU is X

It says if there are 3 or more products, apply a 10% discount on one of the products. Magento is applying the 10% discount on the already reduced 5% product instead of the unit base price.

How do I tell Magento to apply the 10% on the most expensive product or the non-discounted product ?

One solution: Applying some mathematics, I found that if I set Rule #2 to apply a discount of 10.5263% instead of 10%, it works. But the decimal points differ slightly which I can live with.

My concern is I am not sure if Magento always applies this discount on the already reduced product price or the base unit price.

2 Answers 2

1

It can't be achieved directly from admin configuration, need some code tweaking in Rule Validator class.

In the function 'process' of Mage_SalesRule_Model_Validator class, in the case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION: around line #316 add the following code:

if($rule->getId() == YOUR_RULE_ID) { $qty = $qty - 2; }

And regarding the issue "apply a discount of 10.5263% instead of 10%", you need to add 10% only in admin. As two rules are applying one after one, the second rule is considering the already applied discount to do calculation. So you need to make Discount Qty Step (Buy X) in admin as zero to avoid it.

Thanks,

Aravind.

3
  • Please add some information about this code tweaking, otherwise the answer is unlikely to help future visitors. Commented Dec 3, 2014 at 13:52
  • Updated my answer....Added information about code tweaking...
    – Aravind
    Commented Dec 4, 2014 at 5:40
  • Aravind, I couldn't understand your solution. How will $qty-2 help ? Also, Discount QTY step is already 0. Could you please explain ?
    – Hashid
    Commented Dec 4, 2014 at 9:56
0

I used Amasty's Special Promotions extension to accomplish this. They have an option to specifiy discount percentage "after N products"

So I set 2 rules one using default Magento for the 5% discount and another one using Amasty for 10% discount on additional.

I know this is not the answer expected, well someday I will code this and post it here. Running busy now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.