How to make the first drop-down product attribute just informational

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hi I posted the same question on Nop-Template Forum #4546

Hi Support, we created a product attribute named "item condition" . The first pre-selected attribute is only informational with a text hint "select on" in there, to direct the customer, to choose one of the attributes in the drop-down.
If the customer just click "buy" without making any selection (and that will happen very often) the first record is retrieved as "select one" and added to the cart. his is not the desired behavior, I did check the Motion demo store and the same happen if Buy is clicked for the blank pre-selected box.
Question: Will be possible to make the first selection of the product attribute drop-down just informational with no Ajax control applied to it?
10 years ago
Two ways.

(remove your extra "choose one" attribute, then ...)

1) Use radio button instead of drop-down

2) If you really want drop-down, then minor code change: In \Views\Catalog\_ProductAttributes.cshtml
Add this
@if (!attribute.Values.Any(pav => pav.IsPreSelected))
{
    <option value="" disabled="disabled" selected="selected">Select your option</option>
}


after this
                            @foreach (var pvaValue in attribute.Values)
                            {
                                <option selected="@pvaValue.IsPreSelected" value="@pvaValue.Id">@pvaValue.Name
                                    @(!String.IsNullOrEmpty(pvaValue.PriceAdjustment) ? " [" + pvaValue.PriceAdjustment + "]" : null)
                                </option>
                            }


(P.S.  If you use mobile theme, then you may need to do similar in _ProductAttributes.Mobile.cshtml)

(P.P.S.  Andrei, it might be a nice feature - new setting "include choose option for drop-down attribute values when none preselected".  )
10 years ago
Thank you a lot New York guru.
Just brilliant!, I didn't use radio buttons because the look and feel of it, isn't as neat as drop-down controls, at least, in this specific case.
The code snippet injection you wrote, work perfectly, even triggering validation if (attribute.IsRequired) is ticked on the Admin/Product/Edit/--> attribute record
..sweet...
9 years ago
Thank you for the snippet, this has been an ongoing issue for us and this works great for requiring the selection! However, I get $NaN for the price until options are selected, even with a price set in the main product listing. Is there a way to show the default price and adjust that price once a selection is made with a price adjustment?

Thanks again
9 years ago
@benjaminlp, I haven't being able to puzzzle this one out, nor found help or a solution yet, so the issue still remain, make this two to boot
8 years ago
To solve this on 3.70, go to \Views\Product\_ProductAttributes.cshtml and change this:

<select name="@(controlId)" id="@(controlId)">
                            @if (!attribute.IsRequired)
                            {
                                <option value="0">---</option>
                            }
                            @foreach (var attributeValue in attribute.Values)
                            {
                                var attributeName = String.IsNullOrEmpty(attributeValue.PriceAdjustment) ?
                                    attributeValue.Name :
                                    T("Products.ProductAttributes.PriceAdjustment", attributeValue.Name, attributeValue.PriceAdjustment).Text;
                                <option selected="@attributeValue.IsPreSelected" value="@attributeValue.Id">@attributeName</option>
                            }
                        </select>


To this:

<select name="@(controlId)" id="@(controlId)">
                            @if (!attribute.IsRequired)
                            {
                                <option value="0">---</option>
                            }else{
                                <option value="0">Please select</option>
                            }
                            
                            @foreach (var attributeValue in attribute.Values)
                            {
                                var attributeName = String.IsNullOrEmpty(attributeValue.PriceAdjustment) ?
                                    attributeValue.Name :
                                    T("Products.ProductAttributes.PriceAdjustment", attributeValue.Name, attributeValue.PriceAdjustment).Text;
                                <option selected="@attributeValue.IsPreSelected" value="@attributeValue.Id">@attributeName</option>
                            }
                        </select>
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.