1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Component\Shipping\Model; |
13
|
|
|
|
14
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
15
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
16
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
17
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
21
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ShippingMethod implements ShippingMethodInterface |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
use TimestampableTrait, ToggleableTrait; |
26
|
|
|
use TranslatableTrait { |
27
|
|
|
__construct as private initializeTranslationsCollection; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var mixed |
32
|
|
|
*/ |
33
|
|
|
protected $id; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $code; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
protected $position; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ShippingCategoryInterface |
47
|
|
|
*/ |
48
|
|
|
protected $category; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $categoryRequirement = ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ANY; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $calculator; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected $configuration = []; |
64
|
|
|
|
65
|
|
|
public function __construct() |
66
|
|
|
{ |
67
|
|
|
$this->initializeTranslationsCollection(); |
68
|
|
|
|
69
|
|
|
$this->createdAt = new \DateTime(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function __toString() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
return $this->getTranslation()->__toString(); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function getId() |
84
|
|
|
{ |
85
|
|
|
return $this->id; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function getCode() |
92
|
|
|
{ |
93
|
|
|
return $this->code; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
|
public function setCode($code) |
100
|
|
|
{ |
101
|
|
|
$this->code = $code; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function getPosition() |
108
|
|
|
{ |
109
|
|
|
return $this->position; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function setPosition($position) |
116
|
|
|
{ |
117
|
|
|
$this->position = $position; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function getCategory() |
124
|
|
|
{ |
125
|
|
|
return $this->category; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
public function setCategory(ShippingCategoryInterface $category = null) |
132
|
|
|
{ |
133
|
|
|
$this->category = $category; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
public function getCategoryRequirement() |
140
|
|
|
{ |
141
|
|
|
return $this->categoryRequirement; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* {@inheritdoc} |
146
|
|
|
*/ |
147
|
|
|
public function setCategoryRequirement($categoryRequirement) |
148
|
|
|
{ |
149
|
|
|
$this->categoryRequirement = $categoryRequirement; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* {@inheritdoc} |
154
|
|
|
*/ |
155
|
|
|
public function getCategoryRequirementLabel() |
156
|
|
|
{ |
157
|
|
|
return self::getCategoryRequirementLabels()[$this->categoryRequirement]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritdoc} |
162
|
|
|
*/ |
163
|
|
|
public function getName() |
164
|
|
|
{ |
165
|
|
|
return $this->getTranslation()->getName(); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* {@inheritdoc} |
170
|
|
|
*/ |
171
|
|
|
public function setName($name) |
172
|
|
|
{ |
173
|
|
|
$this->getTranslation()->setName($name); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
|
|
public function getDescription() |
180
|
|
|
{ |
181
|
|
|
return $this->getTranslation()->getDescription(); |
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* {@inheritdoc} |
186
|
|
|
*/ |
187
|
|
|
public function setDescription($description) |
188
|
|
|
{ |
189
|
|
|
$this->getTranslation()->setDescription($description); |
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* {@inheritdoc} |
194
|
|
|
*/ |
195
|
|
|
public function getCalculator() |
196
|
|
|
{ |
197
|
|
|
return $this->calculator; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* {@inheritdoc} |
202
|
|
|
*/ |
203
|
|
|
public function setCalculator($calculator) |
204
|
|
|
{ |
205
|
|
|
$this->calculator = $calculator; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* {@inheritdoc} |
210
|
|
|
*/ |
211
|
|
|
public function getConfiguration() |
212
|
|
|
{ |
213
|
|
|
return $this->configuration; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* {@inheritdoc} |
218
|
|
|
*/ |
219
|
|
|
public function setConfiguration(array $configuration) |
220
|
|
|
{ |
221
|
|
|
$this->configuration = $configuration; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return array |
|
|
|
|
226
|
|
|
*/ |
227
|
|
|
public static function getCategoryRequirementLabels() |
228
|
|
|
{ |
229
|
|
|
return [ |
230
|
|
|
ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_NONE => 'None of the units have to match the method category', |
231
|
|
|
ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ANY => 'At least 1 unit has to match the method category', |
232
|
|
|
ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ALL => 'All units has to match the method category', |
233
|
|
|
]; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* {@inheritdoc} |
238
|
|
|
*/ |
239
|
|
|
protected function createTranslation() |
240
|
|
|
{ |
241
|
|
|
return new ShippingMethodTranslation(); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
} |
245
|
|
|
|