5

I have turned off the option to redirect to the cart after a product has been added. Instead, it just redirects back to the page it was originally on.

Is there a way to tell if something was just added? I would love to learn that there is a pretty simple if statement for this!

  • No there is not, but you can hook into any of the events and mark the product. If you use an attribute which is not saved, it is blown away with the next request – Fabian Blechschmidt Mar 29 '13 at 0:21
  • Shouldn't there be a notice that appears after a product is added to the cart? – pspahn Mar 29 '13 at 19:56
14

It's not a single call statement, but here is how you can do it:

  1. Setup an observer to listen to the checkout_cart_add_product_complete and set a flag on the core/session object:

    Mage::getSingleton('core/session')->setProductAddedToCartFlag(true);
    
  2. When you are redirected back to the product page, you'll now have a flag set on the session object. You can retrieve this flag like so:

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

Passing true to the getter method here (as shown above) clears the flag so it will no longer exist on the session, meaning it is only present on the first request immediately following the add to cart action was fired.

  • Thanks for this. I'm no developer and I'm still learning Magento, so I just ended up using javascript to do it if the message was present on the page. – kel Mar 29 '13 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.