1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class OrderStepFeefo extends OrderStep |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* The OrderStatusLog that is relevant to the particular step. |
10
|
|
|
* |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $relevantLogEntryClassName = 'OrderStatusLog_FeefoLog'; |
14
|
|
|
|
15
|
|
|
private static $db = array( |
|
|
|
|
16
|
|
|
'SendData' => 'Boolean', |
17
|
|
|
'FeedbackDelay' => 'Int' |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
private static $defaults = array( |
|
|
|
|
22
|
|
|
'CustomerCanEdit' => 0, |
23
|
|
|
'CustomerCanCancel' => 0, |
24
|
|
|
'CustomerCanPay' => 0, |
25
|
|
|
'Name' => 'Send Order To Feefo', |
26
|
|
|
'Code' => 'FEEFO', |
27
|
|
|
"ShowAsInProcessOrder" => true, |
28
|
|
|
"HideStepFromCustomer" => true |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
public function getCMSFields() |
33
|
|
|
{ |
34
|
|
|
$fields = parent::getCMSFields(); |
35
|
|
|
$fields->removeByName('FeedbackDelay'); |
36
|
|
|
|
37
|
|
|
$fields->addFieldsToTab( |
38
|
|
|
'Root.Feefo', |
39
|
|
|
[ |
40
|
|
|
CheckboxField::create( |
41
|
|
|
'SendData', |
42
|
|
|
'Send Data' |
43
|
|
|
)->setDescription('If checked then the order data will be sent to Feefo, once this order step is reached.'), |
44
|
|
|
NumericField::create( |
45
|
|
|
'FeedbackDelay', |
46
|
|
|
'Feedback Delay' |
47
|
|
|
)->setRightTitle('The amount of after the order has been sent before Feefo should send the feedback request email.') |
48
|
|
|
] |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
return $fields; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function initStep(Order $order) |
56
|
|
|
{ |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function doStep(Order $order) |
61
|
|
|
{ |
62
|
|
|
if ($this->SendData && $order->IsPaid()) { |
|
|
|
|
63
|
|
|
$api = Injector::inst()->get('EntersaleremotelyAPIConnector'); |
64
|
|
|
|
65
|
|
|
$result = $api->sendOrderDataToFeefo($order, $this->FeedbackDelay); |
|
|
|
|
66
|
|
|
$result = $this->convertArrayToHTMLList($result); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
$className = $this->getRelevantLogEntryClassName(); |
71
|
|
|
|
72
|
|
|
if (class_exists($className)) { |
73
|
|
|
$obj = $className::create(); |
74
|
|
|
if (is_a($obj, Object::getCustomClass('OrderStatusLog'))) { |
75
|
|
|
$obj->OrderID = $order->ID; |
76
|
|
|
$obj->Title = $this->Name; |
|
|
|
|
77
|
|
|
$obj->DetailedInfo = $result; |
78
|
|
|
$obj->write(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return true; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* can continue if emails has been sent or if there is no need to send a receipt. |
88
|
|
|
* @param DataObject $order Order |
89
|
|
|
* @return DataObject | Null - DataObject = next OrderStep |
|
|
|
|
90
|
|
|
**/ |
91
|
|
|
public function nextStep(Order $order) |
92
|
|
|
{ |
93
|
|
|
return parent::nextStep($order); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* For some ordersteps this returns true... |
98
|
|
|
* @return Boolean |
99
|
|
|
**/ |
100
|
|
|
protected function hasCustomerMessage() |
101
|
|
|
{ |
102
|
|
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Explains the current order step. |
107
|
|
|
* @return String |
108
|
|
|
*/ |
109
|
|
|
protected function myDescription() |
110
|
|
|
{ |
111
|
|
|
return "The customer and order data is sent to Feefo via the Entersaleremotely API."; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function convertArrayToHTMLList($array) |
115
|
|
|
{ |
116
|
|
|
$html = '<ul>'; |
117
|
|
|
foreach ($array as $arrayItem) { |
118
|
|
|
$html .= '<li>' . $arrayItem . '</li>'; |
119
|
|
|
} |
120
|
|
|
$html .= '</ul>'; |
121
|
|
|
return $html; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
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.