|
7 | 7 |
|
8 | 8 | namespace Magento\GraphQl\Catalog\ResolverCache;
|
9 | 9 |
|
| 10 | +use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory; |
10 | 11 | use Magento\Catalog\Api\Data\ProductInterface;
|
11 | 12 | use Magento\Catalog\Api\ProductManagementInterface;
|
12 | 13 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
|
15 | 16 | use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
16 | 17 | use Magento\CatalogGraphQl\Model\Resolver\Cache\Product\MediaGallery\ResolverCacheIdentity;
|
17 | 18 | use Magento\CatalogGraphQl\Model\Resolver\Product\MediaGallery;
|
| 19 | +use Magento\Framework\Api\Data\ImageContentInterfaceFactory; |
18 | 20 | use Magento\Framework\App\Area as AppArea;
|
19 | 21 | use Magento\Framework\App\ObjectManager\ConfigLoader;
|
20 | 22 | use Magento\Framework\App\State as AppState;
|
@@ -215,6 +217,35 @@ public function actionMechanismProvider(): array
|
215 | 217 | $productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
216 | 218 |
|
217 | 219 | return [
|
| 220 | + 'add new media gallery entry' => [ |
| 221 | + function (ProductInterface $product) use ($galleryManagement, $objectManager) { |
| 222 | + /** @var ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory */ |
| 223 | + $mediaGalleryEntryFactory = $objectManager->get( |
| 224 | + ProductAttributeMediaGalleryEntryInterfaceFactory::class |
| 225 | + ); |
| 226 | + |
| 227 | + /** @var ImageContentInterfaceFactory $imageContentFactory */ |
| 228 | + $imageContentFactory = $objectManager->get(ImageContentInterfaceFactory::class); |
| 229 | + $imageContent = $imageContentFactory->create(); |
| 230 | + $imageContent->setBase64EncodedData( |
| 231 | + // black 1x1 image |
| 232 | + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=' |
| 233 | + ); |
| 234 | + $imageContent->setType("image/png"); |
| 235 | + $imageContent->setName("new_image.png"); |
| 236 | + |
| 237 | + $newImage = $mediaGalleryEntryFactory->create(); |
| 238 | + $newImage->setDisabled(false); |
| 239 | + $newImage->setFile('/n/e/new_image.png'); |
| 240 | + $newImage->setLabel('New Image Alt Text'); |
| 241 | + $newImage->setMediaType('image'); |
| 242 | + $newImage->setPosition(2); |
| 243 | + $newImage->setContent($imageContent); |
| 244 | + |
| 245 | + $galleryManagement->create($product->getSku(), $newImage); |
| 246 | + }, |
| 247 | + true |
| 248 | + ], |
218 | 249 | 'update media label' => [
|
219 | 250 | function (ProductInterface $product) use ($galleryManagement) {
|
220 | 251 | $mediaEntry = $product->getMediaGalleryEntries()[0];
|
|
0 commit comments