Go to Storefront and open created before the category
Category image src uses the full URL
When uploading an image to categories, it would be expected that when loaded on the frontend the category image URL is loaded so that when the media URL is set (i.e. for CDN usage) - the full URL is used to load the image. This is not the case however because of a change introduced in commit 3c3acd75674039f38ee65d81e8daaa9cbb81fadb where it attempts to determine the path of the image value either being relative or absolute. Considering the backend model for the image attribute is using what would be considered an absolute path, it is simply returning the value without prepending the media URL to the file path.

Hi @jkenneydaniel. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance - upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
@jkenneydaniel do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?
@magento give me 2.3.4 instance
Hi @jkenneydaniel. Thank you for your request. I'm working on Magento 2.3.4 instance for you
Hi @jkenneydaniel, here is your Magento instance.
Admin access: https://i-28100-2-3-4.instances.magento-community.engineering/admin_e91c
Login: 6b29d693 Password: 0ed39ee02cc2
Instance will be terminated in up to 3 hours.
Confirmed the issue:

Hi @engcom-Alfa. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop branchDetails
- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Add label Issue: Confirmed once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
@magento give me 2.4-develop instance
Hi @engcom-Alfa. Thank you for your request. I'm working on Magento 2.4-develop instance for you
Hi @engcom-Alfa, here is your Magento instance.
Admin access: https://i-28100-2-4-develop.instances.magento-community.engineering/admin_7c8f
Login: be299754 Password: 5d86697c07be
Instance will be terminated in up to 3 hours.
Hi @jkenneydaniel. Thank you for your reporting.
Unfortunately, we are not able to reproduce this issue on a fresh 2.4-develop instance.
Manual testing scenario:
Actual Result: :heavy_check_mark: Category image src uses the full URL


@jkenneydaniel Could you take a look?
Thanks!
@magento give me 2.4-develop instance
Hi @jkenneydaniel. Thank you for your request. I'm working on Magento 2.4-develop instance for you
Hi @jkenneydaniel, here is your Magento instance.
Admin access: https://i-28100-2-4-develop.instances.magento-community.engineering/admin_7596
Login: ff9671ff Password: a51269174d52
Instance will be terminated in up to 3 hours.
@engcom-Alfa So I see in 2.4 the functionality for the image.phtml was changed to use the Image viewmodel: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/ViewModel/Category/Image.php
Which means that section no longer uses $category->getImageUrl() - however on 2.3 this is not the case - so I'm a little confused, will this issue _not_ be fixed in 2.3 but rather we'll have to wait until after 2021 for 2.4 release?
@jkenneydaniel The issue is reproducible on Magento 2.3.5-p1 composer version (reproduced only on composer versions).
Actual Result: :heavy_multiplication_x: Category image src is actually just a relative path


@magento I am working on this
Hi @jkenneydaniel
Unfortunately I can not pull my fix on 2.3-develop
i leave you here the link with my fix so you can create a patch and fix your issue
https://github.com/magento/magento2/pull/28296/commits/a39d19dcf59aed693d85e84f5685a54d8f4fb59a
@magento give me 2.4-develop instance
Hi @Digisha-97. Thank you for your request. I'm working on Magento 2.4-develop instance for you
Hi @Digisha-97, here is your Magento instance.
Admin access: https://i-28100-2-4-develop.instances.magento-community.engineering/admin_61d1
Login: 6e193aea Password: aa48c7a1512f
Instance will be terminated in up to 3 hours.
@magento I am working on this
Hi @Digisha-97! :wave:
Thank you for joining. Please accept team invitation :point_right: here :point_left: and add your comment one more time.
@magento I am working on this
But I am not able to push changes , everytime it shows Authentication failed.
Yeah, this is broken on 2.3.5p2 and I spent a day debugging code thinking there was something wrong with an extension that did a getImageUrl to get the category image for inclusion in a rich snippet on the page but was putting a partial url in the html on the page.
<meta name="twitter:image" content="/pub/media/catalog/category/m2_link_garmin_2.jpg"/>
instead of this...
<meta name="twitter:image" content="https://www.example.com/pub/media/catalog/category/m2_link_garmin_2.jpg"/>
It also appears that another extension that does a getImage (without the URL) and builds up the url using just the image name is broken too, returning the media path with the image name, resulting in this... (note the double slash in the middle)
<meta property="og:image" content="https://www.example.com/pub/media/catalog/category//pub/media/catalog/category/m2_link_garmin_2.jpg" />
instead of this...
<meta property="og:image" content="https://www.example.com/pub/media/catalog/category/m2_link_garmin_2.jpg" />
* Problem seems to manifest in both getImageUrl and getImage on 2.3.5 (composer install), and appears to have begun around 2.3.4 or so and seems to persist in 2.4.0 version. This issue is compounded by the fact that the improper image file name with the relative path prefix has been stored in the image attribute of the catalog_category_entity_varchar table. Fixing the bug that causes it to be stored there incorrectly is not enough, the effect of the bug remains in the database. For those categories saved with a new image while the bug was present, you also will have to repair the category image file names stored in the database to remove the improper path prefix. *
/vendor/magento/module-catalog/Model/Category/Attribute/Backend/Image.php
public function beforeSave($object)
In This method below code is creating issue
$value[0]['url'] = '/' . $baseMediaDir . '/' . $newImgRelativePath;
$value[0]['name'] = $value[0]['url'];
Update it with
$value[0]['url'] = $baseMediaDir . $newImgRelativePath;
$value[0]['name'] = $value[0]['name'];
This will fix issue
Do Not forget to forget to override this file from your module to avoid direct core file changes
Before official patch is ready we are using following SQL only workaround:
DROP TRIGGER catalog_category_entity_varchar_before_update;
DROP TRIGGER catalog_category_entity_varchar_before_insert;
DELIMITER //
CREATE TRIGGER catalog_category_entity_varchar_before_update
BEFORE UPDATE
ON catalog_category_entity_varchar FOR EACH ROW
BEGIN
SET NEW.value = REPLACE(NEW.value, '/media/catalog/category/', '');
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER catalog_category_entity_varchar_before_insert
BEFORE INSERT
ON catalog_category_entity_varchar FOR EACH ROW
BEGIN
SET NEW.value = REPLACE(NEW.value, '/media/catalog/category/', '');
END; //
DELIMITER ;
Most helpful comment
Yeah, this is broken on 2.3.5p2 and I spent a day debugging code thinking there was something wrong with an extension that did a getImageUrl to get the category image for inclusion in a rich snippet on the page but was putting a partial url in the html on the page.
instead of this...
It also appears that another extension that does a getImage (without the URL) and builds up the url using just the image name is broken too, returning the media path with the image name, resulting in this... (note the double slash in the middle)
instead of this...
* Problem seems to manifest in both getImageUrl and getImage on 2.3.5 (composer install), and appears to have begun around 2.3.4 or so and seems to persist in 2.4.0 version. This issue is compounded by the fact that the improper image file name with the relative path prefix has been stored in the image attribute of the catalog_category_entity_varchar table. Fixing the bug that causes it to be stored there incorrectly is not enough, the effect of the bug remains in the database. For those categories saved with a new image while the bug was present, you also will have to repair the category image file names stored in the database to remove the improper path prefix. *
