|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of PHP CS Fixer. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
|
7
|
|
|
* Dariusz Rumiński <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This source file is subject to the MIT license that is bundled |
|
10
|
|
|
* with this source code in the file LICENSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Etrias\EwarehousingConnector\Services; |
|
14
|
|
|
|
|
15
|
|
|
use DateTime; |
|
16
|
|
|
use Etrias\EwarehousingConnector\Client\EwarehousingClient; |
|
17
|
|
|
use Etrias\EwarehousingConnector\Response\StockResponse; |
|
18
|
|
|
use Etrias\EwarehousingConnector\Response\SuccessResponse; |
|
19
|
|
|
use Etrias\EwarehousingConnector\Serializer\ServiceTrait; |
|
20
|
|
|
use GuzzleHttp\RequestOptions; |
|
21
|
|
|
use JMS\Serializer\SerializerInterface; |
|
22
|
|
|
|
|
23
|
|
|
class StockService implements StockServiceInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use ServiceTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** @var EwarehousingClient */ |
|
28
|
|
|
protected $client; |
|
29
|
|
|
|
|
30
|
|
|
/** @var SerializerInterface */ |
|
31
|
|
|
protected $serializer; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* OrderService constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param EwarehousingClient $client |
|
37
|
|
|
* @param SerializerInterface $serializer |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(EwarehousingClient $client, SerializerInterface $serializer) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->client = $client; |
|
42
|
|
|
$this->serializer = $serializer; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
* |
|
48
|
|
|
* @return StockResponse[] |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getListing( |
|
51
|
|
|
array $articleCodes = null, |
|
52
|
|
|
$articleDescription = null, |
|
53
|
|
|
DateTime $updatedAfter = null, |
|
54
|
|
|
$page = 1, |
|
55
|
|
|
$limit = 1000, |
|
56
|
|
|
$sort = null, |
|
57
|
|
|
$direction = null |
|
58
|
|
|
) { |
|
59
|
|
|
$data = [ |
|
60
|
|
|
'article_code' => $articleCodes, |
|
61
|
|
|
'article_description' => $articleDescription, |
|
62
|
|
|
'updated_after' => $updatedAfter ? $updatedAfter->format('Y-m-d') : null, |
|
63
|
|
|
'page' => $page, |
|
64
|
|
|
'sort' => $sort, |
|
65
|
|
|
'direction' => $direction, |
|
66
|
|
|
'limit' => $limit, |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
$guzzleResponse = $this->client->get('3/stock', [RequestOptions::QUERY => $data]); |
|
70
|
|
|
|
|
71
|
|
|
return $this->deserializeResponse($guzzleResponse, 'array<'.StockResponse::class.'>'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
* |
|
77
|
|
|
* @return StockResponse[] |
|
78
|
|
|
*/ |
|
79
|
|
|
public function listVariants( |
|
80
|
|
|
array $articleCodes = null, |
|
81
|
|
|
$articleDescription = null, |
|
82
|
|
|
DateTime $updatedAfter = null, |
|
83
|
|
|
$page = 1, |
|
84
|
|
|
$limit = 1000, |
|
85
|
|
|
$sort = null, |
|
86
|
|
|
$direction = null |
|
87
|
|
|
) { |
|
88
|
|
|
$data = [ |
|
89
|
|
|
'article_code' => $articleCodes, |
|
90
|
|
|
'article_description' => $articleDescription, |
|
91
|
|
|
'updated_after' => $updatedAfter ? $updatedAfter->format('Y-m-d') : null, |
|
92
|
|
|
'page' => $page, |
|
93
|
|
|
'sort' => $sort, |
|
94
|
|
|
'direction' => $direction, |
|
95
|
|
|
'limit' => $limit, |
|
96
|
|
|
]; |
|
97
|
|
|
|
|
98
|
|
|
$guzzleResponse = $this->client->get('1/variant', [RequestOptions::QUERY => $data]); |
|
99
|
|
|
|
|
100
|
|
|
return $this->deserializeResponse($guzzleResponse, 'array<'.StockResponse::class.'>'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritdoc} |
|
105
|
|
|
* |
|
106
|
|
|
* @return SuccessResponse |
|
107
|
|
|
*/ |
|
108
|
|
|
public function updateStock($articleCode, $minStock, $margin) |
|
109
|
|
|
{ |
|
110
|
|
|
$data = [ |
|
111
|
|
|
'article_code' => $articleCode, |
|
112
|
|
|
'min_stock' => $minStock, |
|
113
|
|
|
'margin' => $margin, |
|
114
|
|
|
]; |
|
115
|
|
|
|
|
116
|
|
|
$guzzleResponse = $this->client->post('2/stock/update', [RequestOptions::FORM_PARAMS => $data]); |
|
117
|
|
|
|
|
118
|
|
|
return $this->deserializeResponse($guzzleResponse, SuccessResponse::class); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* {@inheritdoc} |
|
123
|
|
|
* |
|
124
|
|
|
* @return SuccessResponse |
|
125
|
|
|
*/ |
|
126
|
|
|
public function createStock(array $products = []) |
|
127
|
|
|
{ |
|
128
|
|
|
$data = [ |
|
129
|
|
|
'products' => $this->serializer->serialize($products, 'array'), |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
$guzzleResponse = $this->client->post('2/stock/create', [RequestOptions::FORM_PARAMS => $data]); |
|
133
|
|
|
|
|
134
|
|
|
return $this->deserializeResponse($guzzleResponse, SuccessResponse::class); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|