Skip to content

Create product programmatically, addImageToMediaGallery throws exception (v2.1.0) #5249

@cizgidekiadam

Description

@cizgidekiadam

Steps to reproduce

  1. Install Magento with composer create-project
  2. Create custom script for create sample product.
  3. All images in pub/media/jpg folder
  4. Code:
$product = $objectManager->create(Magento\Catalog\Model\Product::class);
   $product->setTypeId(Type::TYPE_SIMPLE)
   ->setAttributeSetId($attributeSetId)
   ->setWebsiteIds([1])
   ->setName($name)
   ->setSku($sku)
   ->setPrice(100)
   ->setStatus(Status::STATUS_ENABLED)
   ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]);
   $imagePath = "jpg/SKU.jpg";
   $product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), false, false);
   $productRepository->save($product);

Expected result

  1. Product with image and a cup of coffee 😒

Actual result

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogEvent: distributed-cdDistributed Contribution DayIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions