2012-10-28 10 views
5

Utknąłem na tym, w zasadzie to, czego potrzebuję, to sposób automatycznego rozwinięcia węzła drzewa kategorii, który zawiera zaznaczony węzeł podkategorii.Auto Expand Drzewo kategorii produktów

Punkt wejścia w kodzie jest js/extjs/ext-tree-checkbox.js i 'catalog/category/tree.phtml'

Możliwe jest rozwinąć węzeł metodą expand() js i nie jest trudne, aby rozwinąć cały węzeł, ale to spowolnienie strony zbyt dużo.

Aktualizacja:

Ja testowałem następujące rozwiązanie:

  1. Zmień js/extjs/ext-tree-checkbox.js renderowania metoda dodawania to:

    var tree = n.getOwnerTree(); 
        if (tree){ 
         expandNodeIds = tree.expandNodeIds.split(','); 
         for (i in expandNodeIds) 
         { 
          if (n.id == expandNodeIds[i]) 
           n.expand(); 
         } 
        } 
    

to rozwiązanie działa, ale Łamie (nie jest już wyświetlany) drzewo o pozwolenie Role

+0

Co próbowałeś do tej pory? – Alex

Odpowiedz

1

to rozwiązać wszystkie problemy

var tree = n.getOwnerTree(); 
    if (tree){ 
     expandNodeIds = tree.expandNodeIds; 

     if (expandNodeIds) { 
      expandNodeIds = expandNodeIds.split(','); 
      for (i in expandNodeIds) 
      { 
       if (n.id == expandNodeIds[i]) 
        n.expand(); 
      } 
     } 

Dodaj powyższy kod w render metody js/extjs/ext-tree-checkbox.js

+0

Przetestowałeś to? Gdzie byś go dodał w metodzie "renderowania"? Poza tym wydaje się, że na końcu brakuje średnika. Przetestowałem to w wersji CE 1.7.0.2 i wydawało się, że nie działa. –

+0

w tym czasie, udało mi się go używać .. w każdym razie To może być dobry punkt wyjścia dla rozwiązania, jeśli znajdziesz jakiś problem, możesz poprawić odpowiedź lub dodać nową – WonderLand

2

Ponieważ:

- Google sees this as a solution 

Moje rozwiązanie jest na stronie PHP, w klasie Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories.

// start Added stuff 
protected $_ubProductCategoriesParents; 

public function getUbProductCategories() 
{ 
    if (is_null($this->_ubProductCategoriesParents)) { 
     $this->_ubProductCategoriesParents = array(); 
     $this->_ubProductCategoriesParents = array(); 
     foreach ($this->getCategoryIds() as $id) { 
      $storeId = (int) $this->getRequest()->getParam('store'); 
      $path = Mage::getResourceModel('catalog/category') 
       ->getAttributeRawValue($id, 'path', $storeId); // no model->load ever ever ever 
      if (empty($path)) { 
       $path = ""; 
      } 
      $parentsIds = explode("/", $path); 
      if (!(is_array($parentsIds) && count($parentsIds) > 0)) { 
       $parentsIds = array(); 
      } 
      $this->_ubProductCategoriesParents = array_unique(array_merge($this->_ubProductCategoriesParents, $parentsIds)); 
     } 

     //Mage::log(print_r($this->_ubProductCategoriesParents, true)); 
    } 

    return $this->_ubProductCategoriesParents; 
} 
// end Added stuff 

// magento core function from class 
protected function _getNodeJson($node, $level = 1) 
{ 
    $item = parent::_getNodeJson($node, $level); 

    if ($this->_isParentSelectedCategory($node)) { 
     $item['expanded'] = true; 
    } 

    // added new if statement 
    if (!(isset($item['expanded']) && $item['expanded'] == true) && array_search($node->getId(), $this->getUbProductCategories()) !== false) { 
     $item['expanded'] = true; 
    } 

    if (in_array($node->getId(), $this->getCategoryIds())) { 
     $item['checked'] = true; 
    } 

    if ($this->isReadonly()) { 
     $item['disabled'] = true; 
    } 

    return $item; 
} 

Przechodzenie teraz, aby powyższy kod w klasie przepisywania.

Dziękuję

+0

Intro wydaje się nieco nie na miejscu – RacerNerd

+0

I zmienił to, thx – obscure

Powiązane problemy