Ejemplo n.º 1
0
        /// <summary>
        /// Gets a list of LineItemDetailViewModel from a list of overture LineItem objects.
        /// </summary>
        public virtual IEnumerable <LineItemDetailViewModel> CreateViewModel(CreateListOfLineItemDetailViewModelParam param)
        {
            if (param.LineItems == null)
            {
                yield break;
            }

            var imgDictionary = LineItemHelper.BuildImageDictionaryFor(param.ImageInfo.ImageUrls);

            var processedCart = param.Cart as ProcessedCart;
            var preMapAction  = processedCart == null
                ? new Action <LineItem>(li => { })
                : li => LineItemValidationProvider.ValidateLineItem(processedCart, li);

            foreach (var lineItem in param.LineItems)
            {
                var vm = GetLineItemDetailViewModel(new CreateLineItemDetailViewModelParam
                {
                    PreMapAction    = preMapAction,
                    LineItem        = lineItem,
                    CultureInfo     = param.CultureInfo,
                    ImageDictionary = imgDictionary,
                    BaseUrl         = param.BaseUrl
                });

                yield return(vm);
            }
        }
        /// <summary>
        ///     Creates the product search results view model.
        /// </summary>
        /// <createSearchViewModelParam name="createSearchViewModelParam">The parameter.</createSearchViewModelParam>
        /// <returns></returns>
        protected virtual async Task <ProductSearchResultsViewModel> CreateProductSearchResultsViewModelAsync(CreateProductSearchResultsViewModelParam <TParam> param)
        {
            //TODO: Implement by calling the ViewModelMapper instead.
            var searchResultViewModel = new ProductSearchResultsViewModel
            {
                SearchResults        = new List <ProductSearchViewModel>(),
                CategoryFacetCounts  = BuildCategoryFacetCounts(param),
                Keywords             = param.SearchParam.Criteria.Keywords,
                TotalCount           = param.SearchResult.TotalCount,
                CorrectedSearchTerms = param.SearchResult.CorrectedSearchTerms,
                Suggestions          = new List <Suggestion>()
            };

            if (param.SearchResult.Suggestions != null)
            {
                foreach (var suggestion in param.SearchResult.Suggestions)
                {
                    var cloneParam = param.SearchParam.Criteria.Clone();
                    cloneParam.Keywords = suggestion.Title;

                    searchResultViewModel.Suggestions.Add(new Suggestion
                    {
                        Title = suggestion.Title,
                        Url   = SearchUrlProvider.BuildSearchUrl(new BuildSearchUrlParam
                        {
                            SearchCriteria = cloneParam
                        })
                    });
                }
            }

            var imgDictionary     = LineItemHelper.BuildImageDictionaryFor(param.ImageUrls);
            var searchResultsList = new List <(ProductSearchViewModel, ProductDocument)>();

            // Populate search results
            foreach (var resultItem in param.SearchResult.Documents)
            {
                searchResultsList.Add((ProductSearchViewModelFactory.GetProductSearchViewModel(resultItem, param.SearchParam.Criteria, imgDictionary), resultItem));
            }

            searchResultViewModel.SearchResults = await ProductSearchViewModelFactory.EnrichAppendProductSearchViewModels(searchResultsList, param.SearchParam.Criteria).ConfigureAwait(false);

            var facets = BuildFacets(param.SearchParam.Criteria, param.SearchResult);

            searchResultViewModel.Facets              = facets;
            searchResultViewModel.Pagination          = BuildPaginationForSearchResults(param.SearchResult, param.SearchParam, SearchConfiguration.MaximumPages);
            searchResultViewModel.PromotedFacetValues = BuildPromotedFacetValues(facets);

            // TODO: Fix this
            new SearchSortByResolver <TParam>(LocalizationProvider, GetSearchSortByList(SearchType), GenerateUrl)
            .Resolve(searchResultViewModel, param.SearchParam);

            searchResultViewModel.BaseUrl = param.SearchParam.Criteria.BaseUrl;

            return(searchResultViewModel);
        }
        public virtual async Task <RecurringOrderTemplateViewModel> CreateRecurringOrderTemplateDetailsViewModel(CreateRecurringOrderTemplateDetailsViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.ProductImageInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductImageInfo)), nameof(param));
            }
            if (param.ProductImageInfo.ImageUrls == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductImageInfo.ImageUrls)), nameof(param));
            }
            if (param.ScopeId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ScopeId)), nameof(param));
            }
            if (param.RecurringOrderLineItem == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.RecurringOrderLineItem)), nameof(param));
            }

            var vm = new RecurringOrderTemplateViewModel();

            var imgDictionary = LineItemHelper.BuildImageDictionaryFor(param.ProductImageInfo.ImageUrls);

            var recurringScheduleUrl = RecurringScheduleUrlProvider.GetRecurringScheduleUrl(new GetRecurringScheduleUrlParam
            {
                CultureInfo = param.CultureInfo
            });

            var lineItemViewModel = await MapToTemplateLineItemViewModel(new MapToTemplateLineItemViewModelParam
            {
                RecurringOrderlineItem = param.RecurringOrderLineItem,
                CultureInfo            = param.CultureInfo,
                ImageDictionnary       = imgDictionary,
                BaseUrl = param.BaseUrl,
                RecurringScheduleUrl = recurringScheduleUrl
            }).ConfigureAwait(false);

            if (lineItemViewModel != null)
            {
                lineItemViewModel.ShippingAddressId = param.RecurringOrderLineItem.ShippingAddressId;
                vm.RecurringOrderTemplateLineItemViewModels.Add(lineItemViewModel);
            }

            return(vm);
        }
