Skip to content

Commit 82caf48

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1793 from magento-engcom/2.2-develop-prs
Public Pull Requests #12207 11882: It's not possible to enable "log to file" (debugging) in production mode. Psr logger debug method does not work by the default in developer mode. by @nmalevanec #11926 8255: Export Products action doesn't consider hide_for_product_page value. by @nmalevanec #11485 do the stock check on default level because the stock on website leve… by @joost-florijn-kega #11388 Fix #11236: Web Setup Wizard Icon Inconsistency by @dverkade #11323 Defaulting missing alt-text for a product to use the product name. by @brobie Fixed Public Issues #11509 Psr logger debug method does not work by the default in developer mode #11882 It's not possible to enable "log to file" (debugging) in production mode #8255 Export Products action doesn't consider hide_for_product_page value #11484 Visual Merchandiser show prices of out of stock simple products for the associated configurable product. #11236 Web Setup Wizard Icon Inconsistency #9931 Empty image alt-text & missing alt attribute on product detail page
2 parents b4bbe21 + 9bc20c4 commit 82caf48

File tree

28 files changed

+901
-242
lines changed

28 files changed

+901
-242
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
146146
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
147147
</argument>
148+
<argument name="exemptions" xsi:type="array">
149+
<item name="dev/debug/debug_logging" xsi:type="string"/>
150+
</argument>
148151
</arguments>
149152
</type>
150153
<type name="Magento\Framework\View\Layout\Generator\Block">

app/code/Magento/Catalog/Block/Product/View/Gallery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getGalleryImagesJson()
116116
'thumb' => $image->getData('small_image_url'),
117117
'img' => $image->getData('medium_image_url'),
118118
'full' => $image->getData('large_image_url'),
119-
'caption' => $image->getLabel(),
119+
'caption' => ($image->getLabel() ?: $this->getProduct()->getName()),
120120
'position' => $image->getPosition(),
121121
'isMain' => $this->isMainImage($image),
122122
'type' => str_replace('external-', '', $image->getMediaType()),

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,19 @@ public function execute($product, $arguments = [])
167167
if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) {
168168
continue;
169169
}
170-
if (in_array($attrData, $clearImages)) {
171-
$product->setData($mediaAttrCode, 'no_selection');
172-
}
173-
174-
if (in_array($attrData, array_keys($newImages))) {
175-
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
176-
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
177-
}
178-
179-
if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
180-
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
181-
}
182-
if (!empty($product->getData($mediaAttrCode))) {
183-
$product->addAttributeUpdate(
170+
$this->processMediaAttribute(
171+
$product,
172+
$mediaAttrCode,
173+
$clearImages,
174+
$newImages
175+
);
176+
if (in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail'])) {
177+
$this->processMediaAttributeLabel(
178+
$product,
184179
$mediaAttrCode,
185-
$product->getData($mediaAttrCode),
186-
$product->getStoreId()
180+
$clearImages,
181+
$newImages,
182+
$existImages
187183
);
188184
}
189185
}
@@ -448,4 +444,77 @@ private function getMediaAttributeCodes()
448444
}
449445
return $this->mediaAttributeCodes;
450446
}
447+
448+
/**
449+
* @param \Magento\Catalog\Model\Product $product
450+
* @param $mediaAttrCode
451+
* @param array $clearImages
452+
* @param array $newImages
453+
*/
454+
private function processMediaAttribute(
455+
\Magento\Catalog\Model\Product $product,
456+
$mediaAttrCode,
457+
array $clearImages,
458+
array $newImages
459+
) {
460+
$attrData = $product->getData($mediaAttrCode);
461+
if (in_array($attrData, $clearImages)) {
462+
$product->setData($mediaAttrCode, 'no_selection');
463+
}
464+
465+
if (in_array($attrData, array_keys($newImages))) {
466+
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
467+
}
468+
if (!empty($product->getData($mediaAttrCode))) {
469+
$product->addAttributeUpdate(
470+
$mediaAttrCode,
471+
$product->getData($mediaAttrCode),
472+
$product->getStoreId()
473+
);
474+
}
475+
}
476+
477+
/**
478+
* @param \Magento\Catalog\Model\Product $product
479+
* @param $mediaAttrCode
480+
* @param array $clearImages
481+
* @param array $newImages
482+
* @param array $existImages
483+
*/
484+
private function processMediaAttributeLabel(
485+
\Magento\Catalog\Model\Product $product,
486+
$mediaAttrCode,
487+
array $clearImages,
488+
array $newImages,
489+
array $existImages
490+
) {
491+
$resetLabel = false;
492+
$attrData = $product->getData($mediaAttrCode);
493+
if (in_array($attrData, $clearImages)) {
494+
$product->setData($mediaAttrCode . '_label', null);
495+
$resetLabel = true;
496+
}
497+
498+
if (in_array($attrData, array_keys($newImages))) {
499+
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
500+
}
501+
502+
if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
503+
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
504+
}
505+
506+
if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) {
507+
$product->setData($mediaAttrCode . '_label', null);
508+
$resetLabel = true;
509+
}
510+
if (!empty($product->getData($mediaAttrCode . '_label'))
511+
|| $resetLabel === true
512+
) {
513+
$product->addAttributeUpdate(
514+
$mediaAttrCode . '_label',
515+
$product->getData($mediaAttrCode . '_label'),
516+
$product->getStoreId()
517+
);
518+
}
519+
}
451520
}

