mostlyharmless Posted May 28, 2015 Share Posted May 28, 2015 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. Link to comment Share on other sites More sharing options...
Xuân Posted May 28, 2015 Share Posted May 28, 2015 (edited) 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 May 28, 2015 by Xuân (see edit history) Link to comment Share on other sites More sharing options...
mostlyharmless Posted May 28, 2015 Author Share Posted May 28, 2015 Oki ill try to explain a bit better.I have a mugIt comes in 2 colorsand in 3 sizesThat 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 Link to comment Share on other sites More sharing options...
Xuân Posted May 28, 2015 Share Posted May 28, 2015 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 ? Link to comment Share on other sites More sharing options...
mostlyharmless Posted May 29, 2015 Author Share Posted May 29, 2015 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. Link to comment Share on other sites More sharing options...
Xuân Posted May 29, 2015 Share Posted May 29, 2015 (edited) 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 May 29, 2015 by Xuân (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now