1

Would it be possible to automatically empty Magento cart if someone abandoned the cart? Basically we do not want customers to have the previous cart items stay in cart once they left the site or logout from the site.

1 Answer 1

0

You have to clear the cart at the time of logout. And for this you have to write a custom module that will have observe customer_logout event and execute the following code

<global>
    <events>
      <customer_logout> 
         <observers>
          <customer_logout_handler> 
            <type>model</type> 
            <class>modulename/observer</class> 
            <method>clearCartAtLogout</method>  
          </customer_logout_handler>
        </observers>
      </customer_logout>
    </events>
  </global>

foreach(Mage::getSingleton("checkout/session")->getQuote()->getItemsCollection) as $item ){ Mage::getSingleton("checkout/cart")->removeItem( $item->getId() )->save(); }

And for guest user you can use this setting : Admin => system => Configuration => Sales => Checkout => Quote Lifetime (days)

2
  • we already did created module for customers but there is no easy way for guest, If we define the quote lifetime (Days) , it will still keep the cart items for that many days in session, Even if we set the minimum 1 days , it will not clear the cat items immediately. Commented Aug 16, 2016 at 8:07
  • You have to create septate script/cron file and in that you have to load all the quote which are not converted in order and check the quote creation date. If that date is before 30* Min then you can delete that quote . Also set this file in cron to run every 30* Min. Or whatever time you want. Commented Aug 16, 2016 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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