We need to get location and user-specific prices in the SXA Storefront. These prices should also be available when calling the Commerce Engine directly for headless scenarios.
We add XDB facets to the contact on the Storefront side with location and a user specific id. We can retrieve these facets in custom versions of the list price and sell price calculation blocks in the Commer Engine project:
.ConfigurePipeline<ICalculateSellableItemListPricePipeline>(builder => builder.Replace<CalculateSellableItemListPriceBlock, ExternalSellableItemListPriceBlock>())
.ConfigurePipeline<ICalculateSellableItemSellPricePipeline>(builder => builder.Replace<CalculateSellableItemSellPriceBlock, ExternalSellableItemSellPriceBlock>())
.ConfigurePipeline<ICalculateVariationsListPricePipeline>(builder => builder.Replace<CalculateVariationsListPriceBlock, ExternalVariationsListPriceBlock>())
.ConfigurePipeline<ICalculateVariationsSellPricePipeline>(builder => builder.Replace<CalculateVariationsSellPriceBlock, ExternalVariationsSellPriceBlock>())
If we try to retrieve customer-specific information from the commerce context, that it is empty in the above blocks. CommerceContext.ContactId
is empty...
After some investigation into for example ShopperId on the Storefront side we see the following:
Looking at usage:
So only the following Storefront side pipeline blocks do set the ShopperId (and ContactId):
Sitecore.Commerce.Engine.Connect.Pipelines.Orders.GetVisitorOrders
Sitecore.Commerce.Engine.Connect.Pipelines.Orders.TranslateOrderToEntity
Sitecore.Commerce.Engine.Connect.Pipelines.Carts.TranslateCartToEntity
So these headers (described in https://doc.sitecore.com/developers/100/sitecore-experience-commerce/en/service-api-headers.html) are NOT set by the pipelines used in showing products or product details.
Is there a way to add these headers ourselves (like is done in the above pipeline blocks) in for example the processSearchItems
pipeline as used for processing the SXA search result items in the case of a product search (used for the product lister pages)?
If we look at pipeline Sitecore.Commerce.Engine.Connect.Pipelines.Orders.GetVisitorOrders
we see:
And in the method TranslateOrderHeaders
we see:
CommerceOrderHeader commerceOrderHeader = EntityFactory.Create<CommerceOrderHeader>("OrderHeader");
commerceOrderHeader.ExternalId = item.Id;
commerceOrderHeader.ShopName = item.ShopName;
commerceOrderHeader.Name = item.Name;
commerceOrderHeader.OrderID = item.OrderConfirmationId;
commerceOrderHeader.TrackingNumber = item.OrderConfirmationId;
commerceOrderHeader.Status = item.Status;
commerceOrderHeader.OrderDate = item.OrderPlacedDate.DateTime;
Don't know if this translates to HTTP headers in Commerce Engine requests, but seems to be in the right direction...