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


PHP Category::getLevel方法代码示例

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


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

示例1: createCategory

 /**
  * Creates a new child category for $parentCategory
  *
  * @param \Magento\Catalog\Model\Category $parentCategory
  * @return \Magento\Catalog\Model\Category
  */
 protected function createCategory($parentCategory)
 {
     /** @var \Magento\Catalog\Model\Category $category */
     $category = $this->objectManager->create('Magento\\Catalog\\Model\\Category');
     $category->setStoreId(self::DEFAULT_STORE_ID)->setParentId($parentCategory->getId())->setName(self::NAMES_PREFIX . $this->titlesGenerator->generateCategoryTitle())->setAttributeSetId($category->getDefaultAttributeSetId())->setLevel($parentCategory->getLevel() + 1)->setPath($parentCategory->getPath())->setIsActive(1)->save();
     return $category;
 }
开发者ID:rogyar,项目名称:m2-sampledata-generator,代码行数:13,代码来源:CategoriesCreator.php

示例2: aroundReindex

 /**
  * Reindex category's data after into search engine after reindexing the category
  *
  * @param \Magento\Catalog\Model\Category $subject The category being reindexed
  * @param callable                        $proceed The parent function we are plugged on
  *                                                 : Magento\Catalog\Model\Category::reindex()
  *
  * @return \Magento\Catalog\Model\Category
  */
 public function aroundReindex(\Magento\Catalog\Model\Category $subject, callable $proceed)
 {
     $proceed();
     if ($subject->getLevel() > 1) {
         $categoryIndexer = $this->indexerRegistry->get(\Smile\ElasticsuiteCatalog\Model\Category\Indexer\Fulltext::INDEXER_ID);
         if (!$categoryIndexer->isScheduled()) {
             $categoryIndexer->reindexRow($subject->getId());
         }
     }
     return;
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:20,代码来源:ReindexCategoryAfterSave.php

示例3: getChildrenIds

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return int[]
  */
 public function getChildrenIds(Category $category, $recursive = false)
 {
     $cacheKey = $category->getId() . '_' . (int) $recursive;
     if (!isset($this->childrenIds[$cacheKey])) {
         $connection = $category->getResource()->getReadConnection();
         $select = $connection->select()->from($category->getResource()->getEntityTable(), 'entity_id')->where($connection->quoteIdentifier('path') . ' LIKE :c_path');
         $bind = ['c_path' => $category->getPath() . '/%'];
         if (!$recursive) {
             $select->where($connection->quoteIdentifier('level') . ' <= :c_level');
             $bind['c_level'] = $category->getLevel() + 1;
         }
         $this->childrenIds[$cacheKey] = $connection->fetchCol($select, $bind);
     }
     return $this->childrenIds[$cacheKey];
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:20,代码来源:ChildrenCategoriesProvider.php

示例4: isNeedToGenerateUrlPathForParent

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @return bool
  */
 protected function isNeedToGenerateUrlPathForParent($category)
 {
     return $category->isObjectNew() || $category->getLevel() >= self::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:8,代码来源:CategoryUrlPathGenerator.php

示例5: getChildren

 /**
  * Return children ids of category
  *
  * @param \Magento\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:pavelnovitsky,项目名称:magento2,代码行数:21,代码来源:Category.php

示例6: getChildren

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

示例7: testGetLevel

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

示例8: getObject

 public function getObject(Category $category)
 {
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $productCollection = $category->getProductCollection();
     $productCollection = $productCollection->addMinimalPrice();
     $category->setProductCount($productCollection->getSize());
     $transport = new DataObject();
     $this->eventManager->dispatch('algolia_category_index_before', ['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 = ['objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), 'include_in_menu' => $category->getIncludeInMenu(), '_tags' => ['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_resource = $category->getResource()->getAttribute($attribute['attribute']);
         if ($attribute_resource) {
             $value = $attribute_resource->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:algolia,项目名称:algoliasearch-magento-2,代码行数:47,代码来源:CategoryHelper.php

示例9: getChildren

 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param bool $recursive
  * @param bool $isActive
  * @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 = [];
     foreach ($_categories as $_category) {
         $categoriesIds[] = $_category['entity_id'];
     }
     return $categoriesIds;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:24,代码来源:Flat.php

示例10: getLevel

 /**
  * {@inheritdoc}
  */
 public function getLevel()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getLevel');
     if (!$pluginInfo) {
         return parent::getLevel();
     } else {
         return $this->___callPlugins('getLevel', func_get_args(), $pluginInfo);
     }
 }
开发者ID:HaonanXu,项目名称:der-snack-backup,代码行数:12,代码来源:Interceptor.php

示例11: _isValidCategory

 /**
  * Validate category for be using as filter
  *
  * @param  \Magento\Catalog\Model\Category $category
  * @return mixed
  */
 protected function _isValidCategory($category)
 {
     if ($category->getId()) {
         while ($category->getLevel() != 0) {
             if (!$category->getIsActive()) {
                 return false;
             }
             $category = $category->getParentCategory();
         }
         return true;
     }
     return false;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:19,代码来源:Category.php


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