Completed
Push — master ( 5987fc...959a28 )
by
unknown
13:59
created
includes/modules/wps_customer/controller/wps_customer_ctr.php 2 patches
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.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                             $company_value = $wpdb->get_var($query);
141 141
                         }
142 142
                     }
143
-                    ob_start();?>
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>
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         }
323 323
         $user_id = $post->post_author;
324 324
         $user_info = array();
325
-        $attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
325
+        $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array();
326 326
         if (!empty($attribute)) {
327 327
             foreach ($attribute as $type => $attributes) {
328 328
                 foreach ($attributes as $meta => $attribute) {
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             }
379 379
         }
380 380
         $user_info = array_merge($attributes_default, $user_info);
381
-		add_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) );
381
+		add_filter('send_password_change_email', array(get_class(), 'prevent_send_mail_from_wordpress'));
382 382
         foreach ($user_info as $user_meta => $user_meta_value) {
383 383
             $attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code');
384 384
             if (!empty($attribute_def)) {
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
                 }
425 425
             }
426 426
         }
427
-		remove_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) );
427
+		remove_filter('send_password_change_email', array(get_class(), 'prevent_send_mail_from_wordpress'));
428 428
     }
429 429
 
430 430
     /**
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
      */
627 627
     public static function get_customer_id_by_author_id($author_id)
