Skip to content

Commit 77855e5

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into 2.2-develop-pr65
2 parents f058e23 + b073545 commit 77855e5

File tree

11 files changed

+82
-15
lines changed

11 files changed

+82
-15
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPurchaseProductWithCustomOptionsTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<severity value="CRITICAL"/>
1818
<testCaseId value="MAGETWO-77414"/>
1919
<group value="product"/>
20+
<skip>
21+
<issueId value="MAGETWO-97404"/>
22+
</skip>
2023
</annotations>
2124
<before>
2225
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ define([
291291
images = this.options.spConfig.images[this.simpleProduct];
292292

293293
if (images) {
294+
images = this._sortImages(images);
295+
294296
if (this.options.gallerySwitchStrategy === 'prepend') {
295297
images = images.concat(initialImages);
296298
}
@@ -309,7 +311,17 @@ define([
309311
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
310312
}
311313

312-
galleryObject.first();
314+
},
315+
316+
/**
317+
* Sorting images array
318+
*
319+
* @private
320+
*/
321+
_sortImages: function (images) {
322+
return _.sortBy(images, function (image) {
323+
return image.position;
324+
});
313325
},
314326

315327
/**

app/code/Magento/Store/etc/frontend/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<type name="Magento\Framework\App\FrontController">
1010
<plugin name="requestPreprocessor" type="Magento\Store\App\FrontController\Plugin\RequestPreprocessor" sortOrder="50"/>
1111
</type>
12-
<type name="Magento\Framework\App\Action\Action">
12+
<type name="Magento\Framework\App\Action\AbstractAction">
1313
<plugin name="contextPlugin" type="Magento\Store\App\Action\Plugin\Context" sortOrder="10"/>
1414
</type>
1515
<type name="Magento\Framework\App\RouterList" shared="true">

app/code/Magento/Swatches/Controller/Ajax/Media.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(
4444
* Get product media for specified configurable product variation
4545
*
4646
* @return string
47+
* @throws \Magento\Framework\Exception\LocalizedException
4748
*/
4849
public function execute()
4950
{

app/code/Magento/Swatches/Helper/Data.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Swatches\Helper;
88

9+
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface;
910
use Magento\Catalog\Api\Data\ProductInterface as Product;
1011
use Magento\Catalog\Api\ProductRepositoryInterface;
1112
use Magento\Catalog\Helper\Image;
@@ -311,37 +312,67 @@ private function addFilterByParent(ProductCollection $productCollection, $parent
311312
* ]
312313
* @param ModelProduct $product
313314
* @return array
315+
* @throws \Magento\Framework\Exception\LocalizedException
314316
*/
315-
public function getProductMediaGallery(ModelProduct $product)
317+
public function getProductMediaGallery(ModelProduct $product): array
316318
{
317319
$baseImage = null;
318320
$gallery = [];
319321

320322
$mediaGallery = $product->getMediaGalleryEntries();
323+
/** @var ProductAttributeMediaGalleryEntryInterface $mediaEntry */
321324
foreach ($mediaGallery as $mediaEntry) {
322325
if ($mediaEntry->isDisabled()) {
323326
continue;
324327
}
325328

326-
if (in_array('image', $mediaEntry->getTypes(), true)) {
327-
$baseImage = $mediaEntry->getFile();
329+
if (!$baseImage || $this->isMainImage($mediaEntry)) {
330+
$baseImage = $mediaEntry;
328331
} elseif (!$baseImage) {
329332
$baseImage = $mediaEntry->getFile();
330333
}
331334

332-
$gallery[$mediaEntry->getId()] = $this->getAllSizeImages($product, $mediaEntry->getFile());
335+
$gallery[$mediaEntry->getId()] = $this->collectImageData($product, $mediaEntry);
333336
}
334337

335338
if (!$baseImage) {
336339
return [];
337340
}
338341

339-
$resultGallery = $this->getAllSizeImages($product, $baseImage);
342+
$resultGallery = $this->collectImageData($product, $baseImage);
340343
$resultGallery['gallery'] = $gallery;
341344

342345
return $resultGallery;
343346
}
344347

348+
/**
349+
* Checks if image is main image in gallery
350+
*
351+
* @param ProductAttributeMediaGalleryEntryInterface $mediaEntry
352+
* @return bool
353+
*/
354+
private function isMainImage(ProductAttributeMediaGalleryEntryInterface $mediaEntry): bool
355+
{
356+
return in_array('image', $mediaEntry->getTypes(), true);
357+
}
358+
359+
/**
360+
* Returns image data for swatches
361+
*
362+
* @param ModelProduct $product
363+
* @param ProductAttributeMediaGalleryEntryInterface $mediaEntry
364+
* @return array
365+
*/
366+
private function collectImageData(
367+
ModelProduct $product,
368+
ProductAttributeMediaGalleryEntryInterface $mediaEntry
369+
): array {
370+
$image = $this->getAllSizeImages($product, $mediaEntry->getFile());
371+
$image[ProductAttributeMediaGalleryEntryInterface::POSITION] = $mediaEntry->getPosition();
372+
$image['isMain'] = $this->isMainImage($mediaEntry);
373+
return $image;
374+
}
375+
345376
/**
346377
* @param ModelProduct $product
347378
* @param string $imageFile

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,9 @@ define([
667667
/**
668668
* Load media gallery using ajax or json config.
669669
*
670-
* @param {String|undefined} eventName
671670
* @private
672671
*/
673-
_loadMedia: function (eventName) {
672+
_loadMedia: function () {
674673
var $main = this.inProductList ?
675674
this.element.parents('.product-item-info') :
676675
this.element.parents('.column.main'),
@@ -685,10 +684,21 @@ define([
685684
images = this.options.mediaGalleryInitial;
686685
}
687686

688-
this.updateBaseImage(images, $main, !this.inProductList, eventName);
687+
this.updateBaseImage(this._sortImages(images), $main, !this.inProductList);
689688
}
690689
},
691690

691+
/**
692+
* Sorting images array
693+
*
694+
* @private
695+
*/
696+
_sortImages: function (images) {
697+
return _.sortBy(images, function (image) {
698+
return image.position;
699+
});
700+
},
701+
692702
/**
693703
* Event for swatch options
694704
*
@@ -1252,9 +1262,6 @@ define([
12521262
dataMergeStrategy: this.options.gallerySwitchStrategy
12531263
});
12541264
}
1255-
1256-
gallery.first();
1257-
12581265
} else if (justAnImage && justAnImage.img) {
12591266
context.find('.product-image-photo').attr('src', justAnImage.img);
12601267
}

dev/tests/functional/tests/app/Magento/Reports/Test/TestCase/SalesOrderReportEntityTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Reports\Test\TestCase\SalesOrderReportEntityTest" summary="Sales Order Report" ticketId="MAGETWO-29136">
1010
<variation name="SalesOrderReportEntityTestVariation1" summary="Create sales order report, check report data and date" ticketId="MAGETWO-45399">
11+
<data name="issue" xsi:type="string">MAGETWO-97404: 2019-01-02: Tests fail Magento\Reports\Test\TestCase\SalesOrderReportEntityTest</data>
1112
<data name="order/dataset" xsi:type="string">default</data>
1213
<data name="order/data/price/dataset" xsi:type="string">full_invoice</data>
1314
<data name="salesReport/report_type" xsi:type="string">Order Created</data>

dev/tests/functional/tests/app/Magento/Reports/Test/TestCase/SalesRefundsReportEntityTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Reports\Test\TestCase\SalesRefundsReportEntityTest" summary="Sales Refunds Report" ticketId="MAGETWO-29348">
1010
<variation name="SalesRefundsReportEntityTestVariation1">
11+
<data name="issue" xsi:type="string">MAGETWO-97404: 2019-01-02: Tests fail Magento\Reports\Test\TestCase\SalesOrderReportEntityTest</data>
1112
<data name="description" xsi:type="string">assert refunds year report</data>
1213
<data name="order/dataset" xsi:type="string">default</data>
1314
<data name="order/data/price/dataset" xsi:type="string">full_invoice</data>

dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/SalesShippingReportEntityTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Shipping\Test\TestCase\SalesShippingReportEntityTest" summary="Sales Shipping Report" ticketId="MAGETWO-40914">
1010
<variation name="SalesShippingReportEntityTestVariation1">
11+
<data name="issue" xsi:type="string">MAGETWO-97404: 2019-01-02: Tests fail Magento\Reports\Test\TestCase\SalesOrderReportEntityTest</data>
1112
<data name="order/dataset" xsi:type="string">default</data>
1213
<data name="order/data/price/dataset" xsi:type="string">full_shipment</data>
1314
<data name="shippingReport/report_type" xsi:type="string">Order Created</data>

lib/web/mage/gallery/gallery.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,18 @@ define([
472472
* @param {Array.<Object>} data - Set of gallery items to update.
473473
*/
474474
updateData: function (data) {
475+
var mainImageIndex;
476+
475477
if (_.isArray(data)) {
476478
settings.fotoramaApi.load(data);
479+
mainImageIndex = getMainImageIndex(data);
480+
481+
if (mainImageIndex) {
482+
settings.fotoramaApi.show({
483+
index: mainImageIndex,
484+
time: 0
485+
});
486+
}
477487

478488
$.extend(false, settings, {
479489
data: data,

0 commit comments

Comments
 (0)