|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
5
|
|
|
* @package: ecommerce |
|
6
|
|
|
* @sub-package: model |
|
7
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
8
|
|
|
**/ |
|
9
|
|
|
class OrderStep_SecurityCheck extends OrderStep implements OrderStepInterface |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
12
|
|
|
'CustomerCanEdit' => 0, |
|
13
|
|
|
'CustomerCanCancel' => 0, |
|
14
|
|
|
'CustomerCanPay' => 0, |
|
15
|
|
|
'Name' => 'Security Check for Order', |
|
16
|
|
|
'Code' => 'SECURITY_CHECK', |
|
17
|
|
|
'ShowAsInProcessOrder' => 1, |
|
18
|
|
|
'HideStepFromCustomer' => 1 |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The OrderStatusLog that is relevant to the particular step. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $relevantLogEntryClassName = 'OrderStatusLog_SecurityCheck'; |
|
27
|
|
|
|
|
28
|
|
|
public function getCMSFields() |
|
29
|
|
|
{ |
|
30
|
|
|
$fields = parent::getCMSFields(); |
|
31
|
|
|
|
|
32
|
|
|
return $fields; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
*initStep: |
|
37
|
|
|
* makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
|
38
|
|
|
* should be able to run this function many times to check if the step is ready. |
|
39
|
|
|
* |
|
40
|
|
|
* @see Order::doNextStatus |
|
41
|
|
|
* |
|
42
|
|
|
* @param Order object |
|
43
|
|
|
* |
|
44
|
|
|
* @return bool - true if the current step is ready to be run... |
|
45
|
|
|
**/ |
|
46
|
|
|
public function initStep(Order $order) |
|
47
|
|
|
{ |
|
48
|
|
|
$logCount = $this->RelevantLogEntries($order)->count(); |
|
49
|
|
View Code Duplication |
if ($logCount) { |
|
|
|
|
|
|
50
|
|
|
//do nothing |
|
51
|
|
|
} else { |
|
52
|
|
|
$className = $this->relevantLogEntryClassName; |
|
53
|
|
|
$object = $className::create(); |
|
54
|
|
|
$object->OrderID = $order->ID; |
|
55
|
|
|
$object->write(); |
|
56
|
|
|
} |
|
57
|
|
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private static $_passed = null; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
*doStep: |
|
64
|
|
|
* should only be able to run this function once |
|
65
|
|
|
* (init stops you from running it twice - in theory....) |
|
66
|
|
|
* runs the actual step. |
|
67
|
|
|
* |
|
68
|
|
|
* @see Order::doNextStatus |
|
69
|
|
|
* |
|
70
|
|
|
* @param Order object |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool - true if run correctly. |
|
73
|
|
|
**/ |
|
74
|
|
|
public function doStep(Order $order) |
|
75
|
|
|
{ |
|
76
|
|
|
if (self::$_passed !== null) { |
|
77
|
|
|
return self::$_passed; |
|
78
|
|
|
} |
|
79
|
|
|
if ($entry = $this->RelevantLogEntry($order)) { |
|
80
|
|
|
self::$_passed = $entry->pass(); |
|
81
|
|
|
return self::$_passed; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
*nextStep: |
|
87
|
|
|
* returns the next step (after it checks if everything is in place for the next step to run...). |
|
88
|
|
|
* |
|
89
|
|
|
* @see Order::doNextStatus |
|
90
|
|
|
* |
|
91
|
|
|
* @param Order $order |
|
92
|
|
|
* |
|
93
|
|
|
* @return OrderStep | Null (next step OrderStep object) |
|
|
|
|
|
|
94
|
|
|
**/ |
|
95
|
|
|
public function nextStep(Order $order) |
|
96
|
|
|
{ |
|
97
|
|
|
if ($this->doStep($order)) { |
|
98
|
|
|
return parent::nextStep($order); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
private static $_my_order = null; |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Allows the opportunity for the Order Step to add any fields to Order::getCMSFields. |
|
108
|
|
|
* |
|
109
|
|
|
* @param FieldList $fields |
|
110
|
|
|
* @param Order $order |
|
111
|
|
|
* |
|
112
|
|
|
* @return FieldList |
|
113
|
|
|
**/ |
|
114
|
|
|
public function addOrderStepFields(FieldList $fields, Order $order) |
|
115
|
|
|
{ |
|
116
|
|
|
$fields = parent::addOrderStepFields($fields, $order); |
|
117
|
|
|
$title = _t('OrderStep.MUST_ACTION_SECURITY_CHECKS', ' ... To move this order to the next step you have to carry out a bunch of security checks.'); |
|
118
|
|
|
$field = $order->getOrderStatusLogsTableFieldEditable('OrderStatusLog_SecurityCheck', $title); |
|
119
|
|
|
$logEntry = $this->RelevantLogEntry($order); |
|
120
|
|
|
$link = '/admin/sales/Order/EditForm/field/Order/item/'.$order->ID.'/ItemEditForm/field/OrderStatusLog_SecurityCheck/item/'.$logEntry->ID.'/edit'; |
|
121
|
|
|
$button = EcommerceCMSButtonField::create( |
|
122
|
|
|
'OrderStatusLog_SecurityCheck_Button', |
|
123
|
|
|
$link, |
|
124
|
|
|
'Open Security Checks' |
|
125
|
|
|
); |
|
126
|
|
|
$fields->addFieldsToTab('Root.Next', array($button, $field), 'ActionNextStepManually'); |
|
127
|
|
|
|
|
128
|
|
|
return $fields; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* For some ordersteps this returns true... |
|
134
|
|
|
* |
|
135
|
|
|
* @return bool |
|
136
|
|
|
**/ |
|
137
|
|
|
protected function hasCustomerMessage() |
|
138
|
|
|
{ |
|
139
|
|
|
return false; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Explains the current order step. |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
protected function myDescription() |
|
148
|
|
|
{ |
|
149
|
|
|
return 'Make sure that the Order is safe to proceed'; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
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.