Skip to content

Commit e5df3f1

Browse files
committed
ACP2E-3900: Update product url_key via REST API does not generate a 301 URL Rewrite
- fixed original issue
1 parent 7da46f5 commit e5df3f1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
use Magento\Catalog\Model\Product\Gallery\MimeTypeExtensionMap;
1515
use Magento\Catalog\Model\ProductRepository\MediaGalleryProcessor;
1616
use Magento\Catalog\Model\ResourceModel\Product\Collection;
17+
use Magento\CatalogUrlRewrite\Block\UrlKeyRenderer;
1718
use Magento\Eav\Model\Entity\Attribute\Exception as AttributeException;
1819
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
1920
use Magento\Framework\Api\ImageContentValidatorInterface;
2021
use Magento\Framework\Api\ImageProcessorInterface;
2122
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
2223
use Magento\Framework\Api\SearchCriteriaInterface;
24+
use Magento\Framework\App\Config\ScopeConfigInterface;
2325
use Magento\Framework\DB\Adapter\ConnectionException;
2426
use Magento\Framework\DB\Adapter\DeadlockException;
2527
use Magento\Framework\DB\Adapter\LockWaitException;
@@ -32,6 +34,7 @@
3234
use Magento\Framework\Exception\TemporaryState\CouldNotSaveException as TemporaryCouldNotSaveException;
3335
use Magento\Framework\Exception\ValidatorException;
3436
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
37+
use Magento\Store\Model\ScopeInterface;
3538
use Magento\Store\Model\Store;
3639
use Magento\Catalog\Api\Data\EavAttributeInterface;
3740

@@ -187,6 +190,11 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
187190
*/
188191
private $scopeOverriddenValue;
189192

193+
/**
194+
* @var ScopeConfigInterface
195+
*/
196+
private ScopeConfigInterface $scopeConfig;
197+
190198
/**
191199
* ProductRepository constructor.
192200
* @param ProductFactory $productFactory
@@ -214,6 +222,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
214222
* @param ReadExtensions $readExtensions
215223
* @param CategoryLinkManagementInterface $linkManagement
216224
* @param ScopeOverriddenValue|null $scopeOverriddenValue
225+
* @param ScopeConfigInterface|null $scopeConfig
217226
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
218227
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
219228
*/
@@ -242,7 +251,8 @@ public function __construct(
242251
$cacheLimit = 1000,
243252
?ReadExtensions $readExtensions = null,
244253
?CategoryLinkManagementInterface $linkManagement = null,
245-
?ScopeOverriddenValue $scopeOverriddenValue = null
254+
?ScopeOverriddenValue $scopeOverriddenValue = null,
255+
?ScopeConfigInterface $scopeConfig = null
246256
) {
247257
$this->productFactory = $productFactory;
248258
$this->collectionFactory = $collectionFactory;
@@ -270,6 +280,8 @@ public function __construct(
270280
->get(CategoryLinkManagementInterface::class);
271281
$this->scopeOverriddenValue = $scopeOverriddenValue ?: \Magento\Framework\App\ObjectManager::getInstance()
272282
->get(ScopeOverriddenValue::class);
283+
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()
284+
->get(ScopeConfigInterface::class);;
273285
}
274286

275287
/**
@@ -649,6 +661,14 @@ public function save(ProductInterface $product, $saveOptions = false)
649661
}
650662
}
651663

664+
$isSaveHistory = $this->scopeConfig->isSetFlag(
665+
UrlKeyRenderer::XML_PATH_SEO_SAVE_HISTORY,
666+
ScopeInterface::SCOPE_STORE,
667+
$productDataArray['store_id']
668+
);
669+
670+
$product->setData('save_rewrites_history', $isSaveHistory);
671+
652672
$this->saveProduct($product);
653673
if ($assignToCategories === true && $product->getCategoryIds()) {
654674
$this->linkManagement->assignProductToCategories(

0 commit comments

Comments
 (0)