1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helix\Shopify; |
4
|
|
|
|
5
|
|
|
use Helix\Shopify\DraftOrder\Discount; |
6
|
|
|
use Helix\Shopify\DraftOrder\Invoice; |
7
|
|
|
use Helix\Shopify\Order\AbstractOrder; |
8
|
|
|
use Helix\Shopify\Order\OrderItem; |
9
|
|
|
use Helix\Shopify\Order\Shipping; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A draft order. |
13
|
|
|
* |
14
|
|
|
* @see https://shopify.dev/docs/admin-api/rest/reference/orders/draftorder |
15
|
|
|
* |
16
|
|
|
* @method $this setUseCustomerDefaultAddress (bool $flag) @depends create-only |
17
|
|
|
* |
18
|
|
|
* @method null|Discount getAppliedDiscount () |
19
|
|
|
* @method string getCompletedAt () |
20
|
|
|
* @method string getCustomerId () injected |
21
|
|
|
* @method string getInvoiceSentAt () |
22
|
|
|
* @method $this setInvoiceSentAt (string $iso8601) |
23
|
|
|
* @method string getInvoiceUrl () |
24
|
|
|
* @method string getOrderId () |
25
|
|
|
* @method null|Shipping getShippingLine () |
26
|
|
|
* @method $this setShippingLine (?Shipping $shipping) |
27
|
|
|
* @method string getStatus () |
28
|
|
|
* @method bool isTaxExempt () |
29
|
|
|
* |
30
|
|
|
* @method $this setTaxExempt (bool $exempt) |
31
|
|
|
* @method $this setLineItems (OrderItem[] $items) |
32
|
|
|
*/ |
33
|
|
|
class DraftOrder extends AbstractOrder |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
const TYPE = 'draft_order'; |
37
|
|
|
const DIR = 'draft_orders'; |
38
|
|
|
|
39
|
|
|
const MAP = parent::MAP + [ |
40
|
|
|
'applied_discount' => Discount::class, |
41
|
|
|
'discount' => Discount::class, |
42
|
|
|
'shipping_line' => Shipping::class, |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
const STATUS_OPEN = 'open'; |
46
|
|
|
const STATUS_INVOICED = 'invoice_sent'; |
47
|
|
|
const STATUS_COMPLETE = 'completed'; |
48
|
|
|
|
49
|
|
|
const SEARCH_STATUS_OPEN = 'open'; |
50
|
|
|
const SEARCH_STATUS_INVOICED = 'invoice_sent'; |
51
|
|
|
const SEARCH_STATUS_COMPLETE = 'completed'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param bool $paymentPending |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function complete(bool $paymentPending = false) |
58
|
|
|
{ |
59
|
|
|
assert($this->hasId()); |
60
|
|
|
$remote = $this->api->put("{$this}/complete", [ |
61
|
|
|
'payment_pending' => ['false', 'true'][$paymentPending] |
62
|
|
|
]); |
63
|
|
|
$this->_setData($remote[self::TYPE]); |
64
|
|
|
$this->_onSave(); |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Invoice|null $invoice |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function sendInvoice(Invoice $invoice = null) |
73
|
|
|
{ |
74
|
|
|
assert($this->hasId()); |
75
|
|
|
$this->api->post("{$this}/send_invoice", [ |
76
|
|
|
'draft_order_invoice' => $invoice ? $invoice->toArray() : (object)[] |
77
|
|
|
]); |
78
|
|
|
return $this->reload(); |
79
|
|
|
} |
80
|
|
|
} |