Create the block file in your module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php namespace Magemonkey\Category\Block; class Category extends \Magento\Framework\View\Element\Template { public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository, array $data = [] ) { $this->categoryRepository = $categoryRepository; parent::__construct($context, $data); } /* $categoryId as category id */ public function getCategoryById($categoryId){ try { return $category = $this->categoryRepository->get($categoryId); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return ['response' => 'Category Not Found']; } } } ?> |
Put this code in your template file and pass the category id in getCategoryById function.
1 2 3 4 5 6 7 |
<?php $categoryId = 10; // category id $getCategory = $block->getCategoryById($categoryId); echo $getCategory->getName();echo "<br>"; echo $getCategory->getUrlKey();echo "<br>"; echo $getCategory->getIsActive();echo "<br>"; echo "<pre>";print_r($getCategory->getData()); ?> |
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62837e378e7f1263960083/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...