Witam
jak w Magento2 w swoim bloku (albo phtmlu) pobrać główną nazwę kategori ROOT całego drzewa (domyślnie nazywa się: "Default ". Zmieniłem jej nazwę i chciałbym ją pobrać do phtmla.
Prosze o pomoce.

To mój blok:
  1. <?php
  2. namespace Bloczek\Mymenu\Block;
  3. class Mymenu extends \Magento\Framework\View\Element\Template
  4. {
  5. protected $_categoryHelper;
  6. protected $categoryFlatConfig;
  7. protected $topMenu;
  8.  
  9. /**
  10.   * @param \Magento\Framework\View\Element\Template\Context $context
  11.   * @param \Magento\Catalog\Helper\Category $categoryHelper
  12.   * @param array $data
  13.   */
  14. public function __construct(
  15. \Magento\Framework\View\Element\Template\Context $context,
  16. \Magento\Catalog\Helper\Category $categoryHelper,
  17. \Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState,
  18. \Magento\Theme\Block\Html\Topmenu $topMenu
  19. ) {
  20. $this->_categoryHelper = $categoryHelper;
  21. $this->categoryFlatConfig = $categoryFlatState;
  22. $this->topMenu = $topMenu;
  23. parent::__construct($context);
  24. }
  25.  
  26. /**
  27.   * Return categories helper
  28.   */
  29. public function getCategoryHelper()
  30. {
  31. return $this->_categoryHelper;
  32. }
  33. /**
  34.   * Return top menu html
  35.   * getHtml($outermostClass = '', $childrenWrapClass = '', $limit = 0)
  36.   * example getHtml('level-top', 'submenu', 0)
  37.   */
  38. public function getHtml()
  39. {
  40. return $this->topMenu->getHtml();
  41. }
  42. /**
  43.   * Retrieve current store categories
  44.   *
  45.   * @param bool|string $sorted
  46.   * @param bool $asCollection
  47.   * @param bool $toLoad
  48.   * @return \Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\Resource\Cat
    egory\Collection|array
  49.   */
  50. public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
  51. {
  52. return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
  53. }
  54. /**
  55.   * Retrieve child store categories
  56.   *
  57.   */
  58. public function getChildCategories($category)
  59. {
  60. if ($this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource()) {
  61. $subcategories = (array)$category->getChildrenNodes();
  62. } else {
  63. $subcategories = $category->getChildren();
  64. }
  65. return $subcategories;
  66. }
  67. }


w phtmlu:

  1. // np. wyświetlenie kategorii:
  2.  
  3. <?php
  4. $categories = $this->getStoreCategories(true,false,true);
  5. $categoryHelper = $this->getCategoryHelper();
  6.  
  7. foreach($categories as $category):
  8. if (!$category->getIsActive()) {
  9. continue;
  10. }
  11. ?>
  12. <a href="<?php echo $categoryHelper->getCategoryUrl($category) ?>" class="c"><?php echo $category->getName() ?></a>
  13.  
  14. // ...


jak przed tymi kategoriami pobrać i wyświetlić ROOT ?