1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Builder\Request; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\ShippingMethod\ShippingMethod; |
9
|
|
|
use Commercetools\Core\Model\ShippingMethod\ShippingMethodDraft; |
10
|
|
|
use Commercetools\Core\Model\Zone\Location; |
11
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByCartIdGetRequest; |
12
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByIdGetRequest; |
13
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByKeyGetRequest; |
14
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByLocationGetRequest; |
15
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodCreateRequest; |
16
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteByKeyRequest; |
17
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteRequest; |
18
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodQueryRequest; |
19
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateByKeyRequest; |
20
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateRequest; |
21
|
|
|
|
22
|
|
|
class ShippingMethodRequestBuilder |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @return ShippingMethodQueryRequest |
26
|
|
|
*/ |
27
|
1 |
|
public function query() |
28
|
|
|
{ |
29
|
1 |
|
return ShippingMethodQueryRequest::of(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param ShippingMethod $shippingMethod |
34
|
|
|
* @return ShippingMethodUpdateRequest |
35
|
|
|
*/ |
36
|
1 |
|
public function update(ShippingMethod $shippingMethod) |
37
|
|
|
{ |
38
|
1 |
|
return ShippingMethodUpdateRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param ShippingMethod $shippingMethod |
43
|
|
|
* @return ShippingMethodUpdateByKeyRequest |
44
|
|
|
*/ |
45
|
1 |
|
public function updateByKey(ShippingMethod $shippingMethod) |
46
|
|
|
{ |
47
|
1 |
|
return ShippingMethodUpdateByKeyRequest::ofKeyAndVersion( |
48
|
1 |
|
$shippingMethod->getKey(), |
49
|
1 |
|
$shippingMethod->getVersion() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param ShippingMethodDraft $shippingMethodDraft |
55
|
|
|
* @return ShippingMethodCreateRequest |
56
|
|
|
*/ |
57
|
1 |
|
public function create(ShippingMethodDraft $shippingMethodDraft) |
58
|
|
|
{ |
59
|
1 |
|
return ShippingMethodCreateRequest::ofDraft($shippingMethodDraft); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param ShippingMethod $shippingMethod |
64
|
|
|
* @return ShippingMethodDeleteRequest |
65
|
|
|
*/ |
66
|
1 |
|
public function delete(ShippingMethod $shippingMethod) |
67
|
|
|
{ |
68
|
1 |
|
return ShippingMethodDeleteRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param ShippingMethod $shippingMethod |
73
|
|
|
* @return ShippingMethodDeleteByKeyRequest |
74
|
|
|
*/ |
75
|
1 |
|
public function deleteByKey(ShippingMethod $shippingMethod) |
76
|
|
|
{ |
77
|
1 |
|
return ShippingMethodDeleteByKeyRequest::ofKeyAndVersion( |
78
|
1 |
|
$shippingMethod->getKey(), |
79
|
1 |
|
$shippingMethod->getVersion() |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $id |
85
|
|
|
* @return ShippingMethodByIdGetRequest |
86
|
|
|
*/ |
87
|
1 |
|
public function getById($id) |
88
|
|
|
{ |
89
|
1 |
|
return ShippingMethodByIdGetRequest::ofId($id); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $key |
94
|
|
|
* @return ShippingMethodByKeyGetRequest |
95
|
|
|
*/ |
96
|
1 |
|
public function getByKey($key) |
97
|
|
|
{ |
98
|
1 |
|
return ShippingMethodByKeyGetRequest::ofKey($key); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $cartId |
103
|
|
|
* @return ShippingMethodByCartIdGetRequest |
104
|
|
|
*/ |
105
|
|
|
public function getByCartId($cartId) |
106
|
|
|
{ |
107
|
|
|
return ShippingMethodByCartIdGetRequest::ofCartId($cartId); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param Location $location |
112
|
|
|
* @param string $currency |
113
|
|
|
* @return ShippingMethodByLocationGetRequest |
114
|
|
|
*/ |
115
|
|
|
public function getByLocation(Location $location, $currency = null) |
116
|
|
|
{ |
117
|
|
|
$request = ShippingMethodByLocationGetRequest::ofCountry($location->getCountry()); |
118
|
|
|
if (!is_null($location->getState())) { |
|
|
|
|
119
|
|
|
$request->withState($location->getState()); |
120
|
|
|
} |
121
|
|
|
if (!is_null($currency)) { |
122
|
|
|
$request->withCurrency($currency); |
123
|
|
|
} |
124
|
|
|
return $request; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|