1
votes

I need check if exists combinations with values selected in web service prestashop (jQuery, Javascript, Ajax, etc not PHP), example:

I have two select (html) with two products options

#

Size: 36, 38, 42, etc.

Color: Blue, Black, White, Green, etc.

#

This shoes is available in Blue-42, Black-42, White-38 and not all options is available.

The web service of prestashop get all product_option_values only id, i can not check if the option selected is the size or color with data return of web service.

For example, not permited add to cart with options of combinations not available.

Thanks!

1
Prestashop won't do that out-of-the-box, you'll have to query (Ajax) a controller for that, on option selection for example. - Julien Lachal
Yes, but is a example, if i have more <select> how check if the has change of the select is size, color or other attribute? - Daniel Riera
Try looking into /themes/your_theme/js/product.js you'll find all the elements (especially triggered events) you need ;) - Julien Lachal
@JulienLachal thanks for you response, i have the solutions :) - Daniel Riera
You should post it as an answer, this way, if people stumbled upon the same interrogation they'd be able to find an answer too ;) - Julien Lachal

1 Answers

2
votes

The solution

@JulienLachal thank you for guiding me in the solution

Create two arrays:

1º: IDs product_option_values. 2º: IDs product_option_values selected.

Later compare arrays with next function:

var foo = [];
var i = 0;
$.grep(arrayOptionsSelected, function(el) {
if ($.inArray(el, arrayCombinations) == -1) foo.push(el);
i++;
});

var objFinal= $.isEmptyObject(foo);
if(objFinal) {
...equal
}

Enjoy! :)