Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create categories
- */
- private function createCategories()
- {
- $storeId = $this->storeManager->getStore('default')->getId();
- $data = [
- [
- 'name' => 'Demo 1',
- 'url_key' => 'demo-1',
- 'position' => '10',
- 'is_active' => '1',
- 'parent_id' => '2',
- 'store_id' => $storeId,
- ],
- [
- 'name' => 'Demo 2',
- 'url_key' => 'demo-2',
- 'position' => '20',
- 'is_active' => '1',
- 'parent_id' => '2',
- 'store_id' => $storeId,
- ],
- [
- 'name' => 'Demo 3',
- 'url_key' => 'demo-3',
- 'position' => '30',
- 'is_active' => '1',
- 'parent_id' => '2',
- 'store_id' => $storeId,
- ],
- ];
- foreach ($data as $item) {
- $category = $this->categoryFactory->create();
- $category->setData($item)->save();
- $category->setData('path', '1/2/' . $category->getId())->save();
- }
- }
Add Comment
Please, Sign In to add comment