View Matching Item Numbers (` + itemCount + ` items ) →
`;
}
else {
htmlLink = `
View All Columns and Pricing (` + itemCount + ` items) →
`;
}
/*htmlLink += `
View All Columns and Pricing
(` + itemCount + ` items)
→
`;*/
return htmlLink;
}
function applyQuickProductCount(count) {
var n = typeof count === "number" ? count : 0;
$(".od-productoptions-records").text(n);
$(".od-productfilteroptions-count").text(n);
if ("SimpleProduct" === "GroupedProduct")
$("#od_resultlink").html(buildGroupedProductResultLinkHtml(n));
}
function loadSuggestedProducts(isFirstLoad = false) {
var gen = ++_odSpecLoadGen;
if (_odSpecCountXhr && _odSpecCountXhr.readyState !== 4) {
_odSpecCountXhr.abort();
_odSpecCountXhr = null;
}
if (_odSpecProductsXhr && _odSpecProductsXhr.readyState !== 4) {
_odSpecProductsXhr.abort();
_odSpecProductsXhr = null;
}
var selectedOptions = getSelectedSpecsOrDefault();
var postData = { specOptions: selectedOptions.join(","), productId: 9383 };
_odSpecCountXhr = $.ajax({
url: "/ODProduct/GetProductsBySpecificationCount",
type: "POST",
dataType: "json",
data: postData,
success: function (countRes) {
if (gen !== _odSpecLoadGen) return;
if (countRes && countRes.success && typeof countRes.count === "number")
applyQuickProductCount(countRes.count);
},
complete: function (jqXHR, textStatus) {
if (gen !== _odSpecLoadGen) return;
if (textStatus === "abort") return;
_odSpecProductsXhr = $.ajax({
url: "/ODProduct/GetProductsBySpecification",
type: "POST",
dataType: "json",
data: postData,
success: function (response) {
if (gen !== _odSpecLoadGen) return;
displayProducts(response.products, response.columns, isFirstLoad);
$(".od-mobile-speclink").attr('onclick', 'openProductFilterOptions()');
$("#od_pgfilter_startover").show();
$("#od_pgfilter_startover_mobile").show();
},
error: function (xhr, status, error) {
if (gen !== _odSpecLoadGen) return;
console.error("Error fetching products:", xhr.responseText);
}
});
}
});
}
function validateIfExistsOnlyOneProduct() {
if(gup("option") == null)
return false;
var selectedOptions = gup("option").split(','); //NO REMOVE, takes the SpeechRecognitionAlternative varuel from querystring
//console.log(`OD DEBUG. Function validateIfExistsOnlyOneProduct. selectedOptions: ${selectedOptions}`);
//return;
var postData = { specOptions: selectedOptions.join(","), productId: 9383 };
$.ajax({
url: "/ODProduct/GetProductsBySpecification",
type: "POST",
dataType: "json",
data: postData,
success: function(response) {
var products = response.products;
if (products.length == 1 && !odIsMobile())
{
//console.log(`OD DEBUG. Function validateIfExistsOnlyOneProduct. Redirect to simple product. Products: ${products.length}, ProductUrl: ${products[0].Url}`);
//location.href = products[0].Url;
displayProducts(response.products, response.columns, false);
return true;
}
},
error: function(xhr, status, error) {
console.error("Error fetching products:", xhr.responseText);
}
});
return false;
}
function getProductUnit(productId){
var postData = { productId };
$.ajax({
url: "/ODProduct/GetProductUnit",
type: "POST",
dataType: "json",
data: postData,
success: function(response) {
if(response.success)
$("#od-product-unit").html(" / "+response.unit);
},
error: function(xhr, status, error) {
console.error("Error laoding unit:", xhr.responseText);
}
});
}
function reloadFacetFilters(isFirstLoad = false){
var selectedOptions = getSelectedSpecsOrDefault();
var postData = { specOptions: selectedOptions.join(","), productId: 9383 };
$('.loader-overlay').addClass('visible');
$.ajax({
url: "/ODProduct/GetProductsSpecificationFacetFilters",
type: "POST",
dataType: "json",
data: postData,
success: function(response) {
$("#od-product-filteroptions").html(response.html);
//console.log("OD DEBUG. Function reloadFacetFilters. Respose: ", response.facets.length, postData, response);
//when no filter options are returned
if(response.facets.length == 0){
$(".prices").show();
$(".od_pgfilter").hide();
return;
}
else{
$("#od_pgfilter").show();
}
//set actions for mobile (load specs o product options)
if(response.html == undefined){
//console.log("OD Debug. Reload Filters Undefined. Html: ", response.html);
$(".od-mobile-speclink").attr('onclick', 'openProductOptions();$("#od_productoptions_editspec").hide();');
}
else {
//console.log("OD Debug. Load Product Options");
$(".od-mobile-speclink").attr('onclick', 'openProductFilterOptions()');
$("#od_pgfilter_startover").show();
$("#od_pgfilter_startover_mobile").show()
}
bindEvents();
//Clear parameters if no url referrer (only apply to simple product) //DDDDD
/*if(isFirstLoad && document.referrer == "" && "InertSustain PFP" != ""){
console.log("load no referrer");
clearFilterOption();
loadSuggestedProducts(false);
}*/
//Load by default Form: Column, only apply for parent product
if(isFirstLoad && "InertSustain PFP" == ""){ // && gup("option") == null
//load Column by default
if (document.querySelector('li[data-optionid="1463"]')) {
var url = new URL(window.location.href);
var params = new URLSearchParams(url.search);
// Get the current option values as an array
var currentOptions = params.get("option") ? params.get("option").split(",") : [];
if(currentOptions.length == 0){
addQueryParam("option", 1463);
reloadFacetFilters(false);
loadSuggestedProducts(false);
}
}
}
},
error: function(xhr, status, error) {
console.error("Error laoding filters:", xhr.responseText);
},
})
.always(function () { //ODX
$('.loader-overlay').removeClass('visible');
});
}
// Function to display products
function displayProducts(products, columns, isFirstLoad = false) {
//console.log(`OD DEBUG. Function displayProducts. isFirstLoad: ${isFirstLoad}, products: ${products.length}`);
//For Grouped Product show only one product to select - 16.Jan.2026
var productType = "SimpleProduct";
var controlVersion = "v2"; //"v2"; ****Todos usaran esta version
var productId = "9551";
if (controlVersion == "v2" && products.length == 1 && !odIsMobile() && gup("option") != null)
{
var product = products[0];
htmlLink = `
1 Matching Item (Item # ${product.Sku})
${product.Name}
`;
$("#od_resultlink").html(htmlLink);
return;
}
if (productType == "GroupedProduct" && products.length == 1 && !odIsMobile())
{
var product = products[0];
location.href = products[0].Url;
return;
}
if(products.length == 0){
$("#od-productoptions-list").hide();
return;
}
//console.log("OD DEBUG. Display Products Set Total Records", products, columns);
$(".od-productoptions-records").html(products.length);
$(".od-productfilteroptions-count").html(products.length); //mobile
//set columns names
var disableSpecColumns = columns.length == 0;
if(disableSpecColumns)
{
$("#od_productfilter_option__spec1").html("Name");
// $("#od_productfilter_option__spec2").remove();
// $("#od_productfilter_option__spec3").remove();
}
else
{
$("#od_productfilter_option__spec1").html(columns[0]);
$("#od_productfilter_option__spec2").html(columns[1]);
$("#od_productfilter_option__spec3").html(columns[2]);
}
//one product match (no redirect to simple product auto for mobile)
var width = $(window).width();
if(products.length == 1 && odIsMobile())
{
if("v2" == "v2")
{
$("#od_filter_option_mobile").html(`
Change Specifications `);
}
}
if(products.length == 1 && !odIsMobile())
{
var product = products[0];
//show only one product
if(gup("uncheck") == "1"){
//condition when unchek and option in simple product
removeQueryParam("uncheck");
}
else
{
if(isFirstLoad && "False" == "True" )
{
//show child products for first load
htmlLink = `
${product.Sku} - ${product.Name} ${product.Price}
`;
}
else
{
if("v2" != "v2")
{
htmlLink = `
${product.Sku} - ${product.Name} $440.00
`;
}
}
$("#od_resultlink").html(htmlLink);
getProductUnit(product.Id);
return;
}
}
//simple product condition
if (productType == "SimpleProduct")
{
if (controlVersion == "v2")
{
//OD CHECK LOGIC
var product = products.find(item => item.Id === 9551);
var htmlLink = "";
//console.log("OD DEBUG. Product Find: ",product);
//if(product != undefined) //DDDDDD
htmlLink = `
View Matching Item Numbers (` + products.length + ` items ) →
`;
//NO show view options for mobile view
var htmlLinkXXX = `
Select Your Specifications
View Product List (` + products.length + ` items)
`;
//When page load without options then show Change Specifications for mobile
if(gup("option") == null || products.length == 1 || document.referrer == "")
$("#od_filter_option_mobile").html(`
Change Specifications `);
else
$("#od_filter_option_mobile").html(`
Back to Results (` + products.length + `) `);
$("#od_resultlink").html(htmlLink);
if(product != undefined)
getProductUnit(product.Id);
}
else
{
//OD CHECK LOGIC
var product = products.find(item => item.Id === 9551);
var htmlLink = "";
if(product != undefined)
htmlLink = `
Product Options (` + products.length + `)
${product.Sku} - ${product.Name} ${product.Price}
`;
htmlLink += `
Select Your Specifications
View Product List (` + products.length + ` items)
`;
$("#od_resultlink").html(htmlLink);
if(product != undefined)
getProductUnit(product.Id);
}
}
//load data includes modal
//console.log("OD Debug. products to render", products);
if(tableProductOptions === undefined)
{
var tableColumns;
if(disableSpecColumns) //show product name instead
{
tableColumns = [
{
data: "Sku",
render: function(data, type, row) {
// append current "option" query parameter from the page to the product URL
return `
${data} `; // Hyperlink on name
}
},
{
data: "Name",
},
{
data: "Spec2",
render: function(data, type, row, meta) {
const colIndex = meta.col;
const table = $('#od_productfilter_option').DataTable(); // replace #example with your table ID
const colTitle = table.column(colIndex).header().textContent;
return `
${colTitle}: ${row.Spec2}`;
}
},
{
data: "Spec3",
render: function(data, type, row, meta) {
const colIndex = meta.col;
const table = $('#od_productfilter_option').DataTable(); // replace #example with your table ID
const colTitle = table.column(colIndex).header().textContent;
return `
${colTitle}: ${row.Spec3}`;
}
},
{
data: "Price",
render: function(data, type, row) {
if(row.SpecUnit == null || row.SpecUnit == "")
return `
${row.Price} `;
else
return `
${row.Price} / ${row.SpecUnit} `;
}
},
{
data: "Id",
orderable: false,
render: function(data, type, row) {
var url = appendOptionParam(row.Url);
return `
Select `;
}
}]
}
else
{
tableColumns = [
{
data: "Sku",
render: function(data, type, row) {
return `
${data} `; // Hyperlink on name (preserve current option param)
}
},
{
data: "Spec1",
render: function(data, type, row, meta) {
const colIndex = meta.col;
const table = $('#od_productfilter_option').DataTable(); // replace #example with your table ID
const colTitle = table.column(colIndex).header().textContent;
var spec1 = row.Spec1 != null ? row.Spec1 : ""
return `
${colTitle}: ${spec1}`;
}
},
{
data: "Spec2",
render: function(data, type, row, meta) {
const colIndex = meta.col;
const table = $('#od_productfilter_option').DataTable(); // replace #example with your table ID
const colTitle = table.column(colIndex).header().textContent;
var spec2 = row.Spec2 != null ? row.Spec2 : ""
return `
${colTitle}: ${spec2}`;
}
},
{
data: "Spec3",
render: function(data, type, row, meta) {
const colIndex = meta.col;
const table = $('#od_productfilter_option').DataTable(); // replace #example with your table ID
const colTitle = table.column(colIndex).header().textContent;
var spec3 = row.Spec3 != null ? row.Spec3 : ""
return `
${colTitle}: ${spec3}`;
}
},
{
data: "Price",
render: function(data, type, row) {
if(row.SpecUnit == null || row.SpecUnit == "")
return `
${row.Price} `;
else
return `
${row.Price} / ${row.SpecUnit} `;
}
},
{
data: "Id",
orderable: false,
render: function(data, type, row) {
//var options = getQueryOptions();
var url = appendOptionParam(row.Url);
return `
Select `;
}
}]
}
tableProductOptions = $('#od_productfilter_option').DataTable({
data: products,
columns: tableColumns,
columnDefs: [
{ targets: 1, type: 'custom-num' },
{ targets: 2, type: 'custom-num' },
{ targets: 3, type: 'custom-num' },
{ targets: 4, type: 'custom-num' }
],
scrollY: 600,
scrollY: '65vh',
deferRender: true,
scroller: true,
"bLengthChange": false, // Hide page size dropdown
"bFilter": false // Hide search box
});
//hide columns specification
if(columns[1] == undefined)
tableProductOptions.column(2).visible(false);
if(columns[2] == undefined)
tableProductOptions.column(3).visible(false);
}
else
{
//console.log("OD DEBUG. Reload Product Options Table", products);
// Clear and reload table with new data
tableProductOptions.clear();
tableProductOptions.rows.add(products);
tableProductOptions.draw();
}
tableProductOptions.on('page', function () {
$('#od-productoptions-list').closest(".od-ct-modal-body").animate({
scrollTop: 0
}, 400);
});
$("#od-productoptions-list").show();
//fix when header render not properly
setTimeout(function() {
tableProductOptions.columns.adjust().draw(false);
}, 1000);
if (productType == "GroupedProduct") //&& productId != 15978
{
/*if (controlVersion == "v2")
{*/
$("#od_resultlink").html(buildGroupedProductResultLinkHtml(products.length));
isReload = true;
/*}
else
{
htmlLink = `
View Product List (` + products.length + ` items)
– See Pricing
`;
//open product list if doesn't exists specifications'
htmlLink += `
Select Your Specifications
View Product List (` + products.length + ` items)
`;
$("#od_resultlink").html(htmlLink);
isReload = true;
}*/
}
/*else if (productType == "GroupedProduct")
{
htmlLink = `
Select Your Column
` + products.length + ` Columns Available
→
`;
$("#od_resultlink").html(htmlLink);
isReload = true;
}*/
}
// Append current page "option" query parameter to a target URL, using correct separator
function appendOptionParam(url) {
try {
var opt = (new URLSearchParams(window.location.search)).get('option');
if (!opt) return url;
var sep = url.indexOf('?') !== -1 ? '&' : '?';
return url + sep + 'option=' + encodeURIComponent(opt) + "&conf=fs";
} catch (e) {
return url;
}
}
//});
function closeCrossModal(){
$("#od-productoptions").hide();
}
function getQueryOptions(){
var url = new URL(window.location.href);
var params = new URLSearchParams(url.search);
// Get the current option values as an array
if(params.get("option") != undefined)
return "?option=" + params.get("option");
return "";
}
//---------------------------------------------------------------------------------------------------------------------
function sendTrackingEvents() {
return;
gtag('event', 'page_view', { page_path: window.location.pathname });
}
function loadPageContent(productId) {
var postData = { productId };
$("#product-details-form").html("");
goTop();
$.ajax({
url: "/ODProduct/RenderProductDetailInfo",
type: "POST",
dataType: "json",
data: postData,
success: function(response) {
$("#product-details-form").html(response.html);
//$("#od-product-info").html(response.html);
// Ensure scripts are re-initialized
if (typeof AjaxCartFailure === "undefined") {
$.getScript('/js/public.ajaxcart.js');
}
setTimeout(function() {
bindProductTabEvents();
}, 2000);
},
error: function(xhr, status, error) {
console.error("Error laoding filters:", xhr.responseText);
}
});
}
function openProductDetail(url) {
var optionValue = getQueryParam("option");
if(optionValue !== null)
url = addQueryParamGetUrl(url, "option", optionValue);
location.href = url;
}
//Resturn an array with spec options selected from URL, additional if option == null inlcude product specs
function getSelectedSpecsOrDefault() {
var option = gup("option");
var productType = "SimpleProduct";
var controlVersion = "v2";
//especial condition for simple product when navigate directly to product
if(productType == "SimpleProduct" && option == null && !odIsMobile()){ //gup("conf") == null
//return specs assigned for product simple
return selectedSpecifications;
}
if(option != null)
return option.split(',').map(Number); //NO REMOVE, takes the SpeechRecognitionAlternative varuel from querystring
return [];
}
var tableProductOptions;