-
Notifications
You must be signed in to change notification settings - Fork 9.4k

Description
Preconditions
- Magento Commerce 2.1.8
- Have an active frontend theme whose first letter comes alphabetically before "Magento/blank" e.g. "Acme/default"
- Have an "Visual swatch" attribute with at least one option
- Have a configurable product that offers this "Visual swatch" as an option with one simple product using it.
Steps to reproduce
- In "app/design/frontend/YOUR THEME/etc/view.xml" add changes for the image swatches. (e.g. "YOUR THEME" may be "Acme/default")
<?xml version="1.0"?>
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
<media>
<images module="Magento_Catalog">
<image id="swatch_image" type="swatch_image">
<width>250</width>
<height>250</height>
</image>
<image id="swatch_thumb" type="swatch_thumb">
<width>500</width>
<height>500</height>
</image>
<image id="swatch_image_base" type="swatch_image">
<width>250</width>
<height>250</height>
</image>
<image id="swatch_thumb_base" type="swatch_thumb">
<width>500</width>
<height>500</height>
</image>
</images>
</media>
</view>
- Flush Magento Cache
- In backend go to Stores => (Attributes) Product and edit your "Visual swatch" attribute
- Upload a new image for the option used in the simple product.
- Flush Magento Cache and go to the product detail page of that simple product
- Inspect the "Visual swatch" option image with the inspector of your browser
Expected result
The background image used for the visual swatch has the dimensions 250x250
Actual result
The background image used for the visual swatch has the dimensions 30x20 which represents the default setting
Underlying issue
The media helper in the module Magento_Swatches loops through all, even unused, themes in an alphabetical order to apply their view configuration.
In our case loading the view configuration happened in the following order:
- Acme/default (swatch_image: 250x250, swatch_thumb: 500x500)
- Magento/blank (swatch_image: 30x20, swatch_thumb: 110x90)
- Magento/luma (swatch_image: 30x20, swatch_thumb: 110x90)
Each step overwrites its previous settings therefore we don't see the dimensions of the swatch image changing.
Uploading image for a visual swatch option happens here:
Magento/Swatches/Controller/Adminhtml/Iframe/Show.php#L105
// ...
$this->swatchHelper->generateSwatchVariations($newFile);
generateSwatchVariations
Magento/Swatches/Helper/Media.php#L184
// ...
$imageConfig = $this->getImageConfig();
getImageConfig
Magento/Swatches/Helper/Media.php#L253
public function getImageConfig() {
// ...
foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
// ...
}
The problem is that the function loadRegisteredThemes returns all themes in an alphabetical order, even unused ones. It should load themes in the order they are used in frontend taking their hierarchy into account and also skip themes that are not used.