/** * Represents the "update_order" action. * * @throws ShopgateLibraryException * @see http://wiki.shopgate.com/Shopgate_Plugin_API_update_order */ protected function updateOrder() { 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, '"order" 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)); } $payment = 0; $shipping = 0; if (isset($this->params['payment'])) { $payment = (bool) $this->params['payment']; } if (isset($this->params['shipping'])) { $shipping = (bool) $this->params['shipping']; } $orders[0]->setUpdatePayment($payment); $orders[0]->setUpdateShipping($shipping); if (empty($this->response)) { $this->response = new ShopgatePluginApiResponseAppJson($this->trace_id); } $orderData = $this->plugin->updateOrder($orders[0]); if (is_array($orderData)) { $this->responseData = $orderData; } else { $this->responseData['external_order_id'] = $orderData; $this->responseData['external_order_number'] = null; } }