0

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>
</div>
<?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> -->
                    </div>
                </div>
                <?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>
                <div class="clear"></div>
                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
        </ul>
        <?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. – ravi patel Dec 4 '14 at 12:54
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.

Thanks.

0

You need to check the getAddToCartUrl function. I see the format of uenc in the add to cart url is different between homepage and category page:

on Homepage: setLocation('http://www.royalcandycompany.com/checkout/cart/add/uenc/aHR0cDovL3d3dy5yb3lhbGNhbmR5Y29tcGFueS5jb20v/product/2823/form_key/ST8YmCGhMm6JbKWT/')

on category Page: setLocation('http://www.royalcandycompany.com/checkout/cart/add/uenc/aHR0cDovL3d3dy5yb3lhbGNhbmR5Y29tcGFueS5jb20vYnJhbmRzL2NhbmR5LWR5bmFtaWNzLw,,/product/2172/form_key/boEQHpU1MYApiFrv/')

Moreover, I see an error on home page, I have no idea why you need to include the opchecckout js on homepage?:

Uncaught ReferenceError: Billing is not definedopcheckout-override.js:4

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.