5

I'm using Sitecore 9 + Ecommerce Update 1. I have a custom SXA component which uses as data source some Commerce Product.

enter image description here

For displaying all data I need to retrieve an Ecommerce Sellable item. I also need all variants under parent items. What is the best way to do this?

4

I just received an answer from Sitecore support.

You have to reference next dlls:

  • Sitecore.Commerce.Engine.Connect
  • Sitecore.Commerce.ServiceProxy
  • Microsoft.OData.Client

To retrieve the sellable item from Sitecore Commerce 9 Update 1 you can use following code snippet. To retrieve a sellable item without variants:

var container = Sitecore.Commerce.Engine.Connect.EngineConnectUtility.GetShopsContainer(); var sellableItem = Sitecore.Commerce.ServiceProxy.Proxy .GetValue<SellableItem>(container.SellableItems .ByKey("Habitat_Master,Entity-SellableItem-6042134,") .Expand("Components"));

or

var sellableItem = Sitecore.Commerce.Engine.Connect.Search.IndexUtility .GetSellableItem("Habitat_Master,Entity-SellableItem-6042134,")

where Habitat_Master is catalog name and Entity-SellableItem-6042134 is id of the sellable item.

To retrieve a sellable item with variants:

var sellableItem = Sitecore.Commerce.ServiceProxy.Proxy .GetValue<SellableItem>(container1.SellableItems .ByKey("Habitat_Master,Entity-SellableItem-6042134,") .Expand("Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents))))"));

| improve this answer | |
0

To achive this you can use commerce connect with the ICatalogrepository from the namespace sitecore.commerce.connect.commerceserver.catalog .

There is a getproduct() which can so what you need.

With the ProductFamily which is retrieved you get all Information about Product and variants.

| improve this answer | |
  • 1
    Hello @Christian. Thank you for the answer, but I can't find mentioned namespace. In which assembly it locates? – Igor Marenych Jul 26 '18 at 13:48
  • It is in theq sitecore.commerceserver.connect. can be found as nuget package in the commerce feed – Christian Jul 26 '18 at 14:20
  • 1
    Is it compatible with Sitecore 9 + Ecommerce Update 1? – Igor Marenych Jul 26 '18 at 14:26
  • 1
    This I dont know. I have it in use with Sitecore Commerce 8.2.1. – Christian Jul 26 '18 at 15:00
0

For 9.0.2 This I dont know. I have it in use with Sitecore Commerce 8.2.1. But for your answer I just reflectored a bit inside the 9.0.2 dll and found some implementation of en eqivalent implementation

public override Item GetProduct(string productId, string catalogName) { Assert.ArgumentNotNullOrEmpty(catalogName, nameof (catalogName)); Item obj = (Item) null; ISearchIndex index = CommerceTypeLoader.CreateInstance<ICommerceSearchManager>().GetIndex(catalogName); string catalogId = this.StorefrontContext.CurrentStorefront.CatalogItem.ID.ToGuid().ToString(); int num = 0; using (IProviderSearchContext searchContext = index.CreateSearchContext((SearchSecurityOptions) num)) { ParameterExpression parameterExpression; // ISSUE: method reference // ISSUE: method reference CommerceSellableItemSearchResultItem searchResultItem = searchContext.GetQueryable<CommerceSellableItemSearchResultItem>().Where<CommerceSellableItemSearchResultItem>((Expression<Func<CommerceSellableItemSearchResultItem, bool>>) (item => item.CommerceSearchItemType == "SellableItem")).Where<CommerceSellableItemSearchResultItem>((Expression<Func<CommerceSellableItemSearchResultItem, bool>>) (item => item.Language == this.Context.Language.Name)).Where<CommerceSellableItemSearchResultItem>((Expression<Func<CommerceSellableItemSearchResultItem, bool>>) (item => item.Name == productId.ToLowerInvariant())).Where<CommerceSellableItemSearchResultItem>((Expression<Func<CommerceSellableItemSearchResultItem, bool>>) (item => item.ParentCatalogList.Contains<string>(catalogId))).Where<CommerceSellableItemSearchResultItem>((Expression<Func<CommerceSellableItemSearchResultItem, bool>>) (item => item["_latestversion"].Equals("1"))).Select<CommerceSellableItemSearchResultItem, CommerceSellableItemSearchResultItem>(Expression.Lambda<Func<CommerceSellableItemSearchResultItem, CommerceSellableItemSearchResultItem>>((Expression) Expression.MemberInit(Expression.New(typeof (CommerceSellableItemSearchResultItem)), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SearchResultItem.set_ItemId)), )))); //unable to render the statement if (searchResultItem != null) obj = searchResultItem.GetItem(); } return obj; }

enter image description here

This can be found within OOTB existing SearchManager.cs from namespace Sitecore.Commerce.XA.Foundation.CommerceEngine.Managers Maybe this could help you

| improve this answer | |
  • Hello Christian. Thank you for an answer. But this is not exactly what I need. I opened Sitecore support ticket and I'll update this topic when they give me an answer. – Igor Marenych Jul 30 '18 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.