Skip to content

Commit 1adcc4a

Browse files
author
Gabriel Galvao da Gama
committed
Merge remote-tracking branch 'magento-engcom/ENGCOM-7987-magento-magento2-29435' into 2.4-develop-prs
2 parents 6d2ab95 + 4793e47 commit 1adcc4a

File tree

5 files changed

+64
-15
lines changed

5 files changed

+64
-15
lines changed

app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/ActionGroup/AdminAssertCategoryGridPageDetailsActionGroup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<description>Assert category grid page basic columns values for default category</description>
1313
</annotations>
1414

15+
<seeElement selector="{{AdminMediaGalleryCatalogUiCategoryGridSection.image('1','image')}}" stepKey="assertImageColumn"/>
1516
<seeElement selector="{{AdminMediaGalleryCatalogUiCategoryGridSection.path('1')}}" stepKey="assertPathColumn"/>
1617
<seeElement selector="{{AdminMediaGalleryCatalogUiCategoryGridSection.name('1', 'Default Category')}}" stepKey="assertNameColumn"/>
1718
<seeElement selector="{{AdminMediaGalleryCatalogUiCategoryGridSection.displayMode('1', 'PRODUCTS')}}" stepKey="assertDisplayModeColumn"/>

app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Section/AdminMediaGalleryCatalogUiCategoryGridSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="AdminMediaGalleryCatalogUiCategoryGridSection">
1212
<element name="activeFilterPlaceholder" type="text" selector="//div[@class='admin__current-filters-list-wrap']//li//span[contains(text(), '{{filterPlaceholder}}')]" parameterized="true"/>
13+
<element name="image" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Image')]/preceding-sibling::th) +1]//img[contains(@src, '{{imageName}}')]" parameterized="true"/>
1314
<element name="path" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Path')]/preceding-sibling::th)]" parameterized="true"/>
1415
<element name="name" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Name')]/preceding-sibling::th) +1 ]//*[text()='{{categoryName}}']" parameterized="true"/>
1516
<element name="displayMode" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Display Mode')]/preceding-sibling::th) +1 ]//*[text()='{{productsText}}']" parameterized="true"/>

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

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66
namespace Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Columns;
77

8-
use Magento\Catalog\Helper\Image;
9-
use Magento\Framework\DataObject;
8+
use Magento\Catalog\Model\Category\Image;
9+
use Magento\Catalog\Model\CategoryRepository;
10+
use Magento\Framework\View\Asset\Repository as AssetRepository;
1011
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1112
use Magento\Framework\View\Element\UiComponentFactory;
1213
use Magento\Store\Model\Store;
@@ -27,48 +28,87 @@ class Thumbnail extends Column
2728
/**
2829
* @var Image
2930
*/
30-
private $imageHelper;
31+
private $categoryImage;
3132

3233
/**
34+
* @var CategoryRepository
35+
*/
36+
private $categoryRepository;
37+
38+
/**
39+
* @var AssetRepository
40+
*/
41+
private $assetRepository;
42+
43+
/**
44+
* @var string[]
45+
*/
46+
private $defaultPlaceholder;
47+
48+
/**
49+
* Thumbnail constructor.
3350
* @param ContextInterface $context
3451
* @param UiComponentFactory $uiComponentFactory
3552
* @param StoreManagerInterface $storeManager
36-
* @param Image $image
53+
* @param Image $categoryImage
54+
* @param CategoryRepository $categoryRepository
55+
* @param AssetRepository $assetRepository
56+
* @param array $defaultPlaceholder
3757
* @param array $components
3858
* @param array $data
3959
*/
4060
public function __construct(
4161
ContextInterface $context,
4262
UiComponentFactory $uiComponentFactory,
4363
StoreManagerInterface $storeManager,
44-
Image $image,
64+
Image $categoryImage,
65+
CategoryRepository $categoryRepository,
66+
AssetRepository $assetRepository,
67+
array $defaultPlaceholder = [],
4568
array $components = [],
4669
array $data = []
4770
) {
4871
parent::__construct($context, $uiComponentFactory, $components, $data);
49-
$this->imageHelper = $image;
5072
$this->storeManager = $storeManager;
73+
$this->categoryImage = $categoryImage;
74+
$this->categoryRepository = $categoryRepository;
75+
$this->assetRepository = $assetRepository;
76+
$this->defaultPlaceholder = $defaultPlaceholder;
5177
}
5278

5379
/**
5480
* Prepare Data Source
5581
*
5682
* @param array $dataSource
5783
* @return array
84+
* @throws \Magento\Framework\Exception\LocalizedException
85+
* @throws \Magento\Framework\Exception\NoSuchEntityException
5886
*/
5987
public function prepareDataSource(array $dataSource)
6088
{
61-
if (isset($dataSource['data']['items'])) {
62-
$fieldName = $this->getData('name');
63-
foreach ($dataSource['data']['items'] as & $item) {
64-
if (isset($item[$fieldName])) {
65-
$item[$fieldName . '_src'] = $this->getUrl($item[$fieldName]);
66-
} else {
67-
$category = new DataObject($item);
68-
$imageHelper = $this->imageHelper->init($category, 'product_listing_thumbnail');
69-
$item[$fieldName . '_src'] = $imageHelper->getUrl();
89+
if (!isset($dataSource['data']['items'])) {
90+
return $dataSource;
91+
}
92+
93+
$fieldName = $this->getData('name');
94+
foreach ($dataSource['data']['items'] as & $item) {
95+
if (isset($item[$fieldName])) {
96+
$item[$fieldName . '_src'] = $this->getUrl($item[$fieldName]);
97+
continue;
98+
}
99+
100+
if (isset($item['entity_id'])) {
101+
$src = $this->categoryImage->getUrl(
102+
$this->categoryRepository->get($item['entity_id'])
103+
);
104+
105+
if (!empty($src)) {
106+
$item[$fieldName . '_src'] = $src;
107+
continue;
70108
}
71109
}
110+
111+
$item[$fieldName . '_src'] = $this->assetRepository->getUrl($this->defaultPlaceholder['image']);
72112
}
73113

74114
return $dataSource;

app/code/Magento/MediaGalleryCatalogUi/etc/adminhtml/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@
3838
</argument>
3939
</arguments>
4040
</type>
41+
<type name="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Columns\Thumbnail">
42+
<arguments>
43+
<argument name="defaultPlaceholder" xsi:type="array">
44+
<item name="image" xsi:type="string">Magento_MediaGalleryCatalogUi::images/category/placeholder/image.jpg</item>
45+
</argument>
46+
</arguments>
47+
</type>
4148
</config>
Loading

0 commit comments

Comments
 (0)