Skip to content

Commit 2f8053b

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-94435' into 2.1.16-develop-pr56
2 parents d89ebf2 + c40fd81 commit 2f8053b

File tree

110 files changed

+634
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+634
-396
lines changed

app/code/Magento/AdminNotification/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lib-libxml": "*"
1111
},
1212
"type": "magento2-module",
13-
"version": "100.1.4",
13+
"version": "100.1.5",
1414
"license": [
1515
"OSL-3.0",
1616
"AFL-3.0"

app/code/Magento/AdvancedPricingImportExport/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"magento/framework": "100.1.*"
1414
},
1515
"type": "magento2-module",
16-
"version": "100.1.4",
16+
"version": "100.1.5",
1717
"license": [
1818
"OSL-3.0",
1919
"AFL-3.0"

app/code/Magento/Authorization/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"magento/framework": "100.1.*"
88
},
99
"type": "magento2-module",
10-
"version": "100.1.3",
10+
"version": "100.1.4",
1111
"license": [
1212
"OSL-3.0",
1313
"AFL-3.0"

app/code/Magento/Authorizenet/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"magento/framework": "100.1.*"
1414
},
1515
"type": "magento2-module",
16-
"version": "100.1.7",
16+
"version": "100.1.8",
1717
"license": [
1818
"proprietary"
1919
],

app/code/Magento/Backend/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"magento/framework": "100.1.*"
2323
},
2424
"type": "magento2-module",
25-
"version": "100.1.9",
25+
"version": "100.1.10",
2626
"license": [
2727
"OSL-3.0",
2828
"AFL-3.0"

app/code/Magento/Braintree/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"magento/module-checkout-agreements": "100.1.*"
2525
},
2626
"type": "magento2-module",
27-
"version": "100.1.9",
27+
"version": "100.1.10",
2828
"license": [
2929
"proprietary"
3030
],

app/code/Magento/Bundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"magento/module-bundle-sample-data": "Sample Data version:100.1.*"
2626
},
2727
"type": "magento2-module",
28-
"version": "100.1.7",
28+
"version": "100.1.8",
2929
"license": [
3030
"OSL-3.0",
3131
"AFL-3.0"

app/code/Magento/CacheInvalidate/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"magento/framework": "100.1.*"
88
},
99
"type": "magento2-module",
10-
"version": "100.1.4",
10+
"version": "100.1.5",
1111
"license": [
1212
"OSL-3.0",
1313
"AFL-3.0"

app/code/Magento/Captcha/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"magento/framework": "100.1.*"
1111
},
1212
"type": "magento2-module",
13-
"version": "100.1.4",
13+
"version": "100.1.5",
1414
"license": [
1515
"OSL-3.0",
1616
"AFL-3.0"

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 89 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -455,25 +455,19 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
455455
$newEntries[] = $entry;
456456
}
457457
}
458-
foreach ($existingMediaGallery as $key => &$existingEntry) {
459-
if (isset($entriesById[$existingEntry['value_id']])) {
460-
$updatedEntry = $entriesById[$existingEntry['value_id']];
461-
if ($updatedEntry['file'] === null) {
462-
unset($updatedEntry['file']);
463-
}
464-
$existingMediaGallery[$key] = array_merge($existingEntry, $updatedEntry);
465-
} else {
466-
//set the removed flag
467-
$existingEntry['removed'] = true;
468-
}
469-
}
458+
$existingMediaGallery = $this->processingExistingImages($existingMediaGallery, $entriesById);
470459
$product->setData('media_gallery', ["images" => $existingMediaGallery]);
471460
} else {
472461
$newEntries = $mediaGalleryEntries;
473462
}
474463

