Пример #1
0
 public void GetStockInformation_IfParameterIsNull_ShouldThrowArgumentNullException(
     string shopName,
     IEnumerable <CommerceInventoryProduct> inventoryProducts,
     StockDetailsLevel detailsLevel)
 {
     // act, assert
     Assert.Throws <ArgumentNullException>(
         () => this.inventoryManager.GetStockInformation(shopName, inventoryProducts, detailsLevel));
 }
        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));
        }
Пример #3
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>()));
        }
Пример #4
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>());
        }
        /// <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>()));
        }
        /// <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);
        }
Пример #7
0
        /// <summary>
        /// Populates an OBEC <see cref="StockInformation"/> entity based on a NOP <see cref="StockInformationModel"/> model.
        /// </summary>
        /// <param name="entity">The OBEC <see cref="StockInformation"/> entity to populate.</param>
        /// <param name="model">The NOP <see cref="StockInformationModel"/> model.</param>
        /// <param name="detailsLevel">The stock information details level to retrieved.</param>
        protected virtual void PopulateStockInformation([NotNull] StockInformation entity, [NotNull] StockInformationModel model, StockDetailsLevel detailsLevel)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(entity, "entity");
            Sitecore.Diagnostics.Assert.IsNotNull(model, "model");

            entity.Product           = this.EntityFactory.Create <InventoryProduct>("InventoryProduct");
            entity.Product.ProductId = model.ProductId;

            if ((detailsLevel.Value & StockDetailsLevel.AvailibilityFlag) != 0)
            {
                entity.AvailabilityDate = model.AvailabilityDate;
            }

            if ((detailsLevel.Value & StockDetailsLevel.CountFlag) != 0)
            {
                entity.Count = model.Count;
            }

            if ((detailsLevel.Value & StockDetailsLevel.StatusFlag) != 0)
            {
                entity.Status = this.GetStockStatus(model.Status);
            }
        }
Пример #8
0
 public ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > GetStockInformation(CommerceStorefront storefront, IEnumerable <InventoryProduct> products, StockDetailsLevel detailsLevel)
 {
     return(null);
 }
        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>()));
        }
        /// <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>());
        }
Пример #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>()));
        }