I need add to cart functionality on product listing page.

On the product list page I have size and quantity box and add to cart is directly placed on the shopping cart page.

Currently it redirects on the product view page.

Magento version is 1.9

Kindly help.

1 Answer 1

  <div class="product_btn">
       <div class="add-to-cart">
          <div class="add-to-cart-buttons">
             <?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
             <p class="action"><button type="button" title="<?php echo $this->quoteEscape($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></p>
             <?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
             <p class="action"><a title="<?php echo $this->quoteEscape($this->__('View Details')) ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a></p>
             <?php else: ?>
             <p class="action availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
             <?php endif; ?>
          <!-- Closed div add-to-cart-buttons -->
       </div><!-- Closed div add-to-cart -->
    </div><!-- Closed div product_btn -->

Try this. It worked for me perfectly. Paste the code into your list page.

Hope it will work for you also.

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.