<?php // development settings set_time_limit(3000); ini_set('max_execution_time', 3000); ini_set('display_errors', 1); error_reporting(E_ALL); ?> <!DOCTYPE html> <html> <body> <?php // -------------------- // Initialize API // -------------------- require_once(__DIR__ . '/SwaggerClient-php/autoload.php'); $simple_key = '508052342b482a015d85c69048030a0005a9da7cea5afe015d85c69048030a00'; ultracart\v2\Configuration::getDefaultConfiguration()->setApiKey('x-ultracart-simple-key', $simple_key); ultracart\v2\Configuration::getDefaultConfiguration()->addDefaultHeader("X-UltraCart-Api-Version", "2017-03-01"); function die_if_api_error(\ultracart\v2\models\OrderResponse $order_response){ if ($order_response->getError() != null) { echo "Error:<br>"; echo $order_response->getError()->getDeveloperMessage() . '<br>'; echo $order_response->getError()->getUserMessage() . '<br>'; die('handle this error gracefully'); } } try { $order_id = 'DEMO-0009103637'; $new_item_id = 'PDF'; $order_api = new ultracart\v2\Api\OrderApi(); $order_expansion = "item"; // this is absolutely critical. expansion must contain item or you'll wipe out the existing items. $order_api = new \ultracart\v2\api\OrderApi(); $order_response = $order_api->getOrder($order_id, $order_expansion); die_if_api_error($order_response); $order = $order_response->getOrder(); $items = $order->getItems(); $new_item = new \ultracart\v2\models\OrderItem(); $new_item->setQuantity(2); $new_item->setMerchantItemId($new_item_id); $new_item->setDescription("PDF blueprint or something..."); $new_item->setCost(new \ultracart\v2\models\Currency(['value' => 9.99])); $new_item->setWeight(new \ultracart\v2\models\Weight(['uom' => "OZ", 'value' => 5])); $new_item->setDistributionCenterCode('DFLT'); // don't assume the code. look it up on the item. array_push($items, $new_item); $order_response = $order_api->updateOrder($order, $order_id, $order_expansion); // be sure to use the same expansion so the result can be checked. die_if_api_error($order_response); $updated_order = $order_response->getOrder(); foreach ($updated_order->getItems() as $item) { echo "<pre>"; echo print_r($item); echo "</pre>"; echo "-----------------------------------------"; } } catch (\ultracart\v2\ApiException $e) { echo 'API Exception when calling OrderAPI: ', $e->getMessage(), PHP_EOL; echo print_r($e->getResponseBody()), PHP_EOL; } catch (Exception $e) { echo 'Exception when calling OrderAPI: ', $e->getMessage(), PHP_EOL; } ?> </body> </html>
Manage space
Manage content
Integrations