コード例 #1
0
        public void ShouldNotAddNewRecordsIfProductStockInformationIsNotFound()
        {
            // Arrange
            var request = new GetStockInformationRequest("shopname", new List <InventoryProduct> {
                new InventoryProduct {
                    ProductId = "noExist"
                }
            });
            var result = new GetStockInformationResult();
            var args   = new ServicePipelineArgs(request, result);

            var results = new StockInformationModel[1];

            results[0] = null;
            this._client.GetStocksInformation("shopname", Arg.Is <string[]>(ids => (ids.Length == 1) && (ids[1] == "noExist")), new System.Guid()).Returns(results);

            // Act
            this._processor.Process(args);

            // Assert
            result.StockInformation.Should().HaveCount(1);
            result.StockInformation.ElementAt(0).Product.ProductId.Should().Be("noExist");
            result.StockInformation.ElementAt(0).Status.Should().Be(null);
            result.StockInformation.ElementAt(0).Count.Should().Be(0);
            result.StockInformation.ElementAt(0).AvailabilityDate.Should().Be(null);
        }
        /// <summary>
        /// Gets the product stock information.
        /// </summary>
        /// <param name="shopName">The shop name.</param>
        /// <param name="productIds">The product ids.</param>
        /// <param name="detailsLevel">The details level.</param>
        /// <param name="location">The location.</param>
        /// <param name="visitorId">The visitor id.</param>
        /// <returns>The products stock information.</returns>
        public List <StockInformation> GetStockInformation(string shopName, IEnumerable <string> productIds, StockDetailsLevel detailsLevel, string location, string visitorId)
        {
            var request = new GetStockInformationRequest(shopName, productIds.Select(pid => new InventoryProduct {
                ProductId = pid
            }).ToList(), detailsLevel)
            {
                Location = location, VisitorId = visitorId
            };
            GetStockInformationResult result = this._serviceProvider.GetStockInformation(request);
            var stockInfos = new List <StockInformation>();

            if (result == null)
            {
                return(stockInfos);
            }

            foreach (var stockInfo in productIds.Select(id => (result.StockInformation.FirstOrDefault(i => i.Product.ProductId.Equals(id, System.StringComparison.OrdinalIgnoreCase)) ?? new StockInformation {
                Product = new InventoryProduct {
                    ProductId = id
                }
            })).Where(stockInfo => !stockInfos.Contains(stockInfo)))
            {
                stockInfos.Add(stockInfo);
            }

            return(stockInfos);
        }
コード例 #3
0
        public void ShouldGetStockInformationOnlyStatusForTheSpecifiedProducts()
        {
            // Arrange
            var request = new GetStockInformationRequest("shopname", new List <InventoryProduct> {
                new InventoryProduct {
                    ProductId = "pid1"
                }
            });
            var result = new GetStockInformationResult();
            var args   = new ServicePipelineArgs(request, result);

            this._client.GetStocksInformation("shopname", Arg.Is <string[]>(ids => (ids.Length == 1) && (ids[0] == "pid1")), new System.Guid())
            .Returns(new[] { new StockInformationModel {
                                 ProductId = "pid1", Status = NopCommerce.NopInventoryService.StockStatus.InStock
                             } });

            // Act
            this._processor.Process(args);

            // Assert
            result.StockInformation.Should().HaveCount(1);
            result.StockInformation.ElementAt(0).Product.ProductId.Should().Be("pid1");
            result.StockInformation.ElementAt(0).Status.Should().Be(1);
            result.StockInformation.ElementAt(0).Count.Should().Be(0);
            result.StockInformation.ElementAt(0).AvailabilityDate.Should().Be(null);
        }
