diff --git a/Model/Config.php b/Model/Config.php index 2fa0f13..b36c389 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -15,15 +15,17 @@ class Config private const OCS_GENERAL_PRODUCT_ID_PATH = 'optimize_cache_size/general/product_id'; private const OCS_GENERAL_PRODUCT_SKU_PATH = 'optimize_cache_size/general/product_sku'; private const OCS_GENERAL_CATEGORY_ID_PATH = 'optimize_cache_size/general/category_id'; + private const OCS_GENERAL_CATEGORY_ID_EXCLUSION_PATH = 'optimize_cache_size/general/category_id_exclusion'; public function __construct( private ScopeConfigInterface $scopeConfig - ) { + ) + { } public function isModuleEnabled(int $store = 0): bool { - return $this->scopeConfig->isSetFlag( + return $this->scopeConfig->isSetFlag( self::OCS_GENERAL_IS_ENABLED_PATH, ScopeInterface::SCOPE_STORE, $store @@ -32,7 +34,7 @@ public function isModuleEnabled(int $store = 0): bool public function isRemoveProductIdHandlers(int $store = 0): bool { - return $this->scopeConfig->isSetFlag( + return $this->scopeConfig->isSetFlag( self::OCS_GENERAL_PRODUCT_ID_PATH, ScopeInterface::SCOPE_STORE, $store @@ -41,7 +43,7 @@ public function isRemoveProductIdHandlers(int $store = 0): bool public function isRemoveProductSkuHandlers(int $store = 0): bool { - return $this->scopeConfig->isSetFlag( + return $this->scopeConfig->isSetFlag( self::OCS_GENERAL_PRODUCT_SKU_PATH, ScopeInterface::SCOPE_STORE, $store @@ -50,10 +52,19 @@ public function isRemoveProductSkuHandlers(int $store = 0): bool public function isRemoveCategoryIdHandlers(int $store = 0): bool { - return $this->scopeConfig->isSetFlag( + return $this->scopeConfig->isSetFlag( self::OCS_GENERAL_CATEGORY_ID_PATH, ScopeInterface::SCOPE_STORE, $store ); } + + public function getCategoryIdExclusions(int $store = 0): array + { + return explode(',', $this->scopeConfig->getValue( + self::OCS_GENERAL_CATEGORY_ID_EXCLUSION_PATH, + ScopeInterface::SCOPE_STORE, + $store + ) ?? ''); + } } diff --git a/Model/Config/Source/CategoryList.php b/Model/Config/Source/CategoryList.php new file mode 100644 index 0000000..a57773b --- /dev/null +++ b/Model/Config/Source/CategoryList.php @@ -0,0 +1,43 @@ +categoryCollectionFactory = $categoryCollectionFactory; + } + + /** + * Return array of ['value' => , 'label' => ] + * + * @return array + */ + public function toOptionArray() + { + $collection = $this->categoryCollectionFactory->create(); + $collection->addAttributeToSelect('name') + ->addIsActiveFilter() + ->addAttributeToSort('name', 'ASC'); + + $options = []; + foreach ($collection as $category) { + $options[] = [ + 'value' => $category->getId(), + 'label' => $category->getName() + ]; + } + + return $options; + } +} diff --git a/Plugin/RemoveHandlersPlugin.php b/Plugin/RemoveHandlersPlugin.php index 8b7ba02..7c4c890 100644 --- a/Plugin/RemoveHandlersPlugin.php +++ b/Plugin/RemoveHandlersPlugin.php @@ -33,8 +33,14 @@ public function afterAddHandle( foreach ($handlers as $handler) { if ($this->config->isRemoveCategoryIdHandlers() && str_contains($handler, self::CATEGORY_ID_HANDLER_STRING)) { - $result->removeHandle($handler); - continue; + + $categoryID = str_replace(self::CATEGORY_ID_HANDLER_STRING, '', $handler); + $categoryIdExclusions = $this->config->getCategoryIdExclusions(); + + if(!in_array($categoryID, $categoryIdExclusions)){ + $result->removeHandle($handler); + continue; + } } if ($this->config->isRemoveProductIdHandlers() && str_contains($handler, self::PRODUCT_ID_HANDLER_STRING)) { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index df5bd7a..ca584e2 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -48,6 +48,16 @@ 1 + + + Vendic\OptimizeCacheSize\Model\Config\Source\CategoryList + Select all categories which should keep their id in the cache handle + + 1 + 1 + +