2014-10-17 35 views
0

我有一个扩展名来检索magento的类别。你可以看到下面的代码。该代码适用于多个网站,但其中两个我得到的是空值。但是,它返回类别对象,但它就是这样。当我尝试获取类别的名称,id或url时,它是空的。Magento getModel('catalog/category')返回空类别名称,ID和网址

这是我得到的类别:

// Load all categories (flat) 
    $activeCategoryCollection = Mage::getModel('catalog/category') 
      ->getCollection() 
      ->addAttributeToSelect('*'); 

    // Load all categories (tree) 
    $categoriesArray = Mage::getModel('catalog/category') 
      ->getCollection() 
      ->addAttributeToSelect('name') 
      ->addAttributeToSort('path', 'asc') 
      ->load() 
      ->toArray(); 

而在此之后在foreach循环中我做的followning创建我的对象:

// Expose composite category data 
    foreach ($categoriesArray as $categoryId => $category) 
    { 
     // Check if category is not at root category level 
     if (isset($category['name']) && isset($category['level']) && $category['level'] > $rootCategory['level']) 
     { 

      // Remove root category path from category 
      $path = str_replace($rootCategory['path'] . '/', '', $category['path']); 

      // Explode parent categories 
      $parents = explode('/', $path); 
      $name = ''; 
      $url = ''; 

      // Get category name and urls for each parent 
      foreach ($parents as $parent) 
      { 
       $name .= $activeCategorNamesById[$parent] . '>'; 
       $url .= $activeCategoryUrlsById[$parent] . '>'; 
      } 

      // Get products in category with their positions 
      $currentCategory = Mage::getModel('catalog/category')->load($categoryId); 
      $collection = $currentCategory->getProductCollection()->addAttributeToSort('position'); 
      Mage::getModel('catalog/layer')->prepareProductCollection($collection); 

      // Index category data 
      $categories[$categoryId] = array(
       'name' => substr($name, 0, -1), 
       'level' => $category['level'], 
       'ids' => str_replace('/', '>', $path), 
       'url' => substr($url, 0, -1), 
       'id' => $categoryId, 
       'products' => $currentCategory->getProductsPosition() 
      ); 
     } 
    } 

目前,我没有访问这些网站的ftp手动更新我的扩展,并且我无法在商店中更新它。我不知道这个问题是什么,以及我如何测试它。其中一个建议是,在这些商店中,他们已经为类别显示了id,标题和网址等自定义字段,但我仍然不知道如何看到这些信息。我有权访问他们的magento管理站点,但在那里我找不到与其他人相比有什么不同。

编辑:下面的代码返回空数组,即使他们在他们的系统类别

var_dump($this->getCategories()); 

此外,在其他网站System > Configuration下有Catalog,但对于那些没有工作的一个很System > Configuration > Catalogue 。我不确定他们之间有什么区别。

回答

0

哪里$name$path$url定义

尝试

$categories[$categoryId] = array(
    'name' => substr($category['name'], 0, -1), 
    'level' => $category['level'], 
    'ids' => str_replace('/', '>', $category['path']), 
    'url' => substr($category['url'], 0, -1), 
    'id' => $categoryId, 
); 
+0

我刚刚更新的代码中的问题,以显示其中'$ name''$ path'和'$ url'定义和组。你能告诉我什么是错的吗? – erincerol 2014-10-20 09:17:29