1
votes

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.
1
You added the formkey to the category page, too? I think in the default theme there are no buttons on category pages.Simon H

1 Answers

3
votes

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....