1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\OrdersAdmin\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\i18n\i18n; |
6
|
|
|
use SilverStripe\Forms\Form; |
7
|
|
|
use SilverStripe\Core\Extension; |
8
|
|
|
use SilverStripe\View\ArrayData; |
9
|
|
|
use SilverStripe\Forms\TextField; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
use SilverStripe\Forms\FormAction; |
12
|
|
|
use SilverStripe\ORM\PaginatedList; |
13
|
|
|
use SilverStripe\Forms\HeaderField; |
14
|
|
|
use SilverStripe\Forms\HiddenField; |
15
|
|
|
use SilverStripe\Security\Security; |
16
|
|
|
use SilverStripe\Forms\LiteralField; |
17
|
|
|
use SilverStripe\Forms\CheckboxField; |
18
|
|
|
use SilverStripe\Forms\DropdownField; |
19
|
|
|
use SilverStripe\Forms\CompositeField; |
20
|
|
|
use SilverStripe\Forms\RequiredFields; |
21
|
|
|
use SilverStripe\ORM\ValidationResult; |
22
|
|
|
use SilverCommerce\ContactAdmin\Model\ContactLocation; |
23
|
|
|
use ilateral\SilverStripe\Users\Control\AccountController; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Add extra fields to a user account (if the users module is |
27
|
|
|
* installed) to allow logged in users to see their invoices. |
28
|
|
|
* |
29
|
|
|
* @package orders |
30
|
|
|
*/ |
31
|
|
|
class AccountControllerExtension extends Extension |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Add extra URL endpoints |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private static $allowed_actions = [ |
|
|
|
|
39
|
|
|
"history", |
40
|
|
|
"outstanding" |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
public function updateIndexSections($sections) |
44
|
|
|
{ |
45
|
|
|
$member = Security::getCurrentUser(); |
46
|
|
|
|
47
|
|
|
$outstanding = $member->OutstandingInvoices()->limit(5); |
48
|
|
|
|
49
|
|
|
$sections->push(ArrayData::create([ |
50
|
|
|
"Title" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), |
51
|
|
|
"Content" => $this->owner->renderWith( |
52
|
|
|
"SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", |
53
|
|
|
["List" => $outstanding] |
54
|
|
|
) |
55
|
|
|
])); |
56
|
|
|
|
57
|
|
|
$historic = $member->HistoricInvoices()->limit(5); |
58
|
|
|
|
59
|
|
|
$sections->push(ArrayData::create([ |
60
|
|
|
"Title" => _t('Orders.OrderHistory', 'Order History'), |
61
|
|
|
"Content" => $this->owner->renderWith( |
62
|
|
|
"SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", |
63
|
|
|
["List" => $historic] |
64
|
|
|
) |
65
|
|
|
])); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Display all historic orders for the current user |
70
|
|
|
* |
71
|
|
|
* @return HTMLText |
|
|
|
|
72
|
|
|
*/ |
73
|
|
|
public function history() |
74
|
|
|
{ |
75
|
|
|
$member = Security::getCurrentUser(); |
76
|
|
|
$list = PaginatedList::create( |
77
|
|
|
$member->HistoricInvoices(), |
78
|
|
|
$this->owner->getRequest() |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this |
82
|
|
|
->owner |
83
|
|
|
->customise([ |
84
|
|
|
"Title" => _t('Orders.OrderHistory', 'Order History'), |
85
|
|
|
"MenuTitle" => _t('Orders.OrderHistory', 'Order History'), |
86
|
|
|
"Content" => $this->owner->renderWith( |
87
|
|
|
"SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", |
88
|
|
|
["List" => $list] |
89
|
|
|
) |
90
|
|
|
]); |
91
|
|
|
|
92
|
|
|
$this->owner->extend("updateHistoricOrders", $orders); |
|
|
|
|
93
|
|
|
|
94
|
|
|
return $this |
95
|
|
|
->owner |
96
|
|
|
->renderWith([ |
97
|
|
|
'AccountController_history', |
98
|
|
|
AccountController::class . '_history', |
99
|
|
|
'AccountController', |
100
|
|
|
AccountController::class, |
101
|
|
|
'Page' |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Display all outstanding orders for the current user |
107
|
|
|
* |
108
|
|
|
* @return HTMLText |
109
|
|
|
*/ |
110
|
|
|
public function outstanding() |
111
|
|
|
{ |
112
|
|
|
$member = Security::getCurrentUser(); |
113
|
|
|
$list = PaginatedList::create( |
114
|
|
|
$member->OutstandingInvoices(), |
115
|
|
|
$this->owner->getRequest() |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$this->owner->customise([ |
119
|
|
|
"Title" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), |
120
|
|
|
"MenuTitle" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), |
121
|
|
|
"Content" => $this->owner->renderWith( |
122
|
|
|
"SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", |
123
|
|
|
["List" => $list] |
124
|
|
|
) |
125
|
|
|
]); |
126
|
|
|
|
127
|
|
|
$this->owner->extend("updateOutstandingOrders", $orders); |
|
|
|
|
128
|
|
|
|
129
|
|
|
return $this |
130
|
|
|
->owner |
131
|
|
|
->renderWith([ |
132
|
|
|
'AccountController_outstanding', |
133
|
|
|
AccountController::class . '_outstanding', |
134
|
|
|
'AccountController', |
135
|
|
|
AccountController::class, |
136
|
|
|
'Page' |
137
|
|
|
]); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Add commerce specific links to account menu |
142
|
|
|
* |
143
|
|
|
* @param ArrayList $menu |
|
|
|
|
144
|
|
|
*/ |
145
|
|
|
public function updateAccountMenu($menu) |
146
|
|
|
{ |
147
|
|
|
$curr_action = $this |
148
|
|
|
->owner |
149
|
|
|
->getRequest() |
150
|
|
|
->param("Action"); |
151
|
|
|
|
152
|
|
|
$menu->add(ArrayData::create([ |
153
|
|
|
"ID" => 1, |
154
|
|
|
"Title" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), |
155
|
|
|
"Link" => $this->owner->Link("outstanding"), |
156
|
|
|
"LinkingMode" => ($curr_action == "outstanding") ? "current" : "link" |
157
|
|
|
])); |
158
|
|
|
|
159
|
|
|
$menu->add(ArrayData::create([ |
160
|
|
|
"ID" => 2, |
161
|
|
|
"Title" => _t('Orders.OrderHistory', "Order history"), |
162
|
|
|
"Link" => $this->owner->Link("history"), |
163
|
|
|
"LinkingMode" => ($curr_action == "history") ? "current" : "link" |
164
|
|
|
])); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths