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 $...
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(
...
\...
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::...
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 $...
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" />
</...
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 ...
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 ...
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 ...
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 ...
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\...
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 ...
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' => '...
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 ...
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\...
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="...
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/...
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=...
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,...
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"/> ...
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 ...
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->...
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>
<...
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", ...
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.
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
...
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:...
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\...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
category-tree × 235category × 107
magento2 × 75
magento-1.9 × 54
category-products × 22
admin × 11
magento-2.1 × 9
magento-1.7 × 9
menu × 9
product × 8
magento2.3 × 8
php × 8
rest-api × 8
url-rewrite × 8
category-listing × 8
magento2.2 × 7
adminform × 7
navigation × 7
category-attribute × 6
topmenu × 6
magento-1.8 × 5
attributes × 5
api × 5
database × 4
layout × 4