private function nodeToArray(Varien_Data_Tree_Node $node, $mediaUrl, $baseUrl)
 {
     $result = array();
     $thumbnail = '';
     try {
         $thumbImg = $node->getThumbnail();
         if ($thumbImg != null) {
             $thumbnail = $mediaUrl . 'catalog/category/' . $node->getThumbnail();
         }
     } catch (Exception $e) {
     }
     $result['category_id'] = $node->getId();
     $result['image'] = $mediaUrl . 'catalog/category/' . $node->getImage();
     $result['thumbnail'] = $thumbnail;
     $result['description'] = strip_tags($node->getDescription());
     $result['parent_id'] = $node->getParentId();
     $result['name'] = $node->getName();
     $result['is_active'] = $node->getIsActive();
     $result['children'] = array();
     if (method_exists('Mage', 'getEdition') && Mage::getEdition() == Mage::EDITION_COMMUNITY) {
         $result['url_path'] = $baseUrl . $node->getData('url_path');
     } else {
         $category = Mage::getModel('catalog/category')->load($node->getId());
         $result['url_path'] = $category->getUrl();
     }
     foreach ($node->getChildren() as $child) {
         $result['children'][] = $this->nodeToArray($child, $mediaUrl, $baseUrl);
     }
     return $result;
 }
Пример #2
0
 /**
  * Get JSON of a tree node or an associative array
  *
  * @param Varien_Data_Tree_Node|array $node
  * @param int $level
  * @return string
  */
 protected function _getNodeJson($node, $level = 1)
 {
     $item = array();
     $item['text'] = $this->htmlEscape($node->getName());
     if ($this->_withProductCount) {
         $item['text'] .= ' (' . $node->getProductCount() . ')';
     }
     $item['id'] = $node->getId();
     $item['path'] = $node->getData('path');
     $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
     $item['allowDrop'] = false;
     $item['allowDrag'] = false;
     if ($node->hasChildren()) {
         $item['children'] = array();
         foreach ($node->getChildren() as $child) {
             $item['children'][] = $this->_getNodeJson($child, $level + 1);
         }
     }
     if (empty($item['children']) && (int) $node->getChildrenCount() > 0) {
         $item['children'] = array();
     }
     if (!empty($item['children'])) {
         $item['expanded'] = true;
     }
     if (in_array($node->getId(), $this->getCategoryIds())) {
         $item['checked'] = true;
     }
     return $item;
 }
Пример #3
0
    public function BuildBranch(Varien_Data_Tree_Node $node)
    {
        $buildString = '<li style="padding-left: 16px;">';
        $buildString .= '<div class="tree-level-' . $node->getLevel() . '">';
        if ($node->getChildrenCount() != 0) {
            $buildString .= '<div class="opener" id="opener' . $node->getId() . '"  OnClick="OpenMe(this)"></div>';
        } else {
            $buildString .= '<div class="child"></div>';
        }
        $buildString .= '
			<input type="checkbox" class="inputcb" id="inputcb' . $node->getId() . '" OnClick="Decide(this)" enabled="false"/>
			<div class="folder"></div>
			<a tabindex="1" href="#" hidefocus="on" id="linkItem"><span unselectable="on" id="extdd-' . $node->getLevel() . '">' . $node->getName() . '</a>
		';
        $buildString .= '</div>';
        if ($node->getChildrenCount() != 0) {
            $buildString .= '<ul id="ToOpen' . $node->getId() . '">';
            foreach ($node->getChildren() as $child) {
                $buildString .= $this->BuildBranch($child);
            }
            $buildString .= '</ul>';
        }
        $buildString .= '</li>';
        return $buildString;
    }
Пример #4
0
 public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
 {
     $level++;
     $values[$node->getId()]['value'] = $node->getId();
     $values[$node->getId()]['label'] = str_repeat("--", $level) . $node->getName();
     foreach ($node->getChildren() as $child) {
         $values = $this->buildCategoriesMultiselectValues($child, $values, $level);
     }
     return $values;
 }
