Magento Enterprise is a powerful and flexible eCommerce platform. However, as Magento adoption rapidly increases, there are retailers who require more than the Magento developers can provide.
Works on Magento’s Reward Points Functionality
Recently, I have worked on Magento’s Reward Points functionality. Our work on Magento development included a little bit of custom coding in order to bring about the usage of reward points in X percent of total checkout value.
I was panicked while dealing with Magento checkout as the time consumption for this was unknown. After detailed study a quick solution was obtained. The solution to this problem was including the method that returns the reward points balance and fake the reward points using the logic “use reward points in X percent of total (subtotal) checkout value”.
Drawbacks
Faking the amount of reward points will fake the amount throughout the site. We just wanted to fake it throughout the checkout process until we create a successful order.
It will be difficult for me to give you a detailed code overview. But I can give details of what I have coded.
First of all let’s rewrite the Enterprise_Reward_Model_Reward class trough modules config.xml files.
<global>
<models>
<enterprise_reward>
<rewrite>
<reward>Inchoo_MyModule_Model_Reward</reward>
</rewrite>
</enterprise_reward>
</models>
</global>
After this you need to implement Inchoo_MyModule_Model_Reward.
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’);
}
}
In all these the best part is getPointsBalance() method. This method doesn’t exist in the parent class. This is a Magento/PHP magic method implemented trough Varien_Object. By implementing this method a control over the returned balance value is achieved, 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.
Finally, we 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’). It can even be limited to a controller action level. Everything must be tested to prevent breaking of the calls to $reward->getPointsBalance() on places that should not implement the above logic.
The default message for Reward Points shown on the Payment step of the checkout can be changed as shown below:
<?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’)); ?>
Conclusion
Even though my approach was not the best, still it strikes the right balances between “do it on time and do it stable”. I hope that this post gave you an idea of how Magento EE uses the reward point’s functionality.