示例#1
0
        /// <summary>
        /// 下载产品
        /// </summary>
        public static void LoadProduct()
        {
            GetProductParam getProductParam = new GetProductParam();

            getProductParam.productId = 547363119296;// 576620941437 565461451556  561577651929 554833936110
            getProductParam.GetRequestUrl();
            string            url            = getProductParam.URL;
            string            postData       = string.Join("&", getProductParam.m_DictParameters.Select(zw => zw.Key + "=" + zw.Value));
            HttpClientRequest httpClient     = new HttpClientRequest();
            ResponseResult    responseResult = httpClient.RequesResult(url, postData);

            if (responseResult.Success)
            {
                //进行序列化
                if (!string.IsNullOrEmpty(responseResult.Result))
                {
                    try
                    {
                        GetProductResponse productResponse = JsonConvert.DeserializeObject <GetProductResponse>(responseResult.Result);
                        string             productId       = productResponse.productInfo.productID.ToString();
                        string             staus           = productResponse.productInfo.status;
                        string             subject         = productResponse.productInfo.subject;
                        string             categoryName    = productResponse.productInfo.categoryName;
                        List <SkuInfos>    skuInfosList    = new List <SkuInfos>();
                        List <SkuInfos>    list            = productResponse.productInfo.skuInfos;
                    }
                    catch (Exception ex)
                    {
                        string meg = ex.Message;
                    }
                }
            }
        }
示例#2
0
        public void WhenAnyStringArgumentNullOrWhitespace_ThrowsArgumentException(string scope, string productId)
        {
            //Arrange
            var productRepository = _container.CreateInstance <ProductRepository>();
            var param             = new GetProductParam {
                Scope = scope, CultureInfo = _englishCultureInfo, ProductId = productId
            };

            //Act & Assert
            Assert.ThrowsAsync <ArgumentException>(() => productRepository.GetProductAsync(param));
        }
        protected override async Task <IEnumerable <ProductIdentifier> > GetProductIdentifiersAsync(GetProductIdentifiersParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException("param argument passed to GetRelatedProductIds missing required CultureInfo property");
            }
            if (param.MerchandiseTypes == null)
            {
                throw new ArgumentException("param argument passed to GetRelatedProductIds missing required MerchandiseTypes property");
            }
            if (param.MerchandiseTypes.Length == 0)
            {
                throw new ArgumentException("param.MerchandiseTypes must contain at least one element");
            }
            if (param.ProductId == null)
            {
                throw new ArgumentException("param argument passed to GetRelatedProductIds missing required ProductId property");
            }
            if (param.Scope == null)
            {
                throw new ArgumentException("param argument passed to GetRelatedProductIds missing required MerchandiseType property");
            }

            var getProductParam = new GetProductParam
            {
                ProductId   = param.ProductId,
                CultureInfo = param.CultureInfo,
                Scope       = param.Scope
            };

            var product = await ProductRepository.GetProductAsync(getProductParam).ConfigureAwait(false);

            var relatedProductIdentifiers = ExtractRelatedProductIdentifiers(product, param.MerchandiseTypes, param.MaxItems).ToList();

            if (!relatedProductIdentifiers.Any() && param.FallbackOnSameCategoriesProduct)
            {
                var sameCategoryProductIdentifier = await GetSameCategoryProductIdentifier(param, product.PrimaryParentCategoryId).ConfigureAwait(false);

                if (sameCategoryProductIdentifier.Any())
                {
                    relatedProductIdentifiers = relatedProductIdentifiers.Concat(sameCategoryProductIdentifier).ToList();
                }
            }

            return(relatedProductIdentifiers);
        }
示例#4
0
        protected override async Task <IEnumerable <ProductIdentifier> > GetProductIdentifiersAsync(GetProductIdentifiersParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.MerchandiseTypes == null || !param.MerchandiseTypes.Any())
            {
                throw new ArgumentException(GetMessageOfNullEmpty(nameof(param.MerchandiseTypes)), nameof(param));
            }
            if (param.ProductId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductId)), nameof(param));
            }
            if (param.Scope == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.Scope)), nameof(param));
            }

            var getProductParam = new GetProductParam
            {
                ProductId   = param.ProductId,
                CultureInfo = param.CultureInfo,
                Scope       = param.Scope
            };

            var product = await ProductRepository.GetProductAsync(getProductParam).ConfigureAwait(false);

            var relatedProductIdentifiers = ExtractRelatedProductIdentifiers(product, param.MerchandiseTypes, param.MaxItems).ToList();

            if (!relatedProductIdentifiers.Any() && param.FallbackOnSameCategoriesProduct)
            {
                var sameCategoryProductIdentifier = await GetSameCategoryProductIdentifier(param, product.PrimaryParentCategoryId).ConfigureAwait(false);

                if (sameCategoryProductIdentifier.Any())
                {
                    relatedProductIdentifiers = relatedProductIdentifiers.Concat(sameCategoryProductIdentifier).ToList();
                }
            }

            return(relatedProductIdentifiers);
        }
