-
Notifications
You must be signed in to change notification settings - Fork 2
/
ListProducts.php
43 lines (38 loc) · 1.9 KB
/
ListProducts.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
<?php
include_once '../vendor/autoload.php';
$client = new \AutomaterSDK\Client\Client('YOUR_API_KEY', 'YOUR_API_SECRET');
$productRequest = new \AutomaterSDK\Request\ProductsRequest();
$productRequest->setType(\AutomaterSDK\Request\ProductsRequest::TYPE_SHOP);
$productRequest->setStatus(\AutomaterSDK\Request\ProductsRequest::STATUS_ACTIVE);
$productRequest->setPage(1);
$productRequest->setLimit(10);
try {
$productsResponse = $client->getProducts($productRequest);
} catch (\AutomaterSDK\Exception\UnauthorizedException $exception) {
die('Invalid API key');
} catch (\AutomaterSDK\Exception\TooManyRequestsException $exception) {
die('Too many requests to Automater: ' . $exception->getMessage());
} catch (\AutomaterSDK\Exception\NotFoundException $exception) {
die('Not found - invalid params');
} catch (\AutomaterSDK\Exception\ApiException $exception) {
die($exception->getMessage());
}
echo 'Pages count: ' . $productsResponse->getPagesCount() . '<br>';
echo 'Records count: ' . $productsResponse->getRecordsCount() . '<br>';
echo 'Current page: ' . $productsResponse->getCurrentPage() . '<br>';
echo 'Current records count: ' . $productsResponse->getCurrentCount() . '<br>';
echo '<br>';
foreach ($productsResponse->getData() as $product) {
/** @var \AutomaterSDK\Response\Entity\Product $product */
echo 'Product ID: ' . $product->getId() . '<br>';
echo 'Status: ' . $product->getStatus() . '<br>';
echo 'Price: ' . $product->getPrice() . '<br>';
echo 'External offer ID: ' . $product->getExtOfferId() . '<br>';
echo 'Currency: ' . $product->getCurrency() . '<br>';
echo 'Name: ' . $product->getName() . '<br>';
echo 'Description: ' . $product->getDescription() . '<br>';
echo 'Type: ' . $product->getType() . '<br>';
echo 'Database ID: ' . $product->getDatabaseId() . '<br>';
echo 'Available codes: ' . $product->getAvailableCodes() . '<br>';
echo '<br>';
}