Use the script to add variants of products based on attributes
<script>
const SIZE_FACET_NAME = "Size";
const PRICE_FACET_NAME = "Price";
const SELLABLE_FACET_NAME = "Sellable";
var __isp_options = {
isp_serp_callback: function() {
$('.isp_grid_product').each(function(index) {
var product_id = $jquery_isp(this).attr('product_id');
var variants = ISP_PRODUCTS[product_id].vra;
var $mod_value = "";
for (const variant of variants) {
const variantID = variant[0];
const $price = findVariantOption(variant, PRICE_FACET_NAME);
const $size = findVariantOption(variant, SIZE_FACET_NAME);
const $sellable = findVariantOption(variant, SELLABLE_FACET_NAME);
var $modprice = $price.replace("EUR:","");
if ($sellable == false)
continue;
if ($size != null) {
$mod_value += `<span class="isp_custom_price">€${$modprice}/${$size}</span>`;
} else
$mod_value += `<span class="isp_custom_price">€${$modprice}</span>`;
}
$jquery_isp(this).find(".isp_product_price_wrapper").html("");
if ($jquery_isp(this).find(".isp_custom_price").length === 0) {
$jquery_isp(this).find(".isp_product_price_wrapper").append($mod_value);
}
});
},
function findVariantOption(variant, optionName) {
const data = variant[1].find(option => option[0] === optionName);
return data ? data[1][0] : null;
}
</script>