Dynamic SKU change with "Simple Configurable Products" Magento

Dynamic SKU change with "Simple Configurable Products" Magento

July 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Dynamic SKU change with "Simple Configurable Products" Magento

Dynamic SKU Changes for Simple Configurable Products in Magento

Magento’s “Simple Configurable Products” extension is a powerful tool for managing complex product structures. However, as you’ve noticed, keeping up with bug fixes and feature updates can sometimes be challenging due to the nature of open-source projects.

If you’re facing issues updating the SKU dynamically within the cart when simple products are selected, don’t worry—we can solve this through a combination of Magento’s built-in event observers and some custom PHP coding. Let me guide you through the process.

Understanding the Problem

The core issue lies in how Magento handles the product selection for configurable items. By default, when a simple product is chosen from the dropdown, Magento doesn’t update the SKU displayed in the cart unless you manually refresh the page.

To fix this, we need to intercept the event that triggers when a simple product is selected and then manually update the SKU accordingly.

Step-by-Step Solution

1. Identify the Relevant Event in Magento

In Magento, events are triggered using the Varien_Event class. For our purpose, we’re interested in the event that handles changing the super attribute (which is essentially the dropdown selection for simple products).

The event name you need to intercept is:

<event name="catalog_product_attribute_update">

2. Create a Custom Observer

Next, create an observer file under your custom module’s configuration directory (usually located at app/code/local/YourCompany/YourModule/etc/events.xml). This XML file will define the event and the controller that should handle it.

Here’s what your XML might look like:

<config>
  <global>
    <events>
      <catalog_product_attribute_update>
        <observers>
          <your_module_observer>
            <type>singleton</type>
            <class>YourCompany_YourModule_Model_Observer</class>
            <method>updateSuperAttributes</method>
          </your_module_observer>
        </observers>
      </catalog_product_attribute_update>
    </events>
  </global>
</config>

In this configuration, we map the catalog_product_attribute_update event to our custom observer class YourCompany_YourModule_Model_Observer.

3. Implement the Observer Method

Now create the Observer class mentioned in the XML config file. This is where you’ll handle the actual SKU update.

class YourCompany_YourModule_Model_Observer
{
    public function updateSuperAttributes($observer)
    {
        $product = $observer->getEvent()->getProduct();
        $attributeId = $observer->getEvent()->getAttributeId();

        // Retrieve the selected simple product
        $simpleProduct = $product->getTypeInstance()->getSelectedProduct($product);

        if ($simpleProduct) {
            // Set the new SKU for the configurable product
            $product->setSku($simpleProduct->getSku());

            // Save the changes (optional, as Magento usually saves automatically)
            $product->save();
        }
    }
}

In this observer method, we retrieve the selected simple product using the getSelectedProduct function provided by Magento’s catalog_product_type_configurable. We then set the SKU of the configurable product to match the selected simple product’s SKU.

Testing Your Solution

After implementing these changes and clearing your cache, you should be able to see the SKU in the cart update dynamically whenever a simple product is selected from the dropdown menu on the product page. This change will occur without requiring a manual page refresh.

Remember, when working with Magento, it’s crucial to keep your code organized and follow best practices for maintainability. If you need more advanced solutions or assistance with integrating multiple extensions like Simple Configurable Products with other tools in your tech stack, feel free to reach out to our team at Laravel Company.

Conclusion

Updating the SKU dynamically for simple configurable products requires a deep understanding of Magento’s event-driven architecture and its product management system. By using an observer to intercept the catalog_product_attribute_update event, we can manually update the SKU whenever a simple product is selected.

This solution ensures your cart always displays the correct, dynamic SKU without requiring any additional JavaScript or AJAX calls, keeping your site’s performance optimized.

Don’t hesitate to explore more advanced features and customize this code further based on your specific business needs. Happy coding!

Checkout Catalog API Extensions

Our network