public ProductDetailsModel MapProduct(Product product)
        {
            var pdm = new ProductDetailsModel {
                Id               = Guid.NewGuid().ToString(),
                ProductType      = product.ProductType,
                Condition        = product.Condition,
                Designation      = product.Designation,
                DisplayName      = GetIdentifierValue(product, "Display Name"),
                Status           = product.Status,
                ManufacturerCode = product.Manufacturer.Code,
                ManufacturerMake = product.Manufacturer.Make,
                ModelCode        = product.Model.Code,
                SubModelName     = product.Model.Models.Count > 0 ? product.Model.Models[0].Name : "",
                ModelName        = product.Model.Name,
                ModelYear        = GetYear(product),
                StockNumber      = GetIdentifierValue(product, "Stock Number")
            };

            pdm.NavigationItems = new List <NavigationItem> {
                new NavigationItem {
                    Id          = pdm.Id,
                    DisplayName = pdm.DisplayName
                }
            };

            if (product.Description.Length > 0)
            {
                pdm.MarketingDetails.Add(new MarketingDetailModel {
                    Category = "Product Description",
                    Name     = "",
                    Value    = product.Description
                });
            }

            foreach (var activity in product.Activities.OrderBy(a => a.Name))
            {
                pdm.Activities.Add(new ActivityModel {
                    Category = GetSelectItem(GetActivityTypes(), activity.CategoryName),
                    Name     = activity.Name,
                    Value    = activity.Value
                });
            }

            foreach (var color in product.Colors.OrderBy(c => c.Name))
            {
                string colorCategory = "Exterior";
                if (!String.IsNullOrWhiteSpace(color.Category))
                {
                    colorCategory = color.Category;
                }
                pdm.Colors.Add(new ColorModel {
                    Category = GetSelectItem(GetColorTypes(), colorCategory),
                    Name     = color.Name,
                    Value    = color.Value
                });
            }

            foreach (var c in product.MarketingDescriptions.OrderBy(md => md.Name))
            {
                pdm.MarketingDetails.Add(new MarketingDetailModel {
                    Category = c.CategoryName,
                    Name     = c.Name,
                    Value    = c.Value
                });
            }

            foreach (var c in product.Prices.OrderBy(p => p.Value))
            {
                pdm.Prices.Add(new PriceModel {
                    Amount          = c.Value,
                    Category        = GetSelectItem(GetPriceTypes(), c.Category),
                    FormattedAmount = String.Format("{0:C}", c.Value.Value),
                    DisplayValue    = c.DisplayValue
                });
            }

            foreach (var c in product.Specifications.OrderBy(s => s.CategoryName).ThenBy(s => s.Name))
            {
                pdm.Specifications.Add(new SpecificationModel {
                    Amount   = c.NumericValue,
                    Category = GetSelectItem(GetSpecificationTypes(), c.CategoryName),
                    Name     = c.Name,
                    UnitType = GetSelectItem(GetUnitTypes(), c.UnitType),
                    Value    = c.Value
                });
            }

            foreach (var feature in product.Features.OrderBy(f => f.Description))
            {
                pdm.Features.Add(MapFeature(feature, pdm.NavigationItems));
            }

            return(pdm);
        }
Exemplo n.º 2
0
        private async Task <CartPromotionResultModel> CaclulateInclusivePromotion(Promotion promotion, CartPromotionCheckModel data, int productsInPromotionCount, IList <string> productsInPromotionFromCart)
        {
            CartPromotionResultModel result = new CartPromotionResultModel
            {
                Cart = new List <ProductInCartModel>()
            };

            int quantityToBeGivenAsPromotion = promotion.IsAccumulative
                ? (productsInPromotionCount / promotion.ProductsCount) * promotion.DiscountedProductsCount
                : promotion.DiscountedProductsCount;

            int quantityGivenAsPromotion = 0;

            bool includePriceDiscounts = promotion.IncludePriceDiscounts;

            decimal promotionDisount = promotion.Discount;

            data.Products = await this.OrderProductsInCart(data.Products, includePriceDiscounts);

            foreach (ProductInCartModel product in data.Products)
            {
                int remainingQuantityToBeGivenAsPromotion = quantityToBeGivenAsPromotion - quantityGivenAsPromotion;

                ProductDetailsModel currentProduct = await this.products.Get(product.Id);

                if (remainingQuantityToBeGivenAsPromotion > 0 && productsInPromotionFromCart.Contains(product.Id))
                {
                    if (includePriceDiscounts)
                    {
                        promotionDisount += currentProduct.Discount;
                    }

                    if (promotionDisount > 100)
                    {
                        promotionDisount = 100;
                    }

                    if (product.Quantity > remainingQuantityToBeGivenAsPromotion)
                    {
                        ProductInCartModel discounted = new ProductInCartModel
                        {
                            Id       = product.Id,
                            Name     = currentProduct.Name,
                            ImageUrl = currentProduct.Images
                                       .Reverse()
                                       .FirstOrDefault(),

                            Quantity = remainingQuantityToBeGivenAsPromotion,
                            Price    = currentProduct.Price,
                            Discount = promotionDisount
                        };

                        ProductInCartModel productNotDiscounted = new ProductInCartModel
                        {
                            Id       = product.Id,
                            Name     = currentProduct.Name,
                            ImageUrl = currentProduct.Images
                                       .Reverse()
                                       .FirstOrDefault(),

                            Quantity = product.Quantity - remainingQuantityToBeGivenAsPromotion,
                            Price    = currentProduct.Price,
                            Discount = includePriceDiscounts ? currentProduct.Discount : 0
                        };

                        result.Cart.Add(discounted);

                        result.Cart.Add(productNotDiscounted);

                        quantityGivenAsPromotion += remainingQuantityToBeGivenAsPromotion;
                    }

                    else
                    {
                        ProductInCartModel discounted = new ProductInCartModel
                        {
                            Id       = product.Id,
                            Name     = currentProduct.Name,
                            ImageUrl = currentProduct.Images
                                       .Reverse()
                                       .FirstOrDefault(),

                            Quantity = product.Quantity,
                            Price    = currentProduct.Price,
                            Discount = promotionDisount
                        };

                        result.Cart.Add(discounted);

                        quantityGivenAsPromotion += product.Quantity;
                    }
                }

                else
                {
                    product.Name = currentProduct.Name;

                    product.ImageUrl = currentProduct.Images.Reverse().FirstOrDefault();

                    product.Price = currentProduct.Price;

                    product.Discount = !includePriceDiscounts && productsInPromotionFromCart.Contains(product.Id) ? 0 : currentProduct.Discount;

                    result.Cart.Add(product);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 public void AddViewToCollection(ProductDetailsModel product)
 {
     this.view.Add(product);
 }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateProductDetails(int productId, string itemType, int bundleItemId, ProductVariantQuery query)
        {
            // TODO: (core) UpdateProductDetails action needs some decent refactoring.
            var    form              = HttpContext.Request.Form;
            var    quantity          = 1;
            var    galleryStartIndex = -1;
            string galleryHtml       = null;
            string dynamicThumbUrl   = null;
            var    isAssociated      = itemType.EqualsNoCase("associateditem");
            var    currency          = Services.WorkContext.WorkingCurrency;
            var    displayPrices     = await Services.Permissions.AuthorizeAsync(Permissions.Catalog.DisplayPrice);

            var product = await _db.Products.FindByIdAsync(productId);

            var batchContext = _productService.CreateProductBatchContext(new[] { product }, includeHidden: false);
            var bundleItem   = await _db.ProductBundleItem
                               .Include(x => x.BundleProduct)
                               .FindByIdAsync(bundleItemId, false);

            // Quantity required for tier prices.
            string quantityKey = form.Keys.FirstOrDefault(k => k.EndsWith("EnteredQuantity"));

            if (quantityKey.HasValue())
            {
                _ = int.TryParse(form[quantityKey], out quantity);
            }

            var modelContext = new ProductDetailsModelContext
            {
                Product             = product,
                BatchContext        = batchContext,
                VariantQuery        = query,
                IsAssociatedProduct = isAssociated,
                ProductBundleItem   = bundleItem,
                Customer            = batchContext.Customer,
                Store         = batchContext.Store,
                Currency      = currency,
                DisplayPrices = displayPrices
            };

            // Get merged model data.
            var model = new ProductDetailsModel();
            await _helper.PrepareProductDetailModelAsync(model, modelContext, quantity);

            if (bundleItem != null)
            {
                // Update bundle item thumbnail.
                if (!bundleItem.HideThumbnail)
                {
                    var assignedMediaIds = model.SelectedCombination?.GetAssignedMediaIds() ?? Array.Empty <int>();

                    if (assignedMediaIds.Any() && await _db.MediaFiles.AnyAsync(x => x.Id == assignedMediaIds[0]))
                    {
                        var file = await _db.ProductMediaFiles
                                   .AsNoTracking()
                                   .Include(x => x.MediaFile)
                                   .ApplyProductFilter(bundleItem.ProductId)
                                   .FirstOrDefaultAsync();

                        dynamicThumbUrl = _mediaService.GetUrl(file?.MediaFile, _mediaSettings.BundledProductPictureSize, null, false);
                    }
                }
            }
            else if (isAssociated)
            {
                // Update associated product thumbnail.
                var assignedMediaIds = model.SelectedCombination?.GetAssignedMediaIds() ?? Array.Empty <int>();

                if (assignedMediaIds.Any() && await _db.MediaFiles.AnyAsync(x => x.Id == assignedMediaIds[0]))
                {
                    var file = await _db.ProductMediaFiles
                               .AsNoTracking()
                               .Include(x => x.MediaFile)
                               .ApplyProductFilter(productId)
                               .FirstOrDefaultAsync();

                    dynamicThumbUrl = _mediaService.GetUrl(file?.MediaFile, _mediaSettings.AssociatedProductPictureSize, null, false);
                }
            }
            else if (product.ProductType != ProductType.BundledProduct)
            {
                // Update image gallery.
                var files = await _db.ProductMediaFiles
                            .AsNoTracking()
                            .Include(x => x.MediaFile)
                            .ApplyProductFilter(productId)
                            .ToListAsync();

                if (product.HasPreviewPicture && files.Count > 1)
                {
                    files.RemoveAt(0);
                }

                if (files.Count <= _catalogSettings.DisplayAllImagesNumber)
                {
                    // All pictures rendered... only index is required.
                    galleryStartIndex = 0;

                    var assignedMediaIds = model.SelectedCombination?.GetAssignedMediaIds() ?? Array.Empty <int>();
                    if (assignedMediaIds.Any())
                    {
                        var file = files.FirstOrDefault(p => p.Id == assignedMediaIds[0]);
                        galleryStartIndex = file == null ? 0 : files.IndexOf(file);
                    }
                }
                else
                {
                    var allCombinationPictureIds = await _productAttributeService.GetAttributeCombinationFileIdsAsync(product.Id);

                    var mediaFiles = files
                                     .Where(x => x.MediaFile != null)
                                     .Select(x => _mediaService.ConvertMediaFile(x.MediaFile))
                                     .ToList();

                    var mediaModel = _helper.PrepareProductDetailsMediaGalleryModel(
                        mediaFiles,
                        product.GetLocalized(x => x.Name),
                        allCombinationPictureIds,
                        false,
                        bundleItem,
                        model.SelectedCombination);

                    galleryStartIndex = mediaModel.GalleryStartIndex;
                    galleryHtml       = (await this.InvokeViewAsync("Product.Media", mediaModel)).ToString();
                }

                model.PriceDisplayStyle        = _catalogSettings.PriceDisplayStyle;
                model.DisplayTextForZeroPrices = _catalogSettings.DisplayTextForZeroPrices;
            }

            object partials = null;

            if (model.IsBundlePart)
            {
                partials = new
                {
                    BundleItemPrice    = await this.InvokeViewAsync("Product.Offer.Price", model),
                    BundleItemStock    = await this.InvokeViewAsync("Product.StockInfo", model),
                    BundleItemVariants = await this.InvokeViewAsync("Product.Variants", model.ProductVariantAttributes)
                };
            }
            else
            {
                var dataDictAddToCart = new ViewDataDictionary(ViewData)
                {
                    Model = model
                };
                dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = $"addtocart_{model.Id}";

                partials = new
                {
                    Attrs        = await this.InvokeViewAsync("Product.Attrs", model),
                    Price        = await this.InvokeViewAsync("Product.Offer.Price", model),
                    Stock        = await this.InvokeViewAsync("Product.StockInfo", model),
                    Variants     = await this.InvokeViewAsync("Product.Variants", model.ProductVariantAttributes),
                    OfferActions = await this.InvokeViewAsync("Product.Offer.Actions", dataDictAddToCart),
                    TierPrices   = await this.InvokeViewAsync("Product.TierPrices", model.TierPrices),
                    BundlePrice  = product.ProductType == ProductType.BundledProduct ? await this.InvokeViewAsync("Product.Bundle.Price", model) : null
                };
            }

            object data = new
            {
                Partials          = partials,
                DynamicThumblUrl  = dynamicThumbUrl,
                GalleryStartIndex = galleryStartIndex,
                GalleryHtml       = galleryHtml
            };

            return(new JsonResult(data));
        }
Exemplo n.º 5
0
        private async Task <CartPromotionResultModel> CalculateNotInclusivePromotion(Promotion promotion, CartPromotionCheckModel data, int productsInPromotionCount, IList <string> productsInPromotionFromCart)
        {
            CartPromotionResultModel result = new CartPromotionResultModel
            {
                Cart = new List <ProductInCartModel>()
            };

            int quantityToBeGivenAsPromotion = promotion.IsAccumulative
                ? (productsInPromotionCount / promotion.ProductsCount) * promotion.DiscountedProductsCount
                : promotion.DiscountedProductsCount;

            bool includePriceDiscounts = promotion.IncludePriceDiscounts;

            decimal promotionDiscount = promotion.Discount;

            IList <string> freeProductIds = await this.db.DiscountedProductsPromotions
                                            .Where(d => d.PromotionId == promotion.Id)
                                            .Select(p => p.ProductId)
                                            .ToListAsync();

            //if (freeProductIds.Count == 1)
            //{
            //    string freeProductId = freeProductIds.FirstOrDefault();

            //    ProductDetailsModel productDetails = await this.products.Get(freeProductId);

            //    if (includePriceDiscounts) promotionDiscount += productDetails.Discount;

            //    if (promotionDiscount > 100) promotionDiscount = 100;

            //    ProductInCartModel freeProduct = new ProductInCartModel
            //    {
            //        Id = freeProductId,
            //        Name = productDetails.Name,
            //        ImageUrl = productDetails.Images.Reverse().FirstOrDefault(),

            //        Quantity = quantityToBeGivenAsPromotion,
            //        Price = productDetails.Price,
            //        Discount = promotionDiscount
            //    };

            //    result.Cart.Add(freeProduct);
            //}
            //else
            //{

            result.DiscountedProductsCount = quantityToBeGivenAsPromotion;

            result.DiscountedProducts = new List <ProductDetailsModel>();

            foreach (string id in freeProductIds)
            {
                ProductDetailsModel product = await this.products.Get(id);

                result.DiscountedProducts.Add(product);
            }

            if (!includePriceDiscounts)
            {
                foreach (ProductDetailsModel product in result.DiscountedProducts)
                {
                    product.Discount = promotion.Discount;
                }
            }
            else
            {
                foreach (ProductDetailsModel product in result.DiscountedProducts)
                {
                    product.Discount += promotionDiscount;

                    if (product.Discount > 100)
                    {
                        product.Discount = 100;
                    }
                }
            }
            //}

            foreach (ProductInCartModel product in data.Products)
            {
                ProductDetailsModel currentProduct = await this.products.Get(product.Id);

                decimal discount = currentProduct.Discount;

                if (productsInPromotionFromCart.Contains(currentProduct.Id) && !includePriceDiscounts)
                {
                    discount = 0;
                }

                ProductInCartModel modifiedProduct = new ProductInCartModel
                {
                    Id       = product.Id,
                    Name     = currentProduct.Name,
                    ImageUrl = currentProduct.Images
                               .Reverse()
                               .FirstOrDefault(),

                    Quantity = product.Quantity,
                    Price    = currentProduct.Price,
                    Discount = discount
                };

                result.Cart.Add(modifiedProduct);
            }

            return(result);
        }
Exemplo n.º 6
0
        public ActionResult UpdateProductDetails(int productId, string itemType, int bundleItemId, ProductVariantQuery query, FormCollection form)
        {
            int    quantity          = 1;
            int    galleryStartIndex = -1;
            string galleryHtml       = null;
            string dynamicThumbUrl   = null;
            var    isAssociated      = itemType.IsCaseInsensitiveEqual("associateditem");
            var    pictureModel      = new ProductDetailsPictureModel();
            var    m       = new ProductDetailsModel();
            var    product = _productService.GetProductById(productId);
            var    bItem   = _productService.GetBundleItemById(bundleItemId);
            IList <ProductBundleItemData> bundleItems = null;
            ProductBundleItemData         bundleItem  = bItem == null ? null : new ProductBundleItemData(bItem);

            // Quantity required for tier prices.
            string quantityKey = form.AllKeys.FirstOrDefault(k => k.EndsWith("EnteredQuantity"));

            if (quantityKey.HasValue())
            {
                int.TryParse(form[quantityKey], out quantity);
            }

            if (product.ProductType == ProductType.BundledProduct && product.BundlePerItemPricing)
            {
                bundleItems = _productService.GetBundleItems(product.Id);
                if (query.Variants.Count > 0)
                {
                    // May add elements to query object if they are preselected by bundle item filter.
                    foreach (var itemData in bundleItems)
                    {
                        _helper.PrepareProductDetailsPageModel(itemData.Item.Product, query, false, itemData, null);
                    }
                }
            }

            // Get merged model data.
            _helper.PrepareProductDetailModel(m, product, query, isAssociated, bundleItem, bundleItems, quantity);

            if (bundleItem != null)
            {
                // Update bundle item thumbnail.
                if (!bundleItem.Item.HideThumbnail)
                {
                    var assignedMediaIds = m.SelectedCombination?.GetAssignedMediaIds() ?? new int[0];
                    if (assignedMediaIds.Any() && _mediaService.GetFileById(assignedMediaIds[0], MediaLoadFlags.AsNoTracking) != null)
                    {
                        var file = _productService.GetProductPicturesByProductId(bundleItem.Item.ProductId, 1)
                                   .Select(x => x.MediaFile)
                                   .FirstOrDefault();

                        dynamicThumbUrl = _mediaService.GetUrl(file, _mediaSettings.BundledProductPictureSize, null, false);
                    }
                }
            }
            else if (isAssociated)
            {
                // Update associated product thumbnail.
                var assignedMediaIds = m.SelectedCombination?.GetAssignedMediaIds() ?? new int[0];
                if (assignedMediaIds.Any() && _mediaService.GetFileById(assignedMediaIds[0], MediaLoadFlags.AsNoTracking) != null)
                {
                    var file = _productService.GetProductPicturesByProductId(productId, 1)
                               .Select(x => x.MediaFile)
                               .FirstOrDefault();

                    dynamicThumbUrl = _mediaService.GetUrl(file, _mediaSettings.AssociatedProductPictureSize, null, false);
                }
            }
            else if (product.ProductType != ProductType.BundledProduct)
            {
                // Update image gallery.
                var files = _productService.GetProductPicturesByProductId(productId)
                            .Select(x => x.MediaFile)
                            .ToList();

                if (product.HasPreviewPicture && files.Count > 1)
                {
                    files.RemoveAt(0);
                }

                if (files.Count <= _catalogSettings.DisplayAllImagesNumber)
                {
                    // All pictures rendered... only index is required.
                    galleryStartIndex = 0;

                    var assignedMediaIds = m.SelectedCombination?.GetAssignedMediaIds() ?? new int[0];
                    if (assignedMediaIds.Any())
                    {
                        var file = files.FirstOrDefault(p => p.Id == assignedMediaIds[0]);
                        galleryStartIndex = file == null ? 0 : files.IndexOf(file);
                    }
                }
                else
                {
                    var allCombinationPictureIds = _productAttributeService.GetAllProductVariantAttributeCombinationPictureIds(product.Id);

                    _helper.PrepareProductDetailsPictureModel(
                        pictureModel,
                        files,
                        product.GetLocalized(x => x.Name),
                        allCombinationPictureIds,
                        false,
                        bundleItem,
                        m.SelectedCombination);

                    galleryStartIndex = pictureModel.GalleryStartIndex;
                    galleryHtml       = this.RenderPartialViewToString("Product.Picture", pictureModel);
                }

                m.PriceDisplayStyle        = _catalogSettings.PriceDisplayStyle;
                m.DisplayTextForZeroPrices = _catalogSettings.DisplayTextForZeroPrices;
            }

            object partials = null;

            if (m.IsBundlePart)
            {
                partials = new
                {
                    BundleItemPrice = this.RenderPartialViewToString("Product.Offer.Price", m),
                    BundleItemStock = this.RenderPartialViewToString("Product.StockInfo", m)
                };
            }
            else
            {
                var dataDictAddToCart = new ViewDataDictionary();
                dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", m.Id);

                decimal adjustment = decimal.Zero;
                decimal taxRate    = decimal.Zero;
                var     finalPriceWithDiscountBase = _taxService.GetProductPrice(product, product.Price, _services.WorkContext.CurrentCustomer, out taxRate);

                if (!_taxSettings.Value.PricesIncludeTax && _services.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    adjustment = (m.ProductPrice.PriceValue - finalPriceWithDiscountBase) / (taxRate / 100 + 1);
                }
                else if (_taxSettings.Value.PricesIncludeTax && _services.WorkContext.TaxDisplayType == TaxDisplayType.ExcludingTax)
                {
                    adjustment = (m.ProductPrice.PriceValue - finalPriceWithDiscountBase) * (taxRate / 100 + 1);
                }
                else
                {
                    adjustment = m.ProductPrice.PriceValue - finalPriceWithDiscountBase;
                }

                partials = new
                {
                    Attrs        = this.RenderPartialViewToString("Product.Attrs", m),
                    Price        = this.RenderPartialViewToString("Product.Offer.Price", m),
                    Stock        = this.RenderPartialViewToString("Product.StockInfo", m),
                    OfferActions = this.RenderPartialViewToString("Product.Offer.Actions", m, dataDictAddToCart),
                    TierPrices   = this.RenderPartialViewToString("Product.TierPrices", _helper.CreateTierPriceModel(product, adjustment)),
                    BundlePrice  = product.ProductType == ProductType.BundledProduct ? this.RenderPartialViewToString("Product.Bundle.Price", m) : (string)null
                };
            }

            object data = new
            {
                Partials          = partials,
                DynamicThumblUrl  = dynamicThumbUrl,
                GalleryStartIndex = galleryStartIndex,
                GalleryHtml       = galleryHtml
            };

            return(new JsonResult {
                Data = data
            });
        }
Exemplo n.º 7
0
        protected ProductDetailsModel PrepareProductDetailsModel(ProductOverviewModel product, int?selectedPriceId = null)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            #region Standard properties

            var model = new ProductDetailsModel
            {
                Id                  = product.Id,
                Name                = string.IsNullOrWhiteSpace(product.H1Title) ? product.Name : product.H1Title,
                ShortDescription    = product.ShortDescription,
                FullDescription     = product.FullDescription,
                DeliveryTimeLine    = product.DeliveryTimeLine,
                OptionType          = product.OptionType,
                AverageReviewRating = product.AverageReviewRating,
                IsPhoneOrder        = product.IsPhoneOrder,
                PhoneOrderMessage   = product.IsPhoneOrder ? _catalogSettings.PhoneOrderMessage : string.Empty,
                UrlKey              = product.UrlKey,
                Enabled             = product.Enabled,
                Discontinued        = product.Discontinued,
                MetaDescription     = product.MetaDescription,
                MetaKeywords        = product.MetaKeywords,
                MetaTitle           = product.MetaTitle
            };

            #endregion

            #region Brand

            var brand = _brandService.GetBrandById(product.BrandId);
            if (brand != null)
            {
                PictureModel brandPicture = null;
                if (string.IsNullOrEmpty(brand.FlashImage) == false)
                {
                    brandPicture = new PictureModel
                    {
                        AlternateText = brand.Name,
                        Title         = brand.Name,
                        ImageUrl      = "/media/brand/" + brand.FlashImage
                    };
                }
                var productBrandModel = new ProductBrandModel();
                productBrandModel.Picture  = brandPicture;
                productBrandModel.Name     = brand.Name;
                productBrandModel.BrandUrl = Url.RouteUrl("Brand", new { urlKey = brand.UrlRewrite }, Request.Url.Scheme);
                productBrandModel.Visible  = true;

                model.ProductBrand = productBrandModel;
            }

            #endregion

            #region Pictures

            var medias              = product.Images;
            var defaultPicture      = medias.Where(x => x.Enabled == true).FirstOrDefault();
            var defaultPictureModel = new PictureModel();
            if (defaultPicture != null)
            {
                defaultPictureModel = new PictureModel
                {
                    Title            = product.Name,
                    AlternateText    = product.Name,
                    ImageUrl         = string.Format("/media/product/{0}", defaultPicture.ThumbnailFilename),
                    FullSizeImageUrl = string.Format("/media/product/{0}", string.IsNullOrEmpty(defaultPicture.HighResFilename) ? defaultPicture.MediaFilename : defaultPicture.HighResFilename)
                };
            }

            var pictureModels = new List <PictureModel>();
            foreach (var picture in medias)
            {
                if (picture.Enabled)
                {
                    pictureModels.Add(new PictureModel
                    {
                        Id               = picture.Id,
                        Title            = product.Name,
                        AlternateText    = product.Name,
                        ImageUrl         = string.Format("/media/product/{0}", picture.ThumbnailFilename),
                        FullSizeImageUrl = string.Format("/media/product/{0}", string.IsNullOrEmpty(picture.HighResFilename) ? picture.MediaFilename : picture.HighResFilename)
                    });
                }
            }

            model.DefaultPicture = defaultPictureModel;
            model.PictureModels  = pictureModels;

            #endregion

            #region Product prices

            var productPrices = _productService.GetProductPricesByProductId(product.Id);
            productPrices = productPrices.OrderBy(pp => pp.Priority).ToList();

            var defaultProductPrice = productPrices.Where(x => x.Stock > 0).FirstOrDefault();
            if (defaultProductPrice == null)
            {
                defaultProductPrice = productPrices.Where(x => x.Enabled == true).FirstOrDefault();
            }

            if (selectedPriceId.HasValue)
            {
                var found = productPrices.Where(x => x.Id == selectedPriceId.Value).FirstOrDefault();
                if (found != null)
                {
                    defaultProductPrice = found;
                }
            }

            var defaultProductPriceModel = new ProductPriceModel();
            if (defaultProductPrice != null)
            {
                defaultProductPriceModel = defaultProductPrice.PrepareProductPriceModel(
                    product.OptionType,
                    product.Discontinued,
                    product.ProductEnforcedStockCount,
                    product.BrandEnforcedStockCount,
                    isPreSelected: true);
            }
            model.DefaultProductPrice = defaultProductPriceModel;

            foreach (var item in productPrices)
            {
                var price = item.PrepareProductPriceModel(
                    product.OptionType,
                    product.Discontinued,
                    product.ProductEnforcedStockCount,
                    product.BrandEnforcedStockCount,
                    isPreSelected: item.Id == defaultProductPriceModel.Id);

                model.ProductPrices.Add(price);
            }

            #endregion

            #region Add to cart

            model.AddToCart = PrepareAddToCartModel(product, defaultProductPrice);

            #endregion

            #region Product offer

            if (defaultProductPrice != null && (defaultProductPrice.OfferRuleId > 0))
            {
                var offerRule = _offerService.GetOfferRuleById(defaultProductPrice.OfferRuleId);
                if (offerRule != null &&
                    offerRule.ShowCountDown &&
                    offerRule.EndDate != null &&
                    offerRule.EndDate.Value != DateTime.MinValue &&
                    offerRule.EndDate.Value.CompareTo(DateTime.Now) >= 0)
                {
                    model.ProductOffer = new ProductOfferModel
                    {
                        ExpiryDate = offerRule.EndDate.Value,
                        Visible    = true
                    };
                }
            }

            #endregion

            #region Product tags

            var productTags = _productService.GetProductTagsByProductId(product.Id);

            if (productTags != null)
            {
                foreach (var productTag in productTags)
                {
                    model.ProductTags.Add(new ProductTagModel
                    {
                        Id          = productTag.TagId,
                        Tag         = productTag.Tag.Name,
                        Description = productTag.Value
                    });
                }
            }

            #endregion

            #region Product reviews

            var reviews = _productService.GetApprovedProductReviewsByProductId(product.Id);

            if (reviews != null)
            {
                foreach (var review in reviews)
                {
                    model.Reviews.Add(new ProductReviewModel
                    {
                        Title     = review.Title,
                        Comment   = review.Comment,
                        Score     = review.Score,
                        Alias     = review.Alias,
                        TimeStamp = review.TimeStamp
                    });
                }
            }

            #endregion

            #region Breadcrumb

            model.ProductBreadcrumb = PrepareProductBreadcrumbModel(product.Id);

            #endregion

            return(model);
        }
        /// <summary>
        /// Prepare the product details model
        /// </summary>
        /// <param name="product">Product</param>
        /// <param name="isAssociatedProduct">Whether the product is associated</param>
        /// <returns>Product details model</returns>
        public virtual ProductDetailsModel PrepareProductDetailsModel(Product product,
                                                                      bool isAssociatedProduct = false)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            //standard properties
            var model = new ProductDetailsModel
            {
                Id                         = product.Id,
                Name                       = _localizationService.GetLocalized(product, x => x.Name),
                ShortDescription           = _localizationService.GetLocalized(product, x => x.ShortDescription),
                FullDescription            = _localizationService.GetLocalized(product, x => x.FullDescription),
                MetaKeywords               = _localizationService.GetLocalized(product, x => x.MetaKeywords),
                MetaDescription            = _localizationService.GetLocalized(product, x => x.MetaDescription),
                MetaTitle                  = _localizationService.GetLocalized(product, x => x.MetaTitle),
                SeName                     = _urlRecordService.GetSeName(product),
                ProductType                = product.ProductType,
                DisplayDiscontinuedMessage = !product.Published && _catalogSettings.DisplayDiscontinuedMessageForUnpublishedProducts
            };

            //automatically generate product description?
            if (_seoSettings.GenerateProductMetaDescription && string.IsNullOrEmpty(model.MetaDescription))
            {
                //based on short description
                model.MetaDescription = model.ShortDescription;
            }

            //email a friend
            model.EmailAFriendEnabled = _catalogSettings.EmailAFriendEnabled;
            //store name
            model.CurrentStoreName = _localizationService.GetLocalized(_storeContext.CurrentStore, x => x.Name);

            //vendor details
            if (_vendorSettings.ShowVendorOnProductDetailsPage)
            {
                var vendor = _vendorService.GetVendorById(product.VendorId);
                if (vendor != null && !vendor.Deleted && vendor.Active)
                {
                    model.ShowVendor = true;

                    model.VendorModel = new VendorBriefInfoModel
                    {
                        Id     = vendor.Id,
                        Name   = _localizationService.GetLocalized(vendor, x => x.Name),
                        SeName = _urlRecordService.GetSeName(vendor),
                    };
                }
            }

            //page sharing
            if (_catalogSettings.ShowShareButton && !string.IsNullOrEmpty(_catalogSettings.PageShareCode))
            {
                var shareCode = _catalogSettings.PageShareCode;
                if (_webHelper.IsCurrentConnectionSecured())
                {
                    //need to change the add this link to be https linked when the page is, so that the page doesn't ask about mixed mode when viewed in https...
                    shareCode = shareCode.Replace("http://", "https://");
                }
                model.PageShareCode = shareCode;
            }

            //breadcrumb
            //do not prepare this model for the associated products. anyway it's not used
            if (_catalogSettings.CategoryBreadcrumbEnabled && !isAssociatedProduct)
            {
                model.Breadcrumb = PrepareProductBreadcrumbModel(product);
            }

            //product tags
            //do not prepare this model for the associated products. anyway it's not used
            if (!isAssociatedProduct)
            {
                model.ProductTags = PrepareProductTagModels(product);
            }

            //pictures
            model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled;
            model.DefaultPictureModel       = PrepareProductDetailsPictureModel(product, isAssociatedProduct, out IList <PictureModel> allPictureModels);
            model.PictureModels             = allPictureModels;


            //product review overview
            model.ProductReviewOverview = PrepareProductReviewOverviewModel(product);

            //associated products
            if (product.ProductType == ProductType.GroupedProduct)
            {
                //ensure no circular references
                if (!isAssociatedProduct)
                {
                    var associatedProducts = _productService.GetAssociatedProducts(product.Id, _storeContext.CurrentStore.Id);
                    foreach (var associatedProduct in associatedProducts)
                    {
                        model.AssociatedProducts.Add(PrepareProductDetailsModel(associatedProduct, true));
                    }
                }
            }

            return(model);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> UpdateProductDetails(int productId, string itemType, int bundleItemId, ProductVariantQuery query)
        {
            // TODO: (core) UpdateProductDetails action needs some decent refactoring.
            var    form              = HttpContext.Request.Form;
            int    quantity          = 1;
            int    galleryStartIndex = -1;
            string galleryHtml       = null;
            string dynamicThumbUrl   = null;
            var    isAssociated      = itemType.EqualsNoCase("associateditem");

            var product = await _db.Products.FindByIdAsync(productId);

            var batchContext = _productService.CreateProductBatchContext(new[] { product }, includeHidden: false);
            var bItem        = await _db.ProductBundleItem
                               .Include(x => x.BundleProduct)
                               .FindByIdAsync(bundleItemId, false);

            IList <ProductBundleItemData> bundleItemDatas = null;
            ProductBundleItemData         bundleItem      = bItem == null ? null : new ProductBundleItemData(bItem);

            // Quantity required for tier prices.
            string quantityKey = form.Keys.FirstOrDefault(k => k.EndsWith("EnteredQuantity"));

            if (quantityKey.HasValue())
            {
                _ = int.TryParse(form[quantityKey], out quantity);
            }

            if (product.ProductType == ProductType.BundledProduct && product.BundlePerItemPricing)
            {
                var bundleItemQuery = await _db.ProductBundleItem
                                      .AsNoTracking()
                                      .ApplyBundledProductsFilter(new[] { product.Id })
                                      .Include(x => x.Product)
                                      .Include(x => x.BundleProduct)
                                      .ToListAsync();

                if (bundleItemQuery.Count > 0)
                {
                    bundleItemDatas = new List <ProductBundleItemData>();
                    bundleItemQuery.Each(x => bundleItemDatas.Add(new ProductBundleItemData(x)));
                }

                if (query.Variants.Count > 0)
                {
                    batchContext.Collect(bundleItemDatas.Select(x => x.Item.Product.Id).ToArray());

                    // May add elements to query object if they are preselected by bundle item filter.
                    foreach (var itemData in bundleItemDatas)
                    {
                        await _helper.MapProductDetailsPageModelAsync(new ProductDetailsModelContext
                        {
                            Product           = itemData.Item.Product,
                            BatchContext      = batchContext,
                            VariantQuery      = query,
                            ProductBundleItem = itemData
                        });
                    }
                }
            }

            var modelContext = new ProductDetailsModelContext
            {
                Product             = product,
                BatchContext        = batchContext,
                VariantQuery        = query,
                IsAssociatedProduct = isAssociated,
                ProductBundleItem   = bundleItem,
                BundleItemDatas     = bundleItemDatas,
                Customer            = batchContext.Customer,
                Store    = batchContext.Store,
                Currency = Services.WorkContext.WorkingCurrency
            };

            // Get merged model data.
            var model = new ProductDetailsModel();
            await _helper.PrepareProductDetailModelAsync(model, modelContext, quantity);

            if (bundleItem != null)
            {
                // Update bundle item thumbnail.
                if (!bundleItem.Item.HideThumbnail)
                {
                    var assignedMediaIds = model.SelectedCombination?.GetAssignedMediaIds() ?? Array.Empty <int>();
                    var hasFile          = assignedMediaIds.Any() && await _db.MediaFiles.AnyAsync(x => x.Id == assignedMediaIds[0]);

                    if (assignedMediaIds.Any() && hasFile)
                    {
                        var file = await _db.ProductMediaFiles
                                   .AsNoTracking()
                                   .ApplyProductFilter(new[] { bundleItem.Item.ProductId }, 1)
                                   .Select(x => x.MediaFile)
                                   .FirstOrDefaultAsync();

                        dynamicThumbUrl = _mediaService.GetUrl(file, _mediaSettings.BundledProductPictureSize, null, false);
                    }
                }
            }
            else if (isAssociated)
            {
                // Update associated product thumbnail.
                var assignedMediaIds = model.SelectedCombination?.GetAssignedMediaIds() ?? new int[0];
                var hasFile          = await _db.MediaFiles.AnyAsync(x => x.Id == assignedMediaIds[0]);

                if (assignedMediaIds.Any() && hasFile)
                {
                    var file = await _db.ProductMediaFiles
                               .AsNoTracking()
                               .ApplyProductFilter(new[] { productId }, 1)
                               .Select(x => x.MediaFile)
                               .FirstOrDefaultAsync();

                    dynamicThumbUrl = _mediaService.GetUrl(file, _mediaSettings.AssociatedProductPictureSize, null, false);
                }
            }
            else if (product.ProductType != ProductType.BundledProduct)
            {
                // Update image gallery.
                var files = await _db.ProductMediaFiles
                            .AsNoTracking()
                            .ApplyProductFilter(new[] { productId })
                            .Select(x => _mediaService.ConvertMediaFile(x.MediaFile))
                            .ToListAsync();

                if (product.HasPreviewPicture && files.Count > 1)
                {
                    files.RemoveAt(0);
                }

                if (files.Count <= _catalogSettings.DisplayAllImagesNumber)
                {
                    // All pictures rendered... only index is required.
                    galleryStartIndex = 0;

                    var assignedMediaIds = model.SelectedCombination?.GetAssignedMediaIds() ?? new int[0];
                    if (assignedMediaIds.Any())
                    {
                        var file = files.FirstOrDefault(p => p.Id == assignedMediaIds[0]);
                        galleryStartIndex = file == null ? 0 : files.IndexOf(file);
                    }
                }
                else
                {
                    var allCombinationPictureIds = await _productAttributeService.GetAttributeCombinationFileIdsAsync(product.Id);

                    var mediaModel = _helper.PrepareProductDetailsMediaGalleryModel(
                        files,
                        product.GetLocalized(x => x.Name),
                        allCombinationPictureIds,
                        false,
                        bundleItem,
                        model.SelectedCombination);

                    galleryStartIndex = mediaModel.GalleryStartIndex;
                    galleryHtml       = (await this.InvokeViewAsync("Product.Media", mediaModel)).ToString();
                }

                model.PriceDisplayStyle        = _catalogSettings.PriceDisplayStyle;
                model.DisplayTextForZeroPrices = _catalogSettings.DisplayTextForZeroPrices;
            }

            object partials = null;

            if (model.IsBundlePart)
            {
                partials = new
                {
                    BundleItemPrice    = await this.InvokeViewAsync("Product.Offer.Price", model),
                    BundleItemStock    = await this.InvokeViewAsync("Product.StockInfo", model),
                    BundleItemVariants = await this.InvokeViewAsync("Product.Variants", model.ProductVariantAttributes)
                };
            }
            else
            {
                var dataDictAddToCart = new ViewDataDictionary(ViewData);
                dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = $"addtocart_{model.Id}";

                decimal adjustment = decimal.Zero;
                decimal taxRate    = decimal.Zero;

                // TODO: (mh) (core) Implement when pricing is available.
                //var finalPriceWithDiscountBase = _taxService.GetProductPrice(product, product.Price, Services.WorkContext.CurrentCustomer, out taxRate);

                //if (!_taxSettings.Value.PricesIncludeTax && Services.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax)
                //{
                //    adjustment = (m.ProductPrice.PriceValue - finalPriceWithDiscountBase) / (taxRate / 100 + 1);
                //}
                //else if (_taxSettings.Value.PricesIncludeTax && Services.WorkContext.TaxDisplayType == TaxDisplayType.ExcludingTax)
                //{
                //    adjustment = (m.ProductPrice.PriceValue - finalPriceWithDiscountBase) * (taxRate / 100 + 1);
                //}
                //else
                //{
                //    adjustment = m.ProductPrice.PriceValue - finalPriceWithDiscountBase;
                //}

                partials = new
                {
                    Attrs    = await this.InvokeViewAsync("Product.Attrs", model),
                    Price    = await this.InvokeViewAsync("Product.Offer.Price", model),
                    Stock    = await this.InvokeViewAsync("Product.StockInfo", model),
                    Variants = await this.InvokeViewAsync("Product.Variants", model.ProductVariantAttributes),

                    // TODO: (mc) (core) We may need another parameter for this.
                    //OfferActions = await _razorViewInvoker.Value.InvokeViewAsync("Product.Offer.Actions", m, dataDictAddToCart),

                    // TODO: (mh) (core) Implement when Component or Partial is available.
                    //TierPrices = await _razorViewInvoker.Value.InvokeViewAsync("Product.TierPrices", await _razorViewInvoker.InvokeViewAsync(product, adjustment)),
                    BundlePrice = product.ProductType == ProductType.BundledProduct ? await this.InvokeViewAsync("Product.Bundle.Price", model) : null
                };
            }

            object data = new
            {
                Partials          = partials,
                DynamicThumblUrl  = dynamicThumbUrl,
                GalleryStartIndex = galleryStartIndex,
                GalleryHtml       = galleryHtml
            };

            return(new JsonResult(new { Data = data }));
        }
Exemplo n.º 10
0
        public static MergeModel GetMergeModel(Collection <int> ids, TranBook tranBook, SubTranBook subTranBook)
        {
            int rowIndex = 0;

            if (ids == null)
            {
                return(new MergeModel());
            }

            if (ids.Count.Equals(0))
            {
                return(new MergeModel());
            }

            MergeModel model = new MergeModel();

            foreach (int tranId in ids)
            {
                model.AddTransactionIdToCollection(tranId);
            }

            model.Book    = tranBook;
            model.SubBook = subTranBook;

            using (NpgsqlConnection connection = new NpgsqlConnection(DbConnection.ConnectionString()))
            {
                using (NpgsqlCommand command = GetViewCommand(tranBook, subTranBook, ids))
                {
                    command.Connection = connection;
                    command.Connection.Open();
                    NpgsqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);

                    if (!reader.HasRows)
                    {
                        return(new MergeModel());
                    }

                    while (reader.Read())
                    {
                        if (rowIndex.Equals(0))
                        {
                            model.ValueDate          = Conversion.TryCastDate(reader["value_date"]);
                            model.PartyCode          = Conversion.TryCastString(reader["party_code"]);
                            model.PriceTypeId        = Conversion.TryCastInteger(reader["price_type_id"]);
                            model.ReferenceNumber    = Conversion.TryCastString(reader["reference_number"]);
                            model.StatementReference = Conversion.TryCastString(reader["statement_reference"]);
                        }

                        ProductDetailsModel product = new ProductDetailsModel();

                        product.ItemCode = Conversion.TryCastString(reader["item_code"]);
                        product.ItemName = Conversion.TryCastString(reader["item_name"]);
                        product.Unit     = Conversion.TryCastString(reader["unit_name"]);


                        product.Quantity = Conversion.TryCastInteger(reader["quantity"]);
                        product.Price    = Conversion.TryCastDecimal(reader["price"]);
                        product.Amount   = product.Quantity * product.Price;

                        product.Discount = Conversion.TryCastDecimal(reader["discount"]);
                        product.Subtotal = product.Amount - product.Discount;

                        product.Rate  = Conversion.TryCastDecimal(reader["tax_rate"]);
                        product.Tax   = Conversion.TryCastDecimal(reader["tax"]);
                        product.Total = product.Subtotal + product.Tax;

                        model.AddViewToCollection(product);

                        rowIndex++;
                    }
                }
            }

            if (ids.Count > 0)
            {
                if (!string.IsNullOrWhiteSpace(model.StatementReference))
                {
                    model.StatementReference += Environment.NewLine;
                }

                model.StatementReference += "(" + Conversion.GetBookAcronym(tranBook, subTranBook) + "# " + string.Join(",", ids) + ")";
            }

            return(model);
        }
Exemplo n.º 11
0
        protected ProductDetailsModel PrepareProductDetailsPageModel(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            var model = new ProductDetailsModel()
            {
                Id                   = product.Id,
                Name                 = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id),
                ShortDescription     = product.GetLocalized(x => x.ShortDescription, _workContext.WorkingLanguage.Id),
                FullDescription      = product.GetLocalized(x => x.FullDescription, _workContext.WorkingLanguage.Id),
                OrderingComments     = product.GetLocalized(x => x.AdminComment, _workContext.WorkingLanguage.Id, false),
                MetaKeywords         = product.GetLocalized(x => x.MetaKeywords, _workContext.WorkingLanguage.Id),
                MetaDescription      = product.GetLocalized(x => x.MetaDescription, _workContext.WorkingLanguage.Id),
                MetaTitle            = product.GetLocalized(x => x.MetaTitle, _workContext.WorkingLanguage.Id),
                SeName               = product.GetSeName(),
                MinimumOrderQuantity = product.MinimumOrderQuantity.HasValue ? product.MinimumOrderQuantity.Value : 1,
                Favorit              = _favoritsService.IsItemFavorit(_workContext.CurrentCustomer.Id, product.Id)
            };

            //template

            var templateCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_TEMPLATE_MODEL_KEY, product.ProductTemplateId);

            model.ProductTemplateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _productTemplateService.GetProductTemplateById(product.ProductTemplateId);
                if (template == null)
                {
                    template = _productTemplateService.GetAllProductTemplates().FirstOrDefault();
                }
                return(template.ViewPath);
            });

            //pictures
            model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled;
            var pictures = _pictureService.GetPicturesByProductId(product.Id);

            if (pictures.Count > 0)
            {
                //default picture
                model.DefaultPictureModel = new PictureModel()
                {
                    ImageUrl         = _pictureService.GetPictureUrl(pictures.FirstOrDefault()),
                    FullSizeImageUrl = _pictureService.GetPictureUrl(pictures.FirstOrDefault()),
                    Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
                    AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
                };
                //all pictures
                int i = 0;
                foreach (var picture in pictures)
                {
                    model.PictureModels.Add(new PictureModel()
                    {
                        ImageUrl         = _pictureService.GetPictureUrl(picture),
                        FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
                        Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
                        AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
                        Default          = i == 0
                    });
                    i++;
                }
            }
            else
            {
                //no images. set the default one
                model.DefaultPictureModel = new PictureModel()
                {
                    ImageUrl         = _pictureService.GetDefaultPictureUrl(_mediaSettings.ProductDetailsPictureSize),
                    FullSizeImageUrl = _pictureService.GetDefaultPictureUrl(),
                    Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
                    AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
                };
            }

            List <CategoryProductAttributeGroup> _attrGroups         = product.ProductAttributes.Select(x => x.CategoryProductAttribute.CategoryProductGroup).Distinct().ToList();
            List <CategoryAttributeModel>        DisplayedAttributes = new List <CategoryAttributeModel>();

            foreach (var _aG in _attrGroups)
            {
                foreach (var cpa in _aG.CategoryProductAttributes)
                {
                    CategoryAttributeModel cam = new CategoryAttributeModel();
                    cam.Values = new List <CategoryProductAttributeValueModel>();
                    cam.Values.AddRange(cpa.CategoryProductAttributeValues.OrderBy(x => x.DisplayOrder)
                                        .ThenBy(x => x.Name)
                                        .Select(x =>
                    {
                        var md = new CategoryProductAttributeValueModel();
                        if (x.CategoryProductAttribute.AttributeControlType != AttributeControlType.TextBox)
                        {
                            md.Name = x.GetLocalized(z => z.Name, _workContext.WorkingLanguage.Id, false);
                        }
                        else
                        {
                            md.Name = x.Name;
                        }
                        md.IsPreSelected = product.ProductAttributes.Where(p => p.Id == x.Id).Count() > 0;
                        md.CategoryProductAttributeId = x.CategoryProductAttributeId;
                        md.Id                         = x.Id;
                        md.DisplayOrder               = x.DisplayOrder;
                        md.ColorSquaresRgb            = x.ColorSquaresRgb;
                        md.CategoryProductAttributeId = x.CategoryProductAttributeId;
                        return(md);
                    })
                                        .ToList());
                    //cam.Values.ForEach(i =>
                    //{
                    //    i.Name = i.GetLocalized(xi => xi.Name, _workContext.WorkingLanguage.Id, true);
                    //});

                    cam.Name        = cpa.ProductAttribute.GetLocalized(n => n.Name, _workContext.WorkingLanguage.Id, false);
                    cam.ControlType = cpa.AttributeControlType;
                    //cam.Values.ForEach(x =>
                    //{
                    //    x.IsPreSelected = product.ProductAttributes.Where(i => i.Id == x.Id).Count() > 0;
                    //});
                    //foreach (var val in cam.Values)
                    //{
                    //    val.IsPreSelected = product.ProductAttributes.Where(p => p.Id == val.Id).Count() > 0;
                    //}
                    var attrValue = cam.Values.Where(i => i.IsPreSelected).FirstOrDefault();
                    cam.SelectedValue = attrValue;
                    cam.DisplayOrder  = cpa.DisplayOrder;
                    //cam.SelectedValue.Name = attrValue.GetLocalized(v => v.Name, _workContext.WorkingLanguage.Id, true);
                    //cam.Values.ForEach(i => { i.Name = i.GetLocalized(xi => xi.Name, _workContext.WorkingLanguage.Id, true); });
                    DisplayedAttributes.Add(cam);
                }
            }
            model.CategoryAttributes = DisplayedAttributes.OrderBy(x => x.DisplayOrder).ToList();

            //product tags
            foreach (var item in product.ProductTags)
            {
                model.ProductTags.Add(new ProductTagModel()
                {
                    Name         = item.Name,
                    ProductCount = item.ProductCount,
                    Id           = item.Id
                });
            }
            model.CompanyInformationModel               = new CompanyInformationModel();
            model.CompanyInformationModel.CompanyName   = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, _workContext.WorkingLanguage.Id, false);
            model.CompanyInformationModel.CompanySeName = product.Customer.CompanyInformation.GetSeName(_workContext.WorkingLanguage.Id);
            if (model.CompanyInformationModel.CompanyName == null)
            {
                var languages = _languageService.GetAllLanguages().ToList();
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "es-MX").FirstOrDefault().Id, false);
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "de-DE").FirstOrDefault().Id, false);
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "en-US").FirstOrDefault().Id, false);
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "ru-RU").FirstOrDefault().Id, false);
            }

            var prices     = _productPriceService.GetAllProductPrices(model.Id);
            var currencies = _currencyService.GetAllCurrencies().Where(c => c.Published).ToList();

            model.ProductPrices = new List <ProductDetailsModel.ProductPriceModel>();
            var prices_to_delete = prices.Where(p => !currencies.Contains(p.Currency)).ToList();

            prices = prices.Where(p => currencies.Contains(p.Currency)).ToList();
            foreach (var p in prices_to_delete)
            {
                _productPriceService.DeleteProductPriceById(p.Id);
            }
            model.ProductPrices = new List <ProductDetailsModel.ProductPriceModel>();
            foreach (var price in prices)
            {
                model.ProductPrices.Add(new ProductDetailsModel.ProductPriceModel()
                {
                    CurrencyId     = price.CurrencyId,
                    Id             = price.Id,
                    Price          = price.Price,
                    PriceUpdatedOn = price.PriceUpdatedOn,
                    PriceValue     = price.Price.ToString("N2"),
                    ProductId      = price.ProductId,
                    Currency       = new Core.Domain.Directory.Currency()
                    {
                        CurrencyCode = price.Currency.CurrencyCode
                    }
                });
            }

            return(model);
        }
