0

I am trying to find a way to keep a customer shopping cart items in the shopping cart after they have logged out.

I have enabled persistence already which is fine as long as the customer logs back in their shopping cart items are visible.

What I would like to do is keep them visible when they log out until they click empty cart.

So far I have added an Observer to hook into controller_action_predispatch_customer_account_logoutSuccess Then in my Observer I have

    public function preserveQuote(Varien_Event_Observer $observer)
    {
        $customerQuote = Mage::getModel('sales/quote')->loadByCustomer($observer->getCustomer());
        $currentQuote = Mage::getSingleton('checkout/session')->getQuote();
        $currentQuote->merge($customerQuote);
    }

This logic doesn't work as I think the session has already been cleared by the time the Observer does it's thing.

Has anyone come across a better way to do it?

Please let me know as always very appreciative...

2 Answers 2

1

I tried your code:

public function preserveQuote(Varien_Event_Observer $observer)
{
    $customerQuote = Mage::getModel('sales/quote')->loadByCustomer($observer->getCustomer());
    $currentQuote = Mage::getSingleton('checkout/session')->getQuote();
    $currentQuote->merge($customerQuote);
}

And it works but I used this observer:

    <events>
        <customer_logout>
            <observers>
                <pengo_customer_logout_observer>
                    <type>singleton</type>
                    <class>Pengo_Customer_Model_Observer</class>
                    <method>preserveQuote</method>
                </pengo_customer_logout_observer>
            </observers>
        </customer_logout>
    </events>

Now Cart items persist when i logout.

3
  • Thanks for the feedback and confirmation, for me I still see an empty shopping cart when I've logged out. However, logging back in I can see the items but for some reason the code isn't working for me... Mar 24, 2015 at 19:33
  • You must Disable Persistent Shopping Cart after that you'll able to see your cart when you logout
    – Duarte
    Mar 24, 2015 at 20:50
  • Still not working, I'm going to try on a default install and see what happens... Mar 24, 2015 at 21:04
0

Turns out the Observer wasn't neccessary and instead enabled persistence in admin then included <?php echo $this->getChildHtml('persistent.remember.me'); ?> inside persistent/customer/form/login.phtml

The cart is now persistent when logged out!!

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.