Beispiel #1
0
 /**
  * Represents the "add_order" action.
  *
  * @throws ShopgateLibraryException
  * @see http://wiki.shopgate.com/Shopgate_Plugin_API_add_order
  */
 protected function addOrder()
 {
     if (!isset($this->params['order_number'])) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_ORDER_NUMBER);
     }
     $orders = $this->merchantApi->getOrders(array('order_numbers[0]' => $this->params['order_number'], 'with_items' => 1))->getData();
     if (empty($orders)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::MERCHANT_API_INVALID_RESPONSE, '"orders" not set. Response: ' . var_export($orders, true));
     }
     if (count($orders) > 1) {
         throw new ShopgateLibraryException(ShopgateLibraryException::MERCHANT_API_INVALID_RESPONSE, 'more than one order in response. Response: ' . var_export($orders, true));
     }
     if (empty($this->response)) {
         $this->response = new ShopgatePluginApiResponseAppJson($this->trace_id);
     }
     $orderData = $this->plugin->addOrder($orders[0]);
     if (is_array($orderData)) {
         $this->responseData = $orderData;
     } else {
         $this->responseData['external_order_id'] = $orderData;
         $this->responseData['external_order_number'] = null;
     }
 }