Skip to content

Commit 9ab406b

Browse files
committed
Merge branch 'ACP2E-3009' of https://github.com/adobe-commerce-tier-4/magento2ce into 04-29-24-Tier4-Bugfix-Delivery
2 parents 6d41441 + eaca4d3 commit 9ab406b

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app/code/Magento/Catalog/Model/ProductLink/Repository.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,14 @@ public function __construct(
133133
*/
134134
public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
135135
{
136+
if (!$entity->getSku()) {
137+
throw new CouldNotSaveException(__(
138+
'The parent product SKU is required for linking child products. '
139+
. 'Please ensure the parent product SKU is provided and try again.'
140+
));
141+
}
136142
if (!$entity->getLinkedProductSku()) {
137-
throw new NoSuchEntityException(__('The linked product SKU is invalid. Verify the data and try again.'));
143+
throw new CouldNotSaveException(__('The linked product SKU is invalid. Verify the data and try again.'));
138144
}
139145
$linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
140146
$product = $this->productRepository->get($entity->getSku());

app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testSave()
132132
['linkedProduct', false, null, false, $linkedProductMock],
133133
]);
134134
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('linkedProduct');
135-
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
135+
$entityMock->expects($this->exactly(2))->method('getSku')->willReturn('product');
136136
$entityMock->expects($this->exactly(1))->method('getLinkType')->willReturn('linkType');
137137
$this->linkTypeProvider->expects($this->once())->method('getLinkTypes')->willReturn(['linkType' => $typeId]);
138138
$this->metadataPoolMock->expects($this->once())->method('getHydrator')->willReturn($this->hydratorMock);
@@ -164,7 +164,7 @@ public function testSaveWithException()
164164
['linkedProduct', false, null, false, $linkedProductMock],
165165
]);
166166
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('linkedProduct');
167-
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
167+
$entityMock->expects($this->exactly(2))->method('getSku')->willReturn('product');
168168
$entityMock->expects($this->exactly(1))->method('getLinkType')->willReturn('linkType');
169169
$this->linkTypeProvider->expects($this->once())->method('getLinkTypes')->willReturn(['linkType' => $typeId]);
170170
$this->metadataPoolMock->expects($this->once())->method('getHydrator')->willReturn($this->hydratorMock);
@@ -182,13 +182,27 @@ public function testSaveWithException()
182182

183183
public function testSaveWithoutLinkedProductSku()
184184
{
185-
$this->expectException('Magento\Framework\Exception\NoSuchEntityException');
185+
$this->expectException('Magento\Framework\Exception\CouldNotSaveException');
186186
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
187187
$entityMock = $this->createMock(\Magento\Catalog\Model\ProductLink\Link::class);
188+
$entityMock->expects($this->any())->method('getSku')->willReturn('sku1');
188189
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('');
189190
$this->model->save($entityMock);
190191
}
191192

193+
public function testSaveWithoutProductSku()
194+
{
195+
$this->expectException('Magento\Framework\Exception\CouldNotSaveException');
196+
$this->expectExceptionMessage(
197+
'The parent product SKU is required for linking child products. '
198+
. 'Please ensure the parent product SKU is provided and try again.'
199+
);
200+
$entityMock = $this->createMock(\Magento\Catalog\Model\ProductLink\Link::class);
201+
$entityMock->expects($this->any())->method('getSku')->willReturn('');
202+
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('linkedProductSku');
203+
$this->model->save($entityMock);
204+
}
205+
192206
/**
193207
* Test method
194208
*/

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,4 @@ Details,Details
823823
"The url has invalid characters. Please correct and try again.","The url has invalid characters. Please correct and try again."
824824
"Restricted admin is allowed to perform actions with images or videos, only when the admin has rights to all websites which the product is assigned to.","Restricted admin is allowed to perform actions with images or videos, only when the admin has rights to all websites which the product is assigned to."
825825
"Synchronize website specific attributes values","Synchronize website specific attributes values"
826+
"The parent product SKU is required for linking child products. Please ensure the parent product SKU is provided and try again.","The parent product SKU is required for linking child products. Please ensure the parent product SKU is provided and try again."

0 commit comments

Comments
 (0)