How to Force Product Variant Attribute Selection

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
I have a prodcut variant attribute that is a single dropdown box with 23 items the use can select. How do I force the user to select one of the items in the dropdown and not have them leave it with the default selection? I would like to have a message displayed when they try to add the item to the cart if they do not have the attribute selected and not allow them to place the item in the cart until they select one.
11 years ago
When you add a product attribute on the product variant details page (admin area), just ensure that "Is required" checkbox is ticked
11 years ago
I have "required"checked. My problem is that the combobox has the first item in the list selected by default and this may not be what the customer wants. I would like to have the combobox empty and then require the customer to make a selection. There is probably something simple I am doing wrong. Thank you for the help!
11 years ago
In this case try the following:
1. Open \Views\Catalog\_ProductAttributes.cshtml (Nop.Web project)
2. Replace
@if (!attribute.IsRequired)
{
   <option value="0">---</option>
}

with
<option value="0">---</option>

P.S. I haven't tested it.
11 years ago
Hi this option seems to work but produces incorrect behaviour when dynamic price update is set.  Prices are showing incorrectly when selecting options and the last option shows as $NaN
9 years ago
I know this is an old post but I just had the same problem with 3.30.

Change the following line

@Html.Raw(Regex.Replace(Model.Price, pattern, replacement))

to

@Html.Raw(Model.Price)

in Views\Catalog\_ProductPrice.cshtml (look for the "render price" comment)
9 years ago
Hi ,

Currently i am customizing NOP Solution, i need to hide Price & ADD TO CART button , for few selective countries.

i can hide country from shipping & billing restrictions but that does not server my purpose.

i dont want user of particuler country , not to see product price as well.

Is there any settings available or some code needs to be change.
9 years ago
After making the change in my above comment I noticed that the product attribute images were displaying incorrectly for products with required attributes. To fix it I changed the following code

if (!attribute.IsRequired)
{
     pictureAdjustmentTableScripts.AppendFormat(CultureInfo.InvariantCulture, "'{0}',", "");
     numberOfJsArrayItems++;
}

to

pictureAdjustmentTableScripts.AppendFormat(CultureInfo.InvariantCulture, "'{0}',", "");
numberOfJsArrayItems++;

in

Views\Catalog\_ProductAttributes.cshtml
9 years ago
rjpatel43 wrote:
Hi ,

Currently i am customizing NOP Solution, i need to hide Price & ADD TO CART button , for few selective countries.

i can hide country from shipping & billing restrictions but that does not server my purpose.

i dont want user of particuler country , not to see product price as well.

Is there any settings available or some code needs to be change.


Your question is a bit off topic from this thread, however, awhile ago this same item came up and I ended up doing my own solution back in 3.2.  Take a quick read of this thread.

Now, since I did that previous implementation, I have started to do a 3.4 upgrade and am improving on this.  A few key changes I am making is that I am not going to use the customer admin field anymore, but going to use a new key in the generic attribute table. This just makes sense as I am interested in the country/state origin of a customer... and the generic attributes table is a great fit for this....plus I want my customer admin field back :-)
The other change...and this one is more significant... I am not going to do a separate store/tenant like I did previously.  Instead, I am extending the core and expanding on the price tier structure to include country.  So each product will have tier prices set for quantity of 1 (effectively overriding the base), and just like we can filter on store and customer role, I am adding a 3rd dropdown to filter on country (that their IP is from).  If the country component of the check is true on a product, the model returns it as a "call for price"...of which the default text can be changed to whatever makes sense.  The first attempt was a bit crude also... I didn't use dependency injection on the home controller for the geoservice lookkup (which i should have).  The rest is the same as before... when a guest/customer hits the site, I will check for my new "countryorigin" key in the generic attribute...if it doesn't exist, do a lookup based on their IP (just like before) and store it. Thus... only 1 check is ever done for a guest/customer...once they get assigned a country origin, the key is in memory when they return for future visits.

Anyway, as far as I know, I am not aware of anyone else doing this specific customization other than myself.  Should you want to discuss further, lets use my original thread (here) rather than this one, as this one is really about something different.
8 years ago
a.m. wrote:
When you add a product attribute on the product variant details page (admin area), just ensure that "Is required" checkbox is ticked


How to make the "Is Required" checked by default when adding a new product attribute in the admin?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.