|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* NOTICE OF LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
|
9
|
|
|
* It is also available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
|
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace eBayEnterprise\RetailOrderManagement\Payload\Order; |
|
17
|
|
|
|
|
18
|
|
|
use DOMXPath; |
|
19
|
|
|
|
|
20
|
|
|
trait TGifting |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $giftItemId; |
|
24
|
|
|
/** @var IPriceGroup */ |
|
25
|
|
|
protected $giftPricing; |
|
26
|
|
|
/** @var bool */ |
|
27
|
|
|
protected $includeGiftWrapping; |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $giftMessageTo; |
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
protected $giftMessageFrom; |
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
protected $giftMessageContent; |
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
protected $giftCardTo; |
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
protected $giftCardFrom; |
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
protected $giftCardMessage; |
|
40
|
|
|
/** @var string */ |
|
41
|
|
|
protected $packslipTo; |
|
42
|
|
|
/** @var string */ |
|
43
|
|
|
protected $packslipFrom; |
|
44
|
|
|
/** @var string */ |
|
45
|
|
|
protected $packslipMessage; |
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
protected $localizedFromLabel; |
|
48
|
|
|
/** @var string */ |
|
49
|
|
|
protected $localizedToLabel; |
|
50
|
|
|
|
|
51
|
|
|
public function getEmptyGiftingPriceGroup() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->buildPayloadForInterface(self::GIFTING_PRICE_GROUP_INTERFACE); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getGiftItemId() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->giftItemId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setGiftItemId($giftItemId) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->giftItemId = $this->cleanString($giftItemId, 20); |
|
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getGiftPricing() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->giftPricing; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function setGiftPricing(IPriceGroup $giftPricing) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->giftPricing = $giftPricing; |
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getIncludeGiftWrapping() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->includeGiftWrapping; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function setIncludeGiftWrapping($includeGiftWrapping) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->includeGiftWrapping = (bool) $includeGiftWrapping; |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getGiftMessageTo() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->giftMessageTo; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function setGiftMessageTo($giftMessageTo) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->giftMessageTo = $giftMessageTo; |
|
97
|
|
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getGiftMessageFrom() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->giftMessageFrom; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function setGiftMessageFrom($giftMessageFrom) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->giftMessageFrom = $giftMessageFrom; |
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getGiftMessageContent() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->giftMessageContent; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function setGiftMessageContent($giftMessageContent) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->giftMessageContent = $this->normalizeWhitespace($giftMessageContent); |
|
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getGiftCardTo() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->giftCardTo; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function setGiftCardTo($giftCardTo) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->giftCardTo = $giftCardTo; |
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getGiftCardFrom() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->giftCardFrom; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function setGiftCardFrom($giftCardFrom) |
|
139
|
|
|
{ |
|
140
|
|
|
$this->giftCardFrom = $giftCardFrom; |
|
141
|
|
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function getGiftCardMessage() |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->giftCardMessage; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function setGiftCardMessage($giftCardMessage) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->giftCardMessage = $this->normalizeWhitespace($giftCardMessage); |
|
|
|
|
|
|
152
|
|
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function getPackslipTo() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->packslipTo; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function setPackslipTo($packslipTo) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->packslipTo = $packslipTo; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function getPackslipFrom() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->packslipFrom; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function setPackslipFrom($packslipFrom) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->packslipFrom = $packslipFrom; |
|
174
|
|
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function getPackslipMessage() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->packslipMessage; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function setPackslipMessage($packslipMessage) |
|
183
|
|
|
{ |
|
184
|
|
|
$this->packslipMessage = $this->normalizeWhitespace($packslipMessage); |
|
|
|
|
|
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function getLocalizedFromLabel() |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->localizedFromLabel; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function setLocalizedFromLabel($localizedFromLabel) |
|
194
|
|
|
{ |
|
195
|
|
|
$this->localizedFromLabel = $localizedFromLabel; |
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function getLocalizedToLabel() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->localizedToLabel; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function setLocalizedToLabel($localizedToLabel) |
|
205
|
|
|
{ |
|
206
|
|
|
$this->localizedToLabel = $localizedToLabel; |
|
207
|
|
|
return $this; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Serialize gifting data. |
|
212
|
|
|
* |
|
213
|
|
|
* @return string |
|
214
|
|
|
*/ |
|
215
|
|
|
protected function serializeGifting() |
|
216
|
|
|
{ |
|
217
|
|
|
$serializedData = $this->serializeGift() |
|
218
|
|
|
. $this->serializeGiftingGiftCard() |
|
219
|
|
|
. $this->serializeGiftingPackslip(); |
|
220
|
|
|
return $serializedData ? "<Gifting>$serializedData</Gifting>" : ''; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Serialize the "Gift" gifting data. Will only be included if there is |
|
225
|
|
|
* a gift item id set. |
|
226
|
|
|
* |
|
227
|
|
|
* @return string |
|
228
|
|
|
*/ |
|
229
|
|
|
protected function serializeGift() |
|
230
|
|
|
{ |
|
231
|
|
|
if ($this->getGiftItemId()) { |
|
232
|
|
|
$pricing = $this->getGiftPricing(); |
|
233
|
|
|
return '<Gift>' |
|
234
|
|
|
. "<ItemId>{$this->xmlEncode($this->getGiftItemId())}</ItemId>" |
|
235
|
|
|
. ($pricing ? $pricing->setRootNodeName('Pricing')->serialize() : '') |
|
236
|
|
|
. $this->serializeGiftingGiftMessage() |
|
237
|
|
|
. '</Gift>'; |
|
238
|
|
|
} |
|
239
|
|
|
return ''; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Serialize the gift message data. Will only be included if there |
|
244
|
|
|
* are valid to and from fields. |
|
245
|
|
|
* |
|
246
|
|
|
* @return string |
|
247
|
|
|
*/ |
|
248
|
|
|
protected function serializeGiftingGiftMessage() |
|
249
|
|
|
{ |
|
250
|
|
|
$messageSerialization = $this->serializeGiftingMessage( |
|
251
|
|
|
$this->getGiftMessageTo(), |
|
252
|
|
|
$this->getGiftMessageFrom(), |
|
253
|
|
|
$this->getGiftMessageContent() |
|
254
|
|
|
); |
|
255
|
|
|
return $messageSerialization ? $messageSerialization : ''; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* Serialize the gift card message data. Will only be included if there |
|
260
|
|
|
* are valid to and from fields. |
|
261
|
|
|
* |
|
262
|
|
|
* @return string |
|
263
|
|
|
*/ |
|
264
|
|
|
protected function serializeGiftingGiftCard() |
|
265
|
|
|
{ |
|
266
|
|
|
$messageSerialization = $this->serializeGiftingMessage( |
|
267
|
|
|
$this->getGiftCardTo(), |
|
268
|
|
|
$this->getGiftCardFrom(), |
|
269
|
|
|
$this->getGiftCardMessage() |
|
270
|
|
|
); |
|
271
|
|
|
// If the gifting includes gift wrapping, the gift card node |
|
272
|
|
|
// must always be included. |
|
273
|
|
|
return ($messageSerialization || $this->getIncludeGiftWrapping()) |
|
274
|
|
|
? "<GiftCard>$messageSerialization</GiftCard>" |
|
275
|
|
|
: ''; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Serialize the packslip message data. Will only be included if there |
|
280
|
|
|
* are valid to and from fields. |
|
281
|
|
|
* |
|
282
|
|
|
* @return string |
|
283
|
|
|
*/ |
|
284
|
|
|
protected function serializeGiftingPackslip() |
|
285
|
|
|
{ |
|
286
|
|
|
$messageSerialization = $this->serializeGiftingMessage( |
|
287
|
|
|
$this->getPackslipTo(), |
|
288
|
|
|
$this->getPackslipFrom(), |
|
289
|
|
|
$this->getPackslipMessage() |
|
290
|
|
|
); |
|
291
|
|
|
return $messageSerialization ? "<Packslip>$messageSerialization</Packslip>" : ''; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Serialize a gifting message from, to and message. Will only return a |
|
296
|
|
|
* serialization if at least a from and to name are given. |
|
297
|
|
|
* |
|
298
|
|
|
* @param string |
|
299
|
|
|
* @param string |
|
300
|
|
|
* @param string |
|
301
|
|
|
* @return string |
|
302
|
|
|
*/ |
|
303
|
|
|
protected function serializeGiftingMessage($toName, $fromName, $messageText) |
|
304
|
|
|
{ |
|
305
|
|
|
$localizedTo = $this->serializeOptionalAttribute( |
|
|
|
|
|
|
306
|
|
|
'localizedDisplayText', |
|
307
|
|
|
$this->xmlEncode($this->getLocalizedToLabel()) |
|
308
|
|
|
); |
|
309
|
|
|
$localizedFrom = $this->serializeOptionalAttribute( |
|
|
|
|
|
|
310
|
|
|
'localizedDisplayText', |
|
311
|
|
|
$this->xmlEncode($this->getLocalizedFromLabel()) |
|
312
|
|
|
); |
|
313
|
|
|
return $toName && $fromName |
|
314
|
|
|
? '<Message>' |
|
315
|
|
|
. "<To $localizedTo>{$this->xmlEncode($toName)}</To>" |
|
316
|
|
|
. "<From $localizedFrom>{$this->xmlEncode($fromName)}</From>" |
|
317
|
|
|
. $this->serializeOptionalXmlEncodedValue('Message', $messageText) |
|
318
|
|
|
. '</Message>' |
|
319
|
|
|
: ''; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Extract gifting pricing from the payload in the DOMXPath and, if it is |
|
324
|
|
|
* included in the serialized data, deserialize it into a new price group. |
|
325
|
|
|
* |
|
326
|
|
|
* @return self |
|
327
|
|
|
*/ |
|
328
|
|
View Code Duplication |
protected function deserializeGiftPricing(DOMXPath $xpath) |
|
|
|
|
|
|
329
|
|
|
{ |
|
330
|
|
|
$priceNode = $xpath->query('x:Gifting/x:Gift/x:Pricing')->item(0); |
|
331
|
|
|
if ($priceNode) { |
|
332
|
|
|
$this->setGiftPricing( |
|
333
|
|
|
$this->getEmptyGiftingPriceGroup()->deserialize($priceNode->C14N()) |
|
334
|
|
|
); |
|
335
|
|
|
} |
|
336
|
|
|
return $this; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* Serialize an optional element containing a string. The value will be |
|
341
|
|
|
* xml-encoded if is not null. |
|
342
|
|
|
* |
|
343
|
|
|
* @param string |
|
344
|
|
|
* @param string |
|
345
|
|
|
* @return string |
|
346
|
|
|
*/ |
|
347
|
|
|
abstract protected function serializeOptionalXmlEncodedValue($name, $value); |
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* encode the passed in string to be safe for xml if it is not null, |
|
351
|
|
|
* otherwise simply return the null parameter. |
|
352
|
|
|
* |
|
353
|
|
|
* @param string|null |
|
354
|
|
|
* @return string|null |
|
355
|
|
|
*/ |
|
356
|
|
|
abstract protected function xmlEncode($value = null); |
|
357
|
|
|
} |
|
358
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.