|
1
|
|
|
<?php |
|
2
|
|
|
// phpcs:disable Generic.Files.LineLength |
|
3
|
|
|
namespace Commercetools\Core\Builder\Request; |
|
4
|
|
|
|
|
5
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByCartIdGetRequest; |
|
6
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByIdGetRequest; |
|
7
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByKeyGetRequest; |
|
8
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByLocationGetRequest; |
|
9
|
|
|
use Commercetools\Core\Model\Zone\Location; |
|
10
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByMatchingLocationGetRequest; |
|
11
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByMatchingOrderEditGetRequest; |
|
12
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodCreateRequest; |
|
13
|
|
|
use Commercetools\Core\Model\ShippingMethod\ShippingMethodDraft; |
|
14
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteByKeyRequest; |
|
15
|
|
|
use Commercetools\Core\Model\ShippingMethod\ShippingMethod; |
|
16
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteRequest; |
|
17
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodQueryRequest; |
|
18
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateByKeyRequest; |
|
19
|
|
|
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateRequest; |
|
20
|
|
|
|
|
21
|
|
|
class ShippingMethodRequestBuilder |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethods-for-a-cart |
|
26
|
|
|
* @param string $cartId |
|
27
|
|
|
* @return ShippingMethodByCartIdGetRequest |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getByCartId($cartId) |
|
30
|
|
|
{ |
|
31
|
|
|
$request = ShippingMethodByCartIdGetRequest::ofCartId($cartId); |
|
32
|
|
|
return $request; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethod-by-id |
|
37
|
|
|
* @param string $id |
|
38
|
|
|
* @return ShippingMethodByIdGetRequest |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function getById($id) |
|
41
|
|
|
{ |
|
42
|
2 |
|
$request = ShippingMethodByIdGetRequest::ofId($id); |
|
43
|
2 |
|
return $request; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethod-by-key |
|
48
|
|
|
* @param string $key |
|
49
|
|
|
* @return ShippingMethodByKeyGetRequest |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function getByKey($key) |
|
52
|
|
|
{ |
|
53
|
1 |
|
$request = ShippingMethodByKeyGetRequest::ofKey($key); |
|
54
|
1 |
|
return $request; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethods-for-a-location |
|
59
|
|
|
* @param Location $location |
|
60
|
|
|
* @param string $currency |
|
61
|
|
|
* @return ShippingMethodByLocationGetRequest |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function getByLocation(Location $location, $currency = null) |
|
64
|
|
|
{ |
|
65
|
1 |
|
$request = ShippingMethodByLocationGetRequest::ofCountry($location->getCountry()); |
|
66
|
1 |
|
if (!is_null($location->getState())) { |
|
|
|
|
|
|
67
|
1 |
|
$request->withState($location->getState()); |
|
68
|
|
|
} |
|
69
|
1 |
|
if (!is_null($currency)) { |
|
70
|
|
|
$request->withCurrency($currency); |
|
71
|
|
|
} |
|
72
|
1 |
|
return $request; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethods-for-a-location |
|
77
|
|
|
* @param Location $location |
|
78
|
|
|
* @param string $currency |
|
79
|
|
|
* @return ShippingMethodByMatchingLocationGetRequest |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function getMatchingLocation(Location $location, $currency = null) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$request = ShippingMethodByMatchingLocationGetRequest::ofCountry($location->getCountry()); |
|
84
|
1 |
|
if (!is_null($location->getState())) { |
|
|
|
|
|
|
85
|
1 |
|
$request->withState($location->getState()); |
|
86
|
|
|
} |
|
87
|
1 |
|
if (!is_null($currency)) { |
|
88
|
|
|
$request->withCurrency($currency); |
|
89
|
|
|
} |
|
90
|
1 |
|
return $request; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethods-for-an-orderedit |
|
95
|
|
|
* @param string $orderEditId |
|
96
|
|
|
* @param Location $location |
|
97
|
|
|
* @return ShippingMethodByMatchingOrderEditGetRequest |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function getMatchingOrderEdit($orderEditId, Location $location) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$request = ShippingMethodByMatchingOrderEditGetRequest::ofOrderEditAndCountry($orderEditId, $location->getCountry()); |
|
102
|
1 |
|
if (!is_null($location->getState())) { |
|
|
|
|
|
|
103
|
1 |
|
$request->withState($location->getState()); |
|
104
|
|
|
} |
|
105
|
1 |
|
return $request; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#create-shippingmethod |
|
110
|
|
|
* @param ShippingMethodDraft $shippingMethod |
|
111
|
|
|
* @return ShippingMethodCreateRequest |
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function create(ShippingMethodDraft $shippingMethod) |
|
114
|
|
|
{ |
|
115
|
1 |
|
$request = ShippingMethodCreateRequest::ofDraft($shippingMethod); |
|
116
|
1 |
|
return $request; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#delete-shippingmethod-by-key |
|
121
|
|
|
* @param ShippingMethod $shippingMethod |
|
122
|
|
|
* @return ShippingMethodDeleteByKeyRequest |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function deleteByKey(ShippingMethod $shippingMethod) |
|
125
|
|
|
{ |
|
126
|
1 |
|
$request = ShippingMethodDeleteByKeyRequest::ofKeyAndVersion($shippingMethod->getKey(), $shippingMethod->getVersion()); |
|
127
|
1 |
|
return $request; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#delete-shippingmethod |
|
132
|
|
|
* @param ShippingMethod $shippingMethod |
|
133
|
|
|
* @return ShippingMethodDeleteRequest |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function delete(ShippingMethod $shippingMethod) |
|
136
|
|
|
{ |
|
137
|
1 |
|
$request = ShippingMethodDeleteRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion()); |
|
138
|
1 |
|
return $request; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#query-shippingmethods |
|
143
|
|
|
* |
|
144
|
|
|
* @return ShippingMethodQueryRequest |
|
145
|
|
|
*/ |
|
146
|
2 |
|
public function query() |
|
147
|
|
|
{ |
|
148
|
2 |
|
$request = ShippingMethodQueryRequest::of(); |
|
149
|
2 |
|
return $request; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#update-shippingmethod-by-key |
|
154
|
|
|
* @param ShippingMethod $shippingMethod |
|
155
|
|
|
* @return ShippingMethodUpdateByKeyRequest |
|
156
|
|
|
*/ |
|
157
|
3 |
|
public function updateByKey(ShippingMethod $shippingMethod) |
|
158
|
|
|
{ |
|
159
|
3 |
|
$request = ShippingMethodUpdateByKeyRequest::ofKeyAndVersion($shippingMethod->getKey(), $shippingMethod->getVersion()); |
|
160
|
3 |
|
return $request; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#update-shippingmethod |
|
165
|
|
|
* @param ShippingMethod $shippingMethod |
|
166
|
|
|
* @return ShippingMethodUpdateRequest |
|
167
|
|
|
*/ |
|
168
|
13 |
|
public function update(ShippingMethod $shippingMethod) |
|
169
|
|
|
{ |
|
170
|
13 |
|
$request = ShippingMethodUpdateRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion()); |
|
171
|
13 |
|
return $request; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return ShippingMethodRequestBuilder |
|
176
|
|
|
*/ |
|
177
|
|
|
public function of() |
|
178
|
|
|
{ |
|
179
|
|
|
return new self(); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|