Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 692 posts 1068 karma points
    Oct 23, 2015 @ 12:53
    Simon
    0

    Update Cart Items Quantity CHECK

    Hi Guys,

    I cannot figure it out how I can check for products current quantity.

    Basically, I would check that once a user click on the update button in the bazaar, check for those products which are trackable and eventaully disallowing users from updating if the quantity is larger the that current stock.

    Can anybody lead me pleasE?

    thank you.

  • Simon 692 posts 1068 karma points
    Oct 24, 2015 @ 13:13
    Simon
    0

    Anyone can help me please?

    Thank you.

  • progproger 52 posts 130 karma points
    Dec 16, 2015 @ 10:42
    progproger
    0

    Hi Simon,

    You need to edit UpdateBasket action in BazaarBasketController... I've done only for product variants and it looks like:

            [HttpPost]
                    public ActionResult UpdateBasket(BasketTableModel model)
                    {
                        if (!this.ModelState.IsValid)
                            return this.CurrentUmbracoPage();
    
                        // The only thing that can be updated in this basket is the quantity
                        foreach (var item in model.Items.Where(item => this.Basket.Items.First(x => x.Key == item.Key).Quantity != item.Quantity))
                        {                
                            var currentVariant = MerchelloServices.ProductVariantService.GetByKey(new Guid(item.ExtendedData.GetValue("merchProductVariantKey")));//David M
                            var catalogInventory = currentVariant.CatalogInventories.First();
    
                            if (item.Quantity > catalogInventory.Count)
                            {
                                ModelState.AddModelError("", "Maximum quantity of '" + item.Name + "' is " + catalogInventory.Count);
                                return this.CurrentUmbracoPage();
                            }
    
                            this.Basket.UpdateQuantity(item.Key, item.Quantity);
                        }
    
                        this.Basket.Save();
    this.CurrentUmbracoPage();    
    
        }
    

    Also you should add hidden field to post value to action in BasketTable.cshtml:

    @Html.HiddenFor(model => Model.Items[i].ExtendedData["merchProductVariantKey"])
    

    Hidden should be in Model.Items loop ofc.

    To display an error, add @Html.ValidationSummary(true)

Please Sign in or register to post replies

Write your reply to:

Draft