Jump to content

Alert when no attribute is selected


mostlyharmless
 Share

Recommended Posts

Hello.

Let me start off with all the basics.

Im running 16.0.14 with the default bootstrap.

Ive stumbled upon a problem that i could use someone with a bit more coding skills than i have to figure out.

In the ajax-cart.js around line 139 ive added the following code:

 

//for product page 'add' button...
		$(document).on('click', '#add_to_cart button', function(e){
			e.preventDefault();
                        if (!combinationSelected && productHasAttributes)
                            alert('Alert Text');
                        else
    			    ajaxCart.add($('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
		});

This works great when i have 1 attribute but as soon as i have 2 it doesnt work for the second set of attributes.

Now my question here is:

Is it possible to modify this code to give the alert on an the stock lvl?

Ex.

If the stock of the item is set to 9999 (an amount alot thats so out there its unrealistic) at that point it will show the alert will show up.

The will be that in that way you can exclude the "non" valid choices by setting the stock at that number.

Hope someone can help me out here. 

If i havnt made myself clear enough please say so and i will try to explain it better.

Share this post


Link to post
Share on other sites

Hello !

This works great when i have 1 attribute but as soon as i have 2 it doesnt work for the second set of attributes.

Not sure what you mean. You have an "alert text" that pops if you try to add a product to cart without selecting an attribute, but you don't have that alert if this product is meant to have more than one attribute ? Do you have that alert if you select only one out of two attributes, or when you select none ?

 

And you also want that alert to be the number of items in the stock ?

 

I'm tempted to touch the .tpl to use the smarty globals but I'm not sure that's the best solution, so atm just asking for precisions ^^

Edited by Xuân (see edit history)

Share this post


Link to post
Share on other sites

Oki ill try to explain a bit better.

I have a mug

It comes in 2 colors

and in 3 sizes

That means that i make the 2 attribute sets, 1 for color and 1 for size.

Now with the code i have on there now i add "choose color" and make sure thats the first value, which gives me 3 values under the color set.

If i then use the code snippet above and its on the "choose color"  it wont add anything to the cart because no attribute was selected.



Now here comes the problem.

If i add the size set with 4 values (one for chose size) that one wont be affected like the first one, and if i just fill out 1 of them i can add them to cart which leaves me with a product that has 2 attributes but only 1 is filled out.


The reason i asked about the number of items in stock is because that is one of the variables i figured i could use to adjust to a number that could be used to catch the version where 1 of the "selections" is "choose color/size"

If you have a better suggestion id LOVE to hear it.

Hope that makes sense
 

Share this post


Link to post
Share on other sites

I still don't really get it, since you always have attributes selected if your product has attributes, therefore I don't see how you can have "a product that has 2 attributes but only 1 is filled out."

 

For example, if I have a mug with two availables colors and 3 sizes, when I go to the product page, I already have a preselected color and size, that I can change...

You did use the declinations generator to create them ?

Share this post


Link to post
Share on other sites

Well to me íts back to my background as a designer.

Purely for the usability you should have the "choose" selection available.

i know you can just choose to preset some values but in my experience that leads to ALOT of buy's that have to be refunded/returned because the size is wrong or they didnt choose the right metal or color.

Share this post


Link to post
Share on other sites

Sure, I see the point ^^ it's just that you didn't mention it, so to clarify I had to know.

You added those "choose" options by yourself then I presume ? What did you alter to do so ?

 

Edit : I don't have your code, but I think you can go for something like

 

if( attribute.val()=='Choose')

    alert('Alert Text'); 

Edited by Xuân (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More