Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Category.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Model;
7 
17 
43  \Magento\Framework\DataObject\IdentityInterface,
46 {
51  const ENTITY = 'catalog_category';
52 
56  const DM_PRODUCT = 'PRODUCTS';
57 
58  const DM_PAGE = 'PAGE';
59 
60  const DM_MIXED = 'PRODUCTS_AND_PAGE';
66  const ROOT_CATEGORY_ID = 0;
67 
71  const TREE_ROOT_ID = 1;
72 
73  const CACHE_TAG = 'cat_c';
74 
76  protected $_eventPrefix = 'catalog_category';
77 
83  protected $_eventObject = 'category';
84 
91 
97  protected $_url;
98 
103  protected $_resource;
104 
111  protected $_urlRewrite;
112 
118  protected $_useFlatResource = false;
119 
125  protected $_designAttributes = [
126  'custom_design',
127  'custom_design_from',
128  'custom_design_to',
129  'page_layout',
130  'custom_layout_update',
131  'custom_apply_to_products',
132  ];
133 
142 
148  protected $_treeModel = null;
149 
155  protected $filter;
156 
162  protected $_catalogConfig;
163 
170 
177 
184 
188  protected $flatState;
189 
194 
198  protected $urlFinder;
199 
203  protected $indexerRegistry;
204 
209 
213  protected $metadataService;
214 
239  public function __construct(
240  \Magento\Framework\Model\Context $context,
241  \Magento\Framework\Registry $registry,
242  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
245  \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService,
246  \Magento\Catalog\Model\ResourceModel\Category\Tree $categoryTreeResource,
247  \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryTreeFactory,
248  \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeCollectionFactory,
249  \Magento\Framework\UrlInterface $url,
250  \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
251  \Magento\Catalog\Model\Config $catalogConfig,
252  \Magento\Framework\Filter\FilterManager $filter,
253  Indexer\Category\Flat\State $flatState,
254  \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
256  \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
258  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
259  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
260  array $data = []
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  }
286 
292  protected function _construct()
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  }
302 
306  protected function getCustomAttributesCodes()
307  {
308  if ($this->customAttributesCodes === null) {
309  $this->customAttributesCodes = $this->getEavAttributesCodes($this->metadataService);
310  $this->customAttributesCodes = array_diff($this->customAttributesCodes, CategoryInterface::ATTRIBUTES);
311  }
313  }
314 
321  protected function _getResource()
322  {
323  return parent::_getResource();
324  }
325 
332  public function getUseFlatResource()
333  {
335  }
336 
342  public function getUrlInstance()
343  {
344  return $this->_url;
345  }
346 
352  public function getTreeModel()
353  {
354  return $this->_categoryTreeFactory->create();
355  }
356 
362  public function getTreeModelInstance()
363  {
364  return $this->_treeModel;
365  }
366 
375  public function move($parentId, $afterCategoryId)
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  }
448 
454  public function getDefaultAttributeSetId()
455  {
456  return $this->getResource()->getEntityType()->getDefaultAttributeSetId();
457  }
458 
464  public function getProductCollection()
465  {
466  $collection = $this->_productCollectionFactory->create()->setStoreId(
467  $this->getStoreId()
468  )->addCategoryFilter(
469  $this
470  );
471  return $collection;
472  }
473 
482  public function getAttributes($noDesignAttributes = false)
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  }
496 
505  public function getProductsPosition()
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  }
518 
524  public function getStoreIds()
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  }
561 
569  public function getStoreId()
570  {
571  if ($this->hasData('store_id')) {
572  return (int)$this->_getData('store_id');
573  }
574  return (int)$this->_storeManager->getStore()->getId();
575  }
576 
583  public function setStoreId($storeId)
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  }
592 
598  public function getUrl()
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  }
626 
632  public function getCategoryIdUrl()
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  }
640 
647  public function formatUrlKey($str)
648  {
649  return $this->filter->translitUrl($str);
650  }
651 
657  public function getImageUrl($attributeCode = 'image')
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  }
687 
693  public function getParentCategory()
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  }
700 
706  public function getParentId()
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  }
715 
721  public function getParentIds()
722  {
723  return array_diff($this->getPathIds(), [$this->getId()]);
724  }
725 
731  public function getCustomDesignDate()
732  {
733  $result = [];
734  $result['from'] = $this->getData('custom_design_from');
735  $result['to'] = $this->getData('custom_design_to');
736 
737  return $result;
738  }
739 
745  public function getDesignAttributes()
746  {
747  $result = [];
748  foreach ($this->_designAttributes as $attrName) {
749  $result[] = $this->_getAttribute($attrName);
750  }
751  return $result;
752  }
753 
760  private function _getAttribute($attributeCode)
761  {
762  if (!$this->_useFlatResource) {
763  $attribute = $this->getResource()->getAttribute($attributeCode);
764  } else {
765  $attribute = $this->_catalogConfig->getAttribute(self::ENTITY, $attributeCode);
766  }
767  return $attribute;
768  }
769 
776  public function getAllChildren($asArray = false)
777  {
778  $children = $this->getResource()->getAllChildren($this);
779  if ($asArray) {
780  return $children;
781  } else {
782  return implode(',', $children);
783  }
784  }
785 
794  public function getChildren($recursive = false, $isActive = true, $sortByPosition = false)
795  {
796  return implode(',', $this->getResource()->getChildren($this, $recursive, $isActive, $sortByPosition));
797  }
798 
805  public function getPathInStore()
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  }
817 
824  public function checkId($id)
825  {
826  return $this->_getResource()->checkId($id);
827  }
828 
835  public function getPathIds()
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  }
844 
850  public function getLevel()
851  {
852  if (!$this->hasLevel()) {
853  return count(explode('/', $this->getPath())) - 1;
854  }
855  return $this->getData(self::KEY_LEVEL);
856  }
857 
864  public function verifyIds(array $ids)
865  {
866  return $this->getResource()->verifyIds($ids);
867  }
868 
874  public function hasChildren()
875  {
876  return $this->_getResource()->getChildrenAmount($this) > 0;
877  }
878 
884  public function getRequestPath()
885  {
886  return $this->_getData('request_path');
887  }
888 
894  public function getName()
895  {
896  return $this->_getData(self::KEY_NAME);
897  }
898 
905  public function beforeDelete()
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  }
912 
918  public function getAnchorsAbove()
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  }
942 
948  public function getProductCount()
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  }
957 
968  public function getCategories($parent, $recursionLevel = 0, $sorted = false, $asCollection = false, $toLoad = true)
969  {
970  $categories = $this->getResource()->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
971  return $categories;
972  }
973 
979  public function getParentCategories()
980  {
981  return $this->getResource()->getParentCategories($this);
982  }
983 
989  public function getChildrenCategories()
990  {
991  return $this->getResource()->getChildrenCategories($this);
992  }
993 
999  public function getParentDesignCategory()
1000  {
1001  return $this->getResource()->getParentDesignCategory($this);
1002  }
1003 
1009  public function isInRootCategoryList()
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  }
1014 
1020  public function getAvailableSortBy()
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  }
1031 
1038  public function getAvailableSortByOptions()
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  }
1056 
1062  public function getDefaultSortBy()
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  }
1075 
1082  public function validate()
1083  {
1084  return $this->_getResource()->validate($this);
1085  }
1086 
1092  public function afterSave()
1093  {
1094  $result = parent::afterSave();
1095  $this->_getResource()->addCommitCallback([$this, 'reindex']);
1096  return $result;
1097  }
1098 
1104  public function reindex()
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  }
1123 
1129  public function afterDeleteCommit()
1130  {
1131  $this->reindex();
1132  return parent::afterDeleteCommit();
1133  }
1134 
1140  public function getIdentities()
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  }
1153 
1158  public function getPath()
1159  {
1160  return $this->getData(self::KEY_PATH);
1161  }
1162 
1166  public function getPosition()
1167  {
1168  return $this->getData(self::KEY_POSITION);
1169  }
1170 
1174  public function getChildrenCount()
1175  {
1176  return $this->getData('children_count');
1177  }
1178 
1182  public function getCreatedAt()
1183  {
1184  return $this->getData('created_at');
1185  }
1186 
1190  public function getUpdatedAt()
1191  {
1192  return $this->getData(self::KEY_UPDATED_AT);
1193  }
1194 
1199  public function getIsActive()
1200  {
1201  return $this->getData(self::KEY_IS_ACTIVE);
1202  }
1203 
1207  public function getCategoryId()
1208  {
1209  return $this->getData('category_id');
1210  }
1211 
1215  public function getDisplayMode()
1216  {
1217  return $this->getData('display_mode');
1218  }
1219 
1223  public function getIncludeInMenu()
1224  {
1225  return $this->getData(self::KEY_INCLUDE_IN_MENU);
1226  }
1227 
1231  public function getUrlKey()
1232  {
1233  return $this->getData('url_key');
1234  }
1235 
1239  public function getChildrenData()
1240  {
1241  return $this->getData(self::KEY_CHILDREN_DATA);
1242  }
1243 
1244  //@codeCoverageIgnoreEnd
1245 
1252  public function __toArray()
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  }
1272 
1278  public function toFlatArray()
1279  {
1280  $dataArray = $this->__toArray();
1281  //process custom attributes if present
1282  if (array_key_exists('custom_attributes', $dataArray) && !empty($dataArray['custom_attributes'])) {
1284  $customAttributes = $dataArray['custom_attributes'];
1285  unset($dataArray['custom_attributes']);
1286  foreach ($customAttributes as $attributeValue) {
1289  }
1290  }
1291  return ConvertArray::toFlatArray($dataArray);
1292  }
1293 
1294  //@codeCoverageIgnoreStart
1295 
1302  public function setParentId($parentId)
1303  {
1304  return $this->setData(self::KEY_PARENT_ID, $parentId);
1305  }
1306 
1313  public function setName($name)
1314  {
1315  return $this->setData(self::KEY_NAME, $name);
1316  }
1317 
1324  public function setIsActive($isActive)
1325  {
1326  return $this->setData(self::KEY_IS_ACTIVE, $isActive);
1327  }
1328 
1335  public function setPosition($position)
1336  {
1337  return $this->setData(self::KEY_POSITION, $position);
1338  }
1339 
1346  public function setLevel($level)
1347  {
1348  return $this->setData(self::KEY_LEVEL, $level);
1349  }
1350 
1355  public function setUpdatedAt($updatedAt)
1356  {
1357  return $this->setData(self::KEY_UPDATED_AT, $updatedAt);
1358  }
1359 
1364  public function setCreatedAt($createdAt)
1365  {
1366  return $this->setData(self::KEY_CREATED_AT, $createdAt);
1367  }
1368 
1373  public function setPath($path)
1374  {
1375  return $this->setData(self::KEY_PATH, $path);
1376  }
1377 
1382  public function setAvailableSortBy($availableSortBy)
1383  {
1384  return $this->setData(self::KEY_AVAILABLE_SORT_BY, $availableSortBy);
1385  }
1386 
1391  public function setIncludeInMenu($includeInMenu)
1392  {
1393  return $this->setData(self::KEY_INCLUDE_IN_MENU, $includeInMenu);
1394  }
1395 
1402  public function setProductCount($productCount)
1403  {
1404  return $this->setData(self::KEY_PRODUCT_COUNT, $productCount);
1405  }
1406 
1411  public function setChildrenData(array $childrenData = null)
1412  {
1413  return $this->setData(self::KEY_CHILDREN_DATA, $childrenData);
1414  }
1415 
1421  public function getExtensionAttributes()
1422  {
1423  return $this->_getExtensionAttributes();
1424  }
1425 
1432  public function setExtensionAttributes(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
1433  {
1434  return $this->_setExtensionAttributes($extensionAttributes);
1435  }
1436 
1437  //@codeCoverageIgnoreEnd
1438 }
getAllChildren($asArray=false)
Definition: Category.php:776
getAttributes($noDesignAttributes=false)
Definition: Category.php:482
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$id
Definition: fieldset.phtml:14
setChildrenData(array $childrenData=null)
Definition: Category.php:1411
setIncludeInMenu($includeInMenu)
Definition: Category.php:1391
$count
Definition: recent.phtml:13
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
setProductCount($productCount)
Definition: Category.php:1402
$storeManager
__()
Definition: __.php:13
getCategories($parent, $recursionLevel=0, $sorted=false, $asCollection=false, $toLoad=true)
Definition: Category.php:968
$resource
Definition: bulk.php:12
move($parentId, $afterCategoryId)
Definition: Category.php:375
__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=[])
Definition: Category.php:239
setAvailableSortBy($availableSortBy)
Definition: Category.php:1382
setExtensionAttributes(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
Definition: Category.php:1432
$value
Definition: gender.phtml:16
getChildren($recursive=false, $isActive=true, $sortByPosition=false)
Definition: Category.php:794
$attributeCode
Definition: extend.phtml:12
$children
Definition: actions.phtml:11
$categories
getImageUrl($attributeCode='image')
Definition: Category.php:657
if(!isset($_GET['name'])) $name
Definition: log.php:14