20 votes

Magento 2 - Get Subcategories of Specific Parent Category

Check below example to list of all subcategories of specific parent category using parent category ID using the repository. First of all add CategoryRepository in construct: <?php protected $...
user avatar
  • 5,244
18 votes

Magento 2 - Get Subcategories of Specific Parent Category

You need to add a dependency to your class \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory. Like this: protected $categoryCollectionFactory; public function __construct( ... \...
user avatar
  • 195k
14 votes

Get custom category attribute

Try something like that: $value = Mage::getModel('catalog/category')->load($category->getId())->getData('catalog_pdf'); EDIT: Better way (without loading whole category model): Mage::...
user avatar
  • 616
12 votes

Magento 2 - Get Subcategories of Specific Parent Category

Always try to use repository. Here is an example. Inject CategoryRepository by construct protected $categoryRepository; public function __construct( \Magento\Catalog\Model\CategoryRepository $...
user avatar
  • 34.3k
12 votes

Magento 2 : How to display the category image in the topmenu

Look at vendor/magento/module-catalog/etc/di.xml <type name="Magento\Theme\Block\Html\Topmenu"> <plugin name="catalogTopmenu" type="Magento\Catalog\Plugin\Block\Topmenu" /> </...
user avatar
11 votes
Accepted

Magento 2 REST API returns only default category and its children

Well you can easily get all your categories by passing "all" keyword in your categories get API URL It will give you all the categories including all your root categories. Try below Steps: Your Api ...
user avatar
  • 9,580
9 votes
Accepted

How to get category tree in Magento 2?

I searched over internet for solution to this but got nothing useful. Then I diverted my research towards Magento core where I found \Magento\Catalog\Block\Adminhtml\Category\Tree class where I found ...
user avatar
7 votes
Accepted

Category Paths in Product URLS - Yes or No?

It's fine to have category paths in URL's as long as you also enable canonicals (system->config->catalog->seo->canonical for categories/products->yes). This will stop any duplicate ...
user avatar
7 votes
Accepted

Magento 2 : Selected categories are not visible in edit form

In that case you need to modify getData function. For edit category_ids value must be an array.Suppose category_ids value save in db as comma separated that means '7,9,22'. So when you edit this ...
user avatar
  • 34.3k
7 votes
Accepted

How to add multi-select category tree at admin end in magento 2?

please follow the below logic to get the category collection as tree structure. please let me know if u need any help. <?php namespace Hello\ConfigurableSku\Model\Config\Source; use Magento\...
user avatar
6 votes
Accepted

Magento 1.9.2.4 - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' while saving categories

You have an issue in magento log tables. first Take backup of below tables log_customer log_visitor log_visitor_info log_url log_url_info log_quote Then truncate the tables. This will resolved ...
user avatar
  • 75.7k
6 votes
Accepted

Magento 2 Add category chooser without UI component

I have solved the issue by following codes: Adding field by following code: $fieldset->addField( 'category_ids', '\Vendor\Module\Block\Adminhtml\Chooser', [ 'name' => '...
user avatar
5 votes
Accepted

Check if category is child of another

You can pull the path of the current category: $path = $category->getPath(); The path contains the location in the category tree of the current category separated by a /. You can do the ...
user avatar
5 votes

Get child categories tree when Flat Catalog Category is enabled in admin in Magento 2

You can use getChildren to get child category data in your block even Use Flat Catalog Category is enabled. For example namespace Custom\Module\Block\World; class Index extends \Magento\Framework\...
user avatar
5 votes
Accepted

Magento 2 : How to add category selector on admin form?

If you just want to add tree input renderer you can add this code in your ui component form xml <field name="parent"> <argument name="data" xsi:type="array"> <item name="...
user avatar
  • 7,342
5 votes

Magento 2 : Show admin category tree on frontend

1) go to "app" from root directory of Magento 2 and create new directory code. Then create two more directories in app/code, Namespace and Module Name. The final directory will look like this: app/...
user avatar
  • 1,075
4 votes

Get Sub Category List of a Current Category as Select option

This might help you. <select id="category" class="myinput-text required-entry widthinput" name="category"> <?php $parentid=5; // parent id which you want sub category $categories=...
user avatar
  • 1,567
4 votes
Accepted

Add custom css class to each item in Topmenu - Magento 2

Try following code: app/code/[VendorName]/[ModuleName]/registration.php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE,...
user avatar
  • 3,754
4 votes
Accepted

Magento 2.3 sort categories alphabetically

In your module di.xml (app\code\vender\module\etc\di.xml) place this line <preference for="Magento\Catalog\Model\ResourceModel\Category" type="Vendor\Module\Model\Category"/> ...
user avatar
  • 1,107
3 votes
Accepted

hide only some categories from layered navigation in magento

Include in navigation menu flag does not apply by default to layered nav. If you want to do so, you need to rewrite the method Mage_Catalog_Model_Layer_Filter_Category::_getItemsData. You need to ...
user avatar
  • 195k
3 votes

order sub categories alphabetically

if you take a look on the template file for layered navigation (catalog\layer\view.phtml), you can see that, layered navigation filtering is carried out by this call <?php $_filters = $this->...
user avatar
3 votes
Accepted

Render only children in $_menu

You can probably do that by overwriting the file app/core/Mage/Catalog/Block/Navigation.php app/code/local/YourCompany/Catalog/etc/config.xml: <?xml version="1.0"?> <config> <...
user avatar
3 votes

Magento Categories Drag & Drop Reorder Extremely Slow / Fails

The category move is an expensive event. It triggers the reindexing of url rewrites and category product association (and maybe others). You should put the indexes on 'manual' instead of "on save", ...
user avatar
  • 195k
3 votes

Multi vendor + add product - force to choose only 1 category

Yes, you’re on the right track, you can add Java Script and restrict the user to one category. After that you need to apply restriction in product save function in controller or model.
user avatar
3 votes

Magento 2 - Get Subcategories of Specific Parent Category

Use below code to get all active child categories of a specific category. Function getChildCategories($categoryId) gives all child categories. Where $categoryId - is parent category id <?php ...
user avatar
  • 835
3 votes
Accepted

How to add this category in marketing menu?

In your extension you have to create a new file menu.xml Foo/Bar/etc/adminhtml/menu.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
user avatar
3 votes
Accepted

Magento 2 - top menu show from 2nd sub category

Let's create a new module. We'll call it StackExchange_Topmenu. you will need the following files. app/code/StackExchange/Topmenu/registration.php - the registration file <?php \Magento\...
user avatar
  • 195k
3 votes
Accepted

Get products directly assigned to a category

This is how is_anchor works in Magento. I had problems understanding the reason also. I still do, but I don't care anymore. is_anchor, as you already stated, serves 2 purposes. to include the ...
user avatar
  • 195k
3 votes

Issue - Multi-Store Category Disable Not Working

Well No one can answer this question until and unless they see your code. What logic theme/or menu extension has written for fetching categories. But I can give you a hint where you start debug this ...
user avatar
3 votes

creating categories and subcategories using the api catalogCategoryRepositoryV1

I created a category under deafult category using following request { "category": { "parent_id": 2, "name": "test", "is_active": true } } To create a sub category for your new category change ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible