Hi,
First of all, thanks to the VM Developers, for all your nice work. I'm now in the middle of my fourth VM installation for a Client an once again I'm stumbling upon the following problem.
The Problem:Custom field prices will be added to the base price and then the discount i calculated. I've had different cases where I needed to add the custom field price after the discount is applied to the sales price.
There are also a couple of other posts about this or related Problems in the forum:
http://forum.virtuemart.net/index.php?topic=127526.0http://forum.virtuemart.net/index.php?topic=115544.0http://forum.virtuemart.net/index.php?topic=103628.0http://forum.virtuemart.net/index.php?topic=130934.0My unsatisfying solution:Since I try to avoid hacking the VM core files like the plague, because you will run sooner or later into troubles if you do it. And every time you update the shop you have to apply and test your hacks.
So, for custom field prices that should ignore the discount on a product I use the a modified version of the dropbox Plugins. The plugin just adds the product discount( I included also the VAT, one of my customers is so bad in math

) to the price modificator. Like this, the plugin adds the exact amount you specified to the sales price.
But there is a slight Problem you have to live with! Technically it will show the wrong base price since the custom field price modificator includes the discount! If someone is interested in the modifications you'll find it at the end of this post.
The proper solutionIn my opinion the proper solution for this problem is to add a new parameter to custom fields to specify how the price modificator should be applied ( before or after the product discount is applied ).
So practically you have to extend the calculation rule for the sales price to something like the following:
The current base price calcualtion:
( "base price" + "custom field prices" ) * discount = "sale price"The new sales price calculation:
( "base price" + "custom field prices before discount" ) * discount ) + "custom field prices after discount" = "sale price" So I'd like to hear from the Developers
- Can it be done without interfering to much with the existing calculation rules?
- Is this already on someone’s Todo list?
So far I didn't look at the VM code. But if no one is already working on this, and you think it's feasible. I'll would give it a shot and try to work out a way to implement this.
Regards Thomas
VM 2 Dropbox plugin and modificationDropbox Plugin VM2: http://forum.virtuemart.net/index.php?topic=99678.0
ATTENTION!!
The following code is for the VM2 Dropbox Plugin only.
I was in a hurry to get the shop working and so I hard coded the VAT for my country. If you want to use it you need to change the VAT according to your country or improve the code to pull the VAT from the product or remove it entierly.
--- a/src/plugins/vmcustom/drop/drop.php
+++ b/src/plugins/vmcustom/drop/drop.php
@@ -1,9 +1,14 @@
<?php
-defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ) ;
+defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ) ;
//@Banquet Tables Pro custom dropbox plugin.
//Lets go 2.0
-if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
+if (!class_exists( 'vmCustomPlugin' )) {
+ require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
+}
+if (!class_exists( 'calculationHelper' )) {
+ require (JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
+}
class plgVmCustomDrop extends vmCustomPlugin {
@@ -74,11 +79,25 @@ class plgVmCustomDrop extends vmCustomPlugin {
$valueWithPrice = explode('|', $valuesWithPrice);
if ( $customVariant['custom_drop'] == $valueWithPrice[0]) {
- if ( isset ($valueWithPrice[1]) ) {
-
+ if ( isset ($valueWithPrice[1]) ) {
$op = $valueWithPrice[1][0];
$cValue = substr($valueWithPrice[1], 1);
- $valueWithVAT = (float) ($cValue/0.8) / 1.08;
+
+
+ $discount = 1;
+ $VAT = 1.08;
+
+ $cHelper = calculationHelper::getInstance();
+ $prices = $cHelper->getProductPrices( $product );
+ $discounts = $prices['DATax'];
+
+ if( !empty( $discounts ) ) {
+ $keys = array_keys( $discounts );
+ $discount -= $discounts[ $keys[0] ][1] / 100;
+ }
+ //print_r( $discount );
+ //$discount = $product->salesPriceWithDiscount / $product->basePriceWithTax;
+ $valueWithVAT = (float) ($cValue/$discount) / $VAT;
if ($op == '+') $productCustomsPrice->custom_price = $valueWithVAT;
// testing equals
else if ($op == '=') $productCustomsPrice->custom_price = -$product->product_price+$valueWithVAT;
VM3 Dropbox PluginDropbox Plugin VM3: http://forum.virtuemart.net/index.php?topic=127362.0ModificationsI did not make the modification yet. But I'll post them here as soon as possible...