VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: artfener on October 12, 2014, 20:15:05 PM

Title: Issue with wrong weight calculation
Post by: artfener on October 12, 2014, 20:15:05 PM
I have an issue regarding a live site, it's about weight calculation.
If you try to put this product in the cart (q.ty=1):
http://www.gambasafety.com/linea-vita/prodotti/ancoraggi/ancoraggio-round-d-detail.html

And then try to add 1 or more items, when you will update cart the shipment method "TNT TRACO" will display a wrong weight (this product weight is 4 kg per unit), so advanced shipping rates formules will not be able to calculate the right shipping price. The weight appears to be multiplied by itself, ie: for 5 items it seems to calculate (5*5)*4=100kg instead of 5*4=20kg. If you buy 6, the weight is (6*6)*4=144kg, etc.

Software version is
vm2 rules shipping v4.2
VirtueMart 2.6.10
Joomla! 2.5.26

Can someone please help me?  :)
Daniele Comello
Title: Re: Issue with wrong weight calculation
Post by: GJC Web Design on October 12, 2014, 20:22:03 PM
This certainly isn't normal behaviour - the weights are calculated in vmpsplugin.php if the rules shipping uses getOrderWeight() function

foreach ($cart->products as $product) {
            $weight[$to_weight_unit] += (ShopFunctions::convertWeightUnit ($product->product_weight, $product->product_weight_uom, $to_weight_unit) * $product->quantity);
         }
Title: Re: Issue with wrong weight calculation
Post by: artfener on October 12, 2014, 22:26:20 PM
You're absolutely right, please check the code from my vmpsplugin.php file:

   protected function getOrderWeight (VirtueMartCart $cart, $to_weight_unit) {

      static $weight = array();
      if(!isset($weight[$to_weight_unit])) $weight[$to_weight_unit] = 0.0;
      if(count($cart->products)>0 and empty($weight[$to_weight_unit])){

         foreach ($cart->products as $product) {
            $weight[$to_weight_unit] += (ShopFunctions::convertWeightUnit ($product->product_weight, $product->product_weight_uom, $to_weight_unit) * $product->quantity);
         }
      }
      return $weight[$to_weight_unit];
   }

Best regards
Title: Re: Issue with wrong weight calculation
Post by: GJC Web Design on October 12, 2014, 22:28:49 PM
but u need to check

1. is the rules plugin using the function getOrderWeight ()

2. if not what and why the calc is inaccurate - you can find your way around the files so ech out some vars to see where it goes wrong
Title: Re: Issue with wrong weight calculation
Post by: artfener on October 12, 2014, 22:36:45 PM
Thanks for your answer but I'm not very skilled to understand it...  :'(

Best regards
Daniele