<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1114119085333160&amp;ev=PageView&amp;noscript=1">

rewards.jpg

For all the features and benefits with using Magento Enterprise, there will always be some quirks where you may think to yourself; ‘this doesn't work how it should’. 

Recently during our quality assurance step for a client's website, we came across a minor bug with Magento EE rewards points. Users who have subscribed to the newsletter would still  visually see on the frontend 'Subscribe to our newsletter now and earn x Reward points'. Nothing groundbreaking, but a small gripe none the less. 

screen_shot_2015-06-30_at_13.50.59.png

If you take a look at the enterprise layout reward.xml you will see this message is defined here. Unfortunately we cannot remove it based on whether the user has already subscribed once.

rewards.xml for newsletter 

enterprise_reward/action_newsletter reward-newsletter Subscribe to our newsletter now and earn %s. 

tooltip.phtml template 

In rewards.xml you can see that most, if not all rewards messages use this template to render the content. 

<code class="language-php">&lt;?php if ($this-&gt;hasRewardMessage()):?&gt;

&lt;?php echo $this-&gt;__($this-&gt;getRewardMessage(), Mage::helper('enterprise_reward')-&gt;formatReward($this-&gt;getRewardPoints(), $this-&gt;getRewardAmount(), null, '%s'))?&gt;

&lt;?php endif;?&gt;</code>

Solution 

Originally I had created a new action method assigning a helper method to check for the subscribed email existing and adding this check by overriding the _prepareTemplateData() method for the Enterprise_Reward_Block_Tooltip class.  If the action method was defined and returning 1, it would change all reward messages to blank. 

Although not a bad idea, as you would be able to hide any rewards message based on some conditional check, I changed it to overriding the tooltip.phtml template instead, adding the subscribe check because of the pure fact I was editing a core method. Ben Marks would probably call the Magento police if I left it as is. 

What we need to do first is create a helper method to test if the customer has ever subscribed to the newsletter. If the user has subscribed, you will be able to see their email in the database table 'newsletter_subscriber'.

Create a folder structure and file like the one listed below:

- app
  - code
    - local
      - Cti
       - RewardExtended
         - etc
           - config.xml
         - Helper
           - Data.php

 

In the helper Data.php file copy and paste the following:

<code>&lt;?php
class Cti_RewardExtended_Helper_Data extends Mage_Core_Helper_Data
{
    // add a helper method for toggling newsletter message is user has subscribed once
    public function isSubscribed() {
        $_email = Mage::getSingleton('customer/session')-&gt;getCustomer()-&gt;getData('email');
        $_subscribedEmail = Mage::getModel('newsletter/subscriber')-&gt;loadByEmail($_email, 'subscriber_email');

        if( $_subscribedEmail-&gt;getId() &amp;&amp; !empty($_email)) {
            $isSubscribed =  1;
            return $isSubscribed;
        }

    }
}</code>

What we are doing here is checking if the customer email exists and seeing if that email is in the subscriber list.

In config.xml copy and paste the following:

<code>&lt;?xml version="1.0"?&gt;
&lt;config&gt;
    &lt;modules&gt;
        &lt;Cti_RewardExtended&gt;
            &lt;version&gt;1.0.0&lt;/version&gt;
        &lt;/Cti_RewardExtended&gt;
    &lt;/modules&gt;
    &lt;global&gt;
        &lt;helpers&gt;
            &lt;cti_rewardextended&gt;
                &lt;class&gt;Cti_RewardExtended_Helper&lt;/class&gt;
            &lt;/cti_rewardextended&gt;
        &lt;/helpers&gt;
    &lt;/global&gt;
&lt;/config&gt;</code>

Now in your theme folder add a directory in template/reward called 'tooltip-newsletter.phtml'.

The path I will be adding to is 'app/design/frontend/cti/theme/rewards/tooltip-newsletter.phtml’.

Copy and paste the following code in this file:

<code>&lt;?php
/**
 * @see Enterprise_Reward_Block_Tooltip
 */
