/** * @param CalculationResultInterface $result * @param PackageInterface $package * @return mixed */ public function visit(CalculationResultInterface $result, PackageInterface $package) { $this->validateSenderAddress($package->getSenderAddress()); $this->validateRecipientAddress($package->getRecipientAddress()); $this->validateMaximumDimension($package); $this->validateMaximumPerimeter($package); $this->validateWeight($package); $price = $this->getPrice($package); $result->setTotalCost($price); $result->setCurrency($this->get('currency')); }
/** * @param CalculationResultInterface $result * @param PackageInterface $package * @return mixed */ public function visit(CalculationResultInterface $result, PackageInterface $package) { $this->validateSenderAddress($package->getSenderAddress()); $this->validateRecipientAddress($package->getRecipientAddress()); $this->validateDimensions($package); $this->validateWeight($package); $zoneCalculator = $this->getZoneCalculator($package); $weight = $package->getWeight(); $weight = $this->getWeightConverter()->convert($weight->getValue(), $weight->getUnit(), $this->get('mass_unit')); $math = $this->getMath(); $cost = $zoneCalculator->calculate($weight); $wholeWeight = $math->roundUp($weight); $fuelCost = $math->mul($wholeWeight, $this->get('fuel_subcharge')); $total = $math->sum($cost, $fuelCost); $result->setTotalCost($total); $result->setCurrency($this->get('currency')); }
/** * @param CalculationResultInterface $result * @param PackageInterface $package * @return mixed */ public function visit(CalculationResultInterface $result, PackageInterface $package) { $this->validateSenderAddress($package->getSenderAddress()); $this->validateRecipientAddress($package->getRecipientAddress()); $this->validateDimensions($package); $this->validateWeight($package); $weight = $package->getWeight(); $volumetricWeight = $this->getVolumetricWeightCalculator()->calculate($package->getDimensions()); $weight = $this->getWeightConverter()->convert($weight->getValue(), $weight->getUnit(), $this->get('mass_unit')); $volumetricWeight = $this->getWeightConverter()->convert($volumetricWeight->getValue(), $volumetricWeight->getUnit(), $this->get('mass_unit')); $math = $this->getMath(); if ($math->greaterThan($volumetricWeight, $weight)) { $weight = $volumetricWeight; } $zoneCalculator = $this->getZoneCalculator($package); $total = $zoneCalculator->calculate($weight); $result->setTotalCost($total); $result->setCurrency($this->get('currency')); }