1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class Sale extends Base |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Private constructor so only the client can create this |
10
|
|
|
* @param Client $client |
11
|
|
|
*/ |
12
|
11 |
|
public function __construct(Client $client) |
13
|
|
|
{ |
14
|
11 |
|
parent::__construct($client); |
15
|
11 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/sale"); |
16
|
11 |
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get one or multiple sales |
20
|
|
|
* @param string sale id, leave null for list of boxes |
21
|
|
|
* @param object Containing query arguments |
22
|
|
|
* @return object Result of the request |
23
|
|
|
*/ |
24
|
|
|
public function Get($saleId = null, $args = array("limit" => 50)) |
25
|
|
|
{ |
26
|
|
|
if (is_null($saleId)) { |
27
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
28
|
|
|
} |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$saleId, $args); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create new sale |
34
|
|
|
* @param object Containing all the information of a sale |
35
|
|
|
* @return object Result of the request |
36
|
|
|
*/ |
37
|
|
|
public function Create($sale) |
38
|
|
|
{ |
39
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $sale); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Delete a sale object by sale id |
44
|
|
|
* @param string Id of the sale |
45
|
|
|
* @return object Result of the request |
46
|
|
|
*/ |
47
|
|
|
public function Delete($saleId) |
48
|
|
|
{ |
49
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$saleId); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Updates a maximum of 50 sale items at a time. |
54
|
|
|
* @param array Containing content items with a maximum of 50 |
55
|
|
|
* @throws \Exception When more that 50 content items are provided |
56
|
|
|
* @return object Result of the request |
57
|
|
|
*/ |
58
|
|
|
public function Bulk($items) |
59
|
|
|
{ |
60
|
|
|
if (count($items) > 50) { |
61
|
|
|
throw new \Exception("Maximum of 50 sale items allowed at a time"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/bulk", ['items' => $items]); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|