Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
simple_product.php
Go to the documentation of this file.
1 <?php
9 $product->setTypeId(
10  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
11 )->setId(
12  1
13 )->setAttributeSetId(
14  4
15 )->setWebsiteIds(
16  [1]
17 )->setName(
18  'Simple Product'
19 )->setSku(
20  'simple'
21 )->setPrice(
22  10
23 )->setDescription(
24  'Description with <b>html tag</b>'
25 )->setMetaTitle(
26  'meta title'
27 )->setMetaKeyword(
28  'meta keyword'
29 )->setMetaDescription(
30  'meta description'
31 )->setVisibility(
32  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
33 )->setStatus(
34  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
35 )->setCategoryIds(
36  [2]
37 )->setStockData(
38  ['use_config_manage_stock' => 0]
39 )->setCanSaveCustomOptions(
40  true
41 )->setHasOptions(
42  true
43 )->save();
$product