当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Catalog_Model_Category::getLevel方法代码示例

本文整理汇总了PHP中Mage_Catalog_Model_Category::getLevel方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category::getLevel方法的具体用法?PHP Mage_Catalog_Model_Category::getLevel怎么用?PHP Mage_Catalog_Model_Category::getLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Catalog_Model_Category的用法示例。


在下文中一共展示了Mage_Catalog_Model_Category::getLevel方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportData

 protected function exportData(Mage_Catalog_Model_Category $category, $file, $depth = 0)
 {
     $data = array('id' => $category->getId(), 'parent_id' => $category->getParentId(), 'attribute_set_id' => $category->getAttributeSetId(), 'urlPath' => $category->getUrlPath(), 'urlKey' => $category->getUrlKey(), 'path' => $category->getPath(), 'position' => $category->getPosition(), 'page_layout' => $category->getPageLayout(), 'description' => $category->getDescription(), 'display_mode' => $category->getDisplayMode(), 'is_active' => $category->getIsActive(), 'is_anchor' => $category->getIsAnchor(), 'include_in_menu' => $category->getIncludeInMenu(), 'custom_design' => $category->getCustomDesign(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'metaTitle' => $category->getMetaTitle(), 'metaKeywords' => $category->getMetaKeywords(), 'metaDescription' => $category->getMetaDescription());
     echo str_repeat('  ', $depth);
     echo '* ' . $category->getName() . sprintf(' (%s products)', $category->getProductCount()) . PHP_EOL;
     fputcsv($file, $data);
     if ($category->hasChildren()) {
         $children = Mage::getModel('catalog/category')->getCategories($category->getId());
         foreach ($children as $child) {
             $child = Mage::getModel('catalog/category')->load($child->getId());
             $this->exportData($child, $file, $depth + 1);
         }
     }
 }
开发者ID:sonaht,项目名称:magento-category-migration,代码行数:14,代码来源:exportCategories.php

示例2: _applyCustomDesignSettings

 /**
  * Recursively apply custom design settings to category if it's option
  * custom_use_parent_settings is setted to 1 while parent option is not
  *
  * @deprecated after 1.4.2.0-beta1, functionality moved to Mage_Catalog_Model_Design
  * @param Mage_Catalog_Model_Category $category
  * @param Mage_Core_Model_Layout_Update $update
  *
  * @return Mage_Catalog_CategoryController
  */
 protected function _applyCustomDesignSettings($category, $update)
 {
     if ($category->getCustomUseParentSettings() && $category->getLevel() > 1) {
         $parentCategory = $category->getParentCategory();
         if ($parentCategory && $parentCategory->getId()) {
             return $this->_applyCustomDesignSettings($parentCategory, $update);
         }
     }
     $validityDate = $category->getCustomDesignDate();
     if (array_key_exists('from', $validityDate) && array_key_exists('to', $validityDate) && Mage::app()->getLocale()->isStoreDateInInterval(null, $validityDate['from'], $validityDate['to'])) {
         if ($category->getPageLayout()) {
             $this->getLayout()->helper('page/layout')->applyHandle($category->getPageLayout());
         }
         $update->addUpdate($category->getCustomLayoutUpdate());
     }
     return $this;
 }
开发者ID:jpbender,项目名称:mage_virtual,代码行数:27,代码来源:CategoryController.php

示例3: getChildCategories

 /**
  * Recursively returns a value / label array of all active categories
  * @param Mage_Catalog_Model_Category $category
  * @param String $parentname
  * @return array
  */
 private function getChildCategories($category, $parentname = '')
 {
     //category not active - skip it
     if (!$category->getIsActive()) {
         return '';
     }
     //array containing all the categories to return
     $ret = array();
     /* Add the current category to return array
      * Root categories shouldn't be selected
      */
     if ($category->getLevel() > 1) {
         $ret[$category->getID()] = $category->getName() . $parentname;
     }
     // get all children
     if (Mage::helper('catalog/category_flat')->isEnabled()) {
         $children = (array) $category->getChildrenNodes();
         $childrenCount = count($children);
     } else {
         $children = $category->getChildrenCategories();
         $childrenCount = $children->count();
     }
     $hasChildren = $children && $childrenCount;
     // select active children
     $activeChildren = array();
     foreach ($children as $child) {
         if ($child->getIsActive()) {
             $activeChildren[] = $child;
         }
     }
     $activeChildrenCount = count($activeChildren);
     $hasActiveChildren = $activeChildrenCount > 0;
     /**
      * Use recursion to include all children categories too
      */
     foreach ($activeChildren as $child) {
         $childarray = $this->getChildCategories($child, " / " . $category->getName() . $parentname);
         foreach ($childarray as $k => $v) {
             $ret[$k] = $v;
         }
     }
     return $ret;
 }
开发者ID:jtoshmat,项目名称:mystore,代码行数:49,代码来源:Categories.php

示例4: _fastIndexerLoadNodes

 /**
  * Load nodes by parent id
  *
  * @param Mage_Catalog_Model_Category|int $parentNode
  * @param integer                         $recursionLevel
  * @param integer                         $storeId
  *
  * @return Mage_Catalog_Model_Resource_Category_Flat
  */
 protected function _fastIndexerLoadNodes($parentNode = null, $recursionLevel = 0, $storeId = 0)
 {
     $_conn = $this->_getReadAdapter();
     $startLevel = 1;
     $parentPath = '';
     if ($parentNode instanceof Mage_Catalog_Model_Category) {
         $parentPath = $parentNode->getPath();
         $startLevel = $parentNode->getLevel();
     } elseif (is_numeric($parentNode)) {
         $selectParent = $_conn->select()->from($this->getMainStoreTable($storeId))->where('entity_id = ?', $parentNode)->where('store_id = ?', $storeId);
         $parentNode = $_conn->fetchRow($selectParent);
         if ($parentNode) {
             $parentPath = $parentNode['path'];
             $startLevel = $parentNode['level'];
         }
     }
     $select = $_conn->select()->from(array('main_table' => $this->getMainStoreTable($storeId)), array('entity_id', new Zend_Db_Expr('main_table.' . $_conn->quoteIdentifier('name')), new Zend_Db_Expr('main_table.' . $_conn->quoteIdentifier('path')), 'is_active', 'is_anchor', 'main_table.url_path as request_path'))->where('main_table.is_active = ?', '1')->where('main_table.include_in_menu = ?', '1')->order('main_table.position');
     if ($parentPath) {
         $select->where($_conn->quoteInto("main_table.path like ?", "{$parentPath}/%"));
     }
     if ($recursionLevel != 0) {
         $levelField = $_conn->quoteIdentifier('level');
         $select->where($levelField . ' <= ?', $startLevel + $recursionLevel);
     }
     $inactiveCategories = $this->getInactiveCategoryIds();
     if (!empty($inactiveCategories)) {
         $select->where('main_table.entity_id NOT IN (?)', $inactiveCategories);
     }
     // Allow extensions to modify select (e.g. add custom category attributes to select)
     Mage::dispatchEvent('catalog_category_flat_loadnodes_before', array('select' => $select));
     $arrNodes = $_conn->fetchAll($select);
     $nodes = array();
     foreach ($arrNodes as $node) {
         $node['id'] = $node['entity_id'];
         $nodes[$node['id']] = Mage::getModel('catalog/category')->setData($node);
     }
     return $nodes;
 }
开发者ID:ThomasNegeli,项目名称:Magento-FastIndexer,代码行数:47,代码来源:FlatAbstract.php

示例5: getChildCategories

 /**
  * Recursively returns a value / label array of all active categories
  *
  * @param Mage_Catalog_Model_Category $category
  * @param String $parentname
  * @return array
  */
 private function getChildCategories($category, $parentname = '')
 {
     //category not active - skip it
     if (!$category->getIsActive()) {
         return '';
     }
     //array containing all the categories to return
     $ret = array();
     /* Add the current category to return array
      * Root categories shouldn't be selected
      */
     if ($category->getLevel() > 1) {
         $ret[$category->getID()] = ltrim($parentname . " / " . $category->getName(), " / ");
     }
     // get all children
     $children = $category->getChildrenCategories();
     $childrenCount = $children->count();
     $hasChildren = $children && $childrenCount;
     // select active children
     $activeChildren = array();
     foreach ($children as $child) {
         if ($child->getIsActive()) {
             $activeChildren[] = $child;
         }
     }
     $activeChildrenCount = count($activeChildren);
     $hasActiveChildren = $activeChildrenCount > 0;
     /**
      * Use recursion to include all children categories too
      */
     foreach ($activeChildren as $child) {
         $childarray = $this->getChildCategories($child, $parentname . " / " . $category->getName());
         foreach ($childarray as $k => $v) {
             $ret[$k] = ltrim($v, " / ");
         }
     }
     return $ret;
 }
开发者ID:ironizm,项目名称:background_image,代码行数:45,代码来源:Categories.php

示例6: getChildren

 /**
  * Return children ids of category
  *
  * @param Mage_Catalog_Model_Category $category
  * @param boolean $recursive
  * @return array
  */
 public function getChildren($category, $recursive = true)
 {
     $attributeId = (int) $this->_getIsActiveAttributeId();
     $backendTable = $this->getTable(array($this->getEntityTablePrefix(), 'int'));
     $adapter = $this->_getReadAdapter();
     $checkSql = $adapter->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
     $bind = array('attribute_id' => $attributeId, 'store_id' => $category->getStoreId(), 'scope' => 1, 'c_path' => $category->getPath() . '/%');
     $select = $this->_getReadAdapter()->select()->from(array('m' => $this->getEntityTable()), 'entity_id')->joinLeft(array('d' => $backendTable), 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = m.entity_id', array())->joinLeft(array('c' => $backendTable), 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id', array())->where($checkSql . ' = :scope')->where($adapter->quoteIdentifier('path') . ' LIKE :c_path');
     if (!$recursive) {
         $select->where($adapter->quoteIdentifier('level') . ' <= :c_level');
         $bind['c_level'] = $category->getLevel() + 1;
     }
     return $adapter->fetchCol($select, $bind);
 }
开发者ID:nemphys,项目名称:magento2,代码行数:21,代码来源:Category.php

示例7: getLevel

 /**
  * Return level of indent
  *
  * @param Mage_Catalog_Model_Category $item
  * @param integer $delta
  * @return integer
  */
 public function getLevel($item, $delta = 1)
 {
     return (int) ($item->getLevel() - $this->_storeRootCategoryLevel - 1) * $delta;
 }
开发者ID:natxetee,项目名称:magento2,代码行数:11,代码来源:Category.php

示例8: getChildren

 /**
  * Return children ids of category
  *
  * @param Mage_Catalog_Model_Category $category
  * @param integer $level
  * @return array
  */
 public function getChildren($category, $recursive = true, $isActive = true)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainStoreTable($category->getStoreId()), 'entity_id')->where('path LIKE ?', "{$category->getPath()}/%");
     if (!$recursive) {
         $select->where('level <= ?', $category->getLevel() + 1);
     }
     if ($isActive) {
         $select->where('is_active = ?', '1');
     }
     $_categories = $this->_getReadAdapter()->fetchAll($select);
     $categoriesIds = array();
     foreach ($_categories as $_category) {
         $categoriesIds[] = $_category['entity_id'];
     }
     return $categoriesIds;
 }
开发者ID:ronseigel,项目名称:agent-ohm,代码行数:23,代码来源:Resource_Eav_Mysql4_Category_Flat.php

示例9: testGetLevel

 public function testGetLevel()
 {
     $this->assertEquals(0, $this->_model->getLevel());
     $this->_model->setData('level', 1);
     $this->assertEquals(1, $this->_model->getLevel());
 }
开发者ID:nemphys,项目名称:magento2,代码行数:6,代码来源:CategoryTreeTest.php

示例10: getChildren

 /**
  * Return children ids of category
  *
  * @param Mage_Catalog_Model_Category $category
  * @param boolean $recursive
  * @return array
  */
 public function getChildren($category, $recursive = true)
 {
     $attributeId = $this->_getIsActiveAttributeId();
     $select = $this->_getReadAdapter()->select()->from(array('m' => $this->getEntityTable()), 'entity_id')->joinLeft(array('d' => $this->getEntityTable() . '_int'), "d.attribute_id = '{$attributeId}' AND d.store_id = 0 AND d.entity_id = m.entity_id", array())->joinLeft(array('c' => $this->getEntityTable() . '_int'), "c.attribute_id = '{$attributeId}' AND c.store_id = '{$category->getStoreId()}' AND c.entity_id = m.entity_id", array())->where('(IFNULL(c.value, d.value) = ?)', '1')->where('path LIKE ?', "{$category->getPath()}/%");
     if (!$recursive) {
         $select->where('level <= ?', $category->getLevel() + 1);
     }
     $_categories = $this->_getReadAdapter()->fetchAll($select);
     $categoriesIds = array();
     foreach ($_categories as $_category) {
         $categoriesIds[] = $_category['entity_id'];
     }
     return $categoriesIds;
     //        $this->_getTree()->load();
     //        return $this->_getTree()->getChildren($category->getId(), false);
 }
