Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Flat Class Reference
Inheritance diagram for Flat:
AbstractResource AbstractDb AbstractResource

Public Member Functions

 __construct (\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Config $catalogConfig, \Magento\Framework\Event\ManagerInterface $eventManager, $connectionName=null, \Magento\Catalog\Model\ResourceModel\Category\Flat\CollectionFactory $categoryFlatCollectionFactory=null)
 
 setStoreId ($storeId)
 
 getStoreId ()
 
 getMainTable ()
 
 getMainStoreTable ($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
 
 addInactiveCategoryIds ($ids)
 
 getInactiveCategoryIds ()
 
 addChildNodes ($children, $path, $parent)
 
 getNodes ($parentId, $recursionLevel=0, $storeId=0)
 
 getCategories ($parent, $recursionLevel=0, $sorted=false, $asCollection=false, $toLoad=true)
 
 getNodeById ($nodeId, $nodes=null)
 
 getAttribute ($attribute)
 
 getChildrenAmount ($category, $isActiveFlag=true)
 
 getProductCount ($category)
 
 getParentCategories ($category, $isActive=true)
 
 getParentDesignCategory ($category)
 
 getChildrenCategories ($category)
 
 isInRootCategoryList ($category)
 
 getChildren ($category, $recursive=true, $isActive=true, $sortByPosition=false)
 
 getAllChildren ($category)
 
 checkId ($id)
 
 getAnchorsAbove (array $filterIds, $storeId=0)
 
 getProductsPosition ($category)
 
- Public Member Functions inherited from AbstractResource
 __construct (\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, $connectionName=null)
 
 reindexAll ()
 
 getIdxTable ($table=null)
 
 syncData ()
 
 insertFromTable ($sourceTable, $destTable, $readToIndex=true)
 
 insertFromSelect ($select, $destTable, array $columns, $readToIndex=true)
 
 clearTemporaryIndexTable ()
 
- Public Member Functions inherited from AbstractDb
 __construct (\Magento\Framework\Model\ResourceModel\Db\Context $context, $connectionName=null)
 
 __sleep ()
 
 __wakeup ()
 
 getIdFieldName ()
 
 getMainTable ()
 
 getTable ($tableName)
 
 getConnection ()
 
 load (\Magento\Framework\Model\AbstractModel $object, $value, $field=null)
 
 save (\Magento\Framework\Model\AbstractModel $object)
 
 delete (\Magento\Framework\Model\AbstractModel $object)
 
 addUniqueField ($field)
 
 resetUniqueField ()
 
 unserializeFields (\Magento\Framework\Model\AbstractModel $object)
 
 getUniqueFields ()
 
 hasDataChanged ($object)
 
 getChecksum ($table)
 
 afterLoad (\Magento\Framework\DataObject $object)
 
 beforeSave (\Magento\Framework\DataObject $object)
 
 afterSave (\Magento\Framework\DataObject $object)
 
 beforeDelete (\Magento\Framework\DataObject $object)
 
 afterDelete (\Magento\Framework\DataObject $object)
 
 serializeFields (\Magento\Framework\Model\AbstractModel $object)
 
- Public Member Functions inherited from AbstractResource
 __construct ()
 
 getConnection ()
 
 beginTransaction ()
 
 addCommitCallback ($callback)
 
 commit ()
 
 rollBack ()
 
 getValidationRulesBeforeSave ()
 

Protected Member Functions

 _construct ()
 
 _initInactiveCategoryIds ()
 
 _loadNodes ($parentNode=null, $recursionLevel=0, $storeId=0, $skipMenuFilter=false)
 
- Protected Member Functions inherited from AbstractResource
 _getIndexAdapter ()
 
- Protected Member Functions inherited from AbstractDb
 _init ($mainTable, $idFieldName)
 
 _setResource ($connections, $tables=null)
 
 _setMainTable ($mainTable, $idFieldName=null)
 
 _getConnection ($resourceName)
 
 _getLoadSelect ($field, $value, $object)
 
 _initUniqueFields ()
 
 _prepareDataForSave (\Magento\Framework\Model\AbstractModel $object)
 
 _prepareValueForSave ($value, $type)
 
 _checkUnique (\Magento\Framework\Model\AbstractModel $object)
 
 _afterLoad (\Magento\Framework\Model\AbstractModel $object)
 
 _beforeSave (\Magento\Framework\Model\AbstractModel $object)
 
 _afterSave (\Magento\Framework\Model\AbstractModel $object)
 
 _beforeDelete (\Magento\Framework\Model\AbstractModel $object)
 
 _afterDelete (\Magento\Framework\Model\AbstractModel $object)
 
 _serializeFields (\Magento\Framework\Model\AbstractModel $object)
 
 prepareDataForUpdate ($object)
 
 isObjectNotNew (\Magento\Framework\Model\AbstractModel $object)
 
 saveNewObject (\Magento\Framework\Model\AbstractModel $object)
 
 updateObject (\Magento\Framework\Model\AbstractModel $object)
 
 processAfterSaves (\Magento\Framework\Model\AbstractModel $object)
 
 isModified (\Magento\Framework\Model\AbstractModel $object)
 
 processNotModifiedSave (\Magento\Framework\Model\AbstractModel $object)
 
- Protected Member Functions inherited from AbstractResource
 _construct ()
 
 _serializeField (DataObject $object, $field, $defaultValue=null, $unsetEmpty=false)
 
 _unserializeField (DataObject $object, $field, $defaultValue=null)
 
 _prepareDataForTable (DataObject $object, $table)
 
 _prepareTableValueForSave ($value, $type)
 
 _getColumnsForEntityLoad (\Magento\Framework\Model\AbstractModel $object, $tableName)
 
 getSerializer ()
 

Protected Attributes

 $_storeId
 
 $_loaded = false
 
 $_nodes = []
 
 $_inactiveCategoryIds
 
 $_eventManager
 
 $_catalogConfig
 
 $_storeManager
 
 $_categoryCollectionFactory
 
 $_categoryFactory
 
- Protected Attributes inherited from AbstractResource
 $tableStrategy
 
- Protected Attributes inherited from AbstractDb
 $_resources
 
 $connectionName = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION
 
 $_connections = []
 
 $_resourceModel
 
 $_tables = []
 
 $_mainTable
 
 $_idFieldName
 
 $_isPkAutoIncrement = true
 
 $_useIsObjectNew = false
 
 $_mainTableFields
 
 $_uniqueFields = null
 
 $_serializableFields = []
 
 $transactionManager
 
 $objectRelationProcessor
 
- Protected Attributes inherited from AbstractResource
 $serializer
 
 $_logger
 

Detailed Description

Category flat model

@SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 17 of file Flat.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\ResourceModel\Db\Context  $context,
\Magento\Framework\Indexer\Table\StrategyInterface  $tableStrategy,
\Magento\Catalog\Model\CategoryFactory  $categoryFactory,
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory  $categoryCollectionFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Catalog\Model\Config  $catalogConfig,
\Magento\Framework\Event\ManagerInterface  $eventManager,
  $connectionName = null,
\Magento\Catalog\Model\ResourceModel\Category\Flat\CollectionFactory  $categoryFlatCollectionFactory = null 
)

