These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * CheckoutPage is a CMS page-type that shows the order |
||
5 | * details to the customer for their current shopping |
||
6 | * cart on the site. It also lets the customer review |
||
7 | * the items in their cart, and manipulate them (add more, |
||
8 | * deduct or remove items completely). The most important |
||
9 | * thing is that the {@link CheckoutPage_Controller} handles |
||
10 | * the {@link OrderForm} form instance, allowing the customer |
||
11 | * to fill out their shipping details, confirming their order |
||
12 | * and making a payment. |
||
13 | * |
||
14 | * @see CheckoutPage_Controller->Order() |
||
15 | * @see OrderForm |
||
16 | * @see CheckoutPage_Controller->OrderForm() |
||
17 | * |
||
18 | * The CheckoutPage_Controller is also responsible for setting |
||
19 | * up the modifier forms for each of the OrderModifiers that are |
||
20 | * enabled on the site (if applicable - some don't require a form |
||
21 | * for user input). A usual implementation of a modifier form would |
||
22 | * be something like allowing the customer to enter a discount code |
||
23 | * so they can receive a discount on their order. |
||
24 | * @see OrderModifier |
||
25 | * @see CheckoutPage_Controller->ModifierForms() |
||
26 | * |
||
27 | * TO DO: get rid of all the messages... |
||
28 | * |
||
29 | * @authors: Nicolaas [at] Sunny Side Up .co.nz |
||
30 | * @package: ecommerce |
||
31 | * @sub-package: Pages |
||
32 | * @inspiration: Silverstripe Ltd, Jeremy |
||
33 | **/ |
||
34 | class CheckoutPage extends CartPage |
||
35 | { |
||
36 | /** |
||
37 | * standard SS variable. |
||
38 | * |
||
39 | * @Var Boolean |
||
40 | */ |
||
41 | private static $hide_ancestor = 'CartPage'; |
||
42 | |||
43 | /** |
||
44 | * standard SS variable. |
||
45 | * |
||
46 | * @Var string |
||
47 | */ |
||
48 | private static $icon = 'ecommerce/images/icons/CheckoutPage'; |
||
49 | |||
50 | /** |
||
51 | * standard SS variable. |
||
52 | * |
||
53 | * @Var Array |
||
54 | */ |
||
55 | private static $db = array( |
||
56 | 'TermsAndConditionsMessage' => 'Varchar(200)', |
||
57 | ); |
||
58 | |||
59 | /** |
||
60 | * standard SS variable. |
||
61 | * |
||
62 | * @Var Array |
||
63 | */ |
||
64 | private static $has_one = array( |
||
65 | 'TermsPage' => 'Page', |
||
66 | ); |
||
67 | |||
68 | /** |
||
69 | * standard SS variable. |
||
70 | * |
||
71 | * @Var Array |
||
72 | */ |
||
73 | private static $defaults = array( |
||
74 | 'TermsAndConditionsMessage' => 'You must agree with the terms and conditions before proceeding.', |
||
75 | ); |
||
76 | |||
77 | /** |
||
78 | * standard SS variable. |
||
79 | * |
||
80 | * @Var String |
||
81 | */ |
||
82 | private static $singular_name = 'Checkout Page'; |
||
83 | public function i18n_singular_name() |
||
84 | { |
||
85 | return _t('CheckoutPage.SINGULARNAME', 'Checkout Page'); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * standard SS variable. |
||
90 | * |
||
91 | * @Var String |
||
92 | */ |
||
93 | private static $plural_name = 'Checkout Pages'; |
||
94 | public function i18n_plural_name() |
||
95 | { |
||
96 | return _t('CheckoutPage.PLURALNAME', 'Checkout Pages'); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Standard SS variable. |
||
101 | * |
||
102 | * @var string |
||
103 | */ |
||
104 | private static $description = 'A page where the customer can view the current order (cart) and finalise (submit) the order. Every e-commerce site needs an Order Confirmation Page.'; |
||
105 | |||
106 | /** |
||
107 | * Returns the Terms and Conditions Page (if there is one). |
||
108 | * |
||
109 | * @return Page | NULL |
||
110 | */ |
||
111 | public static function find_terms_and_conditions_page() |
||
112 | { |
||
113 | $checkoutPage = CheckoutPage::get()->First(); |
||
114 | if ($checkoutPage && $checkoutPage->TermsPageID) { |
||
115 | return Page::get()->byID($checkoutPage->TermsPageID); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Returns the link or the Link to the Checkout page on this site. |
||
121 | * |
||
122 | * @param string $action [optional] |
||
123 | * |
||
124 | * @return string (URLSegment) |
||
125 | */ |
||
126 | public static function find_link($action = null) |
||
127 | { |
||
128 | $page = CheckoutPage::get()->First(); |
||
129 | if ($page) { |
||
130 | return $page->Link($action); |
||
131 | } |
||
132 | user_error('No Checkout Page has been created - it is recommended that you create this page type for correct functioning of E-commerce.', E_USER_NOTICE); |
||
133 | |||
134 | return ''; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Returns the link or the Link to the Checkout page on this site |
||
139 | * for the last step. |
||
140 | * |
||
141 | * @param string $step |
||
142 | * |
||
143 | * @return string (URLSegment) |
||
144 | */ |
||
145 | public static function find_last_step_link($step = '') |
||
146 | { |
||
147 | if (!$step) { |
||
148 | $steps = EcommerceConfig::get('CheckoutPage_Controller', 'checkout_steps'); |
||
149 | if ($steps && count($steps)) { |
||
150 | $step = array_pop($steps); |
||
151 | } |
||
152 | } |
||
153 | if ($step) { |
||
154 | $step = 'checkoutstep/'.strtolower($step).'/#'.$step; |
||
155 | } |
||
156 | |||
157 | return self::find_link($step); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Returns the link to the next step. |
||
162 | * |
||
163 | * @param string - $currentStep is the step that has just been actioned.... |
||
164 | * @param bool - $doPreviousInstead - return previous rather than next step |
||
165 | * |
||
166 | * @return string (URLSegment) |
||
167 | */ |
||
168 | public static function find_next_step_link($currentStep, $doPreviousInstead = false) |
||
169 | { |
||
170 | $nextStep = null; |
||
171 | if ($link = self::find_link()) { |
||
172 | $steps = EcommerceConfig::get('CheckoutPage_Controller', 'checkout_steps'); |
||
173 | if (in_array($currentStep, $steps)) { |
||
174 | $key = array_search($currentStep, $steps); |
||
175 | if ($key !== false) { |
||
176 | if ($doPreviousInstead) { |
||
177 | --$key; |
||
178 | } else { |
||
179 | ++$key; |
||
180 | } |
||
181 | if (isset($steps[$key])) { |
||
182 | $nextStep = $steps[$key]; |
||
183 | } |
||
184 | } |
||
185 | } else { |
||
186 | if ($doPreviousInstead) { |
||
187 | $nextStep = array_shift($steps); |
||
188 | } else { |
||
189 | $nextStep = array_pop($steps); |
||
190 | } |
||
191 | } |
||
192 | if ($nextStep) { |
||
193 | return $link.'checkoutstep'.'/'.$nextStep.'/'; |
||
194 | } else { |
||
0 ignored issues
–
show
|
|||
195 | } |
||
196 | |||
197 | return $link; |
||
198 | } |
||
199 | |||
200 | return ''; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Returns the link to the checkout page on this site, using |
||
205 | * a specific Order ID that already exists in the database. |
||
206 | * |
||
207 | * @param int $orderID ID of the {@link Order} |
||
208 | * |
||
209 | * @return string Link to checkout page |
||
210 | */ |
||
211 | public static function get_checkout_order_link($orderID) |
||
212 | { |
||
213 | if ($page = self::find_link()) { |
||
214 | return $page->Link('showorder').'/'.$orderID.'/'; |
||
215 | } |
||
216 | |||
217 | return ''; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * Standard SS function, we only allow for one checkout page to exist |
||
222 | * but we do allow for extensions to exist at the same time. |
||
223 | * |
||
224 | * @param Member $member |
||
225 | * |
||
226 | * @return bool |
||
227 | **/ |
||
228 | public function canCreate($member = null) |
||
229 | { |
||
230 | return CheckoutPage::get()->Filter(array('ClassName' => 'CheckoutPage'))->Count() ? false : $this->canEdit($member); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Shop Admins can edit. |
||
235 | * |
||
236 | * @param Member $member |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | public function canEdit($member = null) |
||
241 | { |
||
242 | if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
||
243 | return true; |
||
244 | } |
||
245 | |||
246 | return parent::canEdit($member); |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * Standard SS method. |
||
251 | * |
||
252 | * @param Member $member |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | public function canDelete($member = null) |
||
257 | { |
||
258 | return false; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Standard SS method. |
||
263 | * |
||
264 | * @param Member $member |
||
265 | * |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function canPublish($member = null) |
||
269 | { |
||
270 | return $this->canEdit($member); |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Standard SS function. |
||
275 | * |
||
276 | * @return FieldList |
||
277 | **/ |
||
278 | public function getCMSFields() |
||
279 | { |
||
280 | $fields = parent :: getCMSFields(); |
||
281 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'ProceedToCheckoutLabel'); |
||
282 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'ContinueShoppingLabel'); |
||
283 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'ContinuePageID'); |
||
284 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'LoadOrderLinkLabel'); |
||
285 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'CurrentOrderLinkLabel'); |
||
286 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'SaveOrderLinkLabel'); |
||
287 | $fields->removeFieldFromTab('Root.Messages.Messages.Actions', 'DeleteOrderLinkLabel'); |
||
288 | $termsPageIDField = OptionalTreeDropdownField::create( |
||
289 | 'TermsPageID', |
||
290 | _t('CheckoutPage.TERMSANDCONDITIONSPAGE', 'Terms and conditions page'), |
||
291 | 'SiteTree' |
||
292 | ); |
||
293 | $termsPageIDField->setRightTitle(_t('CheckoutPage.TERMSANDCONDITIONSPAGE_RIGHT', 'This is optional. To remove this page clear the reminder message below.')); |
||
294 | $fields->addFieldToTab('Root.Terms', $termsPageIDField); |
||
295 | $fields->addFieldToTab( |
||
296 | 'Root.Terms', |
||
297 | $termsPageIDFieldMessage = new TextField( |
||
298 | 'TermsAndConditionsMessage', |
||
299 | _t('CheckoutPage.TERMSANDCONDITIONSMESSAGE', 'Reminder Message') |
||
300 | ) |
||
301 | ); |
||
302 | $termsPageIDFieldMessage->setRightTitle( |
||
303 | _t('CheckoutPage.TERMSANDCONDITIONSMESSAGE_RIGHT', "Shown if the user does not tick the 'I agree with the Terms and Conditions' box. Leave blank to allow customer to proceed without ticking this box") |
||
304 | ); |
||
305 | //The Content field has a slightly different meaning for the Checkout Page. |
||
306 | $fields->removeFieldFromTab('Root.Main', 'Content'); |
||
307 | $fields->addFieldToTab('Root.Messages.Messages.AlwaysVisible', $htmlEditorField = new HTMLEditorField('Content', _t('CheckoutPage.CONTENT', 'General note - always visible on the checkout page'))); |
||
308 | $htmlEditorField->setRows(3); |
||
309 | if (OrderModifier_Descriptor::get()->count()) { |
||
310 | $fields->addFieldToTab('Root.Messages.Messages.OrderExtras', $this->getOrderModifierDescriptionField()); |
||
311 | } |
||
312 | if (CheckoutPage_StepDescription::get()->count()) { |
||
313 | $fields->addFieldToTab('Root.Messages.Messages.CheckoutSteps', $this->getCheckoutStepDescriptionField()); |
||
314 | } |
||
315 | |||
316 | return $fields; |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * @return GridField |
||
321 | */ |
||
322 | protected function getOrderModifierDescriptionField() |
||
323 | { |
||
324 | $gridFieldConfig = GridFieldConfig::create()->addComponents( |
||
325 | new GridFieldToolbarHeader(), |
||
326 | new GridFieldSortableHeader(), |
||
327 | new GridFieldDataColumns(), |
||
328 | new GridFieldEditButton(), |
||
329 | new GridFieldDetailForm() |
||
330 | ); |
||
331 | $title = _t('CheckoutPage.ORDERMODIFIERDESCRIPTMESSAGES', 'Messages relating to order form extras (e.g. tax or shipping)'); |
||
332 | $source = OrderModifier_Descriptor::get(); |
||
333 | |||
334 | return new GridField('OrderModifier_Descriptor', $title, $source, $gridFieldConfig); |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * @return GridField |
||
339 | */ |
||
340 | protected function getCheckoutStepDescriptionField() |
||
341 | { |
||
342 | $gridFieldConfig = GridFieldConfig::create()->addComponents( |
||
343 | new GridFieldToolbarHeader(), |
||
344 | new GridFieldSortableHeader(), |
||
345 | new GridFieldDataColumns(), |
||
346 | new GridFieldEditButton(), |
||
347 | new GridFieldDetailForm() |
||
348 | ); |
||
349 | $title = _t('CheckoutPage.CHECKOUTSTEPESCRIPTIONS', 'Checkout Step Descriptions'); |
||
350 | $source = CheckoutPage_StepDescription::get(); |
||
351 | |||
352 | return new GridField('CheckoutPage_StepDescription', $title, $source, $gridFieldConfig); |
||
353 | } |
||
354 | |||
355 | public function requireDefaultRecords() |
||
356 | { |
||
357 | parent::requireDefaultRecords(); |
||
358 | $checkoutPage = CheckoutPage::get()->first(); |
||
359 | if (!$checkoutPage) { |
||
360 | $checkoutPage = self::create(); |
||
361 | $checkoutPage->Title = 'Checkout'; |
||
362 | $checkoutPage->MenuTitle = 'Checkout'; |
||
363 | $checkoutPage->URLSegment = 'checkout'; |
||
364 | $checkoutPage->writeToStage('Stage'); |
||
365 | $checkoutPage->publish('Stage', 'Live'); |
||
366 | } |
||
367 | } |
||
368 | } |
||
369 | |||
370 | class CheckoutPage_Controller extends CartPage_Controller |
||
371 | { |
||
372 | private static $allowed_actions = array( |
||
373 | 'checkoutstep', |
||
374 | 'OrderFormAddress', |
||
375 | 'saveorder', |
||
376 | 'CreateAccountForm', |
||
377 | 'retrieveorder', |
||
378 | 'loadorder', |
||
379 | 'startneworder', |
||
380 | 'showorder', |
||
381 | 'LoginForm', |
||
382 | 'OrderForm', |
||
383 | ); |
||
384 | |||
385 | /** |
||
386 | * FOR STEP STUFF SEE BELOW. |
||
387 | **/ |
||
388 | |||
389 | /** |
||
390 | * Standard SS function |
||
391 | * if set to false, user can edit order, if set to true, user can only review order. |
||
392 | **/ |
||
393 | public function init() |
||
394 | { |
||
395 | parent::init(); |
||
396 | |||
397 | Requirements::themedCSS('CheckoutPage', 'ecommerce'); |
||
398 | $ajaxifyArray = EcommerceConfig::get('CheckoutPage_Controller', 'ajaxify_steps'); |
||
399 | if (count($ajaxifyArray)) { |
||
400 | foreach ($ajaxifyArray as $js) { |
||
401 | Requirements::javascript($js); |
||
402 | } |
||
403 | } |
||
404 | Requirements::javascript('ecommerce/javascript/EcomPayment.js'); |
||
405 | Requirements::customScript(' |
||
406 | if (typeof EcomOrderForm != "undefined") { |
||
407 | EcomOrderForm.set_TermsAndConditionsMessage(\''.convert::raw2js($this->TermsAndConditionsMessage).'\'); |
||
408 | }', |
||
409 | 'TermsAndConditionsMessage' |
||
410 | ); |
||
411 | $this->steps = EcommerceConfig::get('CheckoutPage_Controller', 'checkout_steps'); |
||
412 | $this->currentStep = $this->request->Param('ID'); |
||
413 | if ($this->currentStep && in_array($this->currentStep, $this->steps)) { |
||
414 | //do nothing |
||
415 | } else { |
||
416 | $this->currentStep = array_shift($this->steps); |
||
417 | } |
||
418 | //redirect to current order - |
||
419 | // this is only applicable when people submit order (start to pay) |
||
420 | // and then return back |
||
421 | if ($checkoutPageCurrentOrderID = Session::get('CheckoutPageCurrentOrderID')) { |
||
422 | if ($this->currentOrder->ID != $checkoutPageCurrentOrderID) { |
||
423 | Session::clear('CheckoutPageCurrentOrderID'); |
||
424 | Session::set('CheckoutPageCurrentOrderID', 0); |
||
425 | Session::save(); |
||
426 | } |
||
427 | } |
||
428 | if ($this->currentOrder) { |
||
429 | //we make sure all the OrderModifiers are up to date.... |
||
430 | Session::set('CheckoutPageCurrentOrderID', $this->currentOrder->ID); |
||
431 | } |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * Returns a ArrayList of {@link OrderModifierForm} objects. These |
||
436 | * forms are used in the OrderInformation HTML table for the user to fill |
||
437 | * in as needed for each modifier applied on the site. |
||
438 | * |
||
439 | * @return ArrayList (ModifierForms) | Null |
||
440 | */ |
||
441 | public function ModifierForms() |
||
442 | { |
||
443 | if ($this->currentOrder) { |
||
444 | return $this->currentOrder->getModifierForms(); |
||
445 | } |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * Returns a form allowing a user to enter their |
||
450 | * details to checkout their order. |
||
451 | * |
||
452 | * @return OrderForm object |
||
453 | */ |
||
454 | public function OrderFormAddress() |
||
455 | { |
||
456 | $form = OrderFormAddress::create($this, 'OrderFormAddress'); |
||
457 | $this->data()->extend('updateOrderFormAddress', $form); |
||
458 | //load session data |
||
459 | if ($data = Session::get("FormInfo.{$form->FormName()}.data")) { |
||
460 | $form->loadDataFrom($data); |
||
461 | } |
||
462 | |||
463 | return $form; |
||
464 | } |
||
465 | |||
466 | /** |
||
467 | * Returns a form allowing a user to enter their |
||
468 | * details to checkout their order. |
||
469 | * |
||
470 | * @return OrderForm object |
||
471 | */ |
||
472 | public function OrderForm() |
||
473 | { |
||
474 | $form = OrderForm::create($this, 'OrderForm'); |
||
475 | $this->data()->extend('updateOrderForm', $form); |
||
476 | //load session data |
||
477 | if ($data = Session :: get("FormInfo.{$form->FormName()}.data")) { |
||
478 | $form->loadDataFrom($data); |
||
479 | } |
||
480 | |||
481 | return $form; |
||
482 | } |
||
483 | |||
484 | /** |
||
485 | * Can the user proceed? It must be an editable order (see @link CartPage) |
||
486 | * and is must also contain items. |
||
487 | * |
||
488 | * @return bool |
||
489 | */ |
||
490 | public function CanCheckout() |
||
491 | { |
||
492 | return $this->currentOrder->getTotalItems() && !$this->currentOrder->IsSubmitted(); |
||
493 | } |
||
494 | |||
495 | /** |
||
496 | * Catch for incompatable coding only.... |
||
497 | */ |
||
498 | public function ModifierForm($request) |
||
499 | { |
||
500 | user_error('Make sure that you set the controller for your ModifierForm to a controller directly associated with the Modifier', E_USER_WARNING); |
||
501 | |||
502 | return array(); |
||
503 | } |
||
504 | |||
505 | /** |
||
506 | * STEP STUFF ---------------------------------------------------------------------------. |
||
507 | * |
||
508 | |||
509 | |||
510 | /** |
||
511 | *@var String |
||
512 | **/ |
||
513 | protected $currentStep = ''; |
||
514 | |||
515 | /** |
||
516 | *@var array |
||
517 | **/ |
||
518 | protected $steps = array(); |
||
519 | |||
520 | /** |
||
521 | * returns a dataobject set of the steps. |
||
522 | * Or just one step if that is more relevant. |
||
523 | * |
||
524 | * @param int $number - if set, it returns that one step. |
||
525 | */ |
||
526 | public function CheckoutSteps($number = 0) |
||
527 | { |
||
528 | $where = ''; |
||
529 | $dos = CheckoutPage_StepDescription::get() |
||
530 | ->Sort('ID', 'ASC'); |
||
531 | if ($number) { |
||
532 | $dos = $dos->Filter(array('ID' => $number)); |
||
533 | } |
||
534 | if ($number) { |
||
535 | if ($dos->count()) { |
||
536 | return $dos->First(); |
||
537 | } |
||
538 | } |
||
539 | $returnData = new ArrayList(array()); |
||
540 | $completed = 1; |
||
541 | $completedClass = 'completed'; |
||
542 | foreach ($dos as $do) { |
||
543 | if ($this->currentStep && $do->Code() == $this->currentStep) { |
||
544 | $do->LinkingMode = 'current'; |
||
545 | $completed = 0; |
||
546 | $completedClass = 'notCompleted'; |
||
547 | } else { |
||
548 | if ($completed) { |
||
549 | $do->Link = $this->Link('checkoutstep').'/'.$do->Code.'/'; |
||
550 | } |
||
551 | $do->LinkingMode = "link $completedClass"; |
||
552 | } |
||
553 | $do->Completed = $completed; |
||
554 | $returnData->push($do); |
||
555 | } |
||
556 | if (EcommerceConfig::get('OrderConfirmationPage_Controller', 'include_as_checkout_step')) { |
||
557 | $orderConfirmationPage = OrderConfirmationPage::get()->First(); |
||
558 | if ($orderConfirmationPage) { |
||
559 | $do = $orderConfirmationPage->CurrentCheckoutStep(false); |
||
560 | if ($do) { |
||
561 | $returnData->push($do); |
||
562 | } |
||
563 | } |
||
564 | } |
||
565 | |||
566 | return $returnData; |
||
567 | } |
||
568 | |||
569 | /** |
||
570 | * returns the heading for the Checkout Step. |
||
571 | * |
||
572 | * @param int $number |
||
573 | * |
||
574 | * @return string |
||
575 | */ |
||
576 | public function StepsContentHeading($number) |
||
577 | { |
||
578 | $do = $this->CheckoutSteps($number); |
||
579 | if ($do) { |
||
580 | return $do->Heading; |
||
581 | } |
||
582 | |||
583 | return ''; |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * returns the top of the page content for the Checkout Step. |
||
588 | * |
||
589 | * @param int $number |
||
590 | * |
||
591 | * @return string |
||
592 | */ |
||
593 | public function StepsContentAbove($number) |
||
594 | { |
||
595 | $do = $this->CheckoutSteps($number); |
||
596 | if ($do) { |
||
597 | return $do->Above; |
||
598 | } |
||
599 | |||
600 | return ''; |
||
601 | } |
||
602 | |||
603 | /** |
||
604 | * returns the bottom of the page content for the Checkout Step. |
||
605 | * |
||
606 | * @param int $number |
||
607 | * |
||
608 | * @return string |
||
609 | */ |
||
610 | public function StepsContentBelow($number) |
||
611 | { |
||
612 | $do = $this->CheckoutSteps($number); |
||
613 | if ($do) { |
||
614 | return $do->Below; |
||
615 | } |
||
616 | |||
617 | return ''; |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * sets the current checkout step |
||
622 | * if it is ajax it returns the current controller |
||
623 | * as the inner for the page. |
||
624 | * |
||
625 | * @param SS_HTTPRequest $request |
||
626 | * |
||
627 | * @return array |
||
628 | */ |
||
629 | public function checkoutstep(SS_HTTPRequest $request) |
||
630 | { |
||
631 | if ($this->request->isAjax()) { |
||
632 | Requirements::clear(); |
||
633 | |||
634 | return $this->renderWith('LayoutCheckoutPageInner'); |
||
635 | } |
||
636 | |||
637 | return array(); |
||
638 | } |
||
639 | |||
640 | /** |
||
641 | * when you extend the CheckoutPage you can change this... |
||
642 | * |
||
643 | * @return bool |
||
644 | */ |
||
645 | public function HasCheckoutSteps() |
||
646 | { |
||
647 | return true; |
||
648 | } |
||
649 | |||
650 | /** |
||
651 | * @param string $step |
||
652 | * |
||
653 | * @return bool |
||
654 | **/ |
||
655 | public function CanShowStep($step) |
||
656 | { |
||
657 | if ($this->ShowOnlyCurrentStep()) { |
||
658 | return $step == $this->currentStep; |
||
659 | } else { |
||
660 | return in_array($step, $this->steps); |
||
661 | } |
||
662 | } |
||
663 | |||
664 | /** |
||
665 | * Is this the final step in the process. |
||
666 | * |
||
667 | * @return bool |
||
668 | */ |
||
669 | public function ShowOnlyCurrentStep() |
||
670 | { |
||
671 | return $this->currentStep ? true : false; |
||
672 | } |
||
673 | |||
674 | /** |
||
675 | * Is this the final step in the process? |
||
676 | * |
||
677 | * @return bool |
||
678 | */ |
||
679 | public function IsFinalStep() |
||
680 | { |
||
681 | foreach ($this->steps as $finalStep) { |
||
682 | //do nothing... |
||
683 | } |
||
684 | |||
685 | return $this->currentStep == $finalStep; |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * returns the percentage of steps done (0 - 100). |
||
690 | * |
||
691 | * @return int |
||
692 | */ |
||
693 | public function PercentageDone() |
||
694 | { |
||
695 | return round($this->currentStepNumber() / $this->numberOfSteps(), 2) * 100; |
||
696 | } |
||
697 | |||
698 | /** |
||
699 | * returns the number of the current step (e.g. step 1). |
||
700 | * |
||
701 | * @return int |
||
702 | */ |
||
703 | protected function currentStepNumber() |
||
704 | { |
||
705 | $key = 1; |
||
706 | if ($this->currentStep) { |
||
707 | $key = array_search($this->currentStep, $this->steps); |
||
708 | ++$key; |
||
709 | } |
||
710 | |||
711 | return $key; |
||
712 | } |
||
713 | |||
714 | /** |
||
715 | * returns the total number of steps (e.g. 3) |
||
716 | * we add one for the confirmation page. |
||
717 | * |
||
718 | * @return int |
||
719 | */ |
||
720 | protected function numberOfSteps() |
||
721 | { |
||
722 | return count($this->steps) + 1; |
||
723 | } |
||
724 | |||
725 | /** |
||
726 | * Here are some additional rules that can be applied to steps. |
||
727 | * If you extend the checkout page, you canm overrule these rules. |
||
728 | */ |
||
729 | protected function applyStepRules() |
||
730 | { |
||
731 | //no items, back to beginning. |
||
732 | //has step xxx been completed? if not go back one? |
||
733 | //extend |
||
734 | //reset current step if different |
||
735 | } |
||
736 | } |
||
737 |
This check looks for the
else
branches ofif
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
else
branches can be removed.could be turned into
This is much more concise to read.