Example #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>';
     }
 }
Example #2
0
 public function assemblePackages($items)
 {
     $this->packages = array();
     $newpackage = $this->app->parameter->create();
     $count = 1;
     foreach ($items as $item) {
         $shipWeight = $item->getPrice()->getShippingWeight();
         $qty = $item->qty;
         while ($qty >= 1) {
             if ($newpackage->get('weight', 0) + $shipWeight > $this->packageWeightMax) {
                 $package = new \SimpleUPS\Rates\Package();
                 $package->setWeight($newpackage->get('weight'))->setDeclaredValue($newpackage->get('insurance'), 'USD');
                 $this->packages[] = $package;
                 $newpackage = $this->app->parameter->create();
                 $count = 1;
             }
             $newpackage->set('weight', $newpackage->get('weight', 0) + $shipWeight);
             $newpackage->set('insurance', $newpackage->get('insurance', 0.0) + $item->getPrice()->retail * $this->packageInsuredValuePercentage);
             $count++;
             $qty--;
         }
     }
     $package = new \SimpleUPS\Rates\Package();
     $package->setWeight($newpackage->get('weight'))->setDeclaredValue($newpackage->get('insurance'), 'USD');
     $this->packages[] = $package;
     // var_dump($this->packages);
     // return;
     return $this;
 }