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
|
|
|
public static $show_post_submit_actions = false; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* standard OrderModifier Method |
21
|
|
|
* Should we show a form in the checkout page for this modifier? |
22
|
|
|
*/ |
23
|
|
|
public function ShowForm() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
return $this->Order()->Items(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getModifierForm(Controller $optionalController = NULL, Validator $optionalValidator = NULL) |
29
|
|
|
{ |
30
|
|
|
$showCreateRepeatOrderForm = false; |
31
|
|
|
$fields = FieldList::create(); |
32
|
|
|
$actions = null; |
33
|
|
|
$fields->push($this->headingField()); |
34
|
|
|
$fields->push($this->descriptionField()); |
35
|
|
|
$order = ShoppingCart::current_order(); |
36
|
|
|
$currentMember = Member::currentUser(); |
37
|
|
|
|
38
|
|
|
$repeatOrder = null; |
39
|
|
|
if($order && $order->exists()) { |
40
|
|
|
$orderID = $order->ID; |
41
|
|
|
$repeatOrder = DataObject::get_one('RepeatOrder', ['OriginatingOrderID' => $order->ID]); |
42
|
|
|
} else { |
43
|
|
|
$orderID = 0; |
44
|
|
|
} |
45
|
|
|
$createLink = RepeatOrdersPage::get_repeat_order_link('createorder', $orderID); |
|
|
|
|
46
|
|
|
$allowNonMembers = Config::inst()->get('RepeatOrder', 'allow_non_members'); |
47
|
|
|
|
48
|
|
|
if (($repeatOrder && $currentMember) || ($repeatOrder && $allowNonMembers)) { |
49
|
|
|
if ($repeatOrder->canModify()) { |
50
|
|
|
$repeatOrderFormFields = RepeatOrderForm::repeatOrderFormFields($repeatOrder->ID, $orderID, true); |
51
|
|
|
foreach ($repeatOrderFormFields as $repeatOrderFormField) { |
52
|
|
|
$fields->push( |
53
|
|
|
$repeatOrderFormField |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$cancelRepeatOrderLink = RepeatOrdersPage::get_repeat_order_link('ajaxcheckoutcancel', $repeatOrder->ID); |
58
|
|
|
$fields->push( |
59
|
|
|
HiddenField::create('AjaxCancelLink', 'AjaxCancelLink', $cancelRepeatOrderLink) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$actions = RepeatOrderForm::repeatOrderFormActions('Update', $repeatOrder); |
63
|
|
|
$actions->push( |
64
|
|
|
FormAction::create('doCancel', 'Cancel Subscription') |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
else { |
68
|
|
|
$showCreateRepeatOrderForm = true; |
69
|
|
|
} |
70
|
|
|
Requirements::customScript("jQuery(document).ready(function(){jQuery(\"input[name='action_processOrder']\").hide();});", "hide_action_processOrder"); |
71
|
|
|
} elseif ($currentMember || $allowNonMembers) { |
72
|
|
|
//this shouldn't actually happen as the repeat order should have been found and used in the previous if statement |
73
|
|
|
if ($order->RepeatOrderID) { |
74
|
|
|
$fields->push( |
75
|
|
|
LiteralField::create( |
76
|
|
|
"whatAreRepeatOrders", |
77
|
|
|
'<div id="WhatAreRepeatOrders">This order is based on a Repeat Order.</div>' |
78
|
|
|
) |
79
|
|
|
); |
80
|
|
|
} else { |
81
|
|
|
$showCreateRepeatOrderForm = true; |
82
|
|
|
} |
83
|
|
|
} else { |
84
|
|
|
$page = DataObject::get_one("RepeatOrdersPage"); |
85
|
|
|
if ($page) { |
86
|
|
|
$fields->push( |
87
|
|
|
LiteralField::create( |
88
|
|
|
"whatAreRepeatOrders", |
89
|
|
|
'<div id="WhatAreRepeatOrders">' . $page->OnceLoggedInYouCanCreateRepeatOrder . '</div>' |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if($showCreateRepeatOrderForm){ |
96
|
|
|
$repeatOrderFormFields = RepeatOrderForm::repeatOrderFormFields(0, $orderID); |
97
|
|
|
foreach ($repeatOrderFormFields as $repeatOrderFormField) { |
98
|
|
|
$fields->push( |
99
|
|
|
$repeatOrderFormField |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$page = DataObject::get_one("RepeatOrdersPage"); |
104
|
|
|
if ($page) { |
105
|
|
|
$fields->push( |
106
|
|
|
LiteralField::create("whatAreRepeatOrders", |
107
|
|
|
'<div id="WhatAreRepeatOrders">' . $page->WhatAreRepeatOrders . '</div>' |
108
|
|
|
) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$actions = RepeatOrderForm::repeatOrderFormActions('Confirm and Pay'); |
113
|
|
|
|
114
|
|
|
//required fields |
115
|
|
|
$requiredArray = array('Start', 'Period'); |
116
|
|
|
$optionalValidator = RequiredFields::create($requiredArray); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if($actions === NULL){ |
120
|
|
|
$actions = FieldList::create(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return RepeatOrderModifierForm::create( |
124
|
|
|
$optionalController, |
125
|
|
|
'RepeatOrderModifier', |
126
|
|
|
$fields, |
127
|
|
|
$actions, |
128
|
|
|
$optionalValidator |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function LiveCalculatedTotal() |
133
|
|
|
{ |
134
|
|
|
return 0; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function CanBeRemoved() |
138
|
|
|
{ |
139
|
|
|
return false; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function ShowInTable() |
143
|
|
|
{ |
144
|
|
|
return false; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function LiveName() |
148
|
|
|
{ |
149
|
|
|
return ''; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* retursn and array like this: array(Title => "bla", Link => "/doit/now/"); |
154
|
|
|
* This will be shown on the confirmation page.... |
155
|
|
|
* @return Array |
|
|
|
|
156
|
|
|
*/ |
157
|
|
|
public function PostSubmitAction() |
158
|
|
|
{ |
159
|
|
|
if($this->config()->get('$show_post_submit_actions')){ |
160
|
|
|
$order = $this->Order(); |
161
|
|
|
if($order && $order->exists()) { |
162
|
|
|
if ($order->MemberID) { |
163
|
|
|
if($order->RepeatOrderID) { |
164
|
|
|
return array( |
165
|
|
|
"Title" => _t("RepeatOrder.MODIFYORDER", "Edit repeating order"), |
166
|
|
|
"Link" => RepeatOrdersPage::get_repeat_order_link("view", $order->RepeatOrderID) |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
$existingRepeatOrder = RepeatOrder::get()->filter(['OriginatingOrderID' => $order->ID])->first(); |
170
|
|
|
if($existingRepeatOrder && $existingRepeatOrder->exists()) { |
171
|
|
|
return array( |
172
|
|
|
"Title" => _t("RepeatOrder.MODIFYORDER", "Edit repeating order"), |
173
|
|
|
"Link" => RepeatOrdersPage::get_repeat_order_link("modify", $existingRepeatOrder->ID) |
174
|
|
|
); |
175
|
|
|
} else { |
176
|
|
|
return array( |
177
|
|
|
"Title" => _t("RepeatOrder.CREATEREPEATEORDER", "Turn this Order into a Repeat Order"), |
178
|
|
|
"Link" => RepeatOrdersPage::get_repeat_order_link("createorder", $this->Order()->ID) |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
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.