Completed
Push — master ( b876da...364439 )
by
unknown
13:05
created
includes/librairies/install.class.php 1 patch
Indentation   +2376 added lines, -2376 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('ABSPATH')) {
2
-    exit;
2
+	exit;
3 3
 }
4 4
 
5 5
 /*    Check if file is include. No direct access possible with file url    */
6 6
 if (!defined('WPSHOP_VERSION')) {
7
-    die(__('Access is not allowed by this way', 'wpshop'));
7
+	die(__('Access is not allowed by this way', 'wpshop'));
8 8
 }
9 9
 
10 10
 /**
@@ -25,1785 +25,1785 @@  discard block
 block discarded – undo
25 25
 class wpshop_install
26 26
 {
27 27
 
28
-    /**
29
-     *    Define the action launch when plugin is activate
30
-     *
31
-     * @return void
32
-     */
33
-    public static function install_on_activation()
34
-    {
35
-        /*    Create the different option needed for the plugin work properly    */
36
-        add_option('wpshop_db_options', array('db_version' => 0));
37
-        add_option('wpshop_shop_default_currency', WPSHOP_SHOP_DEFAULT_CURRENCY);
38
-        add_option('wpshop_emails', array('noreply_email' => get_bloginfo('admin_email'), 'contact_email' => get_bloginfo('admin_email')));
39
-        add_option('wpshop_catalog_product_option', array('wpshop_catalog_product_slug' => WPSHOP_CATALOG_PRODUCT_SLUG));
40
-        add_option('wpshop_catalog_categories_option', array('wpshop_catalog_categories_slug' => WPSHOP_CATALOG_CATEGORIES_SLUG));
41
-        add_option('wpshop_display_option', array('wpshop_display_list_type' => 'grid', 'wpshop_display_grid_element_number' => '3', 'wpshop_display_cat_sheet_output' => array('category_description', 'category_subcategory', 'category_subproduct')));
42
-    }
43
-
44
-    /**
45
-     *    Create the default pages
46
-     */
47
-    public static function wpshop_insert_default_pages($pages_type = '')
48
-    {
49
-        global $wpdb, $wp_rewrite;
50
-
51
-        /**    if we will create any new pages we need to flush page cache */
52
-        $page_creation = false;
53
-        $created_pages = array();
54
-
55
-        /** Default data array for add page */
56
-        $page_default_args = array(
57
-            'post_type' => 'page',
58
-            'comment_status' => 'closed',
59
-            'ping_status' => 'closed',
60
-            'post_status' => 'publish',
61
-            'post_author' => get_current_user_id(),
62
-        );
63
-
64
-        /**    Get defined shop type    */
65
-        $wpshop_shop_type = !empty($pages_type) ? $pages_type : get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
66
-
67
-        /**    Get the default datas for installation - Pages    */
68
-        $xml_default_pages = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_pages.xml');
69
-        $defined_default_pages = new SimpleXMLElement($xml_default_pages);
70
-        foreach ($defined_default_pages->xpath('//pages/page') as $page) {
71
-            if (($wpshop_shop_type == $page->attributes()->shop_type) || ('sale' == $wpshop_shop_type)) {
72
-                $page_id = null;
73
-
74
-                /**    Do a specific check for cart page, for old wpshop installation    */
75
-                if ('wpshop_cart_page_id' == (string) $page->attributes()->code) {
76
-                    $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s	AND post_type != %s", '%[wpshop_basket]%', 'revision');
77
-                    $page_id = $wpdb->get_var($query);
78
-
79
-                    wp_update_post(array(
80
-                        'ID' => $page_id,
81
-                        'post_content' => (string) $page->content,
82
-                    ));
83
-                }
84
-
85
-                /**    Check if a page exists with the current content readed form xml file    */
86
-                if (empty($page_id)) {
87
-                    $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string) $page->content . '%', 'revision');
88
-                    $page_id = $wpdb->get_var($query);
89
-                }
90
-
91
-                /**    If the page does not exists create it    */
92
-                if (empty($page_id)) {
93
-                    $default_page_args = wp_parse_args(array(
94
-                        'post_title' => __((string) $page->title, 'wpshop'),
95
-                        'post_name' => __((string) $page->slug, 'wpshop'),
96
-                        'post_content' => __((string) $page->content, 'wpshop'),
97
-                        'menu_order' => (string) $page->attributes()->position,
98
-                    ), $page_default_args);
99
-
100
-                    $page_id = wp_insert_post($default_page_args);
101
-                    $created_pages[] = (string) $page->attributes()->code;
102
-                }
103
-
104
-                /**    If the page is created or already exists associated the page to the good service    */
105
-                if (!empty($page_id)) {
106
-                    add_option((string) $page->attributes()->code, $page_id);
107
-
108
-                    $page_creation = true;
109
-                }
110
-
111
-            }
112
-        }
113
-
114
-        /**    Check if page have been created in order to do specific action    */
115
-        if (!empty($created_pages)) {
116
-            /**    If cart page and checkout page have just been created, change cart page id into checkout page id    */
117
-            if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) {
118
-                update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id'));
119
-            }
120
-
121
-        }
122
-
123
-        wp_cache_flush();
124
-        /** If new page => empty cache */
125
-        if ($page_creation) {
126
-            wp_cache_delete('all_page_ids', 'pages');
127
-            //    $wp_rewrite->flush_rules();
128
-        }
129
-    }
130
-
131
-    /**
132
-     * Insert sample datas when installing wpshop the first time if the admin choose
133
-     */
134
-    public static function import_sample_datas()
135
-    {
136
-        global $wpdb, $wp_rewrite;
137
-
138
-        /** Default data array for add product */
139
-        $product_default_args = array(
140
-            'comment_status' => 'closed',
141
-            'ping_status' => 'closed',
142
-            'post_status' => 'publish',
143
-            'post_author' => get_current_user_id(),
144
-        );
145
-
146
-        /**    Get the default datas for installation - sample products    */
147
-        $sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml');
148
-        $defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA);
149
-
150
-        $namespaces = $defined_sample_datas->getDocNamespaces();
151
-        if (!isset($namespaces['wp'])) {
152
-            $namespaces['wp'] = 'http://wordpress.org/export/1.1/';
153
-        }
154
-
155
-        if (!isset($namespaces['excerpt'])) {
156
-            $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
157
-        }
158
-
159
-        foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) {
160
-            $dc = $product->children('http://purl.org/dc/elements/1.1/');
161
-            $content = $product->children('http://purl.org/rss/1.0/modules/content/');
162
-            $excerpt = $product->children($namespaces['excerpt']);
163
-            $wp = $product->children($namespaces['wp']);
164
-
165
-            $product_args = wp_parse_args(array(
166
-                'post_title' => (string) $product->title,
167
-                'post_name' => (string) $wp->post_name,
168
-                'post_content' => (string) $content->encoded,
169
-                'post_excerpt' => (string) $excerpt->encoded,
170
-                'post_type' => (string) $wp->post_type,
171
-            ), $product_default_args);
172
-
173
-            $product_id = wp_insert_post($product_args);
174
-
175
-            foreach ($wp->postmeta as $meta) {
176
-                update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value);
177
-            }
178
-
179
-            foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) {
180
-                $wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/');
181
-                $wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/');
182
-                $wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']);
183
-                $wps_pdt_var_wp = $product_variation->children($namespaces['wp']);
184
-
185
-                $product_args = wp_parse_args(array(
186
-                    'post_title' => (string) $product_variation->title,
187
-                    'post_name' => (string) $wps_pdt_var_wp->post_name,
188
-                    'post_content' => (string) $wps_pdt_var_content->encoded,
189
-                    'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded,
190
-                    'post_type' => (string) $wps_pdt_var_wp->post_type,
191
-                    'post_parent' => $product_id,
192
-                ), $product_default_args);
193
-
194
-                $product_variation_id = wp_insert_post($product_args);
195
-
196
-                foreach ($wps_pdt_var_wp->postmeta as $meta) {
197
-                    update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value);
198
-                }
199
-            }
200
-        }
201
-    }
202
-
203
-    /**
204
-     * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content.
205
-     */
206
-    public static function update_wpshop_dev()
207
-    {
208
-        global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update;
209
-
210
-        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
211
-
212
-        self::execute_operation_on_db_for_update('dev');
213
-    }
214
-
215
-    /**
216
-     * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content.
217
-     */
218
-    public static function update_wpshop()
219
-    {
220
-        global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update;
221
-        $do_changes = false;
222
-
223
-        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
224
-
225
-        $current_db_version = get_option('wpshop_db_options', 0);
226
-        $current_db_version = $current_db_version['db_version'];
227
-
228
-        $current_def_max_version = max(array_keys($wpshop_update_way));
229
-        $new_version = $current_def_max_version + 1;
230
-        $version_nb_delta = $current_def_max_version - $current_db_version;
231
-
232
-        /*    Check if there are modification to do    */
233
-        if ($current_def_max_version >= $current_db_version) {
234
-            /*    Check the lowest version of db to execute    */
235
-            $lowest_version_to_execute = $current_def_max_version - $version_nb_delta;
236
-
237
-            for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) {
238
-                $do_changes = self::execute_operation_on_db_for_update($i);
239
-            }
240
-        }
241
-
242
-        /*    Update the db version option value    */
243
-        if ($do_changes) {
244
-            $db_version = get_option('wpshop_db_options', 0);
245
-            $db_version['db_version'] = $new_version;
246
-            update_option('wpshop_db_options', $db_version);
247
-        }
248
-    }
249
-
250
-    /**
251
-     * Update db structure on each plugin update
252
-     *
253
-     * @param integer $i The current plugin db version
254
-     * @return boolean If the changes are done correctly or not
255
-     */
256
-    public static function alter_db_structure_on_update($i)
257
-    {
258
-        $do_changes = false;
259
-        global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete;
260
-
261
-        /*    Check if there are modification to do    */
262
-        if (isset($wpshop_update_way[$i])) {
263
-            /*    Check if there are modification to make on table    */
264
-            if (isset($wpshop_db_table_list[$i])) {
265
-                foreach ($wpshop_db_table_list[$i] as $table_name) {
266
-                    dbDelta($wpshop_db_table[$table_name]);
267
-                }
268
-                $do_changes = true;
269
-            }
270
-
271
-            /*    Request maker    */
272
-            if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) {
273
-                foreach ($wpshop_db_request[$i] as $request) {
274
-                    $wpdb->query($request);
275
-                    $do_changes = true;
276
-                }
277
-            }
278
-
279
-            /*    Delete datas    */
280
-            if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) {
281
-                foreach ($wpshop_db_delete[$i] as $request) {
282
-                    $wpdb->query($request);
283
-                }
284
-            }
285
-        }
286
-
287
-        return $do_changes;
288
-    }
289
-
290
-    /**
291
-     * Do changes on database for wpshop plugin for a given version
292
-     *
293
-     * @param integer $i The wpshop db version to execute operation for
294
-     *
295
-     * @return boolean
296
-     */
297
-    public static function execute_operation_on_db_for_update($i)
298
-    {
299
-        global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete;
300
-        $do_changes = false;
301
-
302
-        /*    Check if there are modification to do    */
303
-        if (isset($wpshop_update_way[$i])) {
304
-            $do_changes = self::alter_db_structure_on_update($i);
305
-
306
-            /********************/
307
-            /*        Insert data        */
308
-            /********************/
309
-            /*    Options content    */
310
-            if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) {
311
-                foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) {
312
-                    add_option($option_name, $option_content, '', 'yes');
313
-                }
314
-                $do_changes = true;
315
-            }
316
-            if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) {
317
-                foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) {
318
-                    $option_current_content = get_option($option_name);
319
-                    foreach ($option_content as $option_key => $option_value) {
320
-                        $option_current_content[$option_key] = $option_value;
321
-                    }
322
-                    update_option($option_name, $option_current_content);
323
-                }
324
-                $do_changes = true;
325
-            }
326
-
327
-            /*    Eav content    */
328
-            if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) {
329
-                $do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes);
330
-            }
331
-            /*    Eav content update    */
332
-            if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) {
333
-                $do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes);
334
-            }
335
-
336
-            /*    Add datas    */
337
-            if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) {
338
-                foreach ($wpshop_db_content_add[$i] as $table_name => $def) {
339
-                    foreach ($def as $information_index => $table_information) {
340
-                        $wpdb->insert($table_name, $table_information, '%s');
341
-                        $do_changes = true;
342
-                    }
343
-                }
344
-            }
345
-
346
-            /*    Update datas    */
347
-            if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) {
348
-                foreach ($wpshop_db_content_update[$i] as $table_name => $def) {
349
-                    foreach ($def as $information_index => $table_information) {
350
-                        $wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s');
351
-                        $do_changes = true;
352
-                    }
353
-                }
354
-            }
355
-        }
356
-
357
-        $do_changes = self::make_specific_operation_on_update($i);
358
-
359
-        return $do_changes;
360
-    }
361
-
362
-    /**
363
-     * Create specific data in eav db model
364
-     *
365
-     * @param array $eav_content The complete array with all element to create into database
366
-     * @param boolean $do_changes The current state of changes to do
367
-     *
368
-     * @return boolean If there are changes to do or not
369
-     */
370
-    public static function add_content_to_eav($eav_content, $do_changes)
371
-    {
372
-        global $wpdb;
373
-        /*    Create entities if entites are set to be created for the current version    */
374
-        if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) {
375
-            foreach ($eav_content['entities'] as $entity) {
376
-                /*    Creation de l'entité produit dans la table des posts    */
377
-                wpshop_entities::create_cpt_from_csv_file($entity);
378
-            }
379
-            $do_changes = true;
380
-        }
381
-
382
-        /*    Create attributes for a given entity if attributes are set to be created for current version    */
383
-        if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) {
384
-            foreach ($eav_content['attributes'] as $entity_code) {
385
-                wpshop_entities::create_cpt_attributes_from_csv_file($entity_code);
386
-            }
387
-            $do_changes = true;
388
-        }
389
-
390
-        /*    Create attribute groups for a given entity if attributes groups are set to be created for current version    */
391
-        if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) {
392
-            foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) {
393
-                $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code);
394
-
395
-                if ($entity_id > 0) {
396
-                    foreach ($attribute_set as $set_name => $set_groups) {
397
-                        $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase')));
398
-                        $attribute_set_id = $wpdb->get_var($query);
399
-                        if ($attribute_set_id <= 0) {
400
-                            $attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name);
401
-                            if ($set_name == 'default') {
402
-                                $attribute_set_content['default_set'] = 'yes';
403
-                            }
404
-                            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content);
405
-                            $attribute_set_id = $wpdb->insert_id;
406
-                        }
407
-
408
-                        if ($attribute_set_id > 0) {
409
-                            foreach ($set_groups as $set_group_infos) {
410
-                                $set_group_infos_details = $set_group_infos['details'];
411
-                                unset($set_group_infos['details']);
412
-                                /*    Change an attribute set status if definition specify this param     */
413
-                                if (isset($set_group_infos['status'])) {
414
-                                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id));
415
-                                }
416
-                                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']);
417
-                                $attribute_set_section_id = $wpdb->get_var($query);
418
-                                if ($attribute_set_section_id <= 0) {
419
-                                    $new_set_section_infos = $set_group_infos;
420
-                                    $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid');
421
-                                    $new_set_section_infos['creation_date'] = current_time('mysql', 0);
422
-                                    $new_set_section_infos['attribute_set_id'] = $attribute_set_id;
423
-                                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos);
424
-                                    $attribute_set_section_id = $wpdb->insert_id;
425
-                                }
426
-
427
-                                if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) {
428
-                                    $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id);
429
-                                    $last_position = $wpdb->get_var($query);
430
-                                    $position = (int) $last_position + 1;
431
-                                    foreach ($set_group_infos_details as $attribute_code) {
432
-                                        $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
433
-                                        $attribute_id = $wpdb->get_row($query);
434
-
435
-                                        if ($attribute_id->id > 0) {
436
-                                            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position));
437
-                                            $position++;
438
-                                        }
439
-                                    }
440
-                                }
441
-
442
-                            }
443
-                        }
444
-                    }
445
-                }
446
-            }
447
-            $do_changes = true;
448
-        }
449
-
450
-        return $do_changes;
451
-    }
452
-
453
-    /**
454
-     * Update specific data in eav db model
455
-     *
456
-     * @param array $eav_content The complete array with all element to create into database
457
-     * @param boolean $do_changes The current state of changes to do
458
-     *
459
-     * @return boolean If there are changes to do or not
460
-     */
461
-    public static function update_eav_content($eav_content, $do_changes)
462
-    {
463
-        /*    Update attributes fo a given entity if attributes are set to be updated for current version    */
464
-        if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) {
465
-            foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) {
466
-                foreach ($attribute_definition as $attribute_def) {
467
-                    $option_list_for_attribute = '';
468
-                    if (isset($attribute_def['backend_input_values'])) {
469
-                        $option_list_for_attribute = $attribute_def['backend_input_values'];
470
-                        unset($attribute_def['backend_input_values']);
471
-                    }
472
-
473
-                    /*    Get entity identifier from code    */
474
-                    $attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code);
475
-                    $attribute_def['status'] = $attribute_def['attribute_status'];
476
-                    unset($attribute_def['attribute_status']);
477
-                    $attribute_def['last_update_date'] = current_time('mysql', 0);
478
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code']));
479
-                    $attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code']));
480
-
481
-                    /*    Insert option values if there are some to add for the current attribute    */
482
-                    if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) {
483
-                        foreach ($option_list_for_attribute as $option_code => $option_value) {
484
-                            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value));
485
-                            if ($option_code == $attribute_def['default_value']) {
486
-                                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code));
487
-                            }
488
-                        }
489
-                    }
490
-                }
491
-            }
492
-            $do_changes = true;
493
-        }
494
-
495
-        /*    Update attribute groups fo a given entity if attributes groups are set to be updated for current version    */
496
-        if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) {
497
-            foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) {
498
-                $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code);
499
-
500
-                if ($entity_id > 0) {
501
-                    foreach ($attribute_set as $set_name => $set_groups) {
502
-                        $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase')));
503
-                        $attribute_set_id = $wpdb->get_var($query);
504
-                        if ($attribute_set_id <= 0) {
505
-                            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name));
506
-                            $attribute_set_id = $wpdb->insert_id;
507
-                        }
508
-
509
-                        if ($attribute_set_id > 0) {
510
-                            foreach ($set_groups as $set_group_infos) {
511
-                                $set_group_infos_details = $set_group_infos['details'];
512
-                                unset($set_group_infos['details']);
513
-                                /*    Change an attribute set status if definition specify this param     */
514
-                                if (isset($set_group_infos['status'])) {
515
-                                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id));
516
-                                }
517
-                                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']);
518
-                                $attribute_set_section_id = $wpdb->get_var($query);
519
-                                if ($attribute_set_section_id <= 0) {
520
-                                    $new_set_section_infos = $set_group_infos;
521
-                                    $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid');
522
-                                    $new_set_section_infos['creation_date'] = current_time('mysql', 0);
523
-                                    $new_set_section_infos['attribute_set_id'] = $attribute_set_id;
524
-                                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos);
525
-                                    $attribute_set_section_id = $wpdb->insert_id;
526
-                                } else {
527
-                                    $new_set_section_infos = $set_group_infos;
528
-                                    $new_set_section_infos['last_update_date'] = current_time('mysql', 0);
529
-                                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id));
530
-                                }
531
-
532
-                                if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) {
533
-                                    if (count($set_group_infos_details) <= 0) {
534
-                                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id));
535
-                                    } else {
536
-                                        $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id);
537
-                                        $last_position = $wpdb->get_var($query);
538
-                                        $position = (int) $last_position + 1;
539
-                                        foreach ($set_group_infos_details as $attribute_code) {
540
-                                            $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
541
-                                            $attribute_id = $wpdb->get_var($query);
542
-                                            if ($attribute_id > 0) {
543
-                                                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position));
544
-                                                $position++;
545
-                                            }
546
-                                        }
547
-                                    }
548
-                                }
549
-                            }
550
-                        }
551
-                    }
552
-                }
553
-            }
554
-            $do_changes = true;
555
-        }
556
-
557
-        return $do_changes;
558
-    }
559
-
560
-    /**
561
-     * Manage special operation on wpshop plugin update
562
-     */
563
-    public static function make_specific_operation_on_update($version)
564
-    {
565
-        global $wpdb, $wp_rewrite;
566
-        $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
567
-
568
-        switch ($version) {
569
-            case 3:
570
-            case 6:
571
-                self::wpshop_insert_default_pages($wpshop_shop_type);
572
-                wp_cache_flush();
573
-                return true;
574
-                break;
575
-            case 8:
576
-                /**    Change metaboxes order for product in case it already exists    */
577
-                $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product');
578
-                $customer_metaboxes_order = $wpdb->get_results($query);
579
-                if (!empty($customer_metaboxes_order)) {
580
-                    foreach ($customer_metaboxes_order as $customer_metabox_order) {
581
-                        $do_changes = false;
582
-                        $current_order = unserialize($customer_metabox_order->meta_value);
583
-                        if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) {
584
-                            str_replace('wpshop_product_important_datas,', '', $current_order['normal']);
585
-                            $do_changes = true;
586
-                        }
587
-
588
-                        if (array_key_exists('side', $current_order)) {
589
-                            str_replace('wpshop_product_important_datas,', '', $current_order['side']);
590
-                            str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']);
591
-                            $do_changes = true;
592
-                        }
593
-
594
-                        if (true === $do_changes) {
595
-                            $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id));
596
-                        }
597
-                    }
598
-                } else {
599
-                    $users = get_users(array('role' => 'administrator'));
600
-                    if (!empty($users)) {
601
-                        foreach ($users as $user) {
602
-                            $user_meta = array(
603
-                                'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv',
604
-                                'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic',
605
-                                'advanced' => '',
606
-                            );
607
-                            update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta);
608
-                        }
609
-                    }
610
-                }
611
-
612
-                /*    Update the product prices into database    */
613
-                $query = $wpdb->prepare("
28
+	/**
29
+	 *    Define the action launch when plugin is activate
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public static function install_on_activation()
34
+	{
35
+		/*    Create the different option needed for the plugin work properly    */
36
+		add_option('wpshop_db_options', array('db_version' => 0));
37
+		add_option('wpshop_shop_default_currency', WPSHOP_SHOP_DEFAULT_CURRENCY);
38
+		add_option('wpshop_emails', array('noreply_email' => get_bloginfo('admin_email'), 'contact_email' => get_bloginfo('admin_email')));
39
+		add_option('wpshop_catalog_product_option', array('wpshop_catalog_product_slug' => WPSHOP_CATALOG_PRODUCT_SLUG));
40
+		add_option('wpshop_catalog_categories_option', array('wpshop_catalog_categories_slug' => WPSHOP_CATALOG_CATEGORIES_SLUG));
41
+		add_option('wpshop_display_option', array('wpshop_display_list_type' => 'grid', 'wpshop_display_grid_element_number' => '3', 'wpshop_display_cat_sheet_output' => array('category_description', 'category_subcategory', 'category_subproduct')));
42
+	}
43
+
44
+	/**
45
+	 *    Create the default pages
46
+	 */
47
+	public static function wpshop_insert_default_pages($pages_type = '')
48
+	{
49
+		global $wpdb, $wp_rewrite;
50
+
51
+		/**    if we will create any new pages we need to flush page cache */
52
+		$page_creation = false;
53
+		$created_pages = array();
54
+
55
+		/** Default data array for add page */
56
+		$page_default_args = array(
57
+			'post_type' => 'page',
58
+			'comment_status' => 'closed',
59
+			'ping_status' => 'closed',
60
+			'post_status' => 'publish',
61
+			'post_author' => get_current_user_id(),
62
+		);
63
+
64
+		/**    Get defined shop type    */
65
+		$wpshop_shop_type = !empty($pages_type) ? $pages_type : get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
66
+
67
+		/**    Get the default datas for installation - Pages    */
68
+		$xml_default_pages = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_pages.xml');
69
+		$defined_default_pages = new SimpleXMLElement($xml_default_pages);
70
+		foreach ($defined_default_pages->xpath('//pages/page') as $page) {
71
+			if (($wpshop_shop_type == $page->attributes()->shop_type) || ('sale' == $wpshop_shop_type)) {
72
+				$page_id = null;
73
+
74
+				/**    Do a specific check for cart page, for old wpshop installation    */
75
+				if ('wpshop_cart_page_id' == (string) $page->attributes()->code) {
76
+					$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s	AND post_type != %s", '%[wpshop_basket]%', 'revision');
77
+					$page_id = $wpdb->get_var($query);
78
+
79
+					wp_update_post(array(
80
+						'ID' => $page_id,
81
+						'post_content' => (string) $page->content,
82
+					));
83
+				}
84
+
85
+				/**    Check if a page exists with the current content readed form xml file    */
86
+				if (empty($page_id)) {
87
+					$query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string) $page->content . '%', 'revision');
88
+					$page_id = $wpdb->get_var($query);
89
+				}
90
+
91
+				/**    If the page does not exists create it    */
92
+				if (empty($page_id)) {
93
+					$default_page_args = wp_parse_args(array(
94
+						'post_title' => __((string) $page->title, 'wpshop'),
95
+						'post_name' => __((string) $page->slug, 'wpshop'),
96
+						'post_content' => __((string) $page->content, 'wpshop'),
97
+						'menu_order' => (string) $page->attributes()->position,
98
+					), $page_default_args);
99
+
100
+					$page_id = wp_insert_post($default_page_args);
101
+					$created_pages[] = (string) $page->attributes()->code;
102
+				}
103
+
104
+				/**    If the page is created or already exists associated the page to the good service    */
105
+				if (!empty($page_id)) {
106
+					add_option((string) $page->attributes()->code, $page_id);
107
+
108
+					$page_creation = true;
109
+				}
110
+
111
+			}
112
+		}
113
+
114
+		/**    Check if page have been created in order to do specific action    */
115
+		if (!empty($created_pages)) {
116
+			/**    If cart page and checkout page have just been created, change cart page id into checkout page id    */
117
+			if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) {
118
+				update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id'));
119
+			}
120
+
121
+		}
122
+
123
+		wp_cache_flush();
124
+		/** If new page => empty cache */
125
+		if ($page_creation) {
126
+			wp_cache_delete('all_page_ids', 'pages');
127
+			//    $wp_rewrite->flush_rules();
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Insert sample datas when installing wpshop the first time if the admin choose
133
+	 */
134
+	public static function import_sample_datas()
135
+	{
136
+		global $wpdb, $wp_rewrite;
137
+
138
+		/** Default data array for add product */
139
+		$product_default_args = array(
140
+			'comment_status' => 'closed',
141
+			'ping_status' => 'closed',
142
+			'post_status' => 'publish',
143
+			'post_author' => get_current_user_id(),
144
+		);
145
+
146
+		/**    Get the default datas for installation - sample products    */
147
+		$sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml');
148
+		$defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA);
149
+
150
+		$namespaces = $defined_sample_datas->getDocNamespaces();
151
+		if (!isset($namespaces['wp'])) {
152
+			$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
153
+		}
154
+
155
+		if (!isset($namespaces['excerpt'])) {
156
+			$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
157
+		}
158
+
159
+		foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) {
160
+			$dc = $product->children('http://purl.org/dc/elements/1.1/');
161
+			$content = $product->children('http://purl.org/rss/1.0/modules/content/');
162
+			$excerpt = $product->children($namespaces['excerpt']);
163
+			$wp = $product->children($namespaces['wp']);
164
+
165
+			$product_args = wp_parse_args(array(
166
+				'post_title' => (string) $product->title,
167
+				'post_name' => (string) $wp->post_name,
168
+				'post_content' => (string) $content->encoded,
169
+				'post_excerpt' => (string) $excerpt->encoded,
170
+				'post_type' => (string) $wp->post_type,
171
+			), $product_default_args);
172
+
173
+			$product_id = wp_insert_post($product_args);
174
+
175
+			foreach ($wp->postmeta as $meta) {
176
+				update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value);
177
+			}
178
+
179
+			foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) {
180
+				$wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/');
181
+				$wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/');
182
+				$wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']);
183
+				$wps_pdt_var_wp = $product_variation->children($namespaces['wp']);
184
+
185
+				$product_args = wp_parse_args(array(
186
+					'post_title' => (string) $product_variation->title,
187
+					'post_name' => (string) $wps_pdt_var_wp->post_name,
188
+					'post_content' => (string) $wps_pdt_var_content->encoded,
189
+					'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded,
190
+					'post_type' => (string) $wps_pdt_var_wp->post_type,
191
+					'post_parent' => $product_id,
192
+				), $product_default_args);
193
+
194
+				$product_variation_id = wp_insert_post($product_args);
195
+
196
+				foreach ($wps_pdt_var_wp->postmeta as $meta) {
197
+					update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value);
198
+				}
199
+			}
200
+		}
201
+	}
202
+
203
+	/**
204
+	 * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content.
205
+	 */
206
+	public static function update_wpshop_dev()
207
+	{
208
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update;
209
+
210
+		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
211
+
212
+		self::execute_operation_on_db_for_update('dev');
213
+	}
214
+
215
+	/**
216
+	 * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content.
217
+	 */
218
+	public static function update_wpshop()
219
+	{
220
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update;
221
+		$do_changes = false;
222
+
223
+		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
224
+
225
+		$current_db_version = get_option('wpshop_db_options', 0);
226
+		$current_db_version = $current_db_version['db_version'];
227
+
228
+		$current_def_max_version = max(array_keys($wpshop_update_way));
229
+		$new_version = $current_def_max_version + 1;
230
+		$version_nb_delta = $current_def_max_version - $current_db_version;
231
+
232
+		/*    Check if there are modification to do    */
233
+		if ($current_def_max_version >= $current_db_version) {
234
+			/*    Check the lowest version of db to execute    */
235
+			$lowest_version_to_execute = $current_def_max_version - $version_nb_delta;
236
+
237
+			for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) {
238
+				$do_changes = self::execute_operation_on_db_for_update($i);
239
+			}
240
+		}
241
+
242
+		/*    Update the db version option value    */
243
+		if ($do_changes) {
244
+			$db_version = get_option('wpshop_db_options', 0);
245
+			$db_version['db_version'] = $new_version;
246
+			update_option('wpshop_db_options', $db_version);
247
+		}
248
+	}
249
+
250
+	/**
251
+	 * Update db structure on each plugin update
252
+	 *
253
+	 * @param integer $i The current plugin db version
254
+	 * @return boolean If the changes are done correctly or not
255
+	 */
256
+	public static function alter_db_structure_on_update($i)
257
+	{
258
+		$do_changes = false;
259
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete;
260
+
261
+		/*    Check if there are modification to do    */
262
+		if (isset($wpshop_update_way[$i])) {
263
+			/*    Check if there are modification to make on table    */
264
+			if (isset($wpshop_db_table_list[$i])) {
265
+				foreach ($wpshop_db_table_list[$i] as $table_name) {
266
+					dbDelta($wpshop_db_table[$table_name]);
267
+				}
268
+				$do_changes = true;
269
+			}
270
+
271
+			/*    Request maker    */
272
+			if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) {
273
+				foreach ($wpshop_db_request[$i] as $request) {
274
+					$wpdb->query($request);
275
+					$do_changes = true;
276
+				}
277
+			}
278
+
279
+			/*    Delete datas    */
280
+			if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) {
281
+				foreach ($wpshop_db_delete[$i] as $request) {
282
+					$wpdb->query($request);
283
+				}
284
+			}
285
+		}
286
+
287
+		return $do_changes;
288
+	}
289
+
290
+	/**
291
+	 * Do changes on database for wpshop plugin for a given version
292
+	 *
293
+	 * @param integer $i The wpshop db version to execute operation for
294
+	 *
295
+	 * @return boolean
296
+	 */
297
+	public static function execute_operation_on_db_for_update($i)
298
+	{
299
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete;
300
+		$do_changes = false;
301
+
302
+		/*    Check if there are modification to do    */
303
+		if (isset($wpshop_update_way[$i])) {
304
+			$do_changes = self::alter_db_structure_on_update($i);
305
+
306
+			/********************/
307
+			/*        Insert data        */
308
+			/********************/
309
+			/*    Options content    */
310
+			if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) {
311
+				foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) {
312
+					add_option($option_name, $option_content, '', 'yes');
313
+				}
314
+				$do_changes = true;
315
+			}
316
+			if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) {
317
+				foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) {
318
+					$option_current_content = get_option($option_name);
319
+					foreach ($option_content as $option_key => $option_value) {
320
+						$option_current_content[$option_key] = $option_value;
321
+					}
322
+					update_option($option_name, $option_current_content);
323
+				}
324
+				$do_changes = true;
325
+			}
326
+
327
+			/*    Eav content    */
328
+			if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) {
329
+				$do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes);
330
+			}
331
+			/*    Eav content update    */
332
+			if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) {
333
+				$do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes);
334
+			}
335
+
336
+			/*    Add datas    */
337
+			if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) {
338
+				foreach ($wpshop_db_content_add[$i] as $table_name => $def) {
339
+					foreach ($def as $information_index => $table_information) {
340
+						$wpdb->insert($table_name, $table_information, '%s');
341
+						$do_changes = true;
342
+					}
343
+				}
344
+			}
345
+
346
+			/*    Update datas    */
347
+			if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) {
348
+				foreach ($wpshop_db_content_update[$i] as $table_name => $def) {
349
+					foreach ($def as $information_index => $table_information) {
350
+						$wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s');
351
+						$do_changes = true;
352
+					}
353
+				}
354
+			}
355
+		}
356
+
357
+		$do_changes = self::make_specific_operation_on_update($i);
358
+
359
+		return $do_changes;
360
+	}
361
+
362
+	/**
363
+	 * Create specific data in eav db model
364
+	 *
365
+	 * @param array $eav_content The complete array with all element to create into database
366
+	 * @param boolean $do_changes The current state of changes to do
367
+	 *
368
+	 * @return boolean If there are changes to do or not
369
+	 */
370
+	public static function add_content_to_eav($eav_content, $do_changes)
371
+	{
372
+		global $wpdb;
373
+		/*    Create entities if entites are set to be created for the current version    */
374
+		if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) {
375
+			foreach ($eav_content['entities'] as $entity) {
376
+				/*    Creation de l'entité produit dans la table des posts    */
377
+				wpshop_entities::create_cpt_from_csv_file($entity);
378
+			}
379
+			$do_changes = true;
380
+		}
381
+
382
+		/*    Create attributes for a given entity if attributes are set to be created for current version    */
383
+		if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) {
384
+			foreach ($eav_content['attributes'] as $entity_code) {
385
+				wpshop_entities::create_cpt_attributes_from_csv_file($entity_code);
386
+			}
387
+			$do_changes = true;
388
+		}
389
+
390
+		/*    Create attribute groups for a given entity if attributes groups are set to be created for current version    */
391
+		if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) {
392
+			foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) {
393
+				$entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code);
394
+
395
+				if ($entity_id > 0) {
396
+					foreach ($attribute_set as $set_name => $set_groups) {
397
+						$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase')));
398
+						$attribute_set_id = $wpdb->get_var($query);
399
+						if ($attribute_set_id <= 0) {
400
+							$attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name);
401
+							if ($set_name == 'default') {
402
+								$attribute_set_content['default_set'] = 'yes';
403
+							}
404
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content);
405
+							$attribute_set_id = $wpdb->insert_id;
406
+						}
407
+
408
+						if ($attribute_set_id > 0) {
409
+							foreach ($set_groups as $set_group_infos) {
410
+								$set_group_infos_details = $set_group_infos['details'];
411
+								unset($set_group_infos['details']);
412
+								/*    Change an attribute set status if definition specify this param     */
413
+								if (isset($set_group_infos['status'])) {
414
+									$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id));
415
+								}
416
+								$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']);
417
+								$attribute_set_section_id = $wpdb->get_var($query);
418
+								if ($attribute_set_section_id <= 0) {
419
+									$new_set_section_infos = $set_group_infos;
420
+									$new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid');
421
+									$new_set_section_infos['creation_date'] = current_time('mysql', 0);
422
+									$new_set_section_infos['attribute_set_id'] = $attribute_set_id;
423
+									$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos);
424
+									$attribute_set_section_id = $wpdb->insert_id;
425
+								}
426
+
427
+								if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) {
428
+									$query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id);
429
+									$last_position = $wpdb->get_var($query);
430
+									$position = (int) $last_position + 1;
431
+									foreach ($set_group_infos_details as $attribute_code) {
432
+										$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
433
+										$attribute_id = $wpdb->get_row($query);
434
+
435
+										if ($attribute_id->id > 0) {
436
+											$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position));
437
+											$position++;
438
+										}
439
+									}
440
+								}
441
+
442
+							}
443
+						}
444
+					}
445
+				}
446
+			}
447
+			$do_changes = true;
448
+		}
449
+
450
+		return $do_changes;
451
+	}
452
+
453
+	/**
454
+	 * Update specific data in eav db model
455
+	 *
456
+	 * @param array $eav_content The complete array with all element to create into database
457
+	 * @param boolean $do_changes The current state of changes to do
458
+	 *
459
+	 * @return boolean If there are changes to do or not
460
+	 */
461
+	public static function update_eav_content($eav_content, $do_changes)
462
+	{
463
+		/*    Update attributes fo a given entity if attributes are set to be updated for current version    */
464
+		if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) {
465
+			foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) {
466
+				foreach ($attribute_definition as $attribute_def) {
467
+					$option_list_for_attribute = '';
468
+					if (isset($attribute_def['backend_input_values'])) {
469
+						$option_list_for_attribute = $attribute_def['backend_input_values'];
470
+						unset($attribute_def['backend_input_values']);
471
+					}
472
+
473
+					/*    Get entity identifier from code    */
474
+					$attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code);
475
+					$attribute_def['status'] = $attribute_def['attribute_status'];
476
+					unset($attribute_def['attribute_status']);
477
+					$attribute_def['last_update_date'] = current_time('mysql', 0);
478
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code']));
479
+					$attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code']));
480
+
481
+					/*    Insert option values if there are some to add for the current attribute    */
482
+					if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) {
483
+						foreach ($option_list_for_attribute as $option_code => $option_value) {
484
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value));
485
+							if ($option_code == $attribute_def['default_value']) {
486
+								$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code));
487
+							}
488
+						}
489
+					}
490
+				}
491
+			}
492
+			$do_changes = true;
493
+		}
494
+
495
+		/*    Update attribute groups fo a given entity if attributes groups are set to be updated for current version    */
496
+		if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) {
497
+			foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) {
498
+				$entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code);
499
+
500
+				if ($entity_id > 0) {
501
+					foreach ($attribute_set as $set_name => $set_groups) {
502
+						$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase')));
503
+						$attribute_set_id = $wpdb->get_var($query);
504
+						if ($attribute_set_id <= 0) {
505
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name));
506
+							$attribute_set_id = $wpdb->insert_id;
507
+						}
508
+
509
+						if ($attribute_set_id > 0) {
510
+							foreach ($set_groups as $set_group_infos) {
511
+								$set_group_infos_details = $set_group_infos['details'];
512
+								unset($set_group_infos['details']);
513
+								/*    Change an attribute set status if definition specify this param     */
514
+								if (isset($set_group_infos['status'])) {
515
+									$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id));
516
+								}
517
+								$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']);
518
+								$attribute_set_section_id = $wpdb->get_var($query);
519
+								if ($attribute_set_section_id <= 0) {
520
+									$new_set_section_infos = $set_group_infos;
521
+									$new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid');
522
+									$new_set_section_infos['creation_date'] = current_time('mysql', 0);
523
+									$new_set_section_infos['attribute_set_id'] = $attribute_set_id;
524
+									$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos);
525
+									$attribute_set_section_id = $wpdb->insert_id;
526
+								} else {
527
+									$new_set_section_infos = $set_group_infos;
528
+									$new_set_section_infos['last_update_date'] = current_time('mysql', 0);
529
+									$wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id));
530
+								}
531
+
532
+								if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) {
533
+									if (count($set_group_infos_details) <= 0) {
534
+										$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id));
535
+									} else {
536
+										$query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id);
537
+										$last_position = $wpdb->get_var($query);
538
+										$position = (int) $last_position + 1;
539
+										foreach ($set_group_infos_details as $attribute_code) {
540
+											$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
541
+											$attribute_id = $wpdb->get_var($query);
542
+											if ($attribute_id > 0) {
543
+												$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position));
544
+												$position++;
545
+											}
546
+										}
547
+									}
548
+								}
549
+							}
550
+						}
551
+					}
552
+				}
553
+			}
554
+			$do_changes = true;
555
+		}
556
+
557
+		return $do_changes;
558
+	}
559
+
560
+	/**
561
+	 * Manage special operation on wpshop plugin update
562
+	 */
563
+	public static function make_specific_operation_on_update($version)
564
+	{
565
+		global $wpdb, $wp_rewrite;
566
+		$wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
567
+
568
+		switch ($version) {
569
+			case 3:
570
+			case 6:
571
+				self::wpshop_insert_default_pages($wpshop_shop_type);
572
+				wp_cache_flush();
573
+				return true;
574
+				break;
575
+			case 8:
576
+				/**    Change metaboxes order for product in case it already exists    */
577
+				$query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product');
578
+				$customer_metaboxes_order = $wpdb->get_results($query);
579
+				if (!empty($customer_metaboxes_order)) {
580
+					foreach ($customer_metaboxes_order as $customer_metabox_order) {
581
+						$do_changes = false;
582
+						$current_order = unserialize($customer_metabox_order->meta_value);
583
+						if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) {
584
+							str_replace('wpshop_product_important_datas,', '', $current_order['normal']);
585
+							$do_changes = true;
586
+						}
587
+
588
+						if (array_key_exists('side', $current_order)) {
589
+							str_replace('wpshop_product_important_datas,', '', $current_order['side']);
590
+							str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']);
591
+							$do_changes = true;
592
+						}
593
+
594
+						if (true === $do_changes) {
595
+							$wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id));
596
+						}
597
+					}
598
+				} else {
599
+					$users = get_users(array('role' => 'administrator'));
600
+					if (!empty($users)) {
601
+						foreach ($users as $user) {
602
+							$user_meta = array(
603
+								'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv',
604
+								'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic',
605
+								'advanced' => '',
606
+							);
607
+							update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta);
608
+						}
609
+					}
610
+				}
611
+
612
+				/*    Update the product prices into database    */
613
+				$query = $wpdb->prepare("
614 614
 SELECT
615 615
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price,
616 616
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht,
617 617
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva,
618 618
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva');
619
-                $product_prices = $wpdb->get_row($query);
620
-                $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva));
621
-                $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price);
622
-                $price_list = $wpdb->get_results($query);
623
-                foreach ($price_list as $existing_ttc_price) {
624
-                    $tax_rate = 1.20;
625
-                    $price_ht = $existing_ttc_price->value / $tax_rate;
626
-                    $tax_amount = $existing_ttc_price->value - $price_ht;
627
-
628
-                    $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0)));
629
-                    $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0)));
630
-                    $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0)));
631
-                }
632
-
633
-                /*    Update orders structure into database    */
634
-                $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
635
-                foreach ($orders_id as $o) {
636
-                    $myorder = get_post_meta($o->ID, '_order_postmeta', true);
637
-                    $neworder = array();
638
-                    $items = array();
639
-
640
-                    if (!isset($myorder['order_tva'])) {
641
-                        $order_total_ht = 0;
642
-                        $order_total_ttc = 0;
643
-                        $order_tva = array('20' => 0);
644
-
645
-                        foreach ($myorder['order_items'] as $item) {
646
-                            /* item */
647
-                            $pu_ht = $item['cost'] / 1.20;
648
-                            $pu_tva = $item['cost'] - $pu_ht;
649
-                            $total_ht = $pu_ht * $item['qty'];
650
-                            $tva_total_amount = $pu_tva * $item['qty'];
651
-                            $total_ttc = $item['cost'] * $item['qty'];
652
-                            /* item */
653
-                            $order_total_ht += $total_ht;
654
-                            $order_total_ttc += $total_ttc;
655
-                            $order_tva['20'] += $tva_total_amount;
656
-
657
-                            $items[] = array(
658
-                                'item_id' => $item['id'],
659
-                                'item_ref' => 'Nc',
660
-                                'item_name' => $item['name'],
661
-                                'item_qty' => $item['qty'],
662
-
663
-                                'item_pu_ht' => number_format($pu_ht, 2, '.', ''),
664
-                                'item_pu_ttc' => number_format($item['cost'], 2, '.', ''),
665
-
666
-                                'item_ecotaxe_ht' => number_format(0, 2, '.', ''),
667
-                                'item_ecotaxe_tva' => 20,
668
-                                'item_ecotaxe_ttc' => number_format(0, 2, '.', ''),
669
-
670
-                                'item_discount_type' => 0,
671
-                                'item_discount_value' => 0,
672
-                                'item_discount_amount' => number_format(0, 2, '.', ''),
673
-
674
-                                'item_tva_rate' => 20,
675
-                                'item_tva_amount' => number_format($pu_tva, 2, '.', ''),
676
-
677
-                                'item_total_ht' => number_format($total_ht, 2, '.', ''),
678
-                                'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''),
679
-                                'item_total_ttc' => number_format($total_ttc, 2, '.', ''),
680
-                                /*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/
681
-                            );
682
-                        }
683
-
684
-                        $neworder = array(
685
-                            'order_key' => $myorder['order_key'],
686
-                            'customer_id' => $myorder['customer_id'],
687
-                            'order_status' => $myorder['order_status'],
688
-                            'order_date' => $myorder['order_date'],
689
-                            'order_payment_date' => $myorder['order_payment_date'],
690
-                            'order_shipping_date' => $myorder['order_shipping_date'],
691
-                            'payment_method' => $myorder['payment_method'],
692
-                            'order_invoice_ref' => '',
693
-                            'order_currency' => $myorder['order_currency'],
694
-                            'order_total_ht' => $order_total_ht,
695
-                            'order_total_ttc' => $order_total_ttc,
696
-                            'order_grand_total' => $order_total_ttc,
697
-                            'order_shipping_cost' => number_format(0, 2, '.', ''),
698
-                            'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva),
699
-                            'order_items' => $items,
700
-                        );
701
-                        /* Update the order postmeta */
702
-                        update_post_meta($o->ID, '_order_postmeta', $neworder);
703
-                    }
704
-                }
705
-
706
-                self::wpshop_insert_default_pages($wpshop_shop_type);
707
-                wp_cache_flush();
708
-                return true;
709
-                break;
710
-            case 12:
711
-                $query = "SELECT ID FROM " . $wpdb->users;
712
-                $user_list = $wpdb->get_results($query);
713
-                foreach ($user_list as $user) {
714
-                    $user_first_name = get_user_meta($user->ID, 'first_name', true);
715
-                    $user_last_name = get_user_meta($user->ID, 'last_name', true);
716
-                    $shipping_info = get_user_meta($user->ID, 'shipping_info', true);
717
-
718
-                    if (($user_first_name == '') && !empty($shipping_info['first_name'])) {
719
-                        update_user_meta($user->ID, 'first_name', $shipping_info['first_name']);
720
-                    }
721
-
722
-                    if (($user_last_name == '') && !empty($shipping_info['last_name'])) {
723
-                        update_user_meta($user->ID, 'last_name', $shipping_info['last_name']);
724
-                    }
725
-                }
726
-
727
-                /*    Update orders structure into database    */
728
-                $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
729
-                foreach ($orders_id as $o) {
730
-                    $myorder = get_post_meta($o->ID, '_order_postmeta', true);
731
-                    if (!empty($myorder)) {
732
-                        $new_items = array();
733
-                        foreach ($myorder['order_items'] as $item) {
734
-                            $new_items = $item;
735
-                            $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount';
736
-                            // unset($new_items['item_discount_rate']);
737
-                            $new_items['item_discount_value'] = 0;
738
-                        }
739
-                        $myorder['order_items'] = $new_items;
740
-
741
-                        /* Update the order postmeta */
742
-                        update_post_meta($o->ID, '_order_postmeta', $myorder);
743
-                    }
744
-                }
745
-
746
-                /*    Delete useless database table    */
747
-                $query = "DROP TABLE " . WPSHOP_DBT_CART;
748
-                $wpdb->query($query);
749
-                $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS;
750
-                $wpdb->query($query);
751
-                return true;
752
-                break;
753
-            case 13:
754
-                $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true);
755
-                foreach ($attribute_used_for_sort_by as $attribute) {
756
-                    $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
757
-                    foreach ($data as $post) {
758
-                        $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true);
759
-                        if (!empty($postmeta[$attribute->code])) {
760
-                            update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]);
761
-                        }
762
-                    }
763
-                    wp_reset_query();
764
-                }
765
-                return true;
766
-                break;
767
-            case 17:
768
-                $products = query_posts(array(
769
-                    'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)
770
-                );
771
-                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes');
772
-                $default_attribute_set = $wpdb->get_var($query);
773
-                foreach ($products as $product) {
774
-                    $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
775
-                    if (empty($p_att_set_id)) {
776
-                        /*    Update the attribute set id for the current product    */
777
-                        update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set);
778
-                    }
779
-                    wp_reset_query();
780
-                }
781
-                self::wpshop_insert_default_pages($wpshop_shop_type);
782
-                wp_cache_flush();
783
-                return true;
784
-                break;
785
-            case 18:
786
-                self::wpshop_insert_default_pages($wpshop_shop_type);
787
-                wp_cache_flush();
788
-                return true;
789
-                break;
790
-            case 19:
791
-                $wp_rewrite->flush_rules();
792
-                return true;
793
-                break;
794
-
795
-            case 21:
796
-                /**
797
-                 * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement
798
-                 */
799
-                $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock');
800
-                $manage_stock_option = $wpdb->get_results($query);
801
-                if (!empty($manage_stock_option)) {
802
-                    $no_is_present = false;
803
-                    $attribute_id = $manage_stock_option[0]->attribute_id;
804
-                    foreach ($manage_stock_option as $manage_definition) {
805
-                        if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) {
806
-                            $no_is_present = true;
807
-                        }
808
-                    }
809
-                    if (!$no_is_present) {
810
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop')));
811
-                    }
812
-                }
813
-
814
-                /** Change price attribute set section order for default set */
815
-                $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES);
816
-                unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]);
817
-                $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')";
818
-                $attribute_ids = $wpdb->get_var($query);
619
+				$product_prices = $wpdb->get_row($query);
620
+				$tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva));
621
+				$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price);
622
+				$price_list = $wpdb->get_results($query);
623
+				foreach ($price_list as $existing_ttc_price) {
624
+					$tax_rate = 1.20;
625
+					$price_ht = $existing_ttc_price->value / $tax_rate;
626
+					$tax_amount = $existing_ttc_price->value - $price_ht;
627
+
628
+					$wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0)));
629
+					$wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0)));
630
+					$wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0)));
631
+				}
632
+
633
+				/*    Update orders structure into database    */
634
+				$orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
635
+				foreach ($orders_id as $o) {
636
+					$myorder = get_post_meta($o->ID, '_order_postmeta', true);
637
+					$neworder = array();
638
+					$items = array();
639
+
640
+					if (!isset($myorder['order_tva'])) {
641
+						$order_total_ht = 0;
642
+						$order_total_ttc = 0;
643
+						$order_tva = array('20' => 0);
644
+
645
+						foreach ($myorder['order_items'] as $item) {
646
+							/* item */
647
+							$pu_ht = $item['cost'] / 1.20;
648
+							$pu_tva = $item['cost'] - $pu_ht;
649
+							$total_ht = $pu_ht * $item['qty'];
650
+							$tva_total_amount = $pu_tva * $item['qty'];
651
+							$total_ttc = $item['cost'] * $item['qty'];
652
+							/* item */
653
+							$order_total_ht += $total_ht;
654
+							$order_total_ttc += $total_ttc;
655
+							$order_tva['20'] += $tva_total_amount;
656
+
657
+							$items[] = array(
658
+								'item_id' => $item['id'],
659
+								'item_ref' => 'Nc',
660
+								'item_name' => $item['name'],
661
+								'item_qty' => $item['qty'],
662
+
663
+								'item_pu_ht' => number_format($pu_ht, 2, '.', ''),
664
+								'item_pu_ttc' => number_format($item['cost'], 2, '.', ''),
665
+
666
+								'item_ecotaxe_ht' => number_format(0, 2, '.', ''),
667
+								'item_ecotaxe_tva' => 20,
668
+								'item_ecotaxe_ttc' => number_format(0, 2, '.', ''),
669
+
670
+								'item_discount_type' => 0,
671
+								'item_discount_value' => 0,
672
+								'item_discount_amount' => number_format(0, 2, '.', ''),
673
+
674
+								'item_tva_rate' => 20,
675
+								'item_tva_amount' => number_format($pu_tva, 2, '.', ''),
676
+
677
+								'item_total_ht' => number_format($total_ht, 2, '.', ''),
678
+								'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''),
679
+								'item_total_ttc' => number_format($total_ttc, 2, '.', ''),
680
+								/*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/
681
+							);
682
+						}
683
+
684
+						$neworder = array(
685
+							'order_key' => $myorder['order_key'],
686
+							'customer_id' => $myorder['customer_id'],
687
+							'order_status' => $myorder['order_status'],
688
+							'order_date' => $myorder['order_date'],
689
+							'order_payment_date' => $myorder['order_payment_date'],
690
+							'order_shipping_date' => $myorder['order_shipping_date'],
691
+							'payment_method' => $myorder['payment_method'],
692
+							'order_invoice_ref' => '',
693
+							'order_currency' => $myorder['order_currency'],
694
+							'order_total_ht' => $order_total_ht,
695
+							'order_total_ttc' => $order_total_ttc,
696
+							'order_grand_total' => $order_total_ttc,
697
+							'order_shipping_cost' => number_format(0, 2, '.', ''),
698
+							'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva),
699
+							'order_items' => $items,
700
+						);
701
+						/* Update the order postmeta */
702
+						update_post_meta($o->ID, '_order_postmeta', $neworder);
703
+					}
704
+				}
705
+
706
+				self::wpshop_insert_default_pages($wpshop_shop_type);
707
+				wp_cache_flush();
708
+				return true;
709
+				break;
710
+			case 12:
711
+				$query = "SELECT ID FROM " . $wpdb->users;
712
+				$user_list = $wpdb->get_results($query);
713
+				foreach ($user_list as $user) {
714
+					$user_first_name = get_user_meta($user->ID, 'first_name', true);
715
+					$user_last_name = get_user_meta($user->ID, 'last_name', true);
716
+					$shipping_info = get_user_meta($user->ID, 'shipping_info', true);
717
+
718
+					if (($user_first_name == '') && !empty($shipping_info['first_name'])) {
719
+						update_user_meta($user->ID, 'first_name', $shipping_info['first_name']);
720
+					}
721
+
722
+					if (($user_last_name == '') && !empty($shipping_info['last_name'])) {
723
+						update_user_meta($user->ID, 'last_name', $shipping_info['last_name']);
724
+					}
725
+				}
726
+
727
+				/*    Update orders structure into database    */
728
+				$orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
729
+				foreach ($orders_id as $o) {
730
+					$myorder = get_post_meta($o->ID, '_order_postmeta', true);
731
+					if (!empty($myorder)) {
732
+						$new_items = array();
733
+						foreach ($myorder['order_items'] as $item) {
734
+							$new_items = $item;
735
+							$new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount';
736
+							// unset($new_items['item_discount_rate']);
737
+							$new_items['item_discount_value'] = 0;
738
+						}
739
+						$myorder['order_items'] = $new_items;
740
+
741
+						/* Update the order postmeta */
742
+						update_post_meta($o->ID, '_order_postmeta', $myorder);
743
+					}
744
+				}
745
+
746
+				/*    Delete useless database table    */
747
+				$query = "DROP TABLE " . WPSHOP_DBT_CART;
748
+				$wpdb->query($query);
749
+				$query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS;
750
+				$wpdb->query($query);
751
+				return true;
752
+				break;
753
+			case 13:
754
+				$attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true);
755
+				foreach ($attribute_used_for_sort_by as $attribute) {
756
+					$data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
757
+					foreach ($data as $post) {
758
+						$postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true);
759
+						if (!empty($postmeta[$attribute->code])) {
760
+							update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]);
761
+						}
762
+					}
763
+					wp_reset_query();
764
+				}
765
+				return true;
766
+				break;
767
+			case 17:
768
+				$products = query_posts(array(
769
+					'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)
770
+				);
771
+				$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes');
772
+				$default_attribute_set = $wpdb->get_var($query);
773
+				foreach ($products as $product) {
774
+					$p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
775
+					if (empty($p_att_set_id)) {
776
+						/*    Update the attribute set id for the current product    */
777
+						update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set);
778
+					}
779
+					wp_reset_query();
780
+				}
781
+				self::wpshop_insert_default_pages($wpshop_shop_type);
782
+				wp_cache_flush();
783
+				return true;
784
+				break;
785
+			case 18:
786
+				self::wpshop_insert_default_pages($wpshop_shop_type);
787
+				wp_cache_flush();
788
+				return true;
789
+				break;
790
+			case 19:
791
+				$wp_rewrite->flush_rules();
792
+				return true;
793
+				break;
819 794
 
820
-                $query = $wpdb->prepare("
795
+			case 21:
796
+				/**
797
+				 * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement
798
+				 */
799
+				$query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock');
800
+				$manage_stock_option = $wpdb->get_results($query);
801
+				if (!empty($manage_stock_option)) {
802
+					$no_is_present = false;
803
+					$attribute_id = $manage_stock_option[0]->attribute_id;
804
+					foreach ($manage_stock_option as $manage_definition) {
805
+						if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) {
806
+							$no_is_present = true;
807
+						}
808
+					}
809
+					if (!$no_is_present) {
810
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop')));
811
+					}
812
+				}
813
+
814
+				/** Change price attribute set section order for default set */
815
+				$price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES);
816
+				unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]);
817
+				$query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')";
818
+				$attribute_ids = $wpdb->get_var($query);
819
+
820
+				$query = $wpdb->prepare("
821 821
 SELECT ATTR_DET.attribute_group_id
822 822
 FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET
823 823
 	INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTR_GROUP ON ((ATTR_GROUP.id = ATTR_DET.attribute_group_id) AND (ATTR_GROUP.code = %s))
824 824
 	INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTR_SET ON ((ATTR_SET.id = ATTR_GROUP.attribute_set_id) AND (ATTR_SET.name = %s))
825 825
 WHERE ATTR_DET.attribute_id IN (" . $attribute_ids . ")"
826
-                    , 'prices', __('default', 'wpshop'));
827
-                $list = $wpdb->get_results($query);
828
-                if (!empty($list)) {
829
-                    $change_order = true;
830
-                    $old_value = $list[0]->attribute_group_id;
831
-                    unset($list[0]);
832
-                    if (!empty($list)) {
833
-                        foreach ($list as $data) {
834
-                            if ($old_value != $data->attribute_group_id) {
835
-                                $change_order = false;
836
-                            }
837
-                        }
838
-                        if ($change_order) {
839
-                            foreach ($price_tab as $price_code) {
840
-                                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code);
841
-                                $attribute_id = $wpdb->get_var($query);
842
-                                switch ($price_code) {
843
-                                    case WPSHOP_PRODUCT_PRICE_HT:
844
-                                        $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 1 : 3;
845
-                                        break;
846
-                                    case WPSHOP_PRODUCT_PRICE_TAX:
847
-                                        $position = 2;
848
-                                        break;
849
-                                    case WPSHOP_PRODUCT_PRICE_TTC:
850
-                                        $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 3 : 1;
851
-                                        break;
852
-                                    case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT:
853
-                                        $position = 4;
854
-                                        break;
855
-                                }
856
-                                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id));
857
-                            }
858
-                        }
859
-                    }
860
-                }
861
-                return true;
862
-                break;
863
-            case 22:
864
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
865
-                $product_entity_id = $wpdb->get_var($query);
866
-                if (empty($product_entityd_id) || ($product_entity_id <= 0) || !$product_entity_id) {
867
-                    /*    Create the product entity into post table    */
868
-                    $product_entity = array(
869
-                        'post_title' => __('Products', 'wpshop'),
870
-                        'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
871
-                        'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'),
872
-                        'post_status' => 'publish',
873
-                        'post_author' => 1,
874
-                        'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES,
875
-                    );
876
-                    $product_entity_id = wp_insert_post($product_entity);
877
-                }
878
-
879
-                /*    Update eav table with the new entity id for product    */
880
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1));
881
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1));
882
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
883
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
884
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
885
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
886
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
887
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
888
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
889
-
890
-                /*    Create an element of customer entity for each existing user    */
891
-                $user_list = get_users();
892
-                foreach ($user_list as $user) {
893
-                    wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID);
894
-                }
895
-
896
-                return true;
897
-                break;
898
-            case 23:
899
-                /*    Delete duplicate entities    */
900
-                $query = ("SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' ");
901
-                $product_entity_list = $wpdb->get_results($query);
902
-                if (count($product_entity_list) > 1) {
903
-                    $i = 0;
904
-                    foreach ($product_entity_list as $product_entity) {
905
-                        if ($i > 0) {
906
-                            wp_delete_post($product_entity->ID);
907
-                        }
908
-                    }
909
-                }
910
-                return true;
911
-                break;
912
-            case 24:
913
-                /*    Update the link status for disabled attribute set    */
914
-                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted');
915
-                $deleted_attribute_group = $wpdb->get_results($query);
916
-                if (!empty($deleted_attribute_group)) {
917
-                    foreach ($deleted_attribute_group as $group) {
918
-                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id));
919
-                    }
920
-                }
921
-
922
-                /*    Update entities meta management    */
923
-                $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES));
924
-                if (!empty($entities)) {
925
-                    foreach ($entities as $entity) {
926
-                        $support = get_post_meta($entity->ID, '_wpshop_entity_support', true);
927
-                        $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true);
928
-                        update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite)));
929
-                    }
930
-                }
931
-                wp_reset_query();
932
-                return true;
933
-                break;
934
-            case 25:
935
-                /*    Get the first entities of product and customer    */
936
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
937
-                $product_entity_id = $wpdb->get_var($query);
938
-
939
-                /*    Update attributes that are not linked with entities    */
940
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0));
941
-
942
-                /*    Get entities that have been created a lot of time and delete them    */
943
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
944
-                $entities_to_delete = $wpdb->get_results($query);
945
-                if (!empty($entities_to_delete) && is_array($entities_to_delete)) {
946
-                    foreach ($entities_to_delete as $entity) {
947
-                        wp_delete_post($entity->ID, true);
948
-                    }
949
-                }
950
-
951
-                /*    Get post list that are children of entities created a lot of time */
952
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%");
953
-                $entities_to_update = $wpdb->get_results($query);
954
-                if (!empty($entities_to_update) && is_array($entities_to_update)) {
955
-                    foreach ($entities_to_update as $entity) {
956
-                        wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS));
957
-                    }
958
-                }
959
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%");
960
-                $entities_to_update = $wpdb->get_results($query);
961
-                if (!empty($entities_to_update) && is_array($entities_to_update)) {
962
-                    foreach ($entities_to_update as $entity) {
963
-                        wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
964
-                    }
965
-                }
966
-
967
-                /*    Change addons managament    */
968
-                $wpshop_addons_options = get_option('wpshop_addons_state', array());
969
-                if (!empty($wpshop_addons_options)) {
970
-                    foreach ($wpshop_addons_options as $addon_name => $addon_state) {
971
-                        $options_args = array();
972
-                        $options_args[$addon_name]['activate'] = $addon_state;
973
-                        $options_args[$addon_name]['activation_date'] = current_time('mysql', 0);
974
-                        if (!$addon_state) {
975
-                            $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0);
976
-                        }
826
+					, 'prices', __('default', 'wpshop'));
827
+				$list = $wpdb->get_results($query);
828
+				if (!empty($list)) {
829
+					$change_order = true;
830
+					$old_value = $list[0]->attribute_group_id;
831
+					unset($list[0]);
832
+					if (!empty($list)) {
833
+						foreach ($list as $data) {
834
+							if ($old_value != $data->attribute_group_id) {
835
+								$change_order = false;
836
+							}
837
+						}
838
+						if ($change_order) {
839
+							foreach ($price_tab as $price_code) {
840
+								$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code);
841
+								$attribute_id = $wpdb->get_var($query);
842
+								switch ($price_code) {
843
+									case WPSHOP_PRODUCT_PRICE_HT:
844
+										$position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 1 : 3;
845
+										break;
846
+									case WPSHOP_PRODUCT_PRICE_TAX:
847
+										$position = 2;
848
+										break;
849
+									case WPSHOP_PRODUCT_PRICE_TTC:
850
+										$position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 3 : 1;
851
+										break;
852
+									case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT:
853
+										$position = 4;
854
+										break;
855
+								}
856
+								$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id));
857
+							}
858
+						}
859
+					}
860
+				}
861
+				return true;
862
+				break;
863
+			case 22:
864
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
865
+				$product_entity_id = $wpdb->get_var($query);
866
+				if (empty($product_entityd_id) || ($product_entity_id <= 0) || !$product_entity_id) {
867
+					/*    Create the product entity into post table    */
868
+					$product_entity = array(
869
+						'post_title' => __('Products', 'wpshop'),
870
+						'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
871
+						'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'),
872
+						'post_status' => 'publish',
873
+						'post_author' => 1,
874
+						'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES,
875
+					);
876
+					$product_entity_id = wp_insert_post($product_entity);
877
+				}
878
+
879
+				/*    Update eav table with the new entity id for product    */
880
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1));
881
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1));
882
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
883
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
884
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
885
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
886
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
887
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
888
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
889
+
890
+				/*    Create an element of customer entity for each existing user    */
891
+				$user_list = get_users();
892
+				foreach ($user_list as $user) {
893
+					wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID);
894
+				}
977 895
 
978
-                        add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args);
979
-                    }
980
-                    delete_option('wpshop_addons_state');
981
-                }
982
-
983
-                /*    Update the different entities id into attribute set details table    */
984
-                $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
985
-                $wpdb->query($query);
986
-
987
-                return true;
988
-                break;
989
-            case 26:
990
-                $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' ";
991
-                $results = $wpdb->get_results($query);
992
-                foreach ($results as $result) {
993
-                    $order_info = unserialize($result->meta_value);
994
-                    update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']);
995
-                    update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']);
996
-                    update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']);
997
-                }
998
-
999
-                /*    Update the different entities id into attribute set details table    */
1000
-                $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
1001
-                $wpdb->query($query);
1002
-
1003
-                return true;
1004
-                break;
1005
-
1006
-            case 29:
1007
-                $billing_title = __('Billing address', 'wpshop');
1008
-                $shipping_title = __('Shipping address', 'wpshop');
1009
-
1010
-                //UPDATE USERS ADDRESSES
1011
-                $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"';
1012
-                $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"';
1013
-
1014
-                $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query);
1015
-                $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query);
1016
-
1017
-                //Add Address & Google Map API KEY options
1018
-                add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes');
1019
-                add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes');
1020
-                add_option('wpshop_google_map_api_key', '', '', 'yes');
1021
-
1022
-                $query = 'SELECT * FROM ' . $wpdb->users . '';
1023
-                $results = $wpdb->get_results($query);
1024
-                foreach ($results as $result) {
1025
-                    $billing_infos = get_user_meta($result->ID, 'billing_info', true);
1026
-                    $shipping_infos = get_user_meta($result->ID, 'shipping_info', true);
1027
-                    if (!empty($billing_infos)) {
1028
-                        //Save Billing Infos
1029
-                        $billing_address = array();
1030
-                        if (!empty($billing_infos['civility'])) {
1031
-                            switch ($billing_infos['civility']) {
1032
-                                case 1:
1033
-                                    $civility = $mister_id;
1034
-                                    break;
1035
-                                case 2:
1036
-                                    $civility = $madam_id;
1037
-                                    break;
1038
-                                case 3:
1039
-                                    $civility = $miss_id;
1040
-                                    break;
1041
-                            }
1042
-                        } else {
1043
-                            $civility = $mister_id;
1044
-                        }
1045
-                        $billing_address = array('address_title' => $billing_title,
1046
-                            'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '',
1047
-                            'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '',
1048
-                            'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '',
1049
-                            'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '',
1050
-                            'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '',
1051
-                            'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '',
1052
-                            'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '',
1053
-                            'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '',
1054
-                            'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '',
1055
-                            'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '',
1056
-                            'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '',
1057
-                            'civility' => $civility,
1058
-                        );
1059
-                        //Create the post and post_meta for the billing address
1060
-                        $post_address = array(
1061
-                            'post_author' => $result->ID,
1062
-                            'post_title' => $billing_title,
1063
-                            'post_status' => 'publish',
1064
-                            'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1065
-                            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1066
-                            'post_parent' => $result->ID,
1067
-                        );
1068
-                        $post_address_id = wp_insert_post($post_address);
1069
-
1070
-                        //Create the post_meta with the address infos
1071
-                        update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address);
1072
-                        update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id);
1073
-                    }
896
+				return true;
897
+				break;
898
+			case 23:
899
+				/*    Delete duplicate entities    */
900
+				$query = ("SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' ");
901
+				$product_entity_list = $wpdb->get_results($query);
902
+				if (count($product_entity_list) > 1) {
903
+					$i = 0;
904
+					foreach ($product_entity_list as $product_entity) {
905
+						if ($i > 0) {
906
+							wp_delete_post($product_entity->ID);
907
+						}
908
+					}
909
+				}
910
+				return true;
911
+				break;
912
+			case 24:
913
+				/*    Update the link status for disabled attribute set    */
914
+				$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted');
915
+				$deleted_attribute_group = $wpdb->get_results($query);
916
+				if (!empty($deleted_attribute_group)) {
917
+					foreach ($deleted_attribute_group as $group) {
918
+						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id));
919
+					}
920
+				}
921
+
922
+				/*    Update entities meta management    */
923
+				$entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES));
924
+				if (!empty($entities)) {
925
+					foreach ($entities as $entity) {
926
+						$support = get_post_meta($entity->ID, '_wpshop_entity_support', true);
927
+						$rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true);
928
+						update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite)));
929
+					}
930
+				}
931
+				wp_reset_query();
932
+				return true;
933
+				break;
934
+			case 25:
935
+				/*    Get the first entities of product and customer    */
936
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
937
+				$product_entity_id = $wpdb->get_var($query);
938
+
939
+				/*    Update attributes that are not linked with entities    */
940
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0));
941
+
942
+				/*    Get entities that have been created a lot of time and delete them    */
943
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
944
+				$entities_to_delete = $wpdb->get_results($query);
945
+				if (!empty($entities_to_delete) && is_array($entities_to_delete)) {
946
+					foreach ($entities_to_delete as $entity) {
947
+						wp_delete_post($entity->ID, true);
948
+					}
949
+				}
950
+
951
+				/*    Get post list that are children of entities created a lot of time */
952
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%");
953
+				$entities_to_update = $wpdb->get_results($query);
954
+				if (!empty($entities_to_update) && is_array($entities_to_update)) {
955
+					foreach ($entities_to_update as $entity) {
956
+						wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS));
957
+					}
958
+				}
959
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%");
960
+				$entities_to_update = $wpdb->get_results($query);
961
+				if (!empty($entities_to_update) && is_array($entities_to_update)) {
962
+					foreach ($entities_to_update as $entity) {
963
+						wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
964
+					}
965
+				}
966
+
967
+				/*    Change addons managament    */
968
+				$wpshop_addons_options = get_option('wpshop_addons_state', array());
969
+				if (!empty($wpshop_addons_options)) {
970
+					foreach ($wpshop_addons_options as $addon_name => $addon_state) {
971
+						$options_args = array();
972
+						$options_args[$addon_name]['activate'] = $addon_state;
973
+						$options_args[$addon_name]['activation_date'] = current_time('mysql', 0);
974
+						if (!$addon_state) {
975
+							$options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0);
976
+						}
977
+
978
+						add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args);
979
+					}
980
+					delete_option('wpshop_addons_state');
981
+				}
982
+
983
+				/*    Update the different entities id into attribute set details table    */
984
+				$query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
985
+				$wpdb->query($query);
1074 986
 
1075
-                    if (!empty($shipping_infos)) {
1076
-                        //Save Shipping Infos
1077
-                        if (!empty($shipping_infos['civility'])) {
1078
-                            switch ($shipping_infos['civility']) {
1079
-                                case 1:
1080
-                                    $civility = $mister_id;
1081
-                                    break;
1082
-                                case 2:
1083
-                                    $civility = $madam_id;
1084
-                                    break;
1085
-                                case 3:
1086
-                                    $civility = $miss_id;
1087
-                                    break;
1088
-                            }
1089
-                        } else {
1090
-                            $civility = $mister_id;
1091
-                        }
1092
-                        $shipping_address = array();
1093
-                        $shipping_address = array('address_title' => $shipping_title,
1094
-                            'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '',
1095
-                            'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '',
1096
-                            'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '',
1097
-                            'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '',
1098
-                            'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '',
1099
-                            'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '',
1100
-                            'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '',
1101
-                            'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '',
1102
-                            'civility' => $civility,
1103
-                        );
1104
-                        //Create the post and post_meta for the billing address
1105
-                        $post_address = array(
1106
-                            'post_author' => $result->ID,
1107
-                            'post_title' => $shipping_title,
1108
-                            'post_status' => 'publish',
1109
-                            'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1110
-                            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1111
-                            'post_parent' => $result->ID,
1112
-                        );
1113
-                        $post_address_id = wp_insert_post($post_address);
1114
-                        //Create the post_meta with the address infos
1115
-                        update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address);
1116
-                        update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id);
1117
-                    }
1118
-                }
1119
-
1120
-                // FORMATE THE ORDER ADDRESSES INFOS
1121
-                $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
1122
-                foreach ($results as $result) {
1123
-                    $address = get_post_meta($result->ID, '_order_info', true);
1124
-
1125
-                    $billing_address = array();
1126
-                    if (!empty($address['billing'])) {
1127
-                        if (!empty($address['billing']['civility'])) {
1128
-                            switch ($address['billing']['civility']) {
1129
-                                case 1:
1130
-                                    $civility = $mister_id;
1131
-                                    break;
1132
-                                case 2:
1133
-                                    $civility = $madam_id;
1134
-                                    break;
1135
-                                case 3:
1136
-                                    $civility = $miss_id;
1137
-                                    break;
1138
-                                default:
1139
-                                    $civility = $mister_id;
1140
-                                    break;
1141
-                            }
1142
-                        } else {
1143
-                            $civility = $mister_id;
1144
-                        }
1145
-                        $billing_address = array('address_title' => $billing_title,
1146
-                            'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '',
1147
-                            'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '',
1148
-                            'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '',
1149
-                            'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '',
1150
-                            'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '',
1151
-                            'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '',
1152
-                            'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '',
1153
-                            'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '',
1154
-                            'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '',
1155
-                            'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '',
1156
-                            'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '',
1157
-                            'civility' => $civility,
1158
-                        );
1159
-                    }
987
+				return true;
988
+				break;
989
+			case 26:
990
+				$query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' ";
991
+				$results = $wpdb->get_results($query);
992
+				foreach ($results as $result) {
993
+					$order_info = unserialize($result->meta_value);
994
+					update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']);
995
+					update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']);
996
+					update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']);
997
+				}
998
+
999
+				/*    Update the different entities id into attribute set details table    */
1000
+				$query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
1001
+				$wpdb->query($query);
1160 1002
 
1161
-                    $shipping_address = array();
1162
-                    if (!empty($address['shipping'])) {
1163
-                        if (!empty($address['shipping']['civility'])) {
1164
-                            switch ($address['shipping']['civility']) {
1165
-                                case 1:
1166
-                                    $civility = $mister_id;
1167
-                                    break;
1168
-                                case 2:
1169
-                                    $civility = $madam_id;
1170
-                                    break;
1171
-                                case 3:
1172
-                                    $civility = $miss_id;
1173
-                                    break;
1174
-                            }
1175
-                        } else {
1176
-                            $civility = $mister_id;
1177
-                        }
1178
-                        $shipping_address = array('address_title' => $shipping_title,
1179
-                            'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '',
1180
-                            'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '',
1181
-                            'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '',
1182
-                            'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '',
1183
-                            'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '',
1184
-                            'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '',
1185
-                            'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '',
1186
-                            'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '',
1187
-                            'civility' => $civility,
1188
-                        );
1189
-                    }
1003
+				return true;
1004
+				break;
1190 1005
 
1191
-                    $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address);
1192
-                    $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address);
1193
-                    $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content);
1006
+			case 29:
1007
+				$billing_title = __('Billing address', 'wpshop');
1008
+				$shipping_title = __('Shipping address', 'wpshop');
1009
+
1010
+				//UPDATE USERS ADDRESSES
1011
+				$billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"';
1012
+				$shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"';
1013
+
1014
+				$billing_address_set_id = $wpdb->get_var($billing_address_set_id_query);
1015
+				$shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query);
1016
+
1017
+				//Add Address & Google Map API KEY options
1018
+				add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes');
1019
+				add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes');
1020
+				add_option('wpshop_google_map_api_key', '', '', 'yes');
1021
+
1022
+				$query = 'SELECT * FROM ' . $wpdb->users . '';
1023
+				$results = $wpdb->get_results($query);
1024
+				foreach ($results as $result) {
1025
+					$billing_infos = get_user_meta($result->ID, 'billing_info', true);
1026
+					$shipping_infos = get_user_meta($result->ID, 'shipping_info', true);
1027
+					if (!empty($billing_infos)) {
1028
+						//Save Billing Infos
1029
+						$billing_address = array();
1030
+						if (!empty($billing_infos['civility'])) {
1031
+							switch ($billing_infos['civility']) {
1032
+								case 1:
1033
+									$civility = $mister_id;
1034
+									break;
1035
+								case 2:
1036
+									$civility = $madam_id;
1037
+									break;
1038
+								case 3:
1039
+									$civility = $miss_id;
1040
+									break;
1041
+							}
1042
+						} else {
1043
+							$civility = $mister_id;
1044
+						}
1045
+						$billing_address = array('address_title' => $billing_title,
1046
+							'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '',
1047
+							'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '',
1048
+							'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '',
1049
+							'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '',
1050
+							'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '',
1051
+							'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '',
1052
+							'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '',
1053
+							'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '',
1054
+							'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '',
1055
+							'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '',
1056
+							'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '',
1057
+							'civility' => $civility,
1058
+						);
1059
+						//Create the post and post_meta for the billing address
1060
+						$post_address = array(
1061
+							'post_author' => $result->ID,
1062
+							'post_title' => $billing_title,
1063
+							'post_status' => 'publish',
1064
+							'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1065
+							'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1066
+							'post_parent' => $result->ID,
1067
+						);
1068
+						$post_address_id = wp_insert_post($post_address);
1069
+
1070
+						//Create the post_meta with the address infos
1071
+						update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address);
1072
+						update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id);
1073
+					}
1074
+
1075
+					if (!empty($shipping_infos)) {
1076
+						//Save Shipping Infos
1077
+						if (!empty($shipping_infos['civility'])) {
1078
+							switch ($shipping_infos['civility']) {
1079
+								case 1:
1080
+									$civility = $mister_id;
1081
+									break;
1082
+								case 2:
1083
+									$civility = $madam_id;
1084
+									break;
1085
+								case 3:
1086
+									$civility = $miss_id;
1087
+									break;
1088
+							}
1089
+						} else {
1090
+							$civility = $mister_id;
1091
+						}
1092
+						$shipping_address = array();
1093
+						$shipping_address = array('address_title' => $shipping_title,
1094
+							'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '',
1095
+							'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '',
1096
+							'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '',
1097
+							'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '',
1098
+							'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '',
1099
+							'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '',
1100
+							'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '',
1101
+							'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '',
1102
+							'civility' => $civility,
1103
+						);
1104
+						//Create the post and post_meta for the billing address
1105
+						$post_address = array(
1106
+							'post_author' => $result->ID,
1107
+							'post_title' => $shipping_title,
1108
+							'post_status' => 'publish',
1109
+							'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1110
+							'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS,
1111
+							'post_parent' => $result->ID,
1112
+						);
1113
+						$post_address_id = wp_insert_post($post_address);
1114
+						//Create the post_meta with the address infos
1115
+						update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address);
1116
+						update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id);
1117
+					}
1118
+				}
1119
+
1120
+				// FORMATE THE ORDER ADDRESSES INFOS
1121
+				$results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
1122
+				foreach ($results as $result) {
1123
+					$address = get_post_meta($result->ID, '_order_info', true);
1124
+
1125
+					$billing_address = array();
1126
+					if (!empty($address['billing'])) {
1127
+						if (!empty($address['billing']['civility'])) {
1128
+							switch ($address['billing']['civility']) {
1129
+								case 1:
1130
+									$civility = $mister_id;
1131
+									break;
1132
+								case 2:
1133
+									$civility = $madam_id;
1134
+									break;
1135
+								case 3:
1136
+									$civility = $miss_id;
1137
+									break;
1138
+								default:
1139
+									$civility = $mister_id;
1140
+									break;
1141
+							}
1142
+						} else {
1143
+							$civility = $mister_id;
1144
+						}
1145
+						$billing_address = array('address_title' => $billing_title,
1146
+							'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '',
1147
+							'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '',
1148
+							'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '',
1149
+							'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '',
1150
+							'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '',
1151
+							'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '',
1152
+							'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '',
1153
+							'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '',
1154
+							'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '',
1155
+							'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '',
1156
+							'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '',
1157
+							'civility' => $civility,
1158
+						);
1159
+					}
1160
+
1161
+					$shipping_address = array();
1162
+					if (!empty($address['shipping'])) {
1163
+						if (!empty($address['shipping']['civility'])) {
1164
+							switch ($address['shipping']['civility']) {
1165
+								case 1:
1166
+									$civility = $mister_id;
1167
+									break;
1168
+								case 2:
1169
+									$civility = $madam_id;
1170
+									break;
1171
+								case 3:
1172
+									$civility = $miss_id;
1173
+									break;
1174
+							}
1175
+						} else {
1176
+							$civility = $mister_id;
1177
+						}
1178
+						$shipping_address = array('address_title' => $shipping_title,
1179
+							'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '',
1180
+							'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '',
1181
+							'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '',
1182
+							'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '',
1183
+							'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '',
1184
+							'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '',
1185
+							'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '',
1186
+							'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '',
1187
+							'civility' => $civility,
1188
+						);
1189
+					}
1190
+
1191
+					$billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address);
1192
+					$shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address);
1193
+					$array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content);
1194
+
1195
+					//Update the post meta
1196
+					update_post_meta($result->ID, '_order_info', $array_new_format);
1197
+				}
1198
+
1199
+				/*    Update entities meta management    */
1200
+				$entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1));
1201
+				if (!empty($entities)) {
1202
+					foreach ($entities as $entity) {
1203
+						$params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
1204
+						$support = (!empty($params['support'])) ? $params['support'] : '';
1205
+						$rewrite = (!empty($params['rewrite'])) ? $params['rewrite'] : '';
1206
+
1207
+						$display_admin_menu = 'on';
1208
+
1209
+						update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu));
1210
+					}
1211
+				}
1212
+				wp_reset_query();
1213
+
1214
+				// Default Weight unity and Currency Options
1215
+				add_option('wpshop_shop_weight_group', 3, '', 'yes');
1216
+				add_option('wpshop_shop_default_weight_unity', 6, '', 'yes');
1217
+				add_option('wpshop_shop_currency_group', 4, '', 'yes');
1218
+
1219
+				$default_currency = get_option('wpshop_shop_default_currency');
1220
+				foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
1221
+					if ($default_currency == $k) {
1222
+						$symbol = $v;
1223
+					}
1224
+				}
1225
+				if (!empty($symbol)) {
1226
+					$query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"';
1227
+					$currency = $wpdb->get_row($query);
1228
+					if (!empty($currency)) {
1229
+						update_option('wpshop_shop_default_currency', $currency->id);
1230
+						// Update the change rate of the default currency
1231
+						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
1232
+					}
1233
+				}
1234
+
1235
+				// Update the field for variation and user definition field
1236
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes'));
1237
+				// Update field type for frontend output selection
1238
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array());
1239
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea'));
1240
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select'));
1241
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select'));
1242
+
1243
+				add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page')));
1194 1244
 
1195
-                    //Update the post meta
1196
-                    update_post_meta($result->ID, '_order_info', $array_new_format);
1197
-                }
1245
+				return true;
1246
+				break;
1198 1247
 
1199
-                /*    Update entities meta management    */
1200
-                $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1));
1201
-                if (!empty($entities)) {
1202
-                    foreach ($entities as $entity) {
1203
-                        $params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
1204
-                        $support = (!empty($params['support'])) ? $params['support'] : '';
1205
-                        $rewrite = (!empty($params['rewrite'])) ? $params['rewrite'] : '';
1248
+			case '30':
1249
+				/**    Update the current price piloting field for using it into variation specific attributes    */
1250
+				$price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT);
1251
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute));
1252
+
1253
+				/**    Update the product reference field for using it into variation specific attributes    */
1254
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference'));
1255
+
1256
+				/**    Insert new message for admin when a customer make an order    */
1257
+				$admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
1258
+				if (empty($admin_new_order_message)) {
1259
+					wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
1260
+				}
1261
+				/**    Update all amount for paypal orders    */
1262
+				$query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal');
1263
+				$paypal_payment_list = $wpdb->get_results($query);
1264
+				if (!empty($paypal_payment_list)) {
1265
+					foreach ($paypal_payment_list as $post) {
1266
+						$order_meta = get_post_meta($post->post_id, '_order_postmeta', true);
1267
+						$order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true);
1268
+						if (!empty($order_meta['order_status']) && ($order_meta['order_status'] == 'incorrect_amount')) {
1269
+							if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) {
1270
+								$order_amount_to_pay = number_format($order_meta['order_grand_total'], 5);
1271
+								$order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5);
1272
+								if ($order_amount_payed == $order_amount_to_pay) {
1273
+									wpshop_payment::setOrderPaymentStatus($order_id, 'completed');
1274
+								}
1275
+							}
1276
+						}
1277
+					}
1278
+				}
1279
+
1280
+				/**    Save existing orders address information    */
1281
+				$billing_title = __('Billing address', 'wpshop');
1282
+				$shipping_title = __('Shipping address', 'wpshop');
1283
+				$results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
1284
+				foreach ($results as $result) {
1285
+					$address = get_post_meta($result->ID, '_order_info', true);
1286
+					$address_format = array();
1287
+
1288
+					$billing_address = array();
1289
+					if (!empty($address['billing']) && empty($address['billing']['id'])) {
1290
+						if (!empty($address['billing']['civility'])) {
1291
+							switch ($address['billing']['civility']) {
1292
+								case 1:
1293
+									$civility = $mister_id;
1294
+									break;
1295
+								case 2:
1296
+									$civility = $madam_id;
1297
+									break;
1298
+								case 3:
1299
+									$civility = $miss_id;
1300
+									break;
1301
+								default:
1302
+									$civility = $mister_id;
1303
+									break;
1304
+							}
1305
+						} else {
1306
+							$civility = $mister_id;
1307
+						}
1308
+						$billing_address = array('address_title' => $billing_title,
1309
+							'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '',
1310
+							'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '',
1311
+							'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '',
1312
+							'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '',
1313
+							'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '',
1314
+							'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '',
1315
+							'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '',
1316
+							'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '',
1317
+							'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '',
1318
+							'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '',
1319
+							'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '',
1320
+							'civility' => $civility,
1321
+						);
1322
+						$billing_address_option = get_option('wpshop_billing_address');
1323
+						$address_format['billing']['id'] = $billing_address_option['choice'];
1324
+						$address_format['billing']['address'] = $shipping_address;
1325
+					}
1326
+
1327
+					$shipping_address = array();
1328
+					if (!empty($address['shipping']) && empty($address['shipping']['id'])) {
1329
+						if (!empty($address['shipping']['civility'])) {
1330
+							switch ($address['shipping']['civility']) {
1331
+								case 1:
1332
+									$civility = $mister_id;
1333
+									break;
1334
+								case 2:
1335
+									$civility = $madam_id;
1336
+									break;
1337
+								case 3:
1338
+									$civility = $miss_id;
1339
+									break;
1340
+							}
1341
+						} else {
1342
+							$civility = $mister_id;
1343
+						}
1344
+						$shipping_address = array('address_title' => $shipping_title,
1345
+							'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '',
1346
+							'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '',
1347
+							'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '',
1348
+							'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '',
1349
+							'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '',
1350
+							'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '',
1351
+							'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '',
1352
+							'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '',
1353
+							'civility' => $civility,
1354
+						);
1355
+						$shipping_address_options = get_option('wpshop_shipping_address_choice');
1356
+						$address_format['shipping']['id'] = $shipping_address_options['choice'];
1357
+						$address_format['shipping']['address'] = $shipping_address;
1358
+					}
1359
+
1360
+					if (!empty($address_format)) {
1361
+						update_post_meta($result->ID, '_order_info', $address_format);
1362
+					}
1363
+				}
1364
+
1365
+				/**    Delete username from frontend form    */
1366
+				$attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code');
1367
+				if (!empty($attribute_login)) {
1368
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id));
1369
+				}
1370
+
1371
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted'));
1206 1372
 
1207
-                        $display_admin_menu = 'on';
1373
+				return true;
1374
+				break;
1208 1375
 
1209
-                        update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu));
1210
-                    }
1211
-                }
1212
-                wp_reset_query();
1213
-
1214
-                // Default Weight unity and Currency Options
1215
-                add_option('wpshop_shop_weight_group', 3, '', 'yes');
1216
-                add_option('wpshop_shop_default_weight_unity', 6, '', 'yes');
1217
-                add_option('wpshop_shop_currency_group', 4, '', 'yes');
1218
-
1219
-                $default_currency = get_option('wpshop_shop_default_currency');
1220
-                foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
1221
-                    if ($default_currency == $k) {
1222
-                        $symbol = $v;
1223
-                    }
1224
-                }
1225
-                if (!empty($symbol)) {
1226
-                    $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"';
1227
-                    $currency = $wpdb->get_row($query);
1228
-                    if (!empty($currency)) {
1229
-                        update_option('wpshop_shop_default_currency', $currency->id);
1230
-                        // Update the change rate of the default currency
1231
-                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
1232
-                    }
1233
-                }
1234
-
1235
-                // Update the field for variation and user definition field
1236
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes'));
1237
-                // Update field type for frontend output selection
1238
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array());
1239
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea'));
1240
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select'));
1241
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select'));
1242
-
1243
-                add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page')));
1244
-
1245
-                return true;
1246
-                break;
1247
-
1248
-            case '30':
1249
-                /**    Update the current price piloting field for using it into variation specific attributes    */
1250
-                $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT);
1251
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute));
1252
-
1253
-                /**    Update the product reference field for using it into variation specific attributes    */
1254
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference'));
1255
-
1256
-                /**    Insert new message for admin when a customer make an order    */
1257
-                $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
1258
-                if (empty($admin_new_order_message)) {
1259
-                    wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
1260
-                }
1261
-                /**    Update all amount for paypal orders    */
1262
-                $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal');
1263
-                $paypal_payment_list = $wpdb->get_results($query);
1264
-                if (!empty($paypal_payment_list)) {
1265
-                    foreach ($paypal_payment_list as $post) {
1266
-                        $order_meta = get_post_meta($post->post_id, '_order_postmeta', true);
1267
-                        $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true);
1268
-                        if (!empty($order_meta['order_status']) && ($order_meta['order_status'] == 'incorrect_amount')) {
1269
-                            if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) {
1270
-                                $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5);
1271
-                                $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5);
1272
-                                if ($order_amount_payed == $order_amount_to_pay) {
1273
-                                    wpshop_payment::setOrderPaymentStatus($order_id, 'completed');
1274
-                                }
1275
-                            }
1276
-                        }
1277
-                    }
1278
-                }
1279
-
1280
-                /**    Save existing orders address information    */
1281
-                $billing_title = __('Billing address', 'wpshop');
1282
-                $shipping_title = __('Shipping address', 'wpshop');
1283
-                $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
1284
-                foreach ($results as $result) {
1285
-                    $address = get_post_meta($result->ID, '_order_info', true);
1286
-                    $address_format = array();
1287
-
1288
-                    $billing_address = array();
1289
-                    if (!empty($address['billing']) && empty($address['billing']['id'])) {
1290
-                        if (!empty($address['billing']['civility'])) {
1291
-                            switch ($address['billing']['civility']) {
1292
-                                case 1:
1293
-                                    $civility = $mister_id;
1294
-                                    break;
1295
-                                case 2:
1296
-                                    $civility = $madam_id;
1297
-                                    break;
1298
-                                case 3:
1299
-                                    $civility = $miss_id;
1300
-                                    break;
1301
-                                default:
1302
-                                    $civility = $mister_id;
1303
-                                    break;
1304
-                            }
1305
-                        } else {
1306
-                            $civility = $mister_id;
1307
-                        }
1308
-                        $billing_address = array('address_title' => $billing_title,
1309
-                            'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '',
1310
-                            'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '',
1311
-                            'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '',
1312
-                            'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '',
1313
-                            'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '',
1314
-                            'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '',
1315
-                            'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '',
1316
-                            'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '',
1317
-                            'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '',
1318
-                            'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '',
1319
-                            'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '',
1320
-                            'civility' => $civility,
1321
-                        );
1322
-                        $billing_address_option = get_option('wpshop_billing_address');
1323
-                        $address_format['billing']['id'] = $billing_address_option['choice'];
1324
-                        $address_format['billing']['address'] = $shipping_address;
1325
-                    }
1376
+			case '31':
1377
+				/**    Change order structure in order to support several payment    */
1378
+				$existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish')));
1379
+				if (!empty($existing_orders)) {
1380
+					foreach ($existing_orders as $order_main_informations) {
1381
+						/**    Transfer payment return data form old meta to new    */
1382
+						$order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true);
1383
+						update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data);
1384
+						delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data');
1385
+
1386
+						/**    Transfer old payment storage method to new storage method    */
1387
+						$order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true);
1388
+						if (!empty($order_meta['order_status'])) {
1389
+							$order_meta['order_payment']['customer_choice'] = array('method' => (!empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : '')));
1390
+							unset($order_meta['payment_method']);
1391
+							$order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0;
1392
+							$order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method'];
1393
+							$order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date'];
1394
+							$order_meta['order_payment']['received'][0]['status'] = 'waiting_payment';
1395
+							$order_meta['order_payment']['received'][0]['comment'] = '';
1396
+							$order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
1397
+							if (in_array($order_meta['order_status'], array('completed', 'shipped'))) {
1398
+								$order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total'];
1399
+								$order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID);
1400
+								$order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date'];
1401
+								$order_meta['order_payment']['received'][0]['status'] = 'payment_received';
1402
+								$order_meta['order_payment']['received'][0]['comment'] = '';
1403
+								$order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
1404
+								$order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref'];
1405
+							}
1406
+							update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta);
1407
+
1408
+							if (!empty($order_meta['order_payment']['customer_choice'])) {
1409
+								switch ($order_meta['order_payment']['customer_choice']) {
1410
+									case 'check':
1411
+										delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true));
1412
+										break;
1413
+									case 'paypal':
1414
+										delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true));
1415
+										break;
1416
+									case 'cic':
1417
+										delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true));
1418
+										break;
1419
+								}
1420
+							}
1421
+						}
1422
+					}
1423
+				}
1424
+				$wps_messages = new wps_message_ctr();
1425
+				$wps_messages->wpshop_messages_historic_correction();
1426
+				wp_reset_query();
1427
+
1428
+				$default_currency = get_option('wpshop_shop_default_currency');
1429
+				foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
1430
+					if ($default_currency == $k) {
1431
+						$symbol = $v;
1432
+					}
1433
+				}
1434
+				if (!empty($symbol)) {
1435
+					$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', '');
1436
+					$currency = $wpdb->get_row($query);
1437
+					if (!empty($currency)) {
1438
+						update_option('wpshop_shop_default_currency', $currency->id);
1439
+						// Update the change rate of the default currency
1440
+						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
1441
+					}
1442
+				}
1443
+
1444
+				$shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE');
1445
+				if (!empty($shipping_confirmation_message)) {
1446
+					$message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop');
1447
+					$post = array('ID' => $shipping_confirmation_message, 'post_content' => $message);
1448
+					wp_update_post($post);
1449
+				}
1450
+				return true;
1451
+				break;
1452
+			case '32':
1453
+				/**    Update product set id that are null     */
1454
+				$query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id');
1455
+				$wpdb->query($query);
1456
+
1457
+				$addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME);
1458
+				if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) {
1459
+					$admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
1460
+					if (empty($admin_new_quotation_message)) {
1461
+						wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
1462
+					}
1463
+					$admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
1464
+					if (empty($admin_new_quotation_confirm_message)) {
1465
+						wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
1466
+					}
1467
+				}
1468
+
1469
+				/**    Allows the administrator to manage a little bit more the catalog rewrite parameters    */
1470
+				$options = get_option('wpshop_catalog_product_option');
1471
+				$options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category'];
1472
+				update_option('wpshop_catalog_product_option', $options);
1473
+
1474
+				/**    Create a new page for unsuccessfull payment return    */
1475
+				self::wpshop_insert_default_pages($wpshop_shop_type);
1476
+				wp_cache_flush();
1477
+
1478
+				/**    Update the iso code of currencies    */
1479
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro'));
1480
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar'));
1481
+
1482
+				/** Update VAT Rate*/
1483
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva');
1484
+				$attribute_ids = $wpdb->get_results($query);
1485
+				foreach ($attribute_ids as $attribute_id) {
1486
+					$query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id);
1487
+					$wpdb->query($query);
1488
+				}
1326 1489
 
1327
-                    $shipping_address = array();
1328
-                    if (!empty($address['shipping']) && empty($address['shipping']['id'])) {
1329
-                        if (!empty($address['shipping']['civility'])) {
1330
-                            switch ($address['shipping']['civility']) {
1331
-                                case 1:
1332
-                                    $civility = $mister_id;
1333
-                                    break;
1334
-                                case 2:
1335
-                                    $civility = $madam_id;
1336
-                                    break;
1337
-                                case 3:
1338
-                                    $civility = $miss_id;
1339
-                                    break;
1340
-                            }
1341
-                        } else {
1342
-                            $civility = $mister_id;
1343
-                        }
1344
-                        $shipping_address = array('address_title' => $shipping_title,
1345
-                            'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '',
1346
-                            'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '',
1347
-                            'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '',
1348
-                            'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '',
1349
-                            'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '',
1350
-                            'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '',
1351
-                            'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '',
1352
-                            'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '',
1353
-                            'civility' => $civility,
1354
-                        );
1355
-                        $shipping_address_options = get_option('wpshop_shipping_address_choice');
1356
-                        $address_format['shipping']['id'] = $shipping_address_options['choice'];
1357
-                        $address_format['shipping']['address'] = $shipping_address;
1358
-                    }
1490
+				return true;
1491
+				break;
1359 1492
 
1360
-                    if (!empty($address_format)) {
1361
-                        update_post_meta($result->ID, '_order_info', $address_format);
1362
-                    }
1363
-                }
1364
-
1365
-                /**    Delete username from frontend form    */
1366
-                $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code');
1367
-                if (!empty($attribute_login)) {
1368
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id));
1369
-                }
1370
-
1371
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted'));
1372
-
1373
-                return true;
1374
-                break;
1375
-
1376
-            case '31':
1377
-                /**    Change order structure in order to support several payment    */
1378
-                $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish')));
1379
-                if (!empty($existing_orders)) {
1380
-                    foreach ($existing_orders as $order_main_informations) {
1381
-                        /**    Transfer payment return data form old meta to new    */
1382
-                        $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true);
1383
-                        update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data);
1384
-                        delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data');
1385
-
1386
-                        /**    Transfer old payment storage method to new storage method    */
1387
-                        $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true);
1388
-                        if (!empty($order_meta['order_status'])) {
1389
-                            $order_meta['order_payment']['customer_choice'] = array('method' => (!empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : '')));
1390
-                            unset($order_meta['payment_method']);
1391
-                            $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0;
1392
-                            $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method'];
1393
-                            $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date'];
1394
-                            $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment';
1395
-                            $order_meta['order_payment']['received'][0]['comment'] = '';
1396
-                            $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
1397
-                            if (in_array($order_meta['order_status'], array('completed', 'shipped'))) {
1398
-                                $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total'];
1399
-                                $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID);
1400
-                                $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date'];
1401
-                                $order_meta['order_payment']['received'][0]['status'] = 'payment_received';
1402
-                                $order_meta['order_payment']['received'][0]['comment'] = '';
1403
-                                $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
1404
-                                $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref'];
1405
-                            }
1406
-                            update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta);
1407
-
1408
-                            if (!empty($order_meta['order_payment']['customer_choice'])) {
1409
-                                switch ($order_meta['order_payment']['customer_choice']) {
1410
-                                    case 'check':
1411
-                                        delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true));
1412
-                                        break;
1413
-                                    case 'paypal':
1414
-                                        delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true));
1415
-                                        break;
1416
-                                    case 'cic':
1417
-                                        delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true));
1418
-                                        break;
1419
-                                }
1420
-                            }
1421
-                        }
1422
-                    }
1423
-                }
1424
-                $wps_messages = new wps_message_ctr();
1425
-                $wps_messages->wpshop_messages_historic_correction();
1426
-                wp_reset_query();
1427
-
1428
-                $default_currency = get_option('wpshop_shop_default_currency');
1429
-                foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
1430
-                    if ($default_currency == $k) {
1431
-                        $symbol = $v;
1432
-                    }
1433
-                }
1434
-                if (!empty($symbol)) {
1435
-                    $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', '');
1436
-                    $currency = $wpdb->get_row($query);
1437
-                    if (!empty($currency)) {
1438
-                        update_option('wpshop_shop_default_currency', $currency->id);
1439
-                        // Update the change rate of the default currency
1440
-                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
1441
-                    }
1442
-                }
1443
-
1444
-                $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE');
1445
-                if (!empty($shipping_confirmation_message)) {
1446
-                    $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop');
1447
-                    $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message);
1448
-                    wp_update_post($post);
1449
-                }
1450
-                return true;
1451
-                break;
1452
-            case '32':
1453
-                /**    Update product set id that are null     */
1454
-                $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id');
1455
-                $wpdb->query($query);
1456
-
1457
-                $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME);
1458
-                if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) {
1459
-                    $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
1460
-                    if (empty($admin_new_quotation_message)) {
1461
-                        wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
1462
-                    }
1463
-                    $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
1464
-                    if (empty($admin_new_quotation_confirm_message)) {
1465
-                        wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
1466
-                    }
1467
-                }
1468
-
1469
-                /**    Allows the administrator to manage a little bit more the catalog rewrite parameters    */
1470
-                $options = get_option('wpshop_catalog_product_option');
1471
-                $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category'];
1472
-                update_option('wpshop_catalog_product_option', $options);
1473
-
1474
-                /**    Create a new page for unsuccessfull payment return    */
1475
-                self::wpshop_insert_default_pages($wpshop_shop_type);
1476
-                wp_cache_flush();
1477
-
1478
-                /**    Update the iso code of currencies    */
1479
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro'));
1480
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar'));
1481
-
1482
-                /** Update VAT Rate*/
1483
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva');
1484
-                $attribute_ids = $wpdb->get_results($query);
1485
-                foreach ($attribute_ids as $attribute_id) {
1486
-                    $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id);
1487
-                    $wpdb->query($query);
1488
-                }
1489
-
1490
-                return true;
1491
-                break;
1492
-
1493
-            case '33':
1494
-                /** Update the user_mail for the new system of log in/register */
1495
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"');
1496
-
1497
-                /** Put discount attributes in price attribute set section*/
1498
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
1499
-                $prices_section_id = $wpdb->get_var($query);
1500
-
1501
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount');
1502
-                $attributes = $wpdb->get_results($query);
1503
-                if (!empty($attributes) && !empty($prices_section_id)) {
1504
-                    foreach ($attributes as $attribute) {
1505
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id);
1506
-                    }
1507
-                }
1508
-                return true;
1509
-                break;
1493
+			case '33':
1494
+				/** Update the user_mail for the new system of log in/register */
1495
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"');
1496
+
1497
+				/** Put discount attributes in price attribute set section*/
1498
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
1499
+				$prices_section_id = $wpdb->get_var($query);
1500
+
1501
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount');
1502
+				$attributes = $wpdb->get_results($query);
1503
+				if (!empty($attributes) && !empty($prices_section_id)) {
1504
+					foreach ($attributes as $attribute) {
1505
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id);
1506
+					}
1507
+				}
1508
+				return true;
1509
+				break;
1510
+
1511
+			case '34':
1512
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
1513
+				$prices_section_id = $wpdb->get_var($query);
1514
+
1515
+				$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id);
1516
+				$last_position_id = $wpdb->get_var($query);
1517
+
1518
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE  attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id);
1519
+				$attribute_example = $wpdb->get_row($query);
1520
+
1521
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to');
1522
+				$attributes = $wpdb->get_results($query);
1523
+				$i = 1;
1524
+				if (!empty($attributes) && !empty($prices_section_id)) {
1525
+
1526
+					foreach ($attributes as $attribute) {
1527
+						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id));
1528
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i));
1529
+						$i++;
1530
+					}
1531
+				}
1532
+				$discount_options = get_option('wpshop_catalog_product_option');
1533
+				$status = (!empty($discount_options) && !empty($discount_options['discount'])) ? 'valid' : 'notused';
1534
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from'));
1535
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to'));
1536
+				return true;
1537
+				break;
1538
+
1539
+			case '35':
1540
+				$wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS));
1541
+				return true;
1542
+				break;
1543
+
1544
+			case '36':
1545
+				wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
1546
+				@set_time_limit(900);
1547
+				/** Change the path for old categories pictures */
1548
+				@chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755);
1549
+
1550
+				$query = 'SELECT * FROM ' . $wpdb->terms;
1551
+				$terms = $wpdb->get_results($query);
1552
+				if (!empty($terms)) {
1553
+					foreach ($terms as $term) {
1554
+						@chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755);
1555
+						/** Check if a picture exists **/
1556
+						$term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id);
1557
+						if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) {
1558
+							$wp_upload_dir = wp_upload_dir();
1559
+							$img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'];
1560
+							$img_basename = basename($img_path);
1561
+							$wp_filetype = wp_check_filetype($img_basename, null);
1562
+							/** Check if there is an image with the same name, if yes we add a rand number to image's name **/
1563
+							$rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : '';
1564
+							$img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename;
1565
+							if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
1566
+								$attachment = array(
1567
+									'guid' => $wp_upload_dir['url'] . '/' . $img_basename,
1568
+									'post_mime_type' => $wp_filetype['type'],
1569
+									'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename),
1570
+									'post_content' => '',
1571
+									'post_status' => 'inherit',
1572
+								);
1573
+								$attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
1574
+								/** Generate differnts sizes for this image **/
1575
+								require_once ABSPATH . 'wp-admin/includes/image.php';
1576
+								$attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
1577
+								wp_update_attachment_metadata($attach_id, $attach_data);
1578
+								/** Update option picture **/
1579
+								$term_option['wpshop_category_picture'] = $attach_id;
1580
+								update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option);
1581
+							}
1582
+						}
1583
+					}
1584
+				}
1585
+
1586
+				/** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
1587
+				$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus');
1588
+				$meta_keys = $wpdb->get_results($query);
1589
+				if (!empty($meta_keys) && is_array($meta_keys)) {
1590
+					foreach ($meta_keys as $meta_key) {
1591
+						$user_id = $meta_key->user_id;
1592
+						$meta_value = unserialize($meta_key->meta_value);
1593
+						if (!empty($meta_value) && is_array($meta_value)) {
1594
+							$data_to_delete = array_search('add-wpshop_product_category', $meta_value);
1595
+							if ($data_to_delete !== false) {
1596
+								unset($meta_value[$data_to_delete]);
1597
+							}
1598
+						}
1599
+						update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value);
1600
+					}
1601
+				}
1602
+				return true;
1603
+				break;
1510 1604
 
1511
-            case '34':
1512
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
1513
-                $prices_section_id = $wpdb->get_var($query);
1605
+			case '37':
1606
+				@set_time_limit(900);
1607
+				/** Change the path for old categories pictures */
1608
+				@chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755);
1609
+				/** Read all categories folders **/
1610
+				$categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category';
1611
+				if (file_exists($categories_main_dir)) {
1612
+					$main_folder_content = scandir($categories_main_dir);
1613
+					/** For each category folder **/
1614
+					foreach ($main_folder_content as $category_folder) {
1615
+						if ($category_folder && substr($category_folder, 0, 1) != '.') {
1616
+							$category_id = $category_folder;
1617
+							@chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755);
1618
+							$scan_category_folder = opendir($categories_main_dir . '/' . $category_folder);
1619
+							/** For each Picture of category **/
1620
+							$file_time = 0;
1621
+							$save_this_picture = false;
1622
+							while (false !== ($fichier = readdir($scan_category_folder))) {
1623
+								if ($fichier && substr($fichier, 0, 1) != '.') {
1624
+									if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) {
1625
+										$save_this_picture = true;
1626
+										$file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier);
1627
+									}
1628
+									/** Select category option **/
1629
+									$term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id);
1630
+									$wp_upload_dir = wp_upload_dir();
1631
+									$img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier;
1632
+									$img_basename = basename($img_path);
1633
+									$wp_filetype = wp_check_filetype($img_basename, null);
1634
+									/** Check if there is an image with the same name, if yes we add a rand number to image's name **/
1635
+									$rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : '';
1636
+									$img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename;
1637
+
1638
+									if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
1639
+										$attachment = array(
1640
+											'guid' => $wp_upload_dir['url'] . '/' . $img_basename,
1641
+											'post_mime_type' => $wp_filetype['type'],
1642
+											'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename),
1643
+											'post_content' => '',
1644
+											'post_status' => 'inherit',
1645
+										);
1646
+										$attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
1647
+										/** Generate differnts sizes for this image **/
1648
+										require_once ABSPATH . 'wp-admin/includes/image.php';
1649
+										$attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
1650
+										wp_update_attachment_metadata($attach_id, $attach_data);
1651
+										/** Update option picture **/
1652
+										$term_option['wpshop_category_picture'] = $attach_id;
1653
+										if ($save_this_picture) {
1654
+											update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option);
1655
+										}
1656
+										$save_this_picture = false;
1657
+									}
1658
+								}
1659
+							}
1660
+						}
1661
+					}
1662
+				}
1663
+				return true;
1664
+				break;
1514 1665
 
1515
-                $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id);
1516
-                $last_position_id = $wpdb->get_var($query);
1666
+			case '38':
1667
+				wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE');
1668
+				return true;
1669
+				break;
1517 1670
 
1518
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE  attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id);
1519
-                $attribute_example = $wpdb->get_row($query);
1671
+			case '39':
1672
+				$attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
1673
+				/** Check if the 7% VAT Rate is not already created **/
1674
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7');
1675
+				$exist_vat_rate = $wpdb->get_results($query);
1676
+
1677
+				if (empty($exist_vat_rate)) {
1678
+					/** Get Max Position **/
1679
+					$query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
1680
+					$max_position = $wpdb->get_var($query);
1681
+
1682
+					if (!empty($attribute_def) && !empty($attribute_def->id)) {
1683
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7'));
1684
+					}
1685
+				}
1686
+
1687
+				/** Filter Search optimization **/
1688
+				@set_time_limit(900);
1689
+				$query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1690
+				$categories = $wpdb->get_results($query);
1691
+				$cats = array();
1692
+				if (!empty($categories)) {
1693
+					foreach ($categories as $category) {
1694
+						$cats[] = $category->term_id;
1695
+					}
1696
+					$wpshop_filter_search = new wps_filter_search();
1697
+					$wpshop_filter_search->stock_values_for_attribute($cats);
1698
+				}
1699
+				return true;
1700
+				break;
1520 1701
 
1521
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to');
1522
-                $attributes = $wpdb->get_results($query);
1523
-                $i = 1;
1524
-                if (!empty($attributes) && !empty($prices_section_id)) {
1702
+			case '40':
1703
+				/**    Store watt in puissance unit group    */
1704
+				$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop'));
1705
+				$puissance_unit_group_id = $wpdb->get_var($query);
1706
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt'));
1707
+
1708
+				/**    Store day/week/year in duration unit group    */
1709
+				$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop'));
1710
+				$duration_unit_group_id = $wpdb->get_var($query);
1711
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day'));
1712
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week'));
1713
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year'));
1714
+
1715
+				/**    Store day/week/year in duration unit group    */
1716
+				$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop'));
1717
+				$length_unit_group_id = $wpdb->get_var($query);
1718
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm'));
1719
+				return true;
1720
+				break;
1525 1721
 
1526
-                    foreach ($attributes as $attribute) {
1527
-                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id));
1528
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i));
1529
-                        $i++;
1530
-                    }
1531
-                }
1532
-                $discount_options = get_option('wpshop_catalog_product_option');
1533
-                $status = (!empty($discount_options) && !empty($discount_options['discount'])) ? 'valid' : 'notused';
1534
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from'));
1535
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to'));
1536
-                return true;
1537
-                break;
1538
-
1539
-            case '35':
1540
-                $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS));
1541
-                return true;
1542
-                break;
1543
-
1544
-            case '36':
1545
-                wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
1546
-                @set_time_limit(900);
1547
-                /** Change the path for old categories pictures */
1548
-                @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755);
1549
-
1550
-                $query = 'SELECT * FROM ' . $wpdb->terms;
1551
-                $terms = $wpdb->get_results($query);
1552
-                if (!empty($terms)) {
1553
-                    foreach ($terms as $term) {
1554
-                        @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755);
1555
-                        /** Check if a picture exists **/
1556
-                        $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id);
1557
-                        if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) {
1558
-                            $wp_upload_dir = wp_upload_dir();
1559
-                            $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'];
1560
-                            $img_basename = basename($img_path);
1561
-                            $wp_filetype = wp_check_filetype($img_basename, null);
1562
-                            /** Check if there is an image with the same name, if yes we add a rand number to image's name **/
1563
-                            $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : '';
1564
-                            $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename;
1565
-                            if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
1566
-                                $attachment = array(
1567
-                                    'guid' => $wp_upload_dir['url'] . '/' . $img_basename,
1568
-                                    'post_mime_type' => $wp_filetype['type'],
1569
-                                    'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename),
1570
-                                    'post_content' => '',
1571
-                                    'post_status' => 'inherit',
1572
-                                );
1573
-                                $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
1574
-                                /** Generate differnts sizes for this image **/
1575
-                                require_once ABSPATH . 'wp-admin/includes/image.php';
1576
-                                $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
1577
-                                wp_update_attachment_metadata($attach_id, $attach_data);
1578
-                                /** Update option picture **/
1579
-                                $term_option['wpshop_category_picture'] = $attach_id;
1580
-                                update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option);
1581
-                            }
1582
-                        }
1583
-                    }
1584
-                }
1585
-
1586
-                /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
1587
-                $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus');
1588
-                $meta_keys = $wpdb->get_results($query);
1589
-                if (!empty($meta_keys) && is_array($meta_keys)) {
1590
-                    foreach ($meta_keys as $meta_key) {
1591
-                        $user_id = $meta_key->user_id;
1592
-                        $meta_value = unserialize($meta_key->meta_value);
1593
-                        if (!empty($meta_value) && is_array($meta_value)) {
1594
-                            $data_to_delete = array_search('add-wpshop_product_category', $meta_value);
1595
-                            if ($data_to_delete !== false) {
1596
-                                unset($meta_value[$data_to_delete]);
1597
-                            }
1598
-                        }
1599
-                        update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value);
1600
-                    }
1601
-                }
1602
-                return true;
1603
-                break;
1604
-
1605
-            case '37':
1606
-                @set_time_limit(900);
1607
-                /** Change the path for old categories pictures */
1608
-                @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755);
1609
-                /** Read all categories folders **/
1610
-                $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category';
1611
-                if (file_exists($categories_main_dir)) {
1612
-                    $main_folder_content = scandir($categories_main_dir);
1613
-                    /** For each category folder **/
1614
-                    foreach ($main_folder_content as $category_folder) {
1615
-                        if ($category_folder && substr($category_folder, 0, 1) != '.') {
1616
-                            $category_id = $category_folder;
1617
-                            @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755);
1618
-                            $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder);
1619
-                            /** For each Picture of category **/
1620
-                            $file_time = 0;
1621
-                            $save_this_picture = false;
1622
-                            while (false !== ($fichier = readdir($scan_category_folder))) {
1623
-                                if ($fichier && substr($fichier, 0, 1) != '.') {
1624
-                                    if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) {
1625
-                                        $save_this_picture = true;
1626
-                                        $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier);
1627
-                                    }
1628
-                                    /** Select category option **/
1629
-                                    $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id);
1630
-                                    $wp_upload_dir = wp_upload_dir();
1631
-                                    $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier;
1632
-                                    $img_basename = basename($img_path);
1633
-                                    $wp_filetype = wp_check_filetype($img_basename, null);
1634
-                                    /** Check if there is an image with the same name, if yes we add a rand number to image's name **/
1635
-                                    $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : '';
1636
-                                    $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename;
1637
-
1638
-                                    if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
1639
-                                        $attachment = array(
1640
-                                            'guid' => $wp_upload_dir['url'] . '/' . $img_basename,
1641
-                                            'post_mime_type' => $wp_filetype['type'],
1642
-                                            'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename),
1643
-                                            'post_content' => '',
1644
-                                            'post_status' => 'inherit',
1645
-                                        );
1646
-                                        $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
1647
-                                        /** Generate differnts sizes for this image **/
1648
-                                        require_once ABSPATH . 'wp-admin/includes/image.php';
1649
-                                        $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
1650
-                                        wp_update_attachment_metadata($attach_id, $attach_data);
1651
-                                        /** Update option picture **/
1652
-                                        $term_option['wpshop_category_picture'] = $attach_id;
1653
-                                        if ($save_this_picture) {
1654
-                                            update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option);
1655
-                                        }
1656
-                                        $save_this_picture = false;
1657
-                                    }
1658
-                                }
1659
-                            }
1660
-                        }
1661
-                    }
1662
-                }
1663
-                return true;
1664
-                break;
1665
-
1666
-            case '38':
1667
-                wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE');
1668
-                return true;
1669
-                break;
1670
-
1671
-            case '39':
1672
-                $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
1673
-                /** Check if the 7% VAT Rate is not already created **/
1674
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7');
1675
-                $exist_vat_rate = $wpdb->get_results($query);
1676
-
1677
-                if (empty($exist_vat_rate)) {
1678
-                    /** Get Max Position **/
1679
-                    $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
1680
-                    $max_position = $wpdb->get_var($query);
1681
-
1682
-                    if (!empty($attribute_def) && !empty($attribute_def->id)) {
1683
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7'));
1684
-                    }
1685
-                }
1686
-
1687
-                /** Filter Search optimization **/
1688
-                @set_time_limit(900);
1689
-                $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1690
-                $categories = $wpdb->get_results($query);
1691
-                $cats = array();
1692
-                if (!empty($categories)) {
1693
-                    foreach ($categories as $category) {
1694
-                        $cats[] = $category->term_id;
1695
-                    }
1696
-                    $wpshop_filter_search = new wps_filter_search();
1697
-                    $wpshop_filter_search->stock_values_for_attribute($cats);
1698
-                }
1699
-                return true;
1700
-                break;
1701
-
1702
-            case '40':
1703
-                /**    Store watt in puissance unit group    */
1704
-                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop'));
1705
-                $puissance_unit_group_id = $wpdb->get_var($query);
1706
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt'));
1707
-
1708
-                /**    Store day/week/year in duration unit group    */
1709
-                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop'));
1710
-                $duration_unit_group_id = $wpdb->get_var($query);
1711
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day'));
1712
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week'));
1713
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year'));
1714
-
1715
-                /**    Store day/week/year in duration unit group    */
1716
-                $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop'));
1717
-                $length_unit_group_id = $wpdb->get_var($query);
1718
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm'));
1719
-                return true;
1720
-                break;
1721
-
1722
-            case '41':
1723
-                /**    Get distinct attribute set and delete doublons    */
1724
-                $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1";
1725
-                $list_of_set = $wpdb->get_results($query);
1726
-                foreach ($list_of_set as $set_infos) {
1727
-                    $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
1728
-                    $wpdb->query($query);
1729
-                }
1730
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET);
1731
-
1732
-                /**    Get and delete attribute set section    */
1733
-                $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )";
1734
-                $wpdb->query($query);
1735
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP);
1736
-
1737
-                /**    Get and delete attribute set details    */
1738
-                $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
1739
-                $wpdb->query($query);
1740
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
1741
-
1742
-                $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
1743
-                $affectation_list = $wpdb->get_results($query);
1744
-                foreach ($affectation_list as $affectation_to_treat) {
1745
-                    $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id);
1746
-                    $wpdb->query($query);
1747
-                }
1748
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
1749
-
1750
-                /**    Get and delete double unit    */
1751
-                $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1";
1752
-                $list_of_set = $wpdb->get_results($query);
1753
-                foreach ($list_of_set as $set_infos) {
1754
-                    $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id);
1755
-                    $wpdb->query($query);
1756
-                }
1757
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT);
1758
-
1759
-                $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1";
1760
-                $list_of_set = $wpdb->get_results($query);
1761
-                foreach ($list_of_set as $set_infos) {
1762
-                    $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
1763
-                    $wpdb->query($query);
1764
-                }
1765
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
1766
-
1767
-                /**    Get and delete attribute set details    */
1768
-                $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
1769
-                $wpdb->query($query);
1770
-                $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
1771
-                $affectation_list = $wpdb->get_results($query);
1772
-                foreach ($affectation_list as $list) {
1773
-                    $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, '');
1774
-                    $wpdb->query($query);
1775
-                }
1776
-                $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
1777
-
1778
-                return true;
1779
-                break;
1780
-
1781
-            case '42':
1782
-                $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
1783
-                if (empty($available_downloadable_product)) {
1784
-                    wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
1785
-                }
1786
-                return true;
1787
-                break;
1788
-
1789
-            case '43':
1790
-                $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED');
1791
-                if (empty($available_downloadable_product)) {
1792
-                    wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED');
1793
-                }
1794
-                return true;
1795
-                break;
1796
-
1797
-            case '44':
1798
-                $display_option = get_option('wpshop_display_option');
1799
-                if (!empty($display_option) && empty($display_option['latest_products_ordered'])) {
1800
-                    $display_option['latest_products_ordered'] = 3;
1801
-                    update_option('wpshop_display_option', $display_option);
1802
-                }
1803
-
1804
-                /** Check messages for customization **/
1805
-                // @since 1.4.3.7 Deleted messages constants
1806
-                /*$messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED);
1722
+			case '41':
1723
+				/**    Get distinct attribute set and delete doublons    */
1724
+				$query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1";
1725
+				$list_of_set = $wpdb->get_results($query);
1726
+				foreach ($list_of_set as $set_infos) {
1727
+					$query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
1728
+					$wpdb->query($query);
1729
+				}
1730
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET);
1731
+
1732
+				/**    Get and delete attribute set section    */
1733
+				$query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )";
1734
+				$wpdb->query($query);
1735
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP);
1736
+
1737
+				/**    Get and delete attribute set details    */
1738
+				$query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
1739
+				$wpdb->query($query);
1740
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
1741
+
1742
+				$query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
1743
+				$affectation_list = $wpdb->get_results($query);
1744
+				foreach ($affectation_list as $affectation_to_treat) {
1745
+					$query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id);
1746
+					$wpdb->query($query);
1747
+				}
1748
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
1749
+
1750
+				/**    Get and delete double unit    */
1751
+				$query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1";
1752
+				$list_of_set = $wpdb->get_results($query);
1753
+				foreach ($list_of_set as $set_infos) {
1754
+					$query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id);
1755
+					$wpdb->query($query);
1756
+				}
1757
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT);
1758
+
1759
+				$query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1";
1760
+				$list_of_set = $wpdb->get_results($query);
1761
+				foreach ($list_of_set as $set_infos) {
1762
+					$query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
1763
+					$wpdb->query($query);
1764
+				}
1765
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
1766
+
1767
+				/**    Get and delete attribute set details    */
1768
+				$query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
1769
+				$wpdb->query($query);
1770
+				$query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
1771
+				$affectation_list = $wpdb->get_results($query);
1772
+				foreach ($affectation_list as $list) {
1773
+					$query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, '');
1774
+					$wpdb->query($query);
1775
+				}
1776
+				$wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
1777
+
1778
+				return true;
1779
+				break;
1780
+
1781
+			case '42':
1782
+				$available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
1783
+				if (empty($available_downloadable_product)) {
1784
+					wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
1785
+				}
1786
+				return true;
1787
+				break;
1788
+
1789
+			case '43':
1790
+				$available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED');
1791
+				if (empty($available_downloadable_product)) {
1792
+					wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED');
1793
+				}
1794
+				return true;
1795
+				break;
1796
+
1797
+			case '44':
1798
+				$display_option = get_option('wpshop_display_option');
1799
+				if (!empty($display_option) && empty($display_option['latest_products_ordered'])) {
1800
+					$display_option['latest_products_ordered'] = 3;
1801
+					update_option('wpshop_display_option', $display_option);
1802
+				}
1803
+
1804
+				/** Check messages for customization **/
1805
+				// @since 1.4.3.7 Deleted messages constants
1806
+				/*$messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED);
1807 1807
                 if (!empty($messages)) {
1808 1808
                     foreach ($messages as $key => $message) {
1809 1809
                         $message_option = get_option($key);
@@ -1818,635 +1818,635 @@  discard block
 block discarded – undo
1818 1818
                     }
1819 1819
                 }*/
1820 1820
 