628 628
     {
629
-		if( !isset( self::$customer_user_identifier_cache[$author_id] ) ) {
629
+		if (!isset(self::$customer_user_identifier_cache[$author_id])) {
630 630
 	        global $wpdb;
631 631
 	        $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
632 632
 	        self::$customer_user_identifier_cache[$author_id] = $wpdb->get_var($query);
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
     public static function get_author_id_by_customer_id($customer_id)
646 646
     {
647 647
 		$flipped = array_flip(self::$customer_user_identifier_cache);
648
-		if( !isset( $flipped[$customer_id] ) ) {
648
+		if (!isset($flipped[$customer_id])) {
649 649
 	        global $wpdb;
650 650
 			$author_id = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $customer_id));
651 651
 	        self::$customer_user_identifier_cache[$author_id] = $customer_id;
Please login to merge, or discard this patch.
includes/modules/wps_options/controller/wps_display_options_ctr.php 1 patch
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -1,40 +1,40 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'ABSPATH' ) ) { exit;
1
+<?php if (!defined('ABSPATH')) { exit;
2 2
 }
3 3
 class wps_display_options {
4 4
 
5 5
 
6 6
 	function __construct() {
7 7
 
8
-		add_action( 'admin_init', array( $this, 'declare_display_options' ) );
9
-		add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
10
-		add_filter( 'plugin_action_links_' . WPSHOP_PLUGIN_NAME, array( $this, 'plugin_action_links' ) );
8
+		add_action('admin_init', array($this, 'declare_display_options'));
9
+		add_action('admin_enqueue_scripts', array($this, 'add_scripts'));
10
+		add_filter('plugin_action_links_' . WPSHOP_PLUGIN_NAME, array($this, 'plugin_action_links'));
11 11
 		// End if().
12
-		add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts_frontend' ) );
12
+		add_action('wp_enqueue_scripts', array($this, 'add_scripts_frontend'));
13 13
 	}
14 14
 
15
-	function plugin_action_links( $links ) {
15
+	function plugin_action_links($links) {
16 16
 
17 17
 		$action_links = array(
18
-			'settings' => '<a href="' . admin_url( 'admin.php?page=' . WPSHOP_URL_SLUG_OPTION ) . '" aria-label="' . esc_attr__( 'View WPShop settings', 'wpshop' ) . '">' . esc_html__( 'Settings' ) . '</a>',
18
+			'settings' => '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_OPTION) . '" aria-label="' . esc_attr__('View WPShop settings', 'wpshop') . '">' . esc_html__('Settings') . '</a>',
19 19
 		);
20
-		return array_merge( $action_links, $links );
20
+		return array_merge($action_links, $links);
21 21
 	}
22 22
 
23
-	function add_scripts( $hook ) {
23
+	function add_scripts($hook) {
24 24
 
25
-		if ( $hook != 'settings_page_wpshop_option' ) {
25
+		if ($hook != 'settings_page_wpshop_option') {
26 26
 			return;
27 27
 		}
28 28
 
29
-		wp_enqueue_script( 'jquery' );
29
+		wp_enqueue_script('jquery');
30 30
 		// End if().
31
-		wp_enqueue_script( 'iris' );
32
-		wp_enqueue_script( 'wps_options_display_js',  WPS_OPTIONS_URL . WPS_OPTIONS_DIR . '/assets/backend/js/wps_option_display.js', false );
31
+		wp_enqueue_script('iris');
32
+		wp_enqueue_script('wps_options_display_js', WPS_OPTIONS_URL . WPS_OPTIONS_DIR . '/assets/backend/js/wps_option_display.js', false);
33 33
 	}
34 34
 
35 35
 	function add_scripts_frontend() {
36 36
 
37
-		add_action( 'wp_print_scripts', array( $this, 'create_customizing_css_rules' ) );
37
+		add_action('wp_print_scripts', array($this, 'create_customizing_css_rules'));
38 38
 	}
39 39
 
40 40
 
@@ -44,29 +44,29 @@  discard block
 block discarded – undo
44 44
 	function declare_display_options() {
45 45
 
46 46
 		// Frontend display options
47
-		register_setting( 'wpshop_options', 'wpshop_display_option', array( $this, 'display_part_validator' ) );
48
-		add_settings_section( 'wpshop_display_options_sections', '<span class="dashicons dashicons-welcome-view-site"></span>' . __( 'Display options', 'wpshop' ), array( $this, 'frontend_display_part_explanation' ), 'wpshop_display_option' );
47
+		register_setting('wpshop_options', 'wpshop_display_option', array($this, 'display_part_validator'));
48
+		add_settings_section('wpshop_display_options_sections', '<span class="dashicons dashicons-welcome-view-site"></span>' . __('Display options', 'wpshop'), array($this, 'frontend_display_part_explanation'), 'wpshop_display_option');
49 49
 		// Add the different field option for frontend
50
-		add_settings_field( 'wpshop_display_cat_sheet_output', __( 'Display type for category page', 'wpshop' ), array( $this, 'wpshop_display_cat_sheet_output' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
51
-		add_settings_field( 'wpshop_display_list_type', __( 'Display type for element list', 'wpshop' ), array( $this, 'wpshop_display_list_type' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
52
-		add_settings_field( 'wpshop_display_grid_element_number', __( 'Number of element by line for grid mode', 'wpshop' ), array( $this, 'wpshop_display_grid_element_number' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
53
-		add_settings_field( 'wpshop_display_element_per_page', __( 'Number of element per page', 'wpshop' ), array( $this, 'wpshop_display_element_per_page' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
54
-		add_settings_field( 'wpshop_display_latest_products_ordered', __( 'Number of element in "latest products ordered" part', 'wpshop' ), array( $this, 'wpshop_display_latest_products_ordered' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
55
-		add_settings_field( 'wpshop_hide_admin_bar', __( 'Hide Wordpress Admin Bar for customers', 'wpshop' ), array( $this, 'wpshop_hide_admin_bar' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
56
-		add_settings_field( 'wpshop_display_delete_order', __( 'Display delete order for customers', 'wpshop' ), array( $this, 'wpshop_display_delete_order' ), 'wpshop_display_option', 'wpshop_display_options_sections' );
50
+		add_settings_field('wpshop_display_cat_sheet_output', __('Display type for category page', 'wpshop'), array($this, 'wpshop_display_cat_sheet_output'), 'wpshop_display_option', 'wpshop_display_options_sections');
51
+		add_settings_field('wpshop_display_list_type', __('Display type for element list', 'wpshop'), array($this, 'wpshop_display_list_type'), 'wpshop_display_option', 'wpshop_display_options_sections');
52
+		add_settings_field('wpshop_display_grid_element_number', __('Number of element by line for grid mode', 'wpshop'), array($this, 'wpshop_display_grid_element_number'), 'wpshop_display_option', 'wpshop_display_options_sections');
53
+		add_settings_field('wpshop_display_element_per_page', __('Number of element per page', 'wpshop'), array($this, 'wpshop_display_element_per_page'), 'wpshop_display_option', 'wpshop_display_options_sections');
54
+		add_settings_field('wpshop_display_latest_products_ordered', __('Number of element in "latest products ordered" part', 'wpshop'), array($this, 'wpshop_display_latest_products_ordered'), 'wpshop_display_option', 'wpshop_display_options_sections');
55
+		add_settings_field('wpshop_hide_admin_bar', __('Hide Wordpress Admin Bar for customers', 'wpshop'), array($this, 'wpshop_hide_admin_bar'), 'wpshop_display_option', 'wpshop_display_options_sections');
56
+		add_settings_field('wpshop_display_delete_order', __('Display delete order for customers', 'wpshop'), array($this, 'wpshop_display_delete_order'), 'wpshop_display_option', 'wpshop_display_options_sections');
57 57
 		// Customize WPShop display part
58
-		register_setting( 'wpshop_options', 'wpshop_customize_display_option', array( $this, 'customize_color_validator' ) );
59
-		add_settings_section( 'wpshop_customize_wpshop_display_option', '<span class="dashicons dashicons-admin-appearance"></span>' . __( 'Customize your WPShop', 'wpshop' ), array( $this, 'customize_wpshop_colors_explanation' ), 'wpshop_customize_display_option' );
60
-		add_settings_field( 'wpshop_customize_first_button_field', __( 'Change the principal button style', 'wpshop' ), array( $this, 'wps_customize_first_button_style' ), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option' );
61
-		add_settings_field( 'wpshop_customize_second_button_field', __( 'Change the second button style', 'wpshop' ), array( $this, 'wps_customize_second_button_style' ), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option' );
62
-		add_settings_field( 'wpshop_customize_account_field', __( 'Change the customer account elements style', 'wpshop' ), array( $this, 'wps_customize_account_style' ), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option' );
63
-		add_settings_field( 'wpshop_customize_shipping_list_field', __( 'Change The shipping mode choice element style', 'wpshop' ), array( $this, 'wps_customize_shipping_style' ), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option' );
58
+		register_setting('wpshop_options', 'wpshop_customize_display_option', array($this, 'customize_color_validator'));
59
+		add_settings_section('wpshop_customize_wpshop_display_option', '<span class="dashicons dashicons-admin-appearance"></span>' . __('Customize your WPShop', 'wpshop'), array($this, 'customize_wpshop_colors_explanation'), 'wpshop_customize_display_option');
60
+		add_settings_field('wpshop_customize_first_button_field', __('Change the principal button style', 'wpshop'), array($this, 'wps_customize_first_button_style'), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option');
61
+		add_settings_field('wpshop_customize_second_button_field', __('Change the second button style', 'wpshop'), array($this, 'wps_customize_second_button_style'), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option');
62
+		add_settings_field('wpshop_customize_account_field', __('Change the customer account elements style', 'wpshop'), array($this, 'wps_customize_account_style'), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option');
63
+		add_settings_field('wpshop_customize_shipping_list_field', __('Change The shipping mode choice element style', 'wpshop'), array($this, 'wps_customize_shipping_style'), 'wpshop_customize_display_option', 'wpshop_customize_wpshop_display_option');
64 64
 		// Admin (Back-end) display options
65
-		register_setting( 'wpshop_options', 'wpshop_admin_display_option', array( $this, 'admin_part_validator' ) );
66
-		add_settings_section( 'wpshop_admin_display_options_sections', '<span class="dashicons dashicons-desktop"></span>' . __( 'Admin display options', 'wpshop' ), array( $this, 'admin_part_explanation' ), 'wpshop_admin_display_option' );
67
-		add_settings_field( 'wpshop_admin_display_attribute_set_layout', __( 'Attribute set page layout', 'wpshop' ), array( $this, 'wpshop_admin_display_attr_set_layout' ), 'wpshop_admin_display_option', 'wpshop_admin_display_options_sections' );
68
-		add_settings_field( 'wpshop_admin_display_attribute_layout', __( 'Attribute page layout', 'wpshop' ), array( $this, 'wpshop_admin_display_attr_layout' ), 'wpshop_admin_display_option', 'wpshop_admin_display_options_sections' );
69
-		add_settings_field( 'wpshop_admin_display_shortcode_product', __( 'Shortcode display in product page', 'wpshop' ), array( $this, 'wpshop_admin_display_shortcode_in_product_page' ), 'wpshop_admin_display_option', 'wpshop_admin_display_options_sections' );
65
+		register_setting('wpshop_options', 'wpshop_admin_display_option', array($this, 'admin_part_validator'));
66
+		add_settings_section('wpshop_admin_display_options_sections', '<span class="dashicons dashicons-desktop"></span>' . __('Admin display options', 'wpshop'), array($this, 'admin_part_explanation'), 'wpshop_admin_display_option');
67
+		add_settings_field('wpshop_admin_display_attribute_set_layout', __('Attribute set page layout', 'wpshop'), array($this, 'wpshop_admin_display_attr_set_layout'), 'wpshop_admin_display_option', 'wpshop_admin_display_options_sections');
68
+		add_settings_field('wpshop_admin_display_attribute_layout', __('Attribute page layout', 'wpshop'), array($this, 'wpshop_admin_display_attr_layout'), 'wpshop_admin_display_option', 'wpshop_admin_display_options_sections');
69
+		add_settings_field('wpshop_admin_display_shortcode_product', __('Shortcode display in product page', 'wpshop'), array($this, 'wpshop_admin_display_shortcode_in_product_page'), 'wpshop_admin_display_option', 'wpshop_admin_display_options_sections');
70 70
 	}
71 71
 
72 72
 	/**
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	 * @param array $input
84 84
 	 * @return array
85 85
 	 */
86
-	function display_part_validator( $input ) {
86
+	function display_part_validator($input) {
87 87
 
88 88
 		$newinput['wpshop_display_list_type'] = $input['wpshop_display_list_type'];
89
-		if ( $input['wpshop_display_grid_element_number'] < WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MIN_RANGE ) {
89
+		if ($input['wpshop_display_grid_element_number'] < WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MIN_RANGE) {
90 90
 			$input['wpshop_display_grid_element_number'] = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MIN_RANGE;
91
-		} elseif ( $input['wpshop_display_grid_element_number'] > WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MAX_RANGE ) {
91
+		} elseif ($input['wpshop_display_grid_element_number'] > WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MAX_RANGE) {
92 92
 			$input['wpshop_display_grid_element_number'] = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MAX_RANGE;
93 93
 		}
94 94
 		$newinput['wpshop_display_grid_element_number'] = $input['wpshop_display_grid_element_number'];
95 95
 		$newinput['wpshop_display_cat_sheet_output'] = $input['wpshop_display_cat_sheet_output'];
96
-		$newinput['wpshop_display_element_per_page'] = ! empty( $input['wpshop_display_element_per_page'] ) ? $input['wpshop_display_element_per_page'] : '';
96
+		$newinput['wpshop_display_element_per_page'] = !empty($input['wpshop_display_element_per_page']) ? $input['wpshop_display_element_per_page'] : '';
97 97
 		$newinput['latest_products_ordered'] = $input['latest_products_ordered'];
98
-		$newinput['wpshop_hide_admin_bar'] = ! empty( $input['wpshop_hide_admin_bar'] ) ? $input['wpshop_hide_admin_bar'] : '';
99
-		$newinput['wpshop_display_delete_order'] = ! empty( $input['wpshop_display_delete_order'] ) ? $input['wpshop_display_delete_order'] : '';
98
+		$newinput['wpshop_hide_admin_bar'] = !empty($input['wpshop_hide_admin_bar']) ? $input['wpshop_hide_admin_bar'] : '';
99
+		$newinput['wpshop_display_delete_order'] = !empty($input['wpshop_display_delete_order']) ? $input['wpshop_display_delete_order'] : '';
100 100
 		return $newinput;
101 101
 	}
102 102
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	function frontend_display_part_explanation() {
107 107
 
108
-		_e( 'Manage here your frontend display options', 'wpshop' );
108
+		_e('Manage here your frontend display options', 'wpshop');
109 109
 	}
110 110
 
111 111
 	/**
@@ -113,39 +113,39 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	function wpshop_display_cat_sheet_output() {
115 115
 
116
-		$wpshop_display_option = get_option( 'wpshop_display_option' );
116
+		$wpshop_display_option = get_option('wpshop_display_option');
117 117
 		$field_identifier = 'wpshop_display_cat_sheet_output';
118
-		if ( current_user_can( 'wpshop_edit_options' ) ) {
119
-			$content = array( 'category_description', 'category_subcategory', 'category_subproduct' );
118
+		if (current_user_can('wpshop_edit_options')) {
119
+			$content = array('category_description', 'category_subcategory', 'category_subproduct');
120 120
 			$option_field_output = '';
121
-			foreach ( $content as $content_definition ) {
122
-				$current_value = (is_array( $wpshop_display_option['wpshop_display_cat_sheet_output'] ) && in_array( $content_definition, $wpshop_display_option['wpshop_display_cat_sheet_output'] )) || ! is_array( $wpshop_display_option['wpshop_display_cat_sheet_output'] ) ? $content_definition : '';
123
-				switch ( $content_definition ) {
121
+			foreach ($content as $content_definition) {
122
+				$current_value = (is_array($wpshop_display_option['wpshop_display_cat_sheet_output']) && in_array($content_definition, $wpshop_display_option['wpshop_display_cat_sheet_output'])) || !is_array($wpshop_display_option['wpshop_display_cat_sheet_output']) ? $content_definition : '';
123
+				switch ($content_definition) {
124 124
 					case 'category_description':
125 125
 						{
126
-							$field_label = __( 'Display product category description', 'wpshop' );
126
+							$field_label = __('Display product category description', 'wpshop');
127 127
 					}
128 128
 						break;
129 129
 					case 'category_subcategory':
130 130
 						{
131
-							$field_label = __( 'Display sub categories listing', 'wpshop' );
131
+							$field_label = __('Display sub categories listing', 'wpshop');
132 132
 					}
133 133
 						break;
134 134
 					case 'category_subproduct':
135 135
 						{
136
-							$field_label = __( 'Display products listing', 'wpshop' );
136
+							$field_label = __('Display products listing', 'wpshop');
137 137
 					}
138 138
 						break;
139 139
 					default:
140 140
 						{
141
-							$field_label = __( 'Nothing defined here', 'wpshop' );
141
+							$field_label = __('Nothing defined here', 'wpshop');
142 142
 					}
143 143
 						break;
144 144
 				}
145
-				$option_field_output .= wpshop_form::form_input_check( 'wpshop_display_option[' . $field_identifier . '][]', $field_identifier . '_' . $content_definition, $content_definition, $current_value, 'checkbox' ) . '<label for="' . $field_identifier . '_' . $content_definition . '" >' . $field_label . '</label><br/>';
145
+				$option_field_output .= wpshop_form::form_input_check('wpshop_display_option[' . $field_identifier . '][]', $field_identifier . '_' . $content_definition, $content_definition, $current_value, 'checkbox') . '<label for="' . $field_identifier . '_' . $content_definition . '" >' . $field_label . '</label><br/>';
146 146
 			}
147 147
 		} else {
148
-			$option_field_output = $wpshop_display_option[ $field_identifier ];
148
+			$option_field_output = $wpshop_display_option[$field_identifier];
149 149
 		}
150 150
 
151 151
 		echo $option_field_output;
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
 	 */
157 157
 	function wpshop_display_list_type() {
158 158
 
159
-		$wpshop_display_option = get_option( 'wpshop_display_option' );
159
+		$wpshop_display_option = get_option('wpshop_display_option');
160 160
 		$field_identifier = 'wpshop_display_list_type';
161
-		if ( current_user_can( 'wpshop_edit_options' ) ) {
162
-			$option_field_output = wpshop_form::form_input_select( 'wpshop_display_option[' . $field_identifier . ']', $field_identifier, array(
163
-				'grid' => __( 'Grid', 'wpshop' ),
164
-				'list' => __( 'List', 'wpshop' ),
165
-			), $wpshop_display_option[ $field_identifier ], '', 'index' );
161
+		if (current_user_can('wpshop_edit_options')) {
162
+			$option_field_output = wpshop_form::form_input_select('wpshop_display_option[' . $field_identifier . ']', $field_identifier, array(
163
+				'grid' => __('Grid', 'wpshop'),
164
+				'list' => __('List', 'wpshop'),
165
+			), $wpshop_display_option[$field_identifier], '', 'index');
166 166
 		} else {
167
-			$option_field_output = $wpshop_display_option[ $field_identifier ];
167
+			$option_field_output = $wpshop_display_option[$field_identifier];
168 168
 		}
169 169
 
170
-		echo $option_field_output . ' <a href="#" title="' . __( 'Default display mode on shop','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
170
+		echo $option_field_output . ' <a href="#" title="' . __('Default display mode on shop', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
171 171
 	}
172 172
 
173 173
 	/**
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 	 */
176 176
 	function wpshop_display_grid_element_number() {
177 177
 
178
-		$wpshop_display_option = get_option( 'wpshop_display_option' );
178
+		$wpshop_display_option = get_option('wpshop_display_option');
179 179
 		$field_identifier = 'wpshop_display_grid_element_number';
180
-		require( wpshop_tools::get_template_part( WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_grid_field' ) );
180
+		require(wpshop_tools::get_template_part(WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_grid_field'));
181 181
 	}
182 182
 
183 183
 	/**
@@ -185,15 +185,15 @@  discard block
 block discarded – undo
185 185
 	 */
186 186
 	function wpshop_display_element_per_page() {
187 187
 
188
-		$wpshop_display_option = get_option( 'wpshop_display_option' );
188
+		$wpshop_display_option = get_option('wpshop_display_option');
189 189
 		$field_identifier = 'wpshop_display_element_per_page';
190
-		if ( current_user_can( 'wpshop_edit_options' ) ) {
191
-			$option_field_output = wpshop_form::form_input( 'wpshop_display_option[' . $field_identifier . ']', $field_identifier, ! empty( $wpshop_display_option[ $field_identifier ] ) ? $wpshop_display_option[ $field_identifier ] : 20, 'text' );
190
+		if (current_user_can('wpshop_edit_options')) {
191
+			$option_field_output = wpshop_form::form_input('wpshop_display_option[' . $field_identifier . ']', $field_identifier, !empty($wpshop_display_option[$field_identifier]) ? $wpshop_display_option[$field_identifier] : 20, 'text');
192 192
 		} else {
193
-			$option_field_output = $wpshop_display_option[ $field_identifier ];
193
+			$option_field_output = $wpshop_display_option[$field_identifier];
194 194
 		}
195 195
 
196
-		echo $option_field_output . ' <a href="#" title="' . __( 'Number of elements per page','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
196
+		echo $option_field_output . ' <a href="#" title="' . __('Number of elements per page', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
197 197
 	}
198 198
 
199 199
 	/**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 	 */
202 202
 	function wpshop_display_latest_products_ordered() {
203 203
 
204
-		$display_option = get_option( 'wpshop_display_option' );
205
-		$output = '<input type="text" value="' . ( ( ! empty( $display_option ) && ! empty( $display_option['latest_products_ordered'] ) ) ? $display_option['latest_products_ordered'] : '') . '" name="wpshop_display_option[latest_products_ordered]" id="wpshop_display_latest_products_ordered" />';
204
+		$display_option = get_option('wpshop_display_option');
205
+		$output = '<input type="text" value="' . ((!empty($display_option) && !empty($display_option['latest_products_ordered'])) ? $display_option['latest_products_ordered'] : '') . '" name="wpshop_display_option[latest_products_ordered]" id="wpshop_display_latest_products_ordered" />';
206 206
 		echo $output;
207 207
 	}
208 208
 
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	 */
212 212
 	function wpshop_hide_admin_bar() {
213 213
 
214
-		$wpshop_hide_admin_bar_option = get_option( 'wpshop_display_option' );
215
-		$output = '<input type="checkbox" name="wpshop_display_option[wpshop_hide_admin_bar]" ' . ( ( ! empty( $wpshop_hide_admin_bar_option ) && ! empty( $wpshop_hide_admin_bar_option['wpshop_hide_admin_bar'] ) ) ? 'checked="checked"' : '') . '/>';
214
+		$wpshop_hide_admin_bar_option = get_option('wpshop_display_option');
215
+		$output = '<input type="checkbox" name="wpshop_display_option[wpshop_hide_admin_bar]" ' . ((!empty($wpshop_hide_admin_bar_option) && !empty($wpshop_hide_admin_bar_option['wpshop_hide_admin_bar'])) ? 'checked="checked"' : '') . '/>';
216 216
 		echo $output;
217 217
 	}
218 218
 
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 	 */
222 222
 	public function wpshop_display_delete_order() {
223 223
 
224
-		$wpshop_display_delete_order_option = get_option( 'wpshop_display_option' );
225
-		$output = '<input type="checkbox" name="wpshop_display_option[wpshop_display_delete_order]" ' . ( ( ! empty( $wpshop_display_delete_order_option ) && ! empty( $wpshop_display_delete_order_option['wpshop_display_delete_order'] ) ) ? 'checked="checked"' : '') . '/>';
224
+		$wpshop_display_delete_order_option = get_option('wpshop_display_option');
225
+		$output = '<input type="checkbox" name="wpshop_display_option[wpshop_display_delete_order]" ' . ((!empty($wpshop_display_delete_order_option) && !empty($wpshop_display_delete_order_option['wpshop_display_delete_order'])) ? 'checked="checked"' : '') . '/>';
226 226
 		echo $output;
227 227
 	}
228 228
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 * @param array $input
242 242
 	 * @return array
243 243
 	 */
244
-	function customize_color_validator( $input ) {
244
+	function customize_color_validator($input) {
245 245
 
246 246
 		return $input;
247 247
 	}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 */
252 252
 	function customize_wpshop_colors_explanation() {
253 253
 
254
-		_e( 'Here, you can customize your WPShop elements like buttons, customer account parts and selected shipping method colors...', 'wpshop' );
254
+		_e('Here, you can customize your WPShop elements like buttons, customer account parts and selected shipping method colors...', 'wpshop');
255 255
 	}
256 256
 
257 257
 	/**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	function wps_customize_first_button_style() {
261 261
 
262
-		$wpshop_customize_display_option = get_option( 'wpshop_customize_display_option' );
263
-		require( wpshop_tools::get_template_part( WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_first_button' ) );
262
+		$wpshop_customize_display_option = get_option('wpshop_customize_display_option');
263
+		require(wpshop_tools::get_template_part(WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_first_button'));
264 264
 	}
265 265
 
266 266
 	/**
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 	 */
269 269
 	function wps_customize_second_button_style() {
270 270
 
271
-		$wpshop_customize_display_option = get_option( 'wpshop_customize_display_option' );
272
-		require( wpshop_tools::get_template_part( WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_second_button' ) );
271
+		$wpshop_customize_display_option = get_option('wpshop_customize_display_option');
272
+		require(wpshop_tools::get_template_part(WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_second_button'));
273 273
 	}
274 274
 
275 275
 	/**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 */
278 278
 	function wps_customize_account_style() {
279 279
 
280
-		$wpshop_customize_display_option = get_option( 'wpshop_customize_display_option' );
281
-		require( wpshop_tools::get_template_part( WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_customer_account' ) );
280
+		$wpshop_customize_display_option = get_option('wpshop_customize_display_option');
281
+		require(wpshop_tools::get_template_part(WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_customer_account'));
282 282
 	}
283 283
 
284 284
 	/**
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	function wps_customize_shipping_style() {
288 288
 
289
-		$wpshop_customize_display_option = get_option( 'wpshop_customize_display_option' );
290
-		require( wpshop_tools::get_template_part( WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_shipping_list' ) );
289
+		$wpshop_customize_display_option = get_option('wpshop_customize_display_option');
290
+		require(wpshop_tools::get_template_part(WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'backend', 'wps_display_options_customize_shipping_list'));
291 291
 	}
292 292
 
293 293
 	/**
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	function create_customizing_css_rules() {
297 297
 
298
-		$wpshop_customize_display_option = get_option( 'wpshop_customize_display_option' );
299
-		require( wpshop_tools::get_template_part( WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'frontend', 'wps_display_options_customize_css_rules' ) );
298
+		$wpshop_customize_display_option = get_option('wpshop_customize_display_option');
299
+		require(wpshop_tools::get_template_part(WPS_OPTIONS_DIR, WPS_OPTIONS_TEMPLATE_DIR, 'frontend', 'wps_display_options_customize_css_rules'));
300 300
 	}
301 301
 
302 302
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 * @param array $input
315 315
 	 * @return array
316 316
 	 */
317
-	function admin_part_validator( $input ) {
317
+	function admin_part_validator($input) {
318 318
 
319 319
 		return $input;
320 320
 	}
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	 */
325 325
 	function admin_part_explanation() {
326 326
 
327
-		_e( 'You can defined some parameters for admin display', 'wpshop' );
327
+		_e('You can defined some parameters for admin display', 'wpshop');
328 328
 	}
329 329
 
330 330
 	/**
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
 
335 335
 		global $attribute_page_layout_types;
336 336
 		$field_identifier = 'wpshop_admin_attr_set_layout';
337
-		$wpshop_admin_display_option = get_option( 'wpshop_admin_display_option', array() );
338
-		if ( current_user_can( 'wpshop_edit_options' ) ) {
339
-			$option_field_output = wpshop_form::form_input_select( 'wpshop_admin_display_option[' . $field_identifier . ']', $field_identifier, $attribute_page_layout_types, WPSHOP_ATTRIBUTE_SET_EDITION_PAGE_LAYOUT, '', 'index' );
340
-		} else { $option_field_output = $wpshop_admin_display_option[ $field_identifier ];
337
+		$wpshop_admin_display_option = get_option('wpshop_admin_display_option', array());
338
+		if (current_user_can('wpshop_edit_options')) {
339
+			$option_field_output = wpshop_form::form_input_select('wpshop_admin_display_option[' . $field_identifier . ']', $field_identifier, $attribute_page_layout_types, WPSHOP_ATTRIBUTE_SET_EDITION_PAGE_LAYOUT, '', 'index');
340
+		} else { $option_field_output = $wpshop_admin_display_option[$field_identifier];
341 341
 		}
342 342
 
343
-		echo $option_field_output . ' <a href="#" title="' . __( 'Define if the attribute set edition page is displayed as tab or as separated bloc','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
343
+		echo $option_field_output . ' <a href="#" title="' . __('Define if the attribute set edition page is displayed as tab or as separated bloc', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
344 344
 	}
345 345
 
346 346
 	/**
@@ -350,13 +350,13 @@  discard block
 block discarded – undo
350 350
 
351 351
 		global $attribute_page_layout_types;
352 352
 		$field_identifier = 'wpshop_admin_attr_layout';
353
-		$wpshop_admin_display_option = get_option( 'wpshop_admin_display_option', array() );
354
-		if ( current_user_can( 'wpshop_edit_options' ) ) {
355
-			$option_field_output = wpshop_form::form_input_select( 'wpshop_admin_display_option[' . $field_identifier . ']', $field_identifier, $attribute_page_layout_types, WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT, '', 'index' );
356
-		} else { $option_field_output = $wpshop_admin_display_option[ $field_identifier ];
353
+		$wpshop_admin_display_option = get_option('wpshop_admin_display_option', array());
354
+		if (current_user_can('wpshop_edit_options')) {
355
+			$option_field_output = wpshop_form::form_input_select('wpshop_admin_display_option[' . $field_identifier . ']', $field_identifier, $attribute_page_layout_types, WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT, '', 'index');
356
+		} else { $option_field_output = $wpshop_admin_display_option[$field_identifier];
357 357
 		}
358 358
 
359
-		echo $option_field_output . ' <a href="#" title="' . __( 'Define if the attribute edition page is displayed as tab or as separated bloc','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
359
+		echo $option_field_output . ' <a href="#" title="' . __('Define if the attribute edition page is displayed as tab or as separated bloc', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
360 360
 	}
361 361
 
362 362
 	/**
@@ -366,12 +366,12 @@  discard block
 block discarded – undo
366 366
 
367 367
 		global $product_page_layout_types;
368 368
 		$field_identifier = 'wpshop_admin_product_shortcode_display';
369
-		$wpshop_admin_display_option = get_option( 'wpshop_admin_display_option', array() );
370
-		if ( current_user_can( 'wpshop_edit_options' ) ) {
371
-			$option_field_output = wpshop_form::form_input_select( 'wpshop_admin_display_option[' . $field_identifier . ']', $field_identifier, $product_page_layout_types, WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE, '', 'index' );
372
-		} else { $option_field_output = $wpshop_admin_display_option[ $field_identifier ];
369
+		$wpshop_admin_display_option = get_option('wpshop_admin_display_option', array());
370
+		if (current_user_can('wpshop_edit_options')) {
371
+			$option_field_output = wpshop_form::form_input_select('wpshop_admin_display_option[' . $field_identifier . ']', $field_identifier, $product_page_layout_types, WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE, '', 'index');
372
+		} else { $option_field_output = $wpshop_admin_display_option[$field_identifier];
373 373
 		}
374 374
 
375
-		echo $option_field_output . ' <a href="#" title="' . __( 'Define how to display the shortcode summary in product edition page','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
375
+		echo $option_field_output . ' <a href="#" title="' . __('Define how to display the shortcode summary in product edition page', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
376 376
 	}
377 377
 }
Please login to merge, or discard this patch.
includes/librairies/options/options_email.class.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'ABSPATH' ) ) { exit;
1
+<?php if (!defined('ABSPATH')) { exit;
2 2
 }
3 3
 
4 4
 // End if().
5
-if ( ! defined( 'WPSHOP_VERSION' ) ) {
6
-	die( __( 'Access is not allowed by this way', 'wpshop' ) );
5
+if (!defined('WPSHOP_VERSION')) {
6
+	die(__('Access is not allowed by this way', 'wpshop'));
7 7
 }
8 8
 
9 9
 /**
@@ -32,23 +32,23 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public static function declare_options() {
34 34
 
35
-		add_settings_section( 'wpshop_emails', '<span class="dashicons dashicons-email"></span>' . __( 'Email addresses', 'wpshop' ), array( 'wpshop_email_options', 'plugin_section_text' ), 'wpshop_emails' );
36
-		register_setting( 'wpshop_options', 'wpshop_emails', array( 'wpshop_email_options', 'wpshop_options_validate_emails' ) );
37
-		add_settings_field( 'wpshop_noreply_email', __( 'Mails answers address email', 'wpshop' ), array( 'wpshop_email_options', 'wpshop_noreply_email_field' ), 'wpshop_emails', 'wpshop_emails' );
38
-		add_settings_field( 'wpshop_contact_email', __( 'Contact email', 'wpshop' ), array( 'wpshop_email_options', 'wpshop_contact_email_field' ), 'wpshop_emails', 'wpshop_emails' );
39
-		add_settings_field( 'wpshop_send_confirmation_order_email', '', array( 'wpshop_email_options', 'wpshop_send_confirmation_order_message_field' ), 'wpshop_emails', 'wpshop_emails' );
35
+		add_settings_section('wpshop_emails', '<span class="dashicons dashicons-email"></span>' . __('Email addresses', 'wpshop'), array('wpshop_email_options', 'plugin_section_text'), 'wpshop_emails');
36
+		register_setting('wpshop_options', 'wpshop_emails', array('wpshop_email_options', 'wpshop_options_validate_emails'));
37
+		add_settings_field('wpshop_noreply_email', __('Mails answers address email', 'wpshop'), array('wpshop_email_options', 'wpshop_noreply_email_field'), 'wpshop_emails', 'wpshop_emails');
38
+		add_settings_field('wpshop_contact_email', __('Contact email', 'wpshop'), array('wpshop_email_options', 'wpshop_contact_email_field'), 'wpshop_emails', 'wpshop_emails');
39
+		add_settings_field('wpshop_send_confirmation_order_email', '', array('wpshop_email_options', 'wpshop_send_confirmation_order_message_field'), 'wpshop_emails', 'wpshop_emails');
40 40
 		/** Define the settings section for message	*/
41
-		add_settings_section( 'wpshop_messages', '<span class="dashicons dashicons-email-alt"></span>' . __( 'Messages', 'wpshop' ), array( 'wpshop_email_options', 'plugin_section_text' ), 'wpshop_messages' );
41
+		add_settings_section('wpshop_messages', '<span class="dashicons dashicons-email-alt"></span>' . __('Messages', 'wpshop'), array('wpshop_email_options', 'plugin_section_text'), 'wpshop_messages');
42 42
 		/**	Get default messages defined into xml files 	*/
43
-		$xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' );
44
-		$default_emails = new SimpleXMLElement( $xml_default_emails );
43
+		$xml_default_emails = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml');
44
+		$default_emails = new SimpleXMLElement($xml_default_emails);
45 45
 		/**	Read default emails for options creation	*/
46
-		foreach ( $default_emails->xpath( '//emails/email' ) as $email ) {
47
-			if ( ( WPSHOP_DEFINED_SHOP_TYPE == (string) $email->attributes()->shop_type ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) {
48
-				register_setting( 'wpshop_options', (string) $email->attributes()->code, array( 'wpshop_email_options', 'wps_options_validate_emails' ) );
49
-				add_settings_field( (string) $email->attributes()->code, __( (string) $email->description, 'wpshop' ), array( 'wpshop_email_options', 'wps_options_emails_field' ), 'wpshop_messages', 'wpshop_messages', array(
50
-					'code' => (string) $email->attributes()->code,
51
-				) );
46
+		foreach ($default_emails->xpath('//emails/email') as $email) {
47
+			if ((WPSHOP_DEFINED_SHOP_TYPE == (string)$email->attributes()->shop_type) || ('sale' == WPSHOP_DEFINED_SHOP_TYPE)) {
48
+				register_setting('wpshop_options', (string)$email->attributes()->code, array('wpshop_email_options', 'wps_options_validate_emails'));
49
+				add_settings_field((string)$email->attributes()->code, __((string)$email->description, 'wpshop'), array('wpshop_email_options', 'wps_options_emails_field'), 'wpshop_messages', 'wpshop_messages', array(
50
+					'code' => (string)$email->attributes()->code,
51
+				));
52 52
 			}
53 53
 		}
54 54
 	}
@@ -66,33 +66,33 @@  discard block
 block discarded – undo
66 66
 	/* ------------------------ */
67 67
 	public static function wpshop_noreply_email_field() {
68 68
 
69
-		$admin_email = get_bloginfo( 'admin_email' );
70
-		$emails = get_option( 'wpshop_emails', null );
71
-		$email = empty( $emails['noreply_email'] ) ? $admin_email : $emails['noreply_email'];
69
+		$admin_email = get_bloginfo('admin_email');
70
+		$emails = get_option('wpshop_emails', null);
71
+		$email = empty($emails['noreply_email']) ? $admin_email : $emails['noreply_email'];
72 72
 		echo '<input name="wpshop_emails[noreply_email]" type="text" value="' . $email . '" />
73
-		<a href="#" title="' . __( 'This is the no reply email','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
73
+		<a href="#" title="' . __('This is the no reply email', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
74 74
 	}
75 75
 	public static function wpshop_contact_email_field() {
76 76
 
77
-		$admin_email = get_bloginfo( 'admin_email' );
78
-		$emails = get_option( 'wpshop_emails', null );
79
-		$email = empty( $emails['contact_email'] ) ? $admin_email : $emails['contact_email'];
77
+		$admin_email = get_bloginfo('admin_email');
78
+		$emails = get_option('wpshop_emails', null);
79
+		$email = empty($emails['contact_email']) ? $admin_email : $emails['contact_email'];
80 80
 		echo '<input name="wpshop_emails[contact_email]" type="text" value="' . $email . '" />
81
-		<a href="#" title="' . __( 'This is the email on which customers can contact you','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
81
+		<a href="#" title="' . __('This is the email on which customers can contact you', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
82 82
 	}
83
-	public static function wpshop_options_validate_emails( $input ) {
83
+	public static function wpshop_options_validate_emails($input) {
84 84
 		return $input;
85 85
 	}
86 86
 
87 87
 	public static function wpshop_send_confirmation_order_message_field() {
88 88
 
89
-		$email_option = get_option( 'wpshop_emails' );
90
-		$output = '<input type="checkbox" name="wpshop_emails[send_confirmation_order_message]" id="wpshop_emails_send_confirmation_order_message" ' . ( ( ! empty( $email_option ) && ! empty( $email_option['send_confirmation_order_message'] ) ) ? 'checked="checked"' : '') . '/> ';
91
-		$output .= '<label for="wpshop_emails_send_confirmation_order_message">' . __( 'Send confirmation order message when order is totally paid', 'wpshop' ) . '</label>';
89
+		$email_option = get_option('wpshop_emails');
90
+		$output = '<input type="checkbox" name="wpshop_emails[send_confirmation_order_message]" id="wpshop_emails_send_confirmation_order_message" ' . ((!empty($email_option) && !empty($email_option['send_confirmation_order_message'])) ? 'checked="checked"' : '') . '/> ';
91
+		$output .= '<label for="wpshop_emails_send_confirmation_order_message">' . __('Send confirmation order message when order is totally paid', 'wpshop') . '</label>';
92 92
 		echo $output;
93 93
 	}
94 94
 
95
-	function wpshop_send_confirmation_order_message_validate( $input ) {
95
+	function wpshop_send_confirmation_order_message_validate($input) {
96 96
 
97 97
 		return $input;
98 98
 	}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @param unknown_type $input
106 106
 	 * @return unknown
107 107
 	 */
108
-	public static function wps_options_validate_emails( $input ) {
108
+	public static function wps_options_validate_emails($input) {
109 109
 
110 110
 		return $input;
111 111
 	}
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 	 *
115 115
 	 * @param unknown_type $args
116 116
 	 */
117
-	public static function wps_options_emails_field( $args ) {
117
+	public static function wps_options_emails_field($args) {
118 118
 
119 119
 		$content = '';
120
-		$current_message_id = get_option( $args['code'], '' );
120
+		$current_message_id = get_option($args['code'], '');
121 121
 		/*
122 122
 		$wps_message = new wps_message_ctr();
123 123
 		$options = $wps_message->getMessageListOption( $current_message_id );
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			$content .= '</select> <a id="wps-email-' . $current_message_id . '" title="' . __( 'Edit current selected message', 'wpshop' ) . '" href="' . admin_url( 'post.php?post=' . $current_message_id . '&action=edit' ) . '" target="_wps_content_customisation" class="shop-content-customisation shop-content-customisation-email dashicons dashicons-edit"></a>';
129 129
 		}*/
130 130
 
131
-		echo $content . '<a id="wps-email-' . $current_message_id . '" title="' . __( 'Edit current selected message', 'wpshop' ) . '" href="' . admin_url( 'post.php?post=' . $current_message_id . '&action=edit' ) . '" target="_wps_content_customisation" class="shop-content-customisation shop-content-customisation-email dashicons dashicons-edit"></a>';
131
+		echo $content . '<a id="wps-email-' . $current_message_id . '" title="' . __('Edit current selected message', 'wpshop') . '" href="' . admin_url('post.php?post=' . $current_message_id . '&action=edit') . '" target="_wps_content_customisation" class="shop-content-customisation shop-content-customisation-email dashicons dashicons-edit"></a>';
132 132
 	}
133 133
 
134 134
 }
Please login to merge, or discard this patch.
includes/librairies/options/options.class.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 /**
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 		$groups = array();
44 44
 
45 45
 		$groups['wpshop_general_option'] =
46
-			array(	'label' => __('General', 'wpshop'),
46
+			array('label' => __('General', 'wpshop'),
47 47
 					'subgroups' => array(
48 48
 						'wpshop_general_config' => array('class' => 'wpshop_admin_box_options_general'),
49 49
 						'wpshop_company_info' => array('class' => 'wpshop_admin_box_options_company'),
50 50
 					),
51 51
 			);
52 52
 		$groups['wpshop_catalog_option'] =
53
-			array(	'label' => __('Catalog', 'wpshop'),
53
+			array('label' => __('Catalog', 'wpshop'),
54 54
 					'subgroups' => array(
55 55
 						'wpshop_catalog_product_option' => array('class' => ' wpshop_admin_box_options_product'),
56 56
 						'wpshop_catalog_main_option' => array('class' => ' wpshop_admin_box_options_catalog'),
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 					),
59 59
 			);
60 60
 		$groups['wpshop_pages_option'] =
61
-			array(	'label' => __('Pages', 'wpshop'),
61
+			array('label' => __('Pages', 'wpshop'),
62 62
 					'subgroups' => array(
63 63
 						'wpshop_pages_option' => array('class' => ' wpshop_admin_box_options_pages'),
64 64
 					),
65 65
 			);
66 66
 		$groups['wpshop_display_option'] =
67
-			array(	'label' => __('Display', 'wpshop'),
67
+			array('label' => __('Display', 'wpshop'),
68 68
 					'subgroups' => array(
69 69
 						'wpshop_display_option' => array('class' => ' wpshop_admin_box_options_display'),
70 70
 						'wpshop_customize_display_option' => array('class' => ' wpshop_admin_box_options_display'),
@@ -72,32 +72,32 @@  discard block
 block discarded – undo
72 72
 					),
73 73
 			);
74 74
 		$groups['wpshop_emails_option'] =
75
-			array(	'label' => __('Emails', 'wpshop'),
75
+			array('label' => __('Emails', 'wpshop'),
76 76
 					'subgroups' => array(
77 77
 						'wpshop_emails' => array('class' => ' wpshop_admin_box_options_email'),
78 78
 						'wpshop_messages' => array('class' => ' wpshop_admin_box_options_message'),
79 79
 					),
80 80
 			);
81 81
 
82
-		$wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : '';
82
+		$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
83 83
 
84 84
 		/**	Some options are available only when sale mode is active	*/
85
-		if((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation'))) :
85
+		if ((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation'))) :
86 86
 			$groups['wpshop_cart_option'] =
87
-				array(	'label' => __('Cart', 'wpshop'),
87
+				array('label' => __('Cart', 'wpshop'),
88 88
 						'subgroups' => array(
89 89
 							'wpshop_cart_info' => array('class' => ' wpshop_admin_box_options_cart'),
90 90
 						),
91 91
 				);
92 92
 			$groups['wpshop_payments_option'] =
93
-				array(	'label' => __('Payments', 'wpshop'),
93
+				array('label' => __('Payments', 'wpshop'),
94 94
 						'subgroups' => array(
95 95
 							'wpshop_paymentMethod' => array('class' => ' wpshop_admin_box_options_payment_method'),
96 96
 							'wpshop_payment_partial_on_command' => array('class' => ' wpshop_admin_box_options_payment_partial'),
97 97
 						),
98 98
 				);
99 99
 			$groups['wpshop_shipping_option'] =
100
-				array(	'label' => __('Shipping', 'wpshop'),
100
+				array('label' => __('Shipping', 'wpshop'),
101 101
 						'subgroups' => array(
102 102
 							'wpshop_shipping_rules' => array('class' => ' wpshop_admin_box_options_shipping_rules')
103 103
 						),
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 		endif;
106 106
 
107 107
 		$groups['wpshop_addons_option'] =
108
-			array(	'label' => __('Addons', 'wpshop'),
108
+			array('label' => __('Addons', 'wpshop'),
109 109
 					'subgroups' => array(
110 110
 						'wpshop_addons_options' => array('class' => ' wpshop_admin_box_options_addons'),
111 111
 					),
112 112
 			);
113 113
 
114 114
 		$groups['wpshop_advanced_options'] =
115
-			array(	'label' => __('Advanced options', 'wpshop'),
115
+			array('label' => __('Advanced options', 'wpshop'),
116 116
 					'subgroups' => array(
117 117
 						'wpshop_extra_options' => array('class' => ' wpshop_admin_box_options_advanced'),
118 118
 					),
@@ -138,17 +138,17 @@  discard block
 block discarded – undo
138 138
 		ob_end_clean();
139 139
 		$tpl_component['ADMIN_OPTIONS_TAB_LIST'] = '';
140 140
 		$tpl_component['ADMIN_OPTIONS_TAB_CONTENT_LIST'] = '';
141
-		if ( !empty($options_list) ) {
142
-			foreach ( $options_list as $group_key => $group_content) {
141
+		if (!empty($options_list)) {
142
+			foreach ($options_list as $group_key => $group_content) {
143 143
 				$sub_tpl_component = array();
144
-				if ( !empty($group_content['subgroups']) && is_array($group_content['subgroups']) ) {
144
+				if (!empty($group_content['subgroups']) && is_array($group_content['subgroups'])) {
145 145
 					$sub_tpl_component['ADMIN_OPTIONS_GROUP_CONTENT'] = '';
146 146
 					$sub_tpl_component['ADMIN_OPTIONS_TAB_KEY'] = $group_key;
147
-					$sub_tpl_component['ADMIN_OPTIONS_TAB_LABEL'] = ( !empty($group_content['label']) ) ? $group_content['label'] : '';
147
+					$sub_tpl_component['ADMIN_OPTIONS_TAB_LABEL'] = (!empty($group_content['label'])) ? $group_content['label'] : '';
148 148
 					$tpl_component['ADMIN_OPTIONS_TAB_LIST'] .= wpshop_display::display_template_element('wpshop_admin_options_group_tab', $sub_tpl_component, array(), 'admin');
149
-					foreach ( $group_content['subgroups'] as $subgroup_key => $subgroup_def) {
149
+					foreach ($group_content['subgroups'] as $subgroup_key => $subgroup_def) {
150 150
 						ob_start();
151
-						do_settings_sections( $subgroup_key );
151
+						do_settings_sections($subgroup_key);
152 152
 						$sub_tpl_component['ADMIN_OPTIONS_SUBGROUP_CONTENT'] = ob_get_contents();
153 153
 						ob_end_clean();
154 154
 						$sub_tpl_component['ADMIN_OPTIONS_SUBGROUP_CLASS'] = $subgroup_def['class'];
@@ -166,21 +166,21 @@  discard block
 block discarded – undo
166 166
 	/**
167 167
 	*	Declare the different options for the plugin
168 168
 	*/
169
-	public static function add_options(){
169
+	public static function add_options() {
170 170
 		global $wpshop_display_option;
171 171
 
172 172
 
173 173
 		/*Catalog - Main	*/
174 174
 		register_setting('wpshop_options', 'wpshop_catalog_main_option', array('wpshop_options', 'wpshop_options_validate_catalog_main_option'));
175
-			add_settings_section('wpshop_catalog_main_section', '<span class="dashicons dashicons-category"></span>'.__('Catalog', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_catalog_main_option');
175
+			add_settings_section('wpshop_catalog_main_section', '<span class="dashicons dashicons-category"></span>' . __('Catalog', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_catalog_main_option');
176 176
 				add_settings_field('wpshop_catalog_empty_price_behaviour', __('Empty price', 'wpshop'), array('wpshop_options', 'wpshop_catalog_empty_price_behaviour'), 'wpshop_catalog_main_option', 'wpshop_catalog_main_section');
177 177
 		/* Catalog - Product */
178 178
 		register_setting('wpshop_options', 'wpshop_catalog_product_option', array('wpshop_options', 'wpshop_options_validate_catalog_product_option'));
179
-			add_settings_section('wpshop_catalog_product_section', '<span class="dashicons dashicons-archive"></span>'.__('Products', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_catalog_product_option');
179
+			add_settings_section('wpshop_catalog_product_section', '<span class="dashicons dashicons-archive"></span>' . __('Products', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_catalog_product_option');
180 180
 				add_settings_field('wpshop_catalog_product_slug', __('Products common rewrite param', 'wpshop'), array('wpshop_options', 'wpshop_catalog_product_slug_field'), 'wpshop_catalog_product_option', 'wpshop_catalog_product_section');
181 181
 		/* Catalog - Categories */
182 182
 		register_setting('wpshop_options', 'wpshop_catalog_categories_option', array('wpshop_options', 'wpshop_options_validate_catalog_categories_option'));
183
-		add_settings_section('wpshop_catalog_categories_section', '<span class="dashicons dashicons-portfolio"></span>'.__('Categories', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_catalog_categories_option');
183
+		add_settings_section('wpshop_catalog_categories_section', '<span class="dashicons dashicons-portfolio"></span>' . __('Categories', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_catalog_categories_option');
184 184
 		add_settings_field('wpshop_catalog_categories_slug', __('Categories common rewrite param', 'wpshop'), array('wpshop_options', 'wpshop_catalog_categories_slug_field'), 'wpshop_catalog_categories_option', 'wpshop_catalog_categories_section');
185 185
 		add_settings_field('wpshop_catalog_no_category_slug', __('Default category slug for unassociated product', 'wpshop'), array('wpshop_options', 'wpshop_catalog_no_category_slug_field'), 'wpshop_catalog_categories_option', 'wpshop_catalog_categories_section');
186 186
 
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
 		wpshop_company_options::declare_options();
192 192
 
193 193
 		/* Payments */
194
-		$wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : '';
195
-		$old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : '';
196
-		if((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation')) && !isset($old_wpshop_shop_type) || (isset($old_wpshop_shop_type) && ($old_wpshop_shop_type != 'presentation'))){
194
+		$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
195
+		$old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
196
+		if ((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation')) && !isset($old_wpshop_shop_type) || (isset($old_wpshop_shop_type) && ($old_wpshop_shop_type != 'presentation'))) {
197 197
 			wpshop_payment_options::declare_options();
198 198
 		}
199 199
 
200 200
 		/* Cart */
201
-		if((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation')) && !isset($old_wpshop_shop_type) || (isset($old_wpshop_shop_type) && ($old_wpshop_shop_type != 'presentation'))){
201
+		if ((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation')) && !isset($old_wpshop_shop_type) || (isset($old_wpshop_shop_type) && ($old_wpshop_shop_type != 'presentation'))) {
202 202
 			register_setting('wpshop_options', 'wpshop_cart_option', array('wpshop_options', 'wpshop_options_validate_cart'));
203
-			add_settings_section('wpshop_cart_info', '<span class="dashicons dashicons-cart"></span>'.__('Cart', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_cart_info');
203
+			add_settings_section('wpshop_cart_info', '<span class="dashicons dashicons-cart"></span>' . __('Cart', 'wpshop'), array('wpshop_options', 'plugin_section_text'), 'wpshop_cart_info');
204 204
 			add_settings_field('wpshop_cart_product_added_behaviour', __('Action when produt is added succesfully into cart', 'wpshop'), array('wpshop_options', 'wpshop_cart_product_added_behaviour_field'), 'wpshop_cart_info', 'wpshop_cart_info');
205 205
 			add_settings_field('wpshop_cart_product_added_to_quotation_behaviour', __('Action when produt is added succesfully into a quotation', 'wpshop'), array('wpshop_options', 'wpshop_cart_product_added_to_quotation_behaviour_field'), 'wpshop_cart_info', 'wpshop_cart_info');
206 206
 			add_settings_field('wpshop_cart_total_item_nb', __('Only a limited number of products in cart', 'wpshop'), array('wpshop_options', 'wpshop_cart_total_item_nb_field'), 'wpshop_cart_info', 'wpshop_cart_info');
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		$wpshop_advanced_settings->declare_options();
228 228
 
229 229
 		/* Shipping section */
230
-		if((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation')) && !isset($old_wpshop_shop_type) || (isset($old_wpshop_shop_type) && ($old_wpshop_shop_type != 'presentation'))){
230
+		if ((WPSHOP_DEFINED_SHOP_TYPE == 'sale') && !isset($wpshop_shop_type) || (isset($wpshop_shop_type) && ($wpshop_shop_type != 'presentation')) && !isset($old_wpshop_shop_type) || (isset($old_wpshop_shop_type) && ($old_wpshop_shop_type != 'presentation'))) {
231 231
 		$wpshop_shipping_options = new wpshop_shipping_options();
232 232
 			$wpshop_shipping_options->declare_options();
233 233
 		}
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 		$options = get_option('wpshop_catalog_main_option');
246 246
 		echo '<input type="checkbox"' . (!empty($options['wpshop_catalog_empty_price_behaviour']) ? ' checked="checked" ' : '') . ' value="yes" name="wpshop_catalog_main_option[wpshop_catalog_empty_price_behaviour]" id="wpshop_catalog_empty_price_behaviour" /> <label for="wpshop_catalog_empty_price_behaviour" >' . __('Hide price and add to cart button when price is empty or equal to 0', 'wpshop') . '</label>';
247 247
 	}
248
-	public static function wpshop_catalog_product_slug_field(){
248
+	public static function wpshop_catalog_product_slug_field() {
249 249
 		$options = get_option('wpshop_catalog_product_option');
250 250
 		$catalog_cat_options = get_option('wpshop_catalog_categories_option');
251 251
 		echo '<input type="checkbox"' . (!empty($options['wpshop_catalog_product_slug_with_category']) ? ' checked="checked" ' : '') . ' value="yes" name="wpshop_catalog_product_option[wpshop_catalog_product_slug_with_category]" id="wpshop_catalog_product_slug_with_category" /> <label for="wpshop_catalog_product_slug_with_category">' . __('Use product category in url', 'wpshop') . '</label><br/>
@@ -253,24 +253,24 @@  discard block
 block discarded – undo
253 253
 		<div class="alignleft wpshop_options_catalog_product_rewrite" ><input type="text" name="wpshop_catalog_product_option[wpshop_catalog_product_slug]" value="' . (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : WPSHOP_CATALOG_PRODUCT_SLUG) . '" /></div>
254 254
 		<div class="alignleft wpshop_options_catalog_product_rewrite" ><span class="wpshop_catalog_product_slug_category' . (empty($options['wpshop_catalog_product_slug_with_category']) ? ' disable' : '') . '" >/' . (!empty($catalog_cat_options['wpshop_catalog_categories_slug']) ? $catalog_cat_options['wpshop_catalog_categories_slug'] : WPSHOP_CATALOG_CATEGORIES_SLUG) . '</span></div>
255 255
 		<div class="alignleft wpshop_options_catalog_product_rewrite" >/' . __('Your_product_slug', 'wpshop') . '</div>
256
-		<div class="alignleft" ><a href="#" title="'.__('This slug will be used in url to describe products page','wpshop').'" class="wpshop_infobulle_marker">?</a></div><br /><br />
257
-		<div><span style="color: red;" class="dashicons dashicons-megaphone"></span> '.__('"/" permit to disable slug of products (<b>but don\'t work with rewrites plugins</b>)','wpshop').'</div>';
256
+		<div class="alignleft" ><a href="#" title="'.__('This slug will be used in url to describe products page', 'wpshop') . '" class="wpshop_infobulle_marker">?</a></div><br /><br />
257
+		<div><span style="color: red;" class="dashicons dashicons-megaphone"></span> '.__('"/" permit to disable slug of products (<b>but don\'t work with rewrites plugins</b>)', 'wpshop') . '</div>';
258 258
 	}
259
-	public static function wpshop_catalog_categories_slug_field(){
259
+	public static function wpshop_catalog_categories_slug_field() {
260 260
 		$options = get_option('wpshop_catalog_categories_option');
261 261
 		echo '<input type="text" name="wpshop_catalog_categories_option[wpshop_catalog_categories_slug]" value="' . (!empty($options['wpshop_catalog_categories_slug']) ? $options['wpshop_catalog_categories_slug'] : WPSHOP_CATALOG_CATEGORIES_SLUG) . '" />
262
-		<a href="#" title="'.__('This slug will be used in url to describe catagories page','wpshop').'" class="wpshop_infobulle_marker">?</a>';
262
+		<a href="#" title="'.__('This slug will be used in url to describe catagories page', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
263 263
 	}
264
-	public static function wpshop_catalog_no_category_slug_field(){
264
+	public static function wpshop_catalog_no_category_slug_field() {
265 265
 		$options = get_option('wpshop_catalog_categories_option');
266 266
 		echo '<input type="text" name="wpshop_catalog_categories_option[wpshop_catalog_no_category_slug]" value="' . (!empty($options['wpshop_catalog_no_category_slug']) ? $options['wpshop_catalog_no_category_slug'] : WPSHOP_CATALOG_PRODUCT_NO_CATEGORY) . '" />
267
-		<a href="#" title="'.__('This slug will be used for products not being related to any category ','wpshop').'" class="wpshop_infobulle_marker">?</a>';
267
+		<a href="#" title="'.__('This slug will be used for products not being related to any category ', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
268 268
 	}
269 269
 
270 270
 	/* Processing */
271
-	public static function wpshop_options_validate_catalog_product_option($input){
272
-		foreach($input as $option_key => $option_value){
273
-			switch($option_key){
271
+	public static function wpshop_options_validate_catalog_product_option($input) {
272
+		foreach ($input as $option_key => $option_value) {
273
+			switch ($option_key) {
274 274
 				default:
275 275
 					$new_input[$option_key] = $option_value;
276 276
 				break;
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 
280 280
 		return $new_input;
281 281
 	}
282
-	public static function wpshop_options_validate_catalog_categories_option($input){
283
-		foreach($input as $option_key => $option_value){
284
-			switch($option_key){
282
+	public static function wpshop_options_validate_catalog_categories_option($input) {
283
+		foreach ($input as $option_key => $option_value) {
284
+			switch ($option_key) {
285 285
 				default:
286 286
 					$new_input[$option_key] = $option_value;
287 287
 				break;
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 
291 291
 		return $new_input;
292 292
 	}
293
-	public static function wpshop_options_validate_catalog_main_option($input){
293
+	public static function wpshop_options_validate_catalog_main_option($input) {
294 294
 		$new_input = $input;
295
-		if ( !empty($input) && is_array( $input ) ) {
296
-			foreach($input as $option_key => $option_value){
297
-				switch($option_key){
295
+		if (!empty($input) && is_array($input)) {
296
+			foreach ($input as $option_key => $option_value) {
297
+				switch ($option_key) {
298 298
 					default:
299 299
 						$new_input[$option_key] = $option_value;
300 300
 						break;
@@ -305,16 +305,16 @@  discard block
 block discarded – undo
305 305
 		return $new_input;
306 306
 	}
307 307
 
308
-	public static function wpshop_catalog_varition_product_field () {
308
+	public static function wpshop_catalog_varition_product_field() {
309 309
 		$catalog_product_option = get_option('wpshop_catalog_product_option');
310
-		$output  = '<input type="checkbox" name="wpshop_catalog_product_option[price_display][text_from]" id="wpshop_catalog_product_option_price_display_text_from" ' .( ( !empty($catalog_product_option) && !empty($catalog_product_option['price_display']) && !empty($catalog_product_option['price_display']['text_from']) ) ? 'checked="checked"' : '' ). ' /> ';
311
-		$output .= '<label for="wpshop_catalog_product_option_price_display_text_from">'. __('Display "price from" before basic price of product', 'wpshop').'</label><br/>';
312
-		$output .= '<input type="checkbox" name="wpshop_catalog_product_option[price_display][lower_price]" id="wpshop_catalog_product_option_price_display_lower_price" ' .( ( !empty($catalog_product_option) && !empty($catalog_product_option['price_display']) && !empty($catalog_product_option['price_display']['lower_price']) ) ? 'checked="checked"' : '' ). ' /> ';
313
-		$output .= '<label for="wpshop_catalog_product_option_price_display_lower_price">'. __('Display the lowest price of variation', 'wpshop').'</label>';
310
+		$output  = '<input type="checkbox" name="wpshop_catalog_product_option[price_display][text_from]" id="wpshop_catalog_product_option_price_display_text_from" ' . ((!empty($catalog_product_option) && !empty($catalog_product_option['price_display']) && !empty($catalog_product_option['price_display']['text_from'])) ? 'checked="checked"' : '') . ' /> ';
311
+		$output .= '<label for="wpshop_catalog_product_option_price_display_text_from">' . __('Display "price from" before basic price of product', 'wpshop') . '</label><br/>';
312
+		$output .= '<input type="checkbox" name="wpshop_catalog_product_option[price_display][lower_price]" id="wpshop_catalog_product_option_price_display_lower_price" ' . ((!empty($catalog_product_option) && !empty($catalog_product_option['price_display']) && !empty($catalog_product_option['price_display']['lower_price'])) ? 'checked="checked"' : '') . ' /> ';
313
+		$output .= '<label for="wpshop_catalog_product_option_price_display_lower_price">' . __('Display the lowest price of variation', 'wpshop') . '</label>';
314 314
 		echo $output;
315 315
 	}
316 316
 
317
-	public static function wpshop_catalog_product_variation_option_validate ($input) {
317
+	public static function wpshop_catalog_product_variation_option_validate($input) {
318 318
 		return $input;
319 319
 	}
320 320
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		$input_def['id'] = 'wpshop_cart_option_total_nb_of_item_allowed';
331 331
 		$input_def['type'] = 'text';
332 332
 		$input_def['value'] = !empty($cart_option['total_nb_of_item_allowed']) ? $cart_option['total_nb_of_item_allowed'][0] : '';
333
-		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[total_nb_of_item_allowed]') . '<a href="#" title="'.__('This value count all quantities in cart. Example : 2 products A + 3 products B = 5 products','wpshop').'" class="wpshop_infobulle_marker">?</a>';
333
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[total_nb_of_item_allowed]') . '<a href="#" title="' . __('This value count all quantities in cart. Example : 2 products A + 3 products B = 5 products', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
334 334
 
335 335
 		echo $output;
336 336
 	}
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 		$input_def['id'] = 'wpshop_cart_option_nb_of_same_item_allowed';
344 344
 		$input_def['type'] = 'text';
345 345
 		$input_def['value'] = $cart_option['total_nb_of_same_item_allowed'][0];
346
-		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[total_nb_of_same_item_allowed]') . '<a href="#" title="'.__('Empty for no restriction','wpshop').'" class="wpshop_infobulle_marker">?</a>';
346
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[total_nb_of_same_item_allowed]') . '<a href="#" title="' . __('Empty for no restriction', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
347 347
 
348 348
 		echo $output;
349 349
 	}
@@ -362,11 +362,11 @@  discard block
 block discarded – undo
362 362
 		$input_def['options_label']['container'] = true;
363 363
 		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[product_added_to_cart]');
364 364
 
365
-		$hide = ( (!empty($cart_option) && !empty($cart_option['product_added_to_cart'][0]) && $cart_option['product_added_to_cart'][0] == 'cart_page') ? 'wpshopHide' : null);
366
-		$output .= '<div id="wpshop_cart_option_animation_cart_type" class="' .$hide. '"><label for="wpshop_cart_option[animation_cart_type]">' .__('Cart animation type', 'wpshop'). '</label>';
365
+		$hide = ((!empty($cart_option) && !empty($cart_option['product_added_to_cart'][0]) && $cart_option['product_added_to_cart'][0] == 'cart_page') ? 'wpshopHide' : null);
366
+		$output .= '<div id="wpshop_cart_option_animation_cart_type" class="' . $hide . '"><label for="wpshop_cart_option[animation_cart_type]">' . __('Cart animation type', 'wpshop') . '</label>';
367 367
 		$output .= '<select name="wpshop_cart_option[animation_cart_type]" id="wpshop_cart_option[animation_cart_type]">';
368
-		$output .= '<option value="pop-in" ' .( ( !empty($cart_option['animation_cart_type']) && $cart_option['animation_cart_type'] == 'pop-in') ? 'selected="selected"' : null). '>' .__('Dialog box', 'wpshop'). '</option>';
369
-		$output .= '<option value="animation" ' .( ( !empty($cart_option['animation_cart_type']) && $cart_option['animation_cart_type'] == 'animation') ? 'selected="selected"' : null). '>' .__('Image animation', 'wpshop'). '</option>';
368
+		$output .= '<option value="pop-in" ' . ((!empty($cart_option['animation_cart_type']) && $cart_option['animation_cart_type'] == 'pop-in') ? 'selected="selected"' : null) . '>' . __('Dialog box', 'wpshop') . '</option>';
369
+		$output .= '<option value="animation" ' . ((!empty($cart_option['animation_cart_type']) && $cart_option['animation_cart_type'] == 'animation') ? 'selected="selected"' : null) . '>' . __('Image animation', 'wpshop') . '</option>';
370 370
 		$output .= '</select></div>';
371 371
 
372 372
 		echo $output;
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 		$input_def['id'] = 'wpshop_cart_option_action_after_product_added_to_quotation';
385 385
 		$input_def['type'] = 'radio';
386 386
 		$input_def['valueToPut'] = 'index';
387
-		$input_def['value'] = ( !empty($cart_option['product_added_to_quotation']) ? $cart_option['product_added_to_quotation'] : null );
387
+		$input_def['value'] = (!empty($cart_option['product_added_to_quotation']) ? $cart_option['product_added_to_quotation'] : null);
388 388
 		$input_def['possible_value'] = array('dialog_msg' => __('Display the dialog allowing to choose between continue shopping or go to cart', 'wpshop'), 'cart_page' => __('Automaticaly send user to cart page', 'wpshop'));
389 389
 		$input_def['options_label']['original'] = true;
390 390
 		$input_def['options_label']['container'] = true;
@@ -392,14 +392,14 @@  discard block
 block discarded – undo
392 392
 
393 393
 		echo $output;
394 394
 	}
395
-	public static function wpshop_options_validate_cart( $input ) {
395
+	public static function wpshop_options_validate_cart($input) {
396 396
 
397
-		if ( empty( $input ) || empty( $input[ 'display_newsletter' ] ) || empty( $input[ 'display_newsletter' ][ 'partner_subscription' ] ) ) {
398
-			$input[ 'display_newsletter' ][ 'partner_subscription' ] = 'no';
397
+		if (empty($input) || empty($input['display_newsletter']) || empty($input['display_newsletter']['partner_subscription'])) {
398
+			$input['display_newsletter']['partner_subscription'] = 'no';
399 399
 		}
400 400
 
401
-		if ( empty( $input ) || empty( $input[ 'display_newsletter' ] ) || empty( $input[ 'display_newsletter' ][ 'site_subscription' ] ) ) {
402
-			$input[ 'display_newsletter' ][ 'site_subscription' ] = 'no';
401
+		if (empty($input) || empty($input['display_newsletter']) || empty($input['display_newsletter']['site_subscription'])) {
402
+			$input['display_newsletter']['site_subscription'] = 'no';
403 403
 		}
404 404
 
405 405
 		return $input;
Please login to merge, or discard this patch.
includes/librairies/db/db_structure_definition.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 /**
@@ -525,11 +525,11 @@  discard block
 block discarded – undo
525 525
 	$wpshop_db_table_operation_list[$wpshop_db_version]['FIELD_ADD'][WPSHOP_DBT_ATTRIBUTE_GROUP] = array('backend_display_type');
526 526
 
527 527
 	$wpshop_db_table_list[$wpshop_db_version] = array(WPSHOP_DBT_ATTRIBUTE, WPSHOP_DBT_ATTRIBUTE_GROUP);
528
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME." DROP INDEX entity_attribute_id";
529
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL." DROP INDEX entity_attribute_id";
530
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT." DROP INDEX entity_attribute_id";
531
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER." DROP INDEX entity_attribute_id";
532
-	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE ".WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR." DROP INDEX entity_attribute_id";
528
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME . " DROP INDEX entity_attribute_id";
529
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " DROP INDEX entity_attribute_id";
530
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT . " DROP INDEX entity_attribute_id";
531
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . " DROP INDEX entity_attribute_id";
532
+	$wpshop_db_request[$wpshop_db_version][] = "ALTER TABLE " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " DROP INDEX entity_attribute_id";
533 533
 }
534 534
 
535 535
 {/*	Version 17  - 1.3.1.3	*/
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 
562 562
 	$wpshop_db_table_list[$wpshop_db_version] = array(WPSHOP_DBT_ATTRIBUTE, WPSHOP_DBT_ATTRIBUTE_GROUP);
563 563
 
564
-	$wpshop_db_request[$wpshop_db_version][] = "UPDATE ".WPSHOP_DBT_ATTRIBUTE." SET backend_input=frontend_input WHERE frontend_input!='text'";
564
+	$wpshop_db_request[$wpshop_db_version][] = "UPDATE " . WPSHOP_DBT_ATTRIBUTE . " SET backend_input=frontend_input WHERE frontend_input!='text'";
565 565
 }
566 566
 
567 567
 {/*	Version 21  - 1.3.2.0	*/
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 }
792 792
 {/*	Version 67  - 1.4.3.8	*/
793 793
 $wpshop_db_version = 67;
794
-$wpshop_update_way[ $wpshop_db_version ] = 'data';
794
+$wpshop_update_way[$wpshop_db_version] = 'data';
795 795
 }
796 796
 {/*	Version dev	- Call for every plugin db version	*/
797 797
 	$wpshop_db_version = 'dev';
Please login to merge, or discard this patch.
includes/librairies/install.class.php 2 patches
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.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -72,38 +72,38 @@  discard block
 block discarded – undo
72 72
                 $page_id = null;
73 73
 
74 74
                 /**    Do a specific check for cart page, for old wpshop installation    */
75
-                if ('wpshop_cart_page_id' == (string) $page->attributes()->code) {
75
+                if ('wpshop_cart_page_id' == (string)$page->attributes()->code) {
76 76
                     $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s	AND post_type != %s", '%[wpshop_basket]%', 'revision');
77 77
                     $page_id = $wpdb->get_var($query);
78 78
 
79 79
                     wp_update_post(array(
80 80
                         'ID' => $page_id,
81
-                        'post_content' => (string) $page->content,
81
+                        'post_content' => (string)$page->content,
82 82
                     ));
83 83
                 }
84 84
 
85 85
                 /**    Check if a page exists with the current content readed form xml file    */
86 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');
87
+                    $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string)$page->content . '%', 'revision');
88 88
                     $page_id = $wpdb->get_var($query);
89 89
                 }
90 90
 
91 91
                 /**    If the page does not exists create it    */
92 92
                 if (empty($page_id)) {
93 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,
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 98
                     ), $page_default_args);
99 99
 
100 100
                     $page_id = wp_insert_post($default_page_args);
101
-                    $created_pages[] = (string) $page->attributes()->code;
101
+                    $created_pages[] = (string)$page->attributes()->code;
102 102
                 }
103 103
 
104 104
                 /**    If the page is created or already exists associated the page to the good service    */
105 105
                 if (!empty($page_id)) {
106
-                    add_option((string) $page->attributes()->code, $page_id);
106
+                    add_option((string)$page->attributes()->code, $page_id);
107 107
 
108 108
                     $page_creation = true;
109 109
                 }
@@ -163,17 +163,17 @@  discard block
 block discarded – undo
163 163
             $wp = $product->children($namespaces['wp']);
164 164
 
165 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,
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 171
             ), $product_default_args);
172 172
 
173 173
             $product_id = wp_insert_post($product_args);
174 174
 
175 175
             foreach ($wp->postmeta as $meta) {
176
-                update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value);
176
+                update_post_meta($product_id, (string)$meta->meta_key, (string)$meta->meta_value);
177 177
             }
178 178
 
179 179
             foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) {
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
                 $wps_pdt_var_wp = $product_variation->children($namespaces['wp']);
184 184
 
185 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,
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 191
                     'post_parent' => $product_id,
192 192
                 ), $product_default_args);
193 193
 
194 194
                 $product_variation_id = wp_insert_post($product_args);
195 195
 
196 196
                 foreach ($wps_pdt_var_wp->postmeta as $meta) {
197
-                    update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value);
197
+                    update_post_meta($product_variation_id, (string)$meta->meta_key, (string)$meta->meta_value);
198 198
                 }
199 199
             }
200 200
         }
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 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 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 429
                                     $last_position = $wpdb->get_var($query);
430
-                                    $position = (int) $last_position + 1;
430
+                                    $position = (int)$last_position + 1;
431 431
                                     foreach ($set_group_infos_details as $attribute_code) {
432 432
                                         $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
433 433
                                         $attribute_id = $wpdb->get_row($query);
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                                     } else {
536 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 537
                                         $last_position = $wpdb->get_var($query);
538
-                                        $position = (int) $last_position + 1;
538
+                                        $position = (int)$last_position + 1;
539 539
                                         foreach ($set_group_infos_details as $attribute_code) {
540 540
                                             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
541 541
                                             $attribute_id = $wpdb->get_var($query);
@@ -1680,7 +1680,7 @@  discard block
 block discarded – undo
1680 1680
                     $max_position = $wpdb->get_var($query);
1681 1681
 
1682 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'));
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 1684
                     }
1685 1685
                 }
1686 1686
 
@@ -2004,7 +2004,7 @@  discard block
 block discarded – undo
2004 2004
                     $max_position = $wpdb->get_var($query);
2005 2005
 
2006 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'));
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 2008
                     }
2009 2009
                 }
2010 2010
                 return true;
@@ -2268,14 +2268,14 @@  discard block
 block discarded – undo
2268 2268
 
2269 2269
                     if (!isset($company_section_detail_id)) {
2270 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));
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 2272
                         $set_details_id_postion_order[$max_position] = $company_id;
2273 2273
                         $company_section_detail_id = $wpdb->insert_id;
2274 2274
                     }
2275 2275
 
2276 2276
                     if (!isset($is_provider_section_detail_id)) {
2277 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));
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 2279
                         $set_details_id_postion_order[$max_position] = $is_provider_id;
2280 2280
                         $is_provider_section_detail_id = $wpdb->insert_id;
2281 2281
                     }
@@ -2377,11 +2377,11 @@  discard block
 block discarded – undo
2377 2377
 				if (empty($admin_new_version_message)) {
2378 2378
 					wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2379 2379
 				}
2380
-				$wpshop_cart_option = get_option( 'wpshop_cart_option' );
2381
-				if( !empty( $wpshop_cart_option ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) ) {
2382
-					$wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] = (int) filter_var($wpshop_cart_option[ 'total_nb_of_item_allowed' ][0], FILTER_VALIDATE_BOOLEAN);
2380
+				$wpshop_cart_option = get_option('wpshop_cart_option');
2381
+				if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) {
2382
+					$wpshop_cart_option['total_nb_of_item_allowed'][0] = (int)filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN);
2383 2383
 				}
2384
-				update_option( 'wpshop_cart_option', $wpshop_cart_option );
2384
+				update_option('wpshop_cart_option', $wpshop_cart_option);
2385 2385
 				break;
2386 2386
 
2387 2387
             /*    Always add specific case before this bloc    */
Please login to merge, or discard this patch.
includes/librairies/init.class.php 1 patch
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 /**
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  * @package wpshop
23 23
  * @subpackage librairies
24 24
  */
25
-class wpshop_init{
25
+class wpshop_init {
26 26
 
27 27
 	/**
28 28
 	 *	This is the function loaded when wordpress load the different plugin
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 		/*	Include head js	*/
41 41
 		add_action('admin_print_scripts', array('wpshop_init', 'admin_print_js'));
42 42
 
43
-		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
44
-		$post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '';
45
-		$action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
46
-		$post = !empty( $_GET['post'] ) ? (array) $_GET['post'] : '';
47
-		$taxonomy = !empty( $_GET['taxonomy'] ) ? sanitize_text_field( $_GET['taxonomy'] ) : '';
48
-		if((isset($page) && substr($page, 0, 7) == 'wpshop_') || (isset($page) && $page == 'wps-installer' ) || (isset($post_type) && substr($post_type, 0, 7) == 'wpshop_') || !empty($post) || (isset($page) && $page==WPSHOP_NEWTYPE_IDENTIFIER_GROUP) || (isset($taxonomy) && ($taxonomy == WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES))){
43
+		$page = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
44
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
45
+		$action = !empty($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
46
+		$post = !empty($_GET['post']) ? (array)$_GET['post'] : '';
47
+		$taxonomy = !empty($_GET['taxonomy']) ? sanitize_text_field($_GET['taxonomy']) : '';
48
+		if ((isset($page) && substr($page, 0, 7) == 'wpshop_') || (isset($page) && $page == 'wps-installer') || (isset($post_type) && substr($post_type, 0, 7) == 'wpshop_') || !empty($post) || (isset($page) && $page == WPSHOP_NEWTYPE_IDENTIFIER_GROUP) || (isset($taxonomy) && ($taxonomy == WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES))) {
49 49
 			/*	Include the different javascript	*/
50 50
 // 			add_action('admin_init', array('wpshop_init', 'admin_js'));
51
-			add_action( 'admin_enqueue_scripts', array('wpshop_init', 'admin_js') );
51
+			add_action('admin_enqueue_scripts', array('wpshop_init', 'admin_js'));
52 52
 			add_action('admin_footer', array('wpshop_init', 'admin_js_footer'));
53 53
 
54 54
 			/*	Include the different css	*/
@@ -57,28 +57,28 @@  discard block
 block discarded – undo
57 57
 		add_action('admin_init', array('wpshop_init', 'admin_css'));
58 58
 
59 59
 		/*	Include the different css	*/
60
-		if ( !is_admin() ) {
60
+		if (!is_admin()) {
61 61
 			add_action('wp_print_styles', array('wpshop_init', 'frontend_css'));
62 62
 			add_action('wp_print_scripts', array('wpshop_init', 'frontend_js_instruction'));
63 63
 		}
64 64
 
65
-		if (isset($page,$action) && $page=='wpshop_doc' && $action=='edit') {
65
+		if (isset($page, $action) && $page == 'wpshop_doc' && $action == 'edit') {
66 66
 			add_action('admin_init', array('wpshop_doc', 'init_wysiwyg'));
67 67
 		}
68 68
 
69 69
 		// RICH TEXT EDIT INIT
70
-		add_action('init', array('wpshop_display','wpshop_rich_text_tags'), 9999);
71
-		add_action('init', array('wpshop_display','wps_hide_admin_bar_for_customers'), 9999 );
70
+		add_action('init', array('wpshop_display', 'wpshop_rich_text_tags'), 9999);
71
+		add_action('init', array('wpshop_display', 'wps_hide_admin_bar_for_customers'), 9999);
72 72
 
73 73
 		/**	Adda custom class to the admin body	*/
74
-		add_filter( 'admin_body_class', array( 'wpshop_init', 'admin_body_class' ) );
75
-		add_filter( 'site_transient_update_plugins', array( 'wpshop_init', 'site_transient_update_plugins' ) );
74
+		add_filter('admin_body_class', array('wpshop_init', 'admin_body_class'));
75
+		add_filter('site_transient_update_plugins', array('wpshop_init', 'site_transient_update_plugins'));
76 76
 	}
77 77
 
78 78
 	/**
79 79
 	 *	Admin menu creation
80 80
 	 */
81
-	public static function admin_menu(){
81
+	public static function admin_menu() {
82 82
 		global $menu;
83 83
 
84 84
 		/*	Get current plugin version	*/
@@ -86,17 +86,17 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$wpshop_catalog_menu_order = 34;
88 88
 
89
-		$menu[ $wpshop_catalog_menu_order-1 ] = array( '', 'read', 'separator-wpshop_dashboard', '', 'wp-menu-separator wpshop_dashboard' );
89
+		$menu[$wpshop_catalog_menu_order - 1] = array('', 'read', 'separator-wpshop_dashboard', '', 'wp-menu-separator wpshop_dashboard');
90 90
 
91 91
 		/*	Main menu creation	*/
92 92
 		global $wps_dashboard_ctr;
93
-		add_menu_page(__( 'Dashboard', 'wpshop' ), __( 'Shop', 'wpshop' ), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_DASHBOARD, array( $wps_dashboard_ctr, 'display_dashboard' ), 'dashicons-admin-home', $wpshop_catalog_menu_order);
94
-		add_submenu_page(WPSHOP_URL_SLUG_DASHBOARD, __('Dashboard', 'wpshop' ), __('Dashboard', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_DASHBOARD, array( $wps_dashboard_ctr, 'display_dashboard' ));
93
+		add_menu_page(__('Dashboard', 'wpshop'), __('Shop', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_DASHBOARD, array($wps_dashboard_ctr, 'display_dashboard'), 'dashicons-admin-home', $wpshop_catalog_menu_order);
94
+		add_submenu_page(WPSHOP_URL_SLUG_DASHBOARD, __('Dashboard', 'wpshop'), __('Dashboard', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_DASHBOARD, array($wps_dashboard_ctr, 'display_dashboard'));
95 95
 
96 96
 		/*	Add eav model menus	*/
97
-		add_menu_page(__( 'Entities', 'wpshop' ), __( 'Entities', 'wpshop' ), 'wpshop_view_dashboard', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, array('wpshop_display', 'display_page'), 'dashicons-universal-access-alt', $wpshop_catalog_menu_order + 1);
98
-		add_submenu_page(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, __( 'Attributes', 'wpshop' ), __('Attributes', 'wpshop'), 'wpshop_view_attributes', WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, array('wpshop_display','display_page'));
99
-		add_submenu_page(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, __( 'Attributes groups', 'wpshop' ), __('Attributes groups', 'wpshop'), 'wpshop_view_attribute_set', WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING, array('wpshop_display','display_page'));
97
+		add_menu_page(__('Entities', 'wpshop'), __('Entities', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, array('wpshop_display', 'display_page'), 'dashicons-universal-access-alt', $wpshop_catalog_menu_order + 1);
98
+		add_submenu_page(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, __('Attributes', 'wpshop'), __('Attributes', 'wpshop'), 'wpshop_view_attributes', WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, array('wpshop_display', 'display_page'));
99
+		add_submenu_page(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, __('Attributes groups', 'wpshop'), __('Attributes groups', 'wpshop'), 'wpshop_view_attribute_set', WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING, array('wpshop_display', 'display_page'));
100 100
 
101 101
 		/*	Add messages menus	*/
102 102
 		//add_submenu_page(WPSHOP_URL_SLUG_DASHBOARD, __( 'Messages', 'wpshop' ), __( 'Messages', 'wpshop'), 'wpshop_view_messages', 'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
 		/*	Add a menu for plugin tools	*/
107 107
 // 		if (WPSHOP_DISPLAY_TOOLS_MENU) {
108
-			add_management_page( __('Wpshop - Tools', 'wpshop' ), __('Wpshop - Tools', 'wpshop' ), 'wpshop_view_tools_menu', WPSHOP_URL_SLUG_TOOLS , array('wpshop_tools', 'main_page'));
108
+			add_management_page(__('Wpshop - Tools', 'wpshop'), __('Wpshop - Tools', 'wpshop'), 'wpshop_view_tools_menu', WPSHOP_URL_SLUG_TOOLS, array('wpshop_tools', 'main_page'));
109 109
 // 		}
110 110
 
111 111
 		/*	Add the options menu	*/
@@ -119,29 +119,29 @@  discard block
 block discarded – undo
119 119
 		$wpshop_menu_order = array();
120 120
 
121 121
 		// Get the index of our custom separator
122
-		$separator = array_search( 'separator-wpshop_dashboard', $menu_order );
123
-		$product = array_search( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $menu_order );
124
-		$order = array_search( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $menu_order );
125
-		$customers = array_search( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $menu_order );
122
+		$separator = array_search('separator-wpshop_dashboard', $menu_order);
123
+		$product = array_search('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $menu_order);
124
+		$order = array_search('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $menu_order);
125
+		$customers = array_search('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $menu_order);
126 126
 		//$entities = array_search( 'admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, $menu_order );
127
-		$entities = array_search( WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, $menu_order );
127
+		$entities = array_search(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, $menu_order);
128 128
 
129
-		unset( $menu_order[$separator] );
130
-		unset( $menu_order[$product] );
131
-		unset( $menu_order[$order] );
132
-		unset( $menu_order[$customers] );
133
-		unset( $menu_order[$entities] );
129
+		unset($menu_order[$separator]);
130
+		unset($menu_order[$product]);
131
+		unset($menu_order[$order]);
132
+		unset($menu_order[$customers]);
133
+		unset($menu_order[$entities]);
134 134
 
135 135
 		// Loop through menu order and do some rearranging
136
-		foreach ( $menu_order as $index => $item ) :
137
-			if ( 'wpshop_dashboard' == $item ) :
136
+		foreach ($menu_order as $index => $item) :
137
+			if ('wpshop_dashboard' == $item) :
138 138
 				$wpshop_menu_order[] = 'separator-wpshop_dashboard';
139 139
 				$wpshop_menu_order[] = $item;
140 140
 				$wpshop_menu_order[] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
141 141
 				$wpshop_menu_order[] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER;
142 142
 				$wpshop_menu_order[] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
143 143
 				$wpshop_menu_order[] = WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES;
144
-			elseif ( !in_array( $item, array( 'separator-wpshop_dashboard' ) ) ) :
144
+			elseif (!in_array($item, array('separator-wpshop_dashboard'))) :
145 145
 				$wpshop_menu_order[] = $item;
146 146
 			endif;
147 147
 		endforeach;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	}
152 152
 
153 153
 	public static function admin_custom_menu_order() {
154
-		return current_user_can( 'manage_options' );
154
+		return current_user_can('manage_options');
155 155
 	}
156 156
 
157 157
 	/**
@@ -161,18 +161,18 @@  discard block
 block discarded – undo
161 161
 
162 162
 		/*	Désactivation de l'enregistrement automatique pour certains type de post	*/
163 163
 		global $post;
164
-		if ( $post && ( (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) ||  (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE)
165
-				|| (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) || (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) ) ) {
164
+		if ($post && ((get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) || (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE)
165
+				|| (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) || (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_COUPON))) {
166 166
 			wp_dequeue_script('autosave');
167 167
 		}
168 168
 
169
-		$entity_to_search = !empty( $_GET['entity_to_search'] ) ? sanitize_text_field( $_GET['entity_to_search'] ) : '';
169
+		$entity_to_search = !empty($_GET['entity_to_search']) ? sanitize_text_field($_GET['entity_to_search']) : '';
170 170
 //	var WPSHOP_AJAX_FILE_URL = "'.WPSHOP_AJAX_FILE_URL.'";
171 171
 		echo '
172 172
 <script type="text/javascript">
173 173
 
174
-	var WPSHOP_MEDIAS_ICON_URL = "'.WPSHOP_MEDIAS_ICON_URL.'";
175
-	var WPSHOP_PRODUCT_PRICE_PILOT = "'.WPSHOP_PRODUCT_PRICE_PILOT.'";
174
+	var WPSHOP_MEDIAS_ICON_URL = "'.WPSHOP_MEDIAS_ICON_URL . '";
175
+	var WPSHOP_PRODUCT_PRICE_PILOT = "'.WPSHOP_PRODUCT_PRICE_PILOT . '";
176 176
 	var WPSHOP_PRODUCT_PRICE_HT = "' . WPSHOP_PRODUCT_PRICE_HT . '";
177 177
 	var WPSHOP_PRODUCT_PRICE_TAX = "' . WPSHOP_PRODUCT_PRICE_TAX . '";
178 178
 	var WPSHOP_PRODUCT_PRICE_TTC = "' . WPSHOP_PRODUCT_PRICE_TTC . '";
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 	var WPSHOP_JS_VAR_ADD_LOGO = "' . __('Upload your logo', 'wpshop') . '";
189 189
 	var WPSHOP_NEWOPTION_CREATION_NONCE = "' . wp_create_nonce("wpshop_new_option_for_attribute_creation") . '";
190 190
 
191
-	var WPSHOP_ADD_TEXT = "'.__('Add', 'wpshop').'";
192
-	var WPSHOP_CREATE_TEXT = "'.__('Create', 'wpshop').'";
193
-	var WPSHOP_SAVE_PRODUCT_OPTIONS_PARAMS = "'.__('Save parameters', 'wpshop').'";
191
+	var WPSHOP_ADD_TEXT = "'.__('Add', 'wpshop') . '";
192
+	var WPSHOP_CREATE_TEXT = "'.__('Create', 'wpshop') . '";
193
+	var WPSHOP_SAVE_PRODUCT_OPTIONS_PARAMS = "'.__('Save parameters', 'wpshop') . '";
194 194
 
195
-	var WPSHOP_NEW_OPTION_IN_LIST_EMPTY = "'.__('You don\'t specify all needed file', 'wpshop').'";
196
-	var WPSHOP_IS_NOT_ALLOWED_SHIPPING_COUNTRY = "'.__('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop').'";
197
-	var WPSHOP_CONFIRM_BEFORE_GENERATE_INVOICE = "'.__('If you generate the invoice, you will cannot modify this order later. Are you sure to do this action ?', 'wpshop').'";
198
-	var WPSHOP_NEW_OPTION_ALREADY_EXIST_IN_LIST = "'.__('The value you entered already exist in list', 'wpshop').'";
199
-	var WPSHOP_SURE_TO_DELETE_ATTR_OPTION_FROM_LIST = "'.__('Are you sure you want to delete this option from list?', 'wpshop').'";
200
-	var WPSHOP_DEFAULT_VALUE = "'.__('Set as default value', 'wpshop').'";
195
+	var WPSHOP_NEW_OPTION_IN_LIST_EMPTY = "'.__('You don\'t specify all needed file', 'wpshop') . '";
196
+	var WPSHOP_IS_NOT_ALLOWED_SHIPPING_COUNTRY = "'.__('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop') . '";
197
+	var WPSHOP_CONFIRM_BEFORE_GENERATE_INVOICE = "'.__('If you generate the invoice, you will cannot modify this order later. Are you sure to do this action ?', 'wpshop') . '";
198
+	var WPSHOP_NEW_OPTION_ALREADY_EXIST_IN_LIST = "'.__('The value you entered already exist in list', 'wpshop') . '";
199
+	var WPSHOP_SURE_TO_DELETE_ATTR_OPTION_FROM_LIST = "'.__('Are you sure you want to delete this option from list?', 'wpshop') . '";
200
+	var WPSHOP_DEFAULT_VALUE = "'.__('Set as default value', 'wpshop') . '";
201 201
 	var WPSHOP_MSG_INVOICE_QUOTATION = "' . __('Are you sure you want to charge this order? You\'ll be unable to modify the content after this operation', 'wpshop') . '";
202 202
 	var WPSHOP_MSG_IGNORE_CONFIGURATION = "' . __('If you continue without install the plugin. Your products won\'t be purchasable', 'wpshop') . '";
203 203
 	var WPSHOP_MSG_CONFIRM_THUMBNAIL_DELETION = "' . __('Are you sure you want to delete this thumbnail?', 'wpshop') . '";
@@ -206,55 +206,55 @@  discard block
 block discarded – undo
206 206
 	var WPSHOP_CHOSEN_SELECT_FROM_LIST = "' . __('Select an Option', 'wpshop') . '";
207 207
 	var WPSHOP_AJAX_CHOSEN_KEEP_TYPING = "' . __('Keep typing for search launching', 'wpshop') . '";
208 208
 	var WPSHOP_AJAX_CHOSEN_SEARCHING = "' . __('Searching in progress for', 'wpshop') . '";
209
-	var WPSHOP_MSG_CONFIRM_ADDON_DEACTIVATION = "'.__('Are you sure you want to deactivate this addon?', 'wpshop').'";
210
-	var WPS_DELETE_SHOP_LOGO_MSG = "'.__('Are you sure you want to delete this logo?', 'wpshop').'";
209
+	var WPSHOP_MSG_CONFIRM_ADDON_DEACTIVATION = "'.__('Are you sure you want to deactivate this addon?', 'wpshop') . '";
210
+	var WPS_DELETE_SHOP_LOGO_MSG = "'.__('Are you sure you want to delete this logo?', 'wpshop') . '";
211 211
 	var WPS_DEFAULT_LOGO = "'.WPSHOP_MEDIAS_IMAGES_URL . 'no_picture.png";
212 212
 
213
-	var WPSHOP_NO_ATTRIBUTES_SELECT_FOR_VARIATION = "'.__('You have to select at least one attribute for creating a new variation', 'wpshop').'";
213
+	var WPSHOP_NO_ATTRIBUTES_SELECT_FOR_VARIATION = "'.__('You have to select at least one attribute for creating a new variation', 'wpshop') . '";
214 214
 
215 215
 	var WPSHOP_CHOSEN_ATTRS = {disable_search_threshold: 5, no_results_text: WPSHOP_CHOSEN_NO_RESULT, placeholder_text_single : WPSHOP_CHOSEN_SELECT_FROM_LIST, placeholder_text_multiple : WPSHOP_CHOSEN_SELECT_FROM_MULTI_LIST};
216 216
 
217
-	var WPSHOP_TEMPLATES_URL = "'.WPSHOP_TEMPLATES_URL.'";
218
-	var WPSHOP_BUTTON_DESCRIPTION = "'.__('Insert shortcode into page content', 'wpshop').'";
219
-	var WPSHOP_WYSIWYG_MENU_TITLE_PRODUCT_LISTING = "'.__('Product listing', 'wpshop').'";
220
-	var WPSHOP_WYSIWYG_PRODUCT_LISTING_BY_PID_TITLE = "'.__('By product ID', 'wpshop').'";
221
-	var WPSHOP_WYSIWYG_PRODUCT_LISTING_BY_ATTRIBUTE_TITLE = "'.__('By attribute value', 'wpshop').'";
222
-	var WPSHOP_WYSIWYG_MENU_TITLE_CATEGORIES = "'.__('WPShop categories', 'wpshop').'";
223
-	var WPSHOP_WYSIWYG_MENU_TITLE_ATTRIBUTE_VALUE = "'.__('Attribute value', 'wpshop').'";
224
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_TITLE = "'.__('Custom message content', 'wpshop').'";
225
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_FIRST_NAME = "'.__('Customer first name', 'wpshop').'";
226
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_LAST_NAME = "'.__('Customer last name', 'wpshop').'";
227
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_EMAIL = "'.__('Customer email', 'wpshop').'";
228
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_ID = "'.__('Order identifer', 'wpshop').'";
229
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_PAYPAL_TRANSACTION_ID = "'.__('Paypal transaction ID', 'wpshop').'";
230
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_CONTENT = "'.__('Order content', 'wpshop').'";
231
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_CUSTOMER_PERSONNAL_INFORMATIONS = "'.__('Customer personnal informations', 'wpshop').'";
232
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_ADDRESSES = "'.__('Order addresses', 'wpshop').'";
233
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_BILLING_ORDER_ADDRESS = "'.__('Billing order address', 'wpshop').'";
234
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_SHIPPING_ORDER_ADDRESS = "'.__('Shipping order address', 'wpshop').'";
235
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_SHIPPING_METHOD = "'.__('Shipping method', 'wpshop').'";
236
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_PAYMENT_METHOD = "'.__('order payment_method', 'wpshop').'";
237
-	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_COMMENT = "'.__('Order customer comment', 'wpshop').'";
238
-	var WPSHOP_CUSTOM_TAGS_TITLE = "'.__('Wpshop custom tags', 'wpshop').'";
239
-	var WPSHOP_CUSTOM_TAGS_CART = "'.__('Cart', 'wpshop').'";
240
-	var WPSHOP_CUSTOM_TAGS_CART_MINI = "'.__('Cart widget', 'wpshop').'";
241
-	var WPSHOP_CUSTOM_TAGS_CHECKOUT = "'.__('Checkout', 'wpshop').'";
242
-	var WPSHOP_CUSTOM_TAGS_ACCOUNT = "'.__('Customer account', 'wpshop').'";
243
-	var WPSHOP_CUSTOM_TAGS_SHOP = "'.__('Shop', 'wpshop').'";
244
-	var WPSHOP_CUSTOM_TAGS_ADVANCED_SEARCH = "'.__('Advanced search', 'wpshop').'";
245
-	var WPSHOP_CANCEL_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to cancel this order ?', 'wpshop').'";
246
-	var WPSHOP_REFUND_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to refund this order ?', 'wpshop').'";
247
-	var WPSHOP_RESEND_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to resend this order to customer ?', 'wpshop').'";
248
-	var WPSHOP_SEARCH_IN_ORDER_EXPLAIN_MESSAGE = "'.__('You want to search in orders', 'wpshop').'";
249
-	var WPSHOP_SEARCH_IN_ORDER_CHOICE_CUSTOMER = "'.__('a customer', 'wpshop').'";
250
-	var WPSHOP_SEARCH_IN_ORDER_CHOICE_PRODUCT = "'.__('a product', 'wpshop').'";
251
-	var WPSHOP_SEARCH_IN_ORDER_USER_CHOICE = "'.( (!empty($entity_to_search) ) ? $entity_to_search : 'customer' ).'";
252
-	var WPSHOP_DELETE_ADDRESS_CONFIRMATION = "'.__( 'Do you really want to delete this address', 'wpshop' ).'";
253
-
254
-	var wps_options_shipping_weight_for_custom_fees = "'.__( 'You must enter a weight', 'wpshop' ).'";
255
-	var wps_options_country_choose_for_custom_fees = "'.__( 'You must a country for custom fees saving', 'wpshop' ).'";
256
-	var wps_options_country_postcode_choose_for_custom_fees = "'.__( 'You must choose a country or write a postcode.', 'wpshop' ).'";
257
-	var wps_an_error_occured = "'.__( 'An error occured', 'wpshop' ).'";
217
+	var WPSHOP_TEMPLATES_URL = "'.WPSHOP_TEMPLATES_URL . '";
218
+	var WPSHOP_BUTTON_DESCRIPTION = "'.__('Insert shortcode into page content', 'wpshop') . '";
219
+	var WPSHOP_WYSIWYG_MENU_TITLE_PRODUCT_LISTING = "'.__('Product listing', 'wpshop') . '";
220
+	var WPSHOP_WYSIWYG_PRODUCT_LISTING_BY_PID_TITLE = "'.__('By product ID', 'wpshop') . '";
221
+	var WPSHOP_WYSIWYG_PRODUCT_LISTING_BY_ATTRIBUTE_TITLE = "'.__('By attribute value', 'wpshop') . '";
222
+	var WPSHOP_WYSIWYG_MENU_TITLE_CATEGORIES = "'.__('WPShop categories', 'wpshop') . '";
223
+	var WPSHOP_WYSIWYG_MENU_TITLE_ATTRIBUTE_VALUE = "'.__('Attribute value', 'wpshop') . '";
224
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_TITLE = "'.__('Custom message content', 'wpshop') . '";
225
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_FIRST_NAME = "'.__('Customer first name', 'wpshop') . '";
226
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_LAST_NAME = "'.__('Customer last name', 'wpshop') . '";
227
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_EMAIL = "'.__('Customer email', 'wpshop') . '";
228
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_ID = "'.__('Order identifer', 'wpshop') . '";
229
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_PAYPAL_TRANSACTION_ID = "'.__('Paypal transaction ID', 'wpshop') . '";
230
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_CONTENT = "'.__('Order content', 'wpshop') . '";
231
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_CUSTOMER_PERSONNAL_INFORMATIONS = "'.__('Customer personnal informations', 'wpshop') . '";
232
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_ADDRESSES = "'.__('Order addresses', 'wpshop') . '";
233
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_BILLING_ORDER_ADDRESS = "'.__('Billing order address', 'wpshop') . '";
234
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_SHIPPING_ORDER_ADDRESS = "'.__('Shipping order address', 'wpshop') . '";
235
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_SHIPPING_METHOD = "'.__('Shipping method', 'wpshop') . '";
236
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_PAYMENT_METHOD = "'.__('order payment_method', 'wpshop') . '";
237
+	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_COMMENT = "'.__('Order customer comment', 'wpshop') . '";
238
+	var WPSHOP_CUSTOM_TAGS_TITLE = "'.__('Wpshop custom tags', 'wpshop') . '";
239
+	var WPSHOP_CUSTOM_TAGS_CART = "'.__('Cart', 'wpshop') . '";
240
+	var WPSHOP_CUSTOM_TAGS_CART_MINI = "'.__('Cart widget', 'wpshop') . '";
241
+	var WPSHOP_CUSTOM_TAGS_CHECKOUT = "'.__('Checkout', 'wpshop') . '";
242
+	var WPSHOP_CUSTOM_TAGS_ACCOUNT = "'.__('Customer account', 'wpshop') . '";
243
+	var WPSHOP_CUSTOM_TAGS_SHOP = "'.__('Shop', 'wpshop') . '";
244
+	var WPSHOP_CUSTOM_TAGS_ADVANCED_SEARCH = "'.__('Advanced search', 'wpshop') . '";
245
+	var WPSHOP_CANCEL_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to cancel this order ?', 'wpshop') . '";
246
+	var WPSHOP_REFUND_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to refund this order ?', 'wpshop') . '";
247
+	var WPSHOP_RESEND_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to resend this order to customer ?', 'wpshop') . '";
248
+	var WPSHOP_SEARCH_IN_ORDER_EXPLAIN_MESSAGE = "'.__('You want to search in orders', 'wpshop') . '";
249
+	var WPSHOP_SEARCH_IN_ORDER_CHOICE_CUSTOMER = "'.__('a customer', 'wpshop') . '";
250
+	var WPSHOP_SEARCH_IN_ORDER_CHOICE_PRODUCT = "'.__('a product', 'wpshop') . '";
251
+	var WPSHOP_SEARCH_IN_ORDER_USER_CHOICE = "'.((!empty($entity_to_search)) ? $entity_to_search : 'customer') . '";
252
+	var WPSHOP_DELETE_ADDRESS_CONFIRMATION = "'.__('Do you really want to delete this address', 'wpshop') . '";
253
+
254
+	var wps_options_shipping_weight_for_custom_fees = "'.__('You must enter a weight', 'wpshop') . '";
255
+	var wps_options_country_choose_for_custom_fees = "'.__('You must a country for custom fees saving', 'wpshop') . '";
256
+	var wps_options_country_postcode_choose_for_custom_fees = "'.__('You must choose a country or write a postcode.', 'wpshop') . '";
257
+	var wps_an_error_occured = "'.__('An error occured', 'wpshop') . '";
258 258
 </script>';
259 259
 	}
260 260
 
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 		ob_end_clean();
270 270
 
271 271
 		echo '<script type="text/javascript">
272
-			var wp_version = "'.$wp_version.'";
273
-			'.$wpshop_product_js.'
272
+			var wp_version = "'.$wp_version . '";
273
+			'.$wpshop_product_js . '
274 274
 		</script>';
275 275
 	}
276 276
 
@@ -286,21 +286,21 @@  discard block
 block discarded – undo
286 286
 		wp_enqueue_script('jquery-ui-dialog');
287 287
 		wp_enqueue_script('jquery-form');
288 288
 		wp_enqueue_script('jquery-ui-slider');
289
-		wp_enqueue_script( 'jquery-ui-autocomplete' );
289
+		wp_enqueue_script('jquery-ui-autocomplete');
290 290
 		wp_enqueue_script('wpshop_main_function_js', WPSHOP_JS_URL . 'main_function.js', '', WPSHOP_VERSION);
291 291
 		wp_enqueue_script('wpshop_main_js', WPSHOP_JS_URL . 'main.js', '', WPSHOP_VERSION);
292 292
 		wp_enqueue_script('wpshop_jq_datatable', WPSHOP_JS_URL . 'jquery-libs/jquery.dataTables.min.js', '', WPSHOP_VERSION);
293
-		wp_enqueue_script('wpshop_jquery_chosen',  WPSHOP_JS_URL . 'jquery-libs/chosen.jquery.min.js', '', WPSHOP_VERSION);
293
+		wp_enqueue_script('wpshop_jquery_chosen', WPSHOP_JS_URL . 'jquery-libs/chosen.jquery.min.js', '', WPSHOP_VERSION);
294 294
 		wp_enqueue_script('jquery-effects-core');
295 295
 		wp_enqueue_script('jquery-effects-highlight');
296 296
 
297
-		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
297
+		$page = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
298 298
 
299 299
 		/*	Include specific js file for the current page if existing	*/
300
-		if(isset($page) && is_file(WPSHOP_JS_DIR . 'pages/' . $page . '.js')){
300
+		if (isset($page) && is_file(WPSHOP_JS_DIR . 'pages/' . $page . '.js')) {
301 301
 			wp_enqueue_script($page . '_js', WPSHOP_JS_URL . 'pages/' . $page . '.js', '', WPSHOP_VERSION);
302 302
 		}
303
-		if((isset($page) && ($page == 'wpshop_dashboard'))) {
303
+		if ((isset($page) && ($page == 'wpshop_dashboard'))) {
304 304
 			wp_enqueue_script($page . '_js', WPSHOP_JS_URL . 'pages/' . WPSHOP_URL_SLUG_OPTION . '.js', '', WPSHOP_VERSION);
305 305
 			wp_register_style($page . '_css', WPSHOP_CSS_URL . 'pages/' . WPSHOP_URL_SLUG_OPTION . '.css', '', WPSHOP_VERSION);
306 306
 			wp_enqueue_style($page . '_css');
@@ -327,12 +327,12 @@  discard block
 block discarded – undo
327 327
 	 * @param array $classes
328 328
 	 * @return string
329 329
 	 */
330
-	public static function admin_body_class( $classes ) {
330
+	public static function admin_body_class($classes) {
331 331
 		global $post;
332 332
 
333
-		if ( !empty($post->ID) ) {
334
-			$post_type = get_post_type( $post->ID );
335
-			if ( is_admin() && in_array( $post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, WPSHOP_NEWTYPE_IDENTIFIER_COUPON, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) ) ) {
333
+		if (!empty($post->ID)) {
334
+			$post_type = get_post_type($post->ID);
335
+			if (is_admin() && in_array($post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, WPSHOP_NEWTYPE_IDENTIFIER_COUPON, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS))) {
336 336
 				$classes .= ' wpshop-admin-body wpshop-admin-post-type-' . $post_type;
337 337
 			}
338 338
 		}
@@ -360,8 +360,8 @@  discard block
 block discarded – undo
360 360
 		wp_enqueue_style('wpshop_chosen_css');
361 361
 
362 362
 		/*	Include specific css file for the current page if existing	*/
363
-		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
364
-		if(isset($page) && is_file(WPSHOP_CSS_DIR . 'pages/' . $page . '.css')){
363
+		$page = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
364
+		if (isset($page) && is_file(WPSHOP_CSS_DIR . 'pages/' . $page . '.css')) {
365 365
 			wp_register_style($page . '_css', WPSHOP_CSS_URL . 'pages/' . $page . '.css', '', WPSHOP_VERSION);
366 366
 			wp_enqueue_style($page . '_css');
367 367
 		}
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 		wp_register_style('wpshop_default_wps_style_css', WPSHOP_TEMPLATES_URL . 'wpshop/css/wps_style.css', '', WPSHOP_VERSION);
404 404
 		wp_enqueue_style('wpshop_default_wps_style_css');
405 405
 
406
-		if( file_exists( get_stylesheet_directory().'/wpshop/css/wps_style.css' ) ) {
407
-			wp_deregister_style( 'wpshop_default_wps_style_css' );
406
+		if (file_exists(get_stylesheet_directory() . '/wpshop/css/wps_style.css')) {
407
+			wp_deregister_style('wpshop_default_wps_style_css');
408 408
 			wp_register_style('wps_style_css', wpshop_display::get_template_file('wps_style.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output', true), '', WPSHOP_VERSION);
409 409
 			wp_enqueue_style('wps_style_css', 11);
410 410
 		}
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 		wp_register_style('wps_owl_caroussel_transitions', wpshop_display::get_template_file('owl.transitions.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output'), '', WPSHOP_VERSION);
417 417
 		wp_enqueue_style('wps_owl_caroussel_transitions');
418 418
 
419
-			wp_enqueue_style( 'dashicons' );
419
+			wp_enqueue_style('dashicons');
420 420
 	}
421 421
 
422 422
 	/**
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 		wp_enqueue_script('jquery-ui-slider');
435 435
 		wp_enqueue_script('wpshop_frontend_main_js', wpshop_display::get_template_file('frontend_main.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
436 436
 // 		wp_enqueue_script('wpshop_jquery_jqzoom_core_js', wpshop_display::get_template_file('jquery.jqzoom-core.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
437
-		wp_enqueue_script('fancyboxmousewheel',WPSHOP_JS_URL . 'fancybox/jquery.mousewheel-3.0.4.pack.js', '', WPSHOP_VERSION, true);
437
+		wp_enqueue_script('fancyboxmousewheel', WPSHOP_JS_URL . 'fancybox/jquery.mousewheel-3.0.4.pack.js', '', WPSHOP_VERSION, true);
438 438
 		wp_enqueue_script('fancybox', WPSHOP_JS_URL . 'fancybox/jquery.fancybox-1.3.4.pack.js', '', WPSHOP_VERSION, true);
439 439
 		wp_enqueue_script('jquery_address', WPSHOP_JS_URL . 'jquery-libs/jquery.address-1.5.min.js', '', WPSHOP_VERSION);
440 440
 		wp_enqueue_script('wps_api', wpshop_display::get_template_file('wps-api.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	var WPSHOP_MUST_CHOOSE_SHIPPING_MODE = "<?php _e('You must to choose a shipping mode', 'wpshop'); ?>";
458 458
 	var WPSHOP_NO_SHIPPING_MODE_AVAILABLE = "<?php _e('You can\'t order because no shipping mode is available.', 'wpshop'); ?>";
459 459
 	var WPSHOP_LOADER_ICON_JQUERY_ADDRESS = "<img src=\"<?php echo WPSHOP_LOADING_ICON; ?>\" alt=\"Loading...\" />";
460
-	var WPSHOP_CONFIRM_DELETE_ADDRESS = "<?php _e( 'Do you really want to delete this address ?', 'wpshop' ); ?>";
460
+	var WPSHOP_CONFIRM_DELETE_ADDRESS = "<?php _e('Do you really want to delete this address ?', 'wpshop'); ?>";
461 461
 	var wps_speed_slideUpDown = 200;
462 462
 	var MODAL_URL = '<?php echo WPSHOP_TEMPLATES_URL; ?>wpshop/modal.php';
463 463
 </script>
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 		$product_class = new wpshop_products();
496 496
 		add_action('save_post', array($product_class, 'save_product_custom_informations'));
497 497
 		/*	Modification des paramètres de variation quand ils ne sont pas configurés individuellement	*/
498
-		add_filter('pre_update_option_' . 'wpshop_catalog_product_option', array('wpshop_products', 'update_wpshop_catalog_product_option'), 10, 2 );
498
+		add_filter('pre_update_option_' . 'wpshop_catalog_product_option', array('wpshop_products', 'update_wpshop_catalog_product_option'), 10, 2);
499 499
 
500 500
 		/*	Add wpshop product category term	*/
501 501
 		wpshop_categories::create_product_categories();
@@ -503,14 +503,14 @@  discard block
 block discarded – undo
503 503
 		/*	Add wpshop message term	*/
504 504
 
505 505
 
506
-		if ( $wpshop_shop_type == 'sale' ) {
506
+		if ($wpshop_shop_type == 'sale') {
507 507
 			/*	Add wpshop orders term	*/
508 508
 			wpshop_orders::create_orders_type();
509 509
 			add_action('add_meta_boxes', array('wpshop_orders', 'add_meta_boxes'));
510
-			add_action('manage_'.WPSHOP_NEWTYPE_IDENTIFIER_ORDER.'_posts_custom_column',  array('wpshop_orders', 'orders_custom_columns'), 10, 2);
511
-			add_filter('manage_edit-'.WPSHOP_NEWTYPE_IDENTIFIER_ORDER.'_columns', array('wpshop_orders', 'orders_edit_columns'));
512
-			add_action('restrict_manage_posts', array('wpshop_orders', 'list_table_filters') );
513
-			add_filter('parse_query', array('wpshop_orders', 'list_table_filter_parse_query') );
510
+			add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_posts_custom_column', array('wpshop_orders', 'orders_custom_columns'), 10, 2);
511
+			add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_columns', array('wpshop_orders', 'orders_edit_columns'));
512
+			add_action('restrict_manage_posts', array('wpshop_orders', 'list_table_filters'));
513
+			add_filter('parse_query', array('wpshop_orders', 'list_table_filter_parse_query'));
514 514
 		}
515 515
 
516 516
 		$args = array(
@@ -520,14 +520,14 @@  discard block
 block discarded – undo
520 520
 		$output = 'objects'; // names or objects, note names is the default
521 521
 		$operator = 'or'; // 'and' or 'or'
522 522
 
523
-		$wp_types_original=get_post_types($args,$output,$operator);
523
+		$wp_types_original = get_post_types($args, $output, $operator);
524 524
 		foreach ($wp_types_original as $type => $type_definition):
525 525
 			$wp_types[$type] = $type_definition->labels->name;
526 526
 		endforeach;
527
-		$to_exclude=unserialize(WPSHOP_INTERNAL_TYPES_TO_EXCLUDE);
528
-		if(!empty($to_exclude)):
529
-			foreach($to_exclude as $excluded_type):
530
-				if(isset($wp_types[$excluded_type]))unset($wp_types[$excluded_type]);
527
+		$to_exclude = unserialize(WPSHOP_INTERNAL_TYPES_TO_EXCLUDE);
528
+		if (!empty($to_exclude)):
529
+			foreach ($to_exclude as $excluded_type):
530
+				if (isset($wp_types[$excluded_type]))unset($wp_types[$excluded_type]);
531 531
 			endforeach;
532 532
 		endif;
533 533
 		DEFINE('WPSHOP_INTERNAL_TYPES', serialize(array_merge($wp_types, array('users' => __('Users', 'wpshop')))));
@@ -536,29 +536,29 @@  discard block
 block discarded – undo
536 536
 	/**
537 537
 	 * Send mail when new version is available
538 538
 	 */
539
-	public static function site_transient_update_plugins( $option ) {
540
-		if ( isset( $option->response[ WPSHOP_PLUGIN_NAME ] ) ) {
539
+	public static function site_transient_update_plugins($option) {
540
+		if (isset($option->response[WPSHOP_PLUGIN_NAME])) {
541 541
 			global $wpdb;
542 542
 			$message_mdl = new wps_message_mdl();
543
-			$admin_new_version_message = get_option( 'WPSHOP_NEW_VERSION_ADMIN_MESSAGE', null );
544
-			$shop_admin_email_option = get_option( 'wpshop_emails' );
545
-			$shop_admin_id = $wpdb->get_var( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_email = %s', $shop_admin_email_option['contact_email'] ) );
546
-			if ( ! is_null( $shop_admin_id ) && ! is_null( $admin_new_version_message ) ) {
547
-				$messages_histo = $message_mdl->get_messages_histo( $admin_new_version_message, $shop_admin_id );
548
-				if ( ! empty( $messages_histo ) ) {
549
-					foreach ( $messages_histo as $messages_histo_group ) {
550
-						foreach ( $messages_histo_group as $messages_histo ) {
551
-							if ( strpos( $messages_histo['mess_title'], $option->response[ WPSHOP_PLUGIN_NAME ]->new_version ) !== false
552
-							|| strpos( $messages_histo['mess_message'], $option->response[ WPSHOP_PLUGIN_NAME ]->new_version ) !== false ) {
543
+			$admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE', null);
544
+			$shop_admin_email_option = get_option('wpshop_emails');
545
+			$shop_admin_id = $wpdb->get_var($wpdb->prepare('SELECT ID FROM ' . $wpdb->users . ' WHERE user_email = %s', $shop_admin_email_option['contact_email']));
546
+			if (!is_null($shop_admin_id) && !is_null($admin_new_version_message)) {
547
+				$messages_histo = $message_mdl->get_messages_histo($admin_new_version_message, $shop_admin_id);
548
+				if (!empty($messages_histo)) {
549
+					foreach ($messages_histo as $messages_histo_group) {
550
+						foreach ($messages_histo_group as $messages_histo) {
551
+							if (strpos($messages_histo['mess_title'], $option->response[WPSHOP_PLUGIN_NAME]->new_version) !== false
552
+							|| strpos($messages_histo['mess_message'], $option->response[WPSHOP_PLUGIN_NAME]->new_version) !== false) {
553 553
 								return $option;
554 554
 							}
555 555
 						}
556 556
 					}
557 557
 				}
558 558
 				$wps_message = new wps_message_ctr();
559
-				$wps_message->wpshop_prepared_email( $shop_admin_email_option['contact_email'], 'WPSHOP_NEW_VERSION_ADMIN_MESSAGE', array(
560
-					'wpshop_version' => $option->response[ WPSHOP_PLUGIN_NAME ]->new_version,
561
-				) );
559
+				$wps_message->wpshop_prepared_email($shop_admin_email_option['contact_email'], 'WPSHOP_NEW_VERSION_ADMIN_MESSAGE', array(
560
+					'wpshop_version' => $option->response[WPSHOP_PLUGIN_NAME]->new_version,
561
+				));
562 562
 			}
563 563
 		}
564 564
 	}
Please login to merge, or discard this patch.
includes/librairies/eav/attributes_unit.class.php 3 patches
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.
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 /**
@@ -116,22 +116,22 @@  discard block
 block discarded – undo
116 116
 	{
117 117
 		$action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
118 118
 		$objectInEdition = isset($_REQUEST['id']) ? sanitize_key($_REQUEST['id']) : '';
119
-		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
119
+		$page = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
120 120
 
121
-		$title = __(self::pageTitle, 'wpshop' );
122
-		if($action != '')
121
+		$title = __(self::pageTitle, 'wpshop');
122
+		if ($action != '')
123 123
 		{
124
-			if(($action == 'edit') || ($action == 'delete'))
124
+			if (($action == 'edit') || ($action == 'delete'))
125 125
 			{
126 126
 				$editedItem = self::getElement($objectInEdition);
127 127
 				$title = sprintf(__(self::pageEditingTitle, 'wpshop'), str_replace("\\", "", $editedItem->frontend_label) . '&nbsp;(' . $editedItem->code . ')');
128 128
 			}
129
-			elseif($action == 'add')
129
+			elseif ($action == 'add')
130 130
 			{
131 131
 				$title = __(self::pageAddingTitle, 'wpshop');
132 132
 			}
133 133
 		}
134
-		elseif((self::getEditionSlug() != self::getListingSlug()) && (sanitize_text_field($page) == self::getEditionSlug()))
134
+		elseif ((self::getEditionSlug() != self::getListingSlug()) && (sanitize_text_field($page) == self::getEditionSlug()))
135 135
 		{
136 136
 			$title = __(self::pageAddingTitle, 'wpshop');
137 137
 		}
@@ -152,31 +152,31 @@  discard block
 block discarded – undo
152 152
 		/****************************************************************************/
153 153
 		$action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add';
154 154
 		$saveditem = isset($_REQUEST['saveditem']) ? wpshop_tools::varSanitizer($_REQUEST['saveditem']) : '';
155
-		if(($action != '') && ($action == 'saveok') && ($saveditem > 0))
155
+		if (($action != '') && ($action == 'saveok') && ($saveditem > 0))
156 156
 		{
157 157
 			$editedElement = self::getElement($saveditem);
158 158
 			$pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>');
159 159
 		}
160
-		elseif(($action != '') && ($action == 'deleteok') && ($saveditem > 0))
160
+		elseif (($action != '') && ($action == 'deleteok') && ($saveditem > 0))
161 161
 		{
162 162
 			$editedElement = self::getElement($saveditem, "'deleted'");
163 163
 			$pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>');
164 164
 		}
165 165
 
166 166
 		/*	Define the database operation type from action launched by the user	 */
167
-		$attribute_group_parameter = (!empty($_REQUEST[self::getDbTable()])) ? (array) $_REQUEST[self::getDbTable()] : array();
168
-		$attribute_group_parameter['default_value'] = str_replace('"', "'", sanitize_text_field( $attribute_group_parameter['default_value']));
167
+		$attribute_group_parameter = (!empty($_REQUEST[self::getDbTable()])) ? (array)$_REQUEST[self::getDbTable()] : array();
168
+		$attribute_group_parameter['default_value'] = str_replace('"', "'", sanitize_text_field($attribute_group_parameter['default_value']));
169 169
 		/*************************		GENERIC				**************************/
170 170
 		/*************************************************************************/
171 171
 		$pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable() . '_action']) : '';
172 172
 		$id = isset($attribute_group_parameter['id']) ? sanitize_key($attribute_group_parameter['id']) : '';
173
-		if(($pageAction != '') && (($pageAction == 'edit') || ($pageAction == 'editandcontinue'))){
174
-			if(current_user_can('wpshop_edit_attributes'))
173
+		if (($pageAction != '') && (($pageAction == 'edit') || ($pageAction == 'editandcontinue'))) {
174
+			if (current_user_can('wpshop_edit_attributes'))
175 175
 			{
176 176
 				$attribute_group_parameter['last_update_date'] = date('Y-m-d H:i:s');
177
-				if($pageAction == 'delete')
177
+				if ($pageAction == 'delete')
178 178
 				{
179
-					if(current_user_can('wpshop_delete_attributes'))
179
+					if (current_user_can('wpshop_delete_attributes'))
180 180
 					{
181 181
 						$attribute_group_parameter['status'] = 'deleted';
182 182
 					}
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 				$actionResult = 'userNotAllowedForActionEdit';
193 193
 			}
194 194
 		}
195
-		elseif(($pageAction != '') && (($pageAction == 'delete'))){
196
-			if(current_user_can('wpshop_delete_attributes'))
195
+		elseif (($pageAction != '') && (($pageAction == 'delete'))) {
196
+			if (current_user_can('wpshop_delete_attributes'))
197 197
 			{
198 198
 				$attribute_group_parameter['last_update_date'] = date('Y-m-d H:i:s');
199 199
 				$attribute_group_parameter['status'] = 'deleted';
@@ -204,21 +204,21 @@  discard block
 block discarded – undo
204 204
 				$actionResult = 'userNotAllowedForActionDelete';
205 205
 			}
206 206
 		}
207
-		elseif(($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))){
208
-			if(current_user_can('wpshop_add_attributes')){
207
+		elseif (($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))) {
208
+			if (current_user_can('wpshop_add_attributes')) {
209 209
 				$attribute_group_parameter['creation_date'] = date('Y-m-d H:i:s');
210
-				if(trim($attribute_group_parameter['code']) == ''){
210
+				if (trim($attribute_group_parameter['code']) == '') {
211 211
 					$attribute_group_parameter['code'] = $attribute_group_parameter['frontend_label'];
212 212
 				}
213 213
 				$attribute_group_parameter['code'] = wpshop_tools::slugify(str_replace("\'", "_", str_replace('\"', "_", $attribute_group_parameter['code'])), array('noAccent', 'noSpaces', 'lowerCase', 'noPunctuation'));
214 214
 				$code_exists = self::getElement($attribute_group_parameter['code'], "'valid', 'moderated', 'deleted'", 'code');
215
-				if((is_object($code_exists) || is_array($code_exists)) && (count($code_exists) > 0)){
215
+				if ((is_object($code_exists) || is_array($code_exists)) && (count($code_exists) > 0)) {
216 216
 					$attribute_group_parameter['code'] = $attribute_group_parameter['code'] . '_' . (count($code_exists) + 1);
217 217
 				}
218 218
 				$actionResult = wpshop_database::save($attribute_group_parameter, self::getDbTable());
219 219
 				$id = $wpdb->insert_id;
220 220
 			}
221
-			else{
221
+			else {
222 222
 				$actionResult = 'userNotAllowedForActionAdd';
223 223
 			}
224 224
 		}
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
 		/************		CHANGE THE FIELD NAME TO TAKE TO DISPLAY				*************/
229 229
 		/************		CHANGE ERROR MESSAGE FOR SPECIFIC CASE					*************/
230 230
 		/****************************************************************************/
231
-		if($actionResult != ''){
231
+		if ($actionResult != '') {
232 232
 			$elementIdentifierForMessage = '<span class="bold" >' . $attribute_group_parameter['frontend_label'] . '</span>';
233 233
 			if ($actionResult == 'error') {
234 234
 				$pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage);
235
-				if(WPSHOP_DEBUG_MODE)
235
+				if (WPSHOP_DEBUG_MODE)
236 236
 				{
237 237
 					$pageMessage .= '<br/>' . $wpdb->last_error;
238 238
 				}
239 239
 			}
240
-			elseif(($actionResult == 'done') || ($actionResult == 'nothingToUpdate'))
240
+			elseif (($actionResult == 'done') || ($actionResult == 'nothingToUpdate'))
241 241
 			{/*	CHANGE HERE FOR SPECIFIC CASE	*/
242 242
 				/*****************************************************************************************************************/
243 243
 				/*************************			CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT				******************/
@@ -247,20 +247,20 @@  discard block
 block discarded – undo
247 247
 				/*************************			GENERIC				****************************/
248 248
 				/***********************************************************************************/
249 249
 				$pageMessage .= '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), $elementIdentifierForMessage);
250
-				if(($pageAction == 'edit') || ($pageAction == 'save'))
250
+				if (($pageAction == 'edit') || ($pageAction == 'save'))
251 251
 				{
252 252
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id));
253 253
 				}
254
-				elseif($pageAction == 'add')
254
+				elseif ($pageAction == 'add')
255 255
 				{
256 256
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id));
257 257
 				}
258
-				elseif($pageAction == 'delete')
258
+				elseif ($pageAction == 'delete')
259 259
 				{
260 260
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id));
261 261
 				}
262 262
 			}
263
-			elseif(($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete'))
263
+			elseif (($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete'))
264 264
 			{
265 265
 				$pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop');
266 266
 			}
@@ -292,36 +292,36 @@  discard block
 block discarded – undo
292 292
 
293 293
 		$line = 0;
294 294
 		$elementList = self::getElement();
295
-		if(is_array($elementList) && (count($elementList) > 0)){
296
-			foreach($elementList as $element)
295
+		if (is_array($elementList) && (count($elementList) > 0)) {
296
+			foreach ($elementList as $element)
297 297
 			{
298 298
 				$tableRowsId[$line] = self::getDbTable() . '_' . $element->id;
299 299
 
300 300
 				$elementLabel = __($element->name, 'wpshop');
301 301
 				$subRowActions = '';
302 302
 				$attributeSlugUrl = self::getListingSlug();
303
-				if(current_user_can('wpshop_add_attributes_unit'))
303
+				if (current_user_can('wpshop_add_attributes_unit'))
304 304
 				{
305 305
 					$attributeSlugUrl = self::getEditionSlug();
306 306
 				}
307
-				if(current_user_can('wpshop_edit_attributes_unit'))
307
+				if (current_user_can('wpshop_edit_attributes_unit'))
308 308
 				{
309 309
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
310 310
 					$subRowActions .= '
311
-		<a href="#" id="edit_attribute_unit_' . $element->id . '" class="edit_attribute_unit" data-nonce="' . wp_create_nonce( 'edit_attribute_unit_' . $element->id ) . '" >' . __('Edit', 'wpshop') . '</a>';
311
+		<a href="#" id="edit_attribute_unit_' . $element->id . '" class="edit_attribute_unit" data-nonce="' . wp_create_nonce('edit_attribute_unit_' . $element->id) . '" >' . __('Edit', 'wpshop') . '</a>';
312 312
 				}
313
-				elseif(current_user_can('wpshop_view_attributes_unit'))
313
+				elseif (current_user_can('wpshop_view_attributes_unit'))
314 314
 				{
315 315
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
316 316
 				}
317
-				if(current_user_can('wpshop_delete_attributes_unit'))
317
+				if (current_user_can('wpshop_delete_attributes_unit'))
318 318
 				{
319
-					if($subRowActions != '')
319
+					if ($subRowActions != '')
320 320
 					{
321 321
 						$subRowActions .= '&nbsp;|&nbsp;';
322 322
 					}
323 323
 					$subRowActions .= '
324
-		<a href="#" id="delete_attribute_unit_' . $element->id . '" class="delete_attribute_unit" data-nonce="' . wp_create_nonce( 'delete_attribute_unit_' . $element->id ) . '" >' . __('Delete', 'wpshop') . '</a>';
324
+		<a href="#" id="delete_attribute_unit_' . $element->id . '" class="delete_attribute_unit" data-nonce="' . wp_create_nonce('delete_attribute_unit_' . $element->id) . '" >' . __('Delete', 'wpshop') . '</a>';
325 325
 				}
326 326
 
327 327
 				$rowActions = '
@@ -337,14 +337,14 @@  discard block
 block discarded – undo
337 337
 				$line++;
338 338
 			}
339 339
 		}
340
-		else{
340
+		else {
341 341
 			unset($tableRowValue);
342 342
 			$tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => __('No element to ouput here', 'wpshop'));
343 343
 			$tableRowValue[] = array('class' => self::currentPageCode . '_name_cell', 'value' => '');
344 344
 			$tableRowValue[] = array('class' => self::currentPageCode . '_code_cell', 'value' => '');
345 345
 			$tableRows[] = $tableRowValue;
346 346
 		}
347
-		if(current_user_can('wpshop_add_attributes_unit')){
347
+		if (current_user_can('wpshop_add_attributes_unit')) {
348 348
 			$listItemOutput .= '
349 349
 <input type="button" value="' . __('Add an unit', 'wpshop') . '" class="button-secondary alignleft" name="add_attribute_unit" id="add_attribute_unit" />';
350 350
 		}
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
 	wpshop(document).ready(function(){
354 354
 		jQuery("#' . $tableId . '").dataTable();
355 355
 		jQuery("#wpshop_unit_group_list_tab").show();';
356
-		if(current_user_can('wpshop_delete_attributes_unit')){
356
+		if (current_user_can('wpshop_delete_attributes_unit')) {
357 357
 			$listItemOutput .= '
358 358
 		wpshop(document).on("click", ".delete_attribute_unit", function() {
359 359
 			var nonce = jQuery( this ).data( "nonce" );
360
-			if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this unit', 'wpshop')  .' ?"))){
360
+			if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this unit', 'wpshop') . ' ?"))){
361 361
 				wpshop("#wpshop_unit_list").load(ajaxurl,{
362 362
 					"action": "wps_attribute_unit_delete",
363 363
 					"elementIdentifier": wpshop(this).attr("id").replace("delete_attribute_unit_", ""),
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 			}
367 367
 		});';
368 368
 		}
369
-		if(current_user_can('wpshop_edit_attributes_unit')){
369
+		if (current_user_can('wpshop_edit_attributes_unit')) {
370 370
 			$listItemOutput .= '
371 371
 		wpshop(document).on("click", ".edit_attribute_unit", function() {
372 372
 			var nonce = jQuery( this ).data( "nonce" );
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 			});
378 378
 		});';
379 379
 		}
380
-		if(current_user_can('wpshop_add_attributes_unit')){
380
+		if (current_user_can('wpshop_add_attributes_unit')) {
381 381
 			$listItemOutput .= '
382 382
 		jQuery("#add_attribute_unit").click(function(){
383 383
 			jQuery("#wpshop_unit_list").load(ajaxurl,{
@@ -397,34 +397,34 @@  discard block
 block discarded – undo
397 397
 	*
398 398
 	*	@return string The html code that output the interface for adding a nem item
399 399
 	*/
400
-	public static function elementEdition($itemToEdit = ''){
400
+	public static function elementEdition($itemToEdit = '') {
401 401
 		global $attribute_displayed_field; global $wpdb;
402 402
 		$dbFieldList = wpshop_database::fields_to_input(self::getDbTable());
403 403
 
404 404
 		$editedItem = '';
405 405
 		// @TODO : Request
406 406
 		// $_REQUEST['action'] = 'save_new_attribute_unit';
407
-		if($itemToEdit != ''){
407
+		if ($itemToEdit != '') {
408 408
 			$editedItem = self::getElement($itemToEdit);
409 409
 			// $_REQUEST['action'] = 'update_attribute_unit';
410 410
 		}
411
-		$query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id = ' .get_option('wpshop_shop_default_currency'). '', '');
411
+		$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = ' . get_option('wpshop_shop_default_currency') . '', '');
412 412
  		$default_unit = $wpdb->get_var($query);
413 413
 
414 414
 		$the_form_content_hidden = $the_form_general_content = $the_form_option_content = '';
415
-		foreach($dbFieldList as $input_key => $input_def){
415
+		foreach ($dbFieldList as $input_key => $input_def) {
416 416
 			$pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? sanitize_text_field($_REQUEST[self::getDbTable() . '_action']) : '';
417 417
 			$requestFormValue = isset($_REQUEST[self::currentPageCode][$input_def['name']]) ? sanitize_text_field($_REQUEST[self::currentPageCode][$input_def['name']]) : '';
418 418
 			$currentFieldValue = $input_def['value'];
419
-			if(is_object($editedItem)){
419
+			if (is_object($editedItem)) {
420 420
 				$currentFieldValue = $editedItem->{$input_def['name']};
421 421
 			}
422
-			elseif(($pageAction != '') && ($requestFormValue != '')){
422
+			elseif (($pageAction != '') && ($requestFormValue != '')) {
423 423
 				$currentFieldValue = $requestFormValue;
424 424
 			}
425 425
 
426 426
 			$input_def['value'] = $currentFieldValue;
427
-			if($input_def['name'] == 'group_id'){
427
+			if ($input_def['name'] == 'group_id') {
428 428
 				$attribute_unit_group_list = self::get_unit_group();
429 429
 				$input_def['possible_value'] = $attribute_unit_group_list;
430 430
 				$input_def['type'] = 'select';
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 			$the_input = wpshop_form::check_input_type($input_def, self::getDbTable());
435 435
 
436 436
 
437
-			if($input_def['type'] != 'hidden'){
437
+			if ($input_def['type'] != 'hidden') {
438 438
 				$label = 'for="' . $input_def['name'] . '"';
439
-				if(($input_def['type'] == 'radio') || ($input_def['type'] == 'checkbox')){
439
+				if (($input_def['type'] == 'radio') || ($input_def['type'] == 'checkbox')) {
440 440
 					$label = '';
441 441
 				}
442 442
 
@@ -446,29 +446,29 @@  discard block
 block discarded – undo
446 446
 						<label ' . $label . ' >' . __($input_def['name'], 'wpshop') . '</label>
447 447
 					</div>
448 448
 					<div class="wpshop_form_input wpshop_' . self::currentPageCode . '_' . $input_def['name'] . '_input alignleft" >
449
-						' . $the_input . ' ' .( ($input_def['name'] == 'change_rate') ? $default_unit : ''). '
449
+						' . $the_input . ' ' . (($input_def['name'] == 'change_rate') ? $default_unit : '') . '
450 450
 					</div>
451 451
 				</div>';
452 452
 
453 453
 
454 454
 			}
455
-			else{
455
+			else {
456 456
 				$the_form_content_hidden .= '
457 457
 	' . $the_input;
458 458
 			}
459 459
 		}
460 460
 
461
-		$the_form = '<form name="' . self::getDbTable() . '_form" id="' . self::getDbTable() . '_form" method="post" action="' . admin_url( 'admin-ajax.php' ) . '" >';
462
-		if( ctype_digit( (string) $itemToEdit ) ) {
461
+		$the_form = '<form name="' . self::getDbTable() . '_form" id="' . self::getDbTable() . '_form" method="post" action="' . admin_url('admin-ajax.php') . '" >';
462
+		if (ctype_digit((string)$itemToEdit)) {
463 463
 			$the_form .= wpshop_form::form_input('action', 'action', 'wps_attribute_unit_update', 'hidden');
464
-			$the_form .= wp_nonce_field( 'update_attribute_unit', '_wpnonce' );
464
+			$the_form .= wp_nonce_field('update_attribute_unit', '_wpnonce');
465 465
 		} else {
466 466
 			$the_form .= wpshop_form::form_input('action', 'action', 'wps_attribute_unit_new', 'hidden');
467
-			$the_form .= wp_nonce_field( 'save_new_attribute_unit', '_wpnonce' );
467
+			$the_form .= wp_nonce_field('save_new_attribute_unit', '_wpnonce');
468 468
 		}
469
-		$the_form .= wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no' , 'hidden');
469
+		$the_form .= wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no', 'hidden');
470 470
 		$the_form .= $the_form_content_hidden . $the_form_general_content;
471
-		$the_form .= '<input type="button" value="' . __('Back', 'wpshop') . '" class="button-primary alignright" name="cancel_unit_edition" id="cancel_unit_edition" data-nonce="' . wp_create_nonce( 'load_attribute_units' ) . '" />
471
+		$the_form .= '<input type="button" value="' . __('Back', 'wpshop') . '" class="button-primary alignright" name="cancel_unit_edition" id="cancel_unit_edition" data-nonce="' . wp_create_nonce('load_attribute_units') . '" />
472 472
 				<input type="submit" value="' . __('Save', 'wpshop') . '" class="button-primary alignright" name="save_new_unit" id="save_new_unit" />
473 473
 			</form>
474 474
 			<script type="text/javascript" >
@@ -502,18 +502,18 @@  discard block
 block discarded – undo
502 502
 		$action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add';
503 503
 		$currentPageButton = '';
504 504
 
505
-		if($action == 'add')
505
+		if ($action == 'add')
506 506
 		{
507
-			if(current_user_can('wpshop_add_attributes'))
507
+			if (current_user_can('wpshop_add_attributes'))
508 508
 			{
509 509
 				$currentPageButton .= '<input type="button" class="button-primary" id="add" name="add" value="' . __('Add', 'wpshop') . '" />';
510 510
 			}
511 511
 		}
512
-		elseif(current_user_can('wpshop_edit_attributes'))
512
+		elseif (current_user_can('wpshop_edit_attributes'))
513 513
 		{
514 514
 			$currentPageButton .= '<input type="button" class="button-primary" id="save" name="save" value="' . __('Save', 'wpshop') . '" /><input type="button" class="button-primary" id="saveandcontinue" name="saveandcontinue" value="' . __('Save and continue edit', 'wpshop') . '" />';
515 515
 		}
516
-		if(current_user_can('wpshop_delete_attributes') && ($action != 'add'))
516
+		if (current_user_can('wpshop_delete_attributes') && ($action != 'add'))
517 517
 		{
518 518
 			$currentPageButton .= '<input type="button" class="button-primary" id="delete" name="delete" value="' . __('Delete', 'wpshop') . '" />';
519 519
 		}
@@ -532,13 +532,13 @@  discard block
 block discarded – undo
532 532
 	*
533 533
 	*	@return object $element_list A wordpress database object containing the attribute list
534 534
 	*/
535
-	public static function getElement($element_id = '', $element_status = "'valid', 'moderated'", $field_to_search = 'id'){
535
+	public static function getElement($element_id = '', $element_status = "'valid', 'moderated'", $field_to_search = 'id') {
536 536
 		global $wpdb;
537 537
 		$element_list = array();
538 538
 		$moreQuery = "";
539
-		$moreQueryArgs = array( 1, );
539
+		$moreQueryArgs = array(1,);
540 540
 
541
-		if($element_id != ''){
541
+		if ($element_id != '') {
542 542
 			$moreQuery = "
543 543
 			AND CURRENT_ELEMENT." . $field_to_search . " = %s ";
544 544
 			$moreQueryArgs[] = $element_id;
@@ -548,14 +548,14 @@  discard block
 block discarded – undo
548 548
 		"SELECT CURRENT_ELEMENT.*, UNIT_GROUP.name as group_name
549 549
 		FROM " . self::getDbTable() . " AS CURRENT_ELEMENT
550 550
 			LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " AS UNIT_GROUP ON (UNIT_GROUP.id = CURRENT_ELEMENT.group_id)
551
-		WHERE %d AND CURRENT_ELEMENT.status IN (".$element_status.") " . $moreQuery, $moreQueryArgs
551
+		WHERE %d AND CURRENT_ELEMENT.status IN (".$element_status . ") " . $moreQuery, $moreQueryArgs
552 552
 		);
553 553
 
554 554
 		/*	Get the query result regarding on the function parameters. If there must be only one result or a collection	*/
555
-		if($element_id == ''){
555
+		if ($element_id == '') {
556 556
 			$element_list = $wpdb->get_results($query);
557 557
 		}
558
-		else{
558
+		else {
559 559
 			$element_list = $wpdb->get_row($query);
560 560
 		}
561 561
 
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	/**
566 566
 	*
567 567
 	*/
568
-	public static function get_unit_list_for_group($group_id){
568
+	public static function get_unit_list_for_group($group_id) {
569 569
 		global $wpdb;
570 570
 		$unit_list_for_group = '';
571 571
 
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 	/**
581 581
 	*
582 582
 	*/
583
-	public static function get_default_unit_for_group($group_id){
583
+	public static function get_default_unit_for_group($group_id) {
584 584
 		global $wpdb;
585 585
 		$default_unit_for_group = '';
586 586
 
@@ -596,13 +596,13 @@  discard block
 block discarded – undo
596 596
 	*
597 597
 	*	@return object $attribute_unit_group_list The list of existing unit group
598 598
 	*/
599
-	public static function get_unit_group($element_id = '', $element_status = "'valid', 'moderated'", $field_to_search = 'id'){
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();
602 602
 		$moreQuery = "";
603
-		$moreQueryArgs = array( 1, );
603
+		$moreQueryArgs = array(1,);
604 604
 
605
-		if($element_id != ''){
605
+		if ($element_id != '') {
606 606
 			$moreQuery = "
607 607
 			AND CURRENT_ELEMENT." . $field_to_search . " = %d ";
608 608
 			$moreQueryArgs[] = $element_id;
@@ -611,11 +611,11 @@  discard block
 block discarded – undo
611 611
 		$query = $wpdb->prepare(
612 612
 		"SELECT CURRENT_ELEMENT.*
613 613
 		FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " AS CURRENT_ELEMENT
614
-		WHERE %d AND CURRENT_ELEMENT.status IN (".$element_status.") " . $moreQuery, $moreQueryArgs
614
+		WHERE %d AND CURRENT_ELEMENT.status IN (".$element_status . ") " . $moreQuery, $moreQueryArgs
615 615
 		);
616 616
 
617 617
 		/*	Get the query result regarding on the function parameters. If there must be only one result or a collection	*/
618
-		if($element_id == '')
618
+		if ($element_id == '')
619 619
 			$element_list = $wpdb->get_results($query);
620 620
 		else
621 621
 			$element_list = $wpdb->get_row($query);
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	*
633 633
 	*	@return string $listItemOutput The html code that output the item list
634 634
 	*/
635
-	public static function unit_group_list(){
635
+	public static function unit_group_list() {
636 636
 		$listItemOutput = '';
637 637
 
638 638
 		/*	Start the table definition	*/
@@ -645,36 +645,36 @@  discard block
 block discarded – undo
645 645
 
646 646
 		$line = 0;
647 647
 		$elementList = self::get_unit_group();
648
-		if(is_array($elementList) && (count($elementList) > 0)){
649
-			foreach($elementList as $element)
648
+		if (is_array($elementList) && (count($elementList) > 0)) {
649
+			foreach ($elementList as $element)
650 650
 			{
651 651
 				$tableRowsId[$line] = self::getDbTable() . '_' . $element->id;
652 652
 
653 653
 				$elementLabel = __($element->name, 'wpshop');
654 654
 				$subRowActions = '';
655 655
 				$attributeSlugUrl = self::getListingSlug();
656
-				if(current_user_can('wpshop_add_attributes_unit_group'))
656
+				if (current_user_can('wpshop_add_attributes_unit_group'))
657 657
 				{
658 658
 					$attributeSlugUrl = self::getEditionSlug();
659 659
 				}
660
-				if(current_user_can('wpshop_edit_attributes_unit_group'))
660
+				if (current_user_can('wpshop_edit_attributes_unit_group'))
661 661
 				{
662 662
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
663 663
 					$subRowActions .= '
664
-		<a href="#" id="edit_attribute_unit_group_' . $element->id . '" class="edit_attribute_unit_group" data-nonce="' . wp_create_nonce( 'edit_attribute_unit_group_' . $element->id ) . '" >' . __('Edit', 'wpshop') . '</a>';
664
+		<a href="#" id="edit_attribute_unit_group_' . $element->id . '" class="edit_attribute_unit_group" data-nonce="' . wp_create_nonce('edit_attribute_unit_group_' . $element->id) . '" >' . __('Edit', 'wpshop') . '</a>';
665 665
 				}
666
-				elseif(current_user_can('wpshop_view_attributes_unit_group'))
666
+				elseif (current_user_can('wpshop_view_attributes_unit_group'))
667 667
 				{
668 668
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
669 669
 				}
670
-				if(current_user_can('wpshop_delete_attributes_unit_group'))
670
+				if (current_user_can('wpshop_delete_attributes_unit_group'))
671 671
 				{
672
-					if($subRowActions != '')
672
+					if ($subRowActions != '')
673 673
 					{
674 674
 						$subRowActions .= '&nbsp;|&nbsp;';
675 675
 					}
676 676
 					$subRowActions .= '
677
-		<a href="#" id="delete_attribute_unit_group_' . $element->id . '" class="delete_attribute_unit_group" data-nonce="' . wp_create_nonce( 'delete_attribute_unit_group_' . $element->id ) . '" >' . __('Delete', 'wpshop') . '</a>';
677
+		<a href="#" id="delete_attribute_unit_group_' . $element->id . '" class="delete_attribute_unit_group" data-nonce="' . wp_create_nonce('delete_attribute_unit_group_' . $element->id) . '" >' . __('Delete', 'wpshop') . '</a>';
678 678
 				}
679 679
 
680 680
 				$rowActions = '
@@ -688,24 +688,24 @@  discard block
 block discarded – undo
688 688
 				$line++;
689 689
 			}
690 690
 		}
691
-		else{
691
+		else {
692 692
 			unset($tableRowValue);
693 693
 			$tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => __('No element to ouput here', 'wpshop'));
694 694
 			$tableRows[] = $tableRowValue;
695 695
 		}
696
-		if(current_user_can('wpshop_add_attributes_unit_group')){
696
+		if (current_user_can('wpshop_add_attributes_unit_group')) {
697 697
 			$listItemOutput .= '
698
-<input type="button" value="' . __('Add an unit group', 'wpshop') . '" class="button-secondary alignleft" name="add_attribute_unit_group" id="add_attribute_unit_group" data-nonce="' . wp_create_nonce( 'add_attribute_unit_group' ) . '" />';
698
+<input type="button" value="' . __('Add an unit group', 'wpshop') . '" class="button-secondary alignleft" name="add_attribute_unit_group" id="add_attribute_unit_group" data-nonce="' . wp_create_nonce('add_attribute_unit_group') . '" />';
699 699
 		}
700 700
 		$listItemOutput .= wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, $tableSummary, true) . '
701 701
 <script type="text/javascript" >
702 702
 	wpshop(document).ready(function(){
703 703
 		jQuery("#' . $tableId . '").dataTable();
704 704
 		jQuery("#wpshop_unit_list_tab").show();';
705
-		if(current_user_can('wpshop_delete_attributes_unit_group')){
705
+		if (current_user_can('wpshop_delete_attributes_unit_group')) {
706 706
 			$listItemOutput .= '
707 707
 		wpshop(document).on("click", ".delete_attribute_unit_group", function() {
708
-			if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this unit group', 'wpshop')  .' ?"))){
708
+			if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this unit group', 'wpshop') . ' ?"))){
709 709
 				wpshop("#wpshop_unit_group_list").load(ajaxurl, {
710 710
 					"action": "wps_attribute_group_unit_delete",
711 711
 					"elementIdentifier": wpshop(this).attr("id").replace("delete_attribute_unit_group_", ""),
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 			}
715 715
 		});';
716 716
 		}
717
-		if(current_user_can('wpshop_edit_attributes_unit_group')){
717
+		if (current_user_can('wpshop_edit_attributes_unit_group')) {
718 718
 			$listItemOutput .= '
719 719
 		wpshop(document).on("click", ".edit_attribute_unit_group", function() {
720 720
 			wpshop("#wpshop_unit_group_list").load(ajaxurl, {
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 			});
725 725
 		});';
726 726
 		}
727
-		if(current_user_can('wpshop_add_attributes_unit_group')){
727
+		if (current_user_can('wpshop_add_attributes_unit_group')) {
728 728
 			$listItemOutput .= '
729 729
 		wpshop("#add_attribute_unit_group").click(function(){
730 730
 			wpshop("#wpshop_unit_group_list").load(ajaxurl, {
@@ -744,25 +744,25 @@  discard block
 block discarded – undo
744 744
 	*
745 745
 	*	@return string The html code that output the interface for adding a nem item
746 746
 	*/
747
-	public static function unit_group_edition($itemToEdit = ''){
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);
750 750
 
751
-		if( ctype_digit( (string) $itemToEdit ) ) {
752
-			$editedItem = self::get_unit_group( (int) $itemToEdit );
751
+		if (ctype_digit((string)$itemToEdit)) {
752
+			$editedItem = self::get_unit_group((int)$itemToEdit);
753 753
 		} else {
754 754
 			$editedItem = '';
755 755
 		}
756 756
 
757 757
 		$the_form_content_hidden = $the_form_general_content = $the_form_option_content = '';
758
-		foreach($dbFieldList as $input_key => $input_def){
758
+		foreach ($dbFieldList as $input_key => $input_def) {
759 759
 			$pageAction = isset($_REQUEST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_action']) : '';
760 760
 			$requestFormValue = isset($_REQUEST[self::currentPageCode][$input_def['name']]) ? wpshop_tools::varSanitizer($_REQUEST[self::currentPageCode][$input_def['name']]) : '';
761 761
 			$currentFieldValue = $input_def['value'];
762
-			if(is_object($editedItem)){
762
+			if (is_object($editedItem)) {
763 763
 				$currentFieldValue = $editedItem->{$input_def['name']};
764 764
 			}
765
-			elseif(($pageAction != '') && ($requestFormValue != '')){
765
+			elseif (($pageAction != '') && ($requestFormValue != '')) {
766 766
 				$currentFieldValue = $requestFormValue;
767 767
 			}
768 768
 
@@ -771,9 +771,9 @@  discard block
 block discarded – undo
771 771
 			$input_def['value'] = __(str_replace("\\", "", $input_def['value']), 'wpshop');
772 772
 			$the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
773 773
 
774
-			if($input_def['type'] != 'hidden'){
774
+			if ($input_def['type'] != 'hidden') {
775 775
 				$label = 'for="' . $input_def['name'] . '"';
776
-				if(($input_def['type'] == 'radio') || ($input_def['type'] == 'checkbox')){
776
+				if (($input_def['type'] == 'radio') || ($input_def['type'] == 'checkbox')) {
777 777
 					$label = '';
778 778
 				}
779 779
 				$input = '
@@ -785,30 +785,30 @@  discard block
 block discarded – undo
785 785
 			' . $the_input . '
786 786
 		</div>
787 787
 	</div>';
788
-				if(substr($input_def['name'], 0, 3) == 'is_'){
788
+				if (substr($input_def['name'], 0, 3) == 'is_') {
789 789
 					$the_form_option_content .= $input;
790 790
 				}
791
-				else{
791
+				else {
792 792
 					$the_form_general_content .= $input;
793 793
 				}
794 794
 			}
795
-			else{
795
+			else {
796 796
 				$the_form_content_hidden .= '
797 797
 	' . $the_input;
798 798
 			}
799 799
 		}
800 800
 
801 801
 		$the_form = '<form name="' . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_form" id="' . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_form" method="post" action="' . admin_url('admin-ajax.php') . '" >';
802
-		if( ctype_digit( (string) $itemToEdit ) ) {
802
+		if (ctype_digit((string)$itemToEdit)) {
803 803
 			$the_form .= wpshop_form::form_input('action', 'action', 'wps_attribute_group_unit_update', 'hidden');
804
-			$the_form .= wp_nonce_field( 'update_attribute_unit_group', '_wpnonce' );
804
+			$the_form .= wp_nonce_field('update_attribute_unit_group', '_wpnonce');
805 805
 		} else {
806 806
 			$the_form .= wpshop_form::form_input('action', 'action', 'wps_attribute_group_unit_new', 'hidden');
807
-			$the_form .= wp_nonce_field( 'save_new_attribute_unit_group', '_wpnonce' );
807
+			$the_form .= wp_nonce_field('save_new_attribute_unit_group', '_wpnonce');
808 808
 		}
809
-		$the_form .= wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no' , 'hidden');
809
+		$the_form .= wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no', 'hidden');
810 810
 		$the_form .= $the_form_content_hidden . $the_form_general_content;
811
-		$the_form .= '<input type="button" value="' . __('Retour', 'wpshop') . '" class="button-primary alignright" name="cancel_unit_group_edition" id="cancel_unit_group_edition" data-nonce="' . wp_create_nonce( 'load_attribute_unit_groups' ) . '"/>
811
+		$the_form .= '<input type="button" value="' . __('Retour', 'wpshop') . '" class="button-primary alignright" name="cancel_unit_group_edition" id="cancel_unit_group_edition" data-nonce="' . wp_create_nonce('load_attribute_unit_groups') . '"/>
812 812
 				<input type="submit" value="' . __('Save', 'wpshop') . '" class="button-primary alignright" name="save_new_unit_group" id="save_new_unit_group" />
813 813
 			</form>
814 814
 			<script type="text/javascript" >
@@ -836,11 +836,11 @@  discard block
 block discarded – undo
836 836
 
837 837
 	/*	Default currecy for the entire shop	*/
838 838
 	public static function wpshop_shop_currency_list_field() {
839
-		if( is_null( self::$currencies_cache ) ) {
839
+		if (is_null(self::$currencies_cache)) {
840 840
 			$currency_group = get_option('wpshop_shop_currency_group');
841
-			if( !empty ( $currency_group ) ) {
841
+			if (!empty ($currency_group)) {
842 842
 				global $wpdb;
843
-				$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE group_id = %d', $currency_group);
843
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id = %d', $currency_group);
844 844
 				self::$currencies_cache = $wpdb->get_results($query);
845 845
 			} else {
846 846
 				self::$currencies_cache = '';
@@ -850,17 +850,17 @@  discard block
 block discarded – undo
850 850
 		$current_currency = get_option('wpshop_shop_default_currency');
851 851
 
852 852
 		$currencies_options = '';
853
-		if ( !empty (self::$currencies_cache) ) {
854
-			foreach ( self::$currencies_cache as $currency) {
855
-				$currencies_options .= '<option value="'.$currency->id.'"'.(($currency->id == $current_currency) ? ' selected="selected"' : null).'>'.$currency->name.' ('.$currency->unit.')</option>';
853
+		if (!empty (self::$currencies_cache)) {
854
+			foreach (self::$currencies_cache as $currency) {
855
+				$currencies_options .= '<option value="' . $currency->id . '"' . (($currency->id == $current_currency) ? ' selected="selected"' : null) . '>' . $currency->name . ' (' . $currency->unit . ')</option>';
856 856
 			}
857 857
 		}
858 858
 		else {
859
-			foreach($wpshop_shop_currencies as $k => $v) {
860
-				$currencies_options .= '<option value="'.$k.'"'.(($k==$current_currency) ? ' selected="selected"' : null).'>'.$k.' ('.$v.')</option>';
859
+			foreach ($wpshop_shop_currencies as $k => $v) {
860
+				$currencies_options .= '<option value="' . $k . '"' . (($k == $current_currency) ? ' selected="selected"' : null) . '>' . $k . ' (' . $v . ')</option>';
861 861
 			}
862 862
 		}
863
-		return '<select name="wpshop_shop_default_currency" class="wpshop_currency_field" >'.$currencies_options.'</select>';
863
+		return '<select name="wpshop_shop_default_currency" class="wpshop_currency_field" >' . $currencies_options . '</select>';
864 864
 	}
865 865
 
866 866
 	/**
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 		global $wpdb;
874 874
 
875 875
 		/** Get the _unit_group_id and _default_unit */
876
-		return $wpdb->get_row( $wpdb->prepare( 'SELECT _unit_group_id, _default_unit FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code=%s', array( $attribute_code ) ) );
876
+		return $wpdb->get_row($wpdb->prepare('SELECT _unit_group_id, _default_unit FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code=%s', array($attribute_code)));
877 877
 	}
878 878
 
879 879
 	/**
@@ -885,15 +885,15 @@  discard block
 block discarded – undo
885 885
 	 * @return stdClass Object [_unit_group_id], [_default_unit]
886 886
 	 */
887 887
 	public static function get_the_attribute_unit_by_code_for_product($product_id, $attribute_code) {
888
-		$unit = self::get_default_unit_attribute( $attribute_code );
888
+		$unit = self::get_default_unit_attribute($attribute_code);
889 889
 
890
-		if(empty($unit))
890
+		if (empty($unit))
891 891
 			return null;
892 892
 
893 893
 		$post_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
894 894
 
895 895
 		/** Si on trouve une unité */
896
-		if(!empty($post_meta) && !empty($post_meta['unit']) && !empty($post_meta['unit'][$attribute_code]))
896
+		if (!empty($post_meta) && !empty($post_meta['unit']) && !empty($post_meta['unit'][$attribute_code]))
897 897
 			$unit->_default_unit = $post_meta['unit'][$attribute_code];
898 898
 
899 899
 		return $unit;
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
 	public static function the_attribute_unit_by_code_for_product($product_id, $attribute_code) {
909 909
 		$unit = self::get_the_attribute_unit_by_code_for_product($product_id, $attribute_code);
910 910
 
911
-		if(empty($unit))
911
+		if (empty($unit))
912 912
 			return null;
913 913
 
914 914
 		echo self::get_the_subname_unit($unit->_unit_group_id, $unit->_default_unit);
@@ -925,10 +925,10 @@  discard block
 block discarded – undo
925 925
 		global $wpdb;
926 926
 
927 927
 		/** Si pas d'unité ou de groupe, null */
928
-		if(0 === $unit_id || 0 === $group_id)
928
+		if (0 === $unit_id || 0 === $group_id)
929 929
 			return null;
930 930
 
931
-		return $wpdb->get_var( $wpdb->prepare( 'SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id=%d AND id=%d', array( $group_id, $unit_id ) ) );
931
+		return $wpdb->get_var($wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id=%d AND id=%d', array($group_id, $unit_id)));
932 932
 	}
933 933
 
934 934
 	/**
@@ -942,9 +942,9 @@  discard block
 block discarded – undo
942 942
 		global $wpdb;
943 943
 
944 944
 		/** Si pas d'unité ou de groupe, null */
945
-		if(0 === $unit_id || 0 === $group_id)
945
+		if (0 === $unit_id || 0 === $group_id)
946 946
 			return null;
947 947
 
948
-		return $wpdb->get_var( $wpdb->prepare( 'SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id=%d AND id=%d', array( $group_id, $unit_id ) ) );
948
+		return $wpdb->get_var($wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id=%d AND id=%d', array($group_id, $unit_id)));
949 949
 	}
950 950
 }
Please login to merge, or discard this patch.
Braces   +48 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 
3 5
 /*	Check if file is include. No direct access possible with file url	*/
4 6
 if ( !defined( 'WPSHOP_VERSION' ) ) {
@@ -125,13 +127,11 @@  discard block
 block discarded – undo
125 127
 			{
126 128
 				$editedItem = self::getElement($objectInEdition);
127 129
 				$title = sprintf(__(self::pageEditingTitle, 'wpshop'), str_replace("\\", "", $editedItem->frontend_label) . '&nbsp;(' . $editedItem->code . ')');
128
-			}
129
-			elseif($action == 'add')
130
+			} elseif($action == 'add')
130 131
 			{
131 132
 				$title = __(self::pageAddingTitle, 'wpshop');
132 133
 			}
133
-		}
134
-		elseif((self::getEditionSlug() != self::getListingSlug()) && (sanitize_text_field($page) == self::getEditionSlug()))
134
+		} elseif((self::getEditionSlug() != self::getListingSlug()) && (sanitize_text_field($page) == self::getEditionSlug()))
135 135
 		{
136 136
 			$title = __(self::pageAddingTitle, 'wpshop');
137 137
 		}
@@ -156,8 +156,7 @@  discard block
 block discarded – undo
156 156
 		{
157 157
 			$editedElement = self::getElement($saveditem);
158 158
 			$pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>');
159
-		}
160
-		elseif(($action != '') && ($action == 'deleteok') && ($saveditem > 0))
159
+		} elseif(($action != '') && ($action == 'deleteok') && ($saveditem > 0))
161 160
 		{
162 161
 			$editedElement = self::getElement($saveditem, "'deleted'");
163 162
 			$pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>');
@@ -179,32 +178,27 @@  discard block
 block discarded – undo
179 178
 					if(current_user_can('wpshop_delete_attributes'))
180 179
 					{
181 180
 						$attribute_group_parameter['status'] = 'deleted';
182
-					}
183
-					else
181
+					} else
184 182
 					{
185 183
 						$actionResult = 'userNotAllowedForActionDelete';
186 184
 					}
187 185
 				}
188 186
 				$actionResult = wpshop_database::update($attribute_group_parameter, $id, self::getDbTable());
189
-			}
190
-			else
187
+			} else
191 188
 			{
192 189
 				$actionResult = 'userNotAllowedForActionEdit';
193 190
 			}
194
-		}
195
-		elseif(($pageAction != '') && (($pageAction == 'delete'))){
191
+		} elseif(($pageAction != '') && (($pageAction == 'delete'))){
196 192
 			if(current_user_can('wpshop_delete_attributes'))
197 193
 			{
198 194
 				$attribute_group_parameter['last_update_date'] = date('Y-m-d H:i:s');
199 195
 				$attribute_group_parameter['status'] = 'deleted';
200 196
 				$actionResult = wpshop_database::update($attribute_group_parameter, $id, self::getDbTable());
201
-			}
202
-			else
197
+			} else
203 198
 			{
204 199
 				$actionResult = 'userNotAllowedForActionDelete';
205 200
 			}
206
-		}
207
-		elseif(($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))){
201
+		} elseif(($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))){
208 202
 			if(current_user_can('wpshop_add_attributes')){
209 203
 				$attribute_group_parameter['creation_date'] = date('Y-m-d H:i:s');
210 204
 				if(trim($attribute_group_parameter['code']) == ''){
@@ -217,8 +211,7 @@  discard block
 block discarded – undo
217 211
 				}
218 212
 				$actionResult = wpshop_database::save($attribute_group_parameter, self::getDbTable());
219 213
 				$id = $wpdb->insert_id;
220
-			}
221
-			else{
214
+			} else{
222 215
 				$actionResult = 'userNotAllowedForActionAdd';
223 216
 			}
224 217
 		}
@@ -236,8 +229,7 @@  discard block
 block discarded – undo
236 229
 				{
237 230
 					$pageMessage .= '<br/>' . $wpdb->last_error;
238 231
 				}
239
-			}
240
-			elseif(($actionResult == 'done') || ($actionResult == 'nothingToUpdate'))
232
+			} elseif(($actionResult == 'done') || ($actionResult == 'nothingToUpdate'))
241 233
 			{/*	CHANGE HERE FOR SPECIFIC CASE	*/
242 234
 				/*****************************************************************************************************************/
243 235
 				/*************************			CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT				******************/
@@ -250,17 +242,14 @@  discard block
 block discarded – undo
250 242
 				if(($pageAction == 'edit') || ($pageAction == 'save'))
251 243
 				{
252 244
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id));
253
-				}
254
-				elseif($pageAction == 'add')
245
+				} elseif($pageAction == 'add')
255 246
 				{
256 247
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id));
257
-				}
258
-				elseif($pageAction == 'delete')
248
+				} elseif($pageAction == 'delete')
259 249
 				{
260 250
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id));
261 251
 				}
262
-			}
263
-			elseif(($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete'))
252
+			} elseif(($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete'))
264 253
 			{
265 254
 				$pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop');
266 255
 			}
@@ -309,8 +298,7 @@  discard block
 block discarded – undo
309 298
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
310 299
 					$subRowActions .= '
311 300
 		<a href="#" id="edit_attribute_unit_' . $element->id . '" class="edit_attribute_unit" data-nonce="' . wp_create_nonce( 'edit_attribute_unit_' . $element->id ) . '" >' . __('Edit', 'wpshop') . '</a>';
312
-				}
313
-				elseif(current_user_can('wpshop_view_attributes_unit'))
301
+				} elseif(current_user_can('wpshop_view_attributes_unit'))
314 302
 				{
315 303
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
316 304
 				}
@@ -336,8 +324,7 @@  discard block
 block discarded – undo
336 324
 
337 325
 				$line++;
338 326
 			}
339
-		}
340
-		else{
327
+		} else{
341 328
 			unset($tableRowValue);
342 329
 			$tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => __('No element to ouput here', 'wpshop'));
343 330
 			$tableRowValue[] = array('class' => self::currentPageCode . '_name_cell', 'value' => '');
@@ -418,8 +405,7 @@  discard block
 block discarded – undo
418 405
 			$currentFieldValue = $input_def['value'];
419 406
 			if(is_object($editedItem)){
420 407
 				$currentFieldValue = $editedItem->{$input_def['name']};
421
-			}
422
-			elseif(($pageAction != '') && ($requestFormValue != '')){
408
+			} elseif(($pageAction != '') && ($requestFormValue != '')){
423 409
 				$currentFieldValue = $requestFormValue;
424 410
 			}
425 411
 
@@ -451,8 +437,7 @@  discard block
 block discarded – undo
451 437
 				</div>';
452 438
 
453 439
 
454
-			}
455
-			else{
440
+			} else{
456 441
 				$the_form_content_hidden .= '
457 442
 	' . $the_input;
458 443
 			}
@@ -508,8 +493,7 @@  discard block
 block discarded – undo
508 493
 			{
509 494
 				$currentPageButton .= '<input type="button" class="button-primary" id="add" name="add" value="' . __('Add', 'wpshop') . '" />';
510 495
 			}
511
-		}
512
-		elseif(current_user_can('wpshop_edit_attributes'))
496
+		} elseif(current_user_can('wpshop_edit_attributes'))
513 497
 		{
514 498
 			$currentPageButton .= '<input type="button" class="button-primary" id="save" name="save" value="' . __('Save', 'wpshop') . '" /><input type="button" class="button-primary" id="saveandcontinue" name="saveandcontinue" value="' . __('Save and continue edit', 'wpshop') . '" />';
515 499
 		}
@@ -554,8 +538,7 @@  discard block
 block discarded – undo
554 538
 		/*	Get the query result regarding on the function parameters. If there must be only one result or a collection	*/
555 539
 		if($element_id == ''){
556 540
 			$element_list = $wpdb->get_results($query);
557
-		}
558
-		else{
541
+		} else{
559 542
 			$element_list = $wpdb->get_row($query);
560 543
 		}
561 544
 
@@ -615,10 +598,11 @@  discard block
 block discarded – undo
615 598
 		);
616 599
 
617 600
 		/*	Get the query result regarding on the function parameters. If there must be only one result or a collection	*/
618
-		if($element_id == '')
619
-			$element_list = $wpdb->get_results($query);
620
-		else
621
-			$element_list = $wpdb->get_row($query);
601
+		if($element_id == '') {
602
+					$element_list = $wpdb->get_results($query);
603
+		} else {
604
+					$element_list = $wpdb->get_row($query);
605
+		}
622 606
 
623 607
 		return $element_list;
624 608
 
@@ -662,8 +646,7 @@  discard block
 block discarded – undo
662 646
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
663 647
 					$subRowActions .= '
664 648
 		<a href="#" id="edit_attribute_unit_group_' . $element->id . '" class="edit_attribute_unit_group" data-nonce="' . wp_create_nonce( 'edit_attribute_unit_group_' . $element->id ) . '" >' . __('Edit', 'wpshop') . '</a>';
665
-				}
666
-				elseif(current_user_can('wpshop_view_attributes_unit_group'))
649
+				} elseif(current_user_can('wpshop_view_attributes_unit_group'))
667 650
 				{
668 651
 					$editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&amp;action=edit&amp;id=' . $element->id);
669 652
 				}
@@ -687,8 +670,7 @@  discard block
 block discarded – undo
687 670
 
688 671
 				$line++;
689 672
 			}
690
-		}
691
-		else{
673
+		} else{
692 674
 			unset($tableRowValue);
693 675
 			$tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => __('No element to ouput here', 'wpshop'));
694 676
 			$tableRows[] = $tableRowValue;
@@ -761,8 +743,7 @@  discard block
 block discarded – undo
761 743
 			$currentFieldValue = $input_def['value'];
762 744
 			if(is_object($editedItem)){
763 745
 				$currentFieldValue = $editedItem->{$input_def['name']};
764
-			}
765
-			elseif(($pageAction != '') && ($requestFormValue != '')){
746
+			} elseif(($pageAction != '') && ($requestFormValue != '')){
766 747
 				$currentFieldValue = $requestFormValue;
767 748
 			}
768 749
 
@@ -787,12 +768,10 @@  discard block
 block discarded – undo
787 768
 	</div>';
788 769
 				if(substr($input_def['name'], 0, 3) == 'is_'){
789 770
 					$the_form_option_content .= $input;
790
-				}
791
-				else{
771
+				} else{
792 772
 					$the_form_general_content .= $input;
793 773
 				}
794
-			}
795
-			else{
774
+			} else{
796 775
 				$the_form_content_hidden .= '
797 776
 	' . $the_input;
798 777
 			}
@@ -854,8 +833,7 @@  discard block
 block discarded – undo
854 833
 			foreach ( self::$currencies_cache as $currency) {
855 834
 				$currencies_options .= '<option value="'.$currency->id.'"'.(($currency->id == $current_currency) ? ' selected="selected"' : null).'>'.$currency->name.' ('.$currency->unit.')</option>';
856 835
 			}
857
-		}
858
-		else {
836
+		} else {
859 837
 			foreach($wpshop_shop_currencies as $k => $v) {
860 838
 				$currencies_options .= '<option value="'.$k.'"'.(($k==$current_currency) ? ' selected="selected"' : null).'>'.$k.' ('.$v.')</option>';
861 839
 			}
@@ -887,14 +865,16 @@  discard block
 block discarded – undo
887 865
 	public static function get_the_attribute_unit_by_code_for_product($product_id, $attribute_code) {
888 866
 		$unit = self::get_default_unit_attribute( $attribute_code );
889 867
 
890
-		if(empty($unit))
891
-			return null;
868
+		if(empty($unit)) {
869
+					return null;
870
+		}
892 871
 
893 872
 		$post_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
894 873
 
895 874
 		/** Si on trouve une unité */
896
-		if(!empty($post_meta) && !empty($post_meta['unit']) && !empty($post_meta['unit'][$attribute_code]))
897
-			$unit->_default_unit = $post_meta['unit'][$attribute_code];
875
+		if(!empty($post_meta) && !empty($post_meta['unit']) && !empty($post_meta['unit'][$attribute_code])) {
876
+					$unit->_default_unit = $post_meta['unit'][$attribute_code];
877
+		}
898 878
 
899 879
 		return $unit;
900 880
 	}
@@ -908,8 +888,9 @@  discard block
 block discarded – undo
908 888
 	public static function the_attribute_unit_by_code_for_product($product_id, $attribute_code) {
909 889
 		$unit = self::get_the_attribute_unit_by_code_for_product($product_id, $attribute_code);
910 890
 
911
-		if(empty($unit))
912
-			return null;
891
+		if(empty($unit)) {
892
+					return null;
893
+		}
913 894
 
914 895
 		echo self::get_the_subname_unit($unit->_unit_group_id, $unit->_default_unit);
915 896
 	}
@@ -925,8 +906,9 @@  discard block
 block discarded – undo
925 906
 		global $wpdb;
926 907
 
927 908
 		/** Si pas d'unité ou de groupe, null */
928
-		if(0 === $unit_id || 0 === $group_id)
929
-			return null;
909
+		if(0 === $unit_id || 0 === $group_id) {
910
+					return null;
911
+		}
930 912
 
931 913
 		return $wpdb->get_var( $wpdb->prepare( 'SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id=%d AND id=%d', array( $group_id, $unit_id ) ) );
932 914
 	}
@@ -942,8 +924,9 @@  discard block
 block discarded – undo
942 924
 		global $wpdb;
943 925
 
944 926
 		/** Si pas d'unité ou de groupe, null */
945
-		if(0 === $unit_id || 0 === $group_id)
946
-			return null;
927
+		if(0 === $unit_id || 0 === $group_id) {
928
+					return null;
929
+		}
947 930
 
948 931
 		return $wpdb->get_var( $wpdb->prepare( 'SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE group_id=%d AND id=%d', array( $group_id, $unit_id ) ) );
949 932
 	}
Please login to merge, or discard this patch.
includes/librairies/eav/entities.class.php 1 patch
Spacing   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 /**
3 3
  * Define utilities to manage entities
4 4
  *
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 /*
12 12
  * Check if file is include. No direct access possible with file url
13 13
  */
14
-if ( !defined( 'WPSHOP_VERSION' ) ) {
15
-	die( __('Access is not allowed by this way', 'wpshop') );
14
+if (!defined('WPSHOP_VERSION')) {
15
+	die(__('Access is not allowed by this way', 'wpshop'));
16 16
 }
17 17
 
18 18
 /**
@@ -33,20 +33,20 @@  discard block
 block discarded – undo
33 33
 	public static function create_wpshop_entities_type() {
34 34
 		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, array(
35 35
 			'labels' => array(
36
-				'name'					=> __( 'Entities', 'wpshop' ),
37
-				'singular_name' 		=> __( 'Entity', 'wpshop' ),
38
-				'add_new_item' 			=> __( 'Add new entity', 'wpshop' ),
39
-				'add_new' 				=> __( 'Add new entity', 'wpshop' ),
40
-				'add_new_item' 			=> __( 'Add new entity', 'wpshop' ),
41
-				'edit_item' 			=> __( 'Edit entity', 'wpshop' ),
42
-				'new_item' 				=> __( 'New entity', 'wpshop' ),
43
-				'view_item' 			=> __( 'View entity', 'wpshop' ),
44
-				'search_items' 			=> __( 'Search entities', 'wpshop' ),
45
-				'not_found' 			=> __( 'No entities found', 'wpshop' ),
46
-				'not_found_in_trash' 	=> __( 'No entities found in Trash', 'wpshop' ),
36
+				'name'					=> __('Entities', 'wpshop'),
37
+				'singular_name' 		=> __('Entity', 'wpshop'),
38
+				'add_new_item' 			=> __('Add new entity', 'wpshop'),
39
+				'add_new' 				=> __('Add new entity', 'wpshop'),
40
+				'add_new_item' 			=> __('Add new entity', 'wpshop'),
41
+				'edit_item' 			=> __('Edit entity', 'wpshop'),
42
+				'new_item' 				=> __('New entity', 'wpshop'),
43
+				'view_item' 			=> __('View entity', 'wpshop'),
44
+				'search_items' 			=> __('Search entities', 'wpshop'),
45
+				'not_found' 			=> __('No entities found', 'wpshop'),
46
+				'not_found_in_trash' 	=> __('No entities found in Trash', 'wpshop'),
47 47
 				'parent_item_colon' 	=> '',
48 48
 			),
49
-			'supports' 				=> array( 'title', 'editor', 'page-attributes' ),
49
+			'supports' 				=> array('title', 'editor', 'page-attributes'),
50 50
 			'public' 				=> true,
51 51
 			'has_archive'			=> true,
52 52
 			'publicly_queryable' 	=> false,
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 		/** Metabox allowgin to choose a custome rewrite for an entiy	*/
77 77
 		add_meta_box(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES . '_rewrite', __('Rewrite for entity', 'wpshop'), array('wpshop_entities', 'wpshop_entity_rewrite'), WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'normal', 'high');
78 78
 
79
-		if ( !in_array( $post->post_name, unserialize( WPSHOP_DEFAULT_CUSTOM_TYPES ) ) ) {
79
+		if (!in_array($post->post_name, unserialize(WPSHOP_DEFAULT_CUSTOM_TYPES))) {
80 80
 			/** Display or not address in admin menu	*/
81 81
 			add_meta_box(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES . '_admin_menu_display', __('Display in admin menu', 'wpshop'), array('wpshop_entities', 'wpshop_display_entity_in_admin_menu'), WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'side', 'low');
82 82
 		}
83 83
 
84 84
 		/** Join address to entity	*/
85
-		if ( !in_array( $post->post_name, array( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ) ) ) {
85
+		if (!in_array($post->post_name, array(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS))) {
86 86
 			add_meta_box(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES . '_join_address_to_entity', __('Join Address to this entity', 'wpshop'), array('wpshop_entities', 'wpshop_join_address_to_entity'), WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'side', 'low');
87 87
 		}
88 88
 	}
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @param object $post The entity type being edited
94 94
 	 */
95
-	public static function wpshop_entity_support_section( $entity ) {
95
+	public static function wpshop_entity_support_section($entity) {
96 96
 		$output = '';
97 97
 		$support_list = unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT);
98 98
 
99 99
 		$current_entity_params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
100 100
 
101
-		unset($input_def);$input_def=array();
101
+		unset($input_def); $input_def = array();
102 102
 		$input_def['type'] = 'checkbox';
103 103
 
104
-		foreach ( $support_list as $support ) {
104
+		foreach ($support_list as $support) {
105 105
 			$input_def['id'] = 'wpshop_entity_support';
106 106
 			$input_def['name'] = $support;
107 107
 			$input_def['possible_value'] = array($support);
108
-			if ( !empty($current_entity_params['support']) && in_array($support, $current_entity_params['support']) ) {
108
+			if (!empty($current_entity_params['support']) && in_array($support, $current_entity_params['support'])) {
109 109
 				$input_def['value'] = $support;
110 110
 			}
111 111
 
112
-			$output .= '<p class="wpshop_entities_support_type wpshop_entities_support_type_' . $support . '" >' . wpshop_form::check_input_type($input_def, 'wpshop_entity_support') . ' <label for="'.$input_def['id'].'_'.$support.'">' . __($support, 'wpshop') . '</label></p>';
112
+			$output .= '<p class="wpshop_entities_support_type wpshop_entities_support_type_' . $support . '" >' . wpshop_form::check_input_type($input_def, 'wpshop_entity_support') . ' <label for="' . $input_def['id'] . '_' . $support . '">' . __($support, 'wpshop') . '</label></p>';
113 113
 		}
114 114
 		$output .= '<p class="wpshop_cls" ></p>';
115 115
 
@@ -121,33 +121,33 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @param unknown_type $entity
123 123
 	 */
124
-	public static function wpshop_entity_rewrite( $entity ) {
124
+	public static function wpshop_entity_rewrite($entity) {
125 125
 		$output = '';
126 126
 
127 127
 		$current_entity_params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
128 128
 
129
-		unset($input_def);$input_def=array();
129
+		unset($input_def); $input_def = array();
130 130
 		$input_def['type'] = 'text';
131 131
 		$input_def['id'] = 'wpshop_entity_rewrite';
132 132
 		$input_def['name'] = 'wpshop_entity_rewrite[slug]';
133
-		$input_def['value'] = (!empty($current_entity_params['rewrite']['slug']) ? $current_entity_params['rewrite']['slug'] :'');
133
+		$input_def['value'] = (!empty($current_entity_params['rewrite']['slug']) ? $current_entity_params['rewrite']['slug'] : '');
134 134
 
135
-		$output .= '<p><label for="'.$input_def['id'].'">' . __('Choose how this entity will be rewrite in front side. If you let it empty default will be taken', 'wpshop') . '</label><br/>' . wpshop_form::check_input_type($input_def) . '</p>';
135
+		$output .= '<p><label for="' . $input_def['id'] . '">' . __('Choose how this entity will be rewrite in front side. If you let it empty default will be taken', 'wpshop') . '</label><br/>' . wpshop_form::check_input_type($input_def) . '</p>';
136 136
 
137 137
 		echo $output;
138 138
 	}
139 139
 
140 140
 	public static function wpshop_display_entity_in_admin_menu() {
141 141
 		$checked = '';
142
-		$post = !empty( $_GET['post'] ) ? (int) $_GET['post'] : 0;
143
-		if ( !empty($post) ) {
144
-			$current_entity_params = get_post_meta( $post, '_wpshop_entity_params', true);
142
+		$post = !empty($_GET['post']) ? (int)$_GET['post'] : 0;
143
+		if (!empty($post)) {
144
+			$current_entity_params = get_post_meta($post, '_wpshop_entity_params', true);
145 145
 
146
-			if ( !empty($current_entity_params['display_admin_menu']) ) {
146
+			if (!empty($current_entity_params['display_admin_menu'])) {
147 147
 				$checked = 'checked ="checked"';
148 148
 				}
149 149
 		}
150
-		$output = '<input type="checkbox" id="wpshop_display_in_admin_menu" name="wpshop_display_in_admin_menu" ' .$checked. '/><label for="wpshop_display_in_admin_menu"> '.__('Display in admin menu', 'wpshop').'</label>';
150
+		$output = '<input type="checkbox" id="wpshop_display_in_admin_menu" name="wpshop_display_in_admin_menu" ' . $checked . '/><label for="wpshop_display_in_admin_menu"> ' . __('Display in admin menu', 'wpshop') . '</label>';
151 151
 		echo $output;
152 152
 	}
153 153
 
@@ -155,21 +155,21 @@  discard block
 block discarded – undo
155 155
 	 * Save custom information for entity type
156 156
 	 */
157 157
 	public static function save_entity_type_custom_informations() {
158
-		$post_id = !empty($_POST['post_ID']) ? intval( sanitize_key($_POST['post_ID']) ) : null;
159
-		$post_support = !empty($_POST['wpshop_entity_support']) && is_array( (array)$_POST['wpshop_entity_support'] ) ? (array)$_POST['wpshop_entity_support'] : null;
160
-		$wpshop_entity_rewrite = !empty($_POST['wpshop_entity_rewrite']) ? (array) $_POST['wpshop_entity_rewrite'] : null;
158
+		$post_id = !empty($_POST['post_ID']) ? intval(sanitize_key($_POST['post_ID'])) : null;
159
+		$post_support = !empty($_POST['wpshop_entity_support']) && is_array((array)$_POST['wpshop_entity_support']) ? (array)$_POST['wpshop_entity_support'] : null;
160
+		$wpshop_entity_rewrite = !empty($_POST['wpshop_entity_rewrite']) ? (array)$_POST['wpshop_entity_rewrite'] : null;
161 161
 		$wpshop_entity_display_menu = !empty($_POST['wpshop_display_in_admin_menu']) ? sanitize_key($_POST['wpshop_display_in_admin_menu']) : null;
162 162
 
163
-		$address_type = !empty ($_POST['address_type']) ? (array) $_POST['address_type'] : null;
164
-		if ( isset($address_type) ) {
163
+		$address_type = !empty ($_POST['address_type']) ? (array)$_POST['address_type'] : null;
164
+		if (isset($address_type)) {
165 165
 			$save_array = array();
166
-			foreach ( $address_type as $key=>$value ) {
167
-				$save_array[] = intval( sanitize_text_field($value) );
166
+			foreach ($address_type as $key=>$value) {
167
+				$save_array[] = intval(sanitize_text_field($value));
168 168
 			}
169
-			update_post_meta( $post_id, '_wpshop_entity_attached_address', $save_array );
169
+			update_post_meta($post_id, '_wpshop_entity_attached_address', $save_array);
170 170
 		}
171 171
 
172
-		if ( get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES ) {
172
+		if (get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) {
173 173
 			update_post_meta($post_id, '_wpshop_entity_params', array('support' => $post_support, 'rewrite' => $wpshop_entity_rewrite, 'display_admin_menu'=>$wpshop_entity_display_menu));
174 174
 			flush_rewrite_rules();
175 175
 		}
@@ -178,19 +178,19 @@  discard block
 block discarded – undo
178 178
 	/**
179 179
 	 * Permite to join one or several address to an entity
180 180
 	 */
181
-	public static function wpshop_join_address_to_entity () {
181
+	public static function wpshop_join_address_to_entity() {
182 182
 		global $wpdb;
183 183
 		// Select the id of the entity address
184
-		$query = $wpdb->prepare('SELECT id FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_name = %s', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
185
-		$entity_id = $wpdb->get_var( $query );
184
+		$query = $wpdb->prepare('SELECT id FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_name = %s', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
185
+		$entity_id = $wpdb->get_var($query);
186 186
 		//Get the Post_meta
187
-		$attached_address_values = get_post_meta( intval(wpshop_tools::varSanitizer( (!empty($_GET['post']) ? $_GET['post'] : '') )), '_wpshop_entity_attached_address', true );
187
+		$attached_address_values = get_post_meta(intval(wpshop_tools::varSanitizer((!empty($_GET['post']) ? $_GET['post'] : ''))), '_wpshop_entity_attached_address', true);
188 188
 		//Select and Display all addresses type
189
-		$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $entity_id);
190
-		$addresses = $wpdb->get_results( $query);
189
+		$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
190
+		$addresses = $wpdb->get_results($query);
191 191
 		$output = '';
192
-		foreach ( $addresses as $address ) {
193
-			$output .= '<p><input type="checkbox" id="' .$address->name.'_'.$address->id.'" name="address_type[' .$address->name. ']" value="'.$address->id.'" ' .( ( !empty($attached_address_values) && in_array( $address->id, $attached_address_values) ) ? 'checked="checked"' : '' ). ' /> <label for="' .$address->name.'_'.$address->id.'">'.$address->name.'</label></p>';
192
+		foreach ($addresses as $address) {
193
+			$output .= '<p><input type="checkbox" id="' . $address->name . '_' . $address->id . '" name="address_type[' . $address->name . ']" value="' . $address->id . '" ' . ((!empty($attached_address_values) && in_array($address->id, $attached_address_values)) ? 'checked="checked"' : '') . ' /> <label for="' . $address->name . '_' . $address->id . '">' . $address->name . '</label></p>';
194 194
 		}
195 195
 		echo $output;
196 196
 	}
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
 		/*
211 211
 		 * Read the entity list for custom type declaration
212 212
 		 */
213
-		if ( !empty($entities) ) {
214
-			foreach ( $entities as $entity ) {
215
-				$wpshop_builtin_types = unserialize( WPSHOP_DEFAULT_CUSTOM_TYPES );
216
-				if ( !empty( $entity->post_name ) && !in_array( $entity->post_name, $wpshop_builtin_types ) ) {
213
+		if (!empty($entities)) {
214
+			foreach ($entities as $entity) {
215
+				$wpshop_builtin_types = unserialize(WPSHOP_DEFAULT_CUSTOM_TYPES);
216
+				if (!empty($entity->post_name) && !in_array($entity->post_name, $wpshop_builtin_types)) {
217 217
 					$current_entity_params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
218
-					if ( !empty($current_entity_params['display_admin_menu']) ) {
218
+					if (!empty($current_entity_params['display_admin_menu'])) {
219 219
 						$show_in_menu = WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES;
220 220
 					}
221 221
 					else {
@@ -223,17 +223,17 @@  discard block
 block discarded – undo
223 223
 					}
224 224
 					$post_type_params = array(
225 225
 						'labels' => array(
226
-							'name'					=> __( $entity->post_title , 'wpshop' ),
227
-							'singular_name' 		=> __( $entity->post_title, 'wpshop' ),
228
-							'add_new_item' 			=> sprintf( __( 'Add new %s', 'wpshop' ), $entity->post_title),
229
-							'add_new' 				=> sprintf( __( 'Add new %s', 'wpshop' ), $entity->post_title),
230
-							'add_new_item' 			=> sprintf( __( 'Add new %s', 'wpshop' ), $entity->post_title),
231
-							'edit_item' 			=> sprintf( __( 'Edit %s', 'wpshop' ), $entity->post_title),
232
-							'new_item' 				=> sprintf( __( 'New %s', 'wpshop' ), $entity->post_title),
233
-							'view_item' 			=> sprintf( __( 'View %s', 'wpshop' ), $entity->post_title),
234
-							'search_items' 			=> sprintf( __( 'Search %s', 'wpshop' ), $entity->post_title),
235
-							'not_found' 			=> sprintf( __( 'No %s found', 'wpshop' ), $entity->post_title),
236
-							'not_found_in_trash' 	=> sprintf( __( 'No %s found in Trash', 'wpshop' ), $entity->post_title),
226
+							'name'					=> __($entity->post_title, 'wpshop'),
227
+							'singular_name' 		=> __($entity->post_title, 'wpshop'),
228
+							'add_new_item' 			=> sprintf(__('Add new %s', 'wpshop'), $entity->post_title),
229
+							'add_new' 				=> sprintf(__('Add new %s', 'wpshop'), $entity->post_title),
230
+							'add_new_item' 			=> sprintf(__('Add new %s', 'wpshop'), $entity->post_title),
231
+							'edit_item' 			=> sprintf(__('Edit %s', 'wpshop'), $entity->post_title),
232
+							'new_item' 				=> sprintf(__('New %s', 'wpshop'), $entity->post_title),
233
+							'view_item' 			=> sprintf(__('View %s', 'wpshop'), $entity->post_title),
234
+							'search_items' 			=> sprintf(__('Search %s', 'wpshop'), $entity->post_title),
235
+							'not_found' 			=> sprintf(__('No %s found', 'wpshop'), $entity->post_title),
236
+							'not_found_in_trash' 	=> sprintf(__('No %s found in Trash', 'wpshop'), $entity->post_title),
237 237
 							'parent_item_colon' 	=> '',
238 238
 						),
239 239
 						'description' 			=> $entity->post_content,
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 						'rewrite'				=> !empty($current_entity_params['rewrite']) ? $current_entity_params['rewrite'] : array(),
248 248
 						'hierarchical'			=> true,
249 249
 					);
250
-					register_post_type($entity->post_name, $post_type_params );
250
+					register_post_type($entity->post_name, $post_type_params);
251 251
 				}
252 252
 
253 253
 				/**	Add basic metabox */
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 
259 259
 			}
260 260
 
261
-			add_filter( 'map_meta_cap', array('wpshop_entities', 'map_meta_cap'), 10, 4 );
261
+			add_filter('map_meta_cap', array('wpshop_entities', 'map_meta_cap'), 10, 4);
262 262
 			/*
263 263
 			 * Reset query for security reasons
264 264
 			 */
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
 	 * @param integer $user_id
274 274
 	 * @param array $args
275 275
 	 */
276
-	public static function map_meta_cap( $caps, $cap, $user_id, $args ) {
277
-		if ( !empty($args) ) {
276
+	public static function map_meta_cap($caps, $cap, $user_id, $args) {
277
+		if (!empty($args)) {
278 278
 			$post = get_post($args[0]);
279
-			if ( false && !empty($post) && is_object($post) && ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) && (($post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)  || ($post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) || ($post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)) && ($cap == 'delete_product') ) {
279
+			if (false && !empty($post) && is_object($post) && ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) && (($post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) || ($post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)) && ($cap == 'delete_product')) {
280 280
 				$caps = 'wpshop_view_dashboard';
281 281
 			}
282 282
 		}
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 	/**
289 289
 	 * Add metaboxes to the custom post types defined by entities
290 290
 	 */
291
-	public static function add_meta_boxes_to_custom_types( $post ) {
291
+	public static function add_meta_boxes_to_custom_types($post) {
292 292
 		global $post,
293 293
 			   $wpdb;
294 294
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		/*
304 304
 		 * Product are managed from another place
305 305
 		 */
306
-		if ( $post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
306
+		if ($post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
307 307
 			/*
308 308
 			 * Get the attribute set list for current entity
309 309
 			 */
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 			 */
315 315
 			$attribute_set_id = get_post_meta($post->ID, sprintf(WPSHOP_ATTRIBUTE_SET_ID_META_KEY, $post->post_type), true);
316 316
 
317
-			if(((count($attribute_set_list) == 1) || ((count($attribute_set_list) > 1) && !empty($attribute_set_id)))){
318
-				if((count($attribute_set_list) == 1) || empty($attribute_set_id)){
317
+			if (((count($attribute_set_list) == 1) || ((count($attribute_set_list) > 1) && !empty($attribute_set_id)))) {
318
+				if ((count($attribute_set_list) == 1) || empty($attribute_set_id)) {
319 319
 					$attribute_set_id = $attribute_set_list[0]->id;
320 320
 				}
321 321
 
@@ -328,28 +328,28 @@  discard block
 block discarded – undo
328 328
 				/*
329 329
 				 * Read the different element for building output for current entity
330 330
 				 */
331
-				if ( !empty($currentTabContent['box']) && is_array($currentTabContent['box']) ) {
331
+				if (!empty($currentTabContent['box']) && is_array($currentTabContent['box'])) {
332 332
 					foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
333
-						if (!empty($currentTabContent['box'][$boxIdentifier.'_backend_display_type']) &&( $currentTabContent['box'][$boxIdentifier.'_backend_display_type']=='movable-tab')) {
333
+						if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
334 334
 							add_meta_box($post->post_type . '_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_entities', 'meta_box_content'), $post->post_type, 'normal', 'default', array('currentTabContent' => $currentTabContent['boxContent'][$boxIdentifier]));
335 335
 						}
336 336
 						else $fixed_box_exist = true;
337 337
 					}
338 338
 				}
339
-				if ($fixed_box_exist && $post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) {
339
+				if ($fixed_box_exist && $post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
340 340
 					add_meta_box($post->post_type . '_fixed_tab', __('Informations', 'wpshop'), array('wpshop_entities', 'meta_box_content_datas'), $post->post_type, 'normal', 'high', array('currentTabContent' => $currentTabContent));
341 341
 				}
342 342
 			}
343 343
 			elseif (count($attribute_set_list) > 1) {
344
-				$input_def['id'] = $post->post_type.'_attribute_set_id';
345
-				$input_def['name'] = $post->post_type.'_attribute_set_id';
344
+				$input_def['id'] = $post->post_type . '_attribute_set_id';
345
+				$input_def['name'] = $post->post_type . '_attribute_set_id';
346 346
 				$input_def['value'] = '';
347 347
 				$input_def['type'] = 'select';
348 348
 				$input_def['possible_value'] = $attribute_set_list;
349 349
 
350 350
 				$input_def['value'] = '';
351 351
 				foreach ($attribute_set_list as $set) {
352
-					if( $set->default_set == 'yes' ) {
352
+					if ($set->default_set == 'yes') {
353 353
 						$input_def['value'] = $set->id;
354 354
 					}
355 355
 				}
@@ -357,12 +357,12 @@  discard block
 block discarded – undo
357 357
 				$currentTabContent = '
358 358
 		<ul class="attribute_set_selector" >
359 359
 			<li class="attribute_set_selector_title_select" ><label for="title" >' . sprintf(__('Choose a title for the %s', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</label></li>
360
-			<li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . sprintf(__('Choose an attribute group for this %s', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</label>&nbsp;'.wpshop_form::check_input_type($input_def).'</li>
360
+			<li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . sprintf(__('Choose an attribute group for this %s', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</label>&nbsp;' . wpshop_form::check_input_type($input_def) . '</li>
361 361
 			<li class="attribute_set_selector_save_instruction" >' . sprintf(__('Save the %s with the "Save draft" button on the right side', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</li>
362 362
 			<li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li>
363 363
 		</ul>';
364 364
 
365
-				add_meta_box($post->post_type . '_attribute_set_selector',sprintf( __('%s attributes', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))), array('wpshop_entities', 'meta_box_content'), $post->post_type, 'normal', 'high', array('currentTabContent' => $currentTabContent));
365
+				add_meta_box($post->post_type . '_attribute_set_selector', sprintf(__('%s attributes', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))), array('wpshop_entities', 'meta_box_content'), $post->post_type, 'normal', 'high', array('currentTabContent' => $currentTabContent));
366 366
 			}
367 367
 
368 368
 		}
@@ -392,22 +392,22 @@  discard block
 block discarded – undo
392 392
 
393 393
 		echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs entities_attribute_tabs ' . $post->post_type . '_attribute_tabs" >
394 394
 				<ul>';
395
-		if(!empty($currentTabContent['box'])){
396
-			foreach($currentTabContent['box'] as $boxIdentifier => $boxTitle){
397
-				if(!empty($currentTabContent['boxContent'][$boxIdentifier])) {
398
-					if($currentTabContent['box'][$boxIdentifier.'_backend_display_type']=='fixed-tab') {
399
-						echo '<li><a href="#tabs-'.$boxIdentifier.'">'.__($boxTitle, 'wpshop').'</a></li>';
395
+		if (!empty($currentTabContent['box'])) {
396
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
397
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
398
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
399
+						echo '<li><a href="#tabs-' . $boxIdentifier . '">' . __($boxTitle, 'wpshop') . '</a></li>';
400 400
 					}
401 401
 				}
402 402
 			}
403 403
 		}
404 404
 		echo '</ul>';
405 405
 
406
-		if(!empty($currentTabContent['box'])){
407
-			foreach($currentTabContent['box'] as $boxIdentifier => $boxTitle){
408
-				if(!empty($currentTabContent['boxContent'][$boxIdentifier])) {
409
-					if($currentTabContent['box'][$boxIdentifier.'_backend_display_type']=='fixed-tab') {
410
-						echo '<div id="tabs-'.$boxIdentifier.'">'.$currentTabContent['boxContent'][$boxIdentifier].'</div>';
406
+		if (!empty($currentTabContent['box'])) {
407
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
408
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
409
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
410
+						echo '<div id="tabs-' . $boxIdentifier . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
411 411
 					}
412 412
 				}
413 413
 			}
@@ -422,32 +422,32 @@  discard block
 block discarded – undo
422 422
 	/**
423 423
 	 * Save informations for current entity
424 424
 	 */
425
-	public static function save_entities_custom_informations( $post_id ) {
425
+	public static function save_entities_custom_informations($post_id) {
426 426
     global $wpdb, $wpshop_account;
427 427
 
428
-		$edit_other_thing = !empty( $_POST['edit_other_thing'] ) ? (int) $_POST['edit_other_thing'] : 0;
428
+		$edit_other_thing = !empty($_POST['edit_other_thing']) ? (int)$_POST['edit_other_thing'] : 0;
429 429
 
430
-		if ( ( ( !empty($post_id) && empty( $edit_other_thing ) ) || ( !empty($post_id) && !(bool)$edit_other_thing ) )
431
-				 && ( get_post_type( $post_id ) != WPSHOP_NEWTYPE_IDENTIFIER_ORDER )  ) {
432
-			$current_post_type = get_post_type( $post_id );
433
-			$current_post_type_text = !empty( $_REQUEST[$current_post_type . '_attribute_set_id'] ) ? sanitize_text_field( $_REQUEST[$current_post_type . '_attribute_set_id'] ) : '';
430
+		if (((!empty($post_id) && empty($edit_other_thing)) || (!empty($post_id) && !(bool)$edit_other_thing))
431
+				 && (get_post_type($post_id) != WPSHOP_NEWTYPE_IDENTIFIER_ORDER)) {
432
+			$current_post_type = get_post_type($post_id);
433
+			$current_post_type_text = !empty($_REQUEST[$current_post_type . '_attribute_set_id']) ? sanitize_text_field($_REQUEST[$current_post_type . '_attribute_set_id']) : '';
434 434
 			/*	Vérification de l'existence de l'envoi de l'identifiant du set d'attribut	*/
435
-			if	( !empty($current_post_type_text) ) {
436
-				$attribute_set_id = intval( $current_post_type_text );
435
+			if (!empty($current_post_type_text)) {
436
+				$attribute_set_id = intval($current_post_type_text);
437 437
 				$attribet_set_infos = wpshop_attributes_set::getElement($attribute_set_id, "'valid'", 'id');
438 438
 
439
-				if ( $attribet_set_infos->entity == sanitize_key( $current_post_type ) ) {
439
+				if ($attribet_set_infos->entity == sanitize_key($current_post_type)) {
440 440
 					/*	Enregistrement de l'identifiant du set d'attribut associé à l'entité	*/
441 441
 					update_post_meta($post_id, sprintf(WPSHOP_ATTRIBUTE_SET_ID_META_KEY, $current_post_type), $attribute_set_id);
442 442
 
443 443
 					/*	Enregistrement de tous les attributs	*/
444 444
 					$current_post_type_attributes = !empty($_REQUEST[$current_post_type . '_attribute']) ? (array)$_REQUEST[$current_post_type . '_attribute'] : null;
445
-					if ( isset($current_post_type_attributes) ) {
445
+					if (isset($current_post_type_attributes)) {
446 446
 						/*	Traduction des virgule en point pour la base de donnees	*/
447
-						if ( !empty($current_post_type_attributes['decimal']) ) {
448
-							foreach($current_post_type_attributes['decimal'] as $attributeName => $attributeValue){
449
-								if(!is_array($attributeValue)){
450
-									$current_post_type_attributes['decimal'][$attributeName] = str_replace(',','.',$current_post_type_attributes['decimal'][$attributeName]);
447
+						if (!empty($current_post_type_attributes['decimal'])) {
448
+							foreach ($current_post_type_attributes['decimal'] as $attributeName => $attributeValue) {
449
+								if (!is_array($attributeValue)) {
450
+									$current_post_type_attributes['decimal'][$attributeName] = str_replace(',', '.', $current_post_type_attributes['decimal'][$attributeName]);
451 451
 								}
452 452
 							}
453 453
 						}
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 
457 457
 						/*	Enregistrement des valeurs des attributs dans les metas de l'entité => Permet de profiter de la recherche native de wordpress	*/
458 458
 						$productMetaDatas = array();
459
-						foreach ( $current_post_type_attributes as $attributeType => $attributeValues ) {
460
-							foreach ( $attributeValues as $attributeCode => $attributeValue ) {
459
+						foreach ($current_post_type_attributes as $attributeType => $attributeValues) {
460
+							foreach ($attributeValues as $attributeCode => $attributeValue) {
461 461
 								$productMetaDatas[$attributeCode] = $attributeValue;
462 462
 							}
463 463
 						}
@@ -467,42 +467,42 @@  discard block
 block discarded – undo
467 467
 				}
468 468
 			}
469 469
 
470
-			$attribute = !empty($_REQUEST['attribute']) ? (array) $_REQUEST['attribute'] : null;
471
-			$post_id = !empty($_REQUEST['post_ID']) ? (int) $_REQUEST['post_ID'] : null;
472
-			if ( isset($attribute) ) {
470
+			$attribute = !empty($_REQUEST['attribute']) ? (array)$_REQUEST['attribute'] : null;
471
+			$post_id = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : null;
472
+			if (isset($attribute)) {
473 473
 				$current_id = array();
474
-				foreach ( $attribute as $key=>$values ) {
474
+				foreach ($attribute as $key=>$values) {
475 475
 					$ad_id = '';
476 476
 					$addresses_id = get_post_meta($post_id, '_wpshop_attached_address', true);
477
-					if ( !empty($addresses_id) ) {
478
-						foreach ( $addresses_id as $address_id) {
477
+					if (!empty($addresses_id)) {
478
+						foreach ($addresses_id as $address_id) {
479 479
 							$address_type = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true);
480 480
 							if ($address_type == $key) {
481 481
 								$ad_id = $address_id;
482 482
 							}
483 483
 						}
484 484
 					}
485
-					if( !empty( $ad_id ) ) {
485
+					if (!empty($ad_id)) {
486 486
 						// @TODO : REQUEST
487 487
 						// $_REQUEST['item_id'] = $ad_id;
488
-						$result = wps_address::save_address_infos( $key );
488
+						$result = wps_address::save_address_infos($key);
489 489
 						$current_id[] = $result['current_id'];
490 490
 					}
491 491
 				}
492
-				if( !empty( $current_id ) ) {
493
-					update_post_meta ($post_id, '_wpshop_attached_address', $current_id);
492
+				if (!empty($current_id)) {
493
+					update_post_meta($post_id, '_wpshop_attached_address', $current_id);
494 494
 				}
495 495
 			}
496 496
 			else {
497 497
 				$current_id = array();
498 498
 
499
-				$address_type = !empty($_REQUEST['address_type']) ? (array) $_REQUEST['address_type'] : null;
500
-				if ( isset($address_type) ) {
501
-					foreach ( $address_type as $key=>$value ) {
499
+				$address_type = !empty($_REQUEST['address_type']) ? (array)$_REQUEST['address_type'] : null;
500
+				if (isset($address_type)) {
501
+					foreach ($address_type as $key=>$value) {
502 502
 						$current_id[] = $value;
503 503
 					}
504 504
 				}
505
-				update_post_meta ($post_id, '_wpshop_entity_attached_address', $current_id);
505
+				update_post_meta($post_id, '_wpshop_entity_attached_address', $current_id);
506 506
 			}
507 507
 		}
508 508
 
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
 			'posts_per_page' 	=> '-1',
526 526
 		));
527 527
 
528
-		if ( !empty($entities) ) {
528
+		if (!empty($entities)) {
529 529
 			foreach ($entities as $entity_index => $entity) {
530 530
 				$entities_list[$entity->ID] = $entity->post_title;
531 531
 			}
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 	 * @return integer The entity identifier that match to given parameters
545 545
 	 */
546 546
 	public static function get_entity_identifier_from_code($code, $post_status = 'publish', $entity_code = WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) {
547
-		if ( ! isset( self::$entities_cache[$entity_code][$code][$post_status] ) ) {
547
+		if (!isset(self::$entities_cache[$entity_code][$code][$post_status])) {
548 548
 			global $wpdb;
549 549
 			self::$entities_cache[$entity_code][$code][$post_status] = null;
550 550
 			$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s AND post_name=%s ORDER BY menu_order ASC", $entity_code, $post_status, $code);
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 		global $wpdb;
564 564
 
565 565
 		/*	Get current post information	*/
566
-		$post_infos = get_post( $post_id, ARRAY_A );
566
+		$post_infos = get_post($post_id, ARRAY_A);
567 567
 		/*	Set new information for post that will be created	*/
568 568
 		unset($post_infos['ID']);
569 569
 		$post_infos['post_date'] = current_time('mysql', 1);
@@ -581,18 +581,18 @@  discard block
 block discarded – undo
581 581
 		$last_post = wp_insert_post($post_infos);
582 582
 
583 583
 		/*	If there is no error then duplicate meta informations	*/
584
-		if ( is_int($last_post) && !empty($last_post) ) {
584
+		if (is_int($last_post) && !empty($last_post)) {
585 585
 			$meta_creation = true;
586 586
 
587 587
 			$current_post_meta = get_post_meta($post_id);
588
-			foreach ( $current_post_meta as $post_meta_key => $post_meta_value ) {
589
-				$meta_is_array = ( !empty( $post_meta_value[0] ) && wpshop_tools::is_serialized( $post_meta_value[0] ) ) ? unserialize( $post_meta_value[0] ) : '';
588
+			foreach ($current_post_meta as $post_meta_key => $post_meta_value) {
589
+				$meta_is_array = (!empty($post_meta_value[0]) && wpshop_tools::is_serialized($post_meta_value[0])) ? unserialize($post_meta_value[0]) : '';
590 590
 				$meta_real_value = (is_array($meta_is_array) ? $meta_is_array : $post_meta_value[0]);
591 591
 				$meta_creation = update_post_meta($last_post, $post_meta_key, $meta_real_value);
592 592
 			}
593 593
 			/*	Duplicate element taxonomy	*/
594 594
 			/*	Check the taxonomy to get	*/
595
-			switch ( get_post_type($post_id) ) {
595
+			switch (get_post_type($post_id)) {
596 596
 				case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
597 597
 					$taxonomy = WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES;
598 598
 					break;
@@ -600,17 +600,17 @@  discard block
 block discarded – undo
600 600
 					$taxonomy = '';
601 601
 					break;
602 602
 			}
603
-			$post_taxonomies = wp_get_post_terms( $post_id,  $taxonomy);
604
-			foreach ( $post_taxonomies as $post_taxonomy ) {
605
-				wp_set_post_terms( $last_post, $post_taxonomy->term_id, $taxonomy, true);
603
+			$post_taxonomies = wp_get_post_terms($post_id, $taxonomy);
604
+			foreach ($post_taxonomies as $post_taxonomy) {
605
+				wp_set_post_terms($last_post, $post_taxonomy->term_id, $taxonomy, true);
606 606
 			}
607 607
 
608 608
 			/*	Create a post meta allowing to know if the element has been duplicated from another	*/
609 609
 			update_post_meta($last_post, '_wpshop_duplicate_element', $post_id);
610 610
 
611 611
 			$new_element_link = '<a class="wpshop_cls wpshop_duplicate_entity_element_link" href="' . admin_url('post.php?post=' . $last_post . '&action=edit') . '" >' . __('Go on the new element edit page', 'wpshop') . '</a>';
612
-			if ( $meta_creation ) {
613
-				return array('true', '<br/>' . $new_element_link, $last_post );
612
+			if ($meta_creation) {
613
+				return array('true', '<br/>' . $new_element_link, $last_post);
614 614
 			}
615 615
 			else {
616 616
 				return array('true', '<br/>' . __('Some errors occured while duplicating meta information, but element has been created.', 'wpshop') . ' ' . $new_element_link);
@@ -636,12 +636,12 @@  discard block
 block discarded – undo
636 636
 		$query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATT WHERE status=%s AND is_used_in_admin_listing_column=%s AND entity_id=%d", 'valid', 'yes', self::get_entity_identifier_from_code($post_type));
637 637
 		$attributes_list = $wpdb->get_results($query);
638 638
 		$wpshop_custom_columns = array();
639
-		foreach ( $attributes_list as $attribute ) {
639
+		foreach ($attributes_list as $attribute) {
640 640
 			$wpshop_custom_columns[$attribute->code] = __($attribute->frontend_label, 'wpshop');
641 641
 		}
642 642
 
643 643
 		/*	Check the current entity to display custom column correctly. Add the custom column into default column list	*/
644
-		switch ( $post_type ) {
644
+		switch ($post_type) {
645 645
 			case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
646 646
 				$columns = array_merge(array(
647 647
 					'cb' => '<input type="checkbox" />',
@@ -668,34 +668,34 @@  discard block
 block discarded – undo
668 668
 	public static function custom_columns_content($column, $post_id) {
669 669
 		$post_type = get_post_type($post_id);
670 670
 
671
-		switch ( $post_type ) {
671
+		switch ($post_type) {
672 672
 			case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
673 673
 				$column_content = '<strong>-</strong>';
674 674
 				$product = wpshop_products::get_product_data($post_id);
675 675
 
676 676
 				switch ($column) {
677 677
 					case 'picture' :
678
-						$column_content = get_the_post_thumbnail( $post_id, 'thumbnail');
678
+						$column_content = get_the_post_thumbnail($post_id, 'thumbnail');
679 679
 					break;
680 680
 					case "product_stock":
681
-						if( !empty($product['product_stock']) )
682
-							$column_content = (int)$product['product_stock'].' '.__('unit(s)','wpshop');
681
+						if (!empty($product['product_stock']))
682
+							$column_content = (int)$product['product_stock'] . ' ' . __('unit(s)', 'wpshop');
683 683
 					break;
684 684
 
685 685
 					case "product_price":
686
-						if( !empty($product['product_price']) )
687
-							$column_content = wpshop_prices::get_product_price( $product, 'price_display', 'complete_sheet');
686
+						if (!empty($product['product_price']))
687
+							$column_content = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
688 688
 					break;
689 689
 
690 690
 					case "tx_tva":
691
-						if( !empty($product['product_price']) )
692
-							$column_content = number_format($product[$column],2,'.', ' ').' %';
691
+						if (!empty($product['product_price']))
692
+							$column_content = number_format($product[$column], 2, '.', ' ') . ' %';
693 693
 					break;
694 694
 					default:
695
-						if ( !empty($product[$column]) ) {
695
+						if (!empty($product[$column])) {
696 696
 							$attribute_prices = unserialize(WPSHOP_ATTRIBUTE_PRICES);
697
-							if ( in_array($column, $attribute_prices) ) {
698
-								$column_content = number_format($product[$column],2,'.', ' ').' '.wpshop_tools::wpshop_get_currency();
697
+							if (in_array($column, $attribute_prices)) {
698
+								$column_content = number_format($product[$column], 2, '.', ' ') . ' ' . wpshop_tools::wpshop_get_currency();
699 699
 
700 700
 							}
701 701
 							else
@@ -716,16 +716,16 @@  discard block
 block discarded – undo
716 716
 	 * Display a form allowing to create an entity from frontend with a shortcode
717 717
 	 * @param array $shortcode_args The different parameters for the shortocde: the field list for the form, different parameters for the entity to create
718 718
 	 */
719
-	public static function wpshop_entities_shortcode( $shortcode_args ) {
719
+	public static function wpshop_entities_shortcode($shortcode_args) {
720 720
 		global $wpshop_account, $wpdb;
721 721
 		$output = $form_content = '';
722
-		$quick_entity_add_button = !empty( $_POST['quick_entity_add_button'] ) ? (int) $_POST['quick_entity_add_button'] : 0;
723
-		if ( get_current_user_id() > 0 ) {
724
-			if ( !empty( $quick_entity_add_button ) ) {
722
+		$quick_entity_add_button = !empty($_POST['quick_entity_add_button']) ? (int)$_POST['quick_entity_add_button'] : 0;
723
+		if (get_current_user_id() > 0) {
724
+			if (!empty($quick_entity_add_button)) {
725 725
 				$attributes = array();
726
-				$attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
727
-				foreach ( $attribute as $attribute_type => $attribute ) {
728
-					foreach ( $attribute as $attribute_code => $attribute_value ) {
726
+				$attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array();
727
+				foreach ($attribute as $attribute_type => $attribute) {
728
+					foreach ($attribute as $attribute_code => $attribute_value) {
729 729
 						$attributes[$attribute_code] = $attribute_value;
730 730
 					}
731 731
 				}
@@ -733,23 +733,23 @@  discard block
 block discarded – undo
733 733
 				$result = wpshop_products::addProduct($title, '', $attributes, 'complete');
734 734
 			}
735 735
 
736
-			if ( empty($shortcode_args['attribute_set_id']) || empty($shortcode_args['post_type']) ) {
736
+			if (empty($shortcode_args['attribute_set_id']) || empty($shortcode_args['post_type'])) {
737 737
 				$output = __('This form page is invalid because no set or type or content is defined. Please contact administrator with this error message', 'wpshop');
738 738
 			}
739 739
 			else {
740 740
 				$entity_identifier = wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']);
741 741
 				$attribute_set_def = wpshop_attributes_set::getElement($shortcode_args['attribute_set_id'], "'valid'");
742 742
 
743
-				if ( empty($entity_identifier) || empty($attribute_set_def) || ($entity_identifier != $attribute_set_def->entity_id) ) {
743
+				if (empty($entity_identifier) || empty($attribute_set_def) || ($entity_identifier != $attribute_set_def->entity_id)) {
744 744
 					$output = __('This form page is invalid because type and set are not linked. Please contact administrator with this error message', 'wpshop');
745 745
 				}
746 746
 				else {
747 747
 					/** Display wordpress fields */
748
-					foreach ( explode(', ', $shortcode_args['fields']) as $field_name ) {
748
+					foreach (explode(', ', $shortcode_args['fields']) as $field_name) {
749 749
 						$label = '';
750
-						switch ( $field_name ) {
750
+						switch ($field_name) {
751 751
 							case 'post_title':
752
-								switch ( $shortcode_args['post_type'] ) {
752
+								switch ($shortcode_args['post_type']) {
753 753
 									case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
754 754
 										$label = __('Product title', 'wpshop');
755 755
 										break;
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 								$field_type = 'text';
762 762
 							break;
763 763
 							case 'post_thumbnail':
764
-								switch ( $shortcode_args['post_type'] ) {
764
+								switch ($shortcode_args['post_type']) {
765 765
 									case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
766 766
 										$label = __('Product picture', 'wpshop');
767 767
 									break;
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 							break;
775 775
 						}
776 776
 
777
-						if ( !empty( $label ) ) {
777
+						if (!empty($label)) {
778 778
 							$template_part = 'quick_entity_wp_internal_field_' . $field_type;
779 779
 							$tpl_component = array();
780 780
 							$tpl_component['WP_FIELD_NAME'] = $field_name;
@@ -807,20 +807,20 @@  discard block
 block discarded – undo
807 807
 ORDER BY ATT_GROUP.position, ATTR_DET.position"
808 808
 						, 'yes', 'valid', wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']), $shortcode_args['attribute_set_id']);
809 809
 					$attribute_for_creation = $wpdb->get_results($query);
810
-					foreach ( $attribute_for_creation as $attribute ) {
811
-						$attr_field = wpshop_attributes::display_attribute( $attribute->code, 'frontend'/* (is_admin() ? 'admin' : 'frontend') */ );
810
+					foreach ($attribute_for_creation as $attribute) {
811
+						$attr_field = wpshop_attributes::display_attribute($attribute->code, 'frontend'/* (is_admin() ? 'admin' : 'frontend') */);
812 812
 						$form_content .= $attr_field['field'];
813 813
 					}
814 814
 
815 815
 					/**	Check if there are extra parameters	*/
816
-					if ( !empty( $shortcode_args['extra_element'] ) ) {
816
+					if (!empty($shortcode_args['extra_element'])) {
817 817
 						$extra_element = explode(', ', $shortcode_args['extra_element']);
818
-						foreach ( $extra_element as $element) {
818
+						foreach ($extra_element as $element) {
819 819
 							$element_def = explode('!#wps#!', $element);
820 820
 							$element_type = $element_def[0];
821 821
 							$element_id = $element_def[1];
822 822
 
823
-							if ( $element_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ) {
823
+							if ($element_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) {
824 824
 								$form_content .= '<div class="wpshop_entity_address_container">';
825 825
 // 								$form_content .= $wpshop_account->display_form_fields($element_id, null, 'not');
826 826
 								$form_content .= '</div><div class="wpshop_cls"></div>';
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			$template_part = 'quick_entity_add_form';
834 834
 			$tpl_component = array();
835 835
 			$tpl_component['ENTITY_TYPE'] = $shortcode_args['post_type'];
836
-			$tpl_component['ENTITY_ATTRIBUTE_SET_ID'] = !empty( $shortcode_args['attribute_set_id'] ) ? $shortcode_args['attribute_set_id'] : 0;
836
+			$tpl_component['ENTITY_ATTRIBUTE_SET_ID'] = !empty($shortcode_args['attribute_set_id']) ? $shortcode_args['attribute_set_id'] : 0;
837 837
 			$tpl_component['NEW_ENTITY_FORM_DETAILS'] = $form_content;
838 838
 			$tpl_component['ENTITY_QUICK_ADDING_FORM_NONCE'] = wp_create_nonce("wpshop_add_new_entity_ajax_nonce");
839 839
 			$tpl_component['ENTITY_QUICK_ADD_BUTTON_TEXT'] = __($shortcode_args['button_text'], 'wpshop');
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 			$dialog_identifier = 'new_value_for_entity';
844 844
 			$dialog_input_identifier = 'wpshop_new_attribute_option_value';
845 845
 			ob_start();
846
-			include(WPSHOP_TEMPLATES_DIR.'admin/add_new_element_dialog.tpl.php');
846
+			include(WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php');
847 847
 			$tpl_component['DIALOG_BOX'] = ob_get_contents();
848 848
 			ob_end_clean();
849 849
 			$tpl_component['DIALOG_BOX'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
@@ -885,14 +885,14 @@  discard block
 block discarded – undo
885 885
 		/** Add the new product	*/
886 886
 		$entity_id = wp_insert_post($entity_args);
887 887
 
888
-		do_action( 'wps_entity_more_action' , $entity_id, $attributes);
888
+		do_action('wps_entity_more_action', $entity_id, $attributes);
889 889
 
890 890
 		/** Update the attribute set id for the current product	*/
891
-		if ( !empty($extra_params['attribute_set_id']) ) {
891
+		if (!empty($extra_params['attribute_set_id'])) {
892 892
 			$attribute_set_id = $extra_params['attribute_set_id'];
893 893
 		}
894 894
 		else {
895
-			$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE status = %s AND entity_id = %d AND default_set = %s", 'valid', wpshop_entities::get_entity_identifier_from_code($entity_type) , 'yes');
895
+			$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE status = %s AND entity_id = %d AND default_set = %s", 'valid', wpshop_entities::get_entity_identifier_from_code($entity_type), 'yes');
896 896
 			$attribute_set_id = $wpdb->get_var($query);
897 897
 		}
898 898
 		update_post_meta($entity_id, '_' . $entity_type . '_attribute_set_id', $attribute_set_id);
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 *
911 911
 	 * @return array The different response element for the request. $result: Boolean representing if creation is OK / $container: Where the result must be placed into output code / $output: The html content to output
912 912
 	 */
913
-	public static function create_cpt_from_csv_file( $identifier, $custom_file = '' ) {
913
+	public static function create_cpt_from_csv_file($identifier, $custom_file = '') {
914 914
 		global $wpdb;
915 915
 		$output = '';
916 916
 		$container = '';
@@ -930,47 +930,47 @@  discard block
 block discarded – undo
930 930
 		$custom_post_type_identifier = $wpdb->get_var($query);
931 931
 		$container = 'wpshop_cpt_' . $identifier;
932 932
 
933
-		$file_uri = !empty( $custom_file ) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '.csv';
934
-		if ( is_file( $file_uri ) && empty($custom_post_type_identifier) ) {
933
+		$file_uri = !empty($custom_file) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '.csv';
934
+		if (is_file($file_uri) && empty($custom_post_type_identifier)) {
935 935
 			$csv_file_default_data = file($file_uri, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
936 936
 
937
-			$db_field_definition = explode( ";", $csv_file_default_data[0] );
938
-			$db_datas_definition = explode( ";", $csv_file_default_data[1] );
937
+			$db_field_definition = explode(";", $csv_file_default_data[0]);
938
+			$db_datas_definition = explode(";", $csv_file_default_data[1]);
939 939
 
940 940
 			$has_error = false;
941 941
 			$errors = array();
942
-			foreach ( $custom_post_type_default_structure as $field_name => $field_default_value ) {
943
-				if ( !in_array( str_replace( 'post_', '', $field_name ) , $db_field_definition ) ) {
944
-					if ( $field_name == 'post_name' ) {
942
+			foreach ($custom_post_type_default_structure as $field_name => $field_default_value) {
943
+				if (!in_array(str_replace('post_', '', $field_name), $db_field_definition)) {
944
+					if ($field_name == 'post_name') {
945 945
 						$db_datas_definition[] = $identifier;
946
-						$db_field_definition[] = str_replace( 'post_', '', $field_name );
946
+						$db_field_definition[] = str_replace('post_', '', $field_name);
947 947
 					}
948
-					else if ( $field_default_value == 'mandatory' ) {
948
+					else if ($field_default_value == 'mandatory') {
949 949
 						$has_error = true;
950 950
 						$errors[] = $field_name;
951 951
 					}
952 952
 					else {
953 953
 						$db_datas_definition[] = $field_default_value;
954
-						$db_field_definition[] = str_replace( 'post_', '', $field_name );
954
+						$db_field_definition[] = str_replace('post_', '', $field_name);
955 955
 					}
956 956
 				}
957 957
 			}
958 958
 
959
-			if ( $has_error ) {
959
+			if ($has_error) {
960 960
 				$result = false;
961
-				$output = sprintf( __('You have to fill %s, they are mandatory for custom type creation', 'wpshop'), implode(',', $errors) );
961
+				$output = sprintf(__('You have to fill %s, they are mandatory for custom type creation', 'wpshop'), implode(',', $errors));
962 962
 			}
963 963
 			else {
964 964
 				$custom_post_type_def = array();
965
-				foreach ( $db_field_definition as $field_position => $field_name ) {
965
+				foreach ($db_field_definition as $field_position => $field_name) {
966 966
 					$custom_post_type_def['post_' . $field_name] = $db_datas_definition[$field_position];
967 967
 				}
968
-				$new_custom_post_type = wp_insert_post( $custom_post_type_def );
969
-				if ( is_int($new_custom_post_type) && !empty($new_custom_post_type) ) {
968
+				$new_custom_post_type = wp_insert_post($custom_post_type_def);
969
+				if (is_int($new_custom_post_type) && !empty($new_custom_post_type)) {
970 970
 					$result = true;
971 971
 				}
972 972
 
973
-				$check_cpt = wpshop_entities::check_default_custom_post_type( $identifier, array(), $result, $custom_file );
973
+				$check_cpt = wpshop_entities::check_default_custom_post_type($identifier, array(), $result, $custom_file);
974 974
 				$output = $check_cpt[1];
975 975
 			}
976 976
 		}
@@ -986,20 +986,20 @@  discard block
 block discarded – undo
986 986
 	 *
987 987
 	 * @return array The different response element for the request. $has_error: A boolean result of request / $output: The complete html output for custom post type check / $tpl_componene: A mode complete list of element of templates
988 988
 	 */
989
-	public static function check_default_custom_post_type( $identifier, $tpl_component ) {
989
+	public static function check_default_custom_post_type($identifier, $tpl_component) {
990 990
 		global $wpdb;
991 991
 		$has_error = false;
992 992
 
993 993
 		/**	Check if custom post type exists	*/
994 994
 		$query = $wpdb->prepare("SELECT post_title FROM " . $wpdb->posts . " WHERE post_name = %s", $identifier);
995 995
 		$custom_post_type_title = $wpdb->get_var($query);
996
-		if ( !empty($custom_post_type_title) ) {
996
+		if (!empty($custom_post_type_title)) {
997 997
 			$tpl_component['CUSTOM_POST_TYPE_IDENTIFIER'] = '<img class="wpshop_tools_check_icon no_error" src="' . WPSHOP_MEDIAS_ICON_URL . 'informations/success_s.png" /> ' . $custom_post_type_title . ' (' . $identifier . ')';
998 998
 			$tpl_component['TOOLS_CUSTOM_POST_TYPE_CONTAINER_CLASS'] = ' no_error';
999 999
 			$tpl_component['CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES'] = '';
1000 1000
 			$template_part = 'wpshop_admin_tools_default_datas_check_main_element_content_no_error';
1001 1001
 
1002
-			$attributes_for_cpt = wpshop_entities::check_default_cpt_attributes( $identifier, $tpl_component, $has_error );
1002
+			$attributes_for_cpt = wpshop_entities::check_default_cpt_attributes($identifier, $tpl_component, $has_error);
1003 1003
 			$has_error = $attributes_for_cpt[0];
1004 1004
 			$tpl_component['CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES'] = $attributes_for_cpt[1];
1005 1005
 		}
@@ -1024,39 +1024,39 @@  discard block
 block discarded – undo
1024 1024
 	 *
1025 1025
 	 * @return array The different response element for the request. $has_error: A boolean information for request result / $output: The complete html output for attribute check
1026 1026
 	 */
1027
-	public static function check_default_cpt_attributes( $identifier, $tpl_component, $has_error, $custom_file = '' ) {
1027
+	public static function check_default_cpt_attributes($identifier, $tpl_component, $has_error, $custom_file = '') {
1028 1028
 		global $wpdb, $attribute_displayed_field;
1029 1029
 		$output = '';
1030 1030
 
1031
-		$cpt_attributes_file_uri = !empty( $custom_file ) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '-attributes.csv';
1032
-		if ( is_file( $cpt_attributes_file_uri ) ) {
1031
+		$cpt_attributes_file_uri = !empty($custom_file) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '-attributes.csv';
1032
+		if (is_file($cpt_attributes_file_uri)) {
1033 1033
 			/**	Read lines into file defining default datas */
1034 1034
 			$csv_file_default_data = file($cpt_attributes_file_uri, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
1035
-			if ( !empty($csv_file_default_data) ) {
1035
+			if (!empty($csv_file_default_data)) {
1036 1036
 				$header_line = explode(';', $csv_file_default_data[0]);
1037 1037
 				unset($csv_file_default_data[0]);
1038 1038
 				$code_column = null;
1039 1039
 				$available_columns = array();
1040
-				foreach ( $header_line as $column_key => $column_value ) {
1041
-					if ( $column_value == 'code' ) {
1040
+				foreach ($header_line as $column_key => $column_value) {
1041
+					if ($column_value == 'code') {
1042 1042
 						$code_column = $column_key;
1043 1043
 // 						$available_columns[$column_value] = $column_key;
1044 1044
 					}
1045
-					else if ( in_array( $column_value, array('frontend_label')/* $attribute_displayed_field */ ) ) {
1045
+					else if (in_array($column_value, array('frontend_label')/* $attribute_displayed_field */)) {
1046 1046
 						$available_columns[$column_value] = $column_key;
1047 1047
 					}
1048 1048
 				}
1049 1049
 
1050 1050
 				/**	Read the complete file content	*/
1051 1051
 				$attribute_ok = $attribute_not_ok = '  ';
1052
-				foreach ( $csv_file_default_data as $line_index => $line_content ) {
1052
+				foreach ($csv_file_default_data as $line_index => $line_content) {
1053 1053
 					$line_contents = explode(';', $line_content);
1054 1054
 					$query = $wpdb->prepare("SELECT id, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $line_contents[$code_column], wpshop_entities::get_entity_identifier_from_code($identifier));
1055
-					$attribute = $wpdb->get_row( $query );
1056
-					if ( !empty($line_contents) ) {
1057
-						foreach ( $line_contents as $line_column => $line_column_value ) {
1058
-							if ( in_array( $line_column, $available_columns ) ) {
1059
-								if ( !empty($attribute) ) {
1055
+					$attribute = $wpdb->get_row($query);
1056
+					if (!empty($line_contents)) {
1057
+						foreach ($line_contents as $line_column => $line_column_value) {
1058
+							if (in_array($line_column, $available_columns)) {
1059
+								if (!empty($attribute)) {
1060 1060
 									$attribute_ok .= $attribute->frontend_label . ', ';
1061 1061
 								}
1062 1062
 								else {
@@ -1067,18 +1067,18 @@  discard block
 block discarded – undo
1067 1067
 						}
1068 1068
 					}
1069 1069
 				}
1070
-				$attribute_not_ok = substr( $attribute_not_ok, 2, -2 );
1071
-				if ( !empty($attribute_not_ok) ) {
1072
-					$output .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element_content_attributes_error', array_merge( $tpl_component, array( 'CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES_LIST' => $attribute_not_ok )), array(), 'admin');
1070
+				$attribute_not_ok = substr($attribute_not_ok, 2, -2);
1071
+				if (!empty($attribute_not_ok)) {
1072
+					$output .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element_content_attributes_error', array_merge($tpl_component, array('CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES_LIST' => $attribute_not_ok)), array(), 'admin');
1073 1073
 				}
1074
-				$attribute_ok = substr( $attribute_ok, 2, -2 );
1075
-				if ( !empty($attribute_ok) ) {
1076
-					$output .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element_content_attributes_no_error', array_merge( $tpl_component, array( 'CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES_LIST' => $attribute_ok )), array(), 'admin');
1074
+				$attribute_ok = substr($attribute_ok, 2, -2);
1075
+				if (!empty($attribute_ok)) {
1076
+					$output .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element_content_attributes_no_error', array_merge($tpl_component, array('CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES_LIST' => $attribute_ok)), array(), 'admin');
1077 1077
 				}
1078 1078
 			}
1079 1079
 		}
1080 1080
 
1081
-		return array( $has_error, $output );
1081
+		return array($has_error, $output);
1082 1082
 	}
1083 1083
 
1084 1084
 	/**
@@ -1088,60 +1088,60 @@  discard block
 block discarded – undo
1088 1088
 	 *
1089 1089
 	 * @return array The different response element for the request. $result: Boolean representing if creation is OK / $container: Where the result must be placed into output code / $output: The html content to output
1090 1090
 	 */
1091
-	public static function create_cpt_attributes_from_csv_file( $identifier, $custom_file = '' ) {
1091
+	public static function create_cpt_attributes_from_csv_file($identifier, $custom_file = '') {
1092 1092
 		global $wpdb;
1093 1093
 
1094 1094
 		$output = $container = '';
1095 1095
 		$result = true;
1096 1096
 		$container = 'wpshop_cpt_' . $identifier . ' ul.wpshop_tools_default_datas_repair_attribute_container';
1097
-		$excluded_column = array( 'available_values' );
1097
+		$excluded_column = array('available_values');
1098 1098
 
1099
-		$file_uri = !empty( $custom_file ) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '-attributes.csv';
1100
-		if ( is_file( $file_uri ) ) {
1099
+		$file_uri = !empty($custom_file) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '-attributes.csv';
1100
+		if (is_file($file_uri)) {
1101 1101
 			$entity_id = wpshop_entities::get_entity_identifier_from_code($identifier);
1102 1102
 			$csv_file_default_data = file($file_uri, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
1103 1103
 
1104
-			$db_field_definition = explode( ";", $csv_file_default_data[0] );
1104
+			$db_field_definition = explode(";", $csv_file_default_data[0]);
1105 1105
 			$code_column = null;
1106
-			foreach ( $db_field_definition as $column_index => $column_name ) {
1107
-				if ( $column_name == 'code' ) {
1106
+			foreach ($db_field_definition as $column_index => $column_name) {
1107
+				if ($column_name == 'code') {
1108 1108
 					$code_column = $column_index;
1109 1109
 					continue;
1110 1110
 				}
1111 1111
 			}
1112 1112
 			unset($csv_file_default_data[0]);
1113 1113
 
1114
-			if ( !empty($code_column) || ($code_column == 0) ) {
1115
-				foreach ( $csv_file_default_data as $line_index => $line_content ) {
1116
-					$attribute_definition = explode( ";", $line_content );
1117
-					$query = $wpdb->prepare( "SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_definition[$code_column], $entity_id);
1114
+			if (!empty($code_column) || ($code_column == 0)) {
1115
+				foreach ($csv_file_default_data as $line_index => $line_content) {
1116
+					$attribute_definition = explode(";", $line_content);
1117
+					$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_definition[$code_column], $entity_id);
1118 1118
 					$attribute_identifier = $wpdb->get_var($query);
1119 1119
 
1120
-					if ( empty($attribute_identifier) ) {
1120
+					if (empty($attribute_identifier)) {
1121 1121
 						$attribute_def = array();
1122 1122
 						$attribute_values = $default_value = null;
1123
-						foreach ( $db_field_definition as $column_index => $column_name ) {
1123
+						foreach ($db_field_definition as $column_index => $column_name) {
1124 1124
 							$column_name = trim($column_name);
1125
-							if ( !empty($column_name) && !in_array($column_name, $excluded_column) ) {
1125
+							if (!empty($column_name) && !in_array($column_name, $excluded_column)) {
1126 1126
 								$column_value = $attribute_definition[$column_index];
1127
-								switch ( $column_name ) {
1127
+								switch ($column_name) {
1128 1128
 									case 'frontend_label':
1129
-										$column_value = __( $column_value, 'wpshop' );
1129
+										$column_value = __($column_value, 'wpshop');
1130 1130
 										break;
1131 1131
 								}
1132
-								$attribute_def[$column_name] = ( !empty($attribute_definition[$column_index]) ) ? $column_value : '';
1132
+								$attribute_def[$column_name] = (!empty($attribute_definition[$column_index])) ? $column_value : '';
1133 1133
 							}
1134 1134
 							else {
1135
-								switch ( $column_name ) {
1135
+								switch ($column_name) {
1136 1136
 									case 'available_values':
1137 1137
 										$attribute_values = $attribute_definition[$column_index];
1138 1138
 									break;
1139 1139
 								}
1140 1140
 							}
1141 1141
 
1142
-							switch ( $column_name ) {
1142
+							switch ($column_name) {
1143 1143
 								case 'default_value':
1144
-									$default_value = __( $attribute_definition[$column_index], 'wpshop' );
1144
+									$default_value = __($attribute_definition[$column_index], 'wpshop');
1145 1145
 								break;
1146 1146
 							}
1147 1147
 						}
@@ -1150,14 +1150,14 @@  discard block
 block discarded – undo
1150 1150
 						$last_attribute_id = $wpdb->insert_id;
1151 1151
 
1152 1152
 						/**	Create values for select element	*/
1153
-						if ( !empty($attribute_values) ) {
1154
-							$list_of_values_to_create = explode( ',', $attribute_values );
1155
-							if ( !empty($list_of_values_to_create) ) {
1156
-								foreach ( $list_of_values_to_create as $value ) {
1157
-									$value_element = explode( '!:!:!', $value);
1158
-									$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $last_attribute_id, 'label' => __( $value_element[0], 'wpshop' ), 'value' => __( (!empty($value_element[1]) ? $value_element[1] : strtolower($value_element[0]) ), 'wpshop' )));
1159
-
1160
-									if ( $default_value == (!empty($value_element[1]) ? $value_element[1] : strtolower($value_element[0])) ) {
1153
+						if (!empty($attribute_values)) {
1154
+							$list_of_values_to_create = explode(',', $attribute_values);
1155
+							if (!empty($list_of_values_to_create)) {
1156
+								foreach ($list_of_values_to_create as $value) {
1157
+									$value_element = explode('!:!:!', $value);
1158
+									$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $last_attribute_id, 'label' => __($value_element[0], 'wpshop'), 'value' => __((!empty($value_element[1]) ? $value_element[1] : strtolower($value_element[0])), 'wpshop')));
1159
+
1160
+									if ($default_value == (!empty($value_element[1]) ? $value_element[1] : strtolower($value_element[0]))) {
1161 1161
 										$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $last_attribute_id, 'default_value' => $default_value));
1162 1162
 									}
1163 1163
 								}
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 			}
1170 1170
 		}
1171 1171
 
1172
-		$check_cpt = wpshop_entities::check_default_cpt_attributes( $identifier, array(), false, $custom_file );
1172
+		$check_cpt = wpshop_entities::check_default_cpt_attributes($identifier, array(), false, $custom_file);
1173 1173
 		$output = $check_cpt[1];
1174 1174
 
1175 1175
 		return array($result, $container, $output);
Please login to merge, or discard this patch.