Price calculator files

Price calculator files are an alternative to the formula.
They are PHP files that can be added to the folder “calculator” inside the module and calculate the price using PHP code.
The path is /modules/dynamicproduct/calculator or /dynamicproduct/calculator if you have version 2.3 or above
The files should be named productXX.php where XX is replaced by the desired product ID.
As an example for product #7, you can create a file “product7.php” and add your code to calculate the price.

The variables that are available inside the file are:
$id_product: holds the current product ID
$id_attribute: holds the combination ID selected by the user
$quantity: The quantity selected by the client
Other variables include the field names.

If you have a product with fields such as widthheightunit_price
there will be variables with the same name and holding the values entered by the user i.e.
To access the secondary value of a field, you can add an underscore like so $_width, $_height, $_unit_price

The return variable should be named $result
Initially, the $result variable contains the result of the price formula.

Additionally, you can add a global calculator with the name “products.php” which will affect all products.
You can use this file for function declaration too as it will be included before other calculators.

The php file should start with an open tag <?php


Was this article helpful to you? Yes 3 No