diff --git a/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php b/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php index 5ed18d15b2f304cdc9ca6e89a7bcc09e2a5c3590..a2df5b7c2331ee47c58860f8d938c37502fd25a1 100644 --- a/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php +++ b/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php @@ -40,6 +40,11 @@ class Suffix extends \Magento\Framework\App\Config\Value */ protected $resource; + /** + * @var \Magento\Framework\App\Config\ScopePool + */ + private $scopePool; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -75,6 +80,22 @@ class Suffix extends \Magento\Framework\App\Config\Value $this->resource = $appResource; } + /** + * Get instance of ScopePool + * + * @return \Magento\Framework\App\Config\ScopePool + * @deprecated + */ + private function getScopePool() + { + if ($this->scopePool === null) { + $this->scopePool = \Magento\Framework\App\ObjectManager::getInstance()->get( + \Magento\Framework\App\Config\ScopePool::class + ); + } + return $this->scopePool; + } + /** * Check url rewrite suffix - whether we can support it * @@ -103,6 +124,24 @@ class Suffix extends \Magento\Framework\App\Config\Value return parent::afterSave(); } + /** + * @return $this + */ + public function afterDeleteCommit() + { + if ($this->isValueChanged()) { + $this->updateSuffixForUrlRewrites(); + if ($this->isCategorySuffixChanged()) { + $this->cacheTypeList->invalidate([ + \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER, + \Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER + ]); + } + } + + return parent::afterDeleteCommit(); + } + /** * Check is category suffix changed * @@ -135,7 +174,12 @@ class Suffix extends \Magento\Framework\App\Config\Value } $entities = $this->urlFinder->findAllByData($dataFilter); $oldSuffixPattern = '~' . preg_quote($this->getOldValue()) . '$~'; - $suffix = $this->getValue(); + if ($this->getValue() !== null) { + $suffix = $this->getValue(); + } else { + $this->getScopePool()->clean(); + $suffix = $this->_config->getValue($this->getPath()); + } foreach ($entities as $urlRewrite) { $bind = $urlRewrite->getIsAutogenerated() ? [UrlRewrite::REQUEST_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getRequestPath())]