2012-10-28 13 views
5

Mi sono bloccato su questo, in pratica quello di cui ho bisogno è un modo per espandere automaticamente il nodo dell'albero della categoria che contiene un nodo di sottocategoria controllato.Espandi automaticamente l'albero delle categorie di prodotto

Il punto di ingresso nel codice è js/extjs/ext-tree-checkbox.js e 'catalog/category/tree.phtml'

E 'possibile un espandere un nodo con il metodo expand() js e non è un difficile espandere tutti i nodi, ma questo lento in basso nella pagina troppo.

Aggiornamento:

ho provato la seguente soluzione:

  1. Change js/extjs/ext-tree-checkbox.js rendono metodo aggiungendo questo:

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

questa soluzione funziona ma rompe (non viene più visualizzato) l'albero per il permesso di ruolo

+0

Cosa hai provato fino ad ora? – Alex

risposta

1

Questa risolvere tutti i problemi

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(); 
      } 
     } 

Aggiungere il codice di cui sopra in render metodo js/extjs/ext-tree-checkbox.js

+0

Hai provato questo? Dove lo aggiungerei nel metodo 'render'? Inoltre, sembra che manchi un punto e virgola alla fine. Ho provato questo in CE 1.7.0.2 e non sembra funzionare. –

+0

in quel momento, l'ho usato con successo .. comunque potrebbe essere un buon punto di ingresso per la soluzione, se trovi qualche problema puoi migliorare la risposta o aggiungerne una nuova – WonderLand

2

Perché:

- Google sees this as a solution 

La mia soluzione è in parte Php, in classe 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; 
} 

Ora per avere il codice sopra riportato in una classe di riscrittura.

Grazie

+0

L'introduzione sembra un po 'fuori luogo – RacerNerd

+0

I cambiato, thx – obscure

Problemi correlati