From 99b944e67cd362fc9cbe27e9e4cfc3f04c9f15fc Mon Sep 17 00:00:00 2001 From: convenient Date: Sun, 2 Aug 2015 17:29:42 +0100 Subject: [PATCH] Created a shell script to create a number of categories --- scripts/abstract.php | 46 ++++++++++++++++++++++++++++++++++ scripts/create-categories.php | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 scripts/abstract.php create mode 100644 scripts/create-categories.php diff --git a/scripts/abstract.php b/scripts/abstract.php new file mode 100644 index 0000000000000..d882478730702 --- /dev/null +++ b/scripts/abstract.php @@ -0,0 +1,46 @@ +_objectManager = $objectManager; + $this->_eventManager = $eventManager; + $this->_areaList = $areaList; + $this->_request = $request; + $this->_response = $response; + $this->_configLoader = $configLoader; + $this->_state = $state; + $this->_filesystem = $filesystem; + $this->registry = $registry; + } + + public function launch() + { + return $this->_response; + } + + public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception) + { + return false; + } +} diff --git a/scripts/create-categories.php b/scripts/create-categories.php new file mode 100644 index 0000000000000..6a4ac3b6e1877 --- /dev/null +++ b/scripts/create-categories.php @@ -0,0 +1,47 @@ +_objectManager->get('Magento\Framework\Registry') + ->register('isSecureArea', true); + + for ($i=0; $i<200; ++$i) { + $newCategoryName = 'Performance Category ' .$i; + + /** @var Magento\Catalog\Model\Category\Interceptor $newCategory */ + $newCategory = $this->_objectManager->create('\Magento\Catalog\Model\Category'); + $existingCategory = $newCategory->loadByAttribute('name', $newCategoryName); + + if (!$existingCategory) { + $newCategory->setData( + array( + 'name' => $newCategoryName, + 'parent_id' => Magento\Catalog\Model\Category::TREE_ROOT_ID, + 'attribute_set_id' => $newCategory->getDefaultAttributeSetId(), + 'path' => Magento\Catalog\Model\Category::TREE_ROOT_ID, + ) + ); + $newCategory->save(); + + echo "Created\t" . $newCategoryName . PHP_EOL; + } else { + $newCategory->delete(); + echo "Deleting\t" . $newCategoryName . PHP_EOL; + } + } + + return parent::launch(); + } +} + +/** @var \Magento\Framework\App\Http $app */ +$app = $bootstrap->createApplication('CreateCategoriesApp'); +$bootstrap->run($app); + +