Пример #5
0
 /**
  * @param Varien_Data_Tree_Node $node
  * @param array $values
  * @param int $level
  * @return array
  */
 protected function _buildCategoriesValues(Varien_Data_Tree_Node $node, $values, $level = 0)
 {
     ++$level;
     $values[$node->getId()]['value'] = $node->getId();
     $values[$node->getId()]['label'] = str_repeat('--', $level) . $node->getName();
     foreach ($node->getChildren() as $child) {
         $values = $this->_buildCategoriesValues($child, $values, $level);
     }
     return $values;
 }
 public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
 {
     $nonEscapableNbspChar = html_entity_decode('&#160;', ENT_NOQUOTES, 'UTF-8');
     $level++;
     $values[$node->getId()]['value'] = $node->getId();
     $values[$node->getId()]['label'] = str_repeat($nonEscapableNbspChar, ($level - 1) * 5) . $node->getName();
     foreach ($node->getChildren() as $child) {
         $values = $this->buildCategoriesMultiselectValues($child, $values, $level);
     }
     return $values;
 }
Пример #7
0
 public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
 {
     $level++;
     if ($level == 3) {
         //we have to show only third level category in drop down
         $values[$node->getId()]['value'] = $node->getId();
         $values[$node->getId()]['label'] = $node->getName();
     }
     foreach ($node->getChildren() as $child) {
         $values = $this->buildCategoriesMultiselectValues($child, $values, $level);
     }
     return $values;
 }
Пример #8
0
 private function nodeToArray(Varien_Data_Tree_Node $node)
 {
     $result = array();
     $category = Mage::getModel('catalog/category')->load($node->getId());
     if ($category->getAvailableForSupplier() == 1) {
         $result['category_id'] = $node->getId();
         $result['parent_id'] = $node->getParentId();
         $result['name'] = $node->getName();
         $result['is_active'] = $node->getIsActive();
         $result['position'] = $node->getPosition();
         $result['level'] = $node->getLevel();
     }
     $result['children'] = array();
     foreach ($node->getChildren() as $child) {
         $result['children'][] = $this->nodeToArray($child);
     }
     return $result;
 }
Пример #9
0
 /**
  * Adds a node to this node
  */
 public function add(Varien_Data_Tree_Node $node)
 {
     $node->setParent($this->_container);
     // Set the Tree for the node
     if ($this->_container->getTree() instanceof Varien_Data_Tree) {
         $node->setTree($this->_container->getTree());
     }
     $this->_nodes[$node->getId()] = $node;
     return $node;
 }
Пример #10
0
 /**
  * Export product collection
  *
  * @param Varien_Data_Tree_Node $category
  */
 protected function _exportProductCollection($category)
 {
     $categoryModel = Mage::getModel('catalog/category')->load($category->getId());
     $this->setCategory($categoryModel)->setLayer(Mage::getSingleton('catalog/layer'));
     foreach ($this->_getProductCollection() as $product) {
         $product->load($product->getEntityId());
         Mage::app()->getRequest()->setParam('id', $product->getId());
         $this->_getExportModel(self::TYPE_PRODUCT)->setProduct($product)->exportData();
         $this->_getExportModel(self::TYPE_GALLERY)->setProduct($product)->exportData();
         $this->_getExportModel(self::TYPE_REVIEW)->setProduct($product)->exportData();
     }
 }
Пример #11
0
 /**
  * Checks whether category belongs to active category's path
  *
  * @param Varien_Data_Tree_Node $category
  * @return bool
  */
 protected function _isActiveMenuCategory($category)
 {
     $catalogLayer = Mage::getSingleton('catalog/layer');
     if (!$catalogLayer) {
         return false;
     }
     $currentCategory = $catalogLayer->getCurrentCategory();
     if (!$currentCategory) {
         return false;
     }
     $categoryPathIds = explode(',', $currentCategory->getPathInStore());
     return in_array($category->getId(), $categoryPathIds);
 }
Пример #12
0
 function nodeToArray(Varien_Data_Tree_Node $node)
 {
     $result = array();
     $result['category_id'] = $node->getId();
     $result['parent_id'] = $node->getParentId();
     $result['name'] = $node->getName();
     $result['is_active'] = $node->getIsActive();
     $result['position'] = $node->getPosition();
     $result['level'] = $node->getLevel();
     $result['children'] = array();
     foreach ($node->getChildren() as $child) {
         $result['children'][] = $this->nodeToArray($child);
     }
     return $result;
 }
