November Happy Hour will be moved to Thursday December 5th.

Scott Reed
Apr 17, 2018
  3052
(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
Adding Geolocation Personalisation to Optimizely CMS with Cloudflare

Enhance your Optimizely CMS personalisation by integrating Cloudflare's geolocation headers. Learn how my Cloudflare Geo-location Criteria package...

Andy Blyth | Nov 26, 2024 | Syndicated blog

Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog