Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_new.php
Go to the documentation of this file.
1 <?php
9 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
10  ->setAttributeSetId(4)
11  ->setName('New Product')
12  ->setSku('simple')
13  ->setPrice(10)
14  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
15  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
16  ->setWebsiteIds([1])
17  ->setStockData(['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1])
18  ->setNewsFromDate(date('Y-m-d', strtotime('-2 day')))
19  ->setNewsToDate(date('Y-m-d', strtotime('+2 day')))
20  ->setDescription('description')
21  ->setShortDescription('short desc')
22  ->save();
$product
Definition: products_new.php:8