public void ProductInventory_TestFindProductInventory()
        {
            //Create API Proxy
            var proxy = CreateApiProxy();

            //Create Product Inventory
            var productInventory = new ProductInventoryDTO
            {
                LowStockPoint    = 5,
                OutOfStockPoint  = 2,
                QuantityOnHand   = 50,
                QuantityReserved = 4,
                ProductBvin      = TestConstants.TestProductBvin
            };
            var createResponse = proxy.ProductInventoryCreate(productInventory);

            CheckErrors(createResponse);
            Assert.IsFalse(string.IsNullOrEmpty(createResponse.Content.Bvin));

            //Find Product Inventory
            var findResponse = proxy.ProductInventoryFind(createResponse.Content.Bvin);

            CheckErrors(findResponse);
            Assert.AreEqual(createResponse.Content.LowStockPoint, findResponse.Content.LowStockPoint);
            Assert.AreEqual(createResponse.Content.OutOfStockPoint, findResponse.Content.OutOfStockPoint);

            //Delete Product Inventory
            var deleteResponse = proxy.ProductInventoryDelete(createResponse.Content.Bvin);

            CheckErrors(deleteResponse);
            Assert.IsTrue(deleteResponse.Content);
        }
Esempio n. 2
0
        //DTO
        public ProductInventoryDTO ToDto()
        {
            ProductInventoryDTO dto = new ProductInventoryDTO();

            dto.Bvin             = this.Bvin;
            dto.LastUpdated      = this.LastUpdated;
            dto.LowStockPoint    = this.LowStockPoint;
            dto.ProductBvin      = this.ProductBvin;
            dto.QuantityOnHand   = this.QuantityOnHand;
            dto.QuantityReserved = this.QuantityReserved;
            dto.VariantId        = this.VariantId;

            return(dto);
        }
Esempio n. 3
0
        /// <summary>
        ///     Allows you to convert the current product inventory object to the DTO equivalent for use with the REST API
        /// </summary>
        /// <returns>A new instance of ProductInventoryDTO</returns>
        public ProductInventoryDTO ToDto()
        {
            var dto = new ProductInventoryDTO();

            dto.Bvin             = Bvin;
            dto.LastUpdated      = LastUpdated;
            dto.LowStockPoint    = LowStockPoint;
            dto.ProductBvin      = ProductBvin;
            dto.QuantityOnHand   = QuantityOnHand;
            dto.QuantityReserved = QuantityReserved;
            dto.OutOfStockPoint  = OutOfStockPoint;
            dto.VariantId        = VariantId;

            return(dto);
        }
Esempio n. 4
0
        public void FromDto(ProductInventoryDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            this.Bvin             = dto.Bvin;
            this.LastUpdated      = dto.LastUpdated;
            this.LowStockPoint    = dto.LowStockPoint;
            this.ProductBvin      = dto.ProductBvin;
            this.QuantityOnHand   = dto.QuantityOnHand;
            this.QuantityReserved = dto.QuantityReserved;
            this.VariantId        = dto.VariantId;
        }
Esempio n. 5
0
        /// <summary>
        ///     Allows you to populate the current product inventory object using a ProductInventoryDTO instance
        /// </summary>
        /// <param name="dto">An instance of the product inventory from the REST API</param>
        public void FromDto(ProductInventoryDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            Bvin             = dto.Bvin;
            LastUpdated      = dto.LastUpdated;
            LowStockPoint    = dto.LowStockPoint;
            ProductBvin      = dto.ProductBvin;
            QuantityOnHand   = dto.QuantityOnHand;
            QuantityReserved = dto.QuantityReserved;
            OutOfStockPoint  = dto.OutOfStockPoint;
            VariantId        = dto.VariantId;
        }
