Jump to content

Force clients to choose attribute size in 1.6.1.9


Thels

Recommended Posts

Unfortunately, Prestashop requires you to choose default attributes, which can easily result in clients purchasing an item with the default attributes, where having a default value for an attribute does not make sense.

 

I've been searching for a while on how to bypass this problem, and finally figured out a tweak that we were content with.

 

Our webshop runs on Prestashop 1.6.1.9, and only uses one attribute: "Size". If you use a different version, or use additional attributes, this tweak may or may not work for you.

 

There are two ways for clients to bypass choosing of attributes. The first one is by adding products directly from the frontpage to their cart. This can easily be disabled:

 

In the back office, go to Preferences, Products.

Change "Display the add to cart button when a product has attributes" to No, then Save.

 

The second way is a lot more tricky to prevent. When visiting a product's page, the default size is pre-selected, and the client may easily overlook this. To fix this, we're going to add a "Choose your size" entry at the top of the dropdown list, and make that the default selected entry. While this entry is selected, the "Add to cart" button will be hidden.

 

For this, we need to edit the product.tpl file, which can be found in themes/default-bootstrap. At lines 348 to 350, you'll find the following code:

{foreach from=$group.attributes key=id_attribute item=group_attribute}
	<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'html':'UTF-8'}">{$group_attribute|escape:'html':'UTF-8'}</option>
{/foreach}

Replace those 3 lines of code with the following 4 lines of code:

<option disabled="disabled" selected="selected" title={l s='This combination does not exist for this product. Please select another combination.'}>{l s='This combination does not exist for this product. Please select another combination.'}</option>
{foreach from=$group.attributes key=id_attribute item=group_attribute}
	<option value="{$id_attribute|intval}" title="{$group_attribute|escape:'html':'UTF-8'}">{$group_attribute|escape:'html':'UTF-8'}</option>
{/foreach}

The code populates the entries in the dropdown box. Normally, it checks all available options for the attribute, and adds them 1 at a time. It also checks if the option being added is the default option for that product, and if so, makes it the default entry in the dropdown box.

 

The new code still populates the entries in the dropdown box, but there are 2 changes:

 

1) It adds one additional entry at the top. This entry uses the text "This combination does not exist for this product. Please select another combination." I have chosen to use this text, because it's the same text that appears on the middle of the screen. We will edit this text later. (Note that because we only use one attribute, this text never applies in our store. If you do use different attributes, this solution may not work for you.)

 

The additional entry is also made the default dropdown entry, and it is disabled. Being disabled doesn't prevent it from being selected initially, but it does prevent the client from changing back to this entry after choosing a proper size. (Going back to this entry weirds the system out, and forces the page to refresh.)

 

2) It no longer sets the default product option as the default dropdown entry.

 

After saving the file and uploading it, remember to update your Cache! You can do this in Advanced Parameters, Performance.

 

The last thing you need to do is change the text description:

 

Go to Localization, Translations.

Choose Front Office Translations, set the language to English, and click Modify.

Scroll down to Products, and expand the category.

Change the entry "This combination does not exist for this product. Please select another combination." to "Choose your size".

Press Save.

 

Remember to also do this for all other languages that your webshop supports!

 

Note: This solution worked for me, but I'm merely posting it here as a helpful gesture. Use this at your own risk! I cannot be held responsible if it breaks your shop or eats your cat.

 

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...