在 Magento 根文件夹中创建一个名为 somename.php 的文件,并将以下代码粘贴到该文件中并保存。只需通过您的网络浏览器运行脚本。它应该创建一个类别“汽车”-它在 1.4.2.0 上对我有用。
<?php
require_once 'app/Mage.php';
Mage::app('default'); // Default or your store view name.
//get a new category object
$category = Mage::getModel('catalog/category');
$category->setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()->getStore()->getId().
//if update
if ($id) {
$category->load($id);
}
$general['name'] = "Cars";
$general['path'] = "1/3"; // 1/3 is root catalog
$general['description'] = "Great new cars";
$general['meta_title'] = "Cars"; //Page title
$general['meta_keywords'] = "car, automobile";
$general['meta_description'] = "Some description to be found by meta search robots.";
$general['landing_page'] = ""; //has to be created in advance, here comes id
$general['display_mode'] = "PRODUCTS_AND_PAGE"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 0;
$general['url_key'] = "cars";//url to be used for this category's page by magento.
$general['image'] = "cars.jpg";
$category->addData($general);
try {
$category->save();
echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
echo $e->getMessage();
}