Esempio n. 6
0
        public void ProductInventory_Bug12570()
        {
            //Create API Proxy
            var proxy = CreateApiProxy();

            //Find Product by Slug
            var resP = proxy.ProductsBySlug(TestConstants.TestProduct1Slug);

            CheckErrors(resP);

            //Find Product Variants for given product
            var resV = proxy.ProductVariantsFindByProduct(resP.Content.Bvin);

            CheckErrors(resV);

            //Create Product Inventory
            var prodInvDto = new ProductInventoryDTO
            {
                ProductBvin    = resP.Content.Bvin,
                VariantId      = resV.Content.First().Bvin,
                QuantityOnHand = 11
            };

            //Update Product Inventory
            // 1-st pass
            var resI = proxy.ProductInventoryUpdate(prodInvDto);

            CheckErrors(resI);
            Assert.AreEqual(resI.Content.QuantityOnHand, prodInvDto.QuantityOnHand);

            //Update Product Inventory
            // 2-nd pass
            prodInvDto.QuantityOnHand = 10;
            resI = proxy.ProductInventoryUpdate(prodInvDto);

            CheckErrors(resI);
            Assert.AreEqual(resI.Content.QuantityOnHand, prodInvDto.QuantityOnHand);
        }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse <ProductInventoryDTO> response = new ApiResponse <ProductInventoryDTO>();

            ProductInventoryDTO postedItem = null;

            try
            {
                postedItem = MerchantTribe.Web.Json.ObjectFromJson <ProductInventoryDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return(MerchantTribe.Web.Json.ObjectToJson(response));
            }

            ProductInventory item = new ProductInventory();

            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                bool mustCreate = false;

                // see if there is already an inventory object for product
                List <ProductInventory> existing = MTApp.CatalogServices.ProductInventories.FindByProductId(item.ProductBvin);
                if (existing == null || existing.Count < 1)
                {
                    mustCreate = true;
                }
                else
                {
                    var pi = existing.Where(y => y.VariantId == string.Empty).FirstOrDefault();
                    if (pi == null)
                    {
                        mustCreate = true;
                    }
                    else
                    {
                        pi.LowStockPoint    = item.LowStockPoint;
                        pi.QuantityOnHand   = item.QuantityOnHand;
                        pi.QuantityReserved = item.QuantityReserved;
                        MTApp.CatalogServices.ProductInventories.Update(pi);
                        bvin = pi.Bvin;
                    }
                }

                // if inventory object doesn't exist yet, create one.
                if (mustCreate)
                {
                    if (MTApp.CatalogServices.ProductInventories.Create(item))
                    {
                        bvin = item.Bvin;
                    }
                }
            }
            else
            {
                MTApp.CatalogServices.ProductInventories.Update(item);
            }
            ProductInventory resultItem = MTApp.CatalogServices.ProductInventories.Find(bvin);

            if (resultItem != null)
            {
                response.Content = resultItem.ToDto();
            }

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }
Esempio n. 8
0
        /// <summary>
        ///     Allows the REST API to create or update inventory for a product
        /// </summary>
        /// <param name="parameters">
        ///     Parameters passed in the URL of the REST API call. If there is a first parameter found in the
        ///     URL, the method will assume it is the product inventory ID (bvin) and that this is an update, otherwise it assumes
        ///     to create product inventory.
        /// </param>
        /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param>
        /// <param name="postdata">Serialized (JSON) version of the ProductInventoryDTO object</param>
        /// <returns>ProductInventoryDTO - Serialized (JSON) version of the product inventory</returns>
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            var bvin = FirstParameter(parameters);

            ProductInventoryDTO postedItem = null;

            try
            {
                postedItem = Json.ObjectFromJson <ProductInventoryDTO>(postdata);
            }
            catch (Exception ex)
            {
                return(JsonApiResponseException(ex));
            }

            var item = new ProductInventory();

            // convert the dto to a cbo
            item.FromDto(postedItem);

            // update the store id if it isn't populated (prevents an obscured issue with updates)
            if (item.StoreId == 0)
            {
                item.StoreId = HccApp.CurrentStore.Id;
            }

            if (string.IsNullOrEmpty(bvin))
            {
                // see if there is already an inventory object for product
                var pi = HccApp.CatalogServices.ProductInventories.FindByProductIdAndVariantId(item.ProductBvin,
                                                                                               item.VariantId);
                if (pi != null)
                {
                    // update the existing object with the posted information
                    pi.OutOfStockPoint  = item.OutOfStockPoint;
                    pi.LowStockPoint    = item.LowStockPoint;
                    pi.QuantityOnHand   = item.QuantityOnHand;
                    pi.QuantityReserved = item.QuantityReserved;

                    // update the inventory
                    HccApp.CatalogServices.ProductInventories.Update(pi);

                    // update the local variable to get updated data later
                    bvin = pi.Bvin;
                }
                else
                {
                    // if inventory object doesn't exist yet, create one.
                    if (HccApp.CatalogServices.ProductInventories.Create(item))
                    {
                        // update the local variable to get updated data later
                        bvin = item.Bvin;
                    }
                }
            }
            else
            {
                // update the inventory
                HccApp.CatalogServices.ProductInventories.Update(item);
            }

            // update the visibility/availability status of the product
            if (!string.IsNullOrEmpty(item.ProductBvin))
            {
                var product = HccApp.CatalogServices.Products.Find(item.ProductBvin);
                if (product != null)
                {
                    HccApp.CatalogServices.UpdateProductVisibleStatusAndSave(product);
                }
            }

            // get an updated instance of the inventory
            var resultItem = HccApp.CatalogServices.ProductInventories.Find(bvin);

            // return the result
            return(JsonApiResponse(resultItem.ToDto()));
        }