Code for adding addtocart button and quantity box at the category list page in Magento 1 - Magesan

Code for adding addtocart button and quantity box at the category list page in Magento 1

Code for adding addtocart button and quantity box at the category list page in Magento 1

Open list.phtml and any other related on which you want to display the addtocart button and quantity box.

<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>" <?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
  <?php if($_product->isSaleable()) : ?>
    <div class="category-addtocart">
      <div class="qty-box">
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="<?php echo $product_id ?>" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
      </div>
      <div class="add-to-cart-buttons">
        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-success btn-block btn-lg" onclick="product_addtocart_submit('<?php echo $_product->getId() ?>')" ><i class="fa fa-shopping-cart"></i><?php echo $this->__('Add to Cart') ?></button>
      </div>
    </div>
  <?php else: ?>
    <span class="label label-danger availability out-of-stock">
      <?php echo $this->__('Out of stock') ?>
    </span>
  <?php endif; ?>
</form>

<script type="text/javascript">
  function product_addtocart_submit(pid) {
    var productAddToCartForm = new VarienForm('product_addtocart_form_'+pid); 
    ajaxcart.ajaxCartSubmit(productAddToCartForm);  
    return false;
  }
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>