2013-02-20 1 views
2

Magento의 탐색에 포함되도록 표시된 범주를 모두 관리자 패널에있는 순서대로로드하려고합니다. 사용자 지정 계층화 된 메뉴를 만들기 위해 DB에 저장된 다른 메뉴와 출력을 다른 페이지와 결합).Magento로드 범주 관리자 순서 ​​

private function generateCategories() { 

    $_root_category_id = Mage::app()->getWebsite(true)->getDefaultStore()->getRootCategoryId(); 

    $_current_children = Mage::getModel('catalog/category') 
     ->getCollection() 
     ->addAttributeToSelect('*') 
     ->addIsActiveFilter() 
     ->addLevelFilter(2) 
     ->addOrderField('position', 'asc'); 

    $i = 0; 

    $html = ''; 

    foreach($_current_children as $l0) { 
     if ($l0->getID() != $_root_category_id && $l0->getName() != '' && $l0->getIncludeInMenu()) { 

      $i++; 

      if (Mage::helper('core/url')->getCurrentUrl() == $l0->getURL()) 
       $active = ' active'; 
      else 
       $active = ''; 

      if ($l0->hasChildren()) 
       $parent = ' parent'; 
      else 
       $parent = ''; 

      $html .= '<li class=" level0' . $active . $parent . '"><a href="' . $l0->getURL() . '" class="top">' . $l0->getName() . '</a>'; 

      if ($l0->hasChildren()) { 
       $multiplier = 1; 
       $iteration = 0; 

       $level1 = ''; 
       $level1[] = ''; 

       foreach (explode(',', $l0->getChildren()) as $l1) { 

        $l1 = Mage::getModel('catalog/category')->load($l1); 

        if ($l1->getIncludeInMenu()) { 

         if (Mage::helper('core/url')->getCurrentUrl() == $l1->getURL()) 
          $active = ' active'; 
         else 
          $active = ''; 

         if ($iteration == $this->perColumn) { 
          $iteration = 0; 
          $multiplier++; 
         } 

         $iteration++; 

         $level1[] = '<span class="level1' . $active . '"><a href="' . $l1->getURL() . '" title="' . $l1->getName() . '">' . $l1->getName() . '</a></span>'; 
        } 
       } 

       unset($level1[0]); 

       $numLinks = count($level1); 
       $columns = $numLinks/$this->perColumn; 

       $html .= '<div class="border-cover"></div><div class="dropdown" style="width: ' . $this->colWidth * $multiplier . 'em;">'; 

       $used = 0; 
       $iteration = 0; 

       foreach($level1 as $link) { 
        $used++; 
        $iteration++; 

        if ($used == 1) 
         $html .= '<div class="col" style="float: left; width: ' . $this->colWidth . 'em;">'; 

        $html .= $link; 

        if ($used == 4 || $iteration == $numLinks) { 
         $html .= '</div>'; 
         $used = 0; 
        } 
       } 

       $html .= '</div>'; 
      } 

      $html .= '</li>'; 
     } 
    } 

    return $html; 

} 

내가 ->addOrderField('position', 'asc') 관리자 패널에서와 같은 순서로 범주를 필터링해야한다는 인상을했지만이 :

는 지금까지 메뉴를 생성하는 기능으로 사용하고 무엇인가 하위 카테고리가 아니라 첫 번째 레벨 ( $l0) 카테고리에서만 작동합니다.

아무에게도 이것이 작동하도록 수정 될 수있는 방법을 제안 할 수 있습니까?

답변

3

getChildren 대신 getChildrenCategories() 함수를 사용하면 카테고리의 ID가 아닌 객체를 반환하므로 정보를로드 할 필요가 없습니다.

상세 정보 Change sort order of Magento subcategories

+0

고맙습니다. 완벽하게 작동합니다. 나는 그들이 그 범주를 객체로 반환하는 방법이라는 것을 깨닫지 못했고, 나는 그 객체들을로드해야한다고 생각했다. –

0
$ 하위 범주 = 마법사 ::을 getModel ('카탈로그/카테고리')에서 찾을 수 있습니다 -> getCollection()
-> addAttributeToSelect ('이름')
-> addFieldToFilter ('parent_id', $ categoryId)
-> addAttributeToSort ('name', ASC);
?>
+0

이름에 관한 것이 아닙니다! –