Beispiel #1
0
 public function testCreateRequest()
 {
     $api = new Ups\Locator();
     $api->setRequest($request = new RequestMock());
     // Get locator data based on shipment address
     $locatorRequest = new \Ups\Entity\LocatorRequest();
     // $originAddress
     $originAddress = new \Ups\Entity\OriginAddress();
     $address = new \Ups\Entity\AddressKeyFormat();
     $address->setPostcodePrimaryLow('1000');
     $address->setCountryCode('NL');
     $originAddress->setAddressKeyFormat($address);
     $locatorRequest->setOriginAddress($originAddress);
     // $translate
     $translate = new \Ups\Entity\Translate();
     $translate->setLanguageCode('ENG');
     $locatorRequest->setTranslate($translate);
     // $unitOfMeasurement
     $unitOfMeasurement = new \Ups\Entity\UnitOfMeasurement();
     $unitOfMeasurement->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KM);
     $unitOfMeasurement->setDescription('Kilometers');
     $locatorRequest->setUnitOfMeasurement($unitOfMeasurement);
     try {
         // Get data
         $locations = $api->getLocations($locatorRequest, Ups\Locator::OPTION_UPS_ACCESS_POINT_LOCATIONS);
     } catch (Exception $e) {
     }
     $this->assertEquals($request->getRequestXml(), $request->getExpectedRequestXml('/Locator/Request1.xml'));
 }
 public function testCreateRequest()
 {
     $tit = new Ups\TimeInTransit();
     $tit->setRequest($request = new RequestMock());
     $data = new \Ups\Entity\TimeInTransitRequest();
     // Addresses
     $from = new \Ups\Entity\AddressArtifactFormat();
     $from->setPoliticalDivision3('Amsterdam');
     $from->setPostcodePrimaryLow('1000AA');
     $from->setCountryCode('NL');
     $data->setTransitFrom($from);
     $to = new \Ups\Entity\AddressArtifactFormat();
     $to->setPoliticalDivision3('Amsterdam');
     $to->setPostcodePrimaryLow('1000AA');
     $to->setCountryCode('NL');
     $data->setTransitTo($to);
     // Weight
     $shipmentWeight = new \Ups\Entity\ShipmentWeight();
     $shipmentWeight->setWeight(5.0);
     $unit = new \Ups\Entity\UnitOfMeasurement();
     $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
     $shipmentWeight->setUnitOfMeasurement($unit);
     $data->setShipmentWeight($shipmentWeight);
     // Packages
     $data->setTotalPackagesInShipment(2);
     // InvoiceLines
     $invoiceLineTotal = new \Ups\Entity\InvoiceLineTotal();
     $invoiceLineTotal->setMonetaryValue(100.0);
     $invoiceLineTotal->setCurrencyCode('EUR');
     $data->setInvoiceLineTotal($invoiceLineTotal);
     // Pickup date
     $data->setPickupDate(new \DateTime('2015-05-23'));
     try {
         // Get data
         $times = $tit->getTimeInTransit($data);
     } catch (Exception $e) {
     }
     $this->assertEquals($request->getRequestXml(), $request->getExpectedRequestXml('/TimeInTransit/Request1.xml'));
     // Try now with documentsOnlyIndicator
     $data->setDocumentsOnlyIndicator();
     try {
         // Get data
         $times = $tit->getTimeInTransit($data);
     } catch (Exception $e) {
     }
     $this->assertEquals($request->getRequestXml(), $request->getExpectedRequestXml('/TimeInTransit/Request2.xml'));
 }
 /**
  * Build a UPS Cpmpatible Package Object
  * @param IsotopeProductCollection
  * @return stdClass
  */
 protected function buildPackages(IsotopeProductCollection $objCollection)
 {
     $arrPackages = array();
     foreach ($objCollection->getItems() as $objItem) {
         $product = $objItem->getProduct();
         $arrDimensions = $product->package_dimensions;
         $Package = new Ups_Package();
         $strWeight = strval($this->getShippingWeight($objItem, 'lb'));
         for ($i = 0; $i < $objItem->quantity; $i++) {
             //Packaging Type
             $PackagingType = new Ups_PackagingType();
             $PackagingType->setCode('02');
             //Box for now
             $PackagingType->setDescription('');
             $Package->setPackagingType($PackagingType);
             //Package Dimensions
             $Dimensions = new Ups_Dimensions();
             $UnitOfMeasurementD = new Ups_UnitOfMeasurement();
             $UnitOfMeasurementD->setCode('IN');
             $Dimensions->setUnitOfMeasurement($UnitOfMeasurementD);
             $Dimensions->setLength(round($arrDimensions[0]));
             $Dimensions->setWidth(round($arrDimensions[1]));
             $Dimensions->setHeight(round($arrDimensions[2]));
             $Package->setDimensions($Dimensions);
             //Package Weight
             $PackageWeight = new Ups_PackageWeight();
             $UnitOfMeasurementW = new Ups_UnitOfMeasurement();
             $UnitOfMeasurementW->setCode('LBS');
             $PackageWeight->setUnitOfMeasurement($UnitOfMeasurementW);
             $PackageWeight->setWeight($strWeight == 0 ? '1' : $strWeight);
             $Package->setPackageWeight($PackageWeight);
             //Insured Value
             if ($this->ups_insure_packages) {
                 $InsuredValue = new Ups_InsuredValue();
                 $InsuredValue->setCurrencyCode('USD');
                 //For now
                 $InsuredValue->setMonetaryValue($objItem->getProduct()->getPrice()->getAmount(1));
                 $PackageServiceOptions = new Ups_PackageServiceOptions();
                 $PackageServiceOptions->setInsuredValue($InsuredValue);
                 $Package->setPackageServiceOptions($PackageServiceOptions);
             }
             $arrPackages[] = $Package;
         }
     }
     return $arrPackages;
 }