3

When I add a view.xml file to my theme I get the following error:

Exception #0 (Magento\Framework\View\Asset\File\NotFoundException): Unable to resolve the source file for 'frontend/Holy/mytheme/en_GB/Magento_Catalog/images/product/placeholder/.jpg' error message

I can fix it by uploading new product placeholder images on the Magento admin.

Is there another way to avoid this error? Why is this error occurring in the first place?

3

In my case I had to add the requested image-format to my theme's view.xml file, for example:

<?xml version="1.0"?>    
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
        <media>
            <images module="Magento_Catalog">
                <image id="bundled_product_customization_page" type="thumbnail">
                    <width>140</width>
                    <height>140</height>
                </image>
    [...]
1

I have resolved this issue using below solution:

Please inject

\Magento\Store\Model\App\Emulation $appEmulation,

$sku = "my-sku";
// get the store ID from somewhere (maybe a specific store?)
$storeId = $this->storeManager->getStore()->getId();
// emulate the frontend environment
$this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
// load the product however you want
$product = $this->productRepositoryFactory->create()->get($sku);
// now the image helper will get the correct URL with the frontend environment emulated
$imageUrl = $this->imageHelperFactory->create()
  ->init($product, 'product_thumbnail_image')->getUrl();
// end emulation
$this->appEmulation->stopEnvironmentEmulation();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.