1
我正在进口的产品,提前数据流量分布和同时节省了类别为我传递的类别名称,我的功能Magento的:问题类别名称,同时自动保存更名
相关类别面对奇怪的问题/子类别
类别之间的/符号自动创建并将产品分配给子类别 它按预期工作,但在我的情况下父类别名称正在重命名某种程度上我检查了我正在将正确的名称传递给函数...例如Semipreciuos宝玉石珠/石类型保存为Semipreciuos宝玉石珠/石型
最后的话语从名称
protected function _addCategories($categories,$desc='',$discountable,$store) {
$rootId = $store->getRootCategoryId();
if (! $rootId) {
return array();
}
$rootPath = '1/' . $rootId;
if (empty ($this->_categoryCache [$store->getId()])) {
$collection = Mage::getModel ('catalog/category')->getCollection()->setStore($store)->addAttributeToSelect ('name');
$collection->getSelect()->where ("path like '" . $rootPath . "/%'");
foreach ($collection as $cat) {
$pathArr = explode ('/', $cat->getPath());
$namePath = '';
for($i = 2, $l = sizeof ($pathArr); $i < $l; $i ++) {
$name = $collection->getItemById ($pathArr [$i])->getName();
$namePath .= (empty ($namePath) ? '' : '/') . trim ($name);
}
$cat->setNamePath ($namePath);
}
$cache = array();
foreach ($collection as $cat) {
$cache [strtolower ($cat->getNamePath())] = $cat;
$cat->unsNamePath();
}
$this->_categoryCache [$store->getId()] = $cache;
}
$cache = & $this->_categoryCache [$store->getId()];
$catIds = array();
foreach (explode (',', $categories) as $categoryPathStr) {
$categoryPathStr = preg_replace ('#s*/s*#', '/', trim ($categoryPathStr));
if (! empty ($cache [$categoryPathStr])) {
$catIds [] = $cache [$categoryPathStr]->getId();
continue;
}
$path = $rootPath;
$namePath = '';
foreach (explode ('/', $categoryPathStr) as $catName) {
$namePath .= (empty ($namePath) ? '' : '/') . strtolower ($catName);
if (empty ($cache [$namePath])) {
$cat = Mage::getModel('catalog/category')->setStoreId($store->getId())->setPath ($path)->setName ($catName)->// comment out the following line if new categories should stay inactive
setIsActive(1)->setDescription($desc)->setData('discountable',$discountable)->save();
$cache [$namePath] = $cat;
}
$catId = $cache [$namePath]->getId();
$path .= '/' . $catId;
}
##Assigning product to child category
/*$parentId = null;
$currentcat = Mage::getModel("catalog/category")->load($catId);
$parentId = $currentcat->getParentId();
if($parentId){
$catIds[] = $parentId;
}
*/
if ($catId) {
$catIds [] = $catId;
}
}
return join (',', $catIds);
}
以上就是我为创建类别分类功能......任何一人失踪有什么想法是怎么回事..
你是英雄......很好的帮助......非常感谢:-) – ravisoni