$_subscribed = Mage::helper('cti_rewardextended/data')-&gt;isSubscribed();
?&gt;
&lt;div class="reward-message &lt;?php echo $this-&gt;getWrapperClass()?&gt;"&gt;
    &lt;div class="reward"&gt;
    &lt;?php if ($this-&gt;hasRewardMessage()):?&gt;
        &lt;?php if(empty($_subscribed)):?&gt;
            &lt;p&gt;&lt;?php echo $this-&gt;__($this-&gt;getRewardMessage(), Mage::helper('enterprise_reward')-&gt;formatReward($this-&gt;getRewardPoints(), $this-&gt;getRewardAmount(), null, '&lt;strong&gt;%s&lt;/strong&gt;'))?&gt;&lt;/p&gt;
        &lt;?php else:?&gt;
            &lt;p&gt;&lt;?php echo $this-&gt;__($this-&gt;getRewardAmount(), null, '&lt;strong&gt;%s&lt;/strong&gt;')?&gt;&lt;/p&gt;
        &lt;?php endif;?&gt;
    &lt;?php endif;?&gt;
    &lt;?php if ($this-&gt;hasPointsBalance() &amp;&amp; !$this-&gt;hasHideBalance()):?&gt;
    &lt;p class="balance"&gt;
        &lt;?php echo $this-&gt;__('Your current balance is %s.', Mage::helper('enterprise_reward')-&gt;formatReward($this-&gt;getPointsBalance(), null, null, '&lt;strong&gt;%s&lt;/strong&gt;'))?&gt;
    &lt;/p&gt;
    &lt;?php endif;?&gt;
    &lt;?php if (!$this-&gt;hasHideLink()):?&gt;
        &lt;p class="a-more"&gt;&lt;?php echo $this-&gt;renderLearnMoreLink()?&gt;&lt;/p&gt;
    &lt;?php endif;?&gt;
    &lt;?php if ($this-&gt;hasQtyLimit() &amp;&amp; $this-&gt;hasRewardQtyLimitationMessage()):?&gt;
        &lt;p class="limit"&gt;&lt;?php echo $this-&gt;__($this-&gt;getRewardQtyLimitationMessage(), "&lt;strong&gt;{$this-&gt;getQtyLimit()}&lt;/strong&gt;")?&gt;&lt;/p&gt;
    &lt;?php endif;?&gt;
    &lt;?php if ($this-&gt;hasGuestNote()):?&gt;
        &lt;p class="limit"&gt;&lt;?php echo $this-&gt;__($this-&gt;getGuestNote())?&gt;&lt;/p&gt;
    &lt;?php endif;?&gt;
    &lt;/div&gt;
&lt;/div&gt;</code>

Look between line 9 to 15 to see where the magic happens. With this new helper method, we check to see if $_subscribed is equal to something and if it is, remove the reward message.

All we need to do now, is add a 'setTemplate' call to your local.xml theme file or layout module. For simplicity we will add it in local.xml. Copy and paste the following in your theme local.xml file:

<code>&lt;newsletter_manage_index&gt;
  &lt;reference name="reward.tooltip.newsletter"&gt;
    &lt;action method="setTemplate"&gt;
      &lt;template&gt;reward/tooltip-newsletter.phtml&lt;/template&gt;
    &lt;/action&gt;
  &lt;/reference&gt;
&lt;/newsletter_manage_index&gt;</code>

Now sit back, refresh the page and see that the reward points for subscribers is now gone for customers who have already signed up once. 

I hope you have found this post useful and please feel free to comment.

Note: This post provides a temporary fix until Magento looks at addressing this issue.

About the author

Ian Cassidy
Ian Cassidy
Find me on:
As the head of the department Ian is responsible for ensuring client projects are planned to meet your requirements, architected and delivered to the highest standards. Ian has been working with Magento since its first release in 2007. During that time he has helped countless businesses transition to the platform and is well versed when it comes to the technical challenges faced with large scale commerce applications.

Get the latest content directly to your inbox

SUBSCRIBE

Recent posts