コード例 #4
0
        /// <summary>
        /// The update stock informationS.
        /// </summary>
        /// <param name="cartLine">The cart line.</param>
        private void UpdateStockInformation([NotNull] CartLine cartLine)
        {
            Assert.ArgumentNotNull(cartLine, "cartLine");

            var products = new List <InventoryProduct> {
                new InventoryProduct {
                    ProductId = cartLine.Product.ProductId
                }
            };
            var stockInfoRequest = new GetStockInformationRequest(this.ShopName, products, StockDetailsLevel.Status);
            var stockInfoResult  = this._inventoryServiceProvider.GetStockInformation(stockInfoRequest);

            if (stockInfoResult.StockInformation == null || !stockInfoResult.StockInformation.Any())
            {
                return;
            }

            var stockInfo     = stockInfoResult.StockInformation.FirstOrDefault();
            var orderableInfo = new OrderableInformation();

            if (stockInfo != null && stockInfo.Status != null)
            {
                if (Equals(stockInfo.Status, StockStatus.PreOrderable))
                {
                    var preOrderableRequest = new GetPreOrderableInformationRequest(this.ShopName, products);
                    var preOrderableResult  = this._inventoryServiceProvider.GetPreOrderableInformation(preOrderableRequest);
                    if (preOrderableResult.OrderableInformation != null && preOrderableResult.OrderableInformation.Any())
                    {
                        orderableInfo = preOrderableResult.OrderableInformation.FirstOrDefault();
                    }
                }
                else if (Equals(stockInfo.Status, StockStatus.BackOrderable))
                {
                    var backOrderableRequest = new GetBackOrderableInformationRequest(this.ShopName, products);
                    var backOrderableResult  = this._inventoryServiceProvider.GetBackOrderableInformation(backOrderableRequest);
                    if (backOrderableResult.OrderableInformation != null && backOrderableResult.OrderableInformation.Any())
                    {
                        orderableInfo = backOrderableResult.OrderableInformation.FirstOrDefault();
                    }
                }
            }

            if (stockInfo != null)
            {
                cartLine.Product.StockStatus = stockInfo.Status;
            }

            if (orderableInfo == null)
            {
                return;
            }

            cartLine.Product.InStockDate  = orderableInfo.InStockDate;
            cartLine.Product.ShippingDate = orderableInfo.ShippingDate;
        }
コード例 #5
0
        public GetStockInformationResult GetStockInformation(
            string shopName,
            IEnumerable <CommerceInventoryProduct> inventoryProducts,
            StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNullOrEmpty(shopName, nameof(shopName));
            Assert.ArgumentNotNull(inventoryProducts, nameof(inventoryProducts));
            Assert.ArgumentNotNull(detailsLevel, nameof(detailsLevel));

            var request = new GetStockInformationRequest(shopName, inventoryProducts, detailsLevel);

            return(this.Execute(request, this.inventoryServiceProvider.GetStockInformation));
        }
コード例 #6
0
        /// <summary>
        /// Gets the stock information.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="products">The products.</param>
        /// <param name="detailsLevel">The details level.</param>
        /// <returns>
        /// The manager response which returns an enumerable collection of StockInformation in the Result.
        /// </returns>
        public virtual ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > GetStockInformation([NotNull] CommerceStorefront storefront, IEnumerable <InventoryProduct> products, StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(products, "products");

            var request = new GetStockInformationRequest(storefront.ShopName, products, detailsLevel)
            {
                Location = this._obecContext.InventoryLocation, VisitorId = this.ContactFactory.GetContact()
            };
            var result = this.InventoryServiceProvider.GetStockInformation(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> >(result, result.StockInformation ?? new List <StockInformation>()));
        }
