1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* OrderStatusLog_Submitted is an important class that is created when an order is submitted. |
6
|
|
|
* It is created by the order and it signifies to the OrderStep to continue to the next step. |
7
|
|
|
* |
8
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
9
|
|
|
* @package: ecommerce |
10
|
|
|
* @sub-package: model |
11
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
12
|
|
|
**/ |
13
|
|
|
class OrderStatusLog_Submitted extends OrderStatusLog |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
private static $db = array( |
|
|
|
|
16
|
|
|
'OrderAsHTML' => 'HTMLText', |
17
|
|
|
'OrderAsString' => 'Text', |
18
|
|
|
'SequentialOrderNumber' => 'Int', |
19
|
|
|
'Total' => 'Currency', |
20
|
|
|
'SubTotal' => 'Currency', |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
private static $defaults = array( |
|
|
|
|
24
|
|
|
'InternalUseOnly' => true, |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
private static $casting = array( |
|
|
|
|
28
|
|
|
'HTMLRepresentation' => 'HTMLText', |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
private static $singular_name = 'Submitted Order'; |
|
|
|
|
32
|
|
|
public function i18n_singular_name() |
33
|
|
|
{ |
34
|
|
|
return _t('OrderStatusLog.SUBMITTEDORDER', 'Submitted Order - Fulltext Backup'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private static $plural_name = 'Submitted Orders'; |
|
|
|
|
38
|
|
|
public function i18n_plural_name() |
39
|
|
|
{ |
40
|
|
|
return _t('OrderStatusLog.SUBMITTEDORDERS', 'Submitted Orders - Fulltext Backup'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Standard SS variable. |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private static $description = 'The record that the order has been submitted by the customer. This is important in e-commerce, because from here, nothing can change to the order.'; |
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Standard SS method. |
52
|
|
|
* |
53
|
|
|
* @param Member $member |
|
|
|
|
54
|
|
|
* |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function canDelete($member = null) |
58
|
|
|
{ |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Standard SS method. |
64
|
|
|
* |
65
|
|
|
* @param Member $member |
|
|
|
|
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function canEdit($member = null) |
70
|
|
|
{ |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Standard SS method. |
76
|
|
|
* |
77
|
|
|
* @param Member $member |
|
|
|
|
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
public function canCreate($member = null) |
82
|
|
|
{ |
83
|
|
|
if (! $member) { |
84
|
|
|
$member = Member::currentUser(); |
85
|
|
|
} |
86
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
|
|
|
87
|
|
|
if ($extended !== null) { |
88
|
|
|
return $extended; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* can only be created when the order is submitted. |
96
|
|
|
* |
97
|
|
|
*@return string |
98
|
|
|
**/ |
99
|
|
|
public function HTMLRepresentation() |
100
|
|
|
{ |
101
|
|
|
return $this->getHTMLRepresentation(); |
102
|
|
|
} |
103
|
|
|
public function getHTMLRepresentation() |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
if ($this->OrderAsHTML) { |
|
|
|
|
106
|
|
|
return $this->OrderAsHTML; |
|
|
|
|
107
|
|
|
} elseif ($this->OrderAsString) { |
|
|
|
|
108
|
|
|
return unserialize($this->OrderAsString); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return _t('OrderStatusLog.NO_FURTHER_INFO_AVAILABLE', 'no further information available'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* adding a sequential order number. |
116
|
|
|
*/ |
117
|
|
|
public function onBeforeWrite() |
118
|
|
|
{ |
119
|
|
|
parent::onBeforeWrite(); |
120
|
|
|
if ($order = $this->Order()) { |
|
|
|
|
121
|
|
|
if (!$this->Total) { |
|
|
|
|
122
|
|
|
$this->Total = $order->Total(); |
|
|
|
|
123
|
|
|
$this->SubTotal = $order->SubTotal(); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
if (!intval($this->SequentialOrderNumber)) { |
|
|
|
|
127
|
|
|
$this->SequentialOrderNumber = 1; |
|
|
|
|
128
|
|
|
$min = intval(EcommerceConfig::get('Order', 'order_id_start_number')) - 0; |
129
|
|
|
if (isset($this->ID)) { |
130
|
|
|
$id = intval($this->ID); |
131
|
|
|
} else { |
132
|
|
|
$id = 0; |
133
|
|
|
} |
134
|
|
|
$lastOne = DataObject::get_one( |
135
|
|
|
'OrderStatusLog_Submitted', |
136
|
|
|
'\'ID\' != \''.$id.'\'', |
137
|
|
|
$cache = true, |
138
|
|
|
array('SequentialOrderNumber' => 'DESC') |
|
|
|
|
139
|
|
|
); |
140
|
|
|
if ($lastOne) { |
141
|
|
|
$this->SequentialOrderNumber = intval($lastOne->SequentialOrderNumber) + 1; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
if (intval($min) && $this->SequentialOrderNumber < $min) { |
|
|
|
|
144
|
|
|
$this->SequentialOrderNumber = $min; |
|
|
|
|
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
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.