1821
-                return true;
1822
-                break;
1823
-
1824
-            case '45':
1825
-                $shipping_mode_ctr = new wps_shipping_mode_ctr();
1826
-                $shipping_mode_ctr->migrate_default_shipping_mode();
1827
-                return true;
1828
-                break;
1829
-
1830
-            case '46':
1831
-                wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE');
1832
-                wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE);
1833
-                return true;
1834
-                break;
1835
-
1836
-            case '47':
1837
-                wps_payment_mode::migrate_payment_modes();
1838
-                return true;
1839
-                break;
1840
-
1841
-            case '48':
1842
-                @ini_set('max_execution_time', '500');
1843
-
1844
-                $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1845
-                $output_type_option = get_option('wpshop_display_option');
1846
-                $output_type = $output_type_option['wpshop_display_list_type'];
1847
-
1848
-                for ($i = 0; $i <= $count_products->publish; $i += 20) {
1849
-                    $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
1850
-                    $products = $wpdb->get_results($query);
1851
-                    if (!empty($products)) {
1852
-                        foreach ($products as $product) {
1853
-                            $p = wpshop_products::get_product_data($product->ID);
1854
-                            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
1855
-                            update_post_meta($product->ID, '_wps_price_infos', $price);
1856
-                        }
1857
-                    }
1858
-                }
1859
-
1860
-                return true;
1861
-                break;
1862
-
1863
-            case '49':
1864
-                update_option('wpshop_send_invoice', true);
1865
-                return true;
1866
-                break;
1867
-
1868
-            case '50':
1869
-                $price_display_option = get_option('wpshop_catalog_product_option');
1870
-                $price_display_option['price_display']['text_from'] = 'on';
1871
-                $price_display_option['price_display']['lower_price'] = 'on';
1872
-                update_option('wpshop_catalog_product_option', $price_display_option);
1873
-
1874
-                self::wpshop_insert_default_pages();
1875
-
1876
-                return true;
1877
-                break;
1878
-
1879
-            case '51':
1880
-                /**    Insert new message for direct payment link    */
1881
-                $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1882
-                if (empty($direct_payment_link_message)) {
1883
-                    wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1884
-                }
1885
-                return true;
1886
-                break;
1887
-
1888
-            case '52':
1889
-                $account_page_option = get_option('wpshop_myaccount_page_id');
1890
-                if (!empty($account_page_option)) {
1891
-                    $page_account = get_post($account_page_option);
1892
-                    $page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]';
1893
-                    wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content));
1894
-                }
1895
-                return true;
1896
-                break;
1897
-
1898
-            case '53':
1899
-                $payment_modes_option = get_option('wps_payment_mode');
1900
-                if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) {
1901
-                    $payment_modes_option['mode']['cash_on_delivery'] = array(
1902
-                        'name' => __('Cash on delivery', 'wpshop'),
1903
-                        'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png',
1904
-                        'description' => __('Pay your order on delivery', 'wpshop'));
1905
-
1906
-                    update_option('wps_payment_mode', $payment_modes_option);
1907
-                }
1908
-
1909
-                // Mass action on products to add a flag on variation definition
1910
-                $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1911
-                if (!empty($products)) {
1912
-                    foreach ($products as $p) {
1913
-                        $post_id = $p->ID;
1914
-                        $check_product_have_variations = wpshop_products::get_variation($post_id);
1915
-                        if (!empty($check_product_have_variations)) {
1916
-                            $variation_flag = wpshop_products::check_variation_type($post_id);
1917
-                            $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1918
-                            $variation_defining['variation_type'] = $variation_flag;
1919
-                            update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1920
-                        }
1921
-                    }
1922
-                }
1923
-                return true;
1924
-                break;
1925
-
1926
-            case '54':
1927
-                // Change shortcode of sign up page
1928
-                $signup_page_id = get_option('wpshop_signup_page_id');
1929
-                if (!empty($signup_page_id)) {
1930
-                    $signup_page = get_post($signup_page_id);
1931
-                    $signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]';
1932
-                    wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content));
1933
-                }
1934
-
1935
-                // Change Terms of sale default content
1936
-                $terms_page_id = get_option('wpshop_terms_of_sale_page_id');
1937
-                if (!empty($terms_page_id)) {
1938
-                    $terms_sale_page = get_post($terms_page_id);
1939
-                    if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') {
1940
-                        $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>';
1941
-                        $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>';
1942
-                        $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1943
-                        $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>';
1944
-                        $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1945
-                        $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>';
1946
-                        $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1947
-                        $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>';
1948
-                        $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name'));
1949
-                        wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data));
1950
-                    }
1951
-                }
1952
-
1953
-                return true;
1954
-                break;
1955
-
1956
-            case '55':
1957
-                $checkout_page_id = get_option('wpshop_checkout_page_id');
1958
-                $checkout_page = get_post($checkout_page_id);
1959
-                $checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]';
1960
-                wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content));
1961
-
1962
-                // Update cart page id
1963
-                update_option('wpshop_cart_page_id', $checkout_page_id);
1964
-                return true;
1965
-                break;
1966
-
1967
-            case '56':
1968
-                $wps_entities = new wpshop_entities();
1969
-                $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1970
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id);
1971
-                $set = $wpdb->get_row($query);
1972
-                if (!empty($set)) {
1973
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET,
1974
-                        array('default_set' => 'yes'),
1975
-                        array('id' => $set->id));
1976
-                }
1977
-                // Update Opinions activation option
1978
-                update_option('wps_opinion', array('active' => 'on'));
1979
-                return true;
1980
-                break;
1981
-
1982
-            case '57':
1983
-                $wpshop_cart_option = get_option('wpshop_cart_option');
1984
-                $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes';
1985
-                $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes';
1986
-
1987
-                update_option('wpshop_cart_option', $wpshop_cart_option);
1988
-                return true;
1989
-                break;
1990
-
1991
-            case '58':
1992
-                /** Turn customers publish into draft **/
1993
-                $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1994
-                $wpdb->query($query);
1995
-
1996
-                $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
1997
-                /** Check if the 0% VAT Rate is not already created **/
1998
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0');
1999
-                $exist_vat_rate = $wpdb->get_results($query);
2000
-
2001
-                if (empty($exist_vat_rate)) {
2002
-                    /** Get Max Position **/
2003
-                    $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
2004
-                    $max_position = $wpdb->get_var($query);
2005
-
2006
-                    if (!empty($attribute_def) && !empty($attribute_def->id)) {
2007
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0'));
2008
-                    }
2009
-                }
2010
-                return true;
2011
-                break;
2012
-
2013
-            case '59':
2014
-                /** Move old images gallery to the new gallery, and remove old links **/
2015
-                $allowed = get_allowed_mime_types();
2016
-                $args = array(
2017
-                    'posts_per_page' => -1,
2018
-                    'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
2019
-                    'post_status' => array('publish', 'draft', 'trash'),
2020
-                );
2021
-                $posts = get_posts($args);
2022
-                $result = array();
2023
-                foreach ($posts as $post) {
2024
-                    $array = array();
2025
-                    $array['Post'] = $post;
2026
-                    $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true);
2027
-                    $array['Attachments'] = get_attached_media($allowed, $post->ID);
2028
-                    $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true);
2029
-                    if (!empty($array['TrueAttachmentsString'])) {
2030
-                        $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']);
2031
-                    }
2032
-                    $array['OldAttachmentsString'] = '';
2033
-                    foreach ($array['Attachments'] as $attachment) {
2034
-                        $filename = basename(get_attached_file($attachment->ID));
2035
-                        $pos_ext = strrpos($filename, '.');
2036
-                        $filename_no_ext = substr($filename, 0, $pos_ext);
2037
-                        if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) {
2038
-                            $array['OldAttachmentsString'] .= $attachment->ID . ',';
2039
-                        }
2040
-                    }
2041
-                    unset($TrueAttachments_id);
2042
-                    $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString'];
2043
-                    update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]);
2044
-                }
2045
-                return true;
2046
-                break;
2047
-
2048
-            case '60':
2049
-                /* Create default emails */
2050
-                wps_message_ctr::create_default_message();
2051
-
2052
-                /** Update entries for quick add */
2053
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"');
2054
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"');
2055
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"');
2056
-                switch (WPSHOP_PRODUCT_PRICE_PILOT) {
2057
-                    case 'HT':
2058
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"');
2059
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"');
2060
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"');
2061
-                        break;
2062
-                    default:
2063
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"');
2064
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"');
2065
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"');
2066
-                        break;
2067
-                }
2068
-
2069
-                /* Default country with WP language */
2070
-                $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice');
2071
-                if (empty($wpshop_country_default_choice_option)) {
2072
-                    update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3));
2073
-                }
2074
-                return true;
2075
-                break;
2076
-
2077
-            case '61':
2078
-                /** Import the xml for guided tour */
2079
-                wpsBubble_ctr::import_xml();
2080
-
2081
-                /* Hide admin bar */
2082
-                $wpshop_display_option = get_option('wpshop_display_option');
2083
-                if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) {
2084
-                    $wpshop_display_option['wpshop_hide_admin_bar'] = 'on';
2085
-                    update_option('wpshop_display_option', $wpshop_display_option);
2086
-                }
2087
-
2088
-                return true;
2089
-                break;
2090
-
2091
-            case '62':
2092
-                /** Install user default for POS */
2093
-                wps_pos_addon::action_to_do_on_activation();
2094
-
2095
-                return true;
2096
-                break;
2097
-
2098
-            case '63':
2099
-                $data = get_option('wps_shipping_mode');
2100
-                if (empty($data['modes']['default_shipping_mode_for_pos'])) {
2101
-                    $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop');
2102
-                    $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop');
2103
-                    update_option('wps_shipping_mode', $data);
2104
-                }
2105
-                return true;
2106
-                break;
2107
-
2108
-            case '64':
2109
-                $options = get_option('wpshop_catalog_product_option');
2110
-                if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
2111
-                    unset($options['wpshop_catalog_product_slug_with_category']);
2112
-                    update_option('wpshop_catalog_product_option', $options);
2113
-                }
2114
-                return true;
2115
-                break;
2116
-
2117
-            case '65':
2118
-                $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
2119
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id);
2120
-                $company_id = $wpdb->get_var($query);
2121
-                if (!isset($company_id)) {
2122
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2123
-                        'is_visible_in_front' => 'no',
2124
-                        'is_visible_in_front_listing' => 'yes',
2125
-                        'is_global' => 'no',
2126
-                        'is_user_defined' => 'no',
2127
-                        'is_required' => 'no',
2128
-                        'is_visible_in_advanced_search' => 'no',
2129
-                        'is_searchable' => 'no',
2130
-                        'is_filterable' => 'no',
2131
-                        'is_comparable' => 'no',
2132
-                        'is_html_allowed_on_front' => 'no',
2133
-                        'is_unique' => 'no',
2134
-                        'is_filterable_in_search' => 'no',
2135
-                        'is_used_for_sort_by' => 'no',
2136
-                        'is_configurable' => 'no',
2137
-                        'is_requiring_unit' => 'no',
2138
-                        'is_recordable_in_cart_meta' => 'no',
2139
-                        'is_used_in_admin_listing_column' => 'no',
2140
-                        'is_used_in_quick_add_form' => 'no',
2141
-                        'is_used_for_variation' => 'no',
2142
-                        'is_used_in_variation' => 'no',
2143
-                        '_display_informations_about_value' => 'no',
2144
-                        '_need_verification' => 'no',
2145
-                        '_unit_group_id' => null,
2146
-                        '_default_unit' => null,
2147
-                        'is_historisable' => 'yes',
2148
-                        'is_intrinsic' => 'no',
2149
-                        'data_type_to_use' => 'custom',
2150
-                        'use_ajax_for_filling_field' => 'no',
2151
-                        'data_type' => 'varchar',
2152
-                        'backend_table' => null,
2153
-                        'backend_label' => 'Company',
2154
-                        'backend_input' => 'text',
2155
-                        'frontend_label' => 'Company',
2156
-                        'frontend_input' => 'text',
2157
-                        'frontend_verification' => null,
2158
-                        'code' => 'company_customer',
2159
-                        'note' => '',
2160
-                        'default_value' => '',
2161
-                        'frontend_css_class' => 'company_customer',
2162
-                        'backend_css_class' => null,
2163
-                        'frontend_help_message' => null,
2164
-                        'entity_id' => $entity_id,
2165
-                    ));
2166
-                    $company_id = $wpdb->insert_id;
2167
-                }
2168
-
2169
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id);
2170
-                $is_provider_id = $wpdb->get_var($query);
2171
-                if (!isset($is_provider_id)) {
2172
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2173
-                        'is_visible_in_front' => 'no',
2174
-                        'is_visible_in_front_listing' => 'yes',
2175
-                        'is_global' => 'no',
2176
-                        'is_user_defined' => 'no',
2177
-                        'is_required' => 'yes',
2178
-                        'is_visible_in_advanced_search' => 'no',
2179
-                        'is_searchable' => 'no',
2180
-                        'is_filterable' => 'no',
2181
-                        'is_comparable' => 'no',
2182
-                        'is_html_allowed_on_front' => 'no',
2183
-                        'is_unique' => 'no',
2184
-                        'is_filterable_in_search' => 'no',
2185
-                        'is_used_for_sort_by' => 'no',
2186
-                        'is_configurable' => 'no',
2187
-                        'is_requiring_unit' => 'no',
2188
-                        'is_recordable_in_cart_meta' => 'no',
2189
-                        'is_used_in_admin_listing_column' => 'no',
2190
-                        'is_used_in_quick_add_form' => 'no',
2191
-                        'is_used_for_variation' => 'no',
2192
-                        'is_used_in_variation' => 'no',
2193
-                        '_display_informations_about_value' => 'no',
2194
-                        '_need_verification' => 'no',
2195
-                        '_unit_group_id' => null,
2196
-                        '_default_unit' => null,
2197
-                        'is_historisable' => 'yes',
2198
-                        'is_intrinsic' => 'no',
2199
-                        'data_type_to_use' => 'custom',
2200
-                        'use_ajax_for_filling_field' => 'no',
2201
-                        'data_type' => 'integer',
2202
-                        'backend_table' => null,
2203
-                        'backend_label' => 'Provider',
2204
-                        'backend_input' => 'select',
2205
-                        'frontend_label' => 'Provider',
2206
-                        'frontend_input' => 'select',
2207
-                        'frontend_verification' => null,
2208
-                        'code' => 'is_provider',
2209
-                        'note' => '',
2210
-                        'default_value' => 'no',
2211
-                        'frontend_css_class' => 'is_provider',
2212
-                        'backend_css_class' => null,
2213
-                        'frontend_help_message' => null,
2214
-                        'entity_id' => $entity_id,
2215
-                    ));
2216
-                    $is_provider_id = $wpdb->insert_id;
2217
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2218
-                        'status' => 'valid',
2219
-                        'attribute_id' => $is_provider_id,
2220
-                        'creation_date_value' => current_time('mysql'),
2221
-                        'value' => 'yes',
2222
-                        'label' => 'Yes',
2223
-                    ));
2224
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2225
-                        'status' => 'valid',
2226
-                        'attribute_id' => $is_provider_id,
2227
-                        'creation_date_value' => current_time('mysql'),
2228
-                        'value' => 'no',
2229
-                        'label' => 'No',
2230
-                    ));
2231
-                    $default_value = $wpdb->insert_id;
2232
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id));
2233
-                }
2234
-
2235
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id);
2236
-                $company_section_detail_id = $wpdb->get_var($query);
2237
-
2238
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id);
2239
-                $is_provider_section_detail_id = $wpdb->get_var($query);
2240
-
2241
-                if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) {
2242
-                    $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
2243
-                    $attribute_set_id = $wpdb->get_var($query);
2244
-
2245
-                    $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account');
2246
-                    $attribute_set_section_id = $wpdb->get_var($query);
2247
-
2248
-                    $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id);
2249
-                    $attributes_set_details = $wpdb->get_results($query);
2250
-                    $set_details_id_postion_order = array();
2251
-                    foreach ($attributes_set_details as $attribute_set_detail) {
2252
-                        $query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id);
2253
-                        $attribute_set_detail_code = $wpdb->get_var($query);
2254
-                        if ($attribute_set_detail_code == 'last_name') {
2255
-                            $set_details_id_postion_order[1] = $attribute_set_detail->attribute_id;
2256
-                        }
2257
-                        if ($attribute_set_detail_code == 'first_name') {
2258
-                            $set_details_id_postion_order[2] = $attribute_set_detail->attribute_id;
2259
-                        }
2260
-                        if ($attribute_set_detail_code == 'user_email') {
2261
-                            $set_details_id_postion_order[3] = $attribute_set_detail->attribute_id;
2262
-                        }
2263
-                        if ($attribute_set_detail_code == 'user_pass') {
2264
-                            $set_details_id_postion_order[4] = $attribute_set_detail->attribute_id;
2265
-                        }
2266
-                    }
2267
-                    $max_position = count($set_details_id_postion_order);
1821
+				return true;
1822
+				break;
2268 1823
 
2269
-                    if (!isset($company_section_detail_id)) {
2270
-                        $max_position = $max_position + 1;
2271
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position));
2272
-                        $set_details_id_postion_order[$max_position] = $company_id;
2273
-                        $company_section_detail_id = $wpdb->insert_id;
2274
-                    }
1824
+			case '45':
1825
+				$shipping_mode_ctr = new wps_shipping_mode_ctr();
1826
+				$shipping_mode_ctr->migrate_default_shipping_mode();
1827
+				return true;
1828
+				break;
2275 1829
 
2276
-                    if (!isset($is_provider_section_detail_id)) {
2277
-                        $max_position = $max_position + 1;
2278
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position));
2279
-                        $set_details_id_postion_order[$max_position] = $is_provider_id;
2280
-                        $is_provider_section_detail_id = $wpdb->insert_id;
2281
-                    }
1830
+			case '46':
1831
+				wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE');
1832
+				wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE);
1833
+				return true;
1834
+				break;
2282 1835
 
