简体   繁体   中英

Magento Add to cart button issue after upgrade 1.5 to 1.9

I just upgrade Magento 1.5 to 1.9 and I have a small issue, in the shopping cart I add some products, in my store this are free gifts, each of this products have Add to cart button, but I don't know why in Magento 1.9 this button is not work:

    <button class="button btn-cart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$giftPro->getId(),'qty'=>1)) ?>')">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
    </button>

and the url in this button is:

http://mystore.com/checkout/cart/add/product/1444/qty/1/

If i press on add to cart the page is only refreshing, but the product is not add to cart. How I need to do this button to work in the 1.9 version?

Thank you

I found a solution I use something like this:

<button class="button btn-cart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$giftPro->getId(),'qty'=>1, 'form_key' => Mage::getSingleton('core/session')->getFormKey())) ?>')">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>

After some research I found that for 1.9 we need to add 'form_key' => Mage::getSingleton('core/session')->getFormKey()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM