Skip to content

Commit

Permalink
Merge pull request #1793 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Dec 1, 2017
2 parents b4bbe21 + 9bc20c4 commit 82caf48
Show file tree
Hide file tree
Showing 28 changed files with 901 additions and 242 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
</argument>
<argument name="exemptions" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="string"/>
</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Layout\Generator\Block">
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getGalleryImagesJson()
'thumb' => $image->getData('small_image_url'),
'img' => $image->getData('medium_image_url'),
'full' => $image->getData('large_image_url'),
'caption' => $image->getLabel(),
'caption' => ($image->getLabel() ?: $this->getProduct()->getName()),
'position' => $image->getPosition(),
'isMain' => $this->isMainImage($image),
'type' => str_replace('external-', '', $image->getMediaType()),
Expand Down
101 changes: 85 additions & 16 deletions app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,19 @@ public function execute($product, $arguments = [])
if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) {
continue;
}
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode, 'no_selection');
}

if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
}

if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
}
if (!empty($product->getData($mediaAttrCode))) {
$product->addAttributeUpdate(
$this->processMediaAttribute(
$product,
$mediaAttrCode,
$clearImages,
$newImages
);
if (in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail'])) {
$this->processMediaAttributeLabel(
$product,
$mediaAttrCode,
$product->getData($mediaAttrCode),
$product->getStoreId()
$clearImages,
$newImages,
$existImages
);
}
}
Expand Down Expand Up @@ -448,4 +444,77 @@ private function getMediaAttributeCodes()
}
return $this->mediaAttributeCodes;
}

/**
* @param \Magento\Catalog\Model\Product $product
* @param $mediaAttrCode
* @param array $clearImages
* @param array $newImages
*/
private function processMediaAttribute(
\Magento\Catalog\Model\Product $product,
$mediaAttrCode,
array $clearImages,
array $newImages
) {
$attrData = $product->getData($mediaAttrCode);
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode, 'no_selection');
}

if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
}
if (!empty($product->getData($mediaAttrCode))) {
$product->addAttributeUpdate(
$mediaAttrCode,
$product->getData($mediaAttrCode),
$product->getStoreId()
);
}
}

/**
* @param \Magento\Catalog\Model\Product $product
* @param $mediaAttrCode
* @param array $clearImages
* @param array $newImages
* @param array $existImages
*/
private function processMediaAttributeLabel(
\Magento\Catalog\Model\Product $product,
$mediaAttrCode,
array $clearImages,
array $newImages,
array $existImages
) {
$resetLabel = false;
$attrData = $product->getData($mediaAttrCode);
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode . '_label', null);
$resetLabel = true;
}

if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
}

if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
}

if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) {
$product->setData($mediaAttrCode . '_label', null);
$resetLabel = true;
}
if (!empty($product->getData($mediaAttrCode . '_label'))
|| $resetLabel === true
) {
$product->addAttributeUpdate(
$mediaAttrCode . '_label',
$product->getData($mediaAttrCode . '_label'),
$product->getStoreId()
);
}
}
}
105 changes: 105 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,85 @@ protected function mockContext()
->willReturn($this->registry);
}

public function testGetGalleryImagesJsonWithLabel()
{
$this->prepareGetGalleryImagesJsonMocks();
$json = $this->model->getGalleryImagesJson();
$decodedJson = json_decode($json, true);
$this->assertEquals('product_page_image_small_url', $decodedJson[0]['thumb']);
$this->assertEquals('product_page_image_medium_url', $decodedJson[0]['img']);
$this->assertEquals('product_page_image_large_url', $decodedJson[0]['full']);
$this->assertEquals('test_label', $decodedJson[0]['caption']);
$this->assertEquals('2', $decodedJson[0]['position']);
$this->assertEquals(false, $decodedJson[0]['isMain']);
$this->assertEquals('test_media_type', $decodedJson[0]['type']);
$this->assertEquals('test_video_url', $decodedJson[0]['videoUrl']);
}

