Пример #1
0
 public function testship()
 {
     print_r(get_declared_classes());
     try {
         //set shipper
         $fromAddress = new \SimpleUPS\InstructionalAddress();
         $fromAddress->setAddressee('Mark Stevens');
         $fromAddress->setStreet('10571 Pico Blvd');
         $fromAddress->setStateProvinceCode('CA');
         $fromAddress->setCity('Los Angeles');
         $fromAddress->setPostalCode(90064);
         $fromAddress->setCountryCode('US');
         $shipper = new \SimpleUPS\Shipper();
         $shipper->setNumber('CCE85AD5154DDC46');
         $shipper->setAddress($fromAddress);
         \SimpleUPS\UPS::setShipper($shipper);
         //define a shipping destination
         $shippingDestination = new \SimpleUPS\InstructionalAddress();
         $shippingDestination->setStreet('220 Bowery');
         $shippingDestination->setStateProvinceCode('NY');
         $shippingDestination->setCity('New York');
         $shippingDestination->setPostalCode(10453);
         $shippingDestination->setCountryCode('US');
         //define a package, we could specify the dimensions of the box if we wanted a more accurate estimate
         $package = new \SimpleUPS\Rates\Package();
         $package->setWeight('7');
         $shipment = new \SimpleUPS\Rates\Shipment();
         $shipment->setDestination($shippingDestination);
         $shipment->addPackage($package);
         echo 'Rates: ';
         echo '<ul>';
         foreach (UPS::getRates($shipment) as $shippingMethod) {
             echo '<li>' . $shippingMethod->getService()->getDescription() . ' ($' . $shippingMethod->getTotalCharges() . ')</li>';
         }
         echo '</ul>';
     } catch (Exception $e) {
         //doh, something went wrong
         echo 'Failed: (' . get_class($e) . ') ' . $e->getMessage() . '<br/>';
         echo 'Stack trace:<br/><pre>' . $e->getTraceAsString() . '</pre>';
     }
 }
Пример #2
0
 public function getRates()
 {
     //try {
     //define a package, we could specify the dimensions of the box if we wanted a more accurate estimate
     //$this->setShipper();
     //$shipper = $this->getShipper();
     $shipment = new \SimpleUPS\Rates\Shipment();
     $shipment->setDestination($this->destination);
     foreach ($this->packages as $package) {
         $shipment->addPackage($package);
     }
     //$service = new \SimpleUPS\Service();
     //$service->setCode('03');
     //$shipment->setService($service);
     //$shipment->setShipper($shipper);
     $rates = UPS::getRates($shipment);
     foreach ($rates as $shippingMethod) {
         $this->_rates[$shippingMethod->getService()->getCode()] = $shippingMethod;
     }
     return $this->_rates;
     //} catch (ShipperException $e) {
     //doh, something went wrong
     echo 'Failed: (' . get_class($e) . ') ' . $e->getMessage() . '<br/>';
     echo 'Stack trace:<br/><pre>' . $e->getTraceAsString() . '</pre>';
     //}
     if (UPS::getDebug()) {
         UPS::getDebugOutput();
     }
 }