Exemplo n.º 12
0
        public ActionResult UpdateProductDetails(int productId, string itemType, int bundleItemId, FormCollection form)
        {
            int    quantity          = 1;
            int    galleryStartIndex = -1;
            string galleryHtml       = null;
            string dynamicThumbUrl   = null;
            bool   isAssociated      = itemType.IsCaseInsensitiveEqual("associateditem");
            var    pictureModel      = new ProductDetailsPictureModel();
            var    m       = new ProductDetailsModel();
            var    product = _productService.GetProductById(productId);
            var    bItem   = _productService.GetBundleItemById(bundleItemId);
            IList <ProductBundleItemData> bundleItems = null;
            ProductBundleItemData         bundleItem  = (bItem == null ? null : new ProductBundleItemData(bItem));

            // quantity required for tier prices
            string quantityKey = form.AllKeys.FirstOrDefault(k => k.EndsWith("EnteredQuantity"));

            if (quantityKey.HasValue())
            {
                int.TryParse(form[quantityKey], out quantity);
            }

            if (product.ProductType == ProductType.BundledProduct && product.BundlePerItemPricing)
            {
                bundleItems = _productService.GetBundleItems(product.Id);
                if (form.Count > 0)
                {
                    foreach (var itemData in bundleItems)
                    {
                        var tempModel = _helper.PrepareProductDetailsPageModel(itemData.Item.Product, false, itemData, null, form);
                    }
                }
            }

            // get merged model data
            _helper.PrepareProductDetailModel(m, product, isAssociated, bundleItem, bundleItems, form, quantity);

            if (bundleItem != null)                     // update bundle item thumbnail
            {
                if (!bundleItem.Item.HideThumbnail)
                {
                    var picture = m.GetAssignedPicture(_pictureService, null, bundleItem.Item.ProductId);
                    dynamicThumbUrl = _pictureService.GetPictureUrl(picture, _mediaSettings.BundledProductPictureSize, false);
                }
            }
            else if (isAssociated)                      // update associated product thumbnail
            {
                var picture = m.GetAssignedPicture(_pictureService, null, productId);
                dynamicThumbUrl = _pictureService.GetPictureUrl(picture, _mediaSettings.AssociatedProductPictureSize, false);
            }
            else if (product.ProductType != ProductType.BundledProduct)                         // update image gallery
            {
                var pictures = _pictureService.GetPicturesByProductId(productId);

                if (pictures.Count <= _catalogSettings.DisplayAllImagesNumber)                  // all pictures rendered... only index is required
                {
                    var picture = m.GetAssignedPicture(_pictureService, pictures);
                    galleryStartIndex = (picture == null ? 0 : pictures.IndexOf(picture));
                }
                else
                {
                    var allCombinationImageIds = new List <int>();

                    _productAttributeService
                    .GetAllProductVariantAttributeCombinations(product.Id)
                    .GetAllCombinationImageIds(allCombinationImageIds);

                    _helper.PrepareProductDetailsPictureModel(pictureModel, pictures, product.GetLocalized(x => x.Name), allCombinationImageIds,
                                                              false, bundleItem, m.CombinationSelected);

                    galleryStartIndex = pictureModel.GalleryStartIndex;
                    galleryHtml       = this.RenderPartialViewToString("_PictureGallery", pictureModel);
                }
            }

            #region data object
            object data = new
            {
                Delivery = new
                {
                    Id    = 0,
                    Name  = m.DeliveryTimeName,
                    Color = m.DeliveryTimeHexValue,
                    DisplayAccordingToStock = m.DisplayDeliveryTimeAccordingToStock
                },
                Measure = new
                {
                    Weight = new { Value = m.WeightValue, Text = m.Weight },
                    Height = new { Value = product.Height, Text = m.Height },
                    Width  = new { Value = product.Width, Text = m.Width },
                    Length = new { Value = product.Length, Text = m.Length }
                },
                Number = new
                {
                    Sku  = new { Value = m.Sku, Show = m.ShowSku },
                    Gtin = new { Value = m.Gtin, Show = m.ShowGtin },
                    Mpn  = new { Value = m.ManufacturerPartNumber, Show = m.ShowManufacturerPartNumber }
                },
                Price = new
                {
                    Base = new
                    {
                        Enabled = m.IsBasePriceEnabled,
                        Info    = m.BasePriceInfo
                    },
                    Old = new
                    {
                        Value = decimal.Zero,
                        Text  = m.ProductPrice.OldPrice
                    },
                    WithoutDiscount = new
                    {
                        Value = m.ProductPrice.PriceValue,
                        Text  = m.ProductPrice.Price
                    },
                    WithDiscount = new
                    {
                        Value = m.ProductPrice.PriceWithDiscountValue,
                        Text  = m.ProductPrice.PriceWithDiscount
                    }
                },
                Stock = new
                {
                    Quantity     = new { Value = product.StockQuantity, Show = product.DisplayStockQuantity },
                    Availability = new { Text = m.StockAvailability, Show = product.DisplayStockAvailability, Available = m.IsAvailable }
                },

                DynamicThumblUrl  = dynamicThumbUrl,
                GalleryStartIndex = galleryStartIndex,
                GalleryHtml       = galleryHtml
            };
            #endregion

            return(new JsonResult {
                Data = data
            });
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Update(Guid id, [FromBody] ProductDetailsModel productDetails)
        {
            await _productDetailsService.Update(id, productDetails);

            return(Ok());
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Save([FromBody] ProductDetailsModel productDetails)
        {
            await _productDetailsService.Create(productDetails);

            return(Ok());
        }
Exemplo n.º 15
0
 public static bool RenderBundleTitle(this ProductDetailsModel model)
 {
     return(model.BundleTitleText.HasValue() && model.BundledItems.Where(x => x.BundleItem.Visible).Count() > 0);
 }
Exemplo n.º 16
0
        public ActionResult UpdateProductDetails(int productId, string itemType, int bundleItemId, ProductVariantQuery query, FormCollection form)
        {
            int    quantity          = 1;
            int    galleryStartIndex = -1;
            string galleryHtml       = null;
            string dynamicThumbUrl   = null;
            var    isAssociated      = itemType.IsCaseInsensitiveEqual("associateditem");
            var    pictureModel      = new ProductDetailsPictureModel();
            var    m       = new ProductDetailsModel();
            var    product = _productService.GetProductById(productId);
            var    bItem   = _productService.GetBundleItemById(bundleItemId);
            IList <ProductBundleItemData> bundleItems = null;
            ProductBundleItemData         bundleItem  = (bItem == null ? null : new ProductBundleItemData(bItem));

            // Quantity required for tier prices.
            string quantityKey = form.AllKeys.FirstOrDefault(k => k.EndsWith("EnteredQuantity"));

            if (quantityKey.HasValue())
            {
                int.TryParse(form[quantityKey], out quantity);
            }

            if (product.ProductType == ProductType.BundledProduct && product.BundlePerItemPricing)
            {
                bundleItems = _productService.GetBundleItems(product.Id);
                if (query.Variants.Count > 0)
                {
                    // May add elements to query object if they are preselected by bundle item filter.
                    foreach (var itemData in bundleItems)
                    {
                        _helper.PrepareProductDetailsPageModel(itemData.Item.Product, query, false, itemData, null);
                    }
                }
            }

            // Get merged model data.
            _helper.PrepareProductDetailModel(m, product, query, isAssociated, bundleItem, bundleItems, quantity);

            if (bundleItem != null)
            {
                // Update bundle item thumbnail.
                if (!bundleItem.Item.HideThumbnail)
                {
                    var picture = m.GetAssignedPicture(_pictureService, null, bundleItem.Item.ProductId);
                    dynamicThumbUrl = _pictureService.GetUrl(picture, _mediaSettings.BundledProductPictureSize, false);
                }
            }
            else if (isAssociated)
            {
                // Update associated product thumbnail.
                var picture = m.GetAssignedPicture(_pictureService, null, productId);
                dynamicThumbUrl = _pictureService.GetUrl(picture, _mediaSettings.AssociatedProductPictureSize, false);
            }
            else if (product.ProductType != ProductType.BundledProduct)
            {
                // Update image gallery.
                var pictures = _pictureService.GetPicturesByProductId(productId);

                if (pictures.Count <= _catalogSettings.DisplayAllImagesNumber)
                {
                    // All pictures rendered... only index is required.
                    var picture = m.GetAssignedPicture(_pictureService, pictures);
                    galleryStartIndex = (picture == null ? 0 : pictures.IndexOf(picture));
                }
                else
                {
                    var allCombinationPictureIds = _productAttributeService.GetAllProductVariantAttributeCombinationPictureIds(product.Id);

                    _helper.PrepareProductDetailsPictureModel(
                        pictureModel,
                        pictures,
                        product.GetLocalized(x => x.Name),
                        allCombinationPictureIds,
                        false,
                        bundleItem,
                        m.SelectedCombination);

                    galleryStartIndex = pictureModel.GalleryStartIndex;
                    galleryHtml       = this.RenderPartialViewToString("Product.Picture", pictureModel);
                }
            }

            object partials = null;

            if (m.IsBundlePart)
            {
                partials = new
                {
                    BundleItemPrice = this.RenderPartialViewToString("Product.Offer.Price", m),
                    BundleItemStock = this.RenderPartialViewToString("Product.StockInfo", m)
                };
            }
            else
            {
                var dataDictAddToCart = new ViewDataDictionary();
                dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", m.Id);

                partials = new
                {
                    Attrs        = this.RenderPartialViewToString("Product.Attrs", m),
                    Price        = this.RenderPartialViewToString("Product.Offer.Price", m),
                    Stock        = this.RenderPartialViewToString("Product.StockInfo", m),
                    OfferActions = this.RenderPartialViewToString("Product.Offer.Actions", m, dataDictAddToCart),
                    TierPrices   = this.RenderPartialViewToString("Product.TierPrices", _helper.CreateTierPriceModel(product, m.ProductPrice.PriceValue - product.Price)),
                    BundlePrice  = product.ProductType == ProductType.BundledProduct ? this.RenderPartialViewToString("Product.Bundle.Price", m) : (string)null
                };
            }

            object data = new
            {
                Partials          = partials,
                DynamicThumblUrl  = dynamicThumbUrl,
                GalleryStartIndex = galleryStartIndex,
                GalleryHtml       = galleryHtml
            };

            return(new JsonResult {
                Data = data
            });
        }
Exemplo n.º 17
0
        public ActionResult Index(int id = 0)
        {
            var host   = System.Web.HttpContext.Current.Request.Url.OriginalString.Replace(System.Web.HttpContext.Current.Request.Url.PathAndQuery, "");
            var images = Session["Images"] as List <DataAccessLayer.Image> ?? new List <DataAccessLayer.Image>();

            ViewBag.ProductTypeList = new SelectList(GetProductTypeList(), "Value", "Text");
            ViewBag.MetalList       = new SelectList(GetMetalList(), "Value", "Text");
            ViewBag.GemList         = new SelectList(GetGemList(), "Value", "Text");
            ViewBag.OccasionList    = new SelectList(GetOccasionList(), "Value", "Text");

            ProductDetailsModel objProductDetailsModel = new ProductDetailsModel
            {
                objProductMaster = objAsopalavDBEntities.ProductMasters.Include("Images").Where(p => p.ProductID == id).FirstOrDefault()
            };

            if (objProductDetailsModel.objProductMaster != null)
            {
                objProductModel.ProductID                = objProductDetailsModel.objProductMaster.ProductID;
                objProductModel.ProductCode              = objProductDetailsModel.objProductMaster.ProductCode;
                objProductModel.ProductName              = objProductDetailsModel.objProductMaster.ProductName;
                objProductModel.ProductTypeID            = objProductDetailsModel.objProductMaster.ProductTypeID;
                objProductModel.WeightInGms              = objProductDetailsModel.objProductMaster.WeightInGms;
                objProductModel.HeightInInch             = objProductDetailsModel.objProductMaster.HeightInInch;
                objProductModel.WidthInInch              = objProductDetailsModel.objProductMaster.WidthInInch;
                objProductModel.Price                    = objProductDetailsModel.objProductMaster.Price;
                objProductModel.IsOffer                  = objProductDetailsModel.objProductMaster.IsOffer;
                objProductModel.OfferPrice               = objProductDetailsModel.objProductMaster.OfferPrice;
                objProductModel.IsActive                 = objProductDetailsModel.objProductMaster.IsActive;
                objProductModel.Description              = objProductDetailsModel.objProductMaster.Description;
                objProductModel.OccasionId               = objProductDetailsModel.objProductMaster.OccasionId;
                objProductModel.OfferStartDate           = objProductDetailsModel.objProductMaster.OfferStartDate;
                objProductModel.OfferEndDate             = objProductDetailsModel.objProductMaster.OfferEndDate;
                objProductModel.MakingChargePercentage   = objProductDetailsModel.objProductMaster.MakingChargePercentage;
                objProductModel.MakingCharge             = objProductDetailsModel.objProductMaster.MakingCharge;
                objProductModel.IsMakingChargePercentage = objProductDetailsModel.objProductMaster.IsMakingChargePercentage;
                objProductModel.MetalVariantId           = objProductDetailsModel.objProductMaster.MetalVariantId;
                objProductModel.GemVariantId             = objProductDetailsModel.objProductMaster.GemVariantId;
                objProductModel.AmazonUrl                = objProductDetailsModel.objProductMaster.AmazonUrl;
                objProductModel.eBayUrl                  = objProductDetailsModel.objProductMaster.eBayUrl;

                if (objProductDetailsModel.objProductMaster.Images != null)
                {
                    foreach (var item in objProductDetailsModel.objProductMaster.Images)
                    {
                        if (item.ImagePath != null)
                        {
                            if (!System.IO.File.Exists(Server.MapPath("~/" + item.ImagePath.ToString().Substring(item.ImagePath.ToString().IndexOf("Uploads")))))
                            {
                                item.ImagePath = Request.UrlReferrer.AbsoluteUri.Replace(Request.UrlReferrer.AbsolutePath, "/Content/images/no-product-image.jpg");
                            }
                            else
                            {
                                var tempImagePath = (host + "\\" + item.ImagePath.Substring(item.ImagePath.IndexOf("Uploads"))).Replace(@"\", "/");
                                item.ImagePath = tempImagePath;
                            }
                        }
                        else
                        {
                            item.ImagePath = Request.UrlReferrer.AbsoluteUri.Replace(Request.UrlReferrer.AbsolutePath, "/Content/images/no-product-image.jpg");
                        }
                    }
                    Session["Images"]             = objProductDetailsModel.objProductMaster.Images;
                    objProductModel.ImagePathList = objProductDetailsModel.objProductMaster.Images.Select(x => x.ImagePath).ToList();
                    objProductModel.Images        = objProductDetailsModel.objProductMaster.Images;
                }
            }
            return(View(objProductModel));
        }
        /// <summary>
        /// Invoke the widget view component
        /// </summary>
        /// <param name="widgetZone">Widget zone</param>
        /// <param name="additionalData">Additional parameters</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the view component result
        /// </returns>
        public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
        {
            if (!await _shippingPluginManager.IsPluginActiveAsync(EasyPostDefaults.SystemName))
            {
                return(Content(string.Empty));
            }

            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageShippingSettings))
            {
                return(Content(string.Empty));
            }

            if (!widgetZone.Equals(AdminWidgetZones.ProductDetailsBlock))
            {
                return(Content(string.Empty));
            }

            if (additionalData is not ProductModel productModel || !productModel.IsShipEnabled)
            {
                return(Content(string.Empty));
            }

            var product = await _productService.GetProductByIdAsync(productModel.Id);

            if (product is null)
            {
                return(Content(string.Empty));
            }

            //try to get previously saved values
            var predefinedPackageValue = await _genericAttributeService
                                         .GetAttributeAsync <string>(product, EasyPostDefaults.ProductPredefinedPackageAttribute) ?? string.Empty;

            var carrier           = predefinedPackageValue.Split('.').FirstOrDefault();
            var predefinedPackage = predefinedPackageValue.Split('.').LastOrDefault();
            var htsNumber         = await _genericAttributeService.GetAttributeAsync <string>(product, EasyPostDefaults.ProductHtsNumberAttribute);

            var originCountry = await _genericAttributeService.GetAttributeAsync <string>(product, EasyPostDefaults.ProductOriginCountryAttribute);

            var availablePredefinedPackages = PredefinedPackage.PredefinedPackages.SelectMany(carrierPackages => carrierPackages.Value
                                                                                              .Select(package => new SelectListItem($"{carrierPackages.Key} - {package}", $"{carrierPackages.Key}.{package}")))
                                              .ToList();

            availablePredefinedPackages.Insert(0, new SelectListItem("---", string.Empty));

            var availableCountries = (await _countryService.GetAllCountriesAsync(showHidden: true))
                                     .Select(country => new SelectListItem(country.Name, country.TwoLetterIsoCode))
                                     .ToList();

            availableCountries.Insert(0, new SelectListItem("---", string.Empty));

            var model = new ProductDetailsModel
            {
                EasyPostPredefinedPackage   = !string.IsNullOrEmpty(predefinedPackageValue) ? $"{carrier}.{predefinedPackage}" : string.Empty,
                AvailablePredefinedPackages = availablePredefinedPackages,
                EasyPostHtsNumber           = htsNumber,
                EasyPostOriginCountry       = originCountry,
                AvailableCountries          = availableCountries
            };

            return(View("~/Plugins/Shipping.EasyPost/Views/Product/_CreateOrUpdate.EasyPost.cshtml", model));
        }
        public virtual ProductDetailsModel PrepareProductDetailsModel(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            //standard properties
            var model = new ProductDetailsModel
            {
                Id                         = product.Id,
                Name                       = product.GetLocalized(x => x.Name),
                ShortDescription           = product.GetLocalized(x => x.ShortDescription),
                FullDescription            = product.GetLocalized(x => x.FullDescription),
                MetaKeywords               = product.GetLocalized(x => x.MetaKeywords),
                MetaDescription            = product.GetLocalized(x => x.MetaDescription),
                MetaTitle                  = product.GetLocalized(x => x.MetaTitle),
                SeName                     = product.GetSeName(),
                ProductType                = product.ProductType,
                ShowSku                    = _catalogSettings.ShowSkuOnProductDetailsPage,
                Sku                        = product.Sku,
                DisplayDiscontinuedMessage = !product.Published && _catalogSettings.DisplayDiscontinuedMessageForUnpublishedProducts
            };

            //automatically generate product description?
            if (_seoSettings.GenerateProductMetaDescription && String.IsNullOrEmpty(model.MetaDescription))
            {
                //based on short description
                model.MetaDescription = model.ShortDescription;
            }

            //email a friend
            model.EmailAFriendEnabled = _catalogSettings.EmailAFriendEnabled;
            //store name
            model.CurrentStoreName = _storeContext.CurrentStore.GetLocalized(x => x.Name);

            //page sharing
            if (_catalogSettings.ShowShareButton && !String.IsNullOrEmpty(_catalogSettings.PageShareCode))
            {
                var shareCode = _catalogSettings.PageShareCode;
                if (_webHelper.IsCurrentConnectionSecured())
                {
                    //need to change the addthis link to be https linked when the page is, so that the page doesnt ask about mixed mode when viewed in https...
                    shareCode = shareCode.Replace("http://", "https://");
                }
                model.PageShareCode = shareCode;
            }

            //breadcrumb
            if (_catalogSettings.CategoryBreadcrumbEnabled)
            {
                model.Breadcrumb = PrepareProductBreadcrumbModel(product);
            }

            //product tags
            model.ProductTags = PrepareProductTagModels(product);

            //pictures
            model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled;
            var pictureModels = PrepareProductDetailsPictureModel(product);

            model.DefaultPictureModel = pictureModels.DefaultPictureModel;
            model.PictureModels       = pictureModels.PictureModels;

            //product review overview
            model.ProductReviewOverview = PrepareProductReviewOverviewModel(product);

            return(model);
        }
 public BsQuickViewModel()
 {
     ProductDetailsModel      = new ProductDetailsModel();
     BsQuickViewSettingsModel = new BsQuickViewSettingsModel();
 }