Calcbuilder extended: Virtuemart integration
If you want to use your calculator results to calculate prices and/or quantities of your VirtueMart products before adding them to the cart, you need to configure the VirtueMart options tab.
· Use existing VM products
Select this option if your calculator will be used to calculate the quantity of existing products that will be added to the cart. The products are already created with a fixed price at your VM administration pages, and the calculator will get how many units of the products user needs. For ex, you can use this option to help user calculate how many paint cans he needs to paint a wall given the wall measures, how many heaters he needs for a house given the square meters of a house…everytime the product is recovered from VM, and configured with the calculated quantity before adding it to the cart.
Check ‘Use existing VM products’ and select one category and one product you want to link with the calculator output. Save and you will see the code needed to link your results with the selected product:
Copy the code generated to your calculator code section, replacing the “SET PRODUCT QUANTITY” text for your calculated quantity:
Using this example, the calculator will create an ‘Add to cart’ button added to the result section that we’ll be in charge of adding input1+input2 hammers to your VM cart:
Add to Cart button leads to the cart view of VM, where you will see the product with the calculated quantity:
This is already your default VM view you have configured for your cart, so you can continue checkout from here.
You can add more than one product at at time, clicking ‘Add products’ to the configuration page:
The code generated will contain the expressions needed to set quantities for each product at calculation time:
So you could calculate and set at code tab the required values for these products quantity. If any of the products results a quantity of ‘0’ after your calculations, it will not be added to the cart. This video shows how to configure all the steps explained above.
· Duplicate VM products
You can not store at VM same instance of the same product attached with dynamic prices. If your calculator will set the price and/or the quantity of the products to be added, you need to choose this option. You have to create a ‘template’ of your product at VM, with all parameters you need. When calculator outputs the calculated price/quantity, the template product will be recovered, duplicated with same features, but with its new calculated price set, and will be added to the cart using the calculated quantity.
The configuration steps are the same, you must select the ‘template’ product and save to recover the code you must add to code section in order to use this product as template:
This time you must fill three values with the result of your calculations. The quantity, as we did for the previous option, the price, and also the description of the product. Dynamic prices are usually due to different configuration user chooses for the product, so you can set here detailed specs of the specific instance/configuration of this product, for example:
// Product -> Hammer(6) $vm_price_6=$number1+10; $vm_desc_6="Hammer + special box"; $vm_qty_6=1;
Your calculator will fill dynamically the parameters and add to cart button will create the new product based on your template and add it to the cart:
If you check your VM admin you will see this new instance of the product created with the calculated price.
You can follow this video showing the configuration of these types of products:
Last modified on