Quantcast
Viewing latest article 8
Browse Latest Browse All 15

How to Get Magento’s Email To A Friend URL

In the context of ever needing to get the “send an email to friend” url / link mark up from Magento in other scopes other than view.phtml (say a custom pthml file with layout specific needs that can be configured), here is what you do.

First we need to get our helpers / model / product like so:

<?php
    $_product = Mage::registry('current_product');
    $_helper = Mage::helper('catalog/product');
    $_this = Mage::registry('send_to_friend_model');
?>

Lastly we need to build up our markup with our above helpers / model and product. (Note very similar to how /app/design/frontend/YOUR SITE/YOUR THEME/templates/catelog/product/view.phtml build this link).

<?php if($_this->canEmailToFriend()): ?>
<a href="<?php echo $_helper->getEmailToFriendUrl($_product); ?>"><?php echo $_this->__('Email this page to a Friend'); ?></a>
<php endif; ?>

Note how we use $_this to test if we can display an email link so that we still have admin backend control over this. Also note we are passing $_product t the $_helper object’s getEmailToFriendUrl function; this give us our desired url for our href attribute. Optional target=”_blank” attribute can be added to the link to open in a new page if you like.


Viewing latest article 8
Browse Latest Browse All 15

Trending Articles