Esempio n. 1
0
 /// <summary>
 /// Initializes specifications for a given variant.
 /// </summary>
 /// <param name="productId">ID of the product.</param>
 /// <param name="productImages">Available product images.</param>
 /// <param name="cultureInfo">Culture info.</param>
 /// <param name="variantViewModel">ViewModel to be impacted.</param>
 protected virtual void InitializeVariantSpecificaton(
     Overture.ServiceModel.Products.Product product,
     ProductDefinition productDefinition,
     VariantViewModel variantViewModel)
 {
     variantViewModel.Specifications = ProductSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
     {
         VariantId         = variantViewModel.Id,
         Product           = product,
         ProductDefinition = productDefinition
     });
 }
Esempio n. 2
0
        protected virtual ProductViewModel CreateViewModel(CreateProductDetailViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.Product == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.Product)), nameof(param));
            }
            if (param.ProductDefinition == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductDefinition)), nameof(param));
            }
            if (param.ProductLookups == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductLookups)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (string.IsNullOrEmpty(param.BaseUrl))
            {
                throw new ArgumentException(GetMessageOfNullEmpty(nameof(param.BaseUrl)), nameof(param));
            }

            var productDetailViewModel = ViewModelMapper.MapTo <ProductViewModel>(param.Product, param.CultureInfo);

            InitializeProductImages(param.Product.Id, param.ProductDetailImages, param.CultureInfo, productDetailViewModel);

            var productDisplayName = productDetailViewModel.DisplayName ?? string.Empty;

            var allVariantsVm = GetVariantViewModels(
                param.Product.Variants,
                param.ProductDefinition.VariantProperties,
                productDisplayName,
                param.CultureInfo,
                vvm => InitializeVariantImages(param.Product.Id, param.ProductDetailImages, param.CultureInfo, vvm),
                vvm => InitializeVariantSpecificaton(param.Product, param.ProductDefinition, vvm)
                ).ToList();

            productDetailViewModel.Variants = allVariantsVm;
            var selectedVariantVm = GetSelectedVariantViewModel(param.VariantId, allVariantsVm);

            MergeSelectedVariantVmToProductVm(selectedVariantVm, productDetailViewModel);

            var selectedKvas = GetSelectedKvas(selectedVariantVm, param);

            productDetailViewModel.Context["selectedKvas"] = selectedKvas;

            //todo: create factory? the code to build variants is huge
            // get all the key variant attributes possibilities.  For instance, if the product has colors and size.  This method
            // will produce two collections (colors, sizes) and for each collection, it will contain all the possible values.
            productDetailViewModel.KeyVariantAttributeItems = CreateKvaItems(new GenerateKvaItemsParam
            {
                ProductLookups    = param.ProductLookups,
                Product           = param.Product,
                SelectedKvas      = selectedKvas,
                ProductDefinition = param.ProductDefinition,
                CultureInfo       = param.CultureInfo,
                ProductVariants   = allVariantsVm
            });

            productDetailViewModel.Price = param.Product.ListPrice;

            productDetailViewModel.ProductDetailUrl = ProductUrlProvider.GetProductUrl(new GetProductUrlParam
            {
                CultureInfo = param.CultureInfo,
                ProductId   = param.Product.Id,
                VariantId   = param.VariantId,
                SKU         = param.Product.Sku,
                ProductName = productDisplayName
            });

            productDetailViewModel.CreateAccountUrl = MyAccountUrlProvider.GetCreateAccountUrl(new BaseUrlParameter
            {
                CultureInfo = param.CultureInfo,
                ReturnUrl   = productDetailViewModel.ProductDetailUrl
            });

            SetViewModelContext(productDetailViewModel, selectedVariantVm, allVariantsVm);

            // When the product lookup is loaded, only the keys of the lookup are assigned to the product view model.  This method
            // compare the product view model bag item keys with the lookups name and assign the right localized lookup values to the view model.
            AssignLookupValuesToProductPropertyBag(param.ProductDefinition, param.ProductLookups, param.CultureInfo, productDetailViewModel);

            productDetailViewModel.Description = FixHtml(productDetailViewModel.Description);

            productDetailViewModel.DefinitionName = param.ProductDefinition.Name;

            if (ProductConfiguration.IsQuantityDisplayed &&
                ProductConfiguration.MinQuantity > 0 &&
                ProductConfiguration.MaxQuantity >= ProductConfiguration.MinQuantity)
            {
                productDetailViewModel.Quantity = new ProductQuantityViewModel
                {
                    Min   = ProductConfiguration.MinQuantity,
                    Max   = ProductConfiguration.MaxQuantity,
                    Value = ProductConfiguration.MinQuantity
                };
            }

            productDetailViewModel.Currency       = param.Currency;
            productDetailViewModel.Specifications = ProductSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = param.Product,
                ProductDefinition = param.ProductDefinition
            });

            return(productDetailViewModel);
        }