コード例 #7
0
        public ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > GetStockInformation(
            string shopName,
            IEnumerable <CommerceInventoryProduct> inventoryProducts,
            StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNull(inventoryProducts, nameof(inventoryProducts));

            var request = new GetStockInformationRequest(shopName, inventoryProducts, detailsLevel);

            request.Location = string.Empty;

            GetStockInformationResult stockInformation = this.inventoryServiceProvider.GetStockInformation(request);

            return(new ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> >(stockInformation, stockInformation.StockInformation ?? new List <StockInformation>()));
        }
        /// <summary>
        /// Gets the stock information.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="products">The products.</param>
        /// <param name="detailsLevel">The details level.</param>
        /// <returns>
        /// The manager response which returns an enumerable collection of StockInformation in the Result.
        /// </returns>
        public virtual ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > GetStockInformation([NotNull] CommerceStorefront storefront, IEnumerable <InventoryProduct> products, StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(products, "products");

            var request = new GetStockInformationRequest(storefront.ShopName, products, detailsLevel)
            {
                Location = this._obecContext.InventoryLocation, VisitorId = this._contactFactory.GetContact()
            };
            var result = this._inventoryServiceProvider.GetStockInformation(request);

            // Currently, both Categories and Products are passed in and are waiting for a fix to filter the categories out.  Until then, this code is commented
            // out as it generates an unecessary Error event indicating the product cannot be found.
            // Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> >(result, result.StockInformation ?? new List <StockInformation>()));
        }
コード例 #9
0
        public ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > GetStockInformation(IEnumerable <InventoryProduct> products, StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNull(products, nameof(products));
            if (StorefrontContext.Current == null)
            {
                throw new InvalidOperationException("Cannot be called without a valid storefront context.");
            }

            var request = new GetStockInformationRequest(StorefrontContext.Current.ShopName, products, detailsLevel)
            {
                Location = _obecContext.InventoryLocation, VisitorId = ContactFactory.GetContact()
            };
            var result = InventoryServiceProvider.GetStockInformation(request);

            // Currently, both Categories and Products are passed in and are waiting for a fix to filter the categories out.  Until then, this code is commented
            // out as it generates an unecessary Error event indicating the product cannot be found.
            // result.WriteToSitecoreLog();
            return(new ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> >(result, result.StockInformation ?? new List <StockInformation>()));
        }
コード例 #10
0
        /// <summary>
        /// Gets the stock information.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="products">The products.</param>
        /// <param name="detailsLevel">The details level.</param>
        /// <returns>
        /// The manager response which returns an enumerable collection of StockInformation in the Result.
        /// </returns>
        public virtual ManagerResponse<GetStockInformationResult, IEnumerable<StockInformation>> GetStockInformation([NotNull] CommerceStorefront storefront, IEnumerable<InventoryProduct> products, StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(products, "products");

            var request = new GetStockInformationRequest(storefront.ShopName, products, detailsLevel) { Location = this._obecContext.InventoryLocation, VisitorId = this.ContactFactory.GetContact() };
            var result = this.InventoryServiceProvider.GetStockInformation(request);

            // Currently, both Categories and Products are passed in and are waiting for a fix to filter the categories out.  Until then, this code is commented
            // out as it generates an unecessary Error event indicating the product cannot be found.
            // Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<GetStockInformationResult, IEnumerable<StockInformation>>(result, result.StockInformation ?? new List<StockInformation>());
        }
コード例 #11
0
        /// <summary>
        /// Gets the stock information.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="products">The products.</param>
        /// <param name="detailsLevel">The details level.</param>
        /// <returns>
        /// The manager response which returns an enumerable collection of StockInformation in the Result.
        /// </returns>
        public virtual ManagerResponse<GetStockInformationResult, IEnumerable<StockInformation>> GetStockInformation([NotNull] CommerceStorefront storefront, IEnumerable<InventoryProduct> products, StockDetailsLevel detailsLevel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(products, "products");

            var request = new GetStockInformationRequest(storefront.ShopName, products, detailsLevel) { Location = this._obecContext.InventoryLocation, VisitorId = this.ContactFactory.GetContact() };
            var result = this.InventoryServiceProvider.GetStockInformation(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<GetStockInformationResult, IEnumerable<StockInformation>>(result, result.StockInformation ?? new List<StockInformation>());
        }