Skip to content

Commit 4b5ea6a

Browse files
authored
Merge pull request #17 from magefan/9528-прибрати-заборону-на-генерацію-json-на-рівні-сайту
9528-прибрати-заборону-на-генерацію-json-на-рівні-сайту
2 parents bae8216 + b465290 commit 4b5ea6a

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

Controller/Adminhtml/Container/Generate.php

Lines changed: 14 additions & 1 deletion
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,6 +130,10 @@ public function execute()
121130

122131
try {
123132
$storeId = (string)$this->getRequest()->getParam('store_id') ?: null;
133+
if (!$storeId && ($websiteId = ((string)$this->getRequest()->getParam('website_id') ?: null))) {
134+
$storeId = $this->storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
135+
}
136+
124137
$container = $this->container->generate($storeId);
125138

126139
$fileContent = [

Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,4 @@ public function isSpeedOptimizationEnabled(string $storeId = null): bool
263263
{
264264
return (bool)$this->getConfig(self::XML_PATH_SPEED_OPTIMIZATION_ENABLED, $storeId);
265265
}
266-
}
266+
}

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

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,31 @@ if (!isset($escaper)) {
1414
}
1515
?>
1616
<div class="pp-buttons-container">
17-
<?php if ($block->getRequest()->getParam('website')) { ?>
18-
<strong>
19-
<?= $escaper->escapeHtml(__('Container generation is not available for website scope.')) ?>
20-
</strong>
21-
<?php } else { ?>
22-
<button type="button" id="mf_download">
23-
<?= $escaper->escapeHtml(__('Generate JSON Container & Download File')); ?>
24-
</button>
25-
<p>
26-
<br/>
27-
<?= __('Once the JSON file is downloaded, upload it to %1 > Choose Container > Admin > Import Container.', '<a href="https://tagmanager.google.com/" title="Google Tag Manager" target="_blank">Google Tag Manager</a>') ?>
28-
</p>
29-
<script>
30-
require([
31-
'jquery',
32-
'domReady!'
33-
], function ($) {
34-
$('#mf_download').on('click', function(event) {
35-
event.preventDefault;
36-
window.location='<?= $escaper->escapeUrl(
37-
$block->getUrl(
38-
'mfgoogletagmanager/container/generate',
39-
['store_id' => (int)$block->getRequest()->getParam('store') ?: null]
40-
)
41-
)?>';
42-
});
17+
<button type="button" id="mf_download">
18+
<?= $escaper->escapeHtml(__('Generate JSON Container & Download File')); ?>
19+
</button>
20+
<p>
21+
<br/>
22+
<?= __('Once the JSON file is downloaded, upload it to %1 > Choose Container > Admin > Import Container.', '<a href="https://tagmanager.google.com/" title="Google Tag Manager" target="_blank">Google Tag Manager</a>') ?>
23+
</p>
24+
<script>
25+
require([
26+
'jquery',
27+
'domReady!'
28+
], function ($) {
29+
$('#mf_download').on('click', function(event) {
30+
event.preventDefault;
31+
window.location='<?= $escaper->escapeUrl(
32+
$block->getUrl(
33+
'mfgoogletagmanager/container/generate',
34+
[
35+
'store_id' => (int)$block->getRequest()->getParam('store') ?: null,
36+
'website_id' => (int)$block->getRequest()->getParam('website') ?: null
37+
]
38+
)
39+
)?>';
4340
});
44-
</script>
45-
<?php } ?>
41+
});
42+
</script>
4643
</div>
4744

0 commit comments

Comments
 (0)