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

php bin/magento catalog:images:resize does not process hidden images. #28239

Closed
gwharton opened this issue May 15, 2020 · 24 comments · Fixed by #33452
Closed

php bin/magento catalog:images:resize does not process hidden images. #28239

gwharton opened this issue May 15, 2020 · 24 comments · Fixed by #33452
Assignees
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch improvement Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@gwharton
Copy link
Contributor

gwharton commented May 15, 2020

Preconditions (*)

  1. Magento 2.4-develop

Steps to reproduce (*)

  1. Create a Product
  2. Assign Image 1 to product and set to be visible on product page
  3. Assign Image 2 to product and set to be hidden on product page
  4. Save the product

Expected result (*)

  1. View the product page, only Image 1 should be visible
  2. pub/media/catalog/cache folder should contain resized Image 1's
  3. pub/media/catalog/cache folder should contain resized Image 2's
  4. Clear image cache
  5. Run php bin/magento catalog:images:resize
  6. pub/media/catalog/cache folder should contain resized Image 1's
  7. pub/media/catalog/cache folder should contain resized Image 2's

Actual result (*)

  1. Only Image 1 is visible on product page ✅
  2. Image 1 is present in cache in resized states ✅
  3. Image 2 is present in cache in resized states ✅
  4. Cache is cleared ✅
  5. Image resize command processes 1 image, not 2 ❌
  6. pub/media/catalog/cache folder should contain resized Image 1's ✅
  7. pub/media/catalog/cache folder does not contain resized Image 2's ❌

Images that are hidden from the product page are not processed by the image resize command. They should be. Just because they are hidden from the product page, doesn't mean they won't be used elsewhere.

Magento is written so that hiding the product image, actually sets it to disabled.

IMHO setting a product image to disabled, and setting it to be hidden on product page are two very different settings, but magento currently treats them as the same.

The confusion stems from the hidden setting being stored in the database as the field disabled. A hidden image is NOT a disabled image, and should still be processed, just not displayed on the product page, otherwise, what is the point of the hidden setting?

Additional Information

#28239 (comment)

@m2-assistant
Copy link

m2-assistant bot commented May 15, 2020

Hi @gwharton. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

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

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.

@gwharton do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@ghost ghost added this to Ready for QA in Community Backlog May 15, 2020
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label May 15, 2020
@gwharton gwharton changed the title Product Image "Hide from Product Page" completely disables an Image, not just hides it from product Page php bin/magento catalog:images:resize does not process hidden images. May 15, 2020
@hemendraajmera
Copy link

I have also mentioned this issue as #28182

@gwharton
Copy link
Contributor Author

Note, this behaviour was introduced in commit 048a2ee

@engcom-Delta engcom-Delta self-assigned this May 25, 2020
@m2-assistant
Copy link

m2-assistant bot commented May 25, 2020

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

  • 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 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!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@ghost ghost moved this from Ready for QA to Dev in Progress in Community Backlog May 25, 2020
@gwharton
Copy link
Contributor Author

Looks like the change was made on purpose as an optimisation.

@engcom-Delta
Copy link
Contributor

HI @gwharton could you provide case where we can reuse same hidden image? Image uploaded for product cannot be used by media gallery and same image uploaded for another product has new name in database (name + increment index)
image

@gwharton
Copy link
Contributor Author

gwharton commented May 25, 2020

@engcom-Delta I have a separate custom written module that uploads product data to Google Shopping and Google My Business. I need to use different product images for Google feeds than on my front end, so when I create a product I upload two images, one for front end, and one hidden one for Google. My module then picks up this hidden image url and uses that on the google feeds.

The setting in Magento is named "Hide from Product Page", so seems like the perfect setting for me. And infact, it is the way that Magento works when you initially upload an image for a product. Setting it to hidden on the catalog page, DOES generate the cached images for it, regardless of its hidden state. The cached images only dissapear when you clear image cache and then regenerate using catalog:images:resize. There is an inconsistency there.

If this isn't going to be fixed for catalog:images:resize, then Magento should be changed so that it does not generate cached images for new hidden images when they are uploaded to make it consistent, i.e cached images are not generated for hidden images, and the setting should also be changed on the frontend to "Disabled" instead of "Hidden from product page" to reflect the actual setting that is applied.

@gwharton
Copy link
Contributor Author

gwharton commented May 25, 2020

In my module I call

$this->imageBuilder->setProduct($product)
                    ->setImageId('product_page_main_image_gmb')
                    ->setAttributes([])
                    ->create()
                    ->getImageUrl();

where product_page_main_image_gmb is a custom image type I have defined in my view.xml.

The url returned by this call returns a 404, when the image is "Hidden from product page" as the cached images were not processed by catalog:images:resize after an images cache clear.

@gwharton
Copy link
Contributor Author

Perhaps there should be 2 settings, "hidden" and "disabled"

