Skip to content

Commit 4616bca

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3965' into PR_2025_06_25_muntianu
2 parents 899ce67 + 875522f commit 4616bca

File tree

3 files changed

+83
-66
lines changed

3 files changed

+83
-66
lines changed

app/code/Magento/ConfigurableProduct/Model/LinkManagement.php

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\ConfigurableProduct\Model;
88

99
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory;
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
1013
use Magento\Catalog\Model\ProductRepository;
14+
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
15+
use Magento\ConfigurableProduct\Api\LinkManagementInterface;
16+
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
17+
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;
18+
use Magento\Framework\Api\DataObjectHelper;
19+
use Magento\Framework\App\ObjectManager;
1120
use Magento\Framework\Exception\InputException;
1221
use Magento\Framework\Exception\NoSuchEntityException;
1322
use Magento\Framework\Exception\StateException;
@@ -17,82 +26,82 @@
1726
*
1827
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1928
*/
20-
class LinkManagement implements \Magento\ConfigurableProduct\Api\LinkManagementInterface
29+
class LinkManagement implements LinkManagementInterface
2130
{
2231
/**
23-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
32+
* @var ProductRepositoryInterface
2433
*/
25-
private $productRepository;
34+
private ProductRepositoryInterface $productRepository;
2635

2736
/**
28-
* @var \Magento\Catalog\Api\Data\ProductInterfaceFactory
37+
* @var ProductInterfaceFactory
2938
*/
30-
private $productFactory;
39+
private ProductInterfaceFactory $productFactory;
3140

3241
/**
33-
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable
42+
* @var Configurable
3443
*/
35-
private $configurableType;
44+
private Configurable $configurableType;
3645

3746
/**
38-
* @var \Magento\Framework\Api\DataObjectHelper
47+
* @var DataObjectHelper
3948
*/
40-
private $dataObjectHelper;
49+
private DataObjectHelper $dataObjectHelper;
4150

4251
/**
43-
* @var \Magento\ConfigurableProduct\Helper\Product\Options\Factory;
52+
* @var Factory;
4453
*/
45-
private $optionsFactory;
54+
private Factory $optionsFactory;
4655

4756
/**
48-
* @var \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory
57+
* @var AttributeFactory
4958
*/
50-
private $attributeFactory;
59+
private AttributeFactory $attributeFactory;
5160

5261
/**
5362
* @var ProductRepository|mixed
5463
*/
55-
private \Magento\Catalog\Model\ProductRepository $mediaGallery;
64+
private ProductRepository $mediaGallery;
5665

5766
/**
5867
* @var ProductAttributeMediaGalleryEntryInterfaceFactory|mixed
5968
*/
60-
private \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory;
69+
private ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory;
6170

6271
/**
6372
* Constructor
6473
*
65-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
66-
* @param \Magento\Catalog\Api\Data\ProductInterfaceFactory $productFactory
67-
* @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurableType
68-
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
69-
* @param \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory
70-
* @param \Magento\Catalog\Model\ProductRepository $mediaGalleryProcessor
71-
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory
72-
* @param \Magento\ConfigurableProduct\Helper\Product\Options\Factory $optionsFactory
74+
* @param ProductRepositoryInterface $productRepository
75+
* @param ProductInterfaceFactory $productFactory
76+
* @param Configurable $configurableType
77+
* @param DataObjectHelper $dataObjectHelper
78+
* @param AttributeFactory|null $attributeFactory
79+
* @param ProductRepository|null $mediaGalleryProcessor
80+
* @param ProductAttributeMediaGalleryEntryInterfaceFactory|null $myModelFactory
81+
* @param Factory|null $optionsFactory
7382
*/
7483
public function __construct(
75-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
76-
\Magento\Catalog\Api\Data\ProductInterfaceFactory $productFactory,
77-
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurableType,
78-
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
79-
?\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory = null,
80-
?\Magento\Catalog\Model\ProductRepository $mediaGalleryProcessor = null,
81-
?\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory = null,
82-
?\Magento\ConfigurableProduct\Helper\Product\Options\Factory $optionsFactory = null
84+
ProductRepositoryInterface $productRepository,
85+
ProductInterfaceFactory $productFactory,
86+
Configurable $configurableType,
87+
DataObjectHelper $dataObjectHelper,
88+
?AttributeFactory $attributeFactory = null,
89+
?ProductRepository $mediaGalleryProcessor = null,
90+
?ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory = null,
91+
?Factory $optionsFactory = null
8392
) {
8493
$this->productRepository = $productRepository;
8594
$this->productFactory = $productFactory;
8695
$this->configurableType = $configurableType;
8796
$this->dataObjectHelper = $dataObjectHelper;
88-
$this->attributeFactory = $attributeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
89-
->get(\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory::class);
90-
$this->mediaGallery = $mediaGalleryProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
91-
->get(\Magento\Catalog\Model\ProductRepository::class);
92-
$this->myModelFactory = $myModelFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
93-
->get(\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory::class);
94-
$this->optionsFactory = $optionsFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
95-
->get(\Magento\ConfigurableProduct\Helper\Product\Options\Factory::class);
97+
$this->attributeFactory = $attributeFactory ?: ObjectManager::getInstance()
98+
->get(AttributeFactory::class);
99+
$this->mediaGallery = $mediaGalleryProcessor ?: ObjectManager::getInstance()
100+
->get(ProductRepository::class);
101+
$this->myModelFactory = $myModelFactory ?: ObjectManager::getInstance()
102+
->get(ProductAttributeMediaGalleryEntryInterfaceFactory::class);
103+
$this->optionsFactory = $optionsFactory ?: ObjectManager::getInstance()
104+
->get(Factory::class);
96105
}
97106

98107
/**
@@ -102,10 +111,10 @@ public function getChildren($sku)
102111
{
103112
/** @var \Magento\Catalog\Model\Product $product */
104113
$product = $this->productRepository->get($sku);
105-
if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
114+
if ($product->getTypeId() != Product\Type\Configurable::TYPE_CODE) {
106115
return [];
107116
}
108-
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productTypeInstance */
117+
/** @var Product\Type\Configurable $productTypeInstance */
109118
$productTypeInstance = $product->getTypeInstance();
110119
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
111120
$childrenList = [];
@@ -119,15 +128,12 @@ public function getChildren($sku)
119128
$attributes[$attrCode] = $value;
120129
}
121130
}
122-
$images= (array)$child->getMediaGallery('images');
123131
$attributes['store_id'] = $child->getStoreId();
124-
$attributes['media_gallery_entries'] = $this->getMediaEntries($images);
125-
/** @var \Magento\Catalog\Api\Data\ProductInterface $productDataObject */
126132
$productDataObject = $this->productFactory->create();
127133
$this->dataObjectHelper->populateWithArray(
128-
$productDataObject,
134+
$productDataObject->setMediaGalleryEntries($child->getMediaGalleryEntries()),
129135
$attributes,
130-
\Magento\Catalog\Api\Data\ProductInterface::class
136+
ProductInterface::class
131137
);
132138
$childrenList[] = $productDataObject;
133139
}
@@ -139,6 +145,8 @@ public function getChildren($sku)
139145
*
140146
* @param array $images
141147
* @return array
148+
* @deprecated This approach is designed only for images
149+
* @see ProductInterface::getMediaGalleryEntries
142150
*/
143151
public function getMediaEntries(array $images): array
144152
{
@@ -195,7 +203,7 @@ public function addChild($sku, $childSku)
195203
}
196204
$configurableOptionData = $this->getConfigurableAttributesData($attributeData);
197205

