diff --git a/Helper/Config.php b/Helper/Config.php index c3d465c..873a123 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -13,6 +13,9 @@ class Config { private const XML_PATH_RECACHE_ENABLED = 'system/prerender_io/enabled'; + private const XML_PATH_RECACHE_PRODUCT_ENABLED = 'system/prerender_io/enable_product_indexing'; + private const XML_PATH_RECACHE_PRODUCT_CATEGORY_ENABLED = 'system/prerender_io/enable_product_category_indexing'; + private const XML_PATH_RECACHE_CATEGORY_ENABLED = 'system/prerender_io/enable_category_indexing'; private const XML_PATH_PRERENDER_TOKEN = 'system/prerender_io/token'; private const XML_PATH_PRERENDER_USE_PRODUCT_CANONICAL_URL = 'system/prerender_io/use_product_canonical_url'; @@ -29,7 +32,7 @@ public function __construct(ScopeConfigInterface $scopeConfig) } /** - * Return if recaching functionality is enabled or not + * Return if recaching functionality is enabled globally * * @param int|null $storeId * @return bool @@ -43,6 +46,51 @@ public function isRecacheEnabled(?int $storeId = null): bool ); } + /** + * Return if recaching functionality is enabled for product only indexer + * + * @param int|null $storeId + * @return bool + */ + public function isProductRecacheEnabled(?int $storeId = null): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_RECACHE_PRODUCT_ENABLED, + ScopeInterface::SCOPE_STORES, + $storeId + ); + } + + /** + * Return if recaching functionality is enabled for product-category mapping indexer + * + * @param int|null $storeId + * @return bool + */ + public function isProductCategoryRecacheEnabled(?int $storeId = null): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_RECACHE_PRODUCT_CATEGORY_ENABLED, + ScopeInterface::SCOPE_STORES, + $storeId + ); + } + + /** + * Return if recaching functionality is enabled for category only indexer + * + * @param int|null $storeId + * @return bool + */ + public function isCategoryRecacheEnabled(?int $storeId = null): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_RECACHE_CATEGORY_ENABLED, + ScopeInterface::SCOPE_STORES, + $storeId + ); + } + /** * Return configured Prerender.io token for API calls * diff --git a/Model/Indexer/Category/CategoryIndexer.php b/Model/Indexer/Category/CategoryIndexer.php index 1634db7..96590f5 100644 --- a/Model/Indexer/Category/CategoryIndexer.php +++ b/Model/Indexer/Category/CategoryIndexer.php @@ -121,7 +121,7 @@ public function execute($ids): void /** * Execute indexing per dimension (store) * - * @param arry $dimensions + * @param array $dimensions * @param \Traversable $entityIds * @throws FileSystemException * @throws RuntimeException @@ -133,7 +133,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); - if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) { + if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId) + || !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) { return; } diff --git a/Model/Indexer/Category/ProductIndexer.php b/Model/Indexer/Category/ProductIndexer.php index 9c85fc6..a271d6e 100644 --- a/Model/Indexer/Category/ProductIndexer.php +++ b/Model/Indexer/Category/ProductIndexer.php @@ -132,7 +132,7 @@ public function execute($ids): void /** * Execute indexing per dimension (store) * - * @param arry $dimensions + * @param array $dimensions * @param \Traversable $entityIds * @throws FileSystemException * @throws RuntimeException @@ -144,7 +144,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); - if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) { + if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId) + || !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) { return; } diff --git a/Model/Indexer/Product/ProductIndexer.php b/Model/Indexer/Product/ProductIndexer.php index 0239eb8..310cd4b 100644 --- a/Model/Indexer/Product/ProductIndexer.php +++ b/Model/Indexer/Product/ProductIndexer.php @@ -128,7 +128,7 @@ public function execute($ids): void /** * Execute indexing per dimension (store) * - * @param arry $dimensions + * @param array $dimensions * @param \Traversable $entityIds * @throws FileSystemException * @throws RuntimeException @@ -140,7 +140,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); - if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) { + if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId) + || !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) { return; } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 5f3435e..ea3a92d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -10,8 +10,8 @@ - - Send recache requests to Prerender.io on product changes + + Send recache requests to Prerender.io Magento\Config\Model\Config\Source\Yesno @@ -25,6 +25,30 @@ Ignore the non-canonical URLs which includes category paths for products. Magento\Config\Model\Config\Source\Yesno + + + Product updates will recache PDPs. + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + Product updates will recache linked category PLPs. + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + Category updates will recache PLPs. + Magento\Config\Model\Config\Source\Yesno + + 1 + + diff --git a/etc/config.xml b/etc/config.xml index d346dc2..7838f61 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -5,6 +5,9 @@ 0 + 1 + 1 + 1