27

Prepare yourself, this is going to be a long one. Here goes. You will need the following files: app/code/local/[Namespace]/[Module]/Block/Adminhtml/[Entity]/Edit/Tab/Categories.php - the tab that will render the categories. <?php class [Namespace]_[Module]_Block_Adminhtml_[Entity]_Edit_Tab_Categories extends ...


19

Check below example to get the list of all subcategories of specific parent category using parent category ID using objectManager. <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $catId = 2; //Parent Category ID $subCategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId); $...


18

You need to add a dependency to your class \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory. Like this: protected $categoryCollectionFactory; public function __construct( ... \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, ... ) { ... $this->categoryCollectionFactory = $...


14

Try something like that: $value = Mage::getModel('catalog/category')->load($category->getId())->getData('catalog_pdf'); EDIT: Better way (without loading whole category model): Mage::getResourceModel('catalog/category')->getAttributeRawValue($category->getId(), "catalog_pdf", Mage::app()->getStore()->getId());


12

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" /> </type> As we can see, Magento uses Plugin - Magento\Catalog\Plugin\Block\Topmenu to override some methods of Magento\Theme\Block\Html\Topmenu class. We ...


11

Always try to use repository. Here is an example. Inject CategoryRepository by construct protected $categoryRepository; public function __construct( \Magento\Catalog\Model\CategoryRepository $categoryRepository ) { $this->categoryRepository = $categoryRepository; } Now you can use following way: $parent_category_id = 3; $categoryObj = $this-&...


11

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 url - http://test.com/index.php/rest/all/V1/categories Your Api Method - Get Your Headers should be - Authorization Bearer youradminaccesstoken Note : Make ...


9

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 a function getTree(). Then I tried to observed it's return value in my custom template file. The effort became fruitful as I got the desired result. I created ...


7

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 content issues.


7

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\Framework\Option\ArrayInterface; use Magento\Catalog\Helper\Category; class Categorylist implements ArrayInterface { protected $_categoryHelper; ...


6

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 your issue.


6

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 value should be [7,9,22]. /** * Get data * * @return array */ public function getData() { if (isset($this->loadedData)) { return $this->loadedData; ...


6

I have solved the issue by following codes: Adding field by following code: $fieldset->addField( 'category_ids', '\Vendor\Module\Block\Adminhtml\Chooser', [ 'name' => 'category_ids', 'label' => __('Categories'), 'title' => __('Categories'), 'required' => true ] ); The code for app/code/...


5

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 following to iterate through each category in the path to search for the one you are interested in as being a parent: $path = explode('/', $path); array_pop($path); // ...


5

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\View\Element\Template { protected $_categoryFactory; protected $_category; protected $_categoryHelper; protected $_categoryRepository; public ...


5

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="options" xsi:type="object">Magento\Catalog\Ui\Component\Product\Form\Categories\Options</item> <item name="config" xsi:type="array"> ...


5

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/code/Demo/CategoryTree. Demo as Namespace and CategoryTree as module name. 2) create "module.xml" file in app/code/Demo/CategoryTree/etc and paste below code ...


4

catalogCategoryInfo method returns full information about one category. But ids are the only information about its child categories. Try to use catalogCategoryTree method instead. It will return you category information tree, with all children names.


4

Any need for reorganization of categories in different store scopes means that you have to duplicate your categories under distinct root categories. Sorry - it's a limitation to Magento's tree modeling of the categories which ultimately resolves (as you noticed) to the global-scope sorting attribute on the entity table.


4

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=explode(',',Mage::getModel('catalog/category')->load($parentid)->getChildren()); foreach($categories as $cat){ $category=Mage::getModel('catalog/category')...


4

Try following code: app/code/[VendorName]/[ModuleName]/registration.php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, '[VendorName]_[ModuleName]', __DIR__ ); app/code/[VendorName]/[ModuleName]/etc/module.xml <config xmlns:xsi="http://www.w3.org/2001/...


4

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"/> Create the file Vendor\Module\Model\Category.php and place this code in it: <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING....


3

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->getFilters() ?> So take a look on getFilters() method in Mage_Catalog_Block_Layer_View block class. public function getFilters() { $filters = array(); ...


3

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 replace this $categories = $categoty->getChildrenCategories(); With something like this (untested code) $categories = $categoty->getCollection(); //...


3

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> <modules> <YourCompany_Catalog> <version>1.0</version> </YourCompany_Catalog> </modules> <...


3

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", move your categories around and reindex everything when you are done. I'm not sure that truncating core_url_rewrite table will solve your problem. It may solve it ...


3

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

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 namespace YourModuleName\CategoryLink\Block; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; use Magento\Catalog\...


3

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:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"> <menu> <add id="Foo_Bar::foo_bar" title="Foo Bar" module="Foo_Bar" ...


3

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\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'StackExchange_Topmenu', __DIR__ ); app/code/...


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