1 <?php
2 3 4 5 6 7 8 9
10
11 class CheckoutStep_PaymentMethod extends CheckoutStep{
12
13 static $allowed_actions = array(
14 'paymentmethod',
15 'PaymentMethodForm',
16 );
17
18 function StepIsActive() {
19 $methods = PaymentMethod::getPaymentMethods();
20 if (Order::$use_shipping && Cart::get_info('ShippingMethodID')) {
21 $controller = ModelAsController::controller_for(DataObject::get_one('CheckoutPage'));
22 $controller->extend('removeUnavailableMethods',$methods, Cart::get_info('ShippingMethodID'));
23 }
24 if(!$methods || ($methods->Count() == 0)) {
25 return false;
26 }
27 if($methods->Count() == 1) {
28 return false;
29 }
30 return true;
31 }
32
33 function paymentmethod(){
34 $methods = PaymentMethod::getPaymentMethods();
35
36 if (Order::$use_shipping && Cart::get_info('ShippingMethodID'))
37 $this->owner->extend('removeUnavailableMethods',$methods, Cart::get_info('ShippingMethodID'));
38
39 if(!$methods || ($methods->Count() == 0)){
40 user_error("Необходимо задать доступные способы оплаты - используйте PaymentType::set_supported_methods() в _config.php", E_USER_ERROR);
41 }
42 if($methods->Count() == 1){
43 $this->setpaymentmethod(array(
44 'PaymentMethod' => $methods->First()->ID
45 ), null);
46 return;
47 }
48 return array(
49 'Title' => $this->stepTitle(),
50 'Content' => $this->stepMessage(),
51 'Form' => $this->PaymentMethodForm()
52 );
53 }
54
55 function PaymentMethodForm(){
56 $methods = PaymentMethod::getPaymentMethods();
57 if (Order::$use_shipping && Cart::get_info('ShippingMethodID'))
58 $this->owner->extend('removeUnavailableMethods',$methods, Cart::get_info('ShippingMethodID'));
59
60
61 $fields = new FieldSet(new OptionsetField(
62 'PaymentMethod','',$methods->map('ID', 'ListTitle'),$methods->First()->ID
63 ));
64 $actions = $this->getStepActions(new FormAction('setpaymentmethod', _t('OrderForm.NextStepButton', 'Continue')));
65
66 $validator = new RequiredFields('PaymentMethod');
67 $form = new Form($this->owner,"PaymentMethodForm",$fields,$actions);
68 $form->addExtraClass('checkoutOptions');
69
70 $this->owner->extend('updatePaymentMethodForm',$form);
71 return $form;
72 }
73
74 function setpaymentmethod($data, $form){
75 if (isset($data['PaymentMethod'])) {
76 Cart::set_info('PaymentMethod', convert::raw2sql($data['PaymentMethod']));
77 Director::redirect($this->NextStepLink());
78 return;
79 }
80 Director::redirectBack();
81 }
82
83 function getSelectedPaymentMethod(){
84 return Cart::get_info('PaymentMethod');
85 }
86
87 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-