Constructor

Parameters
\Magento\Framework\Model\ResourceModel\Db\Context$context
\Magento\Framework\Indexer\Table\StrategyInterface$tableStrategy
\Magento\Catalog\Model\CategoryFactory$categoryFactory
CollectionFactory$categoryCollectionFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Catalog\Model\Config$catalogConfig
\Magento\Framework\Event\ManagerInterface$eventManager
string$connectionName
\Magento\Catalog\Model\ResourceModel\Category\Flat\CollectionFactory | null$categoryFlatCollectionFactory

Definition at line 101 of file Flat.php.

111  {
112  $this->_categoryFactory = $categoryFactory;
113  $this->_categoryCollectionFactory = $categoryCollectionFactory;
114  $this->_storeManager = $storeManager;
115  $this->_catalogConfig = $catalogConfig;
116  $this->_eventManager = $eventManager;
117  $this->categoryFlatCollectionFactory = $categoryFlatCollectionFactory ?: ObjectManager::getInstance()
118  ->get(\Magento\Catalog\Model\ResourceModel\Category\Flat\CollectionFactory::class);
119  parent::__construct($context, $tableStrategy, $connectionName);
120  }
$storeManager

Member Function Documentation

◆ _construct()

_construct ( )
protected

Resource initializations

Returns
void

