Skip to content

Commit e697289

Browse files
committed
ACP2E-2842: Switching to single store mode - global content no longer appears
1 parent 7e0fc6b commit e697289

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Theme\Observer;
20+
21+
use Magento\Framework\App\Config\ScopeConfigInterface;
22+
use Magento\Framework\Event\Observer;
23+
use Magento\Framework\Event\ObserverInterface;
24+
use Magento\Store\Model\ScopeInterface;
25+
use Magento\Store\Model\StoreManager;
26+
use Magento\Store\Model\StoreManagerInterface;
27+
use Magento\Theme\Api\DesignConfigRepositoryInterface;
28+
29+
class MoveStoreLevelDesignConfigToWebsiteScopeOnSingleStoreMode implements ObserverInterface
30+
{
31+
/**
32+
* @param ScopeConfigInterface $scopeConfig
33+
* @param DesignConfigRepositoryInterface $designConfigRepository
34+
* @param StoreManagerInterface $storeManager
35+
*/
36+
public function __construct(
37+
private readonly ScopeConfigInterface $scopeConfig,
38+
private readonly DesignConfigRepositoryInterface $designConfigRepository,
39+
private readonly StoreManagerInterface $storeManager
40+
) {
41+
}
42+
43+
/**
44+
* @inheritDoc
45+
*/
46+
public function execute(Observer $observer)
47+
{
48+
$changedPaths = (array)$observer->getEvent()->getChangedPaths();
49+
if (in_array(StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED, $changedPaths, true)
50+
&& $this->scopeConfig->getValue(StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED)
51+
) {
52+
$store = $this->storeManager->getDefaultStoreView();
53+
if ($store) {
54+
$websiteId = $store->getWebsiteId();
55+
$storeId = $store->getId();
56+
$designConfig = $this->designConfigRepository->getByScope(ScopeInterface::SCOPE_STORES, $storeId);
57+
// Copy design config from store scope to website scope
58+
$designConfig->setScope(ScopeInterface::SCOPE_WEBSITES);
59+
$designConfig->setScopeId($websiteId);
60+
$this->designConfigRepository->save($designConfig);
61+
// At this point store design config the same as website design config.
62+
// By saving store design config, we will preserve inheritance from website scope.
63+
$designConfig->setScope(ScopeInterface::SCOPE_STORES);
64+
$designConfig->setScopeId($storeId);
65+
$this->designConfigRepository->save($designConfig);
66+
}
67+
}
68+
}
69+
}

app/code/Magento/Theme/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<event name="theme_save_after">
1313
<observer name="check_theme_is_assigned" instance="Magento\Theme\Observer\CheckThemeIsAssignedObserver" />
1414
</event>
15+
<event name="admin_system_config_changed_section_general">
16+
<observer name="move_store_level_design_config_to_website_scope_on_single_store_mode" instance="Magento\Theme\Observer\MoveStoreLevelDesignConfigToWebsiteScopeOnSingleStoreMode" />
17+
</event>
1518
</config>

0 commit comments

Comments
 (0)