-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_product.php
54 lines (49 loc) · 1.08 KB
/
create_product.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
<?php
session_start();
require __DIR__.'/vendor/autoload.php';
use phpish\shopify;
require __DIR__.'/conf.php';
$shopify = shopify\client($_SESSION['shop'], SHOPIFY_APP_API_KEY, $_SESSION['oauth_token']);
try
{
# Making an API request can throw an exception
$product = $shopify('POST /admin/products.json', array(), array
(
'product' => array
(
"title" => "Burton Custom Freestlye 151",
"body_html" => "<strong>Good snowboard!</strong>",
"vendor" => "Burton",
"product_type" => "Snowboard",
"variants" => array
(
array
(
"option1" => "First",
"price" => "10.00",
"sku" => 123,
),
array (
"option1" => "Second",
"price" => "20.00",
"sku" => "123"
)
)
)
));
print_r($product);
}
catch (shopify\ApiException $e)
{
# HTTP status code was >= 400 or response contained the key 'errors'
echo $e;
print_r($e->getRequest());
print_r($e->getResponse());
}
catch (shopify\CurlException $e)
{
# cURL error
echo $e;
print_r($e->getRequest());
print_r($e->getResponse());
}