Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Why isn’t the quote id available in checkout_cart_add_product_complete the first time something is added to cart
 
crashrox
Jr. Member
 
Total Posts:  6
Joined:  2013-04-01
 

It seems like checkout_cart_add_product_complete or checkout_cart_product_add_after would be triggered after an item was added to cart. But when the first item is added to the cart the quote id is null. Subsequent additions to the cart make the quote id available. Is there a better event to observer which occurs after the data has been written?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

checkout_cart_save_after would be better
quote is not saved yet after ‘checkout_cart_add_product_complete’, so quote id is NULL, but when you add to cart again you are using a previously saved quote

 
Magento Community Magento Community
Magento Community
Magento Community
 
crashrox
Jr. Member
 
Total Posts:  6
Joined:  2013-04-01
 

Thanks for the quick response. Easy to get a list of all the items in the cart. But is there a way to identify the specific item that was added in checkout_cart_save_after?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

then try checkout_cart_product_add_after

 
Magento Community Magento Community
Magento Community
Magento Community
 
crashrox
Jr. Member
 
Total Posts:  6
Joined:  2013-04-01
 

I tried to latch on to checkout_cart_update_items_before with the idea of saving all the current cart items and their qty in the registry and then in checkout_cart_save_after do a comparison to figure out what changed. Unfortunately the Quote object has already been modified at that point. Can’t seem to find anything prior to the quote being changes that I can get a snapshot of cart from.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crashrox
Jr. Member
 
Total Posts:  6
Joined:  2013-04-01
 

Interestingly my code actually works, but for some reason checkout_cart_save_after gets fired twice. It seems like its happening in a redirect because my registry entry is missing by the time checkout_cart_save_after is fired for the second time. Weird.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top