|
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 DateTime; |
|
19
|
|
|
use DOMXPath; |
|
20
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayload; |
|
21
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap; |
|
22
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator; |
|
23
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator; |
|
24
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
|
25
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\Payment\TAmount; |
|
26
|
|
|
use Psr\Log\LoggerInterface; |
|
27
|
|
|
use Psr\Log\NullLogger; |
|
28
|
|
|
|
|
29
|
|
|
class AcceptedOrderItem extends OrderItem implements IAcceptedOrderItem |
|
30
|
|
|
{ |
|
31
|
|
|
use TProductPrice, TItemShipping, TAmount { |
|
32
|
|
|
TAmount::serializeAmount insteadof TProductPrice; |
|
33
|
|
|
TAmount::sanitizeAmount insteadof TProductPrice; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function __construct( |
|
37
|
|
|
IValidatorIterator $validators, |
|
38
|
|
|
ISchemaValidator $schemaValidator, |
|
39
|
|
|
IPayloadMap $payloadMap, |
|
40
|
|
|
LoggerInterface $logger, |
|
41
|
|
|
IPayload $parentPayload = null |
|
42
|
|
|
) { |
|
43
|
|
|
parent::__construct($validators, $schemaValidator, $payloadMap, $logger, $parentPayload); |
|
44
|
|
|
|
|
45
|
|
|
$this->logger = $logger; |
|
|
|
|
|
|
46
|
|
|
$this->payloadMap = $payloadMap; |
|
47
|
|
|
$this->payloadFactory = new PayloadFactory(); |
|
48
|
|
|
|
|
49
|
|
|
$this->extractionPaths = array_merge( |
|
50
|
|
|
$this->extractionPaths, |
|
51
|
|
|
[ |
|
52
|
|
|
'shipmentMethod' => 'string(x:Shipping/x:ShipmentMethod)', |
|
53
|
|
|
'shipmentMethodDisplayText' => 'string(x:Shipping/x:ShipmentMethod/@displayText)', |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
$this->optionalExtractionPaths = array_merge( |
|
57
|
|
|
$this->optionalExtractionPaths, |
|
58
|
|
|
[ |
|
59
|
|
|
'amount' => 'x:Pricing/x:Amount', |
|
60
|
|
|
'unitPrice' => 'x:Pricing/x:UnitPrice', |
|
61
|
|
|
'remainder' => 'x:Pricing/x:Amount/@remainder', |
|
62
|
|
|
] |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function deserializeExtra($serializedPayload) |
|
67
|
|
|
{ |
|
68
|
|
|
$xpath = $this->getPayloadAsXPath($serializedPayload); |
|
69
|
|
|
return $this->deserializeDestination($xpath)->deserializesShipDate($xpath); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Shipping destination may be one of two payload types. If the message |
|
74
|
|
|
* includes a ShippedAddress node, use the mailing address destination type. |
|
75
|
|
|
* If the message includes a StoreFrontAddress node, use a store front |
|
76
|
|
|
* details destination type. |
|
77
|
|
|
* |
|
78
|
|
|
* @return self |
|
79
|
|
|
*/ |
|
80
|
|
View Code Duplication |
protected function deserializeDestination(DOMXPath $xpath) |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
$destinationNode = $xpath->query('x:Shipping/x:ShippedAddress|x:Shipping/x:StoreFrontAddress')->item(0); |
|
83
|
|
|
if ($destinationNode) { |
|
84
|
|
|
$mailingAddress = static::MAILING_ADDRESS_INTERFACE; |
|
85
|
|
|
$storeFront = static::STORE_FRONT_DETAILS_INTERFACE; |
|
86
|
|
|
$destination = null; |
|
87
|
|
|
switch ($destinationNode->nodeName) { |
|
88
|
|
|
case $mailingAddress::ROOT_NODE: |
|
89
|
|
|
$destination = $this->buildPayloadForInterface($mailingAddress); |
|
90
|
|
|
break; |
|
91
|
|
|
case $storeFront::ROOT_NODE: |
|
92
|
|
|
$destination = $this->buildPayloadForInterface($storeFront); |
|
93
|
|
|
break; |
|
94
|
|
|
} |
|
95
|
|
|
if ($destination) { |
|
96
|
|
|
$destination->deserialize($destinationNode->C14N()); |
|
97
|
|
|
$this->setDestination($destination); |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Deserialize the EstimatedShipDate to a DateTime object. |
|
105
|
|
|
* |
|
106
|
|
|
* @param DOMXPath |
|
107
|
|
|
* @return self |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function deserializesShipDate(DOMXPath $xpath) |
|
110
|
|
|
{ |
|
111
|
|
|
$estimatedShipDate = $xpath->evaluate('string(x:Shipping/x:EstimatedShipDate)'); |
|
112
|
|
|
if ($estimatedShipDate) { |
|
113
|
|
|
$shipDate = new DateTime($estimatedShipDate); |
|
114
|
|
|
$this->setEstimatedShipDate($shipDate); |
|
115
|
|
|
} |
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
protected function serializeContents() |
|
120
|
|
|
{ |
|
121
|
|
|
return parent::serializeContents() |
|
122
|
|
|
. ($this->hasPricingData() ? $this->serializeProductPrice() : '') |
|
123
|
|
|
. ($this->hasShippingData() ? $this->serializeItemShipping() : ''); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
protected function getXmlNamespace() |
|
127
|
|
|
{ |
|
128
|
|
|
return self::XML_NS; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Check if the payload has shipping data to include in the serialization. |
|
133
|
|
|
* |
|
134
|
|
|
* @return bool |
|
135
|
|
|
*/ |
|
136
|
|
|
protected function hasShippingData() |
|
137
|
|
|
{ |
|
138
|
|
|
return (bool) $this->getShipmentMethod(); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Check if the payload has pricing data to include in the serialization. |
|
143
|
|
|
* |
|
144
|
|
|
* @return bool |
|
145
|
|
|
*/ |
|
146
|
|
|
protected function hasPricingData() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->getAmount() || $this->getUnitPrice(); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..