0

I Have a form with two button

  1. Add to Cart -> Product Added to the cart and it reload the same page

  2. Buy Now --> Product Added to the cart and it should redirect to shopping cart page.

This is the code:

<form action="<?php echo Mage::helper('checkout/cart')->getAddUrl(Mage::registry('current_product'));?>" method="post" id="seller_addtocart_form1" class="ma">
    <input type="hidden" name="return_url" value="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>" />
    <input type="hidden" value="<?php echo $seller->getMpassignproductId(); ?>" name="mpassignproduct_id" class="mpassignproduct_id"/>
    <button id="<?php echo $seller->getMpassignproductId() ?>"
            class="button btn-cart customaddtocart"
            title="<?php echo $this->__('Add to Cart')?>"
            onclick="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>">
        <span><span><?php echo $this->__('Add to Bag')?></span></span>
    </button>
    <div>
        <button class="button buy-now" onclick="location.href ='{{config path="web/secure/base_url"}}/checkout/cart/add?product=1&qty=1'">
            <span><span>Buy Now</span></span>
        </button>
    </div>
</form>

Both are redirect to same page it self. What mistake I have done?

0

Keep buy now button out side the form because button has own location href and addtocart link.

<form action="<?php echo Mage::helper('checkout/cart')->getAddUrl(Mage::registry('current_product'));?>" method="post" id="seller_addtocart_form1" class="ma">
    <input type="hidden" name="return_url" value="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>" />
    <input type="hidden" value="<?php echo $seller->getMpassignproductId(); ?>" name="mpassignproduct_id" class="mpassignproduct_id"/>
    <button id="<?php echo $seller->getMpassignproductId() ?>"
            class="button btn-cart customaddtocart"
            title="<?php echo $this->__('Add to Cart')?>"
            onclick="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>">
        <span><span><?php echo $this->__('Add to Bag')?></span></span>
    </button>
</form>
<div>
   <button class="button buy-now" onclick="location.href='location.href='{{config path="web/secure/base_url"}}/checkout/cart/add?product=1&qty=1'"> <span><span>Buy Now</span></span></button>
</div>
  • Where i have to add after form – Magento 2 Nov 4 '15 at 10:29
  • updated my answer – Akhilesh Patel Nov 4 '15 at 11:30
  • No it's not working not even to click also – Magento 2 Nov 4 '15 at 11:44
  • what error is showing ? and inspect that buy now div and paste that code here. – Akhilesh Patel Nov 4 '15 at 11:53

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.