1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class RepeatOrderModifier extends OrderModifier |
4
|
|
|
{ |
5
|
|
|
public static $singular_name = "Repeat Order Modifier"; |
6
|
|
|
public function i18n_singular_name() |
7
|
|
|
{ |
8
|
|
|
return _t("RepeatOrderModifier.REPEATORDERMODIFIER", "Repeat Order Modifier"); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
public static $plural_name = "Repeat Order Modifiers"; |
12
|
|
|
public function i18n_plural_name() |
13
|
|
|
{ |
14
|
|
|
return _t("RepeatOrderModifier.REPEATORDERMODIFIERS", "Repeat Order Modifiers"); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* standard OrderModifier Method |
19
|
|
|
* Should we show a form in the checkout page for this modifier? |
20
|
|
|
*/ |
21
|
|
|
public function ShowForm() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
return $this->Order()->Items(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getModifierForm(Controller $optionalController = NULL, Validator $optionalValidator = NULL) |
27
|
|
|
{ |
28
|
|
|
$fields = FieldList::create(); |
29
|
|
|
$actions = null; |
30
|
|
|
$fields->push($this->headingField()); |
31
|
|
|
$fields->push($this->descriptionField()); |
32
|
|
|
$order = ShoppingCart::current_order(); |
33
|
|
|
$currentMember = Member::currentUser(); |
34
|
|
|
|
35
|
|
|
$repeatOrder = null; |
36
|
|
|
if($order && $order->exists()) { |
37
|
|
|
$orderID = $order->ID; |
38
|
|
|
$repeatOrder = DataObject::get_one('RepeatOrder', ['OriginatingOrderID' => $order->ID]); |
39
|
|
|
} else { |
40
|
|
|
$orderID = 0; |
41
|
|
|
} |
42
|
|
|
$createLink = RepeatOrdersPage::get_repeat_order_link('createorder', $orderID); |
43
|
|
|
$allowNonMembers = Config::inst()->get('RepeatOrder', 'allow_non_members'); |
44
|
|
|
|
45
|
|
|
if (($repeatOrder && $currentMember) || ($repeatOrder && $allowNonMembers)) { |
46
|
|
|
|
47
|
|
|
$updateLink = RepeatOrdersPage::get_repeat_order_link('modify', $repeatOrder->ID); |
48
|
|
|
$cancelLink = RepeatOrdersPage::get_repeat_order_link('cancel', $repeatOrder->ID); |
|
|
|
|
49
|
|
|
|
50
|
|
|
if ($repeatOrder->canModify()) { |
51
|
|
|
$fields->push( |
52
|
|
|
LiteralField::create( |
53
|
|
|
'modifyRepeatOrder', |
54
|
|
|
<<<HTML |
55
|
|
|
<div class="Actions"> |
56
|
|
|
<input id="ModifyRepeatOrderUpdate" class="action" type="button" value="Edit your associated Repeat Order" onclick="window.location='{$updateLink}';" /> |
57
|
|
|
</div> |
58
|
|
|
HTML |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
} else { |
62
|
|
|
$fields->push( |
63
|
|
|
LiteralField::create( |
64
|
|
|
'createRepeatOrder', |
65
|
|
|
<<<HTML |
66
|
|
|
<div class="Actions"> |
67
|
|
|
<input id="ModifyRepeatOrderCreate" class="action" type="button" value="Create a new Repeat Order" onclick="window.location='{$createLink}';" /> |
68
|
|
|
</div> |
69
|
|
|
HTML |
70
|
|
|
) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
Requirements::customScript("jQuery(document).ready(function(){jQuery(\"input[name='action_processOrder']\").hide();});", "hide_action_processOrder"); |
74
|
|
|
} elseif ($currentMember || $allowNonMembers) { |
75
|
|
|
if ($order->RepeatOrderID) { |
76
|
|
|
$fields->push( |
77
|
|
|
LiteralField::create( |
78
|
|
|
"whatAreRepeatOrders", |
79
|
|
|
<<<HTML |
80
|
|
|
<div id="WhatAreRepeatOrders">This order is based on a Repeat Order.</div> |
81
|
|
|
HTML |
82
|
|
|
)); |
83
|
|
|
} else { |
84
|
|
|
$repeatOrderFormFields = RepeatOrderForm::repeatOrderFormFields(0, $orderID); |
85
|
|
|
foreach ($repeatOrderFormFields as $repeatOrderFormField) { |
86
|
|
|
$fields->push( |
87
|
|
|
$repeatOrderFormField |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$repeatOrderFormLink = RepeatOrdersPage::get_repeat_order_link('ajaxcreateorder', $orderID); |
92
|
|
|
$fields->push( |
93
|
|
|
HiddenField::create('AjaxSubmissionLink', 'AjaxSubmissionLink', $repeatOrderFormLink) |
94
|
|
|
); |
95
|
|
|
$page = DataObject::get_one("RepeatOrdersPage"); |
96
|
|
|
if ($page) { |
97
|
|
|
$fields->push( |
98
|
|
|
LiteralField::create("whatAreRepeatOrders", |
99
|
|
|
<<<HTML |
100
|
|
|
<div id="WhatAreRepeatOrders">$page->WhatAreRepeatOrders</div> |
101
|
|
|
HTML |
102
|
|
|
)); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$actions = RepeatOrderForm::repeatOrderFormActions('Confirm and Pay'); |
106
|
|
|
|
107
|
|
|
//required fields |
108
|
|
|
$requiredArray = array('Start', 'Period'); |
109
|
|
|
$optionalValidator = RequiredFields::create($requiredArray); |
110
|
|
|
} |
111
|
|
|
} else { |
112
|
|
|
$page = DataObject::get_one("RepeatOrdersPage"); |
113
|
|
|
if ($page) { |
114
|
|
|
$fields->push( |
115
|
|
|
LiteralField::create( |
116
|
|
|
"whatAreRepeatOrders", |
117
|
|
|
<<<HTML |
118
|
|
|
<div id="WhatAreRepeatOrders">$page->OnceLoggedInYouCanCreateRepeatOrder</div> |
119
|
|
|
HTML |
120
|
|
|
)); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if($actions === NULL){ |
125
|
|
|
$actions = FieldList::create(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return RepeatOrderModifierForm::create( |
129
|
|
|
$optionalController, |
130
|
|
|
'RepeatOrderModifier', |
131
|
|
|
$fields, |
132
|
|
|
$actions, |
133
|
|
|
$optionalValidator |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function LiveCalculatedTotal() |
138
|
|
|
{ |
139
|
|
|
return 0; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function CanBeRemoved() |
143
|
|
|
{ |
144
|
|
|
return false; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function ShowInTable() |
148
|
|
|
{ |
149
|
|
|
return false; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function LiveName() |
153
|
|
|
{ |
154
|
|
|
return ''; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* retursn and array like this: array(Title => "bla", Link => "/doit/now/"); |
159
|
|
|
* This will be shown on the confirmation page.... |
160
|
|
|
* @return Array |
|
|
|
|
161
|
|
|
*/ |
162
|
|
|
public function PostSubmitAction() |
163
|
|
|
{ |
164
|
|
|
$order = $this->Order(); |
165
|
|
|
if($order && $order->exists()) { |
166
|
|
|
if ($order->MemberID) { |
167
|
|
|
if($order->RepeatOrderID) { |
168
|
|
|
return array( |
169
|
|
|
"Title" => _t("RepeatOrder.MODIFYORDER", "Edit repeating order"), |
170
|
|
|
"Link" => RepeatOrdersPage::get_repeat_order_link("view", $order->RepeatOrderID) |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
$existingRepeatOrder = RepeatOrder::get()->filter(['OriginatingOrderID' => $order->ID])->first(); |
174
|
|
|
if($existingRepeatOrder && $existingRepeatOrder->exists()) { |
175
|
|
|
return array( |
176
|
|
|
"Title" => _t("RepeatOrder.MODIFYORDER", "Edit repeating order"), |
177
|
|
|
"Link" => RepeatOrdersPage::get_repeat_order_link("modify", $existingRepeatOrder->ID) |
178
|
|
|
); |
179
|
|
|
} else { |
180
|
|
|
return array( |
181
|
|
|
"Title" => _t("RepeatOrder.CREATEREPEATEORDER", "Turn this Order into a Repeat Order"), |
182
|
|
|
"Link" => RepeatOrdersPage::get_repeat_order_link("createorder", $this->Order()->ID) |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.