/** * 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); }
/** * Add all products in the collection to the given scale * @param Scale * @return Scale */ public function addToScale(Scale $objScale = null) { if (null === $objScale) { $objScale = new Scale(); } foreach ($this->getItems() as $objItem) { if (!$objItem->hasProduct()) { continue; } $objProduct = $objItem->getProduct(); if ($objProduct instanceof WeightAggregate) { $objWeight = $objProduct->getWeight(); if (null !== $objWeight) { for ($i = 0; $i < $objItem->quantity; $i++) { $objScale->add($objWeight); } } } elseif ($objProduct instanceof Weighable) { for ($i = 0; $i < $objItem->quantity; $i++) { $objScale->add($objProduct); } } } return $objScale; }
/** * 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); }