Skip to content

Commit bdf7c3e

Browse files
author
Lysenko Olexandr
authored
Merge pull request #3565 from magento-chaika/chaika_december2
[chaika] Bugfixes
2 parents 0502433 + 5aa2886 commit bdf7c3e

File tree

8 files changed

+82
-16
lines changed

8 files changed

+82
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<severity value="CRITICAL"/>
1818
<testCaseId value="MAGETWO-61717"/>
1919
<group value="Catalog"/>
20+
<!-- skip due to MAGETWO-97424 -->
21+
<group value="skip"/>
2022
</annotations>
2123
<before>
2224
<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/Sales/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@
745745
<virtualType name="ShippingAddressAggregator" type="Magento\Framework\DB\Sql\ConcatExpression">
746746
<arguments>
747747
<argument name="columns" xsi:type="array">
748+
<item name="company" xsi:type="array">
749+
<item name="tableAlias" xsi:type="string">sales_shipping_address</item>
750+
<item name="columnName" xsi:type="string">company</item>
751+
</item>
748752
<item name="street" xsi:type="array">
749753
<item name="tableAlias" xsi:type="string">sales_shipping_address</item>
750754
<item name="columnName" xsi:type="string">street</item>
@@ -768,6 +772,10 @@
768772
<virtualType name="BillingAddressAggregator" type="Magento\Framework\DB\Sql\ConcatExpression">
769773
<arguments>
770774
<argument name="columns" xsi:type="array">
775+
<item name="company" xsi:type="array">
776+
<item name="tableAlias" xsi:type="string">sales_billing_address</item>
777+
<item name="columnName" xsi:type="string">company</item>
778+
</item>
771779
<item name="street" xsi:type="array">
772780
<item name="tableAlias" xsi:type="string">sales_billing_address</item>
773781
<item name="columnName" xsi:type="string">street</item>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function __construct(
5252
* Get product media for specified configurable product variation
5353
*
5454
* @return string
55+
* @throws \Magento\Framework\Exception\LocalizedException
5556
*/
5657
public function execute()
5758
{

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66
namespace Magento\Swatches\Helper;
77

8+
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface;
89
use Magento\Catalog\Api\Data\ProductInterface as Product;
910
use Magento\Catalog\Api\ProductRepositoryInterface;
10-
use Magento\Catalog\Helper\Image;
1111
use Magento\Catalog\Model\Product as ModelProduct;
1212
use Magento\Catalog\Model\Product\Image\UrlBuilder;
1313
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
@@ -324,35 +324,61 @@ private function addFilterByParent(ProductCollection $productCollection, $parent
324324
* @param ModelProduct $product
325325
*
326326
* @return array
327+
* @throws \Magento\Framework\Exception\LocalizedException
327328
*/
328-
public function getProductMediaGallery(ModelProduct $product)
329+
public function getProductMediaGallery(ModelProduct $product): array
329330
{
330331
$baseImage = null;
331332
$gallery = [];
332333

333334
$mediaGallery = $product->getMediaGalleryEntries();
335+
/** @var ProductAttributeMediaGalleryEntryInterface $mediaEntry */
334336
foreach ($mediaGallery as $mediaEntry) {
335337
if ($mediaEntry->isDisabled()) {
336338
continue;
337339
}
338-
339-
if (in_array('image', $mediaEntry->getTypes(), true) || !$baseImage) {
340-
$baseImage = $mediaEntry->getFile();
340+
if (!$baseImage || $this->isMainImage($mediaEntry)) {
341+
$baseImage = $mediaEntry;
341342
}
342343

343-
$gallery[$mediaEntry->getId()] = $this->getAllSizeImages($mediaEntry->getFile());
344+
$gallery[$mediaEntry->getId()] = $this->collectImageData($mediaEntry);
344345
}
345346

346347
if (!$baseImage) {
347348
return [];
348349
}
349350

350-
$resultGallery = $this->getAllSizeImages($baseImage);
351+
$resultGallery = $this->collectImageData($baseImage);
351352
$resultGallery['gallery'] = $gallery;
352353

353354
return $resultGallery;
354355
}
355356

357+
/**
358+
* Checks if image is main image in gallery
359+
*
360+
* @param ProductAttributeMediaGalleryEntryInterface $mediaEntry
361+
* @return bool
362+
*/
363+
private function isMainImage(ProductAttributeMediaGalleryEntryInterface $mediaEntry): bool
364+
{
365+
return in_array('image', $mediaEntry->getTypes(), true);
366+
}
367+
368+
/**
369+
* Returns image data for swatches
370+
*
371+
* @param ProductAttributeMediaGalleryEntryInterface $mediaEntry
372+
* @return array
373+
*/
374+
private function collectImageData(ProductAttributeMediaGalleryEntryInterface $mediaEntry): array
375+
{
376+
$image = $this->getAllSizeImages($mediaEntry->getFile());
377+
$image[ProductAttributeMediaGalleryEntryInterface::POSITION] = $mediaEntry->getPosition();
378+
$image['isMain'] =$this->isMainImage($mediaEntry);
379+
return $image;
380+
}
381+
356382
/**
357383
* Get all size images
358384
*

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,21 @@ define([
684684
if (!images) {
685685
images = this.options.mediaGalleryInitial;
686686
}
687-
688-
this.updateBaseImage(images, $main, !this.inProductList);
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
*
@@ -1233,9 +1243,6 @@ define([
12331243
dataMergeStrategy: this.options.gallerySwitchStrategy
12341244
});
12351245
}
1236-
1237-
gallery.first();
1238-
12391246
} else if (justAnImage && justAnImage.img) {
12401247
context.find('.product-image-photo').attr('src', justAnImage.img);
12411248
}

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,

lib/web/mage/validation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,10 +1132,10 @@
11321132
ovId;
11331133

11341134
if (!result) {
1135-
ovId = $(elm).attr('id') + '_value';
1135+
ovId = $('#' + $(elm).attr('id') + '_value');
11361136

1137-
if ($(ovId)) {
1138-
result = !$.mage.isEmptyNoTrim($(ovId).val());
1137+
if (ovId.length > 0) {
1138+
result = !$.mage.isEmptyNoTrim(ovId.val());
11391139
}
11401140
}
11411141

0 commit comments

Comments
 (0)