Jump to content

Can I force customer to select attribute?


manusegarra

Recommended Posts

Hi to everybody:

 

I'm carrying on with an unresolved and important issue. I copied the question directly from the post linked below:

 

A product has different sizes and colors to choose from.

 

If the customer doesn't select a size and just presses add to cart the default size and color is automatically selected.

 

Is there a way to force the customer to select the size and color before adding to the cart?

 

is there anyway to no setup a default size, which will do the trick?.

 

I know you can disable add to cart when viewing products in lists but you can still add when viewing individual products.

 

Help appreciated, thanks in advance.

 

https://www.prestashop.com/forums/topic/341059-can-i-force-customer-to-select-attribute/?hl=%2Bforce+%2Battributes&do=findComment&comment=1863347

Link to comment
Share on other sites

Hi manu,

 

You can try to add this little piece of javascript code to the very end of your themes/<your theme folder>/product.tpl file (Make backup first!!)

 

<script>
  {literal}
    function forceSelectFirst() {
      $('[name=Submit]').removeAttr('disabled');
    }
 
    $(document).ready(function() {
      $('[name=Submit]').attr('disabled','disabled');
      $('.attribute_select').focus(forceSelectFirst);
      $('[class^=color_pick]').focus(forceSelectFirst);
      $('.attribute_radio').focus(forceSelectFirst);
    });
 
  {/literal}
</script>
 
 
 
What it does: (it works with PrestaShop 1.6.0.14, other versions (PS 1.5, 1.4 etc) maybe need other class names to get to the elements)
 
 
It defines a small function forceSelectFirst, which only removes a tag attribute 'disabled' from a (button) element with the name 'Submit' (Which is our 'Add to Cart' - Button)
 
Furthermore, when the document is fully loaded, it :
- first disables the Add to Cart Button. This way we cannot add any product to the cart (yet)
- Adds an onFocus event listener to some elements:
    -  All elements that have a class 'attribute_select'   (This are all drop down menus with attribute values to choose from)
    -  All elements that have a class 'attribute_radio'   (This are all radio button - options with attribute values to choose from)
    -  All elements that have a class that START WITH the name 'color_pick'   (This are all colour icons with attribute values to choose from)
The onFocus event triggers a call to the above defined function.
 
 
Then, the customer cannot add any product UNTIL it at least selects one of the attributes on purpose (i.e. until he/she opens one drop down menu, or selects one of the radio buttons, or select one of the colours) After this, the button enables, and the product can be added.
 
 
Hope this helps. You can make it more beautiful by making the button a different colour or so, to show that it's not selectable. I leave that as an exercise.
 
 
Hope this helps,
pascal.
  • Like 1
Link to comment
Share on other sites

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...