app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,85 @@ protected function mockContext()
7777
->willReturn($this->registry);
7878
}
7979

80+
public function testGetGalleryImagesJsonWithLabel()
81+
{
82+
$this->prepareGetGalleryImagesJsonMocks();
83+
$json = $this->model->getGalleryImagesJson();
84+
$decodedJson = json_decode($json, true);
85+
$this->assertEquals('product_page_image_small_url', $decodedJson[0]['thumb']);
86+
$this->assertEquals('product_page_image_medium_url', $decodedJson[0]['img']);
87+
$this->assertEquals('product_page_image_large_url', $decodedJson[0]['full']);
88+
$this->assertEquals('test_label', $decodedJson[0]['caption']);
89+
$this->assertEquals('2', $decodedJson[0]['position']);
90+
$this->assertEquals(false, $decodedJson[0]['isMain']);
91+
$this->assertEquals('test_media_type', $decodedJson[0]['type']);
92+
$this->assertEquals('test_video_url', $decodedJson[0]['videoUrl']);
93+
}
94+
95+
public function testGetGalleryImagesJsonWithoutLabel()
96+
{
97+
$this->prepareGetGalleryImagesJsonMocks(false);
98+
$json = $this->model->getGalleryImagesJson();
99+
$decodedJson = json_decode($json, true);
100+
$this->assertEquals('test_product_name', $decodedJson[0]['caption']);
101+
}
102+
103+
private function prepareGetGalleryImagesJsonMocks($hasLabel = true)
104+
{
105+
$storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
106+
->disableOriginalConstructor()
107+
->getMock();
108+
109+
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
110+
->disableOriginalConstructor()
111+
->getMock();
112+
113+
$productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\AbstractType::class)
114+
->disableOriginalConstructor()
115+
->getMock();
116+
$productTypeMock->expects($this->any())
117+
->method('getStoreFilter')
118+
->with($productMock)
119+
->willReturn($storeMock);
120+
121+
$productMock->expects($this->any())
122+
->method('getTypeInstance')
123+
->willReturn($productTypeMock);
124+
$productMock->expects($this->any())
125+
->method('getMediaGalleryImages')
126+
->willReturn($this->getImagesCollectionWithPopulatedDataObject($hasLabel));
127+
$productMock->expects($this->any())
128+
->method('getName')
129+
->willReturn('test_product_name');
130+
131+
$this->registry->expects($this->any())
132+
->method('registry')
133+
->with('product')
134+
->willReturn($productMock);
135+
136+
$this->imageHelper->expects($this->any())
137+
->method('init')
138+
->willReturnMap([
139+
[$productMock, 'product_page_image_small', [], $this->imageHelper],
140+
[$productMock, 'product_page_image_medium_no_frame', [], $this->imageHelper],
141+
[$productMock, 'product_page_image_large_no_frame', [], $this->imageHelper],
142+
])
143+
->willReturnSelf();
144+
$this->imageHelper->expects($this->any())
145+
->method('setImageFile')
146+
->with('test_file')
147+
->willReturnSelf();
148+
$this->imageHelper->expects($this->at(2))
149+
->method('getUrl')
150+
->willReturn('product_page_image_small_url');
151+
$this->imageHelper->expects($this->at(5))
152+
->method('getUrl')
153+
->willReturn('product_page_image_medium_url');
154+
$this->imageHelper->expects($this->at(8))
155+
->method('getUrl')
156+
->willReturn('product_page_image_large_url');
157+
}
158+
80159
public function testGetGalleryImages()
81160
{
82161
$storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
@@ -154,4 +233,30 @@ private function getImagesCollection()
154233

155234
return $collectionMock;
156235
}
236+
237+
/**
238+
* @return \Magento\Framework\Data\Collection
239+
*/
240+
private function getImagesCollectionWithPopulatedDataObject($hasLabel)
241+
{
242+
$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
243+
->disableOriginalConstructor()
244+
->getMock();
245+
246+
$items = [
247+
new \Magento\Framework\DataObject([
248+
'file' => 'test_file',
249+
'label' => ($hasLabel ? 'test_label' : ''),
250+
'position' => '2',
251+
'media_type' => 'external-test_media_type',
252+
"video_url" => 'test_video_url'
253+
]),
254+
];
255+
256+
$collectionMock->expects($this->any())
257+
->method('getIterator')
258+
->willReturn(new \ArrayIterator($items));
259+
260+
return $collectionMock;
261+
}
157262
}

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

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,12 @@ protected function getMediaGallery(array $productIds)
532532
]
533533
)->joinLeft(
534534
['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')],
535-
'(mg.value_id = mgv.value_id AND mgv.store_id = 0)',
535+
'(mg.value_id = mgv.value_id)',
536536
[
537537
'mgv.label',
538538
'mgv.position',
539-
'mgv.disabled'
539+
'mgv.disabled',
540+
'mgv.store_id'
540541
]
541542
)->where(
542543
"mgvte.{$this->getProductEntityLinkField()} IN (?)",
@@ -552,6 +553,7 @@ protected function getMediaGallery(array $productIds)
552553
'_media_label' => $mediaRow['label'],
553554
'_media_position' => $mediaRow['position'],
554555
'_media_is_disabled' => $mediaRow['disabled'],
556+
'_media_store_id' => $mediaRow['store_id'],
555557
];
556558
}
557559

@@ -931,8 +933,8 @@ protected function loadCollection(): array
931933
foreach ($collection as $itemId => $item) {
932934
$data[$itemId][$storeId] = $item;
933935
}
936+
$collection->clear();
934937
}
935-
$collection->clear();
936938

937939
return $data;
938940
}
@@ -1024,12 +1026,10 @@ protected function collectRawData()
10241026
unset($data[$itemId][$storeId][self::COL_ADDITIONAL_ATTRIBUTES]);
10251027
}
10261028

1027-
if (!empty($data[$itemId][$storeId]) || $this->hasMultiselectData($item, $storeId)) {
1028-
$attrSetId = $item->getAttributeSetId();
1029-
$data[$itemId][$storeId][self::COL_STORE] = $storeCode;
1030-
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
1031-
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
1032-
}
1029+
$attrSetId = $item->getAttributeSetId();
1030+
$data[$itemId][$storeId][self::COL_STORE] = $storeCode;
1031+
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
1032+
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
10331033
$data[$itemId][$storeId][self::COL_SKU] = htmlspecialchars_decode($item->getSku());
10341034
$data[$itemId][$storeId]['store_id'] = $storeId;
10351035
$data[$itemId][$storeId]['product_id'] = $itemId;
@@ -1104,6 +1104,7 @@ protected function collectMultirawData()
11041104
* @param \Magento\Catalog\Model\Product $item
11051105
* @param int $storeId
11061106
* @return bool
1107+
* @deprecated
11071108
*/
11081109
protected function hasMultiselectData($item, $storeId)
11091110
{
@@ -1162,20 +1163,23 @@ protected function isValidAttributeValue($code, $value)
11621163
* @SuppressWarnings(PHPMD.NPathComplexity)
11631164
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
11641165
*/
1165-
private function appendMultirowData(&$dataRow, &$multiRawData)
1166+
private function appendMultirowData(&$dataRow, $multiRawData)
11661167
{
11671168
$productId = $dataRow['product_id'];
11681169
$productLinkId = $dataRow['product_link_id'];
11691170
$storeId = $dataRow['store_id'];
11701171
$sku = $dataRow[self::COL_SKU];
1172+
$type = $dataRow[self::COL_TYPE];
1173+
$attributeSet = $dataRow[self::COL_ATTR_SET];
11711174

11721175
unset($dataRow['product_id']);
11731176
unset($dataRow['product_link_id']);
11741177
unset($dataRow['store_id']);
11751178
unset($dataRow[self::COL_SKU]);
1176-
1179+
unset($dataRow[self::COL_STORE]);
1180+
unset($dataRow[self::COL_ATTR_SET]);
1181+
unset($dataRow[self::COL_TYPE]);
11771182
if (Store::DEFAULT_STORE_ID == $storeId) {
1178-
unset($dataRow[self::COL_STORE]);
11791183
$this->updateDataWithCategoryColumns($dataRow, $multiRawData['rowCategories'], $productId);
11801184
if (!empty($multiRawData['rowWebsites'][$productId])) {
11811185
$websiteCodes = [];
@@ -1191,11 +1195,13 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
11911195
$additionalImageLabels = [];
11921196
$additionalImageIsDisabled = [];
11931197
foreach ($multiRawData['mediaGalery'][$productLinkId] as $mediaItem) {
1194-
$additionalImages[] = $mediaItem['_media_image'];
1195-
$additionalImageLabels[] = $mediaItem['_media_label'];
1198+
if ((int)$mediaItem['_media_store_id'] === Store::DEFAULT_STORE_ID) {
1199+
$additionalImages[] = $mediaItem['_media_image'];
1200+
$additionalImageLabels[] = $mediaItem['_media_label'];
11961201

1197-
if ($mediaItem['_media_is_disabled'] == true) {
1198-
$additionalImageIsDisabled[] = $mediaItem['_media_image'];
1202+
if ($mediaItem['_media_is_disabled'] == true) {
1203+
$additionalImageIsDisabled[] = $mediaItem['_media_image'];
1204+
}
11991205
}
12001206
}
12011207
$dataRow['additional_images'] =
@@ -1229,6 +1235,21 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
12291235
}
12301236
}
12311237
$dataRow = $this->rowCustomizer->addData($dataRow, $productId);
1238+
} else {
1239+
$additionalImageIsDisabled = [];
1240+
if (!empty($multiRawData['mediaGalery'][$productLinkId])) {
1241+
foreach ($multiRawData['mediaGalery'][$productLinkId] as $mediaItem) {
1242+
if ((int)$mediaItem['_media_store_id'] === $storeId) {
1243+
if ($mediaItem['_media_is_disabled'] == true) {
1244+
$additionalImageIsDisabled[] = $mediaItem['_media_image'];
1245+
}
1246+
}
1247+
}
1248+
}
1249+
if ($additionalImageIsDisabled) {
1250+
$dataRow['hide_from_product_page'] =
1251+
implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalImageIsDisabled);
1252+
}
12321253
}
12331254

12341255
if (!empty($this->collectedMultiselectsData[$storeId][$productId])) {
@@ -1256,6 +1277,9 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
12561277
$dataRow[self::COL_STORE] = $this->_storeIdToCode[$storeId];
12571278
}
12581279
$dataRow[self::COL_SKU] = $sku;
1280+
$dataRow[self::COL_ATTR_SET] = $attributeSet;
1281+
$dataRow[self::COL_TYPE] = $type;
1282+
12591283
return $dataRow;
12601284
}
12611285

0 commit comments

Comments
 (0)