PHP Magento Tips

How to Remove Products from Cart after Customer Logged Out in Magento

Rate this posting:
{[['']]}

to remove items from cart after customer logout, we have to create customer_logout event and its observer.

Step 1:

in /app/etc/modules/Mycompany_Cleancart.xml add below code:

<?xml version="1.0"?>
<config>
  <modules>
    <Mycompany_Cleancart>
      <active>true</active>
      <codePool>local</codePool>
      <depends>
              <Mage_Catalog />
      </depends>
      <version>0.1.0</version>
    </Mycompany_Cleancart>
  </modules>
</config>

Step 2:

in /app/code/local/Mycompany/Cleancart/etc/config.xml add below code:


<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Mycompany_Cleancart>
            <version>0.1.0</version>
        </Mycompany_Cleancart>
    </modules>
    <global>
        <models>
            <mycompany_cleancart>
                <class>Mycompany_Cleancart_Model</class>
            </mycompany_cleancart>
        </models>
    </global>
    <frontend>
        <events>
            <customer_logout><!-- event observer -->
                <observers>
                    <Mycompany_Cleancart>
                        <class>mycompany_cleancart/observer</class>
                        <method>cleancart</method>
                    </Mycompany_Cleancart>
                </observers>
            </customer_logout>
        </events>
    </frontend>
</config>

Step 3:


in /app/code/local/Mycompany/Cleancart/Model/Observer.php add below code:


<?php

class Mycompany_Cleancart_Model_Observer {

    public function cleancart(Varien_Event_Observer $observer){
        foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
            Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();

        }
    }
}

Tag : Magento
1 Comments On "How to Remove Products from Cart after Customer Logged Out in Magento"

The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..
ecommerce website development company | ECommerce Development Company in BangaloreEcommerce Website Design and Development Company in Bangalore | Magento Development Company

Back To Top