Main menu
WalkswithMeJoomlaVirtuemart Calculation Plugin with Custom Rule

Virtuemart Calculation Plugin with Custom Rule

Virtuemart calculation plugin Offers a wide verity of powerful options to the system. The VM2.x is designed in a way that more powerful plugin and modules can be added on the way of upgrading versions. Here I will explain a simple Virtuemart calculation plugin with custom rules.

Why Virtuemart keeps Tax and Calculations in a separate options in VM2.x its designed for more flexibility. The easiest way to alter the product price with custom rule is using vmcalculation plugins. This tutorial is aimed for adding a rule in your Tax and Calculation section for setting up the Double or 3times or “n” times of product price.

virtuemart calculation plugin

virtuemart calculation plugin

I will explain the plugin methods available for vmcalculation plugin.


public function plgVmAddMathOp(&$entryPoints){
$max_length = sizeof($entryPoints);
$entryPoints[$max_length]['calc_value_mathop'] =  "*";
$entryPoints[$max_length]['calc_value_mathop_name'] = "*" ;
return $entryPoints;
}

This plgVmAddMathOp is used for adding you custom math operations in Tax and Calculations DropDown menu.

another plugin methods are plgVmInterpreteMathOp and interpreteMathOp both are same methods but only difference in the argument type, ie, first method is used for VM2.0.6 and its $rule argument is just value but latest versions of VM using second method and its $rule argument is array.

so the plugin method look like below.


public function interpreteMathOp($calculationHelper, $rule, $price,$revert){
if($rule == '*'){
$revert = $revert * $price;
}else{
$revert;
}
return $revert;
}
public function plgVmInterpreteMathOp($calculationHelper, $rule, $price,$revert){
if($rule['calc_value_mathop'] == '*'){
$price = $rule['calc_value'] * $price;
}else{
$price;
}
return $price;
}

Now just set your Virtuemart Calculation plugin with custom rule and see the magic of changes in your product prices. there are several other methods available on the plugin one important method is plgVmOnDisplayEdit this method is used to display some custom fields on your admin Tax and Calculation section .

Hope you guys will able to create more powerful plugins with these logic, Also note Virtuemart is already providing a Quantity discount Plugin as a paid version , they using almost same idea for generating such a plugin. So this information is more relevant for Virtuemart plugin developers.

Hope you guys enjoy the Virtuemart Calculation plugin.

Download854 downloads

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

FacebookTwitterGoogle+RSS