magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Magento 2.3.4 - Category getImageUrl() returns incorrect value #28100

Open jkenneydaniel opened 4 years ago

jkenneydaniel commented 4 years ago

Preconditions (*)

  1. Magento 2.3.5-p1 (reproduced only on composer versions)

Steps to reproduce (*)

  1. Go to Admin->Catalog->Categories;
  2. Create a new category with an image;
  3. Go to Storefront and open created before the category

    Expected result (*)

  4. Category image src uses the full URL

Actual result (*)

  1. Category image src is actually just a relative path

Additional Info

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.

Example from Magento 2.3.4 with Sample Data

m2-assistant[bot] commented 4 years ago

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?


jkenneydaniel commented 4 years ago

@magento give me 2.3.4 instance

magento-engcom-team commented 4 years ago

Hi @jkenneydaniel. Thank you for your request. I'm working on Magento 2.3.4 instance for you

magento-engcom-team commented 4 years ago

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.

jkenneydaniel commented 4 years ago

Confirmed the issue: image

m2-assistant[bot] commented 4 years ago

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:

engcom-Alfa commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @engcom-Alfa. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

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.

engcom-Alfa commented 4 years ago

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:

  1. Add image to category;
  2. Go to Storefront-> Category with an image;
  3. Open dev tools;

Actual Result: :heavy_check_mark: Category image src uses the full URL

image image1

@jkenneydaniel Could you take a look? Thanks!

jkenneydaniel commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @jkenneydaniel. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

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.

jkenneydaniel commented 4 years ago

@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?

engcom-Alfa commented 4 years ago

@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

newww newwwwww

CarmineDamore78 commented 4 years ago

@magento I am working on this

CarmineDamore78 commented 4 years ago

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

Digisha-97 commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @Digisha-97. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

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.

Digisha-97 commented 4 years ago

@magento I am working on this

m2-assistant[bot] commented 4 years ago

Hi @Digisha-97! :wave: Thank you for joining. Please accept team invitation :point_right: here :point_left: and add your comment one more time.

Digisha-97 commented 4 years ago

@magento I am working on this But I am not able to push changes , everytime it shows Authentication failed.

n2diving-dgx commented 4 years ago

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. example-of-bug-effect-on-db

Digisha-97 commented 4 years ago

/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

raybog commented 3 years ago

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 ;
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

dverkade commented 3 years ago

Confirmed issues can't be closed automatically.

kassner commented 3 years ago

@dverkade see https://github.com/magento/magento2/pull/31223#issuecomment-742112083

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

kassner commented 3 years ago

Bump

On 2 Jun 2021, at 02:57, stale[bot] @.***> wrote:

 This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

EmilyPepperman commented 3 years ago

Has this been solved in 2.4.3? Doesn't look like it.

stkrelax commented 3 years ago

unbelievable this is not solved yet... the patch that worked for us:

magento-2.4.2-p1-issue-28100.log

rename .log to .patch

after this you either need to save each category to assure the right way of image is stored in db or run a script to remove /media/catalog/category/ from each catalog_category_entity_varchar value where there is a image

Organizer21 commented 2 years ago

After wasting a lot of time I have landed here and seem to have this issue in 2.4.3 CE, presumably just like @EmilyPepperman (not sure you solved it?). I'm very new to Magento and a quick attempt to apply that patch @stkrelax on 2.4.3 (using ./vendor/bin/ece-patches with the patch in a m2-hotfixeds folder) quickly gave an error about -> No such file or directory: Model/Category/Attribute/Backend/Image.php so I am sort of stuck at this point.

For reference my issue in detail; when I select an Image for a Category it shows correct in the preview/select element, but upon a page refresh the image shows as a broken link in the admin. In my case the link applied to it is https://magento.domain.com/pubhttps://magento.domain.com/media/custom-asset/category-banner-1.png and the double up on the domain name is clearly what's breaking it and I have no idea why and how to fix it at this point. I presume it's related to this issue in this thread, but I might be wrong of course.