Definition at line 127 of file Flat.php.

128  {
129  $this->_init('catalog_category_flat', 'entity_id');
130  }

◆ _initInactiveCategoryIds()

_initInactiveCategoryIds ( )
protected

Retrieve inactive categories ids

Returns
$this

Definition at line 209 of file Flat.php.

210  {
211  $this->_inactiveCategoryIds = [];
212  $this->_eventManager->dispatch('catalog_category_tree_init_inactive_category_ids', ['tree' => $this]);
213  return $this;
214  }

◆ _loadNodes()

_loadNodes (   $parentNode = null,
  $recursionLevel = 0,
  $storeId = 0,
  $skipMenuFilter = false 
)
protected

Load nodes by parent id

Parameters
\Magento\Catalog\Model\Category | int$parentNode
integer$recursionLevel
integer$storeId
bool$skipMenuFilter
Returns
array

Definition at line 239 of file Flat.php.

240  {
241  $_conn = $this->getConnection();
242  $startLevel = 1;
243  $parentPath = '';
244  if ($parentNode instanceof \Magento\Catalog\Model\Category) {
245  $parentPath = $parentNode->getPath();
246  $startLevel = $parentNode->getLevel();
247  } elseif (is_numeric($parentNode)) {
248  $selectParent = $_conn->select()->from(
250  )->where(
251  'entity_id = ?',
252  $parentNode
253  )->where(
254  'store_id = ?',
255  $storeId
256  );
257  $parentNode = $_conn->fetchRow($selectParent);
258  if ($parentNode) {
259  $parentPath = $parentNode['path'];
260  $startLevel = $parentNode['level'];
261  }
262  }
263  $select = $_conn->select()->from(
264  ['main_table' => $this->getMainStoreTable($storeId)],
265  [
266  'entity_id',
267  new \Zend_Db_Expr('main_table.' . $_conn->quoteIdentifier('name')),
268  new \Zend_Db_Expr('main_table.' . $_conn->quoteIdentifier('path')),
269  'is_active',
270  'is_anchor'
271  ]
272  )->joinLeft(
273  ['url_rewrite' => $this->getTable('url_rewrite')],
274  'url_rewrite.entity_id = main_table.entity_id AND url_rewrite.is_autogenerated = 1'
275  . $_conn->quoteInto(' AND url_rewrite.store_id = ?', $storeId)
276  . $_conn->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE),
277  ['request_path' => 'url_rewrite.request_path']
278  )->where('main_table.is_active = 1');
279 
280  if (false == $skipMenuFilter) {
281  $select->where('main_table.include_in_menu = ?', '1');
282  }
283 
284  $select->order('main_table.position');
285 
286  if ($parentPath) {
287  $select->where($_conn->quoteInto("main_table.path like ?", "{$parentPath}/%"));
288  }
289  if ($recursionLevel != 0) {
290  $levelField = $_conn->quoteIdentifier('level');
291  $select->where($levelField . ' <= ?', $startLevel + $recursionLevel);
292  }
293 
294  $inactiveCategories = $this->getInactiveCategoryIds();
295 
296  if (!empty($inactiveCategories)) {
297  $select->where('main_table.entity_id NOT IN (?)', $inactiveCategories);
298  }
299 
300  // Allow extensions to modify select (e.g. add custom category attributes to select)
301  $this->_eventManager->dispatch('catalog_category_flat_loadnodes_before', ['select' => $select]);
302 
303  $arrNodes = $_conn->fetchAll($select);
304  $nodes = [];
305  foreach ($arrNodes as $node) {
306  $node['id'] = $node['entity_id'];
307  $nodes[$node['id']] = $this->_categoryFactory->create()->setData($node);
308  }
309 
310  return $nodes;
311  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ addChildNodes()

