Skip to content

Image Swatch size change not working #12647

@ghost

Description

Preconditions

  1. Magento Commerce 2.1.8
  2. Have an active frontend theme whose first letter comes alphabetically before "Magento/blank" e.g. "Acme/default"
  3. Have an "Visual swatch" attribute with at least one option
  4. Have a configurable product that offers this "Visual swatch" as an option with one simple product using it.

Steps to reproduce

  1. 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>
  1. Flush Magento Cache
  2. In backend go to Stores => (Attributes) Product and edit your "Visual swatch" attribute
  3. Upload a new image for the option used in the simple product.
  4. Flush Magento Cache and go to the product detail page of that simple product
  5. 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:

  1. Acme/default (swatch_image: 250x250, swatch_thumb: 500x500)
  2. Magento/blank (swatch_image: 30x20, swatch_thumb: 110x90)
  3. 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.

Metadata

Metadata

Assignees

Labels

Fixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions