예제 #1
0
 /**
  * Get the shipment status history.
  *
  * @param DOMXPath $xpath
  *
  * @return Track
  * @throws \Exception
  */
 protected function getTrack(DOMXPath $xpath)
 {
     $rows = $xpath->query("//table[@class='dataTable']//tr");
     if (!$rows) {
         throw new \Exception("Unable to parse UPS tracking data for [{$this->parcelNumber}].");
     }
     $track = new Track();
     $lastLocation = '';
     foreach ($rows as $index => $row) {
         if ($index == 0) {
             continue;
             // skip the heading row
         }
         $eventData = $this->parseRow($row, $xpath);
         if (!empty($eventData['location'])) {
             $lastLocation = $eventData['location'];
         } else {
             $eventData['location'] = $lastLocation;
         }
         $event = Event::fromArray($eventData);
         $track->addEvent($event);
         if (array_key_exists('recipient', $eventData)) {
             $track->setRecipient($eventData['recipient']);
         }
     }
     return $track->sortEvents();
 }
예제 #2
0
 /**
  * Get the shipment status history.
  *
  * @param DOMXPath $xpath
  *
  * @return Track
  * @throws \Exception
  */
 protected function getTrack(DOMXPath $xpath)
 {
     $rows = $xpath->query("//div[@id='pieceEvents0']/div/div/div/table/tbody/tr");
     if (!$rows) {
         throw new \Exception("Unable to parse DHL tracking data for [{$this->parcelNumber}].");
     }
     $track = new Track();
     foreach ($rows as $row) {
         $eventData = $this->parseEvent($row, $xpath);
         $track->addEvent(Event::fromArray($eventData));
         if (array_key_exists('recipient', $eventData)) {
             $track->setRecipient($eventData['recipient']);
         }
     }
     return $track->sortEvents();
 }
예제 #3
0
 /**
  * Get the shipment status history.
  *
  * @param array $response
  *
  * @return Track
  */
 protected function getTrack(array $response)
 {
     $track = new Track();
     foreach ($response['tuStatus'][0]['history'] as $index => $historyItem) {
         $event = new Event();
         $status = $this->resolveStatus($response, $index);
         $event->setStatus($status);
         $event->setLocation($this->getLocation($historyItem));
         $event->setDescription($historyItem['evtDscr']);
         $event->setDate($this->getDate($historyItem));
         $event->addAdditionalDetails('eventNumber', $response['tuStatus'][0]['progressBar']['evtNos'][$index]);
         $track->addEvent($event);
         if ($status == Track::STATUS_DELIVERED) {
             $track->setRecipient($this->getRecipient($response));
         }
         if ($status == Track::STATUS_PICKUP) {
             $track->addAdditionalDetails('parcelShop', $this->getParcelShopDetails($response));
         }
     }
     return $track->sortEvents();
 }