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.Url = 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.Url }); 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; productDetailViewModel.Quantity = QuantityConfiguration.GetProductQuantity(); productDetailViewModel.Currency = param.Currency; productDetailViewModel.Specifications = ProductSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam { Product = param.Product, ProductDefinition = param.ProductDefinition }); return(productDetailViewModel); }
protected virtual ProductQuantityViewModel GetQuantity() { return(QuantityConfiguration.GetProductQuantity()); }