Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Category Class Reference
Inheritance diagram for Category:
AbstractModel IdentityInterface CategoryInterface CategoryTreeInterface AbstractExtensibleModel CustomAttributesDataInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService, \Magento\Catalog\Model\ResourceModel\Category\Tree $categoryTreeResource, \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryTreeFactory, \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeCollectionFactory, \Magento\Framework\UrlInterface $url, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Catalog\Model\Config $catalogConfig, \Magento\Framework\Filter\FilterManager $filter, Indexer\Category\Flat\State $flatState, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, UrlFinderInterface $urlFinder, \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getUseFlatResource ()
 
 getUrlInstance ()
 
 getTreeModel ()
 
 getTreeModelInstance ()
 
 move ($parentId, $afterCategoryId)
 
 getDefaultAttributeSetId ()
 
 getProductCollection ()
 
 getAttributes ($noDesignAttributes=false)
 
 getProductsPosition ()
 
 getStoreIds ()
 
 getStoreId ()
 
 setStoreId ($storeId)
 
 getUrl ()
 
 getCategoryIdUrl ()
 
 formatUrlKey ($str)
 
 getImageUrl ($attributeCode='image')
 
 getParentCategory ()
 
 getParentId ()
 
 getParentIds ()
 
 getCustomDesignDate ()
 
 getDesignAttributes ()
 
 getAllChildren ($asArray=false)
 
 getChildren ($recursive=false, $isActive=true, $sortByPosition=false)
 
 getPathInStore ()
 
 checkId ($id)
 
 getPathIds ()
 
 getLevel ()
 
 verifyIds (array $ids)
 
 hasChildren ()
 
 getRequestPath ()
 
 getName ()
 
 beforeDelete ()
 
 getAnchorsAbove ()
 
 getProductCount ()
 
 getCategories ($parent, $recursionLevel=0, $sorted=false, $asCollection=false, $toLoad=true)
 
 getParentCategories ()
 
 getChildrenCategories ()
 
 getParentDesignCategory ()
 
 isInRootCategoryList ()
 
 getAvailableSortBy ()
 
 getAvailableSortByOptions ()
 
 getDefaultSortBy ()
 
 validate ()
 
 afterSave ()
 
 reindex ()
 
 afterDeleteCommit ()
 
 getIdentities ()
 
 getPath ()
 
 getPosition ()
 
 getChildrenCount ()
 
 getCreatedAt ()
 
 getUpdatedAt ()
 
 getIsActive ()
 
 getCategoryId ()
 
 getDisplayMode ()
 
 getIncludeInMenu ()
 
 getUrlKey ()
 
 getChildrenData ()
 
 __toArray ()
 
 setParentId ($parentId)
 
 setName ($name)
 
 setIsActive ($isActive)
 
 setPosition ($position)
 
 setLevel ($level)
 
 setUpdatedAt ($updatedAt)
 
 setCreatedAt ($createdAt)
 
 setPath ($path)
 
 setAvailableSortBy ($availableSortBy)
 
 setIncludeInMenu ($includeInMenu)
 
 setProductCount ($productCount)
 
 setChildrenData (array $childrenData=null)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 lockAttribute ($attributeCode)
 
 unlockAttribute ($attributeCode)
 
 unlockAttributes ()
 
 getLockedAttributes ()
 
 hasLockedAttributes ()
 
 isLockedAttribute ($attributeCode)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getResourceCollection ()
 
 loadByAttribute ($attribute, $value, $additionalAttributes=' *')
 
 getStore ()
 
 getWebsiteStoreIds ()
 
 setAttributeDefaultValue ($attributeCode, $value)
 
 getAttributeDefaultValue ($attributeCode)
 
 setExistsStoreValueFlag ($attributeCode)
 
 getExistsStoreValueFlag ($attributeCode)
 
 beforeSave ()
 
 isDeleteable ()
 
 setIsDeleteable ($value)
 
 isReadonly ()
 
 setIsReadonly ($value)
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from CategoryInterface
 getId ()
 
 setId ($id)
 
 getChildren ()
 
- Public Member Functions inherited from CategoryTreeInterface
 getId ()
 
 setId ($id)
 

Data Fields

const ENTITY = 'catalog_category'
 
const DM_PRODUCT = 'PRODUCTS'
 
const DM_PAGE = 'PAGE'
 
const DM_MIXED = 'PRODUCTS_AND_PAGE'
 
const ROOT_CATEGORY_ID = 0
 
const TREE_ROOT_ID = 1
 
const CACHE_TAG = 'cat_c'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from CategoryInterface
const KEY_PARENT_ID = 'parent_id'
 
const KEY_NAME = 'name'
 
const KEY_IS_ACTIVE = 'is_active'
 
const KEY_POSITION = 'position'
 
const KEY_LEVEL = 'level'
 
const KEY_UPDATED_AT = 'updated_at'
 
const KEY_CREATED_AT = 'created_at'
 
const KEY_PATH = 'path'
 
const KEY_AVAILABLE_SORT_BY = 'available_sort_by'
 
const KEY_INCLUDE_IN_MENU = 'include_in_menu'
 
const KEY_PRODUCT_COUNT = 'product_count'
 
const KEY_CHILDREN_DATA = 'children_data'
 
const ATTRIBUTES
 

