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
|
|
|
|
14
|
|
|
namespace Thelia\Core\Event\Delivery; |
15
|
|
|
|
16
|
|
|
use Thelia\Core\Event\ActionEvent; |
17
|
|
|
use Thelia\Core\Translation\Translator; |
18
|
|
|
use Thelia\Model\Address; |
19
|
|
|
use Thelia\Model\Cart; |
20
|
|
|
use Thelia\Model\Country; |
21
|
|
|
use Thelia\Model\OrderPostage; |
22
|
|
|
use Thelia\Model\State; |
23
|
|
|
use Thelia\Module\AbstractDeliveryModule; |
24
|
|
|
use Thelia\Module\DeliveryModuleInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class DeliveryPostageEvent |
28
|
|
|
* @package Thelia\Core\Event\Delivery |
29
|
|
|
* @author Julien Chanséaume <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class DeliveryPostageEvent extends ActionEvent |
32
|
|
|
{ |
33
|
|
|
/** @var AbstractDeliveryModule */ |
34
|
|
|
protected $module = null; |
35
|
|
|
|
36
|
|
|
/** @var Cart */ |
37
|
|
|
protected $cart = null; |
38
|
|
|
|
39
|
|
|
/** @var Address */ |
40
|
|
|
protected $address = null; |
41
|
|
|
|
42
|
|
|
/** @var Country */ |
43
|
|
|
protected $country = null; |
44
|
|
|
|
45
|
|
|
/** @var State */ |
46
|
|
|
protected $state = null; |
47
|
|
|
|
48
|
|
|
/** @var bool */ |
49
|
|
|
protected $validModule = false; |
50
|
|
|
|
51
|
|
|
/** @var OrderPostage|null */ |
52
|
|
|
protected $postage = null; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var \DateTime|null |
56
|
|
|
*/ |
57
|
|
|
protected $deliveryDate = null; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $deliveryMode = null; |
63
|
|
|
|
64
|
|
|
/** @var array */ |
65
|
|
|
protected $additionalData = []; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* DeliveryPostageEvent constructor. |
69
|
|
|
* @param DeliveryModuleInterface $module |
70
|
|
|
* @param Cart $cart |
71
|
|
|
* @param Address|null $address |
72
|
|
|
* @param Country $country |
73
|
|
|
* @param State $state |
74
|
|
|
*/ |
75
|
|
|
public function __construct( |
76
|
|
|
DeliveryModuleInterface $module, |
77
|
|
|
Cart $cart, |
78
|
|
|
Address $address = null, |
79
|
|
|
Country $country = null, |
80
|
|
|
State $state = null |
81
|
|
|
) { |
82
|
|
|
$this->module = $module; |
|
|
|
|
83
|
|
|
$this->cart = $cart; |
84
|
|
|
$this->address = $address; |
85
|
|
|
$this->country = $country; |
86
|
|
|
$this->state = $state; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return Cart |
91
|
|
|
*/ |
92
|
|
|
public function getCart() |
93
|
|
|
{ |
94
|
|
|
return $this->cart; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Cart $cart |
99
|
|
|
* @return DeliveryPostageEvent |
100
|
|
|
*/ |
101
|
|
|
public function setCart($cart) |
102
|
|
|
{ |
103
|
|
|
$this->cart = $cart; |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return Address |
109
|
|
|
*/ |
110
|
|
|
public function getAddress() |
111
|
|
|
{ |
112
|
|
|
return $this->address; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param Address $address |
117
|
|
|
* @return DeliveryPostageEvent |
118
|
|
|
*/ |
119
|
|
|
public function setAddress($address) |
120
|
|
|
{ |
121
|
|
|
$this->address = $address; |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return \DateTime|null |
127
|
|
|
*/ |
128
|
|
|
public function getDeliveryDate() |
129
|
|
|
{ |
130
|
|
|
return $this->deliveryDate; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param \DateTime|null $deliveryDate |
135
|
|
|
* @return DeliveryPostageEvent |
136
|
|
|
*/ |
137
|
|
|
public function setDeliveryDate($deliveryDate) |
138
|
|
|
{ |
139
|
|
|
$this->deliveryDate = $deliveryDate; |
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return AbstractDeliveryModule |
145
|
|
|
*/ |
146
|
|
|
public function getModule() |
147
|
|
|
{ |
148
|
|
|
return $this->module; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param AbstractDeliveryModule $module |
153
|
|
|
* @return DeliveryPostageEvent |
154
|
|
|
*/ |
155
|
|
|
public function setModule($module) |
156
|
|
|
{ |
157
|
|
|
$this->module = $module; |
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return null|OrderPostage |
163
|
|
|
*/ |
164
|
|
|
public function getPostage() |
165
|
|
|
{ |
166
|
|
|
return $this->postage; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param null|double|OrderPostage $postage |
171
|
|
|
* @return DeliveryPostageEvent |
172
|
|
|
*/ |
173
|
|
|
public function setPostage($postage) |
174
|
|
|
{ |
175
|
|
|
$this->postage = OrderPostage::loadFromPostage($postage); |
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return boolean |
181
|
|
|
*/ |
182
|
|
|
public function isValidModule() |
183
|
|
|
{ |
184
|
|
|
return $this->validModule; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param boolean $validModule |
189
|
|
|
* @return DeliveryPostageEvent |
190
|
|
|
*/ |
191
|
|
|
public function setValidModule($validModule) |
192
|
|
|
{ |
193
|
|
|
$this->validModule = $validModule; |
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return bool |
199
|
|
|
*/ |
200
|
|
|
public function hasAdditionalData() |
201
|
|
|
{ |
202
|
|
|
return \count($this->additionalData) > 0; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return array |
207
|
|
|
*/ |
208
|
|
|
public function getAdditionalData() |
209
|
|
|
{ |
210
|
|
|
return $this->additionalData; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param array $additionalData |
215
|
|
|
* @return DeliveryPostageEvent |
216
|
|
|
*/ |
217
|
|
|
public function setAdditionalData($additionalData) |
218
|
|
|
{ |
219
|
|
|
$this->additionalData = $additionalData; |
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param string $key the key of the additional data |
225
|
|
|
* @param mixed $value the value of the additional data |
226
|
|
|
* |
227
|
|
|
* @return DeliveryPostageEvent |
228
|
|
|
*/ |
229
|
|
|
public function addAdditionalData($key, $value) |
230
|
|
|
{ |
231
|
|
|
$this->additionalData[$key] = $value; |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @return Country|null |
238
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
239
|
|
|
*/ |
240
|
|
|
public function getCountry() |
241
|
|
|
{ |
242
|
|
|
return $this->getAddress() !== null ? $this->getAddress()->getCountry() : $this->country; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return State|null |
247
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
248
|
|
|
*/ |
249
|
|
|
public function getState() |
250
|
|
|
{ |
251
|
|
|
return $this->getAddress() !== null ? $this->getAddress()->getState() : $this->state; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @return mixed |
256
|
|
|
*/ |
257
|
|
|
public function getDeliveryMode() |
258
|
|
|
{ |
259
|
|
|
return $this->deliveryMode; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param mixed $deliveryMode |
264
|
|
|
* |
265
|
|
|
* @return DeliveryPostageEvent |
266
|
|
|
* @throws \Exception |
267
|
|
|
*/ |
268
|
|
|
public function setDeliveryMode($deliveryMode) |
269
|
|
|
{ |
270
|
|
|
if (!in_array($deliveryMode, ['pickup', 'delivery'])) { |
271
|
|
|
throw new \Exception(Translator::getInstance()->trans('A delivery module can only de of type pickup or delivery')); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
$this->deliveryMode = $deliveryMode; |
275
|
|
|
return $this; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.