Hi.
In your module, you sent a list of products as an array to your javascript.
$categories = [5, 18, 24]; $categoriesFind = implode(',', $categories); $products = []; $findProducts = Db::getInstance()->executeS('SELECT id_product FROM '._DB_PREFIX_.'category_product WHERE id_category IN ('.$categoriesFind.') GROUP BY id_product'); if ($findProducts) { foreach ($findProducts as $id_product) { $products[] = $id_product['id_product']; } } $jsDef = ['myCategories' => $categories, 'myProducts' => $products]; Media::addJsDef($jsDef);
javascript eg:
$(document).ready(function(){ var getCategories = myCategories; // array var getProducts = myProducts; // array var currentProduct = document.getElementById('id_product').value; // change to your element in TPL getProducts.forEach(r => { if (currentProduct.includes(r)) { // Ok, found // call your function okAddMyScript(currentProduct); } }); }); function okAddMyScript(e){ var id_product = e; // your function }
or add module hookHeader, or you custom hook and call it on the applicable product page.