Skip to content

Commit 0de0ee2

Browse files
committed
Check for duplicate MageOS_AlpineLocalStorage
1 parent 9d07c3c commit 0de0ee2

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

ViewModel/ModuleConfig.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Loki\Base\ViewModel;
5+
6+
use Magento\Framework\Module\Manager;
7+
use Magento\Framework\View\Element\Block\ArgumentInterface;
8+
9+
class ModuleConfig implements ArgumentInterface
10+
{
11+
public function __construct(
12+
private readonly Manager $moduleManager
13+
) {
14+
}
15+
16+
public function isEnabled(string $moduleName): bool
17+
{
18+
return $this->moduleManager->isEnabled($moduleName);
19+
}
20+
}

view/base/layout/loki_localstorage.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<block name="loki.script.store.local-storage" template="Loki_Base::script/store/localstorage-store.phtml">
77
<arguments>
88
<argument name="section_config" xsi:type="object">Loki\Base\ViewModel\SectionConfig</argument>
9+
<argument name="module_config" xsi:type="object">Loki\Base\ViewModel\ModuleConfig</argument>
910
</arguments>
1011
</block>
1112
</referenceBlock>

view/base/templates/script/store/localstorage-store.phtml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ use Magento\Framework\View\Element\Template;
77
/** @version 1.1.8 */
88
/** @var Template $block */
99
/** @var SectionConfig $sectionConfig */
10+
/** @var \Loki\Base\ViewModel\ModuleConfig $moduleConfig */
11+
if ($moduleConfig->isEnabled('MageOS_AlpineLocalStorage')) {
12+
return;
13+
}
1014

1115
$sectionConfig = $block->getSectionConfig();
16+
$moduleConfig = $block->getModuleConfig();
1217
?>
1318
<script>
1419
document.addEventListener('alpine:init', () => {
15-
Alpine.store('LokiLocalStorage', {
20+
Alpine.store('LocalStorage', {
1621
key: 'mage-cache-storage',
1722
sectionLifetime: <?= (int)$sectionConfig->getSectionDataLifeTime() * 60 ?>,
1823
data: {},
@@ -25,7 +30,7 @@ $sectionConfig = $block->getSectionConfig();
2530
}
2631

2732
let changed = false;
28-
const cookieSections = LokiCookies.get('section_data_ids') || {};
33+
const cookieSections = MageCookies.get('section_data_ids') || {};
2934

3035
Object.entries(this.data).forEach(([key, value]) => {
3136
const isSectionExpired = !value.data_id || parseInt(value.data_id) + this.sectionLifetime < this.getCurrentTimestamp();

0 commit comments

Comments
 (0)