public function testGetGalleryImagesJsonWithoutLabel()
{
$this->prepareGetGalleryImagesJsonMocks(false);
$json = $this->model->getGalleryImagesJson();
$decodedJson = json_decode($json, true);
$this->assertEquals('test_product_name', $decodedJson[0]['caption']);
}

private function prepareGetGalleryImagesJsonMocks($hasLabel = true)
{
$storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
->disableOriginalConstructor()
->getMock();

$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->getMock();

$productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\AbstractType::class)
->disableOriginalConstructor()
->getMock();
$productTypeMock->expects($this->any())
->method('getStoreFilter')
->with($productMock)
->willReturn($storeMock);

$productMock->expects($this->any())
->method('getTypeInstance')
->willReturn($productTypeMock);
$productMock->expects($this->any())
->method('getMediaGalleryImages')
->willReturn($this->getImagesCollectionWithPopulatedDataObject($hasLabel));
$productMock->expects($this->any())
->method('getName')
->willReturn('test_product_name');

$this->registry->expects($this->any())
->method('registry')
->with('product')
->willReturn($productMock);

$this->imageHelper->expects($this->any())
->method('init')
->willReturnMap([
[$productMock, 'product_page_image_small', [], $this->imageHelper],
[$productMock, 'product_page_image_medium_no_frame', [], $this->imageHelper],
[$productMock, 'product_page_image_large_no_frame', [], $this->imageHelper],
])
->willReturnSelf();
$this->imageHelper->expects($this->any())
->method('setImageFile')
->with('test_file')
->willReturnSelf();
$this->imageHelper->expects($this->at(2))
->method('getUrl')
->willReturn('product_page_image_small_url');
$this->imageHelper->expects($this->at(5))
->method('getUrl')
->willReturn('product_page_image_medium_url');
$this->imageHelper->expects($this->at(8))
->method('getUrl')
->willReturn('product_page_image_large_url');
}

public function testGetGalleryImages()
{
$storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
Expand Down Expand Up @@ -154,4 +233,30 @@ private function getImagesCollection()

return $collectionMock;
}

/**
* @return \Magento\Framework\Data\Collection
*/
private function getImagesCollectionWithPopulatedDataObject($hasLabel)
{
$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
->disableOriginalConstructor()
->getMock();

$items = [
new \Magento\Framework\DataObject([
'file' => 'test_file',
'label' => ($hasLabel ? 'test_label' : ''),
'position' => '2',
'media_type' => 'external-test_media_type',
"video_url" => 'test_video_url'
]),
];

$collectionMock->expects($this->any())
->method('getIterator')
->willReturn(new \ArrayIterator($items));

return $collectionMock;
}
}
56 changes: 40 additions & 16 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,12 @@ protected function getMediaGallery(array $productIds)
]
)->joinLeft(
['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')],
'(mg.value_id = mgv.value_id AND mgv.store_id = 0)',
'(mg.value_id = mgv.value_id)',
[
'mgv.label',
'mgv.position',
'mgv.disabled'
'mgv.disabled',
'mgv.store_id'
]
)->where(
"mgvte.{$this->getProductEntityLinkField()} IN (?)",
Expand All @@ -552,6 +553,7 @@ protected function getMediaGallery(array $productIds)
'_media_label' => $mediaRow['label'],
'_media_position' => $mediaRow['position'],
'_media_is_disabled' => $mediaRow['disabled'],
'_media_store_id' => $mediaRow['store_id'],
];
}

Expand Down Expand Up @@ -931,8 +933,8 @@ protected function loadCollection(): array
foreach ($collection as $itemId => $item) {
$data[$itemId][$storeId] = $item;
}
$collection->clear();
}
$collection->clear();

return $data;
}
Expand Down Expand Up @@ -1024,12 +1026,10 @@ protected function collectRawData()
unset($data[$itemId][$storeId][self::COL_ADDITIONAL_ATTRIBUTES]);
}

