Skip to content

Magento 2.3 Fix Notice and Exception while adding image to product programmatically #18952

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

Merged
merged 5 commits into from
Nov 16, 2018
Merged

Conversation

progreg
Copy link
Contributor

@progreg progreg commented Oct 30, 2018

Fixed Issues (if relevant)

  1. Product::addImageToMediaGallery throws Exception #6803: Product::addImageToMediaGallery throws Exception

Preconditions

Magento Version 2.3
PHP Version 7.2

Steps to reproduce

$product = $this->productFactory->create()
            ->setName($productName)
            ->setStatus($productStatus)
            ->setSku($productSku)
$product->setAttributeSetId($product->getDefaultAttributeSetId());

$product->addImageToMediaGallery($file, [
                'image',
                'small_image',
                'thumbnail',
            ], false, false);
$this->productRepository->save($product);

Expected result

Image gets added

Actual result

Exception gets thrown:

Notice: Undefined index: media_type in vendor/magento/module-catalog/Model/Product.php on line 2527

There's a workaround for this issue, using the Product::save method instead of the ProductRepositoryInterface::save method, but because it's a deprecated method I would like to avoid this.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@progreg progreg added Component: Catalog Fixed in 2.3.x The issue has been fixed in 2.3 release line labels Oct 30, 2018
@progreg progreg self-assigned this Oct 30, 2018
@magento-engcom-team
Copy link
Contributor

Hi @progreg. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me $VERSION instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@progreg progreg changed the title Fix Notice and Exception while adding image to product programmatically Magento 2.3 Fix Notice and Exception while adding image to product programmatically Oct 30, 2018
@progreg progreg removed the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Oct 30, 2018
@orlangur orlangur assigned orlangur and unassigned progreg Oct 30, 2018
@slavvka slavvka self-assigned this Oct 31, 2018
@progreg
Copy link
Contributor Author

progreg commented Nov 2, 2018

@orlangur , @slavvka please check if all change requests were implemented in a proper way from my side. Thanks

@slavvka
Copy link
Member

slavvka commented Nov 5, 2018

@orlangur , @slavvka please check if all change requests were implemented in a proper way from my side. Thanks

@progreg looks good. Please add an integration test to have this scenario checked automatically since this could be tested only programmatically.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.1 milestone Nov 9, 2018
@progreg
Copy link
Contributor Author

progreg commented Nov 12, 2018

@slavvka, done

@magento-engcom-team
Copy link
Contributor

Hi @slavvka, thank you for the review.
ENGCOM-3421 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @progreg. Thank you for your contribution.
We will aim to release these changes as part of 2.3.1.
Please check the release notes for final confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants