/** * * * @return Double */ protected function LiveTotalWeight() { if (self::$total_weight === null) { self::$total_weight = 0; if ($this->useWeight()) { if ($fieldName = Config::inst()->get('PickUpOrDeliveryModifier', 'weight_field')) { $items = $this->Order()->Items(); //get index numbers for bonus products - this can only be done now once they have actually been added if ($items && $items->count()) { foreach ($items as $itemIndex => $item) { $buyable = $item->Buyable(); if ($buyable) { // Calculate the total weight of the order if (!empty($buyable->{$fieldName}) && $item->Quantity) { self::$total_weight += $buyable->{$fieldName} * $item->Quantity; } } } } } } } return self::$total_weight; }