Magento : Name der Kategorie anstelle der Kategorie-ids in der Kategorie Pfad.

Ich versuche, Kategorie-Namen, die in der Kategorie-Pfad basierend auf Produkt-id in magento.

Nehme an, Meine Product-Id = 1 und an, dass ich definieren category5 (id = 5) und ich bekomme category path wie 2/3/5. Statt dieser Art von Kategorie-Pfad brauche ich die Kategorie Weg, wie category2/category3/category5. Das heißt, ich brauche Kategorien-Namen im Pfad Statt der Kategorie-Ids. Ich habe dies mit folgendem code, aber die dauert so viel Zeit. Ich brauche, um zu verringern die Verarbeitungszeit.

Bitte gebt mir Vorschläge, wie kann ich den Prozess zu verkürzen.

$category_model = Mage::getModel('catalog/category');  
$product_model = Mage::getModel('catalog/product'); 
$all_cats = array();
$product_model->reset();
$_product = $product_model->load($entityId);
$all_cats = $product_model->getCategoryIds($_product); 
$main_cnt = count($all_cats);
$cat_str_main = ''; 
$j = 0;
foreach($all_cats as $ac)
{
    $root_category = $category_model->load($ac);
    $cat_path = $root_category->getPath();
    $cat_arr = explode("/",$cat_path);
    $cnt = count($cat_arr);
    $cat_str = '';
    $main_str = '';
    $i=0;
    foreach($cat_arr as $ids)
    {
                $root_category = $category_model->load($ids); //load root catalog
        if($i == 2)
        {
            $cat_str = $category_model->getName();
        }
        else if($i > 2)
        {
            $cat_str = $cat_str."/".$category_model->getName();
        }
        $i = $i+1;
    }
    if($j < 1)
    {
        $cat_str_main = $cat_str;
    }
    else 
    {
        $cat_str_main = $cat_str_main .",".$cat_str;
    }
    $j = $j+1;
}

Dank.....

ist es dein Problem gelöst ?

InformationsquelleAutor user123 | 2013-01-02

Schreibe einen Kommentar