addChildNodes (   $children,
  $path,
  $parent 
)

Creating sorted array of nodes

Parameters
array$children
string$path
\Magento\Framework\DataObject$parent
Returns
void

Definition at line 321 of file Flat.php.

322  {
323  if (isset($children[$path])) {
324  foreach ($children[$path] as $child) {
325  $childrenNodes = $parent->getChildrenNodes();
326  if ($childrenNodes && isset($childrenNodes[$child->getId()])) {
327  $childrenNodes[$child['entity_id']]->setChildrenNodes([$child->getId() => $child]);
328  } else {
329  if ($childrenNodes) {
330  $childrenNodes[$child->getId()] = $child;
331  } else {
332  $childrenNodes = [$child->getId() => $child];
333  }
334  $parent->setChildrenNodes($childrenNodes);
335  }
336 
337  if ($path) {
338  $childrenPath = explode('/', $path);
339  } else {
340  $childrenPath = [];
341  }
342  $childrenPath[] = $child->getId();
343  $childrenPath = implode('/', $childrenPath);
344  $this->addChildNodes($children, $childrenPath, $child);
345  }
346  }
347  }
addChildNodes($children, $path, $parent)
Definition: Flat.php:321
$children
Definition: actions.phtml:11

◆ addInactiveCategoryIds()

addInactiveCategoryIds (   $ids)

Add inactive categories ids

Parameters
array$ids
Returns
$this

Definition at line 195 of file Flat.php.

196  {
197  if (!is_array($this->_inactiveCategoryIds)) {
198  $this->_initInactiveCategoryIds();
199  }
200  $this->_inactiveCategoryIds = array_merge($ids, $this->_inactiveCategoryIds);
201  return $this;
202  }

◆ checkId()

checkId (   $id)

Check if category id exist

Parameters
int$id
Returns
bool

Definition at line 655 of file Flat.php.

656  {
657  $select = $this->getConnection()->select()->from(
658  $this->getMainStoreTable($this->getStoreId()),
659  'entity_id'
660  )->where(
661  'entity_id=?',
662  $id
663  );
664  return $this->getConnection()->fetchOne($select);
665  }
$id
Definition: fieldset.phtml:14
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ getAllChildren()

getAllChildren (   $category)

Return all children ids of category (with category id)

Parameters
\Magento\Catalog\Model\Category$category
Returns
array

Definition at line 640 of file Flat.php.

641  {
642  $categoriesIds = $this->getChildren($category);
643  $myId = [$category->getId()];
644  $categoriesIds = array_merge($myId, $categoriesIds);
645 
646  return $categoriesIds;
647  }
getChildren($category, $recursive=true, $isActive=true, $sortByPosition=false)
Definition: Flat.php:608

◆ getAnchorsAbove()

getAnchorsAbove ( array  $filterIds,
  $storeId = 0 
)

Retrieve anchors above

Parameters
array$filterIds
int$storeId
Returns
array

Definition at line 674 of file Flat.php.

675  {
676  $select = $this->getConnection()->select()->from(
677  ['e' => $this->getMainStoreTable($storeId)],
678  'entity_id'
679  )->where(
680  'is_anchor = ?',
681  1
682  )->where(
683  'entity_id IN (?)',
684  $filterIds
685  );
686 
687  return $this->getConnection()->fetchCol($select);
688  }
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ getAttribute()

getAttribute (   $attribute)

Retrieve attribute instance

Special for non static flat table.

Parameters
mixed$attribute
Returns
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute

Definition at line 461 of file Flat.php.

462  {
463  return $this->_catalogConfig->getAttribute(\Magento\Catalog\Model\Category::ENTITY, $attribute);
464  }

◆ getCategories()

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

Return array or collection of categories

Parameters
integer$parent
integer$recursionLevel
boolean | string$sorted
boolean$asCollection
boolean$toLoad
Returns
array|\Magento\Framework\Data\Collection

Definition at line 401 of file Flat.php.

