|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helix\Shopify; |
|
4
|
|
|
|
|
5
|
|
|
use Helix\Shopify\Base\AbstractEntity; |
|
6
|
|
|
use Helix\Shopify\PriceRule\DiscountCode; |
|
7
|
|
|
use Helix\Shopify\PriceRule\QuantityRatio; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* A price rule. |
|
11
|
|
|
* |
|
12
|
|
|
* @see https://shopify.dev/docs/admin-api/rest/reference/discounts/pricerule |
|
13
|
|
|
* |
|
14
|
|
|
* @method int getAllocationLimit () |
|
15
|
|
|
* @method string getAllocationMethod () see the constants |
|
16
|
|
|
* @method string getCreatedAt () |
|
17
|
|
|
* @method string getCustomerSelection () see the constants |
|
18
|
|
|
* @method string getEndsAt () |
|
19
|
|
|
* @method string[] getEntitledCollectionIds () |
|
20
|
|
|
* @method string[] getEntitledCountryIds () |
|
21
|
|
|
* @method string[] getEntitledProductIds () |
|
22
|
|
|
* @method string[] getEntitledVariantIds () |
|
23
|
|
|
* @method bool isOncePerCustomer () |
|
24
|
|
|
* @method string[] getPrerequisiteCollectionIds () |
|
25
|
|
|
* @method string[] getPrerequisiteCustomerIds () |
|
26
|
|
|
* @method string[] getPrerequisiteProductIds () |
|
27
|
|
|
* @method string[] getPrerequisiteSavedSearchIds () |
|
28
|
|
|
* @method string[] getPrerequisiteVariantIds () |
|
29
|
|
|
* @method string getStartsAt () |
|
30
|
|
|
* @method string getTargetSelection () see the constants |
|
31
|
|
|
* @method string getTargetType () see the constants |
|
32
|
|
|
* @method string getTitle () |
|
33
|
|
|
* @method string getUpdatedAt () |
|
34
|
|
|
* @method string getUsageLimit () |
|
35
|
|
|
* @method int getValue () |
|
36
|
|
|
* @method string getValueType () |
|
37
|
|
|
* |
|
38
|
|
|
* @method bool hasEntitledCollectionIds () |
|
39
|
|
|
* @method bool hasEntitledCountryIds () |
|
40
|
|
|
* @method bool hasEntitledProductIds () |
|
41
|
|
|
* @method bool hasEntitledVariantIds () |
|
42
|
|
|
* @method bool hasPrerequisiteCollectionIds () |
|
43
|
|
|
* @method bool hasPrerequisiteCustomerIds () |
|
44
|
|
|
* @method bool hasPrerequisiteProductIds () |
|
45
|
|
|
* @method bool hasPrerequisiteSavedSearchIds () |
|
46
|
|
|
* @method bool hasPrerequisiteVariantIds () |
|
47
|
|
|
* |
|
48
|
|
|
* @method $this setAllocationLimit (int $limit) |
|
49
|
|
|
* @method $this setAllocationMethod (string $method) see the constants |
|
50
|
|
|
* @method $this setCustomerSelection (string $selection) see the constants |
|
51
|
|
|
* @method $this setEndsAt (string $iso8601) |
|
52
|
|
|
* @method $this setEntitledCollectionIds (string[] $ids) |
|
53
|
|
|
* @method $this setEntitledCountryIds (string[] $ids) |
|
54
|
|
|
* @method $this setEntitledProductIds (string[] $ids) |
|
55
|
|
|
* @method $this setEntitledVariantIds (string[] $ids) |
|
56
|
|
|
* @method $this setOncePerCustomer (bool $once) |
|
57
|
|
|
* @method $this setPrerequisiteCollectionIds (string[] $ids) |
|
58
|
|
|
* @method $this setPrerequisiteCustomerIds (string[] $ids) |
|
59
|
|
|
* @method $this setPrerequisiteProductIds (string[] $ids) |
|
60
|
|
|
* @method $this setPrerequisiteSavedSearchIds (string[] $ids) |
|
61
|
|
|
* @method $this setPrerequisiteVariantIds (string[] $ids) |
|
62
|
|
|
* @method $this setStartsAt (string $iso8601) |
|
63
|
|
|
* @method $this setTargetSelection (string $selection) see the constants |
|
64
|
|
|
* @method $this setTargetType (string $type) see the constants |
|
65
|
|
|
* @method $this setTitle (string $title) |
|
66
|
|
|
* @method $this setUsageLimit (string $limit) |
|
67
|
|
|
* @method $this setValue (int $value) negative |
|
68
|
|
|
* @method $this setValueType (string $type) |
|
69
|
|
|
*/ |
|
70
|
|
|
class PriceRule extends AbstractEntity |
|
71
|
|
|
{ |
|
72
|
|
|
|
|
73
|
|
|
const TYPE = 'price_rule'; |
|
74
|
|
|
const DIR = 'price_rules'; |
|
75
|
|
|
|
|
76
|
|
|
const ALLOCATE_EACH = 'each'; |
|
77
|
|
|
const ALLOCATE_ACROSS = 'across'; |
|
78
|
|
|
|
|
79
|
|
|
const CUSTOMER_SELECT_ALL = 'all'; |
|
80
|
|
|
const CUSTOMER_SELECT_CONDITION = 'prerequisite'; |
|
81
|
|
|
|
|
82
|
|
|
const TARGET_SELECT_ALL = 'all'; |
|
83
|
|
|
const TARGET_SELECT_ENTITLED = 'entitled'; |
|
84
|
|
|
|
|
85
|
|
|
const TARGET_TYPE_LINE_ITEM = 'line_item'; |
|
86
|
|
|
const TARGET_TYPE_SHIPPING_LINE = 'shipping_line'; |
|
87
|
|
|
|
|
88
|
|
|
const VALUE_FIXED = 'fixed'; |
|
89
|
|
|
const VALUE_PERCENT = 'percentage'; |
|
90
|
|
|
|
|
91
|
|
|
const MAP = [ |
|
92
|
|
|
'prerequisite_to_entitlement_quantity_ratio' => QuantityRatio::class |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return DiscountCode[] |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getDiscountCodes() |
|
99
|
|
|
{ |
|
100
|
|
|
return DiscountCode::loadAll($this, "{$this}/discount_codes"); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return null|number |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getMaxShipping() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->data['prerequisite_shipping_price_range']['less_than_or_equal_to'] ?? null; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return null|int |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getMinQuantity() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->data['prerequisite_quantity_range']['greater_than_or_equal_to'] ?? null; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return null|number |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getMinSubtotal() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->data['prerequisite_subtotal_range']['greater_than_or_equal_to'] ?? null; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return DiscountCode |
|
129
|
|
|
*/ |
|
130
|
|
|
public function newDiscountCode() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->api->factory($this, DiscountCode::class, [ |
|
133
|
|
|
'price_rule_id' => $this->getId() |
|
134
|
|
|
]); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param null|number $max |
|
139
|
|
|
* @return $this |
|
140
|
|
|
*/ |
|
141
|
|
|
public function setMaxShipping($max) |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->_set('prerequisite_shipping_price_range', isset($max) ? ['less_than_or_equal_to' => $max] : null); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param null|int $min |
|
148
|
|
|
* @return $this |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setMinQuantity(?int $min) |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->_set('prerequisite_quantity_range', isset($min) ? ['greater_than_or_equal_to' => $min] : null); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param null|number $min |
|
157
|
|
|
* @return $this |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setMinSubtotal($min) |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->_set('prerequisite_subtotal_range', isset($min) ? ['greater_than_or_equal_to' => $min] : null); |
|
162
|
|
|
} |
|
163
|
|
|
} |