|
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\OrderEvents; |
|
17
|
|
|
|
|
18
|
|
|
use DOMXPath; |
|
19
|
|
|
use DateTime; |
|
20
|
|
|
|
|
21
|
|
|
trait TShipGroup |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var IDestination */ |
|
24
|
|
|
protected $destination; |
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
protected $shipmentMethod; |
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
protected $shipmentMethodDisplayText; |
|
29
|
|
|
|
|
30
|
|
|
public function getShippingDestination() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->destination; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function setShippingDestination(IDestination $destination) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->destination = $destination; |
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getShipmentMethod() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->shipmentMethod; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setShipmentMethod($method) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->shipmentMethod = $method; |
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Text string to display for the shipment method |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getShipmentMethodDisplayText() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->shipmentMethodDisplayText; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string |
|
64
|
|
|
* @return self |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setShipmentMethodDisplayText($displayText) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->shipmentMethodDisplayText = $displayText; |
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get a payload instance mapped to the specified interface |
|
74
|
|
|
* @param string $interface |
|
75
|
|
|
* @return IPayload |
|
76
|
|
|
*/ |
|
77
|
|
|
abstract protected function buildPayloadForInterface($interface); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Deserialize data not mapped by the extraction paths |
|
81
|
|
|
* @return self |
|
82
|
|
|
*/ |
|
83
|
|
|
abstract protected function deserializeExtra($serializedPayload); |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Deserialize the destination |
|
87
|
|
|
* @param DOMXPath $xpath |
|
88
|
|
|
* @return self |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function deserializeShippingDestination(DOMXPath $xpath) |
|
91
|
|
|
{ |
|
92
|
|
|
$addressMap = [ |
|
93
|
|
|
'ShippedAddress' => static::MAILING_ADDRESS_INTERFACE, |
|
94
|
|
|
'StoreFrontAddress' => static::STORE_FRONT_DETAILS_INTERFACE, |
|
95
|
|
|
]; |
|
96
|
|
|
$destination = null; |
|
97
|
|
|
$destinationNode = null; |
|
98
|
|
|
foreach ($addressMap as $type => $interface) { |
|
99
|
|
|
$node = $xpath->query("x:$type"); |
|
100
|
|
|
if ($node->length) { |
|
101
|
|
|
$destinationNode = $node->item(0); |
|
102
|
|
|
$destination = $this->buildPayloadForInterface($interface); |
|
103
|
|
|
break; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
if ($destination && $destinationNode) { |
|
107
|
|
|
$destination->deserialize($destinationNode->C14N()); |
|
108
|
|
|
$this->setShippingDestination($destination); |
|
109
|
|
|
} |
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function serializeShipmentMethod() |
|
114
|
|
|
{ |
|
115
|
|
|
$serializedAttribute = $this->getShipmentMethodDisplayText() ? |
|
116
|
|
|
" displayText=\"{$this->getShipmentMethodDisplayText()}\"" : |
|
117
|
|
|
''; |
|
118
|
|
|
return sprintf( |
|
119
|
|
|
'<ShipmentMethod%s>%s</ShipmentMethod>', |
|
120
|
|
|
$serializedAttribute, |
|
121
|
|
|
$this->getShipmentMethod() |
|
122
|
|
|
); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|