Completed
Push — master ( 5987fc...959a28 )
by
unknown
13:59
created
controller/wps_product_variation_interface.ctr.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -52,19 +52,19 @@
 block discarded – undo
52 52
 	 * @return boolean          Actual state of module.
53 53
 	 */
54 54
 	public function is_activate( $new_val = null ) {
55
-	    if ( ! isset( $this->is_active ) ) {
56
-	        $option = get_option( 'wps_variation_interface_display', null );
57
-	        if ( is_null( $option ) ) {
58
-	            $new_val = true;
59
-	            $option = false;
60
-	        }
61
-	        $this->is_active = (bool) $option;
62
-	    }
63
-	    if ( isset( $new_val ) && $this->is_active !== $new_val ) {
64
-	        update_option( 'wps_variation_interface_display', $new_val );
65
-	        $this->is_active = $new_val;
66
-	    }
67
-	    return $this->is_active;
55
+		if ( ! isset( $this->is_active ) ) {
56
+			$option = get_option( 'wps_variation_interface_display', null );
57
+			if ( is_null( $option ) ) {
58
+				$new_val = true;
59
+				$option = false;
60
+			}
61
+			$this->is_active = (bool) $option;
62
+		}
63
+		if ( isset( $new_val ) && $this->is_active !== $new_val ) {
64
+			update_option( 'wps_variation_interface_display', $new_val );
65
+			$this->is_active = $new_val;
66
+		}
67
+		return $this->is_active;
68 68
 	}
