Last active
September 28, 2015 15:20
-
-
Save paulmouzas/ac1fcda59dba5f07e2c0 to your computer and use it in GitHub Desktop.
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
<?php | |
require_once 'app/Mage.php'; | |
Mage::app(); | |
// $parent_category = new Mage_Catalog_Model_Category(); | |
// $id = $parent_category->getId(); | |
// print_r(id); | |
// $category = Mage::getModel('catalog/category'); | |
// $category->load(7); // set parent to be root category | |
// print_r($category->getPath()); | |
// ->setName('Classic Rock') | |
// ->setIsActive(1) | |
// ->save(); | |
function createSubCategory($parentId, $categoryName, $isActive) { | |
$parent = Mage::getModel('catalog/category'); | |
$parent->load($parentId); | |
$parentPath = $parent->getPath(); | |
$category = Mage::getModel('catalog/category'); | |
$category->setPath($parentPath) | |
->setName($categoryName) | |
->setIsActive($isActive) | |
->setData('include_in_menu', 0) | |
->save(); | |
} | |
$dir = new DirectoryIterator("./csvfiles"); | |
foreach ($dir as $fileinfo) { | |
if (!$fileinfo->isDot()) { | |
$fname = $fileinfo->getFilename(); | |
$basefname = basename($fname, ".csv"); | |
$parentId = intVal($basefname); | |
$fp = fopen("./csvfiles/" . $fname, "r"); | |
while($line = fgetcsv($fp)) { | |
$categoryName = $line[0]; | |
createSubCategory($parentId, $categoryName, 1); | |
} | |
fclose($fp); | |
} | |
} | |
// $parentId = 112; | |
//// open the file | |
// $fp = fopen("112.csv", "r"); | |
// while($line = fgetcsv($fp)) { | |
// $categoryName = $line[0]; | |
// createSubCategory($parentId, $categoryName, 1); | |
// } | |
// fclose($fp); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment