/** * @param ExpressRuOrderInterface $order * @return array|CalculateResultCollection * @throws \Exception */ public function getDeliveryPricesForOrder(ExpressRuOrderInterface $order) { $calculateArray = $this->orderMapper->mapOrderToApiCalculateArray($order); $method = new CalculateOrderMethod($calculateArray); $apiResponse = $this->apiTransmitter->transmitMethod($method); $resultsCollection = new CalculateResultCollection(); foreach ($apiResponse->getResult() as $resultItem) { $calculateResult = new CalculateResult($this->calculateResultMetadata); $this->calculateResultMapper->mapFromArrayOneToOne($calculateResult, $resultItem); $resultsCollection[] = $calculateResult; } return $resultsCollection; }
/** * @param ExpressRuOrderInterface $order * @return ExpressRuOrderInterface * @throws \Exception */ public function add(ExpressRuOrderInterface $order) { $orderApiArray = $this->orderMapper->mapOrderToApiArray($order); $createOrderMethod = new CreateOrderMethod($orderApiArray); $apiResponse = $this->apiTransmitter->transmitMethod($createOrderMethod); /* @var $apiResponse \ExpressRuSDK\API\Responses\CreateOrderApiResponse */ if (!$apiResponse->isSuccess() and $apiResponse->getValidationErrors()) { throw new ValidationException($apiResponse); } $order->setExpressRuNumber($apiResponse->getOrderNumber()); return $order; }