402  {
403  if ($asCollection) {
404  $select = $this->getConnection()->select()->from(
405  ['mt' => $this->getMainStoreTable($this->getStoreId())],
406  ['path']
407  )->where(
408  'mt.entity_id = ?',
409  $parent
410  );
411  $parentPath = $this->getConnection()->fetchOne($select);
412 
413  $collection = $this->categoryFlatCollectionFactory
414  ->create()
415  ->addNameToResult()
416  ->addUrlRewriteToResult()
417  ->addParentPathFilter($parentPath)
418  ->addStoreFilter()
419  ->addIsActiveFilter()
420  ->addAttributeToFilter('include_in_menu', 1)
421  ->addSortedField($sorted);
422  if ($toLoad) {
423  return $collection->load();
424  }
425  return $collection;
426  }
427  return $this->getNodes($parent, $recursionLevel, $this->_storeManager->getStore()->getId());
428  }
getNodes($parentId, $recursionLevel=0, $storeId=0)
Definition: Flat.php:357
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ getChildren()

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

Return children ids of category

Parameters
\Magento\Catalog\Model\Category$category
bool$recursive
bool$isActive
bool$sortByPosition
Returns
array

Definition at line 608 of file Flat.php.

609  {
610  $select = $this->getConnection()->select()->from(
611  $this->getMainStoreTable($category->getStoreId()),
612  'entity_id'
613  )->where(
614  'path LIKE ?',
615  "{$category->getPath()}/%"
616  );
617  if (!$recursive) {
618  $select->where('level <= ?', $category->getLevel() + 1);
619  }
620  if ($isActive) {
621  $select->where('is_active = ?', '1');
622  }
623  if ($sortByPosition) {
624  $select->order('position ASC');
625  }
626  $_categories = $this->getConnection()->fetchAll($select);
627  $categoriesIds = [];
628  foreach ($_categories as $_category) {
629  $categoriesIds[] = $_category['entity_id'];
630  }
631  return $categoriesIds;
632  }
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173
if(! $block->getCategory()) $_categories
Definition: left.phtml:18
$_category
Definition: image.phtml:19

◆ getChildrenAmount()

getChildrenAmount (   $category,
  $isActiveFlag = true 
)

Get count of active/not active children categories

Parameters
\Magento\Catalog\Model\Category$category
bool$isActiveFlag
Returns
integer

Definition at line 473 of file Flat.php.

474  {
475  $_table = $this->getMainStoreTable($category->getStoreId());
476  $select = $this->getConnection()->select()->from(
477  $_table,
478  "COUNT({$_table}.entity_id)"
479  )->where(
480  "{$_table}.path LIKE ?",
481  $category->getPath() . '/%'
482  )->where(
483  "{$_table}.is_active = ?",
484  (int)$isActiveFlag
485  );
486  return (int)$this->getConnection()->fetchOne($select);
487  }
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ getChildrenCategories()

getChildrenCategories (   $category)

Return children categories of category

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

Definition at line 581 of file Flat.php.

582  {
583  $categories = $this->_loadNodes($category, 1, $category->getStoreId(), true);
584  return $categories;
585  }
_loadNodes($parentNode=null, $recursionLevel=0, $storeId=0, $skipMenuFilter=false)
Definition: Flat.php:239
$categories

◆ getInactiveCategoryIds()

getInactiveCategoryIds ( )

Retrieve inactive categories ids

Returns
array

Definition at line 221 of file Flat.php.

222  {
223  if (!is_array($this->_inactiveCategoryIds)) {
224  $this->_initInactiveCategoryIds();
225  }
226 
228  }

◆ getMainStoreTable()

getMainStoreTable (   $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID)

Return name of table for given $storeId.

Parameters
integer$storeId
Returns
string

Definition at line 173 of file Flat.php.

174  {
175  if (is_string($storeId)) {
176  $storeId = intval($storeId);
177  }
178 
179  if ($storeId) {
180  $suffix = sprintf('store_%d', $storeId);
181  $table = $this->getTable('catalog_category_flat_' . $suffix);
182  } else {
183  $table = parent::getMainTable();
184  }
185 
186  return $table;
187  }
$suffix
Definition: name.phtml:27
$table
Definition: trigger.php:14

◆ getMainTable()

getMainTable ( )

