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