Completed
Push — master ( f161aa...d0d50d )
by
unknown
15:24
created
wpshop.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -18,55 +18,55 @@  discard block
 block discarded – undo
18 18
  * @package wpshop
19 19
  */
20 20
 
21
-ini_set( 'memory_limit', '512M' );
21
+ini_set('memory_limit', '512M');
22 22
 
23 23
 /**    Check if file is include. No direct access possible with file url    */
24
-if ( ! defined( 'ABSPATH' ) ) {
25
-	die( 'Access is not allowed by this way' );
24
+if (!defined('ABSPATH')) {
25
+	die('Access is not allowed by this way');
26 26
 }
27 27
 
28 28
 /**    Allows to refresh css and js file in final user browser    */
29
-DEFINE( 'WPSHOP_VERSION', '1.4.4.3' );
29
+DEFINE('WPSHOP_VERSION', '1.4.4.3');
30 30
 
31 31
 /**    Allows to avoid problem with theme not supporting thumbnail for post    */
32
-add_theme_support( 'post-thumbnails' );
33
-add_image_size( 'wpshop-product-galery', 270, 270, true );
34
-add_image_size( 'wps-categorie-mini-display', 80, 80, true );
35
-add_image_size( 'wps-categorie-display', 480, 340, true );
32
+add_theme_support('post-thumbnails');
33
+add_image_size('wpshop-product-galery', 270, 270, true);
34
+add_image_size('wps-categorie-mini-display', 80, 80, true);
35
+add_image_size('wps-categorie-display', 480, 340, true);
36 36
 
37 37
 /**    First thing we define the main directory for our plugin in a super global var    */
38
-DEFINE( 'WPSHOP_PLUGIN_DIR', basename( dirname( __FILE__ ) ) );
39
-DEFINE( 'WPSHOP_PLUGIN_NAME', plugin_basename( __FILE__ ) );
38
+DEFINE('WPSHOP_PLUGIN_DIR', basename(dirname(__FILE__)));
39
+DEFINE('WPSHOP_PLUGIN_NAME', plugin_basename(__FILE__));
40 40
 
41 41
 /**    Get the current language to translate the different text in plugin    */
42 42
 $locale = get_locale();
43 43
 global $wpdb;
44
-if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
45
-	$query = $wpdb->prepare( 'SELECT locale FROM ' . $wpdb->prefix . 'icl_locale_map WHERE code = %s', ICL_LANGUAGE_CODE );
46
-	$local = $wpdb->get_var( $query );
47
-	$locale = ! empty( $local ) ? $local : $locale;
44
+if (defined('ICL_LANGUAGE_CODE')) {
45
+	$query = $wpdb->prepare('SELECT locale FROM ' . $wpdb->prefix . 'icl_locale_map WHERE code = %s', ICL_LANGUAGE_CODE);
46
+	$local = $wpdb->get_var($query);
47
+	$locale = !empty($local) ? $local : $locale;
48 48
 }
49
-DEFINE( 'WPSHOP_CURRENT_LOCALE', $locale );
49
+DEFINE('WPSHOP_CURRENT_LOCALE', $locale);
50 50
 /**    Load plugin translation    */
51
-load_plugin_textdomain( 'wpshop', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
51
+load_plugin_textdomain('wpshop', false, dirname(plugin_basename(__FILE__)) . '/languages/');
52 52
 
53 53
 /**    Include the config file    */
54 54
 require WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/includes/config.php';
55 55
 
56 56
 /** Allow to get errors back when debug mode is set to true    */
57
-if ( WPSHOP_DEBUG_MODE && (in_array( long2ip( ip2long( $_SERVER['REMOTE_ADDR'] ) ), unserialize( WPSHOP_DEBUG_MODE_ALLOWED_IP ) )) ) {
58
-	ini_set( 'display_errors', true );
59
-	error_reporting( E_ALL );
57
+if (WPSHOP_DEBUG_MODE && (in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP)))) {
58
+	ini_set('display_errors', true);
59
+	error_reporting(E_ALL);
60 60
 }
61 61
 
62 62
 include_once WPSHOP_LIBRAIRIES_DIR . 'init.class.php';
63
-$current_installation_step = get_option( 'wps-installation-current-step', 1 );
63
+$current_installation_step = get_option('wps-installation-current-step', 1);
64 64
 
65 65
 /**    Get current plugin version    */
66
-$current_db_version = get_option( 'wpshop_db_options', 0 );
66
+$current_db_version = get_option('wpshop_db_options', 0);
67 67
 
68 68
 /**    Call main initialisation function    */
69
-add_action( 'init', array( 'wpshop_init', 'load' ) );
69
+add_action('init', array('wpshop_init', 'load'));
70 70
 
71 71
 /**    Include the main including file    */
72 72
 require WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/includes/include.php';
@@ -78,32 +78,32 @@  discard block
 block discarded – undo
78 78
 
79 79
 /**    Call function to create the main left menu    */
80 80
 // if ( ( WPSINSTALLER_STEPS_COUNT <= $current_installation_step ) || ( !empty( $current_db_version ) && !empty( $current_db_version[ 'db_version' ] ) && ( 51 < $current_db_version[ 'db_version' ] ) ) || ( !empty( $_GET ) && !empty( $_GET[ 'installation_state' ] ) && ( "ignored" == $_GET[ 'installation_state' ] ) ) ) {
81
-add_action( 'admin_menu', array( 'wpshop_init', 'admin_menu' ) );
82
-add_action( 'menu_order', array( 'wpshop_init', 'admin_menu_order' ) );
83
-add_action( 'custom_menu_order', array( 'wpshop_init', 'admin_custom_menu_order' ) );
81
+add_action('admin_menu', array('wpshop_init', 'admin_menu'));
82
+add_action('menu_order', array('wpshop_init', 'admin_menu_order'));
83
+add_action('custom_menu_order', array('wpshop_init', 'admin_custom_menu_order'));
84 84
 
85 85
 /*    Call function for new WordPress element creating [term (product_category) / post (product)]    */
86
-add_action( 'init', array( 'wpshop_init', 'add_new_wp_type' ) );
86
+add_action('init', array('wpshop_init', 'add_new_wp_type'));
87 87
 
88 88
 /*    Call function allowing to change element front output    */
89
-add_action( 'the_content', array( 'wpshop_display', 'products_page' ), 1 );
89
+add_action('the_content', array('wpshop_display', 'products_page'), 1);
90 90
 // add_action('archive_template', array('wpshop_categories', 'category_template_switcher'));
91 91
 // }
92 92
 /**    On plugin activation create the default parameters to use the ecommerce    */
93
-register_activation_hook( __FILE__, array( 'wpshop_install', 'install_on_activation' ) );
93
+register_activation_hook(__FILE__, array('wpshop_install', 'install_on_activation'));
94 94
 
95 95
 /**    Get current plugin version    */
96
-$current_db_version = get_option( 'wpshop_db_options', 0 );
96
+$current_db_version = get_option('wpshop_db_options', 0);
97 97
 
98 98
 /**    Add the database content    */
99
-add_action( 'admin_init', array( 'wpshop_install', 'update_wpshop' ) );
100
-if ( (defined( 'WPSINSTALLER_STEPS_COUNT' ) && (WPSINSTALLER_STEPS_COUNT <= $current_installation_step)) || ( ! empty( $current_db_version ) && ! empty( $current_db_version['db_version'] ) && (51 < $current_db_version['db_version'])) || ( ! empty( $current_db_version ) && ! empty( $current_db_version['installation_state'] ) && ('ignore' == $current_db_version['installation_state'])) ) {
101
-	if ( in_array( long2ip( ip2long( $_SERVER['REMOTE_ADDR'] ) ), unserialize( WPSHOP_DEBUG_MODE_ALLOWED_IP ) ) ) {
102
-		add_action( 'admin_init', array( 'wpshop_install', 'update_wpshop_dev' ) );
99
+add_action('admin_init', array('wpshop_install', 'update_wpshop'));
100
+if ((defined('WPSINSTALLER_STEPS_COUNT') && (WPSINSTALLER_STEPS_COUNT <= $current_installation_step)) || (!empty($current_db_version) && !empty($current_db_version['db_version']) && (51 < $current_db_version['db_version'])) || (!empty($current_db_version) && !empty($current_db_version['installation_state']) && ('ignore' == $current_db_version['installation_state']))) {
101
+	if (in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) {
102
+		add_action('admin_init', array('wpshop_install', 'update_wpshop_dev'));
103 103
 	}
104 104
 }
105 105
 // Start session
106
-if ( session_id() == '' ) {
106
+if (session_id() == '') {
107 107
 	 session_start();
108 108
 }
109 109
 
@@ -113,52 +113,52 @@  discard block
 block discarded – undo
113 113
 	$wpshop = new wpshop_form_management();
114 114
 	$wpshop_payment = new wpshop_payment();
115 115
 }
116
-add_action( 'init', 'classes_init' );
116
+add_action('init', 'classes_init');
117 117
 
118 118
 /** Shortcode management */
119
-add_shortcode( 'wpshop_att_val', array( 'wpshop_attributes', 'wpshop_att_val_func' ) ); // Attributes
120
-add_shortcode( 'wpshop_products', array( 'wpshop_products', 'wpshop_products_func' ) ); // Products list
121
-add_shortcode( 'wpshop_product', array( 'wpshop_products', 'wpshop_products_func' ) ); // Products list
122
-add_shortcode( 'wpshop_product_variation_summary', array( 'wpshop_products', 'wpshop_product_variations_summary' ) ); // Variation summary
123
-add_shortcode( 'wpshop_product_variation_value_detail', array( 'wpshop_products', 'wpshop_product_variation_value_detail' ) ); // Variation value detail
124
-add_shortcode( 'wpshop_related_products', array( 'wpshop_products', 'wpshop_related_products_func' ) ); // Products list
125
-add_shortcode( 'wpshop_category', array( 'wpshop_categories', 'wpshop_category_func' ) ); // Category
126
-add_shortcode( 'wpshop_att_group', array( 'wpshop_attributes_set', 'wpshop_att_group_func' ) ); // Attributes groups
127
-add_shortcode( 'wpshop_cart', 'wpshop_display_cart' ); // Cart
119
+add_shortcode('wpshop_att_val', array('wpshop_attributes', 'wpshop_att_val_func')); // Attributes
120
+add_shortcode('wpshop_products', array('wpshop_products', 'wpshop_products_func')); // Products list
121
+add_shortcode('wpshop_product', array('wpshop_products', 'wpshop_products_func')); // Products list
122
+add_shortcode('wpshop_product_variation_summary', array('wpshop_products', 'wpshop_product_variations_summary')); // Variation summary
123
+add_shortcode('wpshop_product_variation_value_detail', array('wpshop_products', 'wpshop_product_variation_value_detail')); // Variation value detail
124
+add_shortcode('wpshop_related_products', array('wpshop_products', 'wpshop_related_products_func')); // Products list
125
+add_shortcode('wpshop_category', array('wpshop_categories', 'wpshop_category_func')); // Category
126
+add_shortcode('wpshop_att_group', array('wpshop_attributes_set', 'wpshop_att_group_func')); // Attributes groups
127
+add_shortcode('wpshop_cart', 'wpshop_display_cart'); // Cart
128 128
 // add_shortcode('wpshop_mini_cart', 'wpshop_display_mini_cart'); // Mini cart
129 129
 // add_shortcode('wpshop_signup', 'wpshop_signup_init'); // Signup
130 130
 // add_shortcode('wpshop_myaccount', 'wpshop_account_display_form' );
131
-add_shortcode( 'wpshop_payment_result', array( 'wpshop_payment', 'wpshop_payment_result' ) ); // Payment result
132
-add_shortcode( 'wpshop_payment_result_unsuccessfull', array( 'wpshop_payment', 'wpshop_payment_result' ) ); // Payment result
131
+add_shortcode('wpshop_payment_result', array('wpshop_payment', 'wpshop_payment_result')); // Payment result
132
+add_shortcode('wpshop_payment_result_unsuccessfull', array('wpshop_payment', 'wpshop_payment_result')); // Payment result
133 133
 
134
-add_shortcode( 'wpshop_variations', array( 'wpshop_products', 'wpshop_variation' ) );
135
-add_shortcode( 'wpshop_entities', array( 'wpshop_entities', 'wpshop_entities_shortcode' ) );
136
-add_shortcode( 'wpshop_attributes', array( 'wpshop_attributes', 'wpshop_attributes_shortcode' ) );
134
+add_shortcode('wpshop_variations', array('wpshop_products', 'wpshop_variation'));
135
+add_shortcode('wpshop_entities', array('wpshop_entities', 'wpshop_entities_shortcode'));
136
+add_shortcode('wpshop_attributes', array('wpshop_attributes', 'wpshop_attributes_shortcode'));
137 137
 
138 138
 /** Add specific messages for wpshop elements management    */
139 139
 // add_filter('post_updated_messages', array('wpshop_messages', 'update_wp_message_list'));
140
-$file = basename( __FILE__ );
141
-$folder = basename( dirname( __FILE__ ) );
140
+$file = basename(__FILE__);
141
+$folder = basename(dirname(__FILE__));
142 142
 $hook = "in_plugin_update_message-{$folder}/{$file}";
143
-add_action( $hook, 'wps_update_message', 10, 2 ); // 10:priority, 2:arguments #
144
-function wps_update_message( $currentPluginMetadata, $newPluginMetadata ) {
143
+add_action($hook, 'wps_update_message', 10, 2); // 10:priority, 2:arguments #
144
+function wps_update_message($currentPluginMetadata, $newPluginMetadata) {
145 145
 	$message = '';
146 146
 
147
-	if ( '1.4.1.6' == $currentPluginMetadata['Version'] ) {
148
-		$message = sprintf( __( 'For security reason %1$splease read this post%2$s', 'wpshop' ), '<a href="" >', '</a>' );
147
+	if ('1.4.1.6' == $currentPluginMetadata['Version']) {
148
+		$message = sprintf(__('For security reason %1$splease read this post%2$s', 'wpshop'), '<a href="" >', '</a>');
149 149
 	}
150 150
 
151 151
 	// check "upgrade_notice"
152
-	if ( isset( $newPluginMetadata->upgrade_notice ) && strlen( trim( $newPluginMetadata->upgrade_notice ) ) > 0 ) {
153
-		$message = esc_html( $newPluginMetadata->upgrade_notice );
152
+	if (isset($newPluginMetadata->upgrade_notice) && strlen(trim($newPluginMetadata->upgrade_notice)) > 0) {
153
+		$message = esc_html($newPluginMetadata->upgrade_notice);
154 154
 	}
155 155
 
156
-	if ( ! empty( $message ) ) {
157
-		echo '<p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px"><strong>' . __( 'Important upgrade notice', 'wpshop' ) . ': </strong>' . $message . '</p>';
156
+	if (!empty($message)) {
157
+		echo '<p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px"><strong>' . __('Important upgrade notice', 'wpshop') . ': </strong>' . $message . '</p>';
158 158
 	}
159 159
 }
160 160
 
161 161
 require_once 'core/external/wpeo_util/singleton.util.php';
162 162
 require_once 'core/external/wpeo_util/init.util.php';
163 163
 require_once 'core/external/wpeo_log/class/log.class.php';
164
-\eoxia\Init_util::g()->exec( realpath( plugin_dir_path( __FILE__ ) ) . '/', basename( __FILE__, '.php' ) );
164
+\eoxia\Init_util::g()->exec(realpath(plugin_dir_path(__FILE__)) . '/', basename(__FILE__, '.php'));
Please login to merge, or discard this patch.
includes/librairies/catalog/products.class.php 2 patches
Indentation   +3049 added lines, -3049 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
 /**
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 /*    Check if file is include. No direct access possible with file url    */
16 16
 if (!defined('WPSHOP_VERSION')) {
17
-    die(__('Access is not allowed by this way', 'wpshop'));
17
+	die(__('Access is not allowed by this way', 'wpshop'));
18 18
 }
19 19
 
20 20
 /**
@@ -25,156 +25,156 @@  discard block
 block discarded – undo
25 25
  * @subpackage librairies
26 26
  */
27 27
 class wpshop_products {
28
-    /**
29
-     *    Définition du code de la classe courante
30
-     */
31
-    const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
32
-    const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION;
33
-
34
-    public function add_product_to_current_order_interface()
35
-    {
36
-        $output = '';
37
-        $output .= self::products_list_js();
38
-        $output .= '<input type="text" id="wps_order_search_product" />';
39
-        echo $output;
40
-        die();
41
-    }
28
+	/**
29
+	 *    Définition du code de la classe courante
30
+	 */
31
+	const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
32
+	const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION;
33
+
34
+	public function add_product_to_current_order_interface()
35
+	{
36
+		$output = '';
37
+		$output .= self::products_list_js();
38
+		$output .= '<input type="text" id="wps_order_search_product" />';
39
+		echo $output;
40
+		die();
41
+	}
42 42
 
43
-    public function products_list_js()
44
-    {
45
-        global $wpdb;
46
-        $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1));
47
-
48
-        if (!empty($products_post)) {
49
-            $products_js_array = 'var products = [';
50
-            foreach ($products_post as $product) {
51
-                $barcode = get_post_meta($product->ID, '_barcode', true);
52
-                $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", ';
53
-                $products_js_array .= 'value:"' . $product->ID . '", ';
54
-                $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},';
55
-            }
56
-            $products_js_array .= '];';
57
-        }
58
-        $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin');
59
-        return $output;
60
-    }
43
+	public function products_list_js()
44
+	{
45
+		global $wpdb;
46
+		$products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1));
47
+
48
+		if (!empty($products_post)) {
49
+			$products_js_array = 'var products = [';
50
+			foreach ($products_post as $product) {
51
+				$barcode = get_post_meta($product->ID, '_barcode', true);
52
+				$products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", ';
53
+				$products_js_array .= 'value:"' . $product->ID . '", ';
54
+				$products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},';
55
+			}
56
+			$products_js_array .= '];';
57
+		}
58
+		$output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin');
59
+		return $output;
60
+	}
61 61
 
62
-    /**
63
-     *    Déclaration des produits et variations en tant que "post" de wordpress
64
-     *
65
-     *    @see register_post_type()
66
-     */
67
-    public static function create_wpshop_products_type()
68
-    {
69
-
70
-        $options = get_option('wpshop_catalog_product_option', array());
71
-        //$options2 = get_option('wpshop_catalog_categories_option', array());
72
-        /*echo '<pre>'; print_r( $options ); echo '</pre>';
62
+	/**
63
+	 *    Déclaration des produits et variations en tant que "post" de wordpress
64
+	 *
65
+	 *    @see register_post_type()
66
+	 */
67
+	public static function create_wpshop_products_type()
68
+	{
69
+
70
+		$options = get_option('wpshop_catalog_product_option', array());
71
+		//$options2 = get_option('wpshop_catalog_categories_option', array());
72
+		/*echo '<pre>'; print_r( $options ); echo '</pre>';
73 73
         echo '<pre>'; print_r( $options2 ); echo '</pre>'; exit();*/
74 74
 
75
-        $slug = array(
76
-            'slug' => '',
77
-            'with_front' => false,
78
-        );
79
-
80
-        if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') {
81
-            $slug = false;
82
-        } else {
83
-            $slug['slug'] = $options['wpshop_catalog_product_slug'];
84
-            if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
85
-                $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%';
86
-            }
87
-        }
88
-        /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/
89
-
90
-        /*    Définition des produits     */
91
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array(
92
-            'labels' => array(
93
-                'name' => __('Products', 'wpshop'),
94
-                'singular_name' => __('Catalog', 'wpshop'),
95
-                'add_new_item' => __('Add new product', 'wpshop'),
96
-                'add_new' => __('Add new product', 'wpshop'),
97
-                'add_new_item' => __('Add new product', 'wpshop'),
98
-                'edit_item' => __('Edit product', 'wpshop'),
99
-                'new_item' => __('New product', 'wpshop'),
100
-                'view_item' => __('View product', 'wpshop'),
101
-                'search_items' => __('Search products', 'wpshop'),
102
-                'not_found' => __('No products found', 'wpshop'),
103
-                'not_found_in_trash' => __('No products found in Trash', 'wpshop'),
104
-                'parent_item_colon' => '',
105
-            ),
106
-            'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
107
-            'public' => true,
108
-            'has_archive' => true,
109
-            'show_in_nav_menus' => true,
110
-            //'rewrite'                 => false,    //    For information see below
111
-            'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES),
112
-            'menu_icon' => 'dashicons-archive',
113
-            'rewrite' => $slug,
114
-        )));
115
-
116
-        /*    Définition des variations de produit (Déclinaisons)    */
117
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array(
118
-            'labels' => array(
119
-                'name' => __('Variations', 'wpshop'),
120
-                'singular_name' => __('Variation', 'wpshop'),
121
-                'add_new' => __('Add Variation', 'wpshop'),
122
-                'add_new_item' => __('Add New Variation', 'wpshop'),
123
-                'edit' => __('Edit', 'wpshop'),
124
-                'edit_item' => __('Edit Variation', 'wpshop'),
125
-                'new_item' => __('New Variation', 'wpshop'),
126
-                'view' => __('View Variation', 'wpshop'),
127
-                'view_item' => __('View Variation', 'wpshop'),
128
-                'search_items' => __('Search Variations', 'wpshop'),
129
-                'not_found' => __('No Variations found', 'wpshop'),
130
-                'not_found_in_trash' => __('No Variations found in trash', 'wpshop'),
131
-                'parent_item_colon' => '',
132
-            ),
133
-            'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
134
-            'public' => true,
135
-            'has_archive' => true,
136
-            'show_in_nav_menus' => false,
137
-            'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
138
-
139
-            'publicly_queryable' => false,
140
-            'exclude_from_search' => true,
141
-            'hierarchical' => false,
142
-
143
-            //             'public'                 => true,
144
-            //             'show_ui'                 => false,
145
-            //             'rewrite'                 => false,
146
-            //             'query_var'                => true,
147
-            //             'supports'                 => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
148
-            //             'show_in_nav_menus'     => false
149
-        )
150
-        ));
151
-
152
-        // add to our plugin init function
153
-        //global $wp_rewrite;
154
-        /*    Slug url is set into option    */
155
-        /*$options = get_option('wpshop_catalog_product_option', array());
75
+		$slug = array(
76
+			'slug' => '',
77
+			'with_front' => false,
78
+		);
79
+
80
+		if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') {
81
+			$slug = false;
82
+		} else {
83
+			$slug['slug'] = $options['wpshop_catalog_product_slug'];
84
+			if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
85
+				$slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%';
86
+			}
87
+		}
88
+		/*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/
89
+
90
+		/*    Définition des produits     */
91
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array(
92
+			'labels' => array(
93
+				'name' => __('Products', 'wpshop'),
94
+				'singular_name' => __('Catalog', 'wpshop'),
95
+				'add_new_item' => __('Add new product', 'wpshop'),
96
+				'add_new' => __('Add new product', 'wpshop'),
97
+				'add_new_item' => __('Add new product', 'wpshop'),
98
+				'edit_item' => __('Edit product', 'wpshop'),
99
+				'new_item' => __('New product', 'wpshop'),
100
+				'view_item' => __('View product', 'wpshop'),
101
+				'search_items' => __('Search products', 'wpshop'),
102
+				'not_found' => __('No products found', 'wpshop'),
103
+				'not_found_in_trash' => __('No products found in Trash', 'wpshop'),
104
+				'parent_item_colon' => '',
105
+			),
106
+			'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
107
+			'public' => true,
108
+			'has_archive' => true,
109
+			'show_in_nav_menus' => true,
110
+			//'rewrite'                 => false,    //    For information see below
111
+			'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES),
112
+			'menu_icon' => 'dashicons-archive',
113
+			'rewrite' => $slug,
114
+		)));
115
+
116
+		/*    Définition des variations de produit (Déclinaisons)    */
117
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array(
118
+			'labels' => array(
119
+				'name' => __('Variations', 'wpshop'),
120
+				'singular_name' => __('Variation', 'wpshop'),
121
+				'add_new' => __('Add Variation', 'wpshop'),
122
+				'add_new_item' => __('Add New Variation', 'wpshop'),
123
+				'edit' => __('Edit', 'wpshop'),
124
+				'edit_item' => __('Edit Variation', 'wpshop'),
125
+				'new_item' => __('New Variation', 'wpshop'),
126
+				'view' => __('View Variation', 'wpshop'),
127
+				'view_item' => __('View Variation', 'wpshop'),
128
+				'search_items' => __('Search Variations', 'wpshop'),
129
+				'not_found' => __('No Variations found', 'wpshop'),
130
+				'not_found_in_trash' => __('No Variations found in trash', 'wpshop'),
131
+				'parent_item_colon' => '',
132
+			),
133
+			'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
134
+			'public' => true,
135
+			'has_archive' => true,
136
+			'show_in_nav_menus' => false,
137
+			'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
138
+
139
+			'publicly_queryable' => false,
140
+			'exclude_from_search' => true,
141
+			'hierarchical' => false,
142
+
143
+			//             'public'                 => true,
144
+			//             'show_ui'                 => false,
145
+			//             'rewrite'                 => false,
146
+			//             'query_var'                => true,
147
+			//             'supports'                 => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
148
+			//             'show_in_nav_menus'     => false
149
+		)
150
+		));
151
+
152
+		// add to our plugin init function
153
+		//global $wp_rewrite;
154
+		/*    Slug url is set into option    */
155
+		/*$options = get_option('wpshop_catalog_product_option', array());
156 156
         $gallery_structure = (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : 'catalog');
157 157
         $gallery_structure .= !empty($options['wpshop_catalog_product_slug_with_category']) ? '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%' : '';
158 158
         $gallery_structure .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';
159 159
         $wp_rewrite->add_permastruct(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $gallery_structure, false);
160 160
         $wp_rewrite->add_rewrite_tag('%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%', '([^/]+)', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "=");*/
161
-        //    flush_rewrite_rules();
162
-    }
161
+		//    flush_rewrite_rules();
162
+	}
163 163
 
164
-    public static function hidden_meta_boxes($hidden, $screen, $use_defaults)
165
-    {
166
-        global $wpdb;
167
-        if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) {
168
-            $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
169
-            foreach ($user_meta_for_wpshop as $meta_to_check) {
170
-                $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true);
171
-                if (empty($metas_hidden) && !is_array($metas_hidden)) {
172
-                    $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX);
173
-                }
174
-            }
175
-        }
176
-        return $hidden;
177
-    }
164
+	public static function hidden_meta_boxes($hidden, $screen, $use_defaults)
165
+	{
166
+		global $wpdb;
167
+		if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) {
168
+			$user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
169
+			foreach ($user_meta_for_wpshop as $meta_to_check) {
170
+				$metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true);
171
+				if (empty($metas_hidden) && !is_array($metas_hidden)) {
172
+					$hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX);
173
+				}
174
+			}
175
+		}
176
+		return $hidden;
177
+	}
178 178
 
179 179
 	public static function admin_menu() {
180 180
 		global $submenu;
@@ -201,35 +201,35 @@  discard block
 block discarded – undo
201 201
 		$submenu['edit.php?post_type=wpshop_product'] = $submenu_reorder;
202 202
 	}
203 203
 
204
-    /**
205
-     *    Create the different bow for the product management page looking for the attribute set to create the different boxes
206
-     */
207
-    public static function add_meta_boxes()
208
-    {
209
-        global $post, $currentTabContent;
210
-
211
-        if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) {
212
-            /*    Get the attribute set list for the current entity    */
213
-            $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
214
-            /*    Check if the meta information of the current product already exists     */
215
-            $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
216
-            /*    Check if the product has been saved without meta information set    */
217
-            $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode);
218
-            /*    Unset 'free_product' from list of attributes set    */
219
-            foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
220
-                if ($attribute_set->slug == 'free_product') {
221
-                    unset($attributeEntitySetList[$key_attribute_set]);
222
-                    break;
223
-                }
224
-            }
225
-
226
-            /*    Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing    */
227
-            if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) {
228
-                if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) {
229
-                    $post_attribute_set_id = $attributeEntitySetList[0]->id;
230
-                } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) {
231
-                    $post_attribute_set_id = $attribute_set_id->value;
232
-                }
204
+	/**
205
+	 *    Create the different bow for the product management page looking for the attribute set to create the different boxes
206
+	 */
207
+	public static function add_meta_boxes()
208
+	{
209
+		global $post, $currentTabContent;
210
+
211
+		if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) {
212
+			/*    Get the attribute set list for the current entity    */
213
+			$attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
214
+			/*    Check if the meta information of the current product already exists     */
215
+			$post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
216
+			/*    Check if the product has been saved without meta information set    */
217
+			$attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode);
218
+			/*    Unset 'free_product' from list of attributes set    */
219
+			foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
220
+				if ($attribute_set->slug == 'free_product') {
221
+					unset($attributeEntitySetList[$key_attribute_set]);
222
+					break;
223
+				}
224
+			}
225
+
226
+			/*    Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing    */
227
+			if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) {
228
+				if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) {
229
+					$post_attribute_set_id = $attributeEntitySetList[0]->id;
230
+				} elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) {
231
+					$post_attribute_set_id = $attribute_set_id->value;
232
+				}
233 233
 
234 234
 		/*$post_attribute_set_id = (int) get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
235 235
 
@@ -247,47 +247,47 @@  discard block
 block discarded – undo
247 247
 			}
248 248
 		}*/
249 249
 
250
-                $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID);
251
-
252
-                $fixed_box_exist = false;
253
-                /*    Get all the other attribute set for hte current entity    */
254
-                if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) {
255
-                    foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
256
-                        if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
257
-                            add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier));
258
-                        } else {
259
-                            $fixed_box_exist = true;
260
-                        }
261
-
262
-                    }
263
-                }
264
-                if ($fixed_box_exist) {
265
-                    add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent));
266
-                    add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent));
267
-                }
268
-
269
-                add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default');
270
-                // Actions
271
-                // @since 1.4.3.7 Deleted
272
-                //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
273
-
274
-                /**    Product option    */
275
-                add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
276
-            } else if (count($attributeEntitySetList) > 1) {
277
-                $input_def['id'] = 'product_attribute_set_id';
278
-                $input_def['name'] = 'product_attribute_set_id';
279
-                $input_def['value'] = '';
280
-                $input_def['type'] = 'select';
281
-                $input_def['possible_value'] = $attributeEntitySetList;
282
-
283
-                $input_def['value'] = '';
284
-                foreach ($attributeEntitySetList as $set) {
285
-                    if ($set->default_set == 'yes') {
286
-                        $input_def['value'] = $set->id;
287
-                    }
288
-                }
289
-
290
-                $currentTabContent['boxContent']['attribute_set_selector'] = '
250
+				$currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID);
251
+
252
+				$fixed_box_exist = false;
253
+				/*    Get all the other attribute set for hte current entity    */
254
+				if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) {
255
+					foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
256
+						if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
257
+							add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier));
258
+						} else {
259
+							$fixed_box_exist = true;
260
+						}
261
+
262
+					}
263
+				}
264
+				if ($fixed_box_exist) {
265
+					add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent));
266
+					add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent));
267
+				}
268
+
269
+				add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default');
270
+				// Actions
271
+				// @since 1.4.3.7 Deleted
272
+				//add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
273
+
274
+				/**    Product option    */
275
+				add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
276
+			} else if (count($attributeEntitySetList) > 1) {
277
+				$input_def['id'] = 'product_attribute_set_id';
278
+				$input_def['name'] = 'product_attribute_set_id';
279
+				$input_def['value'] = '';
280
+				$input_def['type'] = 'select';
281
+				$input_def['possible_value'] = $attributeEntitySetList;
282
+
283
+				$input_def['value'] = '';
284
+				foreach ($attributeEntitySetList as $set) {
285
+					if ($set->default_set == 'yes') {
286
+						$input_def['value'] = $set->id;
287
+					}
288
+				}
289
+
290
+				$currentTabContent['boxContent']['attribute_set_selector'] = '
291 291
 	<ul class="attribute_set_selector" >
292 292
 		<li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li>
293 293
 		<li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . __('Choose an attribute group for this product', 'wpshop') . '</label>&nbsp;' . wpshop_form::check_input_type($input_def, self::currentPageCode . '_attribute[integer]') . '</li>
@@ -295,699 +295,699 @@  discard block
 block discarded – undo
295 295
 		<li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li>
296 296
 	</ul>';
297 297
 
298
-                add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector'));
299
-            }
300
-        }
298
+				add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector'));
299
+			}
300
+		}
301 301
 
302
-    }
302
+	}
303 303
 
304
-    /**
305
-     * Add a box into product edition page for options on the product
306
-     *
307
-     * @param object $post
308
-     */
309
-    public static function product_options_meta_box_content($post)
310
-    {
311
-        $output = '';
304
+	/**
305
+	 * Add a box into product edition page for options on the product
306
+	 *
307
+	 * @param object $post
308
+	 */
309
+	public static function product_options_meta_box_content($post)
310
+	{
311
+		$output = '';
312 312
 
313
-        $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
313
+		$product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
314 314
 
315
-        $tpl_component = array();
316
-        $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
317
-        $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
315
+		$tpl_component = array();
316
+		$tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
317
+		$output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
318 318
 
319
-        echo $output;
320
-    }
319
+		echo $output;
320
+	}
321 321
 
322
-    /**
323
-     * Display the fixed box
324
-     */
325
-    public static function product_data_meta_box($post, $metaboxArgs)
326
-    {
327
-        $output = '';
322
+	/**
323
+	 * Display the fixed box
324
+	 */
325
+	public static function product_data_meta_box($post, $metaboxArgs)
326
+	{
327
+		$output = '';
328 328
 
329
-        $currentTabContent = $metaboxArgs['args']['currentTabContent'];
329
+		$currentTabContent = $metaboxArgs['args']['currentTabContent'];
330 330
 
331
-        echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
331
+		echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
332 332
 				<ul>';
333
-        if (!empty($currentTabContent['box'])) {
334
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
335
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
336
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
337
-                        echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
338
-                    }
339
-                }
340
-            }
341
-        }
342
-        echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
343
-        echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
344
-        echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
345
-        echo '</ul>';
346
-
347
-        if (!empty($currentTabContent['box'])) {
348
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
349
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
350
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
351
-                        echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
352
-                    }
353
-                }
354
-            }
355
-        }
333
+		if (!empty($currentTabContent['box'])) {
334
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
335
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
336
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
337
+						echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
338
+					}
339
+				}
340
+			}
341
+		}
342
+		echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
343
+		echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
344
+		echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
345
+		echo '</ul>';
346
+
347
+		if (!empty($currentTabContent['box'])) {
348
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
349
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
350
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
351
+						echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
352
+					}
353
+				}
354
+			}
355
+		}
356 356
 
357
-        echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
358
-        echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
359
-        if (!empty($currentTabContent['boxMore'])) {
360
-            echo $currentTabContent['boxMore'];
361
-        }
362
-        echo '</div>';
357
+		echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
358
+		echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
359
+		if (!empty($currentTabContent['boxMore'])) {
360
+			echo $currentTabContent['boxMore'];
361
+		}
362
+		echo '</div>';
363 363
 
364
-        echo $output;
365
-    }
364
+		echo $output;
365
+	}
366 366
 
367
-    /**
368
-     * Output the content for related product metabox
369
-     * @param object $post The current edited post
370
-     * @return string
371
-     */
372
-    public static function related_products_meta_box_content($post)
373
-    {
374
-        $content = $existing_selection = '';
375
-
376
-        if (!empty($post->ID)) {
377
-            $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
378
-            if (!empty($related_products_id) && !empty($related_products_id[0])) {
379
-                foreach ($related_products_id as $related_product_id) {
380
-                    $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
381
-                }
382
-            }
383
-        }
367
+	/**
368
+	 * Output the content for related product metabox
369
+	 * @param object $post The current edited post
370
+	 * @return string
371
+	 */
372
+	public static function related_products_meta_box_content($post)
373
+	{
374
+		$content = $existing_selection = '';
375
+
376
+		if (!empty($post->ID)) {
377
+			$related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
378
+			if (!empty($related_products_id) && !empty($related_products_id[0])) {
379
+				foreach ($related_products_id as $related_product_id) {
380
+					$existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
381
+				}
382
+			}
383
+		}
384 384
 
385
-        $content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p>
385
+		$content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p>
386 386
 			<select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select>
387 387
 			<input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" />
388 388
 			<input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
389 389
 
390
-        return $content;
391
-    }
390
+		return $content;
391
+	}
392 392
 
393
-    /**
394
-     * Define the metabox content for the action box
395
-     * @param obejct $post The current element being edited
396
-     */
397
-    public static function product_actions_meta_box_content($post)
398
-    {
399
-        $output = '';
400
-        /*
393
+	/**
394
+	 * Define the metabox content for the action box
395
+	 * @param obejct $post The current element being edited
396
+	 */
397
+	public static function product_actions_meta_box_content($post)
398
+	{
399
+		$output = '';
400
+		/*
401 401
          * Template parameters
402 402
          */
403
-        $template_part = 'wpshop_duplicate_product';
404
-        $tpl_component = array();
405
-        $tpl_component['PRODUCT_ID'] = $post->ID;
406
-        $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
407
-        /*
403
+		$template_part = 'wpshop_duplicate_product';
404
+		$tpl_component = array();
405
+		$tpl_component['PRODUCT_ID'] = $post->ID;
406
+		$tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
407
+		/*
408 408
          * Build template
409 409
          */
410
-        $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
411
-        unset($tpl_component);
410
+		$output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
411
+		unset($tpl_component);
412 412
 
413
-        echo $output;
414
-    }
413
+		echo $output;
414
+	}
415 415
 
416
-    /**
417
-     *    Define the content of the product main information box
418
-     */
419
-    public static function meta_box_content($post, $metaboxArgs)
420
-    {
421
-        global $currentTabContent;
416
+	/**
417
+	 *    Define the content of the product main information box
418
+	 */
419
+	public static function meta_box_content($post, $metaboxArgs)
420
+	{
421
+		global $currentTabContent;
422 422
 
423
-        /*    Add the extra fields defined by the default attribute group in the general section    */
424
-        echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
425
-    }
423
+		/*    Add the extra fields defined by the default attribute group in the general section    */
424
+		echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
425
+	}
426 426
 
427
-    /**
428
-     * Define the metabox content for product custom display in product
429
-     * @param object $post The current element being edited
430
-     * @return string The metabox content
431
-     */
432
-    public static function product_frontend_display_config_meta_box($post)
433
-    {
434
-        $content = '';
435
-
436
-        $product_attribute_frontend_display_config = null;
437
-        if (!empty($post->ID)) {
438
-            $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
439
-
440
-            $extra_options = get_option('wpshop_extra_options', array());
441
-            $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
442
-            $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
443
-            $column = 1;
444
-
445
-            if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
446
-                $sub_tpl_component = array();
447
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
448
-
449
-                $tpl_component = array();
450
-                $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
451
-                $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
452
-                $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
453
-                $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
454
-
455
-                $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : '';
456
-                $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : '';
457
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
458
-                unset($tpl_component);
459
-
460
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
461
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
462
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
463
-                $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
464
-            }
465
-
466
-            if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
467
-                foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
468
-                    if (!isset($sub_content[$column])) {
469
-                        $sub_content[$column] = '';
470
-                    }
471
-
472
-                    $attribute_sub_output = '';
473
-                    foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
474
-                        if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
475
-                            $tpl_component = array();
476
-                            $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
477
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
478
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
479
-                            $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : '';
480
-                            $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : '';
481
-                            $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
482
-                            unset($tpl_component);
483
-                        }
484
-                    }
485
-
486
-                    $tpl_component = array();
487
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
488
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
489
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
490
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
491
-                    $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : '';
492
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>';
493
-                    $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
494
-                    $column++;
495
-                    if ($column > $column_count) {
496
-                        $column = 1;
497
-                    }
498
-                }
499
-            }
500
-            $tpl_component = array();
501
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
502
-            for ($i = 1; $i <= $column_count; $i++) {
503
-                if (!empty($sub_content[$i])) {
504
-                    $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
505
-                }
506
-
507
-            }
508
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
509
-            $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
510
-            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
511
-
512
-            $content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>';
513
-        }
427
+	/**
428
+	 * Define the metabox content for product custom display in product
429
+	 * @param object $post The current element being edited
430
+	 * @return string The metabox content
431
+	 */
432
+	public static function product_frontend_display_config_meta_box($post)
433
+	{
434
+		$content = '';
435
+
436
+		$product_attribute_frontend_display_config = null;
437
+		if (!empty($post->ID)) {
438
+			$product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
439
+
440
+			$extra_options = get_option('wpshop_extra_options', array());
441
+			$column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
442
+			$attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
443
+			$column = 1;
444
+
445
+			if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
446
+				$sub_tpl_component = array();
447
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
448
+
449
+				$tpl_component = array();
450
+				$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
451
+				$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
452
+				$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
453
+				$button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
454
+
455
+				$tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : '';
456
+				$tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : '';
457
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
458
+				unset($tpl_component);
459
+
460
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
461
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
462
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
463
+				$sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
464
+			}
514 465
 
515
-        return $content;
516
-    }
466
+			if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
467
+				foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
468
+					if (!isset($sub_content[$column])) {
469
+						$sub_content[$column] = '';
470
+					}
471
+
472
+					$attribute_sub_output = '';
473
+					foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
474
+						if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
475
+							$tpl_component = array();
476
+							$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
477
+							$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
478
+							$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
479
+							$tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : '';
480
+							$tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : '';
481
+							$attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
482
+							unset($tpl_component);
483
+						}
484
+					}
485
+
486
+					$tpl_component = array();
487
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
488
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
489
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
490
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
491
+					$ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : '';
492
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>';
493
+					$sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
494
+					$column++;
495
+					if ($column > $column_count) {
496
+						$column = 1;
497
+					}
498
+				}
499
+			}
500
+			$tpl_component = array();
501
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
502
+			for ($i = 1; $i <= $column_count; $i++) {
503
+				if (!empty($sub_content[$i])) {
504
+					$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
505
+				}
506
+
507
+			}
508
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
509
+			$tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
510
+			$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
517 511
 
518
-    /**
519
-     * Retrieve the attribute list used for sorting product into frontend listing
520
-     * @return array The attribute list to use for listing sorting
521
-     */
522
-    public static function get_sorting_criteria()
523
-    {
524
-        global $wpdb;
512
+			$content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>';
513
+		}
525 514
 
526
-        $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop')));
515
+		return $content;
516
+	}
527 517
 
528
-        $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
529
-        $results = $wpdb->get_results($query, ARRAY_A);
530
-        if (!empty($results)) {
531
-            $data = array_merge($data, $results);
532
-        }
518
+	/**
519
+	 * Retrieve the attribute list used for sorting product into frontend listing
520
+	 * @return array The attribute list to use for listing sorting
521
+	 */
522
+	public static function get_sorting_criteria()
523
+	{
524
+		global $wpdb;
533 525
 
534
-        return $data;
535
-    }
526
+		$data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop')));
527
+
528
+		$query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
529
+		$results = $wpdb->get_results($query, ARRAY_A);
530
+		if (!empty($results)) {
531
+			$data = array_merge($data, $results);
532
+		}
533
+
534
+		return $data;
535
+	}
536 536
 
537
-    public static function get_products_matching_attribute($attr_name, $attr_value)
538
-    {
539
-        global $wpdb;
537
+	public static function get_products_matching_attribute($attr_name, $attr_value)
538
+	{
539
+		global $wpdb;
540 540
 
541
-        $products = array();
542
-        $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
543
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
541
+		$products = array();
542
+		$query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
543
+		$data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
544 544
 
545
-        if (!empty($data)) {
546
-            if ($data['data_type_to_use'] == 'custom') {
547
-                // Find which table to take
548
-                if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;}
545
+		if (!empty($data)) {
546
+			if ($data['data_type_to_use'] == 'custom') {
547
+				// Find which table to take
548
+				if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;}
549 549
 
550
-                if (isset($table_name)) {
551
-                    // If the value is an id of a select, radio or checkbox
552
-                    if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
550
+				if (isset($table_name)) {
551
+					// If the value is an id of a select, radio or checkbox
552
+					if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
553 553
 
554
-                        $query = $wpdb->prepare("
554
+						$query = $wpdb->prepare("
555 555
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
556 556
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
557 557
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
558 558
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id
559 559
 							WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value
560
-                        );
561
-                        $data = $wpdb->get_results($query);
562
-                    } else {
560
+						);
561
+						$data = $wpdb->get_results($query);
562
+					} else {
563 563
 
564
-                        $query = $wpdb->prepare("
564
+						$query = $wpdb->prepare("
565 565
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
566 566
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
567 567
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
568 568
 								INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
569 569
 							WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000
570
-                        );
571
-                        $data = $wpdb->get_results($query);
572
-
573
-                    }
574
-                } else {
575
-                    return __('Incorrect shortcode', 'wpshop');
576
-                }
577
-
578
-            } elseif ($data['data_type_to_use'] == 'internal') {
579
-                /** Check the ID of manufacturer **/
580
-                $default_value = unserialize($data['default_value']);
581
-                if (!empty($default_value) && !empty($default_value['default_value'])) {
582
-                    $query = get_post($attr_value);
583
-                    $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
584
-                    if (!empty($pid)) {
585
-                        $query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid);
586
-                        $data = $wpdb->get_results($query);
587
-                    }
588
-                }
589
-            } else {
590
-                return __('Incorrect shortcode', 'wpshop');
591
-            }
592
-
593
-        } else {
594
-            return __('Incorrect shortcode', 'wpshop');
595
-        }
570
+						);
571
+						$data = $wpdb->get_results($query);
596 572
 
597
-        if (!empty($data)) {
598
-            foreach ($data as $p) {
599
-                if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
600
-                    $products[] = $p->entity_id;
601
-                }
602
-            }
603
-        }
604
-        return $products;
605
-    }
573
+					}
574
+				} else {
575
+					return __('Incorrect shortcode', 'wpshop');
576
+				}
606 577
 
607
-    /**
608
-     * Related product shortcode reader
609
-     *
610
-     * @param array $atts {
611
-     *    pid : Product idenfifier to get related element for
612
-     *    display_mode : The output mode if defined (grid || list)
613
-     * }
614
-     *
615
-     * @return string
616
-     *
617
-     */
618
-    public static function wpshop_related_products_func($atts)
619
-    {
620
-        global $wp_query;
578
+			} elseif ($data['data_type_to_use'] == 'internal') {
579
+				/** Check the ID of manufacturer **/
580
+				$default_value = unserialize($data['default_value']);
581
+				if (!empty($default_value) && !empty($default_value['default_value'])) {
582
+					$query = get_post($attr_value);
583
+					$pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
584
+					if (!empty($pid)) {
585
+						$query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid);
586
+						$data = $wpdb->get_results($query);
587
+					}
588
+				}
589
+			} else {
590
+				return __('Incorrect shortcode', 'wpshop');
591
+			}
621 592
 
622
-        $atts['product_type'] = 'related';
623
-        if (empty($atts['pid'])) {
624
-            $atts['pid'] = $wp_query->posts[0]->ID;
625
-        }
593
+		} else {
594
+			return __('Incorrect shortcode', 'wpshop');
595
+		}
626 596
 
627
-        $related_product_output = self::wpshop_products_func($atts);
597
+		if (!empty($data)) {
598
+			foreach ($data as $p) {
599
+				if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
600
+					$products[] = $p->entity_id;
601
+				}
602
+			}
603
+		}
604
+		return $products;
605
+	}
628 606
 
629
-        $output = '';
630
-        if (!empty($related_product_output)) {
631
-            ob_start();
632
-            require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
633
-            $output = ob_get_contents();
634
-            ob_end_clean();
635
-        }
607
+	/**
608
+	 * Related product shortcode reader
609
+	 *
610
+	 * @param array $atts {
611
+	 *    pid : Product idenfifier to get related element for
612
+	 *    display_mode : The output mode if defined (grid || list)
613
+	 * }
614
+	 *
615
+	 * @return string
616
+	 *
617
+	 */
618
+	public static function wpshop_related_products_func($atts)
619
+	{
620
+		global $wp_query;
636 621
 
637
-        return $output;
638
-    }
622
+		$atts['product_type'] = 'related';
623
+		if (empty($atts['pid'])) {
624
+			$atts['pid'] = $wp_query->posts[0]->ID;
625
+		}
639 626
 
640
-    /**
641
-     * Display a list of product from a shortcode
642
-     *
643
-     * @param array $atts {
644
-     *    limit : The number of element to display
645
-     *    order : The information to order list by
646
-     *    sorting : List order (ASC | DESC)
647
-     *    display : Display size (normal | mini)
648
-     *    type : Display tyep (grid | list) only work with display=normal
649
-     *    pagination : The number of element per page
650
-     * display_pagination : Display the pagination or not
651
-     * }
652
-     *
653
-     * @return string
654
-     *
655
-     **/
656
-    public static function wpshop_products_func($atts)
657
-    {
658
-        global $wpdb, $wp_query;
659
-
660
-        $string = '';
661
-        $have_results = false;
662
-        $output_results = true;
663
-        $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
664
-        $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
665
-        $cid = !empty($atts['cid']) ? $atts['cid'] : 0;
666
-        $pid = !empty($atts['pid']) ? $atts['pid'] : 0;
667
-        $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
668
-        $limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
669
-        $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
670
-        $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
671
-        $attr = '';
672
-
673
-        $sorting_criteria = self::get_sorting_criteria();
674
-
675
-        /** Get products which have att_name equal to att_value    */
676
-        if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
677
-            $attr = $atts['att_name'] . ':' . $atts['att_value'];
678
-
679
-            $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
680
-
681
-            // Foreach on the found products
682
-            if (!empty($products)) {
683
-                $pid = implode(',', $products);
684
-                if (empty($pid)) {
685
-                    $output_results = false;
686
-                }
687
-
688
-            } else {
689
-                $output_results = false;
690
-            }
627
+		$related_product_output = self::wpshop_products_func($atts);
691 628
 
692
-        }
629
+		$output = '';
630
+		if (!empty($related_product_output)) {
631
+			ob_start();
632
+			require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
633
+			$output = ob_get_contents();
634
+			ob_end_clean();
635
+		}
693 636
 
694
-        /** Get related products    */
695
-        if (!empty($atts['product_type'])) {
696
-            switch ($atts['product_type']) {
697
-                case 'related':
698
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
699
-                    $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
700
-                    $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
701
-
702
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
703
-                    if (!empty($pids) && !empty($pids[0])) {
704
-                        $pid = implode(',', $pids);
705
-                    }
706
-                    if (empty($pid) || $pid == $product_id) {
707
-                        $output_results = false;
708
-                    }
709
-
710
-                    break;
711
-            }
712
-        }
637
+		return $output;
638
+	}
639
+
640
+	/**
641
+	 * Display a list of product from a shortcode
642
+	 *
643
+	 * @param array $atts {
644
+	 *    limit : The number of element to display
645
+	 *    order : The information to order list by
646
+	 *    sorting : List order (ASC | DESC)
647
+	 *    display : Display size (normal | mini)
648
+	 *    type : Display tyep (grid | list) only work with display=normal
649
+	 *    pagination : The number of element per page
650
+	 * display_pagination : Display the pagination or not
651
+	 * }
652
+	 *
653
+	 * @return string
654
+	 *
655
+	 **/
656
+	public static function wpshop_products_func($atts)
657
+	{
658
+		global $wpdb, $wp_query;
659
+
660
+		$string = '';
661
+		$have_results = false;
662
+		$output_results = true;
663
+		$type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
664
+		$pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
665
+		$cid = !empty($atts['cid']) ? $atts['cid'] : 0;
666
+		$pid = !empty($atts['pid']) ? $atts['pid'] : 0;
667
+		$order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
668
+		$limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
669
+		$grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
670
+		$display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
671
+		$attr = '';
672
+
673
+		$sorting_criteria = self::get_sorting_criteria();
674
+
675
+		/** Get products which have att_name equal to att_value    */
676
+		if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
677
+			$attr = $atts['att_name'] . ':' . $atts['att_value'];
678
+
679
+			$products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
680
+
681
+			// Foreach on the found products
682
+			if (!empty($products)) {
683
+				$pid = implode(',', $products);
684
+				if (empty($pid)) {
685
+					$output_results = false;
686
+				}
713 687
 
714
-        /** Output all the products    */
715
-        if ($output_results) {
716
-            $data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination);
688
+			} else {
689
+				$output_results = false;
690
+			}
717 691
 
718
-            if ($data[0]) {
719
-                $have_results = true;
720
-                $string = $data[1];
721
-            }
722
-        }
692
+		}
693
+
694
+		/** Get related products    */
695
+		if (!empty($atts['product_type'])) {
696
+			switch ($atts['product_type']) {
697
+				case 'related':
698
+					$product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
699
+					$type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
700
+					$grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
701
+
702
+					$pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
703
+					if (!empty($pids) && !empty($pids[0])) {
704
+						$pid = implode(',', $pids);
705
+					}
706
+					if (empty($pid) || $pid == $product_id) {
707
+						$output_results = false;
708
+					}
709
+
710
+					break;
711
+			}
712
+		}
713
+
714
+		/** Output all the products    */
715
+		if ($output_results) {
716
+			$data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination);
717
+
718
+			if ($data[0]) {
719
+				$have_results = true;
720
+				$string = $data[1];
721
+			}
722
+		}
723
+
724
+		/** If there are result to display    */
725
+		if ($have_results) {
726
+			$sorting = '';
727
+			if (!empty($pid)) {
728
+				$product_list = explode(',', $pid);
729
+				if (count($product_list) == 1) {
730
+					$atts['sorting'] = 'no';
731
+				}
732
+			}
723 733
 
724
-        /** If there are result to display    */
725
-        if ($have_results) {
726
-            $sorting = '';
727
-            if (!empty($pid)) {
728
-                $product_list = explode(',', $pid);
729
-                if (count($product_list) == 1) {
730
-                    $atts['sorting'] = 'no';
731
-                }
732
-            }
733
-
734
-            /*
734
+			/*
735 735
              * Template parameters
736 736
              */
737
-            $template_part = 'product_listing_sorting';
738
-            $tpl_component = array();
737
+			$template_part = 'product_listing_sorting';
738
+			$tpl_component = array();
739 739
 
740
-            /*
740
+			/*
741 741
              * Build template
742 742
              */
743
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
744
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
745
-                /*    Include the old way template part    */
746
-                ob_start();
747
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
748
-                $sorting = ob_get_contents();
749
-                ob_end_clean();
750
-            } else {
751
-                /*
743
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
744
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
745
+				/*    Include the old way template part    */
746
+				ob_start();
747
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
748
+				$sorting = ob_get_contents();
749
+				ob_end_clean();
750
+			} else {
751
+				/*
752 752
                  * Display hidden field every times
753 753
                  */
754
-                $sub_template_part = 'product_listing_sorting_hidden_field';
755
-                $sub_tpl_component = array();
756
-                $sub_tpl_component['DISPLAY_TYPE'] = $type;
757
-                $sub_tpl_component['ORDER'] = $order_by_sorting;
758
-                $sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
759
-                $sub_tpl_component['CURRENT_PAGE'] = 1;
760
-                $sub_tpl_component['CATEGORY_ID'] = $cid;
761
-                $sub_tpl_component['PRODUCT_ID'] = $pid;
762
-                $sub_tpl_component['ATTR'] = $attr;
763
-                $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
764
-                unset($sub_tpl_component);
765
-
766
-                if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
767
-                    $sub_template_part = 'product_listing_sorting_criteria';
768
-                    $sub_tpl_component = array();
769
-                    $criteria = '';
770
-                    foreach ($sorting_criteria as $c):
754
+				$sub_template_part = 'product_listing_sorting_hidden_field';
755
+				$sub_tpl_component = array();
756
+				$sub_tpl_component['DISPLAY_TYPE'] = $type;
757
+				$sub_tpl_component['ORDER'] = $order_by_sorting;
758
+				$sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
759
+				$sub_tpl_component['CURRENT_PAGE'] = 1;
760
+				$sub_tpl_component['CATEGORY_ID'] = $cid;
761
+				$sub_tpl_component['PRODUCT_ID'] = $pid;
762
+				$sub_tpl_component['ATTR'] = $attr;
763
+				$tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
764
+				unset($sub_tpl_component);
765
+
766
+				if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
767
+					$sub_template_part = 'product_listing_sorting_criteria';
768
+					$sub_tpl_component = array();
769
+					$criteria = '';
770
+					foreach ($sorting_criteria as $c):
771 771
 											$selected = isset( $atts['order'] ) ? $atts['order'] : null;
772
-                      $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
773
-                    endforeach;
774
-                    $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
775
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
776
-                    unset($sub_tpl_component);
777
-                }
778
-
779
-                if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
780
-                    $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
781
-                    $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
782
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component);
783
-                } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
784
-                    $sub_template_part = 'product_listing_sorting_criteria_hidden';
785
-                    $sub_tpl_component = array();
786
-                    $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
787
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
788
-                    unset($sub_tpl_component);
789
-
790
-                    $template_part = 'product_listing_sorting_hidden';
791
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
792
-                }
793
-            }
794
-            unset($tpl_component);
795
-
796
-            if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
797
-                $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
798
-            } else {
799
-                $string = '<div class="wpshop_products_block">' . $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div></div>';
800
-            }
801
-        } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
802
-            $string = __('There is nothing to output here', 'wpshop');
803
-        }
772
+					  $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
773
+					endforeach;
774
+					$sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
775
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
776
+					unset($sub_tpl_component);
777
+				}
804 778
 
805
-        return do_shortcode($string);
806
-    }
779
+				if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
780
+					$tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
781
+					$tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
782
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component);
783
+				} else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
784
+					$sub_template_part = 'product_listing_sorting_criteria_hidden';
785
+					$sub_tpl_component = array();
786
+					$sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
787
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
788
+					unset($sub_tpl_component);
789
+
790
+					$template_part = 'product_listing_sorting_hidden';
791
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
792
+				}
793
+			}
794
+			unset($tpl_component);
807 795
 
808
-    public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true)
809
-    {
810
-        global $wpdb;
796
+			if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
797
+				$string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
798
+			} else {
799
+				$string = '<div class="wpshop_products_block">' . $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div></div>';
800
+			}
801
+		} else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
802
+			$string = __('There is nothing to output here', 'wpshop');
803
+		}
811 804
 
812
-        $string = '<span id="wpshop_loading">&nbsp;</span>';
813
-        $have_results = false;
814
-        $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
805
+		return do_shortcode($string);
806
+	}
815 807
 
816
-        /** Check if Discount are activated */
817
-        $discount_option = get_option('wpshop_catalog_product_option');
808
+	public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true)
809
+	{
810
+		global $wpdb;
818 811
 
819
-        if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
820
-            $criteria = 'wpshop_displayed_price';
821
-        }
812
+		$string = '<span id="wpshop_loading">&nbsp;</span>';
813
+		$have_results = false;
814
+		$display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
822 815
 
823
-        $query = array(
824
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
825
-            'order' => $order,
826
-            'posts_per_page' => $products_per_page,
827
-            'paged' => $page_number,
828
-            'post_status' => 'publish',
829
-        );
830
-
831
-        // If the limit is greater than zero, hide pagination and change posts_per_page var
832
-        if ($nb_of_product_limit > 0) {
833
-            $query['posts_per_page'] = $nb_of_product_limit;
834
-            unset($query['paged']);
835
-        }
836
-        if (!empty($pid)) {
837
-            if (!is_array($pid)) {
838
-                $pid = explode(',', $pid);
839
-            }
816
+		/** Check if Discount are activated */
817
+		$discount_option = get_option('wpshop_catalog_product_option');
840 818
 
841
-            $query['post__in'] = $pid;
842
-        }
843
-        if (!empty($cid)) {
844
-            $cid = explode(',', $cid);
845
-            $query['tax_query'] = array(array(
846
-                'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
847
-                'field' => 'id',
848
-                'terms' => $cid,
849
-                'operator' => 'IN',
850
-            ));
851
-        }
852
-        if ($criteria != null) {
853
-            switch ($criteria) {
854
-                case 'creator':
855
-                case 'author':
856
-                    $query['author'] = get_current_user_id();
857
-                    break;
858
-                case 'none':
859
-                case 'ID':
860
-                case 'title':
861
-                case 'date':
862
-                case 'modified':
863
-                case 'relevance':
864
-                case 'post__in':
865
-                case 'rand':
866
-                    $query['orderby'] = $criteria;
867
-                    break;
868
-                default:
869
-                    if (!empty($pid)) {
870
-                        $post_meta = get_post_meta($pid, '_' . $criteria, true);
871
-                    } else {
872
-                        $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
873
-                        $post_meta = $wpdb->get_var($check_meta);
874
-                    }
875
-                    if (!empty($post_meta)) {
876
-                        if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
877
-                            $query['orderby'] = 'meta_value_num';
878
-                        } else {
879
-                            $query['orderby'] = 'meta_value';
880
-                        }
881
-                        $query['meta_key'] = '_' . $criteria;
882
-                    }
883
-                    break;
884
-            }
885
-        } else {
886
-            $query['orderby'] = 'menu_order ID';
887
-        }
888
-        $post_per_page = $query['posts_per_page'];
889
-        $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
890
-        if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
891
-            $tmp_array = array();
892
-
893
-            if (empty($page_number) || $page_number == 1) {
894
-                for ($i = 0; $i < $query['posts_per_page']; $i++) {
895
-                    $tmp_array[] = $query['post__in'][$i];
896
-                }
897
-            } else {
898
-                $begin_number = (($page_number - 1) * $query['posts_per_page']);
899
-                for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
900
-                    if (!empty($query['post__in'][$i])) {
901
-                        $tmp_array[] = $query['post__in'][$i];
902
-                    }
903
-                }
904
-            }
905
-            unset($query['post__in']);
906
-            $query['post__in'] = $tmp_array;
907
-            $query['posts_per_page'] = -1;
908
-        }
819
+		if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
820
+			$criteria = 'wpshop_displayed_price';
821
+		}
909 822
 
910
-        $query['post_status'] = 'publish';
911
-
912
-        $custom_query = new WP_Query($query);
913
-
914
-        if ($custom_query->have_posts()) {
915
-            $have_results = true;
916
-
917
-            // ---------------- //
918
-            // Products listing //
919
-            // ---------------- //
920
-            $current_position = 1;
921
-            $product_list = '';
922
-            while ($custom_query->have_posts()): $custom_query->the_post();
923
-                $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
924
-                $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
925
-                $cat_id = empty($cats) ? 0 : $cats[0]->term_id;
926
-                $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
927
-                $current_position++;
928
-            endwhile;
929
-            $tpl_component = array();
930
-            $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
931
-            $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
932
-            $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
933
-            $tpl_component['PRODUCT_LIST'] = $product_list;
934
-            $tpl_component['CROSSED_OUT_PRICE'] = '';
935
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
936
-            $string = wpshop_display::display_template_element('product_list_container', $tpl_component);
937
-
938
-            // --------------------- //
939
-            // Pagination management //
940
-            // --------------------- //
941
-            if ( $display_pagination ) {
942
-                if ($nb_of_product_limit == 0) {
943
-
944
-                    $paginate = paginate_links(array(
945
-                        'base' => '%_%',
946
-                        'format' => '/?page_product=%#%',
947
-                        'current' => $page_number,
948
-                        'total' => $custom_query->max_num_pages,
949
-                        'type' => 'array',
950
-                        'prev_next' => false,
951
-                    ));
952
-                    if (!empty($paginate)) {
953
-                        $string .= '<ul class="pagination wps-pagination">';
954
-                        foreach ($paginate as $p) {
955
-                            $string .= '<li>' . $p . '</li>';
956
-                        }
957
-                        $string .= '</ul>';
958
-                    }
959
-                }
960
-
961
-                if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
962
-                    $paginate = paginate_links(array(
963
-                        'base' => '%_%',
964
-                        'format' => '/?page_product=%#%',
965
-                        'current' => $page_number,
966
-                        'total' => ceil(count($total_products) / $post_per_page),
967
-                        'type' => 'array',
968
-                        'prev_next' => false,
969
-                    ));
970
-                    if (!empty($paginate)) {
971
-                        $string .= '<ul class="pagination wps-pagination">';
972
-                        foreach ($paginate as $p) {
973
-                            $string .= '<li>' . $p . '</li>';
974
-                        }
975
-                        $string .= '</ul>';
976
-                    }
977
-                }
978
-            }
823
+		$query = array(
824
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
825
+			'order' => $order,
826
+			'posts_per_page' => $products_per_page,
827
+			'paged' => $page_number,
828
+			'post_status' => 'publish',
829
+		);
830
+
831
+		// If the limit is greater than zero, hide pagination and change posts_per_page var
832
+		if ($nb_of_product_limit > 0) {
833
+			$query['posts_per_page'] = $nb_of_product_limit;
834
+			unset($query['paged']);
835
+		}
836
+		if (!empty($pid)) {
837
+			if (!is_array($pid)) {
838
+				$pid = explode(',', $pid);
839
+			}
979 840
 
980
-        }
981
-        wp_reset_query(); // important
841
+			$query['post__in'] = $pid;
842
+		}
843
+		if (!empty($cid)) {
844
+			$cid = explode(',', $cid);
845
+			$query['tax_query'] = array(array(
846
+				'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
847
+				'field' => 'id',
848
+				'terms' => $cid,
849
+				'operator' => 'IN',
850
+			));
851
+		}
852
+		if ($criteria != null) {
853
+			switch ($criteria) {
854
+				case 'creator':
855
+				case 'author':
856
+					$query['author'] = get_current_user_id();
857
+					break;
858
+				case 'none':
859
+				case 'ID':
860
+				case 'title':
861
+				case 'date':
862
+				case 'modified':
863
+				case 'relevance':
864
+				case 'post__in':
865
+				case 'rand':
866
+					$query['orderby'] = $criteria;
867
+					break;
868
+				default:
869
+					if (!empty($pid)) {
870
+						$post_meta = get_post_meta($pid, '_' . $criteria, true);
871
+					} else {
872
+						$check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
873
+						$post_meta = $wpdb->get_var($check_meta);
874
+					}
875
+					if (!empty($post_meta)) {
876
+						if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
877
+							$query['orderby'] = 'meta_value_num';
878
+						} else {
879
+							$query['orderby'] = 'meta_value';
880
+						}
881
+						$query['meta_key'] = '_' . $criteria;
882
+					}
883
+					break;
884
+			}
885
+		} else {
886
+			$query['orderby'] = 'menu_order ID';
887
+		}
888
+		$post_per_page = $query['posts_per_page'];
889
+		$total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
890
+		if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
891
+			$tmp_array = array();
892
+
893
+			if (empty($page_number) || $page_number == 1) {
894
+				for ($i = 0; $i < $query['posts_per_page']; $i++) {
895
+					$tmp_array[] = $query['post__in'][$i];
896
+				}
897
+			} else {
898
+				$begin_number = (($page_number - 1) * $query['posts_per_page']);
899
+				for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
900
+					if (!empty($query['post__in'][$i])) {
901
+						$tmp_array[] = $query['post__in'][$i];
902
+					}
903
+				}
904
+			}
905
+			unset($query['post__in']);
906
+			$query['post__in'] = $tmp_array;
907
+			$query['posts_per_page'] = -1;
908
+		}
982 909
 
983
-        return array($have_results, $string);
984
-    }
910
+		$query['post_status'] = 'publish';
911
+
912
+		$custom_query = new WP_Query($query);
913
+
914
+		if ($custom_query->have_posts()) {
915
+			$have_results = true;
916
+
917
+			// ---------------- //
918
+			// Products listing //
919
+			// ---------------- //
920
+			$current_position = 1;
921
+			$product_list = '';
922
+			while ($custom_query->have_posts()): $custom_query->the_post();
923
+				$cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
924
+				$cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
925
+				$cat_id = empty($cats) ? 0 : $cats[0]->term_id;
926
+				$product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
927
+				$current_position++;
928
+			endwhile;
929
+			$tpl_component = array();
930
+			$tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
931
+			$tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
932
+			$tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
933
+			$tpl_component['PRODUCT_LIST'] = $product_list;
934
+			$tpl_component['CROSSED_OUT_PRICE'] = '';
935
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
936
+			$string = wpshop_display::display_template_element('product_list_container', $tpl_component);
937
+
938
+			// --------------------- //
939
+			// Pagination management //
940
+			// --------------------- //
941
+			if ( $display_pagination ) {
942
+				if ($nb_of_product_limit == 0) {
943
+
944
+					$paginate = paginate_links(array(
945
+						'base' => '%_%',
946
+						'format' => '/?page_product=%#%',
947
+						'current' => $page_number,
948
+						'total' => $custom_query->max_num_pages,
949
+						'type' => 'array',
950
+						'prev_next' => false,
951
+					));
952
+					if (!empty($paginate)) {
953
+						$string .= '<ul class="pagination wps-pagination">';
954
+						foreach ($paginate as $p) {
955
+							$string .= '<li>' . $p . '</li>';
956
+						}
957
+						$string .= '</ul>';
958
+					}
959
+				}
960
+
961
+				if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
962
+					$paginate = paginate_links(array(
963
+						'base' => '%_%',
964
+						'format' => '/?page_product=%#%',
965
+						'current' => $page_number,
966
+						'total' => ceil(count($total_products) / $post_per_page),
967
+						'type' => 'array',
968
+						'prev_next' => false,
969
+					));
970
+					if (!empty($paginate)) {
971
+						$string .= '<ul class="pagination wps-pagination">';
972
+						foreach ($paginate as $p) {
973
+							$string .= '<li>' . $p . '</li>';
974
+						}
975
+						$string .= '</ul>';
976
+					}
977
+				}
978
+			}
979
+
980
+		}
981
+		wp_reset_query(); // important
982
+
983
+		return array($have_results, $string);
984
+	}
985 985
 
986 986
 /**
987
-	 * Update quantity for a product
988
-	 * @param integer $product_id The product we want to update quantity for
989
-	 * @param decimal $qty The new quantity
990
-	 */
987
+ * Update quantity for a product
988
+ * @param integer $product_id The product we want to update quantity for
989
+ * @param decimal $qty The new quantity
990
+ */
991 991
 public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') {
992 992
 	global $wpdb;
993 993
 
@@ -1042,16 +1042,16 @@  discard block
 block discarded – undo
1042 1042
 		}
1043 1043
 	}
1044 1044
 
1045
-    /**
1046
-     * Retrieve an array with complete information about a given product
1047
-     * @param integer $product_id
1048
-     * @param boolean $for_cart_storage
1049
-     * @return array Information about the product defined by first parameter
1050
-     */
1051
-    public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1052
-    {
1053
-        global $wpdb;
1054
-        $query = $wpdb->prepare('
1045
+	/**
1046
+	 * Retrieve an array with complete information about a given product
1047
+	 * @param integer $product_id
1048
+	 * @param boolean $for_cart_storage
1049
+	 * @return array Information about the product defined by first parameter
1050
+	 */
1051
+	public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1052
+	{
1053
+		global $wpdb;
1054
+		$query = $wpdb->prepare('
1055 1055
 			SELECT P.*, PM.meta_value AS attribute_set_id
1056 1056
 			FROM ' . $wpdb->posts . ' AS P
1057 1057
 				INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID)
@@ -1063,398 +1063,398 @@  discard block
 block discarded – undo
1063 1063
 			LIMIT 1
1064 1064
 		', $product_id);
1065 1065
 
1066
-        $product = $wpdb->get_row($query);
1067
-
1068
-        $product_data = array();
1069
-        $product_meta = array();
1070
-
1071
-        if (!empty($product)) {
1072
-            $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1073
-            $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1074
-            $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1075
-            $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1076
-
1077
-            $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1078
-            $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1079
-            $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1080
-            $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1081
-
1082
-            $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1083
-
1084
-            $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $product->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1085
-            if (!empty($data)) {
1086
-                foreach ($data as $attribute) {
1087
-                    $data_type = 'attribute_value_' . $attribute->data_type;
1088
-                    $value = $attribute->$data_type;
1089
-                    if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1090
-                        $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1091
-                    }
1092
-
1093
-                    /** Special traitment regarding attribute_code    */
1094
-                    switch ($attribute->attribute_code) {
1095
-                        case 'product_weight':
1096
-                            $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1097
-                            if (!empty($default_weight_unity)) {
1098
-                                $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1099
-                                $unity = $wpdb->get_var($query);
1100
-                                if ($unity == 'kg') {
1101
-                                    $value *= 1000;
1102
-                                }
1103
-
1104
-                            }
1105
-                            break;
1106
-                        default:
1107
-                            $value = !empty($value) ? $value : 0;
1108
-                            break;
1109
-                    }
1110
-                    $product_data[$attribute->attribute_code] = $value;
1111
-
1112
-                    if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1113
-                        $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1114
-                        if (!empty($meta)) {
1115
-                            $product_meta[$attribute->attribute_code] = $meta;
1116
-                        }
1117
-                    }
1118
-
1119
-                    if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1120
-                        $product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1121
-                    }
1122
-                    if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1123
-                        $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1124
-                    }
1125
-                }
1126
-            } else {
1127
-
1128
-            }
1129
-
1130
-            /**    Get datas about product options    */
1131
-            if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1132
-                $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1133
-
1134
-                foreach ($variation_details as $attribute_code => $attribute_value) {
1135
-                    $variation_id = $attribute_value;
1136
-                    $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1137
-
1138
-                    $product_meta['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true));
1139
-                    $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1140
-                    switch ($attribute_definition->backend_input) {
1141
-                        case 'select':
1142
-                        case 'multiple-select':
1143
-                        case 'radio':
1144
-                        case 'checkbox':
1145
-                            $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1146
-                            break;
1147
-                    }
1148
-                    $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1149
-                    $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1150
-                }
1151
-            }
1152
-
1153
-            $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1154
-
1155
-            /** Get the display definition for the current product for checking custom display    */
1156
-            $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1157
-        }
1066
+		$product = $wpdb->get_row($query);
1067
+
1068
+		$product_data = array();
1069
+		$product_meta = array();
1070
+
1071
+		if (!empty($product)) {
1072
+			$product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1073
+			$product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1074
+			$product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1075
+			$product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1076
+
1077
+			$product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1078
+			$product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1079
+			$product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1080
+			$product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1081
+
1082
+			$product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1083
+
1084
+			$data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $product->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1085
+			if (!empty($data)) {
1086
+				foreach ($data as $attribute) {
1087
+					$data_type = 'attribute_value_' . $attribute->data_type;
1088
+					$value = $attribute->$data_type;
1089
+					if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1090
+						$value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1091
+					}
1092
+
1093
+					/** Special traitment regarding attribute_code    */
1094
+					switch ($attribute->attribute_code) {
1095
+						case 'product_weight':
1096
+							$default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1097
+							if (!empty($default_weight_unity)) {
1098
+								$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1099
+								$unity = $wpdb->get_var($query);
1100
+								if ($unity == 'kg') {
1101
+									$value *= 1000;
1102
+								}
1103
+
1104
+							}
1105
+							break;
1106
+						default:
1107
+							$value = !empty($value) ? $value : 0;
1108
+							break;
1109
+					}
1110
+					$product_data[$attribute->attribute_code] = $value;
1111
+
1112
+					if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1113
+						$meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1114
+						if (!empty($meta)) {
1115
+							$product_meta[$attribute->attribute_code] = $meta;
1116
+						}
1117
+					}
1118
+
1119
+					if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1120
+						$product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1121
+					}
1122
+					if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1123
+						$product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1124
+					}
1125
+				}
1126
+			} else {
1158 1127
 
1159
-        return $product_data;
1160
-    }
1128
+			}
1161 1129
 
1162
-    /**
1163
-     * Add a product into the db. This function is used for the EDI
1164
-     * @param $name Name of the product
1165
-     * @param $description Description of the product
1166
-     * @param $attrs List of the attributes and values of the product
1167
-     * @return boolean
1168
-     */
1169
-    public function addProduct($name, $description, $attrs = array())
1170
-    {
1171
-        $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1172
-        return $new_product[0];
1173
-    }
1130
+			/**    Get datas about product options    */
1131
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1132
+				$variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1133
+
1134
+				foreach ($variation_details as $attribute_code => $attribute_value) {
1135
+					$variation_id = $attribute_value;
1136
+					$attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1137
+
1138
+					$product_meta['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true));
1139
+					$product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1140
+					switch ($attribute_definition->backend_input) {
1141
+						case 'select':
1142
+						case 'multiple-select':
1143
+						case 'radio':
1144
+						case 'checkbox':
1145
+							$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1146
+							break;
1147
+					}
1148
+					$product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1149
+					$product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1150
+				}
1151
+			}
1174 1152
 
1175
-    /**
1176
-     * Retrieve a product listing
1177
-     * @param boolean $formated If the output have to be formated or not
1178
-     * @param string $product_search Optionnal Define a search term for request
1179
-     * @return object|string If $formated is set to true will display an html output with all product. Else return a wordpress database object with the product list
1180
-     */
1181
-    public static function product_list($formated = false, $product_search = null)
1182
-    {
1183
-        global $wpdb;
1184
-
1185
-        $query_extra_params = $query_extra_params_value = '';
1186
-        if (!empty($product_search)) {
1187
-            $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1188
-            if (is_array($product_search)) {
1189
-                $query_extra_params = " AND ID IN (%s)";
1190
-                $query_extra_params_value = implode(",", $product_search);
1191
-            }
1192
-        }
1153
+			$product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1154
+
1155
+			/** Get the display definition for the current product for checking custom display    */
1156
+			$product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1157
+		}
1158
+
1159
+		return $product_data;
1160
+	}
1161
+
1162
+	/**
1163
+	 * Add a product into the db. This function is used for the EDI
1164
+	 * @param $name Name of the product
1165
+	 * @param $description Description of the product
1166
+	 * @param $attrs List of the attributes and values of the product
1167
+	 * @return boolean
1168
+	 */
1169
+	public function addProduct($name, $description, $attrs = array())
1170
+	{
1171
+		$new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1172
+		return $new_product[0];
1173
+	}
1174
+
1175
+	/**
1176
+	 * Retrieve a product listing
1177
+	 * @param boolean $formated If the output have to be formated or not
1178
+	 * @param string $product_search Optionnal Define a search term for request
1179
+	 * @return object|string If $formated is set to true will display an html output with all product. Else return a wordpress database object with the product list
1180
+	 */
1181
+	public static function product_list($formated = false, $product_search = null)
1182
+	{
1183
+		global $wpdb;
1184
+
1185
+		$query_extra_params = $query_extra_params_value = '';
1186
+		if (!empty($product_search)) {
1187
+			$query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1188
+			if (is_array($product_search)) {
1189
+				$query_extra_params = " AND ID IN (%s)";
1190
+				$query_extra_params_value = implode(",", $product_search);
1191
+			}
1192
+		}
1193 1193
 
1194
-        $query = $wpdb->prepare("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s" . $query_extra_params, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish', $query_extra_params_value);
1195
-        $data = $wpdb->get_results($query);
1194
+		$query = $wpdb->prepare("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s" . $query_extra_params, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish', $query_extra_params_value);
1195
+		$data = $wpdb->get_results($query);
1196 1196
 
1197
-        /*
1197
+		/*
1198 1198
          * Make some arangement on output if parameter is given
1199 1199
          */
1200
-        if ($formated) {
1201
-            $product_string = '';
1202
-            foreach ($data as $d) {
1203
-                $product_string .= '
1200
+		if ($formated) {
1201
+			$product_string = '';
1202
+			foreach ($data as $d) {
1203
+				$product_string .= '
1204 1204
 					<li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" >
1205 1205
 						<input type="checkbox" class="wpshop_shortcode_element wpshop_shortcode_element_product" value="' . $d->ID . '" id="' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '-' . $d->ID . '" name="products[]" /><label for="' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '-' . $d->ID . '" > ' . $d->post_title . '</label>
1206 1206
 					</li>';
1207
-            }
1208
-        }
1207
+			}
1208
+		}
1209 1209
 
1210
-        return $formated ? $product_string : $data;
1211
-    }
1210
+		return $formated ? $product_string : $data;
1211
+	}
1212 1212
 
1213
-    /**
1214
-     * Enregistrement des données pour le produit
1215
-     */
1216
-    public function save_product_custom_informations($post_id, $data_to_save = array())
1217
-    {
1218
-        global $wpdb;
1219
-
1220
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1221
-        // Apply a filter to extra actions
1222
-        $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1223
-
1224
-        if (!empty($data_to_save['post_ID']) && ((get_post_type($data_to_save['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || (get_post_type($data_to_save['post_ID']) == "free_product"))) {
1225
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1226
-                /*    Fill the product reference automatically if nothing is sent    */
1227
-                if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1228
-                    $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1229
-                    $last_ref = $wpdb->get_var($query);
1230
-                    $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1231
-                } else {
1232
-                    /* Check if the product reference existing in the database */
1233
-                    $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1234
-                    $query = $wpdb->prepare(
1235
-                        "SELECT value_id
1213
+	/**
1214
+	 * Enregistrement des données pour le produit
1215
+	 */
1216
+	public function save_product_custom_informations($post_id, $data_to_save = array())
1217
+	{
1218
+		global $wpdb;
1219
+
1220
+		$data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1221
+		// Apply a filter to extra actions
1222
+		$data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1223
+
1224
+		if (!empty($data_to_save['post_ID']) && ((get_post_type($data_to_save['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || (get_post_type($data_to_save['post_ID']) == "free_product"))) {
1225
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1226
+				/*    Fill the product reference automatically if nothing is sent    */
1227
+				if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1228
+					$query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1229
+					$last_ref = $wpdb->get_var($query);
1230
+					$data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1231
+				} else {
1232
+					/* Check if the product reference existing in the database */
1233
+					$ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1234
+					$query = $wpdb->prepare(
1235
+						"SELECT value_id
1236 1236
 						FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
1237 1237
 							INNER JOIN {$wpdb->posts} ON ( ID = entity_id )
1238 1238
 						WHERE value = %s
1239 1239
 							AND entity_id != %d
1240 1240
 							AND entity_type_id = %d"
1241
-                        , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1242
-                    $existing_reference = $wpdb->get_var($query);
1243
-
1244
-                    /* If this product reference exist -> Create a new product reference */
1245
-                    if ($wpdb->num_rows > 0) {
1246
-                        $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1247
-                        $last_ref = $wpdb->get_var($query);
1248
-                        $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1249
-                    }
1250
-                }
1251
-
1252
-                /*    Save the attributes values into wpshop eav database    */
1253
-                $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1254
-                $lang = WPSHOP_CURRENT_LOCALE;
1255
-                if (!empty($data_to_save['icl_post_language'])) {
1256
-                    $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1257
-                    $lang = $wpdb->get_var($query);
1258
-                }
1259
-                wpshop_attributes::saveAttributeForEntity($data_to_save[wpshop_products::currentPageCode . '_attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $data_to_save['post_ID'], $lang, $update_from);
1260
-
1261
-                /*    Update product price looking for shop parameters    */
1262
-                wpshop_products::calculate_price($data_to_save['post_ID']);
1263
-
1264
-                /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1265
-                $productMetaDatas = array();
1266
-                foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1267
-                    foreach ($attributeValues as $attributeCode => $attributeValue) {
1268
-                        if ($attributeCode == 'product_attribute_set_id') {
1269
-                            /*    Update the attribute set id for the current product    */
1270
-                            update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1271
-                        }
1272
-                        if ($attributeType == 'decimal') {
1273
-                            $attributeValue = str_replace(',', '.', $attributeValue);
1274
-                        }
1275
-                        if (($attributeType == 'integer') && !is_array($attributeValue)) {
1276
-                            $attributeValue = (int) $attributeValue;
1277
-                        }
1278
-                        $productMetaDatas[$attributeCode] = $attributeValue;
1279
-                    }
1280
-                }
1281
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1282
-            }
1283
-
1284
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1285
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1286
-            } else if ($data_to_save['action'] != 'autosave') {
1287
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1288
-            }
1289
-
1290
-            $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1291
-            if (empty($product['product_id'])) {
1292
-                $product['product_id'] = $data_to_save['post_ID'];
1293
-            }
1294
-            $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1295
-            update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1296
-
1297
-            /**    Save product variation    */
1298
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1299
-                foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1300
-
1301
-                    foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1302
-                        $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1303
-                        if (!empty($variation_definition) && !empty($variation_definition['attribute']) && is_object($price_attr_def) && !empty($variation_definition['attribute'][$price_attr_def->data_type]) && is_array($variation_definition['attribute'][$price_attr_def->data_type]) && !array_key_exists($price_attribute_code, $variation_definition['attribute'][$price_attr_def->data_type])) {
1304
-                            $variation_definition['attribute'][$price_attr_def->data_type][$price_attribute_code] = !empty($data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code]) ? $data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code] : 0;
1305
-                        }
1306
-                    }
1307
-                    $lang = WPSHOP_CURRENT_LOCALE;
1308
-                    if (!empty($data_to_save['icl_post_language'])) {
1309
-                        $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1310
-                        $lang = $wpdb->get_var($query);
1311
-                    }
1312
-                    wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1313
-
1314
-                    /**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1315
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1316
-                    if (!empty($variation_metadata)) {
1317
-                        $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1318
-                        if (!empty($attributes_list)) {
1319
-                            foreach ($attributes_list as $attribute) {
1320
-                                $value_key = 'attribute_value_' . $attribute->data_type;
1321
-                                $attributeValue = $attribute->$value_key;
1322
-                                if ($attribute->data_type == 'decimal') {
1323
-                                    $attributeValue = str_replace(',', '.', $attribute->$value_key);
1324
-                                }
1325
-                                if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1326
-                                    $attributeValue = (int) $attribute->$value_key;
1327
-                                }
1328
-                                $variation_metadata[$attribute->code] = $attribute->$value_key;
1329
-                            }
1330
-                        }
1331
-                    }
1332
-
1333
-                    foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1334
-                        foreach ($attributeValues as $attributeCode => $attributeValue) {
1335
-                            if ($attributeType == 'decimal') {
1336
-                                $attributeValue = str_replace(',', '.', $attributeValue);
1337
-                            }
1338
-                            if (($attributeType == 'integer') && !is_array($attributeValue)) {
1339
-                                $attributeValue = (int) $attributeValue;
1340
-                            }
1341
-                            $variation_metadata[$attributeCode] = $attributeValue;
1342
-                        }
1343
-                    }
1344
-                    update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1345
-
1346
-                    /** Save attached picture id **/
1347
-                    $attached_picture_id = (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id'])) ? intval($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id']) : '';
1348
-                    $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1349
-
1350
-                    /*    Update product price looking for shop parameters    */
1351
-                    wpshop_products::calculate_price($variation_id);
1352
-                }
1353
-            }
1354
-
1355
-            /*    Update the related products list*/
1356
-            if (!empty($data_to_save['related_products_list'])) {
1357
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1358
-            } else if ($data_to_save['action'] != 'autosave') {
1359
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1360
-            }
1361
-            /*    Update the provider list*/
1362
-            if (!empty($data_to_save['provider_list'])) {
1363
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1364
-            } else if ($data_to_save['action'] != 'autosave') {
1365
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1366
-            }
1367
-
1368
-            /*    Update product options    */
1369
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1370
-                update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1371
-            } else if ($data_to_save['action'] != 'autosave') {
1372
-                delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1373
-            }
1374
-
1375
-            /** Add flag on variations to check which type of variation **/
1376
-            $check_product_have_variations = self::get_variation($post_id);
1377
-            if (!empty($check_product_have_variations)) {
1378
-                $variation_flag = self::check_variation_type($post_id);
1379
-                $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1380
-                $variation_defining['variation_type'] = $variation_flag;
1381
-                update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1382
-            }
1383
-            add_post_meta($post_id, '_wpshop_variation_defining', array('follow_general_config' => true, 'options' => array('priority' => array('combined'), 'price_behaviour' => array('replacement'), 'price_display' => (!empty($catalog_product_option) && !empty($catalog_product_option['price_display'])) ? $catalog_product_option['price_display'] : array('text_from' => 'on', 'lower_price' => 'on'))), true);
1384
-        }
1241
+						, $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1242
+					$existing_reference = $wpdb->get_var($query);
1243
+
1244
+					/* If this product reference exist -> Create a new product reference */
1245
+					if ($wpdb->num_rows > 0) {
1246
+						$query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1247
+						$last_ref = $wpdb->get_var($query);
1248
+						$data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1249
+					}
1250
+				}
1385 1251
 
1386
-        flush_rewrite_rules();
1387
-    }
1252
+				/*    Save the attributes values into wpshop eav database    */
1253
+				$update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1254
+				$lang = WPSHOP_CURRENT_LOCALE;
1255
+				if (!empty($data_to_save['icl_post_language'])) {
1256
+					$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1257
+					$lang = $wpdb->get_var($query);
1258
+				}
1259
+				wpshop_attributes::saveAttributeForEntity($data_to_save[wpshop_products::currentPageCode . '_attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $data_to_save['post_ID'], $lang, $update_from);
1260
+
1261
+				/*    Update product price looking for shop parameters    */
1262
+				wpshop_products::calculate_price($data_to_save['post_ID']);
1263
+
1264
+				/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1265
+				$productMetaDatas = array();
1266
+				foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1267
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
1268
+						if ($attributeCode == 'product_attribute_set_id') {
1269
+							/*    Update the attribute set id for the current product    */
1270
+							update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1271
+						}
1272
+						if ($attributeType == 'decimal') {
1273
+							$attributeValue = str_replace(',', '.', $attributeValue);
1274
+						}
1275
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1276
+							$attributeValue = (int) $attributeValue;
1277
+						}
1278
+						$productMetaDatas[$attributeCode] = $attributeValue;
1279
+					}
1280
+				}
1281
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1282
+			}
1388 1283
 
1389
-    /**
1390
-     * Return the variation type
1391
-     * @param integer $post_id
1392
-     * @return string
1393
-     */
1394
-    public function check_variation_type($post_id)
1395
-    {
1396
-        $variation_type = 'single';
1397
-        if (!empty($variation_type)) {
1398
-            $variations = self::get_variation($post_id);
1399
-            if (!empty($variations)) {
1400
-                foreach ($variations as $variation_id => $variation_data) {
1401
-                    if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1402
-                        return 'single';
1403
-                    } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1404
-                        $variation_type = 'combined';
1405
-                    }
1406
-                }
1407
-            }
1408
-        }
1409
-        return $variation_type;
1410
-    }
1284
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1285
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1286
+			} else if ($data_to_save['action'] != 'autosave') {
1287
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1288
+			}
1411 1289
 
1412
-    /**
1413
-     * Allows to define a specific permalink for each product by checking the parent categories
1414
-     *
1415
-     * @param mixed $permalink The actual permalink of the element
1416
-     * @param object $post The post we want to set the permalink for
1417
-     * @param void
1418
-     *
1419
-     * @return mixed The new permalink for the current element
1420
-     */
1421
-    public static function set_product_permalink($permalink, $post, $unknown)
1422
-    {
1423
-        $options = get_option('wpshop_catalog_product_option', array());
1424
-
1425
-        if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1426
-            if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1427
-                return $permalink;
1428
-            } else {
1429
-                $options_cats = get_option('wpshop_catalog_categories_option', array());
1430
-                $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1431
-                if (empty($product_categories)) {
1432
-                    $product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1433
-                } else {
1434
-                    $product_category_slug = $product_categories[0]->slug;
1435
-                }
1436
-                $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1437
-            }
1438
-        }
1290
+			$product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1291
+			if (empty($product['product_id'])) {
1292
+				$product['product_id'] = $data_to_save['post_ID'];
1293
+			}
1294
+			$price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1295
+			update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1296
+
1297
+			/**    Save product variation    */
1298
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1299
+				foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1300
+
1301
+					foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1302
+						$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1303
+						if (!empty($variation_definition) && !empty($variation_definition['attribute']) && is_object($price_attr_def) && !empty($variation_definition['attribute'][$price_attr_def->data_type]) && is_array($variation_definition['attribute'][$price_attr_def->data_type]) && !array_key_exists($price_attribute_code, $variation_definition['attribute'][$price_attr_def->data_type])) {
1304
+							$variation_definition['attribute'][$price_attr_def->data_type][$price_attribute_code] = !empty($data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code]) ? $data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code] : 0;
1305
+						}
1306
+					}
1307
+					$lang = WPSHOP_CURRENT_LOCALE;
1308
+					if (!empty($data_to_save['icl_post_language'])) {
1309
+						$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1310
+						$lang = $wpdb->get_var($query);
1311
+					}
1312
+					wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1313
+
1314
+					/**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1315
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1316
+					if (!empty($variation_metadata)) {
1317
+						$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1318
+						if (!empty($attributes_list)) {
1319
+							foreach ($attributes_list as $attribute) {
1320
+								$value_key = 'attribute_value_' . $attribute->data_type;
1321
+								$attributeValue = $attribute->$value_key;
1322
+								if ($attribute->data_type == 'decimal') {
1323
+									$attributeValue = str_replace(',', '.', $attribute->$value_key);
1324
+								}
1325
+								if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1326
+									$attributeValue = (int) $attribute->$value_key;
1327
+								}
1328
+								$variation_metadata[$attribute->code] = $attribute->$value_key;
1329
+							}
1330
+						}
1331
+					}
1332
+
1333
+					foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1334
+						foreach ($attributeValues as $attributeCode => $attributeValue) {
1335
+							if ($attributeType == 'decimal') {
1336
+								$attributeValue = str_replace(',', '.', $attributeValue);
1337
+							}
1338
+							if (($attributeType == 'integer') && !is_array($attributeValue)) {
1339
+								$attributeValue = (int) $attributeValue;
1340
+							}
1341
+							$variation_metadata[$attributeCode] = $attributeValue;
1342
+						}
1343
+					}
1344
+					update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1345
+
1346
+					/** Save attached picture id **/
1347
+					$attached_picture_id = (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id'])) ? intval($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id']) : '';
1348
+					$selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1349
+
1350
+					/*    Update product price looking for shop parameters    */
1351
+					wpshop_products::calculate_price($variation_id);
1352
+				}
1353
+			}
1354
+
1355
+			/*    Update the related products list*/
1356
+			if (!empty($data_to_save['related_products_list'])) {
1357
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1358
+			} else if ($data_to_save['action'] != 'autosave') {
1359
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1360
+			}
1361
+			/*    Update the provider list*/
1362
+			if (!empty($data_to_save['provider_list'])) {
1363
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1364
+			} else if ($data_to_save['action'] != 'autosave') {
1365
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1366
+			}
1367
+
1368
+			/*    Update product options    */
1369
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1370
+				update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1371
+			} else if ($data_to_save['action'] != 'autosave') {
1372
+				delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1373
+			}
1374
+
1375
+			/** Add flag on variations to check which type of variation **/
1376
+			$check_product_have_variations = self::get_variation($post_id);
1377
+			if (!empty($check_product_have_variations)) {
1378
+				$variation_flag = self::check_variation_type($post_id);
1379
+				$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1380
+				$variation_defining['variation_type'] = $variation_flag;
1381
+				update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1382
+			}
1383
+			add_post_meta($post_id, '_wpshop_variation_defining', array('follow_general_config' => true, 'options' => array('priority' => array('combined'), 'price_behaviour' => array('replacement'), 'price_display' => (!empty($catalog_product_option) && !empty($catalog_product_option['price_display'])) ? $catalog_product_option['price_display'] : array('text_from' => 'on', 'lower_price' => 'on'))), true);
1384
+		}
1385
+
1386
+		flush_rewrite_rules();
1387
+	}
1388
+
1389
+	/**
1390
+	 * Return the variation type
1391
+	 * @param integer $post_id
1392
+	 * @return string
1393
+	 */
1394
+	public function check_variation_type($post_id)
1395
+	{
1396
+		$variation_type = 'single';
1397
+		if (!empty($variation_type)) {
1398
+			$variations = self::get_variation($post_id);
1399
+			if (!empty($variations)) {
1400
+				foreach ($variations as $variation_id => $variation_data) {
1401
+					if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1402
+						return 'single';
1403
+					} elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1404
+						$variation_type = 'combined';
1405
+					}
1406
+				}
1407
+			}
1408
+		}
1409
+		return $variation_type;
1410
+	}
1411
+
1412
+	/**
1413
+	 * Allows to define a specific permalink for each product by checking the parent categories
1414
+	 *
1415
+	 * @param mixed $permalink The actual permalink of the element
1416
+	 * @param object $post The post we want to set the permalink for
1417
+	 * @param void
1418
+	 *
1419
+	 * @return mixed The new permalink for the current element
1420
+	 */
1421
+	public static function set_product_permalink($permalink, $post, $unknown)
1422
+	{
1423
+		$options = get_option('wpshop_catalog_product_option', array());
1424
+
1425
+		if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1426
+			if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1427
+				return $permalink;
1428
+			} else {
1429
+				$options_cats = get_option('wpshop_catalog_categories_option', array());
1430
+				$product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1431
+				if (empty($product_categories)) {
1432
+					$product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1433
+				} else {
1434
+					$product_category_slug = $product_categories[0]->slug;
1435
+				}
1436
+				$permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1437
+			}
1438
+		}
1439 1439
 
1440
-        return $permalink;
1440
+		return $permalink;
1441 1441
 
1442
-        //echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1442
+		//echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1443 1443
 
1444
-        //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1444
+		//wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1445 1445
 
1446
-        /*if(false) {
1446
+		/*if(false) {
1447 1447
         global $wp_query;
1448 1448
         $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1449 1449
 
1450 1450
         if(count($product_categories) == 0){            /*    Product has only one category we get the only available slug    */
1451
-        /*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1451
+		/*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1452 1452
         }
1453 1453
         elseif(count($product_categories) == 1){    /*    Product has only one category we get the only available slug    */
1454
-        /*        $product_category_slug = $product_categories[0]->slug;
1454
+		/*        $product_category_slug = $product_categories[0]->slug;
1455 1455
         }
1456 1456
         else{                                                                            /*    Product has several categories choose the slug of the we want    */
1457
-        /*        $product_category_slugs = array();
1457
+		/*        $product_category_slugs = array();
1458 1458
     foreach($product_categories as $product_category){
1459 1459
     $product_category_slugs[] = $product_category->slug;
1460 1460
     }
@@ -1464,457 +1464,457 @@  discard block
 block discarded – undo
1464 1464
     $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1465 1465
     return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID );
1466 1466
     }*/
1467
-    }
1467
+	}
1468 1468
 
1469
-    public static function set_product_request_by_name($query)
1470
-    {
1471
-        $options = get_option('wpshop_catalog_product_option', array());
1469
+	public static function set_product_request_by_name($query)
1470
+	{
1471
+		$options = get_option('wpshop_catalog_product_option', array());
1472 1472
 
1473
-        if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1474
-        //    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1475
-    }
1473
+		if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1474
+		//    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1475
+	}
1476 1476
 
1477
-    /**
1478
-     *    Define output for product
1479
-     *
1480
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1481
-     *    @param integer $product_id The product identifier we want to get and output attribute for
1482
-     *
1483
-     *    @return mixed $content The content to add or to modify the product output in frontend
1484
-     */
1485
-    public static function product_complete_sheet_output($initialContent, $product_id)
1486
-    {
1487
-        $content = $attributeContentOutput = '';
1488
-        $wps_product_ctr = new wps_product_ctr();
1489
-        /** Log number of view for the current product    */
1490
-        $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1491
-        $product_view_number++;
1492
-        update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1493
-
1494
-        /** Get product definition    */
1495
-
1496
-        $product = self::get_product_data($product_id);
1497
-        wp_cache_set('wpshop_product_data_' . $product_id, $product);
1498
-
1499
-        /** Get the product thumbnail    */
1500
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1501
-        if (has_post_thumbnail($product_id)) {
1502
-            $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1503
-            $tpl_component = array();
1504
-            $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1505
-            $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1506
-            $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1507
-            $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1508
-            if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1509
-                foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1510
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1511
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1512
-                }
1513
-            }
1514
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = (!empty($tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'])) ? $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1515
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1516
-            unset($tpl_component);
1517
-        }
1477
+	/**
1478
+	 *    Define output for product
1479
+	 *
1480
+	 *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1481
+	 *    @param integer $product_id The product identifier we want to get and output attribute for
1482
+	 *
1483
+	 *    @return mixed $content The content to add or to modify the product output in frontend
1484
+	 */
1485
+	public static function product_complete_sheet_output($initialContent, $product_id)
1486
+	{
1487
+		$content = $attributeContentOutput = '';
1488
+		$wps_product_ctr = new wps_product_ctr();
1489
+		/** Log number of view for the current product    */
1490
+		$product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1491
+		$product_view_number++;
1492
+		update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1493
+
1494
+		/** Get product definition    */
1495
+
1496
+		$product = self::get_product_data($product_id);
1497
+		wp_cache_set('wpshop_product_data_' . $product_id, $product);
1498
+
1499
+		/** Get the product thumbnail    */
1500
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1501
+		if (has_post_thumbnail($product_id)) {
1502
+			$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1503
+			$tpl_component = array();
1504
+			$tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1505
+			$tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1506
+			$tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1507
+			$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1508
+			if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1509
+				foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1510
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1511
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1512
+				}
1513
+			}
1514
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = (!empty($tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'])) ? $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1515
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1516
+			unset($tpl_component);
1517
+		}
1518 1518
 
1519
-        $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1520
-
1521
-        /**    Retrieve product attributes for output    */
1522
-        $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1523
-
1524
-        /** Retrieve product price */
1525
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1526
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1527
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1528
-        $productPrice = '';
1529
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1530
-        $check_product_price = wpshop_prices::check_product_price($product);
1531
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1532
-        if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1533
-            $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1534
-        }
1519
+		$product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1520
+
1521
+		/**    Retrieve product attributes for output    */
1522
+		$attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1523
+
1524
+		/** Retrieve product price */
1525
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1526
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1527
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1528
+		$productPrice = '';
1529
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1530
+		$check_product_price = wpshop_prices::check_product_price($product);
1531
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1532
+		if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1533
+			$productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1534
+		}
1535 1535
 
1536
-        /** Check if there is at less 1 product in stock    */
1537
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1538
-        $productStock = ($productStock === true) ? 1 : null;
1536
+		/** Check if there is at less 1 product in stock    */
1537
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1538
+		$productStock = ($productStock === true) ? 1 : null;
1539 1539
 
1540
-        /** if !product stock check product have variation with stock **/
1540
+		/** if !product stock check product have variation with stock **/
1541 1541
 //         if ( empty($productStock) ) {
1542
-        $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1543
-        if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1544
-            $variations = wpshop_products::get_variation($product_id);
1545
-            if (!empty($variations)) {
1546
-                foreach ($variations as $variation) {
1547
-                    if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1548
-                        $productStock = 1;
1549
-                    }
1550
-                }
1551
-            }
1552
-        }
1542
+		$product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1543
+		if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1544
+			$variations = wpshop_products::get_variation($product_id);
1545
+			if (!empty($variations)) {
1546
+				foreach ($variations as $variation) {
1547
+					if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1548
+						$productStock = 1;
1549
+					}
1550
+				}
1551
+			}
1552
+		}
1553 1553
 //         }
1554 1554
 
1555
-        /** Define "Add to cart" button     */
1556
-        $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'complete_sheet');
1557
-        $display_price_state_when_price_is_empty = true;
1558
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1559
-            $display_price_state_when_price_is_empty = false;
1560
-        } else if (!empty($productPrice)) {
1561
-            $display_price_state_when_price_is_empty = true;
1562
-        }
1563
-        $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'complete') : '';
1564
-        $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1565
-
1566
-        /** Define "Ask a quotation" button    */
1567
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1568
-
1569
-        /** Template parameters    */
1570
-        $template_part = 'product_complete_tpl';
1571
-        $tpl_component = array();
1572
-
1573
-        $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1574
-        $tpl_component['PRODUCT_ID'] = $product_id;
1575
-        $tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1576
-        $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1577
-        $tpl_component['PRODUCT_GALERY_PICS'] = '';
1578
-        $tpl_component['PRODUCT_PRICE'] = $productPrice;
1579
-        $modules_option = get_option('wpshop_modules');
1580
-        $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1581
-        if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1582
-            $wps_marketing_tools = new wps_marketing_tools_ctr();
1583
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1584
-        }
1555
+		/** Define "Add to cart" button     */
1556
+		$add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'complete_sheet');
1557
+		$display_price_state_when_price_is_empty = true;
1558
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1559
+			$display_price_state_when_price_is_empty = false;
1560
+		} else if (!empty($productPrice)) {
1561
+			$display_price_state_when_price_is_empty = true;
1562
+		}
1563
+		$add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'complete') : '';
1564
+		$product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1565
+
1566
+		/** Define "Ask a quotation" button    */
1567
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1568
+
1569
+		/** Template parameters    */
1570
+		$template_part = 'product_complete_tpl';
1571
+		$tpl_component = array();
1572
+
1573
+		$tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1574
+		$tpl_component['PRODUCT_ID'] = $product_id;
1575
+		$tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1576
+		$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1577
+		$tpl_component['PRODUCT_GALERY_PICS'] = '';
1578
+		$tpl_component['PRODUCT_PRICE'] = $productPrice;
1579
+		$modules_option = get_option('wpshop_modules');
1580
+		$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1581
+		if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1582
+			$wps_marketing_tools = new wps_marketing_tools_ctr();
1583
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1584
+		}
1585 1585
 
1586
-        /** Gallery **/
1587
-        $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1588
-
1589
-        $product_new_def = self::display_product_special_state('declare_new', 'complete', (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1590
-
1591
-        $product_new = $product_new_def['output'];
1592
-        $product_class = $product_new_def['class'];
1593
-
1594
-        $product_featured_def = self::display_product_special_state('highlight_product', 'complete', (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1595
-        $product_featured = $product_featured_def['output'];
1596
-        $product_class .= $product_featured_def['class'];
1597
-
1598
-        $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1599
-        $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1600
-        $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1601
-
1602
-        $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1603
-        $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1604
-        $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1605
-        $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1606
-        $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1607
-        $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1608
-        $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1609
-        $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1610
-
1611
-        /** Build template    */
1612
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1613
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1614
-            /*    Include the old way template part    */
1615
-            ob_start();
1616
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
1617
-            $content = ob_get_contents();
1618
-            ob_end_clean();
1619
-        } else {
1620
-            $content = wpshop_display::display_template_element($template_part, $tpl_component);
1621
-        }
1622
-        unset($tpl_component);
1623
-        return $content;
1624
-    }
1586
+		/** Gallery **/
1587
+		$tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1588
+
1589
+		$product_new_def = self::display_product_special_state('declare_new', 'complete', (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1590
+
1591
+		$product_new = $product_new_def['output'];
1592
+		$product_class = $product_new_def['class'];
1593
+
1594
+		$product_featured_def = self::display_product_special_state('highlight_product', 'complete', (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1595
+		$product_featured = $product_featured_def['output'];
1596
+		$product_class .= $product_featured_def['class'];
1597
+
1598
+		$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1599
+		$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1600
+		$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1601
+
1602
+		$tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1603
+		$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1604
+		$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1605
+		$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1606
+		$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1607
+		$tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1608
+		$tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1609
+		$tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1610
+
1611
+		/** Build template    */
1612
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1613
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1614
+			/*    Include the old way template part    */
1615
+			ob_start();
1616
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
1617
+			$content = ob_get_contents();
1618
+			ob_end_clean();
1619
+		} else {
1620
+			$content = wpshop_display::display_template_element($template_part, $tpl_component);
1621
+		}
1622
+		unset($tpl_component);
1623
+		return $content;
1624
+	}
1625 1625
 
1626
-    public static function product_mini_output($product_id, $category_id, $output_type = 'list', $current_item_position = 1, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE)
1627
-    {
1628
-        $content = '';
1629
-        $product_information = $product_class = '';
1626
+	public static function product_mini_output($product_id, $category_id, $output_type = 'list', $current_item_position = 1, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE)
1627
+	{
1628
+		$content = '';
1629
+		$product_information = $product_class = '';
1630 1630
 
1631
-        /** Get the product thumbnail    */
1632
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1633
-        if (has_post_thumbnail($product_id)) {
1634
-            $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1635
-        }
1631
+		/** Get the product thumbnail    */
1632
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1633
+		if (has_post_thumbnail($product_id)) {
1634
+			$productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1635
+		}
1636 1636
 
1637
-        $product = self::get_product_data($product_id);
1637
+		$product = self::get_product_data($product_id);
1638 1638
 
1639
-        /**    Get the product information for output    */
1640
-        if (!empty($product)) {
1639
+		/**    Get the product information for output    */
1640
+		if (!empty($product)) {
1641 1641
 
1642
-            $product_title = $product['post_title'];
1643
-            $product_name = $product['post_name'];
1644
-            $product_link = get_permalink($product_id);
1645
-            $product_more_informations = $product['product_content'];
1646
-            $product_excerpt = $product['product_excerpt'];
1642
+			$product_title = $product['post_title'];
1643
+			$product_name = $product['post_name'];
1644
+			$product_link = get_permalink($product_id);
1645
+			$product_more_informations = $product['product_content'];
1646
+			$product_excerpt = $product['product_excerpt'];
1647 1647
 
1648
-            if (strpos($product['product_content'], '<!--more-->')) {
1649
-                $post_content = explode('<!--more-->', $product['product_content']);
1650
-                $product_more_informations = $post_content[0];
1651
-            }
1648
+			if (strpos($product['product_content'], '<!--more-->')) {
1649
+				$post_content = explode('<!--more-->', $product['product_content']);
1650
+				$product_more_informations = $post_content[0];
1651
+			}
1652 1652
 
1653
-        } else {
1654
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1655
-            $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1656
-            $product_link = '';
1657
-            $product_more_informations = '';
1658
-            $product_excerpt = '';
1659
-        }
1653
+		} else {
1654
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1655
+			$product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1656
+			$product_link = '';
1657
+			$product_more_informations = '';
1658
+			$product_excerpt = '';
1659
+		}
1660 1660
 
1661
-        /** Retrieve product price    */
1662
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1663
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1664
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1665
-        $productPrice = '';
1666
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1667
-        $check_product_price = wpshop_prices::check_product_price($product);
1668
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1669
-        if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1670
-            $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1671
-
1672
-            if (!empty($product_price_infos)) {
1673
-                $tpl_component_price = array();
1674
-                /** Price piloting **/
1661
+		/** Retrieve product price    */
1662
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1663
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1664
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1665
+		$productPrice = '';
1666
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1667
+		$check_product_price = wpshop_prices::check_product_price($product);
1668
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1669
+		if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1670
+			$product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1671
+
1672
+			if (!empty($product_price_infos)) {
1673
+				$tpl_component_price = array();
1674
+				/** Price piloting **/
1675 1675
 				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1676 1676
 				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1677
-                $price_ploting = get_option('wpshop_shop_price_piloting');
1678
-                $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : '';
1679
-                $variations = wpshop_products::get_variation($product_id);
1677
+				$price_ploting = get_option('wpshop_shop_price_piloting');
1678
+				$tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : '';
1679
+				$variations = wpshop_products::get_variation($product_id);
1680 1680
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1681 1681
 				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1682 1682
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1683 1683
 				}
1684
-                $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1685
-                $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1686
-                $product_price_infos['MESSAGE_SAVE_MONEY'];
1687
-                $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1688
-            } else {
1689
-                $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1690
-            }
1691
-        }
1684
+				$tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1685
+				$tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1686
+				$product_price_infos['MESSAGE_SAVE_MONEY'];
1687
+				$productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1688
+			} else {
1689
+				$productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1690
+			}
1691
+		}
1692 1692
 
1693
-        /** Check if there is at less 1 product in stock    */
1694
-        $wps_product_ctr = new wps_product_ctr();
1695
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1696
-        $productStock = $productStock === true ? 1 : null;
1697
-
1698
-        /** Define "Add to cart" button    */
1699
-        $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'mini_output');
1700
-        $display_price_state_when_price_is_empty = false;
1701
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1702
-            $display_price_state_when_price_is_empty = false;
1703
-        } else if (!empty($productPrice)) {
1704
-            $display_price_state_when_price_is_empty = true;
1705
-        }
1706
-        $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'mini') : '';
1707
-        $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1693
+		/** Check if there is at less 1 product in stock    */
1694
+		$wps_product_ctr = new wps_product_ctr();
1695
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1696
+		$productStock = $productStock === true ? 1 : null;
1697
+
1698
+		/** Define "Add to cart" button    */
1699
+		$add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'mini_output');
1700
+		$display_price_state_when_price_is_empty = false;
1701
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1702
+			$display_price_state_when_price_is_empty = false;
1703
+		} else if (!empty($productPrice)) {
1704
+			$display_price_state_when_price_is_empty = true;
1705
+		}
1706
+		$add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'mini') : '';
1707
+		$product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1708 1708
 
1709
-        /** Define "Ask a quotation" button    */
1710
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1711
-        $product_new_def = self::display_product_special_state('declare_new', $output_type, (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1709
+		/** Define "Ask a quotation" button    */
1710
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1711
+		$product_new_def = self::display_product_special_state('declare_new', $output_type, (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1712 1712
 
1713
-        $product_new = $product_new_def['output'];
1714
-        $product_class .= $product_new_def['class'];
1713
+		$product_new = $product_new_def['output'];
1714
+		$product_class .= $product_new_def['class'];
1715 1715
 
1716
-        $product_featured_def = self::display_product_special_state('highlight_product', $output_type, (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1717
-        $product_featured = $product_featured_def['output'];
1718
-        $product_class .= $product_featured_def['class'];
1716
+		$product_featured_def = self::display_product_special_state('highlight_product', $output_type, (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1717
+		$product_featured = $product_featured_def['output'];
1718
+		$product_class .= $product_featured_def['class'];
1719 1719
 
1720
-        if (!($current_item_position % $grid_element_nb_per_line)) {
1721
-            $product_class .= ' wpshop_last_product_of_line';
1722
-        }
1720
+		if (!($current_item_position % $grid_element_nb_per_line)) {
1721
+			$product_class .= ' wpshop_last_product_of_line';
1722
+		}
1723 1723
 
1724
-        if (!empty($product['product_id'])) {
1725
-            /** Template parameters    */
1726
-            $template_part = 'product_mini_' . $output_type;
1727
-            $tpl_component = array();
1728
-            $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1729
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1730
-            $tpl_component['PRODUCT_ID'] = $product_id;
1731
-            $tpl_component['PRODUCT_CLASS'] = $product_class;
1732
-            $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1733
-            $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1734
-            $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1735
-            $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1736
-            $tpl_component['PRODUCT_PRICE'] = $productPrice;
1737
-            $tpl_component['PRODUCT_PERMALINK'] = $product_link;
1738
-            $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1739
-            $tpl_component['PRODUCT_NAME'] = $product_name;
1740
-            $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1741
-            $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1742
-            $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1743
-            $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1744
-            $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1745
-
1746
-            if (has_post_thumbnail($product_id)) {
1747
-                $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1748
-                if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1749
-                    $existing_image_sizes = get_intermediate_image_sizes();
1750
-                    foreach ($existing_image_sizes as $size_name) {
1751
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1752
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1753
-                    }
1754
-                }
1755
-            }
1756
-
1757
-            $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1758
-            $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1759
-            $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1760
-
1761
-            /** Build template    */
1762
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1763
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1764
-                /**    Include the old way template part    */
1765
-                ob_start();
1766
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1767
-                $content = ob_get_contents();
1768
-                ob_end_clean();
1769
-            } else {
1770
-                $content = wpshop_display::display_template_element($template_part, $tpl_component);
1771
-            }
1772
-            unset($tpl_component);
1724
+		if (!empty($product['product_id'])) {
1725
+			/** Template parameters    */
1726
+			$template_part = 'product_mini_' . $output_type;
1727
+			$tpl_component = array();
1728
+			$tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1729
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1730
+			$tpl_component['PRODUCT_ID'] = $product_id;
1731
+			$tpl_component['PRODUCT_CLASS'] = $product_class;
1732
+			$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1733
+			$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1734
+			$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1735
+			$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1736
+			$tpl_component['PRODUCT_PRICE'] = $productPrice;
1737
+			$tpl_component['PRODUCT_PERMALINK'] = $product_link;
1738
+			$tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1739
+			$tpl_component['PRODUCT_NAME'] = $product_name;
1740
+			$tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1741
+			$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1742
+			$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1743
+			$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1744
+			$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1745
+
1746
+			if (has_post_thumbnail($product_id)) {
1747
+				$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1748
+				if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1749
+					$existing_image_sizes = get_intermediate_image_sizes();
1750
+					foreach ($existing_image_sizes as $size_name) {
1751
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1752
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1753
+					}
1754
+				}
1755
+			}
1773 1756
 
1774
-        }
1757
+			$tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1758
+			$tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1759
+			$tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1760
+
1761
+			/** Build template    */
1762
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1763
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1764
+				/**    Include the old way template part    */
1765
+				ob_start();
1766
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1767
+				$content = ob_get_contents();
1768
+				ob_end_clean();
1769
+			} else {
1770
+				$content = wpshop_display::display_template_element($template_part, $tpl_component);
1771
+			}
1772
+			unset($tpl_component);
1775 1773
 
1776
-        return $content;
1777
-    }
1774
+		}
1778 1775
 
1779
-    /**
1780
-     *    Get the products (post) of a given category
1781
-     *
1782
-     *    @param string $category_slug The category slug we want to get the product list for
1783
-     *
1784
-     *    @return mixed $widget_content The output for the product list
1785
-     */
1786
-    public static function get_product_of_category($category_slug, $category_id)
1787
-    {
1788
-        global $top_categories;
1789
-        $widget_content = '';
1790
-        $products = wp_cache_get('wpshop_products_category_' . $category_id);
1791
-        if (false == $products) {
1792
-            $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1793
-            $products = get_posts($args);
1794
-            wp_cache_set('wpshop_products_category_' . $category_id, $products);
1795
-        }
1796
-        if (is_array($products) && (count($products) > 0)) {
1797
-            foreach ($products as $product) {
1798
-                if ($product->post_status == "publish") {
1799
-                    ob_start();
1800
-                    require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1801
-                    $widget_content .= ob_get_contents();
1802
-                    ob_end_clean();
1803
-                }
1804
-            }
1805
-        }
1776
+		return $content;
1777
+	}
1806 1778
 
1807
-        echo $widget_content;
1808
-    }
1779
+	/**
1780
+	 *    Get the products (post) of a given category
1781
+	 *
1782
+	 *    @param string $category_slug The category slug we want to get the product list for
1783
+	 *
1784
+	 *    @return mixed $widget_content The output for the product list
1785
+	 */
1786
+	public static function get_product_of_category($category_slug, $category_id)
1787
+	{
1788
+		global $top_categories;
1789
+		$widget_content = '';
1790
+		$products = wp_cache_get('wpshop_products_category_' . $category_id);
1791
+		if (false == $products) {
1792
+			$args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1793
+			$products = get_posts($args);
1794
+			wp_cache_set('wpshop_products_category_' . $category_id, $products);
1795
+		}
1796
+		if (is_array($products) && (count($products) > 0)) {
1797
+			foreach ($products as $product) {
1798
+				if ($product->post_status == "publish") {
1799
+					ob_start();
1800
+					require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1801
+					$widget_content .= ob_get_contents();
1802
+					ob_end_clean();
1803
+				}
1804
+			}
1805
+		}
1809 1806
 
1810
-    /**
1811
-     *
1812
-     * @param unknown_type $selected_product
1813
-     * @return string
1814
-     */
1815
-    public function custom_product_list($selected_product = array())
1816
-    {
1817
-        global $wpdb;
1818
-
1819
-        /*    Start the table definition    */
1820
-        $tableId = 'wpshop_product_list';
1821
-        $tableTitles = array();
1822
-        $tableTitles[] = '';
1823
-        $tableTitles[] = __('Id', 'wpshop');
1824
-        $tableTitles[] = __('Quantity', 'wpshop');
1825
-        $tableTitles[] = __('Reference', 'wpshop');
1826
-        $tableTitles[] = __('Product name', 'wpshop');
1827
-        $tableTitles[] = __('Actions', 'wpshop');
1828
-        $tableTitles[] = __('Price', 'wpshop');
1829
-        $tableClasses = array();
1830
-        $tableClasses[] = 'wpshop_product_selector_column';
1831
-        $tableClasses[] = 'wpshop_product_identifier_column';
1832
-        $tableClasses[] = 'wpshop_product_quantity_column';
1833
-        $tableClasses[] = 'wpshop_product_sku_column';
1834
-        $tableClasses[] = 'wpshop_product_name_column';
1835
-        $tableClasses[] = 'wpshop_product_link_column';
1836
-        $tableClasses[] = 'wpshop_product_price_column';
1837
-
1838
-        /*    Get post list    */
1839
-        $has_result = false;
1840
-        $current_line_index = 0;
1841
-        $posts = query_posts(array(
1842
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1843
-        ));
1844
-        if (!empty($posts)) {
1845
-            $has_result = true;
1846
-            foreach ($posts as $post) {
1847
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1848
-
1849
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1850
-
1851
-                unset($tableRowValue);
1852
-                $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1853
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1854
-                $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1855
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1856
-                $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1857
-                $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1807
+		echo $widget_content;
1808
+	}
1809
+
1810
+	/**
1811
+	 *
1812
+	 * @param unknown_type $selected_product
1813
+	 * @return string
1814
+	 */
1815
+	public function custom_product_list($selected_product = array())
1816
+	{
1817
+		global $wpdb;
1818
+
1819
+		/*    Start the table definition    */
1820
+		$tableId = 'wpshop_product_list';
1821
+		$tableTitles = array();
1822
+		$tableTitles[] = '';
1823
+		$tableTitles[] = __('Id', 'wpshop');
1824
+		$tableTitles[] = __('Quantity', 'wpshop');
1825
+		$tableTitles[] = __('Reference', 'wpshop');
1826
+		$tableTitles[] = __('Product name', 'wpshop');
1827
+		$tableTitles[] = __('Actions', 'wpshop');
1828
+		$tableTitles[] = __('Price', 'wpshop');
1829
+		$tableClasses = array();
1830
+		$tableClasses[] = 'wpshop_product_selector_column';
1831
+		$tableClasses[] = 'wpshop_product_identifier_column';
1832
+		$tableClasses[] = 'wpshop_product_quantity_column';
1833
+		$tableClasses[] = 'wpshop_product_sku_column';
1834
+		$tableClasses[] = 'wpshop_product_name_column';
1835
+		$tableClasses[] = 'wpshop_product_link_column';
1836
+		$tableClasses[] = 'wpshop_product_price_column';
1837
+
1838
+		/*    Get post list    */
1839
+		$has_result = false;
1840
+		$current_line_index = 0;
1841
+		$posts = query_posts(array(
1842
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1843
+		));
1844
+		if (!empty($posts)) {
1845
+			$has_result = true;
1846
+			foreach ($posts as $post) {
1847
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1848
+
1849
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1850
+
1851
+				unset($tableRowValue);
1852
+				$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1853
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1854
+				$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1855
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1856
+				$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1857
+				$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1858 1858
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1859
-                $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1860
-                $tableRows[] = $tableRowValue;
1859
+				$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1860
+				$tableRows[] = $tableRowValue;
1861 1861
 
1862
-                $current_line_index++;
1863
-            }
1864
-            wp_reset_query();
1865
-        }
1866
-        $posts = query_posts(array(
1867
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1868
-        ));
1869
-        if (!empty($posts)) {
1870
-            $has_result = true;
1871
-            foreach ($posts as $post) {
1872
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1873
-
1874
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1875
-
1876
-                unset($tableRowValue);
1877
-                $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1878
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1879
-                $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1880
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1881
-                $parent_product = wpshop_products::get_parent_variation($post->ID);
1882
-                if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1883
-                    $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1884
-                    $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1885
-                    $option_name = $wpdb->get_var($query);
1886
-                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1887
-                    $option_value = $wpdb->get_var($query);
1888
-                    $parent_post = $parent_product['parent_post'];
1889
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1890
-                } else {
1891
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1892
-                }
1893
-
1894
-                $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1862
+				$current_line_index++;
1863
+			}
1864
+			wp_reset_query();
1865
+		}
1866
+		$posts = query_posts(array(
1867
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1868
+		));
1869
+		if (!empty($posts)) {
1870
+			$has_result = true;
1871
+			foreach ($posts as $post) {
1872
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1873
+
1874
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1875
+
1876
+				unset($tableRowValue);
1877
+				$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1878
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1879
+				$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1880
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1881
+				$parent_product = wpshop_products::get_parent_variation($post->ID);
1882
+				if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1883
+					$product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1884
+					$query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1885
+					$option_name = $wpdb->get_var($query);
1886
+					$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1887
+					$option_value = $wpdb->get_var($query);
1888
+					$parent_post = $parent_product['parent_post'];
1889
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1890
+				} else {
1891
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1892
+				}
1893
+
1894
+				$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1895 1895
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1896
-                $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1897
-                $tableRows[] = $tableRowValue;
1896
+				$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1897
+				$tableRows[] = $tableRowValue;
1898 1898
 
1899
-                $current_line_index++;
1900
-            }
1901
-            wp_reset_query();
1902
-        }
1899
+				$current_line_index++;
1900
+			}
1901
+			wp_reset_query();
1902
+		}
1903 1903
 
1904
-        if (!$has_result) {
1905
-            $tableRowsId[] = 'no_product_found';
1906
-            unset($tableRowValue);
1907
-            $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1908
-            $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1909
-            $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1910
-            $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1911
-            $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1912
-            $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1913
-            $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1914
-            $tableRows[] = $tableRowValue;
1915
-        }
1904
+		if (!$has_result) {
1905
+			$tableRowsId[] = 'no_product_found';
1906
+			unset($tableRowValue);
1907
+			$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1908
+			$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1909
+			$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1910
+			$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1911
+			$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1912
+			$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1913
+			$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1914
+			$tableRows[] = $tableRowValue;
1915
+		}
1916 1916
 
1917
-        return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1917
+		return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1918 1918
 <script type="text/javascript" >
1919 1919
 	wpshop(document).ready(function(){
1920 1920
 		jQuery("#' . $tableId . '").dataTable( {
@@ -1923,1534 +1923,1534 @@  discard block
 block discarded – undo
1923 1923
 		});
1924 1924
 	});
1925 1925
 </script>';
1926
-    }
1926
+	}
1927 1927
 
1928
-    /**
1929
-     * Allows to manage output for special state for a product (New product/highlight product)
1930
-     *
1931
-     * @param string $special The type of special type we want to output
1932
-     * @param string $output_type The current display type (used for product listing)
1933
-     * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1934
-     * @param datetime $special_state_start The start date if applicable for the special state
1935
-     * @param datetime $special_state_end The end date if applicable for the special state
1936
-     *
1937
-     * @return array $product_special_state The product special state
1938
-     */
1939
-    public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1940
-    {
1941
-        $product_special_state = array();
1942
-        $product_special_state['output'] = $product_special_state['class'] = '';
1943
-
1944
-        /** Get product special state definition    */
1945
-        $special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1946
-        $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1947
-        $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1948
-
1949
-        /** Get current time    */
1950
-        $current_time = substr(current_time('mysql', 0), 0, 10);
1951
-
1952
-        /** PRODUCT MARK AS NEW */
1953
-        $show_product_special_state = false;
1954
-        if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1955
-            (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1956
-            (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1957
-            $show_product_special_state = true;
1958
-        }
1928
+	/**
1929
+	 * Allows to manage output for special state for a product (New product/highlight product)
1930
+	 *
1931
+	 * @param string $special The type of special type we want to output
1932
+	 * @param string $output_type The current display type (used for product listing)
1933
+	 * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1934
+	 * @param datetime $special_state_start The start date if applicable for the special state
1935
+	 * @param datetime $special_state_end The end date if applicable for the special state
1936
+	 *
1937
+	 * @return array $product_special_state The product special state
1938
+	 */
1939
+	public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1940
+	{
1941
+		$product_special_state = array();
1942
+		$product_special_state['output'] = $product_special_state['class'] = '';
1943
+
1944
+		/** Get product special state definition    */
1945
+		$special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1946
+		$special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1947
+		$special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1948
+
1949
+		/** Get current time    */
1950
+		$current_time = substr(current_time('mysql', 0), 0, 10);
1951
+
1952
+		/** PRODUCT MARK AS NEW */
1953
+		$show_product_special_state = false;
1954
+		if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1955
+			(empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1956
+			(empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1957
+			$show_product_special_state = true;
1958
+		}
1959 1959
 
1960
-        if ($show_product_special_state) {
1961
-            /** Check the type of special output needed    */
1962
-            switch ($special) {
1963
-                case 'declare_new':
1964
-                    $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1965
-                    $template_part = 'product_is_new_sticker';
1966
-                    break;
1967
-
1968
-                case 'highlight_product':
1969
-                    $product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
1970
-                    $template_part = 'product_is_featured_sticker';
1971
-                    break;
1972
-            }
1973
-
1974
-            /** Template parameters    */
1975
-            $tpl_component = array();
1976
-
1977
-            /** Build template        */
1978
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1979
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1980
-                /**    Include the old way template part    */
1981
-                ob_start();
1982
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1983
-                $product_special_state['output'] = ob_get_contents();
1984
-                ob_end_clean();
1985
-            } else {
1986
-                $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
1987
-            }
1988
-            unset($tpl_component);
1989
-        }
1960
+		if ($show_product_special_state) {
1961
+			/** Check the type of special output needed    */
1962
+			switch ($special) {
1963
+				case 'declare_new':
1964
+					$product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1965
+					$template_part = 'product_is_new_sticker';
1966
+					break;
1990 1967
 
1991
-        return $product_special_state;
1992
-    }
1968
+				case 'highlight_product':
1969
+					$product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
1970
+					$template_part = 'product_is_featured_sticker';
1971
+					break;
1972
+			}
1993 1973
 
1994
-    /**
1995
-     * Prepare product price for saving and easier read later
1996
-     *
1997
-     * @param integer $element_id Identifier of current product
1998
-     */
1999
-    public static function calculate_price($element_id)
2000
-    {
2001
-        global $wpdb;
2002
-
2003
-        /**
2004
-         * Récupères les attributs suivants : product_price, price_ht et tva
2005
-         * par rapport à $element_id / Get the next attributes : product_price,
2006
-         * price_ht and tva
2007
-         */
2008
-        $query = $wpdb->prepare(
2009
-            "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
1974
+			/** Template parameters    */
1975
+			$tpl_component = array();
1976
+
1977
+			/** Build template        */
1978
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1979
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1980
+				/**    Include the old way template part    */
1981
+				ob_start();
1982
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1983
+				$product_special_state['output'] = ob_get_contents();
1984
+				ob_end_clean();
1985
+			} else {
1986
+				$product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
1987
+			}
1988
+			unset($tpl_component);
1989
+		}
1990
+
1991
+		return $product_special_state;
1992
+	}
1993
+
1994
+	/**
1995
+	 * Prepare product price for saving and easier read later
1996
+	 *
1997
+	 * @param integer $element_id Identifier of current product
1998
+	 */
1999
+	public static function calculate_price($element_id)
2000
+	{
2001
+		global $wpdb;
2002
+
2003
+		/**
2004
+		 * Récupères les attributs suivants : product_price, price_ht et tva
2005
+		 * par rapport à $element_id / Get the next attributes : product_price,
2006
+		 * price_ht and tva
2007
+		 */
2008
+		$query = $wpdb->prepare(
2009
+			"SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2010 2010
 			FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR
2011 2011
 				RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d))
2012 2012
 			WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')",
2013
-            $element_id
2014
-        );
2015
-        $prices_attribute = $wpdb->get_results($query, OBJECT_K);
2016
-
2017
-        /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2018
-        if (empty($prices_attribute)) {
2019
-            return false;
2020
-        } else {
2021
-            /**
2022
-             * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2023
-             * the base amount according on the shop price control
2024
-             */
2025
-            $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2026
-            $rate_vat = wpshop_prices::get_rate_vat($element_id);
2027
-            $divider_price_ttc = 1 + ($rate_vat->value / 100);
2028
-
2029
-            /**
2030
-             * Informations nécessaire pour crée un attribut / Information needed to
2031
-             * create an attribute
2032
-             */
2033
-            $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2034
-            $language = WPSHOP_CURRENT_LOCALE;
2035
-            $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2036
-
2037
-            if (!empty($icl_post_language)) {
2038
-                $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2039
-                $language = $wpdb->get_var($query);
2040
-            }
2041
-
2042
-            /**
2043
-             * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2044
-             * Check configuration to know how to make the calcul for the product
2045
-             */
2046
-            if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2047
-                $price_with_vat = ($base_price * $divider_price_ttc);
2048
-                $price_no_vat = $base_price;
2049
-            } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2050
-                $price_with_vat = $base_price;
2051
-                $price_no_vat = ($price_with_vat / $divider_price_ttc);
2052
-            }
2053
-
2054
-            /**
2055
-             * Le dernier paramètre permet de ne pas supprimer les attributs du même
2056
-             * type que celui-ci / The last parameter allows not to delete the
2057
-             * attributes of the same type as this one
2058
-             */
2059
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2060
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2061
-
2062
-            /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2063
-            $vat_amount = $price_with_vat - $price_no_vat;
2064
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2065
-
2066
-            /**    Update the product meta information with the calculated prices    */
2067
-            $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2068
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2069
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2070
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2071
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2072
-
2073
-            update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2013
+			$element_id
2014
+		);
2015
+		$prices_attribute = $wpdb->get_results($query, OBJECT_K);
2016
+
2017
+		/** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2018
+		if (empty($prices_attribute)) {
2019
+			return false;
2020
+		} else {
2021
+			/**
2022
+			 * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2023
+			 * the base amount according on the shop price control
2024
+			 */
2025
+			$base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2026
+			$rate_vat = wpshop_prices::get_rate_vat($element_id);
2027
+			$divider_price_ttc = 1 + ($rate_vat->value / 100);
2028
+
2029
+			/**
2030
+			 * Informations nécessaire pour crée un attribut / Information needed to
2031
+			 * create an attribute
2032
+			 */
2033
+			$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2034
+			$language = WPSHOP_CURRENT_LOCALE;
2035
+			$icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2036
+
2037
+			if (!empty($icl_post_language)) {
2038
+				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2039
+				$language = $wpdb->get_var($query);
2040
+			}
2074 2041
 
2075
-            /** Met à jour la meta _wps_price_infos */
2076
-            $p = wpshop_products::get_product_data($element_id);
2077
-            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2078
-            update_post_meta($element_id, '_wps_price_infos', $price);
2042
+			/**
2043
+			 * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2044
+			 * Check configuration to know how to make the calcul for the product
2045
+			 */
2046
+			if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2047
+				$price_with_vat = ($base_price * $divider_price_ttc);
2048
+				$price_no_vat = $base_price;
2049
+			} else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2050
+				$price_with_vat = $base_price;
2051
+				$price_no_vat = ($price_with_vat / $divider_price_ttc);
2052
+			}
2079 2053
 
2080
-            /** Met à jour la meta _wpshop_displayed_price */
2081
-            wps_filter_search::save_displayed_price_meta($element_id);
2082
-        }
2054
+			/**
2055
+			 * Le dernier paramètre permet de ne pas supprimer les attributs du même
2056
+			 * type que celui-ci / The last parameter allows not to delete the
2057
+			 * attributes of the same type as this one
2058
+			 */
2059
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2060
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2061
+
2062
+			/** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2063
+			$vat_amount = $price_with_vat - $price_no_vat;
2064
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2065
+
2066
+			/**    Update the product meta information with the calculated prices    */
2067
+			$product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2068
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2069
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2070
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2071
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2072
+
2073
+			update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2074
+
2075
+			/** Met à jour la meta _wps_price_infos */
2076
+			$p = wpshop_products::get_product_data($element_id);
2077
+			$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2078
+			update_post_meta($element_id, '_wps_price_infos', $price);
2079
+
2080
+			/** Met à jour la meta _wpshop_displayed_price */
2081
+			wps_filter_search::save_displayed_price_meta($element_id);
2082
+		}
2083 2083
 
2084
-        return true;
2085
-    }
2084
+		return true;
2085
+	}
2086 2086
 
2087
-    /**
2088
-     * Allows to get the good button for adding product to cart
2089
-     *
2090
-     * @param integer $product_id The product identifier
2091
-     * @param boolean $productStock If there is the possibility to add the given product to the cart
2092
-     *
2093
-     * @return string $button The html output for the button
2094
-     */
2095
-    public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2096
-    {
2097
-        $button = '';
2087
+	/**
2088
+	 * Allows to get the good button for adding product to cart
2089
+	 *
2090
+	 * @param integer $product_id The product identifier
2091
+	 * @param boolean $productStock If there is the possibility to add the given product to the cart
2092
+	 *
2093
+	 * @return string $button The html output for the button
2094
+	 */
2095
+	public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2096
+	{
2097
+		$button = '';
2098 2098
 //         $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true );
2099 2099
 
2100
-        if (WPSHOP_DEFINED_SHOP_TYPE == 'sale' /*&& ( empty($attributes_frontend_display) || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['mini_output']) && $output_type == 'mini') || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['complete_sheet']) && $output_type == 'complete') ) */) {
2101
-            /*
2100
+		if (WPSHOP_DEFINED_SHOP_TYPE == 'sale' /*&& ( empty($attributes_frontend_display) || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['mini_output']) && $output_type == 'mini') || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['complete_sheet']) && $output_type == 'complete') ) */) {
2101
+			/*
2102 2102
              * Check if current product has variation for button display
2103 2103
              */
2104
-            $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2105
-            $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2104
+			$variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2105
+			$variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2106 2106
 
2107
-            /*
2107
+			/*
2108 2108
              * Template parameters
2109 2109
              */
2110 2110
 
2111
-            if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2112
-                /** Check variation stock **/
2113
-                $variations = self::get_variation($product_id);
2114
-                if (!empty($variations)) {
2115
-                    foreach ($variations as $variation) {
2116
-                        if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2117
-                            $productStock += $variation['variation_dif']['product_stock'];
2118
-                        }
2119
-                    }
2120
-                }
2121
-            }
2122
-
2123
-            $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2111
+			if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2112
+				/** Check variation stock **/
2113
+				$variations = self::get_variation($product_id);
2114
+				if (!empty($variations)) {
2115
+					foreach ($variations as $variation) {
2116
+						if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2117
+							$productStock += $variation['variation_dif']['product_stock'];
2118
+						}
2119
+					}
2120
+				}
2121
+			}
2122
+
2123
+			$template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2124 2124
 						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2125 2125
 
2126
-            $tpl_component = array();
2127
-            $tpl_component['PRODUCT_ID'] = $product_id;
2128
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2129
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2126
+			$tpl_component = array();
2127
+			$tpl_component['PRODUCT_ID'] = $product_id;
2128
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2129
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2130 2130
 
2131
-            /*
2131
+			/*
2132 2132
              * Build template
2133 2133
              */
2134
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2135
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2136
-                /*    Include the old way template part    */
2137
-                ob_start();
2138
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2139
-                $button = ob_get_contents();
2140
-                ob_end_clean();
2141
-            } else {
2142
-                $button = wpshop_display::display_template_element($template_part, $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $product_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . 'output_type' => $output_type));
2143
-            }
2144
-            unset($tpl_component);
2145
-        }
2146
-        return $button;
2147
-    }
2134
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2135
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2136
+				/*    Include the old way template part    */
2137
+				ob_start();
2138
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2139
+				$button = ob_get_contents();
2140
+				ob_end_clean();
2141
+			} else {
2142
+				$button = wpshop_display::display_template_element($template_part, $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $product_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . 'output_type' => $output_type));
2143
+			}
2144
+			unset($tpl_component);
2145
+		}
2146
+		return $button;
2147
+	}
2148 2148
 
2149
-    /**
2150
-     * Allows to get the good button for adding product to a quotation
2151
-     *
2152
-     * @param integer $product_id The product identifier
2153
-     * @param boolean $product_quotation_state The state of the quotation addons
2154
-     *
2155
-     * @return string $button The html output for the button
2156
-     */
2157
-    public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2158
-    {
2159
-        $quotation_button = '';
2160
-
2161
-        if (WPSHOP_ADDONS_QUOTATION && (!empty($product_quotation_state) && strtolower(__($product_quotation_state, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) && (empty($_SESSION['cart']['cart_type']) || ($_SESSION['cart']['cart_type'] == 'quotation'))) {
2162
-            $variations_list = (is_array(wpshop_products::get_variation($product_id)) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? array_merge(wpshop_products::get_variation($product_id), wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode))) : array();
2163
-            /**
2164
-             * Template parameters
2165
-             */
2166
-            $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2167
-            $tpl_component = array();
2168
-            $tpl_component['PRODUCT_ID'] = $product_id;
2169
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2170
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2149
+	/**
2150
+	 * Allows to get the good button for adding product to a quotation
2151
+	 *
2152
+	 * @param integer $product_id The product identifier
2153
+	 * @param boolean $product_quotation_state The state of the quotation addons
2154
+	 *
2155
+	 * @return string $button The html output for the button
2156
+	 */
2157
+	public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2158
+	{
2159
+		$quotation_button = '';
2160
+
2161
+		if (WPSHOP_ADDONS_QUOTATION && (!empty($product_quotation_state) && strtolower(__($product_quotation_state, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) && (empty($_SESSION['cart']['cart_type']) || ($_SESSION['cart']['cart_type'] == 'quotation'))) {
2162
+			$variations_list = (is_array(wpshop_products::get_variation($product_id)) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? array_merge(wpshop_products::get_variation($product_id), wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode))) : array();
2163
+			/**
2164
+			 * Template parameters
2165
+			 */
2166
+			$template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2167
+			$tpl_component = array();
2168
+			$tpl_component['PRODUCT_ID'] = $product_id;
2169
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2170
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2171
+
2172
+			/**
2173
+			 * Build template
2174
+			 */
2175
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2176
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2177
+				/*    Include the old way template part    */
2178
+				ob_start();
2179
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2180
+				$quotation_button = ob_get_contents();
2181
+				ob_end_clean();
2182
+			} else {
2183
+				$quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2184
+			}
2185
+			unset($tpl_component);
2186
+		}
2171 2187
 
2172
-            /**
2173
-             * Build template
2174
-             */
2175
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2176
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2177
-                /*    Include the old way template part    */
2178
-                ob_start();
2179
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2180
-                $quotation_button = ob_get_contents();
2181
-                ob_end_clean();
2182
-            } else {
2183
-                $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2184
-            }
2185
-            unset($tpl_component);
2186
-        }
2188
+		return $quotation_button;
2189
+	}
2187 2190
 
2188
-        return $quotation_button;
2189
-    }
2191
+	/**
2192
+	 * Return the output for a product attachement gallery (picture or document)
2193
+	 *
2194
+	 * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2195
+	 * @param string $content The gallery content build previously
2196
+	 *
2197
+	 * @return string The attachement gallery output
2198
+	 */
2199
+	public static function display_attachment_gallery($attachement_type, $content)
2200
+	{
2201
+		$galery_output = '';
2190 2202
 
2191
-    /**
2192
-     * Return the output for a product attachement gallery (picture or document)
2193
-     *
2194
-     * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2195
-     * @param string $content The gallery content build previously
2196
-     *
2197
-     * @return string The attachement gallery output
2198
-     */
2199
-    public static function display_attachment_gallery($attachement_type, $content)
2200
-    {
2201
-        $galery_output = '';
2202
-
2203
-        /*
2203
+		/*
2204 2204
          * Get the template part for given galery type
2205 2205
          */
2206
-        switch ($attachement_type) {
2207
-            case 'picture':
2208
-                $template_part = 'product_attachment_picture_galery';
2209
-                break;
2210
-            case 'document':
2211
-                $template_part = 'product_attachment_galery';
2212
-                break;
2213
-        }
2206
+		switch ($attachement_type) {
2207
+			case 'picture':
2208
+				$template_part = 'product_attachment_picture_galery';
2209
+				break;
2210
+			case 'document':
2211
+				$template_part = 'product_attachment_galery';
2212
+				break;
2213
+		}
2214 2214
 
2215
-        /*
2215
+		/*
2216 2216
          * Template parameters
2217 2217
          */
2218
-        $tpl_component = array();
2219
-        $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2220
-        $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2218
+		$tpl_component = array();
2219
+		$tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2220
+		$tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2221 2221
 
2222
-        /*
2222
+		/*
2223 2223
          * Build template
2224 2224
          */
2225
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2226
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2227
-            /*    Include the old way template part    */
2228
-            ob_start();
2229
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
2230
-            $galery_output = ob_get_contents();
2231
-            ob_end_clean();
2232
-        } else {
2233
-            $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2234
-        }
2235
-        unset($tpl_component);
2225
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2226
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2227
+			/*    Include the old way template part    */
2228
+			ob_start();
2229
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
2230
+			$galery_output = ob_get_contents();
2231
+			ob_end_clean();
2232
+		} else {
2233
+			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2234
+		}
2235
+		unset($tpl_component);
2236 2236
 
2237
-        return $galery_output;
2238
-    }
2237
+		return $galery_output;
2238
+	}
2239 2239
 
2240
-    /**
2241
-     * Define the metabox to display in product edition page in backend
2242
-     * @param object $post The current element displayed for edition
2243
-     */
2244
-    public static function meta_box_variations($post)
2245
-    {
2246
-        $output = '';
2247
-        /*    Variations container    */
2248
-        $tpl_component = array();
2249
-        $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2250
-        $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2251
-        $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2252
-        echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2253
-    }
2240
+	/**
2241
+	 * Define the metabox to display in product edition page in backend
2242
+	 * @param object $post The current element displayed for edition
2243
+	 */
2244
+	public static function meta_box_variations($post)
2245
+	{
2246
+		$output = '';
2247
+		/*    Variations container    */
2248
+		$tpl_component = array();
2249
+		$tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2250
+		$tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2251
+		$output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2252
+		echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2253
+	}
2254 2254
 
2255
-    /**
2256
-     * Call variation creation function with a list of defined variation
2257
-     *
2258
-     * @param array $possible_variations A list of variation to create for the current element
2259
-     * @param integer $element_id The product we want to create variation for
2260
-     *
2261
-     * @return mixed The last created variation identifier
2262
-     */
2263
-    public static function creation_variation_callback($possible_variations, $element_id)
2264
-    {
2265
-        /** Get existing variation    */
2266
-        $existing_variations_in_db = wpshop_products::get_variation($element_id);
2267
-        $existing_variations = array();
2268
-        if (!empty($existing_variations_in_db)) {
2269
-            foreach ($existing_variations_in_db as $variations_def) {
2270
-                $existing_variations[] = $variations_def['variation_def'];
2271
-            }
2272
-        }
2273
-        /** New variation definition    */
2274
-        $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2275
-
2276
-        /**    Read possible values    */
2277
-        foreach ($possible_variations as $variation_definition) {
2278
-            if (in_array($variation_definition, $existing_variations)) {
2279
-                continue;
2280
-            }
2281
-
2282
-            $attribute_to_set = array();
2283
-            foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2284
-                $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2285
-                $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2286
-                if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2287
-                    $attribute_defining_variation['attributes'][] = $attribute_code;
2288
-                }
2289
-            }
2290
-            $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2291
-        }
2292
-        update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2255
+	/**
2256
+	 * Call variation creation function with a list of defined variation
2257
+	 *
2258
+	 * @param array $possible_variations A list of variation to create for the current element
2259
+	 * @param integer $element_id The product we want to create variation for
2260
+	 *
2261
+	 * @return mixed The last created variation identifier
2262
+	 */
2263
+	public static function creation_variation_callback($possible_variations, $element_id)
2264
+	{
2265
+		/** Get existing variation    */
2266
+		$existing_variations_in_db = wpshop_products::get_variation($element_id);
2267
+		$existing_variations = array();
2268
+		if (!empty($existing_variations_in_db)) {
2269
+			foreach ($existing_variations_in_db as $variations_def) {
2270
+				$existing_variations[] = $variations_def['variation_def'];
2271
+			}
2272
+		}
2273
+		/** New variation definition    */
2274
+		$attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2293 2275
 
2294
-        return !empty($variation_id) ? $variation_id : 0;
2295
-    }
2276
+		/**    Read possible values    */
2277
+		foreach ($possible_variations as $variation_definition) {
2278
+			if (in_array($variation_definition, $existing_variations)) {
2279
+				continue;
2280
+			}
2296 2281
 
2297
-    /**
2298
-     * Create a new variation for product
2299
-     *
2300
-     * @param integer $head_product The product identifier to create the new variation for
2301
-     * @param array $variation_attributes Attribute list for the variation
2302
-     *
2303
-     * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2304
-     */
2305
-    public static function create_variation($head_product, $variation_attributes)
2306
-    {
2307
-        /** Create custom title */
2308
-        $title_variation = "";
2309
-        if (!empty($variation_attributes)) {
2310
-            foreach ($variation_attributes as $type => $array) {
2311
-                if (!empty($array)) {
2312
-                    foreach ($array as $code => $value) {
2313
-                        $title_variation .= " " . $code . " " . $value;
2314
-                    }
2315
-                }
2316
-            }
2317
-        }
2282
+			$attribute_to_set = array();
2283
+			foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2284
+				$attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2285
+				$attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2286
+				if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2287
+					$attribute_defining_variation['attributes'][] = $attribute_code;
2288
+				}
2289
+			}
2290
+			$variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2291
+		}
2292
+		update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2318 2293
 
2319
-        $variation = array(
2320
-            'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2321
-            'post_content' => '',
2322
-            'post_status' => 'publish',
2323
-            'post_author' => get_current_user_id(),
2324
-            'post_parent' => $head_product,
2325
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2326
-        );
2327
-        $variation_id = wp_insert_post($variation);
2328
-
2329
-        wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2330
-
2331
-        /*    Update product price looking for shop parameters    */
2332
-        wpshop_products::calculate_price($variation_id);
2333
-
2334
-        /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2335
-        $productMetaDatas = array();
2336
-        foreach ($variation_attributes as $attributeType => $attributeValues) {
2337
-            foreach ($attributeValues as $attributeCode => $attributeValue) {
2338
-                if (!empty($attributeValue)) {
2339
-                    $productMetaDatas[$attributeCode] = $attributeValue;
2340
-                }
2341
-            }
2342
-        }
2343
-        update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2344
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2345
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, get_post_meta($head_product, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2294
+		return !empty($variation_id) ? $variation_id : 0;
2295
+	}
2346 2296
 
2347
-        return $variation_id;
2348
-    }
2297
+	/**
2298
+	 * Create a new variation for product
2299
+	 *
2300
+	 * @param integer $head_product The product identifier to create the new variation for
2301
+	 * @param array $variation_attributes Attribute list for the variation
2302
+	 *
2303
+	 * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2304
+	 */
2305
+	public static function create_variation($head_product, $variation_attributes)
2306
+	{
2307
+		/** Create custom title */
2308
+		$title_variation = "";
2309
+		if (!empty($variation_attributes)) {
2310
+			foreach ($variation_attributes as $type => $array) {
2311
+				if (!empty($array)) {
2312
+					foreach ($array as $code => $value) {
2313
+						$title_variation .= " " . $code . " " . $value;
2314
+					}
2315
+				}
2316
+			}
2317
+		}
2349 2318
 
2350
-    /**
2351
-     * Get variation list for a given product
2352
-     *
2353
-     * @param integer $head_product The product identifier to get the variation for
2354
-     * @return object The variation list
2355
-     */
2356
-    public static function get_variation($head_product, $type = 'any')
2357
-    {
2358
-        global $wpdb;
2359
-        $variations_output = null;
2360
-        $args = array(
2361
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2362
-            'post_parent' => $head_product,
2363
-            'orderby' => 'ID',
2364
-            'order' => 'ASC',
2365
-            'posts_per_page' => -1,
2366
-            'post_status' => $type,
2367
-        );
2368
-        $variations = get_posts($args);
2369
-
2370
-        if (!empty($variations)) {
2371
-            $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2372
-
2373
-            foreach ($variations as $post_def) {
2374
-                $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post_def->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, "'valid', 'deleted'");
2375
-                foreach ($data as $content) {
2376
-                    $attribute_value = 'attribute_value_' . $content->data_type;
2377
-                    if (!empty($content->$attribute_value)) {
2378
-                        if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2379
-                            $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2380
-                        } else {
2381
-                            $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2382
-                        }
2383
-                    }
2384
-                }
2385
-                $variations_output[$post_def->ID]['post'] = $post_def;
2386
-            }
2387
-        }
2388
-        wp_reset_query();
2389
-        return $variations_output;
2390
-    }
2319
+		$variation = array(
2320
+			'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2321
+			'post_content' => '',
2322
+			'post_status' => 'publish',
2323
+			'post_author' => get_current_user_id(),
2324
+			'post_parent' => $head_product,
2325
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2326
+		);
2327
+		$variation_id = wp_insert_post($variation);
2328
+
2329
+		wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2330
+
2331
+		/*    Update product price looking for shop parameters    */
2332
+		wpshop_products::calculate_price($variation_id);
2333
+
2334
+		/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2335
+		$productMetaDatas = array();
2336
+		foreach ($variation_attributes as $attributeType => $attributeValues) {
2337
+			foreach ($attributeValues as $attributeCode => $attributeValue) {
2338
+				if (!empty($attributeValue)) {
2339
+					$productMetaDatas[$attributeCode] = $attributeValue;
2340
+				}
2341
+			}
2342
+		}
2343
+		update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2344
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2345
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, get_post_meta($head_product, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2391 2346
 
2392
-    /**
2393
-     * Affichage des variations d'un produit dans l'administration
2394
-     *
2395
-     * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2396
-     * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2397
-     */
2398
-    public static function display_variation_admin($head_product)
2399
-    {
2400
-        $output = '';
2401
-        $productCurrency = wpshop_tools::wpshop_get_currency();
2402
-        /*    Récupération de la liste des variations pour le produit en cours d'édition    */
2403
-        $variations = self::get_variation($head_product);
2404
-        $price_piloting = get_option('wpshop_shop_price_piloting');
2405
-
2406
-        /*    Affichage de la liste des variations pour le produit en cours d'édition    */
2407
-        if (!empty($variations) && is_array($variations)) {
2408
-            $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2409
-
2410
-            foreach ($variations as $variation) {
2411
-                $tpl_component = array();
2412
-
2413
-                $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2414
-                $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2415
-                $tpl_component['VARIATION_DETAIL'] = '  ';
2416
-                $p = (!empty($variation['variation_dif']['product_price']) || !empty($variation['variation_dif']['price_ht'])) ? ((!empty($price_piloting) && $price_piloting == 'HT' && !empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) : 0;
2417
-                $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2418
-                if (!empty($price_piloting) && $price_piloting == 'HT') {
2419
-
2420
-                } else {
2421
-
2422
-                }
2423
-                $post_obj = $variation['post'];
2424
-
2425
-                $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2426
-                if (!empty($parent_product_infos)) {
2427
-                    $parent_post = $parent_product_infos['parent_post'];
2428
-                    $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2429
-                    if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2430
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2431
-                            $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2432
-                        } else {
2433
-                            $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2434
-                        }
2435
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2436
-                    } else {
2437
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2438
-                            $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2439
-                        } else {
2440
-                            $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2441
-                        }
2442
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2443
-                    }
2444
-                    $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2445
-                    $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2446
-                }
2447
-
2448
-                if (!empty($variation['variation_def'])) {
2449
-                    foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2450
-                        if (!empty($variation_value)) {
2451
-                            $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2452
-                            $tpl_component['VARIATION_DETAIL'] .= '<input type="hidden" name="' . self::current_page_variation_code . '[' . $variation['post']->ID . '][attribute][' . $attribute_def_for_variation->data_type . '][' . $variation_key . ']" value="' . $variation_value . '" />' . wpshop_display::display_template_element('wpshop_admin_variation_item_def_header', array('VARIATION_ATTRIBUTE_CODE' => $attribute_def_for_variation->frontend_label, 'VARIATION_ATTRIBUTE_CODE_VALUE' => stripslashes(wpshop_attributes::get_attribute_type_select_option_info($variation_value, 'label', $attribute_def_for_variation->data_type_to_use, true))), array(), 'admin');
2453
-                            $tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2454
-
2455
-                            /** Define Link image to variation interface **/
2456
-                            if (!empty($product_option_postmeta) && !empty($product_option_postmeta['attributes']) && !empty($product_option_postmeta['variation_type']) && ((count($product_option_postmeta['attributes']) == 1 && $product_option_postmeta['variation_type'] == 'single') || ($product_option_postmeta['variation_type'] == 'combined'))) {
2457
-                                $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2458
-
2459
-                                $media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2460
-                                if (!empty($media_id_data)) {
2461
-                                    $medias_ids = explode(',', $media_id_data);
2462
-
2463
-                                    if (!empty($medias_ids)) {
2464
-                                        foreach ($medias_ids as $media_id) {
2465
-                                            if (!empty($media_id)) {
2466
-                                                $pictures[] = get_post($media_id);
2467
-                                            }
2468
-                                        }
2469
-                                    }
2470
-                                }
2471
-
2472
-                                $pictures_data = '';
2473
-                                if (!empty($pictures)) {
2474
-                                    $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2475
-
2476
-                                    $done_picture = array();
2477
-                                    foreach ($pictures as $picture) {
2478
-                                        if (!in_array($picture->ID, $done_picture)) {
2479
-                                            if (wp_attachment_is_image($picture->ID)) {
2480
-                                                $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2481
-                                                $pictures_data .= wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_element', array('PICTURE_CHOICE_VARIATION_ID' => $picture->ID, 'PRODUCT_VARIATION_ID' => $variation['post']->ID, 'PICTURE_CHOICE_SELECTED' => $checked, 'PICTURE_CHOICE_VARIATION_IMG' => wp_get_attachment_image($picture->ID, 'thumbnail')), array(), 'admin');
2482
-
2483
-                                                $done_picture[] = $picture->ID;
2484
-                                            }
2485
-                                        }
2486
-                                    }
2487
-                                }
2488
-
2489
-                                $tpl_component['VARIATION_IMAGE_CHOICE'] = wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_container', array('PICTURE_CHOICE_CONTAINER_CONTENT' => $pictures_data), array(), 'admin');
2490
-                            }
2491
-
2492
-                        }
2493
-                    }
2494
-                }
2495
-
2496
-                $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2497
-
2498
-                $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2499
-                $tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('post_id' => $variation['post']->ID, 'input_class' => ' ', 'field_name' => wpshop_products::current_page_variation_code . '[' . $variation['post']->ID . ']', 'page_code' => self::current_page_variation_code, 'field_id' => self::current_page_variation_code . '_' . $variation['post']->ID, 'variation_dif_values' => (!empty($variation['variation_dif']) ? $variation['variation_dif'] : array())));
2500
-                $tpl_component['VARIATION_DEFINITION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2501
-
2502
-                /*    Add the variation definition to output    */
2503
-                $existing_variation_list .= wpshop_display::display_template_element('wpshop_admin_variation_item_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2504
-            }
2505
-
2506
-            $output .= wpshop_display::display_template_element('wpshop_admin_existing_variation_list', array('ADMIN_EXISTING_VARIATIONS_CONTAINER_CLASS' => '', 'ADMIN_EXISTING_VARIATIONS_CONTAINER' => $existing_variation_list), array(), 'admin');
2507
-            /*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2508
-            wp_reset_query();
2509
-        } else {
2510
-            $output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2511
-        }
2347
+		return $variation_id;
2348
+	}
2512 2349
 
2513
-        return $output;
2514
-    }
2350
+	/**
2351
+	 * Get variation list for a given product
2352
+	 *
2353
+	 * @param integer $head_product The product identifier to get the variation for
2354
+	 * @return object The variation list
2355
+	 */
2356
+	public static function get_variation($head_product, $type = 'any')
2357
+	{
2358
+		global $wpdb;
2359
+		$variations_output = null;
2360
+		$args = array(
2361
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2362
+			'post_parent' => $head_product,
2363
+			'orderby' => 'ID',
2364
+			'order' => 'ASC',
2365
+			'posts_per_page' => -1,
2366
+			'post_status' => $type,
2367
+		);
2368
+		$variations = get_posts($args);
2369
+
2370
+		if (!empty($variations)) {
2371
+			$head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2372
+
2373
+			foreach ($variations as $post_def) {
2374
+				$data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post_def->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, "'valid', 'deleted'");
2375
+				foreach ($data as $content) {
2376
+					$attribute_value = 'attribute_value_' . $content->data_type;
2377
+					if (!empty($content->$attribute_value)) {
2378
+						if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2379
+							$variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2380
+						} else {
2381
+							$variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2382
+						}
2383
+					}
2384
+				}
2385
+				$variations_output[$post_def->ID]['post'] = $post_def;
2386
+			}
2387
+		}
2388
+		wp_reset_query();
2389
+		return $variations_output;
2390
+	}
2515 2391
 
2516
-    /**
2517
-     * Retrieve and display the variation for a given product
2518
-     * @param integer $product_id The product identifier to get variation for
2519
-     */
2520
-    public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2521
-    {
2522
-        global $wp_query;
2523
-        $output = '';
2524
-
2525
-        $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2526
-        $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2527
-        $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2528
-
2529
-        /**    Get attribute order for current product    */
2530
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2531
-        $output_order = array();
2532
-        if (count($product_attribute_order_detail) > 0) {
2533
-            if (!empty($product_attribute_order_detail)) {
2534
-                foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2535
-                    foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2536
-                        if (!empty($attribute_def->code)) {
2537
-                            $output_order[$attribute_def->code] = $position;
2538
-                        }
2539
-
2540
-                    }
2541
-                }
2542
-            }
2543
-        }
2392
+	/**
2393
+	 * Affichage des variations d'un produit dans l'administration
2394
+	 *
2395
+	 * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2396
+	 * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2397
+	 */
2398
+	public static function display_variation_admin($head_product)
2399
+	{
2400
+		$output = '';
2401
+		$productCurrency = wpshop_tools::wpshop_get_currency();
2402
+		/*    Récupération de la liste des variations pour le produit en cours d'édition    */
2403
+		$variations = self::get_variation($head_product);
2404
+		$price_piloting = get_option('wpshop_shop_price_piloting');
2405
+
2406
+		/*    Affichage de la liste des variations pour le produit en cours d'édition    */
2407
+		if (!empty($variations) && is_array($variations)) {
2408
+			$existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2409
+
2410
+			foreach ($variations as $variation) {
2411
+				$tpl_component = array();
2412
+
2413
+				$tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2414
+				$tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2415
+				$tpl_component['VARIATION_DETAIL'] = '  ';
2416
+				$p = (!empty($variation['variation_dif']['product_price']) || !empty($variation['variation_dif']['price_ht'])) ? ((!empty($price_piloting) && $price_piloting == 'HT' && !empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) : 0;
2417
+				$tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2418
+				if (!empty($price_piloting) && $price_piloting == 'HT') {
2419
+
2420
+				} else {
2421
+
2422
+				}
2423
+				$post_obj = $variation['post'];
2424
+
2425
+				$parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2426
+				if (!empty($parent_product_infos)) {
2427
+					$parent_post = $parent_product_infos['parent_post'];
2428
+					$product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2429
+					if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2430
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2431
+							$product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2432
+						} else {
2433
+							$product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2434
+						}
2435
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2436
+					} else {
2437
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2438
+							$product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2439
+						} else {
2440
+							$product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2441
+						}
2442
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2443
+					}
2444
+					$product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2445
+					$tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2446
+				}
2544 2447
 
2545
-        $variations_params = array();
2546
-        $variation_attribute = array();
2547
-        $variation_attribute_ordered = array();
2548
-        $possible_values = array();
2549
-        $possible_values_for_selection_calculation = array();
2550
-
2551
-        /*    Vérification de l'existence de déclinaison pour le produit    */
2552
-        $wpshop_variation_list = self::get_variation($product_id);
2553
-        if (!empty($wpshop_variation_list)) {
2554
-            foreach ($wpshop_variation_list as $variation) {
2555
-                if (!empty($variation['variation_def'])) {
2556
-                    $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2557
-                    foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2558
-                        if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2559
-                            $tpl_component = array();
2560
-
2561
-                            $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2562
-                            $default_value_is_serial = false;
2563
-                            $attribute_list_first_element = $attribute_db_definition->default_value;
2564
-                            if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2565
-                                $default_value_is_serial = true;
2566
-                                $tmp_default_value = unserialize($attribute_db_definition->default_value);
2567
-                                $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2568
-                            }
2569
-
2570
-                            if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2571
-                                $possible_values[$attribute_code][0][0] = ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) ? stripslashes(sprintf($attribute_list_first_element, strtolower($attribute_db_definition->frontend_label))) : __('Choose a value', 'wpshop');
2572
-                            }
2573
-
2574
-                            if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2575
-                                $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2576
-                                $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2577
-                            } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2578
-                                $post_def = get_post($attribute_value);
2579
-                                $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2580
-                                $position = $post_def->menu_order;
2581
-                            }
2582
-
2583
-                            if (!empty($variation['variation_dif'])) {
2584
-                                foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2585
-                                    $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2586
-                                    $the_value = $attribute_dif_value;
2587
-                                    if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2588
-                                        $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2589
-                                    }
2590
-                                    $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2591
-                                }
2592
-                            }
2593
-                            if (!empty($attribute_value)) {
2594
-                                $possible_values[$attribute_code][$position][$attribute_value] = wpshop_display::display_template_element('product_variation_item_possible_values', $tpl_component, array('type' => 'attribute_for_variation', 'id' => $attribute_code));
2595
-                                $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2596
-                            }
2597
-                            unset($tpl_component);
2598
-                        }
2599
-                    }
2600
-                }
2601
-            }
2602
-
2603
-            $variation_tpl = array();
2604
-            if (!empty($head_wpshop_variation_definition['attributes'])) {
2605
-                foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2606
-                    $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2607
-
2608
-                    if (!empty($attribute_db_definition)) {
2609
-                        $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_db_definition->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_code, 'complete_sheet');
2610
-
2611
-                        $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? true : false;
2612
-                        if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2613
-                            $is_required = true;
2614
-                        }
2615
-
2616
-                        $input_def = array();
2617
-                        $input_def['type'] = $attribute_db_definition->frontend_input;
2618
-                        $value = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : (!empty($attribute_db_definition->default_value) ? $attribute_db_definition->default_value : null);
2619
-                        if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2620
-                            unset($possible_values[$attribute_code][0]);
2621
-                            $value = array($value);
2622
-                        }
2623
-                        $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2624
-                        $input_def['name'] = $attribute_code;
2625
-                        $real_possible_values = array();
2626
-                        if (!empty($possible_values[$attribute_code])) {
2627
-                            ksort($possible_values[$attribute_code]);
2628
-                            foreach ($possible_values[$attribute_code] as $position => $def) {
2629
-                                foreach ($def as $attribute_value => $attribute_value_output) {
2630
-                                    $real_possible_values[$attribute_value] = $attribute_value_output;
2631
-                                    if (!empty($attribute_value)) {
2632
-                                        global $wpdb;
2633
-                                        $query = $wpdb->prepare("SELECT post_status FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value LIKE '%%" . serialize($attribute_code) . serialize($attribute_value) . "%%'", $product_id);
2634
-                                        if ('draft' == $wpdb->get_var($query)) {
2635
-                                            unset($real_possible_values[$attribute_value]);
2636
-                                        }
2637
-                                    }
2638
-                                }
2639
-                            }
2640
-                        }
2641
-                        $input_def['possible_value'] = $real_possible_values;
2642
-                        $input_def['valueToPut'] = 'index';
2643
-                        $input_def['value'] = $value;
2644
-
2645
-                        $input_def['options']['more_input'] = '';
2646
-                        if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2647
-                            foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2648
-                                $input_def['options']['more_input'] .= '<input type="hidden" disabled="disabled" value="' . str_replace("\\", "", $value) . '" name="' . $input_def['id'] . '_current_value" id="' . $input_def['id'] . '_current_value_' . $value_id . '" />';
2649
-                            }
2650
-                        }
2651
-
2652
-                        $input_def['options_label']['original'] = true;
2653
-                        $input_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_code . ' ' : '') . ($attribute_db_definition->_display_informations_about_value == 'yes' ? ' wpshop_display_information_about_value' : '') . ' ' . ((is_admin()) ? $attribute_db_definition->backend_css_class : $attribute_db_definition->frontend_css_class) . '" ';
2654
-
2655
-                        if (!empty($real_possible_values)) {
2656
-                            $tpl_component = array();
2657
-                            $attribute_output_def['value'] = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : $input_def['value'];
2658
-                            $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2659
-                            $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_code . '" >' . stripslashes($attribute_db_definition->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_db_definition->frontend_label));
2660
-                            $tpl_component['VARIATION_CODE'] = $attribute_code;
2661
-                            $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2662
-                            $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2663
-                            $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2664
-                            $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2665
-                            $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2666
-                            $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_code : '') . ' wpshop_variation_' . $attribute_code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2667
-                            $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2668
-                            $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2669
-                            $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2670
-                        }
2671
-
2672
-                        $variation_attribute[] = $attribute_code;
2673
-                    }
2674
-                }
2675
-            }
2448
+				if (!empty($variation['variation_def'])) {
2449
+					foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2450
+						if (!empty($variation_value)) {
2451
+							$attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2452
+							$tpl_component['VARIATION_DETAIL'] .= '<input type="hidden" name="' . self::current_page_variation_code . '[' . $variation['post']->ID . '][attribute][' . $attribute_def_for_variation->data_type . '][' . $variation_key . ']" value="' . $variation_value . '" />' . wpshop_display::display_template_element('wpshop_admin_variation_item_def_header', array('VARIATION_ATTRIBUTE_CODE' => $attribute_def_for_variation->frontend_label, 'VARIATION_ATTRIBUTE_CODE_VALUE' => stripslashes(wpshop_attributes::get_attribute_type_select_option_info($variation_value, 'label', $attribute_def_for_variation->data_type_to_use, true))), array(), 'admin');
2453
+							$tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2454
+
2455
+							/** Define Link image to variation interface **/
2456
+							if (!empty($product_option_postmeta) && !empty($product_option_postmeta['attributes']) && !empty($product_option_postmeta['variation_type']) && ((count($product_option_postmeta['attributes']) == 1 && $product_option_postmeta['variation_type'] == 'single') || ($product_option_postmeta['variation_type'] == 'combined'))) {
2457
+								$pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2458
+
2459
+								$media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2460
+								if (!empty($media_id_data)) {
2461
+									$medias_ids = explode(',', $media_id_data);
2462
+
2463
+									if (!empty($medias_ids)) {
2464
+										foreach ($medias_ids as $media_id) {
2465
+											if (!empty($media_id)) {
2466
+												$pictures[] = get_post($media_id);
2467
+											}
2468
+										}
2469
+									}
2470
+								}
2471
+
2472
+								$pictures_data = '';
2473
+								if (!empty($pictures)) {
2474
+									$selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2475
+
2476
+									$done_picture = array();
2477
+									foreach ($pictures as $picture) {
2478
+										if (!in_array($picture->ID, $done_picture)) {
2479
+											if (wp_attachment_is_image($picture->ID)) {
2480
+												$checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2481
+												$pictures_data .= wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_element', array('PICTURE_CHOICE_VARIATION_ID' => $picture->ID, 'PRODUCT_VARIATION_ID' => $variation['post']->ID, 'PICTURE_CHOICE_SELECTED' => $checked, 'PICTURE_CHOICE_VARIATION_IMG' => wp_get_attachment_image($picture->ID, 'thumbnail')), array(), 'admin');
2482
+
2483
+												$done_picture[] = $picture->ID;
2484
+											}
2485
+										}
2486
+									}
2487
+								}
2488
+
2489
+								$tpl_component['VARIATION_IMAGE_CHOICE'] = wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_container', array('PICTURE_CHOICE_CONTAINER_CONTENT' => $pictures_data), array(), 'admin');
2490
+							}
2491
+
2492
+						}
2493
+					}
2494
+				}
2676 2495
 
2677
-        }
2678
-        $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2679
-        wp_reset_query();
2680
-
2681
-        $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2682
-        if (!empty($attribute_defined_to_be_user_defined)) {
2683
-            foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2684
-                $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_not_in_variation_but_user_defined->code, $head_wpshop_variation_definition['options']['required_attributes']))) || $attribute_not_in_variation_but_user_defined->is_required == 'yes') ? true : false;
2685
-
2686
-                $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_not_in_variation_but_user_defined->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_not_in_variation_but_user_defined->code, 'complete_sheet');
2687
-                if ($attribute_display_state && array_key_exists($attribute_not_in_variation_but_user_defined->code, $output_order) && !in_array($attribute_not_in_variation_but_user_defined->code, $variation_attribute) && ($attribute_not_in_variation_but_user_defined->is_used_for_variation == 'no')) {
2688
-                    $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_not_in_variation_but_user_defined, (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code] : ''));
2689
-
2690
-                    $tpl_component = array();
2691
-                    $attribute_output_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_not_in_variation_but_user_defined->code : '') . ' ' . (str_replace('"', '', str_replace('class="', '', $attribute_output_def['option']))) . ' ' . ((is_admin()) ? $attribute_not_in_variation_but_user_defined->backend_css_class : $attribute_not_in_variation_but_user_defined->frontend_css_class) . '" ';
2692
-                    $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2693
-                    $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_not_in_variation_but_user_defined->code . '" >' . stripslashes($attribute_not_in_variation_but_user_defined->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_not_in_variation_but_user_defined->frontend_label));
2694
-                    $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2695
-                    $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' title="' . $attribute_not_in_variation_but_user_defined->frontend_help_message . '" ' : '';
2696
-                    $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2697
-                    $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2698
-                    $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2699
-                    $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2700
-                    $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2701
-                    $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_not_in_variation_but_user_defined->code : '') . ' wpshop_variation_' . $attribute_not_in_variation_but_user_defined->code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2702
-                    $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)] = ($attribute_output_def['type'] != 'hidden') ? wpshop_display::display_template_element('product_variation_item', $tpl_component) : wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2703
-                    $variation_attribute_ordered[$output_order[$attribute_not_in_variation_but_user_defined->code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)];
2704
-                }
2705
-            }
2706
-        }
2707
-        $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2708
-        if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2709
-            ksort($variation_attribute_ordered);
2710
-            foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2711
-                $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2712
-            }
2713
-        }
2714
-        $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2715
-        $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2716
-        if ($from_admin && !empty($order_id)) {
2717
-            $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2718
-            $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2719
-        }
2720
-        $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2496
+				$tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2721 2497
 
2722
-        return $output;
2723
-    }
2498
+				$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2499
+				$tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('post_id' => $variation['post']->ID, 'input_class' => ' ', 'field_name' => wpshop_products::current_page_variation_code . '[' . $variation['post']->ID . ']', 'page_code' => self::current_page_variation_code, 'field_id' => self::current_page_variation_code . '_' . $variation['post']->ID, 'variation_dif_values' => (!empty($variation['variation_dif']) ? $variation['variation_dif'] : array())));
2500
+				$tpl_component['VARIATION_DEFINITION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2724 2501
 
2725
-    public static function get_parent_variation($variation_id)
2726
-    {
2727
-        $result = array();
2728
-        if (!empty($variation_id)) {
2729
-            $variation_post = get_post($variation_id);
2730
-            if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2731
-                $result['parent_post'] = get_post($variation_post->post_parent);
2732
-                $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2733
-            }
2734
-        }
2735
-        return $result;
2736
-    }
2502
+				/*    Add the variation definition to output    */
2503
+				$existing_variation_list .= wpshop_display::display_template_element('wpshop_admin_variation_item_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2504
+			}
2737 2505
 
2738
-    /**
2739
-     * Display the current configuration for a given product
2740
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2741
-     */
2742
-    public function wpshop_product_variations_summary($shortcode_attribute)
2743
-    {
2744
-        $output = '';
2745
-
2746
-        $product_variations_selection_args = array(
2747
-            'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2748
-            'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2749
-        );
2750
-
2751
-        $current_user_id = get_current_user_id();
2752
-
2753
-        if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2754
-            foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2755
-                if (!empty($item) && !empty($item['item_id'])) {
2756
-
2757
-                    $free_variations = array();
2758
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2759
-                        foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2760
-                            $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2761
-                        }
2762
-                    }
2763
-
2764
-                    $variations = array();
2765
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2766
-                        foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2767
-
2768
-                            if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2769
-                                foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2770
-                                    $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2771
-                                }
2772
-                            }
2773
-                        }
2774
-                    }
2775
-                    $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2776
-
2777
-                    $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2778
-                }
2779
-            }
2780
-        }
2506
+			$output .= wpshop_display::display_template_element('wpshop_admin_existing_variation_list', array('ADMIN_EXISTING_VARIATIONS_CONTAINER_CLASS' => '', 'ADMIN_EXISTING_VARIATIONS_CONTAINER' => $existing_variation_list), array(), 'admin');
2507
+			/*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2508
+			wp_reset_query();
2509
+		} else {
2510
+			$output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2511
+		}
2781 2512
 
2782
-        $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2513
+		return $output;
2514
+	}
2783 2515
 
2784
-        echo $output;
2785
-    }
2516
+	/**
2517
+	 * Retrieve and display the variation for a given product
2518
+	 * @param integer $product_id The product identifier to get variation for
2519
+	 */
2520
+	public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2521
+	{
2522
+		global $wp_query;
2523
+		$output = '';
2524
+
2525
+		$product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2526
+		$wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2527
+		$head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2528
+
2529
+		/**    Get attribute order for current product    */
2530
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2531
+		$output_order = array();
2532
+		if (count($product_attribute_order_detail) > 0) {
2533
+			if (!empty($product_attribute_order_detail)) {
2534
+				foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2535
+					foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2536
+						if (!empty($attribute_def->code)) {
2537
+							$output_order[$attribute_def->code] = $position;
2538
+						}
2539
+
2540
+					}
2541
+				}
2542
+			}
2543
+		}
2544
+
2545
+		$variations_params = array();
2546
+		$variation_attribute = array();
2547
+		$variation_attribute_ordered = array();
2548
+		$possible_values = array();
2549
+		$possible_values_for_selection_calculation = array();
2550
+
2551
+		/*    Vérification de l'existence de déclinaison pour le produit    */
2552
+		$wpshop_variation_list = self::get_variation($product_id);
2553
+		if (!empty($wpshop_variation_list)) {
2554
+			foreach ($wpshop_variation_list as $variation) {
2555
+				if (!empty($variation['variation_def'])) {
2556
+					$display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2557
+					foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2558
+						if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2559
+							$tpl_component = array();
2560
+
2561
+							$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2562
+							$default_value_is_serial = false;
2563
+							$attribute_list_first_element = $attribute_db_definition->default_value;
2564
+							if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2565
+								$default_value_is_serial = true;
2566
+								$tmp_default_value = unserialize($attribute_db_definition->default_value);
2567
+								$attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2568
+							}
2569
+
2570
+							if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2571
+								$possible_values[$attribute_code][0][0] = ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) ? stripslashes(sprintf($attribute_list_first_element, strtolower($attribute_db_definition->frontend_label))) : __('Choose a value', 'wpshop');
2572
+							}
2573
+
2574
+							if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2575
+								$tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2576
+								$position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2577
+							} else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2578
+								$post_def = get_post($attribute_value);
2579
+								$tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2580
+								$position = $post_def->menu_order;
2581
+							}
2582
+
2583
+							if (!empty($variation['variation_dif'])) {
2584
+								foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2585
+									$wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2586
+									$the_value = $attribute_dif_value;
2587
+									if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2588
+										$the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2589
+									}
2590
+									$tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2591
+								}
2592
+							}
2593
+							if (!empty($attribute_value)) {
2594
+								$possible_values[$attribute_code][$position][$attribute_value] = wpshop_display::display_template_element('product_variation_item_possible_values', $tpl_component, array('type' => 'attribute_for_variation', 'id' => $attribute_code));
2595
+								$possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2596
+							}
2597
+							unset($tpl_component);
2598
+						}
2599
+					}
2600
+				}
2601
+			}
2602
+
2603
+			$variation_tpl = array();
2604
+			if (!empty($head_wpshop_variation_definition['attributes'])) {
2605
+				foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2606
+					$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2607
+
2608
+					if (!empty($attribute_db_definition)) {
2609
+						$attribute_display_state = wpshop_attributes::check_attribute_display($attribute_db_definition->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_code, 'complete_sheet');
2610
+
2611
+						$is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? true : false;
2612
+						if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2613
+							$is_required = true;
2614
+						}
2615
+
2616
+						$input_def = array();
2617
+						$input_def['type'] = $attribute_db_definition->frontend_input;
2618
+						$value = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : (!empty($attribute_db_definition->default_value) ? $attribute_db_definition->default_value : null);
2619
+						if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2620
+							unset($possible_values[$attribute_code][0]);
2621
+							$value = array($value);
2622
+						}
2623
+						$input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2624
+						$input_def['name'] = $attribute_code;
2625
+						$real_possible_values = array();
2626
+						if (!empty($possible_values[$attribute_code])) {
2627
+							ksort($possible_values[$attribute_code]);
2628
+							foreach ($possible_values[$attribute_code] as $position => $def) {
2629
+								foreach ($def as $attribute_value => $attribute_value_output) {
2630
+									$real_possible_values[$attribute_value] = $attribute_value_output;
2631
+									if (!empty($attribute_value)) {
2632
+										global $wpdb;
2633
+										$query = $wpdb->prepare("SELECT post_status FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value LIKE '%%" . serialize($attribute_code) . serialize($attribute_value) . "%%'", $product_id);
2634
+										if ('draft' == $wpdb->get_var($query)) {
2635
+											unset($real_possible_values[$attribute_value]);
2636
+										}
2637
+									}
2638
+								}
2639
+							}
2640
+						}
2641
+						$input_def['possible_value'] = $real_possible_values;
2642
+						$input_def['valueToPut'] = 'index';
2643
+						$input_def['value'] = $value;
2644
+
2645
+						$input_def['options']['more_input'] = '';
2646
+						if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2647
+							foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2648
+								$input_def['options']['more_input'] .= '<input type="hidden" disabled="disabled" value="' . str_replace("\\", "", $value) . '" name="' . $input_def['id'] . '_current_value" id="' . $input_def['id'] . '_current_value_' . $value_id . '" />';
2649
+							}
2650
+						}
2651
+
2652
+						$input_def['options_label']['original'] = true;
2653
+						$input_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_code . ' ' : '') . ($attribute_db_definition->_display_informations_about_value == 'yes' ? ' wpshop_display_information_about_value' : '') . ' ' . ((is_admin()) ? $attribute_db_definition->backend_css_class : $attribute_db_definition->frontend_css_class) . '" ';
2654
+
2655
+						if (!empty($real_possible_values)) {
2656
+							$tpl_component = array();
2657
+							$attribute_output_def['value'] = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : $input_def['value'];
2658
+							$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2659
+							$tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_code . '" >' . stripslashes($attribute_db_definition->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_db_definition->frontend_label));
2660
+							$tpl_component['VARIATION_CODE'] = $attribute_code;
2661
+							$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2662
+							$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2663
+							$tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2664
+							$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2665
+							$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2666
+							$tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_code : '') . ' wpshop_variation_' . $attribute_code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2667
+							$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2668
+							$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2669
+							$variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2670
+						}
2671
+
2672
+						$variation_attribute[] = $attribute_code;
2673
+					}
2674
+				}
2675
+			}
2786 2676
 
2787
-    /**
2788
-     * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2789
-     *
2790
-     * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2791
-     * @param array $wpshop_variation_selected La liste des options ayant un prix sélectionnées par le client / Options list with price selected by the customer
2792
-     * @param array $wpshop_free_variation La liste des options n'entrainant pas de modification du prix final sélectionnées par le client / Options list without price selected by the customer
2793
-     * @param string $wpshop_current_for_display Inconnu / Unknown
2794
-     * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2795
-     *
2796
-     * @return array Le résultat du calcul pour l'affichage / Output result
2797
-     */
2798
-    public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2799
-    {
2800
-        global $wpdb;
2801
-
2802
-        $wpshop_cart = new wps_cart();
2803
-        $wpshop_products = new wpshop_products();
2804
-
2805
-        $response = '';
2806
-        $response_status = $has_variation = false;
2807
-        $tpl_component = array();
2808
-
2809
-        // Check if variations exists
2810
-        if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2811
-
2812
-            //Recover all selected variations
2813
-            $variations_selected = array();
2814
-            if (!empty($wpshop_variation_selected)) {
2815
-                foreach ($wpshop_variation_selected as $selected_variation) {
2816
-                    $variation_definition = explode('-_variation_val_-', $selected_variation);
2817
-                    $variations_selected[$variation_definition[0]] = $variation_definition[1];
2818
-                }
2819
-            }
2820
-
2821
-            // Check variations priority
2822
-            $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2823
-
2824
-            // Check if $product_with_variation have variations
2825
-            if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2826
-
2827
-                $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2828
-                $product_to_add_to_cart = $formatted_product[0];
2829
-                foreach ($formatted_product[0] as $pid => $product_more_content) {
2830
-                    $order_items[$pid]['product_id'] = $product_more_content['id'];
2831
-
2832
-                    /** For product with variation    */
2833
-                    $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2834
-                    $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2835
-                    $order_items[$pid]['product_variation'] = '';
2836
-                    if (!empty($product_more_content['variations'])) {
2837
-                        foreach ($product_more_content['variations'] as $variation_id) {
2838
-                            $order_items[$pid]['product_variation'][] = $variation_id;
2839
-                        }
2840
-                    }
2841
-                }
2842
-
2843
-                // If Product list is not empty, add products to order
2844
-                if (!empty($order_items)) {
2845
-                    foreach ($order_items as $product_id => $d) {
2846
-                        $product_key = $product_id;
2847
-
2848
-                        // Formate datas
2849
-                        $product_id = $head_product_id = $d['product_id'];
2850
-                        $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2851
-
2852
-                        // If product is a single variation product
2853
-                        if (!empty($product_variation) && (count($product_variation) == 1)) {
2854
-                            $product_id = $product_variation[0];
2855
-                        }
2856
-
2857
-                        // Construct final product
2858
-                        $product = wpshop_products::get_product_data($d['product_id'], true);
2859
-                        $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2677
+		}
2678
+		$variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2679
+		wp_reset_query();
2680
+
2681
+		$attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2682
+		if (!empty($attribute_defined_to_be_user_defined)) {
2683
+			foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2684
+				$is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_not_in_variation_but_user_defined->code, $head_wpshop_variation_definition['options']['required_attributes']))) || $attribute_not_in_variation_but_user_defined->is_required == 'yes') ? true : false;
2685
+
2686
+				$attribute_display_state = wpshop_attributes::check_attribute_display($attribute_not_in_variation_but_user_defined->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_not_in_variation_but_user_defined->code, 'complete_sheet');
2687
+				if ($attribute_display_state && array_key_exists($attribute_not_in_variation_but_user_defined->code, $output_order) && !in_array($attribute_not_in_variation_but_user_defined->code, $variation_attribute) && ($attribute_not_in_variation_but_user_defined->is_used_for_variation == 'no')) {
2688
+					$attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_not_in_variation_but_user_defined, (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code] : ''));
2689
+
2690
+					$tpl_component = array();
2691
+					$attribute_output_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_not_in_variation_but_user_defined->code : '') . ' ' . (str_replace('"', '', str_replace('class="', '', $attribute_output_def['option']))) . ' ' . ((is_admin()) ? $attribute_not_in_variation_but_user_defined->backend_css_class : $attribute_not_in_variation_but_user_defined->frontend_css_class) . '" ';
2692
+					$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2693
+					$tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_not_in_variation_but_user_defined->code . '" >' . stripslashes($attribute_not_in_variation_but_user_defined->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_not_in_variation_but_user_defined->frontend_label));
2694
+					$tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2695
+					$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' title="' . $attribute_not_in_variation_but_user_defined->frontend_help_message . '" ' : '';
2696
+					$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2697
+					$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2698
+					$tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2699
+					$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2700
+					$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2701
+					$tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_not_in_variation_but_user_defined->code : '') . ' wpshop_variation_' . $attribute_not_in_variation_but_user_defined->code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2702
+					$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)] = ($attribute_output_def['type'] != 'hidden') ? wpshop_display::display_template_element('product_variation_item', $tpl_component) : wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2703
+					$variation_attribute_ordered[$output_order[$attribute_not_in_variation_but_user_defined->code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)];
2704
+				}
2705
+			}
2706
+		}
2707
+		$variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2708
+		if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2709
+			ksort($variation_attribute_ordered);
2710
+			foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2711
+				$variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2712
+			}
2713
+		}
2714
+		$variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2715
+		$variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2716
+		if ($from_admin && !empty($order_id)) {
2717
+			$variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2718
+			$variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2719
+		}
2720
+		$output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2721
+
2722
+		return $output;
2723
+	}
2724
+
2725
+	public static function get_parent_variation($variation_id)
2726
+	{
2727
+		$result = array();
2728
+		if (!empty($variation_id)) {
2729
+			$variation_post = get_post($variation_id);
2730
+			if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2731
+				$result['parent_post'] = get_post($variation_post->post_parent);
2732
+				$result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2733
+			}
2734
+		}
2735
+		return $result;
2736
+	}
2737
+
2738
+	/**
2739
+	 * Display the current configuration for a given product
2740
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2741
+	 */
2742
+	public function wpshop_product_variations_summary($shortcode_attribute)
2743
+	{
2744
+		$output = '';
2745
+
2746
+		$product_variations_selection_args = array(
2747
+			'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2748
+			'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2749
+		);
2750
+
2751
+		$current_user_id = get_current_user_id();
2752
+
2753
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2754
+			foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2755
+				if (!empty($item) && !empty($item['item_id'])) {
2756
+
2757
+					$free_variations = array();
2758
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2759
+						foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2760
+							$free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2761
+						}
2762
+					}
2763
+
2764
+					$variations = array();
2765
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2766
+						foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2767
+
2768
+							if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2769
+								foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2770
+									$variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2771
+								}
2772
+							}
2773
+						}
2774
+					}
2775
+					$product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2776
+
2777
+					$product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2778
+				}
2779
+			}
2780
+		}
2781
+
2782
+		$output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2783
+
2784
+		echo $output;
2785
+	}
2786
+
2787
+	/**
2788
+	 * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2789
+	 *
2790
+	 * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2791
+	 * @param array $wpshop_variation_selected La liste des options ayant un prix sélectionnées par le client / Options list with price selected by the customer
2792
+	 * @param array $wpshop_free_variation La liste des options n'entrainant pas de modification du prix final sélectionnées par le client / Options list without price selected by the customer
2793
+	 * @param string $wpshop_current_for_display Inconnu / Unknown
2794
+	 * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2795
+	 *
2796
+	 * @return array Le résultat du calcul pour l'affichage / Output result
2797
+	 */
2798
+	public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2799
+	{
2800
+		global $wpdb;
2801
+
2802
+		$wpshop_cart = new wps_cart();
2803
+		$wpshop_products = new wpshop_products();
2804
+
2805
+		$response = '';
2806
+		$response_status = $has_variation = false;
2807
+		$tpl_component = array();
2808
+
2809
+		// Check if variations exists
2810
+		if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2811
+
2812
+			//Recover all selected variations
2813
+			$variations_selected = array();
2814
+			if (!empty($wpshop_variation_selected)) {
2815
+				foreach ($wpshop_variation_selected as $selected_variation) {
2816
+					$variation_definition = explode('-_variation_val_-', $selected_variation);
2817
+					$variations_selected[$variation_definition[0]] = $variation_definition[1];
2818
+				}
2819
+			}
2820
+
2821
+			// Check variations priority
2822
+			$product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2823
+
2824
+			// Check if $product_with_variation have variations
2825
+			if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2826
+
2827
+				$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2828
+				$product_to_add_to_cart = $formatted_product[0];
2829
+				foreach ($formatted_product[0] as $pid => $product_more_content) {
2830
+					$order_items[$pid]['product_id'] = $product_more_content['id'];
2831
+
2832
+					/** For product with variation    */
2833
+					$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2834
+					$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2835
+					$order_items[$pid]['product_variation'] = '';
2836
+					if (!empty($product_more_content['variations'])) {
2837
+						foreach ($product_more_content['variations'] as $variation_id) {
2838
+							$order_items[$pid]['product_variation'][] = $variation_id;
2839
+						}
2840
+					}
2841
+				}
2842
+
2843
+				// If Product list is not empty, add products to order
2844
+				if (!empty($order_items)) {
2845
+					foreach ($order_items as $product_id => $d) {
2846
+						$product_key = $product_id;
2847
+
2848
+						// Formate datas
2849
+						$product_id = $head_product_id = $d['product_id'];
2850
+						$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2851
+
2852
+						// If product is a single variation product
2853
+						if (!empty($product_variation) && (count($product_variation) == 1)) {
2854
+							$product_id = $product_variation[0];
2855
+						}
2856
+
2857
+						// Construct final product
2858
+						$product = wpshop_products::get_product_data($d['product_id'], true);
2859
+						$the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2860 2860
 						$the_product['text_from'] = $product_with_variation['text_from'];
2861 2861
 
2862
-                        //    Add variation to product into cart for storage
2863
-                        if (!empty($product_variation)) {
2864
-                            $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2865
-                        }
2866
-
2867
-                        // Free Variations Checking
2868
-                        if (!empty($d['free_variation'])) {
2869
-                            $the_product['item_meta']['free_variation'] = $d['free_variation'];
2870
-                            $head_product_id = $the_product['product_id'];
2871
-                        }
2872
-
2873
-                        // If product is a variation, we check parent product general
2874
-                        if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2875
-                            $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2876
-                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2877
-                                $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2878
-                                $parent_meta = $parent_def['parent_post_meta'];
2879
-                                if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) {
2880
-                                    $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2881
-                                    $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2882
-                                    $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2883
-                                }
2884
-                            }
2885
-                        }
2886
-                    }
2887
-                }
2888
-
2889
-                if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2890
-                    $price_infos = wpshop_prices::check_product_price($the_product, true);
2891
-                    if (!empty($price_infos['discount']['discount_exist'])) {
2892
-                        $the_product['price_ttc_before_discount'] = $the_product['product_price'];
2893
-                        $the_product['price_ht_before_discount'] = $the_product['price_ht'];
2894
-                    }
2895
-                    $the_product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
2896
-                    $the_product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
2897
-                    $the_product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
2898
-                }
2899
-
2900
-                $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2901
-                // Add free variations to product
2902
-                if (!empty($wpshop_free_variation)) {
2903
-                    $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2904
-                }
2905
-                // Change picture if have a selected variation
2906
-                $the_selected_variation = !empty($product_with_variation) && !empty($product_with_variation[$head_product_id]) && !empty($product_with_variation[$head_product_id]['variations']) ? $product_with_variation[$head_product_id]['variations'] : null;
2907
-                $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2908
-
2909
-                // Price Display
2910
-                $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2911
-                $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2912
-                $productPrice = '';
2913
-                if ($price_display) {
2914
-                    $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2915
-                }
2916
-
2917
-                //Get Summary cart
2918
-                $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2919
-                $response_status = true;
2920
-            } else {
2921
-                //Product without variations
2922
-                $product_data = wpshop_products::get_product_data($product_id);
2923
-                $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2862
+						//    Add variation to product into cart for storage
2863
+						if (!empty($product_variation)) {
2864
+							$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2865
+						}
2866
+
2867
+						// Free Variations Checking
2868
+						if (!empty($d['free_variation'])) {
2869
+							$the_product['item_meta']['free_variation'] = $d['free_variation'];
2870
+							$head_product_id = $the_product['product_id'];
2871
+						}
2872
+
2873
+						// If product is a variation, we check parent product general
2874
+						if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2875
+							$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2876
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2877
+								$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2878
+								$parent_meta = $parent_def['parent_post_meta'];
2879
+								if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) {
2880
+									$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2881
+									$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2882
+									$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2883
+								}
2884
+							}
2885
+						}
2886
+					}
2887
+				}
2888
+
2889
+				if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2890
+					$price_infos = wpshop_prices::check_product_price($the_product, true);
2891
+					if (!empty($price_infos['discount']['discount_exist'])) {
2892
+						$the_product['price_ttc_before_discount'] = $the_product['product_price'];
2893
+						$the_product['price_ht_before_discount'] = $the_product['price_ht'];
2894
+					}
2895
+					$the_product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
2896
+					$the_product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
2897
+					$the_product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
2898
+				}
2899
+
2900
+				$product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2901
+				// Add free variations to product
2902
+				if (!empty($wpshop_free_variation)) {
2903
+					$the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2904
+				}
2905
+				// Change picture if have a selected variation
2906
+				$the_selected_variation = !empty($product_with_variation) && !empty($product_with_variation[$head_product_id]) && !empty($product_with_variation[$head_product_id]['variations']) ? $product_with_variation[$head_product_id]['variations'] : null;
2907
+				$response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2908
+
2909
+				// Price Display
2910
+				$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2911
+				$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2912
+				$productPrice = '';
2913
+				if ($price_display) {
2914
+					$response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2915
+				}
2916
+
2917
+				//Get Summary cart
2918
+				$response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2924 2919
 				$response_status = true;
2925
-            }
2926
-        }
2920
+			} else {
2921
+				//Product without variations
2922
+				$product_data = wpshop_products::get_product_data($product_id);
2923
+				$response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2924
+				$response_status = true;
2925
+			}
2926
+		}
2927 2927
 
2928
-        return array($response_status, $response);
2929
-    }
2928
+		return array($response_status, $response);
2929
+	}
2930 2930
 
2931
-    /**
2932
-     * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2933
-     *
2934
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2935
-     */
2936
-    public function wpshop_product_variation_value_detail($shortcode_attribute)
2937
-    {
2938
-        echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2939
-    }
2931
+	/**
2932
+	 * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2933
+	 *
2934
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2935
+	 */
2936
+	public function wpshop_product_variation_value_detail($shortcode_attribute)
2937
+	{
2938
+		echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2939
+	}
2940 2940
 
2941
-    /**
2942
-     * Build the product structure with variation for product choosed by the user into frontend sheet
2943
-     *
2944
-     * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2945
-     * @param integer $product_id The basic product choose by the user in frontend
2946
-     *
2947
-     * @return array The product list for adding to the cart build by variation priority
2948
-     */
2949
-    public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2950
-    {
2951
-        global $wpdb;
2952
-        $all_required_variations_selected = $no_selected_variation = true;
2953
-        $single_variations = $combined_variations = $product_to_add_to_cart = array();
2954
-
2955
-        // Check if all required variations are selected
2956
-        $required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2957
-        foreach ($selected_variation as $k => $value) {
2958
-            if ($value == 0 && in_array($k, $required_attributes_list)) {
2959
-                $all_required_variations_selected = false;
2960
-            }
2961
-            if ($value != 0) {
2962
-                $no_selected_variation = false;
2963
-            }
2964
-        }
2965
-        if (!empty($selected_variation)) {
2966
-            //Check variations configuration
2967
-            $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
2968
-            // Check variations type
2969
-            $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
2970
-            $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
2971
-
2972
-            //Check defined variation priority
2973
-            $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
2974
-            $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
2975
-
2976
-            // Recover all product variations
2977
-            $query_variation = $selected_variation;
2978
-            // Delete free variations
2979
-            unset($query_variation['free']);
2980
-
2981
-            if ($product_variation_type == 'single') {
2982
-                // Get single variations
2983
-                $single_variations = array();
2984
-                foreach ($selected_variation as $attribute_code => $attribute_value) {
2985
-                    if (isset($attribute_value) && $attribute_code != 'free') {
2986
-                        $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id);
2987
-                        $single_variation_id = $wpdb->get_var($query);
2988
-                        if (!empty($single_variation_id)) {
2989
-                            $single_variations[] = $single_variation_id;
2990
-                            unset($query_variation[$attribute_code]);
2991
-                        }
2992
-                    }
2993
-                }
2994
-            } else {
2995
-                // Get combined variations
2996
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_key = '_wpshop_variations_attribute_def' AND P_META.meta_value = '" . serialize($query_variation) . "'", $product_id);
2997
-                $combined_variation_id = $wpdb->get_var($query);
2998
-                if (!empty($combined_variation_id)) {
2999
-                    $combined_variations[] = $combined_variation_id;
3000
-                }
3001
-
3002
-            }
3003
-
3004
-            //If all required variations are not selected
3005
-            if (!$all_required_variations_selected || $no_selected_variation) {
3006
-                $product_to_add_to_cart['text_from'] = 'on';
3007
-                // If we choose to display lower price variation combinaison
3008
-                if (empty($product_variation_configuration) || (!empty($product_variation_configuration) && empty($product_variation_configuration['options'])) || (!empty($product_variation_configuration) && !empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['price_display']) && !empty($product_variation_configuration['options']['price_display']['lower_price']))) {
3009
-                    //Get lower price variation combinaison
3010
-                    $lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3011
-                    if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3012
-                        foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3013
-                            $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3014
-                        }
3015
-                    }
3016
-                    $product_to_add_to_cart['display_lower_price'] = true;
3017
-                } else {
3018
-                    $product_to_add_to_cart[$product_id]['variations'] = array();
3019
-                }
3020
-            } else {
3021
-                $product_to_add_to_cart['text_from'] = '';
3022
-                $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3023
-            }
3024
-        }
2941
+	/**
2942
+	 * Build the product structure with variation for product choosed by the user into frontend sheet
2943
+	 *
2944
+	 * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2945
+	 * @param integer $product_id The basic product choose by the user in frontend
2946
+	 *
2947
+	 * @return array The product list for adding to the cart build by variation priority
2948
+	 */
2949
+	public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2950
+	{
2951
+		global $wpdb;
2952
+		$all_required_variations_selected = $no_selected_variation = true;
2953
+		$single_variations = $combined_variations = $product_to_add_to_cart = array();
2954
+
2955
+		// Check if all required variations are selected
2956
+		$required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2957
+		foreach ($selected_variation as $k => $value) {
2958
+			if ($value == 0 && in_array($k, $required_attributes_list)) {
2959
+				$all_required_variations_selected = false;
2960
+			}
2961
+			if ($value != 0) {
2962
+				$no_selected_variation = false;
2963
+			}
2964
+		}
2965
+		if (!empty($selected_variation)) {
2966
+			//Check variations configuration
2967
+			$product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
2968
+			// Check variations type
2969
+			$product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
2970
+			$product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
2971
+
2972
+			//Check defined variation priority
2973
+			$priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
2974
+			$product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
2975
+
2976
+			// Recover all product variations
2977
+			$query_variation = $selected_variation;
2978
+			// Delete free variations
2979
+			unset($query_variation['free']);
2980
+
2981
+			if ($product_variation_type == 'single') {
2982
+				// Get single variations
2983
+				$single_variations = array();
2984
+				foreach ($selected_variation as $attribute_code => $attribute_value) {
2985
+					if (isset($attribute_value) && $attribute_code != 'free') {
2986
+						$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id);
2987
+						$single_variation_id = $wpdb->get_var($query);
2988
+						if (!empty($single_variation_id)) {
2989
+							$single_variations[] = $single_variation_id;
2990
+							unset($query_variation[$attribute_code]);
2991
+						}
2992
+					}
2993
+				}
2994
+			} else {
2995
+				// Get combined variations
2996
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_key = '_wpshop_variations_attribute_def' AND P_META.meta_value = '" . serialize($query_variation) . "'", $product_id);
2997
+				$combined_variation_id = $wpdb->get_var($query);
2998
+				if (!empty($combined_variation_id)) {
2999
+					$combined_variations[] = $combined_variation_id;
3000
+				}
3025 3001
 
3026
-        return $product_to_add_to_cart;
3027
-    }
3002
+			}
3028 3003
 
3029
-    public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3030
-    {
3031
-        global $wpdb;
3032
-
3033
-        if (!empty($product_variations)) {
3034
-            // Initialize variations total price datas
3035
-            $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3036
-            $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3037
-            $vat_rate = 0;
3038
-            $discount_amount = $discount_rate = $special_price = 0;
3039
-            // Recover Head product metadata
3040
-            $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3041
-            $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3042
-            if (!empty($tva_rate_id)) {
3043
-                // Recover VAT Rate of product
3044
-                $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3045
-                $vat_rate = $wpdb->get_var($query);
3046
-            }
3047
-            $price_piloting = get_option('wpshop_shop_price_piloting');
3048
-            foreach ($product_variations as $product_variation) {
3049
-                $variation_metadata['product_price'] = 0;
3050
-                $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3051
-                if (!empty($variation_metadata)) {
3052
-                    $p_et = ((empty($price_piloting) || $price_piloting == 'TTC') ? ((!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + ($vat_rate / 100))) : $variation_metadata['price_ht']);
3053
-                    $p_ati = ((empty($price_piloting) || $price_piloting == 'TTC') ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) : ($variation_metadata['price_ht'] * (1 + ($vat_rate / 100))));
3054
-
3055
-                    $variations_total_price['price_et'] += $p_et;
3056
-                    $variations_total_price['price_ati'] += $p_ati;
3057
-                    $variations_total_price['vat_amount'] += $p_ati - $p_et;
3058
-
3059
-                    $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3060
-
3061
-                    // Check discount
3062
-                    $discount_config = wpshop_prices::check_discount_for_product($product_variation);
3063
-                    if (!empty($discount_config) && !empty($discount_config['value'])) {
3064
-                        $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3065
-                        $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3066
-                        $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3067
-                        $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3068
-
3069
-                        if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3070
-                            $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3071
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3072
-                            $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3073
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3074
-                            $product_into_cart['special_price'] = $special_price + $discount_config['value'];
3075
-                        }
3076
-                    }
3077
-
3078
-                    $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3079
-                    $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3080
-                }
3081
-            }
3082
-
3083
-            // Check if add or replace variation price to head product
3084
-            /**
3085
-             * Since 1.4.3.7
3086
-             * L'option du produit remplace le prix du produit de tête.
3087
-             */
3004
+			//If all required variations are not selected
3005
+			if (!$all_required_variations_selected || $no_selected_variation) {
3006
+				$product_to_add_to_cart['text_from'] = 'on';
3007
+				// If we choose to display lower price variation combinaison
3008
+				if (empty($product_variation_configuration) || (!empty($product_variation_configuration) && empty($product_variation_configuration['options'])) || (!empty($product_variation_configuration) && !empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['price_display']) && !empty($product_variation_configuration['options']['price_display']['lower_price']))) {
3009
+					//Get lower price variation combinaison
3010
+					$lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3011
+					if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3012
+						foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3013
+							$product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3014
+						}
3015
+					}
3016
+					$product_to_add_to_cart['display_lower_price'] = true;
3017
+				} else {
3018
+					$product_to_add_to_cart[$product_id]['variations'] = array();
3019
+				}
3020
+			} else {
3021
+				$product_to_add_to_cart['text_from'] = '';
3022
+				$product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3023
+			}
3024
+		}
3025
+
3026
+		return $product_to_add_to_cart;
3027
+	}
3028
+
3029
+	public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3030
+	{
3031
+		global $wpdb;
3032
+
3033
+		if (!empty($product_variations)) {
3034
+			// Initialize variations total price datas
3035
+			$variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3036
+			$variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3037
+			$vat_rate = 0;
3038
+			$discount_amount = $discount_rate = $special_price = 0;
3039
+			// Recover Head product metadata
3040
+			$head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3041
+			$tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3042
+			if (!empty($tva_rate_id)) {
3043
+				// Recover VAT Rate of product
3044
+				$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3045
+				$vat_rate = $wpdb->get_var($query);
3046
+			}
3047
+			$price_piloting = get_option('wpshop_shop_price_piloting');
3048
+			foreach ($product_variations as $product_variation) {
3049
+				$variation_metadata['product_price'] = 0;
3050
+				$variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3051
+				if (!empty($variation_metadata)) {
3052
+					$p_et = ((empty($price_piloting) || $price_piloting == 'TTC') ? ((!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + ($vat_rate / 100))) : $variation_metadata['price_ht']);
3053
+					$p_ati = ((empty($price_piloting) || $price_piloting == 'TTC') ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) : ($variation_metadata['price_ht'] * (1 + ($vat_rate / 100))));
3054
+
3055
+					$variations_total_price['price_et'] += $p_et;
3056
+					$variations_total_price['price_ati'] += $p_ati;
3057
+					$variations_total_price['vat_amount'] += $p_ati - $p_et;
3058
+
3059
+					$variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3060
+
3061
+					// Check discount
3062
+					$discount_config = wpshop_prices::check_discount_for_product($product_variation);
3063
+					if (!empty($discount_config) && !empty($discount_config['value'])) {
3064
+						$variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3065
+						$variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3066
+						$variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3067
+						$variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3068
+
3069
+						if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3070
+							$product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3071
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3072
+							$product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3073
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3074
+							$product_into_cart['special_price'] = $special_price + $discount_config['value'];
3075
+						}
3076
+					}
3077
+
3078
+					$product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3079
+					$product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3080
+				}
3081
+			}
3082
+
3083
+			// Check if add or replace variation price to head product
3084
+			/**
3085
+			 * Since 1.4.3.7
3086
+			 * L'option du produit remplace le prix du produit de tête.
3087
+			 */
3088 3088
 			if( true ) {
3089
-                //Replace the product price
3090
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3091
-                    $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3092
-                    $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3093
-
3094
-                    $product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3095
-                    $product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3096
-                    $product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3097
-                } else {
3098
-                    $product_into_cart['product_price'] = $variations_total_price['price_ati'];
3099
-                    $product_into_cart['price_ht'] = $variations_total_price['price_et'];
3100
-                    $product_into_cart['tva'] = $variations_total_price['vat_amount'];
3101
-                }
3102
-            } else {
3103
-                // Add variations price to product price
3104
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3105
-                    $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3106
-                    $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3107
-
3108
-                    $product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3109
-                    $product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3110
-                    $product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3111
-                } else {
3112
-                    $product_into_cart['product_price'] += $variations_total_price['price_ati'];
3113
-                    $product_into_cart['price_ht'] += $variations_total_price['price_et'];
3114
-                    $product_into_cart['tva'] += $variations_total_price['vat_amount'];
3115
-                }
3116
-                // Check parent discount
3117
-                $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3118
-                if (!empty($parent_discount_config)) {
3119
-                    $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3120
-                    $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3121
-                    $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3122
-
3123
-                    if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3124
-                        $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3125
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3126
-                        $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3127
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3128
-                        $product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3129
-                    }
3130
-                }
3131
-            }
3132
-        } else {
3133
-            // If product have just Free variations
3134
-            $discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3135
-            if (!empty($discount_config)) {
3136
-                $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3137
-                $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3138
-                $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3139
-            }
3140
-        }
3089
+				//Replace the product price
3090
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3091
+					$product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3092
+					$product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3093
+
3094
+					$product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3095
+					$product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3096
+					$product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3097
+				} else {
3098
+					$product_into_cart['product_price'] = $variations_total_price['price_ati'];
3099
+					$product_into_cart['price_ht'] = $variations_total_price['price_et'];
3100
+					$product_into_cart['tva'] = $variations_total_price['vat_amount'];
3101
+				}
3102
+			} else {
3103
+				// Add variations price to product price
3104
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3105
+					$product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3106
+					$product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3107
+
3108
+					$product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3109
+					$product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3110
+					$product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3111
+				} else {
3112
+					$product_into_cart['product_price'] += $variations_total_price['price_ati'];
3113
+					$product_into_cart['price_ht'] += $variations_total_price['price_et'];
3114
+					$product_into_cart['tva'] += $variations_total_price['vat_amount'];
3115
+				}
3116
+				// Check parent discount
3117
+				$parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3118
+				if (!empty($parent_discount_config)) {
3119
+					$product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3120
+					$product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3121
+					$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3122
+
3123
+					if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3124
+						$product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3125
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3126
+						$product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3127
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3128
+						$product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3129
+					}
3130
+				}
3131
+			}
3132
+		} else {
3133
+			// If product have just Free variations
3134
+			$discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3135
+			if (!empty($discount_config)) {
3136
+				$product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3137
+				$product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3138
+				$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3139
+			}
3140
+		}
3141 3141
 
3142
-        // Text From indicator
3143
-        if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3144
-            $product_into_cart['text_from'] = $variations_options['text_from'];
3145
-        }
3146
-        return $product_into_cart;
3147
-    }
3142
+		// Text From indicator
3143
+		if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3144
+			$product_into_cart['text_from'] = $variations_options['text_from'];
3145
+		}
3146
+		return $product_into_cart;
3147
+	}
3148 3148
 
3149
-    /**
3150
-     * Read an array with product options chosen by the customer, order into an array regarding admin definition
3151
-     *
3152
-     * @param array $product_definition_value The array with the selected product option to ordered
3153
-     * @param array $output_order The good order for attribute defined by administrator
3154
-     * @param dtring $from_page A string allowing to take a specific template regarding the current page
3155
-     *
3156
-     * @return array The array containing all product options ordered as the admin configure it
3157
-     */
3158
-    public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3159
-    {
3160
-        $variation_attribute_ordered = array();
3161
-        $variation_attribute_ordered['prices'] = array();
3162
-        $variation_attribute_ordered['attribute_list'] = array();
3163
-
3164
-        if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3165
-            foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3166
-                $variation_tpl_component = array();
3167
-                foreach ($variation_attribute_detail as $info_name => $info_value) {
3168
-                    $variation_tpl_component['VARIATION_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3169
-                }
3170
-                $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3171
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3172
-                if (!empty($output_order[$variation_attribute_code])) {
3173
-                    $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3174
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3175
-                        $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3176
-                    }
3177
-                } else {
3178
-                    $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3179
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3180
-                        $variation_attribute_ordered['attribute_list'][] = $display_data;
3181
-                    }
3182
-                }
3183
-                unset($variation_tpl_component);
3184
-            }
3185
-        }
3149
+	/**
3150
+	 * Read an array with product options chosen by the customer, order into an array regarding admin definition
3151
+	 *
3152
+	 * @param array $product_definition_value The array with the selected product option to ordered
3153
+	 * @param array $output_order The good order for attribute defined by administrator
3154
+	 * @param dtring $from_page A string allowing to take a specific template regarding the current page
3155
+	 *
3156
+	 * @return array The array containing all product options ordered as the admin configure it
3157
+	 */
3158
+	public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3159
+	{
3160
+		$variation_attribute_ordered = array();
3161
+		$variation_attribute_ordered['prices'] = array();
3162
+		$variation_attribute_ordered['attribute_list'] = array();
3163
+
3164
+		if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3165
+			foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3166
+				$variation_tpl_component = array();
3167
+				foreach ($variation_attribute_detail as $info_name => $info_value) {
3168
+					$variation_tpl_component['VARIATION_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3169
+				}
3170
+				$variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3171
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3172
+				if (!empty($output_order[$variation_attribute_code])) {
3173
+					$display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3174
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3175
+						$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3176
+					}
3177
+				} else {
3178
+					$display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3179
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3180
+						$variation_attribute_ordered['attribute_list'][] = $display_data;
3181
+					}
3182
+				}
3183
+				unset($variation_tpl_component);
3184
+			}
3185
+		}
3186 3186
 
3187
-        if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3188
-            foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3189
-                $variation_tpl_component = array();
3190
-                foreach ($variation_details as $info_name => $info_value) {
3191
-                    if ($info_name != 'item_meta') {
3192
-                        $variation_tpl_component['VARIATION_DETAIL_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3193
-                    }
3194
-                }
3195
-                foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3196
-                    $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3197
-                    $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3198
-                    $variation_tpl_component['VARIATION_ID'] = $variation_id;
3199
-                    $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3200
-
3201
-                    $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3202
-                }
3203
-                if (!empty($output_order[$variation_attribute_code])) {
3204
-                    $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3205
-                }
3206
-                unset($variation_tpl_component);
3207
-            }
3208
-        }
3187
+		if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3188
+			foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3189
+				$variation_tpl_component = array();
3190
+				foreach ($variation_details as $info_name => $info_value) {
3191
+					if ($info_name != 'item_meta') {
3192
+						$variation_tpl_component['VARIATION_DETAIL_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3193
+					}
3194
+				}
3195
+				foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3196
+					$variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3197
+					$variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3198
+					$variation_tpl_component['VARIATION_ID'] = $variation_id;
3199
+					$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3209 3200
 
3210
-        /**    Free Variation part    */
3211
-        if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3212
-            foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3213
-                if (strpos($build_variation, '-_variation_val_-')) {
3214
-                    $variation_definition = explode('-_variation_val_-', $build_variation);
3215
-                    $attribute_code = $variation_definition[0];
3216
-                    $attribute_selected_value = $variation_definition[1];
3217
-                } else {
3218
-                    $attribute_code = $build_variation_key;
3219
-                    $attribute_selected_value = $build_variation;
3220
-                }
3221
-
3222
-                $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3223
-                $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3224
-                $value_to_outut = $attribute_selected_value;
3225
-                switch ($free_variation_attribute_def->data_type) {
3226
-                    case 'datetime':
3227
-                        $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3228
-                        break;
3229
-                }
3230
-
3231
-                if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3232
-                    switch ($free_variation_attribute_def->data_type_to_use) {
3233
-                        case 'custom':
3234
-                        case 'internal':
3235
-                            $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3236
-                            $value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3237
-                            break;
3238
-                    }
3239
-                }
3240
-                $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3241
-                $variation_tpl_component['VARIATION_ID'] = $attribute_code;
3242
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3243
-                if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3244
-                    $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_code), $template_part);
3245
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3246
-                        $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3247
-                    }
3248
-                }
3249
-                unset($variation_tpl_component);
3250
-            }
3251
-        }
3252
-        return $variation_attribute_ordered;
3253
-    }
3201
+					$variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3202
+				}
3203
+				if (!empty($output_order[$variation_attribute_code])) {
3204
+					$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3205
+				}
3206
+				unset($variation_tpl_component);
3207
+			}
3208
+		}
3254 3209
 
3255
-    public function wps_selected_variation_picture($head_product_id, $variations)
3256
-    {
3257
-        $response = array();
3258
-        /** Selected Product image **/
3259
-        $post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3260
-        if (!empty($post_thumbnail_id)) {
3261
-            $response['img_id'] = $post_thumbnail_id;
3262
-            $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3263
-            $response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3264
-        }
3210
+		/**    Free Variation part    */
3211
+		if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3212
+			foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3213
+				if (strpos($build_variation, '-_variation_val_-')) {
3214
+					$variation_definition = explode('-_variation_val_-', $build_variation);
3215
+					$attribute_code = $variation_definition[0];
3216
+					$attribute_selected_value = $variation_definition[1];
3217
+				} else {
3218
+					$attribute_code = $build_variation_key;
3219
+					$attribute_selected_value = $build_variation;
3220
+				}
3265 3221
 
3266
-        /** check if have one variation **/
3267
-        if (!empty($variations) && count($variations) == 1) {
3268
-            $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3269
-            if (!empty($variation_attached_image_id)) {
3270
-                $response['img_id'] = $variation_attached_image_id;
3271
-                $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3272
-                $response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3273
-            }
3274
-        }
3275
-        return $response;
3276
-    }
3222
+				$free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3223
+				$variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3224
+				$value_to_outut = $attribute_selected_value;
3225
+				switch ($free_variation_attribute_def->data_type) {
3226
+					case 'datetime':
3227
+						$value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3228
+						break;
3229
+				}
3277 3230
 
3278
-    /** Add a meta box of product sales history in product administration panel **/
3279
-    public function meta_box_product_sale_informations()
3280
-    {
3281
-        global $post;
3282
-        $product_id = $post->ID;
3283
-
3284
-        $variations = self::get_variation($product_id);
3285
-
3286
-        $sales_informations = array();
3287
-        /** Query **/
3288
-        $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3289
-        $query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE')));
3290
-        $orders = new WP_Query($query_args);
3291
-        if (!empty($orders) && !empty($orders->posts)) {
3292
-            foreach ($orders->posts as $order) {
3293
-                $order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3294
-                $order_info = get_post_meta($order->ID, '_order_info', true);
3295
-                $sales_informations[] = array(
3296
-                    'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3297
-                    'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3298
-                    'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '',
3299
-                    'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '',
3300
-                    'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '',
3301
-                );
3302
-            }
3303
-        }
3231
+				if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3232
+					switch ($free_variation_attribute_def->data_type_to_use) {
3233
+						case 'custom':
3234
+						case 'internal':
3235
+							$possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3236
+							$value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3237
+							break;
3238
+					}
3239
+				}
3240
+				$variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3241
+				$variation_tpl_component['VARIATION_ID'] = $attribute_code;
3242
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3243
+				if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3244
+					$display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_code), $template_part);
3245
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3246
+						$variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3247
+					}
3248
+				}
3249
+				unset($variation_tpl_component);
3250
+			}
3251
+		}
3252
+		return $variation_attribute_ordered;
3253
+	}
3304 3254
 
3305
-        /** If product has been ordered **/
3306
-        $output = '';
3307
-        if (!empty($sales_informations)) {
3308
-            $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3309
-            $output .= '<ul>';
3310
-            foreach ($sales_informations as $sales_information) {
3311
-                $output .= '<li>' . sprintf(__('Ordered by %s %s (%s) on %s (Order ref. : %s)', 'wpshop'), $sales_information['customer_name'], $sales_information['customer_firstname'], $sales_information['customer_email'], $sales_information['order_date'], $sales_information['order_key']) . '</li>';
3312
-            }
3313
-            $output .= '</ul>';
3314
-        } else {
3315
-            $output .= __('This product has never been ordered', 'wpshop');
3316
-        }
3255
+	public function wps_selected_variation_picture($head_product_id, $variations)
3256
+	{
3257
+		$response = array();
3258
+		/** Selected Product image **/
3259
+		$post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3260
+		if (!empty($post_thumbnail_id)) {
3261
+			$response['img_id'] = $post_thumbnail_id;
3262
+			$response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3263
+			$response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3264
+		}
3317 3265
 
3318
-        echo $output;
3319
-    }
3266
+		/** check if have one variation **/
3267
+		if (!empty($variations) && count($variations) == 1) {
3268
+			$variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3269
+			if (!empty($variation_attached_image_id)) {
3270
+				$response['img_id'] = $variation_attached_image_id;
3271
+				$response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3272
+				$response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3273
+			}
3274
+		}
3275
+		return $response;
3276
+	}
3320 3277
 
3321
-    public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3322
-    {
3323
-        global $wpdb, $wpshop_payment;
3324
-        $output = '';
3325
-        $tpl_component = array();
3326
-        /**    Get attribute order for current product    */
3327
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3328
-        $output_order = array();
3329
-        if (count($product_attribute_order_detail) > 0) {
3330
-            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3331
-                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3332
-                    if (!empty($attribute_def->code)) {
3333
-                        $output_order[$attribute_def->code] = $position;
3334
-                    }
3335
-
3336
-                }
3337
-            }
3338
-        }
3339
-        $variation_attribute_ordered = array();
3340
-
3341
-        /** Check if product is a variation and change his name **/
3342
-        $product_post_type = get_post_type($the_product['product_id']);
3343
-        if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3344
-            $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3345
-            $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3346
-            $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3347
-        }
3278
+	/** Add a meta box of product sales history in product administration panel **/
3279
+	public function meta_box_product_sale_informations()
3280
+	{
3281
+		global $post;
3282
+		$product_id = $post->ID;
3283
+
3284
+		$variations = self::get_variation($product_id);
3285
+
3286
+		$sales_informations = array();
3287
+		/** Query **/
3288
+		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3289
+		$query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE')));
3290
+		$orders = new WP_Query($query_args);
3291
+		if (!empty($orders) && !empty($orders->posts)) {
3292
+			foreach ($orders->posts as $order) {
3293
+				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3294
+				$order_info = get_post_meta($order->ID, '_order_info', true);
3295
+				$sales_informations[] = array(
3296
+					'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3297
+					'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3298
+					'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '',
3299
+					'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '',
3300
+					'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '',
3301
+				);
3302
+			}
3303
+		}
3348 3304
 
3349
-        foreach ($the_product as $product_definition_key => $product_definition_value) {
3350
-            if ($product_definition_key != 'item_meta') {
3351
-                $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3352
-                if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3353
-                    $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3354
-                }
3355
-            } else {
3356
-                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3357
-            }
3358
-        }
3305
+		/** If product has been ordered **/
3306
+		$output = '';
3307
+		if (!empty($sales_informations)) {
3308
+			$output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3309
+			$output .= '<ul>';
3310
+			foreach ($sales_informations as $sales_information) {
3311
+				$output .= '<li>' . sprintf(__('Ordered by %s %s (%s) on %s (Order ref. : %s)', 'wpshop'), $sales_information['customer_name'], $sales_information['customer_firstname'], $sales_information['customer_email'], $sales_information['order_date'], $sales_information['order_key']) . '</li>';
3312
+			}
3313
+			$output .= '</ul>';
3314
+		} else {
3315
+			$output .= __('This product has never been ordered', 'wpshop');
3316
+		}
3359 3317
 
3360
-        ksort($variation_attribute_ordered['attribute_list']);
3361
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3362
-        foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3363
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3364
-        }
3318
+		echo $output;
3319
+	}
3365 3320
 
3366
-        /**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3367
-        $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3368
-        if (!empty($attribute_list)) {
3369
-            foreach ($attribute_list as $attribute_def) {
3370
-                $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3371
-            }
3372
-        }
3321
+	public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3322
+	{
3323
+		global $wpdb, $wpshop_payment;
3324
+		$output = '';
3325
+		$tpl_component = array();
3326
+		/**    Get attribute order for current product    */
3327
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3328
+		$output_order = array();
3329
+		if (count($product_attribute_order_detail) > 0) {
3330
+			foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3331
+				foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3332
+					if (!empty($attribute_def->code)) {
3333
+						$output_order[$attribute_def->code] = $position;
3334
+					}
3373 3335
 
3374
-        /**    Fill the array with all prices for different variations    */
3375
-        foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3376
-            $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3377
-        }
3336
+				}
3337
+			}
3338
+		}
3339
+		$variation_attribute_ordered = array();
3340
+
3341
+		/** Check if product is a variation and change his name **/
3342
+		$product_post_type = get_post_type($the_product['product_id']);
3343
+		if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3344
+			$parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3345
+			$parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3346
+			$the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3347
+		}
3378 3348
 
3379
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3380
-        $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3381
-        $post_list_with_options = $wpdb->get_results($query);
3382
-        if (!empty($post_list_with_options)) {
3383
-            $additionnal_price = 0;
3384
-            foreach ($post_list_with_options as $product_info) {
3385
-                $product_meta = unserialize($product_info->meta_value);
3386
-                if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3387
-                    $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3388
-
3389
-                    $the_product = array_merge(array(
3390
-                        'product_id' => $product_info->post_id,
3391
-                        'product_qty' => 1,
3392
-                    ), $product);
3393
-
3394
-                    $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3395
-                    $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3396
-
3397
-                    $tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate));
3398
-                    $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3399
-                }
3400
-            }
3401
-        }
3349
+		foreach ($the_product as $product_definition_key => $product_definition_value) {
3350
+			if ($product_definition_key != 'item_meta') {
3351
+				$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3352
+				if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3353
+					$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3354
+				}
3355
+			} else {
3356
+				$variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3357
+			}
3358
+		}
3402 3359
 
3403
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3404
-        $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3405
-        if (!empty($additionnal_price)) {
3406
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3407
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3408
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3409
-        }
3360
+		ksort($variation_attribute_ordered['attribute_list']);
3361
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3362
+		foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3363
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3364
+		}
3365
+
3366
+		/**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3367
+		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3368
+		if (!empty($attribute_list)) {
3369
+			foreach ($attribute_list as $attribute_def) {
3370
+				$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3371
+			}
3372
+		}
3410 3373
 
3411
-        /**    Call informtion for partial payment    */
3412
-        $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3413
-        $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3374
+		/**    Fill the array with all prices for different variations    */
3375
+		foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3376
+			$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3377
+		}
3378
+
3379
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3380
+		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3381
+		$post_list_with_options = $wpdb->get_results($query);
3382
+		if (!empty($post_list_with_options)) {
3383
+			$additionnal_price = 0;
3384
+			foreach ($post_list_with_options as $product_info) {
3385
+				$product_meta = unserialize($product_info->meta_value);
3386
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3387
+					$product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3388
+
3389
+					$the_product = array_merge(array(
3390
+						'product_id' => $product_info->post_id,
3391
+						'product_qty' => 1,
3392
+					), $product);
3393
+
3394
+					$additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3395
+					$tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3396
+
3397
+					$tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate));
3398
+					$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3399
+				}
3400
+			}
3401
+		}
3414 3402
 
3415
-        /**    Define the current selected currency for the order summary    */
3403
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3404
+		$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3405
+		if (!empty($additionnal_price)) {
3406
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3407
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3408
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3409
+		}
3410
+
3411
+		/**    Call informtion for partial payment    */
3412
+		$partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3413
+		$tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3414
+
3415
+		/**    Define the current selected currency for the order summary    */
3416 3416
 //         $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3417
-        $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3418
-        return $output;
3419
-    }
3417
+		$output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3418
+		return $output;
3419
+	}
3420 3420
 
3421
-    /**
3422
-     * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3423
-     * @param string $ID ID product variations or not
3424
-     * @return string Return ID
3425
-     */
3426
-    public static function get_id_variation($ID)
3427
-    {
3428
-        $result = explode('__', $ID);
3429
-        return end($result);
3430
-    }
3421
+	/**
3422
+	 * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3423
+	 * @param string $ID ID product variations or not
3424
+	 * @return string Return ID
3425
+	 */
3426
+	public static function get_id_variation($ID)
3427
+	{
3428
+		$result = explode('__', $ID);
3429
+		return end($result);
3430
+	}
3431 3431
 
3432
-    /**
3433
-     * Update all variations definitions who not modified
3434
-     * @param array $new_value
3435
-     * @param array $old_value
3436
-     * @return array $new_value
3437
-     */
3438
-    public static function update_wpshop_catalog_product_option($new_value, $old_value)
3439
-    {
3440
-        global $wpdb;
3441
-        $query = $wpdb->prepare('SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND meta_value LIKE %s', '_wpshop_variation_defining', '%' . serialize('follow_general_config') . '%');
3442
-        foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3443
-            $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3444
-            $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3445
-            update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3446
-        }
3447
-        return $new_value;
3448
-    }
3432
+	/**
3433
+	 * Update all variations definitions who not modified
3434
+	 * @param array $new_value
3435
+	 * @param array $old_value
3436
+	 * @return array $new_value
3437
+	 */
3438
+	public static function update_wpshop_catalog_product_option($new_value, $old_value)
3439
+	{
3440
+		global $wpdb;
3441
+		$query = $wpdb->prepare('SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND meta_value LIKE %s', '_wpshop_variation_defining', '%' . serialize('follow_general_config') . '%');
3442
+		foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3443
+			$wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3444
+			$wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3445
+			update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3446
+		}
3447
+		return $new_value;
3448
+	}
3449 3449
 
3450
-    public static function variation_parameters_save($current_post_id, $options)
3451
-    {
3450
+	public static function variation_parameters_save($current_post_id, $options)
3451
+	{
3452 3452
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3453
-        $variation_post_meta['options'] = $options;
3453
+		$variation_post_meta['options'] = $options;
3454 3454
 		$variation_post_meta['follow_general_config'] = true;
3455 3455
 		if( $variation_post_meta['follow_general_config'] ) {
3456 3456
 			$shop_option = get_option('wpshop_catalog_product_option', array());
@@ -3466,6 +3466,6 @@  discard block
 block discarded – undo
3466 3466
 				}
3467 3467
 			}
3468 3468
 		}
3469
-        update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3470
-    }
3469
+		update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3470
+	}
3471 3471
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -179,20 +179,20 @@  discard block
 block discarded – undo
179 179
 	public static function admin_menu() {
180 180
 		global $submenu;
181 181
 		$attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
182
-		$entities_to_unset = array( 'free_product', 'default' );
182
+		$entities_to_unset = array('free_product', 'default');
183 183
 		$submenu_before = $submenu['edit.php?post_type=wpshop_product'];
184 184
 		foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
185
-			if ( !( in_array( $attribute_set->slug, $entities_to_unset ) || in_array( $attribute_set->name, $entities_to_unset ) ) ) {
186
-				add_submenu_page( 'edit.php?post_type=wpshop_product', sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product');
185
+			if (!(in_array($attribute_set->slug, $entities_to_unset) || in_array($attribute_set->name, $entities_to_unset))) {
186
+				add_submenu_page('edit.php?post_type=wpshop_product', sprintf(__('Add %s', 'wpshop'), $attribute_set->name), sprintf(__('Add %s', 'wpshop'), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product');
187 187
 			}
188 188
 		}
189
-		$submenu_new_elements = array_diff_key ( $submenu['edit.php?post_type=wpshop_product'], $submenu_before );
189
+		$submenu_new_elements = array_diff_key($submenu['edit.php?post_type=wpshop_product'], $submenu_before);
190 190
 		$submenu_reorder = array();
191
-		foreach( $submenu_before as $key => $element ) {
192
-			if( empty( $submenu_reorder[$key] ) ) {
191
+		foreach ($submenu_before as $key => $element) {
192
+			if (empty($submenu_reorder[$key])) {
193 193
 				$submenu_reorder[$key] = $element;
194
-				if( in_array( 'post-new.php?post_type=wpshop_product', $element ) ) {
195
-					$submenu_reorder = array_merge( $submenu_reorder, array_values( $submenu_new_elements ) );
194
+				if (in_array('post-new.php?post_type=wpshop_product', $element)) {
195
+					$submenu_reorder = array_merge($submenu_reorder, array_values($submenu_new_elements));
196 196
 				}
197 197
 			} else {
198 198
 				$submenu_reorder[] = $element;
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
 
541 541
         $products = array();
542 542
         $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
543
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
543
+        $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name));
544 544
 
545 545
         if (!empty($data)) {
546 546
             if ($data['data_type_to_use'] == 'custom') {
547 547
                 // Find which table to take
548
-                if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;}
548
+                if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME; } elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL; } elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER; } elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; } elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; } elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR; }
549 549
 
550 550
                 if (isset($table_name)) {
551 551
                     // If the value is an id of a select, radio or checkbox
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
         if (!empty($atts['product_type'])) {
696 696
             switch ($atts['product_type']) {
697 697
                 case 'related':
698
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
698
+                    $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID();
699 699
                     $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
700 700
                     $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
701 701
 
702
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
702
+                    $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
703 703
                     if (!empty($pids) && !empty($pids[0])) {
704 704
                         $pid = implode(',', $pids);
705 705
                     }
@@ -768,8 +768,8 @@  discard block
 block discarded – undo
768 768
                     $sub_tpl_component = array();
769 769
                     $criteria = '';
770 770
                     foreach ($sorting_criteria as $c):
771
-											$selected = isset( $atts['order'] ) ? $atts['order'] : null;
772
-                      $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
771
+											$selected = isset($atts['order']) ? $atts['order'] : null;
772
+                      $criteria .= '<option value="' . $c['code'] . '" ' . selected($selected, $c['code'], false) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
773 773
                     endforeach;
774 774
                     $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
775 775
                     $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
             // --------------------- //
939 939
             // Pagination management //
940 940
             // --------------------- //
941
-            if ( $display_pagination ) {
941
+            if ($display_pagination) {
942 942
                 if ($nb_of_product_limit == 0) {
943 943
 
944 944
                     $paginate = paginate_links(array(
@@ -1013,14 +1013,14 @@  discard block
 block discarded – undo
1013 1013
 		$newQty = $product['product_stock'] - $qty;
1014 1014
 		$value_id = 0;
1015 1015
 		if ($newQty >= 0) {
1016
-			$query = $wpdb->prepare( "
1016
+			$query = $wpdb->prepare("
1017 1017
 				SELECT ATTDEC.value_id
1018 1018
 				FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTDEC
1019 1019
 				LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATTDEC.attribute_id = ATT.id
1020 1020
 				WHERE ATTDEC.entity_id = %d AND ATT.code = %s
1021
-				LIMIT 1", $product_id, 'product_stock' );
1021
+				LIMIT 1", $product_id, 'product_stock');
1022 1022
 				$value_id = $wpdb->get_var($query);
1023
-				$update = $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1023
+				$update = $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1024 1024
 			}
1025 1025
 			// Historic
1026 1026
 			$attribute_histo_content = array();
@@ -1217,7 +1217,7 @@  discard block
 block discarded – undo
1217 1217
     {
1218 1218
         global $wpdb;
1219 1219
 
1220
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1220
+        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST;
1221 1221
         // Apply a filter to extra actions
1222 1222
         $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1223 1223
 
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
                             $attributeValue = str_replace(',', '.', $attributeValue);
1274 1274
                         }
1275 1275
                         if (($attributeType == 'integer') && !is_array($attributeValue)) {
1276
-                            $attributeValue = (int) $attributeValue;
1276
+                            $attributeValue = (int)$attributeValue;
1277 1277
                         }
1278 1278
                         $productMetaDatas[$attributeCode] = $attributeValue;
1279 1279
                     }
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
                                     $attributeValue = str_replace(',', '.', $attribute->$value_key);
1324 1324
                                 }
1325 1325
                                 if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1326
-                                    $attributeValue = (int) $attribute->$value_key;
1326
+                                    $attributeValue = (int)$attribute->$value_key;
1327 1327
                                 }
1328 1328
                                 $variation_metadata[$attribute->code] = $attribute->$value_key;
1329 1329
                             }
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
                                 $attributeValue = str_replace(',', '.', $attributeValue);
1337 1337
                             }
1338 1338
                             if (($attributeType == 'integer') && !is_array($attributeValue)) {
1339
-                                $attributeValue = (int) $attributeValue;
1339
+                                $attributeValue = (int)$attributeValue;
1340 1340
                             }
1341 1341
                             $variation_metadata[$attributeCode] = $attributeValue;
1342 1342
                         }
@@ -1672,13 +1672,13 @@  discard block
 block discarded – undo
1672 1672
             if (!empty($product_price_infos)) {
1673 1673
                 $tpl_component_price = array();
1674 1674
                 /** Price piloting **/
1675
-				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1676
-				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1675
+				$price_display_option = get_option('wpshop_catalog_product_option');
1676
+				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : '';
1677 1677
                 $price_ploting = get_option('wpshop_shop_price_piloting');
1678 1678
                 $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : '';
1679 1679
                 $variations = wpshop_products::get_variation($product_id);
1680 1680
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1681
-				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1681
+				if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) {
1682 1682
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1683 1683
 				}
1684 1684
                 $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
             }
2122 2122
 
2123 2123
             $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2124
-						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2124
+						$template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id);
2125 2125
 
2126 2126
             $tpl_component = array();
2127 2127
             $tpl_component['PRODUCT_ID'] = $product_id;
@@ -2983,7 +2983,7 @@  discard block
 block discarded – undo
2983 2983
                 $single_variations = array();
2984 2984
                 foreach ($selected_variation as $attribute_code => $attribute_value) {
2985 2985
                     if (isset($attribute_value) && $attribute_code != 'free') {
2986
-                        $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id);
2986
+                        $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int)$attribute_value)) . "'", $product_id);
2987 2987
                         $single_variation_id = $wpdb->get_var($query);
2988 2988
                         if (!empty($single_variation_id)) {
2989 2989
                             $single_variations[] = $single_variation_id;
@@ -3085,7 +3085,7 @@  discard block
 block discarded – undo
3085 3085
              * Since 1.4.3.7
3086 3086
              * L'option du produit remplace le prix du produit de tête.
3087 3087
              */
3088
-			if( true ) {
3088
+			if (true) {
3089 3089
                 //Replace the product price
3090 3090
                 if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3091 3091
                     $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
@@ -3452,16 +3452,16 @@  discard block
 block discarded – undo
3452 3452
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3453 3453
         $variation_post_meta['options'] = $options;
3454 3454
 		$variation_post_meta['follow_general_config'] = true;
3455
-		if( $variation_post_meta['follow_general_config'] ) {
3455
+		if ($variation_post_meta['follow_general_config']) {
3456 3456
 			$shop_option = get_option('wpshop_catalog_product_option', array());
3457
-			if( isset( $shop_option ) ) {
3457
+			if (isset($shop_option)) {
3458 3458
 				$variation_post_meta['options']['price_display'] = $shop_option['price_display'];
3459 3459
 			}
3460 3460
 		}
3461 3461
 		$variations = wpshop_attributes::get_variation_available_attribute($current_post_id);
3462
-		if( !empty( $variations['available'] ) ) {
3463
-			foreach( $variations['available'] as $key => $value ) {
3464
-				if( !in_array( $value['attribute_complete_def']->code, $variation_post_meta['attributes'] ) ) {
3462
+		if (!empty($variations['available'])) {
3463
+			foreach ($variations['available'] as $key => $value) {
3464
+				if (!in_array($value['attribute_complete_def']->code, $variation_post_meta['attributes'])) {
3465 3465
 					$variation_post_meta['attributes'][] = $value['attribute_complete_def']->code;
3466 3466
 				}
3467 3467
 			}
Please login to merge, or discard this patch.
includes/librairies/install.class.php 1 patch
Indentation   +2307 added lines, -2307 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
+	}
407 43
 
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
-                                }
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
+				}
441 84
 
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
-                    }
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
+				}
472 90
 
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
-                        }
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
+				}
508 103
 
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
-                        }
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);
587 107
 
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
-                        }
108
+					$page_creation = true;
109
+				}
593 110
 
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
-                }
111
+			}
112
+		}
113
+
114
+		/**    Check if page have been created in order to do specific action    */
115
+		if (!empty($created_pages)) {
116
+			/**    If cart page and checkout page have just been created, change cart page id into checkout page id    */
117
+			if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) {
118
+				update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id'));
119
+			}
120
+
121
+		}
122
+
123
+		wp_cache_flush();
124
+		/** If new page => empty cache */
125
+		if ($page_creation) {
126
+			wp_cache_delete('all_page_ids', 'pages');
127
+			//    $wp_rewrite->flush_rules();
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Insert sample datas when installing wpshop the first time if the admin choose
133
+	 */
134
+	public static function import_sample_datas()
135
+	{
136
+		global $wpdb, $wp_rewrite;
137
+
138
+		/** Default data array for add product */
139
+		$product_default_args = array(
140
+			'comment_status' => 'closed',
141
+			'ping_status' => 'closed',
142
+			'post_status' => 'publish',
143
+			'post_author' => get_current_user_id(),
144
+		);
145
+
146
+		/**    Get the default datas for installation - sample products    */
147
+		$sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml');
148
+		$defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA);
149
+
150
+		$namespaces = $defined_sample_datas->getDocNamespaces();
151
+		if (!isset($namespaces['wp'])) {
152
+			$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
153
+		}
154
+
155
+		if (!isset($namespaces['excerpt'])) {
156
+			$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
157
+		}
158
+
159
+		foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) {
160
+			$dc = $product->children('http://purl.org/dc/elements/1.1/');
161
+			$content = $product->children('http://purl.org/rss/1.0/modules/content/');
162
+			$excerpt = $product->children($namespaces['excerpt']);
163
+			$wp = $product->children($namespaces['wp']);
164
+
165
+			$product_args = wp_parse_args(array(
166
+				'post_title' => (string) $product->title,
167
+				'post_name' => (string) $wp->post_name,
168
+				'post_content' => (string) $content->encoded,
169
+				'post_excerpt' => (string) $excerpt->encoded,
170
+				'post_type' => (string) $wp->post_type,
171
+			), $product_default_args);
172
+
173
+			$product_id = wp_insert_post($product_args);
174
+
175
+			foreach ($wp->postmeta as $meta) {
176
+				update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value);
177
+			}
178
+
179
+			foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) {
180
+				$wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/');
181
+				$wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/');
182
+				$wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']);
183
+				$wps_pdt_var_wp = $product_variation->children($namespaces['wp']);
184
+
185
+				$product_args = wp_parse_args(array(
186
+					'post_title' => (string) $product_variation->title,
187
+					'post_name' => (string) $wps_pdt_var_wp->post_name,
188
+					'post_content' => (string) $wps_pdt_var_content->encoded,
189
+					'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded,
190
+					'post_type' => (string) $wps_pdt_var_wp->post_type,
191
+					'post_parent' => $product_id,
192
+				), $product_default_args);
193
+
194
+				$product_variation_id = wp_insert_post($product_args);
195
+
196
+				foreach ($wps_pdt_var_wp->postmeta as $meta) {
197
+					update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value);
198
+				}
199
+			}
200
+		}
201
+	}
202
+
203
+	/**
204
+	 * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content.
205
+	 */
206
+	public static function update_wpshop_dev()
207
+	{
208
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update;
209
+
210
+		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
211
+
212
+		self::execute_operation_on_db_for_update('dev');
213
+	}
214
+
215
+	/**
216
+	 * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content.
217
+	 */
218
+	public static function update_wpshop()
219
+	{
220
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update;
221
+		$do_changes = false;
222
+
223
+		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
224
+
225
+		$current_db_version = get_option('wpshop_db_options', 0);
226
+		$current_db_version = $current_db_version['db_version'];
227
+
228
+		$current_def_max_version = max(array_keys($wpshop_update_way));
229
+		$new_version = $current_def_max_version + 1;
230
+		$version_nb_delta = $current_def_max_version - $current_db_version;
231
+
232
+		/*    Check if there are modification to do    */
233
+		if ($current_def_max_version >= $current_db_version) {
234
+			/*    Check the lowest version of db to execute    */
235
+			$lowest_version_to_execute = $current_def_max_version - $version_nb_delta;
236
+
237
+			for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) {
238
+				$do_changes = self::execute_operation_on_db_for_update($i);
239
+			}
240
+		}
241
+
242
+		/*    Update the db version option value    */
243
+		if ($do_changes) {
244
+			$db_version = get_option('wpshop_db_options', 0);
245
+			$db_version['db_version'] = $new_version;
246
+			update_option('wpshop_db_options', $db_version);
247
+		}
248
+	}
249
+
250
+	/**
251
+	 * Update db structure on each plugin update
252
+	 *
253
+	 * @param integer $i The current plugin db version
254
+	 * @return boolean If the changes are done correctly or not
255
+	 */
256
+	public static function alter_db_structure_on_update($i)
257
+	{
258
+		$do_changes = false;
259
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete;
260
+
261
+		/*    Check if there are modification to do    */
262
+		if (isset($wpshop_update_way[$i])) {
263
+			/*    Check if there are modification to make on table    */
264
+			if (isset($wpshop_db_table_list[$i])) {
265
+				foreach ($wpshop_db_table_list[$i] as $table_name) {
266
+					dbDelta($wpshop_db_table[$table_name]);
267
+				}
268
+				$do_changes = true;
269
+			}
270
+
271
+			/*    Request maker    */
272
+			if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) {
273
+				foreach ($wpshop_db_request[$i] as $request) {
274
+					$wpdb->query($request);
275
+					$do_changes = true;
276
+				}
277
+			}
278
+
279
+			/*    Delete datas    */
280
+			if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) {
281
+				foreach ($wpshop_db_delete[$i] as $request) {
282
+					$wpdb->query($request);
283
+				}
284
+			}
285
+		}
286
+
287
+		return $do_changes;
288
+	}
289
+
290
+	/**
291
+	 * Do changes on database for wpshop plugin for a given version
292
+	 *
293
+	 * @param integer $i The wpshop db version to execute operation for
294
+	 *
295
+	 * @return boolean
296
+	 */
297
+	public static function execute_operation_on_db_for_update($i)
298
+	{
299
+		global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete;
300
+		$do_changes = false;
301
+
302
+		/*    Check if there are modification to do    */
303
+		if (isset($wpshop_update_way[$i])) {
304
+			$do_changes = self::alter_db_structure_on_update($i);
305
+
306
+			/********************/
307
+			/*        Insert data        */
308
+			/********************/
309
+			/*    Options content    */
310
+			if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) {
311
+				foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) {
312
+					add_option($option_name, $option_content, '', 'yes');
313
+				}
314
+				$do_changes = true;
315
+			}
316
+			if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) {
317
+				foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) {
318
+					$option_current_content = get_option($option_name);
319
+					foreach ($option_content as $option_key => $option_value) {
320
+						$option_current_content[$option_key] = $option_value;
321
+					}
322
+					update_option($option_name, $option_current_content);
323
+				}
324
+				$do_changes = true;
325
+			}
326
+
327
+			/*    Eav content    */
328
+			if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) {
329
+				$do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes);
330
+			}
331
+			/*    Eav content update    */
332
+			if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) {
333
+				$do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes);
334
+			}
335
+
336
+			/*    Add datas    */
337
+			if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) {
338
+				foreach ($wpshop_db_content_add[$i] as $table_name => $def) {
339
+					foreach ($def as $information_index => $table_information) {
340
+						$wpdb->insert($table_name, $table_information, '%s');
341
+						$do_changes = true;
342
+					}
343
+				}
344
+			}
345
+
346
+			/*    Update datas    */
347
+			if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) {
348
+				foreach ($wpshop_db_content_update[$i] as $table_name => $def) {
349
+					foreach ($def as $information_index => $table_information) {
350
+						$wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s');
351
+						$do_changes = true;
352
+					}
353
+				}
354
+			}
355
+		}
356
+
357
+		$do_changes = self::make_specific_operation_on_update($i);
358
+
359
+		return $do_changes;
360
+	}
361
+
362
+	/**
363
+	 * Create specific data in eav db model
364
+	 *
365
+	 * @param array $eav_content The complete array with all element to create into database
366
+	 * @param boolean $do_changes The current state of changes to do
367
+	 *
368
+	 * @return boolean If there are changes to do or not
369
+	 */
370
+	public static function add_content_to_eav($eav_content, $do_changes)
371
+	{
372
+		global $wpdb;
373
+		/*    Create entities if entites are set to be created for the current version    */
374
+		if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) {
375
+			foreach ($eav_content['entities'] as $entity) {
376
+				/*    Creation de l'entité produit dans la table des posts    */
377
+				wpshop_entities::create_cpt_from_csv_file($entity);
378
+			}
379
+			$do_changes = true;
380
+		}
381
+
382
+		/*    Create attributes for a given entity if attributes are set to be created for current version    */
383
+		if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) {
384
+			foreach ($eav_content['attributes'] as $entity_code) {
385
+				wpshop_entities::create_cpt_attributes_from_csv_file($entity_code);
386
+			}
387
+			$do_changes = true;
388
+		}
389
+
390
+		/*    Create attribute groups for a given entity if attributes groups are set to be created for current version    */
391
+		if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) {
392
+			foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) {
393
+				$entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code);
394
+
395
+				if ($entity_id > 0) {
396
+					foreach ($attribute_set as $set_name => $set_groups) {
397
+						$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase')));
398
+						$attribute_set_id = $wpdb->get_var($query);
399
+						if ($attribute_set_id <= 0) {
400
+							$attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name);
401
+							if ($set_name == 'default') {
402
+								$attribute_set_content['default_set'] = 'yes';
403
+							}
404
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content);
405
+							$attribute_set_id = $wpdb->insert_id;
406
+						}
407
+
408
+						if ($attribute_set_id > 0) {
409
+							foreach ($set_groups as $set_group_infos) {
410
+								$set_group_infos_details = $set_group_infos['details'];
411
+								unset($set_group_infos['details']);
412
+								/*    Change an attribute set status if definition specify this param     */
413
+								if (isset($set_group_infos['status'])) {
414
+									$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id));
415
+								}
416
+								$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']);
417
+								$attribute_set_section_id = $wpdb->get_var($query);
418
+								if ($attribute_set_section_id <= 0) {
419
+									$new_set_section_infos = $set_group_infos;
420
+									$new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid');
421
+									$new_set_section_infos['creation_date'] = current_time('mysql', 0);
422
+									$new_set_section_infos['attribute_set_id'] = $attribute_set_id;
423
+									$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos);
424
+									$attribute_set_section_id = $wpdb->insert_id;
425
+								}
426
+
427
+								if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) {
428
+									$query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id);
429
+									$last_position = $wpdb->get_var($query);
430
+									$position = (int) $last_position + 1;
431
+									foreach ($set_group_infos_details as $attribute_code) {
432
+										$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
433
+										$attribute_id = $wpdb->get_row($query);
434
+
435
+										if ($attribute_id->id > 0) {
436
+											$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position));
437
+											$position++;
438
+										}
439
+									}
440
+								}
441
+
442
+							}
443
+						}
444
+					}
445
+				}
446
+			}
447
+			$do_changes = true;
448
+		}
449
+
450
+		return $do_changes;
451
+	}
452
+
453
+	/**
454
+	 * Update specific data in eav db model
455
+	 *
456
+	 * @param array $eav_content The complete array with all element to create into database
457
+	 * @param boolean $do_changes The current state of changes to do
458
+	 *
459
+	 * @return boolean If there are changes to do or not
460
+	 */
461
+	public static function update_eav_content($eav_content, $do_changes)
462
+	{
463
+		/*    Update attributes fo a given entity if attributes are set to be updated for current version    */
464
+		if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) {
465
+			foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) {
466
+				foreach ($attribute_definition as $attribute_def) {
467
+					$option_list_for_attribute = '';
468
+					if (isset($attribute_def['backend_input_values'])) {
469
+						$option_list_for_attribute = $attribute_def['backend_input_values'];
470
+						unset($attribute_def['backend_input_values']);
471
+					}
472
+
473
+					/*    Get entity identifier from code    */
474
+					$attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code);
475
+					$attribute_def['status'] = $attribute_def['attribute_status'];
476
+					unset($attribute_def['attribute_status']);
477
+					$attribute_def['last_update_date'] = current_time('mysql', 0);
478
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code']));
479
+					$attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code']));
480
+
481
+					/*    Insert option values if there are some to add for the current attribute    */
482
+					if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) {
483
+						foreach ($option_list_for_attribute as $option_code => $option_value) {
484
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value));
485
+							if ($option_code == $attribute_def['default_value']) {
486
+								$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code));
487
+							}
488
+						}
489
+					}
490
+				}
491
+			}
492
+			$do_changes = true;
493
+		}
494
+
495
+		/*    Update attribute groups fo a given entity if attributes groups are set to be updated for current version    */
496
+		if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) {
497
+			foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) {
498
+				$entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code);
499
+
500
+				if ($entity_id > 0) {
501
+					foreach ($attribute_set as $set_name => $set_groups) {
502
+						$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase')));
503
+						$attribute_set_id = $wpdb->get_var($query);
504
+						if ($attribute_set_id <= 0) {
505
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name));
506
+							$attribute_set_id = $wpdb->insert_id;
507
+						}
508
+
509
+						if ($attribute_set_id > 0) {
510
+							foreach ($set_groups as $set_group_infos) {
511
+								$set_group_infos_details = $set_group_infos['details'];
512
+								unset($set_group_infos['details']);
513
+								/*    Change an attribute set status if definition specify this param     */
514
+								if (isset($set_group_infos['status'])) {
515
+									$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id));
516
+								}
517
+								$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']);
518
+								$attribute_set_section_id = $wpdb->get_var($query);
519
+								if ($attribute_set_section_id <= 0) {
520
+									$new_set_section_infos = $set_group_infos;
521
+									$new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid');
522
+									$new_set_section_infos['creation_date'] = current_time('mysql', 0);
523
+									$new_set_section_infos['attribute_set_id'] = $attribute_set_id;
524
+									$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos);
525
+									$attribute_set_section_id = $wpdb->insert_id;
526
+								} else {
527
+									$new_set_section_infos = $set_group_infos;
528
+									$new_set_section_infos['last_update_date'] = current_time('mysql', 0);
529
+									$wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id));
530
+								}
531
+
532
+								if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) {
533
+									if (count($set_group_infos_details) <= 0) {
534
+										$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id));
535
+									} else {
536
+										$query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id);
537
+										$last_position = $wpdb->get_var($query);
538
+										$position = (int) $last_position + 1;
539
+										foreach ($set_group_infos_details as $attribute_code) {
540
+											$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id);
541
+											$attribute_id = $wpdb->get_var($query);
542
+											if ($attribute_id > 0) {
543
+												$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position));
544
+												$position++;
545
+											}
546
+										}
547
+									}
548
+								}
549
+							}
550
+						}
551
+					}
552
+				}
553
+			}
554
+			$do_changes = true;
555
+		}
556
+
557
+		return $do_changes;
558
+	}
611 559
 
612
-                /*    Update the product prices into database    */
613
-                $query = $wpdb->prepare("
560
+	/**
561
+	 * Manage special operation on wpshop plugin update
562
+	 */
563
+	public static function make_specific_operation_on_update($version)
564
+	{
565
+		global $wpdb, $wp_rewrite;
566
+		$wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
567
+
568
+		switch ($version) {
569
+			case 3:
570
+			case 6:
571
+				self::wpshop_insert_default_pages($wpshop_shop_type);
572
+				wp_cache_flush();
573
+				return true;
574
+				break;
575
+			case 8:
576
+				/**    Change metaboxes order for product in case it already exists    */
577
+				$query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product');
578
+				$customer_metaboxes_order = $wpdb->get_results($query);
579
+				if (!empty($customer_metaboxes_order)) {
580
+					foreach ($customer_metaboxes_order as $customer_metabox_order) {
581
+						$do_changes = false;
582
+						$current_order = unserialize($customer_metabox_order->meta_value);
583
+						if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) {
584
+							str_replace('wpshop_product_important_datas,', '', $current_order['normal']);
585
+							$do_changes = true;
586
+						}
587
+
588
+						if (array_key_exists('side', $current_order)) {
589
+							str_replace('wpshop_product_important_datas,', '', $current_order['side']);
590
+							str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']);
591
+							$do_changes = true;
592
+						}
593
+
594
+						if (true === $do_changes) {
595
+							$wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id));
596
+						}
597
+					}
598
+				} else {
599
+					$users = get_users(array('role' => 'administrator'));
600
+					if (!empty($users)) {
601
+						foreach ($users as $user) {
602
+							$user_meta = array(
603
+								'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv',
604
+								'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic',
605
+								'advanced' => '',
606
+							);
607
+							update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta);
608
+						}
609
+					}
610
+				}
611
+
612
+				/*    Update the product prices into database    */
613
+				$query = $wpdb->prepare("
614 614
 SELECT
615 615
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price,
616 616
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht,
617 617
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva,
618 618
 (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva');
619
-                $product_prices = $wpdb->get_row($query);
620
-                $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva));
621
-                $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price);
622
-                $price_list = $wpdb->get_results($query);
623
-                foreach ($price_list as $existing_ttc_price) {
624
-                    $tax_rate = 1.20;
625
-                    $price_ht = $existing_ttc_price->value / $tax_rate;
626
-                    $tax_amount = $existing_ttc_price->value - $price_ht;
627
-
628
-                    $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0)));
629
-                    $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0)));
630
-                    $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0)));
631
-                }
632
-
633
-                /*    Update orders structure into database    */
634
-                $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
635
-                foreach ($orders_id as $o) {
636
-                    $myorder = get_post_meta($o->ID, '_order_postmeta', true);
637
-                    $neworder = array();
638
-                    $items = array();
639
-
640
-                    if (!isset($myorder['order_tva'])) {
641
-                        $order_total_ht = 0;
642
-                        $order_total_ttc = 0;
643
-                        $order_tva = array('20' => 0);
644
-
645
-                        foreach ($myorder['order_items'] as $item) {
646
-                            /* item */
647
-                            $pu_ht = $item['cost'] / 1.20;
648
-                            $pu_tva = $item['cost'] - $pu_ht;
649
-                            $total_ht = $pu_ht * $item['qty'];
650
-                            $tva_total_amount = $pu_tva * $item['qty'];
651
-                            $total_ttc = $item['cost'] * $item['qty'];
652
-                            /* item */
653
-                            $order_total_ht += $total_ht;
654
-                            $order_total_ttc += $total_ttc;
655
-                            $order_tva['20'] += $tva_total_amount;
656
-
657
-                            $items[] = array(
658
-                                'item_id' => $item['id'],
659
-                                'item_ref' => 'Nc',
660
-                                'item_name' => $item['name'],
661
-                                'item_qty' => $item['qty'],
662
-
663
-                                'item_pu_ht' => number_format($pu_ht, 2, '.', ''),
664
-                                'item_pu_ttc' => number_format($item['cost'], 2, '.', ''),
665
-
666
-                                'item_ecotaxe_ht' => number_format(0, 2, '.', ''),
667
-                                'item_ecotaxe_tva' => 20,
668
-                                'item_ecotaxe_ttc' => number_format(0, 2, '.', ''),
669
-
670
-                                'item_discount_type' => 0,
671
-                                'item_discount_value' => 0,
672
-                                'item_discount_amount' => number_format(0, 2, '.', ''),
673
-
674
-                                'item_tva_rate' => 20,
675
-                                'item_tva_amount' => number_format($pu_tva, 2, '.', ''),
676
-
677
-                                'item_total_ht' => number_format($total_ht, 2, '.', ''),
678
-                                'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''),
679
-                                'item_total_ttc' => number_format($total_ttc, 2, '.', ''),
680
-                                /*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/
681
-                            );
682
-                        }
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;
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
+					}
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
+				}
1359 1119
 
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;
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
+				}
1510 1198
 
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);
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'] : '';
1514 1206
 
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);
1207
+						$display_admin_menu = 'on';
1517 1208
 
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);
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
+				}
1520 1234
 
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)) {
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'));
1525 1242
 
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);
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,572 +1818,572 @@  discard block
 block discarded – undo
1818 1818
                     }
1819 1819
                 }*/
1820 1820
 
1821
-                return true;
1822
-                break;
1823
-
1824
-            case '45':
1825
-                $shipping_mode_ctr = new wps_shipping_mode_ctr();
1826
-                $shipping_mode_ctr->migrate_default_shipping_mode();
1827
-                return true;
1828
-                break;
1829
-
1830
-            case '46':
1831
-                wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE');
1832
-                wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE);
1833
-                return true;
1834
-                break;
1835
-
1836
-            case '47':
1837
-                wps_payment_mode::migrate_payment_modes();
1838
-                return true;
1839
-                break;
1840
-
1841
-            case '48':
1842
-                @ini_set('max_execution_time', '500');
1843
-
1844
-                $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1845
-                $output_type_option = get_option('wpshop_display_option');
1846
-                $output_type = $output_type_option['wpshop_display_list_type'];
1847
-
1848
-                for ($i = 0; $i <= $count_products->publish; $i += 20) {
1849
-                    $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
1850
-                    $products = $wpdb->get_results($query);
1851
-                    if (!empty($products)) {
1852
-                        foreach ($products as $product) {
1853
-                            $p = wpshop_products::get_product_data($product->ID);
1854
-                            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
1855
-                            update_post_meta($product->ID, '_wps_price_infos', $price);
1856
-                        }
1857
-                    }
1858
-                }
1859
-
1860
-                return true;
1861
-                break;
1862
-
1863
-            case '49':
1864
-                update_option('wpshop_send_invoice', true);
1865
-                return true;
1866
-                break;
1867
-
1868
-            case '50':
1869
-                $price_display_option = get_option('wpshop_catalog_product_option');
1870
-                $price_display_option['price_display']['text_from'] = 'on';
1871
-                $price_display_option['price_display']['lower_price'] = 'on';
1872
-                update_option('wpshop_catalog_product_option', $price_display_option);
1873
-
1874
-                self::wpshop_insert_default_pages();
1875
-
1876
-                return true;
1877
-                break;
1878
-
1879
-            case '51':
1880
-                /**    Insert new message for direct payment link    */
1881
-                $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1882
-                if (empty($direct_payment_link_message)) {
1883
-                    wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1884
-                }
1885
-                return true;
1886
-                break;
1887
-
1888
-            case '52':
1889
-                $account_page_option = get_option('wpshop_myaccount_page_id');
1890
-                if (!empty($account_page_option)) {
1891
-                    $page_account = get_post($account_page_option);
1892
-                    $page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]';
1893
-                    wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content));
1894
-                }
1895
-                return true;
1896
-                break;
1897
-
1898
-            case '53':
1899
-                $payment_modes_option = get_option('wps_payment_mode');
1900
-                if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) {
1901
-                    $payment_modes_option['mode']['cash_on_delivery'] = array(
1902
-                        'name' => __('Cash on delivery', 'wpshop'),
1903
-                        'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png',
1904
-                        'description' => __('Pay your order on delivery', 'wpshop'));
1905
-
1906
-                    update_option('wps_payment_mode', $payment_modes_option);
1907
-                }
1908
-
1909
-                // Mass action on products to add a flag on variation definition
1910
-                $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1911
-                if (!empty($products)) {
1912
-                    foreach ($products as $p) {
1913
-                        $post_id = $p->ID;
1914
-                        $check_product_have_variations = wpshop_products::get_variation($post_id);
1915
-                        if (!empty($check_product_have_variations)) {
1916
-                            $variation_flag = wpshop_products::check_variation_type($post_id);
1917
-                            $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1918
-                            $variation_defining['variation_type'] = $variation_flag;
1919
-                            update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1920
-                        }
1921
-                    }
1922
-                }
1923
-                return true;
1924
-                break;
1925
-
1926
-            case '54':
1927
-                // Change shortcode of sign up page
1928
-                $signup_page_id = get_option('wpshop_signup_page_id');
1929
-                if (!empty($signup_page_id)) {
1930
-                    $signup_page = get_post($signup_page_id);
1931
-                    $signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]';
1932
-                    wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content));
1933
-                }
1934
-
1935
-                // Change Terms of sale default content
1936
-                $terms_page_id = get_option('wpshop_terms_of_sale_page_id');
1937
-                if (!empty($terms_page_id)) {
1938
-                    $terms_sale_page = get_post($terms_page_id);
1939
-                    if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') {
1940
-                        $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>';
1941
-                        $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>';
1942
-                        $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1943
-                        $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>';
1944
-                        $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1945
-                        $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>';
1946
-                        $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1947
-                        $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>';
1948
-                        $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name'));
1949
-                        wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data));
1950
-                    }
1951
-                }
1952
-
1953
-                return true;
1954
-                break;
1955
-
1956
-            case '55':
1957
-                $checkout_page_id = get_option('wpshop_checkout_page_id');
1958
-                $checkout_page = get_post($checkout_page_id);
1959
-                $checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]';
1960
-                wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content));
1961
-
1962
-                // Update cart page id
1963
-                update_option('wpshop_cart_page_id', $checkout_page_id);
1964
-                return true;
1965
-                break;
1966
-
1967
-            case '56':
1968
-                $wps_entities = new wpshop_entities();
1969
-                $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1970
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id);
1971
-                $set = $wpdb->get_row($query);
1972
-                if (!empty($set)) {
1973
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET,
1974
-                        array('default_set' => 'yes'),
1975
-                        array('id' => $set->id));
1976
-                }
1977
-                // Update Opinions activation option
1978
-                update_option('wps_opinion', array('active' => 'on'));
1979
-                return true;
1980
-                break;
1981
-
1982
-            case '57':
1983
-                $wpshop_cart_option = get_option('wpshop_cart_option');
1984
-                $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes';
1985
-                $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes';
1986
-
1987
-                update_option('wpshop_cart_option', $wpshop_cart_option);
1988
-                return true;
1989
-                break;
1990
-
1991
-            case '58':
1992
-                /** Turn customers publish into draft **/
1993
-                $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1994
-                $wpdb->query($query);
1995
-
1996
-                $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
1997
-                /** Check if the 0% VAT Rate is not already created **/
1998
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0');
1999
-                $exist_vat_rate = $wpdb->get_results($query);
2000
-
2001
-                if (empty($exist_vat_rate)) {
2002
-                    /** Get Max Position **/
2003
-                    $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
2004
-                    $max_position = $wpdb->get_var($query);
2005
-
2006
-                    if (!empty($attribute_def) && !empty($attribute_def->id)) {
2007
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0'));
2008
-                    }
2009
-                }
2010
-                return true;
2011
-                break;
2012
-
2013
-            case '59':
2014
-                /** Move old images gallery to the new gallery, and remove old links **/
2015
-                $allowed = get_allowed_mime_types();
2016
-                $args = array(
2017
-                    'posts_per_page' => -1,
2018
-                    'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
2019
-                    'post_status' => array('publish', 'draft', 'trash'),
2020
-                );
2021
-                $posts = get_posts($args);
2022
-                $result = array();
2023
-                foreach ($posts as $post) {
2024
-                    $array = array();
2025
-                    $array['Post'] = $post;
2026
-                    $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true);
2027
-                    $array['Attachments'] = get_attached_media($allowed, $post->ID);
2028
-                    $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true);
2029
-                    if (!empty($array['TrueAttachmentsString'])) {
2030
-                        $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']);
2031
-                    }
2032
-                    $array['OldAttachmentsString'] = '';
2033
-                    foreach ($array['Attachments'] as $attachment) {
2034
-                        $filename = basename(get_attached_file($attachment->ID));
2035
-                        $pos_ext = strrpos($filename, '.');
2036
-                        $filename_no_ext = substr($filename, 0, $pos_ext);
2037
-                        if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) {
2038
-                            $array['OldAttachmentsString'] .= $attachment->ID . ',';
2039
-                        }
2040
-                    }
2041
-                    unset($TrueAttachments_id);
2042
-                    $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString'];
2043
-                    update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]);
2044
-                }
2045
-                return true;
2046
-                break;
2047
-
2048
-            case '60':
2049
-                /* Create default emails */
2050
-                wps_message_ctr::create_default_message();
2051
-
2052
-                /** Update entries for quick add */
2053
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"');
2054
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"');
2055
-                $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"');
2056
-                switch (WPSHOP_PRODUCT_PRICE_PILOT) {
2057
-                    case 'HT':
2058
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"');
2059
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"');
2060
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"');
2061
-                        break;
2062
-                    default:
2063
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"');
2064
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"');
2065
-                        $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"');
2066
-                        break;
2067
-                }
2068
-
2069
-                /* Default country with WP language */
2070
-                $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice');
2071
-                if (empty($wpshop_country_default_choice_option)) {
2072
-                    update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3));
2073
-                }
2074
-                return true;
2075
-                break;
2076
-
2077
-            case '61':
2078
-                /** Import the xml for guided tour */
2079
-                wpsBubble_ctr::import_xml();
2080
-
2081
-                /* Hide admin bar */
2082
-                $wpshop_display_option = get_option('wpshop_display_option');
2083
-                if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) {
2084
-                    $wpshop_display_option['wpshop_hide_admin_bar'] = 'on';
2085
-                    update_option('wpshop_display_option', $wpshop_display_option);
2086
-                }
2087
-
2088
-                return true;
2089
-                break;
2090
-
2091
-            case '62':
2092
-                /** Install user default for POS */
2093
-                wps_pos_addon::action_to_do_on_activation();
2094
-
2095
-                return true;
2096
-                break;
2097
-
2098
-            case '63':
2099
-                $data = get_option('wps_shipping_mode');
2100
-                if (empty($data['modes']['default_shipping_mode_for_pos'])) {
2101
-                    $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop');
2102
-                    $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop');
2103
-                    update_option('wps_shipping_mode', $data);
2104
-                }
2105
-                return true;
2106
-                break;
2107
-
2108
-            case '64':
2109
-                $options = get_option('wpshop_catalog_product_option');
2110
-                if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
2111
-                    unset($options['wpshop_catalog_product_slug_with_category']);
2112
-                    update_option('wpshop_catalog_product_option', $options);
2113
-                }
2114
-                return true;
2115
-                break;
2116
-
2117
-            case '65':
2118
-                $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
2119
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id);
2120
-                $company_id = $wpdb->get_var($query);
2121
-                if (!isset($company_id)) {
2122
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2123
-                        'is_visible_in_front' => 'no',
2124
-                        'is_visible_in_front_listing' => 'yes',
2125
-                        'is_global' => 'no',
2126
-                        'is_user_defined' => 'no',
2127
-                        'is_required' => 'no',
2128
-                        'is_visible_in_advanced_search' => 'no',
2129
-                        'is_searchable' => 'no',
2130
-                        'is_filterable' => 'no',
2131
-                        'is_comparable' => 'no',
2132
-                        'is_html_allowed_on_front' => 'no',
2133
-                        'is_unique' => 'no',
2134
-                        'is_filterable_in_search' => 'no',
2135
-                        'is_used_for_sort_by' => 'no',
2136
-                        'is_configurable' => 'no',
2137
-                        'is_requiring_unit' => 'no',
2138
-                        'is_recordable_in_cart_meta' => 'no',
2139
-                        'is_used_in_admin_listing_column' => 'no',
2140
-                        'is_used_in_quick_add_form' => 'no',
2141
-                        'is_used_for_variation' => 'no',
2142
-                        'is_used_in_variation' => 'no',
2143
-                        '_display_informations_about_value' => 'no',
2144
-                        '_need_verification' => 'no',
2145
-                        '_unit_group_id' => null,
2146
-                        '_default_unit' => null,
2147
-                        'is_historisable' => 'yes',
2148
-                        'is_intrinsic' => 'no',
2149
-                        'data_type_to_use' => 'custom',
2150
-                        'use_ajax_for_filling_field' => 'no',
2151
-                        'data_type' => 'varchar',
2152
-                        'backend_table' => null,
2153
-                        'backend_label' => 'Company',
2154
-                        'backend_input' => 'text',
2155
-                        'frontend_label' => 'Company',
2156
-                        'frontend_input' => 'text',
2157
-                        'frontend_verification' => null,
2158
-                        'code' => 'company_customer',
2159
-                        'note' => '',
2160
-                        'default_value' => '',
2161
-                        'frontend_css_class' => 'company_customer',
2162
-                        'backend_css_class' => null,
2163
-                        'frontend_help_message' => null,
2164
-                        'entity_id' => $entity_id,
2165
-                    ));
2166
-                    $company_id = $wpdb->insert_id;
2167
-                }
2168
-
2169
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id);
2170
-                $is_provider_id = $wpdb->get_var($query);
2171
-                if (!isset($is_provider_id)) {
2172
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2173
-                        'is_visible_in_front' => 'no',
2174
-                        'is_visible_in_front_listing' => 'yes',
2175
-                        'is_global' => 'no',
2176
-                        'is_user_defined' => 'no',
2177
-                        'is_required' => 'yes',
2178
-                        'is_visible_in_advanced_search' => 'no',
2179
-                        'is_searchable' => 'no',
2180
-                        'is_filterable' => 'no',
2181
-                        'is_comparable' => 'no',
2182
-                        'is_html_allowed_on_front' => 'no',
2183
-                        'is_unique' => 'no',
2184
-                        'is_filterable_in_search' => 'no',
2185
-                        'is_used_for_sort_by' => 'no',
2186
-                        'is_configurable' => 'no',
2187
-                        'is_requiring_unit' => 'no',
2188
-                        'is_recordable_in_cart_meta' => 'no',
2189
-                        'is_used_in_admin_listing_column' => 'no',
2190
-                        'is_used_in_quick_add_form' => 'no',
2191
-                        'is_used_for_variation' => 'no',
2192
-                        'is_used_in_variation' => 'no',
2193
-                        '_display_informations_about_value' => 'no',
2194
-                        '_need_verification' => 'no',
2195
-                        '_unit_group_id' => null,
2196
-                        '_default_unit' => null,
2197
-                        'is_historisable' => 'yes',
2198
-                        'is_intrinsic' => 'no',
2199
-                        'data_type_to_use' => 'custom',
2200
-                        'use_ajax_for_filling_field' => 'no',
2201
-                        'data_type' => 'integer',
2202
-                        'backend_table' => null,
2203
-                        'backend_label' => 'Provider',
2204
-                        'backend_input' => 'select',
2205
-                        'frontend_label' => 'Provider',
2206
-                        'frontend_input' => 'select',
2207
-                        'frontend_verification' => null,
2208
-                        'code' => 'is_provider',
2209
-                        'note' => '',
2210
-                        'default_value' => 'no',
2211
-                        'frontend_css_class' => 'is_provider',
2212
-                        'backend_css_class' => null,
2213
-                        'frontend_help_message' => null,
2214
-                        'entity_id' => $entity_id,
2215
-                    ));
2216
-                    $is_provider_id = $wpdb->insert_id;
2217
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2218
-                        'status' => 'valid',
2219
-                        'attribute_id' => $is_provider_id,
2220
-                        'creation_date_value' => current_time('mysql'),
2221
-                        'value' => 'yes',
2222
-                        'label' => 'Yes',
2223
-                    ));
2224
-                    $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2225
-                        'status' => 'valid',
2226
-                        'attribute_id' => $is_provider_id,
2227
-                        'creation_date_value' => current_time('mysql'),
2228
-                        'value' => 'no',
2229
-                        'label' => 'No',
2230
-                    ));
2231
-                    $default_value = $wpdb->insert_id;
2232
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id));
2233
-                }
2234
-
2235
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id);
2236
-                $company_section_detail_id = $wpdb->get_var($query);
2237
-
2238
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id);
2239
-                $is_provider_section_detail_id = $wpdb->get_var($query);
2240
-
2241
-                if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) {
2242
-                    $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
2243
-                    $attribute_set_id = $wpdb->get_var($query);
2244
-
2245
-                    $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account');
2246
-                    $attribute_set_section_id = $wpdb->get_var($query);
2247
-
2248
-                    $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id);
2249
-                    $attributes_set_details = $wpdb->get_results($query);
2250
-                    $set_details_id_postion_order = array();
2251
-                    foreach ($attributes_set_details as $attribute_set_detail) {
2252
-                        $query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id);
2253
-                        $attribute_set_detail_code = $wpdb->get_var($query);
2254
-                        if ($attribute_set_detail_code == 'last_name') {
2255
-                            $set_details_id_postion_order[1] = $attribute_set_detail->attribute_id;
2256
-                        }
2257
-                        if ($attribute_set_detail_code == 'first_name') {
2258
-                            $set_details_id_postion_order[2] = $attribute_set_detail->attribute_id;
2259
-                        }
2260
-                        if ($attribute_set_detail_code == 'user_email') {
2261
-                            $set_details_id_postion_order[3] = $attribute_set_detail->attribute_id;
2262
-                        }
2263
-                        if ($attribute_set_detail_code == 'user_pass') {
2264
-                            $set_details_id_postion_order[4] = $attribute_set_detail->attribute_id;
2265
-                        }
2266
-                    }
2267
-                    $max_position = count($set_details_id_postion_order);
1821
+				return true;
1822
+				break;
2268 1823
 
2269
-                    if (!isset($company_section_detail_id)) {
2270
-                        $max_position = $max_position + 1;
2271
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position));
2272
-                        $set_details_id_postion_order[$max_position] = $company_id;
2273
-                        $company_section_detail_id = $wpdb->insert_id;
2274
-                    }
1824
+			case '45':
1825
+				$shipping_mode_ctr = new wps_shipping_mode_ctr();
1826
+				$shipping_mode_ctr->migrate_default_shipping_mode();
1827
+				return true;
1828
+				break;
2275 1829
 
2276
-                    if (!isset($is_provider_section_detail_id)) {
2277
-                        $max_position = $max_position + 1;
2278
-                        $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position));
2279
-                        $set_details_id_postion_order[$max_position] = $is_provider_id;
2280
-                        $is_provider_section_detail_id = $wpdb->insert_id;
2281
-                    }
1830
+			case '46':
1831
+				wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE');
1832
+				wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE);
1833
+				return true;
1834
+				break;
2282 1835
 
2283
-                    foreach ($set_details_id_postion_order as $pos => $attr_id) {
2284
-                        $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d'));
2285
-                    }
2286
-                }
2287
-
2288
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s'));
2289
-
2290
-                return true;
2291
-                break;
2292
-
2293
-            case 66:
2294
-                $price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2295
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2296
-                    'is_visible_in_front' => 'no',
2297
-                    'is_visible_in_front_listing' => 'yes',
2298
-                    'is_global' => 'no',
2299
-                    'is_user_defined' => 'no',
2300
-                    'is_required' => 'no',
2301
-                    'is_visible_in_advanced_search' => 'no',
2302
-                    'is_searchable' => 'no',
2303
-                    'is_filterable' => 'no',
2304
-                    'is_comparable' => 'no',
2305
-                    'is_html_allowed_on_front' => 'no',
2306
-                    'is_unique' => 'no',
2307
-                    'is_filterable_in_search' => 'no',
2308
-                    'is_used_for_sort_by' => 'no',
2309
-                    'is_configurable' => 'no',
2310
-                    'is_requiring_unit' => 'no',
2311
-                    'is_recordable_in_cart_meta' => 'no',
2312
-                    'is_used_in_admin_listing_column' => 'no',
2313
-                    'is_used_in_quick_add_form' => 'no',
2314
-                    'is_used_for_variation' => 'no',
2315
-                    'is_used_in_variation' => 'yes',
2316
-                    '_display_informations_about_value' => 'no',
2317
-                    '_need_verification' => 'no',
2318
-                    '_unit_group_id' => null,
2319
-                    '_default_unit' => null,
2320
-                    'is_historisable' => 'yes',
2321
-                    'is_intrinsic' => 'no',
2322
-                    'data_type_to_use' => 'custom',
2323
-                    'use_ajax_for_filling_field' => 'no',
2324
-                    'data_type' => 'integer',
2325
-                    'backend_table' => null,
2326
-                    'backend_label' => null,
2327
-                    'backend_input' => 'select',
2328
-                    'frontend_label' => 'price_behaviour',
2329
-                    'frontend_input' => 'select',
2330
-                    'frontend_verification' => null,
2331
-                    'code' => 'price_behaviour',
2332
-                    'note' => '',
2333
-                    'default_value' => '',
2334
-                    'frontend_css_class' => 'price_behaviour',
2335
-                    'backend_css_class' => null,
2336
-                    'frontend_help_message' => null,
2337
-                    'entity_id' => $price_behaviour_entity_id,
2338
-                ));
2339
-                $price_behaviour = $wpdb->insert_id;
2340
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2341
-                    'status' => 'valid',
2342
-                    'attribute_id' => $price_behaviour,
2343
-                    'creation_date' => current_time('mysql'),
2344
-                    'value' => '+',
2345
-                    'label' => '+',
2346
-                ));
2347
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2348
-                    'status' => 'valid',
2349
-                    'attribute_id' => $price_behaviour,
2350
-                    'creation_date' => current_time('mysql'),
2351
-                    'value' => '=',
2352
-                    'label' => '=',
2353
-                ));
2354
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default');
2355
-                $price_behaviour_section_id = $wpdb->get_var($query);
2356
-                $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices');
2357
-                $price_behaviour_section_detail_id = $wpdb->get_var($query);
2358
-                $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array(
2359
-                    'status' => 'deleted',
2360
-                    'creation_date' => current_time('mysql', 0),
2361
-                    'entity_type_id' => $price_behaviour_entity_id,
2362
-                    'attribute_set_id' => $price_behaviour_section_id,
2363
-                    'attribute_group_id' => $price_behaviour_section_detail_id,
2364
-                    'attribute_id' => $price_behaviour,
2365
-                    'position' => 0,
2366
-                ));
2367
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_'));
2368
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva'));
2369
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht'));
2370
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock'));
2371
-                $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight'));
2372
-                return true;
2373
-                break;
2374
-
2375
-            case 67:
2376
-                $admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2377
-                if (empty($admin_new_version_message)) {
2378
-                    wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2379
-                }
2380
-                $wpshop_cart_option = get_option('wpshop_cart_option');
2381
-                if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) {
2382
-                    $wpshop_cart_option['total_nb_of_item_allowed'][0] = (int) filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN);
2383
-                }
2384
-                update_option('wpshop_cart_option', $wpshop_cart_option);
2385
-                return true;
2386
-                break;
1836
+			case '47':
1837
+				wps_payment_mode::migrate_payment_modes();
1838
+				return true;
1839
+				break;
1840
+
1841
+			case '48':
1842
+				@ini_set('max_execution_time', '500');
1843
+
1844
+				$count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1845
+				$output_type_option = get_option('wpshop_display_option');
1846
+				$output_type = $output_type_option['wpshop_display_list_type'];
1847
+
1848
+				for ($i = 0; $i <= $count_products->publish; $i += 20) {
1849
+					$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
1850
+					$products = $wpdb->get_results($query);
1851
+					if (!empty($products)) {
1852
+						foreach ($products as $product) {
1853
+							$p = wpshop_products::get_product_data($product->ID);
1854
+							$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
1855
+							update_post_meta($product->ID, '_wps_price_infos', $price);
1856
+						}
1857
+					}
1858
+				}
1859
+
1860
+				return true;
1861
+				break;
1862
+
1863
+			case '49':
1864
+				update_option('wpshop_send_invoice', true);
1865
+				return true;
1866
+				break;
1867
+
1868
+			case '50':
1869
+				$price_display_option = get_option('wpshop_catalog_product_option');
1870
+				$price_display_option['price_display']['text_from'] = 'on';
1871
+				$price_display_option['price_display']['lower_price'] = 'on';
1872
+				update_option('wpshop_catalog_product_option', $price_display_option);
1873
+
1874
+				self::wpshop_insert_default_pages();
1875
+
1876
+				return true;
1877
+				break;
1878
+
1879
+			case '51':
1880
+				/**    Insert new message for direct payment link    */
1881
+				$direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1882
+				if (empty($direct_payment_link_message)) {
1883
+					wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
1884
+				}
1885
+				return true;
1886
+				break;
1887
+
1888
+			case '52':
1889
+				$account_page_option = get_option('wpshop_myaccount_page_id');
1890
+				if (!empty($account_page_option)) {
1891
+					$page_account = get_post($account_page_option);
1892
+					$page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]';
1893
+					wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content));
1894
+				}
1895
+				return true;
1896
+				break;
1897
+
1898
+			case '53':
1899
+				$payment_modes_option = get_option('wps_payment_mode');
1900
+				if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) {
1901
+					$payment_modes_option['mode']['cash_on_delivery'] = array(
1902
+						'name' => __('Cash on delivery', 'wpshop'),
1903
+						'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png',
1904
+						'description' => __('Pay your order on delivery', 'wpshop'));
1905
+
1906
+					update_option('wps_payment_mode', $payment_modes_option);
1907
+				}
1908
+
1909
+				// Mass action on products to add a flag on variation definition
1910
+				$products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1911
+				if (!empty($products)) {
1912
+					foreach ($products as $p) {
1913
+						$post_id = $p->ID;
1914
+						$check_product_have_variations = wpshop_products::get_variation($post_id);
1915
+						if (!empty($check_product_have_variations)) {
1916
+							$variation_flag = wpshop_products::check_variation_type($post_id);
1917
+							$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1918
+							$variation_defining['variation_type'] = $variation_flag;
1919
+							update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1920
+						}
1921
+					}
1922
+				}
1923
+				return true;
1924
+				break;
1925
+
1926
+			case '54':
1927
+				// Change shortcode of sign up page
1928
+				$signup_page_id = get_option('wpshop_signup_page_id');
1929
+				if (!empty($signup_page_id)) {
1930
+					$signup_page = get_post($signup_page_id);
1931
+					$signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]';
1932
+					wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content));
1933
+				}
1934
+
1935
+				// Change Terms of sale default content
1936
+				$terms_page_id = get_option('wpshop_terms_of_sale_page_id');
1937
+				if (!empty($terms_page_id)) {
1938
+					$terms_sale_page = get_post($terms_page_id);
1939
+					if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') {
1940
+						$data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>';
1941
+						$data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>';
1942
+						$data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1943
+						$data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>';
1944
+						$data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1945
+						$data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>';
1946
+						$data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
1947
+						$data .= '<h3>' . __('Credits', 'wpshop') . '</h3>';
1948
+						$data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name'));
1949
+						wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data));
1950
+					}
1951
+				}
1952
+
1953
+				return true;
1954
+				break;
1955
+
1956
+			case '55':
1957
+				$checkout_page_id = get_option('wpshop_checkout_page_id');
1958
+				$checkout_page = get_post($checkout_page_id);
1959
+				$checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]';
1960
+				wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content));
1961
+
1962
+				// Update cart page id
1963
+				update_option('wpshop_cart_page_id', $checkout_page_id);
1964
+				return true;
1965
+				break;
1966
+
1967
+			case '56':
1968
+				$wps_entities = new wpshop_entities();
1969
+				$customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1970
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id);
1971
+				$set = $wpdb->get_row($query);
1972
+				if (!empty($set)) {
1973
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET,
1974
+						array('default_set' => 'yes'),
1975
+						array('id' => $set->id));
1976
+				}
1977
+				// Update Opinions activation option
1978
+				update_option('wps_opinion', array('active' => 'on'));
1979
+				return true;
1980
+				break;
1981
+
1982
+			case '57':
1983
+				$wpshop_cart_option = get_option('wpshop_cart_option');
1984
+				$wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes';
1985
+				$wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes';
1986
+
1987
+				update_option('wpshop_cart_option', $wpshop_cart_option);
1988
+				return true;
1989
+				break;
1990
+
1991
+			case '58':
1992
+				/** Turn customers publish into draft **/
1993
+				$query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
1994
+				$wpdb->query($query);
1995
+
1996
+				$attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
1997
+				/** Check if the 0% VAT Rate is not already created **/
1998
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0');
1999
+				$exist_vat_rate = $wpdb->get_results($query);
2000
+
2001
+				if (empty($exist_vat_rate)) {
2002
+					/** Get Max Position **/
2003
+					$query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
2004
+					$max_position = $wpdb->get_var($query);
2005
+
2006
+					if (!empty($attribute_def) && !empty($attribute_def->id)) {
2007
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0'));
2008
+					}
2009
+				}
2010
+				return true;
2011
+				break;
2012
+
2013
+			case '59':
2014
+				/** Move old images gallery to the new gallery, and remove old links **/
2015
+				$allowed = get_allowed_mime_types();
2016
+				$args = array(
2017
+					'posts_per_page' => -1,
2018
+					'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
2019
+					'post_status' => array('publish', 'draft', 'trash'),
2020
+				);
2021
+				$posts = get_posts($args);
2022
+				$result = array();
2023
+				foreach ($posts as $post) {
2024
+					$array = array();
2025
+					$array['Post'] = $post;
2026
+					$array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true);
2027
+					$array['Attachments'] = get_attached_media($allowed, $post->ID);
2028
+					$array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true);
2029
+					if (!empty($array['TrueAttachmentsString'])) {
2030
+						$TrueAttachments_id = explode(',', $array['TrueAttachmentsString']);
2031
+					}
2032
+					$array['OldAttachmentsString'] = '';
2033
+					foreach ($array['Attachments'] as $attachment) {
2034
+						$filename = basename(get_attached_file($attachment->ID));
2035
+						$pos_ext = strrpos($filename, '.');
2036
+						$filename_no_ext = substr($filename, 0, $pos_ext);
2037
+						if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) {
2038
+							$array['OldAttachmentsString'] .= $attachment->ID . ',';
2039
+						}
2040
+					}
2041
+					unset($TrueAttachments_id);
2042
+					$result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString'];
2043
+					update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]);
2044
+				}
2045
+				return true;
2046
+				break;
2047
+
2048
+			case '60':
2049
+				/* Create default emails */
2050
+				wps_message_ctr::create_default_message();
2051
+
2052
+				/** Update entries for quick add */
2053
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"');
2054
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"');
2055
+				$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"');
2056
+				switch (WPSHOP_PRODUCT_PRICE_PILOT) {
2057
+					case 'HT':
2058
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"');
2059
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"');
2060
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"');
2061
+						break;
2062
+					default:
2063
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"');
2064
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"');
2065
+						$query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"');
2066
+						break;
2067
+				}
2068
+
2069
+				/* Default country with WP language */
2070
+				$wpshop_country_default_choice_option = get_option('wpshop_country_default_choice');
2071
+				if (empty($wpshop_country_default_choice_option)) {
2072
+					update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3));
2073
+				}
2074
+				return true;
2075
+				break;
2076
+
2077
+			case '61':
2078
+				/** Import the xml for guided tour */
2079
+				wpsBubble_ctr::import_xml();
2080
+
2081
+				/* Hide admin bar */
2082
+				$wpshop_display_option = get_option('wpshop_display_option');
2083
+				if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) {
2084
+					$wpshop_display_option['wpshop_hide_admin_bar'] = 'on';
2085
+					update_option('wpshop_display_option', $wpshop_display_option);
2086
+				}
2087
+
2088
+				return true;
2089
+				break;
2090
+
2091
+			case '62':
2092
+				/** Install user default for POS */
2093
+				wps_pos_addon::action_to_do_on_activation();
2094
+
2095
+				return true;
2096
+				break;
2097
+
2098
+			case '63':
2099
+				$data = get_option('wps_shipping_mode');
2100
+				if (empty($data['modes']['default_shipping_mode_for_pos'])) {
2101
+					$data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop');
2102
+					$data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop');
2103
+					update_option('wps_shipping_mode', $data);
2104
+				}
2105
+				return true;
2106
+				break;
2107
+
2108
+			case '64':
2109
+				$options = get_option('wpshop_catalog_product_option');
2110
+				if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
2111
+					unset($options['wpshop_catalog_product_slug_with_category']);
2112
+					update_option('wpshop_catalog_product_option', $options);
2113
+				}
2114
+				return true;
2115
+				break;
2116
+
2117
+			case '65':
2118
+				$entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
2119
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id);
2120
+				$company_id = $wpdb->get_var($query);
2121
+				if (!isset($company_id)) {
2122
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2123
+						'is_visible_in_front' => 'no',
2124
+						'is_visible_in_front_listing' => 'yes',
2125
+						'is_global' => 'no',
2126
+						'is_user_defined' => 'no',
2127
+						'is_required' => 'no',
2128
+						'is_visible_in_advanced_search' => 'no',
2129
+						'is_searchable' => 'no',
2130
+						'is_filterable' => 'no',
2131
+						'is_comparable' => 'no',
2132
+						'is_html_allowed_on_front' => 'no',
2133
+						'is_unique' => 'no',
2134
+						'is_filterable_in_search' => 'no',
2135
+						'is_used_for_sort_by' => 'no',
2136
+						'is_configurable' => 'no',
2137
+						'is_requiring_unit' => 'no',
2138
+						'is_recordable_in_cart_meta' => 'no',
2139
+						'is_used_in_admin_listing_column' => 'no',
2140
+						'is_used_in_quick_add_form' => 'no',
2141
+						'is_used_for_variation' => 'no',
2142
+						'is_used_in_variation' => 'no',
2143
+						'_display_informations_about_value' => 'no',
2144
+						'_need_verification' => 'no',
2145
+						'_unit_group_id' => null,
2146
+						'_default_unit' => null,
2147
+						'is_historisable' => 'yes',
2148
+						'is_intrinsic' => 'no',
2149
+						'data_type_to_use' => 'custom',
2150
+						'use_ajax_for_filling_field' => 'no',
2151
+						'data_type' => 'varchar',
2152
+						'backend_table' => null,
2153
+						'backend_label' => 'Company',
2154
+						'backend_input' => 'text',
2155
+						'frontend_label' => 'Company',
2156
+						'frontend_input' => 'text',
2157
+						'frontend_verification' => null,
2158
+						'code' => 'company_customer',
2159
+						'note' => '',
2160
+						'default_value' => '',
2161
+						'frontend_css_class' => 'company_customer',
2162
+						'backend_css_class' => null,
2163
+						'frontend_help_message' => null,
2164
+						'entity_id' => $entity_id,
2165
+					));
2166
+					$company_id = $wpdb->insert_id;
2167
+				}
2168
+
2169
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id);
2170
+				$is_provider_id = $wpdb->get_var($query);
2171
+				if (!isset($is_provider_id)) {
2172
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2173
+						'is_visible_in_front' => 'no',
2174
+						'is_visible_in_front_listing' => 'yes',
2175
+						'is_global' => 'no',
2176
+						'is_user_defined' => 'no',
2177
+						'is_required' => 'yes',
2178
+						'is_visible_in_advanced_search' => 'no',
2179
+						'is_searchable' => 'no',
2180
+						'is_filterable' => 'no',
2181
+						'is_comparable' => 'no',
2182
+						'is_html_allowed_on_front' => 'no',
2183
+						'is_unique' => 'no',
2184
+						'is_filterable_in_search' => 'no',
2185
+						'is_used_for_sort_by' => 'no',
2186
+						'is_configurable' => 'no',
2187
+						'is_requiring_unit' => 'no',
2188
+						'is_recordable_in_cart_meta' => 'no',
2189
+						'is_used_in_admin_listing_column' => 'no',
2190
+						'is_used_in_quick_add_form' => 'no',
2191
+						'is_used_for_variation' => 'no',
2192
+						'is_used_in_variation' => 'no',
2193
+						'_display_informations_about_value' => 'no',
2194
+						'_need_verification' => 'no',
2195
+						'_unit_group_id' => null,
2196
+						'_default_unit' => null,
2197
+						'is_historisable' => 'yes',
2198
+						'is_intrinsic' => 'no',
2199
+						'data_type_to_use' => 'custom',
2200
+						'use_ajax_for_filling_field' => 'no',
2201
+						'data_type' => 'integer',
2202
+						'backend_table' => null,
2203
+						'backend_label' => 'Provider',
2204
+						'backend_input' => 'select',
2205
+						'frontend_label' => 'Provider',
2206
+						'frontend_input' => 'select',
2207
+						'frontend_verification' => null,
2208
+						'code' => 'is_provider',
2209
+						'note' => '',
2210
+						'default_value' => 'no',
2211
+						'frontend_css_class' => 'is_provider',
2212
+						'backend_css_class' => null,
2213
+						'frontend_help_message' => null,
2214
+						'entity_id' => $entity_id,
2215
+					));
2216
+					$is_provider_id = $wpdb->insert_id;
2217
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2218
+						'status' => 'valid',
2219
+						'attribute_id' => $is_provider_id,
2220
+						'creation_date_value' => current_time('mysql'),
2221
+						'value' => 'yes',
2222
+						'label' => 'Yes',
2223
+					));
2224
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2225
+						'status' => 'valid',
2226
+						'attribute_id' => $is_provider_id,
2227
+						'creation_date_value' => current_time('mysql'),
2228
+						'value' => 'no',
2229
+						'label' => 'No',
2230
+					));
2231
+					$default_value = $wpdb->insert_id;
2232
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id));
2233
+				}
2234
+
2235
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id);
2236
+				$company_section_detail_id = $wpdb->get_var($query);
2237
+
2238
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id);
2239
+				$is_provider_section_detail_id = $wpdb->get_var($query);
2240
+
2241
+				if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) {
2242
+					$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
2243
+					$attribute_set_id = $wpdb->get_var($query);
2244
+
2245
+					$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account');
2246
+					$attribute_set_section_id = $wpdb->get_var($query);
2247
+
2248
+					$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id);
2249
+					$attributes_set_details = $wpdb->get_results($query);
2250
+					$set_details_id_postion_order = array();
2251
+					foreach ($attributes_set_details as $attribute_set_detail) {
2252
+						$query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id);
2253
+						$attribute_set_detail_code = $wpdb->get_var($query);
2254
+						if ($attribute_set_detail_code == 'last_name') {
2255
+							$set_details_id_postion_order[1] = $attribute_set_detail->attribute_id;
2256
+						}
2257
+						if ($attribute_set_detail_code == 'first_name') {
2258
+							$set_details_id_postion_order[2] = $attribute_set_detail->attribute_id;
2259
+						}
2260
+						if ($attribute_set_detail_code == 'user_email') {
2261
+							$set_details_id_postion_order[3] = $attribute_set_detail->attribute_id;
2262
+						}
2263
+						if ($attribute_set_detail_code == 'user_pass') {
2264
+							$set_details_id_postion_order[4] = $attribute_set_detail->attribute_id;
2265
+						}
2266
+					}
2267
+					$max_position = count($set_details_id_postion_order);
2268
+
2269
+					if (!isset($company_section_detail_id)) {
2270
+						$max_position = $max_position + 1;
2271
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position));
2272
+						$set_details_id_postion_order[$max_position] = $company_id;
2273
+						$company_section_detail_id = $wpdb->insert_id;
2274
+					}
2275
+
2276
+					if (!isset($is_provider_section_detail_id)) {
2277
+						$max_position = $max_position + 1;
2278
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position));
2279
+						$set_details_id_postion_order[$max_position] = $is_provider_id;
2280
+						$is_provider_section_detail_id = $wpdb->insert_id;
2281
+					}
2282
+
2283
+					foreach ($set_details_id_postion_order as $pos => $attr_id) {
2284
+						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d'));
2285
+					}
2286
+				}
2287
+
2288
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s'));
2289
+
2290
+				return true;
2291
+				break;
2292
+
2293
+			case 66:
2294
+				$price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2295
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array(
2296
+					'is_visible_in_front' => 'no',
2297
+					'is_visible_in_front_listing' => 'yes',
2298
+					'is_global' => 'no',
2299
+					'is_user_defined' => 'no',
2300
+					'is_required' => 'no',
2301
+					'is_visible_in_advanced_search' => 'no',
2302
+					'is_searchable' => 'no',
2303
+					'is_filterable' => 'no',
2304
+					'is_comparable' => 'no',
2305
+					'is_html_allowed_on_front' => 'no',
2306
+					'is_unique' => 'no',
2307
+					'is_filterable_in_search' => 'no',
2308
+					'is_used_for_sort_by' => 'no',
2309
+					'is_configurable' => 'no',
2310
+					'is_requiring_unit' => 'no',
2311
+					'is_recordable_in_cart_meta' => 'no',
2312
+					'is_used_in_admin_listing_column' => 'no',
2313
+					'is_used_in_quick_add_form' => 'no',
2314
+					'is_used_for_variation' => 'no',
2315
+					'is_used_in_variation' => 'yes',
2316
+					'_display_informations_about_value' => 'no',
2317
+					'_need_verification' => 'no',
2318
+					'_unit_group_id' => null,
2319
+					'_default_unit' => null,
2320
+					'is_historisable' => 'yes',
2321
+					'is_intrinsic' => 'no',
2322
+					'data_type_to_use' => 'custom',
2323
+					'use_ajax_for_filling_field' => 'no',
2324
+					'data_type' => 'integer',
2325
+					'backend_table' => null,
2326
+					'backend_label' => null,
2327
+					'backend_input' => 'select',
2328
+					'frontend_label' => 'price_behaviour',
2329
+					'frontend_input' => 'select',
2330
+					'frontend_verification' => null,
2331
+					'code' => 'price_behaviour',
2332
+					'note' => '',
2333
+					'default_value' => '',
2334
+					'frontend_css_class' => 'price_behaviour',
2335
+					'backend_css_class' => null,
2336
+					'frontend_help_message' => null,
2337
+					'entity_id' => $price_behaviour_entity_id,
2338
+				));
2339
+				$price_behaviour = $wpdb->insert_id;
2340
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2341
+					'status' => 'valid',
2342
+					'attribute_id' => $price_behaviour,
2343
+					'creation_date' => current_time('mysql'),
2344
+					'value' => '+',
2345
+					'label' => '+',
2346
+				));
2347
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array(
2348
+					'status' => 'valid',
2349
+					'attribute_id' => $price_behaviour,
2350
+					'creation_date' => current_time('mysql'),
2351
+					'value' => '=',
2352
+					'label' => '=',
2353
+				));
2354
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default');
2355
+				$price_behaviour_section_id = $wpdb->get_var($query);
2356
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices');
2357
+				$price_behaviour_section_detail_id = $wpdb->get_var($query);
2358
+				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array(
2359
+					'status' => 'deleted',
2360
+					'creation_date' => current_time('mysql', 0),
2361
+					'entity_type_id' => $price_behaviour_entity_id,
2362
+					'attribute_set_id' => $price_behaviour_section_id,
2363
+					'attribute_group_id' => $price_behaviour_section_detail_id,
2364
+					'attribute_id' => $price_behaviour,
2365
+					'position' => 0,
2366
+				));
2367
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_'));
2368
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva'));
2369
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht'));
2370
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock'));
2371
+				$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight'));
2372
+				return true;
2373
+				break;
2374
+
2375
+			case 67:
2376
+				$admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2377
+				if (empty($admin_new_version_message)) {
2378
+					wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE');
2379
+				}
2380
+				$wpshop_cart_option = get_option('wpshop_cart_option');
2381
+				if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) {
2382
+					$wpshop_cart_option['total_nb_of_item_allowed'][0] = (int) filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN);
2383
+				}
2384
+				update_option('wpshop_cart_option', $wpshop_cart_option);
2385
+				return true;
2386
+				break;
2387 2387
 
2388 2388
 			case 68:
2389 2389
 				wps_message_ctr::create_default_message();
Please login to merge, or discard this patch.
modules/wps_customer/controller/wps-customer-metaboxes.controller.01.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @package WPShop
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit;
12 12
 }
13 13
 
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 	 * Instanciation de la gestion des metaboxes / Insctanciate metaboxes management
24 24
 	 */
25 25
 	function __construct() {
26
-		add_action( 'add_meta_boxes_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array( $this, 'add_meta_box_customer' ) );
27
-		add_action( 'add_meta_boxes_' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, array( $this, 'add_meta_box_order' ) );
26
+		add_action('add_meta_boxes_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'add_meta_box_customer'));
27
+		add_action('add_meta_boxes_' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, array($this, 'add_meta_box_order'));
28 28
 	}
29 29
 
30 30
 	/**
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param WP_Post $customer Le client actuel / The current customer.
34 34
 	 */
35
-	function add_meta_box_customer( $customer ) {
36
-		add_meta_box( 'wps_customer_informations', __( 'Customer\'s account informations', 'wpshop' ), array( $this, 'wps_customer_account_informations' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high' );
37
-		if ( 'auto-draft' !== $customer->post_status ) {
38
-			add_meta_box( 'wps_customer_orders', __( 'Customer\'s orders', 'wpshop' ) . '<a class="page-title-action" href="' . admin_url( 'post-new.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) . '&customer_id=' . $customer->ID . '">' . __( 'Add quotation', 'wpshop' ) . '</a>', array( $this, 'wps_customer_orders_list' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'low' );
39
-			add_meta_box( 'wps_customer_messages_list', __( 'Customer\'s send messages', 'wpshop' ), array( $this, 'wps_customer_messages_list' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'side', 'low' );
40
-			add_meta_box( 'wps_customer_coupons_list', __( 'Customer\'s coupons list', 'wpshop' ), array( $this, 'wps_customer_coupons_list' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'side', 'low' );
41
-			add_meta_box( 'wps_customer_addresses_list', __( 'Customer\'s addresses', 'wpshop' ), array( $this, 'wps_customer_addresses_list' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'low' );
35
+	function add_meta_box_customer($customer) {
36
+		add_meta_box('wps_customer_informations', __('Customer\'s account informations', 'wpshop'), array($this, 'wps_customer_account_informations'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high');
37
+		if ('auto-draft' !== $customer->post_status) {
38
+			add_meta_box('wps_customer_orders', __('Customer\'s orders', 'wpshop') . '<a class="page-title-action" href="' . admin_url('post-new.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER) . '&customer_id=' . $customer->ID . '">' . __('Add quotation', 'wpshop') . '</a>', array($this, 'wps_customer_orders_list'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'low');
39
+			add_meta_box('wps_customer_messages_list', __('Customer\'s send messages', 'wpshop'), array($this, 'wps_customer_messages_list'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'side', 'low');
40
+			add_meta_box('wps_customer_coupons_list', __('Customer\'s coupons list', 'wpshop'), array($this, 'wps_customer_coupons_list'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'side', 'low');
41
+			add_meta_box('wps_customer_addresses_list', __('Customer\'s addresses', 'wpshop'), array($this, 'wps_customer_addresses_list'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'low');
42 42
 		}
43 43
 	}
44 44
 
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @param WP_Post $order La commande sur laquelle on se trouve / Currently edited order.
49 49
 	 */
50
-	function add_meta_box_order( $order ) {
50
+	function add_meta_box_order($order) {
51 51
 		/**	Box with order customer information	*/
52 52
 		$metabox_title_button = '';
53
-		$order_metadata = get_post_meta( $order->ID, '_order_postmeta', true );
54
-		if ( empty( $order_metadata ) || ( ! empty( $order_metadata['order_status'] ) && ( 'awaiting_payment' === $order_metadata['order_status'] ) ) ) {
55
-			$metabox_title_button = '<a href="' . wp_nonce_url( admin_url( 'admin-ajax.php?action=wps_load_customer_creation_form_in_admin&width=730&height=690' ), 'wps_load_customer_creation_form_in_admin', '_wpnonce' ) . '" title="' . __( 'Create a customer', 'wpshop' ) . '" class="page-title-action thickbox" >' . __( 'Create a customer', 'wpshop' ) . '</a>';
53
+		$order_metadata = get_post_meta($order->ID, '_order_postmeta', true);
54
+		if (empty($order_metadata) || (!empty($order_metadata['order_status']) && ('awaiting_payment' === $order_metadata['order_status']))) {
55
+			$metabox_title_button = '<a href="' . wp_nonce_url(admin_url('admin-ajax.php?action=wps_load_customer_creation_form_in_admin&width=730&height=690'), 'wps_load_customer_creation_form_in_admin', '_wpnonce') . '" title="' . __('Create a customer', 'wpshop') . '" class="page-title-action thickbox" >' . __('Create a customer', 'wpshop') . '</a>';
56 56
 		}
57
-		add_meta_box( 'wpshop_order_customer_information_box', '<span class="dashicons dashicons-businessman"></span> ' . __( 'Customer information', 'wpshop' ) . $metabox_title_button, array( $this, 'display_order_customer_informations_in_administration' ), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'high' );
57
+		add_meta_box('wpshop_order_customer_information_box', '<span class="dashicons dashicons-businessman"></span> ' . __('Customer information', 'wpshop') . $metabox_title_button, array($this, 'display_order_customer_informations_in_administration'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'high');
58 58
 	}
59 59
 
60 60
 	/**
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @param WP_Post $post Current post (customer) we are editing.
64 64
 	 */
65
-	function wps_customer_orders_list( $post ) {
65
+	function wps_customer_orders_list($post) {
66 66
 		$output = '';
67 67
 		$wps_orders = new wps_orders_ctr();
68
-		$output .= $wps_orders->display_orders_in_account( $post->ID );
68
+		$output .= $wps_orders->display_orders_in_account($post->ID);
69 69
 
70 70
 		echo $output; // WPCS: XSS ok.
71 71
 	}
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @param WP_Post $post Current post (customer) we are editing.
77 77
 	 */
78
-	function wps_customer_addresses_list( $post ) {
78
+	function wps_customer_addresses_list($post) {
79 79
 		$wps_addresses = new wps_address();
80
-		$output = $wps_addresses->display_addresses_interface( $post->ID, true );
81
-		echo '<input type="hidden" name="wps_customer_id" id="wps_orders_selected_customer" value="' . esc_attr( $post->ID ) . '">';
82
-		echo '<input type="hidden" name="wps_customer_addresses_nonce" id="wps_customer_addresses_nonce" value="' . esc_attr( wp_create_nonce( 'reload_addresses_for_customer' ) ) . '">';
80
+		$output = $wps_addresses->display_addresses_interface($post->ID, true);
81
+		echo '<input type="hidden" name="wps_customer_id" id="wps_orders_selected_customer" value="' . esc_attr($post->ID) . '">';
82
+		echo '<input type="hidden" name="wps_customer_addresses_nonce" id="wps_customer_addresses_nonce" value="' . esc_attr(wp_create_nonce('reload_addresses_for_customer')) . '">';
83 83
 		echo '<div id="wps_customer_addresses" class="wps-gridwrapper2-padded">' . $output . '</div>'; // WPCS: XSS ok.
84 84
 	}
85 85
 
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @param WP_Post $post Current post (customer) we are editing.
90 90
 	 */
91
-	function wps_customer_messages_list( $post ) {
91
+	function wps_customer_messages_list($post) {
92 92
 		$wps_messages = new wps_message_ctr();
93
-		$output = $wps_messages->display_message_histo_per_customer( array(), $post->ID );
93
+		$output = $wps_messages->display_message_histo_per_customer(array(), $post->ID);
94 94
 
95 95
 		echo $output; // WPCS: XSS ok.
96 96
 	}
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @param WP_Post $post Current post (customer) we are editing.
102 102
 	 */
103
-	function wps_customer_coupons_list( $post ) {
103
+	function wps_customer_coupons_list($post) {
104 104
 		$wps_vouncher = new wps_coupon_ctr();
105
-		$output = $wps_vouncher->display_coupons( $post->post_author );
105
+		$output = $wps_vouncher->display_coupons($post->post_author);
106 106
 
107 107
 		echo $output; // WPCS: XSS ok.
108 108
 	}
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @param WP_Post $post Current post (customer) we are editing.
114 114
 	 */
115
-	function wps_customer_account_informations( $post ) {
115
+	function wps_customer_account_informations($post) {
116 116
 		$wps_account = new wps_account_ctr();
117
-		$output = $wps_account->display_account_informations( $post->ID );
117
+		$output = $wps_account->display_account_informations($post->ID);
118 118
 
119 119
 		echo $output; // WPCS: XSS ok.
120 120
 	}
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 	 *
125 125
 	 * @param WP_Post $post L'objet WP_Post correspond à la commande / The WP_Post object corresponding to the order.
126 126
 	 */
127
-	function display_order_customer_informations_in_administration( $post ) {
127
+	function display_order_customer_informations_in_administration($post) {
128 128
 		// N'afficher la metabox uniquement dans les commandes / Only display metabox in orders.
129
-		if ( ! empty( $post ) && ( WPSHOP_NEWTYPE_IDENTIFIER_ORDER === $post->post_type ) ) {
129
+		if (!empty($post) && (WPSHOP_NEWTYPE_IDENTIFIER_ORDER === $post->post_type)) {
130 130
 			$post_id = $post->ID;
131 131
 
132
-			wps_customer_admin::display_customer_informations_in_order( $post_id, ( ! empty( $_REQUEST['customer_id'] ) ? (int) $_REQUEST['customer_id'] : $post->post_parent ) );
132
+			wps_customer_admin::display_customer_informations_in_order($post_id, (!empty($_REQUEST['customer_id']) ? (int)$_REQUEST['customer_id'] : $post->post_parent));
133 133
 		} else {
134
-			esc_html_e( 'The requested order has not been found', 'wpshop' );
134
+			esc_html_e('The requested order has not been found', 'wpshop');
135 135
 		}
136 136
 	}
137 137
 
Please login to merge, or discard this patch.
includes/modules/wps_message/model/wps_message_mdl.php 2 patches
Spacing   +9 added lines, -9 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
 class wps_message_mdl {
3 3
 
4 4
 	function __construct() { }
@@ -9,20 +9,20 @@  discard block
 block discarded – undo
9 9
 	 * @param integer $customer_id
10 10
 	 * @return array
11 11
 	 */
12
-	function get_messages_histo( $message_id = '', $customer_id = '' ) {
12
+	function get_messages_histo($message_id = '', $customer_id = '') {
13 13
 		global $wpdb;
14 14
 		$messages_data = array();
15
-		if( empty($customer_id) ) {
16
-			$query = $wpdb->prepare( 'SELECT meta_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_' . $message_id . '%' );
15
+		if (empty($customer_id)) {
16
+			$query = $wpdb->prepare('SELECT meta_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_' . $message_id . '%');
17 17
 		} else {
18
-			$query = $wpdb->prepare( 'SELECT meta_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND post_id = %d', '_wpshop_messages_histo_' . $message_id . '%', $customer_id );
18
+			$query = $wpdb->prepare('SELECT meta_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND post_id = %d', '_wpshop_messages_histo_' . $message_id . '%', $customer_id);
19 19
 		}
20 20
 
21
-		$messages = $wpdb->get_results( $query );
21
+		$messages = $wpdb->get_results($query);
22 22
 
23
-		if( !empty($messages) ) {
24
-			foreach( $messages as $message ) {
25
-				$messages_data[$message->meta_id] = maybe_unserialize( $message->meta_value );
23
+		if (!empty($messages)) {
24
+			foreach ($messages as $message) {
25
+				$messages_data[$message->meta_id] = maybe_unserialize($message->meta_value);
26 26
 			}
27 27
 		}
28 28
 		return $messages_data;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_message_mdl {
3 5
 
4 6
 	function __construct() { }
Please login to merge, or discard this patch.
includes/modules/wps_message/controller/wps_message_ctr.php 1 patch
Spacing   +205 added lines, -205 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
 class wps_message_ctr {
4 4
 
@@ -18,19 +18,19 @@  discard block
 block discarded – undo
18 18
 	function __construct() {
19 19
 
20 20
 		/** Js */
21
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
21
+		add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
22 22
 		// End if().
23 23
 		$this->template_dir = WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/';
24 24
 		// WP General actions
25
-		add_action( 'admin_init', array( $this, 'wps_messages_init_actions' ) );
26
-		add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
27
-		add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column',  array( $this, 'messages_custom_columns' ) );
28
-		add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array( $this, 'messages_edit_columns' ) );
25
+		add_action('admin_init', array($this, 'wps_messages_init_actions'));
26
+		add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
27
+		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array($this, 'messages_custom_columns'));
28
+		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array($this, 'messages_edit_columns'));
29 29
 		// Shortcodes
30
-		add_shortcode( 'wps_message_histo', array( $this, 'display_message_histo_per_customer' ) );
31
-		add_shortcode( 'order_customer_personnal_informations', array( $this, 'order_personnal_informations' ) );
30
+		add_shortcode('wps_message_histo', array($this, 'display_message_histo_per_customer'));
31
+		add_shortcode('order_customer_personnal_informations', array($this, 'order_personnal_informations'));
32 32
 		/** Ajax */
33
-		add_action( 'wp_ajax_get_content_message', array( $this, 'get_content_message' ) );
33
+		add_action('wp_ajax_get_content_message', array($this, 'get_content_message'));
34 34
 	}
35 35
 
36 36
 	/**
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
 
41 41
 		/** Css */
42 42
 		add_thickbox();
43
-		wp_register_style( 'wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION );
44
-		wp_enqueue_style( 'wpeo-message-css' );
43
+		wp_register_style('wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION);
44
+		wp_enqueue_style('wpeo-message-css');
45 45
 		/** My js */
46
-		wp_enqueue_script( 'wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array( 'jquery', 'thickbox' ), WPS_MESSAGE_VERSION );
46
+		wp_enqueue_script('wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array('jquery', 'thickbox'), WPS_MESSAGE_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
@@ -59,23 +59,23 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	function create_message_type() {
61 61
 
62
-		register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, array(
62
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, array(
63 63
 			'labels' => array(
64
-				'name' => __( 'Message', 'wpshop' ),
65
-				'singular_name' => __( 'message', 'wpshop' ),
66
-				'add_new' => __( 'Add message', 'wpshop' ),
67
-				'add_new_item' => __( 'Add New message', 'wpshop' ),
68
-				'edit' => __( 'Edit', 'wpshop' ),
69
-				'edit_item' => __( 'Edit message', 'wpshop' ),
70
-				'new_item' => __( 'New message', 'wpshop' ),
71
-				'view' => __( 'View message', 'wpshop' ),
72
-				'view_item' => __( 'View message', 'wpshop' ),
73
-				'search_items' => __( 'Search messages', 'wpshop' ),
74
-				'not_found' => __( 'No message found', 'wpshop' ),
75
-				'not_found_in_trash' => __( 'No message found in trash', 'wpshop' ),
64
+				'name' => __('Message', 'wpshop'),
65
+				'singular_name' => __('message', 'wpshop'),
66
+				'add_new' => __('Add message', 'wpshop'),
67
+				'add_new_item' => __('Add New message', 'wpshop'),
68
+				'edit' => __('Edit', 'wpshop'),
69
+				'edit_item' => __('Edit message', 'wpshop'),
70
+				'new_item' => __('New message', 'wpshop'),
71
+				'view' => __('View message', 'wpshop'),
72
+				'view_item' => __('View message', 'wpshop'),
73
+				'search_items' => __('Search messages', 'wpshop'),
74
+				'not_found' => __('No message found', 'wpshop'),
75
+				'not_found_in_trash' => __('No message found in trash', 'wpshop'),
76 76
 				'parent-item-colon' => '',
77 77
 			),
78
-			'description' => __( 'This is where store messages are stored.', 'wpshop' ),
78
+			'description' => __('This is where store messages are stored.', 'wpshop'),
79 79
 			'public' => true,
80 80
 			'show_ui' => true,
81 81
 			'capability_type' => 'post',
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 			'show_in_nav_menus' => false,
87 87
 			'rewrite' => false,
88 88
 			'query_var' => true,
89
-			'supports' => array( 'title', 'editor' ),
89
+			'supports' => array('title', 'editor'),
90 90
 			'has_archive' => false,
91
-		) );
91
+		));
92 92
 	}
93 93
 
94 94
 	/**
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 	function add_meta_boxes() {
98 98
 
99 99
 		// Add message sending historic meta box
100
-		add_meta_box( 'wpshop_message_histo',
101
-			__( 'Message historic', 'wpshop' ),
102
-			array( $this, 'message_histo_box' ),
103
-		WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high' );
100
+		add_meta_box('wpshop_message_histo',
101
+			__('Message historic', 'wpshop'),
102
+			array($this, 'message_histo_box'),
103
+		WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high');
104 104
 	}
105 105
 
106 106
 	/**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 * @param unknown_type $post
110 110
 	 * @param unknown_type $params
111 111
 	 */
112
-	function message_histo_box( $post, $params ) {
112
+	function message_histo_box($post, $params) {
113 113
 
114 114
 		$output  = '<div id="message_histo_container">';
115
-		$output .= $this->get_historic_message_by_type( $post->ID );
115
+		$output .= $this->get_historic_message_by_type($post->ID);
116 116
 		$output .= '</div>';
117 117
 		echo $output;
118 118
 	}
@@ -123,39 +123,39 @@  discard block
 block discarded – undo
123 123
 	 * @param  integer $message_type_id : Message type ID
124 124
 	 * @return string
125 125
 	 */
126
-	function get_historic_message_by_type( $message_type_id ) {
126
+	function get_historic_message_by_type($message_type_id) {
127 127
 
128 128
 		global $wpdb;
129 129
 		$output = '';
130
-		if ( ! empty( $message_type_id ) ) {
130
+		if (!empty($message_type_id)) {
131 131
 			// Recover all sended messages
132 132
 			$wps_message_mdl = new wps_message_mdl();
133
-			$messages = $wps_message_mdl->get_messages_histo( $message_type_id );
133
+			$messages = $wps_message_mdl->get_messages_histo($message_type_id);
134 134
 			ob_start();
135
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend', 'message_historic' ) );
135
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend', 'message_historic'));
136 136
 			$output .= ob_get_contents();
137 137
 			ob_end_clean();
138 138
 		}
139 139
 		return $output;
140 140
 	}
141 141
 
142
-	public static function get_xml_messages( $code = null ) {
143
-		if ( is_null( self::$xml_messages ) ) {
144
-			$xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' );
145
-			$default_emails = new SimpleXMLElement( $xml_default_emails );
142
+	public static function get_xml_messages($code = null) {
143
+		if (is_null(self::$xml_messages)) {
144
+			$xml_default_emails = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml');
145
+			$default_emails = new SimpleXMLElement($xml_default_emails);
146 146
 			self::$xml_messages = array();
147
-			foreach ( $default_emails->xpath( '//emails/email' ) as $email ) {
148
-				self::$xml_messages[ (string) $email->attributes()->code ] = array(
149
-					'shop_type' => (string) $email->attributes()->shop_type,
150
-					'object' => (string) $email->subject,
151
-					'message' => (string) $email->content,
147
+			foreach ($default_emails->xpath('//emails/email') as $email) {
148
+				self::$xml_messages[(string)$email->attributes()->code] = array(
149
+					'shop_type' => (string)$email->attributes()->shop_type,
150
+					'object' => (string)$email->subject,
151
+					'message' => (string)$email->content,
152 152
 				);
153 153
 			}
154 154
 		}
155
-		if ( is_null( $code ) ) {
155
+		if (is_null($code)) {
156 156
 			return self::$xml_messages;
157
-		} elseif ( isset( self::$xml_messages[ $code ] ) ) {
158
-			return self::$xml_messages[ $code ];
157
+		} elseif (isset(self::$xml_messages[$code])) {
158
+			return self::$xml_messages[$code];
159 159
 		} else {
160 160
 			return false;
161 161
 		}
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public static function create_default_message() {
167 167
 		// Read default emails for options creation
168
-		foreach ( self::get_xml_messages() as $code => $email ) {
169
-			if ( ( WPSHOP_DEFINED_SHOP_TYPE == $email['shop_type'] ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) {
170
-				self::createMessage( $code, $email['object'], $email['message'] );
168
+		foreach (self::get_xml_messages() as $code => $email) {
169
+			if ((WPSHOP_DEFINED_SHOP_TYPE == $email['shop_type']) || ('sale' == WPSHOP_DEFINED_SHOP_TYPE)) {
170
+				self::createMessage($code, $email['object'], $email['message']);
171 171
 			}
172 172
 		}
173 173
 	}
@@ -180,25 +180,25 @@  discard block
 block discarded – undo
180 180
 	 * @param string $message : Message content
181 181
 	 * @return integer message ID
182 182
 	 */
183
-	public static function createMessage( $code, $object = '', $message = '' ) {
183
+	public static function createMessage($code, $object = '', $message = '') {
184 184
 		$id = 0;
185
-		$xml_message = self::get_xml_messages( $code );
186
-		$object = empty( $object ) ? $xml_message['object'] : $object;
187
-		$message = empty( $message ) ? $xml_message['message'] : $message;
188
-		$message_option = get_option( $code, null );
189
-		if ( empty( $message_option ) || false === get_post_status( $message_option ) ) {
190
-			$id = post_exists( __( $object , 'wpshop' ), self::customize_message( __( $message, 'wpshop' ) ) );
191
-			if( $id == 0 ) {
185
+		$xml_message = self::get_xml_messages($code);
186
+		$object = empty($object) ? $xml_message['object'] : $object;
187
+		$message = empty($message) ? $xml_message['message'] : $message;
188
+		$message_option = get_option($code, null);
189
+		if (empty($message_option) || false === get_post_status($message_option)) {
190
+			$id = post_exists(__($object, 'wpshop'), self::customize_message(__($message, 'wpshop')));
191
+			if ($id == 0) {
192 192
 				$new_message = array(
193
-					'post_title' => __( $object , 'wpshop' ),
194
-					'post_content' => self::customize_message( __( $message, 'wpshop' ) ),
193
+					'post_title' => __($object, 'wpshop'),
194
+					'post_content' => self::customize_message(__($message, 'wpshop')),
195 195
 					'post_status' => 'publish',
196 196
 					'post_author' => 1,
197 197
 					'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE,
198 198
 				);
199
-				$id = wp_insert_post( $new_message );
199
+				$id = wp_insert_post($new_message);
200 200
 			}
201
-			update_option( $code, $id );
201
+			update_option($code, $id);
202 202
 		} else {
203 203
 			$id = $message_option;
204 204
 		}
@@ -211,17 +211,17 @@  discard block
 block discarded – undo
211 211
 	 *
212 212
 	 * @return array
213 213
 	 */
214
-	function messages_custom_columns( $column ) {
214
+	function messages_custom_columns($column) {
215 215
 
216 216
 		global $post;
217 217
 		$metadata = get_post_custom();
218
-		switch ( $column ) {
218
+		switch ($column) {
219 219
 			case 'extract':
220
-				echo wp_trim_words( $post->post_content, 55 );
220
+				echo wp_trim_words($post->post_content, 55);
221 221
 		break;
222 222
 			case 'last_dispatch_date':
223
-				if ( ! empty( $metadata['wpshop_message_last_dispatch_date'][0] ) ) {
224
-					echo mysql2date( 'd F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true );
223
+				if (!empty($metadata['wpshop_message_last_dispatch_date'][0])) {
224
+					echo mysql2date('d F Y, H:i:s', $metadata['wpshop_message_last_dispatch_date'][0], true);
225 225
 				} else { echo '-';
226 226
 				}
227 227
 		break;
@@ -233,14 +233,14 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @return array
235 235
 	 */
236
-	function messages_edit_columns( $columns ) {
236
+	function messages_edit_columns($columns) {
237 237
 
238 238
 		$columns = array(
239 239
 			'cb' => '<input type="checkbox" />',
240
-			'title' => __( 'Name', 'wpshop' ),
241
-			'extract' => __( 'Extract from the message','wpshop' ),
242
-			'date' => __( 'Creation date','wpshop' ),
243
-			'last_dispatch_date' => __( 'Last dispatch date','wpshop' ),
240
+			'title' => __('Name', 'wpshop'),
241
+			'extract' => __('Extract from the message', 'wpshop'),
242
+			'date' => __('Creation date', 'wpshop'),
243
+			'last_dispatch_date' => __('Last dispatch date', 'wpshop'),
244 244
 		);
245 245
 		return $columns;
246 246
 	}
@@ -251,17 +251,17 @@  discard block
 block discarded – undo
251 251
 	 * @param integer $current
252 252
 	 * @return string
253 253
 	 */
254
-	function getMessageListOption( $current = 0 ) {
254
+	function getMessageListOption($current = 0) {
255 255
 
256
-		$posts = query_posts( array(
256
+		$posts = query_posts(array(
257 257
 			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE,
258 258
 			'posts_per_page' => '-1',
259
-		) );
259
+		));
260 260
 		$options = '';
261
-		if ( ! empty( $posts ) ) {
262
-			$options = '<option value="0">' . __( 'Select values from list', 'wpshop' ) . '</option>';
263
-			foreach ( $posts as $p ) {
264
-				$selected = $p->ID == $current ? ' selected="selected"': '';
261
+		if (!empty($posts)) {
262
+			$options = '<option value="0">' . __('Select values from list', 'wpshop') . '</option>';
263
+			foreach ($posts as $p) {
264
+				$selected = $p->ID == $current ? ' selected="selected"' : '';
265 265
 				$options .= '<option value="' . $p->ID . '"' . $selected . '>' . $p->post_title . '</option>';
266 266
 			}
267 267
 		}
@@ -276,33 +276,33 @@  discard block
 block discarded – undo
276 276
 	 * @param integer $customer_id : ID to identifiate the customer
277 277
 	 * @return string
278 278
 	 */
279
-	function display_message_histo_per_customer( $args, $customer_id = '' ) {
280
-		$customer_id = ( ! empty( $customer_id ) ) ? $customer_id : ( isset( $args['cid'] ) && ! empty( $args['cid'] ) ? $args['cid'] : get_current_user_id() );
281
-		$message_id = ( ! empty( $args ) && ! empty( $args['message_id'] ) ) ? $args['message_id'] : '';
279
+	function display_message_histo_per_customer($args, $customer_id = '') {
280
+		$customer_id = (!empty($customer_id)) ? $customer_id : (isset($args['cid']) && !empty($args['cid']) ? $args['cid'] : get_current_user_id());
281
+		$message_id = (!empty($args) && !empty($args['message_id'])) ? $args['message_id'] : '';
282 282
 		$message_elements = '';
283 283
 		$wps_message_mdl = new wps_message_mdl();
284
-		$messages_data = $wps_message_mdl->get_messages_histo( $message_id, $customer_id );
284
+		$messages_data = $wps_message_mdl->get_messages_histo($message_id, $customer_id);
285 285
 
286 286
 		$messages_histo = array();
287
- 		foreach ( $messages_data as $meta_id => $messages ) :
287
+ 		foreach ($messages_data as $meta_id => $messages) :
288 288
  			$i = 0;
289
- 			foreach ( $messages as $message ) :
290
-				if ( $current_user->user_email === $message['mess_user_email'] ) :
291
-	 				$messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['title'] = $message['mess_title'];
292
-	 				$messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['message'] = $message['mess_message'];
293
-	 				$messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['dates'] = $message['mess_dispatch_date'];
294
-	 				if ( ! empty( $message['mess_object_id'] ) ) {
295
-	 					$messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['object'] = $message['mess_object_id'];
289
+ 			foreach ($messages as $message) :
290
+				if ($current_user->user_email === $message['mess_user_email']) :
291
+	 				$messages_histo[$message['mess_dispatch_date'][0]][$i]['title'] = $message['mess_title'];
292
+	 				$messages_histo[$message['mess_dispatch_date'][0]][$i]['message'] = $message['mess_message'];
293
+	 				$messages_histo[$message['mess_dispatch_date'][0]][$i]['dates'] = $message['mess_dispatch_date'];
294
+	 				if (!empty($message['mess_object_id'])) {
295
+	 					$messages_histo[$message['mess_dispatch_date'][0]][$i]['object'] = $message['mess_object_id'];
296 296
 	 				}
297 297
 	 				$i++;
298 298
 				endif;
299 299
  			endforeach;
300 300
  		endforeach;
301 301
 
302
-		ksort( $messages_histo );
303
-		$messages_histo = array_reverse( $messages_histo );
302
+		ksort($messages_histo);
303
+		$messages_histo = array_reverse($messages_histo);
304 304
 		ob_start();
305
-		require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'frontend', 'customer', 'messages' ) );
305
+		require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'frontend', 'customer', 'messages'));
306 306
 		$output = ob_get_contents();
307 307
 		ob_end_clean();
308 308
 
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 	 * @param string $message : message content
316 316
 	 * @return string
317 317
 	 */
318
-	public static function customize_message( $message ) {
318
+	public static function customize_message($message) {
319 319
 
320
-		if ( ! empty( $message ) ) {
320
+		if (!empty($message)) {
321 321
 			ob_start();
322
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', 'backend', 'message_html_structure' ) );
322
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', 'backend', 'message_html_structure'));
323 323
 			$message = ob_get_contents();
324 324
 			ob_end_clean();
325 325
 		}
@@ -330,15 +330,15 @@  discard block
 block discarded – undo
330 330
 	 *
331 331
 	 * @return boolean
332 332
 	 */
333
-	function add_message( $recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null ) {
333
+	function add_message($recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null) {
334 334
 
335
-		$date = empty( $date ) ? current_time( 'mysql', 0 ) : $date;
335
+		$date = empty($date) ? current_time('mysql', 0) : $date;
336 336
 		$object_empty = array(
337 337
 			'object_type' => '',
338 338
 			'object_id' => 0,
339 339
 		);
340
-		$object = array_merge( $object_empty, $object );
341
-		$historic = get_post_meta( $recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr( $date, 0, 7 ), true );
340
+		$object = array_merge($object_empty, $object);
341
+		$historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), true);
342 342
 		$data_to_insert = array(
343 343
 			'mess_user_id' => $recipient_id,
344 344
 			'mess_user_email' => $email,
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
 			'mess_object_id' => $object['object_id'],
347 347
 			'mess_title' => $title,
348 348
 			'mess_message' => $message,
349
-			'mess_dispatch_date' => array( $date ),
349
+			'mess_dispatch_date' => array($date),
350 350
 		);
351 351
 		$historic[] = $data_to_insert;
352
-		update_post_meta( $recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr( $date, 0, 7 ), $historic );
352
+		update_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), $historic);
353 353
 	}
354 354
 
355 355
 	/**
@@ -361,49 +361,49 @@  discard block
 block discarded – undo
361 361
 	 * @param boolean $duplicate_message : Duplicate a light message for historic storage
362 362
 	 * @return string
363 363
 	 */
364
-	function customMessage( $string, $data, $model_name = '', $duplicate_message = false ) {
364
+	function customMessage($string, $data, $model_name = '', $duplicate_message = false) {
365 365
 
366 366
 		$avant = array();
367 367
 		$apres = array();
368
-		$logo_option = get_option( 'wpshop_logo' );
368
+		$logo_option = get_option('wpshop_logo');
369 369
 
370
-		$data['your_shop_logo'] = ( ! empty( $logo_option ) ) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo( 'name' ) . '" />' : '';
370
+		$data['your_shop_logo'] = (!empty($logo_option)) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo('name') . '" />' : '';
371 371
 
372
-		foreach ( $data as $key => $value ) {
372
+		foreach ($data as $key => $value) {
373 373
 			$avant[] = '[' . $key . ']';
374
-			switch ( $key ) {
374
+			switch ($key) {
375 375
 				case 'order_content' :
376
-					$apres[] = ( $duplicate_message ) ? '[order_content]' : $this->order_content_template_for_mail( $data['order_id'] );
376
+					$apres[] = ($duplicate_message) ? '[order_content]' : $this->order_content_template_for_mail($data['order_id']);
377 377
 					break;
378 378
 				case 'order_addresses' :
379
-					$apres[] = ( $duplicate_message ) ? '[order_addresses]' : $this->order_addresses_template_for_mail( $data['order_id'] );
379
+					$apres[] = ($duplicate_message) ? '[order_addresses]' : $this->order_addresses_template_for_mail($data['order_id']);
380 380
 					break;
381 381
 
382 382
 				case 'order_billing_address' :
383
-					$apres[] = ( $duplicate_message ) ? '[order_billing_address]' : $this->order_addresses_template_for_mail( $data['order_id'], 'billing' );
383
+					$apres[] = ($duplicate_message) ? '[order_billing_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'billing');
384 384
 					break;
385 385
 
386 386
 				case 'order_shipping_address' :
387
-					$apres[] = ( $duplicate_message ) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail( $data['order_id'], 'shipping' );
387
+					$apres[] = ($duplicate_message) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'shipping');
388 388
 					break;
389 389
 
390 390
 				case 'order_customer_comments' :
391
-					$apres[] = ( $duplicate_message ) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail( $data['order_id'] );
391
+					$apres[] = ($duplicate_message) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail($data['order_id']);
392 392
 					break;
393 393
 				case 'order_personnal_informations' :
394
-					$apres[] = ( $duplicate_message ) ? '[order_personnal_informations]' : $this->order_personnal_informations();
394
+					$apres[] = ($duplicate_message) ? '[order_personnal_informations]' : $this->order_personnal_informations();
395 395
 					break;
396 396
 				default :
397 397
 					$apres[] = $value;
398 398
 					break;
399 399
 			}
400 400
 		}
401
-		$string = str_replace( $avant, $apres, $string );
401
+		$string = str_replace($avant, $apres, $string);
402 402
 
403
-		$string = apply_filters( 'wps_more_customized_message', $string, $data, $duplicate_message );
403
+		$string = apply_filters('wps_more_customized_message', $string, $data, $duplicate_message);
404 404
 
405
-		if ( ($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE') ) {
406
-			$string = preg_replace( '/\[(.*)\]/Usi', '', $string );
405
+		if (($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE')) {
406
+			$string = preg_replace('/\[(.*)\]/Usi', '', $string);
407 407
 		}
408 408
 
409 409
 		return $string;
@@ -418,22 +418,22 @@  discard block
 block discarded – undo
418 418
 	 * @param string $object : message object
419 419
 	 * @param file   $attached_file : File to attached to e-mail
420 420
 	 */
421
-	function wpshop_prepared_email( $email, $model_name, $data = array(), $object = array(), $attached_file = '' ) {
421
+	function wpshop_prepared_email($email, $model_name, $data = array(), $object = array(), $attached_file = '') {
422 422
 		global $wpdb;
423
-		$data = apply_filters( 'wps_extra_data_to_send_in_email', $data );
424
-		$model_id = get_option( $model_name, 0 );
425
-		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id );
426
-		$post_message = $wpdb->get_row( $query );
423
+		$data = apply_filters('wps_extra_data_to_send_in_email', $data);
424
+		$model_id = get_option($model_name, 0);
425
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id);
426
+		$post_message = $wpdb->get_row($query);
427 427
 		$duplicate_message = '';
428
-		if ( ! empty( $post_message ) ) {
429
-			$title = $this->customMessage( $post_message->post_title, $data, $model_name );
430
-			$message = $this->customMessage( $post_message->post_content, $data, $model_name );
428
+		if (!empty($post_message)) {
429
+			$title = $this->customMessage($post_message->post_title, $data, $model_name);
430
+			$message = $this->customMessage($post_message->post_content, $data, $model_name);
431 431
 			// End if().
432
-			if ( array_key_exists( 'order_content', $data ) || array_key_exists( 'order_addresses', $data ) || array_key_exists( 'order_customer_comments', $data ) ) {
433
-				$duplicate_message = $this->customMessage( $post_message->post_content, $data, $model_name, true );
432
+			if (array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data)) {
433
+				$duplicate_message = $this->customMessage($post_message->post_content, $data, $model_name, true);
434 434
 			}
435
-			if ( ! empty( $email ) ) {
436
-				$this->wpshop_email( $email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message );
435
+			if (!empty($email)) {
436
+				$this->wpshop_email($email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message);
437 437
 			}
438 438
 		}
439 439
 	}
@@ -450,37 +450,37 @@  discard block
 block discarded – undo
450 450
 	 * @param file    $attachments : File to attached to e-mail
451 451
 	 * @param string  $duplicate_message : lighter message to store
452 452
 	 */
453
-	function wpshop_email( $email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '' ) {
453
+	function wpshop_email($email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '') {
454 454
 		global $wpdb;
455 455
 		// Sauvegarde
456
-		if ( $save ) {
457
-			$user = $wpdb->get_row( 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";' );
456
+		if ($save) {
457
+			$user = $wpdb->get_row('SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";');
458 458
 			$user_id = $user ? $user->ID : get_current_user_id();
459
-			$query = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
460
-			$user_post_id = $wpdb->get_var( $query );
459
+			$query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
460
+			$user_post_id = $wpdb->get_var($query);
461 461
 
462
-			if ( ! empty( $duplicate_message ) ) {
463
-				$this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object );
462
+			if (!empty($duplicate_message)) {
463
+				$this->add_message($user_post_id, $email, $title, $duplicate_message, $model_id, $object);
464 464
 			} else {
465
-				$this->add_message( $user_post_id, $email, $title, $message, $model_id, $object );
465
+				$this->add_message($user_post_id, $email, $title, $message, $model_id, $object);
466 466
 			}
467 467
 		}
468 468
 
469
-		$emails = get_option( 'wpshop_emails', array() );
469
+		$emails = get_option('wpshop_emails', array());
470 470
 		$noreply_email = $emails['noreply_email'];
471 471
 		// Split the email to get the name
472
-		$vers_nom = substr( $email, 0, strpos( $email,'@' ) );
472
+		$vers_nom = substr($email, 0, strpos($email, '@'));
473 473
 
474 474
 		// Headers du mail
475 475
 		$headers = "MIME-Version: 1.0\r\n";
476 476
 		$headers .= "Content-type: text/html; charset=UTF-8\r\n";
477
-		$headers .= 'From: ' . get_bloginfo( 'name' ) . ' <' . $noreply_email . '>' . "\r\n";
477
+		$headers .= 'From: ' . get_bloginfo('name') . ' <' . $noreply_email . '>' . "\r\n";
478 478
 
479 479
 		// Mail en HTML
480
-		@wp_mail( $email, $title, $message, $headers, $attachments );
480
+		@wp_mail($email, $title, $message, $headers, $attachments);
481 481
 
482
-		if ( ! empty( $attachments ) ) {
483
-			unlink( $attachments );
482
+		if (!empty($attachments)) {
483
+			unlink($attachments);
484 484
 		}
485 485
 	}
486 486
 
@@ -490,13 +490,13 @@  discard block
 block discarded – undo
490 490
 	 * @param integer $order_id : Order ID
491 491
 	 * @return string
492 492
 	 */
493
-	function order_content_template_for_mail( $order_id ) {
493
+	function order_content_template_for_mail($order_id) {
494 494
 		$message = '';
495
-		if ( ! empty( $order_id ) ) {
496
-			$currency_code = wpshop_tools::wpshop_get_currency( false );
497
-			$orders_infos = get_post_meta( $order_id, '_order_postmeta', true );
495
+		if (!empty($order_id)) {
496
+			$currency_code = wpshop_tools::wpshop_get_currency(false);
497
+			$orders_infos = get_post_meta($order_id, '_order_postmeta', true);
498 498
 			ob_start();
499
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_content_mail_template' ) );
499
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_content_mail_template'));
500 500
 			$message .= ob_get_contents();
501 501
 			ob_end_clean();
502 502
 		}
@@ -510,44 +510,44 @@  discard block
 block discarded – undo
510 510
 	 * @param integer $address_type : Address type ID
511 511
 	 * @return string
512 512
 	 */
513
-	function order_addresses_template_for_mail( $order_id, $address_type = '' ) {
513
+	function order_addresses_template_for_mail($order_id, $address_type = '') {
514 514
 		global $wpdb;
515
-		$shipping_option = get_option( 'wpshop_shipping_address_choice' );
516
-		$display_shipping = ( ! empty( $shipping_option ) && ! empty( $shipping_option['activate'] ) ) ? true : false;
515
+		$shipping_option = get_option('wpshop_shipping_address_choice');
516
+		$display_shipping = (!empty($shipping_option) && !empty($shipping_option['activate'])) ? true : false;
517 517
 		$message = '';
518
-		if ( ! empty( $order_id ) ) {
519
-			$order_addresses = get_post_meta( $order_id, '_order_info', true );
520
-			if ( ! empty( $order_addresses ) ) {
521
-				foreach ( $order_addresses as $key => $order_address ) {
522
-					if ( ! empty( $order_address ) && ( empty( $address_type ) || $address_type == $key ) ) {
523
-
524
-						if ( $key != 'shipping' || ($key == 'shipping' && $display_shipping) ) {
525
-							$address_type_title = ( ! empty( $key ) && $key == 'billing' ) ? __( 'Billing address', 'wpshop' ) : __( 'Shipping address', 'wpshop' );
518
+		if (!empty($order_id)) {
519
+			$order_addresses = get_post_meta($order_id, '_order_info', true);
520
+			if (!empty($order_addresses)) {
521
+				foreach ($order_addresses as $key => $order_address) {
522
+					if (!empty($order_address) && (empty($address_type) || $address_type == $key)) {
523
+
524
+						if ($key != 'shipping' || ($key == 'shipping' && $display_shipping)) {
525
+							$address_type_title = (!empty($key) && $key == 'billing') ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop');
526 526
 							$civility = '';
527
-							if ( ! empty( $order_address['address']['civility'] ) ) {
528
-								$query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility'] );
529
-								$civility = $wpdb->get_var( $query );
527
+							if (!empty($order_address['address']['civility'])) {
528
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility']);
529
+								$civility = $wpdb->get_var($query);
530 530
 							}
531 531
 
532 532
 							// Address informations
533
-							$customer_last_name = ( ! empty( $order_address['address']['address_last_name'] ) ) ? $order_address['address']['address_last_name'] : '';
534
-							$customer_firtsname = ( ! empty( $order_address['address']['address_first_name'] ) ) ? $order_address['address']['address_first_name'] : '';
535
-							$customer_company = ( ! empty( $order_address['address']['company'] ) ) ? $order_address['address']['company'] : '';
536
-							$customer_address = ( ! empty( $order_address['address']['address'] ) ) ? $order_address['address']['address'] : '';
537
-							$customer_zip_code = ( ! empty( $order_address['address']['postcode'] ) ) ? $order_address['address']['postcode'] : '';
538
-							$customer_city = ( ! empty( $order_address['address']['city'] ) ) ? $order_address['address']['city'] : '';
539
-							$customer_state = ( ! empty( $order_address['address']['state'] ) ) ? $order_address['address']['state'] : '';
540
-							$customer_phone = ( ! empty( $order_address['address']['phone'] ) ) ? ' Tel. : ' . $order_address['address']['phone'] : '';
533
+							$customer_last_name = (!empty($order_address['address']['address_last_name'])) ? $order_address['address']['address_last_name'] : '';
534
+							$customer_firtsname = (!empty($order_address['address']['address_first_name'])) ? $order_address['address']['address_first_name'] : '';
535
+							$customer_company = (!empty($order_address['address']['company'])) ? $order_address['address']['company'] : '';
536
+							$customer_address = (!empty($order_address['address']['address'])) ? $order_address['address']['address'] : '';
537
+							$customer_zip_code = (!empty($order_address['address']['postcode'])) ? $order_address['address']['postcode'] : '';
538
+							$customer_city = (!empty($order_address['address']['city'])) ? $order_address['address']['city'] : '';
539
+							$customer_state = (!empty($order_address['address']['state'])) ? $order_address['address']['state'] : '';
540
+							$customer_phone = (!empty($order_address['address']['phone'])) ? ' Tel. : ' . $order_address['address']['phone'] : '';
541 541
 							$country = '';
542
-							foreach ( unserialize( WPSHOP_COUNTRY_LIST ) as $key => $value ) {
543
-								if ( ! empty( $order_address['address']['country'] ) && $key == $order_address['address']['country'] ) {
542
+							foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) {
543
+								if (!empty($order_address['address']['country']) && $key == $order_address['address']['country']) {
544 544
 									$country = $value;
545 545
 								}
546 546
 							}
547 547
 							$customer_country = $country;
548 548
 
549 549
 							ob_start();
550
-							require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_addresses_template_for_mail' ) );
550
+							require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_addresses_template_for_mail'));
551 551
 							$message .= ob_get_contents();
552 552
 							ob_end_clean();
553 553
 						}
@@ -564,20 +564,20 @@  discard block
 block discarded – undo
564 564
 	 * @param integer $order_id : Order ID
565 565
 	 * @return string
566 566
 	 */
567
-	function order_customer_comment_template_for_mail( $order_id ) {
567
+	function order_customer_comment_template_for_mail($order_id) {
568 568
 		global $wpdb;
569 569
 		$message = '';
570
-		if ( ! empty( $order_id ) ) {
571
-			$query = $wpdb->prepare( 'SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id );
572
-			$comment = $wpdb->get_var( $query );
573
-			$order_infos = get_post_meta( $order_id, '_order_postmeta', true );
574
-			if ( ! empty( $order_infos['order_key'] ) ) {
575
-				$comment_title = __( 'Comments about the order', 'wpshop' );
570
+		if (!empty($order_id)) {
571
+			$query = $wpdb->prepare('SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id);
572
+			$comment = $wpdb->get_var($query);
573
+			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
574
+			if (!empty($order_infos['order_key'])) {
575
+				$comment_title = __('Comments about the order', 'wpshop');
576 576
 			} else {
577
-				$comment_title = __( 'Comments about the quotation', 'wpshop' );
577
+				$comment_title = __('Comments about the quotation', 'wpshop');
578 578
 			}
579 579
 			ob_start();
580
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_email_customer_comments' ) );
580
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_email_customer_comments'));
581 581
 			$message .= ob_get_contents();
582 582
 			ob_end_clean();
583 583
 		}
@@ -593,15 +593,15 @@  discard block
 block discarded – undo
593 593
 		global $wpdb;
594 594
 		$user_id = get_current_user_id();
595 595
 		$message = '';
596
-		$customer_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
597
-		if ( ! empty( $customer_entity ) ) {
596
+		$customer_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
597
+		if (!empty($customer_entity)) {
598 598
 
599
-			$query = $wpdb->prepare( 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid' );
600
-			$attributes_sets = $wpdb->get_results( $query );
599
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid');
600
+			$attributes_sets = $wpdb->get_results($query);
601 601
 
602
-			if ( ! empty( $attributes_sets ) ) {
602
+			if (!empty($attributes_sets)) {
603 603
 				ob_start();
604
-				require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_personnal_informations_template_for_mail' ) );
604
+				require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_personnal_informations_template_for_mail'));
605 605
 				$message .= ob_get_contents();
606 606
 				ob_end_clean();
607 607
 			}
@@ -614,17 +614,17 @@  discard block
 block discarded – undo
614 614
 	 */
615 615
 	function wpshop_messages_historic_correction() {
616 616
 		global $wpdb;
617
-		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%' );
618
-		$messages_histo = $wpdb->get_results( $query );
617
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%');
618
+		$messages_histo = $wpdb->get_results($query);
619 619
 
620
-		foreach ( $messages_histo as $message ) {
621
-			$query_user = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s',  $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
622
-			$user_post_id = $wpdb->get_var( $query_user );
623
-			$wpdb->update( $wpdb->postmeta, array(
620
+		foreach ($messages_histo as $message) {
621
+			$query_user = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
622
+			$user_post_id = $wpdb->get_var($query_user);
623
+			$wpdb->update($wpdb->postmeta, array(
624 624
 				'post_id' => $user_post_id,
625 625
 				), array(
626 626
 				'meta_id' => $message->meta_id,
627
-			) );
627
+			));
628 628
 		}
629 629
 	}
630 630
 
@@ -633,20 +633,20 @@  discard block
 block discarded – undo
633 633
 	 * Récupères le contenu du message
634 634
 	 */
635 635
 	public function get_content_message() {
636
-		$_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
636
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
637 637
 
638
-		if ( ! wp_verify_nonce( $_wpnonce, 'get_content_message' ) ) {
638
+		if (!wp_verify_nonce($_wpnonce, 'get_content_message')) {
639 639
 			wp_die();
640 640
 		}
641 641
 
642 642
 		global $wpdb;
643
-		$meta_id = (int) $_GET['meta_id'];
643
+		$meta_id = (int)$_GET['meta_id'];
644 644
 
645
-		$result = $wpdb->get_results( $wpdb->prepare( 'SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_id=%d', array( ($meta_id) ) ) );
646
-		$result = unserialize( $result[0]->meta_value );
645
+		$result = $wpdb->get_results($wpdb->prepare('SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_id=%d', array(($meta_id))));
646
+		$result = unserialize($result[0]->meta_value);
647 647
 		$result = $result[0]['mess_message'];
648 648
 
649
-		wp_die( $result );
649
+		wp_die($result);
650 650
 	}
651 651
 
652 652
 }
Please login to merge, or discard this patch.
includes/wpshop_ajax.php 2 patches
Spacing   +980 added lines, -980 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
 * Ajax request management file
4 4
 *
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
 */
10 10
 
11 11
 /*	Check if file is include. No direct access possible with file url	*/
12
-if ( !defined( 'WPSHOP_VERSION' ) ) {
13
-	die( __('Access is not allowed by this way', 'wpshop') );
12
+if (!defined('WPSHOP_VERSION')) {
13
+	die(__('Access is not allowed by this way', 'wpshop'));
14 14
 }
15 15
 
16 16
 /*	Products	*/
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	function ajax_duplicate_product() {
21 21
 
22
-		check_ajax_referer( 'wpshop_product_duplication', 'wpshop_ajax_nonce' );
22
+		check_ajax_referer('wpshop_product_duplication', 'wpshop_ajax_nonce');
23 23
 
24 24
 		$current_post_id = isset($_POST['current_post_id']) ? sanitize_key($_POST['current_post_id']) : null;
25 25
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 	 * Delete an attachmant from a product
35 35
 	 */
36 36
 	function ajax_delete_product_thumbnail() {
37
-		check_ajax_referer( 'wpshop_delete_product_thumbnail', 'wpshop_ajax_nonce' );
37
+		check_ajax_referer('wpshop_delete_product_thumbnail', 'wpshop_ajax_nonce');
38 38
 
39 39
 		$bool = false;
40
-		$attachement_id = isset($_POST['attachement_id']) ? (int) $_POST['attachement_id'] : null;
40
+		$attachement_id = isset($_POST['attachement_id']) ? (int)$_POST['attachement_id'] : null;
41 41
 
42
-		if ( !empty($attachement_id) ) {
42
+		if (!empty($attachement_id)) {
43 43
 			$deletion_result = wp_delete_attachment($attachement_id, false);
44 44
 			$bool = !empty($deletion_result);
45 45
 		}
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 	 * Reload attachment container
53 53
 	 */
54 54
 	function ajax_reload_attachment_boxes() {
55
-		check_ajax_referer( 'wpshop_reload_product_attachment_part', 'wpshop_ajax_nonce' );
55
+		check_ajax_referer('wpshop_reload_product_attachment_part', 'wpshop_ajax_nonce');
56 56
 
57 57
 		$bool = false;
58
-		$current_post_id = isset($_POST['current_post_id']) ? (int) $_POST['current_post_id'] : null;
58
+		$current_post_id = isset($_POST['current_post_id']) ? (int)$_POST['current_post_id'] : null;
59 59
 		$attachement_type_list = array('reload_box_document' => 'application/pdf', 'reload_box_picture' => 'image/');
60
-		$part_to_reload = isset($_POST['part_to_reload']) ? sanitize_text_field( $_POST['part_to_reload']) : null;
60
+		$part_to_reload = isset($_POST['part_to_reload']) ? sanitize_text_field($_POST['part_to_reload']) : null;
61 61
 		$attachement_type = $attachement_type_list[$part_to_reload];
62 62
 
63 63
 		echo json_encode(array(wpshop_products::product_attachement_by_type($current_post_id, $attachement_type, 'media-upload.php?post_id=' . $current_post_id . '&amp;tab=library&amp;type=image&amp;TB_iframe=1&amp;width=640&amp;height=566'), $part_to_reload));
@@ -70,25 +70,25 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	function ajax_product_bulk_edit_save() {
72 72
 		global $wpdb;
73
-		check_ajax_referer( 'product_bulk_edit_save', 'wpshop_ajax_nonce' );
73
+		check_ajax_referer('product_bulk_edit_save', 'wpshop_ajax_nonce');
74 74
 
75
-		$post_ids = ( isset( $_POST[ 'post_ids' ] ) && !empty( $_POST[ 'post_ids' ] ) ) ? (array) $_POST[ 'post_ids' ] : array();
76
-		$post_attributes = ( isset( $_POST[ 'attribute' ] ) && !empty( $_POST[ 'attribute' ] ) ) ? (array) $_POST[ 'attribute' ] : array();
75
+		$post_ids = (isset($_POST['post_ids']) && !empty($_POST['post_ids'])) ? (array)$_POST['post_ids'] : array();
76
+		$post_attributes = (isset($_POST['attribute']) && !empty($_POST['attribute'])) ? (array)$_POST['attribute'] : array();
77 77
 
78
-		if ( !empty( $post_ids ) && is_array( $post_ids ) && !empty( $post_attributes ) && is_array( $post_attributes ) ) {
78
+		if (!empty($post_ids) && is_array($post_ids) && !empty($post_attributes) && is_array($post_attributes)) {
79 79
 			$attribute_to_save = array();
80
-			foreach ( $post_attributes as $attribute ) {
80
+			foreach ($post_attributes as $attribute) {
81 81
 				$attribute_component = explode('_-val-_', $attribute);
82 82
 				$attribute_definition = explode('[', $attribute_component[0]);
83 83
 				$attribute_data_type = substr($attribute_definition[1], 0, -1);
84 84
 				$attribute_code = substr($attribute_definition[2], 0, -1);
85 85
 
86
-				if ( !empty($attribute_component[1]) ) {
86
+				if (!empty($attribute_component[1])) {
87 87
 					$attribute_to_save[$attribute_data_type][$attribute_code] = $attribute_component[1];
88 88
 				}
89 89
 			}
90 90
 
91
-			foreach ( $post_ids as $post_id ) {
91
+			foreach ($post_ids as $post_id) {
92 92
 				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = (SELECT language_code FROM " . $wpdb->prefix . "icl_translations WHERE element_id = %d )", $post_id);
93 93
 				$lang_wpml = $wpdb->get_var($query);
94 94
 				$lang = !empty($lang_wpml) ? $lang_wpml : WPSHOP_CURRENT_LOCALE;
@@ -100,18 +100,18 @@  discard block
 block discarded – undo
100 100
 
101 101
 				/*	Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working	*/
102 102
 				$productMetaDatas = get_post_meta($post_id, '_wpshop_product_metadata', true);
103
-				if ( !empty($productMetaDatas) ) {
103
+				if (!empty($productMetaDatas)) {
104 104
 					$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $post_id);
105
-					if ( !empty($attributes_list)) {
105
+					if (!empty($attributes_list)) {
106 106
 						foreach ($attributes_list as $attribute) {
107
-							$value_key = 'attribute_value_'.$attribute->data_type;
107
+							$value_key = 'attribute_value_' . $attribute->data_type;
108 108
 							$productMetaDatas[$attribute->code] = $attribute->$value_key;
109 109
 						}
110 110
 					}
111 111
 				}
112
-				foreach($attribute_to_save as $attributeType => $attributeValues){
113
-					foreach($attributeValues as $attributeCode => $attributeValue){
114
-						if ( $attributeCode == 'product_attribute_set_id' ) {
112
+				foreach ($attribute_to_save as $attributeType => $attributeValues) {
113
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
114
+						if ($attributeCode == 'product_attribute_set_id') {
115 115
 							/*	Update the attribute set id for the current product	*/
116 116
 							update_post_meta($post_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
117 117
 						}
@@ -123,18 +123,18 @@  discard block
 block discarded – undo
123 123
 
124 124
 
125 125
 				/* If the product have some variations */
126
-				$query = $wpdb->prepare('SELECT * FROM ' .$wpdb->posts. ' WHERE post_parent = %d AND post_type = %s', $post_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION);
126
+				$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_parent = %d AND post_type = %s', $post_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION);
127 127
 				$product_variations = $wpdb->get_results($query);
128
-				if ( !empty($product_variations) ) {
129
-					foreach( $product_variations as $product_variation ) {
128
+				if (!empty($product_variations)) {
129
+					foreach ($product_variations as $product_variation) {
130 130
 						$variation_post_meta = get_post_meta($product_variation->ID, '_wpshop_product_metadata', true);
131 131
 						$common_attributes = unserialize(WPSHOP_COMMON_ATTRIBUTES_PARENT_VARIATION_PRODUCT);
132
-						if ( !empty($common_attributes) ) {
133
-							if ( !empty($parent_product_metadata) ) {
134
-								foreach( $parent_product_metadata as $key => $value ) {
135
-									if ( in_array($key, $common_attributes) ) {
132
+						if (!empty($common_attributes)) {
133
+							if (!empty($parent_product_metadata)) {
134
+								foreach ($parent_product_metadata as $key => $value) {
135
+									if (in_array($key, $common_attributes)) {
136 136
 										$variation_post_meta[$key] = $value;
137
-										update_post_meta($product_variation->ID, '_'.$key, $value);
137
+										update_post_meta($product_variation->ID, '_' . $key, $value);
138 138
 									}
139 139
 								}
140 140
 								update_post_meta($product_variation->ID, '_wpshop_product_metadata', $variation_post_meta);
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		die();
152 152
 	}
153
-	add_action( 'wp_ajax_product_bulk_edit_save', 'ajax_product_bulk_edit_save' );
153
+	add_action('wp_ajax_product_bulk_edit_save', 'ajax_product_bulk_edit_save');
154 154
 /*	Products	*/
155 155
 
156 156
 /*	Variations	*/
@@ -158,25 +158,25 @@  discard block
 block discarded – undo
158 158
 	 * Variation list creation
159 159
 	 */
160 160
 	function ajax_add_new_variation_list() {
161
-		check_ajax_referer( 'wpshop_variation_management', 'wpshop_ajax_nonce' );
161
+		check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce');
162 162
 		global $wpdb;
163 163
 
164
-		$attributes_for_variation = isset($_POST['wpshop_attribute_to_use_for_variation']) ? (array) $_POST['wpshop_attribute_to_use_for_variation'] : null;
164
+		$attributes_for_variation = isset($_POST['wpshop_attribute_to_use_for_variation']) ? (array)$_POST['wpshop_attribute_to_use_for_variation'] : null;
165 165
 		$current_post_id = isset($_POST['current_post_id']) ? sanitize_key($_POST['current_post_id']) : null;
166 166
 
167 167
 		/** Get the list of values of the attribute to affect to a variation	*/
168 168
 		$var = array();
169 169
 
170
-		foreach ( $attributes_for_variation as $attribute_code ) {
170
+		foreach ($attributes_for_variation as $attribute_code) {
171 171
 			$query = $wpdb->prepare("SELECT data_type_to_use FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_code);
172
-			$var[$attribute_code] = wpshop_attributes::get_affected_value_for_list( $attribute_code, $current_post_id, $wpdb->get_var($query));
172
+			$var[$attribute_code] = wpshop_attributes::get_affected_value_for_list($attribute_code, $current_post_id, $wpdb->get_var($query));
173 173
 		}
174 174
 
175
-		$possible_variations = wpshop_tools::search_all_possibilities( $var );
175
+		$possible_variations = wpshop_tools::search_all_possibilities($var);
176 176
 
177
-		wpshop_products::creation_variation_callback( $possible_variations, $current_post_id );
177
+		wpshop_products::creation_variation_callback($possible_variations, $current_post_id);
178 178
 
179
-		$output = wpshop_products::display_variation_admin( $current_post_id );
179
+		$output = wpshop_products::display_variation_admin($current_post_id);
180 180
 
181 181
 		echo $output;
182 182
 		die();
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
 	 * Variation uniq item creation
188 188
 	 */
189 189
 	function ajax_new_single_variation_definition() {
190
-		check_ajax_referer( 'wpshop_variation_management', 'wpshop_ajax_nonce' );
190
+		check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce');
191 191
 		$output = '';
192 192
 
193 193
 		$current_post_id = isset($_POST['current_post_id']) ? sanitize_key($_POST['current_post_id']) : null;
194 194
 
195 195
 		/*	Get the list of values of the attribute to affect to a variation	*/
196
-		$attribute_for_variation = wpshop_attributes::get_variation_available_attribute_display( $current_post_id, 'single' );
196
+		$attribute_for_variation = wpshop_attributes::get_variation_available_attribute_display($current_post_id, 'single');
197 197
 		$output = $attribute_for_variation[0];
198 198
 
199 199
 		/**	Display specific element for variation	*/
200 200
 		$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = '';
201 201
 		$tpl_component['VARIATION_IDENTIFIER'] = 'new';
202
-		$tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute( array('input_class' => ' new_variation_specific_values', 'field_name' => wpshop_products::current_page_variation_code . '[' . $tpl_component['VARIATION_IDENTIFIER'] . ']','page_code' => wpshop_products::current_page_variation_code, 'field_id' => wpshop_products::current_page_variation_code . '_' . $tpl_component['VARIATION_IDENTIFIER'], 'variation_dif_values' => '') );
202
+		$tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('input_class' => ' new_variation_specific_values', 'field_name' => wpshop_products::current_page_variation_code . '[' . $tpl_component['VARIATION_IDENTIFIER'] . ']', 'page_code' => wpshop_products::current_page_variation_code, 'field_id' => wpshop_products::current_page_variation_code . '_' . $tpl_component['VARIATION_IDENTIFIER'], 'variation_dif_values' => ''));
203 203
 		$output .= wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $current_post_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $tpl_component['VARIATION_IDENTIFIER']), 'admin');
204 204
 
205 205
 		$tpl_component = array();
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
 	 * Combined variation list creation
218 218
 	 */
219 219
 	function ajax_new_combined_variation_list_definition() {
220
-		check_ajax_referer( 'wpshop_variation_management', 'wpshop_ajax_nonce' );
220
+		check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce');
221 221
 		$current_post_id = isset($_POST['current_post_id']) ? sanitize_key($_POST['current_post_id']) : null;
222 222
 		$output = '';
223 223
 
224
-		$attribute_for_variation = wpshop_attributes::get_variation_available_attribute_display( $current_post_id );
224
+		$attribute_for_variation = wpshop_attributes::get_variation_available_attribute_display($current_post_id);
225 225
 		$output = $attribute_for_variation[0];
226 226
 
227 227
 		echo $output;
@@ -233,43 +233,43 @@  discard block
 block discarded – undo
233 233
 	 * Product variaitons parameters
234 234
 	 */
235 235
 	function wpshop_ajax_admin_variation_parameters() {
236
-		check_ajax_referer( 'wpshop_variation_management', 'wpshop_ajax_nonce' );
236
+		check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce');
237 237
 
238 238
 		$current_post_id = isset($_POST['current_post_id']) ? sanitize_key($_POST['current_post_id']) : null;
239 239
 		$output = '';
240 240
 
241 241
 		/*	Display variation options	*/
242 242
 		$options_tpl_component = array();
243
-		$head_wpshop_variation_definition = get_post_meta( $current_post_id, '_wpshop_variation_defining', true );
244
-		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRIORITY_SINGLE'] = ( empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['priority'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['priority'][0]) && ($head_wpshop_variation_definition['options']['priority'][0] == 'single')) ) ? ' checked="checked"' : '';
245
-		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRIORITY_COMBINED'] = ( empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['priority'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['priority'][0]) && ($head_wpshop_variation_definition['options']['priority'][0] == 'combined')) ) ? ' checked="checked"' : '';
246
-		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_BEHAVIOUR_ADDITION'] = ( empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) && ($head_wpshop_variation_definition['options']['price_behaviour'][0] == 'addition')) ) ? ' checked="checked"' : '';
247
-		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_BEHAVIOUR_REPLACEMENT'] = ( empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) && ($head_wpshop_variation_definition['options']['price_behaviour'][0] == 'replacement')) ) ? ' checked="checked"' : '';
243
+		$head_wpshop_variation_definition = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
244
+		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRIORITY_SINGLE'] = (empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['priority'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['priority'][0]) && ($head_wpshop_variation_definition['options']['priority'][0] == 'single'))) ? ' checked="checked"' : '';
245
+		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRIORITY_COMBINED'] = (empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['priority'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['priority'][0]) && ($head_wpshop_variation_definition['options']['priority'][0] == 'combined'))) ? ' checked="checked"' : '';
246
+		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_BEHAVIOUR_ADDITION'] = (empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) && ($head_wpshop_variation_definition['options']['price_behaviour'][0] == 'addition'))) ? ' checked="checked"' : '';
247
+		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_BEHAVIOUR_REPLACEMENT'] = (empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) || (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) && ($head_wpshop_variation_definition['options']['price_behaviour'][0] == 'replacement'))) ? ' checked="checked"' : '';
248 248
 
249
-		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRICE_DISPLAY_TEXT_FROM'] = ( ( empty($head_wpshop_variation_definition['options']) ) || ( (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_display']['text_from']) && ($head_wpshop_variation_definition['options']['price_display']['text_from'] == 'on')) ) ) ? ' checked="checked"' : '';
250
-		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRICE_DISPLAY_LOWER_PRICE'] = ( (empty($head_wpshop_variation_definition['options']) ) || ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_display']['lower_price']) && ($head_wpshop_variation_definition['options']['price_display']['lower_price'] == 'on')) ) ) ? ' checked="checked"' : '';
249
+		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRICE_DISPLAY_TEXT_FROM'] = ((empty($head_wpshop_variation_definition['options'])) || ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_display']['text_from']) && ($head_wpshop_variation_definition['options']['price_display']['text_from'] == 'on')))) ? ' checked="checked"' : '';
250
+		$options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRICE_DISPLAY_LOWER_PRICE'] = ((empty($head_wpshop_variation_definition['options'])) || ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_display']['lower_price']) && ($head_wpshop_variation_definition['options']['price_display']['lower_price'] == 'on')))) ? ' checked="checked"' : '';
251 251
 
252 252
 		$options_tpl_component['ADMIN_VARIATION_PARAMETERS_FORM_HEAD_PRODUCT_ID'] = $current_post_id;
253 253
 		$options_tpl_component['ADMIN_VARIATION_PARAMETERS_FORM_HEAD_NOUNCE'] = wp_create_nonce("wpshop_variation_parameters");
254 254
 
255 255
 		$options_tpl_component['ADMIN_MORE_OPTIONS_FOR_VARIATIONS'] = '';
256 256
 
257
-		$attribute_list_for_variations = wpshop_attributes::get_variation_available_attribute( $current_post_id );
257
+		$attribute_list_for_variations = wpshop_attributes::get_variation_available_attribute($current_post_id);
258 258
 
259 259
 		$default_value_for_attributes = $required_attributes = '';
260 260
 
261
-		$attribute_user_defined = wpshop_attributes::get_attribute_user_defined( array('entity_type_id' => get_post_type($current_post_id)) );
262
-		if ( !empty($attribute_user_defined) ) {
263
-			foreach ( $attribute_user_defined as $attribute_def ) {
261
+		$attribute_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => get_post_type($current_post_id)));
262
+		if (!empty($attribute_user_defined)) {
263
+			foreach ($attribute_user_defined as $attribute_def) {
264 264
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_LABEL_STATE'] = '';
265 265
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL_EXPLAINATION'] = '';
266 266
 
267 267
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_CODE'] = $attribute_def->code;
268 268
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_NAME'] = $attribute_def->code;
269
-				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL'] = __( $attribute_def->frontend_label, 'wpshop' );
269
+				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL'] = __($attribute_def->frontend_label, 'wpshop');
270 270
 				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CONTAINER_CLASS'] = '';
271 271
 
272
-				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = ( (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && ( in_array( $attribute_def->code, $head_wpshop_variation_definition['options']['required_attributes']) )) ) ? ' checked="checked"' : '';
272
+				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_def->code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? ' checked="checked"' : '';
273 273
 
274 274
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_ID'] = 'required_' . $attribute_def->code;
275 275
 
@@ -277,15 +277,15 @@  discard block
 block discarded – undo
277 277
 			}
278 278
 		}
279 279
 
280
-		if ( !empty($attribute_list_for_variations['available']) ) {
281
-			$head_wpshop_variation_definition = get_post_meta( $current_post_id, '_wpshop_variation_defining', true );
282
-			foreach ( $attribute_list_for_variations['available'] as $attribute_code => $attribute_definition ) {
280
+		if (!empty($attribute_list_for_variations['available'])) {
281
+			$head_wpshop_variation_definition = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
282
+			foreach ($attribute_list_for_variations['available'] as $attribute_code => $attribute_definition) {
283 283
 				/** Default value for attribute	*/
284 284
 				$tpl_component = array();
285 285
 				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CONTAINER_CLASS'] = ' variation_attribute_container_default_value_' . $attribute_code;
286 286
 
287 287
 				$attribute_for_default_value = wpshop_attributes::get_attribute_field_definition($attribute_definition['attribute_complete_def'], (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : 'none'), array('from' => 'frontend', 'field_custom_name_prefix' => 'empty'));
288
-				switch ( $attribute_for_default_value['type'] ) {
288
+				switch ($attribute_for_default_value['type']) {
289 289
 					case 'select':
290 290
 					case 'multiple-select':
291 291
 					case 'radio':
@@ -297,17 +297,17 @@  discard block
 block discarded – undo
297 297
 						break;
298 298
 				}
299 299
 
300
-				if ( !empty($attribute_for_default_value['possible_value']) ) {
300
+				if (!empty($attribute_for_default_value['possible_value'])) {
301 301
 					$attribute_for_default_value['possible_value']['none'] = __('No default value', 'wpshop');
302
-					foreach( $attribute_for_default_value['possible_value'] as $value_id => $value ){
303
-						if ( !empty($value_id) && ($value_id != 'none') && !in_array($value_id, $attribute_definition['values']) ) {
302
+					foreach ($attribute_for_default_value['possible_value'] as $value_id => $value) {
303
+						if (!empty($value_id) && ($value_id != 'none') && !in_array($value_id, $attribute_definition['values'])) {
304 304
 							unset($attribute_for_default_value['possible_value'][$value_id]);
305 305
 						}
306 306
 					}
307 307
 					ksort($attribute_for_default_value['possible_value']);
308 308
 
309 309
 					$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_ID'] = $attribute_for_default_value['id'];
310
-					$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_DEFAULT_VALUE_LABEL'] = sprintf( __('Default value for %s', 'wpshop'), $attribute_for_default_value['label'] );
310
+					$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_DEFAULT_VALUE_LABEL'] = sprintf(__('Default value for %s', 'wpshop'), $attribute_for_default_value['label']);
311 311
 					$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_DEFAULT_VALUE_INPUT'] = wpshop_form::check_input_type($attribute_for_default_value, 'wps_pdt_variations[options][attributes_default_value]');
312 312
 					$default_value_for_attributes .= wpshop_display::display_template_element('wpshop_admin_attribute_for_variation_item_for_default', $tpl_component, array(), 'admin');
313 313
 				}
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
 
319 319
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_CODE'] = $attribute_code;
320 320
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_NAME'] = $attribute_code;
321
-				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL'] = __( $attribute_definition['label'], 'wpshop' );
321
+				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL'] = __($attribute_definition['label'], 'wpshop');
322 322
 				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CONTAINER_CLASS'] = '';
323 323
 
324
-				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = ( (!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && ( in_array( $attribute_code, $head_wpshop_variation_definition['options']['required_attributes']) )) ) ? ' checked="checked"' : '';
324
+				$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? ' checked="checked"' : '';
325 325
 
326 326
 				$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_ID'] = 'required_' . $attribute_code;
327 327
 				$required_attributes .= str_replace('wpshop_attribute_to_use_for_variation', 'wps_pdt_variations[options][required_attributes]', str_replace('variation_attribute_usable', 'variation_attribute_required', wpshop_display::display_template_element('wpshop_admin_attribute_for_variation_item', $tpl_component, array(), 'admin')));
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
 	 * Save product variation paramters
345 345
 	 */
346 346
 	function wpshop_ajax_admin_variation_parameters_save() {
347
-		check_ajax_referer( 'wpshop_variation_parameters', 'wpshop_ajax_nonce' );
347
+		check_ajax_referer('wpshop_variation_parameters', 'wpshop_ajax_nonce');
348 348
 
349 349
 		$current_post_id = isset($_POST['current_post_id']) ? sanitize_key($_POST['current_post_id']) : null;
350
-		$options = !empty( $_POST[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION]['options'] ) ? (array)$_POST[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION]['options'] : array();
350
+		$options = !empty($_POST[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION]['options']) ? (array)$_POST[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION]['options'] : array();
351 351
 
352
-		if ( !empty($options) ) {
353
-			wpshop_products::variation_parameters_save( $post_id, $options );
352
+		if (!empty($options)) {
353
+			wpshop_products::variation_parameters_save($post_id, $options);
354 354
 		}
355 355
 
356 356
 		die();
@@ -361,41 +361,41 @@  discard block
 block discarded – undo
361 361
 	 * Variation uniq item creation
362 362
 	 */
363 363
 	function ajax_add_new_single_variation() {
364
-		check_ajax_referer( 'wpshop_variation_management', 'wpshop_ajax_nonce' );
364
+		check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce');
365 365
 		$output = '';
366 366
 
367
-		$attributes_for_variation = isset($_POST['variation_attr']) ? (array) $_POST['variation_attr'] : null;
368
-		$wpshop_admin_use_attribute_for_single_variation_checkbox = isset($_POST['wpshop_admin_use_attribute_for_single_variation_checkbox']) ? (array) $_POST['wpshop_admin_use_attribute_for_single_variation_checkbox'] : null;
369
-		$variation_specific_definition = isset($_POST['wps_pdt_variations']['new']['attribute']) ? (array) $_POST['wps_pdt_variations']['new']['attribute'] : null;
367
+		$attributes_for_variation = isset($_POST['variation_attr']) ? (array)$_POST['variation_attr'] : null;
368
+		$wpshop_admin_use_attribute_for_single_variation_checkbox = isset($_POST['wpshop_admin_use_attribute_for_single_variation_checkbox']) ? (array)$_POST['wpshop_admin_use_attribute_for_single_variation_checkbox'] : null;
369
+		$variation_specific_definition = isset($_POST['wps_pdt_variations']['new']['attribute']) ? (array)$_POST['wps_pdt_variations']['new']['attribute'] : null;
370 370
 		$current_post_id = isset($_POST['wpshop_head_product_id']) ? sanitize_key($_POST['wpshop_head_product_id']) : null;
371
-		$display = isset( $_POST['data'] ) ? (bool) $_POST['data'] : false;
371
+		$display = isset($_POST['data']) ? (bool)$_POST['data'] : false;
372 372
 
373 373
 		$attribute_to_use_for_creation = array();
374
-		foreach ( $attributes_for_variation as $attribute_code => $attribute_value) {
375
-			if ( array_key_exists($attribute_code, $wpshop_admin_use_attribute_for_single_variation_checkbox) ) {
374
+		foreach ($attributes_for_variation as $attribute_code => $attribute_value) {
375
+			if (array_key_exists($attribute_code, $wpshop_admin_use_attribute_for_single_variation_checkbox)) {
376 376
 				$attribute_to_use_for_creation[0][$attribute_code] = $attributes_for_variation[$attribute_code];
377 377
 				$attr_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
378 378
 				$variation_specific_definition[$attr_def->data_type][$attribute_code] = $attributes_for_variation[$attribute_code];
379 379
 			}
380 380
 		}
381
-		$new_variation_identifier = wpshop_products::creation_variation_callback( $attribute_to_use_for_creation, $current_post_id );
381
+		$new_variation_identifier = wpshop_products::creation_variation_callback($attribute_to_use_for_creation, $current_post_id);
382 382
 
383 383
 		/*	Save variation specific element	*/
384
-		foreach ( unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
384
+		foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
385 385
 			$head_product_price_attribute_value = wpshop_attributes::get_attribute_value_content($price_attribute_code, $current_post_id, wpshop_products::currentPageCode);
386 386
 			$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
387
-			if ( !empty($price_attr_def) && !empty($price_attr_def->data_type) && (empty($variation_specific_definition[$price_attr_def->data_type]) || !array_key_exists($price_attribute_code, $variation_specific_definition[$price_attr_def->data_type]))) {
387
+			if (!empty($price_attr_def) && !empty($price_attr_def->data_type) && (empty($variation_specific_definition[$price_attr_def->data_type]) || !array_key_exists($price_attribute_code, $variation_specific_definition[$price_attr_def->data_type]))) {
388 388
 				$variation_specific_definition[$price_attr_def->data_type][$price_attribute_code] = !empty($head_product_price_attribute_value->value) ? $head_product_price_attribute_value->value : 1;
389 389
 			}
390 390
 		}
391 391
 
392 392
 		wpshop_attributes::saveAttributeForEntity($variation_specific_definition, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $new_variation_identifier, WPSHOP_CURRENT_LOCALE);
393
-		wpshop_products::calculate_price( $new_variation_identifier );
393
+		wpshop_products::calculate_price($new_variation_identifier);
394 394
 
395
-		if( $display ) {
396
-			$output = json_encode( array( 'ID' => $new_variation_identifier ) );
395
+		if ($display) {
396
+			$output = json_encode(array('ID' => $new_variation_identifier));
397 397
 		} else {
398
-			$output = wpshop_products::display_variation_admin( $current_post_id );
398
+			$output = wpshop_products::display_variation_admin($current_post_id);
399 399
 		}
400 400
 
401 401
 		echo $output;
@@ -407,14 +407,14 @@  discard block
 block discarded – undo
407 407
 	 * Delete a variation
408 408
 	*/
409 409
 	function ajax_delete_variation() {
410
-		check_ajax_referer( 'wpshop_variation_management', 'wpshop_ajax_nonce' );
410
+		check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce');
411 411
 		$result = false;
412 412
 		$list_to_remove = '';
413 413
 
414
-		$current_post_id = isset($_POST['current_post_id']) && is_array($_POST['current_post_id']) ? (array) $_POST['current_post_id'] : null;
415
-		foreach ( $current_post_id as $variation_id) {
414
+		$current_post_id = isset($_POST['current_post_id']) && is_array($_POST['current_post_id']) ? (array)$_POST['current_post_id'] : null;
415
+		foreach ($current_post_id as $variation_id) {
416 416
 			$result = wp_delete_post($variation_id, false);
417
-			if ( $result ) {
417
+			if ($result) {
418 418
 				$list_to_remove[] = $variation_id;
419 419
 			}
420 420
 		}
@@ -442,20 +442,20 @@  discard block
 block discarded – undo
442 442
 /*	Orders	*/
443 443
 	/* Validate the payment transaction number */
444 444
 	function wpshop_ajax_validate_payment_method() {
445
-		check_ajax_referer( 'wpshop_validate_payment_method', 'wpshop_ajax_nonce' );
446
-		$order_id = ( isset( $_POST[ 'order_id' ] ) && !empty( $_POST[ 'order_id' ] ) ) ? (int) $_POST[ 'order_id' ] : null;
447
-		$payment_method = ( isset( $_POST[ 'payment_method' ] ) && !empty( $_POST[ 'payment_method' ] ) ) ? sanitize_text_field( $_POST[ 'payment_method' ] ) : null;
448
-		$transaction_id = ( isset( $_POST[ 'transaction_id' ] ) && !empty( $_POST[ 'transaction_id' ] ) ) ? (int) $_POST[ 'transaction_id' ] : null;
445
+		check_ajax_referer('wpshop_validate_payment_method', 'wpshop_ajax_nonce');
446
+		$order_id = (isset($_POST['order_id']) && !empty($_POST['order_id'])) ? (int)$_POST['order_id'] : null;
447
+		$payment_method = (isset($_POST['payment_method']) && !empty($_POST['payment_method'])) ? sanitize_text_field($_POST['payment_method']) : null;
448
+		$transaction_id = (isset($_POST['transaction_id']) && !empty($_POST['transaction_id'])) ? (int)$_POST['transaction_id'] : null;
449 449
 
450
-		if ( !empty($order_id) ) {
451
-			if( !empty($payment_method) && !empty($transaction_id) ) {
450
+		if (!empty($order_id)) {
451
+			if (!empty($payment_method) && !empty($transaction_id)) {
452 452
 				/* Update he payment method */
453 453
 				$order = get_post_meta($order_id, '_order_postmeta', true);
454 454
 				$order['payment_method'] = $payment_method;
455 455
 				update_post_meta($order_id, '_order_postmeta', $order);
456 456
 
457 457
 				// Update Transaction identifier regarding the payment method
458
-				if ( !empty($transaction_id) ) {
458
+				if (!empty($transaction_id)) {
459 459
 // 					$transaction_key = '';
460 460
 // 					switch($payment_method) {
461 461
 // 						case 'check':
@@ -465,28 +465,28 @@  discard block
 block discarded – undo
465 465
 // 					if ( !empty($transaction_key) ) update_post_meta($order_id, $transaction_key, $transaction_id);
466 466
 					wpshop_payment::set_payment_transaction_number($order_id, $transaction_id);
467 467
 				}
468
-				$result = json_encode(array(true,''));
468
+				$result = json_encode(array(true, ''));
469 469
 			}
470 470
 			else {
471
-				$result = json_encode(array(false,__('Choose a payment method and/or type a transaction number', 'wpshop')));
471
+				$result = json_encode(array(false, __('Choose a payment method and/or type a transaction number', 'wpshop')));
472 472
 			}
473 473
 		}
474 474
 		else {
475
-			$result = json_encode(array(false,__('Bad order identifier', 'wpshop')));
475
+			$result = json_encode(array(false, __('Bad order identifier', 'wpshop')));
476 476
 		}
477 477
 		echo json_encode($result);
478 478
 		die();
479 479
 	}
480
-	add_action( 'wp_ajax_validate_payment_method', 'wpshop_ajax_validate_payment_method' );
480
+	add_action('wp_ajax_validate_payment_method', 'wpshop_ajax_validate_payment_method');
481 481
 
482 482
 
483 483
 	/* Display a dialog box to inform a shipping tracking number */
484 484
 	function wpshop_ajax_dialog_inform_shipping_number() {
485
-		check_ajax_referer( 'wpshop_dialog_inform_shipping_number', 'wpshop_ajax_nonce' );
486
-		$order_id = ( isset( $_POST[ 'order_id' ] ) && !empty( $_POST[ 'order_id' ] ) ) ? (int)$_POST[ 'order_id' ] : null;
485
+		check_ajax_referer('wpshop_dialog_inform_shipping_number', 'wpshop_ajax_nonce');
486
+		$order_id = (isset($_POST['order_id']) && !empty($_POST['order_id'])) ? (int)$_POST['order_id'] : null;
487 487
 
488
-		if ( !empty($order_id) ) {
489
-			$result = (array(true, '<h1>'.__('Tracking number','wpshop').'</h1><p>'.__('Enter a tracking number, or leave blank:','wpshop').'</p><input type="hidden" value="'.$order_id.'" name="oid" /><input type="text" name="trackingNumber" /><br /><br /><p>'.__('Enter a tracking link, or leave blank: (http included)','wpshop').'</p><input type="text" name="trackingLink" /><br /><br /><input type="submit" data-nonce="' . esc_attr( wp_create_nonce( 'wpshop_change_order_state' ) ) . '" class="button-primary sendTrackingNumber" value="'.__('Send','wpshop').'" /> <input type="button" class="button-secondary closeAlert" value="'.__('Cancel','wpshop').'" />'));
488
+		if (!empty($order_id)) {
489
+			$result = (array(true, '<h1>' . __('Tracking number', 'wpshop') . '</h1><p>' . __('Enter a tracking number, or leave blank:', 'wpshop') . '</p><input type="hidden" value="' . $order_id . '" name="oid" /><input type="text" name="trackingNumber" /><br /><br /><p>' . __('Enter a tracking link, or leave blank: (http included)', 'wpshop') . '</p><input type="text" name="trackingLink" /><br /><br /><input type="submit" data-nonce="' . esc_attr(wp_create_nonce('wpshop_change_order_state')) . '" class="button-primary sendTrackingNumber" value="' . __('Send', 'wpshop') . '" /> <input type="button" class="button-secondary closeAlert" value="' . __('Cancel', 'wpshop') . '" />'));
490 490
 
491 491
 		}
492 492
 		else {
@@ -495,23 +495,23 @@  discard block
 block discarded – undo
495 495
 		echo json_encode($result);
496 496
 		die();
497 497
 	}
498
-	add_action( 'wp_ajax_dialog_inform_shipping_number', 'wpshop_ajax_dialog_inform_shipping_number' );
498
+	add_action('wp_ajax_dialog_inform_shipping_number', 'wpshop_ajax_dialog_inform_shipping_number');
499 499
 
500 500
 	function wpshop_ajax_change_order_state() {
501 501
 		global $order_status, $wps_shipping_mode_ctr;
502
-		check_ajax_referer( 'wpshop_change_order_state', 'wpshop_ajax_nonce' );
502
+		check_ajax_referer('wpshop_change_order_state', 'wpshop_ajax_nonce');
503 503
 
504
-		$order_id = ( isset( $_POST[ 'order_id' ] ) && !empty( $_POST[ 'order_id' ] ) ) ? (int)$_POST[ 'order_id' ] : null;
505
-		$order_state = ( isset( $_POST[ 'order_state' ] ) && !empty( $_POST[ 'order_state' ] ) ) ? sanitize_text_field( $_POST[ 'order_state' ] ) : null;
506
-		$order_shipped_number = ( isset( $_POST[ 'order_shipped_number' ] ) && !empty( $_POST[ 'order_shipped_number' ] ) ) ? sanitize_text_field( $_POST[ 'order_shipped_number' ] ) : null;
507
-		$order_shipped_link = ( isset( $_POST[ 'order_shipped_link' ] ) && !empty( $_POST[ 'order_shipped_link' ] ) ) ? sanitize_text_field( $_POST[ 'order_shipped_link' ] ) : null;
504
+		$order_id = (isset($_POST['order_id']) && !empty($_POST['order_id'])) ? (int)$_POST['order_id'] : null;
505
+		$order_state = (isset($_POST['order_state']) && !empty($_POST['order_state'])) ? sanitize_text_field($_POST['order_state']) : null;
506
+		$order_shipped_number = (isset($_POST['order_shipped_number']) && !empty($_POST['order_shipped_number'])) ? sanitize_text_field($_POST['order_shipped_number']) : null;
507
+		$order_shipped_link = (isset($_POST['order_shipped_link']) && !empty($_POST['order_shipped_link'])) ? sanitize_text_field($_POST['order_shipped_link']) : null;
508 508
 
509
-		if ( !empty($order_id) ) {
509
+		if (!empty($order_id)) {
510 510
 			/* Update the oder state */
511 511
 			$order = get_post_meta($order_id, '_order_postmeta', true);
512 512
 			$order['order_status'] = $order_state;
513 513
 
514
-			if ( $order_state == 'shipped' ) {
514
+			if ($order_state == 'shipped') {
515 515
 				$order['order_shipping_date'] = current_time('mysql', 0);
516 516
 				$order['order_trackingNumber'] = $order_shipped_number;
517 517
 				$order['order_trackingLink'] = $order_shipped_link;
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 
525 525
 				$order_postmeta = $order;
526 526
 				ob_start();
527
-				require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $wps_shipping_mode_ctr->template_dir, 'backend', 'order-shipping-informations' ) );
527
+				require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $wps_shipping_mode_ctr->template_dir, 'backend', 'order-shipping-informations'));
528 528
 				$output_shipping_box = ob_get_clean();
529 529
 
530
-				$result = array( true, $order_state, $output_shipping_box, $output_payment_box_class, $output_payment_box_content );
530
+				$result = array(true, $order_state, $output_shipping_box, $output_payment_box_class, $output_payment_box_content);
531 531
 			}
532 532
 			else {
533 533
 				wpshop_payment::setOrderPaymentStatus($order_id, $order_state);
@@ -544,39 +544,39 @@  discard block
 block discarded – undo
544 544
 		echo json_encode($result);
545 545
 		die();
546 546
 	}
547
-	add_action( 'wp_ajax_change_order_state', 'wpshop_ajax_change_order_state' );
547
+	add_action('wp_ajax_change_order_state', 'wpshop_ajax_change_order_state');
548 548
 
549 549
 
550 550
 	/* Send a confirmation e-mail to the customer */
551
-	function wpshop_send_confirmation_shipping_email($order_id){
551
+	function wpshop_send_confirmation_shipping_email($order_id) {
552 552
 		$wps_message = new wps_message_ctr();
553
-		if ( !empty($order_id) ) {
553
+		if (!empty($order_id)) {
554 554
 			$order_info = get_post_meta($order_id, '_order_info', true);
555 555
 			$order = get_post_meta($order_id, '_order_postmeta', true);
556
-			$email = ( !empty($order_info['billing']['address']['address_user_email']) ? $order_info['billing']['address']['address_user_email'] : '');
556
+			$email = (!empty($order_info['billing']['address']['address_user_email']) ? $order_info['billing']['address']['address_user_email'] : '');
557 557
 			$first_name = (!empty($order_info['billing']['address']['address_first_name']) ? $order_info['billing']['address']['address_first_name'] : '');
558
-			$last_name = ( !empty($order_info['billing']['address']['address_last_name']) ? $order_info['billing']['address']['address_last_name'] : '');
558
+			$last_name = (!empty($order_info['billing']['address']['address_last_name']) ? $order_info['billing']['address']['address_last_name'] : '');
559 559
 
560
-			if( empty($email) && !empty($order['customer_id']) ) {
561
-				$user_data = get_userdata( $order['customer_id'] );
560
+			if (empty($email) && !empty($order['customer_id'])) {
561
+				$user_data = get_userdata($order['customer_id']);
562 562
 				$email = $user_data->user_email;
563 563
 			}
564 564
 
565
-			$shipping_mode_option = get_option( 'wps_shipping_mode' );
566
-			$shipping_method = ( !empty($order['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order['order_payment']['shipping_method']]['name'] : ( (!empty($order_meta['order_payment']['shipping_method']) ) ? $order['order_payment']['shipping_method'] : '' );
565
+			$shipping_mode_option = get_option('wps_shipping_mode');
566
+			$shipping_method = (!empty($order['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order['order_payment']['shipping_method']]['name'] : ((!empty($order_meta['order_payment']['shipping_method'])) ? $order['order_payment']['shipping_method'] : '');
567 567
 
568 568
 
569
-			$wps_message->wpshop_prepared_email (
569
+			$wps_message->wpshop_prepared_email(
570 570
 				$email,
571 571
 				'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE',
572 572
 				array(
573 573
 					'order_id' => $order_id,
574
-					'order_key' => ( !empty($order['order_key']) ? $order['order_key'] : '' ),
574
+					'order_key' => (!empty($order['order_key']) ? $order['order_key'] : ''),
575 575
 					'customer_first_name' => $first_name,
576 576
 					'customer_last_name' => $last_name,
577
-					'order_date' => ( !empty($order['order_date']) ? $order['order_date'] : '' ),
578
-					'order_trackingNumber' => ( !empty($order['order_trackingNumber']) ? $order['order_trackingNumber'] : '' ),
579
-					'order_trackingLink' => ( !empty($order['order_trackingLink']) ? $order['order_trackingLink'] : '' ),
577
+					'order_date' => (!empty($order['order_date']) ? $order['order_date'] : ''),
578
+					'order_trackingNumber' => (!empty($order['order_trackingNumber']) ? $order['order_trackingNumber'] : ''),
579
+					'order_trackingLink' => (!empty($order['order_trackingLink']) ? $order['order_trackingLink'] : ''),
580 580
 					'order_addresses' => '',
581 581
 					'order_billing_address' => '',
582 582
 					'order_shipping_address' => '',
@@ -595,12 +595,12 @@  discard block
 block discarded – undo
595 595
 	 * @return string The html output for the new value
596 596
 	 */
597 597
 	function ajax_new_option_for_select_callback() {
598
-		check_ajax_referer( 'wpshop_new_option_for_attribute_creation', 'wpshop_ajax_nonce' );
598
+		check_ajax_referer('wpshop_new_option_for_attribute_creation', 'wpshop_ajax_nonce');
599 599
 		global $wpdb;
600 600
 
601
-		$option_id=$option_default_value=$option_value_id=$options_value='';
602
-		$attribute_identifier = isset($_GET['attribute_identifier']) ? (int) $_GET['attribute_identifier'] : '0';
603
-		$option_name = (!empty($_REQUEST['attribute_new_label']) ? sanitize_text_field( $_REQUEST['attribute_new_label'] ) : '');
601
+		$option_id = $option_default_value = $option_value_id = $options_value = '';
602
+		$attribute_identifier = isset($_GET['attribute_identifier']) ? (int)$_GET['attribute_identifier'] : '0';
603
+		$option_name = (!empty($_REQUEST['attribute_new_label']) ? sanitize_text_field($_REQUEST['attribute_new_label']) : '');
604 604
 		$options_value = sanitize_title($option_name);
605 605
 
606 606
 		/*	Check if given value does not exist before continuing	*/
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 		$existing_values = $wpdb->get_results($query);
609 609
 
610 610
 		/*	If given value does not exist: display result. If value exist alert a error message	*/
611
-		if( empty($existing_values) ) {
611
+		if (empty($existing_values)) {
612 612
 			$tpl_component = array();
613 613
 			$tpl_component['ADMIN_ATTRIBUTE_VALUES_OPTION_ID'] = $option_id;
614 614
 			$tpl_component['ADMIN_ATTRIBUTE_VALUES_OPTION_NAME'] = stripslashes($option_name);
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 			$tpl_component['ADMIN_ATTRIBUTE_VALUES_OPTION_VALUE'] = str_replace(".", ",", stripslashes($options_value));
617 617
 			$tpl_component['ADMIN_ATTRIBUTE_VALUES_OPTION_STATE'] = '';
618 618
 			$tpl_component['ADMIN_ATTRIBUTE_VALUE_OPTIN_ACTIONS'] = '';
619
-			if ( current_user_can('wpshop_delete_attributes_select_values') && ($option_id >= 0) ) :
619
+			if (current_user_can('wpshop_delete_attributes_select_values') && ($option_id >= 0)) :
620 620
 				$tpl_component['ADMIN_ATTRIBUTE_VALUE_OPTIN_ACTIONS'] .= wpshop_display::display_template_element('wpshop_admin_attr_option_value_item_deletion', $tpl_component, array('type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_identifier), 'admin');
621 621
 			endif;
622 622
 			$output = wpshop_display::display_template_element('wpshop_admin_attr_option_value_item', $tpl_component, array('type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_identifier), 'admin');
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 	 * Add a new value to an attribute from select type directly from an entity element edition interface
636 636
 	 */
637 637
 	function ajax_new_option_for_select_from_product_edition_callback() {
638
-		check_ajax_referer( 'wpshop_new_option_for_attribute_creation', 'wpshop_ajax_nonce' );
638
+		check_ajax_referer('wpshop_new_option_for_attribute_creation', 'wpshop_ajax_nonce');
639 639
 
640 640
 		global $wpdb;
641 641
 		$result = '';
@@ -652,13 +652,13 @@  discard block
 block discarded – undo
652 652
 		$attribute_options_label = isset($_POST['attribute_new_label']) ? wpshop_tools::varSanitizer($_POST['attribute_new_label']) : null;
653 653
 		$attribute_options_value = sanitize_title($attribute_options_label);
654 654
 
655
-		if ( $type == 'internal' ) {
655
+		if ($type == 'internal') {
656 656
 			/**	Check if the given value does not exist	*/
657 657
 			$query = $wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE post_title = %s AND post_status = 'publish'", $attribute_options_label);
658 658
 			$existing_values = $wpdb->get_results($query);
659 659
 
660 660
 			/**	If the value does not exist, we create it and output, in case it exists alert an error message	*/
661
-			if ( count($existing_values) <= 0 ) {
661
+			if (count($existing_values) <= 0) {
662 662
 				$result_status = true;
663 663
 				/**	Create the new value as an entity into post database	*/
664 664
 				$new_post = array(
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 			$existing_values = $wpdb->get_results($query);
682 682
 
683 683
 			/**	If the value does not exist, we create it and output, in case it exists alert an error message	*/
684
-			if( count($existing_values) <= 0 ) {
684
+			if (count($existing_values) <= 0) {
685 685
 				$result_status = true;
686 686
 				$position = 1;
687 687
 				/**	Get the last value position for adding the new at the end	*/
@@ -700,15 +700,15 @@  discard block
 block discarded – undo
700 700
 
701 701
 		if ($result_status) {
702 702
 			$tmp_selection_for_output = array();
703
-			foreach ( $attribute_selected_values as $value ) {
703
+			foreach ($attribute_selected_values as $value) {
704 704
 				$tmp_selection_for_output[]['value'] = $value;
705 705
 			}
706 706
 			$tmp_selection_for_output[]['value'] = $new_option_id;
707
-			foreach ( $tmp_selection_for_output as $tmp_value ) {
707
+			foreach ($tmp_selection_for_output as $tmp_value) {
708 708
 				$selection_for_output[] = (object)$tmp_value;
709 709
 			}
710 710
 			$attribute_selected_values[] = $new_option_id;
711
-			$input = wpshop_attributes::get_attribute_field_definition( $attribute, $selection_for_output, array('page_code' => $current_page_code, 'from' => $attribute_place_display) );
711
+			$input = wpshop_attributes::get_attribute_field_definition($attribute, $selection_for_output, array('page_code' => $current_page_code, 'from' => $attribute_place_display));
712 712
 			$result = $input['output'] . $input['options'];
713 713
 		}
714 714
 
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	 * Delete a value for a select list attribute
722 722
 	 */
723 723
 	function ajax_delete_option_for_select_callback() {
724
-		check_ajax_referer( 'wpshop_new_option_for_attribute_deletion', 'wpshop_ajax_nonce' );
724
+		check_ajax_referer('wpshop_new_option_for_attribute_deletion', 'wpshop_ajax_nonce');
725 725
 
726 726
 		$attribute_value_id = isset($_POST['attribute_value_id']) ? wpshop_tools::varSanitizer($_POST['attribute_value_id']) : '0';
727 727
 
@@ -745,18 +745,18 @@  discard block
 block discarded – undo
745 745
 	 * Display the field for the selected attribute type
746 746
 	 */
747 747
 	function ajax_attribute_output_type_callback() {
748
-		check_ajax_referer( 'wpshop_attribute_output_type_selection', 'wpshop_ajax_nonce' );
748
+		check_ajax_referer('wpshop_attribute_output_type_selection', 'wpshop_ajax_nonce');
749 749
 
750 750
 		$data_type_to_use = isset($_POST['data_type_to_use']) ? str_replace('_data', '', wpshop_tools::varSanitizer($_POST['data_type_to_use'], '')) : 'custom';
751 751
 		$current_type = isset($_POST['current_type']) ? wpshop_tools::varSanitizer($_POST['current_type']) : 'short_text';
752
-		$elementIdentifier = isset($_POST['elementIdentifier']) ? intval( wpshop_tools::varSanitizer($_POST['elementIdentifier'])) : null;
752
+		$elementIdentifier = isset($_POST['elementIdentifier']) ? intval(wpshop_tools::varSanitizer($_POST['elementIdentifier'])) : null;
753 753
 		$the_input = __('An error occured while getting field type', 'wpshop');
754 754
 		$input_def = array();
755 755
 		$input_def['name'] = 'default_value';
756 756
 		$input_def['id'] = 'wpshop_attributes_edition_table_field_id_default_value';
757 757
 		$input_label = __('Default value', 'wpshop');
758 758
 
759
-		switch($current_type){
759
+		switch ($current_type) {
760 760
 			case 'short_text':
761 761
 			case 'float_field':
762 762
 				$input_def['type'] = 'text';
@@ -767,13 +767,13 @@  discard block
 block discarded – undo
767 767
 			case 'multiple-select':
768 768
 			case 'radio':
769 769
 			case 'checkbox':
770
-				$input_label=__('Options list for attribute', 'wpshop');
770
+				$input_label = __('Options list for attribute', 'wpshop');
771 771
 				$the_input = wpshop_attributes::get_select_options_list($elementIdentifier, $data_type_to_use);
772 772
 				break;
773 773
 			case 'date_field':
774
-				$input_label=__('Date field configuration', 'wpshop');
774
+				$input_label = __('Date field configuration', 'wpshop');
775 775
 
776
-				$the_input = wpshop_attributes::attribute_type_date_config( array() );
776
+				$the_input = wpshop_attributes::attribute_type_date_config(array());
777 777
 				break;
778 778
 			case 'textarea':
779 779
 				$input_def['type'] = 'textarea';
@@ -791,11 +791,11 @@  discard block
 block discarded – undo
791 791
 	 * Get the attribute set list when creating a new attribute for direct affectation
792 792
 	 */
793 793
 	function ajax_attribute_entity_set_selection_callback() {
794
-		check_ajax_referer( 'wpshop_attribute_entity_set_selection', 'wpshop_ajax_nonce' );
794
+		check_ajax_referer('wpshop_attribute_entity_set_selection', 'wpshop_ajax_nonce');
795 795
 
796 796
 		$current_entity_id = isset($_POST['current_entity_id']) ? intval(wpshop_tools::varSanitizer($_POST['current_entity_id'])) : null;
797 797
 
798
-		$the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id,  wpshop_attributes::getDbTable(), wpshop_attributes::currentPageCode);
798
+		$the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id, wpshop_attributes::getDbTable(), wpshop_attributes::currentPageCode);
799 799
 
800 800
 		echo json_encode($the_input);
801 801
 		die();
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
 	 * Get the attribute set list when creating a new attribute for direct affectation
806 806
 	 */
807 807
 	function ajax_attribute_set_entity_selection_callback() {
808
-		check_ajax_referer( 'wpshop_attribute_set_entity_selection', 'wpshop_ajax_nonce' );
808
+		check_ajax_referer('wpshop_attribute_set_entity_selection', 'wpshop_ajax_nonce');
809 809
 
810 810
 		$current_entity_id = isset($_POST['current_entity_id']) ? intval(wpshop_tools::varSanitizer($_POST['current_entity_id'])) : null;
811 811
 
812
-		$the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id,  wpshop_attributes_set::getDbTable(), wpshop_attributes::currentPageCode, false);
812
+		$the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id, wpshop_attributes_set::getDbTable(), wpshop_attributes::currentPageCode, false);
813 813
 
814 814
 		echo json_encode($the_input);
815 815
 		die();
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 	 * Dialog box allowing to change attribute data type from custom to internal
821 821
 	 */
822 822
 	function ajax_attribute_select_data_type_callback() {
823
-		check_ajax_referer( 'wpshop_attribute_change_select_data_type', 'wpshop_ajax_nonce' );
823
+		check_ajax_referer('wpshop_attribute_change_select_data_type', 'wpshop_ajax_nonce');
824 824
 		$result = '';
825 825
 
826 826
 		$current_attribute = isset($_POST['current_attribute']) ? intval(wpshop_tools::varSanitizer($_POST['current_attribute'])) : null;
@@ -828,12 +828,12 @@  discard block
 block discarded – undo
828 828
 
829 829
 		$types_toggled = unserialize(WPSHOP_ATTR_SELECT_TYPE_TOGGLED);
830 830
 		$result .= '<p class="wpshop_change_select_data_type_change wpshop_change_select_data_type_change_current_attribute" >' . sprintf(__('Selected attribute %s', 'wpshop'), $attribute->frontend_label) . '</p>';
831
-		$result .= '<p class="wpshop_change_select_data_type_change wpshop_change_select_data_type_change_types" >' . sprintf(__('Actual data type is %s. After current operation: %s', 'wpshop'), __($attribute->data_type_to_use.'_data', 'wpshop'), __($types_toggled[$attribute->data_type_to_use], 'wpshop')) . '</p>';
831
+		$result .= '<p class="wpshop_change_select_data_type_change wpshop_change_select_data_type_change_types" >' . sprintf(__('Actual data type is %s. After current operation: %s', 'wpshop'), __($attribute->data_type_to_use . '_data', 'wpshop'), __($types_toggled[$attribute->data_type_to_use], 'wpshop')) . '</p>';
832 832
 
833
-		if ( $attribute->data_type_to_use == 'custom' ) {
834
-			$sub_output='';
833
+		if ($attribute->data_type_to_use == 'custom') {
834
+			$sub_output = '';
835 835
 			$wp_types = unserialize(WPSHOP_INTERNAL_TYPES);
836
-			unset($input_def);$input_def=array();
836
+			unset($input_def); $input_def = array();
837 837
 			$input_def['label'] = __('Type of data for list', 'wpshop');
838 838
 			$input_def['type'] = 'select';
839 839
 			$input_def['name'] = 'internal_data';
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 			$input_def['possible_value'] = $wp_types;
842 842
 			$input_def['value'] = !empty($attribute_select_options[0]->default_value) ? $attribute_select_options[0]->default_value : null;
843 843
 			$combo_wp_type = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
844
-			$result .= __('Choose the data type to use for this attribute', 'wpshop') . '<a href="#" title="'.sprintf(__('If the type you want to use is not in the list below. You have to create it by using %s menu', 'wpshop'), __('Entities', 'wpshop')).'" class="wpshop_infobulle_marker">?</a><div class="wpshop_cls wpshop_attribute_select_data_type_internal_list">'.$combo_wp_type.'</div>';
844
+			$result .= __('Choose the data type to use for this attribute', 'wpshop') . '<a href="#" title="' . sprintf(__('If the type you want to use is not in the list below. You have to create it by using %s menu', 'wpshop'), __('Entities', 'wpshop')) . '" class="wpshop_infobulle_marker">?</a><div class="wpshop_cls wpshop_attribute_select_data_type_internal_list">' . $combo_wp_type . '</div>';
845 845
 			$result .= '<input type="hidden" value="no" name="delete_items_of_entity" id="delete_items_of_entity" /><input type="hidden" value="no" name="delete_entity" id="delete_entity" />';
846 846
 		}
847 847
 		else {
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 	 */
875 875
 	function ajax_attribute_select_data_type_change_callback() {
876 876
 		global $wpdb;
877
-		check_ajax_referer( 'wpshop_attribute_change_select_data_type_change', 'wpshop_ajax_nonce' );
877
+		check_ajax_referer('wpshop_attribute_change_select_data_type_change', 'wpshop_ajax_nonce');
878 878
 		$result = '';
879 879
 
880 880
 		$current_attribute = isset($_POST['attribute_id']) ? intval(wpshop_tools::varSanitizer($_POST['attribute_id'])) : null;
@@ -884,10 +884,10 @@  discard block
 block discarded – undo
884 884
 		$delete_entity = isset($_POST['delete_entity']) ? wpshop_tools::varSanitizer($_POST['delete_entity']) : false;
885 885
 
886 886
 
887
-		if ( $data_type == 'internal' ) {
887
+		if ($data_type == 'internal') {
888 888
 			$options_list = wpshop_attributes::get_select_option_list_($current_attribute);
889
-			if(!empty($options_list)){
890
-				foreach($options_list as $option){
889
+			if (!empty($options_list)) {
890
+				foreach ($options_list as $option) {
891 891
 					/*	Creat the new entity	*/
892 892
 					$new_post = array(
893 893
 							'post_title' 	=> $option->name,
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 							'post_type' 	=> $internal_data_type
897 897
 					);
898 898
 					$new_option_id = wp_insert_post($new_post);
899
-					if(!empty($new_option_id)){
899
+					if (!empty($new_option_id)) {
900 900
 						$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'deleted'), array('attribute_id'=>$current_attribute));
901 901
 					}
902 902
 				}
@@ -905,19 +905,19 @@  discard block
 block discarded – undo
905 905
 		else {
906 906
 			$post_list = query_posts(array('post_type' => $internal_data_type));
907 907
 			if (!empty($post_list)) {
908
-				$p=1;
908
+				$p = 1;
909 909
 				$error = false;
910 910
 				foreach ($post_list as $post) {
911
-					$last_insert = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'valid', 'creation_date'=>current_time('mysql',0), 'attribute_id'=>$current_attribute, 'position'=>$p, 'value'=>$post->post_name, 'label'=>$post->post_title));
912
-					if(is_int($last_insert) && $delete_items_of_entity){
911
+					$last_insert = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'valid', 'creation_date'=>current_time('mysql', 0), 'attribute_id'=>$current_attribute, 'position'=>$p, 'value'=>$post->post_name, 'label'=>$post->post_title));
912
+					if (is_int($last_insert) && $delete_items_of_entity) {
913 913
 						wp_delete_post($post->ID, true);
914 914
 					}
915
-					else{
915
+					else {
916 916
 						$error = true;
917 917
 					}
918 918
 					$p++;
919 919
 				}
920
-				if(!$error && $delete_entity){
920
+				if (!$error && $delete_entity) {
921 921
 					$post = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type=%s AND post_name=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, $internal_data_type);
922 922
 					wp_delete_post($wpdb->get_var($post), true);
923 923
 				}
@@ -937,8 +937,8 @@  discard block
 block discarded – undo
937 937
 	/**
938 938
 	 * Duplicate an existing attribute from an entity to another
939 939
 	 */
940
-	function ajax_wpshop_duplicate_attribute_callback (){
941
-		check_ajax_referer( 'wpshop_duplicate_attribute', 'wpshop_ajax_nonce' );
940
+	function ajax_wpshop_duplicate_attribute_callback() {
941
+		check_ajax_referer('wpshop_duplicate_attribute', 'wpshop_ajax_nonce');
942 942
 		global $wpdb;
943 943
 
944 944
 		$result = '';
@@ -958,16 +958,16 @@  discard block
 block discarded – undo
958 958
 		/*	Check if the attribute to duplicate does not exist for the selected entity	*/
959 959
 		$query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code']);
960 960
 		$check_existing_attribute = $wpdb->get_var($query);
961
-		if ( empty($check_existing_attribute) ) {
961
+		if (empty($check_existing_attribute)) {
962 962
 			/*	Save new attribut for the selected entity	*/
963 963
 			$new_attribute = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, $attribute_def);
964 964
 			$new_attribute_id = $wpdb->insert_id;
965 965
 
966 966
 			if ($new_attribute) {
967
-				if ( in_array($attribute_def['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox')) && ($attribute_def['data_type_to_use'] == 'custom') ) {
967
+				if (in_array($attribute_def['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox')) && ($attribute_def['data_type_to_use'] == 'custom')) {
968 968
 					$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d", $current_attribute);
969 969
 					$attribute_options_list = $wpdb->get_results($query, ARRAY_A);
970
-					foreach ( $attribute_options_list as $option ) {
970
+					foreach ($attribute_options_list as $option) {
971 971
 						$option['id'] = '';
972 972
 						$option['creation_date'] = current_time('mysql', 0);
973 973
 						$option['attribute_id'] = $new_attribute_id;
@@ -998,27 +998,27 @@  discard block
 block discarded – undo
998 998
 	/**
999 999
 	 * Load comboBox of unit or group of unit
1000 1000
 	 */
1001
-	function wpshop_ajax_load_attribute_unit_list(){
1002
-		check_ajax_referer( 'wpshop_load_attribute_unit_list', 'wpshop_ajax_nonce' );
1001
+	function wpshop_ajax_load_attribute_unit_list() {
1002
+		check_ajax_referer('wpshop_load_attribute_unit_list', 'wpshop_ajax_nonce');
1003 1003
 		$response = '';
1004 1004
 
1005
-		$current_group = ( isset( $_POST[ 'current_group' ] ) && !empty( $_POST[ 'current_group' ] ) ) ? sanitize_text_field( $_POST[ 'current_group' ] ) : null;
1006
-		$selected_list = ( isset( $_POST[ 'selected_list' ] ) && !empty( $_POST[ 'selected_list' ] ) ) ? sanitize_text_field( $_POST[ 'selected_list' ] ) : null;
1005
+		$current_group = (isset($_POST['current_group']) && !empty($_POST['current_group'])) ? sanitize_text_field($_POST['current_group']) : null;
1006
+		$selected_list = (isset($_POST['selected_list']) && !empty($_POST['selected_list'])) ? sanitize_text_field($_POST['selected_list']) : null;
1007 1007
 
1008 1008
 		$group = wpshop_tools::varSanitizer($current_group);
1009 1009
 		$selected_list = wpshop_tools::varSanitizer($selected_list);
1010 1010
 
1011
-		if ( !empty($group) && !empty($selected_list)) {
1011
+		if (!empty($group) && !empty($selected_list)) {
1012 1012
 			/* Test if we want display the group unit list OR the unit list */
1013
-			if ( $selected_list == 'group unit' ) {
1013
+			if ($selected_list == 'group unit') {
1014 1014
 				$list = wpshop_attributes_unit::get_unit_group();
1015 1015
 			}
1016 1016
 			else {
1017 1017
 				$list = wpshop_attributes_unit::get_unit_list_for_group($group);
1018 1018
 			}
1019 1019
 
1020
-			foreach( $list as $unit ) {
1021
-				$response .= '<option value="' . $unit->id . '" '. ( ($current_group == $unit->id && $selected_list == 'group unit') ? 'selected="selected"' : '' ).'>' . $unit->name . '</option>';
1020
+			foreach ($list as $unit) {
1021
+				$response .= '<option value="' . $unit->id . '" ' . (($current_group == $unit->id && $selected_list == 'group unit') ? 'selected="selected"' : '') . '>' . $unit->name . '</option>';
1022 1022
 			}
1023 1023
 			$result = array(true, $response);
1024 1024
 		}
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 
1035 1035
 /**	Tools page	*/
1036 1036
 	function wpshop_ajax_db_check_tool() {
1037
-		check_ajax_referer( 'wpshop_ajax_db_check_tool', '_wpnonce' );
1037
+		check_ajax_referer('wpshop_ajax_db_check_tool', '_wpnonce');
1038 1038
 
1039 1039
 		global $wpdb, $wpshop_db_table_operation_list, $wpshop_db_table, $wpshop_update_way;
1040 1040
 		$current_db_version = get_option('wpshop_db_options', 0);
@@ -1050,22 +1050,22 @@  discard block
 block discarded – undo
1050 1050
 </div>
1051 1051
 <div class="tools_db_modif_list_version_details" >
1052 1052
 	<ul>';
1053
-			foreach($plugin_db_modification as $modif_name => $modif_list){
1054
-				switch($modif_name){
1053
+			foreach ($plugin_db_modification as $modif_name => $modif_list) {
1054
+				switch ($modif_name) {
1055 1055
 					case 'FIELD_ADD':{
1056
-						foreach($modif_list as $table_name => $field_list){
1056
+						foreach ($modif_list as $table_name => $field_list) {
1057 1057
 							$sub_modif = '  ';
1058
-							foreach($field_list as $column_name){
1059
-								$query = $wpdb->prepare("SHOW COLUMNS FROM " .$table_name . " WHERE Field = %s", $column_name);
1058
+							foreach ($field_list as $column_name) {
1059
+								$query = $wpdb->prepare("SHOW COLUMNS FROM " . $table_name . " WHERE Field = %s", $column_name);
1060 1060
 								$columns = $wpdb->get_row($query);
1061 1061
 								$sub_modif .= $column_name;
1062
-								if( !empty($columns->Field) && ($columns->Field == $column_name) ){
1062
+								if (!empty($columns->Field) && ($columns->Field == $column_name)) {
1063 1063
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been created', 'wpshop') . '" title="' . __('Field has been created', 'wpshop') . '" class="db_added_field_check" />';
1064 1064
 								}
1065
-								else{
1065
+								else {
1066 1066
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />';
1067 1067
 									$error_nb++;
1068
-									if ( !empty($error_list[$plugin_db_version]) ) {
1068
+									if (!empty($error_list[$plugin_db_version])) {
1069 1069
 										$error_list[$plugin_db_version] += 1;
1070 1070
 									}
1071 1071
 									else {
@@ -1074,56 +1074,56 @@  discard block
 block discarded – undo
1074 1074
 								}
1075 1075
 								$sub_modif .= ' / ';
1076 1076
 							}
1077
-							$plugin_db_modification_content .= '<li class="added_field" >' . sprintf(__('Added field list for %s', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' .  substr($sub_modif, 0, -2) . '</li>';
1077
+							$plugin_db_modification_content .= '<li class="added_field" >' . sprintf(__('Added field list for %s', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' . substr($sub_modif, 0, -2) . '</li>';
1078 1078
 						}
1079 1079
 					}break;
1080 1080
 					case 'FIELD_DROP':{
1081
-						foreach($modif_list as $table_name => $field_list){
1081
+						foreach ($modif_list as $table_name => $field_list) {
1082 1082
 							$sub_modif = '  ';
1083
-							foreach($field_list as $column_name){
1084
-								$query = $wpdb->prepare("SHOW COLUMNS FROM " .$table_name . " WHERE Field = %s", $column_name);
1083
+							foreach ($field_list as $column_name) {
1084
+								$query = $wpdb->prepare("SHOW COLUMNS FROM " . $table_name . " WHERE Field = %s", $column_name);
1085 1085
 								$columns = $wpdb->get_row($query);
1086 1086
 								$sub_modif .= $column_name;
1087
-								if(empty($columns) || ($columns->Field != $column_name)){
1087
+								if (empty($columns) || ($columns->Field != $column_name)) {
1088 1088
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been deleted', 'wpshop') . '" title="' . __('Field has been deleted', 'wpshop') . '" class="db_deleted_field_check" />';
1089 1089
 								}
1090
-								else{
1090
+								else {
1091 1091
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field exists', 'wpshop') . '" title="' . __('Field exists', 'wpshop') . '" class="db_deleted_field_check" />';
1092 1092
 									$error_nb++;
1093 1093
 									$error_list[$plugin_db_version] += 1;
1094 1094
 								}
1095 1095
 								$sub_modif .= ' / ';
1096 1096
 							}
1097
-							$plugin_db_modification_content .= '<li class="deleted_field" >' . sprintf(__('Fields list deleted for the %s table', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' .  substr($sub_modif, 0, -2) . '</li>';
1097
+							$plugin_db_modification_content .= '<li class="deleted_field" >' . sprintf(__('Fields list deleted for the %s table', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' . substr($sub_modif, 0, -2) . '</li>';
1098 1098
 						}
1099 1099
 					}break;
1100 1100
 					case 'FIELD_CHANGE':{
1101
-						foreach($modif_list as $table_name => $field_list){
1101
+						foreach ($modif_list as $table_name => $field_list) {
1102 1102
 							$sub_modif = '  ';
1103
-							foreach($field_list as $field_infos){
1104
-								$query = $wpdb->prepare("SHOW COLUMNS FROM " .$table_name . " WHERE Field = %s", $field_infos['field']);
1103
+							foreach ($field_list as $field_infos) {
1104
+								$query = $wpdb->prepare("SHOW COLUMNS FROM " . $table_name . " WHERE Field = %s", $field_infos['field']);
1105 1105
 								$columns = $wpdb->get_row($query);
1106 1106
 								$what_is_changed = '';
1107
-								if(isset($field_infos['type'])){
1107
+								if (isset($field_infos['type'])) {
1108 1108
 									$what_is_changed = __('field type', 'wpshop');
1109 1109
 									$changed_key = 'type';
1110
-									if($columns->Type == $field_infos['type']){
1110
+									if ($columns->Type == $field_infos['type']) {
1111 1111
 										$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been created', 'wpshop') . '" title="' . __('Field has been created', 'wpshop') . '" class="db_added_field_check" />';
1112 1112
 									}
1113
-									else{
1113
+									else {
1114 1114
 										$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />';
1115 1115
 										$error_nb++;
1116 1116
 										$error_list[$plugin_db_version] += 1;
1117 1117
 									}
1118 1118
 									$sub_modif .= sprintf(__('Change %s for field %s to %s', 'wpshop'), $what_is_changed, $field_infos['field'], $field_infos[$changed_key]);
1119 1119
 								}
1120
-								if(isset($field_infos['original_name'])){
1120
+								if (isset($field_infos['original_name'])) {
1121 1121
 									$what_is_changed = __('field name', 'wpshop');
1122 1122
 									$changed_key = 'original_name';
1123
-									if($columns->Field == $field_infos['field']){
1123
+									if ($columns->Field == $field_infos['field']) {
1124 1124
 										$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been created', 'wpshop') . '" title="' . __('Field has been created', 'wpshop') . '" class="db_added_field_check" />';
1125 1125
 									}
1126
-									else{
1126
+									else {
1127 1127
 										$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />';
1128 1128
 										$error_nb++;
1129 1129
 										$error_list[$plugin_db_version] += 1;
@@ -1138,59 +1138,59 @@  discard block
 block discarded – undo
1138 1138
 					}break;
1139 1139
 
1140 1140
 					case 'DROP_INDEX':{
1141
-						foreach($modif_list as $table_name => $field_list){
1141
+						foreach ($modif_list as $table_name => $field_list) {
1142 1142
 							$sub_modif = '   ';
1143
-							foreach($field_list as $column_name){
1144
-								$query = $wpdb->prepare("SHOW INDEX FROM " .$table_name . " WHERE Column_name = %s", $column_name);
1143
+							foreach ($field_list as $column_name) {
1144
+								$query = $wpdb->prepare("SHOW INDEX FROM " . $table_name . " WHERE Column_name = %s", $column_name);
1145 1145
 								$columns = $wpdb->get_row($query);
1146 1146
 								$sub_modif .= $column_name;
1147
-								if((empty($columns)) || ($columns->Column_name != $column_name)){
1147
+								if ((empty($columns)) || ($columns->Column_name != $column_name)) {
1148 1148
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Index has been deleted', 'wpshop') . '" title="' . __('Index has been deleted', 'wpshop') . '" class="db_deleted_index_check" />';
1149 1149
 								}
1150
-								else{
1150
+								else {
1151 1151
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Index does not exists', 'wpshop') . '" title="' . __('Index does not exists', 'wpshop') . '" class="db_deleted_index_check" />';
1152 1152
 									$error_nb++;
1153 1153
 									$error_list[$plugin_db_version] += 1;
1154 1154
 								}
1155 1155
 								$sub_modif .= ' / ';
1156 1156
 							}
1157
-							$plugin_db_modification_content .= '<li class="deleted_index" >' . sprintf(__('Deleted indexes for %s table', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' .  substr($sub_modif, 0, -3) . '</li>';
1157
+							$plugin_db_modification_content .= '<li class="deleted_index" >' . sprintf(__('Deleted indexes for %s table', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' . substr($sub_modif, 0, -3) . '</li>';
1158 1158
 						}
1159 1159
 					}break;
1160 1160
 					case 'ADD_INDEX':{
1161
-						foreach($modif_list as $table_name => $field_list){
1161
+						foreach ($modif_list as $table_name => $field_list) {
1162 1162
 							$sub_modif = '   ';
1163
-							foreach($field_list as $column_name){
1163
+							foreach ($field_list as $column_name) {
1164 1164
 								$query = $wpdb->prepare("SHOW INDEX FROM " . $table_name . " WHERE Column_name = %s OR Key_name = %s", $column_name, $column_name);
1165 1165
 								$columns = $wpdb->get_row($query);
1166 1166
 								$sub_modif .= $column_name;
1167
-								if(($columns->Column_name == $column_name) || ($columns->Key_name == $column_name)){
1167
+								if (($columns->Column_name == $column_name) || ($columns->Key_name == $column_name)) {
1168 1168
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Index has been created', 'wpshop') . '" title="' . __('Index has been created', 'wpshop') . '" class="db_added_index_check" />';
1169 1169
 								}
1170
-								else{
1170
+								else {
1171 1171
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Index does not exist', 'wpshop') . '" title="' . __('Index does not exist', 'wpshop') . '" class="db_added_index_check" />';
1172 1172
 									$error_nb++;
1173 1173
 									$error_list[$plugin_db_version] += 1;
1174 1174
 								}
1175 1175
 								$sub_modif .= ' / ';
1176 1176
 							}
1177
-							$plugin_db_modification_content .= '<li class="added_index" >' . sprintf(__('Added indexes for %s table', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' .  substr($sub_modif, 0, -3) . '</li>';
1177
+							$plugin_db_modification_content .= '<li class="added_index" >' . sprintf(__('Added indexes for %s table', 'wpshop'), $table_name) . '&nbsp;:&nbsp;' . substr($sub_modif, 0, -3) . '</li>';
1178 1178
 						}
1179 1179
 					}break;
1180 1180
 
1181 1181
 					case 'ADD_TABLE':{
1182 1182
 						$sub_modif = '  ';
1183
-						foreach($modif_list as $table_name){
1183
+						foreach ($modif_list as $table_name) {
1184 1184
 							$sub_modif .= $table_name;
1185 1185
 							$query = $wpdb->prepare("SHOW TABLES FROM " . DB_NAME . " LIKE %s", $table_name);
1186 1186
 							$table_exists = $wpdb->query($query);
1187
-							if($table_exists == 1){
1187
+							if ($table_exists == 1) {
1188 1188
 								$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Table has been created', 'wpshop') . '" title="' . __('Table has been created', 'wpshop') . '" class="db_table_check" />';
1189 1189
 							}
1190
-							else{
1190
+							else {
1191 1191
 								$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Table has not been created', 'wpshop') . '" title="' . __('Table has not been created', 'wpshop') . '" class="db_table_check" />';
1192 1192
 								$error_nb++;
1193
-								if ( !empty($error_list[$plugin_db_version]) ) {
1193
+								if (!empty($error_list[$plugin_db_version])) {
1194 1194
 									$error_list[$plugin_db_version] += 1;
1195 1195
 								}
1196 1196
 								else {
@@ -1203,29 +1203,29 @@  discard block
 block discarded – undo
1203 1203
 					}break;
1204 1204
 					case 'TABLE_RENAME':{
1205 1205
 						$sub_modif = '  ';
1206
-						foreach($modif_list as $table){
1206
+						foreach ($modif_list as $table) {
1207 1207
 							$sub_modif .= sprintf(__('%s has been renammed %', 'wpshop'), $table['old_name'], $table['name']);
1208 1208
 							$query = $wpdb->prepare("SHOW TABLES FROM " . DB_NAME . " LIKE %s", $table['name']);
1209 1209
 							$table_exists = $wpdb->query($query);
1210 1210
 							$query = $wpdb->prepare("SHOW TABLES FROM " . DB_NAME . " LIKE %s", $table['old_name']);
1211 1211
 							$old_table_exists = $wpdb->query($query);
1212
-							if(($table_exists == 1) && ($old_table_exists == 1)){
1212
+							if (($table_exists == 1) && ($old_table_exists == 1)) {
1213 1213
 								$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Both database table are still present', 'wpshop') . '" title="' . __('Both database table are still present', 'wpshop') . '" class="db_rename_table_check" />';
1214 1214
 								$error_nb++;
1215
-								if ( !empty($error_list[$plugin_db_version]) ) {
1215
+								if (!empty($error_list[$plugin_db_version])) {
1216 1216
 									$error_list[$plugin_db_version] += 1;
1217 1217
 								}
1218 1218
 								else {
1219 1219
 									$error_list[$plugin_db_version] = 1;
1220 1220
 								}
1221 1221
 							}
1222
-							elseif($table_exists == 1){
1222
+							elseif ($table_exists == 1) {
1223 1223
 								$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Table has been renamed', 'wpshop') . '" title="' . __('Table has been renamed', 'wpshop') . '" class="db_rename_table_check" />';
1224 1224
 							}
1225
-							else{
1225
+							else {
1226 1226
 								$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Table has not been renamed', 'wpshop') . '" title="' . __('Table has not been renamed', 'wpshop') . '" class="db_rename_table_check" />';
1227 1227
 								$error_nb++;
1228
-								if ( !empty($error_list[$plugin_db_version]) ) {
1228
+								if (!empty($error_list[$plugin_db_version])) {
1229 1229
 									$error_list[$plugin_db_version] += 1;
1230 1230
 								}
1231 1231
 								else {
@@ -1238,27 +1238,27 @@  discard block
 block discarded – undo
1238 1238
 					}break;
1239 1239
 					case 'TABLE_RENAME_FOR_DELETION':{
1240 1240
 						$sub_modif = '  ';
1241
-						foreach($modif_list as $table){
1241
+						foreach ($modif_list as $table) {
1242 1242
 							$sub_modif .= sprintf(__('%s has been renammed %', 'wpshop'), $table['old_name'], $table['name']);
1243 1243
 							$query = $wpdb->prepare("SHOW TABLES FROM " . DB_NAME . " LIKE %s", $table['name']);
1244 1244
 							$table_delete_exists = $wpdb->query($query);
1245 1245
 							$query = $wpdb->prepare("SHOW TABLES FROM " . DB_NAME . " LIKE %s", $table['old_name']);
1246 1246
 							$old_table_exists = $wpdb->query($query);
1247
-							if(($table_delete_exists == 1) || ($old_table_exists == 1)){
1248
-								if($old_table_exists == 1){
1247
+							if (($table_delete_exists == 1) || ($old_table_exists == 1)) {
1248
+								if ($old_table_exists == 1) {
1249 1249
 									$deleted_table_result = '<img src="' . admin_url('images/no.png') . '" alt="' . __('Table has not been renamed', 'wpshop') . '" title="' . __('Table has not been renamed', 'wpshop') . '" class="db_deleted_table_check" />';
1250 1250
 									$error_nb++;
1251
-									if ( !empty($error_list[$plugin_db_version]) ) {
1251
+									if (!empty($error_list[$plugin_db_version])) {
1252 1252
 										$error_list[$plugin_db_version] += 1;
1253 1253
 									}
1254 1254
 									else {
1255 1255
 										$error_list[$plugin_db_version] = 1;
1256 1256
 									}
1257 1257
 								}
1258
-								else{
1258
+								else {
1259 1259
 									$deleted_table_result = '<img src="' . EVA_IMG_ICONES_PLUGIN_URL . 'warning_vs.gif" alt="' . __('Table has not been deleted', 'wpshop') . '" title="' . __('Table has not been renamed', 'wpshop') . '" class="db_deleted_table_check" />';
1260 1260
 									$warning_nb++;
1261
-									if ( !empty($warning_list[$plugin_db_version]) ) {
1261
+									if (!empty($warning_list[$plugin_db_version])) {
1262 1262
 										$warning_list[$plugin_db_version] += 1;
1263 1263
 									}
1264 1264
 									else {
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 								}
1268 1268
 								$sub_modif .= $deleted_table_result;
1269 1269
 							}
1270
-							else{
1270
+							else {
1271 1271
 								$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Table has been deleted', 'wpshop') . '" title="' . __('Table has been deleted', 'wpshop') . '" class="db_deleted_table_check" />';
1272 1272
 							}
1273 1273
 							$sub_modif .= ' / ';
@@ -1282,57 +1282,57 @@  discard block
 block discarded – undo
1282 1282
 		}
1283 1283
 
1284 1284
 		$db_table_field_error = '';
1285
-		foreach($wpshop_db_table as $table_name => $table_definition){
1286
-			if(!empty($table_definition)){
1285
+		foreach ($wpshop_db_table as $table_name => $table_definition) {
1286
+			if (!empty($table_definition)) {
1287 1287
 				$table_line = explode("
1288 1288
 ", $table_definition);
1289 1289
 
1290 1290
 				$sub_db_table_field_error = '  ';
1291
-				foreach($table_line as $table_definition_line){
1291
+				foreach ($table_line as $table_definition_line) {
1292 1292
 					$def_line = trim($table_definition_line);
1293
-					if(substr($def_line, 0, 1) == "`"){
1293
+					if (substr($def_line, 0, 1) == "`") {
1294 1294
 						$line_element = explode(" ", $def_line);
1295 1295
 						$field_name = str_replace("`", "", $line_element[0]);
1296
-						$query = $wpdb->prepare("SHOW COLUMNS FROM " .$table_name . " WHERE Field = %s", $field_name);
1296
+						$query = $wpdb->prepare("SHOW COLUMNS FROM " . $table_name . " WHERE Field = %s", $field_name);
1297 1297
 						$columns = $wpdb->get_row($query);
1298
-						if ( !empty($columns->Field) && ($columns->Field != $field_name)) {
1298
+						if (!empty($columns->Field) && ($columns->Field != $field_name)) {
1299 1299
 							$sub_db_table_field_error .= $field_name . ', '/*  . ' : <img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />' */;
1300 1300
 							$error_nb++;
1301 1301
 						}
1302 1302
 					}
1303 1303
 				}
1304 1304
 				$sub_db_table_field_error = trim(substr($sub_db_table_field_error, 0, -2));
1305
-				if(!empty($sub_db_table_field_error)){
1305
+				if (!empty($sub_db_table_field_error)) {
1306 1306
 					$db_table_field_error .= sprintf(__('Following fields of %s don\'t exists: %s', 'wpshop'), '<span class="bold" >' . $table_name . '</span>', $sub_db_table_field_error) . '<br/>';
1307 1307
 				}
1308 1308
 			}
1309 1309
 		}
1310
-		if(!empty($db_table_field_error)){
1310
+		if (!empty($db_table_field_error)) {
1311 1311
 			$db_table_field_error = '<hr class="clear" />' . $db_table_field_error . '<hr/>';
1312 1312
 		}
1313 1313
 
1314 1314
 		/*	Start display	*/
1315 1315
 		$plugin_install_error = '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Wpshop install is ok', 'wpshop') . '" title="' . __('Wpshop install is ok', 'wpshop') . '" />&nbsp;' . __('There is no error in your wpshop installation. Please find details below', 'wpshop') . '<hr/>';
1316
-		if($error_nb > 0){
1316
+		if ($error_nb > 0) {
1317 1317
 			$plugin_install_error = '<img src="' . admin_url('images/no.png') . '" alt="' . __('Error in wpshop install', 'wpshop') . '" title="' . __('Error in wpshop install', 'wpshop') . '" />&nbsp;' . __('There are ne or more errors into your wpshop installation. Please find details below', 'wpshop') . '<br/>
1318 1318
 							<ul>';
1319
-			foreach($error_list as $version => $element_nb){
1320
-				$plugin_install_error .= '<li>' . sprintf(__('There are %d errors into %s version', 'wpshop'), $element_nb, '<a href="#wpshop_plugin_v_' . $version . '" >' . $version . '</a>') . ' - <button id="wpshop_repair_db_version_' . $version  . '" data-nonce="' . wp_create_nonce( 'wpshop_ajax_db_repair_tool ' ) .'" class="wpshop_repair_db_version" >' . __('Repair', 'wpshop') . '</button></li>';
1319
+			foreach ($error_list as $version => $element_nb) {
1320
+				$plugin_install_error .= '<li>' . sprintf(__('There are %d errors into %s version', 'wpshop'), $element_nb, '<a href="#wpshop_plugin_v_' . $version . '" >' . $version . '</a>') . ' - <button id="wpshop_repair_db_version_' . $version . '" data-nonce="' . wp_create_nonce('wpshop_ajax_db_repair_tool ') . '" class="wpshop_repair_db_version" >' . __('Repair', 'wpshop') . '</button></li>';
1321 1321
 			}
1322 1322
 			$plugin_install_error .= '
1323 1323
 							</ul>';
1324 1324
 		}
1325
-		if($warning_nb > 0){
1325
+		if ($warning_nb > 0) {
1326 1326
 			$plugin_install_error .= '<img src="' . EVA_IMG_ICONES_PLUGIN_URL . 'warning_vs.gif" alt="' . __('Warning in wpshop install', 'wpshop') . '" title="' . __('Warning in wpshop install', 'wpshop') . '" />&nbsp;' . __('Some element need your attention. They have no consequences on wpshop operation. Please find details below', 'wpshop') . '<br/>';
1327
-			foreach($warning_list as $version => $element_nb){
1327
+			foreach ($warning_list as $version => $element_nb) {
1328 1328
 				$plugin_install_error .= '&nbsp;&nbsp;' . sprintf(__('There are %d warning into %s version', 'wpshop'), $element_nb, '<a href="#wpshop_plugin_v_' . $version . '" >' . $version . '</a>') . ' - ';
1329 1329
 			}
1330 1330
 			$plugin_install_error = substr($plugin_install_error, 0, -3) . '<hr/>';
1331 1331
 		}
1332 1332
 
1333 1333
 		$max_number = 0;
1334
-		foreach($wpshop_update_way as $number => $operation){
1335
-			if($number > $max_number){
1334
+		foreach ($wpshop_update_way as $number => $operation) {
1335
+			if ($number > $max_number) {
1336 1336
 				$max_number = $number;
1337 1337
 			}
1338 1338
 		}
@@ -1342,30 +1342,30 @@  discard block
 block discarded – undo
1342 1342
 	add_action('wp_ajax_wpshop_tool_db_check', 'wpshop_ajax_db_check_tool');
1343 1343
 
1344 1344
 	function wpshop_tool_default_datas_check() {
1345
-		check_ajax_referer( 'wpshop_tool_default_datas_check' );
1345
+		check_ajax_referer('wpshop_tool_default_datas_check');
1346 1346
 
1347 1347
 		$output_ok = $output_error = '';
1348 1348
 
1349 1349
 		/**	Get defined default datas type	*/
1350
-		$default_custom_post_type = unserialize( WPSHOP_DEFAULT_CUSTOM_TYPES );
1350
+		$default_custom_post_type = unserialize(WPSHOP_DEFAULT_CUSTOM_TYPES);
1351 1351
 
1352 1352
 		/**	Read the default data saved to check	*/
1353
-		if ( !empty($default_custom_post_type) ) {
1354
-			foreach ( $default_custom_post_type as $type ) {
1353
+		if (!empty($default_custom_post_type)) {
1354
+			foreach ($default_custom_post_type as $type) {
1355 1355
 				$has_error = false;
1356 1356
 				$file_uri = WPSHOP_TEMPLATES_DIR . 'default_datas/' . $type . '.csv';
1357
-				if ( is_file( $file_uri ) ) {
1357
+				if (is_file($file_uri)) {
1358 1358
 					unset($tpl_component);
1359 1359
 					$tpl_component = array();
1360 1360
 					$tpl_component['CUSTOM_POST_TYPE_NAME'] = 'wpshop_cpt_' . $type;
1361 1361
 
1362 1362
 					/**	Launch check on custom post type	*/
1363
-					$check_cpt = wpshop_entities::check_default_custom_post_type( $type, $tpl_component );
1363
+					$check_cpt = wpshop_entities::check_default_custom_post_type($type, $tpl_component);
1364 1364
 					$has_error = $check_cpt[0];
1365 1365
 					$tpl_component['TOOLS_CUSTOM_POST_TYPE_CONTAINER'] = $check_cpt[1];
1366
-					$tpl_component = array_merge( $tpl_component, $check_cpt[2] );
1366
+					$tpl_component = array_merge($tpl_component, $check_cpt[2]);
1367 1367
 
1368
-					if ( $has_error ) {
1368
+					if ($has_error) {
1369 1369
 						$output_error .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element', $tpl_component, array(), 'admin');
1370 1370
 					}
1371 1371
 					else {
@@ -1381,77 +1381,77 @@  discard block
 block discarded – undo
1381 1381
 	add_action('wp_ajax_wpshop_tool_default_datas_check', 'wpshop_tool_default_datas_check');
1382 1382
 
1383 1383
 	function wpshop_ajax_repair_default_datas() {
1384
-		check_ajax_referer( 'wpshop_ajax_repair_default_datas' );
1384
+		check_ajax_referer('wpshop_ajax_repair_default_datas');
1385 1385
 
1386 1386
 		global $wpdb;
1387 1387
 		$output = '';
1388 1388
 		$container = '';
1389 1389
 		$result = '';
1390 1390
 
1391
-		$selected_type = ( isset( $_POST['type'] ) && !empty( $_POST['type'] ) ) ? sanitize_text_field( $_POST['type'] ) : null;
1392
-		$identifier = ( isset( $_POST['identifier'] ) && !empty( $_POST['identifier'] ) ) ? sanitize_text_field( $_POST['identifier'] ) : null;
1391
+		$selected_type = (isset($_POST['type']) && !empty($_POST['type'])) ? sanitize_text_field($_POST['type']) : null;
1392
+		$identifier = (isset($_POST['identifier']) && !empty($_POST['identifier'])) ? sanitize_text_field($_POST['identifier']) : null;
1393 1393
 
1394
-		switch ( $selected_type ) {
1394
+		switch ($selected_type) {
1395 1395
 			case WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES:
1396
-				$result = wpshop_entities::create_cpt_from_csv_file( $identifier );
1396
+				$result = wpshop_entities::create_cpt_from_csv_file($identifier);
1397 1397
 			break;
1398 1398
 			case WPSHOP_DBT_ATTRIBUTE:
1399
-				$result = wpshop_entities::create_cpt_attributes_from_csv_file( $identifier );
1399
+				$result = wpshop_entities::create_cpt_attributes_from_csv_file($identifier);
1400 1400
 			break;
1401 1401
 		}
1402 1402
 
1403
-		echo json_encode( $result );
1403
+		echo json_encode($result);
1404 1404
 		die();
1405 1405
 	}
1406 1406
 	add_action('wp_ajax_wpshop_ajax_repair_default_datas', 'wpshop_ajax_repair_default_datas');
1407 1407
 
1408 1408
 	function wpshop_ajax_translate_default_datas() {
1409
-		check_ajax_referer( 'wpshop_ajax_translate_default_datas' );
1409
+		check_ajax_referer('wpshop_ajax_translate_default_datas');
1410 1410
 		global $wpdb;
1411 1411
 		$result = array('status' => true);
1412 1412
 
1413
-		$selected_type = ( isset( $_POST['type'] ) && !empty( $_POST['type'] ) ) ? sanitize_text_field( $_POST['type'] ) : null;
1414
-		$identifier = ( isset( $_POST['identifier'] ) && !empty( $_POST['identifier'] ) ) ? sanitize_text_field( $_POST['identifier'] ) : null;
1413
+		$selected_type = (isset($_POST['type']) && !empty($_POST['type'])) ? sanitize_text_field($_POST['type']) : null;
1414
+		$identifier = (isset($_POST['identifier']) && !empty($_POST['identifier'])) ? sanitize_text_field($_POST['identifier']) : null;
1415 1415
 
1416
-		$entity_id = wpshop_entities::get_entity_identifier_from_code( $identifier );
1416
+		$entity_id = wpshop_entities::get_entity_identifier_from_code($identifier);
1417 1417
 		$query = $wpdb->prepare("SELECT id, frontend_label FROM " . $selected_type . " WHERE entity_id = %d", $entity_id);
1418
-		$attribute_list = $wpdb->get_results( $query );
1419
-		if ( !empty($attribute_list) ) {
1420
-			foreach ( $attribute_list as $attribute) {
1421
-				$update_result = $wpdb->update( $selected_type, array('frontend_label' => __($attribute->frontend_label, 'wpshop')), array('id' => $attribute->id) );
1422
-				if ( $update_result === false ) {
1418
+		$attribute_list = $wpdb->get_results($query);
1419
+		if (!empty($attribute_list)) {
1420
+			foreach ($attribute_list as $attribute) {
1421
+				$update_result = $wpdb->update($selected_type, array('frontend_label' => __($attribute->frontend_label, 'wpshop')), array('id' => $attribute->id));
1422
+				if ($update_result === false) {
1423 1423
 					$result['status'] = false;
1424 1424
 				}
1425 1425
 			}
1426 1426
 		}
1427 1427
 
1428
-		echo json_encode( $result );
1428
+		echo json_encode($result);
1429 1429
 		die();
1430 1430
 	}
1431 1431
 	add_action('wp_ajax_wpshop_ajax_translate_default_datas', 'wpshop_ajax_translate_default_datas');
1432 1432
 
1433 1433
 	function wpshop_ajax_db_repair_tool() {
1434
-		check_ajax_referer( 'wpshop_ajax_db_repair_tool' );
1434
+		check_ajax_referer('wpshop_ajax_db_repair_tool');
1435 1435
 
1436 1436
 		$version_id = isset($_POST['version_id']) ? wpshop_tools::varSanitizer($_POST['version_id']) : null;
1437 1437
 
1438
-		echo wpshop_install::alter_db_structure_on_update( $version_id );
1438
+		echo wpshop_install::alter_db_structure_on_update($version_id);
1439 1439
 
1440 1440
 		die();
1441 1441
 	}
1442 1442
 	add_action('wp_ajax_wpshop_ajax_db_repair_tool', 'wpshop_ajax_db_repair_tool');
1443 1443
 
1444 1444
 	function wps_mass_action_main_interface() {
1445
-		check_ajax_referer( 'wps_mass_action_main_interface' );
1445
+		check_ajax_referer('wps_mass_action_main_interface');
1446 1446
 		$tpl_component = array();
1447 1447
 
1448 1448
 		/**	Copy an attribute content to another	*/
1449
-		$attribute_list = wpshop_attributes::getElement(wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ), "'valid'", 'entity_id', true);
1449
+		$attribute_list = wpshop_attributes::getElement(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), "'valid'", 'entity_id', true);
1450 1450
 		$possible_values = array('' => __('Choose an attribute', 'wpshop'));
1451 1451
 		$possible_values_for_variation = array('' => __('Choose an attribute', 'wpshop'));
1452
-		foreach ( $attribute_list as $attribute ) {
1452
+		foreach ($attribute_list as $attribute) {
1453 1453
 			$possible_values[$attribute->id] = $attribute->frontend_label;
1454
-			if ( $attribute->is_used_for_variation == 'yes' ) {
1454
+			if ($attribute->is_used_for_variation == 'yes') {
1455 1455
 				$possible_values_for_variation[$attribute->id] = $attribute->frontend_label;
1456 1456
 			}
1457 1457
 		}
@@ -1482,22 +1482,22 @@  discard block
 block discarded – undo
1482 1482
 	add_action('wp_ajax_wps_mass_action', 'wps_mass_action_main_interface');
1483 1483
 
1484 1484
 	function wps_mass_action_update_attribute_value() {
1485
-		check_ajax_referer( 'wps_mass_action_update_attribute_value' );
1485
+		check_ajax_referer('wps_mass_action_update_attribute_value');
1486 1486
 		global $wpdb;
1487 1487
 		$response = array();
1488 1488
 
1489
-		$from = !empty( $_POST['wps_update_att_values']['from'] ) ? sanitize_text_field( $_POST['wps_update_att_values']['from'] ) : '';
1490
-		$to = !empty( $_POST['wps_update_att_values']['to'] ) ? sanitize_text_field( $_POST['wps_update_att_values']['to'] ) : '';
1491
-		$entity_to_transfert = !empty( $_POST['wps_entity_to_transfert'] ) ? sanitize_text_field( $_POST['wps_entity_to_transfert'] ) : '';
1489
+		$from = !empty($_POST['wps_update_att_values']['from']) ? sanitize_text_field($_POST['wps_update_att_values']['from']) : '';
1490
+		$to = !empty($_POST['wps_update_att_values']['to']) ? sanitize_text_field($_POST['wps_update_att_values']['to']) : '';
1491
+		$entity_to_transfert = !empty($_POST['wps_entity_to_transfert']) ? sanitize_text_field($_POST['wps_entity_to_transfert']) : '';
1492 1492
 
1493
-		if ( $from != $to ) {
1493
+		if ($from != $to) {
1494 1494
 			$from_attribute = wpshop_attributes::getElement($from, "'valid'");
1495 1495
 			$to_attribute = wpshop_attributes::getElement($to, "'valid'");
1496
-			if ( $from_attribute->data_type == $to_attribute->data_type ) {
1496
+			if ($from_attribute->data_type == $to_attribute->data_type) {
1497 1497
 
1498 1498
 				/**	Manage specific case	*/
1499 1499
 				$query_more_args = array();
1500
-				switch( $to_attribute->code ){
1500
+				switch ($to_attribute->code) {
1501 1501
 					case "barcode":
1502 1502
 							$more_query = "
1503 1503
 						AND VAL.value NOT LIKE %s";
@@ -1513,22 +1513,22 @@  discard block
 block discarded – undo
1513 1513
 					WHERE VAL.attribute_id = %d
1514 1514
 						AND P.post_type = %s
1515 1515
 						AND VAL.value != ''" . $more_query,
1516
-					array_merge( array( $from, $entity_to_transfert ), $query_more_args )
1516
+					array_merge(array($from, $entity_to_transfert), $query_more_args)
1517 1517
 				);
1518
-				$element_list_to_update = $wpdb->get_results( $query );
1518
+				$element_list_to_update = $wpdb->get_results($query);
1519 1519
 
1520
-				if ( !empty($element_list_to_update) ) {
1520
+				if (!empty($element_list_to_update)) {
1521 1521
 					$has_error = false;
1522 1522
 					$error_count = 0;
1523
-					foreach ( $element_list_to_update as $element ) {
1523
+					foreach ($element_list_to_update as $element) {
1524 1524
 
1525 1525
 						/**	Historicize the old value of recevier attribute	*/
1526
-						if (  $to_attribute->is_historisable == 'yes' ) {
1526
+						if ($to_attribute->is_historisable == 'yes') {
1527 1527
 							$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $to_attribute->data_type . " WHERE attribute_id = %d AND entity_id = %d", $to_attribute->id, $element->ID);
1528
-							$attribute_histos = $wpdb->get_results( $query );
1529
-							if ( !empty( $attribute_histos ) ) {
1530
-								foreach ( $attribute_histos as $attribute_histo ) {
1531
-									if ( !empty( $attribute_histo->value ) ) {
1528
+							$attribute_histos = $wpdb->get_results($query);
1529
+							if (!empty($attribute_histos)) {
1530
+								foreach ($attribute_histos as $attribute_histo) {
1531
+									if (!empty($attribute_histo->value)) {
1532 1532
 										$attribute_histo_content['status'] = 'valid';
1533 1533
 										$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1534 1534
 										$attribute_histo_content['creation_date_value'] = $attribute_histo->creation_date_value;
@@ -1541,12 +1541,12 @@  discard block
 block discarded – undo
1541 1541
 										$attribute_histo_content['value'] = $attribute_histo->value;
1542 1542
 										$attribute_histo_content['value_type'] = WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType;
1543 1543
 										$last_histo = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1544
-										if ( $last_histo === false ) {
1544
+										if ($last_histo === false) {
1545 1545
 											$has_error = true;
1546 1546
 											$error_count++;
1547 1547
 										}
1548 1548
 										else {
1549
-											$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array( 'value_id' => $attribute_histo->value_id ) );
1549
+											$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array('value_id' => $attribute_histo->value_id));
1550 1550
 										}
1551 1551
 									}
1552 1552
 								}
@@ -1555,36 +1555,36 @@  discard block
 block discarded – undo
1555 1555
 
1556 1556
 						/**		*/
1557 1557
 						$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $to_attribute->data_type . " WHERE attribute_id = %d AND entity_id = %d", $from_attribute->id, $element->ID);
1558
-						$attribute_to_save = $wpdb->get_row( $query, ARRAY_A );
1558
+						$attribute_to_save = $wpdb->get_row($query, ARRAY_A);
1559 1559
 						unset($attribute_to_save['value_id']);
1560 1560
 						$attribute_to_save['attribute_id'] = $to_attribute->id;
1561 1561
 						$attribute_to_save['creation_date_value'] = current_time('mysql', 0);
1562 1562
 						$attribute_to_save['user_id'] = get_current_user_id();
1563
-						$new_value = $wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $to_attribute->data_type, $attribute_to_save );
1564
-						if ( $new_value === false ) {
1563
+						$new_value = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $to_attribute->data_type, $attribute_to_save);
1564
+						if ($new_value === false) {
1565 1565
 							$has_error = true;
1566 1566
 							$error_count++;
1567 1567
 						}
1568 1568
 						else {
1569 1569
 							/**	Save new atribute values in product metadata	*/
1570
-							$current_product_metadata = get_post_meta( $element->ID, '_wpshop_product_metadata', true);
1570
+							$current_product_metadata = get_post_meta($element->ID, '_wpshop_product_metadata', true);
1571 1571
 							$current_product_metadata[$to_attribute->code] = $element->value;
1572
-							update_post_meta( $element->ID, '_wpshop_product_metadata', $current_product_metadata );
1572
+							update_post_meta($element->ID, '_wpshop_product_metadata', $current_product_metadata);
1573 1573
 
1574 1574
 							/**	Save a single meta for attribute in case it will be used in specific case where meta needs to be alone	*/
1575
-							if ( ( ($to_attribute->is_used_for_sort_by == 'yes') || ($to_attribute->is_searchable == 'yes'))  || ( $to_attribute->is_filterable == 'yes') && !empty($element->value) ) :
1576
-								update_post_meta( $element->ID, '_' . $to_attribute->code, $element->value );
1575
+							if ((($to_attribute->is_used_for_sort_by == 'yes') || ($to_attribute->is_searchable == 'yes')) || ($to_attribute->is_filterable == 'yes') && !empty($element->value)) :
1576
+								update_post_meta($element->ID, '_' . $to_attribute->code, $element->value);
1577 1577
 							endif;
1578 1578
 						}
1579 1579
 					}
1580 1580
 
1581
-					if ( !$has_error ) {
1581
+					if (!$has_error) {
1582 1582
 						$response['status'] = true;
1583 1583
 						$response['error'] = __('Transfert between attribute is done', 'wpshop');
1584 1584
 					}
1585 1585
 					else {
1586 1586
 						$response['status'] = false;
1587
-						$response['error'] = sprinttf( __('There are %d error that occured while copying value through attributes', 'wpshop'), $error_count);
1587
+						$response['error'] = sprinttf(__('There are %d error that occured while copying value through attributes', 'wpshop'), $error_count);
1588 1588
 					}
1589 1589
 				}
1590 1590
 				else {
@@ -1602,20 +1602,20 @@  discard block
 block discarded – undo
1602 1602
 			$response['error'] = __('You have to choose attributes in order to update values', 'wpshop');
1603 1603
 		}
1604 1604
 
1605
-		echo json_encode( $response );
1605
+		echo json_encode($response);
1606 1606
 		die();
1607 1607
 	}
1608 1608
 	add_action('wp_ajax_wps_mass_action_update_attribute', 'wps_mass_action_update_attribute_value');
1609 1609
 
1610 1610
 	function wps_tools_mass_action_load_possible_options_for_variations_attributes() {
1611 1611
 		// @TODO attribute_id est introuvable
1612
-		check_ajax_referer( 'wps_tools_mass_action_load_possible_options_for_variations_attributes' );
1612
+		check_ajax_referer('wps_tools_mass_action_load_possible_options_for_variations_attributes');
1613 1613
 		$output = '';
1614
-		$attribute_id = !empty( $_POST['attribute_id'] ) ? (int) $_POST['attribute_id'] : 0;
1615
-		$attribute = wpshop_attributes::getElement( $attribute_id, "'valid'" );
1614
+		$attribute_id = !empty($_POST['attribute_id']) ? (int)$_POST['attribute_id'] : 0;
1615
+		$attribute = wpshop_attributes::getElement($attribute_id, "'valid'");
1616 1616
 
1617 1617
 		/**	Define new default value	*/
1618
-		$attribute_possible_values_output = wpshop_attributes::get_select_output( $attribute, array() );
1618
+		$attribute_possible_values_output = wpshop_attributes::get_select_output($attribute, array());
1619 1619
 		$attribute_possible_values_output['possible_value']['no_changes'] = __('No changes', 'wpshop');
1620 1620
 		$attribute_possible_values_output['possible_value']['none'] = __('No default value', 'wpshop');
1621 1621
 		ksort($attribute_possible_values_output['possible_value']);
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 		$input_def['valueToPut'] = 'index';
1625 1625
 		$input_def['name'] = 'wps_update_att_for_variation_options_values';
1626 1626
 		$input_def['id'] = 'wps_update_att_for_variation_options_values';
1627
-		$output .= __( 'Default value to affect for this attribute to all products', 'wpshop' ) . ' ' . wpshop_form::check_input_type( $input_def );
1627
+		$output .= __('Default value to affect for this attribute to all products', 'wpshop') . ' ' . wpshop_form::check_input_type($input_def);
1628 1628
 
1629 1629
 		/**	Define if attribute is required for adding product to cart	*/
1630 1630
 		$input_def = array();
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
 		$input_def['valueToPut'] = 'index';
1634 1634
 		$input_def['name'] = 'wps_update_att_for_variation_required_state';
1635 1635
 		$input_def['id'] = 'wps_update_att_for_variation_required_state';
1636
-		$output .= '<br/>' . __( 'Put this attribute as required for all products', 'wpshop' ) . ' ' . wpshop_form::check_input_type( $input_def );
1636
+		$output .= '<br/>' . __('Put this attribute as required for all products', 'wpshop') . ' ' . wpshop_form::check_input_type($input_def);
1637 1637
 
1638 1638
 
1639 1639
 		$input_def = array();
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
 		$input_def['valueToPut'] = 'index';
1643 1643
 		$input_def['name'] = 'wps_update_att_for_variation[price_display][text_from]';
1644 1644
 		$input_def['id'] = 'wps_update_att_for_variation_price_display_text_from';
1645
-		$output .= '<br/>' . __( 'Display "Price from" text before price for all products', 'wpshop' ) . ' ' . wpshop_form::check_input_type( $input_def );
1645
+		$output .= '<br/>' . __('Display "Price from" text before price for all products', 'wpshop') . ' ' . wpshop_form::check_input_type($input_def);
1646 1646
 
1647 1647
 		$input_def = array();
1648 1648
 		$input_def['possible_value'] = array('no_changes' => __('No changes', 'wpshop'), 'no' => __('No', 'wpshop'), 'yes' => __('Yes', 'wpshop'));
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
 		$input_def['valueToPut'] = 'index';
1651 1651
 		$input_def['name'] = 'wps_update_att_for_variation[price_display][lower_price]';
1652 1652
 		$input_def['id'] = 'wps_update_att_for_variation_price_display_lower_price';
1653
-		$output .= '<br/>' . __( 'Display lower price for all products', 'wpshop' ) . ' ' . wpshop_form::check_input_type( $input_def );
1653
+		$output .= '<br/>' . __('Display lower price for all products', 'wpshop') . ' ' . wpshop_form::check_input_type($input_def);
1654 1654
 
1655 1655
 		$input_def = array();
1656 1656
 		$input_def['possible_value'] = array('no_changes' => __('No changes', 'wpshop'), 'replacement' => __('Replace product price with option price', 'wpshop'), 'addition' => __('Add option price to product price', 'wpshop'));
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
 		$input_def['valueToPut'] = 'index';
1659 1659
 		$input_def['name'] = 'wps_update_att_for_variation[price_behaviour]';
1660 1660
 		$input_def['id'] = 'wps_update_att_for_variation_price_behaviour';
1661
-		$output .= '<br/>' . __( 'Price calculation behaviour', 'wpshop' ) . ' ' . wpshop_form::check_input_type( $input_def );
1661
+		$output .= '<br/>' . __('Price calculation behaviour', 'wpshop') . ' ' . wpshop_form::check_input_type($input_def);
1662 1662
 
1663 1663
 		$input_def = array();
1664 1664
 		$input_def['possible_value'] = array('no_changes' => __('No changes', 'wpshop'), 'single' => __('Priority to single options', 'wpshop'), 'combined' => __('Priority to combined options', 'wpshop'));
@@ -1666,7 +1666,7 @@  discard block
 block discarded – undo
1666 1666
 		$input_def['valueToPut'] = 'index';
1667 1667
 		$input_def['name'] = 'wps_update_att_for_variation[priority]';
1668 1668
 		$input_def['id'] = 'wps_update_att_for_variation_priority';
1669
-		$output .= '<br/>' . __( 'Choose priority combination for calculating options', 'wpshop' ) . ' ' . wpshop_form::check_input_type( $input_def );
1669
+		$output .= '<br/>' . __('Choose priority combination for calculating options', 'wpshop') . ' ' . wpshop_form::check_input_type($input_def);
1670 1670
 
1671 1671
 		echo $output;
1672 1672
 		die();
@@ -1674,69 +1674,69 @@  discard block
 block discarded – undo
1674 1674
 	add_action('wp_ajax_wps_tools_mass_action_load_possible_options_for_variations_attributes', 'wps_tools_mass_action_load_possible_options_for_variations_attributes');
1675 1675
 
1676 1676
 	function wps_mass_action_change_variation_option() {
1677
-		check_ajax_referer( 'wps_mass_action_change_variation_option' );
1677
+		check_ajax_referer('wps_mass_action_change_variation_option');
1678 1678
 		global $wpdb;
1679 1679
 
1680
-		$attribute_id = !empty( $_POST['attribute_id'] ) ? (int) $_POST['attribute_id'] : 0;
1681
-		$attribute = wpshop_attributes::getElement( $attribute_id, "'valid'" );
1682
-		$query = $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value LIKE ('%%%s%%')", '_wpshop_variation_defining', $attribute->code );
1683
-		$meta_to_update = $wpdb->get_results( $query );
1680
+		$attribute_id = !empty($_POST['attribute_id']) ? (int)$_POST['attribute_id'] : 0;
1681
+		$attribute = wpshop_attributes::getElement($attribute_id, "'valid'");
1682
+		$query = $wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value LIKE ('%%%s%%')", '_wpshop_variation_defining', $attribute->code);
1683
+		$meta_to_update = $wpdb->get_results($query);
1684 1684
 		$has_error = false;
1685
-		if ( !empty($meta_to_update) ) {
1686
-			foreach ( $meta_to_update as $meta_def ) {
1687
-				$meta_value = unserialize( $meta_def->meta_value );
1688
-				if ( !empty($meta_value) && !empty( $meta_value['attributes'] ) && in_array( $attribute->code, $meta_value['attributes']) ) {
1685
+		if (!empty($meta_to_update)) {
1686
+			foreach ($meta_to_update as $meta_def) {
1687
+				$meta_value = unserialize($meta_def->meta_value);
1688
+				if (!empty($meta_value) && !empty($meta_value['attributes']) && in_array($attribute->code, $meta_value['attributes'])) {
1689 1689
 
1690
-					$update_att_for_variation_options_values = !empty( $_POST['wps_update_att_for_variation_options_values'] ) ? sanitize_text_field( $_POST['wps_update_att_for_variation_options_values'] ) : '';
1691
-					if ( $update_att_for_variation_options_values != 'no_changes' ) {
1690
+					$update_att_for_variation_options_values = !empty($_POST['wps_update_att_for_variation_options_values']) ? sanitize_text_field($_POST['wps_update_att_for_variation_options_values']) : '';
1691
+					if ($update_att_for_variation_options_values != 'no_changes') {
1692 1692
 						$meta_value['options']['attributes_default_value'][$attribute->code] = $update_att_for_variation_options_values;
1693 1693
 					}
1694 1694
 
1695
-					$wps_update_att_for_variation_required_state = !empty( $_POST['wps_update_att_for_variation_required_state'] ) ? sanitize_text_field( $_POST['wps_update_att_for_variation_required_state'] ) : '';
1696
-					if ( !empty($wps_update_att_for_variation_required_state) && ($wps_update_att_for_variation_required_state != 'no_changes') ) {
1697
-						if ( $wps_update_att_for_variation_required_state == 'yes') {
1695
+					$wps_update_att_for_variation_required_state = !empty($_POST['wps_update_att_for_variation_required_state']) ? sanitize_text_field($_POST['wps_update_att_for_variation_required_state']) : '';
1696
+					if (!empty($wps_update_att_for_variation_required_state) && ($wps_update_att_for_variation_required_state != 'no_changes')) {
1697
+						if ($wps_update_att_for_variation_required_state == 'yes') {
1698 1698
 							$meta_value['options']['required_attributes'][$attribute->code] = $attribute->code;
1699 1699
 						}
1700
-						else if ( !empty($meta_value['options']['required_attributes']) && !empty($meta_value['options']['required_attributes'][$attribute->code]) ) {
1700
+						else if (!empty($meta_value['options']['required_attributes']) && !empty($meta_value['options']['required_attributes'][$attribute->code])) {
1701 1701
 							unset($meta_value['options']['required_attributes'][$attribute->code]);
1702 1702
 						}
1703 1703
 					}
1704 1704
 
1705
-					$update_att_for_variation = !empty( $_POST['wps_update_att_for_variation'] ) ? (array) $_POST['wps_update_att_for_variation'] : array();
1706
-					$text_from = !empty( $update_att_for_variation['text_from'] ) ? sanitize_text_field( $update_att_for_variation['text_from'] ) : '';
1707
-					if ( !empty( $update_att_for_variation ) ) {
1708
-						if ( !empty($text_from) && ($text_from != 'no_changes') ) {
1709
-							if ( $text_from == 'yes' ) {
1705
+					$update_att_for_variation = !empty($_POST['wps_update_att_for_variation']) ? (array)$_POST['wps_update_att_for_variation'] : array();
1706
+					$text_from = !empty($update_att_for_variation['text_from']) ? sanitize_text_field($update_att_for_variation['text_from']) : '';
1707
+					if (!empty($update_att_for_variation)) {
1708
+						if (!empty($text_from) && ($text_from != 'no_changes')) {
1709
+							if ($text_from == 'yes') {
1710 1710
 								$meta_value['options']['price_display']['text_from'] = 'on';
1711 1711
 							}
1712
-							else if( !empty($meta_value['options']['price_display']['text_from']) ) {
1712
+							else if (!empty($meta_value['options']['price_display']['text_from'])) {
1713 1713
 								unset($meta_value['options']['price_display']['text_from']);
1714 1714
 							}
1715 1715
 						}
1716 1716
 
1717
-						$lower_price = !empty( $update_att_for_variation['lower_price'] ) ? sanitize_text_field( $update_att_for_variation['lower_price'] ) : '';
1718
-						if ( !empty($lower_price) && ($lower_price != 'no_changes') ) {
1719
-							if ( $lower_price == 'yes' ) {
1717
+						$lower_price = !empty($update_att_for_variation['lower_price']) ? sanitize_text_field($update_att_for_variation['lower_price']) : '';
1718
+						if (!empty($lower_price) && ($lower_price != 'no_changes')) {
1719
+							if ($lower_price == 'yes') {
1720 1720
 								$meta_value['options']['price_display']['lower_price'] = 'on';
1721 1721
 							}
1722
-							else if( !empty($meta_value['options']['price_display']['lower_price']) ) {
1722
+							else if (!empty($meta_value['options']['price_display']['lower_price'])) {
1723 1723
 								unset($meta_value['options']['price_display']['lower_price']);
1724 1724
 							}
1725 1725
 						}
1726 1726
 
1727
-						$price_behaviour = !empty( $update_att_for_variation['price_behaviour'] ) ? sanitize_text_field( $update_att_for_variation['price_behaviour'] ) : '';
1728
-						if ( !empty($price_behaviour) && ($price_behaviour != 'no_changes') ) {
1727
+						$price_behaviour = !empty($update_att_for_variation['price_behaviour']) ? sanitize_text_field($update_att_for_variation['price_behaviour']) : '';
1728
+						if (!empty($price_behaviour) && ($price_behaviour != 'no_changes')) {
1729 1729
 							$meta_value['options']['price_behaviour'][0] = $price_behaviour;
1730 1730
 						}
1731 1731
 
1732
-						$priority = !empty( $update_att_for_variation['priority'] ) ? sanitize_text_field( $update_att_for_variation['priority'] ) : '';
1733
-						if ( !empty($priority) && ($priority != 'no_changes') ) {
1732
+						$priority = !empty($update_att_for_variation['priority']) ? sanitize_text_field($update_att_for_variation['priority']) : '';
1733
+						if (!empty($priority) && ($priority != 'no_changes')) {
1734 1734
 							$meta_value['options']['priority'][0] = $priority;
1735 1735
 						}
1736 1736
 					}
1737 1737
 
1738
-					$meta_save = update_meta( $meta_def->meta_id, '_wpshop_variation_defining', $meta_value);
1739
-					if ( $meta_save === false ) {
1738
+					$meta_save = update_meta($meta_def->meta_id, '_wpshop_variation_defining', $meta_value);
1739
+					if ($meta_save === false) {
1740 1740
 						$has_error = true;
1741 1741
 					}
1742 1742
 
@@ -1744,7 +1744,7 @@  discard block
 block discarded – undo
1744 1744
 			}
1745 1745
 		}
1746 1746
 
1747
-		echo json_encode( array('status' => $has_error, 'error' => (!$has_error ? __('Product variation parameters have been updated', 'wpshop') : __('An error occured while changing products variations options parameters'))) );
1747
+		echo json_encode(array('status' => $has_error, 'error' => (!$has_error ? __('Product variation parameters have been updated', 'wpshop') : __('An error occured while changing products variations options parameters'))));
1748 1748
 		die();
1749 1749
 	}
1750 1750
 	add_action('wp_ajax_wps_mass_action_change_variation_option', 'wps_mass_action_change_variation_option');
@@ -1756,7 +1756,7 @@  discard block
 block discarded – undo
1756 1756
 	 */
1757 1757
 	function ajax_activate_addons() {
1758 1758
 		global $wpdb;
1759
-		check_ajax_referer( 'wpshop_ajax_activate_addons', 'wpshop_ajax_nonce' );
1759
+		check_ajax_referer('wpshop_ajax_activate_addons', 'wpshop_ajax_nonce');
1760 1760
 
1761 1761
 		$addon_name = isset($_POST['addon']) ? wpshop_tools::varSanitizer($_POST['addon']) : null;
1762 1762
 		$addon_code = isset($_POST['code']) ? wpshop_tools::varSanitizer($_POST['code']) : null;
@@ -1765,56 +1765,56 @@  discard block
 block discarded – undo
1765 1765
 		if (!empty($addon_name) && !empty($addon_code)) {
1766 1766
 			$addons_list = (unserialize(WPSHOP_ADDONS_LIST));
1767 1767
 			if (in_array($addon_name, array_keys($addons_list))) {
1768
-				$plug = get_plugin_data( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/wpshop.php' );
1768
+				$plug = get_plugin_data(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/wpshop.php');
1769 1769
 				$code_part = array();
1770
-				$code_part[] = substr(hash ( "sha256" , $addons_list[$addon_name][0] ),  $addons_list[$addon_name][1], 5);
1771
-				$code_part[] = substr(hash ( "sha256" , $plug['Name'] ), WPSHOP_ADDONS_KEY_IS, 5);
1772
-				$code_part[] = substr(hash ( "sha256" , 'addons' ), WPSHOP_ADDONS_KEY_IS, 5);
1770
+				$code_part[] = substr(hash("sha256", $addons_list[$addon_name][0]), $addons_list[$addon_name][1], 5);
1771
+				$code_part[] = substr(hash("sha256", $plug['Name']), WPSHOP_ADDONS_KEY_IS, 5);
1772
+				$code_part[] = substr(hash("sha256", 'addons'), WPSHOP_ADDONS_KEY_IS, 5);
1773 1773
 				$code = $code_part[1] . '-' . $code_part[2] . '-' . $code_part[0];
1774 1774
 
1775 1775
 				$current_web_site = site_url('/');
1776 1776
 
1777
-				if ( $addons_list[$addon_name][2] == 'per_site') {
1778
-					$code .= '-' . substr(hash ( "sha256" , $current_web_site ),  $addons_list[$addon_name][1], 5);
1777
+				if ($addons_list[$addon_name][2] == 'per_site') {
1778
+					$code .= '-' . substr(hash("sha256", $current_web_site), $addons_list[$addon_name][1], 5);
1779 1779
 				}
1780 1780
 
1781
-				if ( !empty($addons_list[$addon_name][4]) && $addons_list[$addon_name][4] == 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE') {
1782
-					$admin_new_quotation_message = get_option( 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' );
1783
-					if ( empty($admin_new_quotation_message) ) {
1784
-						wps_message_ctr::createMessage( 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' );
1781
+				if (!empty($addons_list[$addon_name][4]) && $addons_list[$addon_name][4] == 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE') {
1782
+					$admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
1783
+					if (empty($admin_new_quotation_message)) {
1784
+						wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
1785 1785
 					}
1786
-					$admin_new_quotation_confirm_message = get_option( 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' );
1787
-					if ( empty($admin_new_quotation_confirm_message) ) {
1788
-						wps_message_ctr::createMessage( 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' );
1786
+					$admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
1787
+					if (empty($admin_new_quotation_confirm_message)) {
1788
+						wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
1789 1789
 					}
1790 1790
 				}
1791 1791
 
1792 1792
 				if ($code == $addon_code) {
1793
-					$extra_options = get_option(WPSHOP_ADDONS_OPTION_NAME, array() );
1793
+					$extra_options = get_option(WPSHOP_ADDONS_OPTION_NAME, array());
1794 1794
 					$extra_options[$addon_name]['activate'] = true;
1795 1795
 					$extra_options[$addon_name]['activation_date'] = current_time('mysql', 0);
1796 1796
 					$extra_options[$addon_name]['activation_code'] = $addon_code;
1797
-					if ( update_option(WPSHOP_ADDONS_OPTION_NAME, $extra_options) ) {
1798
-						$result = array(true, __('The addon has been activated successfully', 'wpshop'), __('Activated','wpshop'));
1799
-						if( !empty($addons_list[$addon_name][3]) ) {
1797
+					if (update_option(WPSHOP_ADDONS_OPTION_NAME, $extra_options)) {
1798
+						$result = array(true, __('The addon has been activated successfully', 'wpshop'), __('Activated', 'wpshop'));
1799
+						if (!empty($addons_list[$addon_name][3])) {
1800 1800
 							$activate_attribute_for_addon = $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('status' => 'valid'), array('code' => $addons_list[$addon_name][3]));
1801 1801
 						}
1802 1802
 						$state = true;
1803 1803
 					}
1804 1804
 					else {
1805
-						$result = array(false, __('An error occured','wpshop'), __('Desactivated','wpshop'));
1805
+						$result = array(false, __('An error occured', 'wpshop'), __('Desactivated', 'wpshop'));
1806 1806
 					}
1807 1807
 				}
1808 1808
 				else {
1809
-					$result = array(false, __('The activating code is invalid', 'wpshop'), __('Desactivated','wpshop'));
1809
+					$result = array(false, __('The activating code is invalid', 'wpshop'), __('Desactivated', 'wpshop'));
1810 1810
 				}
1811 1811
 			}
1812 1812
 			else {
1813
-				$result = array(false, __('The addon to activate is invalid', 'wpshop'), __('Desactivated','wpshop'));
1813
+				$result = array(false, __('The addon to activate is invalid', 'wpshop'), __('Desactivated', 'wpshop'));
1814 1814
 			}
1815 1815
 		}
1816 1816
 		else {
1817
-			$result = array(false, __('An error occured','wpshop'), __('Desactivated','wpshop'));
1817
+			$result = array(false, __('An error occured', 'wpshop'), __('Desactivated', 'wpshop'));
1818 1818
 		}
1819 1819
 		$activated_class = unserialize(WPSHOP_ADDONS_STATES_CLASS);
1820 1820
 
@@ -1827,27 +1827,27 @@  discard block
 block discarded – undo
1827 1827
 	 * Addons desactivate
1828 1828
 	 */
1829 1829
 	function ajax_desactivate_wpshop_addons() {
1830
-		check_ajax_referer( 'wpshop_ajax_activate_addons', 'wpshop_ajax_nonce' );
1830
+		check_ajax_referer('wpshop_ajax_activate_addons', 'wpshop_ajax_nonce');
1831 1831
 
1832 1832
 		$addon_name = isset($_POST['addon']) ? wpshop_tools::varSanitizer($_POST['addon']) : null;
1833 1833
 		$state = true;
1834 1834
 
1835
-		if ( !empty($addon_name) ) {
1835
+		if (!empty($addon_name)) {
1836 1836
 			$addons_list = array_keys(unserialize(WPSHOP_ADDONS_LIST));
1837 1837
 			if (in_array($addon_name, $addons_list)) {
1838 1838
 				$extra_options = get_option(WPSHOP_ADDONS_OPTION_NAME, array());
1839 1839
 				$extra_options[$addon_name]['activate'] = false;
1840 1840
 				$extra_options[$addon_name]['deactivation_date'] = current_time('mysql', 0);
1841
-				if ( update_option(WPSHOP_ADDONS_OPTION_NAME, $extra_options) ) {
1842
-					$result = array(true, __('The addon has been desactivated successfully', 'wpshop'), __('Desactivated','wpshop'));
1841
+				if (update_option(WPSHOP_ADDONS_OPTION_NAME, $extra_options)) {
1842
+					$result = array(true, __('The addon has been desactivated successfully', 'wpshop'), __('Desactivated', 'wpshop'));
1843 1843
 					$state = false;
1844 1844
 				}
1845 1845
 				else {
1846
-					$result = array(false, __('An error occured','wpshop'), __('Activated','wpshop'));
1846
+					$result = array(false, __('An error occured', 'wpshop'), __('Activated', 'wpshop'));
1847 1847
 				}
1848 1848
 			}
1849 1849
 			else {
1850
-				$result = array(false, __('The addon to desactivate is invalid', 'wpshop'), __('Activated','wpshop'));
1850
+				$result = array(false, __('The addon to desactivate is invalid', 'wpshop'), __('Activated', 'wpshop'));
1851 1851
 			}
1852 1852
 		}
1853 1853
 		$activated_class = unserialize(WPSHOP_ADDONS_STATES_CLASS);
@@ -1861,39 +1861,39 @@  discard block
 block discarded – undo
1861 1861
 	 * Display opttions for including user address into account form
1862 1862
 	 */
1863 1863
 	function ajax_integrate_billing_into_register() {
1864
-		check_ajax_referer( 'wpshop_ajax_integrate_billin_into_register', 'wpshop_ajax_nonce' );
1864
+		check_ajax_referer('wpshop_ajax_integrate_billin_into_register', 'wpshop_ajax_nonce');
1865 1865
 		global $wpshop_account;
1866 1866
 		$wpshop_billing_address = get_option('wpshop_billing_address');
1867 1867
 		$current_billing_address = isset($_POST['current_billing_address']) ? intval(wpshop_tools::varSanitizer($_POST['current_billing_address'])) : null;
1868 1868
 		$selected_field = isset($_POST['selected_field']) ? wpshop_tools::varSanitizer($_POST['selected_field']) : null;
1869
-		$attribute = !empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : array();
1870
-		$billing_form_fields = wps_address::get_addresss_form_fields_by_type ( $current_billing_address );
1869
+		$attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array();
1870
+		$billing_form_fields = wps_address::get_addresss_form_fields_by_type($current_billing_address);
1871 1871
 		$possible_values_for_billing = array('' => __('No corresponding field', 'wpshop'));
1872
-		foreach ( $billing_form_fields[$current_billing_address] as $attribute_group_id => $attribute_group_detail) {
1873
-			foreach ( $attribute_group_detail['content'] as $attribute_build_code => $attribute_definition) {
1872
+		foreach ($billing_form_fields[$current_billing_address] as $attribute_group_id => $attribute_group_detail) {
1873
+			foreach ($attribute_group_detail['content'] as $attribute_build_code => $attribute_definition) {
1874 1874
 				$possible_values_for_billing[$attribute_build_code] = $attribute_definition['label'];
1875 1875
 			}
1876 1876
 		}
1877
-		$attributes_set = wpshop_attributes_set::getElement( 'yes', "'valid'", 'is_default', '', wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS));
1877
+		$attributes_set = wpshop_attributes_set::getElement('yes', "'valid'", 'is_default', '', wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS));
1878 1878
 		/*	Get the attribute set details in order to build the product interface	*/
1879
-		$productAttributeSetDetails = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'");
1880
-		if(!empty($productAttributeSetDetails)){
1881
-			foreach($productAttributeSetDetails as $productAttributeSetDetail){
1882
-				if(count($productAttributeSetDetail['attribut']) >= 1){
1883
-					foreach($productAttributeSetDetail['attribut'] as $attribute) {
1884
-						if(!empty($attribute->id)) {
1885
-							$submitOrderInfos = !empty( $_POST['submitOrderInfos'] ) ? (int) $_POST['submitOrderInfos'] : 0;
1886
-							if( !empty($submitOrderInfos) ) {
1879
+		$productAttributeSetDetails = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
1880
+		if (!empty($productAttributeSetDetails)) {
1881
+			foreach ($productAttributeSetDetails as $productAttributeSetDetail) {
1882
+				if (count($productAttributeSetDetail['attribut']) >= 1) {
1883
+					foreach ($productAttributeSetDetail['attribut'] as $attribute) {
1884
+						if (!empty($attribute->id)) {
1885
+							$submitOrderInfos = !empty($_POST['submitOrderInfos']) ? (int)$_POST['submitOrderInfos'] : 0;
1886
+							if (!empty($submitOrderInfos)) {
1887 1887
 								$value = $attribute[$attribute->data_type][$attribute->code];
1888 1888
 							}
1889 1889
 							else {
1890 1890
 								$value = '';
1891
-								if ( $attribute->code != 'user_pass') {
1891
+								if ($attribute->code != 'user_pass') {
1892 1892
 									$code = $attribute->code;
1893 1893
 									$value = $user->$code;
1894 1894
 								}
1895 1895
 							}
1896
-							$attribute_output_def = wpshop_attributes::get_attribute_field_definition( $attribute, $value, array() );
1896
+							$attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute, $value, array());
1897 1897
 							$account_form_field[$attribute->code] = $attribute_output_def;
1898 1898
 						}
1899 1899
 					}
@@ -1903,7 +1903,7 @@  discard block
 block discarded – undo
1903 1903
 
1904 1904
 		$possible_values = array();
1905 1905
 		$matching_field = '';
1906
-		foreach ( $account_form_field as $attribute_code => $attribute_detail) {
1906
+		foreach ($account_form_field as $attribute_code => $attribute_detail) {
1907 1907
 			$possible_values[$attribute_code] = $attribute_detail['label'];
1908 1908
 
1909 1909
 			$input_def['name'] = 'wpshop_billing_address[integrate_into_register_form_matching_field][' . $attribute_code . ']';
@@ -1935,13 +1935,13 @@  discard block
 block discarded – undo
1935 1935
 	 * Search element in database for shortcode insertion interface
1936 1936
 	 */
1937 1937
 	function ajax_wpshop_element_search() {
1938
-		check_ajax_referer( 'wpshop_element_search', 'wpshop_ajax_nonce' );
1938
+		check_ajax_referer('wpshop_element_search', 'wpshop_ajax_nonce');
1939 1939
 
1940 1940
 		$wpshop_element_searched = isset($_REQUEST['wpshop_element_searched']) ? wpshop_tools::varSanitizer($_REQUEST['wpshop_element_searched']) : null;
1941 1941
 		$wpshop_element_type = isset($_REQUEST['wpshop_element_type']) ? wpshop_tools::varSanitizer($_REQUEST['wpshop_element_type']) : null;
1942 1942
 		$wpshop_format_result = isset($_REQUEST['wpshop_format_result']) ? (bool)wpshop_tools::varSanitizer($_REQUEST['wpshop_format_result']) : true;
1943 1943
 
1944
-		switch ( $wpshop_element_type ) {
1944
+		switch ($wpshop_element_type) {
1945 1945
 			case 'product':
1946 1946
 			case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
1947 1947
 				$data = wpshop_products::product_list($wpshop_format_result, $wpshop_element_searched);
@@ -1951,18 +1951,18 @@  discard block
 block discarded – undo
1951 1951
 				break;
1952 1952
 			case WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS:
1953 1953
 				$wps_provider_ctr = new wps_provider_ctr();
1954
-				$data = $wps_provider_ctr->read( array( 's' => $wpshop_element_searched ) );
1954
+				$data = $wps_provider_ctr->read(array('s' => $wpshop_element_searched));
1955 1955
 				break;
1956 1956
 		}
1957 1957
 
1958
-		if ( $wpshop_format_result ) {
1958
+		if ($wpshop_format_result) {
1959 1959
 			$data = empty($data) ? __('No match', 'wpshop') : $data;
1960 1960
 		}
1961 1961
 		else {
1962
-			if ( !empty($data) ) {
1962
+			if (!empty($data)) {
1963 1963
 				$temp_data = $data;
1964
-				unset( $data );
1965
-				foreach ( $temp_data as $post) {
1964
+				unset($data);
1965
+				foreach ($temp_data as $post) {
1966 1966
 					$data[$post->ID] = $post->ID . ' - ' . $post->post_title;
1967 1967
 				}
1968 1968
 			}
@@ -1983,35 +1983,35 @@  discard block
 block discarded – undo
1983 1983
 	 * Add product to the end user cart
1984 1984
 	 */
1985 1985
 	function ajax_wpshop_add_to_cart() {
1986
-		check_ajax_referer( 'ajax_pos_product_variation_selection' );
1986
+		check_ajax_referer('ajax_pos_product_variation_selection');
1987 1987
 
1988 1988
 		global $wpdb;
1989 1989
 		$wpshop_cart = new wps_cart();
1990 1990
 
1991 1991
 		$product_id = isset($_POST['wpshop_pdt']) ? intval(wpshop_tools::varSanitizer($_POST['wpshop_pdt'])) : null;
1992 1992
 		$product_qty = isset($_POST['wpshop_pdt_qty']) ? intval(wpshop_tools::varSanitizer($_POST['wpshop_pdt_qty'])) : 1;
1993
-		$cart_option = get_option('wpshop_cart_option', array() );
1993
+		$cart_option = get_option('wpshop_cart_option', array());
1994 1994
 		$wpshop_variation_selected = !empty($_POST['wps_pdt_variations']) ? (array)$_POST['wps_pdt_variations'] : array();
1995
-		$from_administration =  ( !empty($_POST['from_admin']) ) ? (int)$_POST['from_admin'] : false;
1996
-		$order_id =  ( !empty($_POST['wps_orders_order_id']) ) ? wpshop_tools::varSanitizer( $_POST['wps_orders_order_id'] ) : null;
1995
+		$from_administration = (!empty($_POST['from_admin'])) ? (int)$_POST['from_admin'] : false;
1996
+		$order_id = (!empty($_POST['wps_orders_order_id'])) ? wpshop_tools::varSanitizer($_POST['wps_orders_order_id']) : null;
1997 1997
 
1998 1998
 
1999 1999
 		// Check Cart Animation
2000
-		$cart_animation_choice = ( !empty($cart_option) && !empty($cart_option['animation_cart_type']) ? $cart_option['animation_cart_type'] : null);
2001
-		if ( !empty($cart_option['total_nb_of_item_allowed']) && ((int) $cart_option['total_nb_of_item_allowed'][0] == 1) ) {
2000
+		$cart_animation_choice = (!empty($cart_option) && !empty($cart_option['animation_cart_type']) ? $cart_option['animation_cart_type'] : null);
2001
+		if (!empty($cart_option['total_nb_of_item_allowed']) && ((int)$cart_option['total_nb_of_item_allowed'][0] == 1)) {
2002 2002
 			$wpshop_cart->empty_cart();
2003 2003
 		}
2004 2004
 
2005 2005
 		// Prepare Product to be added to cart
2006
-		$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected );
2006
+		$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected);
2007 2007
 		$product_to_add_to_cart = $formatted_product[0];
2008 2008
 		$new_pid = $formatted_product[1];
2009 2009
 
2010 2010
 		// Check cart Type
2011 2011
 		$cart_type_for_adding = 'normal';
2012
-		$wpshop_cart_type = !empty( $_POST['wpshop_cart_type'] ) ? sanitize_text_field( $_POST['wpshop_cart_type'] ) : '';
2013
-		if (!empty($wpshop_cart_type) ) {
2014
-			switch(wpshop_tools::varSanitizer($wpshop_cart_type)){
2012
+		$wpshop_cart_type = !empty($_POST['wpshop_cart_type']) ? sanitize_text_field($_POST['wpshop_cart_type']) : '';
2013
+		if (!empty($wpshop_cart_type)) {
2014
+			switch (wpshop_tools::varSanitizer($wpshop_cart_type)) {
2015 2015
 				case 'quotation':
2016 2016
 					$wpshop_cart_type = 'quotation';
2017 2017
 					break;
@@ -2022,43 +2022,43 @@  discard block
 block discarded – undo
2022 2022
 		}
2023 2023
 
2024 2024
 		// Check Product image
2025
-		$product = get_post( $product_id );
2026
-		$product_img = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="no picture" />';
2027
-		if ( !empty($product_id) ) {
2028
-			if ( $product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
2029
-				$parent_def = wpshop_products::get_parent_variation( $product_id );
2030
-				$parent_post = ( !empty($parent_def['parent_post']) ) ? $parent_def['parent_post'] : array();
2031
-				$product_title = ( !empty($parent_post) && !empty($parent_post->post_title) ) ? $parent_post->post_title : '';
2032
-				$product_description = ( !empty($parent_post) && !empty($parent_post->post_content) ) ? $parent_post->post_content : '';
2033
-				$product_img =  ( !empty($parent_post->ID) ) ? get_the_post_thumbnail( $parent_post->ID, 'thumbnail') : '';
2025
+		$product = get_post($product_id);
2026
+		$product_img = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="no picture" />';
2027
+		if (!empty($product_id)) {
2028
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2029
+				$parent_def = wpshop_products::get_parent_variation($product_id);
2030
+				$parent_post = (!empty($parent_def['parent_post'])) ? $parent_def['parent_post'] : array();
2031
+				$product_title = (!empty($parent_post) && !empty($parent_post->post_title)) ? $parent_post->post_title : '';
2032
+				$product_description = (!empty($parent_post) && !empty($parent_post->post_content)) ? $parent_post->post_content : '';
2033
+				$product_img = (!empty($parent_post->ID)) ? get_the_post_thumbnail($parent_post->ID, 'thumbnail') : '';
2034 2034
 			}
2035 2035
 			else {
2036 2036
 				$product_title = $product->post_title;
2037 2037
 				$product_description = $product->post_content;
2038
-				$product_img =  get_the_post_thumbnail( $product_id, 'thumbnail');
2038
+				$product_img = get_the_post_thumbnail($product_id, 'thumbnail');
2039 2039
 			}
2040 2040
 		}
2041 2041
 
2042
-		$wps_orders_from_admin = !empty( $_POST['wps_orders_from_admin'] ) ? (int) $_POST['wps_orders_from_admin'] : 0;
2043
-		if ( !empty($wps_orders_from_admin) && $wps_orders_from_admin) {
2042
+		$wps_orders_from_admin = !empty($_POST['wps_orders_from_admin']) ? (int)$_POST['wps_orders_from_admin'] : 0;
2043
+		if (!empty($wps_orders_from_admin) && $wps_orders_from_admin) {
2044 2044
 			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
2045
-			$return = $wpshop_cart->add_to_cart( $product_to_add_to_cart, array( $new_pid => $product_qty ), $wpshop_cart_type, array(), true, $order_meta, $order_id );
2045
+			$return = $wpshop_cart->add_to_cart($product_to_add_to_cart, array($new_pid => $product_qty), $wpshop_cart_type, array(), true, $order_meta, $order_id);
2046 2046
 
2047
-			echo json_encode( array(true) );
2047
+			echo json_encode(array(true));
2048 2048
 			die();
2049 2049
 		}
2050 2050
 		else {
2051
-			$return = $wpshop_cart->add_to_cart( $product_to_add_to_cart, array( $new_pid => $product_qty ), $wpshop_cart_type );
2051
+			$return = $wpshop_cart->add_to_cart($product_to_add_to_cart, array($new_pid => $product_qty), $wpshop_cart_type);
2052 2052
 		}
2053 2053
 
2054
-		if ( $return == 'success' ) {
2055
-			$cart_page_url = apply_filters( 'wps_cart_page_url', get_permalink( wpshop_tools::get_page_id( get_option( 'wpshop_cart_page_id' ) ) ) );
2054
+		if ($return == 'success') {
2055
+			$cart_page_url = apply_filters('wps_cart_page_url', get_permalink(wpshop_tools::get_page_id(get_option('wpshop_cart_page_id'))));
2056 2056
 			/** Template parameters	*/
2057 2057
 			$template_part = 'product_added_to_cart_message';
2058 2058
 
2059 2059
 			/** Build template	*/
2060 2060
 			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2061
-			if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
2061
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2062 2062
 				/*	Include the old way template part	*/
2063 2063
 				ob_start();
2064 2064
 				require_once(wpshop_display::get_template_file($tpl_way_to_take[1]));
@@ -2077,14 +2077,14 @@  discard block
 block discarded – undo
2077 2077
 
2078 2078
 			/** Product Price **/
2079 2079
 			$product_price = '';
2080
-			if ( !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($product_to_add_to_cart) ) {
2080
+			if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($product_to_add_to_cart)) {
2081 2081
 				$idp = '';
2082 2082
 
2083
-				if ( !empty($product_to_add_to_cart[$new_pid]['variations']) && count($product_to_add_to_cart[$new_pid]['variations']) < 2 ) {
2083
+				if (!empty($product_to_add_to_cart[$new_pid]['variations']) && count($product_to_add_to_cart[$new_pid]['variations']) < 2) {
2084 2084
 					$idp = $product_to_add_to_cart[$new_pid]['variations'][0];
2085 2085
 				}
2086 2086
 				else {
2087
-					if( strstr( $new_pid, '__') ) {
2087
+					if (strstr($new_pid, '__')) {
2088 2088
 						$idp = $new_pid;
2089 2089
 					}
2090 2090
 					else {
@@ -2092,43 +2092,43 @@  discard block
 block discarded – undo
2092 2092
 					}
2093 2093
 				}
2094 2094
 
2095
-				if( !empty($idp) ) {
2096
-					$default_currency = wpshop_tools::wpshop_get_currency( false );
2097
-					$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
2095
+				if (!empty($idp)) {
2096
+					$default_currency = wpshop_tools::wpshop_get_currency(false);
2097
+					$price_piloting_option = get_option('wpshop_shop_price_piloting');
2098 2098
 
2099 2099
 					$real_price = null;
2100
-					if ( !empty( $_SESSION[ 'cart' ] ) && !empty( $_SESSION[ 'cart' ][ 'order_items' ] ) && !empty( $_SESSION[ 'cart' ][ 'order_items' ][$new_pid] ) && !empty( $_SESSION[ 'cart' ][ 'order_items' ][$new_pid]['item_amount_to_pay_now'] ) ) {
2101
-						$real_price = ( $_SESSION['cart']['order_items'][$new_pid]['item_amount_to_pay_now'] * $product_qty );
2100
+					if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($_SESSION['cart']['order_items'][$new_pid]) && !empty($_SESSION['cart']['order_items'][$new_pid]['item_amount_to_pay_now'])) {
2101
+						$real_price = ($_SESSION['cart']['order_items'][$new_pid]['item_amount_to_pay_now'] * $product_qty);
2102 2102
 					}
2103 2103
 
2104
-					$pr = empty( $real_price ) ? ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? ( $_SESSION['cart']['order_items'][$new_pid]['item_pu_ht']  * $product_qty ) : ( $_SESSION['cart']['order_items'][$new_pid]['item_pu_ttc'] * $product_qty ) : $real_price;
2105
-					$product_price = wpshop_tools::formate_number( $pr ).$default_currency;
2104
+					$pr = empty($real_price) ? (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? ($_SESSION['cart']['order_items'][$new_pid]['item_pu_ht'] * $product_qty) : ($_SESSION['cart']['order_items'][$new_pid]['item_pu_ttc'] * $product_qty) : $real_price;
2105
+					$product_price = wpshop_tools::formate_number($pr) . $default_currency;
2106 2106
 				}
2107 2107
 			}
2108 2108
 			/** Check if there are linked products **/
2109
-			$related_products = get_post_meta( $product_id, '_wpshop_product_related_products', true);
2109
+			$related_products = get_post_meta($product_id, '_wpshop_product_related_products', true);
2110 2110
 			$tpl_component = array();
2111 2111
 			$linked_products = '';
2112
-			if ( !empty($related_products) ) {
2112
+			if (!empty($related_products)) {
2113 2113
 				// $linked_products = '<h2>'.__('Linked products', 'wpshop').'</h2>';
2114
-				$linked_products .= '<div class="modal_product_related">' .do_shortcode( '[wpshop_related_products pid="' .$product_id. '" sorting="no"]' ).'</div>';
2114
+				$linked_products .= '<div class="modal_product_related">' . do_shortcode('[wpshop_related_products pid="' . $product_id . '" sorting="no"]') . '</div>';
2115 2115
 			}
2116 2116
 			else {
2117 2117
 				$linked_products = '';
2118 2118
 			}
2119 2119
 
2120
-			$message_confirmation = sprintf( __('%s has been add to the cart', 'wpshop'), $product->post_title );
2120
+			$message_confirmation = sprintf(__('%s has been add to the cart', 'wpshop'), $product->post_title);
2121 2121
 
2122
-			$modal_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal', array( 'RELATED_PRODUCTS' => $linked_products , 'PRODUCT_PICTURE' => $product_img, 'PRODUCT_TITLE' => $product_title, 'PRODUCT_PRICE' => $product_price, 'PRODUCT_DESCRIPTION' => $product_description) );
2123
-			$modal_footer_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal_footer', array( 'LINK_CART_PAGE' => wpshop_tools::get_page_id( get_permalink( get_option('wpshop_cart_page_id') ) ) ) );
2122
+			$modal_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal', array('RELATED_PRODUCTS' => $linked_products, 'PRODUCT_PICTURE' => $product_img, 'PRODUCT_TITLE' => $product_title, 'PRODUCT_PRICE' => $product_price, 'PRODUCT_DESCRIPTION' => $product_description));
2123
+			$modal_footer_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal_footer', array('LINK_CART_PAGE' => wpshop_tools::get_page_id(get_permalink(get_option('wpshop_cart_page_id')))));
2124 2124
 
2125
-			$response = array( true, $succes_message_box, $action_after_add, $cart_page_url, $product_id, array($cart_animation_choice, $message_confirmation), array($product_img, $product_title, $linked_products, $product_price), $modal_content, $modal_footer_content );
2125
+			$response = array(true, $succes_message_box, $action_after_add, $cart_page_url, $product_id, array($cart_animation_choice, $message_confirmation), array($product_img, $product_title, $linked_products, $product_price), $modal_content, $modal_footer_content);
2126 2126
 		}
2127 2127
 		else {
2128
-			$response = array( false, $return );
2128
+			$response = array(false, $return);
2129 2129
 		}
2130 2130
 
2131
-		wp_die( json_encode( $response ) );
2131
+		wp_die(json_encode($response));
2132 2132
 	}
2133 2133
  	add_action('wp_ajax_wpshop_add_product_to_cart', 'ajax_wpshop_add_to_cart');
2134 2134
 	add_action('wp_ajax_nopriv_wpshop_add_product_to_cart', 'ajax_wpshop_add_to_cart');
@@ -2138,45 +2138,45 @@  discard block
 block discarded – undo
2138 2138
 	 * Set product qty into customer cart
2139 2139
 	 */
2140 2140
 	function ajax_wpshop_set_qty_for_product_into_cart() {
2141
-		check_ajax_referer( 'ajax_wpshop_set_qty_for_product_into_cart' );
2141
+		check_ajax_referer('ajax_wpshop_set_qty_for_product_into_cart');
2142 2142
 		$response = array();
2143 2143
 		$wpshop_cart = new wps_cart();
2144 2144
 		$product_id = isset($_POST['product_id']) ? wpshop_tools::varSanitizer($_POST['product_id']) : null;
2145 2145
 		$product_qty = isset($_POST['product_qty']) ? intval(wpshop_tools::varSanitizer($_POST['product_qty'])) : null;
2146 2146
 
2147 2147
 		$pid = $product_id;
2148
-		if (strpos($product_id,'__') !== false) {
2148
+		if (strpos($product_id, '__') !== false) {
2149 2149
 			//$pid = $_SESSION['cart']['order_items'][$product_id]['item_id'];
2150
-			foreach( $_SESSION['cart']['order_items'][$product_id]['item_meta']['variations'] as $variation ) {
2150
+			foreach ($_SESSION['cart']['order_items'][$product_id]['item_meta']['variations'] as $variation) {
2151 2151
 				$pid = $variation['product_id'];
2152 2152
 				break;
2153 2153
 			}
2154 2154
 		}
2155 2155
 
2156
-		$global_discount = !empty( $_POST['global_discount'] ) ? (int) $_POST['global_discount'] : 0;
2157
-		if ( !empty($global_discount) ) {
2156
+		$global_discount = !empty($_POST['global_discount']) ? (int)$_POST['global_discount'] : 0;
2157
+		if (!empty($global_discount)) {
2158 2158
 			$_SESSION['cart']['pos_global_discount'] = $global_discount;
2159 2159
 		}
2160 2160
 
2161 2161
 		if (!empty($product_id)) {
2162 2162
 			if (isset($product_qty)) {
2163
-				if ( $product_qty == 0 ) {
2164
-					$variation_of_product = query_posts( array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $pid, 'posts_per_page' => -1) );
2165
-					if ( !empty($variation_of_product) ) {
2166
-						foreach ( $variation_of_product as $p_id) {
2163
+				if ($product_qty == 0) {
2164
+					$variation_of_product = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $pid, 'posts_per_page' => -1));
2165
+					if (!empty($variation_of_product)) {
2166
+						foreach ($variation_of_product as $p_id) {
2167 2167
 							$wpshop_cart->set_product_qty($p_id->ID, $product_qty);
2168 2168
 						}
2169 2169
 					}
2170 2170
 				}
2171
-				$return = $wpshop_cart->set_product_qty( $product_id, $product_qty, $pid );
2171
+				$return = $wpshop_cart->set_product_qty($product_id, $product_qty, $pid);
2172 2172
 				$response[] = $return;
2173 2173
 			}
2174 2174
 			else {
2175 2175
 				$response[] = false;
2176
-				$response[] = __('Parameters error.','wpshop');
2176
+				$response[] = __('Parameters error.', 'wpshop');
2177 2177
 			}
2178 2178
 		}
2179
-		wp_die( json_encode( $response ) );
2179
+		wp_die(json_encode($response));
2180 2180
 	}
2181 2181
 	add_action('wp_ajax_wpshop_set_qtyfor_product_into_cart', 'ajax_wpshop_set_qty_for_product_into_cart');
2182 2182
 	add_action('wp_ajax_nopriv_wpshop_set_qtyfor_product_into_cart', 'ajax_wpshop_set_qty_for_product_into_cart');
@@ -2185,7 +2185,7 @@  discard block
 block discarded – undo
2185 2185
 	 * Display cart after doing an action on it
2186 2186
 	 */
2187 2187
 	function ajax_wpshop_display_cart() {
2188
-		check_ajax_referer( 'ajax_wpshop_display_cart' );
2188
+		check_ajax_referer('ajax_wpshop_display_cart');
2189 2189
 		ini_set('display_errors', true);
2190 2190
 		error_reporting(E_ALL);
2191 2191
 		$wps_cart_ctr = new wps_cart();
@@ -2199,8 +2199,8 @@  discard block
 block discarded – undo
2199 2199
 	/**
2200 2200
 	 * Display mini cart widgte after doing an action on it
2201 2201
 	 */
2202
-	function ajax_wpshop_reload_mini_cart(){
2203
-		check_ajax_referer( 'ajax_wpshop_display_cart' );
2202
+	function ajax_wpshop_reload_mini_cart() {
2203
+		check_ajax_referer('ajax_wpshop_display_cart');
2204 2204
 		echo wpshop_cart::mini_cart_content();
2205 2205
 		die();
2206 2206
 	}
@@ -2211,16 +2211,16 @@  discard block
 block discarded – undo
2211 2211
 	 * Refresh Price in complete product sheet and Cart summary display
2212 2212
 	 */
2213 2213
 	function wpshop_ajax_wpshop_variation_selection() {
2214
-		check_ajax_referer( 'wpshop_ajax_wpshop_variation_selection' );
2214
+		check_ajax_referer('wpshop_ajax_wpshop_variation_selection');
2215 2215
 		$product_id = isset($_POST['wpshop_pdt']) ? intval(wpshop_tools::varSanitizer($_POST['wpshop_pdt'])) : null;
2216 2216
 		$wpshop_variation_selected = isset($_POST['wpshop_variation']) ? (array)$_POST['wpshop_variation'] : null;
2217 2217
 		$wpshop_free_variation = isset($_POST['wpshop_free_variation']) ? (array)$_POST['wpshop_free_variation'] : null;
2218
-		$wpshop_current_for_display = isset($_POST['wpshop_current_for_display']) ? sanitize_text_field( $_POST['wpshop_current_for_display'] ) : null;
2218
+		$wpshop_current_for_display = isset($_POST['wpshop_current_for_display']) ? sanitize_text_field($_POST['wpshop_current_for_display']) : null;
2219 2219
 		$product_qty = isset($_POST['product_qty']) ? (int)$_POST['product_qty'] : 1;
2220 2220
 
2221
-		$product_variation_summary = wpshop_products::wpshop_ajax_wpshop_variation_selection( $product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty );
2221
+		$product_variation_summary = wpshop_products::wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty);
2222 2222
 
2223
-		wp_die( json_encode( $product_variation_summary ) );
2223
+		wp_die(json_encode($product_variation_summary));
2224 2224
 	}
2225 2225
 	add_action('wp_ajax_wpshop_variation_selection', 'wpshop_ajax_wpshop_variation_selection');
2226 2226
 	add_action('wp_ajax_nopriv_wpshop_variation_selection', 'wpshop_ajax_wpshop_variation_selection');
@@ -2230,23 +2230,23 @@  discard block
 block discarded – undo
2230 2230
 	function wpshop_ajax_variation_selection_show_detail_for_value() {
2231 2231
 		global $wpdb;
2232 2232
 
2233
-		check_ajax_referer( 'wpshop_ajax_wpshop_variation_selection' );
2233
+		check_ajax_referer('wpshop_ajax_wpshop_variation_selection');
2234 2234
 
2235 2235
 		$display = '';
2236 2236
 		$attribute_for_detail = isset($_POST['attribute_for_detail']) ? (array)$_POST['attribute_for_detail'] : array();
2237 2237
 
2238
-		if ( !empty( $attribute_for_detail ) ) {
2238
+		if (!empty($attribute_for_detail)) {
2239 2239
 			$selection = array();
2240
-			foreach ( $attribute_for_detail as $selected_variation ) {
2240
+			foreach ($attribute_for_detail as $selected_variation) {
2241 2241
 				$variation_definition = explode('-_variation_val_-', $selected_variation);
2242 2242
 				$attribute_definition = wpshop_attributes::getElement($variation_definition[0], "'valid'", 'code');
2243 2243
 				$post_definition = get_post($variation_definition[1]);
2244 2244
 
2245
-				if ( !empty($post_definition) ) {
2246
-					$post_content = ( !empty($post_definition) && !empty($post_definition->post_content) ) ? $post_definition->post_content : '';
2247
-					if ( empty($post_content) && !empty($post_definition->post_parent) ) {
2245
+				if (!empty($post_definition)) {
2246
+					$post_content = (!empty($post_definition) && !empty($post_definition->post_content)) ? $post_definition->post_content : '';
2247
+					if (empty($post_content) && !empty($post_definition->post_parent)) {
2248 2248
 						$post_parent_definition = get_post($post_definition->post_parent);
2249
-						if ( !empty($post_parent_definition) ) {
2249
+						if (!empty($post_parent_definition)) {
2250 2250
 							$post_content = $post_parent_definition->post_content;
2251 2251
 						}
2252 2252
 					}
@@ -2273,74 +2273,74 @@  discard block
 block discarded – undo
2273 2273
 	 * Save customer account informations
2274 2274
 	 */
2275 2275
 	function wpshop_ajax_save_customer_account() {
2276
-		check_ajax_referer( 'wpshop_customer_register', 'wpshop_ajax_nonce' );
2276
+		check_ajax_referer('wpshop_customer_register', 'wpshop_ajax_nonce');
2277 2277
 		global $wpshop, $wpshop_account, $wpdb;
2278
-		$reponse='';
2278
+		$reponse = '';
2279 2279
 		$status = false;
2280 2280
 		$validate = true;
2281 2281
 
2282
-		$attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : array();
2282
+		$attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array();
2283 2283
 
2284 2284
 		$user_id = get_current_user_id();
2285
-		$current_connected_user = !empty( $user_id ) ? $user_id : null;
2285
+		$current_connected_user = !empty($user_id) ? $user_id : null;
2286 2286
 		$wpshop_billing_address = get_option('wpshop_billing_address');
2287
-		if ( !empty($wpshop_billing_address['integrate_into_register_form']) && ($wpshop_billing_address['integrate_into_register_form'] == 'yes') && isset($attribute[$wpshop_billing_address['choice']]) ) {
2288
-			if ( !empty($wpshop_billing_address['integrate_into_register_form_matching_field']) ) {
2289
-				$address_fields = wps_address::get_addresss_form_fields_by_type ( $wpshop_billing_address['choice'] );
2287
+		if (!empty($wpshop_billing_address['integrate_into_register_form']) && ($wpshop_billing_address['integrate_into_register_form'] == 'yes') && isset($attribute[$wpshop_billing_address['choice']])) {
2288
+			if (!empty($wpshop_billing_address['integrate_into_register_form_matching_field'])) {
2289
+				$address_fields = wps_address::get_addresss_form_fields_by_type($wpshop_billing_address['choice']);
2290 2290
 				$address_field = $address_fields[$wpshop_billing_address['choice']];
2291 2291
 				$temp_aray_for_matching = array_flip($wpshop_billing_address['integrate_into_register_form_matching_field']);
2292
-				foreach ( $address_field as $group_id => $group_detail) {
2293
-					foreach ( $group_detail['content'] as $attribute_build_code => $attribute_def) {
2294
-						if ( in_array($attribute_build_code, $wpshop_billing_address['integrate_into_register_form_matching_field']) && empty( $attribute[$wpshop_billing_address['choice']][$attribute_def['data_type']][$attribute_def['name']] ) && !empty(  $attribute[$attribute_def['data_type']][$temp_aray_for_matching[$attribute_build_code]] ) ) {
2292
+				foreach ($address_field as $group_id => $group_detail) {
2293
+					foreach ($group_detail['content'] as $attribute_build_code => $attribute_def) {
2294
+						if (in_array($attribute_build_code, $wpshop_billing_address['integrate_into_register_form_matching_field']) && empty($attribute[$wpshop_billing_address['choice']][$attribute_def['data_type']][$attribute_def['name']]) && !empty($attribute[$attribute_def['data_type']][$temp_aray_for_matching[$attribute_build_code]])) {
2295 2295
 							$attribute[$wpshop_billing_address['choice']][$attribute_def['data_type']][$attribute_def['name']] = $attribute[$attribute_def['data_type']][$temp_aray_for_matching[$attribute_build_code]];
2296
-							if ( $attribute_def['_need_verification'] == 'yes' && !empty($attribute[$wpshop_billing_address['choice']][$attribute_def['data_type']][$attribute_def['name'] . '2']) ) {
2296
+							if ($attribute_def['_need_verification'] == 'yes' && !empty($attribute[$wpshop_billing_address['choice']][$attribute_def['data_type']][$attribute_def['name'] . '2'])) {
2297 2297
 								$attribute[$wpshop_billing_address['choice']][$attribute_def['data_type']][$attribute_def['name'] . '2'] = $attribute[$attribute_def['data_type']][$temp_aray_for_matching[$attribute_build_code] . '2'];
2298 2298
 							}
2299 2299
 						}
2300 2300
 					}
2301 2301
 				}
2302
-				$attribute[$wpshop_billing_address['choice']]['varchar']['address_title'] = !empty( $attribute[$wpshop_billing_address['choice']]['varchar']['address_title'] ) ? $attribute[$wpshop_billing_address['choice']]['varchar']['address_title'] : __('Billing address', 'wpshop');
2302
+				$attribute[$wpshop_billing_address['choice']]['varchar']['address_title'] = !empty($attribute[$wpshop_billing_address['choice']]['varchar']['address_title']) ? $attribute[$wpshop_billing_address['choice']]['varchar']['address_title'] : __('Billing address', 'wpshop');
2303 2303
 			}
2304 2304
 			$group = wps_address::get_addresss_form_fields_by_type($wpshop_billing_address['choice']);
2305 2305
 			$validate = false;
2306
-			foreach ( $group as $attribute_sets ) {
2307
-				foreach ( $attribute_sets as $attribute_set_field ) {
2306
+			foreach ($group as $attribute_sets) {
2307
+				foreach ($attribute_sets as $attribute_set_field) {
2308 2308
 					$validate = $wpshop->validateForm($attribute_set_field['content'], $attribute[$wpshop_billing_address['choice']], '');
2309 2309
 				}
2310 2310
 			}
2311 2311
 		}
2312
-		$cart_url = !empty($_SESSION['cart']['order_items']) ? get_permalink(wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') )) : get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')));
2312
+		$cart_url = !empty($_SESSION['cart']['order_items']) ? get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) : get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')));
2313 2313
 
2314
-		$account_form_type = !empty( $_POST['account_form_type'] ) ? sanitize_text_field( $_POST['account_form_type'] ) : '';
2315
-		$validate_personal_form_infos = ( !empty( $account_form_type ) && $account_form_type == 'partial' ) ? $wpshop->validateForm($wpshop_account->partial_personal_infos_fields, array(), '', true) : $wpshop->validateForm($wpshop_account->personal_info_fields);
2316
-		if( $validate && $validate_personal_form_infos ) {
2317
-			$account_creation_result = $wpshop_account->save_account_form($user_id,  ( ( !empty($account_form_type) && $account_form_type == 'partial' ) ? 'partial' : 'complete') );
2314
+		$account_form_type = !empty($_POST['account_form_type']) ? sanitize_text_field($_POST['account_form_type']) : '';
2315
+		$validate_personal_form_infos = (!empty($account_form_type) && $account_form_type == 'partial') ? $wpshop->validateForm($wpshop_account->partial_personal_infos_fields, array(), '', true) : $wpshop->validateForm($wpshop_account->personal_info_fields);
2316
+		if ($validate && $validate_personal_form_infos) {
2317
+			$account_creation_result = $wpshop_account->save_account_form($user_id, ((!empty($account_form_type) && $account_form_type == 'partial') ? 'partial' : 'complete'));
2318 2318
 			$status = $account_creation_result[0];
2319 2319
 			$user_id = $account_creation_result[1];
2320
-			$is_partial_account_creation  = $account_creation_result[2];
2321
-			if ( $is_partial_account_creation == 'partial' ) {
2320
+			$is_partial_account_creation = $account_creation_result[2];
2321
+			if ($is_partial_account_creation == 'partial') {
2322 2322
 				$permalink_option = get_option('permalink_structure');
2323
-				if ( !empty($permalink_option) ) {
2324
-					$cart_url = get_permalink( wpshop_tools::get_page_id( get_option('wpshop_signup_page_id') ) ).'?complete_sign_up=ok';
2323
+				if (!empty($permalink_option)) {
2324
+					$cart_url = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_signup_page_id'))) . '?complete_sign_up=ok';
2325 2325
 				}
2326 2326
 				else {
2327
-					$cart_url = get_permalink( wpshop_tools::get_page_id(get_option('wpshop_signup_page_id') ) ).'&complete_sign_up=ok';
2327
+					$cart_url = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_signup_page_id'))) . '&complete_sign_up=ok';
2328 2328
 				}
2329 2329
 			}
2330 2330
 			else {
2331
-				if ( !empty($_SESSION['cart']) ) {
2332
-					$cart_url = get_permalink( wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')) );
2331
+				if (!empty($_SESSION['cart'])) {
2332
+					$cart_url = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')));
2333 2333
 				}
2334 2334
 				else {
2335
-					$cart_url = get_permalink( wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')) );
2335
+					$cart_url = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')));
2336 2336
 				}
2337 2337
 			}
2338 2338
 			// check if the customer have already register an address
2339
-			$query = $wpdb->prepare('SELECT * FROM ' .$wpdb->posts. ' WHERE post_author = %d AND post_type = %s', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
2339
+			$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
2340 2340
 			$exist_address = $wpdb->get_results($query);
2341 2341
 		}
2342 2342
 		// If there is errors
2343
-		if($wpshop->error_count()>0) {
2343
+		if ($wpshop->error_count() > 0) {
2344 2344
 			$reponse = $wpshop->show_messages();
2345 2345
 		}
2346 2346
 
@@ -2357,24 +2357,24 @@  discard block
 block discarded – undo
2357 2357
 	function wpshop_ajax_order_customer_adress_load() {
2358 2358
 		global $wpshop_account;
2359 2359
 		global $wpdb;
2360
-		check_ajax_referer( 'wpshop_order_customer_adress_load', 'wpshop_ajax_nonce' );
2361
-		$current_customer_id = !empty( $_REQUEST['customer_id'] ) ? (int)$_REQUEST['customer_id'] : 0;
2362
-		$order_id = !empty( $_REQUEST['order_id'] ) ? (int)$_REQUEST['order_id'] : 0;
2360
+		check_ajax_referer('wpshop_order_customer_adress_load', 'wpshop_ajax_nonce');
2361
+		$current_customer_id = !empty($_REQUEST['customer_id']) ? (int)$_REQUEST['customer_id'] : 0;
2362
+		$order_id = !empty($_REQUEST['order_id']) ? (int)$_REQUEST['order_id'] : 0;
2363 2363
 
2364
-		$order_postmeta = get_post_meta ($order_id, '_order_postmeta', true);
2365
-		$order_infos_postmeta = get_post_meta ($order_id, '_order_info', true);
2364
+		$order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
2365
+		$order_infos_postmeta = get_post_meta($order_id, '_order_info', true);
2366 2366
 
2367
-		if ( !empty($order_postmeta) && !empty($order_postmeta['order_status']) && in_array($order_postmeta['order_status'], array('completed', 'shipped', 'refunded')) ) {
2367
+		if (!empty($order_postmeta) && !empty($order_postmeta['order_status']) && in_array($order_postmeta['order_status'], array('completed', 'shipped', 'refunded'))) {
2368 2368
 			/** Billing address display **/
2369 2369
 			$tpl_component['ADDRESS_COMBOBOX'] = '';
2370 2370
 			$tpl_component['ADDRESS_BUTTONS'] = '';
2371 2371
 			$tpl_component['CUSTOMER_ADDRESS_TYPE_TITLE'] = __('Billing address', 'wpshop');
2372 2372
 			$tpl_component['ADDRESS_TYPE'] = 'billing_address';
2373 2373
 			$address_fields = wps_address::get_addresss_form_fields_by_type($order_infos_postmeta['billing']['id']);
2374
-			$tpl_component['CUSTOMER_ADDRESS_CONTENT'] = wpshop_account::display_an_address( $address_fields, $order_infos_postmeta['billing']['address'] );
2374
+			$tpl_component['CUSTOMER_ADDRESS_CONTENT'] = wpshop_account::display_an_address($address_fields, $order_infos_postmeta['billing']['address']);
2375 2375
 			$tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = wpshop_display::display_template_element('display_address_container', $tpl_component);
2376
-			$retour =  wpshop_display::display_template_element('display_addresses_by_type_container', $tpl_component);
2377
-			unset( $tpl_component );
2376
+			$retour = wpshop_display::display_template_element('display_addresses_by_type_container', $tpl_component);
2377
+			unset($tpl_component);
2378 2378
 
2379 2379
 			/** Shipping address display **/
2380 2380
 			$retour .= '<div id="shipping_infos_bloc" class="wpshop_order_customer_container wpshop_order_customer_container_user_information">';
@@ -2383,67 +2383,67 @@  discard block
 block discarded – undo
2383 2383
 			$tpl_component['CUSTOMER_ADDRESS_TYPE_TITLE'] = __('Shipping address', 'wpshop');
2384 2384
 			$tpl_component['ADDRESS_TYPE'] = 'shipping_address';
2385 2385
 			$address_fields = wps_address::get_addresss_form_fields_by_type($order_infos_postmeta['shipping']['id']);
2386
-			$tpl_component['CUSTOMER_ADDRESS_CONTENT'] = wpshop_account::display_an_address( $address_fields, $order_infos_postmeta['shipping']['address']);
2386
+			$tpl_component['CUSTOMER_ADDRESS_CONTENT'] = wpshop_account::display_an_address($address_fields, $order_infos_postmeta['shipping']['address']);
2387 2387
 			$tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = wpshop_display::display_template_element('display_address_container', $tpl_component);
2388
-			$retour .=  wpshop_display::display_template_element('display_addresses_by_type_container', $tpl_component);
2389
-			unset( $tpl_component );
2388
+			$retour .= wpshop_display::display_template_element('display_addresses_by_type_container', $tpl_component);
2389
+			unset($tpl_component);
2390 2390
 			$retour .= '</div>';
2391 2391
 			$retour .= '<div class="wpshop_cls"></div>';
2392
-			$result = json_encode( array(true, $retour) );
2392
+			$result = json_encode(array(true, $retour));
2393 2393
 
2394 2394
 		}
2395 2395
 
2396
- 		elseif ( !empty($order_postmeta) && !empty($order_postmeta['order_status']) && in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid'))) {
2397
-			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
2396
+ 		elseif (!empty($order_postmeta) && !empty($order_postmeta['order_status']) && in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid'))) {
2397
+			$order_id = !empty($_REQUEST['order_id']) ? (int)$_REQUEST['order_id'] : 0;
2398 2398
  			$order_info_postmeta = get_post_meta($order_id, '_order_info', true);
2399 2399
 
2400 2400
  			$billing_id_attribute_set = get_option('wpshop_billing_address');
2401 2401
  			$shipping_id_attribute_set = get_option('wpshop_shipping_address_choice');
2402 2402
 
2403
- 			$order_billing_address = ( !empty($order_info_postmeta) && !empty($order_info_postmeta['billing']) && !empty($order_info_postmeta['billing']['address']) ) ? $order_info_postmeta['billing']['address'] : array();
2404
- 			$order_shipping_address = ( !empty($order_info_postmeta) && !empty($order_info_postmeta['shipping']) && !empty($order_info_postmeta['shipping']['address']) ) ? $order_info_postmeta['shipping']['address'] : array();
2403
+ 			$order_billing_address = (!empty($order_info_postmeta) && !empty($order_info_postmeta['billing']) && !empty($order_info_postmeta['billing']['address'])) ? $order_info_postmeta['billing']['address'] : array();
2404
+ 			$order_shipping_address = (!empty($order_info_postmeta) && !empty($order_info_postmeta['shipping']) && !empty($order_info_postmeta['shipping']['address'])) ? $order_info_postmeta['shipping']['address'] : array();
2405 2405
 
2406
- 			$billing_form = $wpshop_account->display_form_fields( $billing_id_attribute_set['choice'], '', '', '', array(), array(), $order_billing_address );
2407
- 			if ( !empty($shipping_id_attribute_set) && !empty($shipping_id_attribute_set['activate']) ) {
2408
- 				$shipping_form = $wpshop_account->display_form_fields( $shipping_id_attribute_set['choice'], '', '', '', array(), array(), $order_shipping_address );
2406
+ 			$billing_form = $wpshop_account->display_form_fields($billing_id_attribute_set['choice'], '', '', '', array(), array(), $order_billing_address);
2407
+ 			if (!empty($shipping_id_attribute_set) && !empty($shipping_id_attribute_set['activate'])) {
2408
+ 				$shipping_form = $wpshop_account->display_form_fields($shipping_id_attribute_set['choice'], '', '', '', array(), array(), $order_shipping_address);
2409 2409
  			}
2410 2410
 
2411
- 			$result = json_encode( array(true, $billing_form, $shipping_form, $current_customer_id) );
2411
+ 			$result = json_encode(array(true, $billing_form, $shipping_form, $current_customer_id));
2412 2412
  		}
2413 2413
 		else {
2414 2414
 				// Check the attribute set id of Billing Address
2415
-				$query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE name = "' .__('Billing address', 'wpshop'). '"', '');
2415
+				$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . __('Billing address', 'wpshop') . '"', '');
2416 2416
 				$attribute_set_id = $wpdb->get_var($query);
2417 2417
 				$billing_id_attribute_set = get_option('wpshop_billing_address');
2418 2418
 				//Check the billing address id of the customer
2419
-				$query = $wpdb->prepare('SELECT * FROM ' .$wpdb->posts. ' WHERE post_author = ' .$current_customer_id. ' AND post_type = "' .WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS. '"', '');
2419
+				$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_author = ' . $current_customer_id . ' AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '"', '');
2420 2420
 				$post_addresses = $wpdb->get_results($query);
2421 2421
 				$address_id = '';
2422
-				foreach ( $post_addresses as $post_address ) {
2423
-					$address_type = get_post_meta($post_address->ID, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY,true);
2424
-					if ( $address_type == $attribute_set_id ) {
2422
+				foreach ($post_addresses as $post_address) {
2423
+					$address_type = get_post_meta($post_address->ID, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true);
2424
+					if ($address_type == $attribute_set_id) {
2425 2425
 						$address_id = $post_address->ID;
2426 2426
 					}
2427 2427
 				}
2428 2428
 				$shipping_id_attribute_set = get_option('wpshop_shipping_address_choice');
2429 2429
 				$shipping_form = '';
2430
-				if ( !empty($shipping_id_attribute_set) && !empty($shipping_id_attribute_set['activate']) ) {
2430
+				if (!empty($shipping_id_attribute_set) && !empty($shipping_id_attribute_set['activate'])) {
2431 2431
 					// Check the attribute set id of Shipping Address
2432
-					$query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE name = "' .__('Shipping address', 'wpshop'). '"', '');
2432
+					$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . __('Shipping address', 'wpshop') . '"', '');
2433 2433
 					$attribute_set_id = $wpdb->get_var($query);
2434 2434
 					//Check the billing address id of the customer
2435
-					$query = $wpdb->prepare('SELECT * FROM ' .$wpdb->posts. ' WHERE post_author = ' .$current_customer_id. ' AND post_type = "' .WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS. '"', '');
2435
+					$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_author = ' . $current_customer_id . ' AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '"', '');
2436 2436
 					$post_addresses = $wpdb->get_results($query);
2437 2437
 					$shipping_address_id = '';
2438
-					foreach ( $post_addresses as $post_address ) {
2439
-						$address_type = get_post_meta($post_address->ID, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY,true);
2440
-						if ( $address_type == $attribute_set_id ) {
2438
+					foreach ($post_addresses as $post_address) {
2439
+						$address_type = get_post_meta($post_address->ID, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true);
2440
+						if ($address_type == $attribute_set_id) {
2441 2441
 							$shipping_address_id = $post_address->ID;
2442 2442
 						}
2443 2443
 					}
2444
-					$shipping_form = $wpshop_account->display_form_fields( $shipping_id_attribute_set['choice'], $shipping_address_id );
2444
+					$shipping_form = $wpshop_account->display_form_fields($shipping_id_attribute_set['choice'], $shipping_address_id);
2445 2445
 				}
2446
-				$result = json_encode( array(true, $wpshop_account->display_form_fields( $billing_id_attribute_set['choice'], $address_id ), $shipping_form, $current_customer_id) );
2446
+				$result = json_encode(array(true, $wpshop_account->display_form_fields($billing_id_attribute_set['choice'], $address_id), $shipping_form, $current_customer_id));
2447 2447
 		}
2448 2448
 		echo $result;
2449 2449
 		die();
@@ -2455,23 +2455,23 @@  discard block
 block discarded – undo
2455 2455
 	 */
2456 2456
 	function ajax_wpshop_add_entity() {
2457 2457
 		global $wpdb;
2458
-		check_ajax_referer( 'wpshop_add_new_entity_ajax_nonce', 'wpshop_ajax_nonce' );
2458
+		check_ajax_referer('wpshop_add_new_entity_ajax_nonce', 'wpshop_ajax_nonce');
2459 2459
 
2460
-		$attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : array();
2460
+		$attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array();
2461 2461
 		$attributes = array();
2462 2462
 		/** Get the attribute to create	*/
2463 2463
 		$attribute_to_reload = null;
2464
-		if ( !empty($attribute['new_value_creation']) && is_array( $attribute['new_value_creation'] ) ) {
2465
-			foreach ( $attribute['new_value_creation'] as $attribute_code=>$value) {
2466
-				$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s', $attribute_code);
2464
+		if (!empty($attribute['new_value_creation']) && is_array($attribute['new_value_creation'])) {
2465
+			foreach ($attribute['new_value_creation'] as $attribute_code=>$value) {
2466
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', $attribute_code);
2467 2467
 				$attribute_def = $wpdb->get_row($query);
2468
-				if ( $value != "" ) {
2469
-					if ( $attribute_def->data_type_to_use == 'internal' ) {
2468
+				if ($value != "") {
2469
+					if ($attribute_def->data_type_to_use == 'internal') {
2470 2470
 						$attribute_default_value = unserialize($attribute_def->default_value);
2471
-						if ( $attribute_default_value['default_value'] == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) {
2472
-							$user_id = wp_create_user( sanitize_user( $value ), wp_generate_password( 12, false ) );
2473
-							$query = $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id );
2474
-							$attribute_option_id = $wpdb->get_var( $query );
2471
+						if ($attribute_default_value['default_value'] == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
2472
+							$user_id = wp_create_user(sanitize_user($value), wp_generate_password(12, false));
2473
+							$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
2474
+							$attribute_option_id = $wpdb->get_var($query);
2475 2475
 						}
2476 2476
 						else {
2477 2477
 							$entity_args = array(
@@ -2484,13 +2484,13 @@  discard block
 block discarded – undo
2484 2484
 						}
2485 2485
 					}
2486 2486
 					else {
2487
-						$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'valid', 'creation_date'=>current_time('mysql', 0), 'position' => 1, 'attribute_id'=>$attribute_def->id, 'value'=>$value, 'label'=>$value) );
2487
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'valid', 'creation_date'=>current_time('mysql', 0), 'position' => 1, 'attribute_id'=>$attribute_def->id, 'value'=>$value, 'label'=>$value));
2488 2488
 						$attribute_option_id = $wpdb->insert_id;
2489 2489
 					}
2490 2490
 
2491
-					foreach ( $attribute as $attribute => $val) {
2491
+					foreach ($attribute as $attribute => $val) {
2492 2492
 						foreach ($val as $k=>$v) {
2493
-							if ( $k == $attribute_code) {
2493
+							if ($k == $attribute_code) {
2494 2494
 								$attribute[$attribute][$k] = $attribute_option_id;
2495 2495
 							}
2496 2496
 						}
@@ -2499,82 +2499,82 @@  discard block
 block discarded – undo
2499 2499
 			}
2500 2500
 		}
2501 2501
 		/** Store send attribute into a new array for save purpose	*/
2502
-		if ( is_array( $attribute ) ) {
2503
-			foreach ( $attribute as $attribute_type => $attribute ) {
2504
-				foreach ( $attribute as $attribute_code => $attribute_value ) {
2505
-					if ( !isset( $attributes[$attribute_code] ) ) {
2502
+		if (is_array($attribute)) {
2503
+			foreach ($attribute as $attribute_type => $attribute) {
2504
+				foreach ($attribute as $attribute_code => $attribute_value) {
2505
+					if (!isset($attributes[$attribute_code])) {
2506 2506
 						$attributes[$attribute_code] = $attribute_value;
2507 2507
 					}
2508 2508
 				}
2509 2509
 			}
2510 2510
 		}
2511 2511
 
2512
-		$post_title = !empty( $_POST['wp_fields']['post_title'] ) ? sanitize_text_field( $_POST['wp_fields']['post_title'] ) : '';
2513
-		$entity_type = !empty( $_POST['entity_type'] ) ? sanitize_text_field( $_POST['entity_type'] ) : '';
2514
-		$attribute_set_id = !empty( $_POST['attribute_set_id'] ) ? (int) $_POST['attribute_set_id'] : 0;
2515
-		$type_of_form = !empty( $_POST['type_of_form'] ) ? sanitize_text_field( $_POST['type_of_form'] ) : '';
2512
+		$post_title = !empty($_POST['wp_fields']['post_title']) ? sanitize_text_field($_POST['wp_fields']['post_title']) : '';
2513
+		$entity_type = !empty($_POST['entity_type']) ? sanitize_text_field($_POST['entity_type']) : '';
2514
+		$attribute_set_id = !empty($_POST['attribute_set_id']) ? (int)$_POST['attribute_set_id'] : 0;
2515
+		$type_of_form = !empty($_POST['type_of_form']) ? sanitize_text_field($_POST['type_of_form']) : '';
2516 2516
 
2517 2517
 		/** Save the new entity into database */
2518
-		$result = wpshop_entities::create_new_entity( $entity_type, $post_title, '', $attributes, array('attribute_set_id' => $attribute_set_id) );
2518
+		$result = wpshop_entities::create_new_entity($entity_type, $post_title, '', $attributes, array('attribute_set_id' => $attribute_set_id));
2519 2519
 		$new_entity_id = $result[1];
2520 2520
 
2521
-		if ( !empty($new_entity_id) ) {
2521
+		if (!empty($new_entity_id)) {
2522 2522
 			/**	Save address for current entity	*/
2523
-			if ( !empty( $type_of_form ) && !empty( $attribute[$type_of_form] ) ) {
2523
+			if (!empty($type_of_form) && !empty($attribute[$type_of_form])) {
2524 2524
 				global $wpshop_account;
2525
-				$result = wps_address::wps_address( $type_of_form );
2526
-				update_post_meta ($new_entity_id, '_wpshop_attached_address', $result['current_id']);
2525
+				$result = wps_address::wps_address($type_of_form);
2526
+				update_post_meta($new_entity_id, '_wpshop_attached_address', $result['current_id']);
2527 2527
 			}
2528 2528
 
2529 2529
 			/** Make price calculation if entity is a product	*/
2530
-			if ( $entity_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
2530
+			if ($entity_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2531 2531
 				$wpshop_prices_attribute = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2532 2532
 				$calculate_price = false;
2533
-				foreach( $wpshop_prices_attribute as $attribute_price_code ){
2534
-					if ( array_key_exists($attribute_price_code, $attributes) ) {
2533
+				foreach ($wpshop_prices_attribute as $attribute_price_code) {
2534
+					if (array_key_exists($attribute_price_code, $attributes)) {
2535 2535
 						$calculate_price = true;
2536 2536
 					}
2537 2537
 				}
2538
-				if ( $calculate_price ) {
2538
+				if ($calculate_price) {
2539 2539
 					wpshop_products::calculate_price($new_entity_id);
2540 2540
 				}
2541 2541
 			}
2542 2542
 
2543 2543
 			/** Add picture if a file has been send	*/
2544
-			if ( !empty($_FILES) ) {
2544
+			if (!empty($_FILES)) {
2545 2545
 				$wp_upload_dir = wp_upload_dir();
2546 2546
 				$final_dir = $wp_upload_dir['path'] . '/';
2547
-				if ( !is_dir($final_dir) ) {
2547
+				if (!is_dir($final_dir)) {
2548 2548
 					mkdir($final_dir, 0755, true);
2549 2549
 				}
2550 2550
 
2551
-				foreach ( $_FILES as $file ) {
2551
+				foreach ($_FILES as $file) {
2552 2552
 					$tmp_name = $file['tmp_name']['post_thumbnail'];
2553 2553
 					$name = $file['name']['post_thumbnail'];
2554 2554
 
2555 2555
 					$filename = $final_dir . $name;
2556 2556
 					@move_uploaded_file($tmp_name, $filename);
2557 2557
 
2558
-					$wp_filetype = wp_check_filetype(basename($filename), null );
2558
+					$wp_filetype = wp_check_filetype(basename($filename), null);
2559 2559
 					$attachment = array(
2560
-						'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path( $filename ),
2560
+						'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path($filename),
2561 2561
 						'post_mime_type' => $wp_filetype['type'],
2562
-						'post_title' => preg_replace( '/\.[^.]+$/', '', basename($filename) ),
2562
+						'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
2563 2563
 						'post_content' => '',
2564 2564
 						'post_status' => 'inherit'
2565 2565
 					);
2566
-					$attach_id = wp_insert_attachment( $attachment, $filename, $new_entity_id );
2566
+					$attach_id = wp_insert_attachment($attachment, $filename, $new_entity_id);
2567 2567
 					require_once(ABSPATH . 'wp-admin/includes/image.php');
2568
-					$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
2569
-					wp_update_attachment_metadata( $attach_id, $attach_data );
2568
+					$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
2569
+					wp_update_attachment_metadata($attach_id, $attach_data);
2570 2570
 					add_post_meta($new_entity_id, '_thumbnail_id', $attach_id, true);
2571 2571
 				}
2572 2572
 			}
2573 2573
 
2574
-			echo json_encode( array( true,  __('Element has been saved', 'wpshop'), $attribute_to_reload, $new_entity_id) );
2574
+			echo json_encode(array(true, __('Element has been saved', 'wpshop'), $attribute_to_reload, $new_entity_id));
2575 2575
 		}
2576 2576
 		else {
2577
-			echo json_encode( array(false, __('An error occured while adding your element', 'wpshop')) );
2577
+			echo json_encode(array(false, __('An error occured while adding your element', 'wpshop')));
2578 2578
 		}
2579 2579
 
2580 2580
 		die();
@@ -2583,47 +2583,47 @@  discard block
 block discarded – undo
2583 2583
 // 	add_action('wp_ajax_nopriv_wpshop_quick_add_entity', 'ajax_wpshop_add_entity');
2584 2584
 
2585 2585
 	function ajax_wpshop_reload_attribute_for_quick_add() {
2586
-		check_ajax_referer( 'ajax_wpshop_reload_attribute_for_quick_add' );
2586
+		check_ajax_referer('ajax_wpshop_reload_attribute_for_quick_add');
2587 2587
 		$output = '';
2588
-		$attribute_to_reload = !empty( $_POST['attribute_to_reload'] ) ? (array) $_POST['attribute_to_reload'] : array();
2589
-		if ( !empty($attribute_to_reload) ) {
2590
-			foreach ( $attribute_to_reload as $attribute_code ) {
2591
-				$attr_field = wpshop_attributes::display_attribute( $attribute_code, 'frontend' );
2588
+		$attribute_to_reload = !empty($_POST['attribute_to_reload']) ? (array)$_POST['attribute_to_reload'] : array();
2589
+		if (!empty($attribute_to_reload)) {
2590
+			foreach ($attribute_to_reload as $attribute_code) {
2591
+				$attr_field = wpshop_attributes::display_attribute($attribute_code, 'frontend');
2592 2592
 				$output[$attribute_code]['result'] = $attr_field['field_definition']['output'] . $attr_field['field_definition']['options'];
2593 2593
 			}
2594 2594
 		}
2595
-		echo json_encode( array($output) );
2595
+		echo json_encode(array($output));
2596 2596
 		die();
2597 2597
 	}
2598 2598
 	add_action('wp_ajax_reload_attribute_for_quick_add', 'ajax_wpshop_reload_attribute_for_quick_add');
2599 2599
 
2600 2600
 	function ajax_wpshop_change_address() {
2601
-		check_ajax_referer( 'ajax_wpshop_change_address' );
2602
-		$address_id = ( !empty($_POST['address_id']) ? (int) $_POST['address_id'] : null);
2603
-		$address_type = ( !empty($_POST['address_type']) ? sanitize_text_field($_POST['address_type']) : null);
2604
-		$is_allowed_destination  = true;
2605
-		if ( !empty($address_id) && !empty($address_type) ) {
2601
+		check_ajax_referer('ajax_wpshop_change_address');
2602
+		$address_id = (!empty($_POST['address_id']) ? (int)$_POST['address_id'] : null);
2603
+		$address_type = (!empty($_POST['address_type']) ? sanitize_text_field($_POST['address_type']) : null);
2604
+		$is_allowed_destination = true;
2605
+		if (!empty($address_id) && !empty($address_type)) {
2606 2606
 			//Check if it's an allowed address for shipping
2607 2607
 			$checkout_payment_button = '';
2608
-			$cart_type = (!empty($_SESSION['cart']['cart_type']) && sanitize_text_field($_SESSION['cart']['cart_type'])=='quotation') ? 'quotation' : 'cart';
2609
-			$is_allowed_destination = true;//wpshop_shipping_configuration::is_allowed_country ( $address_id );
2610
-			if ( $is_allowed_destination ) {
2608
+			$cart_type = (!empty($_SESSION['cart']['cart_type']) && sanitize_text_field($_SESSION['cart']['cart_type']) == 'quotation') ? 'quotation' : 'cart';
2609
+			$is_allowed_destination = true; //wpshop_shipping_configuration::is_allowed_country ( $address_id );
2610
+			if ($is_allowed_destination) {
2611 2611
 				$available_payement_method = wpshop_payment::display_payment_methods_choice_form(0, $cart_type);
2612 2612
 				//if(!empty($available_payement_method[1]['paypal']) || !empty($available_payement_method[1]['banktransfer']) || !empty($available_payement_method[1]['checks']) || WPSHOP_PAYMENT_METHOD_CIC || !empty($available_payement_method[1]['cic']) || ($cart_type == 'quotation')) {
2613
-				if ( !empty($available_payement_method[0]) ) {
2614
-					if ( $cart_type=='quotation' ) {
2615
-						$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_quotation_validation_button', array() );
2613
+				if (!empty($available_payement_method[0])) {
2614
+					if ($cart_type == 'quotation') {
2615
+						$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_quotation_validation_button', array());
2616 2616
 					}
2617 2617
 					else {
2618
-						$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_validation_button', array() );
2618
+						$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_validation_button', array());
2619 2619
 					}
2620 2620
 				}
2621 2621
 			}
2622 2622
 			else {
2623 2623
 				$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_impossible_to_order', array());
2624 2624
 			}
2625
-			if( $address_type == 'billing_address') {
2626
-				$billing_option = get_option( 'wpshop_billing_address' );
2625
+			if ($address_type == 'billing_address') {
2626
+				$billing_option = get_option('wpshop_billing_address');
2627 2627
 				$address_option = $billing_option['choice'];
2628 2628
 			}
2629 2629
 			else {
@@ -2631,16 +2631,16 @@  discard block
 block discarded – undo
2631 2631
 				$address_option = $shipping_address_option['choice'];
2632 2632
 			}
2633 2633
 			$add = wps_address::get_addresss_form_fields_by_type($address_option);
2634
-			$address_infos = get_post_meta($address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true);
2635
-			$retour = wpshop_account::display_an_address ( $add, $address_infos, $address_id);
2634
+			$address_infos = get_post_meta($address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true);
2635
+			$retour = wpshop_account::display_an_address($add, $address_infos, $address_id);
2636 2636
 
2637 2637
 			$_SESSION[$address_type] = $address_id;
2638 2638
 
2639
-			$edit_link = '<a href="' .get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&') . 'action=editAddress&amp;id='.$address_id.'" title="' .__('Edit', 'wpshop'). '">' .__('Edit', 'wpshop'). '</a>';
2640
-			$result = json_encode( array(true, $retour, $edit_link, $is_allowed_destination, $checkout_payment_button) );
2639
+			$edit_link = '<a href="' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=editAddress&amp;id=' . $address_id . '" title="' . __('Edit', 'wpshop') . '">' . __('Edit', 'wpshop') . '</a>';
2640
+			$result = json_encode(array(true, $retour, $edit_link, $is_allowed_destination, $checkout_payment_button));
2641 2641
 		}
2642 2642
 		else {
2643
-			$result = json_encode( array(false, 'missing_informations') );
2643
+			$result = json_encode(array(false, 'missing_informations'));
2644 2644
 		}
2645 2645
 		echo $result;
2646 2646
 
@@ -2650,26 +2650,26 @@  discard block
 block discarded – undo
2650 2650
 	add_action('wp_ajax_nopriv_change_address', 'ajax_wpshop_change_address');
2651 2651
 
2652 2652
 	function ajax_wpshop_load_create_new_customer_interface() {
2653
-		check_ajax_referer( 'ajax_wpshop_load_create_new_customer_interface' );
2653
+		check_ajax_referer('ajax_wpshop_load_create_new_customer_interface');
2654 2654
 		$billing_address_option = get_option('wpshop_billing_address');
2655 2655
 		$shipping_address_option = get_option('wpshop_shipping_address_choice');
2656 2656
 
2657 2657
 		$tpl_component = array();
2658 2658
 		$tpl_component['LOADING_ICON'] = WPSHOP_LOADING_ICON;
2659
-		if ( !empty($billing_address) ) {
2660
-			echo wpshop_account::get_addresses_by_type( $billing_address, __('Billing address', 'wpshop'), array('only_display' => 'yes'));
2659
+		if (!empty($billing_address)) {
2660
+			echo wpshop_account::get_addresses_by_type($billing_address, __('Billing address', 'wpshop'), array('only_display' => 'yes'));
2661 2661
 		}
2662 2662
 		$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] = wpshop_account::display_form_fields($billing_address_option['choice'], '', 'first');
2663 2663
 
2664
-		if ( $shipping_address_option['activate'] ) {
2665
-			$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '<p class="formField"><label><input type="checkbox" name="shiptobilling" id="shiptobilling_checkbox" checked="checked" /> '.__('Use as shipping information','wpshop').'</label></p><br/>';
2664
+		if ($shipping_address_option['activate']) {
2665
+			$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '<p class="formField"><label><input type="checkbox" name="shiptobilling" id="shiptobilling_checkbox" checked="checked" /> ' . __('Use as shipping information', 'wpshop') . '</label></p><br/>';
2666 2666
 			$display = 'display:none;';
2667
-			$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '<div id="shipping_infos_bloc" style="'.$display.'">';
2667
+			$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '<div id="shipping_infos_bloc" style="' . $display . '">';
2668 2668
 			$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= wpshop_account::display_form_fields($shipping_address_option['choice'], '', 'first');
2669 2669
 			$tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '</div><br/>';
2670 2670
 		}
2671 2671
 
2672
-		$tpl_component['CUSTOMER_ADDRESSES_FORM_BUTTONS'] = '<p class="formField"><input type="submit" name="submitbillingAndShippingInfo" id="submitbillingAndShippingInfo" value="' . __('Save','wpshop') . '" /></p>';
2672
+		$tpl_component['CUSTOMER_ADDRESSES_FORM_BUTTONS'] = '<p class="formField"><input type="submit" name="submitbillingAndShippingInfo" id="submitbillingAndShippingInfo" value="' . __('Save', 'wpshop') . '" /></p>';
2673 2673
 		$output = wpshop_display::display_template_element('wpshop_customer_addresses_form_admin', $tpl_component, array(), 'admin');
2674 2674
 		unset($tpl_component);
2675 2675
 		$result = json_encode(array(true, $output));
@@ -2679,18 +2679,18 @@  discard block
 block discarded – undo
2679 2679
 	add_action('wp_ajax_load_create_new_customer_interface', 'ajax_wpshop_load_create_new_customer_interface');
2680 2680
 
2681 2681
 	function ajax_wpshop_create_new_customer() {
2682
-		check_ajax_referer( 'ajax_wpshop_create_new_customer' );
2682
+		check_ajax_referer('ajax_wpshop_create_new_customer');
2683 2683
 		$result = '';
2684 2684
 		$billing_address = !empty($_REQUEST['billing_address']) ? sanitize_key($_REQUEST['billing_address']) : '';
2685 2685
 		$shipping_address = !empty($_REQUEST['shipping_address']) ? sanitize_key($_REQUEST['shipping_address']) : '';
2686 2686
 		$shiptobilling = !empty($_REQUEST['shiptobilling']) ? sanitize_key($_REQUEST['shiptobilling']) : null;
2687 2687
 		$username = !empty($_POST['attribute'][$billing_address]['varchar']['address_user_email']) ? sanitize_text_field($_POST['attribute'][$billing_address]['varchar']['address_user_email']) : null;
2688
-		if ( $username != null ) {
2688
+		if ($username != null) {
2689 2689
 			/** Crerate the new customer user account */
2690
-			$password = wp_generate_password( $length=12, $include_standard_special_chars=false );
2690
+			$password = wp_generate_password($length = 12, $include_standard_special_chars = false);
2691 2691
 			$email = $username;
2692
-			if ( !empty($username) && !username_exists($username) && !empty($email) && !email_exists($email) ) {
2693
-				$user_id = wp_create_user( $username, $password, $email );
2692
+			if (!empty($username) && !username_exists($username) && !empty($email) && !email_exists($email)) {
2693
+				$user_id = wp_create_user($username, $password, $email);
2694 2694
 				// @TODO : REQUEST
2695 2695
 				// $_REQUEST['user']['customer_id'] = $user_id;
2696 2696
 				/** Save addresses */
@@ -2701,21 +2701,21 @@  discard block
 block discarded – undo
2701 2701
 					wpshop_account::same_billing_and_shipping_address($billing_address, $shipping_address);
2702 2702
 				}
2703 2703
 
2704
-				if ( !empty($billing_address) ) {
2705
-					wps_address::save_address_infos( $billing_address );
2704
+				if (!empty($billing_address)) {
2705
+					wps_address::save_address_infos($billing_address);
2706 2706
 				}
2707
-				if( !empty($shipping_address ) ) {
2708
-					wps_address::save_address_infos( $shipping_address);
2707
+				if (!empty($shipping_address)) {
2708
+					wps_address::save_address_infos($shipping_address);
2709 2709
 				}
2710
-				$result = json_encode( array(true, __('Customer created', 'wpshop'), $user_id) );
2710
+				$result = json_encode(array(true, __('Customer created', 'wpshop'), $user_id));
2711 2711
 			}
2712 2712
 			else {
2713
-				$result = json_encode( array(false, __('A customer account is already created with this email address', 'wpshop')) );
2713
+				$result = json_encode(array(false, __('A customer account is already created with this email address', 'wpshop')));
2714 2714
 			}
2715 2715
 
2716 2716
 		}
2717 2717
 		else {
2718
-			$result = json_encode( array(false, __('An email address is required', 'wpshop')) );
2718
+			$result = json_encode(array(false, __('An email address is required', 'wpshop')));
2719 2719
 		}
2720 2720
 		echo $result;
2721 2721
 		die();
@@ -2725,26 +2725,26 @@  discard block
 block discarded – undo
2725 2725
 	/**
2726 2726
 	 * Send a message to customer
2727 2727
 	 */
2728
-	function ajax_wpshop_send_message_by_type () {
2729
-		check_ajax_referer( 'ajax_wpshop_send_message_by_type' );
2728
+	function ajax_wpshop_send_message_by_type() {
2729
+		check_ajax_referer('ajax_wpshop_send_message_by_type');
2730 2730
 		global $wpdb;
2731 2731
 		$result = array();
2732
-		$message_type_id = ( !empty( $_POST['message_type_id'])) ? (int) $_POST['message_type_id'] : null;
2733
-		$customer_id = ( !empty( $_POST['customer_user_id'])) ? (int) $_POST['customer_user_id'] : null;
2734
-		$model_name = ( !empty( $_POST['message_model_name'])) ? sanitize_text_field($_POST['message_model_name']) : null;
2735
-		$order_id = ( !empty( $_POST['order_id'])) ? (int) $_POST['order_id'] : null;
2736
-		if ( !empty($customer_id) && !empty($message_type_id) && !empty($model_name)) {
2732
+		$message_type_id = (!empty($_POST['message_type_id'])) ? (int)$_POST['message_type_id'] : null;
2733
+		$customer_id = (!empty($_POST['customer_user_id'])) ? (int)$_POST['customer_user_id'] : null;
2734
+		$model_name = (!empty($_POST['message_model_name'])) ? sanitize_text_field($_POST['message_model_name']) : null;
2735
+		$order_id = (!empty($_POST['order_id'])) ? (int)$_POST['order_id'] : null;
2736
+		if (!empty($customer_id) && !empty($message_type_id) && !empty($model_name)) {
2737 2737
 			$order_post_meta = get_post_meta($order_id, '_order_postmeta', true);
2738
-			$receiver_infos = get_userdata( $customer_id );
2738
+			$receiver_infos = get_userdata($customer_id);
2739 2739
 			$email = $receiver_infos->user_email;
2740 2740
 			$first_name = get_user_meta($customer_id, 'first_name', true);
2741 2741
 			$last_name = get_user_meta($customer_id, 'last_name', true);
2742 2742
 			$wps_message = new wps_message_ctr();
2743
-			$wps_message->wpshop_prepared_email( $email, $model_name, array('order_id' => $order_id, 'order_key' => ( ( !empty($order_post_meta) && !empty($order_post_meta['order_key']) ) ? $order_post_meta['order_key'] : '' ), 'order_date' => ( ( !empty($order_post_meta) && !empty($order_post_meta['order_date']) ) ? $order_post_meta['order_date'] : '' ),'customer_first_name' => $first_name, 'customer_last_name' => $last_name) );
2744
-			$result = array('status' => true, 'response' => $wps_message->get_historic_message_by_type($message_type_id) );
2743
+			$wps_message->wpshop_prepared_email($email, $model_name, array('order_id' => $order_id, 'order_key' => ((!empty($order_post_meta) && !empty($order_post_meta['order_key'])) ? $order_post_meta['order_key'] : ''), 'order_date' => ((!empty($order_post_meta) && !empty($order_post_meta['order_date'])) ? $order_post_meta['order_date'] : ''), 'customer_first_name' => $first_name, 'customer_last_name' => $last_name));
2744
+			$result = array('status' => true, 'response' => $wps_message->get_historic_message_by_type($message_type_id));
2745 2745
 		}
2746 2746
 		else {
2747
-			$result = array('status' => false, 'response' => __('An error occured', 'wpshop') );
2747
+			$result = array('status' => false, 'response' => __('An error occured', 'wpshop'));
2748 2748
 		}
2749 2749
 		echo json_encode($result);
2750 2750
 		die();
@@ -2753,23 +2753,23 @@  discard block
 block discarded – undo
2753 2753
 
2754 2754
 
2755 2755
 	function ajax_wpshop_upload_downloadable_file_action() {
2756
-		check_ajax_referer( 'ajax_wpshop_upload_downloadable_file_action' );
2756
+		check_ajax_referer('ajax_wpshop_upload_downloadable_file_action');
2757 2757
 		$result = '';
2758
-		$element_identifier = ( !empty( $_POST ) && !empty( $_POST[ 'element_identifier' ] ) && is_int( (int)$_POST[ 'element_identifier' ] ) ) ? (int)$_POST[ 'element_identifier' ] : 0;
2759
-		$wpshop_uploaded_file = ( !empty( $_FILES ) && !empty( $_FILES[ 'wpshop_file' ] ) && is_array( (array)$_FILES[ 'wpshop_file' ] ) ) ? (array)$_FILES[ 'wpshop_file' ] : array();
2758
+		$element_identifier = (!empty($_POST) && !empty($_POST['element_identifier']) && is_int((int)$_POST['element_identifier'])) ? (int)$_POST['element_identifier'] : 0;
2759
+		$wpshop_uploaded_file = (!empty($_FILES) && !empty($_FILES['wpshop_file']) && is_array((array)$_FILES['wpshop_file'])) ? (array)$_FILES['wpshop_file'] : array();
2760 2760
 
2761
-		if ( !empty( $wpshop_uploaded_file ) && !empty( $element_identifier ) ) {
2762
-			if(!is_dir(WPSHOP_UPLOAD_DIR)){
2761
+		if (!empty($wpshop_uploaded_file) && !empty($element_identifier)) {
2762
+			if (!is_dir(WPSHOP_UPLOAD_DIR)) {
2763 2763
 				mkdir(WPSHOP_UPLOAD_DIR, 0755, true);
2764 2764
 			}
2765 2765
 			$file = $wpshop_uploaded_file;
2766 2766
 			$tmp_name = $file['tmp_name'];
2767
-			$name = sanitize_file_name( current_time( 'mysql', 0 ).'__'.$file["name"] );
2768
-			move_uploaded_file($tmp_name, WPSHOP_UPLOAD_DIR.$name);
2767
+			$name = sanitize_file_name(current_time('mysql', 0) . '__' . $file["name"]);
2768
+			move_uploaded_file($tmp_name, WPSHOP_UPLOAD_DIR . $name);
2769 2769
 
2770
-			$n = WPSHOP_UPLOAD_URL.'/'.$name;
2771
-			update_post_meta( $element_identifier, 'attribute_option_is_downloadable_', array('file_url' => $n));
2772
-			$result = '<a href="' .$n. '" target="_blank" download>' .$name. '</a>';
2770
+			$n = WPSHOP_UPLOAD_URL . '/' . $name;
2771
+			update_post_meta($element_identifier, 'attribute_option_is_downloadable_', array('file_url' => $n));
2772
+			$result = '<a href="' . $n . '" target="_blank" download>' . $name . '</a>';
2773 2773
 		}
2774 2774
 		else {
2775 2775
 			$result = '';
@@ -2780,91 +2780,91 @@  discard block
 block discarded – undo
2780 2780
 	add_action('wp_ajax_upload_downloadable_file_action', 'ajax_wpshop_upload_downloadable_file_action');
2781 2781
 
2782 2782
 	function ajax_wpshop_fill_the_downloadable_dialog() {
2783
-		$product_id = ( !empty( $_POST ) && !empty( $_POST[ 'product_identifier' ] ) ) ? (int)$_POST[ 'product_identifier' ] : 0;
2784
-		check_ajax_referer( "ajax_wpshop_fill_the_downloadable_dialog".$product_id );
2783
+		$product_id = (!empty($_POST) && !empty($_POST['product_identifier'])) ? (int)$_POST['product_identifier'] : 0;
2784
+		check_ajax_referer("ajax_wpshop_fill_the_downloadable_dialog" . $product_id);
2785 2785
 		ajax_wpshop_fill_the_downloadable_dialog_exec($product_id);
2786 2786
 	}
2787 2787
 	function ajax_wpshop_fill_the_downloadable_dialog_unnonced() {
2788
-		$product_id = ( !empty( $_POST ) && !empty( $_POST[ 'product_identifier' ] ) ) ? (int)$_POST[ 'product_identifier' ] : 0;
2788
+		$product_id = (!empty($_POST) && !empty($_POST['product_identifier'])) ? (int)$_POST['product_identifier'] : 0;
2789 2789
 		ajax_wpshop_fill_the_downloadable_dialog_exec($product_id);
2790 2790
 	}
2791
-	function ajax_wpshop_fill_the_downloadable_dialog_exec( $product_id ) {
2792
-		$output  = '<form method="post" action="' .admin_url('admin-ajax.php') .'" id="upload_downloadable_file" enctype="multipart/form-data" >';
2793
-		$output .= '<p class="formField"><label for="wpshop_file">' .__('Choose your file to send', 'wpshop'). '</label><input type="file" name="wpshop_file" /></p>';
2791
+	function ajax_wpshop_fill_the_downloadable_dialog_exec($product_id) {
2792
+		$output  = '<form method="post" action="' . admin_url('admin-ajax.php') . '" id="upload_downloadable_file" enctype="multipart/form-data" >';
2793
+		$output .= '<p class="formField"><label for="wpshop_file">' . __('Choose your file to send', 'wpshop') . '</label><input type="file" name="wpshop_file" /></p>';
2794 2794
 		$output .= '<input type="hidden" name="action" value="upload_downloadable_file_action" />';
2795
-		$output .= '<input type="hidden" name="element_identifier" id="element_identifier" value="' .esc_attr( $product_id). '" />';
2796
-		$output .= wp_nonce_field( 'ajax_wpshop_upload_downloadable_file_action', '_wpnonce', true, false );
2797
-		$output .= '<p class="formField"><a id="send_downloadable_file_button" class="wps-bton-first-mini-rounded">' .__('Send your file', 'wpshop'). '</a></p>';
2795
+		$output .= '<input type="hidden" name="element_identifier" id="element_identifier" value="' . esc_attr($product_id) . '" />';
2796
+		$output .= wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', '_wpnonce', true, false);
2797
+		$output .= '<p class="formField"><a id="send_downloadable_file_button" class="wps-bton-first-mini-rounded">' . __('Send your file', 'wpshop') . '</a></p>';
2798 2798
 		$output .= '</form>';
2799
-		$output .='<script type="text/javascript">jQuery("#upload_downloadable_file").ajaxForm({
2799
+		$output .= '<script type="text/javascript">jQuery("#upload_downloadable_file").ajaxForm({
2800 2800
 		beforeSubmit : function() { },success: function(response) {
2801
-		jQuery(".is_downloadable_statut_'.$product_id.'").html( response );
2801
+		jQuery(".is_downloadable_statut_'.$product_id . '").html( response );
2802 2802
 		jQuery(".send_downloadable_file_dialog").dialog("close");
2803 2803
 		}});</script>';
2804
-		$output = apply_filters( 'wpshop_download_file_dialog', $output, $product_id );
2804
+		$output = apply_filters('wpshop_download_file_dialog', $output, $product_id);
2805 2805
 
2806
-		$response = array( 'status' => true, 'response' => $output);
2807
-		echo json_encode( $response );
2806
+		$response = array('status' => true, 'response' => $output);
2807
+		echo json_encode($response);
2808 2808
 		die();
2809 2809
 	}
2810 2810
 	add_action('wp_ajax_fill_the_downloadable_dialog', 'ajax_wpshop_fill_the_downloadable_dialog');
2811 2811
 	add_action('wp_ajax_fill_the_downloadable_dialog_unnonced', 'ajax_wpshop_fill_the_downloadable_dialog_unnonced');
2812 2812
 
2813 2813
 	function ajax_wpshop_show_downloadable_interface_in_admin() {
2814
-		$post_id = !empty( $_POST ) && !empty( $_POST[ 'post_id' ] ) && is_int( (int)$_POST[ 'post_id' ] ) ? (int)$_POST[ 'post_id' ] : 0;
2815
-		check_ajax_referer( 'ajax_wpshop_show_downloadable_interface_in_admin'.$post_id );
2814
+		$post_id = !empty($_POST) && !empty($_POST['post_id']) && is_int((int)$_POST['post_id']) ? (int)$_POST['post_id'] : 0;
2815
+		check_ajax_referer('ajax_wpshop_show_downloadable_interface_in_admin' . $post_id);
2816 2816
 		global $wpdb;
2817 2817
 		$status = false;
2818
-		$selected_value = ( !empty($_POST['selected_value']) ) ? sanitize_text_field( $_POST['selected_value'] ) : '';
2819
-		$query = $wpdb->prepare( 'SELECT label FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS.' WHERE id = %d', $selected_value);
2820
-		$value = $wpdb->get_var( $query );
2818
+		$selected_value = (!empty($_POST['selected_value'])) ? sanitize_text_field($_POST['selected_value']) : '';
2819
+		$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $selected_value);
2820
+		$value = $wpdb->get_var($query);
2821 2821
 
2822
-		if ( !empty($value) && __( $value, 'wpshop') == __('Yes', 'wpshop') ) {
2822
+		if (!empty($value) && __($value, 'wpshop') == __('Yes', 'wpshop')) {
2823 2823
 			$status = true;
2824 2824
 		}
2825
-		$response = array( 'status' => $status );
2826
-		echo json_encode( $response );
2825
+		$response = array('status' => $status);
2826
+		echo json_encode($response);
2827 2827
 		die();
2828 2828
 	}
2829
-	add_action( 'wp_ajax_show_downloadable_interface_in_admin', 'ajax_wpshop_show_downloadable_interface_in_admin');
2829
+	add_action('wp_ajax_show_downloadable_interface_in_admin', 'ajax_wpshop_show_downloadable_interface_in_admin');
2830 2830
 
2831 2831
 	function ajax_wpshop_restart_the_order() {
2832
-		check_ajax_referer( 'ajax_wpshop_restart_the_order' );
2832
+		check_ajax_referer('ajax_wpshop_restart_the_order');
2833 2833
 
2834 2834
 		global $wpshop_cart, $wpdb;
2835 2835
 		$status = $add_to_cart_checking = $manage_stock_checking_bool = false;
2836 2836
 		$add_to_cart_checking_message = '';
2837 2837
 		$result = __('Error, you cannot restart this order', 'wpshop');
2838
-		$order_id = ( !empty($_POST['order_id']) ) ? (int) $_POST['order_id'] : null;
2839
-		$is_make_order_again = ( !empty($_POST['make_order_again']) ) ? sanitize_text_field( $_POST['make_order_again'] ) : null;
2840
-		if( !empty( $order_id ) ) {
2838
+		$order_id = (!empty($_POST['order_id'])) ? (int)$_POST['order_id'] : null;
2839
+		$is_make_order_again = (!empty($_POST['make_order_again'])) ? sanitize_text_field($_POST['make_order_again']) : null;
2840
+		if (!empty($order_id)) {
2841 2841
 			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
2842 2842
 			$_SESSION['cart'] = array();
2843 2843
 			$_SESSION['cart']['order_items'] = array();
2844 2844
 			$wpshop_cart_type = $order_meta['cart_type'];
2845 2845
 
2846
-			if ( !empty($order_meta) && !empty( $order_meta['order_items']) ) {
2846
+			if (!empty($order_meta) && !empty($order_meta['order_items'])) {
2847 2847
 				$wpshop_cart_type = $order_meta['cart_type'];
2848
-				foreach( $order_meta['order_items'] as $item_key => $item ) {
2849
-					$item_meta = get_post_meta( $item['item_id'], '_wpshop_product_metadata', true );
2848
+				foreach ($order_meta['order_items'] as $item_key => $item) {
2849
+					$item_meta = get_post_meta($item['item_id'], '_wpshop_product_metadata', true);
2850 2850
 					$stock = $item_meta['product_stock'];
2851 2851
 					$qty = $item['item_qty'];
2852
-					$item_option = get_post_meta( $item['item_id'], '_wpshop_product_options', true );
2853
-					if( !empty($item_meta['manage_stock']) ) {
2854
-						$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $item_meta['manage_stock']);
2855
-						$manage_stock_checking = $wpdb->get_var( $query );
2856
-						if( !empty($manage_stock_checking) && strtolower( __( $manage_stock_checking, 'wpshop') ) == strtolower( __( 'Yes', 'wpshop') )  ) {
2852
+					$item_option = get_post_meta($item['item_id'], '_wpshop_product_options', true);
2853
+					if (!empty($item_meta['manage_stock'])) {
2854
+						$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $item_meta['manage_stock']);
2855
+						$manage_stock_checking = $wpdb->get_var($query);
2856
+						if (!empty($manage_stock_checking) && strtolower(__($manage_stock_checking, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
2857 2857
 							$manage_stock_checking_bool = true;
2858 2858
 						}
2859 2859
 					} else {
2860
-						if( get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
2861
-							$parent_product = wpshop_products::get_parent_variation( $item['item_id'] );
2862
-							if( !empty($parent_product) && !empty($parent_product['parent_post_meta']) ) {
2860
+						if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2861
+							$parent_product = wpshop_products::get_parent_variation($item['item_id']);
2862
+							if (!empty($parent_product) && !empty($parent_product['parent_post_meta'])) {
2863 2863
 								$parent_metadata = $parent_product['parent_post_meta'];
2864
-								if( !empty($parent_product['parent_post_meta']['manage_stock']) ) {
2865
-									$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $parent_product['parent_post_meta']['manage_stock']);
2866
-									$manage_stock_checking = $wpdb->get_var( $query );
2867
-									if( !empty($manage_stock_checking) && strtolower( __( $manage_stock_checking, 'wpshop') ) == strtolower( __( 'Yes', 'wpshop') )  ) {
2864
+								if (!empty($parent_product['parent_post_meta']['manage_stock'])) {
2865
+									$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $parent_product['parent_post_meta']['manage_stock']);
2866
+									$manage_stock_checking = $wpdb->get_var($query);
2867
+									if (!empty($manage_stock_checking) && strtolower(__($manage_stock_checking, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
2868 2868
 										$manage_stock_checking_bool = true;
2869 2869
 										$stock = $parent_product['parent_post_meta']['product_stock'];
2870 2870
 									}
@@ -2874,8 +2874,8 @@  discard block
 block discarded – undo
2874 2874
 					}
2875 2875
 
2876 2876
 					/** Checking stock **/
2877
-					if ( empty($item_meta['manage_stock']) || ( !empty($item_meta['manage_stock']) && !$manage_stock_checking_bool )|| ( !empty($item_meta['manage_stock']) && $manage_stock_checking_bool && $stock >= $qty ) ) {
2878
-						$_SESSION['cart']['order_items'][ $item_key ] = $item;
2877
+					if (empty($item_meta['manage_stock']) || (!empty($item_meta['manage_stock']) && !$manage_stock_checking_bool) || (!empty($item_meta['manage_stock']) && $manage_stock_checking_bool && $stock >= $qty)) {
2878
+						$_SESSION['cart']['order_items'][$item_key] = $item;
2879 2879
 					} else {
2880 2880
 						$add_to_cart_checking = true;
2881 2881
 						$add_to_cart_checking_message = __('Some products cannot be added to cart because they are out of stock', 'wpshop');
@@ -2883,40 +2883,40 @@  discard block
 block discarded – undo
2883 2883
 				}
2884 2884
 
2885 2885
 				$wps_cart_ctr = new wps_cart();
2886
-				$order = $wps_cart_ctr->calcul_cart_information( array() );
2886
+				$order = $wps_cart_ctr->calcul_cart_information(array());
2887 2887
 				$order['cart_type'] = $wpshop_cart_type;
2888
-				$wps_cart_ctr->store_cart_in_session( $order );
2888
+				$wps_cart_ctr->store_cart_in_session($order);
2889 2889
 			}
2890 2890
 
2891
-			if ( empty($is_make_order_again) ) {
2891
+			if (empty($is_make_order_again)) {
2892 2892
 				$_SESSION['order_id'] = $order_id;
2893 2893
 			}
2894 2894
 			$status = true;
2895 2895
 
2896
-			$result = get_permalink( get_option('wpshop_cart_page_id') );
2896
+			$result = get_permalink(get_option('wpshop_cart_page_id'));
2897 2897
 		}
2898 2898
 
2899
-		$response = array( 'status' => $status, 'response' => $result, 'add_to_cart_checking' => $add_to_cart_checking, 'add_to_cart_checking_message' => $add_to_cart_checking_message);
2900
-		echo json_encode( $response );
2899
+		$response = array('status' => $status, 'response' => $result, 'add_to_cart_checking' => $add_to_cart_checking, 'add_to_cart_checking_message' => $add_to_cart_checking_message);
2900
+		echo json_encode($response);
2901 2901
 		die();
2902 2902
 	}
2903
-	add_action( 'wp_ajax_restart_the_order', 'ajax_wpshop_restart_the_order');
2903
+	add_action('wp_ajax_restart_the_order', 'ajax_wpshop_restart_the_order');
2904 2904
 
2905 2905
 
2906 2906
 
2907 2907
 	function wps_hide_notice_messages() {
2908
-		check_ajax_referer( 'wps_hide_notice_messages' );
2908
+		check_ajax_referer('wps_hide_notice_messages');
2909 2909
 
2910 2910
 		$status = false;
2911
-		$indicator = !empty($_POST['indicator'] ) ? sanitize_text_field($_POST['indicator']) : null;
2912
-		if ( !empty($indicator) ) {
2911
+		$indicator = !empty($_POST['indicator']) ? sanitize_text_field($_POST['indicator']) : null;
2912
+		if (!empty($indicator)) {
2913 2913
 			$user_id = get_current_user_id();
2914
-			$hide_notice_meta = get_user_meta( $user_id, '_wps_hide_notice_messages_indicator', true);
2914
+			$hide_notice_meta = get_user_meta($user_id, '_wps_hide_notice_messages_indicator', true);
2915 2915
 			$hide_notice_meta = !empty($hide_notice_meta) ? $hide_notice_meta : array();
2916 2916
 			$indicators = explode(',', $indicator);
2917
-			if ( !empty($indicators) && is_array($indicators) ) {
2918
-				foreach( $indicators as $i ) {
2919
-					if ( !empty($i) ) {
2917
+			if (!empty($indicators) && is_array($indicators)) {
2918
+				foreach ($indicators as $i) {
2919
+					if (!empty($i)) {
2920 2920
 						$hide_notice_meta[$i] = true;
2921 2921
 					}
2922 2922
 				}
@@ -2925,7 +2925,7 @@  discard block
 block discarded – undo
2925 2925
 			$status = true;
2926 2926
 		}
2927 2927
 		$response = array('status' => $status);
2928
-		echo json_encode( $response );
2928
+		echo json_encode($response);
2929 2929
 		die();
2930 2930
 	}
2931 2931
 	add_action('wp_ajax_wps_hide_notice_messages', 'wps_hide_notice_messages');
@@ -2933,106 +2933,106 @@  discard block
 block discarded – undo
2933 2933
 
2934 2934
 
2935 2935
 	function wps_update_products_prices() {
2936
-		check_ajax_referer( 'wps_update_products_prices' );
2936
+		check_ajax_referer('wps_update_products_prices');
2937 2937
 		$action = wpshop_prices::mass_update_prices();
2938
-		$response = array( 'status' => $action[0], 'response' => $action[1] );
2939
-		echo json_encode( $response );
2938
+		$response = array('status' => $action[0], 'response' => $action[1]);
2939
+		echo json_encode($response);
2940 2940
 		die();
2941 2941
 	}
2942
-	add_action( 'wp_ajax_update_products_prices', 'wps_update_products_prices' );
2942
+	add_action('wp_ajax_update_products_prices', 'wps_update_products_prices');
2943 2943
 
2944 2944
 	/** Quotation is payable by customer **/
2945 2945
 	function wps_quotation_is_payable_by_customer() {
2946
-		check_ajax_referer( 'wps_quotation_is_payable_by_customer' );
2946
+		check_ajax_referer('wps_quotation_is_payable_by_customer');
2947 2947
 		global $wpdb;
2948 2948
 		$status = false;
2949 2949
 		$response = '';
2950
-		$order_id = ( !empty($_POST['order_id']) ) ? intval( $_POST['order_id'] ) : null;
2951
-		if( isset($order_id) ) {
2952
-			$order_metadata = get_post_meta( $order_id, '_order_postmeta', true );
2953
-			if( isset( $order_metadata['pay_quotation'] ) ) {
2954
-				unset( $order_metadata['pay_quotation'] );
2950
+		$order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null;
2951
+		if (isset($order_id)) {
2952
+			$order_metadata = get_post_meta($order_id, '_order_postmeta', true);
2953
+			if (isset($order_metadata['pay_quotation'])) {
2954
+				unset($order_metadata['pay_quotation']);
2955 2955
 			} else {
2956 2956
 				$order_metadata['pay_quotation'] = 'on';
2957 2957
 			}
2958
-			update_post_meta( $order_id, '_order_postmeta', $order_metadata );
2958
+			update_post_meta($order_id, '_order_postmeta', $order_metadata);
2959 2959
 
2960
-			$response = wpshop_orders::display_customer_pay_quotation( isset( $order_metadata['pay_quotation'] ), $order_id );
2960
+			$response = wpshop_orders::display_customer_pay_quotation(isset($order_metadata['pay_quotation']), $order_id);
2961 2961
 			$status = true;
2962 2962
 		} else {
2963
-			$response = __( 'An error was occured, no Order ID defined', 'wpshop' );
2963
+			$response = __('An error was occured, no Order ID defined', 'wpshop');
2964 2964
 		}
2965
-		echo json_encode( array( 'status' => $status, 'response' => $response) );
2965
+		echo json_encode(array('status' => $status, 'response' => $response));
2966 2966
 		die();
2967 2967
 	}
2968
-	add_action( 'wp_ajax_wps_quotation_is_payable_by_customer', 'wps_quotation_is_payable_by_customer' );
2968
+	add_action('wp_ajax_wps_quotation_is_payable_by_customer', 'wps_quotation_is_payable_by_customer');
2969 2969
 
2970 2970
 	/** Send a direct payment Link **/
2971 2971
 	function wps_send_direct_payment_link() {
2972
-		check_ajax_referer( 'wps_send_direct_payment_link' );
2972
+		check_ajax_referer('wps_send_direct_payment_link');
2973 2973
 		global $wpdb;
2974 2974
 		$status = false; $response = '';
2975
-		$order_id = ( !empty($_POST['order_id']) ) ? (int) $_POST['order_id'] : null;
2976
-		if( !empty($order_id) ) {
2975
+		$order_id = (!empty($_POST['order_id'])) ? (int)$_POST['order_id'] : null;
2976
+		if (!empty($order_id)) {
2977 2977
 			/** Get the customer **/
2978
-			$order_metadata = get_post_meta( $order_id, '_order_postmeta', true );
2979
-			if( !empty($order_metadata) && !empty($order_metadata['customer_id']) && !empty($order_metadata['order_status']) && $order_metadata['order_status'] == 'awaiting_payment' ) {
2980
-				$user_infos = get_userdata( $order_metadata['customer_id'] );
2978
+			$order_metadata = get_post_meta($order_id, '_order_postmeta', true);
2979
+			if (!empty($order_metadata) && !empty($order_metadata['customer_id']) && !empty($order_metadata['order_status']) && $order_metadata['order_status'] == 'awaiting_payment') {
2980
+				$user_infos = get_userdata($order_metadata['customer_id']);
2981 2981
 
2982
-				$first_name =  get_user_meta($user_infos->ID, 'first_name', true);
2983
-				$last_name =  get_user_meta($user_infos->ID, 'last_name', true);
2982
+				$first_name = get_user_meta($user_infos->ID, 'first_name', true);
2983
+				$last_name = get_user_meta($user_infos->ID, 'last_name', true);
2984 2984
 
2985 2985
 
2986 2986
 				/** Create an activation key **/
2987
-				$token = wps_orders_ctr::wps_token_order_customer( $order_id );
2987
+				$token = wps_orders_ctr::wps_token_order_customer($order_id);
2988 2988
 				/*$token = wp_generate_password(20, false);
2989 2989
 				$wpdb->update($wpdb->users, array('user_activation_key' => $token), array('user_login' => $user_infos->user_login) );*/
2990 2990
 
2991
-				$permalink_option = get_option( 'permalink_structure' );
2992
-				$link = '<a href="' . wpshop_checkout::wps_direct_payment_link_url( $order_id ) . '">' .__( 'Click here to pay your order', 'wpshop' ). '</a>';
2991
+				$permalink_option = get_option('permalink_structure');
2992
+				$link = '<a href="' . wpshop_checkout::wps_direct_payment_link_url($order_id) . '">' . __('Click here to pay your order', 'wpshop') . '</a>';
2993 2993
 
2994 2994
 				/** Send message **/
2995 2995
 				$wps_message = new wps_message_ctr();
2996 2996
 				$wps_message->wpshop_prepared_email($user_infos->user_email,
2997 2997
 				'WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE',
2998
-				array( 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'direct_payment_link' => $link, 'order_content' => '' )
2998
+				array('customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'direct_payment_link' => $link, 'order_content' => '')
2999 2999
 				);
3000 3000
 
3001
-				$response = __( 'Direct payment link has been send', 'wpshop' );
3001
+				$response = __('Direct payment link has been send', 'wpshop');
3002 3002
 				$status = true;
3003 3003
 			}
3004 3004
 			else {
3005
-				$response = __( 'An error was occured', 'wpshop' );
3005
+				$response = __('An error was occured', 'wpshop');
3006 3006
 			}
3007 3007
 		}
3008 3008
 		else {
3009
-			$response = __( 'An error was occured, no Order ID defined', 'wpshop' );
3009
+			$response = __('An error was occured, no Order ID defined', 'wpshop');
3010 3010
 		}
3011
-		echo json_encode( array( 'status' => $status, 'response' => $response) );
3011
+		echo json_encode(array('status' => $status, 'response' => $response));
3012 3012
 		die();
3013 3013
 	}
3014
-	add_action( 'wp_ajax_wps_send_direct_payment_link', 'wps_send_direct_payment_link' );
3014
+	add_action('wp_ajax_wps_send_direct_payment_link', 'wps_send_direct_payment_link');
3015 3015
 
3016 3016
 	function wps_mass_action_product() {
3017
-		check_ajax_referer( 'wps_mass_action_product' );
3017
+		check_ajax_referer('wps_mass_action_product');
3018 3018
 		$mass_actions_tools_page = '';
3019
-		$default_attributes = array( 'product_stock', 'barcode', 'product_price', 'special_price', );
3019
+		$default_attributes = array('product_stock', 'barcode', 'product_price', 'special_price',);
3020 3020
 
3021 3021
 		/**	Copy an attribute content to another	*/
3022
-		$attribute_list = wpshop_attributes::getElement(wpshop_entities::get_entity_identifier_from_code( WPSHOP_PRODUCT ), "'valid'", 'entity_id', true);
3023
-		if ( !empty( $attribute_list ) ) {
3022
+		$attribute_list = wpshop_attributes::getElement(wpshop_entities::get_entity_identifier_from_code(WPSHOP_PRODUCT), "'valid'", 'entity_id', true);
3023
+		if (!empty($attribute_list)) {
3024 3024
 			$mass_actions_tools_page .= '
3025
-			<form action="' . admin_url( "admin-ajax.php" ) . '" method="POST" id="wps_mass_action_on_entity_form" >
3025
+			<form action="' . admin_url("admin-ajax.php") . '" method="POST" id="wps_mass_action_on_entity_form" >
3026 3026
 				<input type="hidden" value="wps_mass_action_on_entity_launch" name="action" />
3027
-				<!--<div>' . __( 'Choose attribute to display into list', 'wpshop' ) . '
3027
+				<!--<div>' . __('Choose attribute to display into list', 'wpshop') . '
3028 3028
 					<ul>';
3029
-			foreach ( $attribute_list as $attribute ) {
3029
+			foreach ($attribute_list as $attribute) {
3030 3030
 				$mass_actions_tools_page .= '
3031
-						<li style="display:inline-block; width:10%;" ><input type="checkbox"' . checked( in_array( $attribute->code, $default_attributes ), true, false ) . ' name="wps_tools_mass_action_on_element[]" value="' . $attribute->id . '" />' . __( $attribute->frontend_label, 'wpshop' ) . '</li>';
3031
+						<li style="display:inline-block; width:10%;" ><input type="checkbox"' . checked(in_array($attribute->code, $default_attributes), true, false) . ' name="wps_tools_mass_action_on_element[]" value="' . $attribute->id . '" />' . __($attribute->frontend_label, 'wpshop') . '</li>';
3032 3032
 			}
3033 3033
 			$mass_actions_tools_page .= '
3034 3034
 					</ul>
3035
-					<button>' . __( 'Voir la liste des produits', 'wpshop' ) . '</button> -->
3035
+					<button>' . __('Voir la liste des produits', 'wpshop') . '</button> -->
3036 3036
 				</div>
3037 3037
 			</form>
3038 3038
 			<div id="wps_entity_list" >' . wps_mass_action_on_entity_launch() . '</div>
@@ -3045,32 +3045,32 @@  discard block
 block discarded – undo
3045 3045
 			</script>';
3046 3046
 		}
3047 3047
 
3048
-		wp_die( $mass_actions_tools_page );
3048
+		wp_die($mass_actions_tools_page);
3049 3049
 	}
3050
-	add_action( 'wp_ajax_wps_mass_action_product', 'wps_mass_action_product' );
3050
+	add_action('wp_ajax_wps_mass_action_product', 'wps_mass_action_product');
3051 3051
 
3052 3052
 	function wps_put_history_back() {
3053
-		check_ajax_referer( 'wps_put_history_back' );
3053
+		check_ajax_referer('wps_put_history_back');
3054 3054
 
3055 3055
 		global $wpdb;
3056 3056
 		$upload_dir = wp_upload_dir();
3057
-		$log_dir = $upload_dir[ 'basedir' ] . '/wps_repair/';
3058
-		wp_mkdir_p( $log_dir );
3059
-		$value_to_take = !empty($_POST[ 'value_to_take' ]) ? (array) $_POST[ 'value_to_take' ] : array();
3060
-		foreach ( $value_to_take as $product_id => $product_element ) {
3061
-			foreach( $product_element as $attribute_id => $attribute_value_to_take ){
3062
-				$query = $wpdb->prepare( "SELECT value, value_type FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO . " WHERE value_id = %d", $attribute_value_to_take );
3063
-				$the_new_value = $wpdb->get_row( $query );
3064
-				if ( 6 == $attribute_id ) {
3065
-					$query = $wpdb->prepare( "SELECT OPT.value, HISTO.value AS rate_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO . " AS HISTO ON ( ( HISTO.attribute_id = OPT.attribute_id ) AND ( HISTO.value = OPT.id ) ) WHERE HISTO.attribute_id = 29 AND HISTO.entity_id = %d ORDER BY HISTO.creation_date_value DESC LIMIT 1", $product_id );
3066
-					$the_tax = $wpdb->get_row( $query );
3067
-					$pttc = number_format( $the_new_value->value, 5, ".", " " );
3068
-					$ht = number_format( $pttc / ( 1 + ( $the_tax->value / 100 ) ), 5, ".", " " );
3069
-					$tax_amount = number_format( $pttc - $ht, 5, ".", " " );
3070
-					$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array( "entity_id" => $product_id, "attribute_id" => 6 ) );
3071
-					$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array( "entity_id" => $product_id, "attribute_id" => 28 ) );
3072
-					$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array( "entity_id" => $product_id, "attribute_id" => 29 ) );
3073
-					$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array( "entity_id" => $product_id, "attribute_id" => 30 ) );
3057
+		$log_dir = $upload_dir['basedir'] . '/wps_repair/';
3058
+		wp_mkdir_p($log_dir);
3059
+		$value_to_take = !empty($_POST['value_to_take']) ? (array)$_POST['value_to_take'] : array();
3060
+		foreach ($value_to_take as $product_id => $product_element) {
3061
+			foreach ($product_element as $attribute_id => $attribute_value_to_take) {
3062
+				$query = $wpdb->prepare("SELECT value, value_type FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO . " WHERE value_id = %d", $attribute_value_to_take);
3063
+				$the_new_value = $wpdb->get_row($query);
3064
+				if (6 == $attribute_id) {
3065
+					$query = $wpdb->prepare("SELECT OPT.value, HISTO.value AS rate_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO . " AS HISTO ON ( ( HISTO.attribute_id = OPT.attribute_id ) AND ( HISTO.value = OPT.id ) ) WHERE HISTO.attribute_id = 29 AND HISTO.entity_id = %d ORDER BY HISTO.creation_date_value DESC LIMIT 1", $product_id);
3066
+					$the_tax = $wpdb->get_row($query);
3067
+					$pttc = number_format($the_new_value->value, 5, ".", " ");
3068
+					$ht = number_format($pttc / (1 + ($the_tax->value / 100)), 5, ".", " ");
3069
+					$tax_amount = number_format($pttc - $ht, 5, ".", " ");
3070
+					$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array("entity_id" => $product_id, "attribute_id" => 6));
3071
+					$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array("entity_id" => $product_id, "attribute_id" => 28));
3072
+					$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array("entity_id" => $product_id, "attribute_id" => 29));
3073
+					$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array("entity_id" => $product_id, "attribute_id" => 30));
3074 3074
 
3075 3075
 					$common_datas = array(
3076 3076
 						'value_id' => null,
@@ -3078,20 +3078,20 @@  discard block
 block discarded – undo
3078 3078
 						'entity_id' => $product_id,
3079 3079
 						'unit_id' => null,
3080 3080
 						'user_id' => 1,
3081
-						'creation_date_value' => current_time( "mysql", 0 ),
3081
+						'creation_date_value' => current_time("mysql", 0),
3082 3082
 						'language' => 'fr_FR',
3083 3083
 					);
3084 3084
 
3085
-					$content_to_write =  "
3086
-" . mysql2date( "d/m/Y H:i", current_time( 'mysql', 0 ), true ) . ' - ' . $product_id . ' - ' . serialize( $common_datas ) . ' - ' . serialize( array( 'ttc' => $pttc,  'ht' => $ht,  'tax_rate_id' => $the_tax->rate_id,  'tax_amount' => $tax_amount,  ) );
3087
-					$fp = fopen( $log_dir . 'correction_prix.txt', 'a' );
3088
-					fwrite( $fp, $content_to_write );
3089
-					fclose( $fp );
3085
+					$content_to_write = "
3086
+" . mysql2date("d/m/Y H:i", current_time('mysql', 0), true) . ' - ' . $product_id . ' - ' . serialize($common_datas) . ' - ' . serialize(array('ttc' => $pttc, 'ht' => $ht, 'tax_rate_id' => $the_tax->rate_id, 'tax_amount' => $tax_amount,));
3087
+					$fp = fopen($log_dir . 'correction_prix.txt', 'a');
3088
+					fwrite($fp, $content_to_write);
3089
+					fclose($fp);
3090 3090
 
3091
-					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge( $common_datas, array( 'attribute_id' => 6, 'value' => $pttc ) ) );
3092
-					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge( $common_datas, array( 'attribute_id' => 28, 'value' => $ht ) ) );
3093
-					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array_merge( $common_datas, array( 'attribute_id' => 29, 'value' => $the_tax->rate_id ) ) );
3094
-					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge( $common_datas, array( 'attribute_id' => 30, 'value' => $tax_amount ) ) );
3091
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge($common_datas, array('attribute_id' => 6, 'value' => $pttc)));
3092
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge($common_datas, array('attribute_id' => 28, 'value' => $ht)));
3093
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array_merge($common_datas, array('attribute_id' => 29, 'value' => $the_tax->rate_id)));
3094
+					$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge($common_datas, array('attribute_id' => 30, 'value' => $tax_amount)));
3095 3095
 				}
3096 3096
 				else {
3097 3097
 					$common_datas = array(
@@ -3100,33 +3100,33 @@  discard block
 block discarded – undo
3100 3100
 						'entity_id' => $product_id,
3101 3101
 						'unit_id' => null,
3102 3102
 						'user_id' => 1,
3103
-						'creation_date_value' => current_time( "mysql", 0 ),
3103
+						'creation_date_value' => current_time("mysql", 0),
3104 3104
 						'language' => 'fr_FR',
3105 3105
 					);
3106
-					$wpdb->delete( $the_new_value->value_type, array( "entity_id" => $product_id, "attribute_id" => $attribute_id ) );
3107
-					$wpdb->insert( $the_new_value->value_type, array_merge( $common_datas, array( 'attribute_id' => $attribute_id, 'value' => trim( $the_new_value->value ) ) ) );
3108
-
3109
-					$content_to_write =  "
3110
-" . mysql2date( "d/m/Y H:i", current_time( 'mysql', 0 ), true ) . ' - ' . $product_id . ' - ' . serialize( $common_datas ) . ' - ' . serialize( array( 'attribute_id' => $attribute_id, 'value' => trim( $the_new_value->value ),  ) ). '';
3111
-					$fp = fopen( $log_dir . 'correction_attribut.txt', 'a' );
3112
-					fwrite( $fp, $content_to_write );
3113
-					fclose( $fp );
3106
+					$wpdb->delete($the_new_value->value_type, array("entity_id" => $product_id, "attribute_id" => $attribute_id));
3107
+					$wpdb->insert($the_new_value->value_type, array_merge($common_datas, array('attribute_id' => $attribute_id, 'value' => trim($the_new_value->value))));
3108
+
3109
+					$content_to_write = "
3110
+" . mysql2date("d/m/Y H:i", current_time('mysql', 0), true) . ' - ' . $product_id . ' - ' . serialize($common_datas) . ' - ' . serialize(array('attribute_id' => $attribute_id, 'value' => trim($the_new_value->value),)) . '';
3111
+					$fp = fopen($log_dir . 'correction_attribut.txt', 'a');
3112
+					fwrite($fp, $content_to_write);
3113
+					fclose($fp);
3114 3114
 				}
3115 3115
 			}
3116 3116
 		}
3117 3117
 		wp_die();
3118 3118
 	}
3119
-	add_action( 'wp_ajax_wps_put_history_back', 'wps_put_history_back' );
3119
+	add_action('wp_ajax_wps_put_history_back', 'wps_put_history_back');
3120 3120
 
3121 3121
 	function wps_mass_action_on_entity_launch() {
3122 3122
 		global $wpdb;
3123 3123
 		$response = '';
3124 3124
 		$element_to_output = array();
3125 3125
 
3126
-		$attributes_to_test = array( 'decimal' => '6,36', 'varchar' => '12', 'integer' => '85', 'text' => '120, 118' );
3126
+		$attributes_to_test = array('decimal' => '6,36', 'varchar' => '12', 'integer' => '85', 'text' => '120, 118');
3127 3127
 
3128 3128
 		$decimal_attribute = $attributes_to_test['decimal']; //,30,28
3129
-		$query = $wpdb->prepare( "
3129
+		$query = $wpdb->prepare("
3130 3130
 				SELECT P.ID, P.post_title,
3131 3131
 					D.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value
3132 3132
 				FROM {$wpdb->posts} AS P
@@ -3140,21 +3140,21 @@  discard block
 block discarded – undo
3140 3140
 					AND H.value_type = %s
3141 3141
 
3142 3142
 				ORDER BY H.entity_id ASC, H.value_id DESC",
3143
-			array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL )
3143
+			array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL)
3144 3144
 		);
3145
-		 $list_of_element = $wpdb->get_results( $query );
3146
-		 if ( !empty( $list_of_element ) ) {
3147
-			foreach ( $list_of_element as $element ) {
3148
-				$element_to_output[ $element->ID ][ 'title' ] = $element->post_title;
3149
-				$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'current' ] = $element->current_value;
3150
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_id' ] = $element->value_id;
3151
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_date' ] = $element->creation_date;
3152
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value' ] = $element->last_history_value;
3145
+		 $list_of_element = $wpdb->get_results($query);
3146
+		 if (!empty($list_of_element)) {
3147
+			foreach ($list_of_element as $element) {
3148
+				$element_to_output[$element->ID]['title'] = $element->post_title;
3149
+				$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
3150
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
3151
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
3152
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
3153 3153
 			}
3154 3154
 		}
3155 3155
 
3156 3156
 		$attribute_list = $attributes_to_test['varchar'];
3157
-		$query = $wpdb->prepare( "
3157
+		$query = $wpdb->prepare("
3158 3158
 			SELECT P.ID, P.post_title,
3159 3159
 				D.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value
3160 3160
 			FROM {$wpdb->posts} AS P
@@ -3167,22 +3167,22 @@  discard block
 block discarded – undo
3167 3167
 				AND H.value != ''
3168 3168
 				AND H.value_type = %s
3169 3169
 			ORDER BY H.creation_date",
3170
-			array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR )
3170
+			array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR)
3171 3171
 		);
3172
-		$list_of_element = $wpdb->get_results( $query );
3173
-		if ( !empty( $list_of_element ) ) {
3174
-			foreach ( $list_of_element as $element ) {
3175
-			 	$element_to_output[ $element->ID ][ 'title' ] = $element->post_title;
3176
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'current' ] = $element->current_value;
3177
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_id' ] = $element->value_id;
3178
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_date' ] = $element->creation_date;
3179
-			 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value' ] = $element->last_history_value;
3172
+		$list_of_element = $wpdb->get_results($query);
3173
+		if (!empty($list_of_element)) {
3174
+			foreach ($list_of_element as $element) {
3175
+			 	$element_to_output[$element->ID]['title'] = $element->post_title;
3176
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
3177
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
3178
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
3179
+			 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
3180 3180
 			}
3181 3181
 		}
3182 3182
 
3183 3183
 
3184 3184
 		$attribute_list = $attributes_to_test['text'];
3185
-		$query = $wpdb->prepare( "
3185
+		$query = $wpdb->prepare("
3186 3186
 				SELECT P.ID, P.post_title,
3187 3187
 				D.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value
3188 3188
 				FROM {$wpdb->posts} AS P
@@ -3195,21 +3195,21 @@  discard block
 block discarded – undo
3195 3195
 				AND H.value != ''
3196 3196
 				AND H.value_type = %s
3197 3197
 			ORDER BY H.creation_date",
3198
-			array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT )
3198
+			array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT)
3199 3199
 		);
3200
-		$list_of_element = $wpdb->get_results( $query );
3201
-		if ( !empty( $list_of_element ) ) {
3202
-		foreach ( $list_of_element as $element ) {
3203
-		 	$element_to_output[ $element->ID ][ 'title' ] = $element->post_title;
3204
-		 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'current' ] = $element->current_value;
3205
-		 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_id' ] = $element->value_id;
3206
-		 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_date' ] = $element->creation_date;
3207
-		 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value' ] = $element->last_history_value;
3200
+		$list_of_element = $wpdb->get_results($query);
3201
+		if (!empty($list_of_element)) {
3202
+		foreach ($list_of_element as $element) {
3203
+		 	$element_to_output[$element->ID]['title'] = $element->post_title;
3204
+		 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
3205
+		 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
3206
+		 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
3207
+		 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
3208 3208
 		 	}
3209 3209
 		}
3210 3210
 
3211 3211
 		$attribute_list = $attributes_to_test['integer'];
3212
-		$query = $wpdb->prepare( "
3212
+		$query = $wpdb->prepare("
3213 3213
 				SELECT P.ID, P.post_title,
3214 3214
 				D.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value
3215 3215
 				FROM {$wpdb->posts} AS P
@@ -3222,21 +3222,21 @@  discard block
 block discarded – undo
3222 3222
 				AND H.value != ''
3223 3223
 				AND H.value_type = %s
3224 3224
 			ORDER BY H.creation_date",
3225
-			array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER )
3225
+			array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish", WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER)
3226 3226
 		);
3227
-							$list_of_element = $wpdb->get_results( $query );
3228
-							if ( !empty( $list_of_element ) ) {
3229
-							foreach ( $list_of_element as $element ) {
3230
-					 	$element_to_output[ $element->ID ][ 'title' ] = $element->post_title;
3231
-					 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'current' ] = $element->current_value;
3232
-					 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_id' ] = $element->value_id;
3233
-					 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value_date' ] = $element->creation_date;
3234
-					 	$element_to_output[ $element->ID ][ 'content' ][ $element->attribute_id ][ $element->creation_date ][ 'histo' ][ 'value' ] = $element->last_history_value;
3227
+							$list_of_element = $wpdb->get_results($query);
3228
+							if (!empty($list_of_element)) {
3229
+							foreach ($list_of_element as $element) {
3230
+					 	$element_to_output[$element->ID]['title'] = $element->post_title;
3231
+					 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
3232
+					 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
3233
+					 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
3234
+					 	$element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
3235 3235
 					 	}
3236 3236
 							}
3237 3237
 
3238 3238
 		$array_done = array();
3239
-		if ( !empty( $element_to_output ) ) {
3239
+		if (!empty($element_to_output)) {
3240 3240
 			$lines = '';
3241 3241
 			$done_header = array();
3242 3242
 
@@ -3244,23 +3244,23 @@  discard block
 block discarded – undo
3244 3244
 			/** Formate informations **/
3245 3245
 			$formatted_datas = array();
3246 3246
 			$controller_rows_array = array();
3247
-			foreach( $attributes_to_test as $attribute_to_test ) {
3248
-				$atts = explode( ',', $attribute_to_test );
3249
-				foreach( $atts as $att ) {
3250
-					$controller_rows_array[ $att ] = false;
3247
+			foreach ($attributes_to_test as $attribute_to_test) {
3248
+				$atts = explode(',', $attribute_to_test);
3249
+				foreach ($atts as $att) {
3250
+					$controller_rows_array[$att] = false;
3251 3251
 				}
3252 3252
 			}
3253 3253
 
3254
-			foreach(  $element_to_output as $element_id => $element_definition ) {
3254
+			foreach ($element_to_output as $element_id => $element_definition) {
3255 3255
 				$formatted_datas[$element_id]['title'] = $element_definition['title'];
3256 3256
 				$formatted_datas[$element_id]['content'] = array();
3257 3257
 
3258
-				foreach( $attributes_to_test as $attribute_to_test ) {
3259
-					$atts = explode( ',', $attribute_to_test );
3260
-					foreach( $atts as $att ) {
3261
-						if( !empty($element_definition['content'][$att]) ) {
3258
+				foreach ($attributes_to_test as $attribute_to_test) {
3259
+					$atts = explode(',', $attribute_to_test);
3260
+					foreach ($atts as $att) {
3261
+						if (!empty($element_definition['content'][$att])) {
3262 3262
 							$formatted_datas[$element_id]['content'][$att] = $element_definition['content'][$att];
3263
-							$controller_rows_array[ $att ] = true;
3263
+							$controller_rows_array[$att] = true;
3264 3264
 						}
3265 3265
 						else {
3266 3266
 							$formatted_datas[$element_id]['content'][$att] = array();
@@ -3269,39 +3269,39 @@  discard block
 block discarded – undo
3269 3269
 				}
3270 3270
 			}
3271 3271
 
3272
-			foreach ( $formatted_datas as $element_id => $element_definition ) {
3273
-				if ( !in_array( $element_id, $array_done ) ) {
3274
-					$lines .= '<tr  style="border:1px solid black;"><td  style="border:1px solid black;" >#' . $element_id . ' - ' . $element_definition[ 'title' ] . '</td>';
3275
-					ksort( $element_definition[ 'content' ] );
3276
-					foreach ( $element_definition[ 'content' ] as $atribute_id => $value_on_date ) {
3277
-						if( $controller_rows_array[$atribute_id] ) {
3278
-							$current_attribute = wpshop_attributes::getElement( $atribute_id );
3279
-							if ( !in_array( $atribute_id, $done_header ) ) {
3280
-								$more_header .= '<td style="border:1px solid black;" >' . __( $current_attribute->frontend_label, 'wpshop' ) . '</td>';
3272
+			foreach ($formatted_datas as $element_id => $element_definition) {
3273
+				if (!in_array($element_id, $array_done)) {
3274
+					$lines .= '<tr  style="border:1px solid black;"><td  style="border:1px solid black;" >#' . $element_id . ' - ' . $element_definition['title'] . '</td>';
3275
+					ksort($element_definition['content']);
3276
+					foreach ($element_definition['content'] as $atribute_id => $value_on_date) {
3277
+						if ($controller_rows_array[$atribute_id]) {
3278
+							$current_attribute = wpshop_attributes::getElement($atribute_id);
3279
+							if (!in_array($atribute_id, $done_header)) {
3280
+								$more_header .= '<td style="border:1px solid black;" >' . __($current_attribute->frontend_label, 'wpshop') . '</td>';
3281 3281
 								$done_header[] = $atribute_id;
3282 3282
 							}
3283 3283
 							$last_value = 'XXXXX';
3284 3284
 							$counter_for_line = 0;
3285 3285
 							$content_line = '';
3286
-							foreach ( $value_on_date as $date => $value ) {
3287
-								if ( $value[ 'histo' ][ 'value' ] != $last_value ) {
3288
-									$current_val = $value[ 'current' ];
3289
-									$old_val = $value[ 'histo' ][ 'value' ];
3286
+							foreach ($value_on_date as $date => $value) {
3287
+								if ($value['histo']['value'] != $last_value) {
3288
+									$current_val = $value['current'];
3289
+									$old_val = $value['histo']['value'];
3290 3290
 									// Test if attribute data Type is integer
3291
-									if ( $current_attribute->data_type == 'integer' ) {
3292
-										if( $current_attribute->data_type_to_use == 'internal' ) {
3291
+									if ($current_attribute->data_type == 'integer') {
3292
+										if ($current_attribute->data_type_to_use == 'internal') {
3293 3293
 											$current_val = get_the_title($current_val);
3294 3294
 											$old_val = get_the_title($old_val);
3295 3295
 										}
3296 3296
 										else {
3297
-											$query = $wpdb->prepare( 'SELECT label FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS.' WHERE id=%d', $old_val);
3298
-											$old_val = $wpdb->get_var( $query );
3299
-											$query = $wpdb->prepare( 'SELECT label FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS.' WHERE id=%d', $current_val);
3300
-											$current_val = $wpdb->get_var( $query );
3297
+											$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $old_val);
3298
+											$old_val = $wpdb->get_var($query);
3299
+											$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $current_val);
3300
+											$current_val = $wpdb->get_var($query);
3301 3301
 										}
3302 3302
 									}
3303
-									$content_line .= '<label ><input type="radio" name="value_to_take[' . $element_id . '][' . $atribute_id . ']" value="' . $value[ 'histo' ][ 'value_id' ] . '"' . checked( ( 0 == $counter_for_line ? true : false), true, false ) . '/>' . __( 'Current value', 'wpshop' ) . ' : ' .$current_val. ' / ' . __( 'Last value', 'wpshop' ) . ' : ' .$old_val. '</label><br/>';
3304
-									$last_value = $value[ 'histo' ][ 'value' ];
3303
+									$content_line .= '<label ><input type="radio" name="value_to_take[' . $element_id . '][' . $atribute_id . ']" value="' . $value['histo']['value_id'] . '"' . checked((0 == $counter_for_line ? true : false), true, false) . '/>' . __('Current value', 'wpshop') . ' : ' . $current_val . ' / ' . __('Last value', 'wpshop') . ' : ' . $old_val . '</label><br/>';
3304
+									$last_value = $value['histo']['value'];
3305 3305
 									$counter_for_line++;
3306 3306
 								}
3307 3307
 							}
@@ -3311,16 +3311,16 @@  discard block
 block discarded – undo
3311 3311
 						}
3312 3312
 					}
3313 3313
 					$lines .= '</tr>';
3314
-					$array_done[ $element_id ];
3314
+					$array_done[$element_id];
3315 3315
 				}
3316 3316
 			}
3317 3317
 
3318 3318
 			$response = '
3319
-				<form action="' . admin_url( 'admin-ajax.php' ) . '" method="POST" id="wps_put_histo_back" >
3319
+				<form action="' . admin_url('admin-ajax.php') . '" method="POST" id="wps_put_histo_back" >
3320 3320
 					<input type="text" name="action" value="wps_put_history_back" />
3321
-					' . wp_nonce_field( 'wps_put_history_back' ) . '
3321
+					' . wp_nonce_field('wps_put_history_back') . '
3322 3322
 					<table style="border-collapse: collapse;border:1px solid black;" cellpadding="0" cellspacing="0" >
3323
-						<tr style="border:1px solid black;"><td style="border:1px solid black;" >' . __( 'Product', 'wpshop' ) . '</td>'.$more_header.'</tr>
3323
+						<tr style="border:1px solid black;"><td style="border:1px solid black;" >' . __('Product', 'wpshop') . '</td>' . $more_header . '</tr>
3324 3324
 						' . $lines . '
3325 3325
 					</table>
3326 3326
 				</form><script type="text/javascript" >
@@ -3337,36 +3337,36 @@  discard block
 block discarded – undo
3337 3337
 
3338 3338
 
3339 3339
 	function wps_delete_picture_category() {
3340
-		check_ajax_referer( 'wps_delete_picture_category' );
3340
+		check_ajax_referer('wps_delete_picture_category');
3341 3341
 		$status = false; $response = '';
3342
-		$cat_id = ( !empty($_POST['cat_id']) ) ? (int) $_POST['cat_id'] : null;
3343
-		if( !empty($cat_id) ) {
3342
+		$cat_id = (!empty($_POST['cat_id'])) ? (int)$_POST['cat_id'] : null;
3343
+		if (!empty($cat_id)) {
3344 3344
 			// Get Category option
3345
-			$category_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $cat_id );
3346
-			if( !empty($category_option) && !empty($category_option['wpshop_category_picture']) ) {
3347
-				unset( $category_option['wpshop_category_picture'] );
3348
-				update_option( WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $cat_id, $category_option );
3349
-				$response = '<img src="' .WPSHOP_DEFAULT_CATEGORY_PICTURE. '" alt="No picture" class="category_thumbnail_preview"/>';
3345
+			$category_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $cat_id);
3346
+			if (!empty($category_option) && !empty($category_option['wpshop_category_picture'])) {
3347
+				unset($category_option['wpshop_category_picture']);
3348
+				update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $cat_id, $category_option);
3349
+				$response = '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail_preview"/>';
3350 3350
 				$status = true;
3351 3351
 			}
3352 3352
 			else {
3353
-				$response = __( 'Category options are not defined', 'wpshop');
3353
+				$response = __('Category options are not defined', 'wpshop');
3354 3354
 			}
3355 3355
 		}
3356 3356
 		else {
3357
-			$response = __( 'Category ID is not defined', 'wpshop');
3357
+			$response = __('Category ID is not defined', 'wpshop');
3358 3358
 		}
3359
-		echo json_encode( array( 'status' => $status, 'response' => $response) );
3359
+		echo json_encode(array('status' => $status, 'response' => $response));
3360 3360
 		wp_die();
3361 3361
 	}
3362
-	add_action( 'wp_ajax_wps_delete_picture_category', 'wps_delete_picture_category' );
3362
+	add_action('wp_ajax_wps_delete_picture_category', 'wps_delete_picture_category');
3363 3363
 
3364 3364
 	/* EAV */
3365 3365
 
3366 3366
 	/* ATTRIBUTES SET */
3367 3367
 
3368 3368
 	function saveNewAttributeSetSection() {
3369
-		check_ajax_referer( 'saveNewAttributeSetSection' );
3369
+		check_ajax_referer('saveNewAttributeSetSection');
3370 3370
 		global $wpdb;
3371 3371
 		$attributeSetSectionName = sanitize_text_field($_REQUEST['attributeSetSectionName']);
3372 3372
 		$elementIdentifier = (int)$_REQUEST['elementIdentifier'];
@@ -3374,37 +3374,37 @@  discard block
 block discarded – undo
3374 3374
 		$attributeSetInfos['id'] = '';
3375 3375
 		$attributeSetInfos['status'] = 'valid';
3376 3376
 		$attributeSetInfos['attribute_set_id'] = $elementIdentifier;
3377
-		$query = $wpdb->prepare("SELECT MAX(position) + 1 AS LAST_GROUP_POSITION FROM ". WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %s", $elementIdentifier);
3377
+		$query = $wpdb->prepare("SELECT MAX(position) + 1 AS LAST_GROUP_POSITION FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %s", $elementIdentifier);
3378 3378
 		$attributeSetInfos['position'] = $wpdb->get_var($query);
3379 3379
 		$attributeSetInfos['creation_date'] = date('Y-m-d H:i:s');
3380 3380
 		$attributeSetInfos['code'] = wpshop_tools::slugify($attributeSetSectionName, array('noAccent', 'noSpaces', 'lowerCase'));
3381 3381
 		$attributeSetInfos['name'] = $attributeSetSectionName;
3382 3382
 
3383
-		$more_script='';
3383
+		$more_script = '';
3384 3384
 		$attributeSetSectionCreation = wpshop_database::save($attributeSetInfos, WPSHOP_DBT_ATTRIBUTE_GROUP);
3385
-		if ( $attributeSetSectionCreation == 'done' ) {
3385
+		if ($attributeSetSectionCreation == 'done') {
3386 3386
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('New section has been created successfully', 'wpshop');
3387
-			$more_script = 'wpshop_go_to("#attribute_group_'.$wpdb->insert_id.'")';
3387
+			$more_script = 'wpshop_go_to("#attribute_group_' . $wpdb->insert_id . '")';
3388 3388
 		}
3389 3389
 		else {
3390 3390
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while saving new section', 'wpshop');
3391 3391
 		}
3392 3392
 
3393
-		$script = '<script type="text/javascript" >wpshop(document).ready(function(){	jQuery("#wpshop_new_set_section_add").dialog("close");jQuery("#wpshop_new_set_section_add").children("img").hide(); });wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);'.$more_script.'</script>';
3394
-		wp_die( wpshop_attributes_set::attributeSetDetailsManagement($elementIdentifier) . $script );
3393
+		$script = '<script type="text/javascript" >wpshop(document).ready(function(){	jQuery("#wpshop_new_set_section_add").dialog("close");jQuery("#wpshop_new_set_section_add").children("img").hide(); });wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);' . $more_script . '</script>';
3394
+		wp_die(wpshop_attributes_set::attributeSetDetailsManagement($elementIdentifier) . $script);
3395 3395
 	}
3396
-	add_action( 'wp_ajax_wps_attribute_set_section_new', 'saveNewAttributeSetSection' );
3396
+	add_action('wp_ajax_wps_attribute_set_section_new', 'saveNewAttributeSetSection');
3397 3397
 
3398 3398
 	function editAttributeSetSection() {
3399
-		check_ajax_referer( 'editAttributeSetSection' );
3399
+		check_ajax_referer('editAttributeSetSection');
3400 3400
 		$attributeSetSectionName = sanitize_title($_REQUEST['attributeSetSectionName']);
3401 3401
 		$attributeSetSectionId = sanitize_key($_REQUEST['attributeSetSectionId']);
3402 3402
 		$attributeSetSectionDefault = sanitize_text_field($_REQUEST['attributeSetSectionDefault']);
3403 3403
 		$backend_display_type = sanitize_text_field($_REQUEST['attributeSetSectionDisplayType']);
3404 3404
 		$display_on_frontend = sanitize_text_field($_REQUEST['attributeSetSectionDisplayinFrontEnd']);
3405
-		$backend_display_type = in_array($backend_display_type, array('movable-tab','fixed-tab')) ? $backend_display_type : 'fixed-tab';
3405
+		$backend_display_type = in_array($backend_display_type, array('movable-tab', 'fixed-tab')) ? $backend_display_type : 'fixed-tab';
3406 3406
 
3407
-		if($attributeSetSectionDefault == 'yes'){
3407
+		if ($attributeSetSectionDefault == 'yes') {
3408 3408
 			$wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, array('last_update_date' => current_time('mysql', 0), 'default_group' => 'no'), array('attribute_set_id' => $elementIdentifier));
3409 3409
 		}
3410 3410
 		$attributeSetInfos = array();
@@ -3414,18 +3414,18 @@  discard block
 block discarded – undo
3414 3414
 		$attributeSetInfos['backend_display_type'] = $backend_display_type;
3415 3415
 		$attributeSetInfos['display_on_frontend'] = $display_on_frontend;
3416 3416
 		$attributeSetSectionCreation = wpshop_database::update($attributeSetInfos, $attributeSetSectionId, WPSHOP_DBT_ATTRIBUTE_GROUP);
3417
-		if ( $attributeSetSectionCreation == 'done' )
3417
+		if ($attributeSetSectionCreation == 'done')
3418 3418
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been updated successfully', 'wpshop');
3419 3419
 		else
3420 3420
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while updating the section', 'wpshop');
3421 3421
 		echo wpshop_attributes_set::attributeSetDetailsManagement($elementIdentifier) . '<script type="text/javascript" >wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);</script>';
3422 3422
 		wp_die();
3423 3423
 	}
3424
-	add_action( 'wp_ajax_wps_attribute_set_section_edit', 'editAttributeSetSection' );
3424
+	add_action('wp_ajax_wps_attribute_set_section_edit', 'editAttributeSetSection');
3425 3425
 
3426 3426
 	function deleteAttributeSetSection() {
3427
-		check_ajax_referer( 'deleteAttributeSetSection' );
3428
-		$attributeSetSectionId = (int) $_REQUEST['attributeSetSectionId'];
3427
+		check_ajax_referer('deleteAttributeSetSection');
3428
+		$attributeSetSectionId = (int)$_REQUEST['attributeSetSectionId'];
3429 3429
 		$attributeSetInfos = array();
3430 3430
 		$attributeSetInfos['status'] = 'deleted';
3431 3431
 		$attributeSetInfos['last_update_date'] = current_time('mysql', 0);
@@ -3434,21 +3434,21 @@  discard block
 block discarded – undo
3434 3434
 		$attributeSetSectionCreation = wpshop_database::update($attributeSetInfos, $attributeSetSectionId, WPSHOP_DBT_ATTRIBUTE_GROUP);
3435 3435
 
3436 3436
 		$more_script = '';
3437
-		if ( $attributeSetSectionCreation == 'done' ) {
3437
+		if ($attributeSetSectionCreation == 'done') {
3438 3438
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been successfully been deleted', 'wpshop');
3439
-			$more_script.='jQuery("#attribute_group_'.$attributeSetSectionId.'").remove();';
3439
+			$more_script .= 'jQuery("#attribute_group_' . $attributeSetSectionId . '").remove();';
3440 3440
 		}
3441 3441
 		else
3442 3442
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while deleting the section', 'wpshop');
3443
-		echo '<script type="text/javascript" >wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);'.$more_script.'</script>';
3443
+		echo '<script type="text/javascript" >wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);' . $more_script . '</script>';
3444 3444
 		wp_die();
3445 3445
 	}
3446
-	add_action( 'wp_ajax_wps_attribute_set_section_delete', 'deleteAttributeSetSection' );
3446
+	add_action('wp_ajax_wps_attribute_set_section_delete', 'deleteAttributeSetSection');
3447 3447
 
3448 3448
 	/* ATTRIBUTES UNIT */
3449 3449
 
3450 3450
 	function load_unit_interface() {
3451
-		check_ajax_referer( 'load_unit_interface' );
3451
+		check_ajax_referer('load_unit_interface');
3452 3452
 		?>
3453 3453
 		<div id="wpshop_unit_main_listing_interface">
3454 3454
 			<div class="wpshop_full_page_tabs">
@@ -3467,28 +3467,28 @@  discard block
 block discarded – undo
3467 3467
 
3468 3468
 		wp_die();
3469 3469
 	}
3470
-	add_action( 'wp_ajax_wps_attribute_unit_interface', 'load_unit_interface' );
3470
+	add_action('wp_ajax_wps_attribute_unit_interface', 'load_unit_interface');
3471 3471
 
3472 3472
 	function load_attribute_units() {
3473
-		check_ajax_referer( 'load_attribute_units' );
3474
-		wp_die( wpshop_attributes_unit::elementList() );
3473
+		check_ajax_referer('load_attribute_units');
3474
+		wp_die(wpshop_attributes_unit::elementList());
3475 3475
 	}
3476
-	add_action( 'wp_ajax_wps_attribute_unit_load', 'load_attribute_units' );
3476
+	add_action('wp_ajax_wps_attribute_unit_load', 'load_attribute_units');
3477 3477
 
3478 3478
 	function add_attribute_unit() {
3479
-		check_ajax_referer( 'add_attribute_unit' );
3480
-		wp_die( wpshop_attributes_unit::elementEdition( '' ) );
3479
+		check_ajax_referer('add_attribute_unit');
3480
+		wp_die(wpshop_attributes_unit::elementEdition(''));
3481 3481
 	}
3482
-	add_action( 'wp_ajax_wps_attribute_unit_add', 'add_attribute_unit' );
3482
+	add_action('wp_ajax_wps_attribute_unit_add', 'add_attribute_unit');
3483 3483
 
3484 3484
 	function edit_attribute_unit() {
3485
-		check_ajax_referer( 'edit_attribute_unit_' . ( isset( $_REQUEST['elementIdentifier'] ) ? (int) $_REQUEST['elementIdentifier'] : '' ) );
3486
-		wp_die( wpshop_attributes_unit::elementEdition( isset( $_REQUEST['elementIdentifier'] ) ? (int) $_REQUEST['elementIdentifier'] : '' ) );
3485
+		check_ajax_referer('edit_attribute_unit_' . (isset($_REQUEST['elementIdentifier']) ? (int)$_REQUEST['elementIdentifier'] : ''));
3486
+		wp_die(wpshop_attributes_unit::elementEdition(isset($_REQUEST['elementIdentifier']) ? (int)$_REQUEST['elementIdentifier'] : ''));
3487 3487
 	}
3488
-	add_action( 'wp_ajax_wps_attribute_unit_edit', 'edit_attribute_unit' );
3488
+	add_action('wp_ajax_wps_attribute_unit_edit', 'edit_attribute_unit');
3489 3489
 
3490 3490
 	function save_new_attribute_unit() {
3491
-		check_ajax_referer( 'save_new_attribute_unit' );
3491
+		check_ajax_referer('save_new_attribute_unit');
3492 3492
 		$save_output = '';
3493 3493
 
3494 3494
 		$attribute_unit_informations['id'] = '';
@@ -3502,11 +3502,11 @@  discard block
 block discarded – undo
3502 3502
 		$attribute_unit_informations['code_iso'] = sanitize_text_field($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT]['code_iso']);
3503 3503
 
3504 3504
 		$save_unit_result = wpshop_database::save($attribute_unit_informations, WPSHOP_DBT_ATTRIBUTE_UNIT);
3505
-		if($save_unit_result == 'done'){
3505
+		if ($save_unit_result == 'done') {
3506 3506
 			$save_output = wpshop_attributes_unit::elementList();
3507 3507
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The new unit has been saved succesfully', 'wpshop');
3508 3508
 		}
3509
-		else{
3509
+		else {
3510 3510
 			$save_output = wpshop_attributes_unit::elementEdition();
3511 3511
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during new unit saving', 'wpshop');
3512 3512
 		}
@@ -3514,10 +3514,10 @@  discard block
 block discarded – undo
3514 3514
 		echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . $save_output;
3515 3515
 		wp_die();
3516 3516
 	}
3517
-	add_action( 'wp_ajax_wps_attribute_unit_new', 'save_new_attribute_unit' );
3517
+	add_action('wp_ajax_wps_attribute_unit_new', 'save_new_attribute_unit');
3518 3518
 
3519 3519
 	function update_attribute_unit() {
3520
-		check_ajax_referer( 'update_attribute_unit' );
3520
+		check_ajax_referer('update_attribute_unit');
3521 3521
 		$save_output = '';
3522 3522
 
3523 3523
 		$attributeUnitId = sanitize_key($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT]['id']);
@@ -3530,7 +3530,7 @@  discard block
 block discarded – undo
3530 3530
 		$attribute_unit_informations['change_rate'] = sanitize_text_field($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT]['change_rate']);
3531 3531
 		$attribute_unit_informations['code_iso'] = sanitize_text_field($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT]['code_iso']);
3532 3532
 
3533
-		if ( $attribute_unit_informations['is_default_of_group'] == 'yes' ) {
3533
+		if ($attribute_unit_informations['is_default_of_group'] == 'yes') {
3534 3534
 			$wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array(
3535 3535
 				'is_default_of_group' => 'no'
3536 3536
 			), array(
@@ -3538,8 +3538,8 @@  discard block
 block discarded – undo
3538 3538
 			));
3539 3539
 		}
3540 3540
 
3541
-		$save_unit_result =  wpshop_database::update($attribute_unit_informations, $attributeUnitId, WPSHOP_DBT_ATTRIBUTE_UNIT);
3542
-		if ( $save_unit_result == 'done' ) {
3541
+		$save_unit_result = wpshop_database::update($attribute_unit_informations, $attributeUnitId, WPSHOP_DBT_ATTRIBUTE_UNIT);
3542
+		if ($save_unit_result == 'done') {
3543 3543
 			$save_output = wpshop_attributes_unit::elementList();
3544 3544
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit has been saved succesfully', 'wpshop');
3545 3545
 		}
@@ -3551,17 +3551,17 @@  discard block
 block discarded – undo
3551 3551
 		echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . $save_output;
3552 3552
 		wp_die();
3553 3553
 	}
3554
-	add_action( 'wp_ajax_wps_attribute_unit_update', 'update_attribute_unit' );
3554
+	add_action('wp_ajax_wps_attribute_unit_update', 'update_attribute_unit');
3555 3555
 
3556 3556
 	function delete_attribute_unit() {
3557
-		check_ajax_referer( 'delete_attribute_unit_' . ( isset( $_REQUEST['elementIdentifier'] ) ? (int) $_REQUEST['elementIdentifier'] : '' ) );
3557
+		check_ajax_referer('delete_attribute_unit_' . (isset($_REQUEST['elementIdentifier']) ? (int)$_REQUEST['elementIdentifier'] : ''));
3558 3558
 		$unit_id = sanitize_key($_REQUEST['elementIdentifier']);
3559 3559
 		$save_output = '';
3560 3560
 
3561 3561
 		$attribute_unit_informations['status'] = 'deleted';
3562 3562
 		$attribute_unit_informations['last_update_date'] = date('Y-m-d H:i:s');
3563 3563
 		$save_unit_result = wpshop_database::update($attribute_unit_informations, $unit_id, WPSHOP_DBT_ATTRIBUTE_UNIT);
3564
-		if ( $save_unit_result == 'done' ) {
3564
+		if ($save_unit_result == 'done') {
3565 3565
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action succesful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit has been deleted succesfully', 'wpshop');
3566 3566
 		}
3567 3567
 		else {
@@ -3571,30 +3571,30 @@  discard block
 block discarded – undo
3571 3571
 		echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . wpshop_attributes_unit::elementList();
3572 3572
 		wp_die();
3573 3573
 	}
3574
-	add_action( 'wp_ajax_wps_attribute_unit_delete', 'delete_attribute_unit' );
3574
+	add_action('wp_ajax_wps_attribute_unit_delete', 'delete_attribute_unit');
3575 3575
 
3576 3576
 	/* ATTRIBUTES UNIT GROUP */
3577 3577
 
3578 3578
 	function load_attribute_unit_groups() {
3579
-		check_ajax_referer( 'load_attribute_unit_groups' );
3580
-		wp_die( wpshop_attributes_unit::unit_group_list() );
3579
+		check_ajax_referer('load_attribute_unit_groups');
3580
+		wp_die(wpshop_attributes_unit::unit_group_list());
3581 3581
 	}
3582
-	add_action( 'wp_ajax_wps_attribute_group_unit_load', 'load_attribute_unit_groups' );
3582
+	add_action('wp_ajax_wps_attribute_group_unit_load', 'load_attribute_unit_groups');
3583 3583
 
3584 3584
 	function add_attribute_unit_group() {
3585
-		check_ajax_referer( 'add_attribute_unit_group' );
3586
-		wp_die( wpshop_attributes_unit::unit_group_edition( '' ) );
3585
+		check_ajax_referer('add_attribute_unit_group');
3586
+		wp_die(wpshop_attributes_unit::unit_group_edition(''));
3587 3587
 	}
3588
-	add_action( 'wp_ajax_wps_attribute_group_unit_add', 'add_attribute_unit_group' );
3588
+	add_action('wp_ajax_wps_attribute_group_unit_add', 'add_attribute_unit_group');
3589 3589
 
3590 3590
 	function edit_attribute_unit_group() {
3591
-		check_ajax_referer( 'edit_attribute_unit_group_' . ( isset( $_REQUEST['elementIdentifier'] ) ? $_REQUEST['elementIdentifier'] : '' ) );
3592
-		wp_die( wpshop_attributes_unit::unit_group_edition( isset( $_REQUEST['elementIdentifier'] ) ? (int) $_REQUEST['elementIdentifier'] : '' ) );
3591
+		check_ajax_referer('edit_attribute_unit_group_' . (isset($_REQUEST['elementIdentifier']) ? $_REQUEST['elementIdentifier'] : ''));
3592
+		wp_die(wpshop_attributes_unit::unit_group_edition(isset($_REQUEST['elementIdentifier']) ? (int)$_REQUEST['elementIdentifier'] : ''));
3593 3593
 	}
3594
-	add_action( 'wp_ajax_wps_attribute_group_unit_edit', 'edit_attribute_unit_group' );
3594
+	add_action('wp_ajax_wps_attribute_group_unit_edit', 'edit_attribute_unit_group');
3595 3595
 
3596 3596
 	function save_new_attribute_unit_group() {
3597
-		check_ajax_referer( 'save_new_attribute_unit_group' );
3597
+		check_ajax_referer('save_new_attribute_unit_group');
3598 3598
 		$save_output = '';
3599 3599
 
3600 3600
 		$attribute_unit_informations['id'] = '';
@@ -3603,11 +3603,11 @@  discard block
 block discarded – undo
3603 3603
 		$attribute_unit_informations['name'] = sanitize_text_field($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['name']);
3604 3604
 
3605 3605
 		$save_unit_result = wpshop_database::save($attribute_unit_informations, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
3606
-		if($save_unit_result == 'done'){
3606
+		if ($save_unit_result == 'done') {
3607 3607
 			$save_output = wpshop_attributes_unit::unit_group_list();
3608 3608
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The new unit group has been saved succesfully', 'wpshop');
3609 3609
 		}
3610
-		else{
3610
+		else {
3611 3611
 			$save_output = wpshop_attributes_unit::unit_group_edition();
3612 3612
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during new unit group saving', 'wpshop');
3613 3613
 		}
@@ -3615,10 +3615,10 @@  discard block
 block discarded – undo
3615 3615
 		echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . $save_output;
3616 3616
 		wp_die();
3617 3617
 	}
3618
-	add_action( 'wp_ajax_wps_attribute_group_unit_new', 'save_new_attribute_unit_group' );
3618
+	add_action('wp_ajax_wps_attribute_group_unit_new', 'save_new_attribute_unit_group');
3619 3619
 
3620 3620
 	function update_attribute_unit_group() {
3621
-		check_ajax_referer( 'update_attribute_unit_group' );
3621
+		check_ajax_referer('update_attribute_unit_group');
3622 3622
 		$save_output = '';
3623 3623
 
3624 3624
 		$attributeUnitId = sanitize_key($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['id']);
@@ -3626,12 +3626,12 @@  discard block
 block discarded – undo
3626 3626
 		$attribute_unit_informations['last_update_date'] = date('Y-m-d H:i:s');
3627 3627
 		$attribute_unit_informations['name'] = sanitize_text_field($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['name']);
3628 3628
 
3629
-		$save_unit_result =  wpshop_database::update($attribute_unit_informations, $attributeUnitId, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
3630
-		if($save_unit_result == 'done'){
3629
+		$save_unit_result = wpshop_database::update($attribute_unit_informations, $attributeUnitId, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
3630
+		if ($save_unit_result == 'done') {
3631 3631
 			$save_output = wpshop_attributes_unit::unit_group_list();
3632 3632
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit group has been saved succesfully', 'wpshop');
3633 3633
 		}
3634
-		else{
3634
+		else {
3635 3635
 			$save_output = wpshop_attributes_unit::unit_group_edition($attributeUnitId);
3636 3636
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit group saving', 'wpshop');
3637 3637
 		}
@@ -3639,65 +3639,65 @@  discard block
 block discarded – undo
3639 3639
 		echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . $save_output;
3640 3640
 		wp_die();
3641 3641
 	}
3642
-	add_action( 'wp_ajax_wps_attribute_group_unit_update', 'update_attribute_unit_group' );
3642
+	add_action('wp_ajax_wps_attribute_group_unit_update', 'update_attribute_unit_group');
3643 3643
 
3644 3644
 	function delete_attribute_unit_group() {
3645
-		check_ajax_referer( 'delete_attribute_unit_group_' . ( isset( $_REQUEST['elementIdentifier'] ) ? (int) $_REQUEST['elementIdentifier'] : '' ) );
3645
+		check_ajax_referer('delete_attribute_unit_group_' . (isset($_REQUEST['elementIdentifier']) ? (int)$_REQUEST['elementIdentifier'] : ''));
3646 3646
 		$unit_id = sanitize_key($_REQUEST['elementIdentifier']);
3647 3647
 		$save_output = '';
3648 3648
 
3649 3649
 		$attribute_unit_informations['status'] = 'deleted';
3650 3650
 		$attribute_unit_informations['last_update_date'] = date('Y-m-d H:i:s');
3651 3651
 		$save_unit_result = wpshop_database::update($attribute_unit_informations, $unit_id, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
3652
-		if($save_unit_result == 'done'){
3652
+		if ($save_unit_result == 'done') {
3653 3653
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action succesful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit group has been deleted succesfully', 'wpshop');
3654 3654
 		}
3655
-		else{
3655
+		else {
3656 3656
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit group deletion', 'wpshop');
3657 3657
 		}
3658 3658
 
3659 3659
 		echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . wpshop_attributes_unit::unit_group_list();
3660 3660
 		wp_die();
3661 3661
 	}
3662
-	add_action( 'wp_ajax_wps_attribute_group_unit_delete', 'delete_attribute_unit_group' );
3662
+	add_action('wp_ajax_wps_attribute_group_unit_delete', 'delete_attribute_unit_group');
3663 3663
 
3664 3664
 	function products_by_criteria() {
3665
-		check_ajax_referer( 'products_by_criteria' );
3665
+		check_ajax_referer('products_by_criteria');
3666 3666
 		$attr = !empty($_REQUEST['attr']) ? sanitize_text_field($_REQUEST['attr']) : '';
3667 3667
 		// If a filter by attribute is found, recalcul the products that matching it
3668
-		if(!empty($attr)) {
3669
-			$att = explode(':',$attr);
3670
-			$products_id = wpshop_products::get_products_matching_attribute($att[0],$att[1]);
3668
+		if (!empty($attr)) {
3669
+			$att = explode(':', $attr);
3670
+			$products_id = wpshop_products::get_products_matching_attribute($att[0], $att[1]);
3671 3671
 		}
3672
-		$products_id = !empty($products_id) ? $products_id : sanitize_text_field( $_REQUEST['pid'] );
3673
-		$page_number = !empty( $_REQUEST ) && !empty( $_REQUEST[ 'page_number' ] ) && is_int( (int) $_REQUEST['page_number'] ) ? (int) $_REQUEST['page_number'] : 0;
3672
+		$products_id = !empty($products_id) ? $products_id : sanitize_text_field($_REQUEST['pid']);
3673
+		$page_number = !empty($_REQUEST) && !empty($_REQUEST['page_number']) && is_int((int)$_REQUEST['page_number']) ? (int)$_REQUEST['page_number'] : 0;
3674 3674
 
3675
-		$criteria = !empty( $_REQUEST ) && !empty( $_REQUEST[ 'criteria' ] ) ? sanitize_text_field( $_REQUEST[ 'criteria' ] ) : null;
3676
-		$cid = !empty( $_REQUEST ) && !empty( $_REQUEST[ 'cid' ] ) && is_int( (int)$_REQUEST[ 'cid' ] ) ? (int)$_REQUEST[ 'cid' ] : null;
3677
-		$display_type = !empty( $_REQUEST ) && !empty( $_REQUEST[ 'display_type' ] ) ? sanitize_text_field( $_REQUEST[ 'display_type' ] ) : null;
3678
-		$order = !empty( $_REQUEST ) && !empty( $_REQUEST[ 'order' ] ) ? sanitize_text_field( $_REQUEST[ 'order' ] ) : null;
3679
-		$products_per_page = !empty( $_REQUEST ) && !empty( $_REQUEST[ 'products_per_page' ] ) && is_int( (int)$_REQUEST[ 'products_per_page' ] ) ? (int)$_REQUEST[ 'products_per_page' ] : 0;
3675
+		$criteria = !empty($_REQUEST) && !empty($_REQUEST['criteria']) ? sanitize_text_field($_REQUEST['criteria']) : null;
3676
+		$cid = !empty($_REQUEST) && !empty($_REQUEST['cid']) && is_int((int)$_REQUEST['cid']) ? (int)$_REQUEST['cid'] : null;
3677
+		$display_type = !empty($_REQUEST) && !empty($_REQUEST['display_type']) ? sanitize_text_field($_REQUEST['display_type']) : null;
3678
+		$order = !empty($_REQUEST) && !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : null;
3679
+		$products_per_page = !empty($_REQUEST) && !empty($_REQUEST['products_per_page']) && is_int((int)$_REQUEST['products_per_page']) ? (int)$_REQUEST['products_per_page'] : 0;
3680 3680
 
3681
-		$data = wpshop_products::wpshop_get_product_by_criteria( $criteria, $cid, $products_id, $display_type, $order, $page_number, $products_per_page );
3682
-		if($data[0]) {
3681
+		$data = wpshop_products::wpshop_get_product_by_criteria($criteria, $cid, $products_id, $display_type, $order, $page_number, $products_per_page);
3682
+		if ($data[0]) {
3683 3683
 			echo json_encode(array(true, do_shortcode($data[1])));
3684
-		} else echo json_encode(array(false,__('No product found','wpshop')));
3684
+		} else echo json_encode(array(false, __('No product found', 'wpshop')));
3685 3685
 		wp_die();
3686 3686
 	}
3687
-	add_action( 'wp_ajax_wps_products_by_criteria', 'products_by_criteria' );
3688
-	add_action( 'wp_ajax_nopriv_wps_products_by_criteria', 'products_by_criteria' );
3687
+	add_action('wp_ajax_wps_products_by_criteria', 'products_by_criteria');
3688
+	add_action('wp_ajax_nopriv_wps_products_by_criteria', 'products_by_criteria');
3689 3689
 
3690 3690
 	function ajax_sendMessage() {
3691
-		check_ajax_referer( 'sendMessage' );
3692
-		$post_id = !empty($_REQUEST['postid']) ? (int) $_REQUEST['postid'] : null;
3691
+		check_ajax_referer('sendMessage');
3692
+		$post_id = !empty($_REQUEST['postid']) ? (int)$_REQUEST['postid'] : null;
3693 3693
 		$title = !empty($_REQUEST['title']) ? sanitize_title($_REQUEST['title']) : '';
3694 3694
 		$message = !empty($_REQUEST['message']) ? sanitize_text_field($_REQUEST['message']) : '';
3695
-		$recipient = !empty($_REQUEST['recipient']) ? (array) $_REQUEST['recipient'] : array();
3696
-		if ( isset($post_id) && isset($title) && isset($message) && !empty($recipient) ) {
3695
+		$recipient = !empty($_REQUEST['recipient']) ? (array)$_REQUEST['recipient'] : array();
3696
+		if (isset($post_id) && isset($title) && isset($message) && !empty($recipient)) {
3697 3697
 			$user_info = get_userdata($recipient);
3698 3698
 			$first_name = $user_info->user_firstname;
3699 3699
 			$last_name = $user_info->user_lastname;
3700
-			$data = array('customer_first_name'=>$first_name,'customer_last_name'=>$last_name);
3700
+			$data = array('customer_first_name'=>$first_name, 'customer_last_name'=>$last_name);
3701 3701
 
3702 3702
 			$wps_message_ctr = new wps_message_ctr();
3703 3703
 
@@ -3706,73 +3706,73 @@  discard block
 block discarded – undo
3706 3706
 			$message = $wps_message_ctr->customMessage($message, $data);
3707 3707
 
3708 3708
 			if (!empty($user_info->user_email)) {
3709
-				$wps_message_ctr->wpshop_email($user_info->user_email, $title, $message, $save=true, $model_id=$post_id, $object=array());
3709
+				$wps_message_ctr->wpshop_email($user_info->user_email, $title, $message, $save = true, $model_id = $post_id, $object = array());
3710 3710
 				$array = array('result' => true, 'message' => '');
3711 3711
 			}
3712
-			else $array = array('result' => true, 'message' => __('An error occured','wpshop'));
3712
+			else $array = array('result' => true, 'message' => __('An error occured', 'wpshop'));
3713 3713
 		}
3714 3714
 		else {
3715
-			$array = array('result' => false, 'message' => __('An error occured','wpshop'));
3715
+			$array = array('result' => false, 'message' => __('An error occured', 'wpshop'));
3716 3716
 		}
3717 3717
 
3718 3718
 		echo json_encode($array);
3719 3719
 		wp_die();
3720 3720
 	}
3721
-	add_action( 'wp_ajax_wps_ajax_send_message', 'ajax_sendMessage' );
3721
+	add_action('wp_ajax_wps_ajax_send_message', 'ajax_sendMessage');
3722 3722
 
3723 3723
 	function ajax_resendMessage() {
3724
-		check_ajax_referer( 'resendMessage' );
3725
-		$message_id = !empty($_REQUEST['messageid']) ? (array) $_REQUEST['messageid'] : array();
3724
+		check_ajax_referer('resendMessage');
3725
+		$message_id = !empty($_REQUEST['messageid']) ? (array)$_REQUEST['messageid'] : array();
3726 3726
 		if (isset($message_id)) {
3727
-			$ids = explode('-',$message_id);
3727
+			$ids = explode('-', $message_id);
3728 3728
 			$postid = $ids[0];
3729
-			$date = $ids[1].'-'.$ids[2];
3729
+			$date = $ids[1] . '-' . $ids[2];
3730 3730
 			$arraykey = $ids[3];
3731 3731
 
3732
-			$historic = get_post_meta($postid, 'wpshop_messages_histo_'.$date, true);
3732
+			$historic = get_post_meta($postid, 'wpshop_messages_histo_' . $date, true);
3733 3733
 
3734 3734
 			if (isset($historic[$arraykey])) {
3735 3735
 				$historic[$arraykey]['mess_dispatch_date'][] = current_time('mysql', 0);
3736
-				update_post_meta($postid, 'wpshop_messages_histo_'.$date, $historic);
3736
+				update_post_meta($postid, 'wpshop_messages_histo_' . $date, $historic);
3737 3737
 
3738 3738
 				$data = $historic[$arraykey];
3739 3739
 				$wps_message_ctr = new wps_message_ctr();
3740
-				$wps_message_ctr->wpshop_email($data['mess_user_email'], $data['mess_title'], $data['mess_message'], $save=false, $object=array());
3740
+				$wps_message_ctr->wpshop_email($data['mess_user_email'], $data['mess_title'], $data['mess_message'], $save = false, $object = array());
3741 3741
 
3742 3742
 				$array = array('result' => true, 'message' => '');
3743 3743
 			}
3744 3744
 			else {
3745
-				$array = array('result' => false, 'message' => __('An error occured','wpshop'));
3745
+				$array = array('result' => false, 'message' => __('An error occured', 'wpshop'));
3746 3746
 			}
3747 3747
 		}
3748 3748
 		else {
3749
-			$array = array('result' => false, 'message' => __('An error occured','wpshop'));
3749
+			$array = array('result' => false, 'message' => __('An error occured', 'wpshop'));
3750 3750
 		}
3751 3751
 
3752 3752
 		echo json_encode($array);
3753 3753
 		wp_die();
3754 3754
 	}
3755
-	add_action( 'wp_ajax_wps_ajax_resend_message', 'ajax_resendMessage' );
3755
+	add_action('wp_ajax_wps_ajax_resend_message', 'ajax_resendMessage');
3756 3756
 
3757 3757
 	function related_products() {
3758
-		check_ajax_referer( 'related_products' );
3758
+		check_ajax_referer('related_products');
3759 3759
 		$search = sanitize_text_field($_REQUEST['search']);
3760 3760
 		$data = wpshop_products::product_list(false, $search);
3761
-		$array=array();
3761
+		$array = array();
3762 3762
 		foreach ($data as $d) {
3763 3763
 			$array[] = array('id' => $d->ID, 'name' => $d->post_title);
3764 3764
 		}
3765 3765
 		echo json_encode($array);
3766 3766
 		wp_die();
3767 3767
 	}
3768
-	add_action( 'wp_ajax_wps_related_products', 'related_products' );
3768
+	add_action('wp_ajax_wps_related_products', 'related_products');
3769 3769
 
3770 3770
 	function applyCoupon() {
3771
-		check_ajax_referer( 'applyCoupon' );
3771
+		check_ajax_referer('applyCoupon');
3772 3772
 		$wps_coupon_ctr = new wps_coupon_ctr();
3773 3773
 		$coupon_code = sanitize_text_field($_REQUEST['coupon_code']);
3774 3774
 		$result = $wps_coupon_ctr->applyCoupon($coupon_code);
3775
-		if ($result['status']===true) {
3775
+		if ($result['status'] === true) {
3776 3776
 			$wps_cart_ctr = new wps_cart();
3777 3777
 			$order = $wps_cart_ctr->calcul_cart_information(array());
3778 3778
 			$wps_cart_ctr->store_cart_in_session($order);
@@ -3780,6 +3780,6 @@  discard block
 block discarded – undo
3780 3780
 		} else echo json_encode(array(false, $result['message']));
3781 3781
 		wp_die();
3782 3782
 	}
3783
-	add_action( 'wp_ajax_wps_cart_action_apply_coupon', 'applyCoupon' );
3783
+	add_action('wp_ajax_wps_cart_action_apply_coupon', 'applyCoupon');
3784 3784
 
3785 3785
 ?>
Please login to merge, or discard this patch.
Braces   +111 added lines, -197 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
 * Ajax request management file
4 6
 *
@@ -466,12 +468,10 @@  discard block
 block discarded – undo
466 468
 					wpshop_payment::set_payment_transaction_number($order_id, $transaction_id);
467 469
 				}
468 470
 				$result = json_encode(array(true,''));
469
-			}
470
-			else {
471
+			} else {
471 472
 				$result = json_encode(array(false,__('Choose a payment method and/or type a transaction number', 'wpshop')));
472 473
 			}
473
-		}
474
-		else {
474
+		} else {
475 475
 			$result = json_encode(array(false,__('Bad order identifier', 'wpshop')));
476 476
 		}
477 477
 		echo json_encode($result);
@@ -488,8 +488,7 @@  discard block
 block discarded – undo
488 488
 		if ( !empty($order_id) ) {
489 489
 			$result = (array(true, '<h1>'.__('Tracking number','wpshop').'</h1><p>'.__('Enter a tracking number, or leave blank:','wpshop').'</p><input type="hidden" value="'.$order_id.'" name="oid" /><input type="text" name="trackingNumber" /><br /><br /><p>'.__('Enter a tracking link, or leave blank: (http included)','wpshop').'</p><input type="text" name="trackingLink" /><br /><br /><input type="submit" data-nonce="' . esc_attr( wp_create_nonce( 'wpshop_change_order_state' ) ) . '" class="button-primary sendTrackingNumber" value="'.__('Send','wpshop').'" /> <input type="button" class="button-secondary closeAlert" value="'.__('Cancel','wpshop').'" />'));
490 490
 
491
-		}
492
-		else {
491
+		} else {
493 492
 			$result = json_encode(array(false, __('Order reference error', 'wpshop')));
494 493
 		}
495 494
 		echo json_encode($result);
@@ -528,16 +527,14 @@  discard block
 block discarded – undo
528 527
 				$output_shipping_box = ob_get_clean();
529 528
 
530 529
 				$result = array( true, $order_state, $output_shipping_box, $output_payment_box_class, $output_payment_box_content );
531
-			}
532
-			else {
530
+			} else {
533 531
 				wpshop_payment::setOrderPaymentStatus($order_id, $order_state);
534 532
 
535 533
 				$result = array(true, $order_state, __($order_status[$order_state], 'wpshop'));
536 534
 			}
537 535
 			update_post_meta($order_id, '_order_postmeta', $order);
538 536
 			update_post_meta($order_id, '_wpshop_order_status', $order_state);
539
-		}
540
-		else {
537
+		} else {
541 538
 			$result = array(false, __('Incorrect order request', 'wpshop'));
542 539
 		}
543 540
 
@@ -623,8 +620,7 @@  discard block
 block discarded – undo
623 620
 			unset($tpl_component);
624 621
 
625 622
 			echo json_encode(array(true, str_replace('optionsUpdate', 'options', $output)));
626
-		}
627
-		else {
623
+		} else {
628 624
 			echo json_encode(array(false, __('The value you entered already exist', 'wpshop')));
629 625
 		}
630 626
 		die();
@@ -669,13 +665,11 @@  discard block
 block discarded – undo
669 665
 				);
670 666
 				$new_option_id = wp_insert_post($new_post);
671 667
 				$input_def['valueToPut'] = 'index';
672
-			}
673
-			else {
668
+			} else {
674 669
 				$result_status = false;
675 670
 				$result = __('This value already exist for this attribute', 'wpshop');
676 671
 			}
677
-		}
678
-		else {
672
+		} else {
679 673
 			/**	Check if the given value does not exist	*/
680 674
 			$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE (label = %s OR value = %s) AND attribute_id = %d AND status = 'valid'", str_replace(",", ".", $attribute_options_label), $attribute_options_value, $attribute->id);
681 675
 			$existing_values = $wpdb->get_results($query);
@@ -691,8 +685,7 @@  discard block
 block discarded – undo
691 685
 				/**	Add the new value into database	*/
692 686
 				$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('creation_date' => current_time('mysql', 0), 'status' => 'valid', 'attribute_id' => $attribute->id, 'position' => $position, 'label' => str_replace(",", ".", stripslashes($attribute_options_label)), 'value' => stripslashes($attribute_options_value)));
693 687
 				$new_option_id = $wpdb->insert_id;
694
-			}
695
-			else {
688
+			} else {
696 689
 				$result_status = false;
697 690
 				$result = __('This value already exist for this attribute', 'wpshop');
698 691
 			}
@@ -843,8 +836,7 @@  discard block
 block discarded – undo
843 836
 			$combo_wp_type = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
844 837
 			$result .= __('Choose the data type to use for this attribute', 'wpshop') . '<a href="#" title="'.sprintf(__('If the type you want to use is not in the list below. You have to create it by using %s menu', 'wpshop'), __('Entities', 'wpshop')).'" class="wpshop_infobulle_marker">?</a><div class="wpshop_cls wpshop_attribute_select_data_type_internal_list">'.$combo_wp_type.'</div>';
845 838
 			$result .= '<input type="hidden" value="no" name="delete_items_of_entity" id="delete_items_of_entity" /><input type="hidden" value="no" name="delete_entity" id="delete_entity" />';
846
-		}
847
-		else {
839
+		} else {
848 840
 			$result .= '<input type="hidden" value="' . $attribute->default_value . '" name="internal_data" id="internal_data" />';
849 841
 
850 842
 			unset($input_def);
@@ -901,8 +893,7 @@  discard block
 block discarded – undo
901 893
 					}
902 894
 				}
903 895
 			}
904
-		}
905
-		else {
896
+		} else {
906 897
 			$post_list = query_posts(array('post_type' => $internal_data_type));
907 898
 			if (!empty($post_list)) {
908 899
 				$p=1;
@@ -911,8 +902,7 @@  discard block
 block discarded – undo
911 902
 					$last_insert = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'valid', 'creation_date'=>current_time('mysql',0), 'attribute_id'=>$current_attribute, 'position'=>$p, 'value'=>$post->post_name, 'label'=>$post->post_title));
912 903
 					if(is_int($last_insert) && $delete_items_of_entity){
913 904
 						wp_delete_post($post->ID, true);
914
-					}
915
-					else{
905
+					} else{
916 906
 						$error = true;
917 907
 					}
918 908
 					$p++;
@@ -976,13 +966,11 @@  discard block
 block discarded – undo
976 966
 				}
977 967
 				$result = true;
978 968
 				$result_output = '<p class="wpshop_duplicate_attribute_result" ><a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING . '&action=edit&id=' . $new_attribute_id) . '" >' . __('Edit the new attribute', 'wpshop') . '</a></p>';
979
-			}
980
-			else {
969
+			} else {
981 970
 				$result = false;
982 971
 				$result_output = __('An error occured while duplicating attribute', 'wpshop');
983 972
 			}
984
-		}
985
-		else {
973
+		} else {
986 974
 			$result = false;
987 975
 			$result_output = __('This attribute has already been duplicate to this entity', 'wpshop');
988 976
 		}
@@ -1012,8 +1000,7 @@  discard block
 block discarded – undo
1012 1000
 			/* Test if we want display the group unit list OR the unit list */
1013 1001
 			if ( $selected_list == 'group unit' ) {
1014 1002
 				$list = wpshop_attributes_unit::get_unit_group();
1015
-			}
1016
-			else {
1003
+			} else {
1017 1004
 				$list = wpshop_attributes_unit::get_unit_list_for_group($group);
1018 1005
 			}
1019 1006
 
@@ -1021,8 +1008,7 @@  discard block
 block discarded – undo
1021 1008
 				$response .= '<option value="' . $unit->id . '" '. ( ($current_group == $unit->id && $selected_list == 'group unit') ? 'selected="selected"' : '' ).'>' . $unit->name . '</option>';
1022 1009
 			}
1023 1010
 			$result = array(true, $response);
1024
-		}
1025
-		else {
1011
+		} else {
1026 1012
 			$result = array(false, __('Incorrect order request', 'wpshop'));
1027 1013
 		}
1028 1014
 
@@ -1061,14 +1047,12 @@  discard block
 block discarded – undo
1061 1047
 								$sub_modif .= $column_name;
1062 1048
 								if( !empty($columns->Field) && ($columns->Field == $column_name) ){
1063 1049
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been created', 'wpshop') . '" title="' . __('Field has been created', 'wpshop') . '" class="db_added_field_check" />';
1064
-								}
1065
-								else{
1050
+								} else{
1066 1051
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />';
1067 1052
 									$error_nb++;
1068 1053
 									if ( !empty($error_list[$plugin_db_version]) ) {
1069 1054
 										$error_list[$plugin_db_version] += 1;
1070
-									}
1071
-									else {
1055
+									} else {
1072 1056
 										$error_list[$plugin_db_version] = 1;
1073 1057
 									}
1074 1058
 								}
@@ -1086,8 +1070,7 @@  discard block
 block discarded – undo
1086 1070
 								$sub_modif .= $column_name;
1087 1071
 								if(empty($columns) || ($columns->Field != $column_name)){
1088 1072
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been deleted', 'wpshop') . '" title="' . __('Field has been deleted', 'wpshop') . '" class="db_deleted_field_check" />';
1089
-								}
1090
-								else{
1073
+								} else{
1091 1074
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field exists', 'wpshop') . '" title="' . __('Field exists', 'wpshop') . '" class="db_deleted_field_check" />';
1092 1075
 									$error_nb++;
1093 1076
 									$error_list[$plugin_db_version] += 1;
@@ -1109,8 +1092,7 @@  discard block
 block discarded – undo
1109 1092
 									$changed_key = 'type';
1110 1093
 									if($columns->Type == $field_infos['type']){
1111 1094
 										$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been created', 'wpshop') . '" title="' . __('Field has been created', 'wpshop') . '" class="db_added_field_check" />';
1112
-									}
1113
-									else{
1095
+									} else{
1114 1096
 										$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />';
1115 1097
 										$error_nb++;
1116 1098
 										$error_list[$plugin_db_version] += 1;
@@ -1122,8 +1104,7 @@  discard block
 block discarded – undo
1122 1104
 									$changed_key = 'original_name';
1123 1105
 									if($columns->Field == $field_infos['field']){
1124 1106
 										$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Field has been created', 'wpshop') . '" title="' . __('Field has been created', 'wpshop') . '" class="db_added_field_check" />';
1125
-									}
1126
-									else{
1107
+									} else{
1127 1108
 										$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Field does not exist', 'wpshop') . '" title="' . __('Field does not exist', 'wpshop') . '" class="db_added_field_check" />';
1128 1109
 										$error_nb++;
1129 1110
 										$error_list[$plugin_db_version] += 1;
@@ -1146,8 +1127,7 @@  discard block
 block discarded – undo
1146 1127
 								$sub_modif .= $column_name;
1147 1128
 								if((empty($columns)) || ($columns->Column_name != $column_name)){
1148 1129
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Index has been deleted', 'wpshop') . '" title="' . __('Index has been deleted', 'wpshop') . '" class="db_deleted_index_check" />';
1149
-								}
1150
-								else{
1130
+								} else{
1151 1131
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Index does not exists', 'wpshop') . '" title="' . __('Index does not exists', 'wpshop') . '" class="db_deleted_index_check" />';
1152 1132
 									$error_nb++;
1153 1133
 									$error_list[$plugin_db_version] += 1;
@@ -1166,8 +1146,7 @@  discard block
 block discarded – undo
1166 1146
 								$sub_modif .= $column_name;
1167 1147
 								if(($columns->Column_name == $column_name) || ($columns->Key_name == $column_name)){
1168 1148
 									$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Index has been created', 'wpshop') . '" title="' . __('Index has been created', 'wpshop') . '" class="db_added_index_check" />';
1169
-								}
1170
-								else{
1149
+								} else{
1171 1150
 									$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Index does not exist', 'wpshop') . '" title="' . __('Index does not exist', 'wpshop') . '" class="db_added_index_check" />';
1172 1151
 									$error_nb++;
1173 1152
 									$error_list[$plugin_db_version] += 1;
@@ -1186,14 +1165,12 @@  discard block
 block discarded – undo
1186 1165
 							$table_exists = $wpdb->query($query);
1187 1166
 							if($table_exists == 1){
1188 1167
 								$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Table has been created', 'wpshop') . '" title="' . __('Table has been created', 'wpshop') . '" class="db_table_check" />';
1189
-							}
1190
-							else{
1168
+							} else{
1191 1169
 								$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Table has not been created', 'wpshop') . '" title="' . __('Table has not been created', 'wpshop') . '" class="db_table_check" />';
1192 1170
 								$error_nb++;
1193 1171
 								if ( !empty($error_list[$plugin_db_version]) ) {
1194 1172
 									$error_list[$plugin_db_version] += 1;
1195
-								}
1196
-								else {
1173
+								} else {
1197 1174
 									$error_list[$plugin_db_version] = 1;
1198 1175
 								}
1199 1176
 							}
@@ -1214,21 +1191,17 @@  discard block
 block discarded – undo
1214 1191
 								$error_nb++;
1215 1192
 								if ( !empty($error_list[$plugin_db_version]) ) {
1216 1193
 									$error_list[$plugin_db_version] += 1;
1217
-								}
1218
-								else {
1194
+								} else {
1219 1195
 									$error_list[$plugin_db_version] = 1;
1220 1196
 								}
1221
-							}
1222
-							elseif($table_exists == 1){
1197
+							} elseif($table_exists == 1){
1223 1198
 								$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Table has been renamed', 'wpshop') . '" title="' . __('Table has been renamed', 'wpshop') . '" class="db_rename_table_check" />';
1224
-							}
1225
-							else{
1199
+							} else{
1226 1200
 								$sub_modif .= '<img src="' . admin_url('images/no.png') . '" alt="' . __('Table has not been renamed', 'wpshop') . '" title="' . __('Table has not been renamed', 'wpshop') . '" class="db_rename_table_check" />';
1227 1201
 								$error_nb++;
1228 1202
 								if ( !empty($error_list[$plugin_db_version]) ) {
1229 1203
 									$error_list[$plugin_db_version] += 1;
1230
-								}
1231
-								else {
1204
+								} else {
1232 1205
 									$error_list[$plugin_db_version] = 1;
1233 1206
 								}
1234 1207
 							}
@@ -1250,24 +1223,20 @@  discard block
 block discarded – undo
1250 1223
 									$error_nb++;
1251 1224
 									if ( !empty($error_list[$plugin_db_version]) ) {
1252 1225
 										$error_list[$plugin_db_version] += 1;
1253
-									}
1254
-									else {
1226
+									} else {
1255 1227
 										$error_list[$plugin_db_version] = 1;
1256 1228
 									}
1257
-								}
1258
-								else{
1229
+								} else{
1259 1230
 									$deleted_table_result = '<img src="' . EVA_IMG_ICONES_PLUGIN_URL . 'warning_vs.gif" alt="' . __('Table has not been deleted', 'wpshop') . '" title="' . __('Table has not been renamed', 'wpshop') . '" class="db_deleted_table_check" />';
1260 1231
 									$warning_nb++;
1261 1232
 									if ( !empty($warning_list[$plugin_db_version]) ) {
1262 1233
 										$warning_list[$plugin_db_version] += 1;
1263
-									}
1264
-									else {
1234
+									} else {
1265 1235
 										$warning_list[$plugin_db_version] = 1;
1266 1236
 									}
1267 1237
 								}
1268 1238
 								$sub_modif .= $deleted_table_result;
1269
-							}
1270
-							else{
1239
+							} else{
1271 1240
 								$sub_modif .= '<img src="' . admin_url('images/yes.png') . '" alt="' . __('Table has been deleted', 'wpshop') . '" title="' . __('Table has been deleted', 'wpshop') . '" class="db_deleted_table_check" />';
1272 1241
 							}
1273 1242
 							$sub_modif .= ' / ';
@@ -1367,8 +1336,7 @@  discard block
 block discarded – undo
1367 1336
 
1368 1337
 					if ( $has_error ) {
1369 1338
 						$output_error .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element', $tpl_component, array(), 'admin');
1370
-					}
1371
-					else {
1339
+					} else {
1372 1340
 						$output_ok .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element', $tpl_component, array(), 'admin');
1373 1341
 					}
1374 1342
 				}
@@ -1544,8 +1512,7 @@  discard block
 block discarded – undo
1544 1512
 										if ( $last_histo === false ) {
1545 1513
 											$has_error = true;
1546 1514
 											$error_count++;
1547
-										}
1548
-										else {
1515
+										} else {
1549 1516
 											$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array( 'value_id' => $attribute_histo->value_id ) );
1550 1517
 										}
1551 1518
 									}
@@ -1564,8 +1531,7 @@  discard block
 block discarded – undo
1564 1531
 						if ( $new_value === false ) {
1565 1532
 							$has_error = true;
1566 1533
 							$error_count++;
1567
-						}
1568
-						else {
1534
+						} else {
1569 1535
 							/**	Save new atribute values in product metadata	*/
1570 1536
 							$current_product_metadata = get_post_meta( $element->ID, '_wpshop_product_metadata', true);
1571 1537
 							$current_product_metadata[$to_attribute->code] = $element->value;
@@ -1581,23 +1547,19 @@  discard block
 block discarded – undo
1581 1547
 					if ( !$has_error ) {
1582 1548
 						$response['status'] = true;
1583 1549
 						$response['error'] = __('Transfert between attribute is done', 'wpshop');
1584
-					}
1585
-					else {
1550
+					} else {
1586 1551
 						$response['status'] = false;
1587 1552
 						$response['error'] = sprinttf( __('There are %d error that occured while copying value through attributes', 'wpshop'), $error_count);
1588 1553
 					}
1589
-				}
1590
-				else {
1554
+				} else {
1591 1555
 					$response['status'] = false;
1592 1556
 					$response['error'] = __('There are no element corresponding to attribute choosen to copy from', 'wpshop');
1593 1557
 				}
1594
-			}
1595
-			else {
1558
+			} else {
1596 1559
 				$response['status'] = false;
1597 1560
 				$response['error'] = __('Both attribute must have same data type to be updated', 'wpshop');
1598 1561
 			}
1599
-		}
1600
-		else {
1562
+		} else {
1601 1563
 			$response['status'] = false;
1602 1564
 			$response['error'] = __('You have to choose attributes in order to update values', 'wpshop');
1603 1565
 		}
@@ -1696,8 +1658,7 @@  discard block
 block discarded – undo
1696 1658
 					if ( !empty($wps_update_att_for_variation_required_state) && ($wps_update_att_for_variation_required_state != 'no_changes') ) {
1697 1659
 						if ( $wps_update_att_for_variation_required_state == 'yes') {
1698 1660
 							$meta_value['options']['required_attributes'][$attribute->code] = $attribute->code;
1699
-						}
1700
-						else if ( !empty($meta_value['options']['required_attributes']) && !empty($meta_value['options']['required_attributes'][$attribute->code]) ) {
1661
+						} else if ( !empty($meta_value['options']['required_attributes']) && !empty($meta_value['options']['required_attributes'][$attribute->code]) ) {
1701 1662
 							unset($meta_value['options']['required_attributes'][$attribute->code]);
1702 1663
 						}
1703 1664
 					}
@@ -1708,8 +1669,7 @@  discard block
 block discarded – undo
1708 1669
 						if ( !empty($text_from) && ($text_from != 'no_changes') ) {
1709 1670
 							if ( $text_from == 'yes' ) {
1710 1671
 								$meta_value['options']['price_display']['text_from'] = 'on';
1711
-							}
1712
-							else if( !empty($meta_value['options']['price_display']['text_from']) ) {
1672
+							} else if( !empty($meta_value['options']['price_display']['text_from']) ) {
1713 1673
 								unset($meta_value['options']['price_display']['text_from']);
1714 1674
 							}
1715 1675
 						}
@@ -1718,8 +1678,7 @@  discard block
 block discarded – undo
1718 1678
 						if ( !empty($lower_price) && ($lower_price != 'no_changes') ) {
1719 1679
 							if ( $lower_price == 'yes' ) {
1720 1680
 								$meta_value['options']['price_display']['lower_price'] = 'on';
1721
-							}
1722
-							else if( !empty($meta_value['options']['price_display']['lower_price']) ) {
1681
+							} else if( !empty($meta_value['options']['price_display']['lower_price']) ) {
1723 1682
 								unset($meta_value['options']['price_display']['lower_price']);
1724 1683
 							}
1725 1684
 						}
@@ -1800,20 +1759,16 @@  discard block
 block discarded – undo
1800 1759
 							$activate_attribute_for_addon = $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('status' => 'valid'), array('code' => $addons_list[$addon_name][3]));
1801 1760
 						}
1802 1761
 						$state = true;
1803
-					}
1804
-					else {
1762
+					} else {
1805 1763
 						$result = array(false, __('An error occured','wpshop'), __('Desactivated','wpshop'));
1806 1764
 					}
1807
-				}
1808
-				else {
1765
+				} else {
1809 1766
 					$result = array(false, __('The activating code is invalid', 'wpshop'), __('Desactivated','wpshop'));
1810 1767
 				}
1811
-			}
1812
-			else {
1768
+			} else {
1813 1769
 				$result = array(false, __('The addon to activate is invalid', 'wpshop'), __('Desactivated','wpshop'));
1814 1770
 			}
1815
-		}
1816
-		else {
1771
+		} else {
1817 1772
 			$result = array(false, __('An error occured','wpshop'), __('Desactivated','wpshop'));
1818 1773
 		}
1819 1774
 		$activated_class = unserialize(WPSHOP_ADDONS_STATES_CLASS);
@@ -1841,12 +1796,10 @@  discard block
 block discarded – undo
1841 1796
 				if ( update_option(WPSHOP_ADDONS_OPTION_NAME, $extra_options) ) {
1842 1797
 					$result = array(true, __('The addon has been desactivated successfully', 'wpshop'), __('Desactivated','wpshop'));
1843 1798
 					$state = false;
1844
-				}
1845
-				else {
1799
+				} else {
1846 1800
 					$result = array(false, __('An error occured','wpshop'), __('Activated','wpshop'));
1847 1801
 				}
1848
-			}
1849
-			else {
1802
+			} else {
1850 1803
 				$result = array(false, __('The addon to desactivate is invalid', 'wpshop'), __('Activated','wpshop'));
1851 1804
 			}
1852 1805
 		}
@@ -1885,8 +1838,7 @@  discard block
 block discarded – undo
1885 1838
 							$submitOrderInfos = !empty( $_POST['submitOrderInfos'] ) ? (int) $_POST['submitOrderInfos'] : 0;
1886 1839
 							if( !empty($submitOrderInfos) ) {
1887 1840
 								$value = $attribute[$attribute->data_type][$attribute->code];
1888
-							}
1889
-							else {
1841
+							} else {
1890 1842
 								$value = '';
1891 1843
 								if ( $attribute->code != 'user_pass') {
1892 1844
 									$code = $attribute->code;
@@ -1957,16 +1909,14 @@  discard block
 block discarded – undo
1957 1909
 
1958 1910
 		if ( $wpshop_format_result ) {
1959 1911
 			$data = empty($data) ? __('No match', 'wpshop') : $data;
1960
-		}
1961
-		else {
1912
+		} else {
1962 1913
 			if ( !empty($data) ) {
1963 1914
 				$temp_data = $data;
1964 1915
 				unset( $data );
1965 1916
 				foreach ( $temp_data as $post) {
1966 1917
 					$data[$post->ID] = $post->ID . ' - ' . $post->post_title;
1967 1918
 				}
1968
-			}
1969
-			else {
1919
+			} else {
1970 1920
 				$data = array();
1971 1921
 			}
1972 1922
 		}
@@ -2031,8 +1981,7 @@  discard block
 block discarded – undo
2031 1981
 				$product_title = ( !empty($parent_post) && !empty($parent_post->post_title) ) ? $parent_post->post_title : '';
2032 1982
 				$product_description = ( !empty($parent_post) && !empty($parent_post->post_content) ) ? $parent_post->post_content : '';
2033 1983
 				$product_img =  ( !empty($parent_post->ID) ) ? get_the_post_thumbnail( $parent_post->ID, 'thumbnail') : '';
2034
-			}
2035
-			else {
1984
+			} else {
2036 1985
 				$product_title = $product->post_title;
2037 1986
 				$product_description = $product->post_content;
2038 1987
 				$product_img =  get_the_post_thumbnail( $product_id, 'thumbnail');
@@ -2046,8 +1995,7 @@  discard block
 block discarded – undo
2046 1995
 
2047 1996
 			echo json_encode( array(true) );
2048 1997
 			die();
2049
-		}
2050
-		else {
1998
+		} else {
2051 1999
 			$return = $wpshop_cart->add_to_cart( $product_to_add_to_cart, array( $new_pid => $product_qty ), $wpshop_cart_type );
2052 2000
 		}
2053 2001
 
@@ -2064,8 +2012,7 @@  discard block
 block discarded – undo
2064 2012
 				require_once(wpshop_display::get_template_file($tpl_way_to_take[1]));
2065 2013
 				$succes_message_box = ob_get_contents();
2066 2014
 				ob_end_clean();
2067
-			}
2068
-			else {
2015
+			} else {
2069 2016
 				$succes_message_box = wpshop_display::display_template_element($template_part, array('PRODUCT_ID' => $product_id));
2070 2017
 			}
2071 2018
 			unset($tpl_component);
@@ -2082,12 +2029,10 @@  discard block
 block discarded – undo
2082 2029
 
2083 2030
 				if ( !empty($product_to_add_to_cart[$new_pid]['variations']) && count($product_to_add_to_cart[$new_pid]['variations']) < 2 ) {
2084 2031
 					$idp = $product_to_add_to_cart[$new_pid]['variations'][0];
2085
-				}
2086
-				else {
2032
+				} else {
2087 2033
 					if( strstr( $new_pid, '__') ) {
2088 2034
 						$idp = $new_pid;
2089
-					}
2090
-					else {
2035
+					} else {
2091 2036
 						$idp = $product_to_add_to_cart[$new_pid]['id'];
2092 2037
 					}
2093 2038
 				}
@@ -2112,8 +2057,7 @@  discard block
 block discarded – undo
2112 2057
 			if ( !empty($related_products) ) {
2113 2058
 				// $linked_products = '<h2>'.__('Linked products', 'wpshop').'</h2>';
2114 2059
 				$linked_products .= '<div class="modal_product_related">' .do_shortcode( '[wpshop_related_products pid="' .$product_id. '" sorting="no"]' ).'</div>';
2115
-			}
2116
-			else {
2060
+			} else {
2117 2061
 				$linked_products = '';
2118 2062
 			}
2119 2063
 
@@ -2123,8 +2067,7 @@  discard block
 block discarded – undo
2123 2067
 			$modal_footer_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal_footer', array( 'LINK_CART_PAGE' => wpshop_tools::get_page_id( get_permalink( get_option('wpshop_cart_page_id') ) ) ) );
2124 2068
 
2125 2069
 			$response = array( true, $succes_message_box, $action_after_add, $cart_page_url, $product_id, array($cart_animation_choice, $message_confirmation), array($product_img, $product_title, $linked_products, $product_price), $modal_content, $modal_footer_content );
2126
-		}
2127
-		else {
2070
+		} else {
2128 2071
 			$response = array( false, $return );
2129 2072
 		}
2130 2073
 
@@ -2170,8 +2113,7 @@  discard block
 block discarded – undo
2170 2113
 				}
2171 2114
 				$return = $wpshop_cart->set_product_qty( $product_id, $product_qty, $pid );
2172 2115
 				$response[] = $return;
2173
-			}
2174
-			else {
2116
+			} else {
2175 2117
 				$response[] = false;
2176 2118
 				$response[] = __('Parameters error.','wpshop');
2177 2119
 			}
@@ -2322,16 +2264,13 @@  discard block
 block discarded – undo
2322 2264
 				$permalink_option = get_option('permalink_structure');
2323 2265
 				if ( !empty($permalink_option) ) {
2324 2266
 					$cart_url = get_permalink( wpshop_tools::get_page_id( get_option('wpshop_signup_page_id') ) ).'?complete_sign_up=ok';
2325
-				}
2326
-				else {
2267
+				} else {
2327 2268
 					$cart_url = get_permalink( wpshop_tools::get_page_id(get_option('wpshop_signup_page_id') ) ).'&complete_sign_up=ok';
2328 2269
 				}
2329
-			}
2330
-			else {
2270
+			} else {
2331 2271
 				if ( !empty($_SESSION['cart']) ) {
2332 2272
 					$cart_url = get_permalink( wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')) );
2333
-				}
2334
-				else {
2273
+				} else {
2335 2274
 					$cart_url = get_permalink( wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')) );
2336 2275
 				}
2337 2276
 			}
@@ -2391,9 +2330,7 @@  discard block
 block discarded – undo
2391 2330
 			$retour .= '<div class="wpshop_cls"></div>';
2392 2331
 			$result = json_encode( array(true, $retour) );
2393 2332
 
2394
-		}
2395
-
2396
- 		elseif ( !empty($order_postmeta) && !empty($order_postmeta['order_status']) && in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid'))) {
2333
+		} elseif ( !empty($order_postmeta) && !empty($order_postmeta['order_status']) && in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid'))) {
2397 2334
 			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
2398 2335
  			$order_info_postmeta = get_post_meta($order_id, '_order_info', true);
2399 2336
 
@@ -2409,8 +2346,7 @@  discard block
 block discarded – undo
2409 2346
  			}
2410 2347
 
2411 2348
  			$result = json_encode( array(true, $billing_form, $shipping_form, $current_customer_id) );
2412
- 		}
2413
-		else {
2349
+ 		} else {
2414 2350
 				// Check the attribute set id of Billing Address
2415 2351
 				$query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE name = "' .__('Billing address', 'wpshop'). '"', '');
2416 2352
 				$attribute_set_id = $wpdb->get_var($query);
@@ -2472,8 +2408,7 @@  discard block
 block discarded – undo
2472 2408
 							$user_id = wp_create_user( sanitize_user( $value ), wp_generate_password( 12, false ) );
2473 2409
 							$query = $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id );
2474 2410
 							$attribute_option_id = $wpdb->get_var( $query );
2475
-						}
2476
-						else {
2411
+						} else {
2477 2412
 							$entity_args = array(
2478 2413
 								'post_type' 	 => $attribute_default_value['default_value'],
2479 2414
 								'post_title'  	 => $value,
@@ -2482,8 +2417,7 @@  discard block
 block discarded – undo
2482 2417
 							);
2483 2418
 							$attribute_option_id = wp_insert_post($entity_args);
2484 2419
 						}
2485
-					}
2486
-					else {
2420
+					} else {
2487 2421
 						$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status'=>'valid', 'creation_date'=>current_time('mysql', 0), 'position' => 1, 'attribute_id'=>$attribute_def->id, 'value'=>$value, 'label'=>$value) );
2488 2422
 						$attribute_option_id = $wpdb->insert_id;
2489 2423
 					}
@@ -2572,8 +2506,7 @@  discard block
 block discarded – undo
2572 2506
 			}
2573 2507
 
2574 2508
 			echo json_encode( array( true,  __('Element has been saved', 'wpshop'), $attribute_to_reload, $new_entity_id) );
2575
-		}
2576
-		else {
2509
+		} else {
2577 2510
 			echo json_encode( array(false, __('An error occured while adding your element', 'wpshop')) );
2578 2511
 		}
2579 2512
 
@@ -2613,20 +2546,17 @@  discard block
 block discarded – undo
2613 2546
 				if ( !empty($available_payement_method[0]) ) {
2614 2547
 					if ( $cart_type=='quotation' ) {
2615 2548
 						$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_quotation_validation_button', array() );
2616
-					}
2617
-					else {
2549
+					} else {
2618 2550
 						$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_validation_button', array() );
2619 2551
 					}
2620 2552
 				}
2621
-			}
2622
-			else {
2553
+			} else {
2623 2554
 				$checkout_payment_button = wpshop_display::display_template_element('wpshop_checkout_page_impossible_to_order', array());
2624 2555
 			}
2625 2556
 			if( $address_type == 'billing_address') {
2626 2557
 				$billing_option = get_option( 'wpshop_billing_address' );
2627 2558
 				$address_option = $billing_option['choice'];
2628
-			}
2629
-			else {
2559
+			} else {
2630 2560
 				$shipping_address_option = get_option('wpshop_shipping_address_choice');
2631 2561
 				$address_option = $shipping_address_option['choice'];
2632 2562
 			}
@@ -2638,8 +2568,7 @@  discard block
 block discarded – undo
2638 2568
 
2639 2569
 			$edit_link = '<a href="' .get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&') . 'action=editAddress&amp;id='.$address_id.'" title="' .__('Edit', 'wpshop'). '">' .__('Edit', 'wpshop'). '</a>';
2640 2570
 			$result = json_encode( array(true, $retour, $edit_link, $is_allowed_destination, $checkout_payment_button) );
2641
-		}
2642
-		else {
2571
+		} else {
2643 2572
 			$result = json_encode( array(false, 'missing_informations') );
2644 2573
 		}
2645 2574
 		echo $result;
@@ -2708,13 +2637,11 @@  discard block
 block discarded – undo
2708 2637
 					wps_address::save_address_infos( $shipping_address);
2709 2638
 				}
2710 2639
 				$result = json_encode( array(true, __('Customer created', 'wpshop'), $user_id) );
2711
-			}
2712
-			else {
2640
+			} else {
2713 2641
 				$result = json_encode( array(false, __('A customer account is already created with this email address', 'wpshop')) );
2714 2642
 			}
2715 2643
 
2716
-		}
2717
-		else {
2644
+		} else {
2718 2645
 			$result = json_encode( array(false, __('An email address is required', 'wpshop')) );
2719 2646
 		}
2720 2647
 		echo $result;
@@ -2742,8 +2669,7 @@  discard block
 block discarded – undo
2742 2669
 			$wps_message = new wps_message_ctr();
2743 2670
 			$wps_message->wpshop_prepared_email( $email, $model_name, array('order_id' => $order_id, 'order_key' => ( ( !empty($order_post_meta) && !empty($order_post_meta['order_key']) ) ? $order_post_meta['order_key'] : '' ), 'order_date' => ( ( !empty($order_post_meta) && !empty($order_post_meta['order_date']) ) ? $order_post_meta['order_date'] : '' ),'customer_first_name' => $first_name, 'customer_last_name' => $last_name) );
2744 2671
 			$result = array('status' => true, 'response' => $wps_message->get_historic_message_by_type($message_type_id) );
2745
-		}
2746
-		else {
2672
+		} else {
2747 2673
 			$result = array('status' => false, 'response' => __('An error occured', 'wpshop') );
2748 2674
 		}
2749 2675
 		echo json_encode($result);
@@ -2770,8 +2696,7 @@  discard block
 block discarded – undo
2770 2696
 			$n = WPSHOP_UPLOAD_URL.'/'.$name;
2771 2697
 			update_post_meta( $element_identifier, 'attribute_option_is_downloadable_', array('file_url' => $n));
2772 2698
 			$result = '<a href="' .$n. '" target="_blank" download>' .$name. '</a>';
2773
-		}
2774
-		else {
2699
+		} else {
2775 2700
 			$result = '';
2776 2701
 		}
2777 2702
 		echo $result;
@@ -3000,12 +2925,10 @@  discard block
 block discarded – undo
3000 2925
 
3001 2926
 				$response = __( 'Direct payment link has been send', 'wpshop' );
3002 2927
 				$status = true;
3003
-			}
3004
-			else {
2928
+			} else {
3005 2929
 				$response = __( 'An error was occured', 'wpshop' );
3006 2930
 			}
3007
-		}
3008
-		else {
2931
+		} else {
3009 2932
 			$response = __( 'An error was occured, no Order ID defined', 'wpshop' );
3010 2933
 		}
3011 2934
 		echo json_encode( array( 'status' => $status, 'response' => $response) );
@@ -3092,8 +3015,7 @@  discard block
 block discarded – undo
3092 3015
 					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge( $common_datas, array( 'attribute_id' => 28, 'value' => $ht ) ) );
3093 3016
 					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array_merge( $common_datas, array( 'attribute_id' => 29, 'value' => $the_tax->rate_id ) ) );
3094 3017
 					$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array_merge( $common_datas, array( 'attribute_id' => 30, 'value' => $tax_amount ) ) );
3095
-				}
3096
-				else {
3018
+				} else {
3097 3019
 					$common_datas = array(
3098 3020
 						'value_id' => null,
3099 3021
 						'entity_type_id' => 5,
@@ -3261,8 +3183,7 @@  discard block
 block discarded – undo
3261 3183
 						if( !empty($element_definition['content'][$att]) ) {
3262 3184
 							$formatted_datas[$element_id]['content'][$att] = $element_definition['content'][$att];
3263 3185
 							$controller_rows_array[ $att ] = true;
3264
-						}
3265
-						else {
3186
+						} else {
3266 3187
 							$formatted_datas[$element_id]['content'][$att] = array();
3267 3188
 						}
3268 3189
 					}
@@ -3292,8 +3213,7 @@  discard block
 block discarded – undo
3292 3213
 										if( $current_attribute->data_type_to_use == 'internal' ) {
3293 3214
 											$current_val = get_the_title($current_val);
3294 3215
 											$old_val = get_the_title($old_val);
3295
-										}
3296
-										else {
3216
+										} else {
3297 3217
 											$query = $wpdb->prepare( 'SELECT label FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS.' WHERE id=%d', $old_val);
3298 3218
 											$old_val = $wpdb->get_var( $query );
3299 3219
 											$query = $wpdb->prepare( 'SELECT label FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS.' WHERE id=%d', $current_val);
@@ -3348,12 +3268,10 @@  discard block
 block discarded – undo
3348 3268
 				update_option( WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $cat_id, $category_option );
3349 3269
 				$response = '<img src="' .WPSHOP_DEFAULT_CATEGORY_PICTURE. '" alt="No picture" class="category_thumbnail_preview"/>';
3350 3270
 				$status = true;
3351
-			}
3352
-			else {
3271
+			} else {
3353 3272
 				$response = __( 'Category options are not defined', 'wpshop');
3354 3273
 			}
3355
-		}
3356
-		else {
3274
+		} else {
3357 3275
 			$response = __( 'Category ID is not defined', 'wpshop');
3358 3276
 		}
3359 3277
 		echo json_encode( array( 'status' => $status, 'response' => $response) );
@@ -3385,8 +3303,7 @@  discard block
 block discarded – undo
3385 3303
 		if ( $attributeSetSectionCreation == 'done' ) {
3386 3304
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('New section has been created successfully', 'wpshop');
3387 3305
 			$more_script = 'wpshop_go_to("#attribute_group_'.$wpdb->insert_id.'")';
3388
-		}
3389
-		else {
3306
+		} else {
3390 3307
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while saving new section', 'wpshop');
3391 3308
 		}
3392 3309
 
@@ -3414,10 +3331,11 @@  discard block
 block discarded – undo
3414 3331
 		$attributeSetInfos['backend_display_type'] = $backend_display_type;
3415 3332
 		$attributeSetInfos['display_on_frontend'] = $display_on_frontend;
3416 3333
 		$attributeSetSectionCreation = wpshop_database::update($attributeSetInfos, $attributeSetSectionId, WPSHOP_DBT_ATTRIBUTE_GROUP);
3417
-		if ( $attributeSetSectionCreation == 'done' )
3418
-			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been updated successfully', 'wpshop');
3419
-		else
3420
-			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while updating the section', 'wpshop');
3334
+		if ( $attributeSetSectionCreation == 'done' ) {
3335
+					$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been updated successfully', 'wpshop');
3336
+		} else {
3337
+					$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while updating the section', 'wpshop');
3338
+		}
3421 3339
 		echo wpshop_attributes_set::attributeSetDetailsManagement($elementIdentifier) . '<script type="text/javascript" >wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);</script>';
3422 3340
 		wp_die();
3423 3341
 	}
@@ -3437,9 +3355,9 @@  discard block
 block discarded – undo
3437 3355
 		if ( $attributeSetSectionCreation == 'done' ) {
3438 3356
 			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been successfully been deleted', 'wpshop');
3439 3357
 			$more_script.='jQuery("#attribute_group_'.$attributeSetSectionId.'").remove();';
3358
+		} else {
3359
+					$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while deleting the section', 'wpshop');
3440 3360
 		}
3441
-		else
3442
-			$attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while deleting the section', 'wpshop');
3443 3361
 		echo '<script type="text/javascript" >wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);'.$more_script.'</script>';
3444 3362
 		wp_die();
3445 3363
 	}
@@ -3505,8 +3423,7 @@  discard block
 block discarded – undo
3505 3423
 		if($save_unit_result == 'done'){
3506 3424
 			$save_output = wpshop_attributes_unit::elementList();
3507 3425
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The new unit has been saved succesfully', 'wpshop');
3508
-		}
3509
-		else{
3426
+		} else{
3510 3427
 			$save_output = wpshop_attributes_unit::elementEdition();
3511 3428
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during new unit saving', 'wpshop');
3512 3429
 		}
@@ -3542,8 +3459,7 @@  discard block
 block discarded – undo
3542 3459
 		if ( $save_unit_result == 'done' ) {
3543 3460
 			$save_output = wpshop_attributes_unit::elementList();
3544 3461
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit has been saved succesfully', 'wpshop');
3545
-		}
3546
-		else {
3462
+		} else {
3547 3463
 			$save_output = wpshop_attributes_unit::elementEdition($attributeUnitId);
3548 3464
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit saving', 'wpshop');
3549 3465
 		}
@@ -3563,8 +3479,7 @@  discard block
 block discarded – undo
3563 3479
 		$save_unit_result = wpshop_database::update($attribute_unit_informations, $unit_id, WPSHOP_DBT_ATTRIBUTE_UNIT);
3564 3480
 		if ( $save_unit_result == 'done' ) {
3565 3481
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action succesful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit has been deleted succesfully', 'wpshop');
3566
-		}
3567
-		else {
3482
+		} else {
3568 3483
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit deletion', 'wpshop');
3569 3484
 		}
3570 3485
 
@@ -3606,8 +3521,7 @@  discard block
 block discarded – undo
3606 3521
 		if($save_unit_result == 'done'){
3607 3522
 			$save_output = wpshop_attributes_unit::unit_group_list();
3608 3523
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The new unit group has been saved succesfully', 'wpshop');
3609
-		}
3610
-		else{
3524
+		} else{
3611 3525
 			$save_output = wpshop_attributes_unit::unit_group_edition();
3612 3526
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during new unit group saving', 'wpshop');
3613 3527
 		}
@@ -3630,8 +3544,7 @@  discard block
 block discarded – undo
3630 3544
 		if($save_unit_result == 'done'){
3631 3545
 			$save_output = wpshop_attributes_unit::unit_group_list();
3632 3546
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit group has been saved succesfully', 'wpshop');
3633
-		}
3634
-		else{
3547
+		} else{
3635 3548
 			$save_output = wpshop_attributes_unit::unit_group_edition($attributeUnitId);
3636 3549
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit group saving', 'wpshop');
3637 3550
 		}
@@ -3651,8 +3564,7 @@  discard block
 block discarded – undo
3651 3564
 		$save_unit_result = wpshop_database::update($attribute_unit_informations, $unit_id, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
3652 3565
 		if($save_unit_result == 'done'){
3653 3566
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action succesful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit group has been deleted succesfully', 'wpshop');
3654
-		}
3655
-		else{
3567
+		} else{
3656 3568
 			$save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit group deletion', 'wpshop');
3657 3569
 		}
3658 3570
 
@@ -3681,7 +3593,9 @@  discard block
 block discarded – undo
3681 3593
 		$data = wpshop_products::wpshop_get_product_by_criteria( $criteria, $cid, $products_id, $display_type, $order, $page_number, $products_per_page );
3682 3594
 		if($data[0]) {
3683 3595
 			echo json_encode(array(true, do_shortcode($data[1])));
3684
-		} else echo json_encode(array(false,__('No product found','wpshop')));
3596
+		} else {
3597
+			echo json_encode(array(false,__('No product found','wpshop')));
3598
+		}
3685 3599
 		wp_die();
3686 3600
 	}
3687 3601
 	add_action( 'wp_ajax_wps_products_by_criteria', 'products_by_criteria' );
@@ -3708,10 +3622,10 @@  discard block
 block discarded – undo
3708 3622
 			if (!empty($user_info->user_email)) {
3709 3623
 				$wps_message_ctr->wpshop_email($user_info->user_email, $title, $message, $save=true, $model_id=$post_id, $object=array());
3710 3624
 				$array = array('result' => true, 'message' => '');
3625
+			} else {
3626
+				$array = array('result' => true, 'message' => __('An error occured','wpshop'));
3711 3627
 			}
3712
-			else $array = array('result' => true, 'message' => __('An error occured','wpshop'));
3713
-		}
3714
-		else {
3628
+		} else {
3715 3629
 			$array = array('result' => false, 'message' => __('An error occured','wpshop'));
3716 3630
 		}
3717 3631
 
@@ -3740,12 +3654,10 @@  discard block
 block discarded – undo
3740 3654
 				$wps_message_ctr->wpshop_email($data['mess_user_email'], $data['mess_title'], $data['mess_message'], $save=false, $object=array());
3741 3655
 
3742 3656
 				$array = array('result' => true, 'message' => '');
3743
-			}
3744
-			else {
3657
+			} else {
3745 3658
 				$array = array('result' => false, 'message' => __('An error occured','wpshop'));
3746 3659
 			}
3747
-		}
3748
-		else {
3660
+		} else {
3749 3661
 			$array = array('result' => false, 'message' => __('An error occured','wpshop'));
3750 3662
 		}
3751 3663
 
@@ -3777,7 +3689,9 @@  discard block
 block discarded – undo
3777 3689
 			$order = $wps_cart_ctr->calcul_cart_information(array());
3778 3690
 			$wps_cart_ctr->store_cart_in_session($order);
3779 3691
 			echo json_encode(array(true, ''));
3780
-		} else echo json_encode(array(false, $result['message']));
3692
+		} else {
3693
+			echo json_encode(array(false, $result['message']));
3694
+		}
3781 3695
 		wp_die();
3782 3696
 	}
3783 3697
 	add_action( 'wp_ajax_wps_cart_action_apply_coupon', 'applyCoupon' );
Please login to merge, or discard this patch.