Ejemplo n.º 1
0
        public bool InventoryCreateWithStatusSave(ProductInventory inv)
        {
            bool result = ProductInventories.Create(inv);

            if (result)
            {
                UpdateProductVisibleStatusAndSave(inv.ProductBvin);
            }
            return(result);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
        // 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;
        }
Ejemplo n.º 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);            
 }        
Ejemplo n.º 7
0
 public bool InventoryCreateWithStatusSave(ProductInventory inv)
 {
     bool result = ProductInventories.Create(inv);
     if (result) UpdateProductVisibleStatusAndSave(inv.ProductBvin);
     return result;
 }