AI OnAI Off
You can use the extension variationContent.GetParentProducts, which returns a list of Products for that variation
Hi everyone.
thank you Quan Mai for your help:
Finally, using your suggestion and researching a little bit more I have solved this by this way:
[CatalogContentType(GUID = "a1b78c39-0549-48bf-adfe-e5a4968c2816", MetaClassName = "Base_Variation")] public class BaseVariation : VariationContent { private IContentLoader contentLoader = null; public BaseVariation() { this.contentLoader = ServiceLocator.Current.GetInstance<EPiServer.IContentLoader>(); } [CultureSpecific] [Display( Name = "Title", Description = "This is the Default Variation Title.", GroupName = SystemTabNames.Content, Order = 1)] public virtual string Title { get; set; } #region Publich Methods public BaseProduct GetBaseParentProduct() { BaseProduct returnValue = null; try { ContentReference productContentReference = this.GetParentProducts().FirstOrDefault(); returnValue = contentLoader.Get<BaseProduct>(productContentReference); } catch { returnValue = null; } return returnValue; } public List<BaseProduct> GetBaseParentProducts() { List<BaseProduct> returnValue = new List<BaseProduct>(); try { IEnumerable<ContentReference> productsContentReference = this.GetParentProducts(); foreach (ContentReference prodcr in productsContentReference) { returnValue.Add(contentLoader.Get<BaseProduct>(prodcr)); } } catch { returnValue = new List<BaseProduct>(); } return returnValue; } #endregion Publich Methods }
With those two methods I can get what I was looking for:
public BaseProduct GetBaseParentProduct() { BaseProduct returnValue = null; try { ContentReference productContentReference = this.GetParentProducts().FirstOrDefault(); returnValue = contentLoader.Get<BaseProduct>(productContentReference); } catch { returnValue = null; } return returnValue; } public List<BaseProduct> GetBaseParentProducts() { List<BaseProduct> returnValue = new List<BaseProduct>(); try { IEnumerable<ContentReference> productsContentReference = this.GetParentProducts(); foreach (ContentReference prodcr in productsContentReference) { returnValue.Add(contentLoader.Get<BaseProduct>(prodcr)); } } catch { returnValue = new List<BaseProduct>(); } return returnValue; }
I hope more than one is useful.
Thank you and best regards.
Hello.
In my Catalog I have a Product with two Variations, and in my code I would like to get the Product for those Variations, so my question is:
Which is the best way to get the Parent Product for a Variation programmatically?.
I'm a little bit stuck with this and I don't know hot to achieve this.
Best reagrds.