Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Show Multiple Discounts Breakdown

I have installed a rewards module into my Magento build. I have also set up some shopping cart promotions. Everything works. On the shopping cart page you can redeem reward points and enter a discount code and everything is discounted correctly. The problem is that they are both labelled under the 'discount' label (where 1,000 points = £1 off)


(source: i.imm.io)

As you can see, it is grouping the £5 coupon discount and the £1 rewards discount together. How do I separate these so that I have two discount rows, one for the coupon and one for the rewards points?

like image 861
Richard Parnaby-King Avatar asked Nov 26 '12 09:11

Richard Parnaby-King


2 Answers

This is not a simple task. Unfortunately Magento's discount system is not supremely prepared for the addition of new discount types that you might not want added together in the cart totals box.

It's true that you need to modify the resetDiscountLabels() method of the TBT_Rewards_Model_Salesrule_Observer class. However, this method is not where Sweet Tooth adds its discount to the discount description. Quite the opposite. Sweet Tooth's discounts are automatically added to Magento's list of discounts on the cart (and the discount description is generated automatically from this list of discounts). The problem is that even the Sweet Tooth discounts that shouldn't be added to the cart will show up there - the discounts that apply to the cart based on the rule you created, but the customer hasn't actually selected to spend their points yet. The resetDiscountLabels() method exists to remove the unwanted discount descriptions from the cart, not add any.

The solution to your problem comes in two steps, and the second step is the more taxing.

First you must modify the above-mentioned method to remove all Sweet Tooth discount descriptions from the cart, rather than just those that don't apply. I would suggest copying the file to your app/code/local codepool first, and modifying that file instead of the original. If you loop through all rule IDs on the cart, then load the rule model, you can tell if it's a Sweet Tooth rule or not if its points_action field is set, i.e. $rule->getPointsAction() !== null. If any of the rules are Sweet Tooth rules, you can unset them from the discount description the way that method is already doing it. After this, Sweet Tooth discounts should no longer appear in that row of your totals box.

The second step is to add a new row to the totals box, a.k.a. add a new total model to the quote. This will be the more complicated step - much more complicated than I can describe in this answer, but here is a tutorial on adding new total columns: http://turnkeye.com/blog/magento-development-add-total-row-checkout/ In your new total model's collect() method, you should check the quote's applied_redemptions field to get a list of Sweet Tooth rule IDs that the customer has applied to their cart. You can then regenerate the total Sweet Tooth discount using these values.

As I said, this is not a simple task, and unfortunately this is the only semi-clean way to do it. Hopefully it's not too much. You could also always hire a development firm to do it for you, if you'd rather focus your own dev time on other tasks.

Hopefully this is useful!

like image 151
JMTyler Avatar answered Nov 15 '22 17:11

JMTyler


You would need to modify /TBT/Rewards/Model/Salesrule/Observer.php - check checkRedemptionCouponBefore() for the discount amount and check resetDiscountLabels() - this is where Sweet Tooth adds its discount to the discount description.

You may also need to modify /app/design/frontend/base/default/template/rss/order/details.phtml - after the lines if ($_order->getDiscountAmount() > 0)

like image 26
Francis Kim Avatar answered Nov 15 '22 15:11

Francis Kim