Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace VendorExtensionBlock;
- class Getcategoryinfo extends MagentoFrameworkViewElementTemplate
- {
- protected $_categoryCollectionFactory;
- public function __construct(
- MagentoFrameworkViewElementTemplateContext $context,
- MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory,
- array $data = []
- ) {
- $this->_categoryCollectionFactory = $categoryCollectionFactory;
- parent::__construct($context, $data);
- }
- public function getCategoryCollection() {
- $collection = $this->_categoryCollectionFactory->create();
- $collection->addAttributeToSelect('*');
- $collection->addIsActiveFilter();
- return $collection;
- }
- }
- // get the list of all categories
- $categories = $block->getCategoryCollection();
- foreach ($categories as $category) {
- echo $category->getName() .' '.$category->getId() . '<br />';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement