Magento Add Configurable Product to shopping cart

Magento Add Configurable Product to shopping cart

October 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Add Configurable Product to shopping cart

Adding Configurable Products to Cart in Magento

Adding configurable products to the cart in Magento involves a slightly different approach compared to simple products. In this post, we’ll guide you through the process using Magento’s SOAP API.

Understanding Configurable Products

Configurable products are composite products that have fixed parent products and variable super attributes (like size or color). They are typically priced based on their simplest child product. Adding a configurable product to the cart requires specifying the desired options for each attribute.

Using the ShoppingCartProductAdd Method

The shoppingCartProductAdd method in Magento’s SOAP API is used to add products to the shopping cart. For simple products, this method works perfectly fine as you demonstrated in your example code. However, it needs to be modified slightly when dealing with configurable products.

Modifying the Method for Configurable Products

When adding a configurable product to the cart, you need to specify the child product’s SKU and attributes within the options array.

Here is an updated version of your code that handles configurable products:

$sessionID = 'your_session_id';
$cartID = 0; // For guest checkout or use customer session ID for logged-in users

$productID = $configurableProductId;
$sku = $childProductSku;
$qty = 2;

$result = $proxy->shoppingCartProductAdd(
    $sessionID,
    $cartID,
    array(array(
        'product_id' => $productID,
        'sku' => $sku,
        'qty' => $qty,
        'options' => array(0 => array('key' => $optionId, 'value' => $optionValue)),
        'bundle_option' => null,
        'bundle_option_qty' => null,
        'links' => null
    ))
);

In this code:

  • $configurableProductId is the ID of your configurable product.
  • $childProductSku is the SKU of the child product that corresponds to the desired options.
  • The key in the options array should match the attribute ID of the super attribute you want to specify (like size or color).
  • The value corresponds to the selected option value.

Conclusion

Adding configurable products to the cart requires a bit more information than adding simple products. By specifying the child product’s SKU and desired options, you can successfully add configurable products to the shopping cart using Magento’s SOAP API.

Remember that the session ID is crucial for this process; make sure it’s set correctly depending on whether the user is logged in or not.

If you found this information helpful, check out our guide on Implementing a Custom Magento Module to learn more about extending Magento functionality.

Happy coding!

Checkout Catalog API Configuration

Our network