Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
0
        public int InventoryReserveQuantity(string productBvin, string variantId, int quantity, bool ReserveZeroWhenQuantityTooLow)
        {
            Catalog.ProductInventory inv = ProductInventories.FindByProductIdAndVariantId(productBvin, variantId);

            // If no inventory, assume available
            if (inv == null)
            {
                return(quantity);
            }

            Catalog.Product prod = Products.Find(productBvin);
            if (prod != null)
            {
                if (prod.InventoryMode == ProductInventoryMode.AlwayInStock)
                {
                    return(quantity);
                }

                if (inv != null && inv.Bvin != string.Empty)
                {
                    switch (prod.InventoryMode)
                    {
                    case ProductInventoryMode.AlwayInStock:
                        inv.QuantityReserved += quantity;
                        ProductInventories.Update(inv);
                        return(quantity);

                    case ProductInventoryMode.WhenOutOfStockAllowBackorders:
                        inv.QuantityReserved += quantity;
                        ProductInventories.Update(inv);
                        return(quantity);

                    case ProductInventoryMode.WhenOutOfStockShow:
                        if (inv.QuantityAvailableForSale < quantity)
                        {
                            if (ReserveZeroWhenQuantityTooLow)
                            {
                                return(0);
                            }
                            else
                            {
                                inv.QuantityReserved += inv.QuantityAvailableForSale;
                                ProductInventories.Update(inv);
                                return(inv.QuantityAvailableForSale);
                            }
                        }
                        else
                        {
                            inv.QuantityReserved += quantity;
                            ProductInventories.Update(inv);
                            return(quantity);
                        }

                    case ProductInventoryMode.WhenOutOfStockHide:
                        if (inv.QuantityAvailableForSale < quantity)
                        {
                            if (ReserveZeroWhenQuantityTooLow)
                            {
                                return(0);
                            }
                            else
                            {
                                inv.QuantityReserved += inv.QuantityAvailableForSale;
                                ProductInventories.Update(inv);
                                return(inv.QuantityAvailableForSale);
                            }
                        }
                        else
                        {
                            inv.QuantityReserved += quantity;
                            ProductInventories.Update(inv);
                            return(quantity);
                        }
                    }
                    return(0);
                }
                else
                {
                    if (prod != null)
                    {
                        if (prod.InventoryMode == ProductInventoryMode.AlwayInStock)
                        {
                            return(0);
                        }
                        else
                        {
                            return(quantity);
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }

            return(0);
        }