|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverShop\Checkout\Component; |
|
4
|
|
|
|
|
5
|
|
|
use SilverShop\Model\Order; |
|
6
|
|
|
use SilverShop\ShopTools; |
|
7
|
|
|
use SilverStripe\Core\Injector\Injectable; |
|
8
|
|
|
use SilverStripe\Forms\FieldList; |
|
9
|
|
|
use SilverStripe\ORM\ValidationException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* CheckoutComponent |
|
13
|
|
|
* |
|
14
|
|
|
* A modularised piece of checkout functionality. |
|
15
|
|
|
* |
|
16
|
|
|
* A checkout component will: |
|
17
|
|
|
* |
|
18
|
|
|
* - provide form fields |
|
19
|
|
|
* - validate entered data |
|
20
|
|
|
* - save data from given form fields |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class CheckoutComponent |
|
23
|
|
|
{ |
|
24
|
|
|
use Injectable; |
|
25
|
|
|
|
|
26
|
|
|
protected $requiredfields = []; |
|
27
|
|
|
|
|
28
|
|
|
protected $dependson = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get form fields for manipulating the current order, |
|
32
|
|
|
* according to the responsibility of this component. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Order $order the form being updated |
|
35
|
|
|
* |
|
36
|
|
|
* @throws \Exception |
|
37
|
|
|
* @return FieldList fields for manipulating order |
|
38
|
|
|
*/ |
|
39
|
|
|
abstract public function getFormFields(Order $order); |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Is this data valid for saving into an order? |
|
43
|
|
|
* |
|
44
|
|
|
* This function should never rely on form. |
|
45
|
|
|
* |
|
46
|
|
|
* @param Order $order the form being updated |
|
47
|
|
|
* @param array $data data to be validated |
|
48
|
|
|
* |
|
49
|
|
|
* @throws ValidationException |
|
50
|
|
|
* @return boolean the data is valid |
|
51
|
|
|
*/ |
|
52
|
|
|
abstract public function validateData(Order $order, array $data); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get required data out of the model. |
|
56
|
|
|
* |
|
57
|
|
|
* @param Order $order |
|
58
|
|
|
* |
|
59
|
|
|
* @return array get data from model(s) |
|
60
|
|
|
*/ |
|
61
|
|
|
abstract public function getData(Order $order); |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set the model data for this component. |
|
65
|
|
|
* |
|
66
|
|
|
* This function should never rely on form. |
|
67
|
|
|
* |
|
68
|
|
|
* @param Order $order |
|
69
|
|
|
* @param array $data data to be saved into order object |
|
70
|
|
|
* |
|
71
|
|
|
* @throws \Exception |
|
72
|
|
|
* @return Order the updated order |
|
73
|
|
|
*/ |
|
74
|
|
|
abstract public function setData(Order $order, array $data); |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the data fields that are required for the component. |
|
78
|
|
|
* |
|
79
|
|
|
* @param Order $order [description] |
|
80
|
|
|
* |
|
81
|
|
|
* @return array required data fields |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getRequiredFields(Order $order) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
return $this->requiredfields; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function dependsOn() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->dependson; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function name() |
|
100
|
|
|
{ |
|
101
|
|
|
return ShopTools::sanitiseClassName(static::class); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Whether or not this component provides the payment data that should be passed to the payment gateway |
|
106
|
|
|
* @return bool |
|
107
|
|
|
*/ |
|
108
|
|
|
public function providesPaymentData() |
|
109
|
|
|
{ |
|
110
|
|
|
return false; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.