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);
        }
示例#2
0
        public ProductViewModel GetGiftCardViewModel(Item productItem, Rendering currentRendering)
        {
            if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null)
            {
                return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]);
            }

            var variants = new List <VariantViewModel>();

            if (productItem != null && productItem.HasChildren)
            {
                foreach (Item item in productItem.Children)
                {
                    var v = new VariantViewModel(item);
                    variants.Add(v);
                }
            }

            var productViewModel = new ProductViewModel(productItem);

            productViewModel.Initialize(currentRendering, variants);
            productViewModel.ProductName = productViewModel.DisplayName;

            if (this.CurrentSiteContext.UrlContainsCategory)
            {
                productViewModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl();

                var category = this.CatalogManager.GetCategory(productViewModel.ParentCategoryId);
                if (category != null)
                {
                    productViewModel.ParentCategoryName = category.DisplayName;
                }
            }

            //Special handling for gift card
            if (productViewModel.ProductId == StorefrontManager.CurrentStorefront.GiftCardProductId)
            {
                productViewModel.GiftCardAmountOptions = GetGiftCardAmountOptions(productViewModel);
            }
            else
            {
                this.CatalogManager.GetProductPrice(this.CurrentVisitorContext, productViewModel);
                productViewModel.CustomerAverageRating = this.CatalogManager.GetProductRating(productItem);
            }

            this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel;

            return(productViewModel);
        }
        /// <summary>
        /// Visiteds the product details page.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <returns>
        /// The manager response
        /// </returns>
        public virtual ManagerResponse <CatalogResult, bool> VisitedProductDetailsPage([NotNull] CommerceStorefront storefront)
        {
            Assert.ArgumentNotNull(storefront, "storefront");

            string productId          = CatalogUrlManager.ExtractItemIdFromCurrentUrl();
            string parentCategoryName = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl();
            var    request            = new VisitedProductDetailsPageRequest(storefront.ShopName, productId, productId, parentCategoryName, parentCategoryName);

            var result = this.CatalogServiceProvider.VisitedProductDetailsPage(request);

            if (!result.Success)
            {
                Helpers.LogSystemMessages(result.SystemMessages, result);
            }

            return(new ManagerResponse <CatalogResult, bool>(result, result.Success));
        }
示例#4
0
        private ProductViewModel GetProductViewModel(Item productItem, Rendering rendering)
        {
            if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null)
            {
                return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]);
            }

            var variants = new List <VariantViewModel>();

            if (productItem != null && productItem.HasChildren)
            {
                foreach (Item item in productItem.Children)
                {
                    var v = new VariantViewModel(item);
                    variants.Add(v);
                }
            }

            var productViewModel = new ProductViewModel(productItem);

            productViewModel.Initialize(rendering, variants);
            productViewModel.ProductName = productViewModel.DisplayName;

            if (this.CurrentSiteContext.UrlContainsCategory)
            {
                productViewModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl();
                var category = _catalogManager.GetCategory(productViewModel.ParentCategoryId);

                if (category != null)
                {
                    productViewModel.ParentCategoryName = category.DisplayName;
                }
            }

            _catalogManager.GetProductPrice(this.CurrentVisitorContext, productViewModel);
            productViewModel.CustomerAverageRating = _catalogManager.GetProductRating(productItem);
            this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel;

            return(productViewModel);
        }