Magento Themes and Magento Extensions

Magento – Share compare product page on facebook to get review from your friends


Here I want to address one thing to you all it’s regarding to the compare product in magento. we all knows magento provides us an compare product functionality as a customer point of view while comparing some products we always have some questions, doubts about that products now it could be better to ask the review to your friends on facebook by sharing your compare product page.

As per developer point of view how to do that? Very Simple

Step 1: You have to override one function which is present in app/code/core/Mage/Catalog/controllers/Product/CompateController.php i.e. function indexAction()
and add the below line of code after $items = $this->getRequest()->getParam(‘items’);



Now Your function will look like below


public function indexAction()
        $items = $this->getRequest()->getParam('items');

        // Added code for Facebook share

        if ($beforeUrl = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED))
       {        Mage::getSingleton('catalog/session')

        if ($items) {
            $items = explode(',', $items);
            $list = Mage::getSingleton('catalog/product_compare_list');


Step 2: Now go to app/design/frontend/default/your_template/template/catalog/product/compare/list.phtml and add below code where you want to show the facebook share button

<div data-href="<?php echo Mage::getBaseUrl().'catalog/product_compare/index/'.Mage::getSingleton('catalog/session')->getCompareUrlParams();?>" data-type="button_count"></div>

Step 3: Now last step is to add javascript method which require to work share button add below step at the bottom of the list.phtml page.

<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); = id;
  js.src = "//";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

Comments are closed.