Magento Retrieve simple product price for configurable product

Magento Retrieve simple product price for configurable product

July 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Retrieve simple product price for configurable product

Retrieving Product Prices in Magento

In Magento, retrieving the price of a simple product that belongs to a configurable product requires understanding how Magento structures its product data. The key lies in accessing the correct child product using the selected attributes.

Current Approach Limitations The provided code snippet attempts to invisibly select an attribute value on the client-side to gather the price. While this approach might work for certain cases, it has some significant limitations:

  1. Performance Issues: Manipulating the DOM and triggering events on the client-side can lead to performance degradation, especially if you have a large number of options.
  2. Accuracy Concerns: Invisibly selecting an option doesn’t always guarantee that Magento will calculate the price correctly, as it may not fully update its state.

Best Practices for Retrieving Prices

To accurately retrieve the price of a simple product based on selected attributes, follow these best practices:

  1. Use Magento’s built-in AJAX functionality: Magento provides built-in functionality to load product prices via AJAX without needing to manually select options on the client-side. This is more efficient and reliable.

  2. Retrieve data using the product.info.purchasedByCustomer event: You can listen for this event and use it to trigger your price retrieval logic when a customer selects an attribute.

  3. Use Magento’s JavaScript API: The Product object in Magento’s JavaScript API provides methods like getPrice() that can be used to retrieve the price of a configurable product with selected attributes.

Correct Implementation Example

Here is an example of how you could implement this using Magento’s built-in functionality:

// Assuming 'productId' contains your configurable product ID
var config = new Product(configId, true);
// Listen for the 'purchasedByCustomer' event
config.on('purchasedByCustomer', function() {
    var price = config.getPrice();
    console.log('Selected Price:', price);
});

In this example, when a customer selects an option on your configurable product page, the purchasedByCustomer event is triggered. The JavaScript getPrice() method then retrieves the price of the selected simple product.

Conclusion

Retrieving prices for Magento products based on selected attributes requires understanding and utilizing Magento’s built-in functionality. Avoiding client-side manipulation of options can lead to more accurate results and better performance. By using methods like product.info.purchasedByCustomer and Product.getPrice(), you can efficiently handle this in a more reliable manner.

Remember, for any advanced customizations or if you encounter complex pricing structures, it’s highly recommended to consult with a Magento developer or seek expert assistance from professional agencies like Laravel Company.

This approach ensures that your e-commerce store provides accurate and reliable pricing information to your customers.

Catalog Performance API Configuration

Our network