I'm creating a web shop based on Sitecore Commerce 9. We are not using SXA. I'm trying to show cart contents on the page. My environment was populated with the example project from SDK.
The problem is that when I add an item to cart and then load the cart, the lines contain only mysterious ProductId, and no reference to neither SellableItem nor Sitecore item.
The problem is repoducible with Postman:
- Add item to cart:
- Load the cart - see that all the line properties are empty:
I use the following class to load the cart programatically and I get same result - no reference to the item.
public class CartManager : ICartManager
{
private CartServiceProvider _cartServiceProvider;
private IStoreContext _storeContext;
private IVisitorContext _visitorContext;
public CartManager(IVisitorContext visitorContext, IStoreContext storefrontContext)
{
this._cartServiceProvider = (CartServiceProvider)Factory.CreateObject("cartServiceProvider", true);
this._storeContext = storefrontContext;
this._visitorContext = visitorContext;
}
public Cart GetCart()
{
var cart = _cartServiceProvider.LoadCart(new LoadCartRequest(this._storeContext.ShopName, "Default", this._visitorContext.CustomerId));
if(cart.Success)
{
return cart.Cart;
}
return null;
}
The only property filled is the Id (in Postman) or the line.Product.ProductId (in the code) which doesn't refer to anything.
How to get the SellableItem or the Sitecore item for the cart line?
Update: There is an error in the log:
6 22:01:28 INFO Executing action method "Sitecore.Commerce.Plugin.Carts.CommandsController.AddCartLine (Sitecore.Commerce.Plugin.Carts)" with arguments (["System.Web.Http.OData.ODataActionParameters"]) - ModelState is Valid
6 22:01:28 ERROR Inventory.block.PopulateItemAvailability-No ProductArgument in Context
6 22:01:28 ERROR PopulateItemAvailabilityBlock.AllocationNull.|6042283|56042283
6 22:01:28 WARN PopulateItemAvailability.NotAvailable.|6042283|56042283
6 22:01:28 ERROR Pipeline completed with error
System.Exception: Error processing block: Preorderable.Block.PopulateItemPreorderableAvailability ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Sitecore.Commerce.Plugin.Preorderable.PopulateItemPreorderableAvailabilityBlock.<Run>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Sitecore.Framework.Pipelines.ReflectionPipelineBlockRunner.<InvokeBlock>d__2.MoveNext()
--- End of inner exception stack trace ---
at Sitecore.Framework.Pipelines.ReflectionPipelineBlockRunner.<InvokeBlock>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Sitecore.Framework.Pipelines.BasePipelineBlockRunner.<Run>d__3`1.MoveNext()
And this is my IAddCartPipeline configuration:
{
"Name": "IAddCartLinePipeline",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.CartLineArgument",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart",
"Blocks": [
{
"Name": "ValidateSellableItemBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Catalog",
"Receives": "Sitecore.Commerce.Plugin.Carts.CartLineArgument",
"Returns": "Sitecore.Commerce.Plugin.Carts.CartLineArgument"
},
{
"Name": "AddCartLineBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.CartLineArgument",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "AddContactBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "ICalculateCartLinesPipeline",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "ICalculateCartPipeline",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "AddCartLineDigitalProductBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.DigitalItems",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "AddCartLineWarrantyBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.DigitalItems",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "AddCartLineInstallationBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.DigitalItems",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "AddCartLineGiftCardBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.GiftCards",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "PersistCartBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
},
{
"Name": "WriteCartTotalsToContextBlock",
"Policies": [],
"Namespace": "Sitecore.Commerce.Plugin.Carts",
"Receives": "Sitecore.Commerce.Plugin.Carts.Cart",
"Returns": "Sitecore.Commerce.Plugin.Carts.Cart"
}
],
"Comment": ""
}