-
Notifications
You must be signed in to change notification settings - Fork 0
/
genericPost.php
executable file
·68 lines (58 loc) · 1.9 KB
/
genericPost.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
<?php
use RocketLabs\SellerCenterSdk\Core\Client;
use RocketLabs\SellerCenterSdk\Core\Configuration;
use RocketLabs\SellerCenterSdk\Core\Request\GenericRequest;
use RocketLabs\SellerCenterSdk\Core\Response\ErrorResponse;
use RocketLabs\SellerCenterSdk\Core\Response\SuccessResponseInterface;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/config/config.php';
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
$brandsResponse = $client->call(
(new GenericRequest(
Client::GET,
'GetBrands',
GenericRequest::V1
))
);
$brands = $brandsResponse->getBody()['Brands']['Brand'];
shuffle($brands);
$brand = array_shift($brands);
$categoriesResponse = $client->call(
(new GenericRequest(
Client::GET,
'GetCategoryTree',
GenericRequest::V1
))
);
$rootCategory = $categoriesResponse->getBody()['Categories']['Category'];
$additional = [];
foreach ($rootCategory['Children']['Category'] as $category) {
$additional[] = $category['CategoryId'];
}
$additional = implode(',', $additional);
$response = $client->call(
(new GenericRequest(
Client::POST,
'ProductCreate',
GenericRequest::V1,
[],
[
'Product' => [
'Brand' => $brand['Name'],
'Description' => 'test product description',
'Name' => 'Test product',
'Price' => 123,
'PrimaryCategory' => $rootCategory['CategoryId'],
'Categories' => $additional,
'SellerSku' => uniqid('TPR_'),
'TaxClass' => 'default'
]
]
))
);
if ($response instanceof SuccessResponseInterface) {
printf("Feed has been created. Feed id = %s\n", $response->getHead()['RequestId']);
} else {
/** @var $response ErrorResponse */
printf("Error %s\n", $response->getMessage());
}