您好我发现堆栈上的代码可以将产品上传到magento2但是我有多个图像说简单的产品多个图像幻灯片但我在下面的代码中看不到添加单个产品图像或变化图像的选项
use Magento\Framework\App\Bootstrap;
include("app/bootstrap.php");
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$simple_product = $objectManager->create('\Magento\Catalog\Model\Product');
$simple_product->setSku('tops123');
$simple_product->setName('tops');
$simple_product->setAttributeSetId(4);;
$simple_product->setCategories('Default Category/Women');
$simple_product->setStatus(1);
$simple_product->setTypeId('simple');
$simple_product->setPrice(10);
$simple_product->setWebsiteIds(array(1));
$simple_product->setCategoryIds(array(31));
$simple_product->setUrlKey ('tops343225');
$simple_product->setColor('Red');
$simple_product->setStockData(array(
'use_config_manage_stock' => 0, //'Use config settings' checkbox
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => 1, //Stock Availability
'qty' => 100 //qty
)
);
$simple_product->save();
$simple_product_id = $simple_product->getId();
echo "simple product id: ".$simple_product_id."\n";