예제 #1
0
 /**
  * @param Address $address
  * @return ImportCountry|null
  */
 protected function detectImportCountry(Address $address)
 {
     $countries = $this->get('import_countries');
     $importCountry = null;
     if (array_key_exists($address->getCountryCode(), $countries)) {
         $importCountry = $countries[$address->getCountryCode()];
     }
     return $importCountry;
 }
예제 #2
0
 /**
  * @param Address $address
  */
 public function validateRecipientAddress(Address $address)
 {
     try {
         $importCountry = $this->getImportCountry($address->getCountryCode());
     } catch (InvalidArgumentException $e) {
         throw new ViolationException('Can not send a package to this country.');
     }
     if (!array_key_exists($importCountry->getZone(), $this->get('zone_calculators'))) {
         throw new ViolationException('Can not send a package to this country.');
     }
 }
<?php

use EsteIt\ShippingCalculator\Calculator\BaseCalculator;
use EsteIt\ShippingCalculator\Handler\IParcelHandler;
use EsteIt\ShippingCalculator\Weight;
use EsteIt\ShippingCalculator\Dimensions;
use EsteIt\ShippingCalculator\Address;
use EsteIt\ShippingCalculator\Package;
include_once __DIR__ . '/../vendor/autoload.php';
$config = (include __DIR__ . '/../src/Resources/IParcel/tariff_2015_01_12_usa.php');
$calculator = new BaseCalculator(['handler' => IParcelHandler::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('SGP');
$package = new Package();
$package->setWeight($weight);
$package->setDimensions($dimensions);
$package->setSenderAddress($senderAddress);
$package->setRecipientAddress($recipientAddress);
$result = $calculator->calculate($package);
var_dump($result->getData());