-
Notifications
You must be signed in to change notification settings - Fork 26
/
address.php
executable file
·141 lines (117 loc) · 6.3 KB
/
address.php
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
133
134
135
136
137
138
139
140
141
<?php
class ModelExtensionDVuefrontAddress extends Model {
public function addAddress($customer_id, $data) {
$this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstName']) . "', lastname = '" . $this->db->escape($data['lastName']) . "', company = '" . $this->db->escape($data['company']) . "', address_1 = '" . $this->db->escape($data['address1']) . "', address_2 = '" . $this->db->escape($data['address2']) . "', postcode = '" . $this->db->escape($data['zipcode']) . "', city = '" . $this->db->escape($data['city']) . "', country_id = '".$data['countryId']."', zone_id = '".$data['zoneId']."', custom_field = '" . $this->db->escape(isset($data['custom_field']['address']) ? json_encode($data['custom_field']['address']) : '') . "'");
$address_id = $this->db->getLastId();
if (!empty($data['default'])) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");
}
return $address_id;
}
public function editAddress($address_id, $data) {
$this->db->query("UPDATE " . DB_PREFIX . "address SET firstname = '" . $this->db->escape($data['firstName']) . "', lastname = '" . $this->db->escape($data['lastName']) . "', company = '" . $this->db->escape($data['company']) . "', address_1 = '" . $this->db->escape($data['address1']) . "', address_2 = '" . $this->db->escape($data['address2']) . "', postcode = '" . $this->db->escape($data['zipcode']) . "', city = '" . $this->db->escape($data['city']) . "', country_id = '".$data['countryId']."', zone_id = '".$data['zoneId']."', custom_field = '" . $this->db->escape(isset($data['custom_field']['address']) ? json_encode($data['custom_field']['address']) : '') . "' WHERE address_id = '" . (int)$address_id . "' AND customer_id = '" . (int)$this->customer->getId() . "'");
if (!empty($data['default'])) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
}
}
public function deleteAddress($address_id) {
$this->db->query("DELETE FROM " . DB_PREFIX . "address WHERE address_id = '" . (int)$address_id . "' AND customer_id = '" . (int)$this->customer->getId() . "'");
}
public function getAddress($address_id) {
$address_query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "address WHERE address_id = '" . (int)$address_id . "' AND customer_id = '" . (int)$this->customer->getId() . "'");
if ($address_query->num_rows) {
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$address_query->row['country_id'] . "'");
if ($country_query->num_rows) {
$country = $country_query->row['name'];
$iso_code_2 = $country_query->row['iso_code_2'];
$iso_code_3 = $country_query->row['iso_code_3'];
$address_format = $country_query->row['address_format'];
} else {
$country = '';
$iso_code_2 = '';
$iso_code_3 = '';
$address_format = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$address_query->row['zone_id'] . "'");
if ($zone_query->num_rows) {
$zone = $zone_query->row['name'];
$zone_code = $zone_query->row['code'];
} else {
$zone = '';
$zone_code = '';
}
$address_data = array(
'address_id' => $address_query->row['address_id'],
'firstname' => $address_query->row['firstname'],
'lastname' => $address_query->row['lastname'],
'company' => $address_query->row['company'],
'address_1' => $address_query->row['address_1'],
'address_2' => $address_query->row['address_2'],
'postcode' => $address_query->row['postcode'],
'city' => $address_query->row['city'],
'zone_id' => $address_query->row['zone_id'],
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => $address_query->row['country_id'],
'country' => $country,
'iso_code_2' => $iso_code_2,
'iso_code_3' => $iso_code_3,
'address_format' => $address_format,
'custom_field' => json_decode($address_query->row['custom_field'], true)
);
return $address_data;
} else {
return false;
}
}
public function getAddresses() {
$address_data = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$this->customer->getId() . "'");
foreach ($query->rows as $result) {
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$result['country_id'] . "'");
if ($country_query->num_rows) {
$country = $country_query->row['name'];
$iso_code_2 = $country_query->row['iso_code_2'];
$iso_code_3 = $country_query->row['iso_code_3'];
$address_format = $country_query->row['address_format'];
} else {
$country = '';
$iso_code_2 = '';
$iso_code_3 = '';
$address_format = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$result['zone_id'] . "'");
if ($zone_query->num_rows) {
$zone = $zone_query->row['name'];
$zone_code = $zone_query->row['code'];
} else {
$zone = '';
$zone_code = '';
}
$address_data[$result['address_id']] = array(
'address_id' => $result['address_id'],
'firstname' => $result['firstname'],
'lastname' => $result['lastname'],
'company' => $result['company'],
'address_1' => $result['address_1'],
'address_2' => $result['address_2'],
'postcode' => $result['postcode'],
'city' => $result['city'],
'zone_id' => $result['zone_id'],
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => $result['country_id'],
'country' => $country,
'iso_code_2' => $iso_code_2,
'iso_code_3' => $iso_code_3,
'address_format' => $address_format,
'custom_field' => json_decode($result['custom_field'], true)
);
}
return $address_data;
}
public function getTotalAddresses() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$this->customer->getId() . "'");
return $query->row['total'];
}
}