-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.php
105 lines (93 loc) · 3.07 KB
/
example.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Created by JetBrains PhpStorm.
* User: grzegorzlech
* Date: 12-08-06
* Time: 14:00
* To change this template use File | Settings | File Templates.
*/
require_once __DIR__ . '/vendor/autoload.php';
ini_set('display_errors','TRUE');
define('SECRET_KEY','GK6b2pmeC40WQY1NOctfBqCB6qK7Z8Y3');
define('CONSUMER_KEY', 'daphlYxoeszwWGoeZnsYNPbMY1fyjiJw');
define('CALLBACK_URL', 'http://localhost/shoplo-php/example.php');
session_start();
try
{
$config = array(
'api_key' => CONSUMER_KEY,
'secret_key' => SECRET_KEY,
'callback_url' => CALLBACK_URL,
);
$shoploApi = new Shoplo\ShoploApi($config);
try
{
# add product
$productInfo = array(
'title' => 'Penne Rigate makaron pióra 500g',
'description' => 'Najwyższej jakości makaron wyprodukowany w 100% z semoliny z pszenicy durum. Najlepiej smakuje z sosem pomidorowym z boczkiem, mięsem lub rybami.',
'short_description' => '',
'require_shipping' => 1,
'availability' => 1,
'visibility' => 1,
'sku' => 'PR-500-P',
'weight' => 50,
'width' => 0,
'height' => 0,
'depth' => 0,
'diameter' => 0,
'buy_if_empty' => 0,
'quantity' => 1,
'price' => 619,
'price_regular' => 619,
'tax' => 23,
'images' => array(
array(
'src' => 'http://lorempixel.com/640/480/food/',
'title' => '',
'img_main' => true
)
),
'vendor' => 'Barilla',
'category' => array( 'Makarony', 'Delikatesy' ),
'collection' => array('Zdrowa żywność'),
'tags' => 'penne,makaron,zdrowy'
);
$product = $shoploApi->product->create($productInfo);
# retrieve all products
#$data = $shoploApi->product->retrieve();
# count all products
$data = $shoploApi->product->count();
print_r($data);exit;
}
catch ( \Shoplo\AuthException $e )
{
unset($_SESSION['oauth_token']);
header('Location: '.CALLBACK_URL);
exit();
}
echo "<table>";
echo "<tr>
<td>id</td>
<td>name</td>
<td>url</td>
<td>description</td>
<td>delivery need</td>
</tr>";
foreach ( $data as $d )
{
echo "<tr>
<td>".$d['id']."</td>
<td>".$d['name']."</td>
<td>".$d['url']."</td>
<td>".$d['description']."</td>
<td>".$d['delivery_need']."</td>
</tr>";
}
echo "</table>";
}
catch ( Shoplo\ShoploException $e )
{
echo 'Throw Shoplo Exception: '.$e->getMessage();
exit();
}