Protected Member Functions

 _construct ()
 
 getCustomAttributesCodes ()
 
 _getResource ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'catalog_category'
 
 $_eventObject = 'category'
 
 $_cacheTag = self::CACHE_TAG
 
 $_url
 
 $_resource
 
 $_urlRewrite
 
 $_useFlatResource = false
 
 $_designAttributes
 
 $interfaceAttributes = CategoryInterface::ATTRIBUTES
 
 $_treeModel = null
 
 $filter
 
 $_catalogConfig
 
 $_productCollectionFactory
 
 $_storeCollectionFactory
 
 $_categoryTreeFactory
 
 $flatState
 
 $categoryUrlPathGenerator
 
 $urlFinder
 
 $indexerRegistry
 
 $categoryRepository
 
 $metadataService
 
- Protected Attributes inherited from AbstractModel
 $_defaultValues
 
 $_storeValuesFlags
 
 $_lockedAttributes = []
 
 $_isDeleteable = true
 
 $_isReadonly = false
 
 $_storeManager
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Catalog category

@api @method Category setAffectedProductIds(array $productIds) @method array getAffectedProductIds() @method Category setMovedCategoryId(array $productIds) @method int getMovedCategoryId() @method Category setAffectedCategoryIds(array $categoryIds) @method array getAffectedCategoryIds() @method Category setUrlKey(string $urlKey) @method Category setUrlPath(string $urlPath) @method Category getSkipDeleteChildren() @method Category setSkipDeleteChildren(boolean $value) @method Category setChangedProductIds(array $categoryIds) Set products ids that inserted or deleted for category @method array getChangedProductIds() Get products ids that inserted or deleted for category

@SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 42 of file Category.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
AttributeValueFactory  $customAttributeFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Catalog\Api\CategoryAttributeRepositoryInterface  $metadataService,
\Magento\Catalog\Model\ResourceModel\Category\Tree  $categoryTreeResource,
\Magento\Catalog\Model\ResourceModel\Category\TreeFactory  $categoryTreeFactory,
\Magento\Store\Model\ResourceModel\Store\CollectionFactory  $storeCollectionFactory,
\Magento\Framework\UrlInterface  $url,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory  $productCollectionFactory,
\Magento\Catalog\Model\Config  $catalogConfig,
\Magento\Framework\Filter\FilterManager  $filter,
Indexer\Category\Flat\State  $flatState,
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator  $categoryUrlPathGenerator,
UrlFinderInterface  $urlFinder,
\Magento\Framework\Indexer\IndexerRegistry  $indexerRegistry,
CategoryRepositoryInterface  $categoryRepository,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
AttributeValueFactory$customAttributeFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Catalog\Api\CategoryAttributeRepositoryInterface$metadataService
\Magento\Catalog\Model\ResourceModel\Category\Tree$categoryTreeResource
\Magento\Catalog\Model\ResourceModel\Category\TreeFactory$categoryTreeFactory
\Magento\Store\Model\ResourceModel\Store\CollectionFactory$storeCollectionFactory
\Magento\Framework\UrlInterface$url
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory$productCollectionFactory
Config$catalogConfig
\Magento\Framework\Filter\FilterManager$filter
Indexer\Category\Flat\State$flatState
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator$categoryUrlPathGenerator
UrlFinderInterface$urlFinder
\Magento\Framework\Indexer\IndexerRegistry$indexerRegistry
CategoryRepositoryInterface$categoryRepository
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 239 of file Category.php.

