public void ShouldReturnOnlyOneBackOrderableInformationIfDuplicatedProductIdsPassed() { // Arrange var orderableInfo = new OrderableInformation { Product = new InventoryProduct { ProductId = "1001" }, Status = StockStatus.InStock }; var invProduct1 = new InventoryProduct { ProductId = "1001" }; this._serviceProvider .GetBackOrderableInformation(Arg.Is <GetBackOrderableInformationRequest>(r => r.Shop.Name == "shopname" && r.Products.Contains(invProduct1) && r.Products.Count() == 1)) .ReturnsForAnyArgs(new GetBackOrderableInformationResult { OrderableInformation = new List <OrderableInformation> { orderableInfo } }); // Act var orderableInfos = this._inventoryService.GetBackOrderableInformation("shopname", new List <string> { "1001", "1001" }, string.Empty, string.Empty); // Assert orderableInfos.Count.Should().Be(1); orderableInfos.FirstOrDefault().ShouldBeEquivalentTo(orderableInfo); }
public void ShouldReturnOnlyProductIdIfNoBackOrderableInformationFound() { // Arrange var orderableInfo1 = new OrderableInformation { Product = new InventoryProduct { ProductId = "1001" } }; var orderableInfo2 = new OrderableInformation { Product = new InventoryProduct { ProductId = "1002" } }; var orderableInfos = new List <OrderableInformation> { orderableInfo1, orderableInfo2 }; var ids = new List <string> { "1001", "1002" }; this._serviceProvider .GetBackOrderableInformation(Arg.Is <GetBackOrderableInformationRequest>(r => r.Shop.Name == "shopname" && r.Products.First().ProductId == "1001" && r.Products.Last().ProductId == "1002" && r.Products.Count() == 2)) .Returns(new GetBackOrderableInformationResult { OrderableInformation = orderableInfos }); // Act & Assert this._inventoryService.GetBackOrderableInformation("shopname", ids, string.Empty, string.Empty).ShouldBeEquivalentTo(orderableInfos); }
/// <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; }
private void UpdateStockInformation(CommerceCartLine cartLine, string catalogName) { Assert.ArgumentNotNull(cartLine, nameof(cartLine)); var products = new List <InventoryProduct> { new CommerceInventoryProduct { ProductId = cartLine.Product.ProductId, CatalogName = catalogName } }; var stockInfoResult = InventoryManager.GetStockInformation(products, StockDetailsLevel.Status).ServiceProviderResult; 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 preOrderableResult = InventoryManager.GetPreOrderableInformation(products).ServiceProviderResult; if (preOrderableResult.OrderableInformation != null && preOrderableResult.OrderableInformation.Any()) { orderableInfo = preOrderableResult.OrderableInformation.FirstOrDefault(); } } else if (Equals(stockInfo.Status, StockStatus.BackOrderable)) { var backOrderableResult = InventoryManager.GetBackOrderableInformation(products).ServiceProviderResult; 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; }
/// <summary> /// Maps orderable information from model. /// </summary> /// <param name="orderableInfo">The orderable information.</param> /// <param name="orderableInfoModel">The orderable information model.</param> public static void MapOrderableInformationFromModel([NotNull] this OrderableInformation orderableInfo, [NotNull] OrderableInformationModel orderableInfoModel) { Assert.ArgumentNotNull(orderableInfo, "orderableInfo"); Assert.ArgumentNotNull(orderableInfoModel, "orderableInfoModel"); orderableInfo.CartQuantityLimit = orderableInfoModel.CartQuantityLimit; orderableInfo.InStockDate = orderableInfoModel.InStockDate; orderableInfo.OrderableEndDate = orderableInfoModel.OrderableEndDate; orderableInfo.OrderableStartDate = orderableInfoModel.OrderableStartDate; orderableInfo.RemainingQuantity = orderableInfoModel.RemainingQuantity; orderableInfo.ShippingDate = orderableInfoModel.ShippingDate; orderableInfo.Status = new StockStatus((int)orderableInfoModel.Status, orderableInfoModel.Status.ToString()); }
public void ShouldGetProductByIdBackOrderable() { // Arrange var stockInfo = new StockInformation { Product = new InventoryProduct { ProductId = "1001" }, Status = StockStatus.BackOrderable, AvailabilityDate = new DateTime(2014, 3, 12) }; var orderableInfo = new OrderableInformation { Product = new InventoryProduct { ProductId = "1001" }, Status = StockStatus.BackOrderable, InStockDate = new DateTime(2014, 3, 12) }; using (new SiteContextSwitcher(new TSiteContext("shopname"))) { using (var tree = new TTree { new TItem("T-800", new NameValueCollection { { "ExternalID", "1001" } }) }) { Item productItem = tree.Database.GetItem("/sitecore/content/home/T-800"); this.productService.ReadProduct("1001").Returns(productItem); this.pricingService.GetProductPrice("1001").Returns(5000); this._inventoryService .GetStockInformation("shopname", Arg.Is <IEnumerable <string> >(ids => ids.Contains("1001") && ids.Count() == 1), StockDetailsLevel.All, string.Empty, string.Empty) .Returns(new List <StockInformation> { stockInfo }); this._inventoryService .GetBackOrderableInformation("shopname", Arg.Is <IEnumerable <string> >(ids => ids.Contains("1001") && ids.Count() == 1), string.Empty, string.Empty) .Returns(new List <OrderableInformation> { orderableInfo }); GlassMapperService.Current.CreateClass <ProductModel, decimal, StockInformation, OrderableInformation>(false, false, Arg.Is <Item>(item => item.ID == productItem.ID), 5000, stockInfo, orderableInfo) .Returns(new ProductModel(5000, stockInfo, orderableInfo)); // Act var result = this.controller.Index("1001"); // Assert var productModel = (ProductModel)((ViewResult)result).Model; productModel.Price.Should().Be(5000); productModel.Status.Should().Be(StockStatus.BackOrderable); productModel.AvailabilityDate.Should().Be(new DateTime(2014, 3, 12)); productModel.InStockDate.Should().Be(new DateTime(2014, 3, 12)); } } }
public ActionResult Index([NotNull] string id) { Item productItem; if (string.IsNullOrEmpty(id)) { productItem = RenderingContext.Current.Rendering.Item; if (productItem != null) { var field = productItem.Fields[Constants.KnownFieldNames.ExternalId]; if (field != null && field.HasValue) { id = field.Value; } } } else { productItem = this.productService.ReadProduct(id); } var price = this.pricingService.GetProductPrice(id); var ids = new List <string> { id }; var stockInfos = this._inventoryService.GetStockInformation(Context.Site.Name, ids, StockDetailsLevel.All, this._obecContext.InventoryLocation, string.Empty); var stockInfo = stockInfos.FirstOrDefault(); OrderableInformation orderableInfo = null; if (stockInfo != null && stockInfo.Status != null) { if (Equals(stockInfo.Status, StockStatus.PreOrderable)) { orderableInfo = this._inventoryService.GetPreOrderableInformation(Context.Site.Name, ids, string.Empty, this._obecContext.InventoryLocation).FirstOrDefault(); } else if (Equals(stockInfo.Status, StockStatus.BackOrderable)) { orderableInfo = this._inventoryService.GetBackOrderableInformation(Context.Site.Name, ids, string.Empty, this._obecContext.InventoryLocation).FirstOrDefault(); } this._inventoryService.VisitedProductStockStatus(Context.Site.Name, stockInfo, string.Empty); } ProductModel productModel = orderableInfo == null?this.GetProductModel(productItem, price, stockInfo) : this.GetProductModel(productItem, price, stockInfo, orderableInfo); this._catalogService.VisitedProductDetailsPage(id, productModel.Name, string.Empty, string.Empty); return(this.View(productModel)); }
/// <summary> /// Updates the stock information. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="cartLine">The cart line.</param> /// <param name="catalogName">Name of the catalog.</param> protected virtual void UpdateStockInformation([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] CommerceCartLine cartLine, [NotNull] string catalogName) { Assert.ArgumentNotNull(cartLine, "cartLine"); var products = new List<InventoryProduct> { new CommerceInventoryProduct { ProductId = cartLine.Product.ProductId, CatalogName = catalogName } }; var stockInfoResult = this.InventoryManager.GetStockInformation(storefront, products, StockDetailsLevel.Status).ServiceProviderResult; 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 preOrderableResult = this.InventoryManager.GetPreOrderableInformation(storefront, products).ServiceProviderResult; if (preOrderableResult.OrderableInformation != null && preOrderableResult.OrderableInformation.Any()) { orderableInfo = preOrderableResult.OrderableInformation.FirstOrDefault(); } } else if (Equals(stockInfo.Status, StockStatus.BackOrderable)) { var backOrderableResult = this.InventoryManager.GetBackOrderableInformation(storefront, products).ServiceProviderResult; 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; }
/// <summary> /// Gets the product model. /// </summary> /// <param name="productItem">The product item.</param> /// <param name="price">The product price.</param> /// <param name="stockInformation">The stock information.</param> /// <param name="orderableInformation">The pre-orderable information.</param> /// <returns>The product model.</returns> private ProductModel GetProductModel(Item productItem, decimal price, StockInformation stockInformation, OrderableInformation orderableInformation) { ISitecoreService glassMapper = GlassMapperService.Current; var productModel = glassMapper.CreateClass <ProductModel, decimal, StockInformation, OrderableInformation>(false, false, productItem, price, stockInformation, orderableInformation); return(productModel.SetProductResource(this.productService, productItem)); }
/// <summary> /// Initializes a new instance of the <see cref="ProductModel" /> class. /// </summary> /// <param name="price">The price.</param> /// <param name="stockInformation">The stock information.</param> /// <param name="orderableInformation">The pre-orderable information.</param> public ProductModel(decimal price, StockInformation stockInformation, OrderableInformation orderableInformation) : this(price, stockInformation) { this.orderableInformation = orderableInformation; }