Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_associated.php
Go to the documentation of this file.
1 <?php
7 /* Create simple product */
10 $product->setTypeId(
11  'simple'
12 )->setId(
13  1
14 )->setAttributeSetId(
15  4
16 )->setWebsiteIds(
17  [1]
18 )->setName(
19  'Simple Product'
20 )->setSku(
21  'simple'
22 )->setPrice(
23  10
24 )->setWeight(
25  1
26 )->setMetaTitle(
27  'meta title'
28 )->setMetaKeyword(
29  'meta keyword'
30 )->setMetaDescription(
31  'meta description'
32 )->setVisibility(
33  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
34 )->setStatus(
35  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
36 )->setStockData(
37  ['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1]
38 )->save();