Skip to content

Commit 51c55ae

Browse files
committed
ACP2E-3965: [Mainline] Configurable product with video causes API error
1 parent 4f82be7 commit 51c55ae

File tree

2 files changed

+62
-87
lines changed

2 files changed

+62
-87
lines changed

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

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

77
namespace Magento\ConfigurableProduct\Model;
88

9-
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory;
9+
use Magento\Catalog\Api\Data\ProductInterface;
10+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
1012
use Magento\Catalog\Model\ProductRepository;
13+
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
14+
use Magento\ConfigurableProduct\Api\LinkManagementInterface;
15+
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
16+
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;
17+
use Magento\Framework\Api\DataObjectHelper;
1118
use Magento\Framework\Exception\InputException;
1219
use Magento\Framework\Exception\NoSuchEntityException;
1320
use Magento\Framework\Exception\StateException;
1421

1522
/**
1623
* Configurable product link management.
1724
*
18-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1925
*/
20-
class LinkManagement implements \Magento\ConfigurableProduct\Api\LinkManagementInterface
26+
class LinkManagement implements LinkManagementInterface
2127
{
2228
/**
23-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
29+
* @var ProductRepositoryInterface
2430
*/
25-
private $productRepository;
31+
private ProductRepositoryInterface $productRepository;
2632

2733
/**
28-
* @var \Magento\Catalog\Api\Data\ProductInterfaceFactory
34+
* @var ProductInterfaceFactory
2935
*/
30-
private $productFactory;
36+
private ProductInterfaceFactory $productFactory;
3137

3238
/**
33-
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable
39+
* @var Configurable
3440
*/
35-
private $configurableType;
41+
private Configurable $configurableType;
3642

3743
/**
38-
* @var \Magento\Framework\Api\DataObjectHelper
44+
* @var DataObjectHelper
3945
*/
40-
private $dataObjectHelper;
46+
private DataObjectHelper $dataObjectHelper;
4147

4248
/**
43-
* @var \Magento\ConfigurableProduct\Helper\Product\Options\Factory;
49+
* @var Factory;
4450
*/
45-
private $optionsFactory;
51+
private Factory $optionsFactory;
4652

4753
/**
48-
* @var \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory
54+
* @var AttributeFactory
4955
*/
50-
private $attributeFactory;
56+
private AttributeFactory $attributeFactory;
5157

5258
/**
5359
* @var ProductRepository|mixed
5460
*/
55-
private \Magento\Catalog\Model\ProductRepository $mediaGallery;
56-
57-
/**
58-
* @var ProductAttributeMediaGalleryEntryInterfaceFactory|mixed
59-
*/
60-
private \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory;
61+
private ProductRepository $mediaGallery;
6162

6263
/**
6364
* Constructor
6465
*
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
66+
* @param ProductRepositoryInterface $productRepository
67+
* @param ProductInterfaceFactory $productFactory
68+
* @param Configurable $configurableType
69+
* @param DataObjectHelper $dataObjectHelper
70+
* @param AttributeFactory|null $attributeFactory
71+
* @param ProductRepository|null $mediaGalleryProcessor
72+
* @param Factory|null $optionsFactory
7373
*/
7474
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
75+
ProductRepositoryInterface $productRepository,
76+
ProductInterfaceFactory $productFactory,
77+
Configurable $configurableType,
78+
DataObjectHelper $dataObjectHelper,
79+
?AttributeFactory $attributeFactory = null,
80+
?ProductRepository $mediaGalleryProcessor = null,
81+
?Factory $optionsFactory = null
8382
) {
8483
$this->productRepository = $productRepository;
8584
$this->productFactory = $productFactory;
8685
$this->configurableType = $configurableType;
8786
$this->dataObjectHelper = $dataObjectHelper;
8887
$this->attributeFactory = $attributeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
89-
->get(\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory::class);
88+
->get(AttributeFactory::class);
9089
$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);
90+
->get(ProductRepository::class);
9491
$this->optionsFactory = $optionsFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
95-
->get(\Magento\ConfigurableProduct\Helper\Product\Options\Factory::class);
92+
->get(Factory::class);
9693
}
9794

9895
/**
@@ -102,10 +99,10 @@ public function getChildren($sku)
10299
{
103100
/** @var \Magento\Catalog\Model\Product $product */
104101
$product = $this->productRepository->get($sku);
105-
if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
102+
if ($product->getTypeId() != Product\Type\Configurable::TYPE_CODE) {
106103
return [];
107104
}
108-
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productTypeInstance */
105+
/** @var Product\Type\Configurable $productTypeInstance */
109106
$productTypeInstance = $product->getTypeInstance();
110107
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
111108
$childrenList = [];
@@ -119,43 +116,18 @@ public function getChildren($sku)
119116
$attributes[$attrCode] = $value;
120117
}
121118
}
122-
$images= (array)$child->getMediaGallery('images');
123119
$attributes['store_id'] = $child->getStoreId();
124-
$attributes['media_gallery_entries'] = $this->getMediaEntries($images);
125-
/** @var \Magento\Catalog\Api\Data\ProductInterface $productDataObject */
126120
$productDataObject = $this->productFactory->create();
127121
$this->dataObjectHelper->populateWithArray(
128-
$productDataObject,
122+
$productDataObject->setMediaGalleryEntries($child->getMediaGalleryEntries()),
129123
$attributes,
130-
\Magento\Catalog\Api\Data\ProductInterface::class
124+
ProductInterface::class
131125
);
132126
$childrenList[] = $productDataObject;
133127
}
134128
return $childrenList;
135129
}
136130

137-
/**
138-
* Get media entries
139-
*
140-
* @param array $images
141-
* @return array
142-
*/
143-
public function getMediaEntries(array $images): array
144-
{
145-
$media = $this->myModelFactory->create();
146-
$mediaGalleryEntries=[];
147-
foreach ($images as $image) {
148-
$media->setId($image["value_id"]);
149-
$media->setMediaType($image["media_type"]);
150-
$media->setLabel($image["label"]);
151-
$media->setPosition($image["position"]);
152-
$media->setDisabled($image["disabled"]);
153-
$media->setFile($image["file"]);
154-
$mediaGalleryEntries[]=$media->getData();
155-
}
156-
return $mediaGalleryEntries;
157-
}
158-
159131
/**
160132
* @inheritdoc
161133
* @throws InputException
@@ -195,7 +167,7 @@ public function addChild($sku, $childSku)
195167
}
196168
$configurableOptionData = $this->getConfigurableAttributesData($attributeData);
197169

198-
/** @var \Magento\ConfigurableProduct\Helper\Product\Options\Factory $optionFactory */
170+
/** @var Factory $optionFactory */
199171
$optionFactory = $this->optionsFactory;
200172
$options = $optionFactory->create($configurableOptionData);
201173
$childrenIds[] = $child->getId();
@@ -216,7 +188,7 @@ public function removeChild($sku, $childSku)
216188
{
217189
$product = $this->productRepository->get($sku);
218190

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

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

Lines changed: 15 additions & 12 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 2025 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
@@ -82,15 +82,18 @@ public function convertTo(Product $product, array $rowData)
8282
public function convertFrom(ProductAttributeMediaGalleryEntryInterface $entry)
8383
{
8484
$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);
85+
if ($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);
94+
} else {
95+
$entryArray = $dataFromPreviewImageEntry;
96+
}
9497
return $entryArray;
9598
}
9699
}

0 commit comments

Comments
 (0)