示例#5
0
        /// <summary>
        /// Gets a product.
        /// </summary>
        /// <param name="param">The parameter.</param>
        /// <returns>
        /// Instance of <see cref="Product" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">param</exception>
        /// <exception cref="System.ArgumentException"></exception>
        public virtual async Task <Product> GetProductAsync(GetProductParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.ProductId))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ProductId)), nameof(param));
            }

            var productCacheKey = new CacheKey(CacheConfigurationCategoryNames.Product)
            {
                Scope = param.Scope,
            };

            productCacheKey.AppendKeyParts(param.ProductId);

            var result = await CacheProvider.GetOrAddAsync(productCacheKey, () =>
            {
                var request = new GetProductV2Request
                {
                    //get all cultures to avoid reloading product page to retrieve new product details
                    CultureName          = string.Empty,
                    IncludePriceLists    = false,
                    IncludeRelationships = true,
                    IncludeVariants      = true,
                    ProductId            = param.ProductId,
                    ScopeId         = param.Scope,
                    IncludeMedia    = true,
                    IncludeImageUrl = true
                };

                return(OvertureClient.SendAsync(request));
            }).ConfigureAwait(false);

            return(param.ReturnInactive || (result?.Active ?? false) ? result : null);
        }
示例#6
0
        public virtual async Task <ProductViewModel> GetProductViewModel(GetProductParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.ProductId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.ProductId)), nameof(param));
            }
            if (param.Scope == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.Scope)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.BaseUrl))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param));
            }

            var product = await ProductRepository.GetProductAsync(param).ConfigureAwait(false);

            if (product == null)
            {
                return(null);
            }

            var productDefinition = await ProductRepository.GetProductDefinitionAsync(new GetProductDefinitionParam
            {
                Name        = product.DefinitionName,
                CultureInfo = param.CultureInfo
            });

            if (productDefinition == null)
            {
                return(null);
            }

            //TODO: Use the GetLookupDisplayName
            var productLookups = await LookupService.GetLookupsAsync(LookupType.Product);

            var productDetailImages = await GetProductImages(product, product.Variants);

            var currency = await ScopeViewService.GetScopeCurrencyAsync(new GetScopeCurrencyParam
            {
                CultureInfo = param.CultureInfo,
                Scope       = param.Scope
            });

            var productViewModel = CreateViewModel(new CreateProductDetailViewModelParam
            {
                Product             = product,
                ProductDefinition   = productDefinition,
                ProductLookups      = productLookups,
                ProductDetailImages = productDetailImages,
                CultureInfo         = param.CultureInfo,
                VariantId           = param.VariantId,
                BaseUrl             = param.BaseUrl,
                Currency            = currency,
            });

            productViewModel = await SetViewModelRecurringOrdersRelatedProperties(param, productViewModel, product);

            return(productViewModel);
        }
示例#7
0
        protected virtual async Task <ProductViewModel> SetViewModelRecurringOrdersRelatedProperties(GetProductParam param, ProductViewModel vm, Overture.ServiceModel.Products.Product product)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }

            var recurringOrdersEnabled = RecurringOrdersSettings.Enabled;

            var recurringOrderProgramName = product.PropertyBag.GetValueOrDefault <string>(Constants.ProductAttributes.RecurringOrderProgramName);

            if (string.IsNullOrWhiteSpace(recurringOrderProgramName))
            {
                return(vm);
            }

            vm.RecurringOrderProgramName            = recurringOrderProgramName;
            vm.Context["RecurringOrderProgramName"] = recurringOrderProgramName;

            var program = await RecurringOrdersRepository.GetRecurringOrderProgram(param.Scope, recurringOrderProgramName).ConfigureAwait(false);

            if (program == null)
            {
                return(vm);
            }

            vm.IsRecurringOrderEligible            = recurringOrdersEnabled;
            vm.Context["IsRecurringOrderEligible"] = recurringOrdersEnabled;

            if (recurringOrdersEnabled)
            {
                var recurringOrderProgramViewModel = RecurringOrderProgramViewModelFactory.CreateRecurringOrderProgramViewModel(program, param.CultureInfo);

                vm.RecurringOrderFrequencies            = recurringOrderProgramViewModel.Frequencies;
                vm.Context["RecurringOrderFrequencies"] = recurringOrderProgramViewModel.Frequencies;
            }

            return(vm);
        }
 public virtual Task <ProductViewModel> GetProductViewModelAsync(GetProductParam param)
 {
     return(ProductViewModelFactory.GetProductViewModel(param));
 }