BillingAddress.php
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace ACA\WC\Column\Order\Address;
use AC;
use ACA\WC\ConditionalFormat\FilteredHtmlIntegerFormatterTrait;
use ACA\WC\Editing;
use ACA\WC\Search;
use ACA\WC\Settings;
use ACA\WC\Sorting;
use ACA\WC\Type\AddressType;
use ACP;
class BillingAddress extends AC\Column implements ACP\Search\Searchable, ACP\Editing\Editable, ACP\Export\Exportable,
ACP\ConditionalFormat\Formattable, ACP\Sorting\Sortable
{
use FilteredHtmlIntegerFormatterTrait;
public function __construct()
{
$this->set_type('column-order_billing_address')
->set_label(__('Billing Address', 'codepress-admin-columns'))
->set_group('woocommerce');
}
public function get_value($id)
{
$order = wc_get_order($id);
$method = $this->get_address_map($this->get_display_property());
$value = method_exists($order, $method)
? $order->$method()
: false;
return $value ?: $this->get_empty_char();
}
private function get_display_property(): string
{
$setting = $this->get_setting('address_property');
return $setting instanceof Settings\Address\Billing
? $setting->get_address_property()
: '';
}
private function get_address_map($property): string
{
$mapping = [
'address_1' => 'get_billing_address_1',
'address_2' => 'get_billing_address_2',
'city' => 'get_billing_city',
'company' => 'get_billing_company',
'country' => 'get_billing_country',
'first_name' => 'get_billing_first_name',
'last_name' => 'get_billing_last_name',
'full_name' => 'get_formatted_billing_full_name',
'postcode' => 'get_billing_postcode',
'state' => 'get_billing_state',
'email' => 'get_billing_email',
'phone' => 'get_billing_phone',
];
return array_key_exists($property, $mapping)
? $mapping[$property]
: 'get_formatted_billing_address';
}
protected function register_settings()
{
parent::register_settings();
$this->add_setting(new Settings\Address\Billing($this));
}
private function get_address_type(): AddressType
{
return new AddressType(AddressType::BILLING);
}
public function search()
{
return (new Search\Order\AddressesComparisonFactory($this->get_address_type()))->create(
$this->get_display_property()
);
}
public function sorting()
{
switch ($this->get_display_property()) {
case 'address_1':
return new Sorting\Order\AddressField('address_1', $this->get_address_type());
case 'address_2':
return new Sorting\Order\AddressField('address_2', $this->get_address_type());
case 'city':
return new Sorting\Order\AddressField('city', $this->get_address_type());
case 'company':
return new Sorting\Order\AddressField('company', $this->get_address_type());
case 'country':
return new Sorting\Order\AddressField('country', $this->get_address_type());
case 'first_name':
return new Sorting\Order\AddressField('first_name', $this->get_address_type());
case 'last_name':
return new Sorting\Order\AddressField('last_name', $this->get_address_type());
case 'postcode':
return new Sorting\Order\AddressField('postcode', $this->get_address_type());
case 'phone':
return new Sorting\Order\AddressField('phone', $this->get_address_type());
case 'state':
return new Sorting\Order\AddressField('state', $this->get_address_type());
case 'full_name':
return new Sorting\Order\FullNameAddress($this->get_address_type());
default:
return false;
}
}
public function editing()
{
return (new Editing\Order\AddressServiceFactory($this->get_address_type()))->create(
$this->get_display_property()
);
}
public function export()
{
return new ACP\Export\Model\StrippedValue($this);
}
}