get selected custom option price for simple product in observer

get selected custom option price for simple product in observer

July 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
get selected custom option price for simple product in observer

Getting Selected Custom Option Price for Simple Products in an Observer

When working with Magento observers, especially when dealing with simple products that have custom options attached to them, retrieving the selected option’s price can be quite challenging. This is particularly true when you’re trying to get this information within a checkout event like checkout_cart_product_add_after.

The Current Approach and Limitations

The provided code snippet is attempting to retrieve all order options for a given product using $product->getTypeInstance(true)->getOrderOptions($product). While this does provide an array containing details about selected custom options, it fails to include the price associated with each option.

The output array includes information such as the label, value, and option ID, but crucially lacks any pricing data. This is because Magento’s default configuration doesn’t include prices in the getOrderOptions() method for simple products.

Retrieving Pricing Information

To get the selected custom option price, you need to fetch it separately using the product’s options collection. Here’s how you can modify your observer code:

public function applyCartPriceChange(Varien_Event_Observer $observer)
{
    $item = $observer->getQuoteItem();
    $product = $item->getProduct();

    // Retrieve all custom options for the product
    $options = $product->getOptions();

    foreach ($options as $option) {
        if (!empty($option->getCustomOption())) {
            // Check if an option is selected and has pricing information
            $customOption = $option->getCustomOption();
            if (isset($customOption['price'])) {
                // Price is available, apply it to the item or perform other actions
                $item->setCustomPrice($customOption['price']);
                $item->setOriginalCustomPrice($customOption['price']);
            }
        }
    }

    // Assuming you want to enable super mode if a special price is applied
    if ($specialPrice > 0) {
        $item->getProduct()->setIsSuperMode(true);
    }
}

The Key Changes

The modified code does the following:

  1. It retrieves all options for the given product, as opposed to just order options.
  2. It checks each option to see if it has a custom value selected (i.e., a value set by the customer).
  3. If a custom option is selected and it contains pricing information ($customOption['price']), it applies this price to the quote item.

Conclusion

Retrieving the selected custom option’s price in an observer requires fetching the product’s options collection and checking each option for pricing data. The provided code demonstrates how to modify your existing logic to achieve this.

By using this approach, you can successfully get the price of a selected custom option for a simple product within a checkout event like checkout_cart_product_add_after.

Remember that observer events are powerful tools in Magento, allowing you to customize behavior at key points in the system. With careful implementation, they can help you achieve complex functionality that isn’t available through the default configuration.

For more information on working with observers and customizing Magento’s core features, consider visiting Laravel Company, where we provide expert guidance and best practices for developing effective e-commerce solutions.

Checkout Catalog Extensions Configuration

Our network