69 69
 	/**
70 70
 	 * Get variations of an element.
Please login to merge, or discard this patch.
includes/modules/wps_customer/controller/wps_customer_ctr.php 1 patch
Indentation   +727 added lines, -727 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('ABSPATH')) {
2
-    exit;
2
+	exit;
3 3
 }
4 4
 
5 5
 /**
@@ -12,548 +12,548 @@  discard block
 block discarded – undo
12 12
 
13 13
 	public static $customer_user_identifier_cache = array();
14 14
 
15
-    public function __construct()
16
-    {
17
-        /**    Create customer entity type on wordpress initilisation*/
18
-        add_action('init', array($this, 'create_customer_entity'));
19
-
20
-        /**    Call style for administration    */
21
-        add_action('admin_enqueue_scripts', array(&$this, 'admin_css'));
22
-
23
-        add_action('admin_init', array($this, 'customer_action_on_plugin_init'));
24
-        add_action('admin_init', array($this, 'redirect_new_user'));
25
-        add_action('admin_menu', array($this, 'customer_action_on_menu'));
26
-
27
-        /**    When a wordpress user is created, create a customer (post type)    */
28
-        add_action('user_register', array($this, 'create_entity_customer_when_user_is_created'));
29
-        add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update'));
30
-
31
-        /** When save customer update */
32
-        add_action('save_post', array($this, 'save_entity_customer'), 10, 2);
33
-        //add_action( 'admin_notices', array( $this, 'notice_save_post_customer_informations' ) );
34
-
35
-        /**    Add filters for customer list    */
36
-        add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions'));
37
-        add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header'));
38
-        add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2);
39
-        add_action('restrict_manage_posts', array(&$this, 'list_table_filters'));
40
-        add_filter('parse_query', array(&$this, 'list_table_filter_parse_query'));
41
-
42
-        /**    Filter search for customers    */
43
-        //add_filter( 'pre_get_posts', array( $this, 'customer_search' ) );
44
-
45
-        /** Customer options for the shop */
46
-        add_action('wsphop_options', array(&$this, 'declare_options'), 8);
47
-    }
48
-
49
-    /**
50
-     * Customer options for the shop
51
-     */
52
-    public static function declare_options()
53
-    {
54
-        if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
55
-            $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
56
-            $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
57
-
58
-            if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
59
-                && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
60
-                /**    Add module option to wpshop general options    */
61
-                register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters'));
62
-                add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info');
63
-
64
-            }
65
-        }
66
-    }
67
-
68
-    /**
69
-     * Validate Options Customer
70
-     * @param unknown_type $input
71
-     * @return unknown
72
-     */
73
-    public static function wpshop_options_validate_customers_newsleters($input)
74
-    {
75
-        return $input;
76
-    }
77
-
78
-    public static function display_newsletters_subscriptions()
79
-    {
80
-        $cart_option = get_option('wpshop_cart_option', array());
81
-        $output = '';
82
-
83
-        $input_def = array();
84
-        $input_def['name'] = '';
85
-        $input_def['id'] = 'wpshop_cart_option_display_newsletter_site_subscription';
86
-        $input_def['type'] = 'checkbox';
87
-        $input_def['valueToPut'] = 'index';
88
-        $input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no';
89
-        $input_def['possible_value'] = 'yes';
90
-        $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
91
-
92
-        $input_def = array();
93
-        $input_def['name'] = '';
94
-        $input_def['id'] = 'wpshop_cart_option_display_newsletter_partner_subscription';
95
-        $input_def['type'] = 'checkbox';
96
-        $input_def['valueToPut'] = 'index';
97
-        $input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no';
98
-        $input_def['possible_value'] = 'yes';
99
-        $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
100
-
101
-        echo $output;
102
-    }
103
-
104
-    /**
105
-     * Include stylesheets
106
-     */
107
-    public function admin_css()
108
-    {
109
-        wp_register_style('wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION);
110
-        wp_enqueue_style('wpshop-modules-customer-backend-styles');
111
-    }
112
-
113
-    /**
114
-     * Return a list  of users
115
-     * @param array $customer_list_params
116
-     * @param integer $selected_user
117
-     * @param boolean $multiple
118
-     * @param boolean $disabled
119
-     * @return string
120
-     */
121
-    public function custom_user_list($customer_list_params = array('name' => 'user[customer_id]', 'id' => 'user_customer_id'), $selected_user = "", $multiple = false, $disabled = false)
122
-    {
123
-        global $wpdb;
124
-        $content_output = '';
125
-
126
-        // USERS
127
-        $wps_customer_mdl = new wps_customer_mdl();
128
-        $users = $wps_customer_mdl->getUserList();
129
-        $select_users = '';
130
-        if (!empty($users)) {
131
-            foreach ($users as $user) {
132
-                if ($user->ID != 1) {
133
-                    $lastname = get_user_meta($user->ID, 'last_name', true);
134
-                    $firstname = get_user_meta($user->ID, 'first_name', true);
135
-                    $customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
136
-                    if (!empty($customer_entity_id)) {
137
-                        $company_attr = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %s AND code = %s AND status = %s', $customer_entity_id, 'company_customer', 'valid'));
138
-                        if (!empty($company_attr)) {
139
-                            $query = $wpdb->prepare('SELECT value  FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($company_attr->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $company_attr->id, wps_customer_ctr::get_customer_id_by_author_id($user->ID));
140
-                            $company_value = $wpdb->get_var($query);
141
-                        }
142
-                    }
143
-                    ob_start();?>
15
+	public function __construct()
16
+	{
17
+		/**    Create customer entity type on wordpress initilisation*/
18
+		add_action('init', array($this, 'create_customer_entity'));
19
+
20
+		/**    Call style for administration    */
21
+		add_action('admin_enqueue_scripts', array(&$this, 'admin_css'));
22
+
23
+		add_action('admin_init', array($this, 'customer_action_on_plugin_init'));
24
+		add_action('admin_init', array($this, 'redirect_new_user'));
25
+		add_action('admin_menu', array($this, 'customer_action_on_menu'));
26
+
27
+		/**    When a wordpress user is created, create a customer (post type)    */
28
+		add_action('user_register', array($this, 'create_entity_customer_when_user_is_created'));
29
+		add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update'));
30
+
31
+		/** When save customer update */
32
+		add_action('save_post', array($this, 'save_entity_customer'), 10, 2);
33
+		//add_action( 'admin_notices', array( $this, 'notice_save_post_customer_informations' ) );
34
+
35
+		/**    Add filters for customer list    */
36
+		add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions'));
37
+		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header'));
38
+		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2);
39
+		add_action('restrict_manage_posts', array(&$this, 'list_table_filters'));
40
+		add_filter('parse_query', array(&$this, 'list_table_filter_parse_query'));
41
+
42
+		/**    Filter search for customers    */
43
+		//add_filter( 'pre_get_posts', array( $this, 'customer_search' ) );
44
+
45
+		/** Customer options for the shop */
46
+		add_action('wsphop_options', array(&$this, 'declare_options'), 8);
47
+	}
48
+
49
+	/**
50
+	 * Customer options for the shop
51
+	 */
52
+	public static function declare_options()
53
+	{
54
+		if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
55
+			$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
56
+			$old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
57
+
58
+			if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
59
+				&& ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
60
+				/**    Add module option to wpshop general options    */
61
+				register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters'));
62
+				add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info');
63
+
64
+			}
65
+		}
66
+	}
67
+
68
+	/**
69
+	 * Validate Options Customer
70
+	 * @param unknown_type $input
71
+	 * @return unknown
72
+	 */
73
+	public static function wpshop_options_validate_customers_newsleters($input)
74
+	{
75
+		return $input;
76
+	}
77
+
78
+	public static function display_newsletters_subscriptions()
79
+	{
80
+		$cart_option = get_option('wpshop_cart_option', array());
81
+		$output = '';
82
+
83
+		$input_def = array();
84
+		$input_def['name'] = '';
85
+		$input_def['id'] = 'wpshop_cart_option_display_newsletter_site_subscription';
86
+		$input_def['type'] = 'checkbox';
87
+		$input_def['valueToPut'] = 'index';
88
+		$input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no';
89
+		$input_def['possible_value'] = 'yes';
90
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
91
+
92
+		$input_def = array();
93
+		$input_def['name'] = '';
94
+		$input_def['id'] = 'wpshop_cart_option_display_newsletter_partner_subscription';
95
+		$input_def['type'] = 'checkbox';
96
+		$input_def['valueToPut'] = 'index';
97
+		$input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no';
98
+		$input_def['possible_value'] = 'yes';
99
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
100
+
101
+		echo $output;
102
+	}
103
+
104
+	/**
105
+	 * Include stylesheets
106
+	 */
107
+	public function admin_css()
108
+	{
109
+		wp_register_style('wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION);
110
+		wp_enqueue_style('wpshop-modules-customer-backend-styles');
111
+	}
112
+
113
+	/**
114
+	 * Return a list  of users
115
+	 * @param array $customer_list_params
116
+	 * @param integer $selected_user
117
+	 * @param boolean $multiple
118
+	 * @param boolean $disabled
119
+	 * @return string
120
+	 */
121
+	public function custom_user_list($customer_list_params = array('name' => 'user[customer_id]', 'id' => 'user_customer_id'), $selected_user = "", $multiple = false, $disabled = false)
122
+	{
123
+		global $wpdb;
124
+		$content_output = '';
125
+
126
+		// USERS
127
+		$wps_customer_mdl = new wps_customer_mdl();
128
+		$users = $wps_customer_mdl->getUserList();
129
+		$select_users = '';
130
+		if (!empty($users)) {
131
+			foreach ($users as $user) {
132
+				if ($user->ID != 1) {
133
+					$lastname = get_user_meta($user->ID, 'last_name', true);
134
+					$firstname = get_user_meta($user->ID, 'first_name', true);
135
+					$customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
136
+					if (!empty($customer_entity_id)) {
137
+						$company_attr = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %s AND code = %s AND status = %s', $customer_entity_id, 'company_customer', 'valid'));
138
+						if (!empty($company_attr)) {
139
+							$query = $wpdb->prepare('SELECT value  FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($company_attr->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $company_attr->id, wps_customer_ctr::get_customer_id_by_author_id($user->ID));
140
+							$company_value = $wpdb->get_var($query);
141
+						}
142
+					}
143
+					ob_start();?>
144 144
 					<option value="<?php echo $user->ID; ?>" <?php echo ((!$multiple) && ($selected_user == $user->ID)) ? ' selected="selected"' : ''; ?>>
145 145
 						<?php echo $lastname; ?> <?php echo $firstname; ?> (<?php echo $user->user_email; ?>)<?php echo isset($company_value) ? ' : ' . $company_value : ''; ?>
146 146
 					</option>
147 147
 					<?php
148 148
 $select_users .= ob_get_clean();
149
-                }
150
-            }
151
-            $content_output = '
149
+				}
150
+			}
151
+			$content_output = '
152 152
 			<select name="' . $customer_list_params['name'] . '" id="' . $customer_list_params['id'] . '" data-placeholder="' . __('Choose a customer', 'wpshop') . '" class="chosen_select"' . ($multiple ? ' multiple="multiple" ' : '') . '' . ($disabled ? ' disabled="disabled" ' : '') . '>
153 153
 				<option value="0" ></option>
154 154
 				' . $select_users . '
155 155
 			</select>';
156
-        }
157
-        return $content_output;
158
-    }
159
-
160
-    /**
161
-     * Action on plug-on action
162
-     */
163
-    public static function customer_action_on_plugin_init()
164
-    {
165
-        return;
166
-    }
167
-
168
-    /**
169
-     * Create the customer entity
170
-     */
171
-    public function create_customer_entity()
172
-    {
173
-        global $wpdb;
174
-        $query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params');
175
-        $customer_entity_definition = $wpdb->get_row($query);
176
-        $current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null;
177
-
178
-        $post_type_params = array(
179
-            'labels' => array(
180
-                'name' => __('Customers', 'wpshop'),
181
-                'singular_name' => __('Customer', 'wpshop'),
182
-                'add_new_item' => __('New customer', 'wpshop'),
183
-                'add_new' => __('New customer', 'wpshop'),
184
-                'edit_item' => __('Edit customer', 'wpshop'),
185
-                'new_item' => __('New customer', 'wpshop'),
186
-                'view_item' => __('View customer', 'wpshop'),
187
-                'search_items' => __('Search in customers', 'wpshop'),
188
-                'not_found' => __('No customer found', 'wpshop'),
189
-                'not_found_in_trash' => __('No customer founded in trash', 'wpshop'),
190
-                'parent_item_colon' => '',
191
-            ),
192
-            'description' => '',
193
-            'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'),
194
-            'hierarchical' => false,
195
-            'public' => false,
196
-            'show_ui' => true,
197
-            'show_in_menu' => true, //'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
198
-            'show_in_nav_menus' => false,
199
-            'show_in_admin_bar' => false,
200
-            'can_export' => false,
201
-            'has_archive' => false,
202
-            'exclude_from_search' => true,
203
-            'publicly_queryable' => false,
204
-            'rewrite' => false,
205
-            'menu_icon' => 'dashicons-id-alt',
206
-            'capabilities' => array(
207
-                'create_posts' => 'wpshop_view_dashboard',
208
-                'edit_post' => 'wpshop_view_dashboard',
209
-                'edit_posts' => 'wpshop_view_dashboard',
210
-                'edit_others_posts' => 'wpshop_view_dashboard',
211
-                'publish_posts' => 'wpshop_view_dashboard',
212
-                'read_post' => 'wpshop_view_dashboard',
213
-                'read_private_posts' => 'wpshop_view_dashboard',
214
-                'delete_posts' => 'delete_product',
215
-            ),
216
-        );
217
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params);
218
-    }
219
-
220
-    /**
221
-     * Link for redirect new customer to new user
222
-     */
223
-    public static function customer_action_on_menu()
224
-    {
225
-        global $submenu;
226
-        //$submenu['edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS][10] = array( __( 'New customer', 'wpshop' ), 'create_users', admin_url( 'user-new.php?redirect_to=edit.php%3Fpost_type%3D' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) );
227
-    }
228
-
229
-    /**
230
-     * Redirect when create new customer in admin
231
-     */
232
-    public function redirect_new_user()
233
-    {
234
-        global $pagenow;
235
-
236
-        /* Check current admin page. */
237
-        if ($pagenow != 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
238
-            $redirect = $_SESSION['redirect_to_customer'];
239
-            unset($_SESSION['redirect_to_customer']);
240
-            if ($pagenow == 'users.php') {
241
-                wp_redirect(admin_url($redirect, 'http'));
242
-                exit;
243
-            }
244
-        }
245
-
246
-        /* Redirect to new user */
247
-        $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
248
-        if ($pagenow == 'post-new.php' && isset($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
249
-            $_SESSION['redirect_to_customer'] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
250
-            wp_redirect(admin_url('user-new.php', 'http'), 301);
251
-            exit;
252
-        }
253
-
254
-        /* Include JS on new user customer */
255
-        if ($pagenow == 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
256
-            add_action('admin_print_scripts', array($this, 'admin_user_customer_js'), 20);
257
-        }
258
-    }
259
-    /* JS to select customer in place of suscriber */
260
-    public function admin_user_customer_js()
261
-    {
262
-        echo "<script type='text/javascript'>\n";
263
-        echo "jQuery(document).ready(function($) {";
264
-        echo "\n$('#role').val('customer').change();";
265
-        echo "\n});\n</script>";
266
-    }
267
-
268
-    /**
269
-     * Create an entity of customer type when a new user is created
270
-     *
271
-     * @param integer $user_id
272
-     */
273
-    public static function create_entity_customer_when_user_is_created($user_id)
274
-    {
275
-        $user_data = get_userdata($user_id);
276
-        $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
277
-        $customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename));
278
-        self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
279
-
280
-        /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
281
-        $usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true);
282
-        if (!empty($usermeta) && is_array($usermeta)) {
283
-            $data_to_delete = array_search('add-wpshop_product_category', $usermeta);
284
-            if ($data_to_delete !== false) {
285
-                unset($usermeta[$data_to_delete]);
286
-                update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta);
287
-            }
288
-        }
289
-    }
290
-    private static function array_map_create_entity_customer_when_user_is_created($a)
291
-    {
292
-        return $a[0];
293
-    }
294
-
295
-    /**
296
-     * Update an entity of customer type when a user profile is update
297
-     *
298
-     * @param integer $user_id
299
-     */
300
-    public static function update_entity_customer_when_profile_user_is_update($user_id)
301
-    {
302
-        $user_data = get_userdata($user_id);
303
-        $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
304
-        $customer_post_ID = self::get_customer_id_by_author_id($user_id);
305
-        self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
306
-    }
307
-    private static function array_map_update_entity_customer_when_profile_user_is_update($a)
308
-    {
309
-        return $a[0];
310
-    }
311
-
312
-    /**
313
-     * Add metas in user when customer is modified
314
-     *
315
-     * @param integer $post_id
316
-     * @param WP_Post $post
317
-     */
318
-    public static function save_entity_customer($customer_post_ID, $post)
319
-    {
320
-        if (WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision($customer_post_ID)) {
321
-            return;
322
-        }
323
-        $user_id = $post->post_author;
324
-        $user_info = array();
325
-        $attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
326
-        if (!empty($attribute)) {
327
-            foreach ($attribute as $type => $attributes) {
328
-                foreach ($attributes as $meta => $attribute) {
329
-                    $user_info[$meta] = sanitize_text_field($attribute);
330
-                }
331
-            }
332
-        }
333
-        self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
334
-        /** Update newsletter user preferences **/
335
-        $newsletter_preferences = array();
336
-        $newsletter_site = !empty($_POST['newsletters_site']) ? sanitize_text_field($_POST['newsletters_site']) : '';
337
-        if (!empty($newsletter_site)) {
338
-            $newsletter_preferences['newsletters_site'] = 1;
339
-        }
340
-        $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? sanitize_text_field($_POST['newsletters_site_partners']) : '';
341
-        if (!empty($newsletters_site_partners)) {
342
-            $newsletter_preferences['newsletters_site_partners'] = 1;
343
-        }
344
-        update_user_meta($user_id, 'user_preferences', $newsletter_preferences);
345
-        return;
346
-    }
156
+		}
157
+		return $content_output;
158
+	}
159
+
160
+	/**
161
+	 * Action on plug-on action
162
+	 */
163
+	public static function customer_action_on_plugin_init()
164
+	{
165
+		return;
166
+	}
167
+
168
+	/**
169
+	 * Create the customer entity
170
+	 */
171
+	public function create_customer_entity()
172
+	{
173
+		global $wpdb;
174
+		$query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params');
175
+		$customer_entity_definition = $wpdb->get_row($query);
176
+		$current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null;
177
+
178
+		$post_type_params = array(
179
+			'labels' => array(
180
+				'name' => __('Customers', 'wpshop'),
181
+				'singular_name' => __('Customer', 'wpshop'),
182
+				'add_new_item' => __('New customer', 'wpshop'),
183
+				'add_new' => __('New customer', 'wpshop'),
184
+				'edit_item' => __('Edit customer', 'wpshop'),
185
+				'new_item' => __('New customer', 'wpshop'),
186
+				'view_item' => __('View customer', 'wpshop'),
187
+				'search_items' => __('Search in customers', 'wpshop'),
188
+				'not_found' => __('No customer found', 'wpshop'),
189
+				'not_found_in_trash' => __('No customer founded in trash', 'wpshop'),
190
+				'parent_item_colon' => '',
191
+			),
192
+			'description' => '',
193
+			'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'),
194
+			'hierarchical' => false,
195
+			'public' => false,
196
+			'show_ui' => true,
197
+			'show_in_menu' => true, //'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
198
+			'show_in_nav_menus' => false,
199
+			'show_in_admin_bar' => false,
200
+			'can_export' => false,
201
+			'has_archive' => false,
202
+			'exclude_from_search' => true,
203
+			'publicly_queryable' => false,
204
+			'rewrite' => false,
205
+			'menu_icon' => 'dashicons-id-alt',
206
+			'capabilities' => array(
207
+				'create_posts' => 'wpshop_view_dashboard',
208
+				'edit_post' => 'wpshop_view_dashboard',
209
+				'edit_posts' => 'wpshop_view_dashboard',
210
+				'edit_others_posts' => 'wpshop_view_dashboard',
211
+				'publish_posts' => 'wpshop_view_dashboard',
212
+				'read_post' => 'wpshop_view_dashboard',
213
+				'read_private_posts' => 'wpshop_view_dashboard',
214
+				'delete_posts' => 'delete_product',
215
+			),
216
+		);
217
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params);
218
+	}
219
+
220
+	/**
221
+	 * Link for redirect new customer to new user
222
+	 */
223
+	public static function customer_action_on_menu()
224
+	{
225
+		global $submenu;
226
+		//$submenu['edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS][10] = array( __( 'New customer', 'wpshop' ), 'create_users', admin_url( 'user-new.php?redirect_to=edit.php%3Fpost_type%3D' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) );
227
+	}
228
+
229
+	/**
230
+	 * Redirect when create new customer in admin
231
+	 */
232
+	public function redirect_new_user()
233
+	{
234
+		global $pagenow;
235
+
236
+		/* Check current admin page. */
237
+		if ($pagenow != 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
238
+			$redirect = $_SESSION['redirect_to_customer'];
239
+			unset($_SESSION['redirect_to_customer']);
240
+			if ($pagenow == 'users.php') {
241
+				wp_redirect(admin_url($redirect, 'http'));
242
+				exit;
243
+			}
244
+		}
245
+
246
+		/* Redirect to new user */
247
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
248
+		if ($pagenow == 'post-new.php' && isset($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
249
+			$_SESSION['redirect_to_customer'] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
250
+			wp_redirect(admin_url('user-new.php', 'http'), 301);
251
+			exit;
252
+		}
253
+
254
+		/* Include JS on new user customer */
255
+		if ($pagenow == 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
256
+			add_action('admin_print_scripts', array($this, 'admin_user_customer_js'), 20);
257
+		}
258
+	}
259
+	/* JS to select customer in place of suscriber */
260
+	public function admin_user_customer_js()
261
+	{
262
+		echo "<script type='text/javascript'>\n";
263
+		echo "jQuery(document).ready(function($) {";
264
+		echo "\n$('#role').val('customer').change();";
265
+		echo "\n});\n</script>";
266
+	}
267
+
268
+	/**
269
+	 * Create an entity of customer type when a new user is created
270
+	 *
271
+	 * @param integer $user_id
272
+	 */
273
+	public static function create_entity_customer_when_user_is_created($user_id)
274
+	{
275
+		$user_data = get_userdata($user_id);
276
+		$user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
277
+		$customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename));
278
+		self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
279
+
280
+		/** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
281
+		$usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true);
282
+		if (!empty($usermeta) && is_array($usermeta)) {
283
+			$data_to_delete = array_search('add-wpshop_product_category', $usermeta);
284
+			if ($data_to_delete !== false) {
285
+				unset($usermeta[$data_to_delete]);
286
+				update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta);
287
+			}
288
+		}
289
+	}
290
+	private static function array_map_create_entity_customer_when_user_is_created($a)
291
+	{
292
+		return $a[0];
293
+	}
294
+
295
+	/**
296
+	 * Update an entity of customer type when a user profile is update
297
+	 *
298
+	 * @param integer $user_id
299
+	 */
300
+	public static function update_entity_customer_when_profile_user_is_update($user_id)
301
+	{
302
+		$user_data = get_userdata($user_id);
303
+		$user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
304
+		$customer_post_ID = self::get_customer_id_by_author_id($user_id);
305
+		self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
306
+	}
307
+	private static function array_map_update_entity_customer_when_profile_user_is_update($a)
308
+	{
309
+		return $a[0];
310
+	}
311
+
312
+	/**
313
+	 * Add metas in user when customer is modified
314
+	 *
315
+	 * @param integer $post_id
316
+	 * @param WP_Post $post
317
+	 */
318
+	public static function save_entity_customer($customer_post_ID, $post)
319
+	{
320
+		if (WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision($customer_post_ID)) {
321
+			return;
322
+		}
323
+		$user_id = $post->post_author;
324
+		$user_info = array();
325
+		$attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
326
+		if (!empty($attribute)) {
327
+			foreach ($attribute as $type => $attributes) {
328
+				foreach ($attributes as $meta => $attribute) {
329
+					$user_info[$meta] = sanitize_text_field($attribute);
330
+				}
331
+			}
332
+		}
333
+		self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
334
+		/** Update newsletter user preferences **/
335
+		$newsletter_preferences = array();
336
+		$newsletter_site = !empty($_POST['newsletters_site']) ? sanitize_text_field($_POST['newsletters_site']) : '';
337
+		if (!empty($newsletter_site)) {
338
+			$newsletter_preferences['newsletters_site'] = 1;
339
+		}
340
+		$newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? sanitize_text_field($_POST['newsletters_site_partners']) : '';
341
+		if (!empty($newsletters_site_partners)) {
342
+			$newsletter_preferences['newsletters_site_partners'] = 1;
343
+		}
344
+		update_user_meta($user_id, 'user_preferences', $newsletter_preferences);
345
+		return;
346
+	}
347 347
 
