Skip to content

Commit 94bddf0

Browse files
committed
MAGETWO-35379: Gallery images are not loaded for Configurable Product
1 parent 08b6497 commit 94bddf0

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ public function getJsonConfig()
183183
'amount' => $this->_registerJsPrice($this->_convertPrice($regularPrice->getAmount()->getValue())),
184184
],
185185
'basePrice' => [
186-
'amount' =>
187-
$this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getBaseAmount())),
186+
'amount' => $this->_registerJsPrice(
187+
$this->_convertPrice($finalPrice->getAmount()->getBaseAmount())
188+
),
188189
],
189190
'finalPrice' => [
190191
'amount' => $this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getValue())),
@@ -193,7 +194,6 @@ public function getJsonConfig()
193194
'productId' => $currentProduct->getId(),
194195
'chooseText' => __('Choose an Option...'),
195196
'images' => isset($options['images']) ? $options['images'] : [],
196-
'baseImage' => $options['baseImage'],
197197
];
198198

199199
if ($currentProduct->hasPreconfiguredValues() && !empty($attributes['defaultValues'])) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function getOptions($currentProduct, $allowedProducts)
5858
$options['images'][$productAttributeId][$attributeValue][$productId] = $imageUrl;
5959
}
6060
}
61-
$options['baseImage'] = $baseImageUrl;
6261

6362
return $options;
6463
}

app/code/Magento/ConfigurableProduct/Test/Unit/Helper/DataTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ public function getOptionsDataProvider()
8282
);
8383
$provider = [];
8484
$provider[] = [
85-
['baseImage' => 'http://example.com/base_img_url'],
85+
[],
8686
[
8787
'allowed_products' => [],
8888
'current_product_mock' => $currentProductMock,
89-
'baseImage' => 'http://example.com/base_img_url'
9089
],
9190
];
9291

@@ -163,12 +162,10 @@ public function getOptionsDataProvider()
163162
'attribute_id_2' => [
164163
'attribute_code_value_2' => ['product_id_1', 'product_id_2'],
165164
],
166-
'baseImage' => 'http://example.com/base_img_url',
167165
],
168166
[
169167
'allowed_products' => $allowedProducts,
170168
'current_product_mock' => $currentProductMock,
171-
'baseImage' => 'http://example.com/base_img_url'
172169
],
173170
];
174171
return $provider;

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ define([
1010
"priceUtils",
1111
"priceBox",
1212
"jquery/ui",
13-
"jquery/jquery.parsequery"
13+
"jquery/jquery.parsequery",
14+
"mage/gallery"
1415
], function($, _, mageTemplate, utils){
1516

1617
function getPrices(elems){
@@ -83,6 +84,8 @@ define([
8384

8485
this.options.values = this.options.spConfig.defaultValues || {};
8586
this.options.parentImage = $('[data-role=base-image-container] img').attr('src');
87+
88+
this.initialGalleryImages = $(this.options.mediaGallerySelector).gallery('option', 'images');
8689
},
8790

8891
/**
@@ -238,12 +241,7 @@ define([
238241
_changeProductImage: function () {
239242
var images = this.options.spConfig.images,
240243
imagesArray = null,
241-
galleryElement = $(this.options.mediaGallerySelector),
242-
baseImage = {
243-
small: this.options.spConfig.baseImage,
244-
medium: this.options.spConfig.baseImage,
245-
large: this.options.spConfig.baseImage
246-
};
244+
galleryElement = $(this.options.mediaGallerySelector);
247245
$.each(this.options.settings, function (k, v) {
248246
var selectValue = parseInt(v.value, 10),
249247
attributeId = v.id.replace(/[a-z]*/, '');
@@ -263,18 +261,16 @@ define([
263261
});
264262

265263
var result = [];
266-
$.each(imagesArray || baseImage, function (k, v) {
264+
$.each(imagesArray || {}, function (k, v) {
267265
result.push({
268266
small: v,
269267
medium: v,
270268
large: v
271269
});
272270
});
273-
if (result.length !== 1) {
274-
result = [baseImage];
275-
}
271+
276272
if (galleryElement.length && galleryElement.data('mageGallery')) {
277-
galleryElement.gallery('option', 'images', result);
273+
galleryElement.gallery('option', 'images', result.length > 0 ? result : this.initialGalleryImages);
278274
}
279275
},
280276

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testGetAllowProducts()
6969
$this->assertInstanceOf('Magento\Catalog\Model\Product', $product);
7070
}
7171
}
72-
72+
7373
/**
7474
* @magentoAppIsolation enabled
7575
*/
@@ -79,7 +79,6 @@ public function testGetJsonConfig()
7979
$this->assertNotEmpty($config);
8080
$this->assertArrayHasKey('productId', $config);
8181
$this->assertEquals(1, $config['productId']);
82-
$this->assertArrayHasKey('baseImage', $config);
8382
$this->assertArrayHasKey('attributes', $config);
8483
$this->assertArrayHasKey('template', $config);
8584
$this->assertArrayHasKey('prices', $config);

0 commit comments

Comments
 (0)