Skip to content

Commit cd2f9b7

Browse files
committed
updated enabled logic to pull from the config helper class
1 parent cd66f91 commit cd2f9b7

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

Factory/CatalogPermissionsFactory.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
class CatalogPermissionsFactory
1010
{
11-
const CATALOG_PERMISSIONS_ENABLED_CONFIG_PATH = 'catalog/magento_catalogpermissions/enabled';
12-
const CATALOG_PERMISSIONS_ENABLED_ALLOW_BROWSING = 'catalog/magento_catalogpermissions/grant_catalog_category_view';
13-
1411
private $scopeConfig;
1512
private $moduleManager;
1613
private $objectManager;
@@ -30,19 +27,8 @@ public function __construct(
3027

3128
public function isCatalogPermissionsEnabled($storeId)
3229
{
33-
$isEnabled = $this->scopeConfig->isSetFlag(
34-
self::CATALOG_PERMISSIONS_ENABLED_CONFIG_PATH,
35-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
36-
$storeId
37-
);
38-
39-
$isAllowBrowsingCatalog = (int) $this->scopeConfig->getValue(
40-
self::CATALOG_PERMISSIONS_ENABLED_ALLOW_BROWSING,
41-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
42-
$storeId
43-
);
44-
45-
return $isEnabled && ($isAllowBrowsingCatalog !== 1) && $this->isCatalogPermissionsModuleEnabled();
30+
return $this->isCatalogPermissionsModuleEnabled()
31+
&& $this->getCatalogPermissionsConfig()->isEnabled($storeId);
4632
}
4733

4834
private function isCatalogPermissionsModuleEnabled()
@@ -60,6 +46,11 @@ public function getCatalogPermissionsHelper()
6046
return $this->objectManager->create('\Magento\CatalogPermissions\Helper\Data');
6147
}
6248

49+
public function getCatalogPermissionsConfig()
50+
{
51+
return $this->objectManager->create('\Magento\CatalogPermissions\App\Config');
52+
}
53+
6354
public function getCategoryPermissionsCollection()
6455
{
6556
if (!$this->categoryPermissionsCollection) {

Factory/SharedCatalogFactory.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
class SharedCatalogFactory
1010
{
11-
const SHARED_CATALOG_ENABLED_CONFIG_PATH = 'btob/website_configuration/sharedcatalog_active';
12-
1311
private $scopeConfig;
1412
private $moduleManager;
1513
private $objectManager;
@@ -29,13 +27,11 @@ public function __construct(
2927

3028
public function isSharedCatalogEnabled($storeId)
3129
{
32-
$isEnabled = $this->scopeConfig->isSetFlag(
33-
self::SHARED_CATALOG_ENABLED_CONFIG_PATH,
34-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
35-
$storeId
36-
);
37-
38-
return $isEnabled && $this->isSharedCatalogModuleEnabled();
30+
return $this->isSharedCatalogModuleEnabled()
31+
&& $this->getSharedCatalogConfig()->isActive(
32+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
33+
$storeId
34+
);
3935
}
4036

4137
private function isSharedCatalogModuleEnabled()
@@ -58,6 +54,11 @@ public function getSharedCatalogResource()
5854
return $this->objectManager->create('\Magento\SharedCatalog\Model\ResourceModel\SharedCatalog');
5955
}
6056

57+
public function getSharedCatalogConfig()
58+
{
59+
return $this->objectManager->create('\Magento\SharedCatalog\Model\Config');
60+
}
61+
6162
public function getSharedCategoryCollection()
6263
{
6364
if (!$this->sharedCategoryCollection) {

Model/Observer/CatalogPermissions/ApplyProductPermissionsFilter.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,44 @@
33
namespace Algolia\AlgoliaSearch\Model\Observer\CatalogPermissions;
44

55
use Algolia\AlgoliaSearch\Factory\CatalogPermissionsFactory;
6+
use Algolia\AlgoliaSearch\Factory\SharedCatalogFactory;
67
use Magento\Framework\Event\Observer;
78
use Magento\Framework\Event\ObserverInterface;
89
use Magento\Store\Model\StoreManager;
910

1011
class ApplyProductPermissionsFilter implements ObserverInterface
1112
{
13+
/** @var CatalogPermissionsFactory */
1214
private $permissionsFactory;
15+
16+
/** @var SharedCatalogFactory */
17+
private $sharedCatalogFactory;
18+
19+
/** @var StoreManager */
1320
private $storeManager;
1421

22+
/**
23+
* @param CatalogPermissionsFactory $permissionsFactory
24+
* @param SharedCatalogFactory $sharedCatalogFactory
25+
* @param StoreManager $storeManager
26+
*/
1527
public function __construct(
1628
CatalogPermissionsFactory $permissionsFactory,
29+
SharedCatalogFactory $sharedCatalogFactory,
1730
StoreManager $storeManager
1831
) {
1932
$this->permissionsFactory = $permissionsFactory;
33+
$this->sharedCatalogFactory = $sharedCatalogFactory;
2034
$this->storeManager = $storeManager;
2135
}
2236

2337
public function execute(Observer $observer)
2438
{
2539
$storeId = $this->storeManager->getStore()->getId();
26-
if (!$this->permissionsFactory->isCatalogPermissionsEnabled($storeId)) {
40+
if (!$this->permissionsFactory->isCatalogPermissionsEnabled($storeId)
41+
|| ($this->permissionsFactory->getCatalogPermissionsHelper()->isAllowedCategoryView($storeId)
42+
&& !$this->sharedCatalogFactory->isSharedCatalogEnabled($storeId))
43+
) {
2744
return $this;
2845
}
2946

0 commit comments

Comments
 (0)