2283
-                    foreach ($set_details_id_postion_order as $pos => $attr_id) {
2284
-                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d'));
2285
-                    }
2286
-                }
2287
-
2288
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s'));
2289
-
2290
-                return true;
2291
-                break;
2292
-
2293
-            case 66:
2294
-                $price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2295
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2296
-                    'is_visible_in_front' => 'no',
2297
-                    'is_visible_in_front_listing' => 'yes',
2298
-                    'is_global' => 'no',
2299
-                    'is_user_defined' => 'no',
2300
-                    'is_required' => 'no',
2301
-                    'is_visible_in_advanced_search' => 'no',
2302
-                    'is_searchable' => 'no',
2303
-                    'is_filterable' => 'no',
2304
-                    'is_comparable' => 'no',
2305
-                    'is_html_allowed_on_front' => 'no',
2306
-                    'is_unique' => 'no',
2307
-                    'is_filterable_in_search' => 'no',
2308
-                    'is_used_for_sort_by' => 'no',
2309
-                    'is_configurable' => 'no',
2310
-                    'is_requiring_unit' => 'no',
2311
-                    'is_recordable_in_cart_meta' => 'no',
2312
-                    'is_used_in_admin_listing_column' => 'no',
2313
-                    'is_used_in_quick_add_form' => 'no',
2314
-                    'is_used_for_variation' => 'no',
2315
-                    'is_used_in_variation' => 'yes',
2316
-                    '_display_informations_about_value' => 'no',
2317
-                    '_need_verification' => 'no',
2318
-                    '_unit_group_id' => null,
2319
-                    '_default_unit' => null,
2320
-                    'is_historisable' => 'yes',
2321
-                    'is_intrinsic' => 'no',
2322
-                    'data_type_to_use' => 'custom',
2323
-                    'use_ajax_for_filling_field' => 'no',
2324
-                    'data_type' => 'integer',
2325
-                    'backend_table' => null,
2326
-                    'backend_label' => null,
2327
-                    'backend_input' => 'select',
2328
-                    'frontend_label' => 'price_behaviour',
2329
-                    'frontend_input' => 'select',
2330
-                    'frontend_verification' => null,
2331
-                    'code' => 'price_behaviour',
2332
-                    'note' => '',
2333
-                    'default_value' => '',
2334
-                    'frontend_css_class' => 'price_behaviour',
2335
-                    'backend_css_class' => null,
2336
-                    'frontend_help_message' => null,
2337
-                    'entity_id' => $price_behaviour_entity_id,
2338
-                ));
2339
-                $price_behaviour = $wpdb->insert_id;
2340
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2341
-                    'status' => 'valid',
2342
-                    'attribute_id' => $price_behaviour,
2343
-                    'creation_date' => current_time('mysql'),
2344
-                    'value' => '+',
2345
-                    'label' => '+',
2346
-                ));
2347
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2348
-                    'status' => 'valid',
2349
-                    'attribute_id' => $price_behaviour,
2350
-                    'creation_date' => current_time('mysql'),
2351
-                    'value' => '=',
2352
-                    'label' => '=',
2353
-                ));
2354
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default');
2355
-                $price_behaviour_section_id = $wpdb->get_var($query);
2356
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices');
2357
-                $price_behaviour_section_detail_id = $wpdb->get_var($query);
2358
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array(
2359
-                    'status' => 'deleted',
2360
-                    'creation_date' => current_time('mysql', 0),
2361
-                    'entity_type_id' => $price_behaviour_entity_id,
2362
-                    'attribute_set_id' => $price_behaviour_section_id,
2363
-                    'attribute_group_id' => $price_behaviour_section_detail_id,
2364
-                    'attribute_id' => $price_behaviour,
2365
-                    'position' => 0,
2366
-                ));
2367
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_'));
2368
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva'));
2369
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht'));
2370
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock'));
2371
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight'));
2372
-                return true;
2373
-                break;
2374
-
2375
-            case 67:
2376
-                $admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2377
-                if (empty($admin_new_version_message)) {
2378
-                    wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2379
-                }
2380
-                $wpshop_cart_option = get_option('wpshop_cart_option');
2381
-                if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) {
2382
-                    $wpshop_cart_option['total_nb_of_item_allowed'][0] = (int) filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN);
2383
-                }
2384
-                update_option('wpshop_cart_option', $wpshop_cart_option);
2385
-                return true;
2386
-                break;
1836
+			case '47':
1837
+				wps_payment_mode::migrate_payment_modes();
1838
+				return true;
1839
+				break;
1840
+
1841
+			case '48':
1842
+				@ini_set('max_execution_time', '500');
1843
+
1844
+				$count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1845
+				$output_type_option = get_option('wpshop_display_option');
1846
+				$output_type = $output_type_option['wpshop_display_list_type'];
1847
+
1848
+				for ($i = 0; $i <= $count_products->publish; $i += 20) {
1849
+					$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
1850
+					$products = $wpdb->get_results($query);
1851
+					if (!empty($products)) {
1852
+						foreach ($products as $product) {
1853
+							$p = wpshop_products::get_product_data($product->ID);
1854
+							$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
1855
+							update_post_meta($product->ID, '_wps_price_infos', $price);
1856
+						}
1857
+					}
1858
+				}
1859
+
1860
+				return true;
1861
+				break;
1862
+
1863
+			case '49':
1864
+				update_option('wpshop_send_invoice', true);
1865
+				return true;
1866
+				break;
1867
+
1868
+			case '50':
1869
+				$price_display_option = get_option('wpshop_catalog_product_option');
1870
+				$price_display_option['price_display']['text_from'] = 'on';
1871
+				$price_display_option['price_display']['lower_price'] = 'on';
1872
+				update_option('wpshop_catalog_product_option', $price_display_option);
1873
+
1874
+				self::wpshop_insert_default_pages();
1875
+
1876
+				return true;
1877
+				break;
1878
+
1879
+			case '51':
1880
+				/**    Insert new message for direct payment link    */
1881
+				$direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1882
+				if (empty($direct_payment_link_message)) {
1883
+					wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1884
+				}
1885
+				return true;
1886
+				break;
1887
+
1888
+			case '52':
1889
+				$account_page_option = get_option('wpshop_myaccount_page_id');
1890
+				if (!empty($account_page_option)) {
1891
+					$page_account = get_post($account_page_option);
1892
+					$page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]';
1893
+					wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content));
1894
+				}
1895
+				return true;
1896
+				break;
1897
+
1898
+			case '53':
1899
+				$payment_modes_option = get_option('wps_payment_mode');
1900
+				if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) {
1901
+					$payment_modes_option['mode']['cash_on_delivery'] = array(
1902
+						'name' => __('Cash on delivery', 'wpshop'),
1903
+						'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png',
1904
+						'description' => __('Pay your order on delivery', 'wpshop'));
1905
+
1906
+					update_option('wps_payment_mode', $payment_modes_option);
1907
+				}
1908
+
1909
+				// Mass action on products to add a flag on variation definition
1910
+				$products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1911
+				if (!empty($products)) {
1912
+					foreach ($products as $p) {
1913
+						$post_id = $p->ID;
1914
+						$check_product_have_variations = wpshop_products::get_variation($post_id);
1915
+						if (!empty($check_product_have_variations)) {
1916
+							$variation_flag = wpshop_products::check_variation_type($post_id);
1917
+							$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1918
+							$variation_defining['variation_type'] = $variation_flag;
1919
+							update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1920
+						}
1921
+					}
1922
+				}
1923
+				return true;
1924
+				break;
1925
+
1926
+			case '54':
1927
+				// Change shortcode of sign up page
1928
+				$signup_page_id = get_option('wpshop_signup_page_id');
1929
+				if (!empty($signup_page_id)) {
1930
+					$signup_page = get_post($signup_page_id);
1931
+					$signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]';
1932
+					wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content));
1933
+				}
1934
+
1935
+				// Change Terms of sale default content
1936
+				$terms_page_id = get_option('wpshop_terms_of_sale_page_id');
1937
+				if (!empty($terms_page_id)) {
1938
+					$terms_sale_page = get_post($terms_page_id);
1939
+					if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') {
1940
+						$data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>';
1941
+						$data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>';
1942
+						$data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1943
+						$data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>';
1944
+						$data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1945
+						$data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>';
1946
+						$data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1947
+						$data .= '<h3>' . __('Credits', 'wpshop') . '</h3>';
1948
+						$data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name'));
1949
+						wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data));
1950
+					}
1951
+				}
1952
+
1953
+				return true;
1954
+				break;
1955
+
1956
+			case '55':
1957
+				$checkout_page_id = get_option('wpshop_checkout_page_id');
1958
+				$checkout_page = get_post($checkout_page_id);
1959
+				$checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]';
1960
+				wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content));
1961
+
1962
+				// Update cart page id
1963
+				update_option('wpshop_cart_page_id', $checkout_page_id);
1964
+				return true;
1965
+				break;
1966
+
1967
+			case '56':
1968
+				$wps_entities = new wpshop_entities();
1969
+				$customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1970
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id);
1971
+				$set = $wpdb->get_row($query);
1972
+				if (!empty($set)) {
1973
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET,
1974
+						array('default_set' => 'yes'),
1975
+						array('id' => $set->id));
1976
+				}
1977
+				// Update Opinions activation option
1978
+				update_option('wps_opinion', array('active' => 'on'));
1979
+				return true;
1980
+				break;
1981
+
1982
+			case '57':
1983
+				$wpshop_cart_option = get_option('wpshop_cart_option');
1984
+				$wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes';
1985
+				$wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes';
1986
+
1987
+				update_option('wpshop_cart_option', $wpshop_cart_option);
1988
+				return true;
1989
+				break;
1990
+
1991
+			case '58':
1992
+				/** Turn customers publish into draft **/
1993
+				$query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1994
+				$wpdb->query($query);
1995
+
1996
+				$attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
1997
+				/** Check if the 0% VAT Rate is not already created **/
1998
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0');
1999
+				$exist_vat_rate = $wpdb->get_results($query);
2000
+
2001
+				if (empty($exist_vat_rate)) {
2002
+					/** Get Max Position **/
2003
+					$query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
2004
+					$max_position = $wpdb->get_var($query);
2005
+
2006
+					if (!empty($attribute_def) && !empty($attribute_def->id)) {
2007
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0'));
2008
+					}
2009
+				}
2010
+				return true;
2011
+				break;
2012
+
2013
+			case '59':
2014
+				/** Move old images gallery to the new gallery, and remove old links **/
2015
+				$allowed = get_allowed_mime_types();
2016
+				$args = array(
2017
+					'posts_per_page' => -1,
2018
+					'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
2019
+					'post_status' => array('publish', 'draft', 'trash'),
2020
+				);
2021
+				$posts = get_posts($args);
2022
+				$result = array();
2023
+				foreach ($posts as $post) {
2024
+					$array = array();
2025
+					$array['Post'] = $post;
2026
+					$array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true);
2027
+					$array['Attachments'] = get_attached_media($allowed, $post->ID);
2028
+					$array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true);
2029
+					if (!empty($array['TrueAttachmentsString'])) {
2030
+						$TrueAttachments_id = explode(',', $array['TrueAttachmentsString']);
2031
+					}
2032
+					$array['OldAttachmentsString'] = '';
2033
+					foreach ($array['Attachments'] as $attachment) {
2034
+						$filename = basename(get_attached_file($attachment->ID));
2035
+						$pos_ext = strrpos($filename, '.');
2036
+						$filename_no_ext = substr($filename, 0, $pos_ext);
2037
+						if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) {
2038
+							$array['OldAttachmentsString'] .= $attachment->ID . ',';
2039
+						}
2040
+					}
2041
+					unset($TrueAttachments_id);
2042
+					$result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString'];
2043
+					update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]);
2044
+				}
2045
+				return true;
2046
+				break;
2047
+
2048
+			case '60':
2049
+				/* Create default emails */
2050
+				wps_message_ctr::create_default_message();
2051
+
2052
+				/** Update entries for quick add */
2053
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"');
2054
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"');
2055
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"');
2056
+				switch (WPSHOP_PRODUCT_PRICE_PILOT) {
2057
+					case 'HT':
2058
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"');
2059
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"');
2060
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"');
2061
+						break;
2062
+					default:
2063
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"');
2064
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"');
2065
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"');
2066
+						break;
2067
+				}
2068
+
2069
+				/* Default country with WP language */
2070
+				$wpshop_country_default_choice_option = get_option('wpshop_country_default_choice');
2071
+				if (empty($wpshop_country_default_choice_option)) {
2072
+					update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3));
2073
+				}
2074
+				return true;
2075
+				break;
2076
+
2077
+			case '61':
2078
+				/** Import the xml for guided tour */
2079
+				wpsBubble_ctr::import_xml();
2080
+
2081
+				/* Hide admin bar */
2082
+				$wpshop_display_option = get_option('wpshop_display_option');
2083
+				if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) {
2084
+					$wpshop_display_option['wpshop_hide_admin_bar'] = 'on';
2085
+					update_option('wpshop_display_option', $wpshop_display_option);
2086
+				}
2087
+
2088
+				return true;
2089
+				break;
2090
+
2091
+			case '62':
2092
+				/** Install user default for POS */
2093
+				wps_pos_addon::action_to_do_on_activation();
2094
+
2095
+				return true;
2096
+				break;
2097
+
2098
+			case '63':
2099
+				$data = get_option('wps_shipping_mode');
2100
+				if (empty($data['modes']['default_shipping_mode_for_pos'])) {
2101
+					$data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop');
2102
+					$data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop');
2103
+					update_option('wps_shipping_mode', $data);
2104
+				}
2105
+				return true;
2106
+				break;
2107
+
2108
+			case '64':
2109
+				$options = get_option('wpshop_catalog_product_option');
2110
+				if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
2111
+					unset($options['wpshop_catalog_product_slug_with_category']);
2112
+					update_option('wpshop_catalog_product_option', $options);
2113
+				}
2114
+				return true;
2115
+				break;
2116
+
2117
+			case '65':
2118
+				$entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
2119
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id);
2120
+				$company_id = $wpdb->get_var($query);
2121
+				if (!isset($company_id)) {
2122
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2123
+						'is_visible_in_front' => 'no',
2124
+						'is_visible_in_front_listing' => 'yes',
2125
+						'is_global' => 'no',
2126
+						'is_user_defined' => 'no',
2127
+						'is_required' => 'no',
2128
+						'is_visible_in_advanced_search' => 'no',
2129
+						'is_searchable' => 'no',
2130
+						'is_filterable' => 'no',
2131
+						'is_comparable' => 'no',
2132
+						'is_html_allowed_on_front' => 'no',
2133
+						'is_unique' => 'no',
2134
+						'is_filterable_in_search' => 'no',
2135
+						'is_used_for_sort_by' => 'no',
2136
+						'is_configurable' => 'no',
2137
+						'is_requiring_unit' => 'no',
2138
+						'is_recordable_in_cart_meta' => 'no',
2139
+						'is_used_in_admin_listing_column' => 'no',
2140
+						'is_used_in_quick_add_form' => 'no',
2141
+						'is_used_for_variation' => 'no',
2142
+						'is_used_in_variation' => 'no',
2143
+						'_display_informations_about_value' => 'no',
2144
+						'_need_verification' => 'no',
2145
+						'_unit_group_id' => null,
2146
+						'_default_unit' => null,
2147
+						'is_historisable' => 'yes',
2148
+						'is_intrinsic' => 'no',
2149
+						'data_type_to_use' => 'custom',
2150
+						'use_ajax_for_filling_field' => 'no',
2151
+						'data_type' => 'varchar',
2152
+						'backend_table' => null,
2153
+						'backend_label' => 'Company',
2154
+						'backend_input' => 'text',
2155
+						'frontend_label' => 'Company',
2156
+						'frontend_input' => 'text',
2157
+						'frontend_verification' => null,
2158
+						'code' => 'company_customer',
2159
+						'note' => '',
2160
+						'default_value' => '',
2161
+						'frontend_css_class' => 'company_customer',
2162
+						'backend_css_class' => null,
2163
+						'frontend_help_message' => null,
2164
+						'entity_id' => $entity_id,
2165
+					));
2166
+					$company_id = $wpdb->insert_id;
2167
+				}
2168
+
2169
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id);
2170
+				$is_provider_id = $wpdb->get_var($query);
2171
+				if (!isset($is_provider_id)) {
2172
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2173
+						'is_visible_in_front' => 'no',
2174
+						'is_visible_in_front_listing' => 'yes',
2175
+						'is_global' => 'no',
2176
+						'is_user_defined' => 'no',
2177
+						'is_required' => 'yes',
2178
+						'is_visible_in_advanced_search' => 'no',
2179
+						'is_searchable' => 'no',
2180
+						'is_filterable' => 'no',
2181
+						'is_comparable' => 'no',
2182
+						'is_html_allowed_on_front' => 'no',
2183
+						'is_unique' => 'no',
2184
+						'is_filterable_in_search' => 'no',
2185
+						'is_used_for_sort_by' => 'no',
2186
+						'is_configurable' => 'no',
2187
+						'is_requiring_unit' => 'no',
2188
+						'is_recordable_in_cart_meta' => 'no',
2189
+						'is_used_in_admin_listing_column' => 'no',
2190
+						'is_used_in_quick_add_form' => 'no',
2191
+						'is_used_for_variation' => 'no',
2192
+						'is_used_in_variation' => 'no',
2193
+						'_display_informations_about_value' => 'no',
2194
+						'_need_verification' => 'no',
2195
+						'_unit_group_id' => null,
2196
+						'_default_unit' => null,
2197
+						'is_historisable' => 'yes',
2198
+						'is_intrinsic' => 'no',
2199
+						'data_type_to_use' => 'custom',
2200
+						'use_ajax_for_filling_field' => 'no',
2201
+						'data_type' => 'integer',
2202
+						'backend_table' => null,
2203
+						'backend_label' => 'Provider',
2204
+						'backend_input' => 'select',
2205
+						'frontend_label' => 'Provider',
2206
+						'frontend_input' => 'select',
2207
+						'frontend_verification' => null,
2208
+						'code' => 'is_provider',
2209
+						'note' => '',
2210
+						'default_value' => 'no',
2211
+						'frontend_css_class' => 'is_provider',
2212
+						'backend_css_class' => null,
2213
+						'frontend_help_message' => null,
2214
+						'entity_id' => $entity_id,
2215
+					));
2216
+					$is_provider_id = $wpdb->insert_id;
2217
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2218
+						'status' => 'valid',
2219
+						'attribute_id' => $is_provider_id,
2220
+						'creation_date_value' => current_time('mysql'),
2221
+						'value' => 'yes',
2222
+						'label' => 'Yes',
2223
+					));
2224
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2225
+						'status' => 'valid',
2226
+						'attribute_id' => $is_provider_id,
2227
+						'creation_date_value' => current_time('mysql'),
2228
+						'value' => 'no',
2229
+						'label' => 'No',
2230
+					));
2231
+					$default_value = $wpdb->insert_id;
2232
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id));
2233
+				}
2234
+
2235
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id);
2236
+				$company_section_detail_id = $wpdb->get_var($query);
2237
+
2238
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id);
2239
+				$is_provider_section_detail_id = $wpdb->get_var($query);
2240
+
2241
+				if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) {
2242
+					$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
2243
+					$attribute_set_id = $wpdb->get_var($query);
2244
+
2245
+					$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account');
2246
+					$attribute_set_section_id = $wpdb->get_var($query);
2247
+
2248
+					$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id);
2249
+					$attributes_set_details = $wpdb->get_results($query);
2250
+					$set_details_id_postion_order = array();
2251
+					foreach ($attributes_set_details as $attribute_set_detail) {
2252
+						$query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id);
2253
+						$attribute_set_detail_code = $wpdb->get_var($query);
2254
+						if ($attribute_set_detail_code == 'last_name') {
2255
+							$set_details_id_postion_order[1] = $attribute_set_detail->attribute_id;
2256
+						}
2257
+						if ($attribute_set_detail_code == 'first_name') {
2258
+							$set_details_id_postion_order[2] = $attribute_set_detail->attribute_id;
2259
+						}
2260
+						if ($attribute_set_detail_code == 'user_email') {
2261
+							$set_details_id_postion_order[3] = $attribute_set_detail->attribute_id;
2262
+						}
2263
+						if ($attribute_set_detail_code == 'user_pass') {
2264
+							$set_details_id_postion_order[4] = $attribute_set_detail->attribute_id;
2265
+						}
2266
+					}
2267
+					$max_position = count($set_details_id_postion_order);
2268
+
2269
+					if (!isset($company_section_detail_id)) {
2270
+						$max_position = $max_position + 1;
2271
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position));
2272
+						$set_details_id_postion_order[$max_position] = $company_id;
2273
+						$company_section_detail_id = $wpdb->insert_id;
2274
+					}
2275
+
2276
+					if (!isset($is_provider_section_detail_id)) {
2277
+						$max_position = $max_position + 1;
2278
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position));
2279
+						$set_details_id_postion_order[$max_position] = $is_provider_id;
2280
+						$is_provider_section_detail_id = $wpdb->insert_id;
2281
+					}
2282
+
2283
+					foreach ($set_details_id_postion_order as $pos => $attr_id) {
2284
+						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d'));
2285
+					}
2286
+				}
2287
+
2288
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s'));
2289
+
2290
+				return true;
2291
+				break;
2292
+
2293
+			case 66:
2294
+				$price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2295
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2296
+					'is_visible_in_front' => 'no',
2297
+					'is_visible_in_front_listing' => 'yes',
2298
+					'is_global' => 'no',
2299
+					'is_user_defined' => 'no',
2300
+					'is_required' => 'no',
2301
+					'is_visible_in_advanced_search' => 'no',
2302
+					'is_searchable' => 'no',
2303
+					'is_filterable' => 'no',
2304
+					'is_comparable' => 'no',
2305
+					'is_html_allowed_on_front' => 'no',
2306
+					'is_unique' => 'no',
2307
+					'is_filterable_in_search' => 'no',
2308
+					'is_used_for_sort_by' => 'no',
2309
+					'is_configurable' => 'no',
2310
+					'is_requiring_unit' => 'no',
2311
+					'is_recordable_in_cart_meta' => 'no',
2312
+					'is_used_in_admin_listing_column' => 'no',
2313
+					'is_used_in_quick_add_form' => 'no',
2314
+					'is_used_for_variation' => 'no',
2315
+					'is_used_in_variation' => 'yes',
2316
+					'_display_informations_about_value' => 'no',
2317
+					'_need_verification' => 'no',
2318
+					'_unit_group_id' => null,
2319
+					'_default_unit' => null,
2320
+					'is_historisable' => 'yes',
2321
+					'is_intrinsic' => 'no',
2322
+					'data_type_to_use' => 'custom',
2323
+					'use_ajax_for_filling_field' => 'no',
2324
+					'data_type' => 'integer',
2325
+					'backend_table' => null,
2326
+					'backend_label' => null,
2327
+					'backend_input' => 'select',
2328
+					'frontend_label' => 'price_behaviour',
2329
+					'frontend_input' => 'select',
2330
+					'frontend_verification' => null,
2331
+					'code' => 'price_behaviour',
2332
+					'note' => '',
2333
+					'default_value' => '',
2334
+					'frontend_css_class' => 'price_behaviour',
2335
+					'backend_css_class' => null,
2336
+					'frontend_help_message' => null,
2337
+					'entity_id' => $price_behaviour_entity_id,
2338
+				));
2339
+				$price_behaviour = $wpdb->insert_id;
2340
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2341
+					'status' => 'valid',
2342
+					'attribute_id' => $price_behaviour,
2343
+					'creation_date' => current_time('mysql'),
2344
+					'value' => '+',
2345
+					'label' => '+',
2346
+				));
2347
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2348
+					'status' => 'valid',
2349
+					'attribute_id' => $price_behaviour,
2350
+					'creation_date' => current_time('mysql'),
2351
+					'value' => '=',
2352
+					'label' => '=',
2353
+				));
2354
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default');
2355
+				$price_behaviour_section_id = $wpdb->get_var($query);
2356
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices');
2357
+				$price_behaviour_section_detail_id = $wpdb->get_var($query);
2358
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array(
2359
+					'status' => 'deleted',
2360
+					'creation_date' => current_time('mysql', 0),
2361
+					'entity_type_id' => $price_behaviour_entity_id,
2362
+					'attribute_set_id' => $price_behaviour_section_id,
2363
+					'attribute_group_id' => $price_behaviour_section_detail_id,
2364
+					'attribute_id' => $price_behaviour,
2365
+					'position' => 0,
2366
+				));
2367
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_'));
2368
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva'));
2369
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht'));
2370
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock'));
2371
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight'));
2372
+				return true;
2373
+				break;
2374
+
2375
+			case 67:
2376
+				$admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2377
+				if (empty($admin_new_version_message)) {
2378
+					wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2379
+				}
2380
+				$wpshop_cart_option = get_option('wpshop_cart_option');
2381
+				if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) {
2382
+					$wpshop_cart_option['total_nb_of_item_allowed'][0] = (int) filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN);
2383
+				}
2384
+				update_option('wpshop_cart_option', $wpshop_cart_option);
2385
+				return true;
2386
+				break;
2387 2387
 
2388 2388
 			case 68:
2389 2389
 				wps_message_ctr::create_default_message();
2390 2390
 				return true;
2391 2391
 				break;
2392 2392
 
2393
-            /*    Always add specific case before this bloc    */
2394
-            case 'dev':
2395
-
2396
-                //wp_cache_flush();
2397
-                // Newsletters options
2398
-                //$wp_rewrite->flush_rules();
2399
-                return true;
2400
-                break;
2401
-
2402
-            default:
2403
-                return true;
2404
-                break;
2405
-        }
2406
-    }
2407
-
2408
-    /**
2409
-     * Method called when deactivating the plugin
2410
-     * @see register_deactivation_hook()
2411
-     */
2412
-    public function uninstall_wpshop()
2413
-    {
2414
-        global $wpdb;
2415
-
2416
-        if (WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION && in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) {
2417
-            $query = $wpdb->query("DROP TABLE `wp_wpshop__attribute`, `wp_wpshop__attributes_unit`, `wp_wpshop__attributes_unit_groups`, `wp_wpshop__attribute_set`, `wp_wpshop__attribute_set_section`, `wp_wpshop__attribute_set_section_details`, `wp_wpshop__attribute_value_datetime`, `wp_wpshop__attribute_value_decimal`, `wp_wpshop__attribute_value_integer`, `wp_wpshop__attribute_value_text`, `wp_wpshop__attribute_value_varchar`, `wp_wpshop__attribute_value__histo`, `wp_wpshop__cart`, `wp_wpshop__cart_contents`, `wp_wpshop__documentation`, `wp_wpshop__entity`, `wp_wpshop__historique`, `wp_wpshop__message`, `wp_wpshop__attribute_value_options`;");
2418
-            $query = $wpdb->query("DELETE FROM " . $wpdb->options . " WHERE `option_name` LIKE '%wpshop%';");
2419
-
2420
-            $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE 'wpshop_%';");
2421
-            $list = '  ';
2422
-            foreach ($wpshop_products_posts as $post) {
2423
-                $list .= "'" . $post->ID . "', ";
2424
-            }
2425
-            $list = substr($list, 0, -2);
2426
-
2427
-            $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_parent IN (" . $list . ");");
2428
-            $list_attachment = '  ';
2429
-            foreach ($wpshop_products_posts as $post) {
2430
-                $list_attachment .= "'" . $post->ID . "', ";
2431
-            }
2432
-            $list_attachment = substr($list_attachment, 0, -2);
2433
-
2434
-            $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list . ");");
2435
-            $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list_attachment . ");");
2436
-            $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list . ");");
2437
-            $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list_attachment . ");");
2438
-            $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE post_content LIKE '%wpshop%';");
2439
-        }
2440
-
2441
-        /*    Unset administrator permission    */
2442
-        $adminRole = get_role('administrator');
2443
-        foreach ($adminRole->capabilities as $capabilityName => $capability) {
2444
-            if (substr($capabilityName, 0, 7) == 'wpshop_') {
2445
-                if ($adminRole->has_cap($capabilityName)) {
2446
-                    $adminRole->remove_cap($capabilityName);
2447
-                }
2448
-            }
2449
-        }
2450
-    }
2393
+			/*    Always add specific case before this bloc    */
2394
+			case 'dev':
2395
+
2396
+				//wp_cache_flush();
2397
+				// Newsletters options
2398
+				//$wp_rewrite->flush_rules();
2399
+				return true;
2400
+				break;
2401
+
2402
+			default:
2403
+				return true;
2404
+				break;
2405
+		}
2406
+	}
2407
+
2408
+	/**
2409
+	 * Method called when deactivating the plugin
2410
+	 * @see register_deactivation_hook()
2411
+	 */
2412
+	public function uninstall_wpshop()
2413
+	{
2414
+		global $wpdb;
2415
+
2416
+		if (WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION && in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) {
2417
+			$query = $wpdb->query("DROP TABLE `wp_wpshop__attribute`, `wp_wpshop__attributes_unit`, `wp_wpshop__attributes_unit_groups`, `wp_wpshop__attribute_set`, `wp_wpshop__attribute_set_section`, `wp_wpshop__attribute_set_section_details`, `wp_wpshop__attribute_value_datetime`, `wp_wpshop__attribute_value_decimal`, `wp_wpshop__attribute_value_integer`, `wp_wpshop__attribute_value_text`, `wp_wpshop__attribute_value_varchar`, `wp_wpshop__attribute_value__histo`, `wp_wpshop__cart`, `wp_wpshop__cart_contents`, `wp_wpshop__documentation`, `wp_wpshop__entity`, `wp_wpshop__historique`, `wp_wpshop__message`, `wp_wpshop__attribute_value_options`;");
2418
+			$query = $wpdb->query("DELETE FROM " . $wpdb->options . " WHERE `option_name` LIKE '%wpshop%';");
2419
+
2420
+			$wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE 'wpshop_%';");
2421
+			$list = '  ';
2422
+			foreach ($wpshop_products_posts as $post) {
2423
+				$list .= "'" . $post->ID . "', ";
2424
+			}
2425
+			$list = substr($list, 0, -2);
2426
+
2427
+			$wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_parent IN (" . $list . ");");
2428
+			$list_attachment = '  ';
2429
+			foreach ($wpshop_products_posts as $post) {
2430
+				$list_attachment .= "'" . $post->ID . "', ";
2431
+			}
2432
+			$list_attachment = substr($list_attachment, 0, -2);
2433
+
2434
+			$query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list . ");");
2435
+			$query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list_attachment . ");");
2436
+			$query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list . ");");
2437
+			$query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list_attachment . ");");
2438
+			$query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE post_content LIKE '%wpshop%';");
2439
+		}
2440
+
2441
+		/*    Unset administrator permission    */
2442
+		$adminRole = get_role('administrator');
2443
+		foreach ($adminRole->capabilities as $capabilityName => $capability) {
2444
+			if (substr($capabilityName, 0, 7) == 'wpshop_') {
2445
+				if ($adminRole->has_cap($capabilityName)) {
2446
+					$adminRole->remove_cap($capabilityName);
2447
+				}
2448
+			}
2449
+		}
2450
+	}
2451 2451
 
2452 2452
 }
Please login to merge, or discard this patch.
includes/librairies/db/db_structure_definition.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 /**
@@ -525,11 +525,11 @@  discard block
 block discarded – undo
525 525
 	$wpshop_db_table_operation_list[$wpshop_db_version]['FIELD_ADD'][WPSHOP_DBT_ATTRIBUTE_GROUP] = array('backend_display_type');
526 526
 
527 527
 	$wpshop_db_table_list[$wpshop_db_version] = array(WPSHOP_DBT_ATTRIBUTE, WPSHOP_DBT_ATTRIBUTE_GROUP);
528
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME." DROP INDEX entity_attribute_id";
529
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL." DROP INDEX entity_attribute_id";
530
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT." DROP INDEX entity_attribute_id";
531
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER." DROP INDEX entity_attribute_id";
532
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR." DROP INDEX entity_attribute_id";
528
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME . " DROP INDEX entity_attribute_id";
529
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " DROP INDEX entity_attribute_id";
530
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT . " DROP INDEX entity_attribute_id";
531
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . " DROP INDEX entity_attribute_id";
532
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " DROP INDEX entity_attribute_id";
533 533
 }
534 534
 
535 535
 {/*	Version 17  - 1.3.1.3	*/
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 
562 562
 	$wpshop_db_table_list[$wpshop_db_version] = array(WPSHOP_DBT_ATTRIBUTE, WPSHOP_DBT_ATTRIBUTE_GROUP);
563 563
 
564
-	$wpshop_db_request[$wpshop_db_version][] = "UPDATE ".WPSHOP_DBT_ATTRIBUTE." SET backend_input=frontend_input WHERE frontend_input!='text'";
564
+	$wpshop_db_request[$wpshop_db_version][] = "UPDATE " . WPSHOP_DBT_ATTRIBUTE . " SET backend_input=frontend_input WHERE frontend_input!='text'";
565 565
 }
566 566
 
567 567
 {/*	Version 21  - 1.3.2.0	*/
@@ -791,11 +791,11 @@  discard block
 block discarded – undo
791 791
 }
792 792
 {/*	Version 67  - 1.4.3.8	*/
793 793
 $wpshop_db_version = 67;
794
-$wpshop_update_way[ $wpshop_db_version ] = 'data';
794
+$wpshop_update_way[$wpshop_db_version] = 'data';
795 795
 }
796 796
 {/*	Version 68  - 1.4.3.9	*/
797 797
 $wpshop_db_version = 68;
798
-$wpshop_update_way[ $wpshop_db_version ] = 'data';
798
+$wpshop_update_way[$wpshop_db_version] = 'data';
799 799
 }
800 800
 {/*	Version dev	- Call for every plugin db version	*/
801 801
 	$wpshop_db_version = 'dev';
Please login to merge, or discard this patch.