Remember Me
Log in

Price dependent on custom product's size in Magento 2

Magento 2 Extensions
Written by ITORIS Team, 2017-04-03   


Do you sell building materials or goods requiring the size be entered by the customer like blinds, doors, windows, etc.? There is no possibility in Magento 2 natively calculate the final price or shipping weight based on the product dimensions. So how businesses like this can handle it in Magento 2?

The Price Product Formula module for Magento 2 offers the possibility to apply formulas and conditions based on product options. The extension helps to customize products in a simple way. The final price will depend on the entered data. You can find more detailed information about the extension's features in the User Guide.

Let's create a simple product and add custom options. Each option should have the unique SKU to use custom option in a formula. For instance, the product has two options "Height" and "Width", the SKUs of which are "height" and "width" like in the picture. Thus we have our variables {height} and {width}.




After you enter the options' SKUs, find the "Product Price Formula" tab.




After you click button "Add New Formula", a new form appears.

The "Price Formulas" provides the following settings:

Name – enter the formula title here. This option is visible for admin only.

Position – define the correct order if you have multiple formulas within the same product.

Status – choose "Active" to enable the formula.

Date From - Date To – if you plan to apply promotion during a limited period of time, specify dates when the formula is active.

Customer Group – choose customer groups the formula should be active for.




Apply Formula To – allows to set what the calculated value should be applied to. Choose "Item Price", and the formula result will be applied to the item price. The row total will be calculated as the item price multiplied by the quantity.

If "Row Total" is chosen, the formula result will be applied to the row total not depending on the quantity selected. The item price will be calculated as the division of the calculated row total and the quantity.

Condition helps to set condition defining when the formula should be executed. Please enter the following formula to set entered height and width to be positive:

{height} > 0 && {width} > 0

Please pay attention that the options' SKUs are used as formula variables.

The extension allows to show tips on the condition syntax. Click link "Need help on condition syntax?" to see additional formulas.

Run always – if the checkbox is marked, the "Condition" textarea will be disabled, and the formula will always run without conditions.

Price = – enter the following formula to calculate the area of a rectangle:

{height} * {width} * 0.3

Need help on price syntax? – click this link to see tips on the price syntax.

Set formula for the product shipping weight if the condition is TRUE – mark this checkbox if you need to override the product shipping weight. Then enter the following formula for the product weight:

{height} * {width} * 0.02

Else? – allows to fork your condition and add another formula. For instance, you can set custom tier price for quantities if one of the option is greater.

Disallow purchasing the product if the following criteria are met – enter the formula and the custom validation message. You can create unlimited number of such restriction formulas and error messages. Please enter:

if ({width} <= 0 || {len} <= 0)

Error = "Width and length should be greater than 0"

This is how your Frontend will look like:




The product original price with the fixed dimensions is $280.00

Enter custom dimensions in the fields, and the price will be changed according to the defined conditions and formulas.

You are able to create various mathematical formulas and apply them to different customers groups, to multiple products or per product, calculate shipping weight, set limited time offers and create conditional branching. Let customers get what they really want and offer value-added services within the Product Price Formula extension for Magento 2.

Isaac, May 2, 2019
How does this work with configurable products?
ITORIS Team, May 10, 2019
Let's say you have 2 configurable attributes - size and color. You can get the currently selected color as {color} and size as {size} in your formula. For example, add $2.00 for White/2XL:
if ({color} == "White" && {size} == "2XL") Price = {price} + 2

You can also, get the product ID of the current variant via variable {configurable_pid}. For example:
if ({configurable_pid} == 1326) Price = {price} + 2;
else if ({configurable_pid} == 1411) Price = {price} + 3;
else etc.