Skip to content

Commit efdc360

Browse files
committed
ACP2E-3900: Update product url_key via REST API does not generate a 301 URL Rewrite
- moved functionality into the correct module
1 parent a6c53e8 commit efdc360

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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;
1817
use Magento\Eav\Model\Entity\Attribute\Exception as AttributeException;
1918
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
2019
use Magento\Framework\Api\ImageContentValidatorInterface;
@@ -34,7 +33,6 @@
3433
use Magento\Framework\Exception\TemporaryState\CouldNotSaveException as TemporaryCouldNotSaveException;
3534
use Magento\Framework\Exception\ValidatorException;
3635
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
37-
use Magento\Store\Model\ScopeInterface;
3836
use Magento\Store\Model\Store;
3937
use Magento\Catalog\Api\Data\EavAttributeInterface;
4038

@@ -190,11 +188,6 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
190188
*/
191189
private $scopeOverriddenValue;
192190

193-
/**
194-
* @var ScopeConfigInterface
195-
*/
196-
private ScopeConfigInterface $scopeConfig;
197-
198191
/**
199192
* ProductRepository constructor.
200193
* @param ProductFactory $productFactory
@@ -251,8 +244,7 @@ public function __construct(
251244
$cacheLimit = 1000,
252245
?ReadExtensions $readExtensions = null,
253246
?CategoryLinkManagementInterface $linkManagement = null,
254-
?ScopeOverriddenValue $scopeOverriddenValue = null,
255-
?ScopeConfigInterface $scopeConfig = null
247+
?ScopeOverriddenValue $scopeOverriddenValue = null
256248
) {
257249
$this->productFactory = $productFactory;
258250
$this->collectionFactory = $collectionFactory;
@@ -280,8 +272,6 @@ public function __construct(
280272
->get(CategoryLinkManagementInterface::class);
281273
$this->scopeOverriddenValue = $scopeOverriddenValue ?: \Magento\Framework\App\ObjectManager::getInstance()
282274
->get(ScopeOverriddenValue::class);
283-
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()
284-
->get(ScopeConfigInterface::class);
285275
}
286276

287277
/**
@@ -661,14 +651,6 @@ public function save(ProductInterface $product, $saveOptions = false)
661651
}
662652
}
663653

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-
672654
$this->saveProduct($product);
673655
if ($assignToCategories === true && $product->getCategoryIds()) {
674656
$this->linkManagement->assignProductToCategories(

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,6 @@ public function testSaveForAllStoreViewScope(array $productData): void
384384
return null;
385385
}
386386
});
387-
$this->product
388-
->method('setData')
389-
->willReturnCallback(function ($key, $value) {
390-
if ($key !== 'save_rewrites_history') {
391-
return null;
392-
}
393-
394-
$this->assertEquals(null, $value);
395-
});
396387
$this->model->save($this->product);
397388
}
398389

app/code/Magento/CatalogUrlRewrite/Model/Product/CurrentUrlRewritesRegenerator.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Model\Category;
99
use Magento\Catalog\Model\CategoryRepository;
1010
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1213
use Magento\UrlRewrite\Model\OptionProvider;
1314
use Magento\CatalogUrlRewrite\Model\ObjectRegistry;
@@ -18,6 +19,8 @@
1819
use Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder;
1920
use Magento\Framework\App\ObjectManager;
2021
use Magento\UrlRewrite\Model\MergeDataProviderFactory;
22+
use Magento\CatalogUrlRewrite\Block\UrlKeyRenderer;
23+
use Magento\Store\Model\ScopeInterface;
2124

2225
/**
2326
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -72,6 +75,11 @@ class CurrentUrlRewritesRegenerator
7275
*/
7376
private $categoryRepository;
7477

78+
/**
79+
* @var ScopeConfigInterface
80+
*/
81+
private ScopeConfigInterface $scopeConfig;
82+
7583
/**
7684
* @param UrlFinderInterface $urlFinder
7785
* @param ProductUrlPathGenerator $productUrlPathGenerator
@@ -86,7 +94,8 @@ public function __construct(
8694
UrlRewriteFactory $urlRewriteFactory,
8795
?UrlRewriteFinder $urlRewriteFinder = null,
8896
?MergeDataProviderFactory $mergeDataProviderFactory = null,
89-
?CategoryRepository $categoryRepository = null
97+
?CategoryRepository $categoryRepository = null,
98+
?ScopeConfigInterface $scopeConfig = null
9099
) {
91100
$this->urlFinder = $urlFinder;
92101
$this->productUrlPathGenerator = $productUrlPathGenerator;
@@ -98,6 +107,7 @@ public function __construct(
98107
}
99108
$this->categoryRepository = $categoryRepository ?: ObjectManager::getInstance()->get(CategoryRepository::class);
100109
$this->mergeDataProviderPrototype = $mergeDataProviderFactory->create();
110+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
101111
}
102112

103113
/**
@@ -119,6 +129,14 @@ public function generate($storeId, Product $product, ObjectRegistry $productCate
119129
$rootCategoryId
120130
);
121131

132+
$isSaveHistory = $this->scopeConfig->isSetFlag(
133+
UrlKeyRenderer::XML_PATH_SEO_SAVE_HISTORY,
134+
ScopeInterface::SCOPE_STORE,
135+
$storeId
136+
);
137+
138+
$product->setData('save_rewrites_history', $isSaveHistory);
139+
122140
foreach ($currentUrlRewrites as $currentUrlRewrite) {
123141
$category = $this->retrieveCategoryFromMetadata($currentUrlRewrite, $productCategories);
124142
if ($category === false) {

0 commit comments

Comments
 (0)