简体   繁体   中英

Magento - add to cart on category page not working

After upgrading Magento 1.7.0 to 1.8.0 (or 1.8.1.0. for that matter) I've noticed that the add to cart function on the product details page and the categorie overview page were no longer working. When clicking on the add to cart button the cart is loading properly but is stating: "You have no items in your shopping cart."

Because this function is rather important for a webshop we took this problem very seriously.

While searching for an answer I've noticed that the problem could be related to formkeys. To solve the problem with the product details page we added a line of PHP-code to yourtemplate/template/catalog/product/view.phtml right after the form opening tag.

After line (42):

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>:

Add:

<?php echo $this->getBlockHtml('formkey'); ?>

After solving this there only remains two questions.

  1. The add to cart buttons on the categorie pages are still not working. How can we fix this?
  2. How does it come that upgrading to Magento 1.8.0 or 1.8.1.0. is producing this kind of errors? Does any one else know what this problem is? Even the base/default theme is having this problem.

Try the following code in the place of your 'Add to cart' button.

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

i have used this code but it is not working in magento version 1.9.2.x ..need help to fixed this issues....

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