Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_base.php
Go to the documentation of this file.
1 <?php
12 $testCases = include __DIR__ . '/_algorithm_base_data.php';
13 
16  \Magento\Catalog\Setup\CategorySetup::class
17 );
23 $category->isObjectNew(true);
24 $category->setId(
25  3
26 )->setName(
27  'Root Category'
28 )->setParentId(
29  2
30 )->setPath(
31  '1/2/3'
32 )->setLevel(
33  2
34 )->setAvailableSortBy(
35  'name'
36 )->setDefaultSortBy(
37  'name'
38 )->setIsActive(
39  true
40 )->setPosition(
41  1
42 )->save();
43 
45 foreach ($testCases as $index => $testCase) {
47  \Magento\Catalog\Model\Category::class
48  );
49  $position = $index + 1;
50  $categoryId = $index + 4;
51  $category->isObjectNew(true);
52  $category->setId(
53  $categoryId
54  )->setName(
55  'Category ' . $position
56  )->setParentId(
57  3
58  )->setPath(
59  '1/2/3/' . $categoryId
60  )->setLevel(
61  3
62  )->setAvailableSortBy(
63  'name'
64  )->setDefaultSortBy(
65  'name'
66  )->setIsActive(
67  true
68  )->setIsAnchor(
69  true
70  )->setPosition(
71  $position
72  )->setUrlKey(
73  'category_' . $categoryId
74  )->save();
75 
76  foreach ($testCase[0] as $price) {
78  \Magento\Catalog\Model\Product::class
79  );
81  $product->setId(
83  )->setTypeId(
84  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
85  )->setAttributeSetId(
86  $installer->getAttributeSetId('catalog_product', 'Default')
87  )->setStoreId(
88  1
89  )->setWebsiteIds(
90  [1]
91  )->setName(
92  'Simple Product ' . $productId
93  )->setSku(
94  'simple-' . $productId
95  )->setPrice(
96  $price
97  )->setStockData(
98  [
99  'qty' => 100,
100  'is_in_stock' => 1,
101  'manage_stock' => 1,
102  ]
103  )->setWeight(
104  18
105  )->setCategoryIds(
106  [$categoryId]
107  )->setVisibility(
108  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
109  )->setStatus(
110  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
111  )->save();
112  ++$lastProductId;
113  }
114 }
$installer
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$price
$testCases
$category
$lastProductId
$index
Definition: list.phtml:44