-
Notifications
You must be signed in to change notification settings - Fork 0
/
discimport_deploy.install
258 lines (233 loc) · 8.71 KB
/
discimport_deploy.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
/**
* @file
*/
/**
* Implements hook_install().
*
* See http://dcycleproject.org/node/43
*/
function discimport_deploy_install() {
for ($i = 7000; $i < 8000; $i++) {
$candidate = 'discimport_deploy_update_' . $i;
if (function_exists($candidate)) {
$candidate();
}
}
}
/**
* Implements hook_update_dependencies().
*/
function discimport_deploy_update_dependencies() {
$deps = array();
$deps['discimport_deploy'][7006] = array(
'commerce_coupon' => 7202,
);
return $deps;
}
/**
* Setting up timezones.
*/
function discimport_deploy_update_7000() {
variable_set('configurable_timezones', 0);
variable_set('date_first_day', 1);
variable_set('date_default_timezone', 'Europe/Copenhagen');
}
/**
* Setting upload to 5MB and skip scheme on upload.
*/
function discimport_deploy_update_7001() {
variable_set('file_entity_max_filesize', '5 MB');
variable_set('file_entity_file_upload_wizard_skip_scheme', 1);
}
/**
* Settings for transliteration.
*/
function discimport_deploy_update_7002() {
if (module_exists('pathauto')) {
if (module_exists('transliteration')) {
variable_set('pathauto_transliterate', 1);
}
variable_set('pathauto_reduce_ascii', 1);
}
}
/**
* Fixes an issue where the discimport.dk site has come into a broke state that gives
* a fatal error on admin/commerce.
*/
function discimport_deploy_update_7003() {
menu_rebuild();
drupal_flush_all_caches();
}
/**
* Disable, uninstall, and reinstall Commerce Stock for 2.x
*/
function discimport_deploy_update_7004() {
// Comment out because we're already done this, breaks installs.
// $modules = array('commerce_sdf', 'commerce_ssr', 'commerce_ss', 'commerce_stock');
// module_disable(array('commerce_stock'));
// drupal_uninstall_modules(array('commerce_stock'));
// module_enable($modules);
}
/**
* Fix the catalog
* @throws \Exception
*/
function discimport_deploy_update_7005() {
// Set up taxonomy main menu.
$vocabulary_machine_name = variable_get('commerce_kickstart_demo_store', FALSE) ? 'collection' : 'product_category';
drupal_set_message(t('Resetting taxonomy menu for @vocab', array('@vocab' => $vocabulary_machine_name)));
if ($collection = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name)) {
$variable_name = _taxonomy_menu_build_variable('vocab_menu', $collection->vid);
variable_set($variable_name, 'main-menu');
$variable_name = _taxonomy_menu_build_variable('vocab_parent', $collection->vid);
variable_set($variable_name, '0');
$variable_name = _taxonomy_menu_build_variable('path', $collection->vid);
variable_set($variable_name, 'commerce_kickstart_taxonomy_term_path');
$variable_name = _taxonomy_menu_build_variable('rebuild', $collection->vid);
variable_set($variable_name, 1);
$variable_name = _taxonomy_menu_build_variable('sync', $collection->vid);
variable_set($variable_name, 1);
}
}
/**
* Enable Commerce GC + Commerce GC Product
*/
function discimport_deploy_update_7006() {
module_enable(array(
'commerce_gc',
'commerce_gc_product',
));
}
/**
* Enable Features Override
*/
function discimport_deploy_update_7007() {
module_enable(array('features_override'));
}
/**
* Update weight for add to cart field.
*/
function discimport_deploy_update_7008() {
db_update('block')->fields(array('weight' => -44))->condition('delta', 'add_to_cart_table-block_1', '=')->execute();
}
/**
* Auto generate product titles.
*/
function discimport_deploy_update_7009() {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'commerce_product')
->propertyCondition('title', '');
$results = $query->execute();
if (!empty($results)) {
$products = entity_load('commerce_product', array_keys($results['commerce_product']));
foreach ($products as $product) {
// Recreate title generation.
$display_query = new EntityFieldQuery();
$display_query->entityCondition('entity_type', 'node')
->fieldCondition('field_product', 'product_id', $product->product_id)->range(0, 1);
$display_query_results = $display_query->execute();
if (empty($display_query_results)) {
continue;
}
$node_stub = reset($display_query_results['node']);
$product->title = entity_label('node', node_load($node_stub->nid));
$attributes = array();
// Loop through all the field instances on that product type.
foreach (field_info_instances('commerce_product', $product->type) as $name => $instance) {
// A field qualifies if it is single value, required and uses a widget
// with a definite set of options. For the sake of simplicity, this is
// currently restricted to fields defined by the options module.
$field = field_info_field($instance['field_name']);
// Get the array of Cart settings pertaining to this instance.
$commerce_cart_settings = commerce_cart_field_instance_attribute_settings($instance);
// If the instance is of a field type that is eligible to function as
// a product attribute field and if its attribute field settings
// specify that this functionality is enabled...
if (commerce_cart_field_attribute_eligible($field) && $commerce_cart_settings['attribute_field']) {
$attributes[$name] = array(
'field' => $field,
'instance' => $instance,
'weight' => $instance['widget']['weight'],
);
}
}
// Sort the fields by weight.
uasort($attributes, 'drupal_sort_weight');
if (!empty($attributes)) {
$wrapper = entity_metadata_wrapper('commerce_product', $product);
$attribute_values = array();
foreach ($attributes as $field_name => $attribute) {
$attribute_label = $wrapper->{$field_name}->label();
if (!empty($attribute_label)) {
$attribute_values[] = $attribute_label;
}
}
if (!empty($attribute_values)) {
$product->title .= ' (' . implode(', ', $attribute_values) . ')';
}
}
entity_save('commerce_product', $product);
}
}
}
/**
* Auto generate product titles.
*/
function discimport_deploy_update_7010() {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'commerce_product')
->propertyCondition('title', '');
$results = $query->execute();
if (!empty($results)) {
$products = entity_load('commerce_product', array_keys($results['commerce_product']));
foreach ($products as $product) {
// Recreate title generation.
$display_query = new EntityFieldQuery();
$display_query->entityCondition('entity_type', 'node')
->fieldCondition('field_product', 'product_id', $product->product_id)->range(0, 1);
$display_query_results = $display_query->execute();
if (empty($display_query_results)) {
continue;
}
$node_stub = reset($display_query_results['node']);
$product->title = entity_label('node', node_load($node_stub->nid));
$attributes = array();
// Loop through all the field instances on that product type.
foreach (field_info_instances('commerce_product', $product->type) as $name => $instance) {
// A field qualifies if it is single value, required and uses a widget
// with a definite set of options. For the sake of simplicity, this is
// currently restricted to fields defined by the options module.
$field = field_info_field($instance['field_name']);
// Get the array of Cart settings pertaining to this instance.
$commerce_cart_settings = commerce_cart_field_instance_attribute_settings($instance);
// If the instance is of a field type that is eligible to function as
// a product attribute field and if its attribute field settings
// specify that this functionality is enabled...
if (commerce_cart_field_attribute_eligible($field) && $commerce_cart_settings['attribute_field']) {
$attributes[$name] = array(
'field' => $field,
'instance' => $instance,
'weight' => $instance['widget']['weight'],
);
}
}
// Sort the fields by weight.
uasort($attributes, 'drupal_sort_weight');
if (!empty($attributes)) {
$wrapper = entity_metadata_wrapper('commerce_product', $product);
$attribute_values = array();
foreach ($attributes as $field_name => $attribute) {
$attribute_label = $wrapper->{$field_name}->label();
if (!empty($attribute_label)) {
$attribute_values[] = $attribute_label;
}
}
if (!empty($attribute_values)) {
$product->title .= ' (' . implode(', ', $attribute_values) . ')';
}
}
entity_save('commerce_product', $product);
}
}
}