@piyushbrainvire
Copy link

piyushbrainvire commented Jul 17, 2020

Due to this cart and wishlist page shows placeholder images if small/thumbnail image is set to Hide from Product page.
Any update on this?

@gwharton
Copy link
Contributor Author

gwharton commented Jul 17, 2020

You can manually apply a patch as a workaround.

composer require vaimo/composer-patches

patches/composer/imageresizeall.diff

--- Service/ImageResize.orig.php	2020-07-17 14:15:47.350000000 +0100
+++ Service/ImageResize.php	2020-07-17 14:25:30.870000000 +0100
@@ -180,12 +180,12 @@
      */
     public function resizeFromThemes(array $themes = null): Generator
     {
-        $count = $this->productImage->getCountUsedProductImages();
+        $count = $this->productImage->getCountAllProductImages();
         if (!$count) {
             throw new NotFoundException(__('Cannot resize images - product images not found'));
         }
 
-        $productImages = $this->productImage->getUsedProductImages();
+        $productImages = $this->productImage->getAllProductImages();
         $viewImages = $this->getViewImages($themes ?? $this->getThemesInUse());
 
         foreach ($productImages as $image) {

composer.json

    "extra": {
        "magento-force": "override",
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/module-media-storage": {
                "https://github.com/magento/magento2/issues/28239": "patches/composer/imageresizeall.diff"
            }
        }
    }

composer install

Works on 2.3.5-p1

@gwharton
Copy link
Contributor Author

Perhaps a compromise would be a command line argument --process-hidden-images with the default to not process hidden images??

@sidolov sidolov added this to Ready for Grooming in Low Priority Backlog Sep 24, 2020
@m2-community-project m2-community-project bot moved this from Ready for Grooming to Dev In Progress in Low Priority Backlog Sep 24, 2020
@Flipmediaco
Copy link

The wording "Hide from Product Page" implies the setting will only hide the image from the product page, but allowing the image to be used on the category listing page, wish list, compare, basket, any other use that is not product page... The original behaviour of only suppressing display of the image in the product page gallery is in line with the wording.

The optimisation of not generating images when "Hide from Product Page" is checked differs from the original intended purpose, which is clearly to stop supporting product images from displaying in the product page image gallery.

Many thanks to @gwharton for your patch, this works perfectly and allows the setting "Hide from Product Page" to be used as originally conceived.

@gwharton
Copy link
Contributor Author

gwharton commented Oct 6, 2020

The catalog:images:resize routine seems to have been butchered a bit lately, but the way I see it, there are two recent changes that would have been better suited to command line arguments to make them optional, than making it work the same for everyone.

--skip-hidden-images = Do not process images marked as hidden from product page
--skip-if-exists = Do not process an image, if it already exists. (Since #26801 If you change the image, but keep the filename the same, there is no way of regenerating that image, apart from clearing entire image cache)

Lets hope that because this went to dev in progress a few weeks ago, that someone from core are on it.

@ghost ghost unassigned engcom-Delta Oct 8, 2020
@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Grooming in Low Priority Backlog Oct 8, 2020
@gabrieldagama gabrieldagama added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Feb 25, 2021
@m2-community-project m2-community-project bot added this to Ready for Development in High Priority Backlog Feb 25, 2021
@BogdanGorbach
Copy link

@magento I am working on this

@m2-assistant
Copy link

m2-assistant bot commented Jul 10, 2021

Hi @BogdanGorbach! 👋
Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

@BogdanGorbach
Copy link

@magento add to contributors team

@m2-assistant
Copy link

m2-assistant bot commented Jul 10, 2021

Hi @BogdanGorbach! 👋
Thank you for joining. Please accept team invitation 👉 here 👈 and add your comment one more time.

@BogdanGorbach
Copy link

@magento I am working on this

@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in High Priority Backlog Jul 10, 2021
BogdanGorbach pushed a commit to BogdanGorbach/magento2 that referenced this issue Jul 10, 2021
- added new options --skip-hidden-images
- added new unit test
@m2-community-project m2-community-project bot moved this from Dev In Progress to Pull Request In Progress in High Priority Backlog Jul 10, 2021
BogdanGorbach pushed a commit to BogdanGorbach/magento2 that referenced this issue Jul 12, 2021
- Fixed Unit Test
- Removed unnecessary dependency in the constructor
BogdanGorbach pushed a commit to BogdanGorbach/magento2 that referenced this issue Jul 13, 2021
@gabrieldagama
Copy link
Contributor

Hi @gwharton. Thank you for your report.
The issue has been fixed in #33452 by @BogdanGorbach in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.3 release.

@gabrieldagama gabrieldagama added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Jul 29, 2021
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in High Priority Backlog Jul 29, 2021
mozok added a commit to mozok/devdocs that referenced this issue Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch improvement Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

Successfully merging a pull request may close this issue.

10 participants