-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a shell script to create a number of categories
- Loading branch information
1 parent
91b9091
commit 99b944e
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|