سؤال

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!

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top