コード例 #1
0
        public bool InventoryCreateWithStatusSave(ProductInventory inv)
        {
            bool result = ProductInventories.Create(inv);

            if (result)
            {
                UpdateProductVisibleStatusAndSave(inv.ProductBvin);
            }
            return(result);
        }
コード例 #2
0
        private void InventoryGenerateSingleInventory(string bvin, string variantId, int onHand, int lowStockPoint)
        {
            ProductInventory i = new ProductInventory();

            i.LowStockPoint    = lowStockPoint;
            i.ProductBvin      = bvin;
            i.QuantityOnHand   = onHand;
            i.QuantityReserved = 0;
            i.VariantId        = variantId;
            InventoryCreateWithStatusSave(i);
        }
コード例 #3
0
        public bool InventoryUnreserveQuantity(string productBvin, string variantId, int quantity)
        {
            bool             result = false;
            ProductInventory inv    = ProductInventories.FindByProductIdAndVariantId(productBvin, variantId);

            if (inv != null)
            {
                inv.QuantityReserved -= quantity;
                ProductInventories.Update(inv);
                UpdateProductVisibleStatusAndSave(productBvin);
            }
            return(result);
        }
コード例 #4
0
        public bool InventorySetAvailableQuantity(string productId, string variantId, int quantity)
        {
            bool             result = false;
            ProductInventory inv    = ProductInventories.FindByProductIdAndVariantId(productId, variantId);

            if (inv != null)
            {
                inv.QuantityOnHand = quantity;
                result             = ProductInventories.Update(inv);
                UpdateProductVisibleStatusAndSave(inv.ProductBvin);
            }
            return(result);
        }
コード例 #5
0
        // 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;
        }
コード例 #6
0
 private void InventoryGenerateSingleInventory(string bvin, string variantId, int onHand, int lowStockPoint)
 {
     ProductInventory i = new ProductInventory();
     i.LowStockPoint = lowStockPoint;
     i.ProductBvin = bvin;
     i.QuantityOnHand = onHand;
     i.QuantityReserved = 0;
     i.VariantId = variantId;
     InventoryCreateWithStatusSave(i);            
 }        
コード例 #7
0
 public bool InventoryCreateWithStatusSave(ProductInventory inv)
 {
     bool result = ProductInventories.Create(inv);
     if (result) UpdateProductVisibleStatusAndSave(inv.ProductBvin);
     return result;
 }