348 348
 	public static function prevent_send_mail_from_wordpress() {
349 349
 		return false;
350 350
 	}
351
-    public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info)
352
-    {
353
-        global $wpdb;
354
-        global $wpshop;
355
-        $exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name');
356
-        $wps_entities = new wpshop_entities();
357
-        $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
358
-        $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
359
-        $attribute_set_id = $wpdb->get_var($query);
360
-        $attributes_default = array();
361
-        if (!empty($attribute_set_id)) {
362
-            $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
363
-            foreach ($group as $attribute_sets) {
364
-                foreach ($attribute_sets as $attribute_set_field) {
365
-                    foreach ($attribute_set_field['content'] as $attribute) {
366
-                        if (isset($attribute['value'])) {
367
-                            if (is_serialized($attribute['value'])) {
368
-                                $unserialized_value = unserialize($attribute['value']);
369
-                                if (isset($unserialized_value['default_value'])) {
370
-                                    $attributes_default[$attribute['name']] = $unserialized_value['default_value'];
371
-                                }
372
-                            } else {
373
-                                $attributes_default[$attribute['name']] = $attribute['value'];
374
-                            }
375
-                        }
376
-                    }
377
-                }
378
-            }
379
-        }
380
-        $user_info = array_merge($attributes_default, $user_info);
351
+	public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info)
352
+	{
353
+		global $wpdb;
354
+		global $wpshop;
355
+		$exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name');
356
+		$wps_entities = new wpshop_entities();
357
+		$element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
358
+		$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
359
+		$attribute_set_id = $wpdb->get_var($query);
360
+		$attributes_default = array();
361
+		if (!empty($attribute_set_id)) {
362
+			$group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
363
+			foreach ($group as $attribute_sets) {
364
+				foreach ($attribute_sets as $attribute_set_field) {
365
+					foreach ($attribute_set_field['content'] as $attribute) {
366
+						if (isset($attribute['value'])) {
367
+							if (is_serialized($attribute['value'])) {
368
+								$unserialized_value = unserialize($attribute['value']);
369
+								if (isset($unserialized_value['default_value'])) {
370
+									$attributes_default[$attribute['name']] = $unserialized_value['default_value'];
371
+								}
372
+							} else {
373
+								$attributes_default[$attribute['name']] = $attribute['value'];
374
+							}
375
+						}
376
+					}
377
+				}
378
+			}
379
+		}
380
+		$user_info = array_merge($attributes_default, $user_info);
381 381
 		add_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) );
