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-2015 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 eBayEnterprise\RetailOrderManagement\Payload\IPayload; |
19
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap; |
20
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator; |
21
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator; |
22
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
23
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\TPayload; |
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
use Psr\Log\NullLogger; |
26
|
|
|
|
27
|
|
|
class ItemRelationship implements IItemRelationship |
28
|
|
|
{ |
29
|
|
|
use TPayload, TOrderItemReferenceContainer; |
30
|
|
|
|
31
|
|
|
const ROOT_NODE = 'Relationship'; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
protected $parentItemId; |
35
|
|
|
/** @var IOrderItem */ |
36
|
|
|
protected $parentItem; |
37
|
|
|
/** @var string */ |
38
|
|
|
protected $type; |
39
|
|
|
/** @var string */ |
40
|
|
|
protected $name; |
41
|
|
|
/** @var array */ |
42
|
|
|
protected $allowedRelationshipTypes = [ |
43
|
|
|
self::TYPE_BUNDLE, |
44
|
|
|
self::TYPE_WARRANTY, |
45
|
|
|
self::TYPE_KIT, |
46
|
|
|
self::TYPE_DYNAMIC, |
47
|
|
|
self::TYPE_CUSTOMIZATION, |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param IValidatorIterator |
52
|
|
|
* @param ISchemaValidator |
53
|
|
|
* @param IPayloadMap |
54
|
|
|
* @param LoggerInterface |
55
|
|
|
* @param IPayload |
56
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
57
|
|
|
*/ |
58
|
|
|
public function __construct( |
59
|
|
|
IValidatorIterator $validators, |
60
|
|
|
ISchemaValidator $schemaValidator, |
61
|
|
|
IPayloadMap $payloadMap, |
62
|
|
|
LoggerInterface $logger, |
63
|
|
|
IPayload $parentPayload = null |
64
|
|
|
) { |
65
|
|
|
$this->logger = $logger; |
|
|
|
|
66
|
|
|
$this->validators = $validators; |
67
|
|
|
$this->schemaValidator = $schemaValidator; |
68
|
|
|
$this->payloadMap = $payloadMap; |
69
|
|
|
$this->parentPayload = $parentPayload; |
70
|
|
|
$this->payloadFactory = new PayloadFactory; |
71
|
|
|
|
72
|
|
|
$this->extractionPaths = [ |
73
|
|
|
'parentItemId' => 'string(@parent)', |
74
|
|
|
'type' => 'string(x:Type)', |
75
|
|
|
]; |
76
|
|
|
$this->optionalExtractionPaths = [ |
77
|
|
|
'name' => 'x:Name', |
78
|
|
|
]; |
79
|
|
|
$this->subpayloadExtractionPaths = [ |
80
|
|
|
'itemReferences' => 'x:Members', |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$this->itemReferences = $this->buildPayloadForInterface( |
84
|
|
|
self::ITEM_REFERENCE_ITERABLE_INTERFACE |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
View Code Duplication |
public function getParentItem() |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
if (!$this->parentItem && $this->parentItemId) { |
91
|
|
|
$itemContainer = $this->getItemContainer(); |
92
|
|
|
if ($itemContainer) { |
93
|
|
|
foreach ($itemContainer->getOrderItems() as $item) { |
94
|
|
|
if ($item->getId() === $this->parentItemId) { |
95
|
|
|
$this->parentItem = $item; |
96
|
|
|
break; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
return $this->parentItem; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public function setParentItem(IOrderItem $parentItem) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
$this->parentItem = $parentItem; |
107
|
|
|
$itemContainer = $this->getItemContainer(); |
108
|
|
|
if ($itemContainer) { |
109
|
|
|
$itemContainer->getOrderItems()->offsetSet($parentItem); |
110
|
|
|
} |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getParentItemId() |
115
|
|
|
{ |
116
|
|
|
$item = $this->getParentItem(); |
117
|
|
|
return $item ? $item->getId() : $this->parentItemId; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getType() |
121
|
|
|
{ |
122
|
|
|
return $this->type; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function setType($type) |
126
|
|
|
{ |
127
|
|
|
$this->type = in_array($type, $this->allowedRelationshipTypes) ? $type : null; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getName() |
132
|
|
|
{ |
133
|
|
|
return $this->name; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function setName($name) |
137
|
|
|
{ |
138
|
|
|
$this->name = $name; |
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get the order item container associated with this payload. Will return |
144
|
|
|
* null if one cannot be found. |
145
|
|
|
* |
146
|
|
|
* @return IOrderItemContainer|null |
147
|
|
|
*/ |
148
|
|
|
protected function getItemContainer() |
149
|
|
|
{ |
150
|
|
|
$this->debug = true; |
|
|
|
|
151
|
|
|
return $this->getAncestorPayloadOfType('\eBayEnterprise\RetailOrderManagement\Payload\Order\IOrderItemContainer'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
protected function serializeContents() |
155
|
|
|
{ |
156
|
|
|
return $this->getItemReferences()->setRootNodeName('Members')->serialize() |
157
|
|
|
. "<Type>{$this->xmlEncode($this->getType())}</Type>" |
158
|
|
|
. $this->serializeOptionalXmlEncodedValue('Name', $this->getName()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
protected function getRootAttributes() |
162
|
|
|
{ |
163
|
|
|
return ['parent' => $this->getParentItemId()]; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
protected function getRootNodeName() |
167
|
|
|
{ |
168
|
|
|
return static::ROOT_NODE; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
protected function getXmlNamespace() |
172
|
|
|
{ |
173
|
|
|
return self::XML_NS; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
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..