0
votes

I'm on Magento 1.9 and i'm display "new products" on my home page, but i cannot get the "Add to Compare" link to appear for each new product. Below is the XML i have at CMS > Pages > Home page > Design tab

<reference name="content">
<block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml" after="cms_page">
<action method="addPriceBlockType"><type>bundle</type><block>bundle/catalog_product_price</block><template>bundle/catalog/product/price.phtml</template></action>
<action method="setColumnCount"><columns>5</columns></action>
<action method="setProductsCount"><count>10</count></action> 
</block>
</reference>

This is the new.phtml that I have in my custom theme folder. under customtheme\warecompare\default\template\catalog\product. As you can see, there is some code there to display "Add to Compare" links.

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<h2 class="subtitle"><?php echo $this->__('New Products') ?></h2>
<?php $_columnCount = $this->getColumnCount(); ?>
    <ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col">
    <?php $i=0; foreach ($_products->getItems() as $_product): ?>
        <?php /*if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif*/ ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_product->getName()) ?>" class="product-image">
                    <?php $_imgSize = 260; ?>
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                </a>
                <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_product->getName()) ?>"><?php echo $this->escapeHtml($_product->getName()) ?></a></h3>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php echo $this->getPriceHtml($_product, true, '-new') ?>
                <div class="actions">
                    <?php if($_product->isSaleable()): ?>
                        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if ($_compareUrl = $this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </li>
        <?php /*if ($i%$_columnCount==0 || $i==count($_products)): ?>
        </ul>
        <?php endif*/ ?>
    <?php endforeach; ?>
    </ul>
<?php endif; ?>

Despite all the code above, all that displays on the new products block is (1) an image of the product (2) Price of the product (3) Nothing else.

Is it because the block type catalog/product_new does not support the getAddToCompareUrl and other methods above? I am also trying to find the source / class file that corresponds to the block type catalog/product_new but i don't know how it is derived and where to find it.

Please help.

Thanks Kevin

1
sometimes $_products->getItems() only returns a subset of the products data. It might be that you need to load the full product in the foreach ($_products->getItems() as $_product): loop. Like so: $_fullProduct = Mage::getModel('catalog/product')->load($_product->getId())sulman
This could very well have been the answer but i found the actual problem, the default template css was hiding the actions div on my homepageaDvo

1 Answers

0
votes

@sulman thanks for your input. Your answer could very well have been the answer but i found the actual problem, the default template css was hiding the actions div on my homepage