EPiCommerce in ReadOnly mode : Note to self

As of update 108, EPiServer Commerce can be “used” in readonly mode as well. Arild Henrichsen wrote a post while back about the how, what and why of readonly mode for the CMS part, and those things apply to Commerce as well I guess. Though with a shop in readonly mode … you will still lose business.

I have been playing around with readonly mode for a Commerce environment and before you use it in production, make sure that you handle errors very well and/or “hide your buttons”.

Adding a product to your cart for example will throw a “not supported” exception, as your database is in readonly mode. So, make sure to handle this error specifically.
If you only catch “Exception” maybe you should consider catching some more specific errors, at least this one, first. There is a great plugin for ReSharper, Exceptional, that helps with analyzing all exceptions your code can run into.
I would have preferred a more specific exception thrown though, like dbreadonlyexception or something like that, so you can take a specific action / show a specific message for this.

Hiding your “add to cart” and “wish list” functionality is a more preferable way to go in my opinion, I think it might be quite confusing if you can add a product to cart and get a message “not now”. You could accomplish this e.g. by adding a Boolean,  property to your viewmodel, which you can set as follows

ServiceLocator.Current.GetInstance<IDatabaseMode>().DatabaseMode == DatabaseMode.ReadOnly;

and use this property to “hide your buttons”.

btw, the POC I wrote about  won’t be of use in readonly mode, as adding a product to your cart will fail.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s