开发者ID:ronseigel,项目名称:agent-ohm,代码行数:23,代码来源:Resource_Eav_Mysql4_Category.php

示例11: getObject

 public function getObject(Mage_Catalog_Model_Category $category)
 {
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $productCollection = $category->getProductCollection();
     $category->setProductCount($productCollection->addMinimalPrice()->count());
     $transport = new Varien_Object();
     Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport));
     $customData = $transport->getData();
     $storeId = $category->getStoreId();
     $category->getUrlInstance()->setStore($storeId);
     $path = '';
     foreach ($category->getPathIds() as $categoryId) {
         if ($path != '') {
             $path .= ' / ';
         }
         $path .= $this->getCategoryName($categoryId, $storeId);
     }
     $image_url = NULL;
     try {
         $image_url = $category->getImageUrl();
     } catch (Exception $e) {
         /* no image, no default: not fatal */
     }
     $data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount());
     if (!empty($image_url)) {
         $data['image_url'] = $image_url;
     }
     foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
         $value = $category->getData($attribute['attribute']);
         $attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']);
         if ($attribute_ressource) {
             $value = $attribute_ressource->getFrontend()->getValue($category);
         }
         if (isset($data[$attribute['attribute']])) {
             $value = $data[$attribute['attribute']];
         }
         if ($value) {
             $data[$attribute['attribute']] = $value;
         }
     }
     $data = array_merge($data, $customData);
     foreach ($data as &$data0) {
         $data0 = $this->try_cast($data0);
     }
     return $data;
 }
开发者ID:halk,项目名称:algoliasearch-magento,代码行数:46,代码来源:Categoryhelper.php


注:本文中的Mage_Catalog_Model_Category::getLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。