I am having an strange problem i have attached new product at home page by calling the block template at home page under CMS->page->home but when click on add to cart button it will redirect to www.example.com/checkout/cart but show's the message cart is empty. but when i go to any category and try to add product from there. It will work properly and after that when i again click on add to cart of home page it workes. The file called new.phtml which i am using to call the block has the following code

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class="page-title category-title">
        <h1><?php echo $this->__('New Products') ?></h1>
<?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_products->getItems() as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid row">
        <?php endif ?>
            <li class="item col-xs-3<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <div class="product-container">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(188) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                <div class="product-shop">
                    <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_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; ?>
                        <button type="button" title="<?php echo $this->__('Details') ?>" class="button btn-details" onclick="setLocation('<?php echo $_product->getProductUrl() ?>')"><span><span><?php echo $this->__('Details') ?></span></span></button>
                        <!-- <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> -->
                <?php $_product = Mage::getModel('catalog/product')->load($_product->getId()); ?>
                <div class="label-product">             
                    <?php if($_product->getData('new')){echo '<span class="new">'.$this->__('New').'</span>';  }?>
                    <?php if($_product->getData('sale')){echo '<span class="sale">'.$this->__('Sale').'</span>';  }?>
                <div class="clear"></div>
        <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
        <?php endif ?>
    <?php endforeach; ?>
<?php endif; ?>

so can any one help me were i am wrong my website is http://www.royalcandycompany.com/

  • jquery conflict issue solve first then check ajax return value for conformation popup. Commented Dec 4, 2014 at 12:54

1 Answer 1


Please try using the below code for "Add to Cart" button.

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_product) ?>', true)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

The above code has been tested and it worked for me on my home page.

Let me know if you find any issues with the above code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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