3

I had a problem adding a product image programatically. Here's the code I used:

$product->setImage('/test.jpg')
    ->setSmallImage('/test.jpg')
    ->setThumbnail('/test.jpg')
    ->addImageToMediaGallery('/test.jpg', array('image','thumbnail','small_image'), false, false);

$product = $productRepository->save($product);

When run, it throws this error:

Uncaught exception 'Magento\Framework\Exception\LocalizedException' with message 'There is no MediaGalleryEntryConverter for given type' in vendor/magento/module-catalog/Model/Product/Attribute/Backend/Media/EntryConverterPool.php:48

when I save product and try to update like this link: $product->save();

Throws this error:

Fatal error:Uncaught InvalidArgumentException: Required parameter 'theme_dir' was not passed in .../vendor/magento/framework/View/Design/Fallback/Rule/Simple.php:61

Any ideas ?

2

Maybe you should initialize the gallery first:

->setMediaGallery (array('images'=>array (), 'values'=>array ())) 
->addImageToMediaGallery('/test.jpg', array('image','thumbnail','small_image'), false, false);
| improve this answer | |
1

In your back-end, go to Content > Design > Configuration. Then set the themes of your front-end. Save it. Then the issue should go away.

Cheers,

Renato.

| improve this answer | |
1

You may check the new product gallery management classes for Magento 2.1 here:

vendor/magento/module-catalog/Model/Product/Gallery/*

| improve this answer | |
1

I found the solution for if someone needs future, This is theme configuration file problem when I update 2.0.x to 2.1 forgot to update all necessary theme files settings to 2.1, after that my problem solved.

| improve this answer | |

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.