Since I updated our version of Magento to 1.9 every time I click the Add to Card button on the category view page I get redirected to the empty shopping cart. What have we done wrong while updating?
The best way to upgrade your custom theme is to look at the same template file in
base/default - with a bit of knowledge on what to look for.
I'm assuming you upgraded from before 1.7.x or lower and are now facing the form key issue. That means you're looking for any code that puts a form key in your template files.
The templates affected are:
Look for the string Nasir posted.
On all other pages, the template doesn't matter. It uses various calls to standard URL objects and finally incorporates the method
Mage_Core_Model_Session::getFormKey() into the URL.
Various stores I've seen have a local copy of Mage_Core_Model_Session for various reasons in
app/codel/local/Mage/Core/Model/Session.php which is missed when upgrading. Check if this file is present and if it contains the method
getFormKey() and compare that to the code in
The reason the absence of this method doesn't break your site is because any method not defined that starts with get (or set, or has or uns), is routed to
__call() and implemented as a getter (or setter or hasAttribute or unsetter) for data contained on the object it is operating on. If no such data can be found it simple returns null, meaning no formkey is set.
This then breaks code in
Mage_Core_Controller_Varien_Action.php::_validateFormKey(), which verifies if a form key is passed to the page and if so it matches the form key set on the user session.
Well I think you have problem in your product list page, wherein you're not getting a product's addtocart url properly, or url params aren't passed properly in the generated addtocart url of products.
Assuming you still have an object like
$_product from loop (
foreach($collection as $_product)), available, use it to load the product anywhere in page before the
foreach loop I described ends, just like:
$product = Mage::getModel('catalog/product')->load($_product->getId());
Then get the it's
addtocart url as following:
$productCartUrl = Mage::helper('checkout/cart')->getAddUrl($product);
and finally replace the addtocart button which isn't working proper with below:
<?php if($_product->isSaleable()): ?> <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $productCartUrl ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button> <?php else: ?> <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> <?php endif; ?>
Hope this helps you resolve your issue.