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

How to clean cart when user closes the browser ? 
 
Rafal
Member
 
Total Posts:  42
Joined:  2007-11-22
Munich
 

Hi,

I’d like to remove all products from cart and additional user informations (like shipping method etc.) when user logout OR closes the browser.

With logout there are no problems ... it’s easy to modify logout method but in the second case ...

I could remove that informations before login but I cannot make it because it could happen that user (before login) added some products to the cart - so I cannot remove them.

I have analyzed the DB structure and I see that in the table: sales_quote_entity there are a few records:
“main” record which contains main quote informations - it’s parent record for others.
Other records are responsible for products, payment info, address info etc. - these are child records for “main” record.

I could easily remove “child” records but ... I don’t think that it’s good idea but I don’t have any other solution.

Do you know any good solution of my problem ?

with best regards,
Rafal

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@Rafal: try

Mage::getModel('sales/quote')->delete($quoteId);
 
Magento Community Magento Community
Magento Community
Magento Community
 
Rafal
Member
 
Total Posts:  42
Joined:  2007-11-22
Munich
 
Moshe - 10 March 2008 08:43 AM

@Rafal: try

Mage::getModel('sales/quote')->delete($quoteId);

Hi Moshe,

Your answer was really fast grin
Should I delete “parent” quota_id or just child ? i.e. I would have to find the “newest” record of that user and remove it ?
Is it good solution ? isn’t it used to any statistics ?

I saw that after logout it creates new quote record in sales_quote_entity which is empty and this one is taken in the next session (after login).
Maybe better would be just to create new “empty” quota record ? but how could I make it ? I didn’t see any method like “createQuota(customerId")"

What do you think ?

with best regards,
Rafal

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rafal
Member
 
Total Posts:  42
Joined:  2007-11-22
Munich
 

Hi,

I found suitable solution (at least I think so wink )

When I override method loadCustomerQuote from Mage_Checkout_Model_Session like this:

public function loadCustomerQuote()
{
    
return $this;
}

then “old” cart of this user won’t be attached to the new one.

with best regards,
Rafal

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