1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helix\Shopify\Order; |
4
|
|
|
|
5
|
|
|
use Helix\Shopify\Base\AbstractEntity; |
6
|
|
|
use Helix\Shopify\Base\AbstractEntity\CreateTrait; |
7
|
|
|
use Helix\Shopify\Order; |
8
|
|
|
use Helix\Shopify\Order\Fulfillment\Receipt; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A fulfillment. |
12
|
|
|
* |
13
|
|
|
* @see https://help.shopify.com/en/api/reference/shipping-and-fulfillment/fulfillment |
14
|
|
|
* |
15
|
|
|
* @method string getCreatedAt () |
16
|
|
|
* @method OrderItem[] getLineItems () |
17
|
|
|
* @method string getLocationId () |
18
|
|
|
* @method string getName () |
19
|
|
|
* @method bool isNotifyCustomer () |
20
|
|
|
* @method $this setNotifyCustomer (bool $notify) |
21
|
|
|
* @method string getOrderId () injected |
22
|
|
|
* @method null|Receipt getReceipt () |
23
|
|
|
* @method string getService () |
24
|
|
|
* @method string getShipmentStatus () |
25
|
|
|
* @method string getStatus () |
26
|
|
|
* @method string getTrackingCompany () |
27
|
|
|
* @method $this setTrackingCompany (string $company) |
28
|
|
|
* @method string[] getTrackingNumbers () |
29
|
|
|
* @method $this setTrackingNumbers (string[] $numbers) |
30
|
|
|
* @method string[] getTrackingUrls () |
31
|
|
|
* @method $this setTrackingUrls (string[] $urls) |
32
|
|
|
* @method string getUpdatedAt () |
33
|
|
|
* @method string getVariantInventoryManagement () |
34
|
|
|
*/ |
35
|
|
|
class Fulfillment extends AbstractEntity |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
use CreateTrait; |
39
|
|
|
|
40
|
|
|
const TYPE = 'fulfillment'; |
41
|
|
|
const DIR = 'fulfillments'; |
42
|
|
|
|
43
|
|
|
const MAP = [ |
44
|
|
|
'line_items' => [OrderItem::class], |
45
|
|
|
'receipt' => Receipt::class |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
const STATUS_PENDING = 'pending'; |
49
|
|
|
const STATUS_OPEN = 'open'; |
50
|
|
|
const STATUS_SUCCESS = 'success'; |
51
|
|
|
const STATUS_CANCELLED = 'cancelled'; |
52
|
|
|
const STATUS_ERROR = 'error'; |
53
|
|
|
const STATUS_FAILURE = 'failure'; |
54
|
|
|
|
55
|
|
|
const SHIPMENT_LABEL_PRINTED = 'label_printed'; |
56
|
|
|
const SHIPMENT_LABEL_PURCHASED = 'label_purchased'; |
57
|
|
|
const SHIPMENT_READY = 'confirmed'; |
58
|
|
|
const SHIPMENT_FREIGHTING = 'in_transit'; |
59
|
|
|
const SHIPMENT_DELIVERING = 'out_for_delivery'; |
60
|
|
|
const SHIPMENT_UNDELIVERED = 'attempted_delivery'; |
61
|
|
|
const SHIPMENT_PICKUP = 'ready_for_pickup'; |
62
|
|
|
const SHIPMENT_COMPLETE = 'delivered'; |
63
|
|
|
const SHIPMENT_FAILURE = 'failure'; |
64
|
|
|
|
65
|
|
|
protected function _container() |
66
|
|
|
{ |
67
|
|
|
return $this->getOrder(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return $this |
72
|
|
|
*/ |
73
|
|
|
public function cancel() |
74
|
|
|
{ |
75
|
|
|
assert($this->hasId()); |
76
|
|
|
$remote = $this->api->post("{$this}/cancel", []); |
77
|
|
|
return $this->_setData($remote[self::TYPE]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function complete() |
84
|
|
|
{ |
85
|
|
|
assert($this->hasId()); |
86
|
|
|
$remote = $this->api->post("{$this}/complete", []); |
87
|
|
|
return $this->_setData($remote[self::TYPE]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return Order |
92
|
|
|
*/ |
93
|
|
|
public function getOrder() |
94
|
|
|
{ |
95
|
|
|
return Order::load($this, $this->getOrderId()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $orderItemId |
100
|
|
|
* @return OrderItem |
101
|
|
|
*/ |
102
|
|
|
public function newItem(string $orderItemId) |
103
|
|
|
{ |
104
|
|
|
return $this->api->factory($this, OrderItem::class, [ |
105
|
|
|
'id' => $orderItemId |
106
|
|
|
]); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return $this |
111
|
|
|
*/ |
112
|
|
|
public function open() |
113
|
|
|
{ |
114
|
|
|
assert($this->hasId()); |
115
|
|
|
$remote = $this->api->post("{$this}/open", []); |
116
|
|
|
return $this->_setData($remote[self::TYPE]); |
117
|
|
|
} |
118
|
|
|
} |