Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_with_image.php
Go to the documentation of this file.
1 <?php
7 require __DIR__ . '/product_image.php';
8 require __DIR__ . '/product_simple.php';
9 
11 $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
12 $product = $productRepository->get('simple');
13 
15 $product->setStoreId(0)
16  ->setImage('/m/a/magento_image.jpg')
17  ->setSmallImage('/m/a/magento_image.jpg')
18  ->setThumbnail('/m/a/magento_image.jpg')
19  ->setData('media_gallery', ['images' => [
20  [
21  'file' => '/m/a/magento_image.jpg',
22  'position' => 1,
23  'label' => 'Image Alt Text',
24  'disabled' => 0,
25  'media_type' => 'image'
26  ],
27  ]])
28  ->setCanSaveCustomOptions(true)
29  ->save();
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$objectManager
$productRepository