Skip to content

Commit

Permalink
Created a shell script to create a number of categories
Browse files Browse the repository at this point in the history
  • Loading branch information
convenient committed Aug 2, 2015
1 parent 91b9091 commit 99b944e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
46 changes: 46 additions & 0 deletions scripts/abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
use \Magento\Framework\AppInterface as AppInterface;
use \Magento\Framework\App\Http as Http;

use Magento\Framework\ObjectManager\ConfigLoaderInterface;
use Magento\Framework\App\Request\Http as RequestHttp;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\Event;
use Magento\Framework\Filesystem;
use Magento\Framework\App\AreaList as AreaList;
use Magento\Framework\App\State as State;

class AbstractApp implements AppInterface
{
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
Event\Manager $eventManager,
AreaList $areaList,
RequestHttp $request,
ResponseHttp $response,
ConfigLoaderInterface $configLoader,
State $state,
Filesystem $filesystem,
\Magento\Framework\Registry $registry
) {
$this->_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;
}
}
47 changes: 47 additions & 0 deletions scripts/create-categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
require dirname(__FILE__) . '/../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
require dirname(__FILE__) . '/abstract.php';

class CreateCategoriesApp extends AbstractApp
{

public function launch()
{
$this->_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);


0 comments on commit 99b944e

Please sign in to comment.