feat: migración PZ La Casita, fix motor N/A/RUEDA, cache-buster catálogo y variant_ids

This commit is contained in:
2026-06-22 22:33:59 +00:00
parent f5711ae22f
commit 14219e7117
9 changed files with 293 additions and 24 deletions

View File

@@ -14,6 +14,7 @@
brandId: null,
model: null,
modelId: null,
modelVariantIds: null, // array of TecDoc model ids for grouped variants
year: null,
yearId: null,
engine: null,
@@ -63,7 +64,7 @@
reset: function() {
this.state = 'brands';
this.nav = { brand: null, brandId: null, model: null, modelId: null, year: null, yearId: null, engine: null, myeId: null, category: null, categoryId: null };
this.nav = { brand: null, brandId: null, model: null, modelId: null, modelVariantIds: null, year: null, yearId: null, engine: null, myeId: null, category: null, categoryId: null };
this._allBrands = [];
this._lastItems = [];
this._offset = 0;
@@ -96,7 +97,7 @@
parts.push('<a href="javascript:void(0)" class="breadcrumb__link" onclick=\'BrandCatalog.selectBrand(' + JSON.stringify(this.nav.brand) + ',' + this.nav.brandId + ')\'>' + escapeHtml(this.nav.brand) + '</a>');
}
if (this.nav.model) {
parts.push('<a href="javascript:void(0)" class="breadcrumb__link" onclick=\'BrandCatalog.selectModel(' + this.nav.modelId + ',' + JSON.stringify(this.nav.model) + ')\'>' + escapeHtml(this.nav.model) + '</a>');
parts.push('<a href="javascript:void(0)" class="breadcrumb__link" onclick=\'BrandCatalog.selectModel(' + this.nav.modelId + ',' + JSON.stringify(this.nav.model) + ',' + JSON.stringify(this.nav.modelVariantIds || [this.nav.modelId]) + ')\'>' + escapeHtml(this.nav.model) + '</a>');
}
if (this.nav.year) {
parts.push('<a href="javascript:void(0)" class="breadcrumb__link" onclick=\'BrandCatalog.selectYear(' + this.nav.yearId + ',' + this.nav.year + ')\'>' + this.nav.year + '</a>');
@@ -202,7 +203,8 @@
renderModelList: function(models) {
var html = '<div class="nav-grid">';
models.forEach(function(m) {
html += '<div class="nav-card" onclick=\'BrandCatalog.selectModel(' + m.id_model + ',' + JSON.stringify(m.display_name || m.name_model) + ')\'>' +
var variantIds = (m.variant_ids && m.variant_ids.length) ? m.variant_ids : [m.id_model];
html += '<div class="nav-card" onclick=\'BrandCatalog.selectModel(' + m.id_model + ',' + JSON.stringify(m.display_name || m.name_model) + ',' + JSON.stringify(variantIds) + ')\'>' +
'<div class="nav-card__name">' + escapeHtml(m.display_name || m.name_model) + '</div>' +
'</div>';
});
@@ -210,20 +212,22 @@
this.setContent(html);
},
selectModel: function(modelId, modelName) {
selectModel: function(modelId, modelName, variantIds) {
this.nav.model = modelName;
this.nav.modelId = modelId;
this.loadYears(modelId);
this.nav.modelVariantIds = variantIds && variantIds.length ? variantIds : [modelId];
this.loadYears(this.nav.modelVariantIds);
},
// ---------- YEARS ----------
loadYears: function(modelId) {
loadYears: function(modelIds) {
this.loading(true);
this.state = 'years';
this.setSearch('');
this.buildBreadcrumb();
var self = this;
fetch('/pos/api/catalog/years?model_id=' + encodeURIComponent(modelId), { headers: this._headers() })
var modelIdParam = Array.isArray(modelIds) ? modelIds.join(',') : String(modelIds);
fetch('/pos/api/catalog/years?model_id=' + encodeURIComponent(modelIdParam), { headers: this._headers() })
.then(function(r) {
if (!self._checkAuth(r)) return null;
return r.json();
@@ -258,17 +262,18 @@
selectYear: function(yearId, yearCar) {
this.nav.year = yearCar;
this.nav.yearId = yearId;
this.loadEngines(this.nav.modelId, yearId);
this.loadEngines(this.nav.modelVariantIds || [this.nav.modelId], yearId);
},
// ---------- ENGINES ----------
loadEngines: function(modelId, yearId) {
loadEngines: function(modelIds, yearId) {
this.loading(true);
this.state = 'engines';
this.setSearch('');
this.buildBreadcrumb();
var self = this;
fetch('/pos/api/catalog/engines?model_id=' + encodeURIComponent(modelId) + '&year_id=' + encodeURIComponent(yearId), { headers: this._headers() })
var modelIdParam = Array.isArray(modelIds) ? modelIds.join(',') : String(modelIds);
fetch('/pos/api/catalog/engines?model_id=' + encodeURIComponent(modelIdParam) + '&year_id=' + encodeURIComponent(yearId), { headers: this._headers() })
.then(function(r) {
if (!self._checkAuth(r)) return null;
return r.json();
@@ -292,8 +297,9 @@
renderEngineList: function(engines) {
var html = '<div class="nav-grid">';
engines.forEach(function(e) {
html += '<div class="nav-card" onclick=\'BrandCatalog.selectEngine(' + e.id_mye + ',' + JSON.stringify(e.name_engine) + ')\'>' +
'<div class="nav-card__name">' + escapeHtml(e.name_engine) + '</div>' +
var name = (e.name_engine && e.name_engine !== 'N/A') ? e.name_engine : 'Sin especificar';
html += '<div class="nav-card" onclick=\'BrandCatalog.selectEngine(' + e.id_mye + ',' + JSON.stringify(name) + ')\'>' +
'<div class="nav-card__name">' + escapeHtml(name) + '</div>' +
'<div class="nav-card__sub">' + escapeHtml(e.trim_level || '') + '</div>' +
'</div>';
});