Magento: How to restore a User's Shopping Cart Session - Abandoned Cart Recovery, notifications and more

Magento: How to restore a User's Shopping Cart Session - Abandoned Cart Recovery, notifications and more

This is a fairly common use case in a lot of E-commerce projects, User has purchased something before, and needs to re-order. Or, a they've has added items to their shopping cart, and we need to email / SMS them a link reminding them to complete the purchase.

I’ve been looking for a solution for Abandoned Cart Recovery for a while now, but one without all the bells and frills that come in the extensions online.

Just needed a simple link to restore the cart contents. After a lot of googling and playing around with the cart, I got it to work.

If you’re looking for a way to recover a customer’s cart contents - here’s the step by step for the same.

We need to work with the CartController file, so lets make a copy of this in our local folder.

This is my file:

Getting to the Code:

Pass the order_id in the checkout/cart URL, so in the CartController indexAction we have access to 2 more parameters:
order_id and key

Note: We’re gonna use a key here to confirm the user has indeed clicked on our link and not modified it in any way. A quick option is to use a md5 hash of the order_id with a salt keyword.

 

And that’s it. We now have an easy URL ready to use which will populate the cart session back, and a user can picked up when he left off.

How do you invoke this URL? Simple, head over to your Email Templates Section and duplicate your order email. Modify the contents. For example, you may want to remove off the “Payment Method” section, and instead add a Button that says “Complete your Purchase”.

For sending out the emails, I added a simple manual trigger to my order page that reads like this:

Magento: How to restore a User's Shopping Cart Session - Abandoned Cart Recovery, notifications and more

Since this is a temporary feature I’ve just shifted the email trigger code outside of my Magento and this is my send-email file:

This was because we wanted to do it manually and not automate it as yet.

I will be automating it at some point in the future, but for now, this works well for us. If you are looking to automate it, I’d add a cron job to check up the status of the orders every X minutes, and check for the “pending” or payment failed orders and then trigger the sending of this email.

Note: While converting the order object to quote object, you won't get the email ID by default, as it’s not part of the convert configuration. To get the user’s email ID, in the Mage/Sales/etc/config.xml file you need to add the following to the sales_convert_order_address xml block:

If you've got any modifications to the code or suggestions, drop them in the comments below.

That's all folks!

About Rashmi B.

Mostly a startup junkie. Dabbled around in Marketing, SEO, Magento, WordPress, Angular, etc etc. Like to help people bring their startup idea to life. Fan of the Lean Startup movement. Hit me up to know more.

View all posts by Rashmi B.

One Comment on “Magento: How to restore a User's Shopping Cart Session - Abandoned Cart Recovery, notifications and more”

  1. Hi, can you please elaborate which files should be modified and where? I’m trying your code for automaking a cart to old customers when reminded of old unpaid orders, but my code get ignored or I get errors when I put your code at the beginning of the CartController.php file:

    ‘PHP message: PHP Parse error: syntax error, unexpected ‘$url_params’ (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in /var/www/clients/client0/web4/web/app/code/local/Mage/Checkout/controllers/CartController.php on line 32\n’

    Thanks for your time and sorry to disturb.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.