382
-        foreach ($user_info as $user_meta => $user_meta_value) {
383
-            $attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code');
384
-            if (!empty($attribute_def)) {
385
-                //Save data in user meta
386
-                if (in_array($user_meta, $exclude_user_meta)) {
387
-                    if ($user_meta == 'user_pass') {
388
-                        $new_password = wpshop_tools::varSanitizer($user_meta_value);
389
-                        if (wp_hash_password($new_password) == get_user_meta($user_id, $user_meta, true)) {
390
-                            continue;
391
-                        }
392
-                    }
393
-                    wp_update_user(array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer($user_meta_value)));
394
-                } else {
395
-                    update_user_meta($user_id, $user_meta, wpshop_tools::varSanitizer($user_meta_value));
396
-                }
397
-                //Save data in attribute tables, ckeck first if exist to know if Insert or Update
398
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id);
399
-                $checking_attribute_exist = $wpdb->get_results($query);
400
-                if (!empty($checking_attribute_exist)) {
401
-                    $wpdb->update(
402
-                        WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
403
-                        array(
404
-                            'value' => wpshop_tools::varSanitizer($user_meta_value)),
405
-                        array(
406
-                            'entity_type_id' => $element_id,
407
-                            'entity_id' => $customer_post_ID,
408
-                            'attribute_id' => $attribute_def->id,
409
-                        )
410
-                    );
411
-                } else {
412
-                    $wpdb->insert(
413
-                        WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
414
-                        array(
415
-                            'entity_type_id' => $element_id,
416
-                            'attribute_id' => $attribute_def->id,
417
-                            'entity_id' => $customer_post_ID,
418
-                            'user_id' => $user_id,
419
-                            'creation_date_value' => current_time('mysql', 0),
420
-                            'language' => 'fr_FR',
421
-                            'value' => wpshop_tools::varSanitizer($user_meta_value),
422
-                        )
423
-                    );
424
-                }
425
-            }
426
-        }
382
+		foreach ($user_info as $user_meta => $user_meta_value) {
383
+			$attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code');
384
+			if (!empty($attribute_def)) {
385
+				//Save data in user meta
386
+				if (in_array($user_meta, $exclude_user_meta)) {
387
+					if ($user_meta == 'user_pass') {
388
+						$new_password = wpshop_tools::varSanitizer($user_meta_value);
389
+						if (wp_hash_password($new_password) == get_user_meta($user_id, $user_meta, true)) {
390
+							continue;
391
+						}
392
+					}
393
+					wp_update_user(array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer($user_meta_value)));
394
+				} else {
395
+					update_user_meta($user_id, $user_meta, wpshop_tools::varSanitizer($user_meta_value));
396
+				}
397
+				//Save data in attribute tables, ckeck first if exist to know if Insert or Update
398
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id);
399
+				$checking_attribute_exist = $wpdb->get_results($query);
400
+				if (!empty($checking_attribute_exist)) {
401
+					$wpdb->update(
402
+						WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
403
+						array(
404
+							'value' => wpshop_tools::varSanitizer($user_meta_value)),
405
+						array(
406
+							'entity_type_id' => $element_id,
407
+							'entity_id' => $customer_post_ID,
408
+							'attribute_id' => $attribute_def->id,
409
+						)
410
+					);
411
+				} else {
412
+					$wpdb->insert(
413
+						WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
414
+						array(
415
+							'entity_type_id' => $element_id,
416
+							'attribute_id' => $attribute_def->id,
417
+							'entity_id' => $customer_post_ID,
418
+							'user_id' => $user_id,
419
+							'creation_date_value' => current_time('mysql', 0),
420
+							'language' => 'fr_FR',
421
+							'value' => wpshop_tools::varSanitizer($user_meta_value),
422
+						)
423
+					);
424
+				}
425
+			}
426
+		}
427 427
 		remove_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) );
