Skip to content

Commit d567457

Browse files
committed
Merge remote-tracking branch 'origin/AC-13311' into spartans_pr_27102025
2 parents 039a867 + f4851c5 commit d567457

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
139139
. 'Please ensure the parent product SKU is provided and try again.'
140140
));
141141
}
142-
if (!$entity->getLinkedProductSku()) {
142+
if ($entity->getLinkedProductSku() === null || $entity->getLinkedProductSku() === '') {
143143
throw new CouldNotSaveException(__('The linked product SKU is invalid. Verify the data and try again.'));
144144
}
145145
$linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,16 @@ public function testDeleteWithNoSuchEntityException()
298298

299299
$this->model->delete($entityMock);
300300
}
301+
302+
public function testSaveWithNullLinkedProductSku()
303+
{
304+
$this->expectException('Magento\Framework\Exception\CouldNotSaveException');
305+
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
306+
307+
$entityMock = $this->createMock(\Magento\Catalog\Model\ProductLink\Link::class);
308+
$entityMock->expects($this->any())->method('getSku')->willReturn('sku1');
309+
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn(null);
310+
311+
$this->model->save($entityMock);
312+
}
301313
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\ProductLink;
9+
10+
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
11+
use Magento\Catalog\Model\ProductLink\Link;
12+
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* @magentoAppIsolation enabled
18+
*/
19+
class RepositorySaveTest extends TestCase
20+
{
21+
/**
22+
* @var ProductLinkRepositoryInterface
23+
*/
24+
private $repository;
25+
26+
protected function setUp(): void
27+
{
28+
parent::setUp();
29+
$this->repository = Bootstrap::getObjectManager()->get(ProductLinkRepositoryInterface::class);
30+
}
31+
32+
public function testSaveWithNullLinkedProductSku(): void
33+
{
34+
$this->expectException(CouldNotSaveException::class);
35+
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
36+
37+
$objectManager = Bootstrap::getObjectManager();
38+
/** @var Link $link */
39+
$link = $objectManager->create(Link::class);
40+
$link->setSku('sku1');
41+
$link->setLinkedProductSku(null);
42+
43+
$this->repository->save($link);
44+
}
45+
46+
public function testSaveWithEmptyLinkedProductSku(): void
47+
{
48+
$this->expectException(CouldNotSaveException::class);
49+
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
50+
51+
$objectManager = Bootstrap::getObjectManager();
52+
/** @var Link $link */
53+
$link = $objectManager->create(Link::class);
54+
$link->setSku('sku1');
55+
$link->setLinkedProductSku('');
56+
57+
$this->repository->save($link);
58+
}
59+
}

0 commit comments

Comments
 (0)