Magento- configurable products options order to match the order they are in the attribute set

Magento- configurable products options order to match the order they are in the attribute set

July 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento- configurable products options order to match the order they are in the attribute set

Maintaining Attribute Order for Magento Configurable Products

As an experienced Magento developer, I frequently encounter issues like the one you’ve described - configurable products’ attributes being reordered after saving them. In this post, I’ll provide a comprehensive solution to ensure that your product options remain in the correct order, matching their position within the attribute set.

The Core Issue: Magento’s Default Behavior

By default, when you create a new configurable product in Magento (version 1.6 and later), the platform saves the attributes based on their IDs rather than their position within the attribute set. This leads to the confusing reordering of options that you’ve noticed.

To illustrate this issue, let’s consider an example:

Imagine you have an attribute set named “Apparel Attributes” with a dropdown attribute called “Color”, placed first in the set, followed by “Size”. When you create a configurable product and select these attributes, Magento saves them as follows: ID 1 (Color), ID 2 (Size).

However, if another attribute is added to the same set before your product creation, it might have an ID of 3. In this case, when you save your product, Magento will reorder the attributes based on their IDs: ID 3 (New Attribute), ID 1 (Color), ID 2 (Size).

This behavior can lead to a poor user experience, as customers may expect options to appear in the order specified within the attribute set.

The Solution: Override Core Functionality

To maintain the correct order of attributes for your configurable products, you’ll need to override Magento’s core functionality. This involves creating an extension that modifies how the product is saved and ensures that the attributes are preserved in their original order.

Here’s a step-by-step guide to implement this solution:

  1. Create a new module: Navigate to app/code folder and create a new directory with your desired module name (e.g., MyCompany_ConfigurableOrder).

  2. Override the saveAction() method: In your new module, create a file named controllers/Adminhtml/ConfigurableProductsController.php. Inside this file, locate the saveAction() method.

  3. Modify the attribute saving process: Within the saveAction() method, you’ll need to modify how Magento saves the selected attributes for the configurable product. To do this, override the way data is prepared before it’s saved to the database.

  4. Use the original order of selected attributes: You can achieve this by iterating through the selected attributes and preserving their original position using the $sort_order field available in the attribute set.

  5. Save the modified data: Once you’ve reordered the attributes, save the product data as usual, ensuring that the correct order is maintained.

Code Sample: Overriding saveAction()

To provide a clearer understanding of how to implement this solution, let’s consider an example code snippet:

public function saveAction()
{
    ...
    $product = $this->_getProduct();
    ...
    if ($postData = $this->getRequest()->getPost()) {
        // Prepare the product data
        $data = $this->_filterPostData($postData);

        // Reorder selected attributes here
        foreach ($selectedAttributes as $attributeCode => $attribute) {
            $sortOrder = $attributeSetAttribute->getSort_order();
            $data['attributes'][$attributeCode]['sort_order'] = $sortOrder;
        }

        // Save the product with the modified data
        try {
            $product->setData($data);
            $product->save();

            ...
        } catch (Exception $e) {
            ...
        }
    }
    ...
}

In this example, replace $selectedAttributes and $attributeSetAttribute with the actual variables containing your selected attributes and their corresponding attribute set attributes. The code iterates through each selected attribute, retrieves its sort order from the attribute set, and assigns it to the product data array.

Best Practices for Magento Configurable Products

To ensure optimal performance and user experience when working with configurable products in Magento, consider these best practices:

  1. Create meaningful attribute sets: Organize your attributes into logical groups based on their purpose or category. This makes it easier to manage and maintain your product data.

  2. Use unique identifiers for attributes: Assign distinct codes to each of your attributes to prevent conflicts when creating multiple configurable products.

  3. Test your configurations thoroughly: Before launching a new product, test its configuration options extensively to ensure they work correctly and provide the expected functionality.

  4. Optimize your database schema: Regularly review and optimize your database structure by removing unused tables and indexes to improve performance.

Conclusion

In this post, we’ve explored the challenge of maintaining the correct order for configurable product attributes in Magento and provided a comprehensive solution to address this issue.

By overriding the core saveAction() method in your custom module, you can ensure that your product options are preserved in their original order within the attribute set. This approach provides a seamless user experience by keeping the configured options consistent across your storefront.

Remember to test your implementation thoroughly and consider the best practices mentioned above for optimal performance and data management in Magento.

For more advanced techniques and customization options, don’t hesitate to explore our extensive resources on Magento development at Laravel Company.

Catalog Configuration Orders Customers

Our network