<!--УДАЛЯЕМ КАРТОЧКИ С ПРОШЕДШЕЙ ДАТОЙ-->
<script>
document.addEventListener("DOMContentLoaded", function() {
(function () {
const gridCont = document.querySelectorAll(".js-store-grid-cont");
let renderedCount = 0;
const totalGrids = gridCont.length;
gridCont.forEach(function(el) {
el.addEventListener('tStoreRendered', function(e) {
renderedCount++;
if (renderedCount === totalGrids) {
loadtStoreXHR();
renderedCount = 0;
}
});
});
function loadtStoreXHR(){
const storeData = window.tStoreXHR;
if(storeData!=undefined){
hideOldDateCard(storeData);
}else{
console.log('window.tStoreXHR is not fined');
};
};
function hideOldDateCard(storeData){
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
for (const key in storeData) {
const response = JSON.parse(window.tStoreXHR[key].response).products;
response.forEach(item => {
if (item.characteristics && Array.isArray(item.characteristics)) {
const dateCharacteristic = item.characteristics.find(char => char.title === "Дата начала");
if (dateCharacteristic) {
const cardDateStr = dateCharacteristic.value;
const [day, month, yearShort] = cardDateStr.split('.');
const year = yearShort.length === 2 ? `20${yearShort}` : yearShort;
const cardDate = new Date(`${year}-${month}-${day}`);
const cardUid = item.uid;
if ( currentDate >= cardDate) {
const elementsToRemove = document.querySelectorAll(
`.js-product[data-product-gen-uid="${cardUid}"]`
);
elementsToRemove.forEach(element => element.remove());
}
}
}
});
};
};
})();
});
</script>
<style>
.t-clear.t-store__grid-separator {
display: none;
}
.js-product.t-store__card.t-col {
margin-bottom: 40px;
}
</style>