if (!empty($data[$itemId][$storeId]) || $this->hasMultiselectData($item, $storeId)) {
$attrSetId = $item->getAttributeSetId();
$data[$itemId][$storeId][self::COL_STORE] = $storeCode;
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
}
$attrSetId = $item->getAttributeSetId();
$data[$itemId][$storeId][self::COL_STORE] = $storeCode;
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
$data[$itemId][$storeId][self::COL_SKU] = htmlspecialchars_decode($item->getSku());
$data[$itemId][$storeId]['store_id'] = $storeId;
$data[$itemId][$storeId]['product_id'] = $itemId;
Expand Down Expand Up @@ -1104,6 +1104,7 @@ protected function collectMultirawData()
* @param \Magento\Catalog\Model\Product $item
* @param int $storeId
* @return bool
* @deprecated
*/
protected function hasMultiselectData($item, $storeId)
{
Expand Down Expand Up @@ -1162,20 +1163,23 @@ protected function isValidAttributeValue($code, $value)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function appendMultirowData(&$dataRow, &$multiRawData)
private function appendMultirowData(&$dataRow, $multiRawData)
{
$productId = $dataRow['product_id'];
$productLinkId = $dataRow['product_link_id'];
$storeId = $dataRow['store_id'];
$sku = $dataRow[self::COL_SKU];
$type = $dataRow[self::COL_TYPE];
$attributeSet = $dataRow[self::COL_ATTR_SET];

unset($dataRow['product_id']);
unset($dataRow['product_link_id']);
unset($dataRow['store_id']);
unset($dataRow[self::COL_SKU]);

unset($dataRow[self::COL_STORE]);
unset($dataRow[self::COL_ATTR_SET]);
unset($dataRow[self::COL_TYPE]);
if (Store::DEFAULT_STORE_ID == $storeId) {
unset($dataRow[self::COL_STORE]);
$this->updateDataWithCategoryColumns($dataRow, $multiRawData['rowCategories'], $productId);
if (!empty($multiRawData['rowWebsites'][$productId])) {
$websiteCodes = [];
Expand All @@ -1191,11 +1195,13 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
$additionalImageLabels = [];
$additionalImageIsDisabled = [];
foreach ($multiRawData['mediaGalery'][$productLinkId] as $mediaItem) {
$additionalImages[] = $mediaItem['_media_image'];
$additionalImageLabels[] = $mediaItem['_media_label'];
if ((int)$mediaItem['_media_store_id'] === Store::DEFAULT_STORE_ID) {
$additionalImages[] = $mediaItem['_media_image'];
$additionalImageLabels[] = $mediaItem['_media_label'];

if ($mediaItem['_media_is_disabled'] == true) {
$additionalImageIsDisabled[] = $mediaItem['_media_image'];
if ($mediaItem['_media_is_disabled'] == true) {
$additionalImageIsDisabled[] = $mediaItem['_media_image'];
}
}
}
$dataRow['additional_images'] =
Expand Down Expand Up @@ -1229,6 +1235,21 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
}
}
$dataRow = $this->rowCustomizer->addData($dataRow, $productId);
} else {
$additionalImageIsDisabled = [];
if (!empty($multiRawData['mediaGalery'][$productLinkId])) {
foreach ($multiRawData['mediaGalery'][$productLinkId] as $mediaItem) {
if ((int)$mediaItem['_media_store_id'] === $storeId) {
if ($mediaItem['_media_is_disabled'] == true) {
$additionalImageIsDisabled[] = $mediaItem['_media_image'];
}
}
}
}
if ($additionalImageIsDisabled) {
$dataRow['hide_from_product_page'] =
implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalImageIsDisabled);
}
}

if (!empty($this->collectedMultiselectsData[$storeId][$productId])) {
Expand Down Expand Up @@ -1256,6 +1277,9 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
$dataRow[self::COL_STORE] = $this->_storeIdToCode[$storeId];
}
$dataRow[self::COL_SKU] = $sku;
$dataRow[self::COL_ATTR_SET] = $attributeSet;
$dataRow[self::COL_TYPE] = $type;

return $dataRow;
}

Expand Down
Loading

0 comments on commit 82caf48

Please sign in to comment.