Guest User

Untitled

a guest
Jun 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function categoryLoop($id, $is_sub = false){
  2. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  3.  
  4. $categories = $objectManager->create('MagentoCatalogModelCategory')->load($id);
  5. if($categories->hasChildren()){
  6. echo '<ul class="leftcat"' . (($is_sub) ? ' class="category_children category-'.$categories->getId().'"' : '') . '>';
  7. $subcategories = explode(',', $categories->getChildren());
  8. foreach ($subcategories as $category) {
  9. $subcategory = $objectManager->create('MagentoCatalogModelCategory')->load($category);
  10. echo '<li><a href="'.$subcategory->getUrl().'">';
  11. echo $subcategory->getName();
  12. echo "</a></li>";
  13. if($subcategory->hasChildren()){ categoryLoop($category, true); }
  14. }
  15. echo "</ul>";
  16. }
  17. }
  18. categoryLoop(3);
Add Comment
Please, Sign In to add comment