Guest User

Untitled

a guest
Apr 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /**
  2. * Create categories
  3. */
  4. private function createCategories()
  5. {
  6. $storeId = $this->storeManager->getStore('default')->getId();
  7.  
  8. $data = [
  9. [
  10. 'name' => 'Demo 1',
  11. 'url_key' => 'demo-1',
  12. 'position' => '10',
  13. 'is_active' => '1',
  14. 'parent_id' => '2',
  15. 'store_id' => $storeId,
  16. ],
  17. [
  18. 'name' => 'Demo 2',
  19. 'url_key' => 'demo-2',
  20. 'position' => '20',
  21. 'is_active' => '1',
  22. 'parent_id' => '2',
  23. 'store_id' => $storeId,
  24. ],
  25. [
  26. 'name' => 'Demo 3',
  27. 'url_key' => 'demo-3',
  28. 'position' => '30',
  29. 'is_active' => '1',
  30. 'parent_id' => '2',
  31. 'store_id' => $storeId,
  32. ],
  33. ];
  34.  
  35. foreach ($data as $item) {
  36. $category = $this->categoryFactory->create();
  37. $category->setData($item)->save();
  38. $category->setData('path', '1/2/' . $category->getId())->save();
  39. }
  40. }
Add Comment
Please, Sign In to add comment