1

we are displaying Product name & Add to cart button in Custom tab under My Account . we wanted to add the product to cart once we click on "Add to cart", but button is not clickable, once if we click on button , its not adding product to cart.

<?php $collections = $this->getCollection(); ?>

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = Mage::helper('core')->quoteEscape($this->__('Add to Cart')); ?>

<?php foreach ($collections as $key => $product) {

    echo $product->getName().' <br>';
?>

<div class="add-to-cart-buttons">

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)">
<span><span>
<?php echo $buttonTitle ?>
</span></span>
</button>

<?php echo $this->getChildHtml('', true, true) ?>

</div>
<hr style='display:inline-block; width:100%;'>
<?php 

}
?>

enter image description here

1 Answer 1

1

Try Below code

<form action="<?php echo  Mage::helper('checkout/cart')->getAddUrl($product);?>" method="post">     
<div class="add-to-cart-buttons">

<button type="submit" title="<?php echo $buttonTitle ?>" class="button btn-cart" >
    <span><span>
    <?php echo $buttonTitle ?>
    </span></span>
</button>

<?php echo $this->getChildHtml('', true, true) ?>

</div>
</form>
5
  • updated code, but now only first product name is displaying and no Add to cart buttons displaying as here : prnt.sc/eklgw7 Mar 16, 2017 at 9:14
  • please check full code : pastebin.com/heYFAqaS Mar 16, 2017 at 9:15
  • @BabyinMagento updated my code I replace $product instead of $_product in form action Mar 16, 2017 at 9:16
  • oh sorry, now it worked like a charm , Thanks for your continous support...... Mar 16, 2017 at 9:20
  • @BabyinMagento You are always Welcome :) Mar 16, 2017 at 9:21

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.