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.
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:
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.
Anyone can help me please?
Thank you.
Hi Simon,
You need to edit UpdateBasket action in BazaarBasketController... I've done only for product variants and it looks like:
Also you should add hidden field to post value to action in BasketTable.cshtml:
Hidden should be in Model.Items loop ofc.
To display an error, add
@Html.ValidationSummary(true)
is working on a reply...