Magento – Form Key issues on new magento version

form-keymagento-1.7

As we know that Form key feature has been added to new versions of Magento. This affects old themes or modules for adding product to cart, wishlist and placing an order. I faced a situation where a third party module for Brands, users were not able to add the products to cart nor to wishlist. On troubleshooting, I found that, the form key used by the brands module was different than of the normal product listing pages and I also found that the form key used for one category page remains the same for other category pages as well, so its seems it doesn't update for a particular session i guess and our module should has to follow the same.

however, I wrote a piece of code to update form key, in the add to cart url, with valid one using events and hence products were successfully added to cart and wishlist.

My question is:

Is there a general way developed/allowed by the Magento team, so that such third party modules, which are developed to list the products on some basis, are simply forced to follow the valid form key which is used by the default product listings instead of generating a new one?

Edit: The key returned by Mage::getSingleton('core/session')->getFormKey(); for custom product listing is not valid for adding the product to wishlist or cart.

Best Answer

Need to change the third party module or override the main module because formkey is the key aspect by which any item goes into cart. get it from session and update where third party extension got it.

Mage::getSingleton('core/session')->getFormKey();