428
-    }
429
-
430
-    /**
431
-     * Notice for errors on admin
432
-     */
433
-    public function notice_save_post_customer_informations()
434
-    {
435
-        $errors = isset($_SESSION['save_post_customer_informations_errors']) ? $_SESSION['save_post_customer_informations_errors'] : '';
436
-        if (!empty($errors)) {
437
-            foreach ($errors as $error) {
438
-                $class = "error";
439
-                $message = $error;
440
-                echo "<div class=\"$class\"> <p>$message</p></div>";
441
-            }
442
-            unset($_SESSION['save_post_customer_informations_errors']);
443
-        }
444
-    }
445
-
446
-    /**
447
-     * Change the customer list table header to display custom informations
448
-     *
449
-     * @param array $current_header The current header list displayed to filter and modify for new output
450
-     *
451
-     * @return array The new header to display
452
-     */
453
-    public function list_table_header($current_header)
454
-    {
455
-        unset($current_header['title']);
456
-        unset($current_header['date']);
457
-
458
-        $current_header['customer_identifier'] = __('Customer ID', 'wpshop');
459
-        $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>';
460
-        $current_header['customer_email'] = __('E-mail', 'wpshop');
461
-        $current_header['customer_orders'] = __('Customer\'s orders', 'wpshop');
462
-        $current_header['customer_date_subscription'] = __('Subscription', 'wpshop');
463
-        $current_header['customer_date_lastlogin'] = __('Last login date', 'wpshop');
464
-
465
-        return $current_header;
466
-    }
467
-
468
-    /**
469
-     * Display the content into list table column
470
-     *
471
-     * @param string $column THe column identifier to modify output for
472
-     * @param integer $post_id The current post identifier
473
-     */
474
-    public function list_table_column_content($column, $post_id)
475
-    {
476
-        global $wpdb;
477
-        /**    Get wp_users idenfifier from customer id    */
478
-        $current_user_id_in_list = self::get_author_id_by_customer_id($post_id);
479
-
480
-        /**    Get current post informations    */
481
-        $customer_post = get_post($post_id);
482
-
483
-        /**    Get user data    */
484
-        $current_user_datas = get_userdata($current_user_id_in_list);
485
-
486
-        /**    Switch current column for custom case    */
487
-        $use_template = true;
488
-        switch ($column) {
489
-            case 'customer_identifier':
490
-                echo $post_id;
491
-                $use_template = false;
492
-                break;
493
-            case 'customer_date_subscription':
494
-                echo mysql2date(get_option('date_format'), $current_user_datas->user_registered, true);
495
-                $use_template = false;
496
-                break;
497
-            case 'customer_date_lastlogin':
498
-                $last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true);
499
-                if (!empty($last_login)):
500
-                    echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
501
-                else:
502
-                    _e('Never logged in', 'wpshop');
503
-                endif;
504
-                $use_template = false;
505
-                break;
506
-        }
507
-
508
-        /**    Require the template for displaying the current column    */
509
-        if ($use_template) {
510
-            $template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column);
511
-            if (is_file($template)) {
512
-                require $template;
513
-            }
514
-        }
515
-    }
516
-
517
-    /**
518
-     * Filter bulk actions into customer list table
519
-     *
520
-     * @param array $actions Current available actions list
521
-     *
522
-     * @return array The new action list to use into customer list table
523
-     */
524
-    public function customer_list_table_bulk_actions($actions)
525
-    {
526
-        unset($actions['edit']);
527
-        unset($actions['trash']);
528
-
529
-        return $actions;
530
-    }
531
-
532
-    public function list_table_filters()
533
-    {
534
-        $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
535
-        if (isset($post_type)) {
536
-            if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) {
537
-                $filter_possibilities = array();
538
-                $filter_possibilities[''] = __('-- Select Filter --', 'wpshop');
539
-                $filter_possibilities['orders'] = __('List customers with orders', 'wpshop');
540
-                $filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop');
541
-                echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
542
-            }
543
-        }
544
-    }
545
-
546
-    public function list_table_filter_parse_query($query)
547
-    {
548
-        global $pagenow, $wpdb;
549
-        $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
550
-        $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
551
-        if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) {
552
-            $check = null;
553
-            switch ($entity_filter) {
554
-                case 'orders':
555
-                    $sql_query = $wpdb->prepare(
556
-                        "SELECT ID
428
+	}
429
+
430
+	/**
431
+	 * Notice for errors on admin
432
+	 */
433
+	public function notice_save_post_customer_informations()
434
+	{
435
+		$errors = isset($_SESSION['save_post_customer_informations_errors']) ? $_SESSION['save_post_customer_informations_errors'] : '';
436
+		if (!empty($errors)) {
437
+			foreach ($errors as $error) {
438
+				$class = "error";
439
+				$message = $error;
440
+				echo "<div class=\"$class\"> <p>$message</p></div>";
441
+			}
442
+			unset($_SESSION['save_post_customer_informations_errors']);
443
+		}
444
+	}
445
+
446
+	/**
447
+	 * Change the customer list table header to display custom informations
448
+	 *
449
+	 * @param array $current_header The current header list displayed to filter and modify for new output
450
+	 *
451
+	 * @return array The new header to display
452
+	 */
453
+	public function list_table_header($current_header)
454
+	{
455
+		unset($current_header['title']);
456
+		unset($current_header['date']);
457
+
458
+		$current_header['customer_identifier'] = __('Customer ID', 'wpshop');
459
+		$current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>';
460
+		$current_header['customer_email'] = __('E-mail', 'wpshop');
461
+		$current_header['customer_orders'] = __('Customer\'s orders', 'wpshop');
462
+		$current_header['customer_date_subscription'] = __('Subscription', 'wpshop');
463
+		$current_header['customer_date_lastlogin'] = __('Last login date', 'wpshop');
464
+
465
+		return $current_header;
466
+	}
467
+
468
+	/**
469
+	 * Display the content into list table column
470
+	 *
471
+	 * @param string $column THe column identifier to modify output for
472
+	 * @param integer $post_id The current post identifier
473
+	 */
474
+	public function list_table_column_content($column, $post_id)
475
+	{
476
+		global $wpdb;
477
+		/**    Get wp_users idenfifier from customer id    */
478
+		$current_user_id_in_list = self::get_author_id_by_customer_id($post_id);
479
+
480
+		/**    Get current post informations    */
481
+		$customer_post = get_post($post_id);
482
+
483
+		/**    Get user data    */
484
+		$current_user_datas = get_userdata($current_user_id_in_list);
485
+
486
+		/**    Switch current column for custom case    */
487
+		$use_template = true;
488
+		switch ($column) {
489
+			case 'customer_identifier':
490
+				echo $post_id;
491
+				$use_template = false;
492
+				break;
493
+			case 'customer_date_subscription':
494
+				echo mysql2date(get_option('date_format'), $current_user_datas->user_registered, true);
495
+				$use_template = false;
496
+				break;
497
+			case 'customer_date_lastlogin':
498
+				$last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true);
499
+				if (!empty($last_login)):
500
+					echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
501
+				else:
502
+					_e('Never logged in', 'wpshop');
503
+				endif;
504
+				$use_template = false;
505
+				break;
506
+		}
507
+
508
+		/**    Require the template for displaying the current column    */
509
+		if ($use_template) {
510
+			$template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column);
511
+			if (is_file($template)) {
512
+				require $template;
513
+			}
514
+		}
515
+	}
516
+
517
+	/**
518
+	 * Filter bulk actions into customer list table
519
+	 *
520
+	 * @param array $actions Current available actions list
521
+	 *
522
+	 * @return array The new action list to use into customer list table
523
+	 */
524
+	public function customer_list_table_bulk_actions($actions)
525
+	{
526
+		unset($actions['edit']);
527
+		unset($actions['trash']);
528
+
529
+		return $actions;
530
+	}
531
+
532
+	public function list_table_filters()
533
+	{
534
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
535
+		if (isset($post_type)) {
536
+			if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) {
537
+				$filter_possibilities = array();
538
+				$filter_possibilities[''] = __('-- Select Filter --', 'wpshop');
539
+				$filter_possibilities['orders'] = __('List customers with orders', 'wpshop');
540
+				$filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop');
541
+				echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
542
+			}
543
+		}
544
+	}
545
+
546
+	public function list_table_filter_parse_query($query)
547
+	{
548
+		global $pagenow, $wpdb;
549
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
550
+		$entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
551
+		if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) {
552
+			$check = null;
553
+			switch ($entity_filter) {
554
+				case 'orders':
555
+					$sql_query = $wpdb->prepare(
556
+						"SELECT ID
557 557
 						FROM {$wpdb->posts}
558 558
 						WHERE post_type = %s
559 559
 						AND post_status != %s
@@ -562,15 +562,15 @@  discard block
 block discarded – undo
562 562
 						FROM {$wpdb->posts}
563 563
 						WHERE post_type = %s
564 564
 						AND post_status != %s)",
565
-                        WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
566
-                        'auto-draft',
567
-                        WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
568
-                        'auto-draft');
569
-                    $check = 'post__in';
570
-                    break;
571
-                case 'no_orders':
572
-                    $sql_query = $wpdb->prepare(
573
-                        "SELECT ID
565
+						WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
566
+						'auto-draft',
567
+						WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
568
+						'auto-draft');
569
+					$check = 'post__in';
570
+					break;
571
+				case 'no_orders':
572
+					$sql_query = $wpdb->prepare(
573
+						"SELECT ID
574 574
 						FROM {$wpdb->posts}
575 575
 						WHERE post_type = %s
576 576
 						AND post_status != %s
@@ -579,204 +579,204 @@  discard block
 block discarded – undo
579 579
 						FROM {$wpdb->posts}
580 580
 						WHERE post_type = %s
581 581
 						AND post_status != %s)",
582
-                        WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
583
-                        'auto-draft',
584
-                        WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
585
-                        'auto-draft');
586
-                    $check = 'post__in';
587
-                    break;
588
-            }
589
-
590
-            if (!empty($check)) {
591
-                $results = $wpdb->get_results($sql_query);
592
-                $user_id_list = array();
593
-                foreach ($results as $item) {
594
-                    $user_id_list[] = $item->ID;
595
-                }
596
-                if (empty($post_id_list)) {
597
-                    $post_id_list[] = 'no_result';
598
-                }
599
-                $query->query_vars[$check] = $user_id_list;
600
-            }
601
-            $query->query_vars['post_type'] = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
602
-            $query->query_vars['post_status'] = 'any';
603
-        }
604
-    }
605
-
606
-    /**
607
-     * Récupère la liste de tous les clients / Get the list of all customers
608
-     *
609
-     * @return array
610
-     */
611
-    public static function get_all_customer($post_status = 'publish')
612
-    {
613
-        global $wpdb;
614
-
615
-        $query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status);
616
-        $list_customer = $wpdb->get_results($query);
617
-
618
-        return $list_customer;
619
-    }
620
-
621
-    /**
622
-     * Récupère l'id du client selon son author id / Get customer id by the author id
623
-     *
624
-     * @param int $author_id
625
-     * @return int $customer_id
626
-     */
627
-    public static function get_customer_id_by_author_id($author_id)
628
-    {
582
+						WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
583
+						'auto-draft',
584
+						WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
585
+						'auto-draft');
586
+					$check = 'post__in';
587
+					break;
588
+			}
589
+
590
+			if (!empty($check)) {
591
+				$results = $wpdb->get_results($sql_query);
592
+				$user_id_list = array();
593
+				foreach ($results as $item) {
594
+					$user_id_list[] = $item->ID;
595
+				}
596
+				if (empty($post_id_list)) {
597
+					$post_id_list[] = 'no_result';
598
+				}
599
+				$query->query_vars[$check] = $user_id_list;
600
+			}
601
+			$query->query_vars['post_type'] = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
602
+			$query->query_vars['post_status'] = 'any';
603
+		}
604
+	}
605
+
606
+	/**
607
+	 * Récupère la liste de tous les clients / Get the list of all customers
608
+	 *
609
+	 * @return array
610
+	 */
611
+	public static function get_all_customer($post_status = 'publish')
612
+	{
613
+		global $wpdb;
614
+
615
+		$query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status);
616
+		$list_customer = $wpdb->get_results($query);
617
+
618
+		return $list_customer;
619
+	}
620
+
621
+	/**
622
+	 * Récupère l'id du client selon son author id / Get customer id by the author id
623
+	 *
624
+	 * @param int $author_id
625
+	 * @return int $customer_id
626
+	 */
627
+	public static function get_customer_id_by_author_id($author_id)
628
+	{
629 629
 		if( !isset( self::$customer_user_identifier_cache[$author_id] ) ) {
630
-	        global $wpdb;
631
-	        $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
632
-	        self::$customer_user_identifier_cache[$author_id] = $wpdb->get_var($query);
630
+			global $wpdb;
631
+			$query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
632
+			self::$customer_user_identifier_cache[$author_id] = $wpdb->get_var($query);
633 633
 		}
634 634
 
635
-        return self::$customer_user_identifier_cache[$author_id];
636
-    }
637
-
638
-    /**
639
-     * Récupère l'id de l'utilisateur selon l'id du client / Get author id by customer id
640
-     *
641
-     * @method get_author_id_by_customer_id
642
-     * @param  int $customer_id ID in wpshop_customers type.
643
-     * @return int
644
-     */
645
-    public static function get_author_id_by_customer_id($customer_id)
646
-    {
635
+		return self::$customer_user_identifier_cache[$author_id];
636
+	}
637
+
638
+	/**
639
+	 * Récupère l'id de l'utilisateur selon l'id du client / Get author id by customer id
640
+	 *
641
+	 * @method get_author_id_by_customer_id
642
+	 * @param  int $customer_id ID in wpshop_customers type.
643
+	 * @return int
644
+	 */
645
+	public static function get_author_id_by_customer_id($customer_id)
646
+	{
647 647
 		$flipped = array_flip(self::$customer_user_identifier_cache);
648 648
 		if( !isset( $flipped[$customer_id] ) ) {
649
-	        global $wpdb;
649
+			global $wpdb;
650 650
 			$author_id = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $customer_id));
