![]() |
VOOZH | about |
This document explains the category management system in Maho's admin interface, focusing on the tree-based UI, drag-and-drop operations, AJAX content updates, and category-product relationships. For product management within categories, see Product Types. For category URL generation and SEO, see URL Rewrites and SEO. For category indexing internals, see Indexing System.
Categories in Maho use a hierarchical tree structure stored in the EAV system. The admin interface provides a modernized JavaScript-driven tree view using MahoTree public/js/maho-tree.js12 with drag-and-drop reordering, AJAX-based form updates, and integrated product assignment grids. The CategoryEditForm class manages all client-side interactions while maintaining state synchronization with the server public/js/mage/adminhtml/catalog/category.js12
Key Components:
Mage_Catalog_Model_Category: The core EAV model for category data.Mage_Catalog_Model_Resource_Category_Tree: Handles the database-backed tree structure and hierarchy app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php13-14CategoryEditForm JavaScript class: Manages the admin UI lifecycle and initializes the tree public/js/mage/adminhtml/catalog/category.js28-83MahoTree component: A modern JavaScript tree for rendering and interacting with the category hierarchy using SortableJS for drag-and-drop public/js/maho-tree.js12Sources: public/js/maho-tree.js12 public/js/mage/adminhtml/catalog/category.js12 app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php13-14 public/js/mage/adminhtml/catalog/category.js28-83
Categories use the EAV architecture with additional relationship tables for the tree structure and product associations.
Title: Category Data Architecture
Sources: app/code/core/Mage/Catalog/Model/Resource/Category.php46-55 app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php63-77 app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php110-113
The hierarchy is maintained using a path field (e.g., 1/2/5) and a position field for ordering. The resource model Mage_Catalog_Model_Resource_Category manages these during the save lifecycle:
Mage_Catalog_Model_Resource_Category_Tree uses Maho\Data\Tree\Dbp to load nodes and adds collection data (like names and active status) to them app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php112-168Sources: app/code/core/Mage/Catalog/Model/Resource/Category.php157-189 app/code/core/Mage/Catalog/Model/Resource/Category.php198-216 app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php112-168
The CategoryEditForm class is the central controller for the category management interface. It coordinates the MahoTree, form validation via varienForm, and the product assignment grid.
Title: Category Management Frontend Logic
Sources: public/js/mage/adminhtml/catalog/category.js28-86 public/js/mage/adminhtml/catalog/category.js112-121 public/js/maho-tree.js58-138
The UI utilizes MahoTree with sortable options enabled public/js/mage/adminhtml/catalog/category.js68-70 When a move is completed, the moveCategory callback sends the node ID, new parent ID, and the ID of the node it was placed after to the server public/js/mage/adminhtml/catalog/category.js203-228
Sources: public/js/mage/adminhtml/catalog/category.js68-70 public/js/mage/adminhtml/catalog/category.js203-228
The Maho admin allows toggling metadata visibility on the tree nodes, such as the Category ID and Product Count public/js/mage/adminhtml/catalog/category.js56-62 These preferences are persisted in localStorage public/js/mage/adminhtml/catalog/category.js94-103
Sources: public/js/mage/adminhtml/catalog/category.js56-62 public/js/mage/adminhtml/catalog/category.js94-103
Products are associated with categories via the catalog_category_product table app/code/core/Mage/Catalog/Model/Resource/Category.php54 In the admin, this is managed by a grid within the category edit page.
The initProductsGrid method in CategoryEditForm synchronizes the selection state of the product grid with a hidden input field public/js/mage/adminhtml/catalog/category.js123-178
position of a product within the category public/js/mage/adminhtml/catalog/category.js139-148products object is updated and serialized into the hidden input public/js/mage/adminhtml/catalog/category.js162-174Sources: app/code/core/Mage/Catalog/Model/Resource/Category.php54 public/js/mage/adminhtml/catalog/category.js123-178 public/js/mage/adminhtml/catalog/category.js139-148 public/js/mage/adminhtml/catalog/category.js162-174
Maho marks the Flat Catalog Category optimization as deprecated app/code/core/Mage/Catalog/etc/system.xml100 Modern databases (PostgreSQL, SQLite, and optimized MySQL) no longer require the denormalized catalog_category_flat tables for performance app/locale/en_US/Mage_Catalog.csv11 While still present in the codebase for legacy compatibility app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php14-16 it is recommended to use the standard EAV models.
Sources: app/code/core/Mage/Catalog/etc/system.xml100 app/locale/en_US/Mage_Catalog.csv11 app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php14-16
| Class | Role | Key Function |
|---|---|---|
Mage_Catalog_Model_Resource_Category | Resource Model | _saveCategoryProducts saves grid associations app/code/core/Mage/Catalog/Model/Resource/Category.php208 |
Mage_Catalog_Model_Resource_Category_Tree | Hierarchy Manager | addCollectionData populates tree nodes app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php112 |
Mage_Adminhtml_Block_Catalog_Category_Abstract | Block Base | getRoot initializes the tree root based on store context app/code/core/Mage/Adminhtml/Block/Catalog/Category/Abstract.php149 |
CategoryEditForm (JS) | Admin Controller | submitCategory handles AJAX form submission public/js/mage/adminhtml/catalog/category.js230 |
MahoTree (JS) | UI Component | setRootNode renders the interactive tree public/js/maho-tree.js140 |
Sources: app/code/core/Mage/Catalog/Model/Resource/Category.php208 app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php112 app/code/core/Mage/Adminhtml/Block/Catalog/Category/Abstract.php149 public/js/mage/adminhtml/catalog/category.js230 public/js/maho-tree.js140