Programatically creating Configurable products in Magento 1.8.1

Programatically creating Configurable products in Magento 1.8.1

September 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Programatically creating Configurable products in Magento 1.8.1

Programatically Creating Configurable Products in Magento 1.8.1

Managing thousands of products in Magento can be a daunting task, especially when it comes to creating configurable items from simple ones programmatically. In this post, we’ll explore how you can efficiently create configurable products for your swimwear store running on Magento 1.8.1.

Understanding Configurable Products in Magento

Configurable products are composite products that offer multiple variations of a single product. They allow customers to choose options like size and color before adding the item to their cart. To create these, you’ll need:

  • One configurable product (the parent)
  • Multiple simple products (children) with different attributes
  • A relationship between the parent and children

Steps to Create Configurable Products Programatically

To achieve this programmatically, you can use Magento’s SOAP API along with some custom PHP code. Here are the key steps involved:

  1. Identify Simple Products: First, fetch all simple products from your Magento store using a SOAP client in PHP.
$client = new SoapClient('http://yourstore.com/api/soap/?wsdl');
$sessionId = $client->login('apiUser', 'apiKey');
$products = $client->call($sessionId, 'product.list', array(
    'sessionId' => $sessionId,
));
  1. Group Simple Products: Iterate through the fetched products to group them based on a common SKU pattern.
$groupedProducts = array();
foreach ($products as $product) {
    $skuPattern = preg_match('/^(.+?)\(\d+\)$/', $product['sku'], $matches);
    if ($skuPattern) {
        $groupKey = $matches[1];
        if (!isset($groupedProducts[$groupKey])) {
            $groupedProducts[$groupKey] = array();
        }
        $groupedProducts[$groupKey][] = $product;
    }
}
  1. Create Configurable Product: For each group of simple products, create a new configurable product.
foreach ($groupedProducts as $productsInGroup) {
    // Extract attributes from the first simple product in the group
    $attributeSetId = $productsInGroup[0]['attribute_set_id'];

    // Create the configurable product
    $configurableProductData = array(
        'sku' => $productsInGroup[0]['sku'],
        'name' => $productsInGroup[0]['name'],
        'description' => $productsInGroup[0]['description'],
        'short_description' => $productsInGroup[0]['short_description'],
        'weight' => 0,
        'status' => 1, // Enabled
        'tax_class_id' => 2,
        'visibility' => 4, // Not visible individually
        'price' => 0,
        'special_price' => 0,
        'msrp_display_actual_price_type' => 1, // As low as
        'created_at' => date('Y-m-d H:i:s'),
    );

    $configurableProductId = $client->call(
        $sessionId,
        'product.create',
        array_merge($configurableProductData, array('attribute_set_id' => $attributeSetId))
    );

    // Create and associate simple products
    foreach ($productsInGroup as $simpleProduct) {
        $superAttributeIds = array(); // Initialize an empty array for super attributes

        // Update the simple product to be associated with the configurable one
        $client->call(
            $sessionId,
            'product.update',
            array_merge($simpleProduct, array('type_id' => 'simple', 'associated_product_ids' => array($configurableProductId)))
        );

        // Create super attributes and link them
        foreach ($superAttributeIds as $superAttributeId) {
            $attributeSet = $client->call(
                $sessionId,
                'product.update',
                array_merge(array('entity_id' => $simpleProduct['entity_id'], 'type_id' => 'simple', 'associated_product_ids' => array($configurableProductId)))
            );
        }
    }

    // Save the configurable product
    $client->call(
        $sessionId,
        'product.update',
        array_merge(array('entity_id' => $configurableProductId), $configurableProductData)
    );
}

Displaying Simple Product Names

To distinguish simple products on the front-end, you can use the size attribute to append to the product name. This can be done in your theme’s templates.

Importing Simple Product Data

If a field is not visible individually, it may not be necessary to import or update its data for each simple product if they all share the same value across groups of configurable products.

Future Improvements in Magento API

While current versions of Magento may lack seamless support for creating configurable products programmatically, future updates and advanced APIs like GraphQL and REST can provide more intuitive methods for managing complex product relationships. It’s worth keeping an eye on Magento 2.x documentation and releases for these improvements.

Remember to always test your scripts thoroughly in a staging environment before deploying them to a live store. Happy coding!

For more insights into Magento development, visit https://laravelcompany.com where we regularly publish tutorials and best practices on e-commerce systems.

Magento 1 Checkout Catalog API

Our network