Skip to content

Commit 82409c4

Browse files
committed
Merge branch 'ACP2E-758' of https://github.com/magento-l3/magento2ce into L3-PR-2022-04-19-v2
2 parents c2a7ad4 + 287d878 commit 82409c4

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Catalog\Model;
88

99
use Magento\Catalog\Api\CategoryLinkManagementInterface;
10+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1011
use Magento\Catalog\Api\Data\ProductExtension;
1112
use Magento\Catalog\Api\Data\ProductInterface;
1213
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
@@ -617,7 +618,10 @@ public function save(ProductInterface $product, $saveOptions = false)
617618
$product->getStoreId()
618619
)
619620
) {
620-
$product->setData($attributeCode);
621+
$product->setData(
622+
$attributeCode,
623+
$attributeCode === ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY ? false : null
624+
);
621625
$hasDataChanged = true;
622626
}
623627
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryMultiWebsiteTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,66 @@ public function testPartialUpdateShouldNotOverrideImagesRolesInheritance(): void
415415
);
416416
}
417417

418+
/**
419+
* @magentoApiDataFixture Magento\Catalog\Test\Fixture\Product as:product1
420+
* @magentoApiDataFixture Magento\Catalog\Test\Fixture\Product as:product2
421+
*/
422+
public function testPartialUpdateShouldNotOverrideUrlKeyInheritance(): void
423+
{
424+
/** @var ProductRepositoryInterface $productRepository */
425+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
426+
$store = $this->objectManager->get(Store::class);
427+
$defaultStore = $store->load('default', 'code');
428+
$sku2 = $this->fixtures->get('product2')->getSku();
429+
$sku1Name = $this->fixtures->get('product1')->getName();
430+
$sku2NewName = $this->fixtures->get('product2')->getName() . ' storeview';
431+
$sku2UrlKey = $this->fixtures->get('product2')->getUrlKey();
432+
433+
// Change the second product name with the first product name in default store view
434+
$this->saveProduct(
435+
[
436+
ProductInterface::SKU => $sku2,
437+
'name' => $sku1Name
438+
],
439+
$defaultStore->getCode()
440+
);
441+
$response = $this->flattenCustomAttributes($this->getProduct($sku2, $defaultStore->getCode()));
442+
$this->assertEquals($sku1Name, $response['name']);
443+
// Assert that Url Key has not changed
444+
$this->assertEquals($sku2UrlKey, $response['url_key']);
445+
$product = $productRepository->get($sku2, false, $defaultStore->getId(), true);
446+
$this->assertOverriddenValues(
447+
[
448+
'name' => true,
449+
'url_key' => false,
450+
],
451+
$product,
452+
(int) $defaultStore->getId()
453+
);
454+
455+
// Change the second product name with a new name in default store view
456+
$this->saveProduct(
457+
[
458+
ProductInterface::SKU => $sku2,
459+
'name' => $sku2NewName
460+
],
461+
$defaultStore->getCode()
462+
);
463+
$response = $this->flattenCustomAttributes($this->getProduct($sku2, $defaultStore->getCode()));
464+
$this->assertEquals($sku2NewName, $response['name']);
465+
// Assert that Url Key has not changed
466+
$this->assertEquals($sku2UrlKey, $response['url_key']);
467+
$product = $productRepository->get($sku2, false, $defaultStore->getId(), true);
468+
$this->assertOverriddenValues(
469+
[
470+
'name' => true,
471+
'url_key' => false,
472+
],
473+
$product,
474+
(int) $defaultStore->getId()
475+
);
476+
}
477+
418478
/**
419479
* @param array $expected
420480
* @param array $actual

0 commit comments

Comments
 (0)