Abstract
Sometimes a formula is getting bigger than we initially thought.
Here are some ideas to help you write a clear formula.
Read this article if don’t know what is {14} or $Price, or how to access options in a product.
Mode “Tomorrow you can not read it”
$FinalPrice = {14} * {16} * ($Price + ({14} < 2 ? 0 : 10));
Mode “Take it easy, step by step”
It’s very recommendable to store each option_id into your own variables so you can read your formula better.
You can create as many variables as you need, just a name preceded by “$”. The only care is not to use reserved words (Take a look at PHP syntax), the better way to avoid using reserved words is to use prefix like “$my”, “$me”, “our”, etc, for example “$meWidth”.
Write some comments, the future “you” will be grateful.
// // Take the values from options (Remember we use option_id instead option name to avoid language changes $meWidth = {14}; $meHeight = {16}; // // Let's calculate SquareMeters $SquareMeters = $meWidth * $meHeight; // // Add some extra cost if Width is "2" or more if($meWidth<2) { $ExtraCostPermeter= 0; } else { $ExtraCostPermeter= 10; } // // This our price per meters after all extra costs $OurPricePerMeter = $Price + $ExtraCostPermeter; // // Calculate the final price $FinalPrice = $SquareMeters * $OurPricePerMeter;