protected IList <ProductModel> AdjustProductPriceAndStockStatus(IVisitorContext visitorContext, SearchResults searchResult, Item currentCategory)
        {
            var result   = new List <ProductModel>();
            var products = new List <Product>();

            if (searchResult.SearchResultItems != null && searchResult.SearchResultItems.Count > 0)
            {
                foreach (Item searchResultItem in searchResult.SearchResultItems)
                {
                    var variants = new List <Variant>();
                    var product  = new Product(searchResultItem, variants);
                    product.CatalogName           = this.StorefrontContext.CatalogName;
                    product.CustomerAverageRating = this.CatalogManager.GetProductRating(searchResultItem);
                    products.Add(product);
                }

                this.CatalogManager.GetProductBulkPrices(products);
                //this.InventoryManager.GetProductsStockStatus(products, currentStorefront.UseIndexFileForProductStatusInLists);
                foreach (var product in products)
                {
                    var productModel         = new ProductModel();
                    var commerceProductModel = this.SitecoreContext.Cast <ICommerceProductModel>(product.Item);
                    productModel.Initialize(commerceProductModel);
                    productModel.CurrencySymbol        = this.CurrencyProvider.GetCurrencySymbolByCode(product.CurrencyCode);
                    productModel.ListPrice             = product.ListPrice;
                    productModel.AdjustedPrice         = product.AdjustedPrice;
                    productModel.StockStatusName       = product.StockStatusName;
                    productModel.CustomerAverageRating = product.CustomerAverageRating;
                    result.Add(productModel);
                }
            }

            return(result);
        }
示例#2
0
        public CartLineModel Initialize(CartLine model)
        {
            Assert.ArgumentNotNull(model, nameof(model));

            var result = new CartLineModel();

            result.Id = model.ExternalCartLineId;

            var commerceCartProduct = model.Product as CommerceCartProduct;

            ProductModel product = this.catalogRepository.GetProduct(model.Product.ProductId);

            result.Product  = product;
            result.Variant  = product.Variants?.FirstOrDefault(x => x.ProductVariantId == commerceCartProduct?.ProductVariantId);
            result.Quantity = model.Quantity;

            var price = new CartPriceModel();

            price.Initialize(model.Total, this.currencyProvider);
            result.Price = price;

            result.Temp = model;

            return(result);
        }
示例#3
0
        protected virtual ProductModel GetProductModel(IVisitorContext visitorContext, Item productItem)
        {
            Assert.ArgumentNotNull(visitorContext, nameof(visitorContext));

            if (productItem == null)
            {
                return(null);
            }

            var variantEntityList = new List <Variant>();

            if (productItem.HasChildren)
            {
                variantEntityList = this.LoadVariants(productItem);
            }

            var product = new Product(productItem, variantEntityList);

            product.CatalogName = this.StorefrontContext.CatalogName;

            product.CustomerAverageRating = this.CatalogManager.GetProductRating(productItem);

            this.CatalogManager.GetProductPrice(product);
            this.CatalogManager.GetStockInfo(product, this.StorefrontContext.ShopName);

            var renderingModel = new ProductModel();
            var model          = this.SitecoreContext.Cast <ICommerceProductModel>(productItem);

            renderingModel.Initialize(model);
            renderingModel.CurrencySymbol        = this.CurrencyProvider.GetCurrencySymbolByCode(product.CurrencyCode);
            renderingModel.ListPrice             = product.ListPrice;
            renderingModel.AdjustedPrice         = product.AdjustedPrice;
            renderingModel.StockStatusName       = product.StockStatusName;
            renderingModel.CustomerAverageRating = product.CustomerAverageRating;

            foreach (ProductVariantModel renderingModelVariant in renderingModel.Variants)
            {
                var variant = product.Variants.FirstOrDefault(x => x.VariantId == renderingModelVariant.ProductVariantId);
                if (variant == null)
                {
                    continue;
                }

                renderingModelVariant.CurrencySymbol        = this.CurrencyProvider.GetCurrencySymbolByCode(variant.CurrencyCode);
                renderingModelVariant.ListPrice             = variant.ListPrice;
                renderingModelVariant.AdjustedPrice         = variant.AdjustedPrice;
                renderingModelVariant.StockStatusName       = variant.StockStatusName;
                renderingModelVariant.CustomerAverageRating = variant.CustomerAverageRating;
            }

            return(renderingModel);
        }