diff --git a/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php index a02d5af3c3916da9bea09c5aef080cce4f38c648..b67361c4fcc8a740dddceeadaed4fe4b4e3429a5 100644 --- a/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php @@ -187,8 +187,9 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView 'amount' => $this->_registerJsPrice($this->_convertPrice($regularPrice->getAmount()->getValue())), ], 'basePrice' => [ - 'amount' => - $this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getBaseAmount())), + 'amount' => $this->_registerJsPrice( + $this->_convertPrice($finalPrice->getAmount()->getBaseAmount()) + ), ], 'finalPrice' => [ 'amount' => $this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getValue())), @@ -197,7 +198,6 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView 'productId' => $currentProduct->getId(), 'chooseText' => __('Choose an Option...'), 'images' => isset($options['images']) ? $options['images'] : [], - 'baseImage' => $options['baseImage'], ]; if ($currentProduct->hasPreconfiguredValues() && !empty($attributesData['defaultValues'])) { diff --git a/app/code/Magento/ConfigurableProduct/Helper/Data.php b/app/code/Magento/ConfigurableProduct/Helper/Data.php index ed0c999f3761ec267791a2f79336965107d0b743..0a30e2f5a5c8d2398b928463cbad080d9148851b 100644 --- a/app/code/Magento/ConfigurableProduct/Helper/Data.php +++ b/app/code/Magento/ConfigurableProduct/Helper/Data.php @@ -58,7 +58,6 @@ class Data $options['images'][$productAttributeId][$attributeValue][$productId] = $imageUrl; } } - $options['baseImage'] = $baseImageUrl; return $options; } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Helper/DataTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Helper/DataTest.php index 4d2d219bc2258d8a5af681f5e8ab4512cce0964f..031dac827c83563ccc7dbd5fcd2d9d9bf29d9cba 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Helper/DataTest.php @@ -82,11 +82,10 @@ class DataTest extends \PHPUnit_Framework_TestCase ); $provider = []; $provider[] = [ - ['baseImage' => 'http://example.com/base_img_url'], + [], [ 'allowed_products' => [], 'current_product_mock' => $currentProductMock, - 'baseImage' => 'http://example.com/base_img_url' ], ]; @@ -163,12 +162,10 @@ class DataTest extends \PHPUnit_Framework_TestCase 'attribute_id_2' => [ 'attribute_code_value_2' => ['product_id_1', 'product_id_2'], ], - 'baseImage' => 'http://example.com/base_img_url', ], [ 'allowed_products' => $allowedProducts, 'current_product_mock' => $currentProductMock, - 'baseImage' => 'http://example.com/base_img_url' ], ]; return $provider; diff --git a/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js b/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js index 0b1449f2bc2733d3c7ebb006e0a66887bc51d360..34cbd39eff804f1bf15ced403f4acf96b0563c0a 100644 --- a/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js +++ b/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js @@ -10,7 +10,8 @@ define([ "priceUtils", "priceBox", "jquery/ui", - "jquery/jquery.parsequery" + "jquery/jquery.parsequery", + "mage/gallery" ], function($, _, mageTemplate, utils){ $.widget('mage.configurable', { @@ -69,6 +70,10 @@ define([ this.options.values = this.options.spConfig.defaultValues || {}; this.options.parentImage = $('[data-role=base-image-container] img').attr('src'); + + this.initialGalleryImages = $(this.options.mediaGallerySelector).data('mageGallery') + ? $(this.options.mediaGallerySelector).gallery('option', 'images') + : []; this.inputSimpleProduct = this.element.find(this.options.selectSimpleProduct); }, @@ -226,12 +231,7 @@ define([ _changeProductImage: function () { var images = this.options.spConfig.images, imagesArray = null, - galleryElement = $(this.options.mediaGallerySelector), - baseImage = { - small: this.options.spConfig.baseImage, - medium: this.options.spConfig.baseImage, - large: this.options.spConfig.baseImage - }; + galleryElement = $(this.options.mediaGallerySelector); $.each(this.options.settings, function (k, v) { var selectValue = parseInt(v.value, 10), attributeId = v.id.replace(/[a-z]*/, ''); @@ -251,18 +251,16 @@ define([ }); var result = []; - $.each(imagesArray || baseImage, function (k, v) { + $.each(imagesArray || {}, function (k, v) { result.push({ small: v, medium: v, large: v }); }); - if (result.length !== 1) { - result = [baseImage]; - } + if (galleryElement.length && galleryElement.data('mageGallery')) { - galleryElement.gallery('option', 'images', result); + galleryElement.gallery('option', 'images', result.length > 0 ? result : this.initialGalleryImages); } }, diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php index a2e6205071db7f2a9b4f1b80444ebfb1ac304c8a..9fbf676b355ed107dcb1db23c847ff5499643e04 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php @@ -69,7 +69,7 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Magento\Catalog\Model\Product', $product); } } - + /** * @magentoAppIsolation enabled */ @@ -79,7 +79,6 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase $this->assertNotEmpty($config); $this->assertArrayHasKey('productId', $config); $this->assertEquals(1, $config['productId']); - $this->assertArrayHasKey('baseImage', $config); $this->assertArrayHasKey('attributes', $config); $this->assertArrayHasKey('template', $config); $this->assertArrayHasKey('prices', $config);