I'm facing a strange error from commerce engine v. 8.2.1
If I add a product to cart as guest, all the pipelines work flawlessly and the product is added to the cart. Instead, as a registered user, the same products make the engine abort the operation: the product isn't added to the cart and this exception appears in the log:
25 13:20:50 DEBUG Request starting HTTP/1.1 GET http://localhost:5000/api/Carts('Default%7B7e7328e7-8caa-4a3d-bf2f-856466fac77c%7Dstorefront')?$expand=Lines($expand=CartLineComponents($expand=ChildComponents)),Components application/json
25 13:20:50 DEBUG Executing action method "Sitecore.Commerce.Plugin.Carts.CartsController.Get (Sitecore.Commerce.Plugin.Carts)" with arguments (["Default{7e7328e7-8caa-4a3d-bf2f-856466fac77c}storefront"]) - ModelState is Valid
25 13:20:50 INFO MemCache.GetInventoryItem.Hit: ItemKey=Habitat_Master|Prod1|Prod1Variant
25 13:20:50 INFO Inventory.block.PopulateLineItemInventory.ItemAvailabilityComponent.Expired: EffectiveDate=08/04/2018 11:20:50 +00:00|Expires=08/04/2018 11:16:48 +00:00|ItemId=Habitat_Master|Prod1|Prod1Variant
25 13:20:50 INFO PopulateLineItemAvailability.ComponentUpdated.Habitat_Master|Prod1|Prod1Variant: Count=1500
26 13:20:51 INFO MemCache.GetInventoryItem.Hit: ItemKey=Habitat_Master|Prod2|Prod2-1
26 13:20:51 INFO Inventory.block.PopulateLineItemInventory.ItemAvailabilityComponent.Expired: EffectiveDate=08/04/2018 11:20:51 +00:00|Expires=08/04/2018 11:16:48 +00:00|ItemId=Habitat_Master|Prod2|Prod2-1
26 13:20:51 INFO PopulateLineItemAvailability.ComponentUpdated.Habitat_Master|Prod2|Prod2-1: Count=10
26 13:20:51 INFO MemCache.GetInventoryItem.Hit: ItemKey=Habitat_Master|Prod3|Prod3_1
26 13:20:51 INFO Inventory.block.PopulateLineItemInventory.ItemAvailabilityComponent.Expired: EffectiveDate=08/04/2018 11:20:51 +00:00|Expires=08/04/2018 11:16:48 +00:00|ItemId=Habitat_Master|Prod3|Prod3_1
26 13:20:51 INFO PopulateLineItemAvailability.ComponentUpdated.Habitat_Master|Prod3|Prod3_1: Count=999
26 13:20:51 ERROR CtxMsg.Error.LineIsNotPurchasable: Text=Item 'Prod1Variant' is not purchasable.
26 13:20:51 ERROR CtxMsg.Error.LineIsNotPurchasable: Text=Item 'Prod2_1' is not purchasable.
26 13:20:51 ERROR CtxMsg.Error.LineIsNotPurchasable: Text=Item 'Prod3' is not purchasable.
26 13:20:51 ERROR PipelineAbort:Cart 'Default{7e7328e7-8caa-4a3d-bf2f-856466fac77c}storefront' has invalid lines.
26 13:20:51 ERROR PipelineAbort:Cart 'Default{7e7328e7-8caa-4a3d-bf2f-856466fac77c}storefront' has invalid lines.
25 13:20:51 DEBUG Executing ObjectResult, writing value "Microsoft.AspNetCore.Mvc.ControllerContext".
26 13:20:51 DEBUG Executed action "Sitecore.Commerce.Plugin.Carts.CartsController.Get (Sitecore.Commerce.Plugin.Carts)" in 578.7314ms
Trying to troubleshot the problem I found that the error comes from the Plugin.Catalog.ValidateCartLinesPriceBlock in the pipeline ICalculateCartLinesPipeline. If this one doesn't find a PurchaseOptionMoneyPolicy in the cartline's policy, it throws the error.
This policy should come from the previous block CalculateCartLinesPriceBlock which calls in turn IGetSellableItemPipeline: this last one should get the list and sell price of the sellable item in order to allow the CalculateCartLinesPriceBlock to set a valid PurchaseOptionMoneyPolicy.
However I didn't understand why the problem shows up only when the user is logged in.