-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_orders.php
70 lines (63 loc) · 1.79 KB
/
create_orders.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace root;
use auth\curl\CurlHandler;
use models\Store;
use models\Order;
include 'auth\auth.php';
include 'auth\curl\curl.php';
require 'models\Order.php';
/**
* This function creates a new order
*/
function createNewOrder(Store $s, Order $order)
{
$arr = json_encode(array(
'customer_id' => $order->getCustomerId(),
'billing_address' => $order->getBillingAddress(),
'products' => json_decode($order->getProducts())
));
$curl_url = $s->getApiPath() . "v2/orders";
$newOrder = CurlHandler::POST($curl_url, $s->getAccessToken(), $arr);
return $newOrder;
}
/**
* TESTING
*/
$myOrder = new Order();
$myOrder->setCustomerId(1);
$billing = array(
'first_name' => "Mike",
'last_name' => "Kirk",
'street_1' => "900 West Hastings Street",
'city' => "Vancouver",
'state' => "British Columbia",
'zip' => "v1x 6h7",
'country' => "Canada",
'country_iso2' => "CA",
'email' => "mikekirk@email.com"
);
$products = json_encode(array
(
array
(
'product_id' => 77,
'quantity' => 3,
'product_options' => array
(
array
(
'id' => 108,
'value' => "72"
),
array
(
'id' => 109,
'value' => "8"
)
)
)
));
$myOrder->setBillingAddress($billing);
$myOrder->setProducts($products);
echo "NEWLY CREATED ORDER => " . createNewOrder($myStore, $myOrder) . "\n\n";
?>