|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helix\Shopify; |
|
4
|
|
|
|
|
5
|
|
|
use Helix\Shopify\Base\AbstractEntity\CrudTrait; |
|
6
|
|
|
use Helix\Shopify\Order\AbstractOrder; |
|
7
|
|
|
use Helix\Shopify\Order\AppliedDiscount; |
|
8
|
|
|
use Helix\Shopify\Order\Discount; |
|
9
|
|
|
use Helix\Shopify\Order\Fulfillment; |
|
10
|
|
|
use Helix\Shopify\Order\Refund; |
|
11
|
|
|
use Helix\Shopify\Order\Shipping; |
|
12
|
|
|
use Helix\Shopify\Order\Tax; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* An order. |
|
16
|
|
|
* |
|
17
|
|
|
* Orders cannot be placed through the REST API. |
|
18
|
|
|
* |
|
19
|
|
|
* Shopify allows order creation on the condition that it's for archival purposes, |
|
20
|
|
|
* like if you're migrating from somewhere. Only finalized orders can be created, |
|
21
|
|
|
* whether that finalization happened through fulfillment or cancellation. |
|
22
|
|
|
* |
|
23
|
|
|
* Open orders cannot be created through the API. Consider using a {@link DraftOrder} instead. |
|
24
|
|
|
* |
|
25
|
|
|
* Orders are mostly immutable except for a few things, which are documented here. |
|
26
|
|
|
* |
|
27
|
|
|
* - billing_address |
|
28
|
|
|
* - buyer_accepts_marketing |
|
29
|
|
|
* - email |
|
30
|
|
|
* - metafields |
|
31
|
|
|
* - note |
|
32
|
|
|
* - note_attributes |
|
33
|
|
|
* - phone |
|
34
|
|
|
* - shipping_address |
|
35
|
|
|
* - tags |
|
36
|
|
|
* |
|
37
|
|
|
* @see https://shopify.dev/docs/admin-api/rest/reference/orders/order |
|
38
|
|
|
* |
|
39
|
|
|
* @method $this setInventoryBehavior (string $behavior) @depends create-only |
|
40
|
|
|
* @method $this setSendFulfillmentReceipt (bool $receipt) @depends create-only |
|
41
|
|
|
* @method $this setTest (bool $test) @depends create-only |
|
42
|
|
|
* @method $this setSendReceipt (bool $receipt) @depends create-only |
|
43
|
|
|
* @method $this setSourceName (string $name) @depends create-only |
|
44
|
|
|
* @method $this setPresentmentCurrency (string $currency) @depends create-only |
|
45
|
|
|
* @method $this setFinancialStatus (string $status) @depends create-only |
|
46
|
|
|
* @method $this setCancelReason (string $reason) @depends create-only |
|
47
|
|
|
* @method $this setLocationId (string $id) @depends create-only |
|
48
|
|
|
* @method $this setDiscountCodes (Discount[] $codes) @depends create-only |
|
49
|
|
|
* @method $this setFulfillmentStatus (string $status) @depends create-only |
|
50
|
|
|
* @method $this setFulfillments (string[] $fulfillments) @depends create-only |
|
51
|
|
|
* @method $this setProcessedAt (string $iso8601) @depends create-only, historical creation date |
|
52
|
|
|
* @method $this setShippingLines (Shipping[] $lines) @depends create-only |
|
53
|
|
|
* @method $this setSubtotalPriceSet (string $set) @depends create-only |
|
54
|
|
|
* @method $this setTaxLines (Tax[] $taxes) @depends create-only |
|
55
|
|
|
* @method $this setTotalDiscounts (string $discounts) @depends create-only |
|
56
|
|
|
* @method $this setTotalDiscountsSet (string $set) @depends create-only |
|
57
|
|
|
* @method $this setTotalLineItemsPrice (number $price) @depends create-only |
|
58
|
|
|
* @method $this setTotalLineItemsPriceSet (string $set) @depends create-only |
|
59
|
|
|
* @method $this setTotalPriceSet (string $set) @depends create-only |
|
60
|
|
|
* @method $this setTotalTaxSet (string $set) @depends create-only |
|
61
|
|
|
* @method $this setTotalTipReceived (string $received) @depends create-only |
|
62
|
|
|
* @method $this setTotalWeight (string $weight) @depends create-only |
|
63
|
|
|
* |
|
64
|
|
|
* @method string getAppId () |
|
65
|
|
|
* @method string getBrowserIp () |
|
66
|
|
|
* @method bool getBuyerAcceptsMarketing () |
|
67
|
|
|
* @method string getCancelReason () |
|
68
|
|
|
* @method string getCancelledAt () |
|
69
|
|
|
* @method string getCartToken () |
|
70
|
|
|
* @method string getClientDetails () |
|
71
|
|
|
* @method string getClosedAt () |
|
72
|
|
|
* @method string getCurrentTotalDutiesSet () |
|
73
|
|
|
* @method string getCustomerLocale () |
|
74
|
|
|
* @method AppliedDiscount[] getDiscountApplications () |
|
75
|
|
|
* @method Discount[] getDiscountCodes () |
|
76
|
|
|
* @method string getFinancialStatus () |
|
77
|
|
|
* @method string getFulfillmentStatus () |
|
78
|
|
|
* @method Fulfillment[] getFulfillments () |
|
79
|
|
|
* @method string getLandingSite () |
|
80
|
|
|
* @method string getLocationId () |
|
81
|
|
|
* @method string getNumber () |
|
82
|
|
|
* @method string getOrderNumber () |
|
83
|
|
|
* @method string getOrderStatusUrl () |
|
84
|
|
|
* @method string getOriginalTotalDutiesSet () |
|
85
|
|
|
* @method string[] getPaymentGatewayNames () |
|
86
|
|
|
* @method string getPhone () |
|
87
|
|
|
* @method string getPresentmentCurrency () |
|
88
|
|
|
* @method string getProcessedAt () |
|
89
|
|
|
* @method string getProcessingMethod () |
|
90
|
|
|
* @method string getReferringSite () |
|
91
|
|
|
* @method Refund[] getRefunds () |
|
92
|
|
|
* @method Shipping[] getShippingLines () |
|
93
|
|
|
* @method string getSourceName () |
|
94
|
|
|
* @method string getSubtotalPriceSet () |
|
95
|
|
|
* @method string getTaxesIncluded () |
|
96
|
|
|
* @method bool isTest () |
|
97
|
|
|
* @method string getToken () |
|
98
|
|
|
* @method string getTotalDiscounts () |
|
99
|
|
|
* @method string getTotalDiscountsSet () |
|
100
|
|
|
* @method number getTotalLineItemsPrice () |
|
101
|
|
|
* @method string getTotalLineItemsPriceSet () |
|
102
|
|
|
* @method string getTotalPriceSet () |
|
103
|
|
|
* @method string getTotalTaxSet () |
|
104
|
|
|
* @method string getTotalTipReceived () |
|
105
|
|
|
* @method string getTotalWeight () |
|
106
|
|
|
* @method string getUserId () staff account id |
|
107
|
|
|
* |
|
108
|
|
|
* @method bool hasDiscountApplications () |
|
109
|
|
|
* @method bool hasDiscountCodes () |
|
110
|
|
|
* @method bool hasFulfillments () |
|
111
|
|
|
* @method bool hasNoteAttributes () |
|
112
|
|
|
* @method bool hasPaymentGatewayNames () |
|
113
|
|
|
* @method bool hasRefunds () |
|
114
|
|
|
* @method bool hasShippingLines () |
|
115
|
|
|
* @method bool hasTaxLines () |
|
116
|
|
|
* |
|
117
|
|
|
* @method $this setBuyerAcceptsMarketing (bool $marketing) |
|
118
|
|
|
* @method $this setPhone (string $phone) |
|
119
|
|
|
* @method $this setReferringSite (string $site) |
|
120
|
|
|
*/ |
|
121
|
|
|
class Order extends AbstractOrder |
|
122
|
|
|
{ |
|
123
|
|
|
|
|
124
|
|
|
use CrudTrait; |
|
125
|
|
|
|
|
126
|
|
|
const TYPE = 'order'; |
|
127
|
|
|
const DIR = 'orders'; |
|
128
|
|
|
|
|
129
|
|
|
const MAP = parent::MAP + [ |
|
130
|
|
|
'discount_applications' => [AppliedDiscount::class], |
|
131
|
|
|
'discount_codes' => [Discount::class], |
|
132
|
|
|
'fulfillments' => [Fulfillment::class], |
|
133
|
|
|
'refunds' => [Refund::class], |
|
134
|
|
|
'shipping_lines' => [Shipping::class], |
|
135
|
|
|
]; |
|
136
|
|
|
|
|
137
|
|
|
const INVENTORY_BYPASS = 'bypass'; |
|
138
|
|
|
const INVENTORY_DECREMENT_IGNORE = 'decrement_ignoring_policy'; |
|
139
|
|
|
const INVENTORY_DECREMENT_OBEY = 'decrement_obeying_policy'; |
|
140
|
|
|
|
|
141
|
|
|
const PAYMENT_AUTHORIZED = 'authorized'; |
|
142
|
|
|
const PAYMENT_COMPLETE = 'paid'; |
|
143
|
|
|
const PAYMENT_PARTIAL = 'partially_paid'; |
|
144
|
|
|
const PAYMENT_PARTIAL_REFUND = 'partially_refunded'; |
|
145
|
|
|
const PAYMENT_PENDING = 'pending'; |
|
146
|
|
|
const PAYMENT_REFUNDED = 'refunded'; |
|
147
|
|
|
const PAYMENT_VOIDED = 'voided'; |
|
148
|
|
|
|
|
149
|
|
|
const FULFILLMENT_COMPLETE = 'fulfilled'; |
|
150
|
|
|
const FULFILLMENT_NONE = null; |
|
151
|
|
|
const FULFILLMENT_PARTIAL = 'partial'; |
|
152
|
|
|
const FULFILLMENT_RESTOCKED = 'restocked'; |
|
153
|
|
|
|
|
154
|
|
|
const SEARCH_STATUS_ANY = 'any'; |
|
155
|
|
|
const SEARCH_STATUS_CANCELLED = 'cancelled'; |
|
156
|
|
|
const SEARCH_STATUS_CLOSED = 'closed'; |
|
157
|
|
|
const SEARCH_STATUS_OPEN = 'open'; |
|
158
|
|
|
const SEARCH_PAYMENT_ANY = 'any'; |
|
159
|
|
|
const SEARCH_PAYMENT_AUTHORIZED = 'authorized'; |
|
160
|
|
|
const SEARCH_PAYMENT_COMPLETE = 'paid'; |
|
161
|
|
|
const SEARCH_PAYMENT_INCOMPLETE = 'unpaid'; |
|
162
|
|
|
const SEARCH_PAYMENT_PARTIAL = 'partially_paid'; |
|
163
|
|
|
const SEARCH_PAYMENT_PARTIAL_REFUND = 'partially_refunded'; |
|
164
|
|
|
const SEARCH_PAYMENT_PENDING = 'pending'; |
|
165
|
|
|
const SEARCH_PAYMENT_REFUNDED = 'refunded'; |
|
166
|
|
|
const SEARCH_PAYMENT_VOIDED = 'voided'; |
|
167
|
|
|
const SEARCH_FULFILLMENT_ANY = 'any'; |
|
168
|
|
|
const SEARCH_FULFILLMENT_PARTIAL = 'partial'; |
|
169
|
|
|
const SEARCH_FULFILLMENT_SHIPPED = 'shipped'; |
|
170
|
|
|
const SEARCH_FULFILLMENT_UNSHIPPED = 'unshipped'; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Cancels the order. |
|
174
|
|
|
* |
|
175
|
|
|
* Applicable refunds must be issued before cancellation. |
|
176
|
|
|
* |
|
177
|
|
|
* @return $this |
|
178
|
|
|
*/ |
|
179
|
|
|
public function cancel() |
|
180
|
|
|
{ |
|
181
|
|
|
assert($this->hasId()); |
|
182
|
|
|
$this->api->post("{$this}/cancel"); |
|
183
|
|
|
return $this->reload(); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Closes the order. |
|
188
|
|
|
* |
|
189
|
|
|
* @return $this |
|
190
|
|
|
*/ |
|
191
|
|
|
public function close() |
|
192
|
|
|
{ |
|
193
|
|
|
assert($this->hasId()); |
|
194
|
|
|
$this->api->post("{$this}/close"); |
|
195
|
|
|
return $this->reload(); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return Discount |
|
200
|
|
|
*/ |
|
201
|
|
|
public function newDiscount() |
|
202
|
|
|
{ |
|
203
|
|
|
return $this->api->factory($this, Discount::class); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @return Fulfillment |
|
208
|
|
|
*/ |
|
209
|
|
|
public function newFulfillment() |
|
210
|
|
|
{ |
|
211
|
|
|
assert($this->hasId()); |
|
212
|
|
|
return $this->api->factory($this, Fulfillment::class, [ |
|
213
|
|
|
'order_id' => $this->getId() |
|
214
|
|
|
]); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @return Refund |
|
219
|
|
|
*/ |
|
220
|
|
|
public function newRefund() |
|
221
|
|
|
{ |
|
222
|
|
|
assert($this->hasId()); |
|
223
|
|
|
return $this->api->factory($this, Refund::class); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @return Shipping |
|
228
|
|
|
*/ |
|
229
|
|
|
public function newShipping() |
|
230
|
|
|
{ |
|
231
|
|
|
return $this->api->factory($this, Shipping::class); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Reopens a closed order. |
|
236
|
|
|
* |
|
237
|
|
|
* @return $this |
|
238
|
|
|
*/ |
|
239
|
|
|
public function reopen() |
|
240
|
|
|
{ |
|
241
|
|
|
assert($this->hasId()); |
|
242
|
|
|
$this->api->post("{$this}/open"); |
|
243
|
|
|
return $this->reload(); |
|
244
|
|
|
} |
|
245
|
|
|
} |