how to add bulk category assign option in update product attribute Magento

how to add bulk category assign option in update product attribute Magento

July 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
how to add bulk category assign option in update product attribute Magento

Extending Magento: Adding Bulk Category Assignment for Products

Are you facing challenges when trying to assign multiple products to the same category in Magento? You’re not alone. By default, the platform doesn’t provide a straightforward way to do this directly from the admin interface. But don’t worry—we can add this functionality ourselves.

Understanding the Current Limitations

As you noticed, under the Update Product Attributes section of an existing product, there’s no option to select multiple categories for bulk assignment. This is because Magento treats category assignments as individual attributes rather than a collection.

The Solution: Extending the Admin Form

To solve this issue, we need to extend the admin form and modify how product categories are handled during saving.

First, let’s update the admin form to include a multi-select field for categories:

// app/code/Vendor/Module/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="vendor_module" translate="label">
            <label>Vendor Module</label>
            <sort_title>499</sort_title>
        </tab>
        <section id="vendor_module_general" group="general" sort_order="10" show_in_default="1" show_in_website="1" show_in_store="1">
            <group id="category_bulk" translate="label" sort_order="200">
                <label>Category Bulk Assign</label>
                <field id="vendor_module_category_bulk" type="multiselect" sort_order="10" show_in_default="1"
                       show_in_website="1" show_in_store="1" translate="label">
                    <label>Bulk Category Assignment</label>
                    <source_model>Magento\Catalog\Model\Category</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

In this XML, we’re adding a new group under the “general” section of our module. The multiselect field allows us to pick multiple categories.

Modifying the Save Action

Now, let’s update the save action in our module to handle the bulk category assignment:

// app/code/Vendor/Module/Observer/SaveProduct.php
public function execute(Observer $observer)
{
    $product = $observer->getEvent()->getProduct();
    $categories = $this->_request->getParam('vendor_module_category_bulk');

    if (is_array($categories)) {
        foreach ($categories as $categoryId) {
            $product->assignCategory($categoryId);
        }
    }

    return $this;
}

This observer listens for the catalog_product_prepare_save event. If our custom category array is present, we iterate through it and assign each category to the product using the assignCategory method.

Conclusion

Adding bulk category assignment functionality in Magento requires a combination of admin form extension and custom save logic. By following these steps, you can create a custom module that adds this feature directly into your admin interface.

Remember, when working with core system files like system.xml, always use the correct naming conventions and follow Magento’s coding standards for observers.

If you need help implementing this or other advanced Magento modifications, feel free to reach out to our team at Laravel Company. We specialize in custom development and have extensive experience with Magento extensions.

Catalog Extensions Admin Configuration

Our network