change qty to drop box and default is zero

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Due do a special requirement, i would like to change two things in the product page:

1. change qty field to a drop box instead of textbox
2. made the qty default as zero instead of 1

any ideas how, please help, thank you!
11 years ago
For 2.50, you can change quantity textfield to a select list with the following change:

Note that you can copy this view to your theme (using the same folder path) to preserve the changes when you update your store.

Edit: Views\Catalog\_ProductVariantAddToCart.cshtml

Remove or comment out line 16 and add the following code:
var maxQty = 100;
var selectList = new List<SelectListItem>(maxQty + 1);
for (var i = 0; i <= maxQty; i++)
{
    selectList.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
}
@Html.DropDownListFor(model => model.EnteredQuantity, selectList, new { @class = "qty-input" })

You can control the number of items in the select list by modifying the line "var maxQty = 100;".  By being the first entry, the zero option is selected by default. This will affect both the SingleVariant and VariantsInGrid product templates.

.
11 years ago
(minor nitpick :)
You have for loop from 0 to less than or equal max.  That will add one more than your initially declared list capacity (which I think actually will double the list capacity).
Personally I'd start from 1 anyway  ... var i = 1; i <= maxQty; ...  , since we'd like customer to buy :)
11 years ago
New York wrote:
(minor nitpick :)
[...]

Thanks, code has been updated.

.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.