public static CatalogItemVariantsRenderingModel InitializeMockData(CatalogItemVariantsRenderingModel model) { Assert.ArgumentNotNull(model, nameof(model)); model.Initialize(GetProductEntity(), true); model.DisplayName = "Lorem ipsum dolor sit amet"; model.DisplayNameRender = new HtmlString(model.DisplayName); model.Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non ultrices risus. Mauris tincidunt urna at ligula viverra mollis. Pellentesque nulla velit, fermentum ac sollicitudin ut, tincidunt non nisl. Ut sagittis faucibus nibh id finibus. Praesent finibus sed ex id rhoncus. Praesent quam elit, accumsan sit amet tincidunt pulvinar, feugiat vitae velit. Aenean sed vestibulum eros."; model.DescriptionRender = new HtmlString(model.Description); model.Link = "/"; MediaItem mediaItem = Context.Database.GetItem(CatalogFeatureConstants.MockDataItems.MockProductId); model.Images.Add(mediaItem); return(model); }
protected virtual CatalogItemVariantsRenderingModel GetCatalogItemVariantsRenderingModel( IVisitorContext visitorContext, Item productItem) { Assert.ArgumentNotNull(visitorContext, nameof(visitorContext)); //Important: make sure to use the CurrentCatalogItemVariantsRenderingModelKeyName constant here if (SiteContext.Items[CurrentCatalogItemVariantsRenderingModelKeyName] != null) { return((CatalogItemVariantsRenderingModel)SiteContext.Items[CurrentCatalogItemVariantsRenderingModelKeyName]); } CommerceStorefront currentStorefront = StorefrontContext.CurrentStorefront; List <VariantEntity> variantEntityList = new List <VariantEntity>(); if (productItem != null && productItem.HasChildren) { foreach (Item child in productItem.Children) { VariantEntity model = ModelProvider.GetModel <VariantEntity>(); model.Initialize(child); variantEntityList.Add(model); } } ProductEntity productEntity = ModelProvider.GetModel <ProductEntity>(); productEntity.Initialize(currentStorefront, productItem, variantEntityList); CatalogItemVariantsRenderingModel catalogModel = ModelProvider.GetModel <CatalogItemVariantsRenderingModel>(); Init(catalogModel); if (SiteContext.UrlContainsCategory) { catalogModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl(); Item category = SearchManager.GetCategory(catalogModel.ParentCategoryId, currentStorefront.Catalog); if (category != null) { catalogModel.ParentCategoryName = category.DisplayName; } } if (string.Equals(catalogModel.ProductId, currentStorefront.GiftCardProductId, StringComparison.Ordinal)) { catalogModel.GiftCardAmountOptions = GetGiftCardAmountOptions(visitorContext, currentStorefront, productEntity); } else { CatalogManager.GetProductPrice(currentStorefront, visitorContext, productEntity, null); catalogModel.CustomerAverageRating = CatalogManager.GetProductRating(productItem, null); } catalogModel.Initialize(productEntity, false); SiteContext.Items["CurrentCatalogItemVariantsRenderingModel"] = catalogModel; return(catalogModel); }