Allocations files

Allocations files are useful when you want to declare dynamic variables.
To create a new allocation file, go to the “allocations” folder inside the module and create a PHP file.
The path is /modules/dynamicproduct/allocations  or /dynamicproduct/allocations if you have version 2.3 or above
The file 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 declare your variables.
The variables that are already 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 width, height, unit_price
there will be variables with the same name and holding the values entered by the user i.e.
$width, $height, $unit_price
To add your custom variable, first create a new field with the name of that variable and give it the type “Dynamic Variable“.

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

Examples of use:

Please note that reading a URL each time may affect performance so the module suggests a caching solution,
that way, your server will load the contents every hour for example and cache the result to use it during that period.

Changing an input value from PHP:
You can change an input value based on another input value, this is useful if you want to preserve proportionality between two fields.
Here’s an example which preserves proportions between width and height and let’s height be always double the width.

Was this article helpful to you? Yes 1 No 1