1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\OrdersAdmin\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataExtension; |
6
|
|
|
use SilverStripe\Forms\TextField; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\ORM\ArrayList; |
9
|
|
|
use SilverStripe\Forms\ReadonlyField; |
10
|
|
|
use SilverStripe\Core\Config\Config; |
11
|
|
|
use SilverCommerce\ContactAdmin\Model\Contact; |
12
|
|
|
use SilverCommerce\OrdersAdmin\Model\Invoice; |
13
|
|
|
use SilverCommerce\OrdersAdmin\Model\Estimate; |
14
|
|
|
use SilverCommerce\OrdersAdmin\Model\MemberAddress; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Add additional settings to a memeber object |
18
|
|
|
* |
19
|
|
|
* @package orders-admin |
20
|
|
|
* @subpackage extensions |
21
|
|
|
*/ |
22
|
|
|
class MemberExtension extends DataExtension |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
private static $casting = [ |
|
|
|
|
26
|
|
|
"ContactTitle" => "Varchar" |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
public function updateCMSFields(FieldList $fields) |
30
|
|
|
{ |
31
|
|
|
if ($this->owner->ID) { |
32
|
|
|
$fields->addFieldToTab( |
33
|
|
|
"Root.Main", |
34
|
|
|
ReadonlyField::create("ContactTitle") |
|
|
|
|
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Find a contact associated with this account |
41
|
|
|
* |
42
|
|
|
* @return Contact |
43
|
|
|
*/ |
44
|
|
|
public function Contact() |
45
|
|
|
{ |
46
|
|
|
$contact = Contact::get() |
47
|
|
|
->find("MemberID", $this->owner->ID); |
48
|
|
|
|
49
|
|
|
if (!$contact) { |
|
|
|
|
50
|
|
|
$contact = Contact::create(); |
51
|
|
|
$contact->ID = -1; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $contact; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The name of the contact assotiated with this account |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function getContactTitle() |
63
|
|
|
{ |
64
|
|
|
$contact = $this->owner->Contact(); |
65
|
|
|
|
66
|
|
|
return $contact->Title; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get a discount from the groups this member is in |
71
|
|
|
* |
72
|
|
|
* @return Discount |
|
|
|
|
73
|
|
|
*/ |
74
|
|
|
public function getDiscount() |
75
|
|
|
{ |
76
|
|
|
$discounts = ArrayList::create(); |
77
|
|
|
|
78
|
|
|
foreach ($this->owner->Groups() as $group) { |
79
|
|
|
foreach ($group->Discounts() as $discount) { |
80
|
|
|
$discounts->add($discount); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$discounts->sort("Amount", "DESC"); |
85
|
|
|
|
86
|
|
|
return $discounts->first(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get all invoices from a contact that are designated |
91
|
|
|
* "outstanding" |
92
|
|
|
* |
93
|
|
|
* @return DataList |
|
|
|
|
94
|
|
|
*/ |
95
|
|
|
public function OutstandingInvoices() |
96
|
|
|
{ |
97
|
|
|
return $this |
98
|
|
|
->owner |
99
|
|
|
->Contact() |
100
|
|
|
->OutstandingInvoices(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get all invoices from a contact that are designated |
105
|
|
|
* "historic" |
106
|
|
|
* |
107
|
|
|
* @return DataList |
108
|
|
|
*/ |
109
|
|
|
public function HistoricInvoices() |
110
|
|
|
{ |
111
|
|
|
return $this |
112
|
|
|
->owner |
113
|
|
|
->Contact() |
114
|
|
|
->HistoricInvoices(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* If no contact exists for this account, then create one |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function onAfterWrite() |
123
|
|
|
{ |
124
|
|
|
parent::onAfterWrite(); |
125
|
|
|
|
126
|
|
|
if (!$this->Contact()->exists()) { |
127
|
|
|
$contact = Contact::create([ |
128
|
|
|
"FirstName" => $this->owner->FirstName, |
129
|
|
|
"Surname" => $this->owner->Surname, |
130
|
|
|
"Email" => $this->owner->Email |
131
|
|
|
]); |
132
|
|
|
$contact->MemberID = $this->owner->ID; |
133
|
|
|
$contact->write(); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
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