|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This is the first Order Step. |
|
6
|
|
|
* |
|
7
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
8
|
|
|
* @package: ecommerce |
|
9
|
|
|
* @sub-package: model |
|
10
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
11
|
|
|
**/ |
|
12
|
|
|
class OrderStep_Created extends OrderStep implements OrderStepInterface |
|
13
|
|
|
{ |
|
14
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
15
|
|
|
'CustomerCanEdit' => 1, |
|
16
|
|
|
'CustomerCanPay' => 1, |
|
17
|
|
|
'CustomerCanCancel' => 1, |
|
18
|
|
|
'Name' => 'Create', |
|
19
|
|
|
'Code' => 'CREATED', |
|
20
|
|
|
'ShowAsUncompletedOrder' => 1, |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
*initStep: |
|
25
|
|
|
* makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
|
26
|
|
|
* should be able to run this function many times to check if the step is ready. |
|
27
|
|
|
* |
|
28
|
|
|
* @see Order::doNextStatus |
|
29
|
|
|
* |
|
30
|
|
|
* @param Order object |
|
31
|
|
|
* |
|
32
|
|
|
* @return bool - true if the current step is ready to be run... |
|
33
|
|
|
**/ |
|
34
|
|
|
public function initStep(Order $order) |
|
35
|
|
|
{ |
|
36
|
|
|
return true; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Add the member to the order, in case the member is not an admin. |
|
41
|
|
|
* |
|
42
|
|
|
* @param DataObject - $order Order |
|
43
|
|
|
* |
|
44
|
|
|
* @return bool |
|
45
|
|
|
**/ |
|
46
|
|
|
public function doStep(Order $order) |
|
47
|
|
|
{ |
|
48
|
|
|
if (!$order->MemberID) { |
|
|
|
|
|
|
49
|
|
|
$member = Member::currentUser(); |
|
50
|
|
|
if ($member) { |
|
51
|
|
|
if (!$member->IsShopAdmin()) { |
|
52
|
|
|
$order->MemberID = $member->ID(); |
|
|
|
|
|
|
53
|
|
|
$order->write(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* We can run the next step, once any items have been added. |
|
63
|
|
|
* |
|
64
|
|
|
* @see Order::doNextStatus |
|
65
|
|
|
* |
|
66
|
|
|
* @param Order $order |
|
67
|
|
|
* |
|
68
|
|
|
* @return OrderStep | Null (next step OrderStep object) |
|
|
|
|
|
|
69
|
|
|
**/ |
|
70
|
|
|
public function nextStep(Order $order) |
|
71
|
|
|
{ |
|
72
|
|
|
if ($order->TotalItems($recalculate = true)) { |
|
73
|
|
|
return parent::nextStep($order); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Allows the opportunity for the Order Step to add any fields to Order::getCMSFields. |
|
81
|
|
|
* |
|
82
|
|
|
*@param FieldList $fields |
|
83
|
|
|
*@param Order $order |
|
84
|
|
|
* |
|
85
|
|
|
*@return FieldList |
|
86
|
|
|
**/ |
|
87
|
|
|
public function addOrderStepFields(FieldList $fields, Order $order) |
|
88
|
|
|
{ |
|
89
|
|
|
$fields = parent::addOrderStepFields($fields, $order); |
|
90
|
|
|
if (!$order->IsSubmitted()) { |
|
91
|
|
|
//LINE BELOW IS NOT REQUIRED |
|
92
|
|
|
$header = _t('OrderStep.SUBMITORDER', 'Submit Order'); |
|
93
|
|
|
$label = _t('OrderStep.SUBMITNOW', 'Submit Now'); |
|
94
|
|
|
$msg = _t('OrderStep.MUSTDOSUBMITRECORD', '<p>Tick the box below to submit this order.</p>'); |
|
95
|
|
|
$problems = array(); |
|
96
|
|
|
if (!$order->getTotalItems()) { |
|
97
|
|
|
$problems[] = 'There are no --- Order Items (products) --- associated with this order.'; |
|
98
|
|
|
} |
|
99
|
|
|
if (!$order->MemberID) { |
|
|
|
|
|
|
100
|
|
|
$problems[] = 'There is no --- Customer --- associated with this order.'; |
|
101
|
|
|
} |
|
102
|
|
|
if (!$order->BillingAddressID) { |
|
|
|
|
|
|
103
|
|
|
$problems[] = 'There is no --- Billing Address --- associated with this order.'; |
|
104
|
|
|
} elseif ($billingAddress = $order->BillingAddress()) { |
|
|
|
|
|
|
105
|
|
|
$requiredBillingFields = $billingAddress->getRequiredFields(); |
|
106
|
|
|
if ($requiredBillingFields && is_array($requiredBillingFields) && count($requiredBillingFields)) { |
|
107
|
|
|
foreach ($requiredBillingFields as $requiredBillingField) { |
|
108
|
|
|
if (!$billingAddress->$requiredBillingField) { |
|
109
|
|
|
$problems[] = "There is no --- $requiredBillingField --- recorded in the billing address."; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
if (count($problems)) { |
|
115
|
|
|
$msg = '<p>You can not submit this order because:</p> <ul><li>'.implode('</li><li>', $problems).'</li></ul>'; |
|
116
|
|
|
} |
|
117
|
|
|
$fields->addFieldToTab('Root.Next', new HeaderField('CreateSubmitRecordHeader', $header, 3), 'ActionNextStepManually'); |
|
118
|
|
|
$fields->addFieldToTab('Root.Next', new LiteralField('CreateSubmitRecordMessage', $msg), 'ActionNextStepManually'); |
|
119
|
|
|
if (!$problems) { |
|
|
|
|
|
|
120
|
|
|
$fields->addFieldToTab('Root.Next', new CheckboxField('SubmitOrderViaCMS', $label), 'ActionNextStepManually'); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return $fields; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Explains the current order step. |
|
129
|
|
|
* |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function myDescription() |
|
133
|
|
|
{ |
|
134
|
|
|
return _t('OrderStep.CREATED_DESCRIPTION', 'During this step the customer creates her or his order. The shop admininistrator does not do anything during this step.'); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|