nahall commented 1 year ago

@magento give me 2.4-develop instance with extensions magepow/categories

magento-deployment-service[bot] commented 1 year ago

Hi @nahall. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @nahall, here is your Magento Instance: https://354dfdfa635d2af46f593a6373bf7ccc.instances-prod.magento-community.engineering Admin access: https://354dfdfa635d2af46f593a6373bf7ccc.instances-prod.magento-community.engineering/admin_bfa7 Login: 1c3fe936 Password: 93eca160036e

nahall commented 1 year ago

@magento give me 2.4-develop instance with extensions magepow/categories

magento-deployment-service[bot] commented 1 year ago

Hi @nahall. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @nahall, here is your Magento Instance: https://354dfdfa635d2af46f593a6373bf7ccc.instances-prod.magento-community.engineering Admin access: https://354dfdfa635d2af46f593a6373bf7ccc.instances-prod.magento-community.engineering/admin_0743 Login: 51b55ec9 Password: b9d69478e866

nahall commented 1 year ago

I verified that this is still a problem. To verify, upload a category image and look at the database like: select * from catalog_category_entity_varchar where attribute_id=37 and entity_id=2135;

The value field will be set like "/media/catalog/category/test.jpg". When it is set like this, getImageUrl() returns '/media/catalog/category/test.jpg' instead of 'https://domain.com/media/catalog/category/test.jpg'.

By editing the database to change value='test.jpg' then getImageUrl() will return 'https://domain.com/media/catalog/category/test.jpg' properly.

I also tested the patch given by stkrelax https://github.com/magento/magento2/issues/28100#issuecomment-935810263 and it fixes the problem.

How can we proceed with getting this merged?

m2-assistant[bot] commented 6 months ago

Hi @engcom-Delta. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


engcom-Delta commented 6 months ago

Hi @jkenneydaniel,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4.7 instance and the issue is no more reproducible.

1.Go to Admin->Catalog->Categories 2.Create a new category with an image 3.Go to Storefront and open created before the category

Go to Admin->Catalog->Categories

Screenshot 2024-05-16 at 2 46 03 PM

Create a new category with an image

Screenshot 2024-05-16 at 2 52 02 PM

Category image src uses the full URL instead of a relative path

Screenshot 2024-05-16 at 3 37 57 PM

Hence we are closing this issue.

Thanks,

magento-deployment-service[bot] commented 6 months ago

Hi @nahall. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 6 months ago

Hi @nahall, here is your Magento Instance: https://354dfdfa635d2af46f593a6373bf7ccc.instances-prod.magento-community.engineering Admin access: https://354dfdfa635d2af46f593a6373bf7ccc.instances-prod.magento-community.engineering/admin_6666 Login: 1a2d53b7 Password: 5dc38bf3a39a

nahall commented 6 months ago

Unfortunately this is still an issue. Please note that this bug refers to "getImageUrl() returning an incorrect value".

@engcom-Delta Your above test is not calling getImageUrl() in that default Luba template.

You need to modify a template file to call getImageUrl(). Doing so I just verified on 2.4.7 that the URL being returned in this case is relative, without the domain name. The above patch is needed to properly fix this.

Please reopen this as verified for 2.4.7. Thank you.

engcom-Delta commented 5 months ago

Hi @nahall ,

Thanks for your input on this issue.

We are reopening this ticket as per your above comment.

Thanks,

m2-assistant[bot] commented 5 months ago

Hi @engcom-November. 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:

engcom-November commented 5 months ago

Hello @nahall,

Thank you for the input.

Verified this on 2.4-develop. I have modified the template file to call getImageUrl(), as you can see in the below image:

image

It can be seen that the image is being rendered with relative path.

image

The getImageUrl() method returns relative path of the image.

Hence this issue can be confirmed.

Thank you.

github-jira-sync-bot commented 5 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12016 is successfully created for this GitHub issue.