198-
/** @var \Magento\ConfigurableProduct\Helper\Product\Options\Factory $optionFactory */
206+
/** @var Factory $optionFactory */
199207
$optionFactory = $this->optionsFactory;
200208
$options = $optionFactory->create($configurableOptionData);
201209
$childrenIds[] = $child->getId();
@@ -216,7 +224,7 @@ public function removeChild($sku, $childSku)
216224
{
217225
$product = $this->productRepository->get($sku);
218226

219-
if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
227+
if ($product->getTypeId() != Product\Type\Configurable::TYPE_CODE) {
220228
throw new InputException(
221229
__('The product with the "%1" SKU isn\'t a configurable product.', $sku)
222230
);

app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -130,14 +130,16 @@ public function testGetChildren(): void
130130
$childProduct->expects($this->once())->method('getData')->with('code')->willReturn(10);
131131
$childProduct->expects($this->once())->method('getStoreId')->willReturn(1);
132132
$childProduct->expects($this->once())->method('getAttributes')->willReturn([$attribute]);
133+
$childProduct->expects($this->once())->method('getMediaGalleryEntries')->willReturn([]);
133134

134135
$productMock = $this->getMockForAbstractClass(ProductInterface::class);
136+
$productMock->expects($this->once())->method('setMediaGalleryEntries')->with([])->willReturnSelf();
135137

136138
$this->dataObjectHelperMock->expects($this->once())
137139
->method('populateWithArray')
138140
->with(
139141
$productMock,
140-
['store_id' => 1, 'code' => 10, 'media_gallery_entries' => []],
142+
['store_id' => 1, 'code' => 10],
141143
ProductInterface::class
142144
)->willReturnSelf();
143145

app/code/Magento/ProductVideo/Model/Product/Attribute/Media/ExternalVideoEntryConverter.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\ProductVideo\Model\Product\Attribute\Media;
@@ -19,7 +19,7 @@ class ExternalVideoEntryConverter extends ImageEntryConverter
1919
/**
2020
* Media Entry type code
2121
*/
22-
const MEDIA_TYPE_CODE = 'external-video';
22+
public const MEDIA_TYPE_CODE = 'external-video';
2323

2424
/**
2525
* @var \Magento\Framework\Api\Data\VideoContentInterfaceFactory
@@ -49,6 +49,8 @@ public function __construct(
4949
}
5050

5151
/**
52+
* Return video entry type
53+
*
5254
* @return string
5355
*/
5456
public function getMediaEntryType()
@@ -57,6 +59,8 @@ public function getMediaEntryType()
5759
}
5860

5961
/**
62+
* Convert raw data to media gallery video entry
63+
*
6064
* @param Product $product
6165
* @param array $rowData
6266
* @return ProductAttributeMediaGalleryEntryInterface
@@ -77,20 +81,23 @@ public function convertTo(Product $product, array $rowData)
7781
}
7882

7983
/**
80-
* {@inheritdoc}
84+
* @inheritdoc
8185
*/
8286
public function convertFrom(ProductAttributeMediaGalleryEntryInterface $entry)
8387
{
8488
$dataFromPreviewImageEntry = parent::convertFrom($entry);
85-
$videoContent = $entry->getExtensionAttributes()->getVideoContent();
86-
$entryArray = [
87-
'video_provider' => $videoContent->getVideoProvider(),
88-
'video_url' => $videoContent->getVideoUrl(),
89-
'video_title' => $videoContent->getVideoTitle(),
90-
'video_description' => $videoContent->getVideoDescription(),
91-
'video_metadata' => $videoContent->getVideoMetadata(),
92-
];
93-
$entryArray = array_merge($dataFromPreviewImageEntry, $entryArray);
89+
if ($videoContent = $entry->getExtensionAttributes()->getVideoContent()) {
90+
$entryArray = [
91+
'video_provider' => $videoContent->getVideoProvider(),
92+
'video_url' => $videoContent->getVideoUrl(),
93+
'video_title' => $videoContent->getVideoTitle(),
94+
'video_description' => $videoContent->getVideoDescription(),
95+
'video_metadata' => $videoContent->getVideoMetadata(),
96+
];
97+
$entryArray = array_merge($dataFromPreviewImageEntry, $entryArray);
98+
} else {
99+
$entryArray = $dataFromPreviewImageEntry;
100+
}
94101
return $entryArray;
95102
}
96103
}

0 commit comments

Comments
 (0)