1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Order; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Cart\CustomLineItemCollection; |
9
|
|
|
use Commercetools\Core\Model\Cart\LineItemCollection; |
10
|
|
|
use Commercetools\Core\Model\Cart\ShippingInfo; |
11
|
|
|
use Commercetools\Core\Model\Common\Address; |
12
|
|
|
use Commercetools\Core\Model\Common\Resource; |
13
|
|
|
use Commercetools\Core\Model\Common\Money; |
14
|
|
|
use Commercetools\Core\Model\Common\TaxedPrice; |
15
|
|
|
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference; |
16
|
|
|
use Commercetools\Core\Model\Cart\DiscountCodeInfoCollection; |
17
|
|
|
use Commercetools\Core\Model\Cart\CartReference; |
18
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObject; |
19
|
|
|
use Commercetools\Core\Model\Common\DateTimeDecorator; |
20
|
|
|
use Commercetools\Core\Model\State\StateReference; |
21
|
|
|
use Commercetools\Core\Model\Payment\PaymentInfo; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package Commercetools\Core\Model\Order |
25
|
|
|
* @link https://dev.commercetools.com/http-api-projects-orders.html#order |
26
|
|
|
* @method string getId() |
27
|
|
|
* @method Order setId(string $id = null) |
28
|
|
|
* @method int getVersion() |
29
|
|
|
* @method Order setVersion(int $version = null) |
30
|
|
|
* @method DateTimeDecorator getCreatedAt() |
31
|
|
|
* @method Order setCreatedAt(\DateTime $createdAt = null) |
32
|
|
|
* @method DateTimeDecorator getLastModifiedAt() |
33
|
|
|
* @method Order setLastModifiedAt(\DateTime $lastModifiedAt = null) |
34
|
|
|
* @method string getOrderNumber() |
35
|
|
|
* @method Order setOrderNumber(string $orderNumber = null) |
36
|
|
|
* @method string getCustomerId() |
37
|
|
|
* @method Order setCustomerId(string $customerId = null) |
38
|
|
|
* @method string getCustomerEmail() |
39
|
|
|
* @method Order setCustomerEmail(string $customerEmail = null) |
40
|
|
|
* @method LineItemCollection getLineItems() |
41
|
|
|
* @method Order setLineItems(LineItemCollection $lineItems = null) |
42
|
|
|
* @method CustomLineItemCollection getCustomLineItems() |
43
|
|
|
* @method Order setCustomLineItems(CustomLineItemCollection $customLineItems = null) |
44
|
|
|
* @method Money getTotalPrice() |
45
|
|
|
* @method Order setTotalPrice(Money $totalPrice = null) |
46
|
|
|
* @method TaxedPrice getTaxedPrice() |
47
|
|
|
* @method Order setTaxedPrice(TaxedPrice $taxedPrice = null) |
48
|
|
|
* @method Address getShippingAddress() |
49
|
|
|
* @method Order setShippingAddress(Address $shippingAddress = null) |
50
|
|
|
* @method Address getBillingAddress() |
51
|
|
|
* @method Order setBillingAddress(Address $billingAddress = null) |
52
|
|
|
* @method string getInventoryMode() |
53
|
|
|
* @method Order setInventoryMode(string $inventoryMode = null) |
54
|
|
|
* @method CustomerGroupReference getCustomerGroup() |
55
|
|
|
* @method Order setCustomerGroup(CustomerGroupReference $customerGroup = null) |
56
|
|
|
* @method string getCountry() |
57
|
|
|
* @method Order setCountry(string $country = null) |
58
|
|
|
* @method string getOrderState() |
59
|
|
|
* @method Order setOrderState(string $orderState = null) |
60
|
|
|
* @method string getShipmentState() |
61
|
|
|
* @method Order setShipmentState(string $shipmentState = null) |
62
|
|
|
* @method string getPaymentState() |
63
|
|
|
* @method Order setPaymentState(string $paymentState = null) |
64
|
|
|
* @method ShippingInfo getShippingInfo() |
65
|
|
|
* @method Order setShippingInfo(ShippingInfo $shippingInfo = null) |
66
|
|
|
* @method SyncInfoCollection getSyncInfo() |
67
|
|
|
* @method Order setSyncInfo(SyncInfoCollection $syncInfo = null) |
68
|
|
|
* @method ReturnInfoCollection getReturnInfo() |
69
|
|
|
* @method Order setReturnInfo(ReturnInfoCollection $returnInfo = null) |
70
|
|
|
* @method DiscountCodeInfoCollection getDiscountCodes() |
71
|
|
|
* @method Order setDiscountCodes(DiscountCodeInfoCollection $discountCodes = null) |
72
|
|
|
* @method int getLastMessageSequenceNumber() |
73
|
|
|
* @method Order setLastMessageSequenceNumber(int $lastMessageSequenceNumber = null) |
74
|
|
|
* @method CartReference getCart() |
75
|
|
|
* @method Order setCart(CartReference $cart = null) |
76
|
|
|
* @method CustomFieldObject getCustom() |
77
|
|
|
* @method Order setCustom(CustomFieldObject $custom = null) |
78
|
|
|
* @method StateReference getState() |
79
|
|
|
* @method Order setState(StateReference $state = null) |
80
|
|
|
* @method PaymentInfo getPaymentInfo() |
81
|
|
|
* @method Order setPaymentInfo(PaymentInfo $paymentInfo = null) |
82
|
|
|
* @method DateTimeDecorator getCompletedAt() |
83
|
|
|
* @method Order setCompletedAt(\DateTime $completedAt = null) |
84
|
|
|
* @method string getAnonymousId() |
85
|
|
|
* @method Order setAnonymousId(string $anonymousId = null) |
86
|
|
|
* @method string getLocale() |
87
|
|
|
* @method OrderReference getReference() |
88
|
|
|
*/ |
89
|
|
|
class Order extends Resource |
90
|
20 |
|
{ |
91
|
|
|
public function fieldDefinitions() |
92
|
|
|
{ |
93
|
20 |
|
return [ |
94
|
20 |
|
'id' => [static::TYPE => 'string'], |
95
|
|
|
'version' => [static::TYPE => 'int'], |
96
|
20 |
|
'createdAt' => [ |
97
|
20 |
|
static::TYPE => '\DateTime', |
98
|
|
|
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
99
|
|
|
], |
100
|
20 |
|
'lastModifiedAt' => [ |
101
|
20 |
|
static::TYPE => '\DateTime', |
102
|
|
|
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
103
|
|
|
], |
104
|
20 |
|
'completedAt' => [ |
105
|
20 |
|
static::TYPE => '\DateTime', |
106
|
|
|
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
107
|
20 |
|
], |
108
|
20 |
|
'orderNumber' => [static::TYPE => 'string'], |
109
|
20 |
|
'customerId' => [static::TYPE => 'string'], |
110
|
20 |
|
'customerEmail' => [static::TYPE => 'string'], |
111
|
20 |
|
'lineItems' => [static::TYPE => '\Commercetools\Core\Model\Cart\LineItemCollection'], |
112
|
20 |
|
'customLineItems' => [static::TYPE => '\Commercetools\Core\Model\Cart\CustomLineItemCollection'], |
113
|
20 |
|
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'], |
114
|
20 |
|
'taxedPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\TaxedPrice'], |
115
|
20 |
|
'shippingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'], |
116
|
20 |
|
'billingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'], |
117
|
20 |
|
'inventoryMode' => [static::TYPE => 'string'], |
118
|
20 |
|
'customerGroup' => [static::TYPE => '\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference'], |
119
|
20 |
|
'country' => [static::TYPE => 'string'], |
120
|
20 |
|
'orderState' => [static::TYPE => 'string'], |
121
|
20 |
|
'shipmentState' => [static::TYPE => 'string'], |
122
|
20 |
|
'paymentState' => [static::TYPE => 'string'], |
123
|
20 |
|
'shippingInfo' => [static::TYPE => '\Commercetools\Core\Model\Cart\ShippingInfo'], |
124
|
20 |
|
'syncInfo' => [static::TYPE => '\Commercetools\Core\Model\Order\SyncInfoCollection'], |
125
|
20 |
|
'returnInfo' => [static::TYPE => '\Commercetools\Core\Model\Order\ReturnInfoCollection'], |
126
|
20 |
|
'discountCodes' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountCodeInfoCollection'], |
127
|
20 |
|
'lastMessageSequenceNumber' => [static::TYPE => 'int'], |
128
|
20 |
|
'cart' => [static::TYPE => '\Commercetools\Core\Model\Cart\CartReference'], |
129
|
20 |
|
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'], |
130
|
20 |
|
'state' => [static::TYPE => '\Commercetools\Core\Model\State\StateReference'], |
131
|
20 |
|
'paymentInfo' => [static::TYPE => '\Commercetools\Core\Model\Payment\PaymentInfo'], |
132
|
|
|
'anonymousId' => [static::TYPE => 'string'], |
133
|
|
|
'locale' => [static::TYPE => 'string'], |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setLocale($locale) |
138
|
|
|
{ |
139
|
|
|
$locale = \Locale::canonicalize($locale); |
140
|
|
|
parent::setLocale($locale); |
|
|
|
|
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
public function toJson() |
149
|
|
|
{ |
150
|
|
|
$data = parent::toArray(); |
|
|
|
|
151
|
|
|
$data['locale'] = str_replace('_', '-', $data['locale']); |
152
|
|
|
|
153
|
|
|
return $data; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: