Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Scott Reed
Apr 17, 2018
  2966
(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
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog