Skip to content

Commit 99b944e

Browse files
committed
Created a shell script to create a number of categories
1 parent 91b9091 commit 99b944e

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

scripts/abstract.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
use \Magento\Framework\AppInterface as AppInterface;
3+
use \Magento\Framework\App\Http as Http;
4+
5+
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
6+
use Magento\Framework\App\Request\Http as RequestHttp;
7+
use Magento\Framework\App\Response\Http as ResponseHttp;
8+
use Magento\Framework\Event;
9+
use Magento\Framework\Filesystem;
10+
use Magento\Framework\App\AreaList as AreaList;
11+
use Magento\Framework\App\State as State;
12+
13+
class AbstractApp implements AppInterface
14+
{
15+
public function __construct(
16+
\Magento\Framework\ObjectManagerInterface $objectManager,
17+
Event\Manager $eventManager,
18+
AreaList $areaList,
19+
RequestHttp $request,
20+
ResponseHttp $response,
21+
ConfigLoaderInterface $configLoader,
22+
State $state,
23+
Filesystem $filesystem,
24+
\Magento\Framework\Registry $registry
25+
) {
26+
$this->_objectManager = $objectManager;
27+
$this->_eventManager = $eventManager;
28+
$this->_areaList = $areaList;
29+
$this->_request = $request;
30+
$this->_response = $response;
31+
$this->_configLoader = $configLoader;
32+
$this->_state = $state;
33+
$this->_filesystem = $filesystem;
34+
$this->registry = $registry;
35+
}
36+
37+
public function launch()
38+
{
39+
return $this->_response;
40+
}
41+
42+
public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
43+
{
44+
return false;
45+
}
46+
}

scripts/create-categories.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
require dirname(__FILE__) . '/../app/bootstrap.php';
3+
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
4+
require dirname(__FILE__) . '/abstract.php';
5+
6+
class CreateCategoriesApp extends AbstractApp
7+
{
8+
9+
public function launch()
10+
{
11+
$this->_objectManager->get('Magento\Framework\Registry')
12+
->register('isSecureArea', true);
13+
14+
for ($i=0; $i<200; ++$i) {
15+
$newCategoryName = 'Performance Category ' .$i;
16+
17+
/** @var Magento\Catalog\Model\Category\Interceptor $newCategory */
18+
$newCategory = $this->_objectManager->create('\Magento\Catalog\Model\Category');
19+
$existingCategory = $newCategory->loadByAttribute('name', $newCategoryName);
20+
21+
if (!$existingCategory) {
22+
$newCategory->setData(
23+
array(
24+
'name' => $newCategoryName,
25+
'parent_id' => Magento\Catalog\Model\Category::TREE_ROOT_ID,
26+
'attribute_set_id' => $newCategory->getDefaultAttributeSetId(),
27+
'path' => Magento\Catalog\Model\Category::TREE_ROOT_ID,
28+
)
29+
);
30+
$newCategory->save();
31+
32+
echo "Created\t" . $newCategoryName . PHP_EOL;
33+
} else {
34+
$newCategory->delete();
35+
echo "Deleting\t" . $newCategoryName . PHP_EOL;
36+
}
37+
}
38+
39+
return parent::launch();
40+
}
41+
}
42+
43+
/** @var \Magento\Framework\App\Http $app */
44+
$app = $bootstrap->createApplication('CreateCategoriesApp');
45+
$bootstrap->run($app);
46+
47+

0 commit comments

Comments
 (0)