1

This is the list.phtml where I display the newest products on homepage.

<?php

$collection = $this->getProductCollection(); 
$_collectionSize = count($collection);
$_columnCount = $this->getColumnCount();

?>

<div class="sama_productblocks_grid">
    <h3 class="divider-h3"><?php echo $this->getTitle();?></h3>

    <div class="sama_productblocks_descrition"><?php echo $this->getDescription();?></div>

    <?php $i=0; foreach ($collection as $item): ?>

    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid column-<?php echo $_columnCount;?> newest-products-list">
    <?php endif;?>

        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
            <a href="<?php echo $item['url']?>" title="<?php echo $item['name']?>" class="product-image">
                <img src="<?php echo $item['image']?>" width="<?php echo $this->getThumbnailWidth();?>" alt="<?php echo $item['name']?>">
            </a>
            <h2 class="product-name">
                <a href="<?php echo $item['url']?>" title="<?php echo $item['name']?>"><?php echo $item['name']?></a>
            </h2>

            <div class="price-box">
                <p class="regular-price">
                    <?php echo Mage::helper('core')->currency($item['finalprice'], true, false);?>
                </p>
            </div>
            <div class="add-to-cart-main">
                <a href = "<?php echo $item['url']?>" class="add-to-cart">
                    <div class="cart-elements">
                        <span class='add-to-cart-img fa fa-arrow-right'></span>
                        <span class='add-to-cart-text'><?php echo $this->__('View details');?></span>
                    </div>
                </a>
                <a href = "#Ineed here a wishlist url"  class="wishlist fa fa-heart-o" > 
                </a>

            </div>
        </li>

    <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
    <?php endif ?>

    <?php endforeach; ?>

</ul>
</div>

I tried to introduce this piece of code to get the wishlist url:

<?php echo $this->getChildHtml('addto') ?>

but with no result. So how do I get a wishlist button ? or a wishlist url where I typed "I need a wishlist url" ? on the homepage. Thx in advance

This is the getProductCollection function:

public function getProductCollection()
    {
        $useCache = Mage::app()->useCache('SAMA_PRODUCTBLOCKS');
        $cacheData = Mage::app()->loadCache($this->getCacheTags());

        if ((empty($cacheData) && $useCache) || !$useCache) {
            $productCollection = $this->_currentList->getSelectedProductsCollection();

            $collection = array();

            foreach ($productCollection as $product) {
                $product = Mage::getModel('catalog/product')->load($product->getId());
                $collection[] = array(
                    'name' => $product->getName(),
                    'image' => (string)$this->helper('catalog/image')->init($product, 'small_image')->resize(max(100, (int)$this->_currentList->getThumbnailWidth())),
                    'url' => $product->getProductUrl(),
                    'price' => $product->getPrice(),
                    'finalprice' => $product->getFinalPrice(),
                    'sku'       => $product->getId(),
                    'qty'       => $product->getIsInStock()
                );
            }

            Mage::app()->saveCache(json_encode($collection), $this->getCacheTags(), array($this->getCacheTags()));
        } else {
            $collection = json_decode($cacheData, true);
        }

        return $collection;
    }
3

Replace #Ineed here a wishlist url with

 <?php echo $this->helper('wishlist')->getAddUrl($item) ?>

[EDIT]
Also you don't need to loop through the collection and load each product separately, then generate an array from them. It's a real performance killer.

you can replace this;

        foreach ($productCollection as $product) {
            $product = Mage::getModel('catalog/product')->load($product->getId());
            $collection[] = array(
                'name' => $product->getName(),
                'image' => (string)$this->helper('catalog/image')->init($product, 'small_image')->resize(max(100, (int)$this->_currentList->getThumbnailWidth())),
                'url' => $product->getProductUrl(),
                'price' => $product->getPrice(),
                'finalprice' => $product->getFinalPrice(),
                'sku'       => $product->getId(),
                'qty'       => $product->getIsInStock()
            );
        }

        Mage::app()->saveCache(json_encode($collection), $this->getCacheTags(), array($this->getCacheTags()));

with this:

         Mage::app()->saveCache(json_encode($collection->toArray()), $this->getCacheTags(), array($this->getCacheTags()));
  • This is the website: latesthoes.mediaswitch.ro . If you check the newest product , there will be a heart image. I put the code as you suggested, but it displays the only the base url. – Attila Naghi Aug 12 '15 at 6:40
  • I guess he doesn't know about $_product.What should it be the $_product ? a collection or the sku ? – Attila Naghi Aug 12 '15 at 6:44
  • Yep. sorry. It should have been $item instead of $_product. I edited my answer. – Marius Aug 12 '15 at 6:45
  • It is also the same , I checked with firebug and the href is empty. any idea ? – Attila Naghi Aug 12 '15 at 6:48
  • See my new edit. It's empty because $item in your case is an array and it should be an instance of Mage_Catalog_Model_Product – Marius Aug 12 '15 at 6:49

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.