Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. namespace VendorExtensionBlock;
  3.  
  4. class Getcategoryinfo extends MagentoFrameworkViewElementTemplate
  5. {
  6. protected $_categoryCollectionFactory;
  7.  
  8. public function __construct(
  9. MagentoFrameworkViewElementTemplateContext $context,
  10. MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory,
  11. array $data = []
  12. ) {
  13. $this->_categoryCollectionFactory = $categoryCollectionFactory;
  14. parent::__construct($context, $data);
  15. }
  16.  
  17. public function getCategoryCollection() {
  18. $collection = $this->_categoryCollectionFactory->create();
  19. $collection->addAttributeToSelect('*');
  20. $collection->addIsActiveFilter();
  21. return $collection;
  22. }
  23. }
  24.  
  25. // get the list of all categories
  26. $categories = $block->getCategoryCollection();
  27. foreach ($categories as $category) {
  28. echo $category->getName() .' '.$category->getId() . '<br />';
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement