Exemplo n.º 1
0
        protected virtual async Task <IEnumerable <ProductIdentifier> > GetSameCategoryProductIdentifier(GetProductIdentifiersParam getProductIdentifiersParam, string categoryId)
        {
            if (getProductIdentifiersParam == null)
            {
                throw new ArgumentNullException(nameof(getProductIdentifiersParam));
            }
            if (string.IsNullOrWhiteSpace(categoryId))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(), nameof(categoryId));
            }

            var sameCategoryProductIdentifier = new List <ProductIdentifier>();
            var productInSameCategoryParam    = new GetProductsInSameCategoryParam()
            {
                CategoryId           = categoryId,
                CultureInfo          = getProductIdentifiersParam.CultureInfo,
                Scope                = getProductIdentifiersParam.Scope,
                MaxItems             = getProductIdentifiersParam.MaxItems,
                SortBy               = "score",
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(),
                CurrentProductId     = getProductIdentifiersParam.ProductId,
                AvailabilityDate     = FulfillmentContext.AvailabilityAndPriceDate
            };

            var sameCategoryProducts = await RelationshipRepository.GetProductInSameCategoryAsync(productInSameCategoryParam).ConfigureAwait(false);

            if (sameCategoryProducts.Documents.Any())
            {
                sameCategoryProductIdentifier = sameCategoryProducts.Documents.Select(d =>
                {
                    string variantId = null;
                    if (d.PropertyBag.ContainsKey(VariantPropertyBagKey))
                    {
                        variantId = d.PropertyBag[VariantPropertyBagKey] as string;
                    }

                    return(new ProductIdentifier
                    {
                        ProductId = d.ProductId,
                        VariantId = variantId
                    });
                }).ToList();
            }
            return(sameCategoryProductIdentifier);
        }
        protected virtual SearchAvailableProductsRequest CreateProductInSameCategorySearchRequest(
            GetProductsInSameCategoryParam getProductsInSameCategoryParam)
        {
            var request = _productRequestFactory.CreateProductRequest(getProductsInSameCategoryParam.Scope);

            request.Query.IncludeTotalCount = false;
            request.Query.MaximumItems      = getProductsInSameCategoryParam.MaxItems;
            request.CultureName             = getProductsInSameCategoryParam.CultureInfo.Name;
            request.InventoryLocationIds    = getProductsInSameCategoryParam.InventoryLocationIds;
            request.ScopeId          = getProductsInSameCategoryParam.Scope;
            request.AvailabilityDate = getProductsInSameCategoryParam.AvailabilityDate;

            var sortDefinitions = BuildQuerySortings(getProductsInSameCategoryParam.SortBy, getProductsInSameCategoryParam.SortDirection);

            if (sortDefinitions != null)
            {
                request.Query.Sortings.Add(sortDefinitions);
            }

            var filters = new List <Filter>()
            {
                new Filter()
                {
                    Member = "ParentCategoryId",
                    Value  = getProductsInSameCategoryParam.CategoryId
                }
            };

            if (!string.IsNullOrWhiteSpace(getProductsInSameCategoryParam.CurrentProductId))
            {
                filters.Add(new Filter()
                {
                    Member = "ProductId",
                    Value  = getProductsInSameCategoryParam.CurrentProductId,
                    Not    = true
                });
            }

            request.Query.Filter.FilterGroups.Add(new FilterGroup()
            {
                Filters = filters
            });
            return(request);
        }
        protected virtual async Task <IEnumerable <ProductIdentifier> > GetSameCategoryProductIdentifier(GetProductIdentifiersParam getProductIdentifiersParam, string categoryId)
        {
            Guard.NotNull(getProductIdentifiersParam, nameof(getProductIdentifiersParam));
            Guard.NotNullOrWhiteSpace(categoryId, nameof(categoryId));
            var sameCategoryProductIdentifier = new List <ProductIdentifier>();
            var productInSameCategoryParam    = new GetProductsInSameCategoryParam()
            {
                CategoryId           = categoryId,
                CultureInfo          = getProductIdentifiersParam.CultureInfo,
                Scope                = getProductIdentifiersParam.Scope,
                MaxItems             = getProductIdentifiersParam.MaxItems,
                SortBy               = "score",
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(),
                CurrentProductId     = getProductIdentifiersParam.ProductId
            };

            var sameCategoryProducts = await RelationshipRepository.GetProductInSameCategoryAsync(productInSameCategoryParam).ConfigureAwait(false);

            if (sameCategoryProducts.Documents.Any())
            {
                sameCategoryProductIdentifier = sameCategoryProducts.Documents.Select(d =>
                {
                    string variantId = null;
                    if (d.PropertyBag.ContainsKey(VariantPropertyBagKey))
                    {
                        variantId = d.PropertyBag[VariantPropertyBagKey] as string;
                    }

                    return(new ProductIdentifier
                    {
                        ProductId = d.ProductId,
                        VariantId = variantId
                    });
                }).ToList();
            }
            return(sameCategoryProductIdentifier);
        }
        public virtual Task <ProductSearchResult> GetProductInSameCategoryAsync(GetProductsInSameCategoryParam getProductsInSameCategoryParam)
        {
            var request = CreateProductInSameCategorySearchRequest(getProductsInSameCategoryParam);

            return(_overtureClient.SendAsync(request));
        }