Sitecore Experience Commerce 9: Add Cart Line Error- Item is Not Purchasable
Recently, I encountered the following error when adding a line item to the cart:
Item 'x' is not purchasable.
After inspecting the out of the box XC plugins, I found that there could be a quite a few blocks where this error could originate from since validations are happening at different points in the pipeline:
In order to hone in on the root cause, I set my Commerce Engine debug level to Verbose, and found that the error was coming from the ValidateCartLinePrice block in Sitecore.Commerce.Plugin.Catalog.
As you can see from the actual block, the block is aborting the pipeline with the error message that we saw above:
In order to understand what's happening here, you need to understand the PurchaseOptionMoneyPolicy. The CalculateCartLinesPriceBlock is responsible for calculating the line sell price. The SellableItem has a PurchaseOptionMoneyPolicy which indicates that the item can be sold in the context currency and represents what the item would actually sell for. It provides the ability to have a dynamically calculated price based on any price books, promotions etc among other things.
Using Postman, you can make a call to the ShopsApi to get the SellableItem details and view the PurchaseOptionMoneyPolicy:
After getting the details for the Sellable Item I was trying to add, I found that it did not have any PurchaseOptionMoneyPolicy. Upon further inspection of the product in the catalog, I discovered the item did not have a List Price in USD (my default storefront and shop currency). After adding the List Price, I was able to add the item to the cart!
Make sure the product has a List Price entered in the default currency for your storefront. E.g. if the default currency is USD, then there must be a List Price entered in USD.
If you are not using SXA and are using code based on the Habitat Retail Demo site, the default currency is USD. If you change your default storefront currency from USD to another currency, make sure you update the CartManager. Here is an excellent answer by Andrei Paliakou on StackExchange outlining what you need to update in order to change the currency.