261  {
262  $this->metadataService = $metadataService;
263  $this->_treeModel = $categoryTreeResource;
264  $this->_categoryTreeFactory = $categoryTreeFactory;
265  $this->_storeCollectionFactory = $storeCollectionFactory;
266  $this->_url = $url;
267  $this->_productCollectionFactory = $productCollectionFactory;
268  $this->_catalogConfig = $catalogConfig;
269  $this->filter = $filter;
270  $this->flatState = $flatState;
271  $this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
272  $this->urlFinder = $urlFinder;
273  $this->indexerRegistry = $indexerRegistry;
274  $this->categoryRepository = $categoryRepository;
275  parent::__construct(
276  $context,
277  $registry,
278  $extensionFactory,
281  $resource,
282  $resourceCollection,
283  $data
284  );
285  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ __toArray()

__toArray ( )

Return Data Object data in array format.

Returns
array
Todo:
refactor with converter for AbstractExtensibleModel

Definition at line 1252 of file Category.php.

1253  {
1254  $data = $this->_data;
1255  $hasToArray = function ($model) {
1256  return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);
1257  };
1258  foreach ($data as $key => $value) {
1259  if ($hasToArray($value)) {
1260  $data[$key] = $value->__toArray();
1261  } elseif (is_array($value)) {
1262  foreach ($value as $nestedKey => $nestedValue) {
1263  if ($hasToArray($nestedValue)) {
1264  $value[$nestedKey] = $nestedValue->__toArray();
1265  }
1266  }
1267  $data[$key] = $value;
1268  }
1269  }
1270  return $data;
1271  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16

◆ _construct()

_construct ( )
protected

Initialize resource mode

Returns
void

Definition at line 292 of file Category.php.

293  {
294  // If Flat Index enabled then use it but only on frontend
295  if ($this->flatState->isAvailable()) {
296  $this->_init(\Magento\Catalog\Model\ResourceModel\Category\Flat::class);
297  $this->_useFlatResource = true;
298  } else {
299  $this->_init(\Magento\Catalog\Model\ResourceModel\Category::class);
300  }
301  }

◆ _getResource()

_getResource ( )
protected
Exceptions

Definition at line 321 of file Category.php.

322  {
323  return parent::_getResource();
324  }

◆ afterDeleteCommit()

afterDeleteCommit ( )

Init indexing process after category delete

Returns
\Magento\Framework\Model\AbstractModel

Definition at line 1129 of file Category.php.

1130  {
1131  $this->reindex();
1132  return parent::afterDeleteCommit();
1133  }

◆ afterSave()

afterSave ( )

Add reindexCallback

Returns
\Magento\Catalog\Model\Category

Definition at line 1092 of file Category.php.

1093  {
1094  $result = parent::afterSave();
1095  $this->_getResource()->addCommitCallback([$this, 'reindex']);
1096  return $result;
1097  }

◆ beforeDelete()

beforeDelete ( )

Before delete process

Exceptions

Definition at line 905 of file Category.php.

906  {
907  if ($this->getResource()->isForbiddenToDelete($this->getId())) {
908  throw new \Magento\Framework\Exception\LocalizedException(__('Can\'t delete root category.'));
909  }
910  return parent::beforeDelete();
911  }
__()
Definition: __.php:13

◆ checkId()

checkId (   $id)

Check category id existing

Parameters
int$id
Returns
bool

Definition at line 824 of file Category.php.

825  {
826  return $this->_getResource()->checkId($id);
827  }
$id
Definition: fieldset.phtml:14

◆ formatUrlKey()

formatUrlKey (   $str)

Format URL key from name or defined key

Parameters
string$str
Returns
string

Definition at line 647 of file Category.php.

648  {
649  return $this->filter->translitUrl($str);
650  }

◆ getAllChildren()

getAllChildren (   $asArray = false)

Get all children categories IDs

Parameters
boolean$asArrayreturn result as array instead of comma-separated list of IDs
Returns
array|string

Definition at line 776 of file Category.php.

777  {
778  $children = $this->getResource()->getAllChildren($this);
779  if ($asArray) {
780  return $children;
781  } else {
782  return implode(',', $children);
783  }
784  }
$children
Definition: actions.phtml:11

◆ getAnchorsAbove()

getAnchorsAbove ( )

Retrieve anchors above

Returns
array

Definition at line 918 of file Category.php.

919  {
920  $anchors = [];
921  $path = $this->getPathIds();
922 
923  if (in_array($this->getId(), $path)) {
924  unset($path[array_search($this->getId(), $path)]);
925  }
926 
927  if ($this->_useFlatResource) {
928  $anchors = $this->_getResource()->getAnchorsAbove($path, $this->getStoreId());
929  } else {
930  if (!$this->_registry->registry('_category_is_anchor_attribute')) {
931  $model = $this->_getAttribute('is_anchor');
932  $this->_registry->register('_category_is_anchor_attribute', $model);
933  }
934 
935  $isAnchorAttribute = $this->_registry->registry('_category_is_anchor_attribute');
936  if ($isAnchorAttribute) {
937  $anchors = $this->getResource()->findWhereAttributeIs($path, $isAnchorAttribute, 1);
938  }
939  }
940  return $anchors;
941  }

◆ getAttributes()

getAttributes (   $noDesignAttributes = false)

Retrieve all customer attributes

Parameters
bool$noDesignAttributes
Returns
array
Todo:
Use with Flat Resource @SuppressWarnings(PHPMD.UnusedLocalVariable)

Definition at line 482 of file Category.php.

483  {
484  $result = $this->getResource()->loadAllAttributes($this)->getSortedAttributes();
485 
486  if ($noDesignAttributes) {
487  foreach ($result as $k => $a) {
488  if (in_array($k, $this->_designAttributes)) {
489  unset($result[$k]);
490  }
491  }
492  }
493 
494  return $result;
495  }

◆ getAvailableSortBy()

getAvailableSortBy ( )

Retrieve Available int Product Listing sort by

Returns
null|array

Implements CategoryInterface.

Definition at line 1020 of file Category.php.

1021  {
1022  $available = $this->getData(self::KEY_AVAILABLE_SORT_BY);
1023  if (empty($available)) {
1024  return [];
1025  }
1026  if ($available && !is_array($available)) {
1027  $available = explode(',', $available);
1028  }
1029  return $available;
1030  }

◆ getAvailableSortByOptions()

getAvailableSortByOptions ( )

Retrieve Available Product Listing Sort By code as key, value - name

Returns
array

Definition at line 1038 of file Category.php.

1039  {
1040  $availableSortBy = [];
1041  $defaultSortBy = $this->_catalogConfig->getAttributeUsedForSortByArray();
1042  if ($this->getAvailableSortBy()) {
1043  foreach ($this->getAvailableSortBy() as $sortBy) {
1044  if (isset($defaultSortBy[$sortBy])) {
1045  $availableSortBy[$sortBy] = $defaultSortBy[$sortBy];
1046  }
1047  }
1048  }
1049 
1050  if (!$availableSortBy) {
1051  $availableSortBy = $defaultSortBy;
1052  }
1053 
1054  return $availableSortBy;
1055  }

◆ getCategories()

getCategories (   $parent,
  $recursionLevel = 0,
  $sorted = false,
  $asCollection = false,
  $toLoad = true 
)

Retrieve categories by parent

Parameters
int$parent
int$recursionLevel
bool$sorted
bool$asCollection
bool$toLoad
Returns
\Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\ResourceModel\Category\Collection

Definition at line 968 of file Category.php.

969  {
970  $categories = $this->getResource()->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
971  return $categories;
972  }
$categories

◆ getCategoryId()

getCategoryId ( )
Returns
int|null

Definition at line 1207 of file Category.php.

1208  {
1209  return $this->getData('category_id');
1210  }

◆ getCategoryIdUrl()

getCategoryIdUrl ( )

Retrieve category id URL

Returns
string

Definition at line 632 of file Category.php.

633  {
634  Profiler::start('REGULAR: ' . __METHOD__, ['group' => 'REGULAR', 'method' => __METHOD__]);
635  $urlKey = $this->getUrlKey() ? $this->getUrlKey() : $this->formatUrlKey($this->getName());
636  $url = $this->getUrlInstance()->getUrl('catalog/category/view', ['s' => $urlKey, 'id' => $this->getId()]);
637  Profiler::stop('REGULAR: ' . __METHOD__);
638  return $url;
639  }

◆ getChildren()

getChildren (   $recursive = false,
  $isActive = true,
  $sortByPosition = false 
)

Retrieve children ids comma separated

Parameters
boolean$recursive
boolean$isActive
boolean$sortByPosition
Returns
string

Definition at line 794 of file Category.php.

795  {
796  return implode(',', $this->getResource()->getChildren($this, $recursive, $isActive, $sortByPosition));
797  }

◆ getChildrenCategories()

getChildrenCategories ( )

Return children categories of current category

Returns
\Magento\Catalog\Model\ResourceModel\Category\Collection|\Magento\Catalog\Model\Category[]

Definition at line 989 of file Category.php.

990  {
991  return $this->getResource()->getChildrenCategories($this);
992  }

◆ getChildrenCount()

getChildrenCount ( )
Returns
int

Definition at line 1174 of file Category.php.

1175  {
1176  return $this->getData('children_count');
1177  }

◆ getChildrenData()

getChildrenData ( )
Returns
\Magento\Catalog\Api\Data\CategoryTreeInterface[]|null

Implements CategoryTreeInterface.

Definition at line 1239 of file Category.php.

1240  {
1241  return $this->getData(self::KEY_CHILDREN_DATA);
1242  }

◆ getCreatedAt()

getCreatedAt ( )
Returns
string|null

Implements CategoryInterface.

Definition at line 1182 of file Category.php.

1183  {
1184  return $this->getData('created_at');
1185  }

◆ getCustomAttributesCodes()

getCustomAttributesCodes ( )
protected

{}

Definition at line 306 of file Category.php.

307  {
308  if ($this->customAttributesCodes === null) {
309  $this->customAttributesCodes = $this->getEavAttributesCodes($this->metadataService);
310  $this->customAttributesCodes = array_diff($this->customAttributesCodes, CategoryInterface::ATTRIBUTES);
311  }
313  }

◆ getCustomDesignDate()

getCustomDesignDate ( )

Retrieve dates for custom design (from & to)

Returns
array

Definition at line 731 of file Category.php.

732  {
733  $result = [];
734  $result['from'] = $this->getData('custom_design_from');
735  $result['to'] = $this->getData('custom_design_to');
736 
737  return $result;
738  }

◆ getDefaultAttributeSetId()

getDefaultAttributeSetId ( )

Retrieve default attribute set id

Returns
int

Definition at line 454 of file Category.php.

455  {
456  return $this->getResource()->getEntityType()->getDefaultAttributeSetId();
457  }

◆ getDefaultSortBy()

getDefaultSortBy ( )

Retrieve Product Listing Default Sort By

Returns
string

Definition at line 1062 of file Category.php.

1063  {
1064  if (!($sortBy = $this->getData('default_sort_by'))) {
1065  $sortBy = $this->_catalogConfig->getProductListDefaultSortBy($this->getStoreId());
1066  }
1067  $available = $this->getAvailableSortByOptions();
1068  if (!isset($available[$sortBy])) {
1069  $sortBy = array_keys($available);
1070  $sortBy = $sortBy[0];
1071  }
1072 
1073  return $sortBy;
1074  }

◆ getDesignAttributes()

getDesignAttributes ( )

Retrieve design attributes array

Returns
array

Definition at line 745 of file Category.php.

746  {
747  $result = [];
748  foreach ($this->_designAttributes as $attrName) {
749  $result[] = $this->_getAttribute($attrName);
750  }
751  return $result;
752  }

◆ getDisplayMode()

getDisplayMode ( )
Returns
string|null

Definition at line 1215 of file Category.php.

1216  {
1217  return $this->getData('display_mode');
1218  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

{Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Catalog\Api\Data\CategoryExtensionInterface|null
}

Returns
\Magento\Catalog\Api\Data\CategoryExtensionInterface|null

Implements CategoryInterface.

Definition at line 1421 of file Category.php.

◆ getIdentities()

getIdentities ( )

Get identities

Returns
array

Implements IdentityInterface.

Definition at line 1140 of file Category.php.

1141  {
1142  $identities = [
1143  self::CACHE_TAG . '_' . $this->getId(),
1144  ];
1145  if (!$this->getId() || $this->hasDataChanges()
1146  || $this->isDeleted() || $this->dataHasChangedFor(self::KEY_INCLUDE_IN_MENU)
1147  ) {
1148  $identities[] = self::CACHE_TAG;
1149  $identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
1150  }
1151  return $identities;
1152  }

◆ getImageUrl()

getImageUrl (   $attributeCode = 'image')
Parameters
string$attributeCode
Returns
bool|string
Exceptions

Definition at line 657 of file Category.php.

658  {
659  $url = false;
660  $image = $this->getData($attributeCode);
661  if ($image) {
662  if (is_string($image)) {
663  $store = $this->_storeManager->getStore();
664 
665  $isRelativeUrl = substr($image, 0, 1) === '/';
666 
667  $mediaBaseUrl = $store->getBaseUrl(
668  \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
669  );
670 
671  if ($isRelativeUrl) {
672  $url = $image;
673  } else {
674  $url = $mediaBaseUrl
675  . ltrim(\Magento\Catalog\Model\Category\FileInfo::ENTITY_MEDIA_PATH, '/')
676  . '/'
677  . $image;
678  }
679  } else {
680  throw new \Magento\Framework\Exception\LocalizedException(
681  __('Something went wrong while getting the image url.')
682  );
683  }
684  }
685  return $url;
686  }
__()
Definition: __.php:13
$attributeCode
Definition: extend.phtml:12

◆ getIncludeInMenu()

getIncludeInMenu ( )
Returns
bool|null

Implements CategoryInterface.

Definition at line 1223 of file Category.php.

1224  {
1225  return $this->getData(self::KEY_INCLUDE_IN_MENU);
1226  }

◆ getIsActive()

getIsActive ( )
Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Implements CategoryInterface.

Definition at line 1199 of file Category.php.

1200  {
1201  return $this->getData(self::KEY_IS_ACTIVE);
1202  }

◆ getLevel()

getLevel ( )

Retrieve level

Returns
int

Implements CategoryInterface.

Definition at line 850 of file Category.php.

851  {
852  if (!$this->hasLevel()) {
853  return count(explode('/', $this->getPath())) - 1;
854  }
855  return $this->getData(self::KEY_LEVEL);
856  }

◆ getName()

getName ( )

Retrieve Name data wrapper

Returns
string

Implements CategoryInterface.

Definition at line 894 of file Category.php.

895  {
896  return $this->_getData(self::KEY_NAME);
897  }

◆ getParentCategories()

getParentCategories ( )

Return parent categories of current category

Returns
\Magento\Framework\DataObject[]|\Magento\Catalog\Model\Category[]

Return parent categories of category

Parameters
\Magento\Catalog\Model\Category$category
Returns
\Magento\Framework\DataObject[]

Definition at line 979 of file Category.php.

980  {
981  return $this->getResource()->getParentCategories($this);
982  }

◆ getParentCategory()

getParentCategory ( )

Get parent category object

Returns
\Magento\Catalog\Model\Category

Definition at line 693 of file Category.php.

694  {
695  if (!$this->hasData('parent_category')) {
696  $this->setData('parent_category', $this->categoryRepository->get($this->getParentId()));
697  }
698  return $this->_getData('parent_category');
699  }

◆ getParentDesignCategory()

getParentDesignCategory ( )

Return parent category of current category with own custom design settings

Returns
\Magento\Catalog\Model\Category

Definition at line 999 of file Category.php.

1000  {
1001  return $this->getResource()->getParentDesignCategory($this);
1002  }

◆ getParentId()

getParentId ( )

Get parent category identifier

Returns
int

Implements CategoryInterface.

Definition at line 706 of file Category.php.

707  {
708  $parentId = $this->getData(self::KEY_PARENT_ID);
709  if (isset($parentId)) {
710  return $parentId;
711  }
712  $parentIds = $this->getParentIds();
713  return intval(array_pop($parentIds));
714  }

◆ getParentIds()

getParentIds ( )

Get all parent categories ids

Returns
array

Definition at line 721 of file Category.php.

722  {
723  return array_diff($this->getPathIds(), [$this->getId()]);
724  }

◆ getPath()

getPath ( )

@codeCoverageIgnoreStart

Returns
string|null

Implements CategoryInterface.

Definition at line 1158 of file Category.php.

1159  {
1160  return $this->getData(self::KEY_PATH);
1161  }

◆ getPathIds()

getPathIds ( )

Get array categories ids which are part of category path Result array contain id of current category because it is part of the path

Returns
array

Definition at line 835 of file Category.php.

836  {
837  $ids = $this->getData('path_ids');
838  if ($ids === null) {
839  $ids = explode('/', $this->getPath());
840  $this->setData('path_ids', $ids);
841  }
842  return $ids;
843  }

◆ getPathInStore()

getPathInStore ( )

Retrieve Stores where isset category Path Return comma separated string

Returns
string

Definition at line 805 of file Category.php.

806  {
807  $result = [];
808  $path = array_reverse($this->getPathIds());
809  foreach ($path as $itemId) {
810  if ($itemId == $this->_storeManager->getStore()->getRootCategoryId()) {
811  break;
812  }
813  $result[] = $itemId;
814  }
815  return implode(',', $result);
816  }

◆ getPosition()

getPosition ( )
Returns
int|null

Implements CategoryInterface.

Definition at line 1166 of file Category.php.

1167  {
1168  return $this->getData(self::KEY_POSITION);
1169  }

◆ getProductCollection()

getProductCollection ( )

Get category products collection

Returns
\Magento\Framework\Data\Collection\AbstractDb
Parameters
\Magento\Catalog\Model\Category$category
int$storeId
Returns
$this

Definition at line 464 of file Category.php.

465  {
466  $collection = $this->_productCollectionFactory->create()->setStoreId(
467  $this->getStoreId()
468  )->addCategoryFilter(
469  $this
470  );
471  return $collection;
472  }

◆ getProductCount()

getProductCount ( )

Retrieve count products of category

Returns
int

Implements CategoryTreeInterface.

Definition at line 948 of file Category.php.

949  {
950  if (!$this->hasData(self::KEY_PRODUCT_COUNT)) {
951  $count = $this->_getResource()->getProductCount($this);
952  $this->setData(self::KEY_PRODUCT_COUNT, $count);
953  }
954 
955  return $this->getData(self::KEY_PRODUCT_COUNT);
956  }
$count
Definition: recent.phtml:13

◆ getProductsPosition()

getProductsPosition ( )

Retrieve array of product id's for category

The array returned has the following format: array($productId => $position)

Returns
array

Definition at line 505 of file Category.php.

506  {
507  if (!$this->getId()) {
508  return [];
509  }
510 
511  $array = $this->getData('products_position');
512  if ($array === null) {
513  $array = $this->getResource()->getProductsPosition($this);
514  $this->setData('products_position', $array);
515  }
516  return $array;
517  }

◆ getRequestPath()

getRequestPath ( )

Retrieve Request Path

Returns
string

Definition at line 884 of file Category.php.

885  {
886  return $this->_getData('request_path');
887  }

◆ getStoreId()

getStoreId ( )

Return store id.

If store id is underfined for category return current active store id

Returns
integer

Definition at line 569 of file Category.php.

570  {
571  if ($this->hasData('store_id')) {
572  return (int)$this->_getData('store_id');
573  }
574  return (int)$this->_storeManager->getStore()->getId();
575  }

◆ getStoreIds()

getStoreIds ( )

Retrieve array of store ids for category

Returns
array

Definition at line 524 of file Category.php.

525  {
526  if ($this->getInitialSetupFlag()) {
527  return [];
528  }
529 
530  $storeIds = $this->getData('store_ids');
531  if ($storeIds) {
532  return $storeIds;
533  }
534 
535  if (!$this->getId()) {
536  return [];
537  }
538 
539  $nodes = [];
540  foreach ($this->getPathIds() as $id) {
541  $nodes[] = $id;
542  }
543 
544  $storeIds = [];
545  $storeCollection = $this->_storeCollectionFactory->create()->loadByCategoryIds($nodes);
546  foreach ($storeCollection as $store) {
547  $storeIds[$store->getId()] = $store->getId();
548  }
549 
550  $entityStoreId = $this->getStoreId();
551  if (!in_array($entityStoreId, $storeIds)) {
552  array_unshift($storeIds, $entityStoreId);
553  }
554  if (!in_array(0, $storeIds)) {
555  array_unshift($storeIds, 0);
556  }
557 
558  $this->setData('store_ids', $storeIds);
559  return $storeIds;
560  }
$id
Definition: fieldset.phtml:14

◆ getTreeModel()

getTreeModel ( )

Retrieve category tree model

Returns
\Magento\Catalog\Model\ResourceModel\Category\Tree

Definition at line 352 of file Category.php.

353  {
354  return $this->_categoryTreeFactory->create();
355  }

◆ getTreeModelInstance()

getTreeModelInstance ( )

Enter description here...

Returns
\Magento\Catalog\Model\ResourceModel\Category\Tree

Definition at line 362 of file Category.php.

363  {
364  return $this->_treeModel;
365  }

◆ getUpdatedAt()

getUpdatedAt ( )
Returns
string|null

Implements CategoryInterface.

Definition at line 1190 of file Category.php.

1191  {
1192  return $this->getData(self::KEY_UPDATED_AT);
1193  }

◆ getUrl()

getUrl ( )

Get category url

Returns
string

Definition at line 598 of file Category.php.

599  {
600  $url = $this->_getData('url');
601  if ($url === null) {
602  Profiler::start('REWRITE: ' . __METHOD__, ['group' => 'REWRITE', 'method' => __METHOD__]);
603  if ($this->hasData('request_path') && $this->getRequestPath() != '') {
604  $this->setData('url', $this->getUrlInstance()->getDirectUrl($this->getRequestPath()));
605  Profiler::stop('REWRITE: ' . __METHOD__);
606  return $this->getData('url');
607  }
608 
609  $rewrite = $this->urlFinder->findOneByData([
610  UrlRewrite::ENTITY_ID => $this->getId(),
612  UrlRewrite::STORE_ID => $this->getStoreId(),
613  ]);
614  if ($rewrite) {
615  $this->setData('url', $this->getUrlInstance()->getDirectUrl($rewrite->getRequestPath()));
616  Profiler::stop('REWRITE: ' . __METHOD__);
617  return $this->getData('url');
618  }
619 
620  $this->setData('url', $this->getCategoryIdUrl());
621  Profiler::stop('REWRITE: ' . __METHOD__);
622  return $this->getData('url');
623  }
624  return $url;
625  }

◆ getUrlInstance()

getUrlInstance ( )

Retrieve URL instance

Returns
\Magento\Framework\UrlInterface

Definition at line 342 of file Category.php.

343  {
344  return $this->_url;
345  }

◆ getUrlKey()

getUrlKey ( )
Returns
string|null

Definition at line 1231 of file Category.php.

1232  {
1233  return $this->getData('url_key');
1234  }

◆ getUseFlatResource()

getUseFlatResource ( )

Get flat resource model flag

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Definition at line 332 of file Category.php.

333  {
335  }

◆ hasChildren()

hasChildren ( )

Retrieve Is Category has children flag

Returns
bool

Definition at line 874 of file Category.php.

875  {
876  return $this->_getResource()->getChildrenAmount($this) > 0;
877  }

◆ isInRootCategoryList()

isInRootCategoryList ( )

Check category is in Root Category list

Returns
bool

Definition at line 1009 of file Category.php.

1010  {
1011  // TODO there are bugs in resource models' methods, store_id set to model o/andr to resource model are ignored
1012  return $this->getResource()->isInRootCategoryList($this);
1013  }

◆ move()

move (   $parentId,
  $afterCategoryId 
)

Move category

Parameters
int$parentIdnew parent category id
null | int$afterCategoryIdcategory id after which we have put current category
Returns
$this
Exceptions

Validate new parent category id. (category model is used for backward compatibility in event params)

Setting affected category ids for third party engine index refresh

Definition at line 375 of file Category.php.

376  {
381  try {
382  $parent = $this->categoryRepository->get($parentId, $this->getStoreId());
383  } catch (NoSuchEntityException $e) {
384  throw new \Magento\Framework\Exception\LocalizedException(
385  __(
386  'Sorry, but we can\'t find the new parent category you selected.'
387  ),
388  $e
389  );
390  }
391 
392  if (!$this->getId()) {
393  throw new \Magento\Framework\Exception\LocalizedException(
394  __('Sorry, but we can\'t find the new category you selected.')
395  );
396  } elseif ($parent->getId() == $this->getId()) {
397  throw new \Magento\Framework\Exception\LocalizedException(
398  __(
399  'We can\'t move the category because the parent category name matches the child category name.'
400  )
401  );
402  }
403 
407  $this->setMovedCategoryId($this->getId());
408  $oldParentId = $this->getParentId();
409  $oldParentIds = $this->getParentIds();
410 
411  $eventParams = [
412  $this->_eventObject => $this,
413  'parent' => $parent,
414  'category_id' => $this->getId(),
415  'prev_parent_id' => $oldParentId,
416  'parent_id' => $parentId,
417  ];
418 
419  $this->_getResource()->beginTransaction();
420  try {
421  $this->_eventManager->dispatch($this->_eventPrefix . '_move_before', $eventParams);
422  $this->getResource()->changeParent($this, $parent, $afterCategoryId);
423  $this->_eventManager->dispatch($this->_eventPrefix . '_move_after', $eventParams);
424  $this->_getResource()->commit();
425 
426  // Set data for indexer
427  $this->setAffectedCategoryIds([$this->getId(), $oldParentId, $parentId]);
428  } catch (\Exception $e) {
429  $this->_getResource()->rollBack();
430  throw $e;
431  }
432  $this->_eventManager->dispatch('category_move', $eventParams);
433  if ($this->flatState->isFlatEnabled()) {
434  $flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
435  if (!$flatIndexer->isScheduled()) {
436  $flatIndexer->reindexList([$this->getId(), $oldParentId, $parentId]);
437  }
438  }
439  $productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
440  if (!$productIndexer->isScheduled()) {
441  $productIndexer->reindexList(array_merge($this->getPathIds(), $oldParentIds));
442  }
443  $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
444  $this->_cacheManager->clean([self::CACHE_TAG]);
445 
446  return $this;
447  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ reindex()

reindex ( )

Init indexing process after category save

Returns
void

Definition at line 1104 of file Category.php.

1105  {
1106  if ($this->flatState->isFlatEnabled()) {
1107  $flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
1108  if (!$flatIndexer->isScheduled()) {
1109  $idsList = [$this->getId()];
1110  if ($this->dataHasChangedFor('url_key')) {
1111  $idsList = array_merge($idsList, explode(',', $this->getAllChildren()));
1112  }
1113  $flatIndexer->reindexList($idsList);
1114  }
1115  }
1116  $productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
1117  if (!$productIndexer->isScheduled()
1118  && (!empty($this->getAffectedProductIds()) || $this->dataHasChangedFor('is_anchor'))
1119  ) {
1120  $productIndexer->reindexList($this->getPathIds());
1121  }
1122  }
getAllChildren($asArray=false)
Definition: Category.php:776

◆ setAvailableSortBy()

setAvailableSortBy (   $availableSortBy)
Parameters
string[]|string$availableSortBy
Returns
$this

Implements CategoryInterface.

Definition at line 1382 of file Category.php.

1383  {
1384  return $this->setData(self::KEY_AVAILABLE_SORT_BY, $availableSortBy);
1385  }

◆ setChildrenData()

setChildrenData ( array  $childrenData = null)
Parameters

Implements CategoryTreeInterface.

Definition at line 1411 of file Category.php.

1412  {
1413  return $this->setData(self::KEY_CHILDREN_DATA, $childrenData);
1414  }

◆ setCreatedAt()

setCreatedAt (   $createdAt)
Parameters
string$createdAt
Returns
$this

Implements CategoryInterface.

Definition at line 1364 of file Category.php.

1365  {
1366  return $this->setData(self::KEY_CREATED_AT, $createdAt);
1367  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Catalog\Api\Data\CategoryExtensionInterface  $extensionAttributes)

{Set an extension attributes object.

Parameters
\Magento\Catalog\Api\Data\CategoryExtensionInterface$extensionAttributes
Returns
$this
}

Parameters
\Magento\Catalog\Api\Data\CategoryExtensionInterface$extensionAttributes
Returns
$this

Implements CategoryInterface.

Definition at line 1432 of file Category.php.

1433  {
1435  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setIncludeInMenu()

setIncludeInMenu (   $includeInMenu)
Parameters
bool$includeInMenu
Returns
$this

Implements CategoryInterface.

Definition at line 1391 of file Category.php.

1392  {
1393  return $this->setData(self::KEY_INCLUDE_IN_MENU, $includeInMenu);
1394  }

◆ setIsActive()

setIsActive (   $isActive)

Set whether category is active

Parameters
bool$isActive
Returns
$this

Implements CategoryInterface.

Definition at line 1324 of file Category.php.

1325  {
1326  return $this->setData(self::KEY_IS_ACTIVE, $isActive);
1327  }

◆ setLevel()

setLevel (   $level)

Set category level

Parameters
int$level
Returns
$this

Implements CategoryInterface.

Definition at line 1346 of file Category.php.

1347  {
1348  return $this->setData(self::KEY_LEVEL, $level);
1349  }

◆ setName()

setName (   $name)

Set category name

Parameters
string$name
Returns
$this

Implements CategoryInterface.

Definition at line 1313 of file Category.php.

1314  {
1315  return $this->setData(self::KEY_NAME, $name);
1316  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setParentId()

setParentId (   $parentId)

Set parent category ID

Parameters
int$parentId
Returns
$this

Implements CategoryInterface.

Definition at line 1302 of file Category.php.

1303  {
1304  return $this->setData(self::KEY_PARENT_ID, $parentId);
1305  }

◆ setPath()

setPath (   $path)
Parameters
string$path
Returns
$this

Implements CategoryInterface.

Definition at line 1373 of file Category.php.

1374  {
1375  return $this->setData(self::KEY_PATH, $path);
1376  }

◆ setPosition()

setPosition (   $position)

Set category position

Parameters
int$position
Returns
$this

Implements CategoryInterface.

Definition at line 1335 of file Category.php.

1336  {
1337  return $this->setData(self::KEY_POSITION, $position);
1338  }

◆ setProductCount()

setProductCount (   $productCount)

Set product count

Parameters
int$productCount
Returns
$this

Implements CategoryTreeInterface.

Definition at line 1402 of file Category.php.

1403  {
1404  return $this->setData(self::KEY_PRODUCT_COUNT, $productCount);
1405  }

◆ setStoreId()

setStoreId (   $storeId)

Set store id

Parameters
int | string$storeId
Returns
$this

Definition at line 583 of file Category.php.

584  {
585  if (!is_numeric($storeId)) {
586  $storeId = $this->_storeManager->getStore($storeId)->getId();
587  }
588  $this->setData('store_id', $storeId);
589  $this->getResource()->setStoreId($storeId);
590  return $this;
591  }

◆ setUpdatedAt()

setUpdatedAt (   $updatedAt)
Parameters
string$updatedAt
Returns
$this

Implements CategoryInterface.

Definition at line 1355 of file Category.php.

1356  {
1357  return $this->setData(self::KEY_UPDATED_AT, $updatedAt);
1358  }

◆ validate()

validate ( )

Validate attribute values

Exceptions

Definition at line 1082 of file Category.php.

1083  {
1084  return $this->_getResource()->validate($this);
1085  }

◆ verifyIds()

verifyIds ( array  $ids)

Verify category ids

Parameters
array$ids
Returns
bool

Definition at line 864 of file Category.php.

865  {
866  return $this->getResource()->verifyIds($ids);
867  }

Field Documentation

◆ $_cacheTag

$_cacheTag = self::CACHE_TAG
protected

Definition at line 90 of file Category.php.

◆ $_catalogConfig

$_catalogConfig
protected

Definition at line 162 of file Category.php.

◆ $_categoryTreeFactory

$_categoryTreeFactory
protected

Definition at line 183 of file Category.php.

◆ $_designAttributes

$_designAttributes
protected
Initial value:
= [
'custom_design',
'custom_design_from',
'custom_design_to',
'page_layout',
'custom_layout_update',
'custom_apply_to_products',
]

Definition at line 125 of file Category.php.

◆ $_eventObject

$_eventObject = 'category'
protected

Definition at line 83 of file Category.php.

◆ $_eventPrefix

$_eventPrefix = 'catalog_category'
protected

#-

Definition at line 76 of file Category.php.

◆ $_productCollectionFactory

$_productCollectionFactory
protected

Definition at line 169 of file Category.php.

◆ $_resource

$_resource
protected

Definition at line 103 of file Category.php.

◆ $_storeCollectionFactory

$_storeCollectionFactory
protected

Definition at line 176 of file Category.php.

◆ $_treeModel

$_treeModel = null
protected

Definition at line 148 of file Category.php.

◆ $_url

$_url
protected

Definition at line 97 of file Category.php.

◆ $_urlRewrite

$_urlRewrite
protected

Definition at line 111 of file Category.php.

◆ $_useFlatResource

$_useFlatResource = false
protected

Definition at line 118 of file Category.php.

◆ $categoryRepository

$categoryRepository
protected

Definition at line 208 of file Category.php.

◆ $categoryUrlPathGenerator

$categoryUrlPathGenerator
protected

Definition at line 193 of file Category.php.

◆ $filter

$filter
protected

Definition at line 155 of file Category.php.

◆ $flatState

$flatState
protected

Definition at line 188 of file Category.php.

◆ $indexerRegistry

$indexerRegistry
protected

Definition at line 203 of file Category.php.

◆ $interfaceAttributes

$interfaceAttributes = CategoryInterface::ATTRIBUTES
protected

Definition at line 141 of file Category.php.

◆ $metadataService

$metadataService
protected

Definition at line 213 of file Category.php.

◆ $urlFinder

$urlFinder
protected

Definition at line 198 of file Category.php.

◆ CACHE_TAG

const CACHE_TAG = 'cat_c'

Definition at line 73 of file Category.php.

◆ DM_MIXED

const DM_MIXED = 'PRODUCTS_AND_PAGE'

Definition at line 60 of file Category.php.

◆ DM_PAGE

const DM_PAGE = 'PAGE'

Definition at line 58 of file Category.php.

◆ DM_PRODUCT

const DM_PRODUCT = 'PRODUCTS'

#+ Category display modes

Definition at line 56 of file Category.php.

◆ ENTITY

const ENTITY = 'catalog_category'

Entity code. Can be used as part of method name for entity processing

Definition at line 51 of file Category.php.

◆ ROOT_CATEGORY_ID

const ROOT_CATEGORY_ID = 0

#- Id of root category

Definition at line 66 of file Category.php.

◆ TREE_ROOT_ID

const TREE_ROOT_ID = 1

Id of category tree root

Definition at line 71 of file Category.php.


The documentation for this class was generated from the following file: