|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Dolibarr\Client\Service; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
7
|
|
|
use Dolibarr\Client\Domain\Common\Barcode; |
|
8
|
|
|
use Dolibarr\Client\Domain\Product\Product; |
|
9
|
|
|
use Dolibarr\Client\Domain\Product\Type; |
|
10
|
|
|
use Dolibarr\Client\Domain\Resource\ApiResource; |
|
11
|
|
|
use Dolibarr\Client\Exception\ApiException; |
|
12
|
|
|
use Dolibarr\Client\HttpClient\HttpClientInterface; |
|
13
|
|
|
use JMS\Serializer\SerializerInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @package Dolibarr\Client\Service |
|
17
|
|
|
*/ |
|
18
|
|
|
final class ProductsService extends AbstractService |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param HttpClientInterface $httpClient |
|
23
|
|
|
* @param SerializerInterface $serializerInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(HttpClientInterface $httpClient, SerializerInterface $serializerInterface) |
|
26
|
|
|
{ |
|
27
|
|
|
parent::__construct($httpClient, $serializerInterface, new ApiResource('products')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param Barcode $barcode |
|
32
|
|
|
* |
|
33
|
|
|
* @return ArrayCollection|Product[] |
|
34
|
|
|
* |
|
35
|
|
|
* @throws ApiException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getByBarcode(Barcode $barcode) |
|
38
|
|
|
{ |
|
39
|
|
|
$resources = $this->getList(['query' => [ |
|
40
|
|
|
'sqlfilters' => 'barcode='.$barcode->barcode() |
|
41
|
|
|
]]); |
|
42
|
|
|
|
|
43
|
|
|
return $this->deserializeCollection($resources, Product::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param int $page |
|
48
|
|
|
* @param int $limit |
|
49
|
|
|
* @param Type|null $mode |
|
50
|
|
|
* |
|
51
|
|
|
* @return ArrayCollection|Product[] |
|
52
|
|
|
* |
|
53
|
|
|
* @throws ApiException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getAll($page, $limit, Type $mode = null) |
|
56
|
|
|
{ |
|
57
|
|
|
if (!$mode) { |
|
58
|
|
|
$mode = Type::all(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$resources = $this->getList([ |
|
62
|
|
|
'query' => [ |
|
63
|
|
|
'limit' => $limit, |
|
64
|
|
|
'page' => $page, |
|
65
|
|
|
'mode' => $mode->getValue(), |
|
66
|
|
|
] |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
return $this->deserializeCollection($resources, Product::class); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|