2

I see a lot of posts in regards to the built in persistent cart not working as expected, IE - doesn't work for guests. What I'm trying to do is actually implement it.

It seems fairly easy. Store the quote ID in a cookie and load it and assign it to the session the next time the customer comes back. However I'm not having success. I've worked my way through the code when a guest first adds an item to their cart. My thought was that code would show me how to initialize a cart. Instead of initializing I'd load an existing cart. I've assigned the loaded quote to the checkout session and cart singleton but it still shows me no items when I visit the cart page.

Can someone point me in the right direction? I'll keep digging in the meantime.

  • I'm getting close by simply setting the quote ID in the checkout session. I'll know more tomorrow and post an answer if applicable. – gwgeller Nov 1 '16 at 21:52
0

Below is the code to load a cart/quote to the session for a guest visitor. I'm getting the quote id from a cookie that I created once the visitor adds an item to their cart.

Mage::getSingleton('checkout/session')->setQuoteId($quote_id);
$cust = Mage::getSingleton('customer/session')->getCustomer();
$quote->setCustomer($cust);
$quote->setTotalsCollectedFlag(false)->collectTotals();
$quote->save();

It is important to set the customer so when collecting totals any rules will be associated with the "guest" customer and not the original customer that created the cart/quote.

One interesting side note I noticed while working on this. Magento creates a blank quote when a customer logs in if the customer doesn't already have an existing one. These blank quotes are inflating my abandoned cart/quote reporting.

  • in what file are you placing this code? – Yehuda Schwartz Mar 2 '17 at 20:45
  • 1
    @YehudaSchwartz I setup an observer on the controller_action_predispatch event. Since that event will fire every page load I have logic in place to bypass the code once the cart has been loaded. It also bypasses the logic if there is no cart to be loaded. – gwgeller Mar 3 '17 at 3:49
  • could you share that code here? – Yehuda Schwartz Mar 3 '17 at 15:07
  • Depending on what you have setup I'm not sure what actual code you need. You will need a module and from there you need to setup the config to observe the event. There are plenty of examples on how to observe events in Magento if you do a search. – gwgeller Mar 3 '17 at 18:48

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.