custom options price calculation

custom options price calculation

October 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
custom options price calculation

Custom Options Price Calculation: Base vs Total Price

When it comes to custom options price calculation, Magento provides built-in functionality that can be customized based on your business requirements. By default, the system calculates percentage-based option prices from the base price, but you may need to change this to calculate from the total price instead.

Let’s break down how the current calculation works and what changes are required to achieve the desired behavior.

Understanding the Default Calculation

In Magento, custom options are added to the product price using a simple formula:

Total Price = Base Price + Option 1 + (Percentage of Base Price)

Using your example:

  • Base Price: $10
  • Custom Option 1: $10
  • Custom Option 2: 10% of Base Price

The calculation would be as follows:

Total Price = $10 (Base) + $10 (Option 1) + (10% of $10)
Total Price = $10 + $10 + $1
Total Price = $21

Changing the Calculation to Total Price

To change the calculation from Base Price to Total Price, you need to update the way percentage-based options are applied. Instead of calculating the percentage from the base price, calculate it from the current total price.

Here’s how you can achieve this:

1. Calculate the Percentage Based on Current Total

When a customer selects an option, first calculate the new total price without the percent option:

New Total = Base Price + Option 1

In your example:

  • New Total = $10 (Base) + $10 (Option 1)
  • New Total = $20

Now, apply the percentage to this new total:

New Total with Percent = New Total * (1 + Percentage)

Using your example:

  • New Total with Percent = $20 * (1 + 0.10)
  • New Total with Percent = $20 * 1.10
  • New Total with Percent = $22

2. Update the Option Price Calculation in Your Code

In your custom price calculation logic, replace the base price with the current total before applying percentage options.

For example, if you have a method like this:

function calculatePrice($basePrice, $option1, $percentOption)
{
    return $basePrice + $option1 + ($basePrice * $percentOption);
}

Change it to:

function calculatePrice($basePrice, $option1, $totalPriceSoFar, $percentOption)
{
    $newTotal = $basePrice + $option1;
    if ($percentOption > 0) {
        return $newTotal * (1 + $percentOption);
    }
    return $newTotal;
}

Conclusion

Changing the custom options price calculation from base price to total price involves a simple logic change in your code. By updating the percentage application process, you can ensure that the final price is calculated correctly based on the current total.

Remember to thoroughly test this new behavior across different scenarios and edge cases to prevent any unexpected results.

For more detailed examples and best practices for customizing Magento’s calculation methods, visit our blog at LaravelCompany.

Catalog Customers Pricing

Our network