Skip to content

Commit a0a4063

Browse files
ACP2E-561 updated conditions to add image value in csv column while exporting
1 parent 10f16d1 commit a0a4063

File tree

4 files changed

+173
-30
lines changed

4 files changed

+173
-30
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,33 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
3838
/**
3939
* Value that means all entities (e.g. websites, groups etc.)
4040
*/
41-
const VALUE_ALL = 'all';
41+
public const VALUE_ALL = 'all';
4242

4343
/**
4444
* Permanent column names.
4545
*
4646
* Names that begins with underscore is not an attribute. This name convention is for
4747
* to avoid interference with same attribute name.
4848
*/
49-
const COL_STORE = '_store';
49+
public const COL_STORE = '_store';
5050

51-
const COL_ATTR_SET = '_attribute_set';
51+
public const COL_ATTR_SET = '_attribute_set';
5252

53-
const COL_TYPE = '_type';
53+
public const COL_TYPE = '_type';
5454

55-
const COL_PRODUCT_WEBSITES = '_product_websites';
55+
public const COL_PRODUCT_WEBSITES = '_product_websites';
5656

57-
const COL_CATEGORY = '_category';
57+
public const COL_CATEGORY = '_category';
5858

59-
const COL_ROOT_CATEGORY = '_root_category';
59+
public const COL_ROOT_CATEGORY = '_root_category';
6060

61-
const COL_SKU = 'sku';
61+
public const COL_SKU = 'sku';
6262

63-
const COL_VISIBILITY = 'visibility';
63+
public const COL_VISIBILITY = 'visibility';
6464

65-
const COL_MEDIA_IMAGE = '_media_image';
65+
public const COL_MEDIA_IMAGE = '_media_image';
6666

67-
const COL_ADDITIONAL_ATTRIBUTES = 'additional_attributes';
67+
public const COL_ADDITIONAL_ATTRIBUTES = 'additional_attributes';
6868

6969
/**
7070
* Pairs of attribute set ID-to-name.
@@ -284,6 +284,18 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
284284
'custom_design_to'
285285
];
286286

287+
/**
288+
* Image labels array
289+
*
290+
* @var array
291+
*/
292+
protected $imageLabelAttributes = [
293+
'base_image_label',
294+
'small_image_label',
295+
'thumbnail_image_label',
296+
'swatch_image_label',
297+
];
298+
287299
/**
288300
* Attributes codes which are appropriate for export and not the part of additional_attributes.
289301
*
@@ -828,12 +840,12 @@ protected function getItemsPerPage()
828840
switch ($lastMemoryLimitLetter) {
829841
case 'g':
830842
$memoryLimit *= 1024;
831-
// fall-through intentional
832-
// no break
843+
// fall-through intentional
844+
// no break
833845
case 'm':
834846
$memoryLimit *= 1024;
835-
// fall-through intentional
836-
// no break
847+
// fall-through intentional
848+
// no break
837849
case 'k':
838850
$memoryLimit *= 1024;
839851
break;
@@ -962,6 +974,7 @@ protected function getExportData()
962974
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
963975
$dataRow = array_merge($dataRow, $stockItemRows[$productId]);
964976
}
977+
$this->updateGalleryImageData($dataRow, $rawData);
965978
$this->appendMultirowData($dataRow, $multirawData);
966979
if ($dataRow) {
967980
$exportData[] = $dataRow;
@@ -1370,6 +1383,28 @@ private function appendMultirowData(&$dataRow, $multiRawData)
13701383
return $dataRow;
13711384
}
13721385

1386+
/**
1387+
* Add image column if image label exists for all scope
1388+
*
1389+
* @param $dataRow
1390+
* @param $rawData
1391+
*/
1392+
private function updateGalleryImageData(&$dataRow, $rawData)
1393+
{
1394+
$storeId = $dataRow['store_id'];
1395+
$productId = $dataRow['product_id'];
1396+
foreach ($this->imageLabelAttributes as $imageLabelCode) {
1397+
$imageAttributeCode = str_replace('_label', '', $imageLabelCode);
1398+
if ($storeId != Store::DEFAULT_STORE_ID
1399+
&& isset($dataRow[$imageLabelCode])
1400+
&& $dataRow[$imageLabelCode]
1401+
&& (!isset($dataRow[$imageAttributeCode]) || !$dataRow[$imageAttributeCode])
1402+
) {
1403+
$dataRow[$imageAttributeCode] = $rawData[$productId][Store::DEFAULT_STORE_ID][$imageAttributeCode];
1404+
}
1405+
}
1406+
}
1407+
13731408
/**
13741409
* Add multi row data to export
13751410
*

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,6 @@ public function getImagesFromRow(array $rowData)
15411541
$labels[$column] = array_slice($labels[$column], 0, count($images[$column]));
15421542
}
15431543
}
1544-
} elseif (!empty($rowData[$column . '_label'])) {
1545-
$labels[$column] = $this->parseMultipleValues($rowData[$column . '_label']);
15461544
}
15471545
}
15481546

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminExportSimpleProductWithImageAndImageAltForDiffrentScopeTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Admin product export with different Alt Text for multiple stores"/>
15+
<title value="Admin product export with different Alt Text for multiple stores"/>
16+
<description value="Admin product export with different Alt Text for multiple stores"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="ACP2E-561"/>
19+
<group value="catalog_import_export"/>
20+
</annotations>
21+
<before>
22+
<!-- Login Admin -->
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
<!-- Create Store View English -->
25+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createStoreViewEn">
26+
<argument name="customStore" value="customStoreEN"/>
27+
</actionGroup>
28+
<!-- Create Store View France -->
29+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createStoreViewFr">
30+
<argument name="customStore" value="customStoreFR"/>
31+
</actionGroup>
32+
<!-- Create Category and Simple Product -->
33+
<createData entity="_defaultCategory" stepKey="createCategory"/>
34+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
35+
<requiredEntity createDataKey="createCategory"/>
36+
<field key="price">100</field>
37+
</createData>
38+
<!-- Upload Image All Store View -->
39+
<createData entity="ApiProductAttributeMediaGalleryEntryTestImage" stepKey="createProductImage">
40+
<requiredEntity createDataKey="createSimpleProduct"/>
41+
</createData>
42+
</before>
43+
<after>
44+
<!-- Delete Store View English -->
45+
<actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteStoreViewEn">
46+
<argument name="customStore" value="customStoreEN"/>
47+
</actionGroup>
48+
<!-- Delete Store View France -->
49+
<actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteStoreViewFr">
50+
<argument name="customStore" value="customStoreFR"/>
51+
</actionGroup>
52+
<!-- Clear Filter Store -->
53+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="resetFiltersOnStorePage"/>
54+
<!-- Delete Category and Simple Product -->
55+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
56+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
57+
<!-- Clear Filter Product -->
58+
<actionGroup ref="AdminClearFiltersActionGroup" stepKey="clearProductFilters"/>
59+
<!-- Logout Admin -->
60+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/>
61+
</after>
62+
<!-- Search Product and Open Edit -->
63+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchProduct">
64+
<argument name="product" value="$$createSimpleProduct$$"/>
65+
</actionGroup>
66+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
67+
<argument name="product" value="$$createSimpleProduct$$"/>
68+
</actionGroup>
69+
<actionGroup ref="AdminAssignImageRolesActionGroup" stepKey="assignImageRole">
70+
<argument name="image" value="$$createProductImage$$"/>
71+
</actionGroup>
72+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
73+
74+
<!-- Switch to the English store view -->
75+
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="switchStoreViewEnglishProduct">
76+
<argument name="storeView" value="customStoreEN.name"/>
77+
</actionGroup>
78+
<actionGroup ref="AdminProductChangeImageAltTextActionGroup" stepKey="changeEnglishImageAltTextOnProduct">
79+
<argument name="image" value="$$createProductImage$$"/>
80+
<argument name="altText" value="english image alt text 1"/>
81+
</actionGroup>
82+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct1"/>
83+
84+
<!-- Switch to the French store view -->
85+
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="switchStoreViewFrenchProduct">
86+
<argument name="storeView" value="customStoreFR.name"/>
87+
</actionGroup>
88+
<actionGroup ref="AdminProductChangeImageAltTextActionGroup" stepKey="changeFrenchImageAltTextOnProduct">
89+
<argument name="image" value="$$createProductImage$$"/>
90+
<argument name="altText" value="french image alt text 1"/>
91+
</actionGroup>
92+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct2"/>
93+
94+
<actionGroup ref="AdminNavigateToExportPageActionGroup" stepKey="goToExportIndexPage"/>
95+
<actionGroup ref="ExportProductsFilterByAttributeActionGroup" stepKey="exportProductBySku">
96+
<argument name="attribute" value="sku"/>
97+
<argument name="attributeData" value="$$createSimpleProduct.sku$$"/>
98+
</actionGroup>
99+
<actionGroup ref="CliConsumerStartActionGroup" stepKey="startMessageQueue">
100+
<argument name="consumerName" value="{{AdminExportMessageConsumerData.consumerName}}"/>
101+
<argument name="maxMessages" value="{{AdminExportMessageConsumerData.messageLimit}}"/>
102+
</actionGroup>
103+
<reloadPage stepKey="refreshPage"/>
104+
<waitForPageLoad stepKey="waitForReload"/>
105+
<waitForElementVisible selector="{{AdminExportAttributeSection.exportFileNameByPosition('0')}}" stepKey="waitForFileName"/>
106+
<grabTextFrom selector="{{AdminExportAttributeSection.exportFileNameByPosition('0')}}" stepKey="getFilename"/>
107+
<actionGroup ref="AdminGetExportFilenameOnServerActionGroup" stepKey="grabNameFile">
108+
<argument name="rowIndex" value="0"/>
109+
</actionGroup>
110+
<!-- Validate Export File on File System: Configurable Product -->
111+
<helper class="Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileExists" stepKey="assertExportFileExists">
112+
<argument name="filePath">var/export/{$grabNameFile}</argument>
113+
</helper>
114+
<helper class="Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileContainsString" stepKey="assertExportFileContainsConfigurableProduct">
115+
<argument name="filePath">var/export/{$grabNameFile}</argument>
116+
<argument name="text">$createProductImage.entry[content][name]$,"english image alt text 1"</argument>
117+
</helper>
118+
<helper class="Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileContainsString" stepKey="assertExportFileContainsConfigurableProduct1">
119+
<argument name="filePath">var/export/{$grabNameFile}</argument>
120+
<argument name="text">$createProductImage.entry[content][name]$,"french image alt text 1"</argument>
121+
</helper>
122+
</test>
123+
</tests>

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,19 +1704,6 @@ public function getImagesFromRowDataProvider(): array
17041704
'_media_image' => ['label1', 'label2']
17051705
]
17061706
]
1707-
],
1708-
[
1709-
[
1710-
'image' => '',
1711-
'_media_image' => '',
1712-
'_media_image_label' => 'label1,label2'
1713-
],
1714-
[
1715-
[],
1716-
[
1717-
'_media_image' => ['label1', 'label2']
1718-
]
1719-
]
17201707
]
17211708
];
17221709
}

0 commit comments

Comments
 (0)