651
-	        self::$customer_user_identifier_cache[$author_id] = $customer_id;
651
+			self::$customer_user_identifier_cache[$author_id] = $customer_id;
652 652
 			$flipped[$customer_id] = $author_id;
653 653
 		}
654 654
 
655
-        return $flipped[$customer_id];
656
-    }
657
-
658
-    /**
659
-     * Essaie de créer une corrélation entre le formulaire que l'on passe et customer ( ex: billing_address => customer )
660
-     *
661
-     * @param array $form Passer directement le $_POST pour créer un client.
662
-     * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà
663
-     */
664
-    public static function quick_add_customer($form)
665
-    {
666
-        $return = 1;
667
-        if (!empty($form)) {
668
-            global $wpdb;
669
-            $customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
670
-            $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id);
671
-            $customer_entity_id = $wpdb->get_var($query);
672
-            $attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
673
-            $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
674
-
675
-            $customer_attributes_to_save = $customer_attributes_to_save_temp = array();
676
-
677
-            foreach ($form['attribute'] as $attribute_type => $attributes) {
678
-                foreach ($attributes as $attribute_code => $attribute_value) {
679
-                    $customer_attributes_compare[$attribute_code] = $attribute_type;
680
-                }
681
-            }
682
-
683
-            foreach ($account_attributes as $account_attribute_group) {
684
-                foreach ($account_attribute_group['attribut'] as $attribute) {
685
-                    foreach (preg_grep('/' . $attribute->code . '/', array_keys($customer_attributes_compare)) as $codeForm) {
686
-                        if ($customer_attributes_compare[$codeForm] == $attribute->data_type) {
687
-                            $user[$attribute->code] = array('attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field($_POST['attribute'][$attribute->data_type][$codeForm]));
688
-                            if ($attribute->code == 'user_email') {
689
-                                $email_founded = true;
690
-                            }
691
-                        }
692
-                    }
693
-                }
694
-            }
695
-
696
-            if ($email_founded && is_email($user['user_email']['value'])) {
697
-                $user_id = username_exists($user['user_email']['value']);
698
-                if (empty($user_id)) {
699
-                    $user_name = isset($user['user_login']['value']) ? $user['user_login']['value'] : $user['user_email']['value'];
700
-                    $user_pass = isset($user['user_pass']['value']) ? $user['user_pass']['value'] : wp_generate_password(12, false);
701
-                    $user_id = wp_create_user($user_name, $user_pass, $user['user_email']['value']);
702
-
703
-                    if (!is_wp_error($user_id)) {
704
-                        $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
705
-                        $customer_entity_id = $wpdb->get_var($customer_entity_request);
706
-                        $return = array();
707
-                        $return['integer']['ID'] = $user_id;
708
-
709
-                        foreach ($user as $meta_key => $meta_values) {
710
-                            update_user_meta($user_id, $meta_key, $meta_values['value']);
711
-                            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($meta_values['data_type']), array('entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value']));
712
-                            $return[$meta_values['data_type']][$meta_key] = $meta_values['value'];
713
-                        }
714
-                    }
715
-                } else {
716
-                    $return = 2;
717
-                }
718
-            }
719
-        }
720
-
721
-        return $return;
722
-    }
723
-
724
-    /**
725
-     * Search function for customer / Fonction de recherche des clients
726
-     *
727
-     * @param string $term The term we have to search into database for getting existing users / Le terme qu'il faut rechercher pour retrouver les utilisateurs dans la base de données
728
-     */
729
-    public function search_customer($term)
730
-    {
731
-        global $wpdb;
732
-
733
-        /**    Build the customer search    */
734
-        $args = array(
735
-            'search' => "*" . $term . "*",
736
-            'search_columns' => array('user_login', 'user_email', 'user_nicename'),
737
-            'meta_query' => array(
738
-                'relation' => 'OR',
739
-                array(
740
-                    'key' => 'first_name',
741
-                    'value' => $term,
742
-                    'compare' => 'LIKE',
743
-                ),
744
-                array(
745
-                    'key' => 'last_name',
746
-                    'value' => $term,
747
-                    'compare' => 'LIKE',
748
-                ),
749
-            ),
750
-        );
751
-        $customer_search = new WP_User_Query($args);
752
-
753
-        $customer_list = array();
754
-        if (!empty($customer_search->results)) {
755
-            foreach ($customer_search->results as $customer) {
756
-                /** Check the username, if last name and first name are empty we select email **/
757
-                $last_name_meta = get_user_meta($customer->ID, 'last_name', true);
758
-                $first_name_meta = get_user_meta($customer->ID, 'first_name', true);
759
-                $user_data = $customer->data;
760
-                $email_data = $user_data->user_email;
761
-
762
-                if (!empty($last_name_meta)) {
763
-                    $user_name = $last_name_meta;
764
-                } elseif (!empty($first_name_meta)) {
765
-                    $user_name = $first_name_meta;
766
-                } else {
767
-                    $user_name = $email_data;
768
-                }
769
-
770
-                $customer_list[] = array(
771
-                    'ID' => $customer->ID,
772
-                    'last_name' => $last_name_meta,
773
-                    'first_name' => $first_name_meta,
774
-                    'email' => $email_data,
775
-                );
776
-            }
777
-        }
778
-
779
-        return $customer_list;
780
-    }
655
+		return $flipped[$customer_id];
656
+	}
657
+
658
+	/**
659
+	 * Essaie de créer une corrélation entre le formulaire que l'on passe et customer ( ex: billing_address => customer )
660
+	 *
661
+	 * @param array $form Passer directement le $_POST pour créer un client.
662
+	 * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà
663
+	 */
664
+	public static function quick_add_customer($form)
665
+	{
666
+		$return = 1;
667
+		if (!empty($form)) {
668
+			global $wpdb;
669
+			$customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
670
+			$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id);
671
+			$customer_entity_id = $wpdb->get_var($query);
672
+			$attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
673
+			$account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
674
+
675
+			$customer_attributes_to_save = $customer_attributes_to_save_temp = array();
676
+
677
+			foreach ($form['attribute'] as $attribute_type => $attributes) {
678
+				foreach ($attributes as $attribute_code => $attribute_value) {
679
+					$customer_attributes_compare[$attribute_code] = $attribute_type;
680
+				}
681
+			}
682
+
683
+			foreach ($account_attributes as $account_attribute_group) {
684
+				foreach ($account_attribute_group['attribut'] as $attribute) {
685
+					foreach (preg_grep('/' . $attribute->code . '/', array_keys($customer_attributes_compare)) as $codeForm) {
686
+						if ($customer_attributes_compare[$codeForm] == $attribute->data_type) {
687
+							$user[$attribute->code] = array('attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field($_POST['attribute'][$attribute->data_type][$codeForm]));
688
+							if ($attribute->code == 'user_email') {
689
+								$email_founded = true;
690
+							}
691
+						}
692
+					}
693
+				}
694
+			}
695
+
696
+			if ($email_founded && is_email($user['user_email']['value'])) {
697
+				$user_id = username_exists($user['user_email']['value']);
698
+				if (empty($user_id)) {
699
+					$user_name = isset($user['user_login']['value']) ? $user['user_login']['value'] : $user['user_email']['value'];
700
+					$user_pass = isset($user['user_pass']['value']) ? $user['user_pass']['value'] : wp_generate_password(12, false);
701
+					$user_id = wp_create_user($user_name, $user_pass, $user['user_email']['value']);
702
+
703
+					if (!is_wp_error($user_id)) {
704
+						$customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
705
+						$customer_entity_id = $wpdb->get_var($customer_entity_request);
706
+						$return = array();
707
+						$return['integer']['ID'] = $user_id;
708
+
709
+						foreach ($user as $meta_key => $meta_values) {
710
+							update_user_meta($user_id, $meta_key, $meta_values['value']);
711
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($meta_values['data_type']), array('entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value']));
712
+							$return[$meta_values['data_type']][$meta_key] = $meta_values['value'];
713
+						}
714
+					}
715
+				} else {
716
+					$return = 2;
717
+				}
718
+			}
719
+		}
720
+
721
+		return $return;
722
+	}
723
+
724
+	/**
725
+	 * Search function for customer / Fonction de recherche des clients
726
+	 *
727
+	 * @param string $term The term we have to search into database for getting existing users / Le terme qu'il faut rechercher pour retrouver les utilisateurs dans la base de données
728
+	 */
729
+	public function search_customer($term)
730
+	{
731
+		global $wpdb;
732
+
733
+		/**    Build the customer search    */
734
+		$args = array(
735
+			'search' => "*" . $term . "*",
736
+			'search_columns' => array('user_login', 'user_email', 'user_nicename'),
737
+			'meta_query' => array(
738
+				'relation' => 'OR',
739
+				array(
740
+					'key' => 'first_name',
741
+					'value' => $term,
742
+					'compare' => 'LIKE',
743
+				),
744
+				array(
745
+					'key' => 'last_name',
746
+					'value' => $term,
747
+					'compare' => 'LIKE',
748
+				),
749
+			),
750
+		);
751
+		$customer_search = new WP_User_Query($args);
752
+
753
+		$customer_list = array();
754
+		if (!empty($customer_search->results)) {
755
+			foreach ($customer_search->results as $customer) {
756
+				/** Check the username, if last name and first name are empty we select email **/
757
+				$last_name_meta = get_user_meta($customer->ID, 'last_name', true);
758
+				$first_name_meta = get_user_meta($customer->ID, 'first_name', true);
759
+				$user_data = $customer->data;
760
+				$email_data = $user_data->user_email;
761
+
762
+				if (!empty($last_name_meta)) {
763
+					$user_name = $last_name_meta;
764
+				} elseif (!empty($first_name_meta)) {
765
+					$user_name = $first_name_meta;
766
+				} else {
767
+					$user_name = $email_data;
768
+				}
769
+
770
+				$customer_list[] = array(
771
+					'ID' => $customer->ID,
772
+					'last_name' => $last_name_meta,
773
+					'first_name' => $first_name_meta,
774
+					'email' => $email_data,
775
+				);
776
+			}
777
+		}
778
+
779
+		return $customer_list;
780
+	}
781 781
 