Ejemplo n.º 4
0
        public HttpResponseMessage PostOrderLineItems(object order)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            //var lineItemModel = lineItem.ToModel();
            var lineItems = new LineItemHelper();
            var items     = lineItems.Parse(order);
            var postCount = 0;

            foreach (LineItem item in items)
            {
                var repo = new LineItemsRepository();
                repo.Post(item);

                var adjustInventory = new ProductsRepository();
                adjustInventory.DecrementProductCount(item.VariantId, item.Quantity);

                postCount += 1;
            }

            return(items.Count == postCount?Request.CreateResponse(HttpStatusCode.Created) : Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not process your order, try again later..."));
        }
        public virtual async Task <List <RecurringOrderTemplateViewModel> > CreateTemplateGroupedShippingAddress(CreateTemplateGroupedShippingAddressParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.ListOfRecurringOrderLineItems == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ListOfRecurringOrderLineItems)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.ProductImageInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductImageInfo)), nameof(param));
            }
            if (param.ProductImageInfo.ImageUrls == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductImageInfo.ImageUrls)), nameof(param));
            }
            if (param.ScopeId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ScopeId)), nameof(param));
            }

            var groups = param.ListOfRecurringOrderLineItems.RecurringOrderLineItems.GroupBy(grp => grp.ShippingAddressId);

            var imgDictionary = LineItemHelper.BuildImageDictionaryFor(param.ProductImageInfo.ImageUrls);

            var itemList = new List <RecurringOrderTemplateViewModel>();

            var recurringScheduleUrl = RecurringScheduleUrlProvider.GetRecurringScheduleUrl(new GetRecurringScheduleUrlParam
            {
                CultureInfo = param.CultureInfo,
            });

            foreach (var group in groups)
            {
                var templateViewModel = new RecurringOrderTemplateViewModel
                {
                    ShippingAddress = await MapShippingAddress(group.Key, param.CultureInfo).ConfigureAwait(false)
                };

                var tasks = group.Select(g => MapToTemplateLineItemViewModel(new MapToTemplateLineItemViewModelParam
                {
                    RecurringOrderlineItem = g,
                    CultureInfo            = param.CultureInfo,
                    ImageDictionnary       = imgDictionary,
                    BaseUrl = param.BaseUrl,
                    RecurringScheduleUrl = recurringScheduleUrl
                }));

                var templateLineItems = await Task.WhenAll(tasks);

                //Filter null to not have an error when rendering the page
                templateViewModel.RecurringOrderTemplateLineItemViewModels.AddRange(templateLineItems.Where(t => t != null).ToList());

                itemList.Add(templateViewModel);
            }

            return(itemList);
        }