Skip to content

Commit

Permalink
Updates for category management
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lee committed Jul 24, 2020
1 parent 3233099 commit 4281813
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 20 additions & 16 deletions Helper/DbHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ public function isProductInCategory(int $productId, int $categoryId) : bool
return false;
}

public function getCategoryIdByPath($categoryPath, $storeId = 0)
public function getCategoryIdsByPath(string $categoryPath, int $storeId = 0) : array
{
$arrIds = [];
$table = $this->getTableName('catalog_category_entity');
$nameTable = $this->getTableName('catalog_category_entity_varchar');
$parentId = $this->getDefaultCategoryId($storeId);
Expand All @@ -333,12 +334,18 @@ public function getCategoryIdByPath($categoryPath, $storeId = 0)
. ");";
$arrRows = $this->sqlRead($sql);
$row = array_pop($arrRows);
if (!isset($row['entity_id'])) {
return 0;
if (isset($row['entity_id'])) {
$arrIds[] = (int) $row['entity_id'];
$parentId = (int) $row['entity_id'];
}
$parentId = (int) $row['entity_id'];
}
return $parentId;
return $arrIds;
}

public function getCategoryIdByPath(string $categoryPath, int $storeId = 0) : int
{
$arrIds = $this->getCategoryIdsByPath($categoryPath, $storeId);
return (int) array_pop($arrIds);
}


Expand All @@ -348,18 +355,15 @@ public function getCategoryIdByPath($categoryPath, $storeId = 0)
* @param int $storeId
* @return int
*/
public function getDefaultCategoryId($storeId = 0) : int
public function getDefaultCategoryId(int $storeId = 0) : int
{
$table = $this->getTableName('catalog_category_entity');
$sql = "SELECT * FROM `".$table."` "
. "WHERE `parent_id` IN "
. "(SELECT `entity_id` FROM `".$table."` WHERE `parent_id` = '0');";
$arrRows = $this->sqlRead($sql);
$row = array_pop($arrRows);
if (isset($row['entity_id'])) {
return (int) $row['entity_id'];
}
return 0;
$tableStore = $this->getTableName('store');
$sqlStore = "SELECT `group_id` FROM `".$tableStore."` WHERE `store_id` = '".$storeId."';";
$groupId = $this->sqlReadOne($sqlStore);
$tableGroup = $this->getTableName('store_group');
$sqlGroup = "SELECT `root_category_id` FROM `".$tableGroup."` WHERE `group_id` = '".$groupId."';";
$rootId = $this->sqlReadOne($sqlGroup);
return (int) $rootId;
}

public function loadExistingAttributeSets()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "arcmedia/mage2-dbhelper",
"description": "Methods to get Data from the Magento DB faster",
"type": "magento2-module",
"version": "0.1.10",
"version": "0.1.11",
"license": [
"MIT"
],
Expand Down

0 comments on commit 4281813

Please sign in to comment.