Magento – I can’t add to cart the first time

addtocartcartmagento-1.9

I am trying fix bug with Add to cart. I have 3 stores – Production, QA and local versions.

When I press add to cart from list or product pages it load empty cart. If I try add the same product second time, it show me shopping cart with this product. This bug only on Production and QA versions, but this is no error on my local PC. Also I deployed this store on my hosting. And there is no bug too.

I think problem with hosting where located Production and QA stores.
Have You any ideas or experience with this bug? Thanks.

Store

Best Answer

There could be two reasons for this:

1) In the past, whenever you would visit the Magento URL "checkout/cart/add" to automatically add something to cart, the Magento session was not initialized properly. Within MageBridge, the Add To Cart Menu-Item therefore performs a little trick, that first visits a temporary page simply to initialize the Magento session and then redirects to the Magento add-to-cart URL and then redirects to the cart (or whatever redirect you have configured here). This only is an issue in the browser if the browser has no Magento cookie set - so most likely this issue can be replayed by flushing all Joomla / MageBridge / Magento cookies from the browser. However, I don't know if this is really the cause of issues, because it works in fine in all 6 testing sites I've just tested this in.

2) In Magento 1.9, the secret form key (which has already been in some forms for some time) was implemented in numerous other forms. Without the proper form key sent in the POST request, the POST request simply fails and redirects to some other default URL. This also happened for the add-to-cart URL, which means that all Magento URLs with "checkout/cart/add" also need to have an additional parameter "form_key/XXX" in it. With a Magento page, this link is automatically generated. But if you have a link in a newsletter (or a Joomla page that is not loading Magento yet), this fails. For this specific condition, there is the MageBridge option to disable the Magento form key entirely, but this will also drop security on other forms. Instead, I will build a new feature that automatically fixes this for the add-to-cart URL specifically. This will be implemented in the next MageBridge build (today).

I hope this will help you.

Related Topic