Magento EE, use reward points in X percent of total (subtotal) checkout value

Featured Image

Magento EE is a great platform, it offers so much features out of the box. However, merchants can be relentless sometimes and always ask for that little extra around a given feature. So happens that I’ve been working on a project recently where we needed to squeeze a little extra from Magenot’s Reward Points functionality. We need the possibility to use reward points in X percent of total (subtotal) checkout value. This is not a built in option that you can configure, so it required a bit of custom coding.

I’ll be honest with you, every time I need to poke around Magento checkout I get all nervous and jumpy, as you never know how much time it will take you. After some careful planning and analysis I came up with the quick solution. Why not simply override the method that returns the reward points balance and fake the reward points amount by implementing the “use reward points in X percent of total (subtotal) checkout value” logic. There is one major drawback to this, if we override the method to fake the amount of reward point’s then the amount would be faked trough entire site, which we do not want. We just want to fake it throughout the checkout process until we create a successful order.

So where do we begin (first off all, we are talking about Magento EE so I’m unable to give you a more detailed code overview, only what I coded)? We will begin by rewriting the Enterprise_Reward_Model_Reward class trough your modules config.xml file.


Then the implementation of Inchoo_MyModule_Model_Reward itself.

class Inchoo_MyModule_Model_Reward extends Enterprise_Reward_Model_Reward
    public function getPointsBalance()
        $request = Mage::app()->getRequest();
        if ($request->getModuleName() == 'checkout') {
            if (($quote = Mage::getModel('checkout/session')->getQuote())) {
                $totals = $quote->getTotals();
                $cartTotal = floor($totals["subtotal"]->getValue());
                if ($cartTotal > 0) {
                    $rpPercent = 23; /* some integer value representing percent, could read this trough some config */
                    $rpAllowedMax = $cartTotal * ($rpPercent / 100);
                    $rpAllowedMax = floor($rpAllowedMax);
                    if ((int)$this->getData('points_balance') >= $rpAllowedMax) {
                        return $rpAllowedMax;
        return $this->getData('points_balance');

The best part of all is the getPointsBalance() method itself. If you look at the parent class, you will see that the method does not exit there. It’s one of those Magento/PHP magic method implemented trough Varien_Object. So, by implementing the method our-self we get the control of the returned balance value, while still being able to fetch the true non-touched value of points_balance by calling the $reward->getData(‘points_balance’) later in the code.

And for the grand finale, we simply limit the special “use reward points in X percent of total (subtotal) checkout value” function behavior to “checkout” module by usage of if($request->getModuleName() == ‘checkout’). If you trace the controller actions more thoroughly, you can even limit it to a controller action level. Just be sure to test everything later so that you do not break calls to $reward->getPointsBalance() on a places that should not implement the above logic.

You might also change the default message for Reward Points shown on the Payment step of the checkout to something like:

<?php echo Mage::helper('enterprise_reward')->__('Use my reward points, %s available out of %d total', Mage::helper('enterprise_reward')->formatReward($this->getPointsBalance(), $this->getCurrencyAmount()), $this->getReward()->getData('points_balance')); ?>

With this simple approach I was able to get the exact behavior I needed. I do realize that the approach I took might not be the best optimized, or in the best spirit of MVC since I was doing a module/controller action check within the module, but it strikes the right balance between “do it on time and do it stable” 🙂

I realize this article is somewhat specific and might not apply directly to wider public, but I hope it was useful, at least as an idea :).


1 comment

  1. Thanks for this wonderful post.
    But where to use these coding? Please help me out.
    I am making ecommerce website and we are in startup.

    Thankyou once again.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.