我有一个magento商店(版本1.5.1.0),包含很多类别,使用以下类别复制脚本添加了类别 -
<?php
if(!is_numeric($_GET['id']))die('Please specify a category ID');
$catId = $_GET['id'];
$xml = simplexml_load_file('app/etc/local.xml');
$host = $xml->global->resources->default_setup->connection->host;
$username = $xml->global->resources->default_setup->connection->username;
$password = $xml->global->resources->default_setup->connection->password;
$dbname = $xml->global->resources->default_setup->connection->dbname;
$res = mysql_pconnect($host, $username, $password);
mysql_select_db($dbname);
$catsDone = 0;
duplicate_entity($catId);
echo $catsDone . ' Categories duplicated.';
function duplicate_entity($id, $parent_id = null){
global $catsDone;
// Grab category to copy
$sql = "SELECT * FROM catalog_category_entity WHERE entity_id = " . $id;
$query_entity = mysql_query($sql);
$entity = mysql_fetch_object($query_entity);
if(!$parent_id)$parent_id = $entity->parent_id;
mysql_query("INSERT INTO catalog_category_entity (entity_type_id, attribute_set_id, parent_id, created_at, updated_at, path, position, level, children_count)
VALUES ({$entity->entity_type_id}, {$entity->attribute_set_id}, {$parent_id}, NOW(), NOW(), '', {$entity->position}, {$entity->level}, {$entity->children_count})");
$newEntityId = mysql_insert_id();
$query = mysql_query("SELECT path FROM catalog_category_entity WHERE entity_id = " . $parent_id);
$parent = mysql_fetch_object($query);
$path = $parent->path . '/' . $newEntityId;
mysql_query("UPDATE catalog_category_entity SET path='". $path."' WHERE entity_id=". $newEntityId);
foreach(array('datetime', 'decimal', 'int', 'text', 'varchar') as $dataType){
$sql = "SELECT * FROM catalog_category_entity_".$dataType."
WHERE entity_id=" . $entity->entity_id;
//die($sql);
$query = mysql_query($sql);
while ($value = mysql_fetch_object($query)){
mysql_query("INSERT INTO catalog_category_entity_".$dataType." (entity_type_id, attribute_id, store_id, entity_id, value)
VALUES ({$value->entity_type_id}, {$value->attribute_id}, {$value->store_id}, {$newEntityId}, '{$value->value}')");
}
}
$sql = "SELECT entity_id FROM catalog_category_entity WHERE parent_id = " . $id;
$query = mysql_query($sql);
while ($entity = mysql_fetch_object($query)){
duplicate_entity($entity->entity_id, $newEntityId);
}
$catsDone++;
}
?>
类别树,前端等类别显示正常,但是在类别编辑标签的产品编辑屏幕上,我只能看到默认类别?
答案 0 :(得分:3)
catalog_category_entity中的“children_count”列可能不正确。我遇到了同样的问题。
运行:
UPDATE catalog_category_entity SET children_count = "1" WHERE children_count < 1;
参考/更多信息:http://zaclee.net/magento/errors-magento/magento-product-edit-only-shows-default-category
答案 1 :(得分:1)
您的导入脚本未涵盖“catalog_category_entity”表的所有表列。基本上,您忘记更新“level”和“children_count”行。 Here's how you can fix this
哦,我忘了。 Zachary在这里链接的剧本也很糟糕。它不能解决问题,只是掩盖它并将其留给JavaScript来“咀嚼”。我链接的脚本将正确设置所有内容。