Public Member Functions | |
__construct () | |
getProduct () | |
isReadonly () | |
getIdsString () | |
getRootNode () | |
getRoot ($parentNodeCategory=null, $recursionLevel=3) | |
getCategoryChildrenJson ($categoryId) | |
getLoadTreeUrl ($expanded=null) | |
getSelectedCategoriesPathIds ($rootId=false) | |
Protected Member Functions | |
getCategoryIds () | |
_getNodeJson ($node, $level=1) | |
_isParentSelectedCategory ($node) | |
_getSelectedNodes () | |
Protected Attributes | |
$_categoryIds | |
$_selectedNodes = null |
Definition at line 34 of file Categories.php.
__construct | ( | ) |
Constructor
By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes
Reimplemented from Mage_Adminhtml_Block_Catalog_Category_Tree.
Definition at line 39 of file Categories.php.
00040 { 00041 parent::__construct(); 00042 $this->setTemplate('catalog/product/edit/categories.phtml'); 00043 }
_getNodeJson | ( | $ | node, | |
$ | level = 1 | |||
) | [protected] |
Get JSON of a tree node or an associative array
Varien_Data_Tree_Node|array | $node | |
int | $level |
Reimplemented from Mage_Adminhtml_Block_Catalog_Category_Tree.
Definition at line 130 of file Categories.php.
00131 { 00132 $item = parent::_getNodeJson($node, $level); 00133 00134 $isParent = $this->_isParentSelectedCategory($node); 00135 00136 if ($isParent) { 00137 $item['expanded'] = true; 00138 } 00139 00140 // if ($node->getLevel() > 1 && !$isParent && isset($item['children'])) { 00141 // $item['children'] = array(); 00142 // } 00143 00144 00145 if (in_array($node->getId(), $this->getCategoryIds())) { 00146 $item['checked'] = true; 00147 } 00148 00149 if ($this->isReadonly()) { 00150 $item['disabled'] = true; 00151 } 00152 return $item; 00153 }
_getSelectedNodes | ( | ) | [protected] |
Definition at line 169 of file Categories.php.
00170 { 00171 if ($this->_selectedNodes === null) { 00172 $this->_selectedNodes = array(); 00173 foreach ($this->getCategoryIds() as $categoryId) { 00174 $this->_selectedNodes[] = $this->getRoot()->getTree()->getNodeById($categoryId); 00175 } 00176 } 00177 00178 return $this->_selectedNodes; 00179 }
_isParentSelectedCategory | ( | $ | node | ) | [protected] |
Reimplemented from Mage_Adminhtml_Block_Catalog_Category_Tree.
Definition at line 155 of file Categories.php.
00156 { 00157 foreach ($this->_getSelectedNodes() as $selected) { 00158 if ($selected) { 00159 $pathIds = explode('/', $selected->getPathId()); 00160 if (in_array($node->getId(), $pathIds)) { 00161 return true; 00162 } 00163 } 00164 } 00165 00166 return false; 00167 }
getCategoryChildrenJson | ( | $ | categoryId | ) |
Definition at line 181 of file Categories.php.
00182 { 00183 $category = Mage::getModel('catalog/category')->load($categoryId); 00184 $node = $this->getRoot($category, 1)->getTree()->getNodeById($categoryId); 00185 00186 if (!$node || !$node->hasChildren()) { 00187 return '[]'; 00188 } 00189 00190 $children = array(); 00191 foreach ($node->getChildren() as $child) { 00192 $children[] = $this->_getNodeJson($child); 00193 } 00194 00195 return Zend_Json::encode($children); 00196 }
getCategoryIds | ( | ) | [protected] |
Definition at line 65 of file Categories.php.
00066 { 00067 return $this->getProduct()->getCategoryIds(); 00068 }
getIdsString | ( | ) |
Definition at line 70 of file Categories.php.
00071 { 00072 return implode(',', $this->getCategoryIds()); 00073 }
getLoadTreeUrl | ( | $ | expanded = null |
) |
Reimplemented from Mage_Adminhtml_Block_Catalog_Category_Tree.
Definition at line 198 of file Categories.php.
getProduct | ( | ) |
Retrieve currently edited product
Definition at line 50 of file Categories.php.
00051 { 00052 return Mage::registry('current_product'); 00053 }
getRoot | ( | $ | parentNodeCategory = null , |
|
$ | recursionLevel = 3 | |||
) |
Reimplemented from Mage_Adminhtml_Block_Catalog_Category_Abstract.
Definition at line 85 of file Categories.php.
00086 { 00087 if (!is_null($parentNodeCategory) && $parentNodeCategory->getId()) { 00088 return $this->getNode($parentNodeCategory, $recursionLevel); 00089 } 00090 $root = Mage::registry('root'); 00091 if (is_null($root)) { 00092 $storeId = (int) $this->getRequest()->getParam('store'); 00093 00094 if ($storeId) { 00095 $store = Mage::app()->getStore($storeId); 00096 $rootId = $store->getRootCategoryId(); 00097 } 00098 else { 00099 $rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID; 00100 } 00101 00102 $ids = $this->getSelectedCategoriesPathIds($rootId); 00103 $tree = Mage::getResourceSingleton('catalog/category_tree') 00104 ->loadByIds($ids, false, false); 00105 00106 if ($this->getCategory()) { 00107 $tree->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId)); 00108 } 00109 00110 $tree->addCollectionData($this->getCategoryCollection()); 00111 00112 $root = $tree->getNodeById($rootId); 00113 00114 if ($root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID) { 00115 $root->setIsVisible(true); 00116 if ($this->isReadonly()) { 00117 $root->setDisabled(true); 00118 } 00119 } 00120 elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID) { 00121 $root->setName(Mage::helper('catalog')->__('Root')); 00122 } 00123 00124 Mage::register('root', $root); 00125 } 00126 00127 return $root; 00128 }
getRootNode | ( | ) |
Definition at line 75 of file Categories.php.
00076 { 00077 // $root = parent::getRoot(); 00078 $root = $this->getRoot(); 00079 if ($root && in_array($root->getId(), $this->getCategoryIds())) { 00080 $root->setChecked(true); 00081 } 00082 return $root; 00083 }
getSelectedCategoriesPathIds | ( | $ | rootId = false |
) |
Return distinct path ids of selected categories
int | $rootId Root category Id for context |
Definition at line 209 of file Categories.php.
00210 { 00211 $ids = array(); 00212 $collection = Mage::getModel('catalog/category')->getCollection() 00213 ->addFieldToFilter('entity_id', array('in'=>$this->getCategoryIds())); 00214 foreach ($collection as $item) { 00215 if ($rootId && !in_array($rootId, $item->getPathIds())) { 00216 continue; 00217 } 00218 foreach ($item->getPathIds() as $id) { 00219 if (!in_array($id, $ids)) { 00220 $ids[] = $id; 00221 } 00222 } 00223 } 00224 return $ids; 00225 }
isReadonly | ( | ) |
Checks when this block is readonly
Definition at line 60 of file Categories.php.
00061 { 00062 return $this->getProduct()->getCategoriesReadonly(); 00063 }
$_categoryIds [protected] |
Definition at line 36 of file Categories.php.
$_selectedNodes = null [protected] |
Definition at line 37 of file Categories.php.