In my Nopcommerce store some of my product variants have a maximum cart setting.
I would like to have the quantity option in my store change based on the maximum cart setting.
For instance, if the maximum cart setting was the default setting of 10,000 I would like the quantity option to stay how it is, just a text box that allows the customer to enter the quantity.
However, if I set the maximum cart setting for a product variant was something under 10; I would like the quantity option to be displayed as a dropdown menu - 1 through the maximum cart setting.
In the following post it was discussed how you could change the quantity box to a dropdown menu.
https://www.nopcommerce.com/boards/t/16874/change-qty-to-drop-box-and-default-is-zero.aspx
However, I am getting an error when I try to reference the maximum cart setting in the _ProductVariantAddToCart.cshtml.
Here is how I tried to code it.
@if (!Model.DisableBuyButton || !Model.DisableWishlistButton)
{
if (Model.OrderMaximumQuantity <= 10)
{
var maxQty = Model.OrderMaximumQuantity;
var selectList = new List<SelectListItem>(maxQty);
for (var i = 1; i <= maxQty; i++)
{
selectList.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
}
@Html.DropDownListFor(model => model.EnteredQuantity, selectList, new { @class = "qty-input" })
}
else
{
@Html.LabelFor(model => model.EnteredQuantity)<text>:</text>
@Html.TextBoxFor(model => model.EnteredQuantity, new { style = "Width: 40px;" })
}
}
The _ProductVariantAddToCart.cshtml does not recognize the Model.OrderMaximumQuantity in the code. I think I need to use @model ProductVariant in order to get the Model.OrderMaximumQuantity to work. However this makes the model.EnteredQuantity show up as an error. So I thought that I might be able to put both at the top like
@model Nop.Web.Models.Catalog.ProductModel.ProductVariantModel.AddToCartModel
@model ProductVariant
but this was also an error.
Does anyone know how I can reference the maximum cart settting in _ProductVariantAddToCart.cshtml?
I am not a programmer so if someone could look at the code and show me how to fix it or how I should go about this I would greatly appreciate it.
I am using Nopcommerce Version 2.4
Thanks in advance!