yireo / Yireo_Webp2

Magento 2 module to add WebP support to Magento 2
Open Software License 3.0
197 stars 57 forks source link

Configurable products throwing error if cache is not generated already. #67

Closed AbdulSamadAbbasi closed 3 years ago

AbdulSamadAbbasi commented 3 years ago

I installed fresh magento 2 and thus all the catalog product cache was cleared. Then I tried running this extension and it threw error for changing swatches and gallery images. The reason, in my view, is that since magento creates cache when the image gets loaded, so maybe for swatches/gallery images, we're calling plugin that do all work before letting magento create the cached image that's why it couldn't find source image and throw exception? Anyone else facing same issue?

jissereitsma commented 3 years ago

Thanks for posting. I've tried it out myself and am not getting any issues. Could you comment on a couple of things? For instance, which version of Magento are you using? Which versions of Yireo_Webp2 and Yireo_NextGenImages? Also, what is the exact error message?

AbdulSamadAbbasi commented 3 years ago

Magento version 2.4.1, Webp2 0.10.4 NextGenImages 0.1.1. The error was thrown because of write permissions, I sort that out but still if the cache is not already generated for swatches and gallery images, it opts for .jpg and not .webp. Once that cache is generated, it works fine. No issue with other images, just changing swatches and gallery images create problems.

jissereitsma commented 3 years ago

Thanks. An error normally means an exception in the Developer Mode. Could you copy and paste that exception? Current releases are designed to intercept all exceptions. There might be something still missing, but without a backtrace it is impossible to troubleshoot.

AbdulSamadAbbasi commented 3 years ago

{"0":"WebP URL \"http:\/\/local.magento242\/media\/catalog\/product\/cache\/18cc112e399f3b9252770d5114f12deb\/w\/t\/wt09-yellow_main_1.webp\" does not exist","1":"#1 Vendor\\WebpImageOptimization\\Plugin\\AddWebpToSwatchesAjaxData->replaceUrls() called at [app\/code\/Vendor\/WebpImageOptimization\/Plugin\/AddWebpToSwatchesAjaxData.php:86]\n#2 Vendor\\WebpImageOptimization\\Plugin\\AddWebpToSwatchesAjaxData->afterGetProductMediaGallery() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:146]\n#3 Magento\\Swatches\\Helper\\Data\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#4 Magento\\Swatches\\Helper\\Data\\Interceptor->___callPlugins() this kinda error. and it's only coming when I flush magento catalog image cache. All the images it loads from cache will be uploaded in .jpg and not .webp, but only for the first time. Once magento creates cache for those images, next time it load .webp. Same goes with swatches and gallery images. They throw not found error when they couldn't find source image in specified cache folder for the very first time. Maybe I should suppose that cached images are always pre-generated in real life scenario? FYI, if I run magento:catalog:resize command, everything is in place then, no errors.

jissereitsma commented 3 years ago

Thanks. I'm really confused though. You say that this error is caused by the Yireo Webp2 extension which would be either installed in app/code/Yireo/Webp2 or vendor/yireo/magento2-webp2. However, the error is mentioning a path app/code/Vendor/WebpImageOptimization. So it seems it is not the code of my extension doing this.

AbdulSamadAbbasi commented 3 years ago

Sorry for that, but I'm running your extension in another instance of Magento2.4.1, it doesn't throw error but if you follow above steps, it'd load .jpg/png for the very first time, by the first time I mean, when there is NO images in cache folder. Once Magento creates cache, which it does on page load, then after clearing cache and reloading page for second time would solve things for me. In a nutshell, we're doing things before magento creates cache on load, that's why it loads .jpg. Maybe you haven't tried it with flushing cache folder and then see on browser by inspecting what images it loads for first time, .jpg/png or .webp?

jissereitsma commented 3 years ago

Ok, so there is no exception that needs to be dealt with? Because the current code prevents an exception and whatever I do, this seems to work on my end.

If there is indeed no exception, it seems you are addressing a different issue instead: The issue is that WebP images are not generated, if the original images are not resized yet by Magento. I think this behaviour is more than correct and there is little to do here. It either requires you to do a reload of the page, or to manually convert WebP images beforehand.

AbdulSamadAbbasi commented 3 years ago

Yes, that's exactly what I'm talking about. Sorry, I thought we could handle it perhaps by finding a plugin which checks for this and convert without reloading of page. Thanks for clarifying, sorry again and you can just delete this issue, I'm closing from my side.