Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_simple.php
Go to the documentation of this file.
1 <?php
7 
10  ->create(\Magento\Catalog\Model\Product::class);
11 $product->isObjectNew(true);
12 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
13  ->setAttributeSetId(4)
14  ->setWebsiteIds([1])
15  ->setName('Simple Products')
16  ->setSku('simple products')
17  ->setPrice(10)
18  ->setWeight(1)
19  ->setShortDescription("Short description")
20  ->setTaxClassId(0)
21  ->setTierPrice(
22  [
23  [
24  'website_id' => 0,
25  'cust_group' => Group::NOT_LOGGED_IN_ID,
26  'price_qty' => 2,
27  'price' => 8,
28  ],
29  [
30  'website_id' => 0,
31  'cust_group' => Group::CUST_GROUP_ALL,
32  'price_qty' => 21,
33  'price' => 81,
34  ],
35  [
36  'website_id' => 0,
37  'cust_group' => Group::CUST_GROUP_ALL,
38  'price_qty' => 30,
39  'percentage_value' => 50,
40  ],
41  ]
42  )
43  ->setDescription('Description with <b>html tag</b>')
44  ->setMetaTitle('meta title')
45  ->setMetaKeyword('meta keyword')
46  ->setMetaDescription('meta description')
47  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
48  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
49  ->setUrlKey('url-key')
50  ->setUrlPath('url-key')
51  ->save();
$product