Magento remove Option from Bundle product

Magento remove Option from Bundle product

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento remove Option from Bundle product

Removing Bundle Options from Magento Programmatically

Removing options from bundle products programmatically in Magento can be a daunting task if you’re unsure of the correct approach. In this post, we’ll guide you through a step-by-step process to achieve this without deleting options from other products.

Understanding the Current Approach

You’ve already started by loading the product using its SKU and attempting to delete the options in a loop. While this seems like a logical approach, it often leads to deleting options associated with different bundle products due to the way Magento’s option model is structured.

Here’s why your current code might not work as expected:

  • The loop iterates through all options of the loaded product.
  • If an option has a non-empty SKU, it attempts to delete that specific option using its option_id.
  • However, if multiple products share the same options (which is common in Magento), deleting by option_id can remove options from other products as well.

The Correct Approach: Deleting Options Based on Product ID

To avoid this issue, you should delete options based on the product ID instead of the option ID. Here’s a corrected version of your code:

$bundled = Mage::getModel('catalog/product')->loadByAttribute('sku', 'YOUR_SKU');

// Load all options for the current product
$options = $bundled->getOptions();

// Loop through each option
foreach ($options as $option) {
    // Skip if it's a custom option or has no SKU
    if (!($option instanceof Mage_Catalog_Model_Product_Option || empty($option['sku'])) {
        continue;
    }

    // Load the option model using the product ID and option value
    $optionModel = Mage::getModel('bundle/option')
        ->loadByProductOptionId($bundled->getId(), $option['option_id']);

    if ($optionModel && $optionModel->getId()) {
        // Delete the option
        try {
            $optionModel->delete();
            echo 'Deleted option: ' . $option['title'] . " (Option ID: {$option['option_id']})";
        } catch (Exception $e) {
            Mage::logException($e);
            echo 'Failed to delete option: ' . $option['title'];
        }
    }
}

Key Changes Made

  • We’re now loading the options directly from the product model using getOptions().
  • The loop condition checks if the current element is a custom option or if it has an empty SKU, ensuring we only process regular product options with a valid SKU.
  • To delete the correct option, we use Mage::getModel('bundle/option')->loadByProductOptionId($productId, $optionId), passing the bundle product ID and the option ID as parameters. This guarantees that we’re deleting an option associated only with the specified product.

Conclusion

Removing options from bundle products programmatically requires a careful approach to avoid deleting options from other products. By loading the options directly from the product model and using loadByProductOptionId, you can ensure that the correct options are deleted without affecting other products in your Magento store.

Remember, always test changes like these thoroughly in a development environment before applying them to your live site.

For more advanced customizations and insights into Magento’s architecture, check out our blog at Laravel Company. We regularly publish articles on Magento development best practices and tips.

Catalog Errors

Our network