Skip to content

Commit

Permalink
Fix cyclic categories
Browse files Browse the repository at this point in the history
  • Loading branch information
lireincore committed Sep 9, 2017
1 parent 980dc46 commit a839295
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,20 @@ public function getCategoryParent($id)
public function getCategoryHierarchy($id)
{
$parents = [];
$ids = [];

if (array_key_exists($id, $this->categories)) {
$parents[$id] = $this->categories[$id];
$parents[] = $this->categories[$id];
$pid = $id;
$ids[] = $pid;

while (($parent = $this->getCategoryParent($pid)) !== null) {
while (null !== $parent = $this->getCategoryParent($pid)) {
$pid = $parent->getId();

if (in_array($pid, $ids, true)) {
break;
}
$ids[] = $pid;
array_unshift($parents, $parent);
}
}
Expand Down

0 comments on commit a839295

Please sign in to comment.