782 782
 }
Please login to merge, or discard this patch.
includes/librairies/install.class.php 1 patch
Indentation   +2352 added lines, -2352 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
-                        }
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
+				}
407 84
 
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
-                                }
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
+				}
441 90
 
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
-                    }
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
+				}
472 103
 
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
-                        }
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);
508 107
 
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
-                        }
108
+					$page_creation = true;
109
+				}
587 110
 
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
-                        }
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
+			}
593 278
 
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
-                }
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 611
 
612
-                /*    Update the product prices into database    */
613
-                $query = $wpdb->prepare("
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
-                        }
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
+				}
683 632
 
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
-                    }
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
+				}
721 705
 
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;
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
+				}
740 726
 
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
-                }
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
+				}
813 745
 
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);
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
+				}
819 813
 
820
-                $query = $wpdb->prepare("
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
+				}
977 878
 
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
-                    }
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
+				}
1074 895
 
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
-                    }
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
+				}
1160 921
 
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
-                    }
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
+				}
1190 950
 
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);
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
+				}
1194 966
 
1195
-                    //Update the post meta
1196
-                    update_post_meta($result->ID, '_order_info', $array_new_format);
1197
-                }
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
+				}
1198 982
 
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'] : '';
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);
1206 986
 
1207
-                        $display_admin_menu = 'on';
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
+				}
1208 998
 
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
-                    }
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);
1326 1002
 
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
-                    }
1003
+				return true;
1004
+				break;
1359 1005
 
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;
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
+				}
1510 1119
 
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);
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
+				}
1514 1198
 
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);
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'] : '';
1517 1206
 
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);
1207
+						$display_admin_menu = 'on';
1520 1208
 
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)) {
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
+				}
1525 1234
 
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);
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
+					}
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'));
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;
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;
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);
1807 1807
                 if (!empty($messages)) {
1808 1808
                     foreach ($messages as $key => $message) {
1809 1809
                         $message_option = get_option($key);
@@ -1818,559 +1818,559 @@  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;
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 2374
 
2375 2375
 			case 67:
2376 2376
 				$admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
@@ -2384,63 +2384,63 @@  discard block
 block discarded – undo
2384 2384
 				update_option( 'wpshop_cart_option', $wpshop_cart_option );
2385 2385
 				break;
2386 2386
 
2387
-            /*    Always add specific case before this bloc    */
2388
-            case 'dev':
2389
-
2390
-                //wp_cache_flush();
2391
-                // Newsletters options
2392
-                //$wp_rewrite->flush_rules();
2393
-                return true;
2394
-                break;
2395
-
2396
-            default:
2397
-                return true;
2398
-                break;
2399
-        }
2400
-    }
2401
-
2402
-    /**
2403
-     * Method called when deactivating the plugin
2404
-     * @see register_deactivation_hook()
2405
-     */
2406
-    public function uninstall_wpshop()
2407
-    {
2408
-        global $wpdb;
2409
-
2410
-        if (WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION && in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) {
2411
-            $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`;");
2412
-            $query = $wpdb->query("DELETE FROM " . $wpdb->options . " WHERE `option_name` LIKE '%wpshop%';");
2413
-
2414
-            $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE 'wpshop_%';");
2415
-            $list = '  ';
2416
-            foreach ($wpshop_products_posts as $post) {
2417
-                $list .= "'" . $post->ID . "', ";
2418
-            }
2419
-            $list = substr($list, 0, -2);
2420
-
2421
-            $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_parent IN (" . $list . ");");
2422
-            $list_attachment = '  ';
2423
-            foreach ($wpshop_products_posts as $post) {
2424
-                $list_attachment .= "'" . $post->ID . "', ";
2425
-            }
2426
-            $list_attachment = substr($list_attachment, 0, -2);
2427
-
2428
-            $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list . ");");
2429
-            $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list_attachment . ");");
2430
-            $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list . ");");
2431
-            $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list_attachment . ");");
2432
-            $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE post_content LIKE '%wpshop%';");
2433
-        }
2434
-
2435
-        /*    Unset administrator permission    */
2436
-        $adminRole = get_role('administrator');
2437
-        foreach ($adminRole->capabilities as $capabilityName => $capability) {
2438
-            if (substr($capabilityName, 0, 7) == 'wpshop_') {
2439
-                if ($adminRole->has_cap($capabilityName)) {
2440
-                    $adminRole->remove_cap($capabilityName);
2441
-                }
2442
-            }
2443
-        }
2444
-    }
2387
+			/*    Always add specific case before this bloc    */
2388
+			case 'dev':
2389
+
2390
+				//wp_cache_flush();
2391
+				// Newsletters options
2392
+				//$wp_rewrite->flush_rules();
2393
+				return true;
2394
+				break;
2395
+
2396
+			default:
2397
+				return true;
2398
+				break;
2399
+		}
2400
+	}
2401
+
2402
+	/**
2403
+	 * Method called when deactivating the plugin
2404
+	 * @see register_deactivation_hook()
2405
+	 */
2406
+	public function uninstall_wpshop()
2407
+	{
2408
+		global $wpdb;
2409
+
2410
+		if (WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION && in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) {
2411
+			$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`;");
2412
+			$query = $wpdb->query("DELETE FROM " . $wpdb->options . " WHERE `option_name` LIKE '%wpshop%';");
2413
+
2414
+			$wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE 'wpshop_%';");
2415
+			$list = '  ';
2416
+			foreach ($wpshop_products_posts as $post) {
2417
+				$list .= "'" . $post->ID . "', ";
2418
+			}
2419
+			$list = substr($list, 0, -2);
2420
+
2421
+			$wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_parent IN (" . $list . ");");
2422
+			$list_attachment = '  ';
2423
+			foreach ($wpshop_products_posts as $post) {
2424
+				$list_attachment .= "'" . $post->ID . "', ";
2425
+			}
2426
+			$list_attachment = substr($list_attachment, 0, -2);
2427
+
2428
+			$query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list . ");");
2429
+			$query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list_attachment . ");");
2430
+			$query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list . ");");
2431
+			$query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list_attachment . ");");
2432
+			$query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE post_content LIKE '%wpshop%';");
2433
+		}
2434
+
2435
+		/*    Unset administrator permission    */
2436
+		$adminRole = get_role('administrator');
2437
+		foreach ($adminRole->capabilities as $capabilityName => $capability) {
2438
+			if (substr($capabilityName, 0, 7) == 'wpshop_') {
2439
+				if ($adminRole->has_cap($capabilityName)) {
2440
+					$adminRole->remove_cap($capabilityName);
2441
+				}
2442
+			}
2443
+		}
2444
+	}
2445 2445
 
2446 2446
 }
Please login to merge, or discard this patch.
includes/librairies/eav/attributes_unit.class.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -24,45 +24,45 @@  discard block
 block discarded – undo
24 24
 class wpshop_attributes_unit
25 25
 {
26 26
 	/**
27
-	*	Define the database table used in the current class
28
-	*/
27
+	 *	Define the database table used in the current class
28
+	 */
29 29
 	const dbTable = WPSHOP_DBT_ATTRIBUTE_UNIT;
30 30
 	/**
31
-	*	Define the url listing slug used in the current class
32
-	*/
31
+	 *	Define the url listing slug used in the current class
32
+	 */
33 33
 	const urlSlugListing = WPSHOP_URL_SLUG_ATTRIBUTE_LISTING;
34 34
 	/**
35
-	*	Define the url edition slug used in the current class
36
-	*/
35
+	 *	Define the url edition slug used in the current class
36
+	 */
37 37
 	const urlSlugEdition = WPSHOP_URL_SLUG_ATTRIBUTE_LISTING;
38 38
 	/**
39
-	*	Define the current entity code
40
-	*/
39
+	 *	Define the current entity code
40
+	 */
41 41
 	const currentPageCode = 'attributes_unit';
42 42
 	/**
43
-	*	Define the page title
44
-	*/
43
+	 *	Define the page title
44
+	 */
45 45
 	const pageContentTitle = 'Attributes unit';
46 46
 	/**
47
-	*	Define the page title when adding an attribute
48
-	*/
47
+	 *	Define the page title when adding an attribute
48
+	 */
49 49
 	const pageAddingTitle = 'Add an unit';
50 50
 	/**
51
-	*	Define the page title when editing an attribute
52
-	*/
51
+	 *	Define the page title when editing an attribute
52
+	 */
53 53
 	const pageEditingTitle = 'Unit "%s" edit';
54 54
 	/**
55
-	*	Define the page title when editing an attribute
56
-	*/
55
+	 *	Define the page title when editing an attribute
56
+	 */
57 57
 	const pageTitle = 'Attributes unit list';
58 58
 
59 59
 	/**
60
-	*	Define the path to page main icon
61
-	*/
60
+	 *	Define the path to page main icon
61
+	 */
62 62
 	public $pageIcon = '';
63 63
 	/**
64
-	*	Define the message to output after an action
65
-	*/
64
+	 *	Define the message to output after an action
65
+	 */
66 66
 	public $pageMessage = '';
67 67
 
68 68
 	/**
@@ -71,47 +71,47 @@  discard block
 block discarded – undo
71 71
 	public static $currencies_cache;
72 72
 
73 73
 	/**
74
-	*	Get the url listing slug of the current class
75
-	*
76
-	*	@return string The table of the class
77
-	*/
74
+	 *	Get the url listing slug of the current class
75
+	 *
76
+	 *	@return string The table of the class
77
+	 */
78 78
 	function setMessage($message)
79 79
 	{
80 80
 		$this->pageMessage = $message;
81 81
 	}
82 82
 	/**
83
-	*	Get the url listing slug of the current class
84
-	*
85
-	*	@return string The table of the class
86
-	*/
83
+	 *	Get the url listing slug of the current class
84
+	 *
85
+	 *	@return string The table of the class
86
+	 */
87 87
 	public static function getListingSlug()
88 88
 	{
89 89
 		return self::urlSlugListing;
90 90
 	}
91 91
 	/**
92
-	*	Get the url edition slug of the current class
93
-	*
94
-	*	@return string The table of the class
95
-	*/
92
+	 *	Get the url edition slug of the current class
93
+	 *
94
+	 *	@return string The table of the class
95
+	 */
96 96
 	public static function getEditionSlug()
97 97
 	{
98 98
 		return self::urlSlugEdition;
99 99
 	}
100 100
 	/**
101
-	*	Get the database table of the current class
102
-	*
103
-	*	@return string The table of the class
104
-	*/
101
+	 *	Get the database table of the current class
102
+	 *
103
+	 *	@return string The table of the class
104
+	 */
105 105
 	public static function getDbTable()
106 106
 	{
107 107
 		return self::dbTable;
108 108
 	}
109 109
 
110 110
 	/**
111
-	*	Define the title of the page
112
-	*
113
-	*	@return string $title The title of the page looking at the environnement
114
-	*/
111
+	 *	Define the title of the page
112
+	 *
113
+	 *	@return string $title The title of the page looking at the environnement
114
+	 */
115 115
 	function pageTitle()
116 116
 	{
117 117
 		$action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	}
140 140
 
141 141
 	/**
142
-	*	Define the different message and action after an action is send through the element interface
143
-	*/
142
+	 *	Define the different message and action after an action is send through the element interface
143
+	 */
144 144
 	function elementAction()
145 145
 	{
146 146
 		global $wpdb, $initialEavData;
@@ -270,10 +270,10 @@  discard block
 block discarded – undo
270 270
 	}
271 271
 
272 272
 	/**
273
-	*	Return the list page content, containing the table that present the item list
274
-	*
275
-	*	@return string $listItemOutput The html code that output the item list
276
-	*/
273
+	 *	Return the list page content, containing the table that present the item list
274
+	 *
275
+	 *	@return string $listItemOutput The html code that output the item list
276
+	 */
277 277
 	public static function elementList()
278 278
 	{
279 279
 		$listItemOutput = '';
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
 		return $listItemOutput;
394 394
 	}
395 395
 	/**
396
-	*	Return the page content to add a new item
397
-	*
398
-	*	@return string The html code that output the interface for adding a nem item
399
-	*/
396
+	 *	Return the page content to add a new item
397
+	 *
398
+	 *	@return string The html code that output the interface for adding a nem item
399
+	 */
400 400
 	public static function elementEdition($itemToEdit = ''){
401 401
 		global $attribute_displayed_field; global $wpdb;
402 402
 		$dbFieldList = wpshop_database::fields_to_input(self::getDbTable());
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 		return $the_form;
494 494
 	}
495 495
 	/**
496
-	*	Return the different button to save the item currently being added or edited
497
-	*
498
-	*	@return string $currentPageButton The html output code with the different button to add to the interface
499
-	*/
496
+	 *	Return the different button to save the item currently being added or edited
497
+	 *
498
+	 *	@return string $currentPageButton The html output code with the different button to add to the interface
499
+	 */
500 500
 	function getPageFormButton($element_id = 0)
501 501
 	{
502 502
 		$action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add';
@@ -524,14 +524,14 @@  discard block
 block discarded – undo
524 524
 	}
525 525
 
526 526
 	/**
527
-	*	Get the existing attribute list into database
528
-	*
529
-	*	@param integer $element_id optionnal The attribute identifier we want to get. If not specify the entire list will be returned
530
-	*	@param string $element_status optionnal The status of element to get into database. Default is set to valid element
531
-	*	@param mixed $field_to_search optionnal The field we want to check the row identifier into. Default is to set id
532
-	*
533
-	*	@return object $element_list A wordpress database object containing the attribute list
534
-	*/
527
+	 *	Get the existing attribute list into database
528
+	 *
529
+	 *	@param integer $element_id optionnal The attribute identifier we want to get. If not specify the entire list will be returned
530
+	 *	@param string $element_status optionnal The status of element to get into database. Default is set to valid element
531
+	 *	@param mixed $field_to_search optionnal The field we want to check the row identifier into. Default is to set id
532
+	 *
533
+	 *	@return object $element_list A wordpress database object containing the attribute list
534
+	 */
535 535
 	public static function getElement($element_id = '', $element_status = "'valid', 'moderated'", $field_to_search = 'id'){
536 536
 		global $wpdb;
537 537
 		$element_list = array();
@@ -563,8 +563,8 @@  discard block
 block discarded – undo
563 563
 	}
564 564
 
565 565
 	/**
566
-	*
567
-	*/
566
+	 *
567
+	 */
568 568
 	public static function get_unit_list_for_group($group_id){
569 569
 		global $wpdb;
570 570
 		$unit_list_for_group = '';
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
 		return $unit_list_for_group;
579 579
 	}
580 580
 	/**
581
-	*
582
-	*/
581
+	 *
582
+	 */
583 583
 	public static function get_default_unit_for_group($group_id){
584 584
 		global $wpdb;
585 585
 		$default_unit_for_group = '';
@@ -592,10 +592,10 @@  discard block
 block discarded – undo
592 592
 	}
593 593
 
594 594
 	/**
595
-	*	Get the unit group existing list in database
596
-	*
597
-	*	@return object $attribute_unit_group_list The list of existing unit group
598
-	*/
595
+	 *	Get the unit group existing list in database
596
+	 *
597
+	 *	@return object $attribute_unit_group_list The list of existing unit group
598
+	 */
599 599
 	public static function get_unit_group($element_id = '', $element_status = "'valid', 'moderated'", $field_to_search = 'id'){
600 600
 		global $wpdb;
601 601
 		$element_list = array();
@@ -628,10 +628,10 @@  discard block
 block discarded – undo
628 628
 		// return $attribute_unit_group_list;
629 629
 	}
630 630
 	/**
631
-	*	Return the list page content, containing the table that present the item list
632
-	*
633
-	*	@return string $listItemOutput The html code that output the item list
634
-	*/
631
+	 *	Return the list page content, containing the table that present the item list
632
+	 *
633
+	 *	@return string $listItemOutput The html code that output the item list
634
+	 */
635 635
 	public static function unit_group_list(){
636 636
 		$listItemOutput = '';
637 637
 
@@ -740,10 +740,10 @@  discard block
 block discarded – undo
740 740
 		return $listItemOutput;
741 741
 	}
742 742
 	/**
743
-	*	Return the page content to add a new item
744
-	*
745
-	*	@return string The html code that output the interface for adding a nem item
746
-	*/
743
+	 *	Return the page content to add a new item
744
+	 *
745
+	 *	@return string The html code that output the interface for adding a nem item
746
+	 */
747 747
 	public static function unit_group_edition($itemToEdit = ''){
748 748
 		global $attribute_displayed_field;
749 749
 		$dbFieldList = wpshop_database::fields_to_input(WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
Please login to merge, or discard this patch.
wpshop.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
 }
108 108
 // Start session
109 109
 if(session_id() == '')
110
-     session_start();
110
+	 session_start();
111 111
 
112 112
 // WP-Shop class instanciation
113 113
 function classes_init() {
Please login to merge, or discard this patch.