/** * @param DimensionsInterface $dimensions * @return Weight */ public function calculate(DimensionsInterface $dimensions) { $length = $this->lengthConverter->convert($dimensions->getLength(), $dimensions->getUnit(), LengthUnits::IN); $width = $this->lengthConverter->convert($dimensions->getWidth(), $dimensions->getUnit(), LengthUnits::IN); $height = $this->lengthConverter->convert($dimensions->getHeight(), $dimensions->getUnit(), LengthUnits::IN); $volume = $this->math->mul($length, $width); $volume = $this->math->mul($volume, $height); $value = $this->math->div($volume, $this->getFactor()); $value = $this->math->roundUp($value, 3); $weight = new Weight(); $weight->setValue($value); $weight->setUnit(WeightUnits::LB); return $weight; }
<?php use EsteIt\ShippingCalculator\Calculator\BaseCalculator; use EsteIt\ShippingCalculator\CalculatorHandler\AramexCalculatorHandler; use EsteIt\ShippingCalculator\Model\Weight; use EsteIt\ShippingCalculator\Model\Dimensions; use EsteIt\ShippingCalculator\Model\Address; use EsteIt\ShippingCalculator\Model\Package; include_once __DIR__ . '/../vendor/autoload.php'; $config = (include __DIR__ . '/../src/Resources/Aramex/tariff_2015_08_25_usa.php'); $calculator = new BaseCalculator(['handler' => AramexCalculatorHandler::create($config)]); $weight = new Weight(); $weight->setValue(10); $weight->setUnit('lb'); $dimensions = new Dimensions(); $dimensions->setLength(10); $dimensions->setWidth(10); $dimensions->setHeight(10); $dimensions->setUnit('in'); $senderAddress = new Address(); $senderAddress->setCountryCode('USA'); $recipientAddress = new Address(); $recipientAddress->setCountryCode('IND'); $package = new Package(); $package->setCalculationDate(new \DateTime()); $package->setWeight($weight); $package->setDimensions($dimensions); $package->setSenderAddress($senderAddress); $package->setRecipientAddress($recipientAddress); $result = $calculator->calculate($package); var_dump($result->getTotalCost());