protected bool ValidateInventory(Product p, string qty)
        {
            bool result = true;

            decimal quantity = 1;

            decimal.TryParse(qty, out quantity);
            if (quantity < 1)
            {
                return(true);
            }

            InventoryCheckData inv = MTApp.CatalogServices.InventoryCheck(p, string.Empty);

            if (inv.IsAvailableForSale && inv.Qty >= quantity)
            {
                result = true;
            }
            else
            {
                result = false;
                if (inv.IsAvailableForSale == true)
                {
                    MessageBox1.ShowWarning("Only " + inv.Qty.ToString() + " of the item " + p.Sku + " are available for purchase. Please adjust your requested amount.");
                }
            }

            return(result);
        }
Beispiel #2
0
        private void CheckForBackOrder(ProductPageViewModel model)
        {
            InventoryCheckData data = MTApp.CatalogServices.InventoryCheck(model.LocalProduct, string.Empty);

            model.StockMessage       = data.InventoryMessage;
            model.IsAvailableForSale = data.IsAvailableForSale;
        }
Beispiel #3
0
        public ActionResult Validate()
        {
            ProductValidateResponse result = new ProductValidateResponse();

            string  bvin = Request.Form["productbvin"];
            Product p    = MTApp.CatalogServices.Products.Find(bvin);

            if ((p != null))
            {
                OptionSelectionList selections = ParseSelections(p);



                UserSpecificPrice price = MTApp.PriceProduct(p, MTApp.CurrentCustomer, selections);

                result.Price    = MerchantTribe.Commerce.Utilities.HtmlRendering.UserSpecificPriceForDisplay(price);
                result.Sku      = price.Sku;
                result.ImageUrl = MerchantTribe.Commerce.Storage.DiskStorage.ProductImageUrlMedium(MTApp, p.Bvin, p.ImageFileSmall, false);
                result.IsValid  = price.IsValid;
                if (result.IsValid)
                {
                    result.Message = string.Empty;
                }
                else
                {
                    result.Message = "<div class=\"flash-message-warning\">The combination of options you've selected isn't available at the moment. Please select different options.</div>";
                }
                if (price.VariantId.Length > 0)
                {
                    result.ImageUrl = MerchantTribe.Commerce.Storage.DiskStorage.ProductVariantImageUrlMedium(MTApp, p.Bvin, p.ImageFileSmall, price.VariantId, false);
                }

                // Make sure we have stock on the product or variant
                InventoryCheckData data = MTApp.CatalogServices.InventoryCheck(p, price.VariantId);
                result.StockMessage = data.InventoryMessage;
                if (result.IsValid)
                {
                    if (!data.IsAvailableForSale)
                    {
                        result.IsValid = false;
                        // Should this be here?
                        //result.Message = "Out of stock?";
                    }
                }

                // Make sure no "labels" are selected
                if (selections.HasLabelsSelected())
                {
                    result.IsValid = false;
                    result.Message = "<div class=\"flash-message-warning\">Please make all selections before adding to cart.</div>";
                }
            }

            return(new PreJsonResult(MerchantTribe.Web.Json.ObjectToJson(result)));
        }
        private bool CheckProduct(PromotionContext context, Product prod, LineItem li, int mainQuantity)
        {
            InventoryCheckData check = null;

            if (!prod.IsBundle)
            {
                var prodQuantity = CalculateProductQuantity(context, prod, li, mainQuantity);
                check = context.HccApp.CatalogServices.SimpleProductInventoryCheck(prod,
                                                                                   li.SelectionData.OptionSelectionList, prodQuantity);

                return(check.IsInStock);
            }
            var results = new List <InventoryCheckData>();

            foreach (var bundledProductAdv in prod.BundledProducts)
            {
                var bundledProduct = bundledProductAdv.BundledProduct;
                if (bundledProduct == null)
                {
                    continue;
                }

                var optionSelection = li.SelectionData.GetSelections(bundledProductAdv.Id);
                var quantity        = bundledProductAdv.Quantity * mainQuantity;
                var prodQuantity    = CalculateProductQuantity(context, bundledProductAdv, optionSelection, quantity);
                var singleResult    = context.HccApp.CatalogServices.SimpleProductInventoryCheck(bundledProduct,
                                                                                                 optionSelection, prodQuantity);

                if (!singleResult.IsInStock)
                {
                    return(false);
                }
            }

            return(true);
        }