dongwen2896 2011-10-15 11:10
浏览 46

Magento产品编辑屏幕,类别没有出现

I have a magento store (ver 1.5.1.0) with a lot of categories, the categories have been added using the following category duplication script -

<?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++;
}
?>

The categories appear fine in the category tree, front end, etc, however on the product edit screen on the category edit tab, I can only see the default category?

  • 写回答

2条回答 默认 最新

  • dqn8235 2011-12-12 00:25
    关注

    Your "children_count" column in catalog_category_entity is probably incorrect. I had the same problem.

    Run this:

    UPDATE catalog_category_entity SET children_count = "1" WHERE children_count < 1;
    

    Reference / more info: http://zaclee.net/magento/errors-magento/magento-product-edit-only-shows-default-category

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度