Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
category_product.php
Go to the documentation of this file.
1 <?php
8 $category->isObjectNew(true);
9 $category->setId(
10  333
11 )->setCreatedAt(
12  '2014-06-23 09:50:07'
13 )->setName(
14  'Category 1'
15 )->setParentId(
16  2
17 )->setPath(
18  '1/2/3'
19 )->setLevel(
20  2
21 )->setAvailableSortBy(
22  'name'
23 )->setDefaultSortBy(
24  'name'
25 )->setIsActive(
26  true
27 )->setPosition(
28  1
29 )->setAvailableSortBy(
30  ['position']
31 )->save();
32 
35 $product->setTypeId(
36  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
37 )->setId(
38  333
39 )->setAttributeSetId(
40  4
41 )->setStoreId(
42  1
43 )->setWebsiteIds(
44  [1]
45 )->setName(
46  'Simple Product Three'
47 )->setSku(
48  'simple333'
49 )->setPrice(
50  10
51 )->setWeight(
52  18
53 )->setStockData(
54  ['use_config_manage_stock' => 0]
55 )->setCategoryIds(
56  [333]
57 )->setVisibility(
58  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
59 )->setStatus(
60  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
61 )->save();
$category