public JsonResult GetCurrentProductStockInfo(ProductStockInfoInputModel model)
        {
            try
            {
                Assert.ArgumentNotNull(model, "model");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var currentProductItem = SearchNavigation.GetProduct(model.ProductId, CurrentCatalog.Name);
                var productId          = currentProductItem.Name;
                var catalogName        = currentProductItem["CatalogName"];
                var products           = new List <CommerceInventoryProduct>();
                if (currentProductItem.HasChildren)
                {
                    foreach (Item item in currentProductItem.Children)
                    {
                        products.Add(new CommerceInventoryProduct
                        {
                            ProductId   = productId,
                            CatalogName = catalogName,
                            VariantId   = item["VariantId"]
                        });
                    }
                }
                else
                {
                    products.Add(new CommerceInventoryProduct {
                        ProductId = productId, CatalogName = catalogName
                    });
                }

                var response = this.InventoryManager.GetStockInformation(this.CurrentStorefront, products, StockDetailsLevel.All);
                var result   = new StockInfoListBaseJsonResult(response.ServiceProviderResult);
                if (response.Result == null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.Initialize(response.Result);
                var stockInfo = response.Result.FirstOrDefault();
                if (stockInfo != null)
                {
                    this.InventoryManager.VisitedProductStockStatus(this.CurrentStorefront, stockInfo, string.Empty);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("GetCurrentProductStockInfo", this, e);
                return(Json(new BaseJsonResult("GetCurrentProductStockInfo", e), JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public StockInfoListBaseJsonResult GetCurrentProductStockInfo(string productId)
        {
            var currentProductItem = SearchNavigation.GetProduct(productId, CurrentCatalog.Name);

            productId = currentProductItem.Name;
            var catalogName = currentProductItem[CommerceTemplates.CommerceGenerated.GeneralCategory.Fields.CatalogName];
            var products    = new List <CommerceInventoryProduct>();

            if (currentProductItem.HasChildren)
            {
                foreach (Item item in currentProductItem.Children)
                {
                    products.Add(new CommerceInventoryProduct
                    {
                        ProductId   = productId,
                        CatalogName = catalogName,
                        VariantId   = item.Name
                    });
                }
            }
            else
            {
                products.Add(new CommerceInventoryProduct {
                    ProductId = productId, CatalogName = catalogName
                });
            }

            var response = _inventoryManager.GetStockInformation(this.CurrentStorefront, products, StockDetailsLevel.All);
            var result   = new StockInfoListBaseJsonResult(response.ServiceProviderResult);

            if (response.Result == null)
            {
                return(result);
            }

            result.Initialize(response.Result);
            var stockInfo = response.Result.FirstOrDefault();

            if (stockInfo != null)
            {
                _inventoryManager.VisitedProductStockStatus(this.CurrentStorefront, stockInfo, string.Empty);
            }

            return(result);
        }