Creating configurable products programmatically - pricing_value not saved

Creating configurable products programmatically - pricing_value not saved

August 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Creating configurable products programmatically - pricing_value not saved

Solving the Configurable Product Pricing Value Issue

Hello developers! Today we’re diving into an issue that many of us have faced while working with configurable products in Magento. The problem: when creating configurable products programmatically, the pricing values for the associated simple products aren’t being saved correctly.

Understanding the Problem

Our friend here has a well-structured XML import file for his products, which includes both simple and configurable items. He’s successfully created the configurable products and linked them to their respective simples through the “associated products” tab. However, when it comes to saving the pricing values for each simple product in the “super product attribute configuration” panel, the script falls short.

Analyzing the Current Script

Let’s break down the existing functions:

Creating the Configurable Product

The createConfigurableProductFromSimpleProduct function seems to be doing its job correctly. It duplicates a simple product, sets the type as configurable, and saves it with basic information like name, status, stock data, and URL key.

protected function createConfigurableProductFromSimpleProduct($product, $flagshipID)
{
    // Duplicate the product
    // Set the type as configurable
    // Save the new configurable product
}

Linking Simple Products to Configurable Product

The linkSimpleProductsToConfigurableProduct function iterates through the simple products and associates them with the configurable product. It sets the visibility of each simple product as “not visible,” saves it, and prepares an array for configuring the attributes.

protected function linkSimpleProductsToConfigurableProduct($simpleProducts, $configurableProduct)
{
    // Iterate through simple products
    // Set visibility to 'not visible'
    // Prepare data for configuring attributes
}

The Missing Piece

The core issue lies in how we’re setting the pricing values. In the current script, we’re only setting the pricing_value attribute while preparing the $configurableProductsData array:

'pricing_value' => $_product->getPrice(),

However, we aren’t actually saving this value anywhere in the configurable product’s configuration. When we call $configurableProduct->save(), Magento expects us to provide the pricing data through the setConfigurableProductsData method.

The Solution

To fix this, we need to ensure that we’re providing the correct format for the pricing_value while setting the ConfigurableProductsData:

'0' => array(
    'label'         => $this->getAttributeRawValue($this->getAttributeId('root_colors'), $_product->getRoot()),
    'attribute_id'  => $this->getAttributeId('root_colors'),
    'value_index'   => $_product->getColor(),
    'price'         => array(
        'pricing_value' => $_product->getPrice(), // Update the key to 'price'
        'is_percent'    => 0
    ),
)

Notice that we’ve wrapped the pricing_value inside a price array with the correct key.

Wrapping Up

In summary, when working with configurable products programmatically in Magento:

  1. Ensure you’re duplicating and setting the correct type for your new configurable product.
  2. Link your simple products to the configurable one using setConfigurableProductsData.
  3. Pay close attention to how you format the pricing data for each associated simple product.

Remember, when working with complex entities like configurable products, it’s crucial to understand the expected data structure and format required by Magento’s core methods.

I hope this helps resolve your issue! If you have any further questions or need more detailed guidance on Magento development, feel free to explore our Magento resource center for in-depth tutorials and best practices.

Catalog Configuration Pricing Import/Export

Our network