Get main table name

Returns
string

Definition at line 162 of file Flat.php.

163  {
164  return $this->getMainStoreTable($this->getStoreId());
165  }
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ getNodeById()

getNodeById (   $nodeId,
  $nodes = null 
)

Return node with id $nodeId

Parameters
integer$nodeId
array$nodes
Returns
\Magento\Framework\DataObject

Definition at line 437 of file Flat.php.

438  {
439  if ($nodes === null) {
440  $nodes = $this->getNodes($nodeId);
441  }
442  if (isset($nodes[$nodeId])) {
443  return $nodes[$nodeId];
444  }
445  foreach ($nodes as $node) {
446  if ($node->getChildrenNodes()) {
447  return $this->getNodeById($nodeId, $node->getChildrenNodes());
448  }
449  }
450  return [];
451  }
getNodes($parentId, $recursionLevel=0, $storeId=0)
Definition: Flat.php:357

◆ getNodes()

getNodes (   $parentId,
  $recursionLevel = 0,
  $storeId = 0 
)

Return sorted array of nodes

Parameters
integer | null$parentId
integer$recursionLevel
integer$storeId
Returns
array

Definition at line 357 of file Flat.php.

358  {
359  if (!$this->_loaded) {
360  $selectParent = $this->getConnection()->select()->from(
362  )->where(
363  'entity_id = ?',
364  $parentId
365  );
366  if ($parentNode = $this->getConnection()->fetchRow($selectParent)) {
367  $parentNode['id'] = $parentNode['entity_id'];
368  $parentNode = $this->_categoryFactory->create()->setData($parentNode);
369  $this->_nodes[$parentNode->getId()] = $parentNode;
370  $nodes = $this->_loadNodes($parentNode, $recursionLevel, $storeId);
371  $childrenItems = [];
372  foreach ($nodes as $node) {
373  $pathToParent = explode('/', $node->getPath());
374  array_pop($pathToParent);
375  $pathToParent = implode('/', $pathToParent);
376  $childrenItems[$pathToParent][] = $node;
377  }
378  $this->addChildNodes($childrenItems, $parentNode->getPath(), $parentNode);
379  $childrenNodes = $this->_nodes[$parentNode->getId()];
380  if ($childrenNodes->getChildrenNodes()) {
381  $this->_nodes = $childrenNodes->getChildrenNodes();
382  } else {
383  $this->_nodes = [];
384  }
385  $this->_loaded = true;
386  }
387  }
388  return $this->_nodes;
389  }
_loadNodes($parentNode=null, $recursionLevel=0, $storeId=0, $skipMenuFilter=false)
Definition: Flat.php:239
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173
addChildNodes($children, $path, $parent)
Definition: Flat.php:321

◆ getParentCategories()

getParentCategories (   $category,
  $isActive = true 
)

Return parent categories of category

Parameters
\Magento\Catalog\Model\Category$category
bool$isActive
Returns
\Magento\Catalog\Model\Category[]

Definition at line 516 of file Flat.php.

517  {
518  $categories = [];
519  $connection = $this->getConnection();
520  $select = $connection->select()->from(
521  ['main_table' => $this->getMainStoreTable($category->getStoreId())],
522  ['main_table.entity_id', 'main_table.name']
523  )->joinLeft(
524  ['url_rewrite' => $this->getTable('url_rewrite')],
525  'url_rewrite.entity_id = main_table.entity_id AND url_rewrite.is_autogenerated = 1'
526  . $connection->quoteInto(' AND url_rewrite.store_id = ?', $category->getStoreId())
527  . $connection->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE),
528  ['request_path' => 'url_rewrite.request_path']
529  )->where(
530  'main_table.entity_id IN (?)',
531  array_reverse(explode(',', $category->getPathInStore()))
532  );
533  if ($isActive) {
534  $select->where('main_table.is_active = ?', '1');
535  }
536  $select->order('main_table.path ASC');
537  $result = $this->getConnection()->fetchAll($select);
538  foreach ($result as $row) {
539  $row['id'] = $row['entity_id'];
540  $categories[$row['entity_id']] = $this->_categoryFactory->create()->setData($row);
541  }
542  return $categories;
543  }
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173
$categories
$connection
Definition: bulk.php:13

◆ getParentDesignCategory()

getParentDesignCategory (   $category)

Return parent category of current category with own custom design settings

Parameters
\Magento\Catalog\Model\Category$category
Returns
\Magento\Catalog\Model\Category

Definition at line 551 of file Flat.php.

552  {
553  $pathIds = array_reverse($category->getPathIds());
554  $collection = clone $category->getCollection();
555  $collection->setMainTable(
556  $this->getMainStoreTable($category->getStoreId())
557  )->addFieldToSelect(
558  '*'
559  )->addFieldToFilter(
560  'entity_id',
561  ['in' => $pathIds]
562  )->addFieldToFilter(
563  'custom_use_parent_settings',
564  [['eq' => 0], ['null' => 0]]
565  )->addFieldToFilter(
566  'level',
567  ['neq' => 0]
568  )->setOrder(
569  'level',
570  'DESC'
571  )->load();
572  return $collection->getFirstItem();
573  }
getMainStoreTable($storeId=\Magento\Store\Model\Store::DEFAULT_STORE_ID)
Definition: Flat.php:173

◆ getProductCount()

getProductCount (   $category)

Get products count in category

Parameters
\Magento\Catalog\Model\Category$category
Returns
integer

Definition at line 495 of file Flat.php.

496  {
497  $select = $this->getConnection()->select()->from(
498  $this->getTable('catalog_category_product'),
499  "COUNT({$this->getTable('catalog_category_product')}.product_id)"
500  )->where(
501  "{$this->getTable('catalog_category_product')}.category_id = ?",
502  $category->getId()
503  )->group(
504  "{$this->getTable('catalog_category_product')}.category_id"
505  );
506  return (int)$this->getConnection()->fetchOne($select);
507  }

◆ getProductsPosition()

getProductsPosition (   $category)

Get positions of associated to category products

Parameters
\Magento\Catalog\Model\Category$category
Returns
array

Definition at line 696 of file Flat.php.

697  {
698  $select = $this->getConnection()->select()->from(
699  $this->getTable('catalog_category_product'),
700  ['product_id', 'position']
701  )->where(
702  'category_id = :category_id'
703  );
704  $bind = ['category_id' => (int)$category->getId()];
705 
706  return $this->getConnection()->fetchPairs($select, $bind);
707  }

◆ getStoreId()

getStoreId ( )

Return store id

Returns
integer

Definition at line 149 of file Flat.php.

150  {
151  if ($this->_storeId === null) {
152  return (int)$this->_storeManager->getStore()->getId();
153  }
154  return $this->_storeId;
155  }

◆ isInRootCategoryList()

isInRootCategoryList (   $category)

Check is category in list of store categories

Parameters
\Magento\Catalog\Model\Category$category
Returns
boolean

Definition at line 593 of file Flat.php.

594  {
595  $pathIds = $category->getParentIds();
596  return in_array($this->_storeManager->getStore()->getRootCategoryId(), $pathIds);
597  }

◆ setStoreId()

setStoreId (   $storeId)

Set store id

Parameters
integer$storeId
Returns
$this

Definition at line 138 of file Flat.php.

139  {
140  $this->_storeId = (int)$storeId;
141  return $this;
142  }

Field Documentation

◆ $_catalogConfig

$_catalogConfig
protected

Definition at line 59 of file Flat.php.

◆ $_categoryCollectionFactory

$_categoryCollectionFactory
protected

Definition at line 74 of file Flat.php.

◆ $_categoryFactory

$_categoryFactory
protected

Definition at line 81 of file Flat.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 52 of file Flat.php.

◆ $_inactiveCategoryIds

$_inactiveCategoryIds
protected

Definition at line 45 of file Flat.php.

◆ $_loaded

$_loaded = false
protected

Definition at line 31 of file Flat.php.

◆ $_nodes

$_nodes = []
protected

Definition at line 38 of file Flat.php.

◆ $_storeId

$_storeId
protected

Definition at line 24 of file Flat.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 66 of file Flat.php.


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