|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class OrderStep_WhitelistCustomer extends OrderStep implements OrderStepInterface |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
6
|
|
|
'CustomerCanEdit' => 0, |
|
7
|
|
|
'CustomerCanCancel' => 0, |
|
8
|
|
|
'CustomerCanPay' => 0, |
|
9
|
|
|
'Name' => 'Whitelist Customer', |
|
10
|
|
|
'Code' => 'WHITELIST_CUSTOMER', |
|
11
|
|
|
'ShowAsInProcessOrder' => 1, |
|
12
|
|
|
'HideStepFromCustomer' => 1 |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The OrderStatusLog that is relevant to the particular step. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $relevantLogEntryClassName = 'OrderStatusLog_WhitelistCustomer'; |
|
21
|
|
|
|
|
22
|
|
|
public function getCMSFields() |
|
23
|
|
|
{ |
|
24
|
|
|
$fields = parent::getCMSFields(); |
|
25
|
|
|
|
|
26
|
|
|
return $fields; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* initStep: |
|
31
|
|
|
* makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
|
32
|
|
|
* should be able to run this function many times to check if the step is ready. |
|
33
|
|
|
* |
|
34
|
|
|
* @see Order::doNextStatus |
|
35
|
|
|
* |
|
36
|
|
|
* @param Order object |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool - true if the current step is ready to be run... |
|
39
|
|
|
**/ |
|
40
|
|
|
public function initStep(Order $order) |
|
41
|
|
|
{ |
|
42
|
|
|
return true; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* |
|
48
|
|
|
* @var null | bool |
|
49
|
|
|
*/ |
|
50
|
|
|
private $_completed = null; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* doStep: |
|
54
|
|
|
* should only be able to run this function once |
|
55
|
|
|
* (init stops you from running it twice - in theory....) |
|
56
|
|
|
* runs the actual step. |
|
57
|
|
|
* |
|
58
|
|
|
* @see Order::doNextStatus |
|
59
|
|
|
* |
|
60
|
|
|
* @param Order object |
|
61
|
|
|
* |
|
62
|
|
|
* @return bool - true if run correctly. |
|
|
|
|
|
|
63
|
|
|
**/ |
|
64
|
|
|
public function doStep(Order $order) |
|
65
|
|
|
{ |
|
66
|
|
|
if ($this->_completed !== null) { |
|
67
|
|
|
return $this->_completed; |
|
68
|
|
|
} |
|
69
|
|
|
$entry = $this->RelevantLogEntry($order); |
|
70
|
|
View Code Duplication |
if (! $entry) { |
|
|
|
|
|
|
71
|
|
|
$className = $this->relevantLogEntryClassName; |
|
72
|
|
|
$entry = $className::create(); |
|
73
|
|
|
$entry->OrderID = $order->ID; |
|
74
|
|
|
$entry->write(); |
|
75
|
|
|
} |
|
76
|
|
|
$entry->assessCustomer(); |
|
77
|
|
|
$this->_completed = true; |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
return $this->_completed; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
*nextStep: |
|
84
|
|
|
* returns the next step (after it checks if everything is in place for the next step to run...). |
|
85
|
|
|
* |
|
86
|
|
|
* @see Order::doNextStatus |
|
87
|
|
|
* |
|
88
|
|
|
* @param Order $order |
|
89
|
|
|
* |
|
90
|
|
|
* @return OrderStep | Null (next step OrderStep object) |
|
|
|
|
|
|
91
|
|
|
**/ |
|
92
|
|
|
public function nextStep(Order $order) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($this->doStep($order)) { |
|
95
|
|
|
return parent::nextStep($order); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* For some ordersteps this returns true... |
|
103
|
|
|
* |
|
104
|
|
|
* @return bool |
|
105
|
|
|
**/ |
|
106
|
|
|
protected function hasCustomerMessage() |
|
107
|
|
|
{ |
|
108
|
|
|
return false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Explains the current order step. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function myDescription() |
|
117
|
|
|
{ |
|
118
|
|
|
return 'Whitelist a customer if they qualify for this.'; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function HideFromEveryone() |
|
122
|
|
|
{ |
|
123
|
|
|
return true; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.