/**
  * @param OrdersCollection $ordersCollection
  * @param null $date
  * @return OrdersCollection
  */
 public function getTrackingStatusesForCollection(OrdersCollection $ordersCollection, $date = null)
 {
     $numberS = array();
     foreach ($ordersCollection as $order) {
         /* @var $order \ExpressRuSDK\Model\Entities\Order\Order */
         if ($order->getExpressRuNumber()) {
             $numberS[] = $order->getExpressRuNumber();
         }
     }
     if (!$numberS) {
         throw new \InvalidArgumentException('Empty orders numbers');
     }
     $method = new GetTrackingStatusesMethod($numberS, $date);
     $apiResponse = $this->apiTransmitter->transmitMethod($method);
     if ($apiResponse->isError()) {
         return $ordersCollection;
     }
     foreach ($apiResponse->getResult() as $number => $statusesArray) {
         $order = $ordersCollection->getByExpressRuNumber($number);
         $statusesCollection = new StatusesCollection();
         foreach ($statusesArray as $statusArray) {
             $status = new TrackingStatus($this->trackingStatusMetadata);
             $this->trackingStatusMapper->mapStatusFromArray($status, $statusArray);
             $statusesCollection[] = $status;
         }
         $order->setStatusesCollection($statusesCollection);
     }
     return $ordersCollection;
 }
Exemplo n.º 2
0
 /**
  * @param ExpressRuOrderInterface $order
  * @param \DateTime|null $date
  * @return null
  */
 public function getTrackingStatus(ExpressRuOrderInterface $order, \DateTime $date = null)
 {
     $ordersCollection = new OrdersCollection();
     $ordersCollection->add($order);
     $statusesResultArray = $this->getTrackingStatusesForCollection($ordersCollection, $date);
     return isset($statusesResultArray[$order->getExpressRuNumber()]) ? $statusesResultArray[$order->getExpressRuNumber()] : null;
 }