1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the Thelia package. */ |
4
|
|
|
/* */ |
5
|
|
|
/* Copyright (c) OpenStudio */ |
6
|
|
|
/* email : [email protected] */ |
7
|
|
|
/* web : http://www.thelia.net */ |
8
|
|
|
/* */ |
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
10
|
|
|
/* file that was distributed with this source code. */ |
11
|
|
|
/*************************************************************************************/ |
12
|
|
|
|
13
|
|
|
namespace Thelia\Core\Event\Delivery; |
14
|
|
|
|
15
|
|
|
use Thelia\Core\Event\ActionEvent; |
16
|
|
|
use Thelia\Model\Address; |
17
|
|
|
use Thelia\Model\Country; |
18
|
|
|
use Thelia\Model\PickupLocation; |
19
|
|
|
use Thelia\Model\State; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class PickupLocationEvent |
23
|
|
|
* @package Thelia\Core\Event\Delivery |
24
|
|
|
* @author Damien Foulhoux <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class PickupLocationEvent extends ActionEvent |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var string|null |
30
|
|
|
*/ |
31
|
|
|
protected $address; |
32
|
|
|
/** |
33
|
|
|
* @var string|null |
34
|
|
|
*/ |
35
|
|
|
protected $city; |
36
|
|
|
/** |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
protected $zipCode; |
40
|
|
|
/** |
41
|
|
|
* @var State|null |
42
|
|
|
*/ |
43
|
|
|
protected $state; |
44
|
|
|
/** |
45
|
|
|
* @var Country|null |
46
|
|
|
*/ |
47
|
|
|
protected $country; |
48
|
|
|
/** |
49
|
|
|
* @var integer|null |
50
|
|
|
*/ |
51
|
|
|
protected $radius; |
52
|
|
|
/** |
53
|
|
|
* @var integer|null |
54
|
|
|
*/ |
55
|
|
|
protected $maxRelays; |
56
|
|
|
/** |
57
|
|
|
* @var integer|null |
58
|
|
|
*/ |
59
|
|
|
protected $orderWeight; |
60
|
|
|
/** |
61
|
|
|
* @var array|null |
62
|
|
|
*/ |
63
|
|
|
protected $moduleIds; |
64
|
|
|
/** |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
protected $locations = []; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* PickupLocationEvent constructor. |
71
|
|
|
* |
72
|
|
|
* @param Address|null $addressModel |
73
|
|
|
* @param integer|null $radius |
74
|
|
|
* @param integer|null $maxRelays |
75
|
|
|
* @param string|null $address |
76
|
|
|
* @param string|null $city |
77
|
|
|
* @param string|null $zipCode |
78
|
|
|
* @param integer|null $orderWeight |
79
|
|
|
* @param State|null $state |
80
|
|
|
* @param Country|null $country |
81
|
|
|
* @param array|null $moduleIds |
82
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
83
|
|
|
*/ |
84
|
|
|
public function __construct( |
85
|
|
|
Address $addressModel = null, |
86
|
|
|
$radius = null, |
87
|
|
|
$maxRelays = null, |
88
|
|
|
$address = null, |
89
|
|
|
$city = null, |
90
|
|
|
$zipCode = null, |
91
|
|
|
$orderWeight = null, |
92
|
|
|
State $state = null, |
93
|
|
|
Country $country = null, |
94
|
|
|
array $moduleIds = null |
95
|
|
|
) { |
96
|
|
|
$this->radius = $radius !== null ? $radius : 20000; |
97
|
|
|
$this->maxRelays = $maxRelays !== null ? $maxRelays : 15; |
98
|
|
|
$this->orderWeight = $orderWeight; |
99
|
|
|
$this->address = $address; |
100
|
|
|
$this->city = $city; |
101
|
|
|
$this->zipCode = $zipCode; |
102
|
|
|
$this->state = $state; |
103
|
|
|
$this->country = $country; |
104
|
|
|
$this->moduleIds = $moduleIds; |
105
|
|
|
|
106
|
|
|
if (null !== $addressModel) { |
107
|
|
|
$this->address = $addressModel->getAddress1(); |
108
|
|
|
$this->city = $addressModel->getCity(); |
109
|
|
|
$this->zipCode = $addressModel->getZipcode(); |
110
|
|
|
$this->state = $addressModel->getState(); |
111
|
|
|
$this->country = $addressModel->getCountry(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($this->address === null && $this->city === null && $this->zipCode === null) { |
115
|
|
|
throw new \Exception("Not enough informations to retrieve pickup locations"); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return string|null |
121
|
|
|
*/ |
122
|
|
|
public function getAddress() |
123
|
|
|
{ |
124
|
|
|
return $this->address; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string|null $address |
129
|
|
|
*/ |
130
|
|
|
public function setAddress($address) |
131
|
|
|
{ |
132
|
|
|
$this->address = $address; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return string|null |
137
|
|
|
*/ |
138
|
|
|
public function getCity() |
139
|
|
|
{ |
140
|
|
|
return $this->city; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param string|null $city |
145
|
|
|
*/ |
146
|
|
|
public function setCity($city) |
147
|
|
|
{ |
148
|
|
|
$this->city = $city; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return string|null |
153
|
|
|
*/ |
154
|
|
|
public function getZipCode() |
155
|
|
|
{ |
156
|
|
|
return $this->zipCode; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string|null $zipCode |
161
|
|
|
*/ |
162
|
|
|
public function setZipCode($zipCode) |
163
|
|
|
{ |
164
|
|
|
$this->zipCode = $zipCode; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return State|null |
169
|
|
|
*/ |
170
|
|
|
public function getState() |
171
|
|
|
{ |
172
|
|
|
return $this->state; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param State|null $state |
177
|
|
|
*/ |
178
|
|
|
public function setState($state) |
179
|
|
|
{ |
180
|
|
|
$this->state = $state; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return Country|null |
185
|
|
|
*/ |
186
|
|
|
public function getCountry() |
187
|
|
|
{ |
188
|
|
|
return $this->country; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param Country|null $country |
193
|
|
|
*/ |
194
|
|
|
public function setCountry($country) |
195
|
|
|
{ |
196
|
|
|
$this->country = $country; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return int|null |
201
|
|
|
*/ |
202
|
|
|
public function getRadius() |
203
|
|
|
{ |
204
|
|
|
return $this->radius; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param int|null $radius |
209
|
|
|
*/ |
210
|
|
|
public function setRadius($radius) |
211
|
|
|
{ |
212
|
|
|
$this->radius = $radius; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return array|null |
217
|
|
|
*/ |
218
|
|
|
public function getModuleIds() |
219
|
|
|
{ |
220
|
|
|
return $this->moduleIds; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param array|null $moduleIds |
225
|
|
|
*/ |
226
|
|
|
public function setModuleIds($moduleIds) |
227
|
|
|
{ |
228
|
|
|
$this->moduleIds = $moduleIds; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** @return array */ |
232
|
|
|
public function getLocations() |
233
|
|
|
{ |
234
|
|
|
return $this->locations; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param $locations PickupLocation[] |
239
|
|
|
* @return PickupLocationEvent |
240
|
|
|
*/ |
241
|
|
|
public function setLocations($locations) |
242
|
|
|
{ |
243
|
|
|
$this->locations = $locations; |
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** @param $location PickupLocation |
248
|
|
|
* @return PickupLocationEvent |
249
|
|
|
*/ |
250
|
|
|
public function appendLocation($location) |
251
|
|
|
{ |
252
|
|
|
$this->locations[] = $location; |
253
|
|
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @return integer|null |
258
|
|
|
*/ |
259
|
|
|
public function getOrderWeight() |
260
|
|
|
{ |
261
|
|
|
return $this->orderWeight; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @param integer|null $orderWeight |
266
|
|
|
* @return PickupLocationEvent |
267
|
|
|
*/ |
268
|
|
|
public function setOrderWeight($orderWeight) |
269
|
|
|
{ |
270
|
|
|
$this->orderWeight = $orderWeight; |
271
|
|
|
|
272
|
|
|
return $this; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @return int|null |
277
|
|
|
*/ |
278
|
|
|
public function getMaxRelays() |
279
|
|
|
{ |
280
|
|
|
return $this->maxRelays; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @param int|null $maxRelays |
285
|
|
|
* @return PickupLocationEvent |
286
|
|
|
*/ |
287
|
|
|
public function setMaxRelays($maxRelays) |
288
|
|
|
{ |
289
|
|
|
$this->maxRelays = $maxRelays; |
290
|
|
|
|
291
|
|
|
return $this; |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
|