|
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 $belongs_to = [ |
|
|
|
|
|
|
26
|
|
|
'Contact' => Contact::class . '.Member' |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
private static $casting = [ |
|
|
|
|
|
|
30
|
|
|
"ContactTitle" => "Varchar" |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
public function updateCMSFields(FieldList $fields) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($this->owner->ID) { |
|
36
|
|
|
$fields->addFieldToTab( |
|
37
|
|
|
"Root.Main", |
|
38
|
|
|
ReadonlyField::create("ContactTitle") |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The name of the contact assotiated with this account |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getContactTitle() |
|
49
|
|
|
{ |
|
50
|
|
|
$contact = $this->owner->Contact(); |
|
51
|
|
|
|
|
52
|
|
|
return $contact->Title; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get a discount from the groups this member is in |
|
57
|
|
|
* |
|
58
|
|
|
* @return Discount |
|
|
|
|
|
|
59
|
|
|
*/ |
|
60
|
|
|
public function getDiscount() |
|
61
|
|
|
{ |
|
62
|
|
|
$discounts = ArrayList::create(); |
|
63
|
|
|
|
|
64
|
|
|
foreach ($this->owner->Groups() as $group) { |
|
65
|
|
|
foreach ($group->Discounts() as $discount) { |
|
66
|
|
|
$discounts->add($discount); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$discounts->sort("Amount", "DESC"); |
|
71
|
|
|
|
|
72
|
|
|
return $discounts->first(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get all invoices from a contact that are designated |
|
77
|
|
|
* "outstanding" |
|
78
|
|
|
* |
|
79
|
|
|
* @return DataList |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
public function OutstandingInvoices() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this |
|
84
|
|
|
->owner |
|
85
|
|
|
->Contact() |
|
86
|
|
|
->OutstandingInvoices(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get all invoices from a contact that are designated |
|
91
|
|
|
* "historic" |
|
92
|
|
|
* |
|
93
|
|
|
* @return DataList |
|
94
|
|
|
*/ |
|
95
|
|
|
public function HistoricInvoices() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this |
|
98
|
|
|
->owner |
|
99
|
|
|
->Contact() |
|
100
|
|
|
->HistoricInvoices(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* If no contact exists for this account, then create one |
|
105
|
|
|
* |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function onAfterWrite() |
|
109
|
|
|
{ |
|
110
|
|
|
parent::onAfterWrite(); |
|
111
|
|
|
|
|
112
|
|
|
if (!$this->Contact()->exists()) { |
|
|
|
|
|
|
113
|
|
|
$contact = Contact::create([ |
|
114
|
|
|
"FirstName" => $this->owner->FirstName, |
|
115
|
|
|
"Surname" => $this->owner->Surname, |
|
116
|
|
|
"Email" => $this->owner->Email |
|
117
|
|
|
]); |
|
118
|
|
|
$contact->MemberID = $this->owner->ID; |
|
119
|
|
|
$contact->write(); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
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