Skip to content

Commit 0b55353

Browse files
authored
Merge pull request #29 from ivanhrytsaim/10568-check-Hyva-Theme
10568-check-Hyva-Theme
2 parents 56a0b72 + dbd6373 commit 0b55353

File tree

4 files changed

+160
-3
lines changed

4 files changed

+160
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\Community\Api;
10+
11+
interface HyvaThemeDetectionInterface
12+
{
13+
14+
/**
15+
* @param $storeId
16+
* @return bool
17+
*/
18+
public function execute($storeId = null): bool;
19+
20+
}

Model/HyvaThemeDetection.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\Community\Model;
10+
11+
use Magefan\Community\Api\HyvaThemeDetectionInterface;
12+
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Framework\Module\Manager as ModuleManager;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
18+
class HyvaThemeDetection implements HyvaThemeDetectionInterface
19+
{
20+
21+
/**
22+
* @var ModuleManager
23+
*/
24+
protected $moduleManager;
25+
26+
/**
27+
* @var StoreManagerInterface
28+
*/
29+
protected $storeManager;
30+
31+
/**
32+
* @var ScopeConfigInterface
33+
*/
34+
protected $scopeConfig;
35+
36+
/**
37+
* @var ThemeProviderInterface
38+
*/
39+
protected $themeProvider;
40+
41+
/**
42+
* @param ModuleManager $moduleManager
43+
* @param StoreManagerInterface $storeManager
44+
* @param ScopeConfigInterface $scopeConfig
45+
* @param ThemeProviderInterface $themeProvider
46+
*/
47+
public function __construct(
48+
ModuleManager $moduleManager,
49+
StoreManagerInterface $storeManager,
50+
ScopeConfigInterface $scopeConfig,
51+
ThemeProviderInterface $themeProvider
52+
53+
) {
54+
$this->moduleManager = $moduleManager;
55+
$this->storeManager = $storeManager;
56+
$this->scopeConfig = $scopeConfig;
57+
$this->themeProvider = $themeProvider;
58+
}
59+
60+
/**
61+
* @param $storeId
62+
* @return bool
63+
* @throws NoSuchEntityException
64+
*/
65+
public function execute($storeId = null): bool
66+
{
67+
$hyvaThemeEnabled = $this->moduleManager->isEnabled('Hyva_Theme');
68+
69+
if ($hyvaThemeEnabled) {
70+
71+
if (null === $storeId) {
72+
$storeId = $this->storeManager->getStore()->getId();
73+
}
74+
75+
if (!$storeId){
76+
$stores = $this->storeManager->getStores();
77+
foreach ($stores as $store) {
78+
if ($this->isHyvaThemeInUse($store->getId())) {
79+
return true;
80+
}
81+
}
82+
} else {
83+
return $this->isHyvaThemeInUse($storeId);
84+
}
85+
}
86+
return false;
87+
}
88+
89+
/**
90+
* @param $storeId
91+
* @return bool
92+
*/
93+
private function isHyvaThemeInUse($storeId)
94+
{
95+
$themeId = $this->scopeConfig->getValue(
96+
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
97+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
98+
$storeId
99+
);
100+
if ($themeId) {
101+
$theme = $this->themeProvider->getThemeById($themeId);
102+
while ($theme) {
103+
$themePath = $theme->getThemePath();
104+
if (false !== stripos($themePath, 'h' . 'y' . 'v' . 'a')) {
105+
return true;
106+
}
107+
108+
$theme = $theme->getParentTheme();
109+
}
110+
}
111+
return false;
112+
}
113+
}

Model/Section.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ final class Section
2929
*/
3030
private $scopeConfig;
3131

32+
/**
33+
* @var \Magefan\Community\Model\GetModuleVersion
34+
*/
35+
private $getModuleVersion;
36+
37+
/**
38+
* @var \Magefan\Community\Model\HyvaThemeDetection
39+
*/
40+
41+
private $hyvaThemeDetection;
42+
3243
/**
3344
* @var string
3445
*/
@@ -46,20 +57,25 @@ final class Section
4657

4758

4859
/**
49-
* Section constructor.
5060
* @param ScopeConfigInterface $scopeConfig
5161
* @param ProductMetadataInterface $metadata
52-
* @param null $name
53-
* @param null $key
62+
* @param \Magefan\Community\Model\GetModuleVersion $getModuleVersion
63+
* @param \Magefan\Community\Model\HyvaThemeDetection $hyvaThemeDetection
64+
* @param $name
65+
* @param $key
5466
*/
5567
final public function __construct(
5668
ScopeConfigInterface $scopeConfig,
5769
ProductMetadataInterface $metadata,
70+
GetModuleVersion $getModuleVersion,
71+
HyvaThemeDetection $hyvaThemeDetection,
5872
$name = null,
5973
$key = null
6074
) {
6175
$this->scopeConfig = $scopeConfig;
6276
$this->metadata = $metadata;
77+
$this->getModuleVersion = $getModuleVersion;
78+
$this->hyvaThemeDetection = $hyvaThemeDetection;
6379
$this->name = $name;
6480
$this->key = $key;
6581
}
@@ -99,6 +115,13 @@ final public function getModule($e = false)
99115
) {
100116
return $module;
101117
}
118+
119+
if ($module == ('B' . 'l' . 'o' . 'g')
120+
&& version_compare($this->getModuleVersion->execute('Ma' . 'ge' . 'fa' . 'n_' . $module), '2.' . '11' . '.4', '>=')
121+
&& $this->hyvaThemeDetection->execute()
122+
) {
123+
return $module;
124+
}
102125
}
103126
return false;
104127
}

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111

1212
<preference for="Magefan\Community\Api\GetParentProductIdsInterface" type="Magefan\Community\Model\GetParentProductIds"/>
1313
<preference for="Magefan\Community\Api\GetWebsitesMapInterface" type="Magefan\Community\Model\GetWebsitesMap"/>
14+
<preference for="Magefan\Community\Api\HyvaThemeDetectionInterface" type="Magefan\Community\Model\HyvaThemeDetection"/>
1415
</config>

0 commit comments

Comments
 (0)