Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento 2.4.4 Mini cart item images not showing #35535

Closed
1 of 5 tasks
khoimm92 opened this issue May 25, 2022 · 24 comments · Fixed by craig-bartlett/magento2#1 or #36371
Closed
1 of 5 tasks

Magento 2.4.4 Mini cart item images not showing #35535

khoimm92 opened this issue May 25, 2022 · 24 comments · Fixed by craig-bartlett/magento2#1 or #36371
Assignees
Labels
Area: Cart & Checkout Component: Theme Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@khoimm92
Copy link
Contributor

khoimm92 commented May 25, 2022

Preconditions and environment

  • Magento 2.4.4
  • PHP8.1

Steps to reproduce

  1. Go to Content >> Design >> Configuration >>Edit theme >>Product Image Watermarks >> Thumbnail
  2. Upload image with Thumbnail and set image position as "Center"
  3. Add Products to Cart that all products have images.
  4. Open Minicart.
  5. Run bin/magento catalog:image:resize and observe the error in the terminal.

Expected result

All item images in Minicart get the images

Actual result

All item images are replaced by the default Product placeholder image

Additional information

I have debugged in this file vendor/magento/module-catalog/Helper/Image.php

public function getUrl()
    {
        try {
            switch ($this->mediaConfig->getMediaUrlFormat()) {
                case CatalogMediaConfig::IMAGE_OPTIMIZATION_PARAMETERS:
                    $this->initBaseFile();
                    break;
                case CatalogMediaConfig::HASH:
                    $this->applyScheduledActions();
                    break;
                default:
                    throw new LocalizedException(__("The specified Catalog media URL format is not supported."));
            }
            return $this->_getModel()->getUrl();
        } catch (\Exception $e) {
            \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info($e->getMessage());
            return $this->getDefaultPlaceholderUrl();
        }
    }

then got those errors

Deprecated Functionality: Implicit conversion from float 12.5 to int loses precision in /home/stagefish/public_html/stage.livefish.com.au/vendor/magento/framework/Image/Adapter/Gd2.php on line 963 [] []

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented May 25, 2022

Hi @khoimm92. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-assistant
Copy link

m2-assistant bot commented May 25, 2022

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

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
      DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
    1. 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.
    1. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- 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!

@engcom-Dash
Copy link

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

Hi @engcom-Dash, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@engcom-Dash engcom-Dash added Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: needs update Additional information is require, waiting for response labels Jun 2, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Jun 2, 2022
@m2-community-project m2-community-project bot removed Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: ready for confirmation labels Jun 2, 2022
@engcom-Dash
Copy link

engcom-Dash commented Jun 2, 2022

Hello @khoimm92 ,
We have tried to reproduce the issue in Magento 2.4.4 issue is not reproducible.

Please refer the below screenshot for the reference;
Screenshot from 2022-06-02 17-05-36
We have followed the below steps in order to reproduce the issue:
1.Add Products to Cart that all products have images
2.Open Mini-cart
3.Images Displaying in Mini Cart Page
Let us know in case we have missed anything. Thanks

@hostep
Copy link
Contributor

hostep commented Jun 5, 2022

@khoimm92, this is just a guess, but could it be that you have a custom theme with a etc/view.xml file where the width or height is set to an odd number for the mini_cart_product_thumbnail image?
You can probably solve this problem you have by making the number even so it's divisible by 2 without getting a decimal fragment.

Also: where did you see that error? Was it outputted to a certain log file? Because I don't see it when I quickly test it out ...

@miteshdhaduk1
Copy link

Magento 2.4.4

small_image URL returns the wrong cache hash in products and cart GraphQL for the default store. In other stores, it returns the correct URL.

@miteshdhaduk1
Copy link

Fix for me, maybe help you @khoimm92
#34540 (comment)

@engcom-Dash
Copy link

Hello @khoimm92 ,
As per our last comment , we have tried reproduce luma theme but here it seems that you are using a custom theme.
So we request you to go through with the solution given in this comment and let us know this issue has resolved or not.
Thanks.

@engcom-Dash
Copy link

Dear @khoimm92 ,

We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.

@craig-bartlett
Copy link
Contributor

Hi,

I've recently come across this same issue. It is indeed caused by theme images with an odd dimension and the watermark position set to centre. If using the Gd2 adapter, it uses the following to calculate the position:

$positionX = $this->_imageSrcWidth / 2 - imagesx($watermark) / 2;
$positionY = $this->_imageSrcHeight / 2 - imagesy($watermark) / 2;

If the image size has an odd dimension, this results in a float. These are then passed to imagecopymergeWithAlphaFix on the next line, which passes them to imagecopy. This function expects integers and therefore gives the warning that the OP reported. I think the same is true for the ImageMagick adapter as it handles it in the same way.

For what it's worth - when debugging this I didn't see any warnings at all in the system or debug log, only managing to get the output the OP saw by wrapping the call to createWatermarkBasedOnPosition in a try/catch. The only sign I had that something was wrong was several missing folders in media/catalog/product/cache which relate to the sizes that were being silently skipped. Generating the images from the command line also gave no errors/warnings. It's worth noting that I couldn't find anything in the documentation regarding the use of odd dimensions with image sizes.

I patched this for our instances (2.4.4) by explicitly casting the resulting positions to integers. It works for us but your results may vary.

index af08cb5..2191f34 100644
--- a/vendor/magento/framework/Image/Adapter/Gd2.php
+++ b/vendor/magento/framework/Image/Adapter/Gd2.php
@@ -538,8 +538,8 @@ class Gd2 extends AbstractAdapter
         } elseif ($this->getWatermarkPosition() == self::POSITION_STRETCH) {
             $watermark = $this->createWaterMark($watermark, $this->_imageSrcWidth, $this->_imageSrcHeight);
         } elseif ($this->getWatermarkPosition() == self::POSITION_CENTER) {
-            $positionX = $this->_imageSrcWidth / 2 - imagesx($watermark) / 2;
-            $positionY = $this->_imageSrcHeight / 2 - imagesy($watermark) / 2;
+            $positionX = (int) ($this->_imageSrcWidth / 2 - imagesx($watermark) / 2);
+            $positionY = (int) ($this->_imageSrcHeight / 2 - imagesy($watermark) / 2);
             $this->imagecopymergeWithAlphaFix(
                 $this->_imageHandler,
                 $watermark,

And for ImageMagick:

index 5cfa7fe..099a960 100644
--- a/vendor/magento/framework/Image/Adapter/ImageMagick.php
+++ b/vendor/magento/framework/Image/Adapter/ImageMagick.php
@@ -326,8 +326,8 @@ class ImageMagick extends AbstractAdapter
                 $watermark->sampleImage($this->_imageSrcWidth, $this->_imageSrcHeight);
                 break;
             case self::POSITION_CENTER:
-                $positionX = ($this->_imageSrcWidth - $watermark->getImageWidth()) / 2;
-                $positionY = ($this->_imageSrcHeight - $watermark->getImageHeight()) / 2;
+                $positionX = (int) (($this->_imageSrcWidth - $watermark->getImageWidth()) / 2);
+                $positionY = (int) (($this->_imageSrcHeight - $watermark->getImageHeight()) / 2);
                 break;
             case self::POSITION_TOP_RIGHT:
                 $positionX = $this->_imageSrcWidth - $watermark->getImageWidth();

@benyatesvortex
Copy link

I've had this same issue with more or less the exact experience as @craig-bartlett . This is a bug in the code and the ticket needs reopening.

One thing I would add, you can generate the error by running bin/magento catalog:image:resize (I saved time by hardcoding the particular image I was having trouble with)

@hostep
Copy link
Contributor

hostep commented Oct 22, 2022

@sdzhepa, @engcom-Dash: can we reopen this ticket and redo the testing based on the last 2 comments?
@craig-bartlett: maybe if you find some time, try opening a Pull Request here with your fixes, it might get fixed quicker that way.

Thanks! 🙂

craig-bartlett added a commit to craig-bartlett/magento2 that referenced this issue Oct 26, 2022
- Cast resized image dimensions from floats to integers for GD and ImageMagick as imagecopy expects ints
craig-bartlett added a commit to craig-bartlett/magento2 that referenced this issue Oct 26, 2022
…ints

magento#35535: Magento 2.4.4 Mini cart item images not showing
@craig-bartlett
Copy link
Contributor

@hostep Sorry I've not had much free time lately - the PR attached is how I fixed the issue on our instances. Hopefully I created the PR correctly, please advise if not!

@hostep
Copy link
Contributor

hostep commented Oct 26, 2022

Awesome, thanks!

@engcom-Dash
Copy link

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

@engcom-Dash
Copy link

Hello @khoimm92 ,
We have tried to reproduce the issue in Magento 2.4.4 issue is not reproducible.

Please refer the below screenshot for the reference;
Screenshot 2022-10-28 at 9 22 32 PM

We have followed the below steps in order to reproduce the issue:
1.Add Products to Cart that all products have images
2.Open Mini-cart
3.Images Displaying in Mini Cart Page
Let us know in case we have missed anything. Thanks

@engcom-Dash engcom-Dash added the Issue: needs update Additional information is require, waiting for response label Oct 31, 2022
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Oct 31, 2022
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board Oct 31, 2022
@engcom-Lima engcom-Lima removed the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Oct 31, 2022
@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Oct 31, 2022
@engcom-Lima engcom-Lima added Progress: PR in progress Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Oct 31, 2022
@m2-community-project m2-community-project bot removed this from Pull Request In Progress in High Priority Backlog Oct 31, 2022
@m2-community-project m2-community-project bot removed the Issue: needs update Additional information is require, waiting for response label Oct 31, 2022
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Oct 31, 2022
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board Oct 31, 2022
@craig-bartlett
Copy link
Contributor

@engcom-Dash

Hi, for reference the following steps are required to trigger the bug:

  • The instance must be running PHP 8.1
  • The theme's image size must have an odd height and/or width
  • The water mark must be enabled
  • The water mark must be set to centred

As @benyatesvortex said above - you can trigger the error after by running bin/magento catalog:image:resize

@engcom-Lima engcom-Lima added Component: Theme Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Cart & Checkout Reported on 2.4.4 Indicates original Magento version for the Issue report. Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Oct 31, 2022
@github-jira-sync-bot
Copy link

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

@m2-assistant
Copy link

m2-assistant bot commented Oct 31, 2022

✅ Confirmed by @engcom-Lima. Thank you for verifying the issue.
Issue Available: @engcom-Lima, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@WouterSteen
Copy link

WouterSteen commented Nov 22, 2022

Its not only cart and checkout, its on every page where an image from a product exists.

When passing the positionX and positionY to this function, its always an int. But it can become a float when caculations are made.

That happens not only on line https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L541

But also on:

https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L542
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L580
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Cart & Checkout Component: Theme Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
10 participants