Skip to content

Commit 3455667

Browse files
🔃 [Magento Community Engineering] Community Contributions
Accepted Community Pull Requests: - #26842: Unit test for Magento\Catalog\Observer\SetSpecialPriceStartDate has added (by @mmezhensky) - #26979: #26800 Fixed Undefined variable in ProductLink/Management (by @srsathish92) - #26615: Add missing annotations to MFTF tests (by @sta1r) - #25311: Add afterGetList method in CustomerRepository plugin to retrieve is_s� (by @enriquei4) - #25828: MFTF: Extract Action Groups to separate files - magento/module-customer (by @lbajsarowicz) Fixed GitHub Issues: - #26800: Undefined variable $type in Product-Link Management (reported by @angelobono) has been fixed in #26979 by @srsathish92 in 2.4-develop branch Related commits: 1. 84eb1fc 2. 55d1f18 3. bb15005 - #13252: Fetching customer entity through API will not return 'is_subscribed' extension attribute (reported by @koenner01) has been fixed in #25311 by @enriquei4 in 2.4-develop branch Related commits: 1. b2d553a 2. 8f5bfad 3. 8b33f69 4. d867655 5. c9f9d71 6. 5020752 - #26331: [ MFTF ] Mess in ActionGroups: invalid names, multiple nodes. (reported by @lbajsarowicz) has been fixed in #25828 by @lbajsarowicz in 2.4-develop branch Related commits: 1. 14f95d9 2. 63582cd 3. 64b820d 4. 0652d0e 5. 7ac6b48 6. b5500f7 7. 632b3e5 8. bf9315b 9. f7c59ba 10. eaeacf1 11. df511be 12. b7e5bcf 13. b7165b9 14. 171215d 15. c6c52d6
2 parents 9f093a3 + 6167b0c commit 3455667

File tree

62 files changed

+1320
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1320
-596
lines changed

app/code/Magento/CardinalCommerce/Test/Mftf/Test/AdminCardinalCommerceSettingsHiddenTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<annotations>
1212
<stories value="Cardinal Commerce Settings"/>
1313
<features value="CardinalCommerce"/>
14+
<stories value="Configure CardinalCommerce"/>
1415
<title value="CardinalCommerce settings hidden" />
1516
<description value="CardinalCommerce config shouldn't be visible if the 3D secure is disabled for Authorize.Net."/>
1617
<severity value="MINOR"/>

app/code/Magento/Catalog/Api/ProductLinkManagementInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface ProductLinkManagementInterface
1717
*
1818
* @param string $sku
1919
* @param string $type
20+
* @throws \Magento\Framework\Exception\NoSuchEntityException
2021
* @return \Magento\Catalog\Api\Data\ProductLinkInterface[]
2122
*/
2223
public function getLinkedItemsByType($sku, $type);
@@ -28,6 +29,7 @@ public function getLinkedItemsByType($sku, $type);
2829
* @param \Magento\Catalog\Api\Data\ProductLinkInterface[] $items
2930
* @throws \Magento\Framework\Exception\NoSuchEntityException
3031
* @throws \Magento\Framework\Exception\CouldNotSaveException
32+
* @throws \Magento\Framework\Exception\InputException
3133
* @return bool
3234
*/
3335
public function setProductLinks($sku, array $items);

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,42 @@
66

77
namespace Magento\Catalog\Model\ProductLink;
88

9-
use Magento\Catalog\Api\Data;
109
use Magento\Framework\Exception\CouldNotSaveException;
1110
use Magento\Framework\Exception\NoSuchEntityException;
1211
use Magento\Framework\Exception\InputException;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Catalog\Model\Product\LinkTypeProvider;
14+
use Magento\Catalog\Api\ProductLinkManagementInterface;
1315

14-
class Management implements \Magento\Catalog\Api\ProductLinkManagementInterface
16+
/**
17+
* Manage product links from api
18+
*/
19+
class Management implements ProductLinkManagementInterface
1520
{
1621
/**
17-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
22+
* @var ProductRepositoryInterface
1823
*/
1924
protected $productRepository;
2025

2126
/**
22-
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
27+
* @var LinkTypeProvider
2328
*/
2429
protected $linkTypeProvider;
2530

2631
/**
27-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
28-
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
32+
* @param ProductRepositoryInterface $productRepository
33+
* @param LinkTypeProvider $linkTypeProvider
2934
*/
3035
public function __construct(
31-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
32-
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
36+
ProductRepositoryInterface $productRepository,
37+
LinkTypeProvider $linkTypeProvider
3338
) {
3439
$this->productRepository = $productRepository;
3540
$this->linkTypeProvider = $linkTypeProvider;
3641
}
3742

3843
/**
39-
* {@inheritdoc}
44+
* @inheritdoc
4045
*/
4146
public function getLinkedItemsByType($sku, $type)
4247
{
@@ -63,47 +68,42 @@ public function getLinkedItemsByType($sku, $type)
6368
}
6469

6570
/**
66-
* {@inheritdoc}
71+
* @inheritdoc
6772
*/
6873
public function setProductLinks($sku, array $items)
6974
{
75+
76+
if (empty($items)) {
77+
throw InputException::invalidFieldValue('items', 'empty array');
78+
}
79+
7080
$linkTypes = $this->linkTypeProvider->getLinkTypes();
7181

7282
// Check if product link type is set and correct
73-
if (!empty($items)) {
74-
foreach ($items as $newLink) {
75-
$type = $newLink->getLinkType();
76-
if ($type == null) {
77-
throw InputException::requiredField("linkType");
78-
}
79-
if (!isset($linkTypes[$type])) {
80-
throw new NoSuchEntityException(
81-
__('The "%1" link type wasn\'t found. Verify the type and try again.', $type)
82-
);
83-
}
83+
foreach ($items as $newLink) {
84+
$type = $newLink->getLinkType();
85+
if ($type == null) {
86+
throw InputException::requiredField("linkType");
87+
}
88+
if (!isset($linkTypes[$type])) {
89+
throw new NoSuchEntityException(
90+
__('The "%1" link type wasn\'t found. Verify the type and try again.', $type)
91+
);
8492
}
8593
}
8694

8795
$product = $this->productRepository->get($sku);
8896

89-
// Replace only links of the specified type
9097
$existingLinks = $product->getProductLinks();
91-
$newLinks = [];
92-
if (!empty($existingLinks)) {
93-
foreach ($existingLinks as $link) {
94-
if ($link->getLinkType() != $type) {
95-
$newLinks[] = $link;
96-
}
97-
}
98-
$newLinks = array_merge($newLinks, $items);
99-
} else {
100-
$newLinks = $items;
101-
}
98+
$newLinks = array_merge($existingLinks, $items);
99+
102100
$product->setProductLinks($newLinks);
103101
try {
104102
$this->productRepository->save($product);
105103
} catch (\Exception $exception) {
106-
throw new CouldNotSaveException(__('The linked products data is invalid. Verify the data and try again.'));
104+
throw new CouldNotSaveException(
105+
__('The linked products data is invalid. Verify the data and try again.')
106+
);
107107
}
108108

109109
return true;

0 commit comments

Comments
 (0)