-
Notifications
You must be signed in to change notification settings - Fork 1
/
uc_addresses.install
227 lines (216 loc) · 7.69 KB
/
uc_addresses.install
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
* @file
* Install file for Ubercart Addresses.
*/
/**
* Implements hook_schema().
*/
function uc_addresses_schema() {
$schema['uc_addresses'] = array(
'description' => 'Ubercart customer addresses',
'fields' => array(
'aid' => array(
'description' => 'The address ID',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The ID of the user who owns this address',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'first_name' => array(
'description' => 'The addressee\'s first name',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'last_name' => array(
'description' => 'The addressee\'s last name',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'phone' => array(
'description' => 'The addressee\'s phone number',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'company' => array(
'description' => 'The addressee\'s company name',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'street1' => array(
'description' => 'The addressee\'s residence number and street',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'street2' => array(
'description' => 'The addressee\'s residence number and street (continued)',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'city' => array(
'description' => 'The addressee\'s city of residence',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'zone' => array(
'description' => 'The addressee\'s zone of residence',
'type' => 'int',
'size' => 'medium',
'not null' => TRUE,
'default' => 0,
),
'postal_code' => array(
'description' => 'The addressee\'s postal code',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'country' => array(
'description' => 'The addressee\'s country of residence',
'type' => 'int',
'size' => 'medium',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'address_name' => array(
'description' => 'The name used to access this address',
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
),
'default_shipping' => array(
'description' => 'If the address is the default shipping address',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
'default_billing' => array(
'description' => 'If the address is the default billing address',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
'created' => array(
'description' => 'The date this address was created',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'modified' => array(
'description' => 'The date this address was last modified',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'aid_uid_idx' => array('aid', 'uid'),
),
'primary key' => array('aid'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function uc_addresses_install() {
$t = get_t();
// Setup default permissions. Authenticated users will automatically
// be granted with permissions to manage their own addresses.
user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, array(
'view own addresses',
'add/edit own addresses',
'delete own addresses',
)
);
// Increase the weight of uc_addresses relative
// to uc_quote by an addition of 1 so that
// uc_addresses module can undo some of the actions
// done by uc_quote's form alter, which causes the
// delivery address form to disapear on checkout.
//
// See also http://drupal.org/node/1421720.
$weight = db_select('system', 's')
->fields('s', array('weight'))
->condition('name', 'uc_quote', '=')
->execute()
->fetchField();
db_update('system')
->fields(array('weight' => $weight + 1))
->condition('name', 'uc_addresses', '=')
->execute();
backdrop_set_message($t("Ubercart Addresses is installed. The authenticated user automatically was granted the permissions %view_own, %edit_own and %delete_own.", array('%view_own' => $t('view own addresses'), '%edit_own' => $t('add/edit own addresses'), '%delete_own' => $t('delete own addresses'))), 'status');
}
/**
* Implements hook_uninstall().
*
*/
function uc_addresses_uninstall() {
}
/**
* Implements hook_update_last_removed().
*/
function uc_addresses_update_last_removed() {
return 7101;
}
/**
* Migrate uc_addresses variables to config.
*/
function uc_addresses_update_1000() {
$config = config('uc_addresses.settings');
$config->set('uc_addresses_use_address_name', update_variable_get('uc_addresses_use_address_name', TRUE));
$config->set('uc_addresses_default_billing_address', update_variable_get('uc_addresses_default_billing_address', TRUE));
$config->set('uc_addresses_default_shipping_address', update_variable_get('uc_addresses_default_shipping_address', TRUE));
$config->set('uc_addresses_require_address', update_variable_get('uc_addresses_require_address', TRUE));
$config->set('uc_addresses_require_address_admin', update_variable_get('uc_addresses_require_address_admin', TRUE));
$config->set('uc_addresses_add_button', update_variable_get('uc_addresses_add_button', 'Save address'));
$config->set('uc_addresses_update_button', update_variable_get('uc_addresses_update_button', 'Save address'));
$config->set('uc_addresses_delete_button', update_variable_get('uc_addresses_delete_button', 'Delete address'));
$config->set('uc_addresses_delete_instructions', update_variable_get('uc_addresses_delete_instructions', 'Are you sure you want to delete this address? Once deleted, the address cannot be recovered.'));
update_variable_del('uc_addresses_use_address_name');
update_variable_del('uc_addresses_default_billing_address');
update_variable_del('uc_addresses_default_shipping_address');
update_variable_del('uc_addresses_require_address');
update_variable_del('uc_addresses_require_address_admin');
update_variable_del('uc_addresses_default_address_shipping_address');
update_variable_del('uc_addresses_default_address_billing_address');
update_variable_del('uc_addresses_add_button');
update_variable_del('uc_addresses_update_button');
update_variable_del('uc_addresses_delete_button');
update_variable_del('uc_addresses_delete_instructions');
$result = db_select('uc_countries')
->condition('version', 0, '>')
->fields('uc_countries', array('country_id'))
->execute();
foreach ($result as $country) {
$config->set('uc_addresses_address_format_' . $country->country_id, update_variable_get('uc_addresses_address_format_' . $country->country_id, NULL));
update_variable_del('uc_addresses_address_format_' . $country->country_id);
}
foreach (uc_addresses_address_types() as $address_type) {
$config->set('uc_addresses_use_default_' . $address_type, update_variable_get('uc_addresses_use_default_' . $address_type, TRUE));
update_variable_del('uc_addresses_use_default_' . $address_type);
}
$config->save();
}