Skip to content
Snippets Groups Projects
Commit 8efbc6d7 authored by Stanislav Lopukhov's avatar Stanislav Lopukhov
Browse files

MAGETWO-54296: Category suffix does not change after the second configuration changes

parent 3a43a254
No related merge requests found
...@@ -40,6 +40,11 @@ class Suffix extends \Magento\Framework\App\Config\Value ...@@ -40,6 +40,11 @@ class Suffix extends \Magento\Framework\App\Config\Value
*/ */
protected $resource; protected $resource;
/**
* @var \Magento\Framework\App\Config\ScopePool
*/
private $scopePool;
/** /**
* @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Registry $registry
...@@ -75,6 +80,22 @@ class Suffix extends \Magento\Framework\App\Config\Value ...@@ -75,6 +80,22 @@ class Suffix extends \Magento\Framework\App\Config\Value
$this->resource = $appResource; $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 * Check url rewrite suffix - whether we can support it
* *
...@@ -103,6 +124,24 @@ class Suffix extends \Magento\Framework\App\Config\Value ...@@ -103,6 +124,24 @@ class Suffix extends \Magento\Framework\App\Config\Value
return parent::afterSave(); 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 * Check is category suffix changed
* *
...@@ -135,7 +174,12 @@ class Suffix extends \Magento\Framework\App\Config\Value ...@@ -135,7 +174,12 @@ class Suffix extends \Magento\Framework\App\Config\Value
} }
$entities = $this->urlFinder->findAllByData($dataFilter); $entities = $this->urlFinder->findAllByData($dataFilter);
$oldSuffixPattern = '~' . preg_quote($this->getOldValue()) . '$~'; $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) { foreach ($entities as $urlRewrite) {
$bind = $urlRewrite->getIsAutogenerated() $bind = $urlRewrite->getIsAutogenerated()
? [UrlRewrite::REQUEST_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getRequestPath())] ? [UrlRewrite::REQUEST_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getRequestPath())]
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment