本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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];
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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");
}
}
示例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;
}
示例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;
}
示例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();
}