Skip to content

Commit 41b798e

Browse files
committed
Merge remote-tracking branch '37862/37607-REST-Configurable-Products-sku-childrenendpoint-missing-media_gallery_entries' into comm_247beta3
2 parents 7d9f152 + 964aac0 commit 41b798e

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

app/code/Magento/Catalog/Ui/Component/Listing/Columns/Thumbnail.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1010

1111
/**
12-
* Class Thumbnail
12+
* Class prepares Thumbnail
1313
*
1414
* @api
1515
* @since 100.0.2
1616
*/
1717
class Thumbnail extends \Magento\Ui\Component\Listing\Columns\Column
1818
{
19-
const NAME = 'thumbnail';
19+
public const NAME = 'thumbnail';
2020

21-
const ALT_FIELD = 'name';
21+
public const ALT_FIELD = 'name';
2222

2323
/**
2424
* @var \Magento\Catalog\Helper\Image
@@ -77,7 +77,6 @@ public function prepareDataSource(array $dataSource)
7777

7878
return $dataSource;
7979
}
80-
8180
/**
8281
* Get Alt
8382
*
@@ -88,6 +87,7 @@ public function prepareDataSource(array $dataSource)
8887
protected function getAlt($row)
8988
{
9089
$altField = $this->getData('config/altField') ?: self::ALT_FIELD;
91-
return $row[$altField] ?? null;
90+
// phpcs:disable Magento2.Functions.DiscouragedFunction
91+
return html_entity_decode($row[$altField], ENT_QUOTES, "UTF-8") ?? null;
9292
}
9393
}

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

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\ConfigurableProduct\Model;
88

9+
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory;
10+
use Magento\Catalog\Model\ProductRepository;
911
use Magento\Framework\Exception\InputException;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Framework\Exception\StateException;
@@ -47,6 +49,16 @@ class LinkManagement implements \Magento\ConfigurableProduct\Api\LinkManagementI
4749
*/
4850
private $attributeFactory;
4951

52+
/**
53+
* @var ProductRepository|mixed
54+
*/
55+
public \Magento\Catalog\Model\ProductRepository $mediaGallery;
56+
57+
/**
58+
* @var ProductAttributeMediaGalleryEntryInterfaceFactory|mixed
59+
*/
60+
public \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory;
61+
5062
/**
5163
* Constructor
5264
*
@@ -55,20 +67,28 @@ class LinkManagement implements \Magento\ConfigurableProduct\Api\LinkManagementI
5567
* @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurableType
5668
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
5769
* @param \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory
70+
* @param \Magento\Catalog\Model\ProductRepository $mediaGalleryProcessor
71+
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory
5872
*/
5973
public function __construct(
6074
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
6175
\Magento\Catalog\Api\Data\ProductInterfaceFactory $productFactory,
6276
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurableType,
6377
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
64-
\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory = null
78+
\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory = null,
79+
\Magento\Catalog\Model\ProductRepository $mediaGalleryProcessor = null,
80+
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $myModelFactory = null
6581
) {
6682
$this->productRepository = $productRepository;
6783
$this->productFactory = $productFactory;
6884
$this->configurableType = $configurableType;
6985
$this->dataObjectHelper = $dataObjectHelper;
7086
$this->attributeFactory = $attributeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
7187
->get(\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory::class);
88+
$this->mediaGallery = $mediaGalleryProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
89+
->get(\Magento\Catalog\Model\ProductRepository::class);
90+
$this->myModelFactory = $myModelFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
91+
->get(\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory::class);
7292
}
7393

7494
/**
@@ -81,11 +101,9 @@ public function getChildren($sku)
81101
if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
82102
return [];
83103
}
84-
85104
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productTypeInstance */
86105
$productTypeInstance = $product->getTypeInstance();
87106
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
88-
89107
$childrenList = [];
90108
/** @var \Magento\Catalog\Model\Product $child */
91109
foreach ($productTypeInstance->getUsedProducts($product) as $child) {
@@ -97,7 +115,9 @@ public function getChildren($sku)
97115
$attributes[$attrCode] = $value;
98116
}
99117
}
118+
$images= (array)$child->getMediaGallery('images');
100119
$attributes['store_id'] = $child->getStoreId();
120+
$attributes['media_gallery_entries'] = $this->getMediaEntries($images);
101121
/** @var \Magento\Catalog\Api\Data\ProductInterface $productDataObject */
102122
$productDataObject = $this->productFactory->create();
103123
$this->dataObjectHelper->populateWithArray(
@@ -110,6 +130,28 @@ public function getChildren($sku)
110130
return $childrenList;
111131
}
112132

133+
/**
134+
* Get media entries
135+
*
136+
* @param array $images
137+
* @return array
138+
*/
139+
public function getMediaEntries($images)
140+
{
141+
$media = $this->myModelFactory->create();
142+
$mediaGalleryEntries=[];
143+
foreach ($images as $image) {
144+
$media->setId($image["value_id"]);
145+
$media->setMediaType($image["media_type"]);
146+
$media->setLabel($image["label"]);
147+
$media->setPosition($image["position"]);
148+
$media->setDisabled($image["disabled"]);
149+
$media->setFile($image["file"]);
150+
$mediaGalleryEntries[]=$media->getData();
151+
}
152+
return $mediaGalleryEntries;
153+
}
154+
113155
/**
114156
* @inheritdoc
115157
* @throws InputException
@@ -200,12 +242,13 @@ public function removeChild($sku, $childSku)
200242
* @return \Magento\ConfigurableProduct\Helper\Product\Options\Factory
201243
*
202244
* @deprecated 100.2.0
245+
* @see Nothing
203246
*/
204247
private function getOptionsFactory()
205248
{
206249
if (!$this->optionsFactory) {
207250
$this->optionsFactory = \Magento\Framework\App\ObjectManager::getInstance()
208-
->get(\Magento\ConfigurableProduct\Helper\Product\Options\Factory::class);
251+
->get(\Magento\ConfigurableProduct\Helper\Product\Options\Factory::class);// phpcs:ignore
209252
}
210253
return $this->optionsFactory;
211254
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ public function testGetChildren(): void
135135

136136
$this->dataObjectHelperMock->expects($this->once())
137137
->method('populateWithArray')
138-
->with($productMock, ['store_id' => 1, 'code' => 10], ProductInterface::class)
139-
->willReturnSelf();
138+
->with(
139+
$productMock,
140+
['store_id' => 1, 'code' => 10, 'media_gallery_entries' => []],
141+
ProductInterface::class
142+
)->willReturnSelf();
140143

141144
$this->productFactory->expects($this->once())
142145
->method('create')

0 commit comments

Comments
 (0)