1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Meanbee\MagentoRoyalmail\Model; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Method |
7
|
|
|
*/ |
8
|
|
|
class Method |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The ID of the method rule. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $id; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The shipping code name of the method |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $code; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The clean shipping method name of the shipping method |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $name; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The country code of the method |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $countryCode; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Price of method |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $price; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Maximum value of package that is insured |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $insuranceValue; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The minimum weight the shipping method can accommodate |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $minimumWeight; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The maximum weight the shipping method can accommodate |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $maximumWeight; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The parcel size, only applies to small and medium parcels |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
protected $size; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Dictionary to replace strings within method codes. |
76
|
|
|
* Without shortening, method codes are too long and Magento rejects order. |
77
|
|
|
* |
78
|
|
|
* @var $methodDitionary |
79
|
|
|
*/ |
80
|
|
|
protected static $methodDictionary = array( |
81
|
|
|
'economy' => 'eco', |
82
|
|
|
'express' => 'xp', |
83
|
|
|
'firstclass' => '1st', |
84
|
|
|
'international' => 'i11l', |
85
|
|
|
'large' => 'lg', |
86
|
|
|
'letter' => 'ltr', |
87
|
|
|
'medium' => 'med', |
88
|
|
|
'parcelforce' => 'pf', |
89
|
|
|
'parcel' => 'prcl', |
90
|
|
|
'saturday' => 'sat', |
91
|
|
|
'standard' => 'std', |
92
|
|
|
'secondclass' => '2nd', |
93
|
|
|
'signedfor' => 'signed', |
94
|
|
|
'small' => 'sm', |
95
|
|
|
'specialdelivery' => 'special', |
96
|
|
|
'trackedandsigned' => 'tracksign', |
97
|
|
|
'trackedsigned' => 'tracksign', |
98
|
|
|
'worldwide' => 'ww', |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Method constructor. |
103
|
|
|
* |
104
|
|
|
* @param string $id - Method unique identifier |
105
|
|
|
* @param string $code - Method code |
106
|
|
|
* @param string $name - Method label |
107
|
|
|
* @param string $countryCode - Country code of method |
108
|
|
|
* @param string $price - Price of method |
109
|
|
|
* @param string $insuranceValue - Insurance value of method |
110
|
|
|
* @param string $minimumWeight - Minimum weight the method can have |
111
|
|
|
* @param string $maximumWeight - Maximum weight the method can have |
112
|
|
|
* @param null $size - Parcel size, only applies to sm and md parcels |
113
|
|
|
*/ |
114
|
|
|
public function __construct( |
115
|
|
|
$id, |
116
|
|
|
$code, |
117
|
|
|
$name, |
118
|
|
|
$countryCode = null, |
119
|
|
|
$price = null, |
120
|
|
|
$insuranceValue = null, |
121
|
|
|
$minimumWeight = null, |
122
|
|
|
$maximumWeight = null, |
123
|
|
|
$size = null |
124
|
|
|
) { |
125
|
|
|
$this->id = $id; |
126
|
|
|
$this->code = str_replace( |
127
|
|
|
array_keys(self::$methodDictionary), |
128
|
|
|
array_values(self::$methodDictionary), |
129
|
|
|
$code |
130
|
|
|
); |
131
|
|
|
$this->name = $name; |
132
|
|
|
$this->countryCode = $countryCode; |
133
|
|
|
$this->price = $price; |
134
|
|
|
$this->insuranceValue = $insuranceValue; |
135
|
|
|
$this->minimumWeight = $minimumWeight; |
136
|
|
|
$this->maximumWeight = $maximumWeight; |
137
|
|
|
$this->size = $size; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* The unique ID of a method |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getId() |
146
|
|
|
{ |
147
|
|
|
return $this->id; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* The method code |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function getCode() |
156
|
|
|
{ |
157
|
|
|
return $this->code; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* The clean shipping method name of the shipping method |
162
|
|
|
* |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
public function getName() |
166
|
|
|
{ |
167
|
|
|
return $this->name; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* The country code of the method |
172
|
|
|
* |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function getCountryCode() |
176
|
|
|
{ |
177
|
|
|
return $this->countryCode; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Price of method |
182
|
|
|
* |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
public function getPrice() |
186
|
|
|
{ |
187
|
|
|
return $this->price; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Maximum value of package that is insured |
192
|
|
|
* |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function getInsuranceValue() |
196
|
|
|
{ |
197
|
|
|
return $this->insuranceValue; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* The minimum weight the shipping method can accommodate |
202
|
|
|
* |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function getMinimumWeight() |
206
|
|
|
{ |
207
|
|
|
return $this->minimumWeight; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* The maximum weight the shipping method can accommodate |
212
|
|
|
* |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function getMaximumWeight() |
216
|
|
|
{ |
217
|
|
|
return $this->maximumWeight; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* The parcel size, only applies to small and medium parcels |
222
|
|
|
* |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
|
|
public function getSize() |
226
|
|
|
{ |
227
|
|
|
return $this->size; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
} |
231
|
|
|
|