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


PHP Category::getId方法代码示例

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


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

示例1: generateForCustom

 /**
  * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url
  * @param int $storeId
  * @return array
  */
 protected function generateForCustom($url, $storeId)
 {
     $urls = [];
     $targetPath = !$url->getRedirectType() ? $url->getTargetPath() : $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category, $storeId);
     if ($url->getRequestPath() !== $targetPath) {
         $urls[$url->getRequestPath() . '_' . $storeId] = $this->urlRewriteFactory->create()->setEntityType(CategoryUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($this->category->getId())->setRequestPath($url->getRequestPath())->setTargetPath($targetPath)->setRedirectType($url->getRedirectType())->setStoreId($storeId)->setDescription($url->getDescription())->setIsAutogenerated(0)->setMetadata($url->getMetadata());
     }
     return $urls;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:CurrentUrlRewritesRegenerator.php

示例2: generateForGlobalScope

 /**
  * Generate list of urls for global scope
  *
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 protected function generateForGlobalScope()
 {
     $urls = [];
     $categoryId = $this->category->getId();
     foreach ($this->category->getStoreIds() as $id) {
         if (!$this->isGlobalScope($id) && !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($id, $categoryId, Category::ENTITY)) {
             $urls = array_merge($urls, $this->generateForSpecificStoreView($id));
         }
     }
     return $urls;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:CategoryUrlRewriteGenerator.php

示例3: 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

示例4: testCheckId

 public function testCheckId()
 {
     $this->_model = $this->getCategoryByName('Category 1.1.1');
     $categoryId = $this->_model->getId();
     $this->assertEquals($categoryId, $this->_model->checkId($categoryId));
     $this->assertFalse($this->_model->checkId(111));
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:7,代码来源:CategoryTest.php

示例5: getNode

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @return Node
  */
 protected function getNode(\Magento\Catalog\Model\Category $category)
 {
     $nodeId = $category->getId();
     $node = $this->categoryTree->loadNode($nodeId);
     $node->loadChildren();
     $this->prepareCollection();
     $this->categoryTree->addCollectionData($this->categoryCollection);
     return $node;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Tree.php

示例6: 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

示例7: 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

示例8: testDeleteChildren

 /**
  * @magentoAppArea adminhtml
  */
 public function testDeleteChildren()
 {
     $this->_model->unsetData();
     $this->_model->load(4);
     $this->_model->setSkipDeleteChildren(true);
     $this->_model->delete();
     $this->_model->unsetData();
     $this->_model->load(5);
     $this->assertEquals($this->_model->getId(), 5);
     $this->_model->unsetData();
     $this->_model->load(3);
     $this->assertEquals($this->_model->getId(), 3);
     $this->_model->delete();
     $this->_model->unsetData();
     $this->_model->load(5);
     $this->assertEquals($this->_model->getId(), null);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:20,代码来源:CategoryTest.php

示例9: getCanonicalUrlPath

 /**
  * Get canonical product url path
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\Category|null $category
  * @return string
  */
 public function getCanonicalUrlPath($product, $category = null)
 {
     $path = 'catalog/product/view/id/' . $product->getId();
     return $category ? $path . '/category/' . $category->getId() : $path;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:ProductUrlPathGenerator.php

示例10: getProductCount

 /**
  * Get products count in category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @return integer
  */
 public function getProductCount($category)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getTable('catalog_category_product'), "COUNT({$this->getTable('catalog_category_product')}.product_id)")->where("{$this->getTable('catalog_category_product')}.category_id = ?", $category->getId())->group("{$this->getTable('catalog_category_product')}.category_id");
     return (int) $this->_getReadAdapter()->fetchOne($select);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:Flat.php

示例11: getId

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

示例12: checkCategoryData

 /**
  * Check EAV and flat data
  *
  * @param \Magento\Catalog\Model\Category $category
  */
 protected function checkCategoryData(\Magento\Catalog\Model\Category $category)
 {
     foreach (self::$attributeCodes as $attributeCode) {
         $this->assertEquals(self::$attributeValues[$category->getId()][$attributeCode], $category->getData($attributeCode), "Data for {$category->getId()} attribute code [{$attributeCode}] is wrong");
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:FlatTest.php

示例13: isActive

 /**
  * Get current category
  *
  * @param \Magento\Catalog\Model\Category $category
  *
  * @return Category
  */
 public function isActive($category)
 {
     $activeCategory = $this->_coreRegistry->registry('current_category');
     $activeProduct = $this->_coreRegistry->registry('current_product');
     if (!$activeCategory) {
         // Check if we're on a product page
         if ($activeProduct !== null) {
             return in_array($category->getId(), $activeProduct->getCategoryIds());
         }
         return false;
     }
     // Check if this is the active category
     if ($this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource() and $category->getId() == $activeCategory->getId()) {
         return true;
     }
     // Check if a subcategory of this category is active
     $childrenIds = $category->getAllChildren(true);
     if (!is_null($childrenIds) and in_array($activeCategory->getId(), $childrenIds)) {
         return true;
     }
     // Fallback - If Flat categories is not enabled the active category does not give an id
     return $category->getName() == $activeCategory->getName() ? true : false;
 }
开发者ID:Sebwite,项目名称:magento2-category-sidebar,代码行数:30,代码来源:Sidebar.php

示例14: _processPositions

 /**
  * Process positions of old parent category children and new parent category children.
  * Get position for moved category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param \Magento\Catalog\Model\Category $newParent
  * @param null|int $afterCategoryId
  * @return int
  */
 protected function _processPositions($category, $newParent, $afterCategoryId)
 {
     $table = $this->getEntityTable();
     $adapter = $this->_getWriteAdapter();
     $positionField = $adapter->quoteIdentifier('position');
     $bind = array('position' => new \Zend_Db_Expr($positionField . ' - 1'));
     $where = array('parent_id = ?' => $category->getParentId(), $positionField . ' > ?' => $category->getPosition());
     $adapter->update($table, $bind, $where);
     /**
      * Prepare position value
      */
     if ($afterCategoryId) {
         $select = $adapter->select()->from($table, 'position')->where('entity_id = :entity_id');
         $position = $adapter->fetchOne($select, array('entity_id' => $afterCategoryId));
         $position += 1;
     } else {
         $position = 1;
     }
     $bind = array('position' => new \Zend_Db_Expr($positionField . ' + 1'));
     $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' >= ?' => $position);
     $adapter->update($table, $bind, $where);
     return $position;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:32,代码来源:Category.php

示例15: getCanonicalUrlPath

 /**
  * Get canonical category url
  *
  * @param \Magento\Catalog\Model\Category $category
  * @return string
  */
 public function getCanonicalUrlPath($category)
 {
     return 'catalog/category/view/id/' . $category->getId();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:10,代码来源:CategoryUrlPathGenerator.php


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