/** * Calculate the weight of all products in the cart in a specific weight unit * * @access public * @param array * @param string * @return string */ public function getShippingWeight($objItem, $unit) { if (null === $objScale) { $objScale = new Scale(); } if (!$objItem->hasProduct()) { return 0.0; } $objProduct = $objItem->getProduct(); if ($objProduct instanceof WeightAggregate) { $objWeight = $objProduct->getWeight(); if (null !== $objWeight) { // Quantity will be taken into account when building packages //for ($i = 0; $i < $objItem->quantity; $i++) { $objScale->add($objWeight); //} } } elseif ($objProduct instanceof Weighable) { // Quantity will be taken into account when building packages //for ($i = 0; $i < $objItem->quantity; $i++) { $objScale->add($objProduct); //} } return $objScale->amountIn($unit); }
/** * Calculate the weight of all products in the cart in a specific weight unit * * @access public * @param array * @param string * @return string */ public static function getShippingWeight($objItem, $unit) { if (null === $objScale) { $objScale = new Scale(); } if (!$objItem->hasProduct()) { return 0.0; } $objProduct = $objItem->getProduct(); if ($objProduct instanceof WeightAggregate) { $objWeight = $objProduct->getWeight(); if (null !== $objWeight) { $objScale->add($objWeight); } } elseif ($objProduct instanceof Weighable) { $objScale->add($objProduct); } return $objScale->amountIn($unit); }