475-
$this->getMediaGalleryProcessor()->clearMediaAttribute($product, array_keys($product->getMediaAttributes()));
476464
$images = $product->getMediaGallery('images');
465+
if ($images) {
466+
$images = $this->determineImageRoles($product, $images);
467+
}
468+
469+
$this->getMediaGalleryProcessor()->clearMediaAttribute($product, array_keys($product->getMediaAttributes()));
470+
477471
if ($images) {
478472
foreach ($images as $image) {
479473
if (!isset($image['removed']) && !empty($image['types'])) {
@@ -482,25 +476,8 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
482476
}
483477
}
484478

485-
foreach ($newEntries as $newEntry) {
486-
if (!isset($newEntry['content'])) {
487-
throw new InputException(__('The image content is not valid.'));
488-
}
489-
/** @var ImageContentInterface $contentDataObject */
490-
$contentDataObject = $this->contentFactory->create()
491-
->setName($newEntry['content']['data'][ImageContentInterface::NAME])
492-
->setBase64EncodedData($newEntry['content']['data'][ImageContentInterface::BASE64_ENCODED_DATA])
493-
->setType($newEntry['content']['data'][ImageContentInterface::TYPE]);
494-
$newEntry['content'] = $contentDataObject;
495-
$this->processNewMediaGalleryEntry($product, $newEntry);
479+
$this->processingNewEntries($newEntries, $product, $entriesById);
496480

497-
$finalGallery = $product->getData('media_gallery');
498-
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
499-
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
500-
$entriesById[$newEntryId] = $newEntry;
501-
$finalGallery['images'][$newEntryId] = $newEntry;
502-
$product->setData('media_gallery', $finalGallery);
503-
}
504481
return $this;
505482
}
506483

@@ -674,6 +651,32 @@ protected function addFilterGroupToCollection(
674651
}
675652
}
676653

654+
/**
655+
* Ascertain image roles, if they are not set against the gallery entries
656+
*
657+
* @param ProductInterface $product
658+
* @param array $images
659+
* @return array
660+
*/
661+
private function determineImageRoles(ProductInterface $product, array $images)
662+
{
663+
$imagesWithRoles = [];
664+
foreach ($images as $image) {
665+
if (!isset($image['types'])) {
666+
$image['types'] = [];
667+
if (isset($image['file'])) {
668+
foreach (array_keys($product->getMediaAttributes()) as $attribute) {
669+
if ($image['file'] == $product->getData($attribute)) {
670+
$image['types'][] = $attribute;
671+
}
672+
}
673+
}
674+
}
675+
$imagesWithRoles[] = $image;
676+
}
677+
return $imagesWithRoles;
678+
}
679+
677680
/**
678681
* Apply custom filters to product collection.
679682
*
@@ -729,4 +732,59 @@ private function getMediaGalleryProcessor()
729732
}
730733
return $this->mediaGalleryProcessor;
731734
}
735+
736+
/**
737+
* @param array $existingMediaGallery
738+
* @param array $entriesById
739+
* @return array
740+
*/
741+
private function processingExistingImages(array $existingMediaGallery, array $entriesById)
742+
{
743+
foreach ($existingMediaGallery as $key => &$existingEntry) {
744+
if (isset($entriesById[$existingEntry['value_id']])) {
745+
$updatedEntry = $entriesById[$existingEntry['value_id']];
746+
if ($updatedEntry['file'] === null) {
747+
unset($updatedEntry['file']);
748+
}
749+
$existingMediaGallery[$key] = array_merge($existingEntry, $updatedEntry);
750+
} else {
751+
//set the removed flag
752+
$existingEntry['removed'] = true;
753+
}
754+
}
755+
756+
return $existingMediaGallery;
757+
}
758+
759+
/**
760+
* @param array $newEntries
761+
* @param ProductInterface $product
762+
* @param array $entriesById
763+
* @return void
764+
* @throws InputException
765+
* @throws LocalizedException
766+
* @throws StateException
767+
*/
768+
private function processingNewEntries(array $newEntries, ProductInterface $product, array $entriesById)
769+
{
770+
foreach ($newEntries as $newEntry) {
771+
if (!isset($newEntry['content'])) {
772+
throw new InputException(__('The image content is not valid.'));
773+
}
774+
/** @var ImageContentInterface $contentDataObject */
775+
$contentDataObject = $this->contentFactory->create()
776+
->setName($newEntry['content']['data'][ImageContentInterface::NAME])
777+
->setBase64EncodedData($newEntry['content']['data'][ImageContentInterface::BASE64_ENCODED_DATA])
778+
->setType($newEntry['content']['data'][ImageContentInterface::TYPE]);
779+
$newEntry['content'] = $contentDataObject;
780+
$this->processNewMediaGalleryEntry($product, $newEntry);
781+
782+
$finalGallery = $product->getData('media_gallery');
783+
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
784+
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
785+
$entriesById[$newEntryId] = $newEntry;
786+
$finalGallery['images'][$newEntryId] = $newEntry;
787+
$product->setData('media_gallery', $finalGallery);
788+
}
789+
}
732790
}

0 commit comments

Comments
 (0)