0

I need to add compare and wishlist link in to the 1column.phtml file. I added this code in this page but nothing show!!!

app/design/frontend/default/celebrity/template/page/1column.phtml

For compare link:

<?php $_product = $this->getProduct(); ?>
            <?php if ($_compareUrl = $this->getAddToCompareUrl($_product)): ?>
                <span><a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></span>                
<?php endif; ?> 

For wishlist link:

<?php if ($this->helper('wishlist')->isAllow()) : ?>
    <a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
<?php endif; ?>

How can I fix this problem?

0

It is because those functions do not exist on that block. The functions however just reference helpers so as long as the call to ->getProduct() is correct and returning a Mage_Catalog_Model_Product object you can do the following. Change...

$this->getAddToCompareUrl($_product)

to

Mage::helper('catalog/product_compare')->getAddUrl($_product)

and

$this->getAddToWishlistUrl($_product)

to

Mage::helper('wishlist')->getAddUrl($_product)

Edit

Although i am still unsure as to why you are adding these to the 1column.phtml, by doing that you will need to change how you get the current product with;

$_product = Mage::registry('current_product');
if ($_product) {
    // put links in here
}

Magento out the box will give you add to compare / wishlist ability on listing and details pages.

4
  • I change these lines but when I clear the cache, the page is empty and nothing in it! – Elham Gdz Sep 5 '15 at 9:40
  • That is likely because there is no actual product available (the ->getProduct() is failing) again because no product has been set. How are you deciding what product you want to show these links for? – Smartie Sep 5 '15 at 9:43
  • I want to add these links show in all products page that customer can do compare and add product to wishlist. And also I should add these links in 1column.phtml. – Elham Gdz Sep 5 '15 at 10:23
  • I want these links work for all type of product. I just add these lines, what should I do that these links work? – Elham Gdz Sep 5 '15 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.