Пример #13
0
 /**
  * Convert node to array with path information.
  * Path information skips the 'Root Catalog' (level=0) and 'Default Category' (level=1) levels.
  *
  * @param Varien_Data_Tree_Node $node
  * @return array
  */
 protected function _nodeToArrayPath(Varien_Data_Tree_Node $node, $parentPath)
 {
     // Only basic category data
     $categories = array();
     $category = array();
     $category['category_id'] = $node->getId();
     $category['parent_id'] = $node->getParentId();
     $category['name'] = $node->getName();
     $category['path'] = !empty($parentPath) && $node->getLevel() > 2 ? $parentPath . '/' . $node->getName() : $node->getName();
     $category['is_active'] = $node->getIsActive();
     $category['position'] = $node->getPosition();
     $category['level'] = $node->getLevel();
     $categories[] = $category;
     foreach ($node->getChildren() as $child) {
         $children = $this->_nodeToArrayPath($child, $category['path']);
         $categories = array_merge($categories, $children);
     }
     return $categories;
 }
Пример #14
0
 /**
  * Convert categories tree to array recursively
  *
  * @param  Varien_Data_Tree_Node $node
  * @return array
  */
 protected function _getNodesArray($node)
 {
     $result = array('id' => (int) $node->getId(), 'parent_id' => (int) $node->getParentId(), 'children_count' => (int) $node->getChildrenCount(), 'is_active' => (bool) $node->getIsActive(), 'name' => $node->getName(), 'level' => (int) $node->getLevel(), 'product_count' => (int) $node->getProductCount());
     if (is_array($this->_allowedCategoryIds) && !in_array($result['id'], $this->_allowedCategoryIds)) {
         $result['disabled'] = true;
     }
     if ($node->hasChildren()) {
         $result['children'] = array();
         foreach ($node->getChildren() as $childNode) {
             $result['children'][] = $this->_getNodesArray($childNode);
         }
     }
     $result['cls'] = ($result['is_active'] ? '' : 'no-') . 'active-category';
     $result['expanded'] = !empty($result['children']);
     return $result;
 }
Пример #15
0
 /**
  * Move tree node
  *
  * @todo Use adapter for generate conditions
  * @param Varien_Data_Tree_Node $node
  * @param Varien_Data_Tree_Node $newParent
  * @param Varien_Data_Tree_Node $prevNode
  */
 public function move($node, $newParent, $prevNode = null)
 {
     $position = 1;
     $oldPath = $node->getData($this->_pathField);
     $newPath = $newParent->getData($this->_pathField);
     $newPath = $newPath . '/' . $node->getId();
     $oldPathLength = strlen($oldPath);
     $newLevel = $newParent->getLevel() + 1;
     $levelDisposition = $newLevel - $node->getLevel();
     $data = array($this->_levelField => new Zend_Db_Expr("{$this->_levelField} + '{$levelDisposition}'"), $this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))"));
     $condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)");
     $this->_conn->beginTransaction();
     $reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1"));
     try {
         if ($prevNode && $prevNode->getId()) {
             $reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}";
             $position = $prevNode->getData($this->_orderField) + 1;
         } else {
             $reorderCondition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$newParent->getData($this->_pathField)}/[0-9]+\$");
             $select = $this->_conn->select()->from($this->_table, new Zend_Db_Expr("MIN({$this->_orderField})"))->where($reorderCondition);
             $position = (int) $this->_conn->fetchOne($select);
         }
         $this->_conn->update($this->_table, $reorderData, $reorderCondition);
         $this->_conn->update($this->_table, $data, $condition);
         $this->_conn->update($this->_table, array($this->_orderField => $position, $this->_levelField => $newLevel), $this->_conn->quoteInto("{$this->_idField} = ?", $node->getId()));
         $this->_conn->commit();
     } catch (Exception $e) {
         $this->_conn->rollBack();
         throw new Exception("Can't move tree node due to error: " . $e->getMessage());
     }
 }
