From 50d387ba576e66876f9a70a332ea5915eee4c23c Mon Sep 17 00:00:00 2001 From: Victor Kloeppel Date: Thu, 25 Jun 2026 13:59:26 +0200 Subject: [PATCH] fixed bug in messages --- .../templates/hyva/script-additions.phtml | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/view/frontend/templates/hyva/script-additions.phtml b/view/frontend/templates/hyva/script-additions.phtml index 6b864d6c..aafeb7db 100644 --- a/view/frontend/templates/hyva/script-additions.phtml +++ b/view/frontend/templates/hyva/script-additions.phtml @@ -37,6 +37,28 @@ $commons = $block->getCommonsViewModel(); return ['cart', 'customer']; } + var removeGtmEventFromStorage = function(sectionName, eventId) { + var raw = window.localStorage.getItem('mage-cache-storage'); + if (!raw) { + return; + } + + var storage; + try { + storage = JSON.parse(raw); + } catch (e) { + return; + } + + if (storage && + storage[sectionName] && + storage[sectionName].gtm_events && + eventId in storage[sectionName].gtm_events) { + delete storage[sectionName].gtm_events[eventId]; + window.localStorage.setItem('mage-cache-storage', JSON.stringify(storage)); + } + } + getSectionNames().forEach(function(sectionName) { if (!event.detail.data[sectionName] || !event.detail.data[sectionName].gtm) { return; @@ -66,21 +88,7 @@ $commons = $block->getCommonsViewModel(); if (!metaData || metaData.cacheable !== true) { googleTagManager2Logger('removing event "' + eventId + '" from section "' + sectionName + '"') - let mageCacheStorage = event.detail.data; - if (mageCacheStorage) { - mageCacheStorage = JSON.parse(JSON.stringify(mageCacheStorage)); - } - - if (mageCacheStorage !== null && - typeof mageCacheStorage[sectionName] !== 'undefined' && - typeof mageCacheStorage[sectionName].gtm_events !== 'undefined' && - eventId in mageCacheStorage[sectionName].gtm_events) { - delete mageCacheStorage[sectionName].gtm_events[eventId]; - } - - setTimeout(() => { - window.localStorage.setItem('mage-cache-storage', JSON.stringify(mageCacheStorage)); - }, 100); + removeGtmEventFromStorage(sectionName, eventId); } } });