2012-10-28 11 views
5

मैं इस पर अटक गया, मूल रूप से मुझे जो श्रेणी की आवश्यकता है वह ऑटो पेड़ नोड का विस्तार करने का एक तरीका है जिसमें एक उप श्रेणी नोड चेक किया गया है।ऑटो विस्तृत उत्पाद श्रेणी वृक्ष

कोड में प्रवेश बिंदु js/extjs/ext-tree-checkbox.js और 'catalog/category/tree.phtml'

यह संभव है एक expand() js विधि के साथ में एक नोड का विस्तार करने के लिए है और यह कोई मुश्किल है सभी नोड का विस्तार करने लेकिन बहुत अधिक पृष्ठ नीचे इस धीमी।

अद्यतन:

  1. बदलें js/extjs/ext-tree-checkbox.js विधि इस जोड़ने प्रस्तुत करना:

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

यह समाधान काम करता है लेकिन यह टूट जाता है (

मैं निम्नलिखित समाधान का परीक्षण किया है यह अब प्रदर्शित नहीं होता है) पेड़ अनुमति भूमिका

+0

आपने अभी तक क्या प्रयास किया? – Alex

उत्तर

1

के लिए यह ठीक सभी समस्या

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

की render विधि में इसके बाद के संस्करण कोड जोड़ें js/extjs/ext-tree-checkbox.js

+0

क्या आपने इसका परीक्षण किया है? आप इसे 'रेंडर' विधि में कहां जोड़ देंगे? इसके अलावा, आप अंत में एक अर्धविराम गायब लगते हैं। मैंने सीई 1.7.0.2 में इसका परीक्षण किया है और यह काम नहीं कर रहा था। –

+0

उस समय, मैंने इसका सफलतापूर्वक उपयोग किया है .. वैसे भी यह समाधान के लिए एक अच्छा प्रवेश बिंदु हो सकता है, अगर आपको कोई समस्या मिलती है तो आप उत्तर में सुधार कर सकते हैं या एक नया – WonderLand

2

क्योंकि:

- Google sees this as a solution 

मेरे समाधान Php पक्ष में है, कक्षा में 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; 
} 

अब उपरोक्त कोड को एक पुनर्लेखन कक्षा में रखने के लिए जा रहा है।

आप एक छोटे से बग फिक्सिंग और पुनर्रचना

+0

जोड़ सकते हैं यह परिचय – RacerNerd

+0

I से थोड़ा सा लगता है। इसे बदल दिया, thx – obscure

4

मैंने किया धन्यवाद और पैक @obscures एक छोटे से विस्तार में जवाब। इसे गिटहब पर आज़माएं: Kiwigrid_AutoExpandProductCategoryTree