November Happy Hour will be moved to Thursday December 5th.

Get Product from SEOURI

Vote:
 

Hi,

I am looking to create a function that will return "Product" for the given SEOURI.

So far I have reached to a point where I can get a product with matching SEOURI if it exists in Root Node.

var RootLink = referenceConverter.GetContentLink(referenceConverter.GetRootLink());
var Product= ContentLoader.GetChildren(RootLink , new CultureInfo("en-GB")).Where(pd => pd.SeoUri == SEOURIParam).ToList();

Is their a way I can search for Product in entire catalog, irrespective of what hierarchy level product exists.

I don't want to loop through each ProductListingNode to find the matching product.

 

Thanks,

Anurag

#185927
Dec 06, 2017 16:07
Vote:
 

This is one place that you should use ICatalogSystem. It has a method named GetCatalogEntryByUriDto which is pretty fast and efficient. You can use it to load the CatalogEntryDto, then use referenceConverter to get the contentLink from CatalogEntryDto.CatalogEntry[0].CatalogEntryId, then load the content.

#185929
Dec 06, 2017 16:19
Vote:
 

Hi Quan,

Thanks for your suggestion, that worked straight away.

Thanks,
Anurag

#185934
Dec 06, 2017 19:01
Vote:
 

Hi Quan,

I just realise that irrespective of what "languageCode" I specify in _catalogSystem.GetCatalogEntryByUriDto(SEOUri, "en-GB"); or "en-CA" I always get "en-US", United State" product.


Do you know what could be the reason as because of the Variants are also "US" language?


Thanks,
Anurag

#186073
Dec 11, 2017 17:29
Vote:
 

You don't even need to pass the languageCode, you just need to get the CatalogEntryDto which then you get the CatalogEntryId, then you need to pass "en-GB" into the IContentLoader.Get<EntryContentBase>(contentLink, CultureInfor.GetCultureInfor("en-GB"))

If you don't pass the CultureInfo into Get<T> then it always load the default language, in this case, en-US

#186074
Dec 11, 2017 17:35
Vote:
 

Hi,

With below code I can now get proper Product, but the variants are still coming for US version.

var productCatalogEntry = _catalogSystem.GetCatalogEntryByUriDto(SEOUri, ConversionHelpers.GetCultureCode(CountryCode));
var productContentLink = _referenceConverter.GetContentLink(productCatalogEntry.CatalogEntry[0].Code);
var productCatalog = _contentLoader.Get<BookProduct>(productContentLink, ConversionHelpers.GetCultureInfo(CountryCode));   // Correct Product is coming now.

var allRelations = _linksRepository.GetRelationsBySource(productCatalog.ContentLink); // This gives US variant even if "en-GB" is passed.
var bookVariantsList = allRelations.OfType<ProductVariation>().ToList();
var variantsList = new List<BookVariant>();

Any idea?

Thanks,

Anurag

#186075
Edited, Dec 11, 2017 18:04
Vote:
 

Hi Quan,

I got the Variants correctly now, below is my code snippet, I did the samething with Variant that you suggested for Product.

var allRelations = _linksRepository.GetRelationsBySource<ProductVariation>(productCatalog.ContentLink);
var variantsList = new List<BookVariant>();

foreach(var bookVariant in allRelations)
{
var variantCatalogEntry = _catalogSystem.GetCatalogEntryDto(bookVariant.Target.ID);
var variantContentLink = _referenceConverter.GetContentLink(variantCatalogEntry.CatalogEntry[0].Code);
var variantCatalog = _contentLoader.Get<BookVariant>(variantContentLink, ConversionHelpers.GetCultureInfo(CountryCode));
variantsList.Add(variantCatalog);
}

Thanks,

Anurag

#186077
Dec 11, 2017 18:34
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.