SaaS CMS has officially launched! Learn more now.

Scott Reed
Apr 17, 2018
  3000
(5 votes)

Using commerce carts for more than just basket and configuring the cart cleanup task

Different Serializable Carts

In a standard commerce implementation we would usually unless building something custom use the new Serializable Carts feature in Episerver Commerce.

For loading a cart we call either LoadCart or LoadOrCreateCart on the IOrderRepository service which allows us to pass a string such as the following

var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
return OrderRepository.Service.LoadCart<ICart>(contactId, "Default");

This is fine for when we just have a single commerce cart but we can also use cart for persisting other lists of items such as wishlists and then still using the standard validation workflows to make sure products removed from our catalogues are removed from these too. We simply pass a different string in to this method which will create a different cart.

Cart Cleanup

One of the problems that you could potentially hit is that out of the box (if you turn it on) there is a clean up Job that cleans up the carts. However as listed here https://world.episerver.com/documentation/developer-guides/commerce/configuration/feature-specific-commerce-configurations/ there is a set of commands that allow you to handle this.

You can either call your wishlist "WishList" (passing this string in to the LoadCart or LoadOrCreateCart method) which will be left by the clean up procedure or you can change the appSetting episerver:ExpiredCartsRemovalJobExcludedCartName and set the name of the cart which you don't want to be cleaned. Sadly this only supports one excluded cart and can only be set in the configuration, I would suggest maybe extending this class and disabling the base Job if you need to change this.

Hopefully this will give an example of using carts for not only the commerce process but also for a wishlist or for other persistent store of commerce items against a user.

As a bonus to note the cart cleanup defaults to 30 days buy can be controlled by adding an appSetting as defined in the above docs of ExpiredCartJobDays which you can set to change the number of days carts that exist should be cleaned up.

Thanks, Scott

Apr 17, 2018

Comments

Bob Bolt
Bob Bolt Apr 17, 2018 04:19 PM

We fixed the capitalization on "WishList" -- Thanks, Scott.

Apr 18, 2018 09:04 AM

Thanks, I've removed that part from my blog :-) 

Please login to comment.
Latest blogs
Optimizely release SaaS CMS

Discover the future of content management with Optimizely SaaS CMS. Enjoy seamless updates, reduced costs, and enhanced flexibility for developers...

Andy Blyth | Jul 17, 2024 | Syndicated blog

A day in the life of an Optimizely Developer - London Meetup 2024

Hello and welcome to another instalment of A Day In The Life Of An Optimizely Developer. Last night (11th July 2024) I was excited to have attended...

Graham Carr | Jul 16, 2024

Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default,...

Nahid | Jul 16, 2024

Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024