Skip to content

Commit 5712f0f

Browse files
author
DenysTsymbal
committed
9528-default-store-id-for-website-id
1 parent c804c4e commit 5712f0f

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

Controller/Adminhtml/Container/Generate.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Psr\Log\LoggerInterface;
2222
use Magefan\GoogleTagManager\Model\Config;
2323
use Magefan\GoogleTagManager\Model\Container;
24+
use Magento\Store\Model\StoreManagerInterface;
2425

2526
class Generate extends Action implements HttpGetActionInterface
2627
{
@@ -66,6 +67,11 @@ class Generate extends Action implements HttpGetActionInterface
6667
*/
6768
private $container;
6869

70+
/**
71+
* @var StoreManagerInterface
72+
*/
73+
private $storeManager;
74+
6975
/**
7076
* Generate constructor.
7177
*
@@ -77,6 +83,7 @@ class Generate extends Action implements HttpGetActionInterface
7783
* @param RedirectInterface $redirect
7884
* @param Config $config
7985
* @param Container $container
86+
* @param StoreManagerInterface $storeManager
8087
*/
8188
public function __construct(
8289
Context $context,
@@ -86,7 +93,8 @@ public function __construct(
8693
LoggerInterface $logger,
8794
RedirectInterface $redirect,
8895
Config $config,
89-
Container $container
96+
Container $container,
97+
StoreManagerInterface $storeManager
9098
) {
9199
$this->resultRawFactory = $resultRawFactory;
92100
$this->fileFactory = $fileFactory;
@@ -95,6 +103,7 @@ public function __construct(
95103
$this->redirect = $redirect;
96104
$this->config = $config;
97105
$this->container = $container;
106+
$this->storeManager = $storeManager;
98107
parent::__construct($context);
99108
}
100109

@@ -121,8 +130,8 @@ public function execute()
121130

122131
try {
123132
$storeId = (string)$this->getRequest()->getParam('store_id') ?: null;
124-
if (!$storeId) {
125-
$storeId = (string)$this->getRequest()->getParam('mf_generate_website_id') ?: null;
133+
if (!$storeId && ($websiteId = ((string)$this->getRequest()->getParam('website_id') ?: null))) {
134+
$storeId = $this->storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
126135
}
127136

128137
$container = $this->container->generate($storeId);

Model/Config.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Store\Model\ScopeInterface;
1313
use Magento\Config\Model\Config\Backend\Admin\Custom;
14-
use Magento\Framework\App\RequestInterface;
1514

1615
class Config
1716
{
@@ -59,23 +58,15 @@ class Config
5958
*/
6059
private $scopeConfig;
6160

62-
/**
63-
* @var RequestInterface
64-
*/
65-
private $request;
66-
6761
/**
6862
* Config constructor.
6963
*
7064
* @param ScopeConfigInterface $scopeConfig
71-
* @param RequestInterface $request
7265
*/
7366
public function __construct(
74-
ScopeConfigInterface $scopeConfig,
75-
RequestInterface $request
67+
ScopeConfigInterface $scopeConfig
7668
) {
7769
$this->scopeConfig = $scopeConfig;
78-
$this->request = $request;
7970
}
8071

8172
/**
@@ -259,8 +250,7 @@ public function getInstallGtm(string $storeId = null): string
259250
*/
260251
public function getConfig(string $path, string $storeId = null)
261252
{
262-
$scope = $this->request->getParam('mf_generate_website_id') ? ScopeInterface::SCOPE_WEBSITE : ScopeInterface::SCOPE_STORE;
263-
return $this->scopeConfig->getValue($path, $scope, $storeId);
253+
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
264254
}
265255

266256
/**

view/adminhtml/templates/system/config/button/button.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (!isset($escaper)) {
3333
'mfgoogletagmanager/container/generate',
3434
[
3535
'store_id' => (int)$block->getRequest()->getParam('store') ?: null,
36-
'mf_generate_website_id' => (int)$block->getRequest()->getParam('website') ?: null
36+
'website_id' => (int)$block->getRequest()->getParam('website') ?: null
3737
]
3838
)
3939
)?>';

0 commit comments

Comments
 (0)