Skip to content

Commit 8efbc6d

Browse files
committed
MAGETWO-54296: Category suffix does not change after the second configuration changes
1 parent 3a43a25 commit 8efbc6d

File tree

1 file changed

+45
-1
lines changed
  • app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite

1 file changed

+45
-1
lines changed

app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class Suffix extends \Magento\Framework\App\Config\Value
4040
*/
4141
protected $resource;
4242

43+
/**
44+
* @var \Magento\Framework\App\Config\ScopePool
45+
*/
46+
private $scopePool;
47+
4348
/**
4449
* @param \Magento\Framework\Model\Context $context
4550
* @param \Magento\Framework\Registry $registry
@@ -75,6 +80,22 @@ public function __construct(
7580
$this->resource = $appResource;
7681
}
7782

83+
/**
84+
* Get instance of ScopePool
85+
*
86+
* @return \Magento\Framework\App\Config\ScopePool
87+
* @deprecated
88+
*/
89+
private function getScopePool()
90+
{
91+
if ($this->scopePool === null) {
92+
$this->scopePool = \Magento\Framework\App\ObjectManager::getInstance()->get(
93+
\Magento\Framework\App\Config\ScopePool::class
94+
);
95+
}
96+
return $this->scopePool;
97+
}
98+
7899
/**
79100
* Check url rewrite suffix - whether we can support it
80101
*
@@ -103,6 +124,24 @@ public function afterSave()
103124
return parent::afterSave();
104125
}
105126

127+
/**
128+
* @return $this
129+
*/
130+
public function afterDeleteCommit()
131+
{
132+
if ($this->isValueChanged()) {
133+
$this->updateSuffixForUrlRewrites();
134+
if ($this->isCategorySuffixChanged()) {
135+
$this->cacheTypeList->invalidate([
136+
\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER,
137+
\Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER
138+
]);
139+
}
140+
}
141+
142+
return parent::afterDeleteCommit();
143+
}
144+
106145
/**
107146
* Check is category suffix changed
108147
*
@@ -135,7 +174,12 @@ protected function updateSuffixForUrlRewrites()
135174
}
136175
$entities = $this->urlFinder->findAllByData($dataFilter);
137176
$oldSuffixPattern = '~' . preg_quote($this->getOldValue()) . '$~';
138-
$suffix = $this->getValue();
177+
if ($this->getValue() !== null) {
178+
$suffix = $this->getValue();
179+
} else {
180+
$this->getScopePool()->clean();
181+
$suffix = $this->_config->getValue($this->getPath());
182+
}
139183
foreach ($entities as $urlRewrite) {
140184
$bind = $urlRewrite->getIsAutogenerated()
141185
? [UrlRewrite::REQUEST_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getRequestPath())]

0 commit comments

Comments
 (0)