/** * Initializes sync orders whit shop and sheepla * @throws Exception * @return array */ public function syncOrders() { $response = array(); if (is_null($this->client) || is_null($this->config) || is_null($this->model)) { throw new Exception("Not all required values are set: " . (is_null($this->client) ? 'pleas use setClient method ' : '') . (is_null($this->model) ? 'pleas use setModel method ' : '') . (is_null($this->config) ? 'pleas use setConfig method ' : '')); } $orders = $this->model->getOrders(); $this->debug('Orders data to be synced: ', $orders); if (!empty($orders)) { $re = $this->client->createOrders($orders); if (isset($re['errors'])) { throw new Exception(print_r($re, true)); } if (is_array($re)) { foreach ($re as $or) { if (isset($or['errors']) && !empty($or['errors'])) { $response[] = array('orderId' => $or['externalOrderId'], 'sheeplaOrderId' => 0, 'shipmentEDTN' => null, 'status' => 'error', 'errors' => $or['errors']); } else { $response[] = array('orderId' => $or['externalOrderId'], 'sheeplaOrderId' => $or['orderId'], 'shipmentEDTN' => isset($or['shipmentEDTN']) ? $or['shipmentEDTN'] : null, 'status' => 'ok', 'errors' => null); } } } else { throw new Exception('Invalid response from sheepla' . print_r($re, true)); } } else { $this->debug('No orders to be synced'); } return $response; }
public function __construct($config = null, $debug = false) { parent::__construct($config, $debug); }