-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewcategories.php
57 lines (44 loc) · 1.47 KB
/
newcategories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
require_once '/var/www/html/magento/app/Mage.php';
umask(0);
Mage::app('default');
$categories = file_get_contents('/var/www/html/magento/shell/Brand_20List.txt');
$categories = explode("\n", $categories);
foreach($categories as $categoryName) {
$categoryName = trim($categoryName);
if (empty($categoryName)) {
continue;
}
$separator = '-';
$catUrl = Mage::helper('catalog/product_url')->format($categoryName);
$url = preg_replace('#[^0-9a-z]+#i', $separator, $catUrl);
$url = strtolower($url);
$url = trim($url);
$parentCategory = Mage::getModel('catalog/category')->load(211);
$general['name'] = $categoryName;
$general['path'] = $parentCategory->getPath(); // catalog path
$general['meta_title'] = $categoryName; //page title
$general['landing_page'] = '';
$general['display_mode'] = "PRODUCTS"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 1;
$general['include_in_menu'] = 0;
$general['url_key'] = $url;
saveCategory($general);
unset($general);
if ($categoryName == '4MOMS')
die('only one');
}
function saveCategory($general) {
$category = Mage::getModel('catalog/category');
$category->setStoreId(0);
$category->addData($general);
try {
$category->save();
echo 'Success! Name: '. $general['name'] .' Id: '.$category->getId() . "\n";
}
catch (Exception $e){
echo $e->getMessage();
}
}
exit;