Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LevelCalculator.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
17 {
22  public function __construct(
24  Category $resourceCategory
25  ) {
26  $this->resourceConnection = $resourceConnection;
27  $this->resourceCategory = $resourceCategory;
28  }
29 
36  public function calculate(int $rootCategoryId) : int
37  {
38  $connection = $this->resourceConnection->getConnection();
39  $select = $connection->select()
40  ->from($this->resourceConnection->getTableName('catalog_category_entity'), 'level')
41  ->where($this->resourceCategory->getLinkField() . " = ?", $rootCategoryId);
42  return (int) $connection->fetchOne($select);
43  }
44 }
__construct(ResourceConnection $resourceConnection, Category $resourceCategory)
$connection
Definition: bulk.php:13