magento2: Image Swatch size change not working
Preconditions
- Magento CE 2.1.0
Steps to reproduce
- Create a product attribute with Catalog Input Type for Store Owner set to “Visual swatch”
- Create configurable product with the attribute above set to the configurations
- Check the image swatch size in frontend ( Product List )
- In “YOUR THEME/etc/view.xml” add changes for the image swatches
<?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>90</width>
<height>30</height>
</image>
<image id="swatch_thumb" type="swatch_thumb">
<width>120</width>
<height>40</height>
</image>
<image id="swatch_image_base" type="swatch_image">
<width>90</width>
<height>30</height>
</image>
<image id="swatch_thumb_base" type="swatch_thumb">
<width>120</width>
<height>40</height>
</image>
</images>
</media>
</view>
- Flush Cache & recheck the image swatch size
Expected result
- The Image swatch to change size
Actual result
- Nothing changed, not the size of the html element
or the actual file size
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 51 (21 by maintainers)
Commits related to this issue
- MAGETWO-73862: Image Swatch size change not working [GitHub #6382] — committed to magento/magento2 by StasKozar 6 years ago
- MAGETWO-73862: Image Swatch size change not working [GitHub #6382] — committed to magento/magento2 by StasKozar 6 years ago
- MAGETWO-73862: Image Swatch size change not working [GitHub #6382] — committed to magento/magento2 by StasKozar 6 years ago
- Merge pull request #3486 from magento-epam/EPAM-PR-23 MAGETWO-91756 In Related product section add to wishlist and compare is not displaying for mobile devices portrait view MAGETWO-59789 Image Swat... — committed to magento/magento2 by rganin 6 years ago
- Issues #6382 - Image Swatch size — committed to srenon/magento2 by srenon 6 years ago
- Merge pull request #1 from srenon/srenon-image-swatch Issues #6382 - Image Swatch size — committed to srenon/magento2 by srenon 6 years ago
So the fix for this bug is not released yet? Wouldn’t it make sense to keep the issue open until that patch release becomes available?
I added the following to my theme/etc/view.xm and CSS and it works. 2.1.7
`<images module="Magento_Catalog">
</images>`
I updated CSS.
.page-wrapper .swatch-option { height: 50px; min-width: 50px; }
So I’ve looked into this further the function
getImageConfig()is only used by the swatches module and I don’t see why looping through the themes is necessary. There are other modules such asMagento_Catalog_Block_Product_View_Gallery::getConfigView()where this isn’t the case.We’ve been able to get around this issue by matching the way
Magento_Catalog_Block_Product_View_Gallery::getConfigView()gets the image configuration. So that means thatMagento\Swatches\Helper\Media::getImageConfig()becomes:I’m not aware of any knock-on effects of rewriting this but will update this ticket if any issues occur.
I’ve discovered the cause of the problem, but am yet to find a solution.
In magento/module-swatches/Helper/Media.php it calls
getSwatchAttributeImage()which then callsgetFolderNameSize()which callsgetImageConfig()- this is what’s responsible for getting the image configuration.The code was looping through 4 registered themes starting with our custom theme, setting the data correctly, then moving through the rest of the themes and overwriting the config in
$imageConfig.I checked
getRegisteredThemes()and this was loading all themes that are of type Physical and Virtual and ordering them alphabetically. Our theme happened to be at the beginning.Next, I just need to understand what the difference between swatches and other images when loading the image config.
We should fix this in 2.2. branch as well
This has been fixed in
2.3-develophttps://github.com/magento/magento2/pull/13506We’re on 2.1.5 and for whatever reason Magento is generating 20x20 swatch images and deploying them to
pub/media/attribute/swatch/swatch_image/30x20/s/w(source images are 50x50). Setting the dimensions inview.xmldoesn’t work, so as a quick fix I add this to our global JS file to fix blurry swatch images on both category and product pages:There’s a tiny bit of FOUC, but it’s better than having blurry swatch images!
I tried it with the xml code above on 2.1.4 and then bin/magento catalog:image:resize (don’t know if that was needed) and images successfully changed. css needs to be adjusted, though.