Calcbuilder extended + Virtuemart integration:calculator inside product page/use of CBforVM plugin
You can use your calculators to configure complex calculations for price depending on your product custom fields. We'll build an example of one product with two comboboxes, the combination of the fields will fix final price of the product.
First step is to install and enable the Calcbuilder plugin for Virtuemart that you'll find at your Calcbuilder extended package. (You must unzip the package to get the plugin installer plg_cbforvm3.zip)
At Virtuemart side, you can add your custom fields to your product as you would do normally. For this example we have created a new product with a base price= 10€, and couple of custom fields with options, that we want to send to our calculator to have it return the final price. We set the price for each option =0 because the price will be calculated by our calculator and this setting will be ignored. We have created one option with name Option 1 and values Value 1A and Value 1B, and another option with name Option 2 and values Value 2A, Value 2B and Value 2C
So our product at the front end now looks like this:
Now you can build your calculator with Calcbuilder. At the code section, you will have available all information from your product, the quantity selected and of course the values of the custom fields that we'll use to find out our final price.
You only need to fill at your calculator the code section, or the 'spreadsheet' section in case you prefer to build your calculator using an excel file. For this example, we'll keep it simple, we'll create a matrix with all combinations of the options:
and we'll return the value selected according to the two inputs to be added to the base price. The values of the custom fields are available inside the variable $_arrData identified with the same name we gave them at VM, so:
will contain the value selected at our first option (Value 1A or Value 1B), and
will gave us the value (Value 2A,Value 2B or Value 2C) for the second option.In order to recover one value from the matrix and return the price, we write this code:
//we recover the price from the matrix
$price=$mymatrix[$_arrData["Option 1"]][$_arrData["Option 2"]];
//And return the price to the VM product
This code section is completely free, for your price calculation you can use any math operation, matrix, querys to database...as always at the calcbuilder configuration. You only need to ensure you return your result at the $returnVM['calculatedprice'] variable.
Now we're going to apply this calculator to our product, we must create a new custom field at VM, typed 'plugins', select VM3 custom calculator and our calcbuilder calculator at 'additional parameters'. Please note we have checked our field as cart attribute and cart input. You can select 'show title'=no in order to hide completely the calculator at your product page.
Now you can add this calculator to your product custom fields:
And you're done. Each time custom fields are changed, your calculator will return the price and it will modify dynamically the product final price at the product page, the cart and the category view.
Last modified on