Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_in_category.php
Go to the documentation of this file.
1 <?php
9 $product->setTypeId(
10  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
11 )->setId(
12  333
13 )->setAttributeSetId(
14  4
15 )->setName(
16  'Simple Related Product'
17 )->setSku(
18  'simple'
19 )->setPrice(
20  10
21 )->setVisibility(
22  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
23 )->setStatus(
24  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
25 )->setWebsiteIds(
26  [1]
27 )->setStockData(
28  ['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1]
29 )->save();
30 
31 $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
32 $product->setTypeId(
33  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
34 )->setId(
35  334
36 )->setAttributeSetId(
37  4
38 )->setName(
39  'Simple Product With Related Product'
40 )->setSku(
41  'simple_with_cross'
42 )->setPrice(
43  10
44 )->setVisibility(
45  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
46 )->setStatus(
47  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
48 )->setWebsiteIds(
49  [1]
50 )->setStockData(
51  ['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1]
52 )->save();
53 
56 $category->isObjectNew(true);
57 $category->setId(
58  333
59 )->setCreatedAt(
60  '2014-06-23 09:50:07'
61 )->setName(
62  'Category 1'
63 )->setParentId(
64  2
65 )->setPath(
66  '1/2/3'
67 )->setLevel(
68  2
69 )->setAvailableSortBy(
70  'name'
71 )->setDefaultSortBy(
72  'name'
73 )->setIsActive(
74  true
75 )->setPosition(
76  1
77 )->setAvailableSortBy(
78  ['position']
79 )->setPostedProducts(
80  [333 => 10]
81 )->save();