Skip to content

Instantly share code, notes, and snippets.

@memoryleak
Created April 27, 2015 14:24
Show Gist options
  • Select an option

  • Save memoryleak/d5d5be8410fd9cab62f9 to your computer and use it in GitHub Desktop.

Select an option

Save memoryleak/d5d5be8410fd9cab62f9 to your computer and use it in GitHub Desktop.
<?php
require_once 'abstract.php';
class Nudorm_Shell_Category extends Mage_Shell_Abstract
{
/**
* Run script
*
*/
public function run()
{
if (!$this->getArg('import') && !$this->getArg('export')) {
print $this->usageHelp();
return;
}
if ($this->getArg('import') && !is_readable($this->getArg('file'))) {
printf("Provided file path '%s' is not readable.", is_readable($this->getArg('file')));
print $this->usageHelp();
return;
}
if ($this->getArg('export') && !is_writable($this->getArg('file'))) {
printf("Provided file path '%s' is not writable.", is_readable($this->getArg('file')));
print $this->usageHelp();
return;
}
$this->stores = Mage::app()->getStores();
}
protected function export()
{
foreach ($this->stores as $store) {
if(!is_array($this->categories[$store->getCode()])) {
$this->categories[$store->getCode()] = array();
}
Mage::setCurrentStore($store->getId());
$categoryCollection = Mage::getModel('catalog/category')->getCollection()->load();
foreach ($categoryCollection as $category) {
$this->categories[$store->getCode()] = $category->getData();
unset($this->categories[$store->getCode()]['entity_id']);
}
}
print_r($this->categories);
}
protected function import()
{
}
protected function findCategory($store, $name)
{
}
protected function saveCategory($store, $name)
{
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f indexer.php -- [options]
--file <path> File to use for import/export
import Import categories from provided file
export Export categories to provided file
help This help
<path> Path to a file to use for import/export
USAGE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment