-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions (*)
- Magento 2.2.8 & 2.3.1
Steps to reproduce (*)
- Add image trough \Magento\Catalog\Model\Product\Gallery\Processor->addImage
- With $product, relative path, $options and true, false
Expected result (*)
- Image should be added to the product
Actual result (*)
- Exception will be raised:
[InvalidArgumentException]
File 'pub/media/import/' doesn't exist
I blocked out the prefix and suffix to the file location but these are correct. The error is because of the following:
In file: Magento\Catalog\Model\Product\Gallery\Processor
Function: addImage
Lines: 194, 195, 196
With "$absoluteFilePath = $this->mediaDirectory->getAbsolutePath($file);" the absolute path to the file in pub/media/import will be resolved. In theory this is correct. However the lines 175 till 190 can possibly move the image to a other directory. When this happens $absoluteFilePath will be filled with a path that is the old path before the move was done since it uses the variable $file. Thus resulting on $this->mime->getMimeType($absoluteFilePath); giving an exception that the file doesn't exist anymore.
Possible fix is by moving lines 194, 195, 196 to above line 175 so the checks are done before the file will be moved.