Пример #16
0
 /**
  * Convert tree node to dropdown option
  *
  * @return array
  */
 protected function _treeNodeToOption(Varien_Data_Tree_Node $node, $without)
 {
     $option = array();
     $option['label'] = $node->getName();
     if ($node->getLevel() < 2) {
         $option['value'] = array();
         foreach ($node->getChildren() as $childNode) {
             if (!in_array($childNode->getId(), $without)) {
                 $option['value'][] = $this->_treeNodeToOption($childNode, $without);
             }
         }
     } else {
         $option['value'] = $node->getId();
     }
     return $option;
 }
Пример #17
0
 /**
  * Returns whether $node is a parent (not exactly direct) of a selected node
  *
  * @param Varien_Data_Tree_Node $node
  * @return bool
  */
 protected function _isParentSelectedCategory($node)
 {
     foreach ($this->_getSelectedNodes() as $selected) {
         if ($selected) {
             $pathIds = explode('/', $selected->getPathId());
             if (in_array($node->getId(), $pathIds)) {
                 return true;
             }
         }
     }
     return false;
 }
Пример #18
0
 /**
  * Move tree node
  *
  * @param Varien_Data_Tree_Node $node
  * @param Varien_Data_Tree_Node $parentNode
  * @param Varien_Data_Tree_Node $prevNode
  */
 public function moveNodeTo($node, $parentNode, $prevNode = null)
 {
     $data = array();
     $data[$this->_parentField] = $parentNode->getId();
     $data[$this->_levelField] = $parentNode->getData($this->_levelField) + 1;
     // New node order
     if (is_null($prevNode) || is_null($prevNode->getData($this->_orderField))) {
         $data[$this->_orderField] = 1;
     } else {
         $data[$this->_orderField] = $prevNode->getData($this->_orderField) + 1;
     }
     $condition = $this->_conn->quoteInto("{$this->_idField}=?", $node->getId());
     // For reorder new node branch
     $dataReorderNew = array($this->_orderField => new Zend_Db_Expr($this->_conn->quoteIdentifier($this->_orderField) . '+1'));
     $conditionReorderNew = $this->_conn->quoteIdentifier($this->_parentField) . '=' . $parentNode->getId() . ' AND ' . $this->_conn->quoteIdentifier($this->_orderField) . '>=' . $data[$this->_orderField];
     // For reorder old node branch
     $dataReorderOld = array($this->_orderField => new Zend_Db_Expr($this->_conn->quoteIdentifier($this->_orderField) . '-1'));
     $conditionReorderOld = $this->_conn->quoteIdentifier($this->_parentField) . '=' . $node->getData($this->_parentField) . ' AND ' . $this->_conn->quoteIdentifier($this->_orderField) . '>' . $node->getData($this->_orderField);
     $this->_conn->beginTransaction();
     try {
         // Prepare new node branch
         $this->_conn->update($this->_table, $dataReorderNew, $conditionReorderNew);
         // Move node
         $this->_conn->update($this->_table, $data, $condition);
         // Update old node branch
         $this->_conn->update($this->_table, $dataReorderOld, $conditionReorderOld);
         $this->_updateChildLevels($node->getId(), $data[$this->_levelField]);
         $this->_conn->commit();
     } catch (Exception $e) {
         $this->_conn->rollBack();
         throw new Exception('Can\'t move tree node');
     }
 }
Пример #19
0
 /**
  * Returns whether $node is a parent (not exactly direct) of a selected node
  *
  * @param Varien_Data_Tree_Node $node
  * @return bool
  */
 protected function _isParentSelectedCategory($node)
 {
     $result = false;
     // Contains string with all category IDs of children (not exactly direct) of the node
     $allChildren = $node->getAllChildren();
     if ($allChildren) {
         $selectedCategoryIds = $this->getCategoryIds();
         $allChildrenArr = explode(',', $allChildren);
         for ($i = 0, $cnt = count($selectedCategoryIds); $i < $cnt; $i++) {
             $isSelf = $node->getId() == $selectedCategoryIds[$i];
             if (!$isSelf && in_array($selectedCategoryIds[$i], $allChildrenArr)) {
                 $result = true;
                 break;
             }
         }
     }
     return $result;
 }
Пример #20
0
 protected function _getProductCountFromTreeNode(Varien_Data_Tree_Node $category)
 {
     return Mage::getSingleton('catalog/category')->setId($category->getId())->getProductCount();
 }
Пример #21
0
 /**
  * @param Mage_Catalog_Model_Category|Varien_Data_Tree_Node $category
  * @return $this
  */
 public function loadByCategory($category)
 {
     $this->_getResource()->loadByCategory($this, $category->getId(), $category->getStoreId());
     $this->_afterLoad();
     return $this;
 }
Пример #22
0
 /**
  * Move tree node
  *
  * @param Varien_Data_Tree_Node $node
  * @param Varien_Data_Tree_Node $parentNode
  * @param Varien_Data_Tree_Node $prevNode
  */
 public function move($category, $newParent, $prevNode = null)
 {
     $position = 1;
     $oldPath = $category->getData($this->_pathField);
     $newPath = $newParent->getData($this->_pathField);
     $newPath = $newPath . '/' . $category->getId();
     $oldPathLength = strlen($oldPath);
     $data = array($this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))"));
     $condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)");
     $this->_conn->beginTransaction();
     try {
         if ($prevNode && $prevNode->getId()) {
             $reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1"));
             $reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}";
             $this->_conn->update($this->_table, $reorderData, $reorderCondition);
             $position = $prevNode->getData($this->_orderField) + 1;
         }
         $this->_conn->update($this->_table, $data, $condition);
         $this->_conn->update($this->_table, array($this->_orderField => $position), $this->_conn->quoteInto("{$this->_idField} = ?", $category->getId()));
         $this->_conn->commit();
     } catch (Exception $e) {
         $this->_conn->rollBack();
         throw new Exception("Can't move tree node due to error: " . $e->getMessage());
     }
 }
Пример #23
0
 /** @param Varien_Data_Tree_Node $category */
 function categoryIsRoot($category)
 {
     return $category->getId() == Mage::app()->getStore()->getRootCategoryId();
 }
Пример #24
0
 /**
  * Returns array of menu item's classes
  *
  * @param Varien_Data_Tree_Node $item
  * @return array
  */
 protected function _getMenuItemClasses(Varien_Data_Tree_Node $item)
 {
     $classes = array();
     $classes[] = $item->getId() . ' level' . $item->getLevel();
     $classes[] = $item->getPositionClass();
     if ($item->getIsFirst()) {
         $classes[] = 'first';
     }
     if ($item->getIsActive()) {
         //            $classes[] = 'active';
     }
     if ($item->getIsLast()) {
         $classes[] = 'last';
     }
     if ($item->getClass()) {
         $classes[] = $item->getClass();
     }
     if ($item->hasChildren()) {
         $classes[] = 'parent';
     }
     return $classes;
 }
Пример #25
0
 /**
  * Get URL to edit page with category ID
  *
  * @param Varien_Data_Tree_Node $node
  * @return string
  */
 public function getCategoryEditUrl($node)
 {
     return $this->getUrl('*/*/edit', array('category_id' => $node->getId(), 'product' => $this->getProductId(), 'type' => 'category'));
 }
Пример #26
0
 protected function _nodeToArray(Varien_Data_Tree_Node $node)
 {
     if (empty($node)) {
         return array();
     }
     $result = $node->debug();
     $result['category_id'] = $node->getId();
     $result['parent_id'] = $node->getParentId();
     $result['name'] = $node->getName();
     $result['is_active'] = $node->getIsActive();
     $result['is_anchor'] = $node->getIsAnchor();
     $result['url_key'] = $node->getUrlKey();
     $result['url'] = $node->getRequestPath();
     $result['position'] = $node->getPosition();
     $result['level'] = $node->getLevel();
     $result['products'] = $node->getProducts();
     $result['children'] = array();
     foreach ($node->getChildren() as $child) {
         $result['children'][] = $this->_nodeToArray($child);
     }
     return $result;
 }