Completed
Push — master ( 431b9c...260ddf )
by
unknown
12:45
created
includes/modules/wps_quotation/controller/wps_quotation_backend_ctr.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_quotation_backend_ctr {
3 3
 	/*
4 4
 	 * Declare filter and actions
5 5
 	 */
6 6
 	public function __construct() {
7 7
 		/**	Appel des styles pour l'administration / Call style for administration	*/
8
-		add_action( 'admin_enqueue_scripts', array( &$this, 'admin_assets' ) );
8
+		add_action('admin_enqueue_scripts', array(&$this, 'admin_assets'));
9 9
 
10 10
 		/**	Définition du filtre permettant le champs d'activation du module avec un code obtenu sur la boutique / Define the filter allowing to display an input for module activation with a given code from the shop	*/
11
-		add_filter( 'wps-addon-extra-info', array( $this, 'display_addon_activation_form' ) );
11
+		add_filter('wps-addon-extra-info', array($this, 'display_addon_activation_form'));
12 12
 		/**	Déclaration de la requête Ajax permettant de vérifier le code d'activation et d'activer le module le cas échéant / Declare ajax request allowing to check the code and activate addon in case the code is correct	*/
13
-		add_action( 'wp_ajax_check_code_for_activation', array( $this, 'check_code_for_activation' ) );
13
+		add_action('wp_ajax_check_code_for_activation', array($this, 'check_code_for_activation'));
14 14
 
15
-		add_filter( 'wps-filter-free-product-bton-tpl', array( $this, 'wps_free_product_bton_tpl' ) );
16
-		add_action( 'wp_ajax_wps_free_product_form_page_tpl', array( $this, 'wps_free_product_form_page_tpl' ) );
17
-		add_action( 'wp_ajax_wps_create_new_free_product', array( $this, 'wps_create_new_free_product' ) );
18
-		add_action( 'init', array( $this, 'wps_free_product_post_status' ) );
15
+		add_filter('wps-filter-free-product-bton-tpl', array($this, 'wps_free_product_bton_tpl'));
16
+		add_action('wp_ajax_wps_free_product_form_page_tpl', array($this, 'wps_free_product_form_page_tpl'));
17
+		add_action('wp_ajax_wps_create_new_free_product', array($this, 'wps_create_new_free_product'));
18
+		add_action('init', array($this, 'wps_free_product_post_status'));
19 19
 	}
20 20
 
21 21
 
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
 	 * Inclusion des feuilles de styles pour l'administration / Admin css enqueue
24 24
 	 */
25 25
 	function admin_assets($hook) {
26
-		if ( $hook != 'settings_page_wpshop_option' )
26
+		if ($hook != 'settings_page_wpshop_option')
27 27
 			return;
28 28
 
29
-		wp_enqueue_script( 'wps_quotation_admin_js', WPS_QUOTATION_URL . '/assets/js/backend.js', array( 'jquery', ), WPSHOP_VERSION );
29
+		wp_enqueue_script('wps_quotation_admin_js', WPS_QUOTATION_URL . '/assets/js/backend.js', array('jquery',), WPSHOP_VERSION);
30 30
 	}
31 31
 
32 32
 
@@ -34,36 +34,36 @@  discard block
 block discarded – undo
34 34
 	/*
35 35
 	 * Create a new post status for free products
36 36
 	 */
37
-	function wps_free_product_post_status(){
38
-		register_post_status( 'free_product', array(
39
-			'label'                     => __( 'Free product', 'wpshop' ),
37
+	function wps_free_product_post_status() {
38
+		register_post_status('free_product', array(
39
+			'label'                     => __('Free product', 'wpshop'),
40 40
 			'public'                    => false,
41 41
 			'exclude_from_search'       => true,
42 42
 			'show_in_admin_all_list'    => false,
43 43
 			'show_in_admin_status_list' => false,
44
-		) );
44
+		));
45 45
 	}
46 46
 	/*
47 47
 	 * Template for display button - Filter : 'wps_orders\templates\backend\product-listing\wps_orders_product_listing.php'
48 48
 	 * @param integer $order_id ID of order
49 49
 	 */
50 50
 	public function wps_free_product_bton_tpl($order_id) {
51
-		$order_post_meta = get_post_meta( $order_id, '_wpshop_order_status', true );
52
-		if ( 'completed' != $order_post_meta ) {
53
-			require ( wpshop_tools::get_template_part( WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "add_free_product_bton_tpl") );
51
+		$order_post_meta = get_post_meta($order_id, '_wpshop_order_status', true);
52
+		if ('completed' != $order_post_meta) {
53
+			require (wpshop_tools::get_template_part(WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "add_free_product_bton_tpl"));
54 54
 		}
55 55
 	}
56 56
 	/*
57 57
 	 * Template for display form (AjaxForm) - Call from : Line 3 'templates\backend\add_free_product_form_page_tpl.php'
58 58
 	 */
59 59
 	public function wps_free_product_form_page_tpl() {
60
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
60
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
61 61
 
62
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_free_product_form_page_tpl' ) )
62
+		if (!wp_verify_nonce($_wpnonce, 'wps_free_product_form_page_tpl'))
63 63
 			wp_die();
64 64
 
65
-		$order_id = ( !empty($_GET['oid']) ) ? intval( $_GET['oid']) : null;
66
-		require ( wpshop_tools::get_template_part( WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "add_free_product_form_page_tpl") );
65
+		$order_id = (!empty($_GET['oid'])) ? intval($_GET['oid']) : null;
66
+		require (wpshop_tools::get_template_part(WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "add_free_product_form_page_tpl"));
67 67
 		wp_die();
68 68
 	}
69 69
 	/*
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 	 * @return integer $pid Product ID
74 74
 	 */
75 75
 	public function wps_create_new_free_product() {
76
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
76
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
77 77
 
78
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_create_new_free_product' ) )
78
+		if (!wp_verify_nonce($_wpnonce, 'wps_create_new_free_product'))
79 79
 			wp_die();
80 80
 
81 81
 		global $wpdb;
@@ -83,43 +83,43 @@  discard block
 block discarded – undo
83 83
 		$output = __('Error at product creation!', 'wpshop');
84 84
 		$new_product_id = -1;
85 85
 
86
-		$post_title = ( !empty($_POST['post_title']) ) ? sanitize_text_field( $_POST['post_title'] ) : -1;
87
-		$post_content = ( !empty($_POST['post_content']) ) ? nl2br( esc_textarea( $_POST['post_content'] ) ) : ''; 
88
-		$attributes = ( !empty($_POST['attribute']) ) ? (array) $_POST['attribute'] : array();
86
+		$post_title = (!empty($_POST['post_title'])) ? sanitize_text_field($_POST['post_title']) : -1;
87
+		$post_content = (!empty($_POST['post_content'])) ? nl2br(esc_textarea($_POST['post_content'])) : ''; 
88
+		$attributes = (!empty($_POST['attribute'])) ? (array)$_POST['attribute'] : array();
89 89
 
90
-		if( $post_title != -1 ) {
91
-			$new_product_id = wp_insert_post( array(
90
+		if ($post_title != -1) {
91
+			$new_product_id = wp_insert_post(array(
92 92
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
93 93
 				'post_status' => 'free_product',
94 94
 				'post_title' => $post_title,
95 95
 				'post_content' => $post_content,
96
-			) );
97
-			if( !is_object( $new_product_id ) ) {
96
+			));
97
+			if (!is_object($new_product_id)) {
98 98
 				$attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code('wpshop_product'));
99 99
 				$id_attribute_set = null;
100
-				foreach( $attribute_set_list as $attribute_set ) {
101
-					if( $attribute_set->slug == 'free_product' ) {
100
+				foreach ($attribute_set_list as $attribute_set) {
101
+					if ($attribute_set->slug == 'free_product') {
102 102
 						$id_attribute_set = $attribute_set->id;
103 103
 						break;
104 104
 					}
105 105
 				}
106
-				update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $id_attribute_set );
107
-				$data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $new_product_id );
108
-				$data_to_save['wpshop_product_attribute'] = ( !empty($attributes) ) ? $attributes : array();
106
+				update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $id_attribute_set);
107
+				$data_to_save['post_ID'] = $data_to_save['product_id'] = intval($new_product_id);
108
+				$data_to_save['wpshop_product_attribute'] = (!empty($attributes)) ? $attributes : array();
109 109
 				$data_to_save['user_ID'] = get_current_user_id();
110 110
 				$data_to_save['action'] = 'editpost';
111 111
 				$status = false;
112 112
 				$output = __('Product created partially!', 'wpshop');
113
-				if( !empty($new_product_id) && !empty( $data_to_save['user_ID'] ) ) {
113
+				if (!empty($new_product_id) && !empty($data_to_save['user_ID'])) {
114 114
 					$product_class = new wpshop_products();
115
-					$product_class->save_product_custom_informations( $new_product_id, $data_to_save );
115
+					$product_class->save_product_custom_informations($new_product_id, $data_to_save);
116 116
 					$status = true;
117 117
 					$output = __('Product created successfully.', 'wpshop');
118 118
 				}
119 119
 			}
120 120
 		}
121 121
 
122
-		echo json_encode( array( 'status' => $status, 'message' => $output, 'pid' => $new_product_id ) );
122
+		echo json_encode(array('status' => $status, 'message' => $output, 'pid' => $new_product_id));
123 123
 		wp_die();
124 124
 	}
125 125
 
@@ -129,78 +129,78 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @param string $module Le nom du module en cours d'affichage et pour lequel il faut afficher le champs/ The module being displayed and to add input for
131 131
 	 */
132
-	function display_addon_activation_form( $module ) {
133
-		if ( WPS_QUOTATION_DIR == $module ) {
132
+	function display_addon_activation_form($module) {
133
+		if (WPS_QUOTATION_DIR == $module) {
134 134
 
135 135
 			/** Récupération du statut du module devis / Get current quotation addon state */
136
-			$addon_option = get_option( 'wpshop_addons' );
136
+			$addon_option = get_option('wpshop_addons');
137 137
 
138
-			if ( empty( $addon_option ) || ( !empty( $addon_option[ 'WPSHOP_ADDONS_QUOTATION' ] ) && ( false === ( $addon_option['WPSHOP_ADDONS_QUOTATION']['activate'] ) ) ) ) {
139
-				$quotation_module_def = get_plugin_data( WPS_QUOTATION_PATH . '/wps_quotation.php' );
140
-				require ( wpshop_tools::get_template_part( WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "addon", "activation" ) );
138
+			if (empty($addon_option) || (!empty($addon_option['WPSHOP_ADDONS_QUOTATION']) && (false === ($addon_option['WPSHOP_ADDONS_QUOTATION']['activate'])))) {
139
+				$quotation_module_def = get_plugin_data(WPS_QUOTATION_PATH . '/wps_quotation.php');
140
+				require (wpshop_tools::get_template_part(WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "addon", "activation"));
141 141
 			}
142
-			else if ( !empty( $addon_option[ 'WPSHOP_ADDONS_QUOTATION' ] ) && ( true === ( $addon_option['WPSHOP_ADDONS_QUOTATION']['activate'] ) ) ) {
143
-				require ( wpshop_tools::get_template_part( WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "addon", "activated" ) );
142
+			else if (!empty($addon_option['WPSHOP_ADDONS_QUOTATION']) && (true === ($addon_option['WPSHOP_ADDONS_QUOTATION']['activate']))) {
143
+				require (wpshop_tools::get_template_part(WPS_QUOTATION_DIR, WPS_QUOTATION_TEMPLATES_MAIN_DIR, "backend", "addon", "activated"));
144 144
 			}
145 145
 		}
146 146
 	}
147 147
 
148 148
 	function check_code_for_activation() {
149
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
149
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
150 150
 
151
-		if ( !wp_verify_nonce( $_wpnonce, 'check_code_for_activation' ) )
151
+		if (!wp_verify_nonce($_wpnonce, 'check_code_for_activation'))
152 152
 			wp_die();
153 153
 
154 154
 		$response = array(
155 155
 			'status' => false,
156
-			'message' => __( 'Activation code for quotation addon is invalid, please check it and try again.', 'wpshop' ),
156
+			'message' => __('Activation code for quotation addon is invalid, please check it and try again.', 'wpshop'),
157 157
 		);
158
-		$required_code = wpshop_tools::get_plugin_validation_code( WPS_QUOTATION_DIR, site_url() );
159
-		$code = sanitize_text_field( $_POST[ 'code' ] );
160
-		if ( $code === $required_code ) {
158
+		$required_code = wpshop_tools::get_plugin_validation_code(WPS_QUOTATION_DIR, site_url());
159
+		$code = sanitize_text_field($_POST['code']);
160
+		if ($code === $required_code) {
161 161
 			$this->action_to_do_to_activate();
162 162
 			$response = array(
163 163
 				'status' => true,
164
-				'message' => __( 'Quotation addon have been successfully activated.', 'wpshop' ),
164
+				'message' => __('Quotation addon have been successfully activated.', 'wpshop'),
165 165
 			);
166 166
 		}
167 167
 
168
-		wp_die( json_encode( $response ) );
168
+		wp_die(json_encode($response));
169 169
 	}
170 170
 
171 171
 	/**
172 172
 	 * Action to do when the activation code is OK
173 173
 	 */
174
-	function action_to_do_to_activate(){
174
+	function action_to_do_to_activate() {
175 175
 		global $wpdb;
176 176
 		/** Activate the plug in **/
177
-		$addon_option = get_option( 'wpshop_addons' );
177
+		$addon_option = get_option('wpshop_addons');
178 178
 		$addon_option['WPSHOP_ADDONS_QUOTATION']['activate'] = true;
179 179
 		$addon_option['WPSHOP_ADDONS_QUOTATION']['activation_date'] = current_time('mysql', 0);
180 180
 
181
-		update_option( 'wpshop_addons', $addon_option );
181
+		update_option('wpshop_addons', $addon_option);
182 182
 
183 183
 		/** Activate the Quotation attribute **/
184
-		$wpdb->update( WPSHOP_DBT_ATTRIBUTE, array('status' => 'valid'), array('code' => 'quotation_allowed') );
184
+		$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('status' => 'valid'), array('code' => 'quotation_allowed'));
185 185
 
186
-		$attribute_def = wpshop_attributes::getElement( 'quotation_allowed', '"valid"', 'code' );
186
+		$attribute_def = wpshop_attributes::getElement('quotation_allowed', '"valid"', 'code');
187 187
 
188 188
 		/** Add the attribute in attributes groups section **/
189
-		$query = $wpdb->prepare('SELECT id, attribute_set_id FROM ' .WPSHOP_DBT_ATTRIBUTE_GROUP. ' WHERE code = %s', 'general');
190
-		$attribute_set_sections = $wpdb->get_results( $query );
191
-
192
-		if ( !empty($attribute_set_sections) ) {
193
-			$entity_type_def = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
194
-			if ( !empty( $entity_type_def) ) {
195
-				foreach ( $attribute_set_sections as $attribute_set_section ) {
196
-					$query = $wpdb->prepare('SELECT COUNT(*) AS count_attribute_affectation FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d', $entity_type_def, $attribute_set_section->attribute_set_id, $attribute_set_section->id, $attribute_def->id);
197
-					$count_attribute_affectation = $wpdb->get_var( $query );
198
-
199
-					if ( $count_attribute_affectation == 0 ) {
200
-						$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_type_def, $attribute_set_section->attribute_set_id, $attribute_set_section->id);
201
-						$max_position = $wpdb->get_var( $query );
189
+		$query = $wpdb->prepare('SELECT id, attribute_set_id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'general');
190
+		$attribute_set_sections = $wpdb->get_results($query);
191
+
192
+		if (!empty($attribute_set_sections)) {
193
+			$entity_type_def = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
194
+			if (!empty($entity_type_def)) {
195
+				foreach ($attribute_set_sections as $attribute_set_section) {
196
+					$query = $wpdb->prepare('SELECT COUNT(*) AS count_attribute_affectation FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d', $entity_type_def, $attribute_set_section->attribute_set_id, $attribute_set_section->id, $attribute_def->id);
197
+					$count_attribute_affectation = $wpdb->get_var($query);
198
+
199
+					if ($count_attribute_affectation == 0) {
200
+						$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_type_def, $attribute_set_section->attribute_set_id, $attribute_set_section->id);
201
+						$max_position = $wpdb->get_var($query);
202 202
 						/** Insert attribute detail **/
203
-						$wpdb->insert( WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_type_def, 'attribute_set_id' =>  $attribute_set_section->attribute_set_id, 'attribute_group_id' => $attribute_set_section->id, 'attribute_id' => $attribute_def->id, 'position' => (int)$max_position + 1) );
203
+						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_type_def, 'attribute_set_id' =>  $attribute_set_section->attribute_set_id, 'attribute_group_id' => $attribute_set_section->id, 'attribute_id' => $attribute_def->id, 'position' => (int)$max_position + 1));
204 204
 					}
205 205
 				}
206 206
 			}
Please login to merge, or discard this patch.
includes/modules/billing/billing.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 					add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info');
104 104
 					add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info');
105 105
 
106
-					register_setting( 'wpshop_options', 'wpshop_billing_invoice_footer_area' );
107
-					add_settings_field( 'wpshop_billing_invoice_footer_area', __( 'Free text for invoice footer', 'wpshop' ), array( $this, 'wpshop_billing_invoice_footer_area' ), 'wpshop_billing_info', 'wpshop_billing_info' );
106
+					register_setting('wpshop_options', 'wpshop_billing_invoice_footer_area');
107
+					add_settings_field('wpshop_billing_invoice_footer_area', __('Free text for invoice footer', 'wpshop'), array($this, 'wpshop_billing_invoice_footer_area'), 'wpshop_billing_info', 'wpshop_billing_info');
108 108
 
109 109
 					$quotation_option = get_option('wpshop_addons');
110 110
 					if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) {
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
 		 * Define the field allowing to define the invoice footer
166 166
 		 */
167 167
 		public function wpshop_billing_invoice_footer_area() {
168
-			$wpshop_billing_invoice_footer_area = get_option( 'wpshop_billing_invoice_footer_area' );
168
+			$wpshop_billing_invoice_footer_area = get_option('wpshop_billing_invoice_footer_area');
169 169
 			$wp_editor_args = array(
170 170
 				'media_buttons' => false,
171 171
 			);
172
-			wp_editor( $wpshop_billing_invoice_footer_area, 'wpshop_billing_invoice_footer_area', $wp_editor_args );
172
+			wp_editor($wpshop_billing_invoice_footer_area, 'wpshop_billing_invoice_footer_area', $wp_editor_args);
173 173
 		}
174 174
 
175 175
 				public function wpshop_options_validate_billing_number_figures($input)
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 						update_option('wpshop_billing_current_number', $billing_current_number);
308 308
 
309 309
 						/**		Create the new invoice number with all parameters viewed above		*/
310
-						$invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number));
310
+						$invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string)sprintf('%0' . $number_figures . 'd', $billing_current_number));
311 311
 
312 312
 						return $invoice_ref;
313 313
 				}
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 																		$item_title = $item['item_name'];
472 472
 																}
473 473
 																$sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title;
474
-																if ( 'free_product' === get_post_status( $item_id ) ) {
474
+																if ('free_product' === get_post_status($item_id)) {
475 475
 																	$sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = '<b>' . $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] . '</b><br>' . get_post_field('post_content', $item_id);
476 476
 																}
477 477
 																/**		Get attribute order for current product		*/
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 
608 608
 																		unset($sub_tpl_component);
609 609
 																		$total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0;
610
-																} else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) {
610
+																} else if (!empty($received_payment['status']) && 'payment_received' == $received_payment['status']) {
611 611
 																		$last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0;
612 612
 																}
613 613
 
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 				public static function generate_footer_invoice() {
993 993
 						$output = '';
994 994
 						$emails = get_option('wpshop_emails', array());
995
-						$wpshop_billing_invoice_footer_area = get_option( 'wpshop_billing_invoice_footer_area' );
995
+						$wpshop_billing_invoice_footer_area = get_option('wpshop_billing_invoice_footer_area');
996 996
 
997 997
 						$tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : '';
998 998
 						$tpl_component['COMPANY_WEBSITE'] = site_url();
Please login to merge, or discard this patch.
wps_product/modules/wps-mass-interface3/include/class-mass-interface3.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @package wps-mass-interface3
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 /**
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 * @method __construct
63 63
 	 */
64 64
 	public function __construct() {
65
-		add_action( 'admin_menu', array( $this, 'mass_init' ), 350 );
66
-		add_action( 'wp_ajax_wps_mass_3_new', array( $this, 'ajax_new' ) );
67
-		add_action( 'wp_ajax_wps_mass_3_save', array( $this, 'ajax_save' ) );
68
-		add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
65
+		add_action('admin_menu', array($this, 'mass_init'), 350);
66
+		add_action('wp_ajax_wps_mass_3_new', array($this, 'ajax_new'));
67
+		add_action('wp_ajax_wps_mass_3_save', array($this, 'ajax_save'));
68
+		add_filter('set-screen-option', array($this, 'set_screen_option'), 10, 3);
69 69
 	}
70 70
 	/**
71 71
 	 * Page Initialisation
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 	 * @return void
75 75
 	 */
76 76
 	public function mass_init() {
77
-		$page = ( isset( $_GET['page'] ) && strpos( $_GET['page'] , 'mass_edit_interface3_att_set_' ) !== false ) ? $_GET['page'] : 'mass_edit_interface3_att_set_1';
77
+		$page = (isset($_GET['page']) && strpos($_GET['page'], 'mass_edit_interface3_att_set_') !== false) ? $_GET['page'] : 'mass_edit_interface3_att_set_1';
78 78
 		$this->hook = add_submenu_page(
79 79
 			'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
80
-			__( 'Mass product edit', 'wpshop' ),
81
-			__( 'Mass product edit', 'wpshop' ),
80
+			__('Mass product edit', 'wpshop'),
81
+			__('Mass product edit', 'wpshop'),
82 82
 			'manage_options',
83 83
 			$page,
84
-			array( $this, 'mass_interface' )
84
+			array($this, 'mass_interface')
85 85
 		);
86
-		add_action( "load-{$this->hook}", array( $this, 'mass_interface_screen_option' ) );
87
-		add_action( "admin_print_scripts-{$this->hook}", array( $this, 'scripts' ) );
88
-		add_action( "admin_print_styles-{$this->hook}", array( $this, 'styles' ) );
86
+		add_action("load-{$this->hook}", array($this, 'mass_interface_screen_option'));
87
+		add_action("admin_print_scripts-{$this->hook}", array($this, 'scripts'));
88
+		add_action("admin_print_styles-{$this->hook}", array($this, 'styles'));
89 89
 	}
90 90
 	/**
91 91
 	 * Page content.
@@ -94,48 +94,48 @@  discard block
 block discarded – undo
94 94
 	 * @return void Direct display.
95 95
 	 */
96 96
 	public function mass_interface() {
97
-		$wp_list_table = $this->wp_list_table( $this->hook );
97
+		$wp_list_table = $this->wp_list_table($this->hook);
98 98
 		$wp_list_table->prepare_items(); ?>
99 99
 		<div class="wrap">
100 100
 		<h1 class="wp-heading-inline"><?php
101
-		echo esc_html( $this->post_type_object->labels->name );
101
+		echo esc_html($this->post_type_object->labels->name);
102 102
 		?></h1>
103 103
 		<?php
104
-		if ( current_user_can( $this->post_type_object->cap->create_posts ) ) {
105
-			echo ' <a href="#addPost" class="page-title-action" data-nonce="' . esc_attr( wp_create_nonce( 'add_post-' . sanitize_title( get_class() ) ) ) . '">';
106
-			echo esc_html( $this->post_type_object->labels->add_new ) . '</a>';
104
+		if (current_user_can($this->post_type_object->cap->create_posts)) {
105
+			echo ' <a href="#addPost" class="page-title-action" data-nonce="' . esc_attr(wp_create_nonce('add_post-' . sanitize_title(get_class()))) . '">';
106
+			echo esc_html($this->post_type_object->labels->add_new) . '</a>';
107 107
 		}
108 108
 		?>
109 109
 		<hr class="wp-header-end">
110
-		<?php echo '<input type="hidden" id="hook" value="' . esc_attr( $this->hook ) . '">'; ?>
110
+		<?php echo '<input type="hidden" id="hook" value="' . esc_attr($this->hook) . '">'; ?>
111 111
 		<form id="posts-filter" method="get">
112 112
 		<?php $wp_list_table->views(); ?>
113
-		<?php $wp_list_table->search_box( $this->post_type_object->labels->search_items, 'post' ); ?>
113
+		<?php $wp_list_table->search_box($this->post_type_object->labels->search_items, 'post'); ?>
114 114
 		<input type="hidden" name="page" value="<?php
115
-		echo esc_attr( str_replace(
115
+		echo esc_attr(str_replace(
116 116
 			"{$wp_list_table->screen->post_type}_page_",
117 117
 			'',
118 118
 			$wp_list_table->screen->id
119
-		) ); ?>">
120
-		<input type="hidden" name="post_type" value="<?php echo esc_attr( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); ?>">
119
+		)); ?>">
120
+		<input type="hidden" name="post_type" value="<?php echo esc_attr(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); ?>">
121 121
 		</form>
122 122
 		<?php $wp_list_table->display(); ?>
123 123
 		<table style="display:none;">
124 124
 		 <tbody id="posts-add">
125
-		  <tr id="inline-edit" class="inline-edit-row inline-edit-row-post <?php echo esc_attr( "inline-edit-{$this->post_type_object->name} quick-edit-row quick-edit-row-post inline-edit-{$this->post_type_object->name}" ); ?>" style="display: none">
126
-		   <td colspan="<?php echo esc_attr( $wp_list_table->get_column_count() ); ?>" class="colspanchange">
125
+		  <tr id="inline-edit" class="inline-edit-row inline-edit-row-post <?php echo esc_attr("inline-edit-{$this->post_type_object->name} quick-edit-row quick-edit-row-post inline-edit-{$this->post_type_object->name}"); ?>" style="display: none">
126
+		   <td colspan="<?php echo esc_attr($wp_list_table->get_column_count()); ?>" class="colspanchange">
127 127
 			<fieldset class="inline-edit-col">
128
-			 <legend class="inline-edit-legend"><?php echo esc_html( $this->post_type_object->labels->add_new ) ?></legend>
128
+			 <legend class="inline-edit-legend"><?php echo esc_html($this->post_type_object->labels->add_new) ?></legend>
129 129
 			 <div class="inline-edit-col">
130 130
 		   <label>
131
-			<span class="title"><?php esc_html_e( 'Title' ); ?></span>
131
+			<span class="title"><?php esc_html_e('Title'); ?></span>
132 132
 			<span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
133 133
 		   </label>
134 134
 			 </div>
135 135
 			</fieldset>
136 136
 			<p class="submit inline-edit-save">
137
-			 <button type="button" class="button cancel alignleft"><?php esc_html_e( 'Cancel' ); ?></button>
138
-			 <button type="button" class="button button-primary save alignright"><?php echo esc_html( $this->post_type_object->labels->add_new ); ?></button>
137
+			 <button type="button" class="button cancel alignleft"><?php esc_html_e('Cancel'); ?></button>
138
+			 <button type="button" class="button button-primary save alignright"><?php echo esc_html($this->post_type_object->labels->add_new); ?></button>
139 139
 			 <span class="spinner"></span>
140 140
 			 <span class="error" style="display:none"></span>
141 141
 			 <br class="clear" />
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return void
155 155
 	 */
156 156
 	public function mass_interface_screen_option() {
157
-		add_action( 'admin_notices', array( $this, 'ajax_admin_notice' ) );
158
-		add_filter( 'default_hidden_columns', array( $this, 'hidden_columns' ), 10, 2 );
159
-		$this->wp_list_table( $this->hook );
157
+		add_action('admin_notices', array($this, 'ajax_admin_notice'));
158
+		add_filter('default_hidden_columns', array($this, 'hidden_columns'), 10, 2);
159
+		$this->wp_list_table($this->hook);
160 160
 	}
161 161
 	/**
162 162
 	 * Instance WPS_Mass_List_Table.
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 	 * @param  string $screen Current screen.
166 166
 	 * @return WPS_Mass_List_Table Table class.
167 167
 	 */
168
-	public function wp_list_table( $screen ) {
169
-		if ( is_null( $this->wp_list_table ) ) {
170
-			$this->post_type_object = get_post_type_object( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
171
-			include_once( WPS_PDCT_MASS_INCLUDE_PATH . 'class-wps-mass-list-table.php' );
168
+	public function wp_list_table($screen) {
169
+		if (is_null($this->wp_list_table)) {
170
+			$this->post_type_object = get_post_type_object(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
171
+			include_once(WPS_PDCT_MASS_INCLUDE_PATH . 'class-wps-mass-list-table.php');
172 172
 			$this->wp_list_table = new WPS_Mass_List_Table(
173 173
 				array(
174 174
 					'screen' => $screen,
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 					'heading_list'       => $this->post_type_object->labels->items_list,
183 183
 				)
184 184
 			);
185
-			$class = sanitize_title( get_class() );
185
+			$class = sanitize_title(get_class());
186 186
 			$this->wp_list_table->screen->add_option(
187 187
 				'per_page', array(
188 188
 					'default' => 20,
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
 	 * @param  WP_Screen $screen Current screen.
201 201
 	 * @return array Return of filter.
202 202
 	 */
203
-	public function hidden_columns( $hidden, $screen ) {
204
-		$wp_list_table = $this->wp_list_table( $this->hook );
205
-		if ( $screen === $wp_list_table->screen ) {
206
-			$hidden = array_diff( array_flip( $wp_list_table->get_columns() ), $this->default_show_columns );
203
+	public function hidden_columns($hidden, $screen) {
204
+		$wp_list_table = $this->wp_list_table($this->hook);
205
+		if ($screen === $wp_list_table->screen) {
206
+			$hidden = array_diff(array_flip($wp_list_table->get_columns()), $this->default_show_columns);
207 207
 			$hidden[] = 'thumbnail';
208 208
 		}
209 209
 		return $hidden;
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 	 * @param  string $option Actual option to save.
217 217
 	 * @param  mixed  $value  Actual value to save.
218 218
 	 */
219
-	public function set_screen_option( $string, $option, $value ) {
220
-		$class = sanitize_title( get_class() );
221
-		if ( "{$class}_per_page" === $option ) {
222
-			$value = (int) $value;
223
-			if ( $value < 1 || $value > 999 ) {
219
+	public function set_screen_option($string, $option, $value) {
220
+		$class = sanitize_title(get_class());
221
+		if ("{$class}_per_page" === $option) {
222
+			$value = (int)$value;
223
+			if ($value < 1 || $value > 999) {
224 224
 				$string = false;
225 225
 			}
226 226
 			return $value;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 * @return void Direct display.
235 235
 	 */
236 236
 	public function ajax_admin_notice() {
237
-		printf( '<div class="%1$s"><p></p></div>', esc_attr( 'hidden is-dismissible notice' ) );
237
+		printf('<div class="%1$s"><p></p></div>', esc_attr('hidden is-dismissible notice'));
238 238
 	}
239 239
 	/**
240 240
 	 * Enqueue scripts.
@@ -246,13 +246,13 @@  discard block
 block discarded – undo
246 246
 		wp_enqueue_script(
247 247
 			'jquery_chosen_js',
248 248
 			WPS_PDCT_MASS_CHOSEN_JS . 'chosen.jquery.min.js',
249
-			array( 'jquery' ),
249
+			array('jquery'),
250 250
 			true
251 251
 		);
252 252
 		wp_enqueue_script(
253 253
 			'mass_interface3-ajax',
254 254
 			WPS_PDCT_MASS_JS . 'wps-mass-interface3.js',
255
-			array( 'jquery', 'jquery-form' ),
255
+			array('jquery', 'jquery-form'),
256 256
 			true
257 257
 		);
258 258
 		wp_enqueue_media();
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
 	 * @return void
265 265
 	 */
266 266
 	public function styles() {
267
-		wp_register_style( 'jquery_chosen_css', WPS_PDCT_MASS_CHOSEN_CSS . 'chosen.min.css' );
268
-		wp_register_style( 'mass_interface3_css', WPS_PDCT_MASS_CSS . 'wps-mass-interface3.css' );
269
-		wp_enqueue_style( 'jquery_chosen_css' );
270
-		wp_enqueue_style( 'mass_interface3_css' );
271
-		wp_deregister_style( 'wpshop_main_css' );
267
+		wp_register_style('jquery_chosen_css', WPS_PDCT_MASS_CHOSEN_CSS . 'chosen.min.css');
268
+		wp_register_style('mass_interface3_css', WPS_PDCT_MASS_CSS . 'wps-mass-interface3.css');
269
+		wp_enqueue_style('jquery_chosen_css');
270
+		wp_enqueue_style('mass_interface3_css');
271
+		wp_deregister_style('wpshop_main_css');
272 272
 	}
273 273
 	/**
274 274
 	 * Change default url for set_url_scheme(). See pagination & get_views. Impossible to re-use set_url_sheme inner.
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 * @param  string        $url    Given url.
278 278
 	 * @param  string | null $scheme Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
279 279
 	 */
280
-	public function set_current_url( $url, $scheme ) {
280
+	public function set_current_url($url, $scheme) {
281 281
 		/*
282 282
 		Remove_filter( 'set_url_scheme', array( $this, 'set_current_url' ), 10 );
283 283
 		$url = set_url_sheme( esc_url( $_POST['current_url'] ) );
@@ -292,23 +292,23 @@  discard block
 block discarded – undo
292 292
 	 * @return void JSON with all elements to update.
293 293
 	 */
294 294
 	public function ajax_new() {
295
-		check_ajax_referer( 'add_post-' . sanitize_title( get_class() ) );
296
-		add_filter( 'default_hidden_columns', array( $this, 'hidden_columns' ), 10, 2 );
297
-		add_filter( 'set_url_scheme', array( $this, 'set_current_url' ), 10, 2 );
298
-		$wp_list_table = $this->wp_list_table( sanitize_title( $_POST['hook'] ) );
295
+		check_ajax_referer('add_post-' . sanitize_title(get_class()));
296
+		add_filter('default_hidden_columns', array($this, 'hidden_columns'), 10, 2);
297
+		add_filter('set_url_scheme', array($this, 'set_current_url'), 10, 2);
298
+		$wp_list_table = $this->wp_list_table(sanitize_title($_POST['hook']));
299 299
 		$wpshop_product_attribute = array();
300
-		foreach ( $wp_list_table->request_items_columns() as $key_var => $var ) {
301
-			$wpshop_product_attribute[ $var['data'] ][ $key_var ] = null;
300
+		foreach ($wp_list_table->request_items_columns() as $key_var => $var) {
301
+			$wpshop_product_attribute[$var['data']][$key_var] = null;
302 302
 		}
303 303
 		$new_product_id = wp_insert_post(
304 304
 			array(
305 305
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
306 306
 				'post_status' => 'publish',
307
-				'post_title' => sanitize_text_field( $_POST['title'] ),
307
+				'post_title' => sanitize_text_field($_POST['title']),
308 308
 			)
309 309
 		);
310
-		if ( ! empty( $new_product_id ) ) {
311
-			update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $wp_list_table->current_view );
310
+		if (!empty($new_product_id)) {
311
+			update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $wp_list_table->current_view);
312 312
 			$product_class = new wpshop_products();
313 313
 			$product_class->save_product_custom_informations(
314 314
 				$new_product_id, array(
@@ -320,30 +320,30 @@  discard block
 block discarded – undo
320 320
 				)
321 321
 			);
322 322
 		} else {
323
-			wp_die( 1 );
323
+			wp_die(1);
324 324
 		}
325
-		$data = $wp_list_table->request( $new_product_id );
326
-		$per_page = $wp_list_table->screen->get_option( 'per_page', 'option' );
325
+		$data = $wp_list_table->request($new_product_id);
326
+		$per_page = $wp_list_table->screen->get_option('per_page', 'option');
327 327
 		$wp_list_table->column_headers();
328 328
 		$wp_list_table->items = true;
329 329
 		ob_start();
330 330
 		$wp_list_table->views();
331 331
 		$subsubsub = ob_get_clean();
332 332
 		ob_start();
333
-		$wp_list_table->display_tablenav( 'top' );
333
+		$wp_list_table->display_tablenav('top');
334 334
 		$tablenav_top = ob_get_clean();
335 335
 		ob_start();
336
-		$wp_list_table->display_tablenav( 'bottom' );
336
+		$wp_list_table->display_tablenav('bottom');
337 337
 		$tablenav_bottom = ob_get_clean();
338 338
 		ob_start();
339
-		$wp_list_table->single_row( $data[0] );
340
-		wp_send_json_success( array(
339
+		$wp_list_table->single_row($data[0]);
340
+		wp_send_json_success(array(
341 341
 			'row' => ob_get_clean(),
342 342
 			'per_page' => $per_page,
343 343
 			'tablenav_top' => $tablenav_top,
344 344
 			'tablenav_bottom' => $tablenav_bottom,
345 345
 			'subsubsub' => $subsubsub,
346
-		) );
346
+		));
347 347
 	}
348 348
 	/**
349 349
 	 * Ajax callback for save selected elements.
@@ -352,22 +352,22 @@  discard block
 block discarded – undo
352 352
 	 * @return void JSON with number of saved elements (not used).
353 353
 	 */
354 354
 	public function ajax_save() {
355
-		check_ajax_referer( 'bulk-save-mass-edit-interface-3' );
355
+		check_ajax_referer('bulk-save-mass-edit-interface-3');
356 356
 		$i = 0;
357 357
 		$product_class = new wpshop_products();
358
-		if ( ! empty( $_REQUEST['cb'] ) ) {
359
-			foreach ( $_REQUEST['cb'] as $id ) {
360
-				$id = intval( $id );
361
-				if ( isset( $_REQUEST[ 'row_' . $id ]['thumbnail'] ) ) {
362
-					intval( $_REQUEST[ 'row_' . $id ]['thumbnail'] );
363
-					update_post_meta( $id, '_thumbnail_id', intval( $_REQUEST[ 'row_' . $id ]['thumbnail'] ) );
364
-					unset( $_REQUEST[ 'row_' . $id ]['thumbnail'] );
358
+		if (!empty($_REQUEST['cb'])) {
359
+			foreach ($_REQUEST['cb'] as $id) {
360
+				$id = intval($id);
361
+				if (isset($_REQUEST['row_' . $id]['thumbnail'])) {
362
+					intval($_REQUEST['row_' . $id]['thumbnail']);
363
+					update_post_meta($id, '_thumbnail_id', intval($_REQUEST['row_' . $id]['thumbnail']));
364
+					unset($_REQUEST['row_' . $id]['thumbnail']);
365 365
 				}
366
-				if ( ! empty( $_REQUEST[ 'row_' . $id ] ) ) {
366
+				if (!empty($_REQUEST['row_' . $id])) {
367 367
 					$product_class->save_product_custom_informations(
368 368
 						$id,
369 369
 						array_merge(
370
-							$_REQUEST[ 'row_' . $id ],
370
+							$_REQUEST['row_' . $id],
371 371
 							array(
372 372
 								'post_ID' => $id,
373 373
 								'product_id' => $id,
Please login to merge, or discard this patch.
modules/wps-mass-interface3/include/class-wps-mass-list-table.php 1 patch
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@  discard block
 block discarded – undo
5 5
  * @package wps-mass-interface3
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11
-if ( ! class_exists( 'WP_List_Table' ) ) {
11
+if (!class_exists('WP_List_Table')) {
12 12
 	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
13 13
 }
14
-if ( ! class_exists( 'WP_List_Table' ) ) {
15
-	exit( 'class-wp-list-table.php not found.' );
14
+if (!class_exists('WP_List_Table')) {
15
+	exit('class-wp-list-table.php not found.');
16 16
 }
17 17
 /**
18 18
  *  Custom WP_List_Table to edit attributes from WPShop EAV.
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
 	 * @method __construct
79 79
 	 * @param  array $args New key : exclude_attribute_codes.
80 80
 	 */
81
-	public function __construct( $args ) {
82
-		if ( isset( $args['exclude_attribute_codes'] ) ) {
81
+	public function __construct($args) {
82
+		if (isset($args['exclude_attribute_codes'])) {
83 83
 			$this->exclude_attribute_codes = $args['exclude_attribute_codes'];
84 84
 		}
85 85
 		parent::__construct(
86 86
 			array(
87 87
 				'plural' => 'posts',
88 88
 				'ajax' => true,
89
-				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
89
+				'screen' => isset($args['screen']) ? $args['screen'] : null,
90 90
 			)
91 91
 		);
92
-		$this->current_view = (int) substr( $this->screen->id, strpos( $this->screen->id, '_att_set_' ) + 9 );
93
-		$this->entity_id = (int) wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
94
-		$this->_post_types = array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION );
92
+		$this->current_view = (int)substr($this->screen->id, strpos($this->screen->id, '_att_set_') + 9);
93
+		$this->entity_id = (int)wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
94
+		$this->_post_types = array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION);
95 95
 	}
96 96
 	/**
97 97
 	 * List columns.
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
 	public function get_columns() {
103 103
 		$columns = array(
104 104
 			'cb'        => '<input type="checkbox" />',
105
-			'title'     => __( 'Title' ),
106
-			'thumbnail' => __( 'Thumbnail' ),
105
+			'title'     => __('Title'),
106
+			'thumbnail' => __('Thumbnail'),
107 107
 		);
108
-		foreach ( $this->request_items_columns() as $column => $data_column ) {
109
-			if ( ! empty( $column ) && ! empty( $data_column ) ) {
110
-				$columns[ $column ] = $data_column['name'];
108
+		foreach ($this->request_items_columns() as $column => $data_column) {
109
+			if (!empty($column) && !empty($data_column)) {
110
+				$columns[$column] = $data_column['name'];
111 111
 			}
112 112
 		}
113
-		$columns['date'] = __( 'Date' );
113
+		$columns['date'] = __('Date');
114 114
 		return $columns;
115 115
 	}
116 116
 	/**
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	protected function get_sortable_columns() {
123 123
 		$sortable_columns = array(
124
-			'title'     => array( 'title', false ),
125
-			'thumbnail' => array( 'thumbnail', false ),
126
-			'date' => array( 'p.post_date', false ),
124
+			'title'     => array('title', false),
125
+			'thumbnail' => array('thumbnail', false),
126
+			'date' => array('p.post_date', false),
127 127
 		);
128
-		foreach ( $this->request_items_columns() as $column => $data_column ) {
129
-			$sortable_columns[ $column ] = array( $data_column['code'], false );
128
+		foreach ($this->request_items_columns() as $column => $data_column) {
129
+			$sortable_columns[$column] = array($data_column['code'], false);
130 130
 		}
131 131
 		return $sortable_columns;
132 132
 	}
@@ -138,22 +138,22 @@  discard block
 block discarded – undo
138 138
 	 * @param  string $column_name Current column.
139 139
 	 * @return string
140 140
 	 */
141
-	public function column_default( $item, $column_name ) {
142
-		if ( isset( $this->columns_items[ $column_name ] ) && is_callable( array( $this, "column_data_{$this->columns_items[ $column_name ]['type']}" ) ) ) {
143
-			$callable_ext = str_replace( '-', '_', $this->columns_items[ $column_name ]['type'] );
144
-			$callable = array( $this, "column_data_{$callable_ext}" );
145
-			if ( ! is_callable( $callable ) ) {
146
-				$callable = array( $this, 'column_data_text' );
141
+	public function column_default($item, $column_name) {
142
+		if (isset($this->columns_items[$column_name]) && is_callable(array($this, "column_data_{$this->columns_items[$column_name]['type']}"))) {
143
+			$callable_ext = str_replace('-', '_', $this->columns_items[$column_name]['type']);
144
+			$callable = array($this, "column_data_{$callable_ext}");
145
+			if (!is_callable($callable)) {
146
+				$callable = array($this, 'column_data_text');
147 147
 			}
148 148
 			return call_user_func(
149 149
 				$callable,
150
-				(int) $this->columns_items[ $column_name ]['id'],
151
-				$this->columns_items[ $column_name ]['code'],
152
-				$this->columns_items[ $column_name ]['data'],
150
+				(int)$this->columns_items[$column_name]['id'],
151
+				$this->columns_items[$column_name]['code'],
152
+				$this->columns_items[$column_name]['data'],
153 153
 				$item
154 154
 			);
155 155
 		}
156
-		return print_r( $item[ $column_name ], true );
156
+		return print_r($item[$column_name], true);
157 157
 	}
158 158
 	/**
159 159
 	 * Column content for checkbox.
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param  array $item Result of sql query.
163 163
 	 * @return string
164 164
 	 */
165
-	public function column_cb( $item ) {
165
+	public function column_cb($item) {
166 166
 		return sprintf(
167 167
 			'<input type="checkbox" name="cb[]" value="%d" />',
168 168
 			$item['ID']
@@ -175,52 +175,52 @@  discard block
 block discarded – undo
175 175
 	 * @param  array $item Result of sql query.
176 176
 	 * @return string
177 177
 	 */
178
-	public function column_thumbnail( $item ) {
178
+	public function column_thumbnail($item) {
179 179
 		$thumbnail_id = '';
180
-		$link_content = get_the_post_thumbnail( $item['ID'], array( 25, 25 ) );
181
-		if ( ! empty( $link_content ) ) {
180
+		$link_content = get_the_post_thumbnail($item['ID'], array(25, 25));
181
+		if (!empty($link_content)) {
182 182
 			$link_content = "<span class=\"img\">{$link_content}</span>";
183
-			$thumbnail_id = get_post_thumbnail_id( $item['ID'] );
183
+			$thumbnail_id = get_post_thumbnail_id($item['ID']);
184 184
 		}
185
-		$popup_title = __( 'Choose Image' );
185
+		$popup_title = __('Choose Image');
186 186
 		return sprintf(
187 187
 			'<input type="hidden" name="row_%1$s[thumbnail]" value="%2$s"><a href="#thumbnail" data-media-title="%3$s">%4$s<span class="text">%3$s</span></a>',
188 188
 			$item['ID'],
189 189
 			$thumbnail_id,
190
-			__( 'Choose Image' ),
190
+			__('Choose Image'),
191 191
 			$link_content
192 192
 		);
193 193
 	}
194
-	public function column_date( $item ) {
194
+	public function column_date($item) {
195 195
 		global $mode;
196 196
 
197
-		if ( '0000-00-00 00:00:00' === $item['pdate'] ) {
198
-			$t_time = $h_time = __( 'Unpublished' );
197
+		if ('0000-00-00 00:00:00' === $item['pdate']) {
198
+			$t_time = $h_time = __('Unpublished');
199 199
 			$time_diff = 0;
200 200
 		} else {
201
-			$t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
201
+			$t_time = get_the_time(__('Y/m/d g:i:s a'));
202 202
 			$m_time = $item['pdate'];
203
-			$time = get_post_time( 'G', true, $item['ID'] );
203
+			$time = get_post_time('G', true, $item['ID']);
204 204
 
205 205
 			$time_diff = time() - $time;
206 206
 
207
-			if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
208
-				$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
207
+			if ($time_diff > 0 && $time_diff < DAY_IN_SECONDS) {
208
+				$h_time = sprintf(__('%s ago'), human_time_diff($time));
209 209
 			} else {
210
-				$h_time = mysql2date( __( 'Y/m/d' ), $m_time );
210
+				$h_time = mysql2date(__('Y/m/d'), $m_time);
211 211
 			}
212 212
 		}
213 213
 
214
-		if ( 'publish' === $item['status'] ) {
215
-			_e( 'Published' );
216
-		} elseif ( 'future' === $item['status'] ) {
217
-			if ( $time_diff > 0 ) {
218
-				echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
214
+		if ('publish' === $item['status']) {
215
+			_e('Published');
216
+		} elseif ('future' === $item['status']) {
217
+			if ($time_diff > 0) {
218
+				echo '<strong class="error-message">' . __('Missed schedule') . '</strong>';
219 219
 			} else {
220
-				_e( 'Scheduled' );
220
+				_e('Scheduled');
221 221
 			}
222 222
 		} else {
223
-			_e( 'Last Modified' );
223
+			_e('Last Modified');
224 224
 		}
225 225
 		echo '<br />';
226 226
 		echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
@@ -232,39 +232,39 @@  discard block
 block discarded – undo
232 232
 	 * @param  array $item Result of sql query.
233 233
 	 * @return string
234 234
 	 */
235
-	public function column_title( $item ) {
236
-		if ( 'private' === $item['status'] ) {
237
-			$post_states['private'] = __( 'Private' );
235
+	public function column_title($item) {
236
+		if ('private' === $item['status']) {
237
+			$post_states['private'] = __('Private');
238 238
 		}
239
-		if ( 'draft' === $item['status'] ) {
240
-			$post_states['draft'] = __( 'Draft' );
239
+		if ('draft' === $item['status']) {
240
+			$post_states['draft'] = __('Draft');
241 241
 		}
242
-		if ( 'pending' === $item['status'] ) {
243
-			$post_states['pending'] = _x( 'Pending', 'post status' );
242
+		if ('pending' === $item['status']) {
243
+			$post_states['pending'] = _x('Pending', 'post status');
244 244
 		}
245
-		if ( 'future' === $item['status'] ) {
246
-			$post_states['scheduled'] = __( 'Scheduled' );
245
+		if ('future' === $item['status']) {
246
+			$post_states['scheduled'] = __('Scheduled');
247 247
 		}
248
-		if ( current_user_can( 'edit_post', $item['ID'] ) && 'trash' !== $item['status'] ) {
248
+		if (current_user_can('edit_post', $item['ID']) && 'trash' !== $item['status']) {
249 249
 			$result = sprintf(
250 250
 				'<a class="row-title" href="%s" aria-label="%s">%s</a>',
251
-				get_edit_post_link( $item['ID'] ),
251
+				get_edit_post_link($item['ID']),
252 252
 				// translators: WordPress translate.
253
-				esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $item['title'] ) ),
253
+				esc_attr(sprintf(__('&#8220;%s&#8221; (Edit)'), $item['title'])),
254 254
 				$item['title']
255 255
 			);
256 256
 		} else {
257 257
 			$result = $item['title'];
258 258
 		}
259
-		if ( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item['type'] ) {
260
-			$attr_def = get_post_meta( $item['ID'], '_wpshop_variations_attribute_def', true );
259
+		if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item['type']) {
260
+			$attr_def = get_post_meta($item['ID'], '_wpshop_variations_attribute_def', true);
261 261
 			$columns_items = $this->request_items_columns();
262 262
 			$first_variation = true;
263
-			$parent = $this->items[ $item['parent'] ];
264
-			foreach ( $attr_def as $key => $value ) {
265
-				foreach ( $this->get_select_items_option( $columns_items[ $key ]['id'] ) as $all_value ) {
266
-					if ( $all_value['id'] === $value ) {
267
-						if ( $first_variation ) {
263
+			$parent = $this->items[$item['parent']];
264
+			foreach ($attr_def as $key => $value) {
265
+				foreach ($this->get_select_items_option($columns_items[$key]['id']) as $all_value) {
266
+					if ($all_value['id'] === $value) {
267
+						if ($first_variation) {
268 268
 							$result = $parent['title'] . ' : ';
269 269
 							$first_variation = false;
270 270
 						} else {
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 				}
277 277
 			}
278 278
 		}
279
-		if ( ! empty( $post_states ) ) {
280
-			$state_count = count( $post_states );
279
+		if (!empty($post_states)) {
280
+			$state_count = count($post_states);
281 281
 			$i = 0;
282 282
 			$result .= ' &mdash; ';
283
-			foreach ( $post_states as $state ) {
283
+			foreach ($post_states as $state) {
284 284
 				++$i;
285
-				( $i === $state_count ) ? $sep = '' : $sep = ', ';
285
+				($i === $state_count) ? $sep = '' : $sep = ', ';
286 286
 				$result .= "<span class='post-state'>$state$sep</span>";
287 287
 			}
288 288
 		}
289 289
 		return sprintf(
290 290
 			'<strong>%s</strong>',
291
-			isset( $item['lvl'] ) ? $item['lvl'] . $result : $result
291
+			isset($item['lvl']) ? $item['lvl'] . $result : $result
292 292
 		);
293 293
 	}
294 294
 	/**
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	 * @param  array  $item           Result of sql query.
302 302
 	 * @return string
303 303
 	 */
304
-	public function column_data_default( $attribute_id, $attribute_code, $attribute_data, $item ) {
304
+	public function column_data_default($attribute_id, $attribute_code, $attribute_data, $item) {
305 305
 		return 'default';
306 306
 	}
307 307
 	/**
@@ -314,13 +314,13 @@  discard block
 block discarded – undo
314 314
 	 * @param  array  $item           Result of sql query.
315 315
 	 * @return string
316 316
 	 */
317
-	public function column_data_text( $attribute_id, $attribute_code, $attribute_data, $item ) {
317
+	public function column_data_text($attribute_id, $attribute_code, $attribute_data, $item) {
318 318
 		$unit = '';
319
-		if ( is_array( $item[ $attribute_code ] ) ) {
320
-			$unit = ' ' . $item[ $attribute_code ]['unit'];
321
-			$value = $item[ $attribute_code ]['value'];
319
+		if (is_array($item[$attribute_code])) {
320
+			$unit = ' ' . $item[$attribute_code]['unit'];
321
+			$value = $item[$attribute_code]['value'];
322 322
 		} else {
323
-			$value = $item[ $attribute_code ];
323
+			$value = $item[$attribute_code];
324 324
 		}
325 325
 		return sprintf(
326 326
 			'<input type="text" name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]" value="%4$s">',
@@ -341,34 +341,34 @@  discard block
 block discarded – undo
341 341
 	 * @param  array  $item           Result of sql query.
342 342
 	 * @return string
343 343
 	 */
344
-	public function column_data_select( $attribute_id, $attribute_code, $attribute_data, $item ) {
344
+	public function column_data_select($attribute_id, $attribute_code, $attribute_data, $item) {
345 345
 		$unit = '';
346
-		if ( is_array( $item[ $attribute_code ] ) && isset( $item[ $attribute_code ]['unit'] ) ) {
347
-			$unit = ' ' . $item[ $attribute_code ]['unit'];
348
-			$value = $item[ $attribute_code ]['value'];
346
+		if (is_array($item[$attribute_code]) && isset($item[$attribute_code]['unit'])) {
347
+			$unit = ' ' . $item[$attribute_code]['unit'];
348
+			$value = $item[$attribute_code]['value'];
349 349
 		} else {
350
-			$value = $item[ $attribute_code ];
350
+			$value = $item[$attribute_code];
351 351
 		}
352 352
 		$has_selected = false;
353 353
 		$select_items = array();
354
-		foreach ( $this->get_select_items_option( $attribute_id ) as $option_item ) {
355
-			if ( is_array( $value ) ) {
356
-				foreach ( $value as $val ) {
357
-					$selected = selected( $val, $option_item['id'], false );
358
-					if ( ! empty( $selected ) ) {
354
+		foreach ($this->get_select_items_option($attribute_id) as $option_item) {
355
+			if (is_array($value)) {
356
+				foreach ($value as $val) {
357
+					$selected = selected($val, $option_item['id'], false);
358
+					if (!empty($selected)) {
359 359
 						break;
360 360
 					}
361 361
 				}
362 362
 			} else {
363
-				$selected = selected( $value, $option_item['id'], false );
363
+				$selected = selected($value, $option_item['id'], false);
364 364
 			}
365
-			$has_selected = empty( $selected ) ? $has_selected : true;
365
+			$has_selected = empty($selected) ? $has_selected : true;
366 366
 			$select_items[] = "<option value=\"{$option_item['id']}\"{$selected}>{$option_item['label']}</option>";
367 367
 		}
368
-		if ( ! $has_selected ) {
369
-			array_unshift( $select_items, '<option selected disabled>' . __( 'None' ) . '</option>' );
368
+		if (!$has_selected) {
369
+			array_unshift($select_items, '<option selected disabled>' . __('None') . '</option>');
370 370
 		}
371
-		$select_items = implode( '', $select_items );
371
+		$select_items = implode('', $select_items);
372 372
 		return sprintf(
373 373
 			'<select name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]">%4$s</select>',
374 374
 			$attribute_code,
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
 	 * @param  array  $item           Result of sql query.
389 389
 	 * @return string
390 390
 	 */
391
-	public function column_data_textarea( $attribute_id, $attribute_code, $attribute_data, $item ) {
391
+	public function column_data_textarea($attribute_id, $attribute_code, $attribute_data, $item) {
392 392
 		$unit = '';
393
-		if ( is_array( $item[ $attribute_code ] ) ) {
394
-			$unit = ' ' . $item[ $attribute_code ]['unit'];
395
-			$value = $item[ $attribute_code ]['value'];
393
+		if (is_array($item[$attribute_code])) {
394
+			$unit = ' ' . $item[$attribute_code]['unit'];
395
+			$value = $item[$attribute_code]['value'];
396 396
 		} else {
397
-			$value = $item[ $attribute_code ];
397
+			$value = $item[$attribute_code];
398 398
 		}
399 399
 		return sprintf(
400 400
 			'<textarea name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]">%4$s</textarea>',
@@ -415,29 +415,29 @@  discard block
 block discarded – undo
415 415
 	 * @param  array  $item           Result of sql query.
416 416
 	 * @return string
417 417
 	 */
418
-	public function column_data_multiple_select( $attribute_id, $attribute_code, $attribute_data, $item ) {
418
+	public function column_data_multiple_select($attribute_id, $attribute_code, $attribute_data, $item) {
419 419
 		$unit = '';
420
-		if ( is_array( $item[ $attribute_code ] ) && isset( $item[ $attribute_code ]['unit'] ) ) {
421
-			$unit = ' ' . $item[ $attribute_code ]['unit'];
422
-			$value = $item[ $attribute_code ]['value'];
420
+		if (is_array($item[$attribute_code]) && isset($item[$attribute_code]['unit'])) {
421
+			$unit = ' ' . $item[$attribute_code]['unit'];
422
+			$value = $item[$attribute_code]['value'];
423 423
 		} else {
424
-			$value = $item[ $attribute_code ];
424
+			$value = $item[$attribute_code];
425 425
 		}
426 426
 		$select_items = array();
427
-		foreach ( $this->get_select_items_option( $attribute_id ) as $option_item ) {
428
-			if ( is_array( $value ) ) {
429
-				foreach ( $value as $val ) {
430
-					$selected = selected( $val, $option_item['id'], false );
431
-					if ( ! empty( $selected ) ) {
427
+		foreach ($this->get_select_items_option($attribute_id) as $option_item) {
428
+			if (is_array($value)) {
429
+				foreach ($value as $val) {
430
+					$selected = selected($val, $option_item['id'], false);
431
+					if (!empty($selected)) {
432 432
 						break;
433 433
 					}
434 434
 				}
435 435
 			} else {
436
-				$selected = selected( $value, $option_item['id'], false );
436
+				$selected = selected($value, $option_item['id'], false);
437 437
 			}
438 438
 			$select_items[] = "<option value=\"{$option_item['id']}\"{$selected}>{$option_item['label']}</option>";
439 439
 		}
440
-		$select_items = implode( '', $select_items );
440
+		$select_items = implode('', $select_items);
441 441
 		return sprintf(
442 442
 			'<select class="chosen-select" multiple data-placeholder="%6$s" name="row_%2$s[wpshop_product_attribute][%3$s][%1$s][]">%4$s</select>',
443 443
 			$attribute_code,
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 	 * @param  Mixed $id_post Null = all / Int = single.
456 456
 	 * @return array Return all values with ARRAY_A.
457 457
 	 */
458
-	public function request( $id_post = null ) {
458
+	public function request($id_post = null) {
459 459
 		global $wpdb;
460
-		$per_page = $this->get_items_per_page( $this->screen->get_option( 'per_page', 'option' ) );
460
+		$per_page = $this->get_items_per_page($this->screen->get_option('per_page', 'option'));
461 461
 		$include_states = array(
462 462
 			'publish',
463 463
 			'future',
@@ -467,17 +467,17 @@  discard block
 block discarded – undo
467 467
 			'trash',
468 468
 			'scheduled',
469 469
 		);
470
-		$include_states = implode( "','", $include_states );
471
-		$post_types = implode( "','", $this->_post_types );
472
-		$orderby = isset( $_REQUEST['orderby'] ) ? esc_sql( $_REQUEST['orderby'] ) : 'p.post_date'; // WPCS: CSRF ok.
473
-		$order = isset( $_REQUEST['order'] ) ? esc_sql( strtoupper( $_REQUEST['order'] ) ) : 'DESC'; // WPCS: CSRF ok.
474
-		$cast = isset( $_REQUEST['cast'] ) ? esc_sql( $_REQUEST['cast'] ) : ''; // WPCS: CSRF ok.
475
-		$cast = strtoupper( $cast );
476
-		$s = isset( $_REQUEST['s'] ) ? esc_sql( $_REQUEST['s'] ) : ''; // WPCS: CSRF ok.
477
-		$exclude_attribute_codes = implode( "','", $this->exclude_attribute_codes );
478
-		$items_count = $wpdb->prepare( "SELECT FOUND_ROWS() FROM {$wpdb->posts} WHERE 1 = %d", 1 );
470
+		$include_states = implode("','", $include_states);
471
+		$post_types = implode("','", $this->_post_types);
472
+		$orderby = isset($_REQUEST['orderby']) ? esc_sql($_REQUEST['orderby']) : 'p.post_date'; // WPCS: CSRF ok.
473
+		$order = isset($_REQUEST['order']) ? esc_sql(strtoupper($_REQUEST['order'])) : 'DESC'; // WPCS: CSRF ok.
474
+		$cast = isset($_REQUEST['cast']) ? esc_sql($_REQUEST['cast']) : ''; // WPCS: CSRF ok.
475
+		$cast = strtoupper($cast);
476
+		$s = isset($_REQUEST['s']) ? esc_sql($_REQUEST['s']) : ''; // WPCS: CSRF ok.
477
+		$exclude_attribute_codes = implode("','", $this->exclude_attribute_codes);
478
+		$items_count = $wpdb->prepare("SELECT FOUND_ROWS() FROM {$wpdb->posts} WHERE 1 = %d", 1);
479 479
 		$true = true;
480
-		if ( $true ) { // FOUND_ROWS incompatibilities ?
480
+		if ($true) { // FOUND_ROWS incompatibilities ?
481 481
 			$items_count = $wpdb->prepare(
482 482
 				"SELECT COUNT(*)
483 483
 				FROM {$wpdb->posts} p
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		$wpsdb_values_text = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;
500 500
 		$wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;
501 501
 		$extra_select = '';
502
-		if ( ! in_array( $orderby, apply_filters( 'wps_mass_list_custom_orderby', array( 'title', 'ID', 'thumbnail', 'p.post_date' ) ), true ) ) {
502
+		if (!in_array($orderby, apply_filters('wps_mass_list_custom_orderby', array('title', 'ID', 'thumbnail', 'p.post_date')), true)) {
503 503
 			$extra_select = "SELECT GROUP_CONCAT( IFNULL( val_dec1.value,
504 504
 				IFNULL( val_dat1.value,
505 505
 					IFNULL( val_tex1.value,
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
 			LEFT JOIN {$wpsdb_values_options} val_opt1 ON val_opt1.attribute_id = attr1.id AND val_opt1.id = val_int1.value
522 522
 			WHERE p1.ID = p.ID";
523 523
 			$extra_select = "( {$extra_select} )";
524
-			if ( ! empty( $cast ) ) {
524
+			if (!empty($cast)) {
525 525
 				$extra_select = "CAST( {$extra_select} AS {$cast} )";
526 526
 			}
527 527
 			$extra_select = ",
528 528
 			{$extra_select} AS {$orderby}";
529 529
 		}
530
-		if ( 'thumbnail' === $orderby ) {
531
-			$ids = $wpdb->get_col( $wpdb->prepare(
530
+		if ('thumbnail' === $orderby) {
531
+			$ids = $wpdb->get_col($wpdb->prepare(
532 532
 				"SELECT CAST( pm.post_id AS SIGNED INTEGER ) as col
533 533
 				FROM {$wpdb->postmeta} pm
534 534
 				JOIN {$wpdb->posts} p ON pm.post_id = p.ID AND p.post_type IN ( '{$post_types}' )
@@ -537,21 +537,21 @@  discard block
 block discarded – undo
537 537
 				ORDER BY pm.meta_value {$order}",
538 538
 				'_thumbnail_id',
539 539
 				0
540
-			) );
541
-			$ids = implode( ', ', $ids );
540
+			));
541
+			$ids = implode(', ', $ids);
542 542
 			$orderby = "FIELD( p.ID, {$ids} )";
543 543
 		}
544
-		$orderby = apply_filters( 'wps_mass_list_custom_orderby_query', $orderby );
544
+		$orderby = apply_filters('wps_mass_list_custom_orderby_query', $orderby);
545 545
 		$extra = "GROUP BY p.ID
546 546
 		ORDER BY {$orderby} {$order}
547 547
 		LIMIT %d, %d";
548
-		if ( ! is_null( $id_post ) ) {
549
-			$id_post = intval( $id_post );
548
+		if (!is_null($id_post)) {
549
+			$id_post = intval($id_post);
550 550
 			$extra = "AND p.ID = {$id_post}";
551 551
 			$s = '';
552 552
 		}
553 553
 		$wpdb->query(
554
-			$wpdb->prepare( 'SET SESSION group_concat_max_len = %d', 1000000 )
554
+			$wpdb->prepare('SET SESSION group_concat_max_len = %d', 1000000)
555 555
 		);
556 556
 		$datas = $wpdb->get_results(
557 557
 			$wpdb->prepare(
@@ -606,23 +606,23 @@  discard block
 block discarded – undo
606 606
 				$this->request_current_view(),
607 607
 				$this->entity_id,
608 608
 				'%' . $s . '%',
609
-				( $this->get_pagenum() -1 ) * $per_page,
609
+				($this->get_pagenum() - 1) * $per_page,
610 610
 				$per_page
611 611
 			),
612 612
 			ARRAY_A
613 613
 		);
614
-		if ( ! is_array( $datas ) ) {
614
+		if (!is_array($datas)) {
615 615
 			$datas = array();
616 616
 		}
617
-		if ( ! isset( $this->_pagination_args['total_items'] ) && ! isset( $this->_pagination_args['per_page'] ) ) {
617
+		if (!isset($this->_pagination_args['total_items']) && !isset($this->_pagination_args['per_page'])) {
618 618
 			$this->set_pagination_args(
619 619
 				array(
620
-					'total_items' => (int) $wpdb->get_var( $items_count ),
621
-					'per_page' => $this->get_items_per_page( $this->screen->get_option( 'per_page', 'option' ) ),
620
+					'total_items' => (int)$wpdb->get_var($items_count),
621
+					'per_page' => $this->get_items_per_page($this->screen->get_option('per_page', 'option')),
622 622
 				)
623 623
 			);
624 624
 		}
625
-		return array_map( array( $this, 'data_reorganize' ), $datas );
625
+		return array_map(array($this, 'data_reorganize'), $datas);
626 626
 	}
627 627
 	/**
628 628
 	 * Main function to call before display WP_List_Table. See parent class.
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
 	 * @return void Same results as request() but id as key.
632 632
 	 */
633 633
 	public function prepare_items() {
634
-		foreach ( $this->request() as $item ) {
635
-			$this->items[ $item['ID'] ] = $item;
634
+		foreach ($this->request() as $item) {
635
+			$this->items[$item['ID']] = $item;
636 636
 		}
637 637
 	}
638 638
 	/**
@@ -642,20 +642,20 @@  discard block
 block discarded – undo
642 642
 	 * @param  string $column_key Current column.
643 643
 	 * @return string
644 644
 	 */
645
-	public function cast_column( $column_key ) {
645
+	public function cast_column($column_key) {
646 646
 		$columns_items = $this->request_items_columns();
647
-		if ( isset( $columns_items[ $column_key ] ) ) {
648
-			$cast = $columns_items[ $column_key ]['data'];
649
-			if ( in_array( $cast, array( 'varchar', 'text' ), true ) ) {
647
+		if (isset($columns_items[$column_key])) {
648
+			$cast = $columns_items[$column_key]['data'];
649
+			if (in_array($cast, array('varchar', 'text'), true)) {
650 650
 				$cast = 'char';
651 651
 			}
652
-			if ( 'tx_tva' === $column_key ) {
652
+			if ('tx_tva' === $column_key) {
653 653
 				return 'decimal';
654 654
 			}
655
-			if ( 'integer' === $cast && 'select' === $columns_items[ $column_key ]['type'] ) {
655
+			if ('integer' === $cast && 'select' === $columns_items[$column_key]['type']) {
656 656
 				return null;
657 657
 			}
658
-			if ( 'integer' === $cast && 'multiple-select' === $columns_items[ $column_key ]['type'] ) {
658
+			if ('integer' === $cast && 'multiple-select' === $columns_items[$column_key]['type']) {
659 659
 				return null;
660 660
 			}
661 661
 			return $cast;
@@ -669,12 +669,12 @@  discard block
 block discarded – undo
669 669
 	 * @param  array $item Result of sql query.
670 670
 	 * @return array Item reorganized.
671 671
 	 */
672
-	public function data_reorganize( $item ) {
673
-		$values = explode( ';', $item['data'] );
674
-		foreach ( $values as $value ) {
675
-			$value = explode( ':', $value );
676
-			if ( ! isset( $this->columns_items[ $value[1] ] ) ) {
677
-				$this->columns_items[ $value[1] ] = array(
672
+	public function data_reorganize($item) {
673
+		$values = explode(';', $item['data']);
674
+		foreach ($values as $value) {
675
+			$value = explode(':', $value);
676
+			if (!isset($this->columns_items[$value[1]])) {
677
+				$this->columns_items[$value[1]] = array(
678 678
 					'id' => $value[0],
679 679
 					'code' => $value[1],
680 680
 					'name' => $value[2],
@@ -682,32 +682,32 @@  discard block
 block discarded – undo
682 682
 					'data' => $value[7],
683 683
 				);
684 684
 			}
685
-			if ( 'yes' === $value[4] ) {
686
-				if ( isset( $item[ $value[1] ]['value'] ) ) {
687
-					if ( is_array( $item[ $value[1] ]['value'] ) ) {
688
-						$item[ $value[1] ]['value'][] = $value[3];
685
+			if ('yes' === $value[4]) {
686
+				if (isset($item[$value[1]]['value'])) {
687
+					if (is_array($item[$value[1]]['value'])) {
688
+						$item[$value[1]]['value'][] = $value[3];
689 689
 					} else {
690
-						$item[ $value[1] ]['value'] = array( $item[ $value[1] ]['value'], $value[3] );
690
+						$item[$value[1]]['value'] = array($item[$value[1]]['value'], $value[3]);
691 691
 					}
692 692
 				} else {
693
-					$item[ $value[1] ] = array(
693
+					$item[$value[1]] = array(
694 694
 						'value' => $value[3],
695 695
 						'unit' => $value[5],
696 696
 					);
697 697
 				}
698 698
 			} else {
699
-				if ( isset( $item[ $value[1] ] ) ) {
700
-					if ( is_array( $item[ $value[1] ] ) ) {
701
-						$item[ $value[1] ][] = $value[3];
702
-					} elseif ( $item[ $value[1] ] !== $value[3] ) {
703
-						$item[ $value[1] ] = array( $item[ $value[1] ], $value[3] );
699
+				if (isset($item[$value[1]])) {
700
+					if (is_array($item[$value[1]])) {
701
+						$item[$value[1]][] = $value[3];
702
+					} elseif ($item[$value[1]] !== $value[3]) {
703
+						$item[$value[1]] = array($item[$value[1]], $value[3]);
704 704
 					}
705 705
 				} else {
706
-					$item[ $value[1] ] = $value[3];
706
+					$item[$value[1]] = $value[3];
707 707
 				}
708 708
 			}
709 709
 		}// End foreach().
710
-		unset( $item['data'] );
710
+		unset($item['data']);
711 711
 		return $item;
712 712
 	}
713 713
 	/**
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
 	 * @param  int $attribute_id Attribute ID.
718 718
 	 * @return array
719 719
 	 */
720
-	public function get_select_items_option( $attribute_id ) {
721
-		if ( ! isset( self::$wpsdb_values_options[ $attribute_id ] ) ) {
720
+	public function get_select_items_option($attribute_id) {
721
+		if (!isset(self::$wpsdb_values_options[$attribute_id])) {
722 722
 			global $wpdb;
723 723
 			$wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;
724
-			self::$wpsdb_values_options[ $attribute_id ] = $wpdb->get_results(
724
+			self::$wpsdb_values_options[$attribute_id] = $wpdb->get_results(
725 725
 				$wpdb->prepare(
726 726
 					"SELECT *
727 727
 					FROM {$wpsdb_values_options}
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 				ARRAY_A
733 733
 			);
734 734
 		}
735
-		return self::$wpsdb_values_options[ $attribute_id ];
735
+		return self::$wpsdb_values_options[$attribute_id];
736 736
 	}
737 737
 	/**
738 738
 	 * Get all views available.
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 	 */
743 743
 	public function request_views() {
744 744
 		global $wpdb;
745
-		if ( is_null( $this->_views ) ) {
745
+		if (is_null($this->_views)) {
746 746
 			$wpsdb_sets = WPSHOP_DBT_ATTRIBUTE_SET;
747 747
 			$include_states = array(
748 748
 				'publish',
@@ -753,8 +753,8 @@  discard block
 block discarded – undo
753 753
 				'trash',
754 754
 				'scheduled',
755 755
 			);
756
-			$include_states = implode( "','", $include_states );
757
-			$post_types = implode( "','", $this->_post_types );
756
+			$include_states = implode("','", $include_states);
757
+			$post_types = implode("','", $this->_post_types);
758 758
 			$this->_views = $wpdb->get_results(
759 759
 				$wpdb->prepare(
760 760
 					"SELECT s.id, name, slug, default_set, COUNT(p.ID) AS count
@@ -780,9 +780,9 @@  discard block
 block discarded – undo
780 780
 	 * @return [type]               [description]
781 781
 	 */
782 782
 	public function request_current_view() {
783
-		if ( is_null( $this->current_view ) ) {
784
-			foreach ( $this->request_views() as $view ) {
785
-				if ( filter_var( $view['default_set'], FILTER_VALIDATE_BOOLEAN ) ) {
783
+		if (is_null($this->current_view)) {
784
+			foreach ($this->request_views() as $view) {
785
+				if (filter_var($view['default_set'], FILTER_VALIDATE_BOOLEAN)) {
786 786
 					$this->current_view = $view['id'];
787 787
 				}
788 788
 			}
@@ -796,12 +796,12 @@  discard block
 block discarded – undo
796 796
 	 * @return array See :754 order columns.
797 797
 	 */
798 798
 	public function request_items_columns() {
799
-		if ( empty( $this->columns_items ) ) {
799
+		if (empty($this->columns_items)) {
800 800
 			global $wpdb;
801 801
 			$wpsdb_attribute = WPSHOP_DBT_ATTRIBUTE;
802 802
 			$wpsdb_attribute_set = WPSHOP_DBT_ATTRIBUTE_DETAILS;
803
-			$exclude_attribute_codes = implode( "','", $this->exclude_attribute_codes );
804
-			foreach ( $wpdb->get_results(
803
+			$exclude_attribute_codes = implode("','", $this->exclude_attribute_codes);
804
+			foreach ($wpdb->get_results(
805 805
 				$wpdb->prepare(
806 806
 					"SELECT attr.id, attr.code, attr.frontend_label AS name, attr.backend_input AS type, attr.data_type AS data
807 807
 					FROM {$wpsdb_attribute} attr
@@ -815,11 +815,11 @@  discard block
 block discarded – undo
815 815
 					$this->entity_id
816 816
 				),
817 817
 				ARRAY_A
818
-			) as $column ) {
819
-				$this->columns_items[ $column['code'] ] = $column;
818
+			) as $column) {
819
+				$this->columns_items[$column['code']] = $column;
820 820
 			}
821 821
 		}
822
-		ksort( $this->columns_items );
822
+		ksort($this->columns_items);
823 823
 		return $this->columns_items;
824 824
 	}
825 825
 	/**
@@ -830,30 +830,30 @@  discard block
 block discarded – undo
830 830
 	 */
831 831
 	public function get_views() {
832 832
 		$result = array();
833
-		foreach ( $this->request_views() as $view ) {
833
+		foreach ($this->request_views() as $view) {
834 834
 			$class = '';
835
-			if ( (int) $view['id'] === (int) $this->request_current_view() ) {
835
+			if ((int)$view['id'] === (int)$this->request_current_view()) {
836 836
 				$class = ' class="current"';
837 837
 			}
838
-			$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
838
+			$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
839 839
 			$link = add_query_arg(
840 840
 				array(
841 841
 					'page' =>
842 842
 					str_replace(
843 843
 						"{$this->screen->post_type}_page_",
844 844
 						'',
845
-						substr( $this->screen->id, 0, strpos( $this->screen->id, '_att_set_' ) ) . '_att_set_' . $view['id']
845
+						substr($this->screen->id, 0, strpos($this->screen->id, '_att_set_')) . '_att_set_' . $view['id']
846 846
 					),
847 847
 				),
848 848
 				$current_url
849 849
 			);
850
-			$link = remove_query_arg( 'paged', $link );
851
-			$result[ $view['id'] ] = sprintf(
850
+			$link = remove_query_arg('paged', $link);
851
+			$result[$view['id']] = sprintf(
852 852
 				'<a href="%s"%s>%s <span class="count">(%s)</span></a>',
853
-				esc_url( $link ),
853
+				esc_url($link),
854 854
 				$class,
855 855
 				$view['name'],
856
-				number_format_i18n( $view['count'] )
856
+				number_format_i18n($view['count'])
857 857
 			);
858 858
 		}
859 859
 		return $result;
@@ -865,10 +865,10 @@  discard block
 block discarded – undo
865 865
 	 * @param  string $which Can be top or bottom.
866 866
 	 * @return void Direct display.
867 867
 	 */
868
-	public function bulk_actions( $which = '' ) {
869
-		submit_button( __( 'Save changes', 'wpshop' ), 'bulk-save', 'bulk-save', false, array(
870
-			'data-nonce' => wp_create_nonce( 'bulk-save-mass-edit-interface-3' ),
871
-		) );
868
+	public function bulk_actions($which = '') {
869
+		submit_button(__('Save changes', 'wpshop'), 'bulk-save', 'bulk-save', false, array(
870
+			'data-nonce' => wp_create_nonce('bulk-save-mass-edit-interface-3'),
871
+		));
872 872
 		?><span class="spinner"></span><?php
873 873
 	}
874 874
 	/**
@@ -882,34 +882,34 @@  discard block
 block discarded – undo
882 882
 	 * @param  array $rows    List of rows always traited.
883 883
 	 * @return void
884 884
 	 */
885
-	private function _display_row( &$lvl, $item_id, $item, &$rows ) {
886
-		if ( array_key_exists( $item_id, $rows ) ) {
885
+	private function _display_row(&$lvl, $item_id, $item, &$rows) {
886
+		if (array_key_exists($item_id, $rows)) {
887 887
 			return;
888 888
 		}
889
-		if ( ! array_key_exists( $item['parent'], $this->items ) && 0 !== (int) $item['parent'] ) {
890
-			$parent_item = $this->request( $item['parent'] );
891
-			if ( isset( $parent_item[0] ) ) {
892
-				$this->items[ $item['parent'] ] = $parent_item[0];
889
+		if (!array_key_exists($item['parent'], $this->items) && 0 !== (int)$item['parent']) {
890
+			$parent_item = $this->request($item['parent']);
891
+			if (isset($parent_item[0])) {
892
+				$this->items[$item['parent']] = $parent_item[0];
893 893
 			} else {
894
-				$this->items[ $item['parent'] ] = null;
894
+				$this->items[$item['parent']] = null;
895 895
 			}
896 896
 		}
897
-		if ( array_key_exists( $item['parent'], $rows ) ) {
898
-			$offset = array_search( $item['parent'], array_keys( $rows ), true );
899
-			$rows_a = array_slice( $rows, $offset, null, true );
900
-			$rows_a[ $item_id ] = $item;
901
-			$rows_b = array_slice( $rows, 0, $offset, true );
902
-			$rows = array_replace( $rows_a, $rows_b );
897
+		if (array_key_exists($item['parent'], $rows)) {
898
+			$offset = array_search($item['parent'], array_keys($rows), true);
899
+			$rows_a = array_slice($rows, $offset, null, true);
900
+			$rows_a[$item_id] = $item;
901
+			$rows_b = array_slice($rows, 0, $offset, true);
902
+			$rows = array_replace($rows_a, $rows_b);
903 903
 			// $rows = $rows_a + $rows_b; FASTER ?
904 904
 			$lvl++;
905
-		} elseif ( 0 !== (int) $item['parent'] ) {
906
-			$this->_display_row( $lvl, $item['parent'], $this->items[ $item['parent'] ], $rows );
905
+		} elseif (0 !== (int)$item['parent']) {
906
+			$this->_display_row($lvl, $item['parent'], $this->items[$item['parent']], $rows);
907 907
 			$lvl++;
908 908
 		}
909
-		if ( ! empty( $item ) ) {
910
-			$item['lvl'] = str_repeat( '&#8212; ', $lvl );
909
+		if (!empty($item)) {
910
+			$item['lvl'] = str_repeat('&#8212; ', $lvl);
911 911
 		}
912
-		$rows[ $item_id ] = $item;
912
+		$rows[$item_id] = $item;
913 913
 	}
914 914
 	/**
915 915
 	 * See WP_List_Table.
@@ -919,13 +919,13 @@  discard block
 block discarded – undo
919 919
 	 */
920 920
 	public function display_rows() {
921 921
 		$rows = array();
922
-		foreach ( $this->items as $item_id => $item ) {
922
+		foreach ($this->items as $item_id => $item) {
923 923
 			$lvl = 0;
924
-			$this->_display_row( $lvl, $item_id, $item, $rows );
924
+			$this->_display_row($lvl, $item_id, $item, $rows);
925 925
 		}
926
-		foreach ( $rows as $item ) {
927
-			if ( ! empty( $item ) ) {
928
-				$this->single_row( $item );
926
+		foreach ($rows as $item) {
927
+			if (!empty($item)) {
928
+				$this->single_row($item);
929 929
 			}
930 930
 		}
931 931
 	}
@@ -946,52 +946,52 @@  discard block
 block discarded – undo
946 946
 	 * @param  boolean $with_id See wp_list_table::print_column_headers.
947 947
 	 * @return void Direct display.
948 948
 	 */
949
-	public function print_column_headers( $with_id = true ) {
950
-		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
949
+	public function print_column_headers($with_id = true) {
950
+		list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
951 951
 
952
-		$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
953
-		$current_url = remove_query_arg( 'paged', $current_url );
952
+		$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
953
+		$current_url = remove_query_arg('paged', $current_url);
954 954
 
955
-		if ( isset( $_GET['orderby'] ) ) { // WPCS: CSRF ok.
955
+		if (isset($_GET['orderby'])) { // WPCS: CSRF ok.
956 956
 			$current_orderby = $_GET['orderby']; // WPCS: CSRF ok.
957 957
 		} else {
958 958
 			$current_orderby = '';
959 959
 		}
960 960
 
961
-		if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) { // WPCS: CSRF ok.
961
+		if (isset($_GET['order']) && 'desc' === $_GET['order']) { // WPCS: CSRF ok.
962 962
 			$current_order = 'desc';
963 963
 		} else {
964 964
 			$current_order = 'asc';
965 965
 		}
966 966
 
967
-		if ( ! empty( $columns['cb'] ) ) {
967
+		if (!empty($columns['cb'])) {
968 968
 			static $cb_counter = 1;
969
-			$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
969
+			$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
970 970
 			 . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
971 971
 			$cb_counter++;
972 972
 		}
973 973
 
974
-		foreach ( $columns as $column_key => $column_display_name ) {
975
-			$class = array( 'manage-column', "column-$column_key" );
974
+		foreach ($columns as $column_key => $column_display_name) {
975
+			$class = array('manage-column', "column-$column_key");
976 976
 
977
-			if ( in_array( $column_key, $hidden, true ) ) {
977
+			if (in_array($column_key, $hidden, true)) {
978 978
 				$class[] = 'hidden';
979 979
 			}
980 980
 
981
-			if ( 'cb' === $column_key ) {
981
+			if ('cb' === $column_key) {
982 982
 				$class[] = 'check-column';
983
-			} elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
983
+			} elseif (in_array($column_key, array('posts', 'comments', 'links'), true)) {
984 984
 				$class[] = 'num';
985 985
 			}
986 986
 
987
-			if ( $column_key === $primary ) {
987
+			if ($column_key === $primary) {
988 988
 				$class[] = 'column-primary';
989 989
 			}
990 990
 
991
-			if ( isset( $sortable[ $column_key ] ) ) {
992
-				list( $orderby, $desc_first ) = $sortable[ $column_key ];
991
+			if (isset($sortable[$column_key])) {
992
+				list($orderby, $desc_first) = $sortable[$column_key];
993 993
 
994
-				if ( $current_orderby === $orderby ) {
994
+				if ($current_orderby === $orderby) {
995 995
 					$order = 'asc' === $current_order ? 'desc' : 'asc';
996 996
 					$class[] = 'sorted';
997 997
 					$class[] = $current_order;
@@ -1001,17 +1001,17 @@  discard block
 block discarded – undo
1001 1001
 					$class[] = $desc_first ? 'asc' : 'desc';
1002 1002
 				}
1003 1003
 
1004
-				$cast = $this->cast_column( $column_key );
1004
+				$cast = $this->cast_column($column_key);
1005 1005
 
1006
-				$column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order', 'cast' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
1006
+				$column_display_name = '<a href="' . esc_url(add_query_arg(compact('orderby', 'order', 'cast'), $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
1007 1007
 			}
1008 1008
 
1009
-			$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
1010
-			$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1009
+			$tag = ('cb' === $column_key) ? 'td' : 'th';
1010
+			$scope = ('th' === $tag) ? 'scope="col"' : '';
1011 1011
 			$id = $with_id ? "id='$column_key'" : '';
1012 1012
 
1013
-			if ( ! empty( $class ) ) {
1014
-				$class = "class='" . join( ' ', $class ) . "'";
1013
+			if (!empty($class)) {
1014
+				$class = "class='" . join(' ', $class) . "'";
1015 1015
 			}
1016 1016
 
1017 1017
 			echo "<$tag $scope $id $class>$column_display_name</$tag>"; // WPCS: XSS ok.
Please login to merge, or discard this patch.
templates/backend/product-listing/wps_orders_product_listing_table.php 2 patches
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@
 block discarded – undo
1
-<?php if ( ! defined( 'ABSPATH' ) ) { exit;
1
+<?php if (!defined('ABSPATH')) { exit;
2 2
 }
3
- $order_post_meta = ! empty( $post ) ? get_post_meta( $post->ID, '_wpshop_order_status', true ) : ''; ?>
3
+ $order_post_meta = !empty($post) ? get_post_meta($post->ID, '_wpshop_order_status', true) : ''; ?>
4 4
 <div class="wps-table">
5 5
 	<div class="wps-table-header wps-table-row">
6
-		<div class="wps-table-cell"><?php _e( 'Picture', 'wpshop' ); ?></div>
7
-		<div class="wps-table-cell"><?php _e( 'Product reference', 'wpshop' ); ?></div>
8
-		<div class="wps-table-cell"><?php _e( 'Product name', 'wpshop' ); ?></div>
9
-		<div class="wps-table-cell"><?php _e( 'Price', 'wpshop' ); ?></div>
6
+		<div class="wps-table-cell"><?php _e('Picture', 'wpshop'); ?></div>
7
+		<div class="wps-table-cell"><?php _e('Product reference', 'wpshop'); ?></div>
8
+		<div class="wps-table-cell"><?php _e('Product name', 'wpshop'); ?></div>
9
+		<div class="wps-table-cell"><?php _e('Price', 'wpshop'); ?></div>
10 10
 
11
-		<?php if ( 'completed' != $order_post_meta ) : ?>
12
-			<div class="wps-table-cell"><?php _e( 'Quantity', 'wpshop' ); ?></div>
13
-			<div class="wps-table-cell"><?php _e( 'Add to order', 'wpshop' ); ?></div>
11
+		<?php if ('completed' != $order_post_meta) : ?>
12
+			<div class="wps-table-cell"><?php _e('Quantity', 'wpshop'); ?></div>
13
+			<div class="wps-table-cell"><?php _e('Add to order', 'wpshop'); ?></div>
14 14
 		<?php endif; ?>
15 15
 	</div>
16
-	<?php if ( ! empty( $products ) ) :
17
-		$total_products = count( $products );
16
+	<?php if (!empty($products)) :
17
+		$total_products = count($products);
18 18
 		$i = 0;
19 19
 		$elements_per_page = 20;
20
-		$paged = absint( isset( $_REQUEST['paged_order'] ) ? $_REQUEST['paged_order'] : 1 );
21
-		$paginate_links = paginate_links( array(
20
+		$paged = absint(isset($_REQUEST['paged_order']) ? $_REQUEST['paged_order'] : 1);
21
+		$paginate_links = paginate_links(array(
22 22
 			'base' => '%_%',
23 23
 			'format' => '?paged_order=%#%',
24 24
 			'current' => $paged,
25
-			'total' => ceil( $total_products / $elements_per_page ),
25
+			'total' => ceil($total_products / $elements_per_page),
26 26
 			'type' => 'list',
27 27
 			'prev_next' => true,
28
-		) );
29
-		foreach ( $products as $product ) :
30
-			if ( ( $elements_per_page * ( $paged - 1 ) ) > $i ) {
28
+		));
29
+		foreach ($products as $product) :
30
+			if (($elements_per_page * ($paged - 1)) > $i) {
31 31
 				$i++;
32 32
 				continue;
33
-			} elseif ( ( $elements_per_page * $paged ) <= $i ) {
33
+			} elseif (($elements_per_page * $paged) <= $i) {
34 34
 				break;
35 35
 			}
36 36
 			$i++;
37 37
 			$pid = $product->ID;
38 38
 	?>
39
-	<?php $product_metadata = get_post_meta( $product->ID, '_wpshop_product_metadata', true ); ?>
39
+	<?php $product_metadata = get_post_meta($product->ID, '_wpshop_product_metadata', true); ?>
40 40
 	<div class="wps-table-content wps-table-row">
41
-		<div class="wps-table-cell  wps-cart-item-img"><?php echo get_the_post_thumbnail( $product->ID, 'thumbnail' ); ?></div>
42
-		<div class="wps-table-cell"><?php echo ( ! empty( $product_metadata ) && $product_metadata['product_reference']) ? $product_metadata['product_reference'] : ''; ?></div>
41
+		<div class="wps-table-cell  wps-cart-item-img"><?php echo get_the_post_thumbnail($product->ID, 'thumbnail'); ?></div>
42
+		<div class="wps-table-cell"><?php echo (!empty($product_metadata) && $product_metadata['product_reference']) ? $product_metadata['product_reference'] : ''; ?></div>
43 43
 		<div class="wps-table-cell"><?php echo $product->post_title; ?></div>
44 44
 		<div class="wps-table-cell">
45 45
 		<?php
46
-		  $product = wpshop_products::get_product_data( $product->ID );
47
-		  echo wpshop_prices::get_product_price( $product, 'price_display', array( 'mini_output', 'grid' ) );
46
+		  $product = wpshop_products::get_product_data($product->ID);
47
+		  echo wpshop_prices::get_product_price($product, 'price_display', array('mini_output', 'grid'));
48 48
 		?>
49 49
 		</div>
50
-		<?php if ( 'completed' != $order_post_meta ) : ?>
50
+		<?php if ('completed' != $order_post_meta) : ?>
51 51
 			<div class="wps-table-cell">
52
-				<a class="wps-bton-icon-minus-small wps-cart-reduce-product-qty" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_set_qty_for_product_into_cart' ); ?>" href=""></a>
52
+				<a class="wps-bton-icon-minus-small wps-cart-reduce-product-qty" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_set_qty_for_product_into_cart'); ?>" href=""></a>
53 53
 				<input id="wps-cart-product-qty-<?php echo $pid; ?>" class="wps-cart-product-qty" type="text" value="1" name="french-hens" size="3" style="text-align : center">
54
-				<a class="wps-bton-icon-plus-small wps-cart-add-product-qty" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_set_qty_for_product_into_cart' ); ?>" href=""></a>
54
+				<a class="wps-bton-icon-plus-small wps-cart-add-product-qty" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_set_qty_for_product_into_cart'); ?>" href=""></a>
55 55
 			</div>
56 56
 			<div class="wps-table-cell">
57
-				<a href="#" data-nonce="<?php echo wp_create_nonce( 'wps_add_product_to_order_admin' ); ?>" class="wps-bton-first-mini-rounded wps-order-add-product" id="wps-order-add-product-<?php echo $pid; ?>"><i class="wps-icon-basket"></i> <?php _e( 'Add to order', 'wpshop' ); ?></a>
57
+				<a href="#" data-nonce="<?php echo wp_create_nonce('wps_add_product_to_order_admin'); ?>" class="wps-bton-first-mini-rounded wps-order-add-product" id="wps-order-add-product-<?php echo $pid; ?>"><i class="wps-icon-basket"></i> <?php _e('Add to order', 'wpshop'); ?></a>
58 58
 			</div>
59 59
 		<?php endif; ?>
60 60
 	 </div>
61 61
 		<?php endforeach;
62 62
   else :
63
-		if ( ! empty( $research ) ) : ?>
64
-		   <div class="wps-alert-info"><?php printf( __( 'No products corresponds to the search <strong>"%s"</strong>', 'wpshop' ), $research ); ?></div>
63
+		if (!empty($research)) : ?>
64
+		   <div class="wps-alert-info"><?php printf(__('No products corresponds to the search <strong>"%s"</strong>', 'wpshop'), $research); ?></div>
65 65
 		<?php else :
66
-		   $letter_display = ( strtoupper( $current_letter ) != 'ALL' ) ? $current_letter : __( 'ALL', 'wpshop' ); ?>
67
-			<div class="wps-alert-info"><?php printf( __( 'No products corresponds to the letter <strong>"%s"</strong> search', 'wpshop' ), strtoupper( $letter_display ) ); ?></div>
66
+		   $letter_display = (strtoupper($current_letter) != 'ALL') ? $current_letter : __('ALL', 'wpshop'); ?>
67
+			<div class="wps-alert-info"><?php printf(__('No products corresponds to the letter <strong>"%s"</strong> search', 'wpshop'), strtoupper($letter_display)); ?></div>
68 68
 	<?php endif;
69 69
 	   endif; ?>
70 70
 </div>
71 71
 <?php
72
-if ( ! empty( $products ) && $total_products > $elements_per_page ) :
72
+if (!empty($products) && $total_products > $elements_per_page) :
73 73
 	echo $paginate_links;
74 74
 	?>
75 75
 	<input type="hidden" name="last_query[oid]" value="<?php echo $post->ID; ?>">
76
-	<input type="hidden" name="last_query[letter]" value="<?php echo strtoupper( $current_letter ); ?>">
77
-	<input type="hidden" name="last_query[research]" value="<?php echo isset( $research ) ? $research : ''; ?>">
78
-	<input type="hidden" name="last_query[_wpnonce]" value="<?php echo wp_create_nonce( 'refresh_product_list_' . strtolower( $current_letter ) ); ?>">
76
+	<input type="hidden" name="last_query[letter]" value="<?php echo strtoupper($current_letter); ?>">
77
+	<input type="hidden" name="last_query[research]" value="<?php echo isset($research) ? $research : ''; ?>">
78
+	<input type="hidden" name="last_query[_wpnonce]" value="<?php echo wp_create_nonce('refresh_product_list_' . strtolower($current_letter)); ?>">
79 79
 	<?php
80 80
 endif;
81 81
 ?>
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,11 +59,17 @@
 block discarded – undo
59 59
 		<?php endif; ?>
60 60
 	 </div>
61 61
 		<?php endforeach;
62
-  else :
62
+  else {
63
+  	:
63 64
 		if ( ! empty( $research ) ) : ?>
64
-		   <div class="wps-alert-info"><?php printf( __( 'No products corresponds to the search <strong>"%s"</strong>', 'wpshop' ), $research ); ?></div>
65
-		<?php else :
66
-		   $letter_display = ( strtoupper( $current_letter ) != 'ALL' ) ? $current_letter : __( 'ALL', 'wpshop' ); ?>
65
+		   <div class="wps-alert-info"><?php printf( __( 'No products corresponds to the search <strong>"%s"</strong>', 'wpshop' ), $research );
66
+  }
67
+  ?></div>
68
+		<?php else {
69
+	:
70
+		   $letter_display = ( strtoupper( $current_letter ) != 'ALL' ) ? $current_letter : __( 'ALL', 'wpshop' );
71
+}
72
+?>
67 73
 			<div class="wps-alert-info"><?php printf( __( 'No products corresponds to the letter <strong>"%s"</strong> search', 'wpshop' ), strtoupper( $letter_display ) ); ?></div>
68 74
 	<?php endif;
69 75
 	   endif; ?>
Please login to merge, or discard this patch.
includes/modules/wps-eav-revisions/wps-eav-revisions.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -2,25 +2,25 @@  discard block
 block discarded – undo
2 2
 class WPS_EAV_Revisions {
3 3
 	public static $created_revisions = array();
4 4
 	public function __construct() {
5
-		add_action( 'save_post', array( $this, 'save_post' ), 100, 2 );
6
-		add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
7
-		add_filter( '_wp_post_revision_fields', array( $this, 'wp_post_revision_fields' ), 10, 2 );
5
+		add_action('save_post', array($this, 'save_post'), 100, 2);
6
+		add_action('wp_restore_post_revision', array($this, 'wp_restore_post_revision'), 10, 2);
7
+		add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields'), 10, 2);
8 8
 	}
9
-	public function save_post( $post_id, $post ) {
10
-		if ( false === wp_is_post_revision( $post_id ) ) {
11
-			if ( ( ! isset( self::$created_revisions[ $post_id ] ) || true !== self::$created_revisions[ $post_id ] ) && post_type_supports( $post->post_type, 'revisions' ) ) {
12
-				self::$created_revisions[ wp_is_post_revision( $post_id ) ] = true;
13
-				add_filter( 'wp_save_post_revision_post_has_changed', array( $this, 'wp_save_post_revision_post_has_changed' ), 10, 3 );
14
-				wp_save_post_revision( $post_id );
9
+	public function save_post($post_id, $post) {
10
+		if (false === wp_is_post_revision($post_id)) {
11
+			if ((!isset(self::$created_revisions[$post_id]) || true !== self::$created_revisions[$post_id]) && post_type_supports($post->post_type, 'revisions')) {
12
+				self::$created_revisions[wp_is_post_revision($post_id)] = true;
13
+				add_filter('wp_save_post_revision_post_has_changed', array($this, 'wp_save_post_revision_post_has_changed'), 10, 3);
14
+				wp_save_post_revision($post_id);
15 15
 			}
16 16
 		} else {
17
-			self::$created_revisions[ wp_is_post_revision( $post_id ) ] = true;
17
+			self::$created_revisions[wp_is_post_revision($post_id)] = true;
18 18
 		}
19 19
 	}
20
-	public function wp_save_post_revision_post_has_changed( $post_has_changed, $last_revision, $post ) {
20
+	public function wp_save_post_revision_post_has_changed($post_has_changed, $last_revision, $post) {
21 21
 		return true;
22 22
 	}
23
-	public function wp_restore_post_revision( $post_id, $revision_id ) {
23
+	public function wp_restore_post_revision($post_id, $revision_id) {
24 24
 		/*
25 25
 		$post     = get_post( $post_id );
26 26
 		$revision = get_post( $revision_id );
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 			update_post_meta( $post_id, 'foo', $meta );
32 32
 		}*/
33 33
 	}
34
-	public function wp_post_revision_fields( $fields, $post ) {
34
+	public function wp_post_revision_fields($fields, $post) {
35 35
 		global $wpdb;
36 36
 		$wpsdb_attribute = WPSHOP_DBT_ATTRIBUTE;
37 37
 		$wpsdb_attribute_set = WPSHOP_DBT_ATTRIBUTE_DETAILS;
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 		$wpsdb_values_varchar = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;
43 43
 		$wpsdb_values_text = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;
44 44
 		$wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;
45
-		$datas = $wpdb->get_results( $wpdb->prepare(
45
+		$datas = $wpdb->get_results($wpdb->prepare(
46 46
 			"SELECT attr.id,
47 47
 			attr.code,
48 48
 			attr.frontend_label,
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
 			WHERE p.ID = %d
72 72
 			GROUP BY attr.code",
73 73
 			$post['ID']
74
-		), ARRAY_A );
75
-		foreach ( $datas as $data ) {
76
-			$fields[ $data['id'] ] = $data['frontend_label'];
77
-			add_filter( "_wp_post_revision_field_{$data['id']}", array( $this, 'wp_post_revision_field' ), 10, 4 );
74
+		), ARRAY_A);
75
+		foreach ($datas as $data) {
76
+			$fields[$data['id']] = $data['frontend_label'];
77
+			add_filter("_wp_post_revision_field_{$data['id']}", array($this, 'wp_post_revision_field'), 10, 4);
78 78
 		}
79 79
 		return $fields;
80 80
 	}
81
-	public function wp_post_revision_field( $value, $field, $revision, $fromto ) {
81
+	public function wp_post_revision_field($value, $field, $revision, $fromto) {
82 82
 		global $wpdb;
83 83
 		$wpsdb_histo = WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO;
84 84
 		$wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;
85
-		$result = $wpdb->get_var( $wpdb->prepare(
85
+		$result = $wpdb->get_var($wpdb->prepare(
86 86
 			"SELECT IFNULL( val_opt.label,
87 87
 				histo.value
88 88
 			)
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 			$revision->post_date,
96 96
 			$field,
97 97
 			$revision->post_parent
98
-		) );
99
-		$result = ( '0' === $result ) ? null : $result;
98
+		));
99
+		$result = ('0' === $result) ? null : $result;
100 100
 		return $result;
101 101
 	}
102 102
 }
Please login to merge, or discard this patch.
includes/config.php 1 patch
Spacing   +250 added lines, -250 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
 /**
4 4
 * Plugin configuration file.
@@ -12,322 +12,322 @@  discard block
 block discarded – undo
12 12
 */
13 13
 
14 14
 // End if().
15
-if ( ! defined( 'WPSHOP_VERSION' ) ) {
16
-	die( __( 'Access is not allowed by this way', 'wpshop' ) );
15
+if (!defined('WPSHOP_VERSION')) {
16
+	die(__('Access is not allowed by this way', 'wpshop'));
17 17
 }
18 18
 
19 19
 // End if().
20 20
 global $wpdb;
21 21
 /*	Define the shop type	*/
22
-DEFINE( 'WPSHOP_DEFAULT_SHOP_TYPE', 'sale' );
23
-$wpshop_shop_type = get_option( 'wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE );
24
-DEFINE( 'WPSHOP_DEFINED_SHOP_TYPE', $wpshop_shop_type );
22
+DEFINE('WPSHOP_DEFAULT_SHOP_TYPE', 'sale');
23
+$wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
24
+DEFINE('WPSHOP_DEFINED_SHOP_TYPE', $wpshop_shop_type);
25 25
 
26 26
 /*
27 27
   Define the different path for the plugin    */
28 28
    /*	Define main plugin directory for our plugin	*/
29
- DEFINE( 'WPSHOP_DIR', WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR );
30
-   DEFINE( 'WPSHOP_URL', WP_PLUGIN_URL . '/' . WPSHOP_PLUGIN_DIR );
29
+ DEFINE('WPSHOP_DIR', WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR);
30
+   DEFINE('WPSHOP_URL', WP_PLUGIN_URL . '/' . WPSHOP_PLUGIN_DIR);
31 31
 
32 32
   /*	Define languages directory for our plugin	*/
33
- DEFINE( 'WPSHOP_LANGUAGES_DIR', WPSHOP_DIR . '/languages/' );
34
-  DEFINE( 'WPSHOP_LANGUAGES_URL', WPSHOP_URL . '/languages/' );
33
+ DEFINE('WPSHOP_LANGUAGES_DIR', WPSHOP_DIR . '/languages/');
34
+  DEFINE('WPSHOP_LANGUAGES_URL', WPSHOP_URL . '/languages/');
35 35
 
36 36
  /*	Define includes directory for our plugin	*/
37
- DEFINE( 'WPSHOP_INCLUDES_DIR', WPSHOP_DIR . '/includes/' );
38
-	DEFINE( 'WPSHOP_INCLUDES_URL', WPSHOP_URL . '/includes/' );
39
-	DEFINE( 'WPSHOP_MODULES_DIR', WPSHOP_INCLUDES_DIR . 'modules/' );
37
+ DEFINE('WPSHOP_INCLUDES_DIR', WPSHOP_DIR . '/includes/');
38
+	DEFINE('WPSHOP_INCLUDES_URL', WPSHOP_URL . '/includes/');
39
+	DEFINE('WPSHOP_MODULES_DIR', WPSHOP_INCLUDES_DIR . 'modules/');
40 40
 	  /*	Define librairies directory for our plugin	*/
41
-	 DEFINE( 'WPSHOP_LIBRAIRIES_DIR', WPSHOP_INCLUDES_DIR . 'librairies/' );
42
-		DEFINE( 'WPSHOP_LIBRAIRIES_URL', WPSHOP_INCLUDES_URL . 'librairies/' );
41
+	 DEFINE('WPSHOP_LIBRAIRIES_DIR', WPSHOP_INCLUDES_DIR . 'librairies/');
42
+		DEFINE('WPSHOP_LIBRAIRIES_URL', WPSHOP_INCLUDES_URL . 'librairies/');
43 43
 
44 44
    /*	Define templates directory for our plugin	*/
45
- DEFINE( 'WPSHOP_TEMPLATES_DIR', WPSHOP_DIR . '/templates/' );
46
-  DEFINE( 'WPSHOP_TEMPLATES_URL', WPSHOP_URL . '/templates/' );
45
+ DEFINE('WPSHOP_TEMPLATES_DIR', WPSHOP_DIR . '/templates/');
46
+  DEFINE('WPSHOP_TEMPLATES_URL', WPSHOP_URL . '/templates/');
47 47
 	  /*	Define medias directory for our plugin	*/
48
-	 DEFINE( 'WPSHOP_MEDIAS_DIR', WPSHOP_TEMPLATES_DIR . 'admin/medias/' );
49
-	 DEFINE( 'WPSHOP_MEDIAS_URL', WPSHOP_TEMPLATES_URL . 'admin/medias/' );
48
+	 DEFINE('WPSHOP_MEDIAS_DIR', WPSHOP_TEMPLATES_DIR . 'admin/medias/');
49
+	 DEFINE('WPSHOP_MEDIAS_URL', WPSHOP_TEMPLATES_URL . 'admin/medias/');
50 50
 		 /*	Define plugin icon directory	*/
51
-		 DEFINE( 'WPSHOP_MEDIAS_ICON_DIR', WPSHOP_MEDIAS_DIR . 'icones/' );
52
-		 DEFINE( 'WPSHOP_MEDIAS_ICON_URL', WPSHOP_MEDIAS_URL . 'icones/' );
51
+		 DEFINE('WPSHOP_MEDIAS_ICON_DIR', WPSHOP_MEDIAS_DIR . 'icones/');
52
+		 DEFINE('WPSHOP_MEDIAS_ICON_URL', WPSHOP_MEDIAS_URL . 'icones/');
53 53
 		 /*	Define plugin picture directory	*/
54
-		 DEFINE( 'WPSHOP_MEDIAS_IMAGES_DIR', WPSHOP_MEDIAS_DIR . 'images/' );
55
-		   DEFINE( 'WPSHOP_MEDIAS_IMAGES_URL', WPSHOP_MEDIAS_URL . 'images/' );
54
+		 DEFINE('WPSHOP_MEDIAS_IMAGES_DIR', WPSHOP_MEDIAS_DIR . 'images/');
55
+		   DEFINE('WPSHOP_MEDIAS_IMAGES_URL', WPSHOP_MEDIAS_URL . 'images/');
56 56
 	   /*	Define medias directory for our plugin	*/
57
-	 DEFINE( 'WPSHOP_JS_DIR', WPSHOP_TEMPLATES_DIR . 'admin/js/' );
58
-	 DEFINE( 'WPSHOP_JS_URL', WPSHOP_TEMPLATES_URL . 'admin/js/' );
57
+	 DEFINE('WPSHOP_JS_DIR', WPSHOP_TEMPLATES_DIR . 'admin/js/');
58
+	 DEFINE('WPSHOP_JS_URL', WPSHOP_TEMPLATES_URL . 'admin/js/');
59 59
 	 /*	Define medias directory for our plugin	*/
60
-	 DEFINE( 'WPSHOP_CSS_DIR', WPSHOP_TEMPLATES_DIR . 'admin/css/' );
61
-	   DEFINE( 'WPSHOP_CSS_URL', WPSHOP_TEMPLATES_URL . 'admin/css/' );
60
+	 DEFINE('WPSHOP_CSS_DIR', WPSHOP_TEMPLATES_DIR . 'admin/css/');
61
+	   DEFINE('WPSHOP_CSS_URL', WPSHOP_TEMPLATES_URL . 'admin/css/');
62 62
 /*	Define upload dir	*/
63 63
  $wp_upload_dir = wp_upload_dir();
64
-  DEFINE( 'WPSHOP_UPLOAD_DIR', $wp_upload_dir['basedir'] . '/' );
65
-	DEFINE( 'WPSHOP_UPLOAD_URL', $wp_upload_dir['baseurl'] . '/' );
66
-	DEFINE( 'WPSHOP_WP_UPLOAD_DIR', $wp_upload_dir['basedir'] . '/' );
67
- DEFINE( 'WPSHOP_WP_UPLOAD_URL', $wp_upload_dir['baseurl'] . '/' );
64
+  DEFINE('WPSHOP_UPLOAD_DIR', $wp_upload_dir['basedir'] . '/');
65
+	DEFINE('WPSHOP_UPLOAD_URL', $wp_upload_dir['baseurl'] . '/');
66
+	DEFINE('WPSHOP_WP_UPLOAD_DIR', $wp_upload_dir['basedir'] . '/');
67
+ DEFINE('WPSHOP_WP_UPLOAD_URL', $wp_upload_dir['baseurl'] . '/');
68 68
 
69 69
 /*
70 70
   Define external ajax file url   */
71 71
 // DEFINE('WPSHOP_AJAX_FILE_URL', WPSHOP_INCLUDES_URL . 'ajax.php');
72 72
 /*	Define element for new type creation	*/
73
- DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES', 'wpshop_entities' );
74
- DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS', 'wpshop_customers' );
75
-   DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT', 'wpshop_product' );
76
-   DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS', 'wpshop_address' );
77
-   DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION', 'wps_pdt_variations' );
78
- DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS_GROUP', 'wps_customer_group' );
79
-   DEFINE( 'WPSHOP_IDENTIFIER_PRODUCT', 'P' );
80
-	DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_ORDER', 'wpshop_shop_order' );
81
-  DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_COUPON', 'wpshop_shop_coupon' );
82
-	DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE', 'wpshop_shop_message' );
83
-  DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_GROUP', 'wpshop_shop_group' );
84
-  DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_ADDONS', 'wpshop_shop_addons' );
85
-	DEFINE( 'WPSHOP_ATTRIBUTE_SET_ID_META_KEY', '_%s_attribute_set_id' );
86
-  DEFINE( 'WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id' );
87
-   DEFINE( 'WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY', '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id' );
88
-   DEFINE( 'WPSHOP_PRODUCT_ATTRIBUTE_META_KEY', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_metadata' );
89
-  DEFINE( 'WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES', 'wpshop_product_category' );
90
-   DEFINE( 'WPSHOP_PRODUCT_RELATED_PRODUCTS', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_related_products' );
91
-	DEFINE( 'WPSHOP_PRODUCT_PROVIDER', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_provider' );
92
-	DEFINE( 'WPSHOP_PRODUCT_VIEW_NB', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_view_nb' );
93
-  DEFINE( 'WPSHOP_PRODUCT_FRONT_DISPLAY_CONF', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attributes_frontend_display' );
94
-
95
-  DEFINE( 'WPSHOP_DEFAULT_CUSTOM_TYPES', serialize( array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ) ) );
96
-
97
-
98
-	DEFINE( 'WPSHOP_IDENTIFIER_CUSTOMER', 'U' );
99
-   $cat_options = get_option( 'wpshop_catalog_categories_option' );
100
-   DEFINE( 'WPSHOP_UNCATEGORIZED_PRODUCT_SLUG', ! empty( $cat_options['wpshop_catalog_no_category_slug'] ) ? $cat_options['wpshop_catalog_no_category_slug'] : 'no-category' );
101
-   DEFINE( 'WPSHOP_CATALOG_PRODUCT_SLUG', 'catalog' );
102
-	DEFINE( 'WPSHOP_CATALOG_CATEGORIES_SLUG', 'catalog' );
103
- DEFINE( 'WPSHOP_CATALOG_PRODUCT_NO_CATEGORY', 'no-categories' );
104
-   include_once( WPSHOP_LIBRAIRIES_DIR . 'purchase/list_countries.php' );
105
- DEFINE( 'WPSHOP_COUNTRY_LIST', serialize( $wpshop_tab_countries ) );
106
-
107
-
108
- DEFINE( 'WPSHOP_COMMON_ATTRIBUTES_PARENT_VARIATION_PRODUCT', serialize( array( 'tx_tva' ) ) );
73
+ DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES', 'wpshop_entities');
74
+ DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS', 'wpshop_customers');
75
+   DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT', 'wpshop_product');
76
+   DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS', 'wpshop_address');
77
+   DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION', 'wps_pdt_variations');
78
+ DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS_GROUP', 'wps_customer_group');
79
+   DEFINE('WPSHOP_IDENTIFIER_PRODUCT', 'P');
80
+	DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_ORDER', 'wpshop_shop_order');
81
+  DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_COUPON', 'wpshop_shop_coupon');
82
+	DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE', 'wpshop_shop_message');
83
+  DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_GROUP', 'wpshop_shop_group');
84
+  DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_ADDONS', 'wpshop_shop_addons');
85
+	DEFINE('WPSHOP_ATTRIBUTE_SET_ID_META_KEY', '_%s_attribute_set_id');
86
+  DEFINE('WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id');
87
+   DEFINE('WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY', '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id');
88
+   DEFINE('WPSHOP_PRODUCT_ATTRIBUTE_META_KEY', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_metadata');
89
+  DEFINE('WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES', 'wpshop_product_category');
90
+   DEFINE('WPSHOP_PRODUCT_RELATED_PRODUCTS', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_related_products');
91
+	DEFINE('WPSHOP_PRODUCT_PROVIDER', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_provider');
92
+	DEFINE('WPSHOP_PRODUCT_VIEW_NB', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_view_nb');
93
+  DEFINE('WPSHOP_PRODUCT_FRONT_DISPLAY_CONF', '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attributes_frontend_display');
94
+
95
+  DEFINE('WPSHOP_DEFAULT_CUSTOM_TYPES', serialize(array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)));
96
+
97
+
98
+	DEFINE('WPSHOP_IDENTIFIER_CUSTOMER', 'U');
99
+   $cat_options = get_option('wpshop_catalog_categories_option');
100
+   DEFINE('WPSHOP_UNCATEGORIZED_PRODUCT_SLUG', !empty($cat_options['wpshop_catalog_no_category_slug']) ? $cat_options['wpshop_catalog_no_category_slug'] : 'no-category');
101
+   DEFINE('WPSHOP_CATALOG_PRODUCT_SLUG', 'catalog');
102
+	DEFINE('WPSHOP_CATALOG_CATEGORIES_SLUG', 'catalog');
103
+ DEFINE('WPSHOP_CATALOG_PRODUCT_NO_CATEGORY', 'no-categories');
104
+   include_once(WPSHOP_LIBRAIRIES_DIR . 'purchase/list_countries.php');
105
+ DEFINE('WPSHOP_COUNTRY_LIST', serialize($wpshop_tab_countries));
106
+
107
+
108
+ DEFINE('WPSHOP_COMMON_ATTRIBUTES_PARENT_VARIATION_PRODUCT', serialize(array('tx_tva')));
109 109
 /*	Define database table names	*/
110
- DEFINE( 'WPSHOP_DBT_ENTITIES', $wpdb->prefix . 'wpshop__entity' );
111
- DEFINE( 'WPSHOP_DBT_ATTRIBUTE_SET', $wpdb->prefix . 'wpshop__attribute_set' );
112
- DEFINE( 'WPSHOP_DBT_ATTRIBUTE_GROUP', $wpdb->prefix . 'wpshop__attribute_set_section' );
113
-   DEFINE( 'WPSHOP_DBT_ATTRIBUTE_DETAILS', $wpdb->prefix . 'wpshop__attribute_set_section_details' );
114
-
115
-	DEFINE( 'WPSHOP_DBT_ATTRIBUTE_UNIT', $wpdb->prefix . 'wpshop__attributes_unit' );
116
-  DEFINE( 'WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP', $wpdb->prefix . 'wpshop__attributes_unit_groups' );
117
-
118
-	DEFINE( 'WPSHOP_DBT_ATTRIBUTE', $wpdb->prefix . 'wpshop__attribute' );
119
- DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX', $wpdb->prefix . 'wpshop__attribute_value_' );
120
-	DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'varchar' );
121
-   DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'datetime' );
122
- DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'decimal' );
123
-   DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'integer' );
124
-   DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'text' );
125
- DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . '_histo' );
126
-  DEFINE( 'WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'options' );
127
-
128
-  DEFINE( 'WPSHOP_DBT_HISTORIC', $wpdb->prefix . 'wpshop__historique' );
129
- DEFINE( 'WPSHOP_DBT_MESSAGES', $wpdb->prefix . 'wpshop__message' );
110
+ DEFINE('WPSHOP_DBT_ENTITIES', $wpdb->prefix . 'wpshop__entity');
111
+ DEFINE('WPSHOP_DBT_ATTRIBUTE_SET', $wpdb->prefix . 'wpshop__attribute_set');
112
+ DEFINE('WPSHOP_DBT_ATTRIBUTE_GROUP', $wpdb->prefix . 'wpshop__attribute_set_section');
113
+   DEFINE('WPSHOP_DBT_ATTRIBUTE_DETAILS', $wpdb->prefix . 'wpshop__attribute_set_section_details');
114
+
115
+	DEFINE('WPSHOP_DBT_ATTRIBUTE_UNIT', $wpdb->prefix . 'wpshop__attributes_unit');
116
+  DEFINE('WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP', $wpdb->prefix . 'wpshop__attributes_unit_groups');
117
+
118
+	DEFINE('WPSHOP_DBT_ATTRIBUTE', $wpdb->prefix . 'wpshop__attribute');
119
+ DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX', $wpdb->prefix . 'wpshop__attribute_value_');
120
+	DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'varchar');
121
+   DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'datetime');
122
+ DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'decimal');
123
+   DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'integer');
124
+   DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'text');
125
+ DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . '_histo');
126
+  DEFINE('WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS', WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . 'options');
127
+
128
+  DEFINE('WPSHOP_DBT_HISTORIC', $wpdb->prefix . 'wpshop__historique');
129
+ DEFINE('WPSHOP_DBT_MESSAGES', $wpdb->prefix . 'wpshop__message');
130 130
 
131 131
    /*	Delete table at database version 12 for new cart management with session and usermeta database	*/
132
- DEFINE( 'WPSHOP_DBT_CART', $wpdb->prefix . 'wpshop__cart' );
133
-   DEFINE( 'WPSHOP_DBT_CART_CONTENTS', $wpdb->prefix . 'wpshop__cart_contents' );
132
+ DEFINE('WPSHOP_DBT_CART', $wpdb->prefix . 'wpshop__cart');
133
+   DEFINE('WPSHOP_DBT_CART_CONTENTS', $wpdb->prefix . 'wpshop__cart_contents');
134 134
 /*	Define the different url for the plugin	*/
135
- DEFINE( 'WPSHOP_URL_SLUG_DASHBOARD', 'wpshop_dashboard' );
136
- DEFINE( 'WPSHOP_URL_SLUG_ATTRIBUTE_LISTING', 'wpshop_attribute' );
137
- DEFINE( 'WPSHOP_URL_SLUG_SHORTCODES', 'wpshop_shortcodes' );
138
-   DEFINE( 'WPSHOP_URL_SLUG_ABOUT', 'wpshop_about' );
139
- DEFINE( 'WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING', 'wpshop_attribute_group' );
140
-   DEFINE( 'WPSHOP_URL_SLUG_OPTION', 'wpshop_option' );
141
-   DEFINE( 'WPSHOP_URL_SLUG_MESSAGES', 'wpshop_messages' );
142
-   DEFINE( 'WPSHOP_URL_SLUG_TOOLS', 'wpshop_tools' );
135
+ DEFINE('WPSHOP_URL_SLUG_DASHBOARD', 'wpshop_dashboard');
136
+ DEFINE('WPSHOP_URL_SLUG_ATTRIBUTE_LISTING', 'wpshop_attribute');
137
+ DEFINE('WPSHOP_URL_SLUG_SHORTCODES', 'wpshop_shortcodes');
138
+   DEFINE('WPSHOP_URL_SLUG_ABOUT', 'wpshop_about');
139
+ DEFINE('WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING', 'wpshop_attribute_group');
140
+   DEFINE('WPSHOP_URL_SLUG_OPTION', 'wpshop_option');
141
+   DEFINE('WPSHOP_URL_SLUG_MESSAGES', 'wpshop_messages');
142
+   DEFINE('WPSHOP_URL_SLUG_TOOLS', 'wpshop_tools');
143 143
 /*	Define the different pictures for the plugin	*/
144
- DEFINE( 'WPSHOP_AUTHORIZED_PICS_EXTENSIONS', 'gif|jp(e)*g|png' );
145
-  DEFINE( 'WPSHOP_LOADING_ICON', admin_url( 'images/loading.gif' ) );
146
-	DEFINE( 'WPSHOP_ERROR_ICON', WPSHOP_MEDIAS_URL . 'icones/informations/error_s.png' );
147
-  DEFINE( 'WPSHOP_SUCCES_ICON', WPSHOP_MEDIAS_URL . 'icones/informations/success_s.png' );
148
-   DEFINE( 'WPSHOP_DEFAULT_PRODUCT_PICTURE', WPSHOP_MEDIAS_IMAGES_URL . 'no_picture.png' );
149
-   DEFINE( 'WPSHOP_DEFAULT_CATEGORY_PICTURE', WPSHOP_MEDIAS_IMAGES_URL . 'no_picture.png' );
150
-  DEFINE( 'WPSHOP_PRODUCT_NOT_EXIST', WPSHOP_MEDIAS_IMAGES_URL . 'not_exist.gif' );
144
+ DEFINE('WPSHOP_AUTHORIZED_PICS_EXTENSIONS', 'gif|jp(e)*g|png');
145
+  DEFINE('WPSHOP_LOADING_ICON', admin_url('images/loading.gif'));
146
+	DEFINE('WPSHOP_ERROR_ICON', WPSHOP_MEDIAS_URL . 'icones/informations/error_s.png');
147
+  DEFINE('WPSHOP_SUCCES_ICON', WPSHOP_MEDIAS_URL . 'icones/informations/success_s.png');
148
+   DEFINE('WPSHOP_DEFAULT_PRODUCT_PICTURE', WPSHOP_MEDIAS_IMAGES_URL . 'no_picture.png');
149
+   DEFINE('WPSHOP_DEFAULT_CATEGORY_PICTURE', WPSHOP_MEDIAS_IMAGES_URL . 'no_picture.png');
150
+  DEFINE('WPSHOP_PRODUCT_NOT_EXIST', WPSHOP_MEDIAS_IMAGES_URL . 'not_exist.gif');
151 151
 
152 152
 /*
153 153
   Define various configuration vars   */
154 154
    /*	FRONTEND DISPLAY	*/
155
- $wpshop_display_option = get_option( 'wpshop_display_option' );
156
-	DEFINE( 'WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE', (isset( $wpshop_display_option['wpshop_display_grid_element_number'] ) && ($wpshop_display_option['wpshop_display_grid_element_number'] >= 1) ? $wpshop_display_option['wpshop_display_grid_element_number'] : 1) );
157
-	DEFINE( 'WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MIN_RANGE', 1 );
158
-  DEFINE( 'WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MAX_RANGE', 6 );
155
+ $wpshop_display_option = get_option('wpshop_display_option');
156
+	DEFINE('WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE', (isset($wpshop_display_option['wpshop_display_grid_element_number']) && ($wpshop_display_option['wpshop_display_grid_element_number'] >= 1) ? $wpshop_display_option['wpshop_display_grid_element_number'] : 1));
157
+	DEFINE('WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MIN_RANGE', 1);
158
+  DEFINE('WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE_MAX_RANGE', 6);
159 159
 
160
- DEFINE( 'WPSHOP_ELEMENT_NB_PER_PAGE', ! empty( $wpshop_display_option['wpshop_display_element_per_page'] ) ? $wpshop_display_option['wpshop_display_element_per_page'] : 20 );
161
- DEFINE( 'WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE', 3 );
162
- DEFINE( 'WPSHOP_DISPLAY_LIST_TYPE', $wpshop_display_option['wpshop_display_list_type'] );
160
+ DEFINE('WPSHOP_ELEMENT_NB_PER_PAGE', !empty($wpshop_display_option['wpshop_display_element_per_page']) ? $wpshop_display_option['wpshop_display_element_per_page'] : 20);
161
+ DEFINE('WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE', 3);
162
+ DEFINE('WPSHOP_DISPLAY_LIST_TYPE', $wpshop_display_option['wpshop_display_list_type']);
163 163
 
164 164
  /*	ADMIN DISPLAY	*/
165 165
  $attribute_page_layout_types = array(
166
-	 'tab' => __( 'Tabs', 'wpshop' ),
167
-	 'separated_bloc' => __( 'Separated bloc', 'wpshop' ),
166
+	 'tab' => __('Tabs', 'wpshop'),
167
+	 'separated_bloc' => __('Separated bloc', 'wpshop'),
168 168
  );
169
-  $wpshop_admin_display_option = get_option( 'wpshop_admin_display_option', array() );
170
-   DEFINE( 'WPSHOP_ATTRIBUTE_SET_EDITION_PAGE_LAYOUT', ( ! empty( $wpshop_admin_display_option['wpshop_admin_attr_set_layout'] )?$wpshop_admin_display_option['wpshop_admin_attr_set_layout']:'separated_bloc') );
171
- DEFINE( 'WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT', ( ! empty( $wpshop_admin_display_option['wpshop_admin_attr_layout'] )?$wpshop_admin_display_option['wpshop_admin_attr_layout']:'tab') );
169
+  $wpshop_admin_display_option = get_option('wpshop_admin_display_option', array());
170
+   DEFINE('WPSHOP_ATTRIBUTE_SET_EDITION_PAGE_LAYOUT', (!empty($wpshop_admin_display_option['wpshop_admin_attr_set_layout']) ? $wpshop_admin_display_option['wpshop_admin_attr_set_layout'] : 'separated_bloc'));
171
+ DEFINE('WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT', (!empty($wpshop_admin_display_option['wpshop_admin_attr_layout']) ? $wpshop_admin_display_option['wpshop_admin_attr_layout'] : 'tab'));
172 172
 	$product_page_layout_types = array(
173
-		'movable-tab' => __( 'Separated box in product page', 'wpshop' ),
174
-		'fixed-tab' => __( 'A tab in product data box "Product data"', 'wpshop' ),
175
-		'each-box' => __( 'In each attribute group section "Product data"', 'wpshop' ),
173
+		'movable-tab' => __('Separated box in product page', 'wpshop'),
174
+		'fixed-tab' => __('A tab in product data box "Product data"', 'wpshop'),
175
+		'each-box' => __('In each attribute group section "Product data"', 'wpshop'),
176 176
 	);
177
-	DEFINE( 'WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE', ( ! empty( $wpshop_admin_display_option['wpshop_admin_product_shortcode_display'] )?$wpshop_admin_display_option['wpshop_admin_product_shortcode_display']:'each-box') );
177
+	DEFINE('WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE', (!empty($wpshop_admin_display_option['wpshop_admin_product_shortcode_display']) ? $wpshop_admin_display_option['wpshop_admin_product_shortcode_display'] : 'each-box'));
178 178
 	/*  Define debug vars   */
179
-	$extra_options = get_option( 'wpshop_extra_options', array() );
180
-	DEFINE( 'WPSHOP_ADDONS_OPTION_NAME', 'wpshop_addons' );
181
-	$wpshop_addons_state = get_option( WPSHOP_ADDONS_OPTION_NAME, array() );
179
+	$extra_options = get_option('wpshop_extra_options', array());
180
+	DEFINE('WPSHOP_ADDONS_OPTION_NAME', 'wpshop_addons');
181
+	$wpshop_addons_state = get_option(WPSHOP_ADDONS_OPTION_NAME, array());
182 182
 
183 183
 	/*	ALLOWED IPS	*/
184
-	$default_ip = array( '127.0.0.1', '0.0.0.0' );
185
-	DEFINE( 'WPSHOP_DEBUG_MODE_ALLOWED_IP', ( ! empty( $extra_options['WPSHOP_DEBUG_MODE_ALLOWED_IP'] )?serialize( array_merge( $default_ip, array( $extra_options['WPSHOP_DEBUG_MODE_ALLOWED_IP'] ) ) ):serialize( $default_ip )) );
184
+	$default_ip = array('127.0.0.1', '0.0.0.0');
185
+	DEFINE('WPSHOP_DEBUG_MODE_ALLOWED_IP', (!empty($extra_options['WPSHOP_DEBUG_MODE_ALLOWED_IP']) ? serialize(array_merge($default_ip, array($extra_options['WPSHOP_DEBUG_MODE_ALLOWED_IP']))) : serialize($default_ip)));
186 186
 	/*	DEBUG MODE	*/
187 187
 	$debug_mode = false;
188
-	if ( ! empty( $extra_options['WPSHOP_DEBUG_MODE'] ) && ($extra_options['WPSHOP_DEBUG_MODE'] == 'true') ) {
188
+	if (!empty($extra_options['WPSHOP_DEBUG_MODE']) && ($extra_options['WPSHOP_DEBUG_MODE'] == 'true')) {
189 189
 		$debug_mode = true;
190 190
 	}
191
-	DEFINE( 'WPSHOP_DEBUG_MODE', $debug_mode );
191
+	DEFINE('WPSHOP_DEBUG_MODE', $debug_mode);
192 192
 	// End if().
193 193
 	$delete_data = false;
194
-	if ( ! empty( $extra_options['WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION'] ) && ($extra_options['WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION'] == 'true') ) {
194
+	if (!empty($extra_options['WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION']) && ($extra_options['WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION'] == 'true')) {
195 195
 		$delete_data = true;
196 196
 	}
197
-	DEFINE( 'WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION', $delete_data );
197
+	DEFINE('WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION', $delete_data);
198 198
 
199 199
 	// End if().
200 200
 	$tools_menu_display = false;
201
-	if ( ! empty( $extra_options['WPSHOP_DISPLAY_TOOLS_MENU'] ) && ($extra_options['WPSHOP_DISPLAY_TOOLS_MENU'] == 'true') ) {
201
+	if (!empty($extra_options['WPSHOP_DISPLAY_TOOLS_MENU']) && ($extra_options['WPSHOP_DISPLAY_TOOLS_MENU'] == 'true')) {
202 202
 		$tools_menu_display = true;
203 203
 	}
204
-	DEFINE( 'WPSHOP_DISPLAY_TOOLS_MENU', $tools_menu_display );
204
+	DEFINE('WPSHOP_DISPLAY_TOOLS_MENU', $tools_menu_display);
205 205
 
206 206
 	// End if().
207 207
 	$attr_value_per_user = false;
208
-	if ( ! empty( $extra_options['WPSHOP_ATTRIBUTE_VALUE_PER_USER'] ) && ($extra_options['WPSHOP_ATTRIBUTE_VALUE_PER_USER'] == 'true') ) {
208
+	if (!empty($extra_options['WPSHOP_ATTRIBUTE_VALUE_PER_USER']) && ($extra_options['WPSHOP_ATTRIBUTE_VALUE_PER_USER'] == 'true')) {
209 209
 		$attr_value_per_user = true;
210 210
 	}
211
-	DEFINE( 'WPSHOP_ATTRIBUTE_VALUE_PER_USER', $attr_value_per_user );
211
+	DEFINE('WPSHOP_ATTRIBUTE_VALUE_PER_USER', $attr_value_per_user);
212 212
 
213 213
 	// End if().
214 214
 	$display_available_keys_for_template = false;
215
-	if ( ! empty( $extra_options['WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE'] ) && ($extra_options['WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE'] == 'true') ) {
215
+	if (!empty($extra_options['WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE']) && ($extra_options['WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE'] == 'true')) {
216 216
 		 $display_available_keys_for_template = true;
217 217
 	}
218
-	DEFINE( 'WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE', $display_available_keys_for_template );
218
+	DEFINE('WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE', $display_available_keys_for_template);
219 219
 
220 220
 	// End if().
221 221
 	$display_value_attribute_type_select = false;
222
-	if ( ! empty( $extra_options['WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT'] ) && ($extra_options['WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT'] == 'true') ) {
222
+	if (!empty($extra_options['WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT']) && ($extra_options['WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT'] == 'true')) {
223 223
 		$display_value_attribute_type_select = true;
224 224
 	}
225
-	DEFINE( 'WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT', $display_value_attribute_type_select );
225
+	DEFINE('WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT', $display_value_attribute_type_select);
226 226
 	// End if().
227
-	DEFINE( 'WPSHOP_PRODUCT_REFERENCE_PREFIX', 'PDCT' );
228
-	DEFINE( 'WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL', 5 );
229
-	DEFINE( 'WPSHOP_BILLING_REFERENCE_PREFIX', 'FA' );
230
-	DEFINE( 'WPSHOP_CREDIT_SLIP_REFERENCE_PREFIX', 'AV' );
231
-	DEFINE( 'WPSHOP_ORDER_REFERENCE_PREFIX', 'OR' );
232
-	DEFINE( 'WPSHOP_PREORDER_REFERENCE_PREFIX', 'D' );
227
+	DEFINE('WPSHOP_PRODUCT_REFERENCE_PREFIX', 'PDCT');
228
+	DEFINE('WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL', 5);
229
+	DEFINE('WPSHOP_BILLING_REFERENCE_PREFIX', 'FA');
230
+	DEFINE('WPSHOP_CREDIT_SLIP_REFERENCE_PREFIX', 'AV');
231
+	DEFINE('WPSHOP_ORDER_REFERENCE_PREFIX', 'OR');
232
+	DEFINE('WPSHOP_PREORDER_REFERENCE_PREFIX', 'D');
233 233
 	/*  Define the different pages to create for basic usage    */
234 234
 	$default_pages = array();
235
-	$product_options = get_option( 'wpshop_catalog_product_option' );
235
+	$product_options = get_option('wpshop_catalog_product_option');
236 236
 	$default_pages['presentation'][] = array(
237 237
 		'page_code' => 'wpshop_product_page_id',
238
-		'post_title' => __( 'Shop', 'wpshop' ),
239
-		'post_name' => ! empty( $product_options['wpshop_catalog_product_slug'] ) ? $product_options['wpshop_catalog_product_slug'] : 'catalog',
238
+		'post_title' => __('Shop', 'wpshop'),
239
+		'post_name' => !empty($product_options['wpshop_catalog_product_slug']) ? $product_options['wpshop_catalog_product_slug'] : 'catalog',
240 240
 		'post_content' => '[wpshop_products]',
241 241
 		'menu_order' => 569841,
242 242
 	);
243 243
 	$default_pages['presentation'][] = array(
244 244
 		'page_code' => 'wpshop_cart_page_id',
245
-		'post_title' => __( 'Cart', 'wpshop' ),
245
+		'post_title' => __('Cart', 'wpshop'),
246 246
 		'post_name' => 'cart',
247 247
 		'post_content' => '[wpshop_cart]',
248 248
 		'menu_order' => 569842,
249 249
 	);
250 250
 	$default_pages['presentation'][] = array(
251 251
 		'page_code' => 'wpshop_checkout_page_id',
252
-		'post_title' => __( 'Checkout', 'wpshop' ),
252
+		'post_title' => __('Checkout', 'wpshop'),
253 253
 		'post_name' => 'checkout',
254 254
 		'post_content' => '[wpshop_checkout]',
255 255
 		'menu_order' => 569843,
256 256
 	);
257 257
 	$default_pages['presentation'][] = array(
258 258
 		'page_code' => 'wpshop_myaccount_page_id',
259
-		'post_title' => __( 'My account', 'wpshop' ),
259
+		'post_title' => __('My account', 'wpshop'),
260 260
 		'post_name' => 'myaccount',
261 261
 		'post_content' => '[wpshop_myaccount]',
262 262
 		'menu_order' => 569844,
263 263
 	);
264 264
 	$default_pages['presentation'][] = array(
265 265
 		'page_code' => 'wpshop_signup_page_id',
266
-		'post_title' => __( 'Signup', 'wpshop' ),
266
+		'post_title' => __('Signup', 'wpshop'),
267 267
 		'post_name' => 'signup',
268 268
 		'post_content' => '[wpshop_signup]',
269 269
 		'menu_order' => 569845,
270 270
 	);
271 271
 	$default_pages['sale'][] = array(
272 272
 		'page_code' => 'wpshop_payment_return_page_id',
273
-		'post_title' => __( 'Payment return successfull', 'wpshop' ),
273
+		'post_title' => __('Payment return successfull', 'wpshop'),
274 274
 		'post_name' => 'return',
275 275
 		'post_content' => '[wpshop_payment_result]',
276 276
 		'menu_order' => 569846,
277 277
 	);
278 278
 	$default_pages['sale'][] = array(
279 279
 		'page_code' => 'wpshop_payment_return_nok_page_id',
280
-		'post_title' => __( 'Payment return unsuccessfull', 'wpshop' ),
280
+		'post_title' => __('Payment return unsuccessfull', 'wpshop'),
281 281
 		'post_name' => 'unsuccessfull_payment_return',
282 282
 		'post_content' => '[wpshop_payment_result_unsuccessfull]',
283 283
 		'menu_order' => 569848,
284 284
 	);
285 285
 	$default_pages['presentation'][] = array(
286 286
 		'page_code' => 'wpshop_terms_of_sale_page_id',
287
-		'post_title' => __( 'Terms of sale', 'wpshop' ),
287
+		'post_title' => __('Terms of sale', 'wpshop'),
288 288
 		'post_name' => 'terms-of-sale',
289 289
 		'post_content' => '[wpshop_terms_of_sale]',
290 290
 		'menu_order' => 569847,
291 291
 	);
292 292
 
293
-	DEFINE( 'WPSHOP_DEFAULT_PAGES', serialize( $default_pages ) );
293
+	DEFINE('WPSHOP_DEFAULT_PAGES', serialize($default_pages));
294 294
 	/*  Define the different vars used for price calculation    */
295
-	$wpshop_shop_price_piloting = get_option( 'wpshop_shop_price_piloting' );
296
-	DEFINE( 'WPSHOP_PRODUCT_PRICE_PILOT', ( ! empty( $wpshop_shop_price_piloting ) ? $wpshop_shop_price_piloting : 'TTC') );
297
-
298
-	DEFINE( 'WPSHOP_COST_OF_POSTAGE', 'cost_of_postage' );
299
-	DEFINE( 'WPSHOP_PRODUCT_PRICE_HT', 'price_ht' );
300
-	DEFINE( 'WPSHOP_PRODUCT_PRICE_TAX', 'tx_tva' );
301
-	DEFINE( 'WPSHOP_PRODUCT_PRICE_TTC', 'product_price' );
302
-	DEFINE( 'WPSHOP_PRODUCT_PRICE_TAX_AMOUNT', 'tva' );
303
-	DEFINE( 'WPSHOP_PRODUCT_WEIGHT', 'product_weight' );
304
-	DEFINE( 'WPSHOP_PRODUCT_SPECIAL_PRICE', 'special_price' );
305
-	DEFINE( 'WPSHOP_PRODUCT_SPECIAL_PRICE_DATE_FROM', 'special_from' );
306
-	DEFINE( 'WPSHOP_PRODUCT_SPECIAL_PRICE_DATE_TO', 'special_to' );
307
-	DEFINE( 'WPSHOP_PRODUCT_DISCOUNT_AMOUNT', 'discount_amount' );
308
-	DEFINE( 'WPSHOP_VAT_ON_SHIPPING_COST', apply_filters( 'wps_change_shipping_vat', 20 ) );
309
-
310
-	DEFINE( 'WPSHOP_ATTRIBUTE_PRICES', serialize( array( WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TAX, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT ) ) );
311
-	DEFINE( 'WPSHOP_ATTRIBUTE_WEIGHT', serialize( array( WPSHOP_PRODUCT_WEIGHT ) ) );
295
+	$wpshop_shop_price_piloting = get_option('wpshop_shop_price_piloting');
296
+	DEFINE('WPSHOP_PRODUCT_PRICE_PILOT', (!empty($wpshop_shop_price_piloting) ? $wpshop_shop_price_piloting : 'TTC'));
297
+
298
+	DEFINE('WPSHOP_COST_OF_POSTAGE', 'cost_of_postage');
299
+	DEFINE('WPSHOP_PRODUCT_PRICE_HT', 'price_ht');
300
+	DEFINE('WPSHOP_PRODUCT_PRICE_TAX', 'tx_tva');
301
+	DEFINE('WPSHOP_PRODUCT_PRICE_TTC', 'product_price');
302
+	DEFINE('WPSHOP_PRODUCT_PRICE_TAX_AMOUNT', 'tva');
303
+	DEFINE('WPSHOP_PRODUCT_WEIGHT', 'product_weight');
304
+	DEFINE('WPSHOP_PRODUCT_SPECIAL_PRICE', 'special_price');
305
+	DEFINE('WPSHOP_PRODUCT_SPECIAL_PRICE_DATE_FROM', 'special_from');
306
+	DEFINE('WPSHOP_PRODUCT_SPECIAL_PRICE_DATE_TO', 'special_to');
307
+	DEFINE('WPSHOP_PRODUCT_DISCOUNT_AMOUNT', 'discount_amount');
308
+	DEFINE('WPSHOP_VAT_ON_SHIPPING_COST', apply_filters('wps_change_shipping_vat', 20));
309
+
310
+	DEFINE('WPSHOP_ATTRIBUTE_PRICES', serialize(array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TAX, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT)));
311
+	DEFINE('WPSHOP_ATTRIBUTE_WEIGHT', serialize(array(WPSHOP_PRODUCT_WEIGHT)));
312 312
 	/*  Define the different attribute that user won't be able to delete from interface */
313
-	DEFINE( 'WPSHOP_ATTRIBUTE_UNDELETABLE', serialize( array_merge( array(), unserialize( WPSHOP_ATTRIBUTE_PRICES ) ) ) );
313
+	DEFINE('WPSHOP_ATTRIBUTE_UNDELETABLE', serialize(array_merge(array(), unserialize(WPSHOP_ATTRIBUTE_PRICES))));
314 314
 	/*  Define the attribute list to hide or variation creation */
315
-	DEFINE( 'WPSHOP_VARIATION_ATTRIBUTE_TO_HIDE', serialize( array_merge( unserialize( WPSHOP_ATTRIBUTE_PRICES ), array( 'product_attribute_set_id', 'product_reference' ) ) ) );
315
+	DEFINE('WPSHOP_VARIATION_ATTRIBUTE_TO_HIDE', serialize(array_merge(unserialize(WPSHOP_ATTRIBUTE_PRICES), array('product_attribute_set_id', 'product_reference'))));
316 316
 	/*  Define the default currency */
317
-	DEFINE( 'WPSHOP_SHOP_DEFAULT_CURRENCY', 'EUR' );
318
-	DEFINE( 'WPSHOP_SHOP_CURRENCIES', serialize( array(
317
+	DEFINE('WPSHOP_SHOP_DEFAULT_CURRENCY', 'EUR');
318
+	DEFINE('WPSHOP_SHOP_CURRENCIES', serialize(array(
319 319
 		'EUR' => 'euro',
320 320
 		'USD' => 'dollar',
321
-	) ) );
321
+	)));
322 322
 
323 323
 	/*  Define the shipping default rules   */
324
-	DEFINE( 'WPSHOP_SHOP_SHIPPING_RULES', serialize( array(
324
+	DEFINE('WPSHOP_SHOP_SHIPPING_RULES', serialize(array(
325 325
 		'min_max' => array(
326 326
 			'min' => 0,
327 327
 			'max' => 30,
328 328
 		),
329 329
 		'free_from' => 4500,
330
-	) ) );
330
+	)));
331 331
 	$shipping_fees_array = array(
332 332
 		'active' => false,
333 333
 		'fees' => array(
@@ -351,66 +351,66 @@  discard block
 block discarded – undo
351 351
 			),
352 352
 		),
353 353
 	);
354
-	DEFINE( 'WPSHOP_SHOP_CUSTOM_SHIPPING', serialize( $shipping_fees_array ) );
354
+	DEFINE('WPSHOP_SHOP_CUSTOM_SHIPPING', serialize($shipping_fees_array));
355 355
 
356 356
 	/*  Define addons modules */
357
-	DEFINE( 'WPSHOP_ADDONS_KEY_IS', '48' );
358
-	DEFINE( 'WPSHOP_ADDONS_STATES_CLASS', serialize( array(
357
+	DEFINE('WPSHOP_ADDONS_KEY_IS', '48');
358
+	DEFINE('WPSHOP_ADDONS_STATES_CLASS', serialize(array(
359 359
 		true => 'wpshop_addons_state wpshop_addons_state_activated',
360 360
 		false => 'wpshop_addons_state wpshop_addons_state_deactivated',
361
-	) ) );
362
-	DEFINE( 'WPSHOP_ADDONS_LIST', serialize( array(
363
-		'WPSHOP_ADDONS_QUOTATION' => array( __( 'Quotation','wpshop' ), '48', 'per_site', 'quotation_allowed', 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' ),
364
-		'WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC' => array( __( 'Payment gateway CIC','wpshop' ), '32', 'per_site', '' ),/* , 'WPSHOP_ADDONS_PRICE_PER_GROUP' => array(__('Price per user group','wpshop'), '13', 'free') */
365
-	) ) );
366
-	DEFINE( 'WPSHOP_ADDONS_QUOTATION', ( ! empty( $wpshop_addons_state['WPSHOP_ADDONS_QUOTATION']['activate'] )?$wpshop_addons_state['WPSHOP_ADDONS_QUOTATION']['activate']:false) );
367
-	DEFINE( 'WPSHOP_ADDONS_PRICE_PER_GROUP', ( ! empty( $wpshop_addons_state['WPSHOP_ADDONS_PRICE_PER_GROUP']['activate'] )?$wpshop_addons_state['WPSHOP_ADDONS_PRICE_PER_GROUP']['activate']:false) );
368
-	DEFINE( 'WPSHOP_PAYMENT_METHOD_CIC', ( ! empty( $wpshop_addons_state['WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC']['activate'] )?$wpshop_addons_state['WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC']['activate']:false) );
369
-	DEFINE( 'WPSHOP_ADDONS_QUOTATION_CODE', 'nfdJK-AsBCO-%AZDZA' );
370
-	DEFINE( 'WPSHOP_ADDONS_PRICE_PER_GROUP_CODE', '7GnnQ-5FeqZ-BiKz3' );
371
-	DEFINE( 'WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC', 'nZYsM-vQ8qC-VfVfA' );
361
+	)));
362
+	DEFINE('WPSHOP_ADDONS_LIST', serialize(array(
363
+		'WPSHOP_ADDONS_QUOTATION' => array(__('Quotation', 'wpshop'), '48', 'per_site', 'quotation_allowed', 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'),
364
+		'WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC' => array(__('Payment gateway CIC', 'wpshop'), '32', 'per_site', ''), /* , 'WPSHOP_ADDONS_PRICE_PER_GROUP' => array(__('Price per user group','wpshop'), '13', 'free') */
365
+	)));
366
+	DEFINE('WPSHOP_ADDONS_QUOTATION', (!empty($wpshop_addons_state['WPSHOP_ADDONS_QUOTATION']['activate']) ? $wpshop_addons_state['WPSHOP_ADDONS_QUOTATION']['activate'] : false));
367
+	DEFINE('WPSHOP_ADDONS_PRICE_PER_GROUP', (!empty($wpshop_addons_state['WPSHOP_ADDONS_PRICE_PER_GROUP']['activate']) ? $wpshop_addons_state['WPSHOP_ADDONS_PRICE_PER_GROUP']['activate'] : false));
368
+	DEFINE('WPSHOP_PAYMENT_METHOD_CIC', (!empty($wpshop_addons_state['WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC']['activate']) ? $wpshop_addons_state['WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC']['activate'] : false));
369
+	DEFINE('WPSHOP_ADDONS_QUOTATION_CODE', 'nfdJK-AsBCO-%AZDZA');
370
+	DEFINE('WPSHOP_ADDONS_PRICE_PER_GROUP_CODE', '7GnnQ-5FeqZ-BiKz3');
371
+	DEFINE('WPSHOP_ADDONS_PAYMENT_GATEWAY_CB_CIC', 'nZYsM-vQ8qC-VfVfA');
372 372
 
373 373
 	/*  Define payment method params    */
374
-	$wpshop_paymentMethod = get_option( 'wps_payment_mode' );
375
-	if ( WPSHOP_PAYMENT_METHOD_CIC || ! empty( $wpshop_paymentMethod['mode'] ) && ! empty( $wpshop_paymentMethod['mode']['cic'] ) ) {
376
-		$cmcic_params = get_option( 'wpshop_cmcic_params', array() );
377
-		if ( ! empty( $cmcic_params ) ) {
378
-			DEFINE( 'CMCIC_CLE', $cmcic_params['cle'] );
379
-			 DEFINE( 'CMCIC_TPE', $cmcic_params['tpe'] );
380
-			 DEFINE( 'CMCIC_VERSION', $cmcic_params['version'] );
381
-			 DEFINE( 'CMCIC_SERVEUR', $cmcic_params['serveur'] );
382
-			 DEFINE( 'CMCIC_CODESOCIETE', $cmcic_params['codesociete'] );
383
-			 DEFINE( 'CMCIC_URLOK', '' );
384
-			 DEFINE( 'CMCIC_URLKO', '' );
374
+	$wpshop_paymentMethod = get_option('wps_payment_mode');
375
+	if (WPSHOP_PAYMENT_METHOD_CIC || !empty($wpshop_paymentMethod['mode']) && !empty($wpshop_paymentMethod['mode']['cic'])) {
376
+		$cmcic_params = get_option('wpshop_cmcic_params', array());
377
+		if (!empty($cmcic_params)) {
378
+			DEFINE('CMCIC_CLE', $cmcic_params['cle']);
379
+			 DEFINE('CMCIC_TPE', $cmcic_params['tpe']);
380
+			 DEFINE('CMCIC_VERSION', $cmcic_params['version']);
381
+			 DEFINE('CMCIC_SERVEUR', $cmcic_params['serveur']);
382
+			 DEFINE('CMCIC_CODESOCIETE', $cmcic_params['codesociete']);
383
+			 DEFINE('CMCIC_URLOK', '');
384
+			 DEFINE('CMCIC_URLKO', '');
385 385
 		}
386 386
 	}
387 387
 
388 388
 	/** Civility    */
389 389
 	$civility = array(
390
-		1 => __( 'Mr.','wpshop' ),
391
-		__( 'Mrs.','wpshop' ),
392
-		__( 'Miss','wpshop' ),
390
+		1 => __('Mr.', 'wpshop'),
391
+		__('Mrs.', 'wpshop'),
392
+		__('Miss', 'wpshop'),
393 393
 	);
394 394
 	/** Status  */
395 395
 	$order_status = array(
396
-		'' => __( 'Awaiting treatment', 'wpshop' ),
397
-		'awaiting_payment' => __( 'Awaiting payment', 'wpshop' ),
398
-		'partially_paid' => __( 'Partially paid', 'wpshop' ),
399
-		'completed' => __( 'Paid', 'wpshop' ),
400
-		'shipped' => __( 'Shipped', 'wpshop' ),
401
-		'denied' => __( 'Denied', 'wpshop' ),
402
-		'incorrect_amount' => __( 'Incorrect amount', 'wpshop' ),
403
-		'canceled' => __( 'Canceled', 'wpshop' ),
404
-		'payment_refused' => __( 'Refused payment', 'wpshop' ),
405
-		'refunded' => __( 'Refunded', 'wpshop' ),
406
-		'pos' => __( 'Taken in store', 'wpshop' ),
396
+		'' => __('Awaiting treatment', 'wpshop'),
397
+		'awaiting_payment' => __('Awaiting payment', 'wpshop'),
398
+		'partially_paid' => __('Partially paid', 'wpshop'),
399
+		'completed' => __('Paid', 'wpshop'),
400
+		'shipped' => __('Shipped', 'wpshop'),
401
+		'denied' => __('Denied', 'wpshop'),
402
+		'incorrect_amount' => __('Incorrect amount', 'wpshop'),
403
+		'canceled' => __('Canceled', 'wpshop'),
404
+		'payment_refused' => __('Refused payment', 'wpshop'),
405
+		'refunded' => __('Refunded', 'wpshop'),
406
+		'pos' => __('Taken in store', 'wpshop'),
407 407
 	);
408
-	DEFINE( 'WPSHOP_ORDER_STATUS', serialize( $order_status ) );
408
+	DEFINE('WPSHOP_ORDER_STATUS', serialize($order_status));
409 409
 
410 410
 	// End if().
411
-	DEFINE( 'WPSHOP_REGISTER_POST_TYPE_SUPPORT', serialize( array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ) ) );
411
+	DEFINE('WPSHOP_REGISTER_POST_TYPE_SUPPORT', serialize(array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions')));
412 412
 	$register_post_type_args = array(
413
-		'labels' => array( 'name', 'singular_name', 'add_new', 'add_new_item', 'edit', 'edit_item', 'new_item', 'view', 'view_item', 'search_items', 'not_found', 'not_found_in_trash' ),
413
+		'labels' => array('name', 'singular_name', 'add_new', 'add_new_item', 'edit', 'edit_item', 'new_item', 'view', 'view_item', 'search_items', 'not_found', 'not_found_in_trash'),
414 414
 		'description' => 'text',
415 415
 		'public' => 'boolean',
416 416
 		'exclude_from_search' => 'boolean',
@@ -418,64 +418,64 @@  discard block
 block discarded – undo
418 418
 		'show_ui' => 'boolean',
419 419
 		'show_in_nav_menus' => 'boolean',
420 420
 		'show_in_menu' => 'boolean|text',
421
-		'capabilities' => array( 'publish_posts', 'edit_posts', 'edit_others_posts', 'delete_posts', 'delete_others_posts', 'read_private_posts', 'edit_post', 'delete_post', 'read_post' ),
421
+		'capabilities' => array('publish_posts', 'edit_posts', 'edit_others_posts', 'delete_posts', 'delete_others_posts', 'read_private_posts', 'edit_post', 'delete_post', 'read_post'),
422 422
 		'hierarchical' => false,
423 423
 		'rewrite' => false,
424 424
 		'query_var' => true,
425
-		'supports' => unserialize( WPSHOP_REGISTER_POST_TYPE_SUPPORT ),
425
+		'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
426 426
 	);
427
-	DEFINE( 'WPSHOP_REGISTER_POST_TYPE_ARGS', serialize( $register_post_type_args ) );
428
-	DEFINE( 'WPSHOP_REGISTER_POST_TYPE_MANDATORY_SUPPORTS', serialize( array( 'title', 'editor', 'thumbnail', 'excerpt' ) ) );
429
-	DEFINE( 'WPSHOP_PRODUCT_HIDDEN_METABOX', serialize( array( 'formatdiv', 'pageparentdiv', 'postexcerpt', 'trackbacksdiv', 'postcustom', 'commentstatusdiv', 'commentsdiv', 'slugdiv', 'authordiv', 'revisionsdiv' ) ) );
427
+	DEFINE('WPSHOP_REGISTER_POST_TYPE_ARGS', serialize($register_post_type_args));
428
+	DEFINE('WPSHOP_REGISTER_POST_TYPE_MANDATORY_SUPPORTS', serialize(array('title', 'editor', 'thumbnail', 'excerpt')));
429
+	DEFINE('WPSHOP_PRODUCT_HIDDEN_METABOX', serialize(array('formatdiv', 'pageparentdiv', 'postexcerpt', 'trackbacksdiv', 'postcustom', 'commentstatusdiv', 'commentsdiv', 'slugdiv', 'authordiv', 'revisionsdiv')));
430 430
 
431 431
 	/* Shop type    */
432
-	DEFINE( 'WPSHOP_SHOP_TYPES', serialize( array( 'presentation', 'sale' ) ) );
432
+	DEFINE('WPSHOP_SHOP_TYPES', serialize(array('presentation', 'sale')));
433 433
 
434 434
 	/* Attribute select_data_type   */
435
-	DEFINE( 'WPSHOP_ATTR_SELECT_TYPE', serialize( array(
435
+	DEFINE('WPSHOP_ATTR_SELECT_TYPE', serialize(array(
436 436
 		'custom' => 'custom_data',
437 437
 		'internal' => 'internal_data',
438
-	) ) );
439
-	DEFINE( 'WPSHOP_ATTR_SELECT_TYPE_TOGGLED', serialize( array(
438
+	)));
439
+	DEFINE('WPSHOP_ATTR_SELECT_TYPE_TOGGLED', serialize(array(
440 440
 		'custom' => 'internal_data',
441 441
 		'internal' => 'custom_data',
442
-	) ) );
442
+	)));
443 443
 
444 444
 	/*  Define the types existing into the current WordPress installation   */
445
-	$default_to_exclude = array( 'attachment', 'revision', 'nav_menu_item', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE );
446
-	DEFINE( 'WPSHOP_INTERNAL_TYPES_TO_EXCLUDE', ( ! empty( $extra_options['WPSHOP_INTERNAL_TYPES_TO_EXCLUDE'] )?serialize( array_merge( array( $extra_options['WPSHOP_INTERNAL_TYPES_TO_EXCLUDE'] ),$default_to_exclude ) ):serialize( $default_to_exclude )) );
445
+	$default_to_exclude = array('attachment', 'revision', 'nav_menu_item', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE);
446
+	DEFINE('WPSHOP_INTERNAL_TYPES_TO_EXCLUDE', (!empty($extra_options['WPSHOP_INTERNAL_TYPES_TO_EXCLUDE']) ? serialize(array_merge(array($extra_options['WPSHOP_INTERNAL_TYPES_TO_EXCLUDE']), $default_to_exclude)) : serialize($default_to_exclude)));
447 447
 
448 448
 	/*
449 449
      Start form field display config */
450 450
 	/*  Get the list of possible posts status   */
451
-	$posts_status = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' );
451
+	$posts_status = array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash');
452 452
 
453 453
 	/*  General configuration   */
454
-	$comboxOptionToHide = array( 'deleted' );
454
+	$comboxOptionToHide = array('deleted');
455 455
 
456 456
 	/*  Attributes form */
457
-	$attribute_displayed_field = array( 'id', 'status', 'entity_id', 'is_required', 'is_unique', 'is_visible_in_front', 'is_visible_in_front_listing', 'frontend_input', 'backend_input', 'frontend_label', 'default_value', 'is_requiring_unit', '_unit_group_id', '_default_unit', 'is_historisable', 'is_intrinsic', 'is_filterable', 'code', 'is_used_for_sort_by', 'is_visible_in_advanced_search', 'is_used_in_admin_listing_column', 'is_used_in_quick_add_form', 'frontend_verification', 'is_user_defined', 'is_used_in_variation', 'is_used_for_variation', '_need_verification', '_display_informations_about_value', 'frontend_css_class', 'backend_css_class', 'frontend_help_message', 'is_searchable' );
457
+	$attribute_displayed_field = array('id', 'status', 'entity_id', 'is_required', 'is_unique', 'is_visible_in_front', 'is_visible_in_front_listing', 'frontend_input', 'backend_input', 'frontend_label', 'default_value', 'is_requiring_unit', '_unit_group_id', '_default_unit', 'is_historisable', 'is_intrinsic', 'is_filterable', 'code', 'is_used_for_sort_by', 'is_visible_in_advanced_search', 'is_used_in_admin_listing_column', 'is_used_in_quick_add_form', 'frontend_verification', 'is_user_defined', 'is_used_in_variation', 'is_used_for_variation', '_need_verification', '_display_informations_about_value', 'frontend_css_class', 'backend_css_class', 'frontend_help_message', 'is_searchable');
458 458
 	$attribute_options_group = array(
459
-		__( 'Attribute unit', 'wpshop' ) => array( 'is_requiring_unit', '_unit_group_id', '_default_unit' ),
460
-		__( 'Frontend option', 'wpshop' ) => array( 'is_visible_in_front', 'is_visible_in_front_listing', 'is_used_for_sort_by', 'is_visible_in_advanced_search', 'is_searchable', '_display_informations_about_value' ),
461
-		__( 'Variations', 'wpshop' ) => array( 'is_user_defined', 'is_used_in_variation', 'is_used_for_variation', 'frontend_input' ),
459
+		__('Attribute unit', 'wpshop') => array('is_requiring_unit', '_unit_group_id', '_default_unit'),
460
+		__('Frontend option', 'wpshop') => array('is_visible_in_front', 'is_visible_in_front_listing', 'is_used_for_sort_by', 'is_visible_in_advanced_search', 'is_searchable', '_display_informations_about_value'),
461
+		__('Variations', 'wpshop') => array('is_user_defined', 'is_used_in_variation', 'is_used_for_variation', 'frontend_input'),
462 462
 	);
463
-	DEFINE( 'WPSHOP_ATTRIBUTE_DEF_COLUMN_INTO_OPTIONS', serialize( array( '_need_verification', 'frontend_verification', 'frontend_css_class', 'backend_css_class', 'frontend_help_message', 'frontend_help_message' ) ) );
463
+	DEFINE('WPSHOP_ATTRIBUTE_DEF_COLUMN_INTO_OPTIONS', serialize(array('_need_verification', 'frontend_verification', 'frontend_css_class', 'backend_css_class', 'frontend_help_message', 'frontend_help_message')));
464 464
 
465 465
 	/*  General form    */
466
-	$attribute_hidden_field = array( 'position' );
466
+	$attribute_hidden_field = array('position');
467 467
 
468 468
 	/*  Definition des differents champs pour les formulaires   */
469 469
 	$customer_adress_information_field = array(
470
-		'civility' => __( 'Civility', 'wpshop' ),
471
-		'first_name' => __( 'First name', 'wpshop' ),
472
-		'last_name' => __( 'Last name', 'wpshop' ),
473
-		'email' => __( 'Email adress', 'wpshop' ),
474
-		'phone' => __( 'Phone number', 'wpshop' ),
475
-		'company' => __( 'Company', 'wpshop' ),
476
-		'address' => __( 'Adresse', 'wpshop' ),
477
-		'postcode' => __( 'Postcode', 'wpshop' ),
478
-		'city' => __( 'City', 'wpshop' ),
479
-		'country' => __( 'Country', 'wpshop' ),
470
+		'civility' => __('Civility', 'wpshop'),
471
+		'first_name' => __('First name', 'wpshop'),
472
+		'last_name' => __('Last name', 'wpshop'),
473
+		'email' => __('Email adress', 'wpshop'),
474
+		'phone' => __('Phone number', 'wpshop'),
475
+		'company' => __('Company', 'wpshop'),
476
+		'address' => __('Adresse', 'wpshop'),
477
+		'postcode' => __('Postcode', 'wpshop'),
478
+		'city' => __('City', 'wpshop'),
479
+		'country' => __('Country', 'wpshop'),
480 480
 	);
481 481
 	/*  End form field display config       */
Please login to merge, or discard this patch.
includes/librairies/eav/attributes.class.php 1 patch
Spacing   +559 added lines, -559 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 /**
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @package wpshop
21 21
  * @subpackage librairies
22 22
  */
23
-class wpshop_attributes{
23
+class wpshop_attributes {
24 24
 	/*	Define the database table used in the current class	*/
25 25
 	const dbTable = WPSHOP_DBT_ATTRIBUTE;
26 26
 	/*	Define the url listing slug used in the current class	*/
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 *	@return string The table of the class
52 52
 	 */
53
-	function setMessage($message){
53
+	function setMessage($message) {
54 54
 		$this->pageMessage = $message;
55 55
 	}
56 56
 	/**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 *	@return string The table of the class
60 60
 	 */
61
-	function getListingSlug(){
61
+	function getListingSlug() {
62 62
 		return self::urlSlugListing;
63 63
 	}
64 64
 	/**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 *	@return string The table of the class
68 68
 	 */
69
-	function getEditionSlug(){
69
+	function getEditionSlug() {
70 70
 		return self::urlSlugEdition;
71 71
 	}
72 72
 	/**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 *	@return string The table of the class
76 76
 	 */
77
-	public static function getDbTable(){
77
+	public static function getDbTable() {
78 78
 		return self::dbTable;
79 79
 	}
80 80
 	/**
@@ -82,21 +82,21 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 *	@return string $title The title of the page looking at the environnement
84 84
 	 */
85
-	function pageTitle(){
85
+	function pageTitle() {
86 86
 		$action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
87 87
 		$objectInEdition = isset($_REQUEST['id']) ? sanitize_key($_REQUEST['id']) : '';
88
-		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
88
+		$page = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
89 89
 
90
-		$title = __(self::pageTitle, 'wpshop' );
91
-		if($action != ''){
92
-			if(($action == 'edit') || ($action == 'delete')){
90
+		$title = __(self::pageTitle, 'wpshop');
91
+		if ($action != '') {
92
+			if (($action == 'edit') || ($action == 'delete')) {
93 93
 				$editedItem = self::getElement($objectInEdition);
94 94
 				$title = sprintf(__(self::pageEditingTitle, 'wpshop'), str_replace("\\", "", $editedItem->frontend_label));
95 95
 			}
96
-			elseif($action == 'add')
96
+			elseif ($action == 'add')
97 97
 				$title = __(self::pageAddingTitle, 'wpshop');
98 98
 		}
99
-		elseif((self::getEditionSlug() != self::getListingSlug()) && ($page == self::getEditionSlug()))
99
+		elseif ((self::getEditionSlug() != self::getListingSlug()) && ($page == self::getEditionSlug()))
100 100
 			$title = __(self::pageAddingTitle, 'wpshop');
101 101
 
102 102
 		return $title;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	/**
106 106
 	 *	Define the different message and action after an action is send through the element interface
107 107
 	 */
108
-	function elementAction(){
108
+	function elementAction() {
109 109
 		global $wpdb, $initialEavData;
110 110
 
111 111
 		$pageMessage = $actionResult = '';
@@ -118,75 +118,75 @@  discard block
 block discarded – undo
118 118
 		$saveditem = isset($_REQUEST['saveditem']) ? sanitize_text_field($_REQUEST['saveditem']) : '';
119 119
 		$set_section = !empty($_REQUEST[self::getDbTable()]['set_section']) ? sanitize_text_field($_REQUEST[self::getDbTable()]['set_section']) : '';
120 120
 		//@TODO $_REQUEST
121
-		$id = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
122
-		if(!empty($action) && ($action=='activate') ){
123
-			if( isset($id) ) {
121
+		$id = !empty($_REQUEST['id']) ? (int)$_REQUEST['id'] : null;
122
+		if (!empty($action) && ($action == 'activate')) {
123
+			if (isset($id)) {
124 124
 				$query = $wpdb->update(self::getDbTable(), array('status'=>'moderated'), array('id'=>$id));
125 125
 				wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id));
126 126
 			}
127 127
 		}
128
-		if(($action != '') && ($action == 'saveok') && ($saveditem > 0)){
128
+		if (($action != '') && ($action == 'saveok') && ($saveditem > 0)) {
129 129
 			$editedElement = self::getElement($saveditem);
130 130
 			$pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>');
131 131
 		}
132
-		elseif(($action != '') && ($action == 'deleteok') && ($saveditem > 0)){
132
+		elseif (($action != '') && ($action == 'deleteok') && ($saveditem > 0)) {
133 133
 			$editedElement = self::getElement($saveditem, "'deleted'");
134 134
 			$pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>');
135 135
 		}
136 136
 
137
-		$attribute_parameter = !empty( $_REQUEST[self::getDbTable()] ) ? (array)$_REQUEST[self::getDbTable()] : array();
138
-		 if ( !empty($set_section) ) unset($attribute_parameter['set_section']);
137
+		$attribute_parameter = !empty($_REQUEST[self::getDbTable()]) ? (array)$_REQUEST[self::getDbTable()] : array();
138
+		 if (!empty($set_section)) unset($attribute_parameter['set_section']);
139 139
 
140 140
 		$wpshop_attribute_combo_values_list_order_def = !empty($attribute_parameter['wpshop_attribute_combo_values_list_order_def']) ? $attribute_parameter['wpshop_attribute_combo_values_list_order_def'] : array();
141 141
 		// @TODO $_REQUEST
142 142
 		// unset($_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def']);
143 143
 
144
-		if(!isset($attribute_parameter['status'])){
144
+		if (!isset($attribute_parameter['status'])) {
145 145
 			$attribute_parameter['status'] = 'moderated';
146 146
 		}
147
-		if(!isset($attribute_parameter['is_historisable'])){
147
+		if (!isset($attribute_parameter['is_historisable'])) {
148 148
 			$attribute_parameter['is_historisable'] = 'no';
149 149
 		}
150
-		if(!isset($attribute_parameter['is_required'])){
150
+		if (!isset($attribute_parameter['is_required'])) {
151 151
 			$attribute_parameter['is_required'] = 'no';
152 152
 		}
153
-		if(!isset($attribute_parameter['is_used_in_admin_listing_column'])){
153
+		if (!isset($attribute_parameter['is_used_in_admin_listing_column'])) {
154 154
 			$attribute_parameter['is_used_in_admin_listing_column'] = 'no';
155 155
 		}
156
-		if(!isset($attribute_parameter['is_used_in_quick_add_form'])){
156
+		if (!isset($attribute_parameter['is_used_in_quick_add_form'])) {
157 157
 			$attribute_parameter['is_used_in_quick_add_form'] = 'no';
158 158
 		}
159
-		if(!isset($attribute_parameter['is_intrinsic'])){
159
+		if (!isset($attribute_parameter['is_intrinsic'])) {
160 160
 			$attribute_parameter['is_intrinsic'] = 'no';
161 161
 		}
162
-		if(!isset($attribute_parameter['is_requiring_unit'])){
162
+		if (!isset($attribute_parameter['is_requiring_unit'])) {
163 163
 			$attribute_parameter['is_requiring_unit'] = 'no';
164 164
 		}
165
-		if(!isset($attribute_parameter['is_visible_in_front'])){
165
+		if (!isset($attribute_parameter['is_visible_in_front'])) {
166 166
 			$attribute_parameter['is_visible_in_front'] = 'no';
167 167
 		}
168
-		if(!isset($attribute_parameter['is_visible_in_front_listing'])){
168
+		if (!isset($attribute_parameter['is_visible_in_front_listing'])) {
169 169
 			$attribute_parameter['is_visible_in_front_listing'] = 'no';
170 170
 		}
171
-		if(!isset($attribute_parameter['is_used_for_sort_by'])){
171
+		if (!isset($attribute_parameter['is_used_for_sort_by'])) {
172 172
 			$attribute_parameter['is_used_for_sort_by'] = 'no';
173 173
 		}
174
-		if(!isset($attribute_parameter['is_visible_in_advanced_search'])){
174
+		if (!isset($attribute_parameter['is_visible_in_advanced_search'])) {
175 175
 			$attribute_parameter['is_visible_in_advanced_search'] = 'no';
176 176
 		}
177
-		if(!isset($attribute_parameter['is_searchable'])){
177
+		if (!isset($attribute_parameter['is_searchable'])) {
178 178
 			$attribute_parameter['is_searchable'] = 'no';
179 179
 		}
180
-		if(!isset($attribute_parameter['is_used_for_variation'])){
180
+		if (!isset($attribute_parameter['is_used_for_variation'])) {
181 181
 			$attribute_parameter['is_used_for_variation'] = 'no';
182 182
 		}
183
-		if(!isset($attribute_parameter['is_used_in_variation'])){
183
+		if (!isset($attribute_parameter['is_used_in_variation'])) {
184 184
 			$attribute_parameter['is_used_in_variation'] = 'no';
185 185
 		}
186
-		if(!isset($attribute_parameter['is_user_defined'])){
186
+		if (!isset($attribute_parameter['is_user_defined'])) {
187 187
 			$attribute_parameter['is_user_defined'] = 'no';
188 188
 		}
189
-		if(!isset($attribute_parameter['_display_informations_about_value'])){
189
+		if (!isset($attribute_parameter['_display_informations_about_value'])) {
190 190
 			$attribute_parameter['_display_informations_about_value'] = 'no';
191 191
 		}
192 192
 
@@ -195,58 +195,58 @@  discard block
 block discarded – undo
195 195
 			switch ($attribute_parameter['frontend_input']) {
196 196
 				case 'short_text':
197 197
 						$attribute_parameter['frontend_input'] = 'text';
198
-						if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text';
198
+						if (empty($attribute_parameter['backend_input'])) $attribute_parameter['backend_input'] = 'text';
199 199
 						$attribute_parameter['data_type'] = 'varchar';
200 200
 					break;
201 201
 				case 'date_field':
202 202
 						$attribute_parameter['frontend_input'] = 'text';
203
-						if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text';
203
+						if (empty($attribute_parameter['backend_input'])) $attribute_parameter['backend_input'] = 'text';
204 204
 						$attribute_parameter['data_type'] = 'datetime';
205 205
 					break;
206 206
 				case 'float_field':
207 207
 						$attribute_parameter['frontend_input'] = 'text';
208
-						if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text';
208
+						if (empty($attribute_parameter['backend_input'])) $attribute_parameter['backend_input'] = 'text';
209 209
 						$attribute_parameter['data_type'] = 'decimal';
210 210
 					break;
211 211
 				case 'hidden_field':
212 212
 						$attribute_parameter['frontend_input'] = 'hidden';
213
-						if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text';
213
+						if (empty($attribute_parameter['backend_input'])) $attribute_parameter['backend_input'] = 'text';
214 214
 						$attribute_parameter['data_type'] = 'varchar';
215 215
 					break;
216 216
 				case 'pass_field':
217 217
 						$attribute_parameter['frontend_input'] = 'password';
218
-						if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text';
218
+						if (empty($attribute_parameter['backend_input'])) $attribute_parameter['backend_input'] = 'text';
219 219
 						$attribute_parameter['data_type'] = 'varchar';
220 220
 					break;
221 221
 
222 222
 				case 'select':
223 223
 						$attribute_parameter['frontend_input'] = 'select';
224
-						if ( empty($attribute_parameter['backend_input']) || empty($id) )
224
+						if (empty($attribute_parameter['backend_input']) || empty($id))
225 225
 							$attribute_parameter['backend_input'] = 'multiple-select';
226 226
 						$attribute_parameter['data_type'] = 'integer';
227 227
 					break;
228 228
 				case 'multiple-select':
229 229
 						$attribute_parameter['frontend_input'] = 'multiple-select';
230
-						if ( empty($attribute_parameter['backend_input']) || empty($id) )
230
+						if (empty($attribute_parameter['backend_input']) || empty($id))
231 231
 							$attribute_parameter['backend_input'] = 'multiple-select';
232 232
 						$attribute_parameter['data_type'] = 'integer';
233 233
 					break;
234 234
 				case 'radio':
235 235
 						$attribute_parameter['frontend_input'] = 'radio';
236
-						if ( empty($attribute_parameter['backend_input']) || empty($id) )
236
+						if (empty($attribute_parameter['backend_input']) || empty($id))
237 237
 							$attribute_parameter['backend_input'] = 'multiple-select';
238 238
 						$attribute_parameter['data_type'] = 'integer';
239 239
 					break;
240 240
 				case 'checkbox':
241 241
 						$attribute_parameter['frontend_input'] = 'checkbox';
242
-						if ( empty($attribute_parameter['backend_input']) || empty($id) )
242
+						if (empty($attribute_parameter['backend_input']) || empty($id))
243 243
 							$attribute_parameter['backend_input'] = 'multiple-select';
244 244
 						$attribute_parameter['data_type'] = 'integer';
245 245
 					break;
246 246
 
247 247
 				case 'textarea':
248 248
 						$attribute_parameter['frontend_input'] = 'textarea';
249
-						if ( empty($attribute_parameter['backend_input']) || empty($id) )
249
+						if (empty($attribute_parameter['backend_input']) || empty($id))
250 250
 							$attribute_parameter['backend_input'] = 'textarea';
251 251
 						$attribute_parameter['data_type'] = 'text';
252 252
 					break;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		}
255 255
 		else {
256 256
 			$attribute_parameter['frontend_input'] = 'text';
257
-			if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text';
257
+			if (empty($attribute_parameter['backend_input'])) $attribute_parameter['backend_input'] = 'text';
258 258
 			$attribute_parameter['data_type'] = 'varchar';
259 259
 		}
260 260
 
@@ -263,55 +263,55 @@  discard block
 block discarded – undo
263 263
 			// $attribute_parameter['use_ajax_for_filling_field']='no';
264 264
 		// }
265 265
 		$attribute_parameter['use_ajax_for_filling_field'] = 'yes';
266
-		if( $attribute_parameter['backend_input'] == 'multiple-select' ) {
266
+		if ($attribute_parameter['backend_input'] == 'multiple-select') {
267 267
 			$attribute_parameter['is_used_for_variation'] = 'yes';
268 268
 		}
269 269
 
270 270
 		/*	Define the database operation type from action launched by the user	 */
271 271
 		$attribute_parameter['default_value'] = (!empty($attribute_parameter['default_value']) && is_array($attribute_parameter['default_value'])) ? serialize($attribute_parameter['default_value']) : (isset($attribute_parameter['default_value']) ? str_replace('"', "'", $attribute_parameter['default_value']) : '');
272
-		if ( $attribute_parameter['data_type'] == 'datetime' ) {
272
+		if ($attribute_parameter['data_type'] == 'datetime') {
273 273
 			$date_default_value_trasform_into_config = array('default_value' => $attribute_parameter['default_value'], 'field_options' => (!empty($_POST[self::getDbTable() . '_options']) ? sanitize_text_field($_POST[self::getDbTable() . '_options']) : null));
274
-			$attribute_parameter['default_value'] = serialize( $date_default_value_trasform_into_config );
274
+			$attribute_parameter['default_value'] = serialize($date_default_value_trasform_into_config);
275 275
 		}
276 276
 		/*****************************		GENERIC				**************************/
277 277
 		/*************************************************************************/
278
-		$pageAction = (!empty($attribute_parameter['frontend_label']) && isset($_REQUEST[self::getDbTable() . '_action'])) ? sanitize_text_field($_REQUEST[self::getDbTable() . '_action']) : ((!empty($_GET['action']) && ($_GET['action']=='delete')) ? sanitize_text_field($_GET['action']) : '');
278
+		$pageAction = (!empty($attribute_parameter['frontend_label']) && isset($_REQUEST[self::getDbTable() . '_action'])) ? sanitize_text_field($_REQUEST[self::getDbTable() . '_action']) : ((!empty($_GET['action']) && ($_GET['action'] == 'delete')) ? sanitize_text_field($_GET['action']) : '');
279 279
 		$id = isset($attribute_parameter['id']) ? sanitize_key($attribute_parameter['id']) : ((!empty($_GET['id'])) ? $_GET['id'] : '');
280
-		if(($pageAction != '') && (($pageAction == 'edit') || ($pageAction == 'editandcontinue'))){
281
-			if(current_user_can('wpshop_edit_attributes')){
280
+		if (($pageAction != '') && (($pageAction == 'edit') || ($pageAction == 'editandcontinue'))) {
281
+			if (current_user_can('wpshop_edit_attributes')) {
282 282
 				$attribute_parameter['last_update_date'] = date('Y-m-d H:i:s');
283
-				if($pageAction == 'delete'){
283
+				if ($pageAction == 'delete') {
284 284
 					$attribute_code = $attribute_parameter['code'];
285
-					if(!isset($attribute_parameter['code']) || ($attribute_parameter['code'] == '')){
285
+					if (!isset($attribute_parameter['code']) || ($attribute_parameter['code'] == '')) {
286 286
 						$attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id');
287 287
 						$attribute_code = $attribute->code;
288 288
 					}
289
-					if(!in_array($attribute_code, $attribute_undeletable)){
290
-						if(current_user_can('wpshop_delete_attributes')){
289
+					if (!in_array($attribute_code, $attribute_undeletable)) {
290
+						if (current_user_can('wpshop_delete_attributes')) {
291 291
 							$attribute_parameter['status'] = 'deleted';
292 292
 						}
293
-						else{
293
+						else {
294 294
 							$actionResult = 'userNotAllowedForActionDelete';
295 295
 						}
296 296
 					}
297
-					else{
297
+					else {
298 298
 						$actionResult = 'unDeletableAtribute';
299 299
 					}
300 300
 				}
301 301
 				$actionResult = wpshop_database::update($attribute_parameter, $id, self::getDbTable());
302 302
 			}
303
-			else{
303
+			else {
304 304
 				$actionResult = 'userNotAllowedForActionEdit';
305 305
 			}
306 306
 		}
307
-		elseif(($pageAction != '') && (($pageAction == 'delete'))){
307
+		elseif (($pageAction != '') && (($pageAction == 'delete'))) {
308 308
 			$attribute_code = '';
309
-			if (empty(	$attribute_parameter['code'])) {
309
+			if (empty($attribute_parameter['code'])) {
310 310
 				$attribute = self::getElement($id, "'valid', 'moderated', 'notused', 'deleted'", 'id');
311 311
 				$attribute_code = $attribute->code;
312 312
 			}
313 313
 			if (!in_array($attribute_code, $attribute_undeletable)) {
314
-				if(current_user_can('wpshop_delete_attributes')){
314
+				if (current_user_can('wpshop_delete_attributes')) {
315 315
 					$attribute_parameter['last_update_date'] = current_time('mysql', 0);
316 316
 					$attribute_parameter['status'] = 'deleted';
317 317
 					$actionResult = wpshop_database::update($attribute_parameter, $id, self::getDbTable());
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 			else
323 323
 				$actionResult = 'unDeletableAtribute';
324 324
 		}
325
-		elseif(($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))){
326
-			if(current_user_can('wpshop_add_attributes')){
325
+		elseif (($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))) {
326
+			if (current_user_can('wpshop_add_attributes')) {
327 327
 				$attribute_parameter['creation_date'] = current_time('mysql', 0);
328
-				if(trim($attribute_parameter['code']) == ''){
328
+				if (trim($attribute_parameter['code']) == '') {
329 329
 					$attribute_parameter['code'] = $attribute_parameter['frontend_label'];
330 330
 				}
331 331
 				$attribute_parameter['code'] = wpshop_tools::slugify(str_replace("\'", "_", str_replace('\"', "_", $attribute_parameter['code'])), array('noAccent', 'noSpaces', 'lowerCase', 'noPunctuation'));
332 332
 				$code_exists = self::getElement($attribute_parameter['code'], "'valid', 'moderated', 'deleted'", 'code');
333
-				if((is_object($code_exists) || is_array($code_exists)) && (count($code_exists) > 0)){
333
+				if ((is_object($code_exists) || is_array($code_exists)) && (count($code_exists) > 0)) {
334 334
 					$attribute_parameter['code'] = $attribute_parameter['code'] . '_' . (count($code_exists) + rand());
335 335
 				}
336 336
 				$actionResult = wpshop_database::save($attribute_parameter, self::getDbTable());
337 337
 				$id = $wpdb->insert_id;
338 338
 			}
339
-			else{
339
+			else {
340 340
 				$actionResult = 'userNotAllowedForActionAdd';
341 341
 			}
342 342
 		}
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 		/************		CHANGE THE FIELD NAME TO TAKE TO DISPLAY				*************/
346 346
 		/************		CHANGE ERROR MESSAGE FOR SPECIFIC CASE					*************/
347 347
 		/****************************************************************************/
348
-		if($actionResult != ''){
348
+		if ($actionResult != '') {
349 349
 			$elementIdentifierForMessage = __('the attribute', 'wpshop');
350
-			if(!empty($attribute_parameter['name']))$elementIdentifierForMessage = '<span class="bold" >' . $attribute_parameter['frontend_label'] . '</span>';
350
+			if (!empty($attribute_parameter['name']))$elementIdentifierForMessage = '<span class="bold" >' . $attribute_parameter['frontend_label'] . '</span>';
351 351
 			if ($actionResult == 'error') {/*	CHANGE HERE FOR SPECIFIC CASE	*/
352 352
 				$pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage, ' -> ' . $wpdb->last_error);
353 353
 			}
@@ -359,11 +359,11 @@  discard block
 block discarded – undo
359 359
 				$done_options_value = array();
360 360
 				$default_value = $attribute_parameter['default_value'];
361 361
 				$i = 1;
362
-				$options = !empty($_REQUEST['options']) ? (array) $_REQUEST['options'] : array();
363
-				$optionsValue = !empty($_REQUEST['optionsValue']) ? (array) $_REQUEST['optionsValue'] : array();
364
-				$optionsUpdate = !empty($_REQUEST['optionsUpdate']) ? (array) $_REQUEST['optionsUpdate'] : array();
365
-				$optionsUpdateValue = !empty($_REQUEST['optionsUpdateValue']) ? (array) $_REQUEST['optionsUpdateValue'] : array();
366
-				if ( !empty($optionsUpdate) ) {
362
+				$options = !empty($_REQUEST['options']) ? (array)$_REQUEST['options'] : array();
363
+				$optionsValue = !empty($_REQUEST['optionsValue']) ? (array)$_REQUEST['optionsValue'] : array();
364
+				$optionsUpdate = !empty($_REQUEST['optionsUpdate']) ? (array)$_REQUEST['optionsUpdate'] : array();
365
+				$optionsUpdateValue = !empty($_REQUEST['optionsUpdateValue']) ? (array)$_REQUEST['optionsUpdateValue'] : array();
366
+				if (!empty($optionsUpdate)) {
367 367
 					/**
368 368
 					 *	Check if there is an attribute code into sended request or if we have to get the code from database (Bug fix)
369 369
 					 */
@@ -377,25 +377,25 @@  discard block
 block discarded – undo
377 377
 					foreach ($optionsUpdate as $option_key => $option_label) {
378 378
 						$option_value = !empty($optionsUpdateValue[$option_key]) ? str_replace(",", ".", $optionsUpdateValue[$option_key]) : '';
379 379
 
380
-						if ( empty($option_value) || !in_array($option_value, $done_options_value) ) {
380
+						if (empty($option_value) || !in_array($option_value, $done_options_value)) {
381 381
 							/*	Update an existing value only if the value does not exist into existing list	*/
382 382
 							$label = (($option_label != '') ? $option_label : str_replace(",", ".", $option_value));
383 383
 							$value = str_replace(",", ".", $option_value);
384
-							if( !WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT ) {
384
+							if (!WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT) {
385 385
 								$label = $option_label;
386
-								$value =  str_replace(",", ".", $label);
386
+								$value = str_replace(",", ".", $label);
387 387
 							}
388 388
 
389 389
 							$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('last_update_date' => current_time('mysql', 0), 'position' => $i, 'label' => stripslashes($label), 'value' => stripslashes($value)), array('id' => $option_key));
390 390
 							$done_options_value[] = str_replace(",", ".", $option_value);
391 391
 
392 392
 							/*	Check if this value is used for price calculation and make update on the different product using this value	*/
393
-							if($attribute_code == WPSHOP_PRODUCT_PRICE_TAX){
393
+							if ($attribute_code == WPSHOP_PRODUCT_PRICE_TAX) {
394 394
 								$action = wpshop_prices::mass_update_prices();
395 395
 							}
396 396
 						}
397 397
 
398
-						if($default_value == $option_key) {
398
+						if ($default_value == $option_key) {
399 399
 							/*	Update an existing a only if the value does not exist into existing list	*/
400 400
 							$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $option_key), array('id' => $id));
401 401
 							$done_options_value[] = str_replace(",", ".", $option_value);
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
 						$i++;
404 404
 					}
405 405
 				}
406
-				if ( !empty($options) ) {
407
-					foreach ( $options as $option_key => $option_label ) {
406
+				if (!empty($options)) {
407
+					foreach ($options as $option_key => $option_label) {
408 408
 						$option_value = !empty($optionsValue[$option_key]) ? str_replace(",", ".", $optionsValue[$option_key]) : sanitize_title($option_label);
409 409
 
410 410
 						/*	Check what value to use for the new values	*/
411 411
 						$label = (!empty($option_label) ? $option_label : str_replace(",", ".", $option_value));
412
-						if( !WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT && empty($option_value) ) {
412
+						if (!WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT && empty($option_value)) {
413 413
 							$label = $option_label;
414 414
 							$option_value = sanitize_title($label);
415 415
 						}
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 						// If the optionsUpdateValue is empty, set it a empty array to avoid error calling the in_array() function
418 418
 						// $_REQUEST['optionsUpdateValue'] = !empty($_REQUEST['optionsUpdateValue']) ? $_REQUEST['optionsUpdateValue'] : array();
419 419
 
420
-						if (!in_array($option_value, $done_options_value) && !in_array($option_value, $optionsUpdateValue) ) {
420
+						if (!in_array($option_value, $done_options_value) && !in_array($option_value, $optionsUpdateValue)) {
421 421
 
422 422
 							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('creation_date' => current_time('mysql', 0), 'status' => 'valid', 'attribute_id' => $id, 'position' => $i, 'label' => stripslashes($label), 'value' => stripslashes($option_value)));
423 423
 							$done_options_value[] = str_replace(",", ".", $option_value);
@@ -435,19 +435,19 @@  discard block
 block discarded – undo
435 435
 				}
436 436
 
437 437
 				// If the is_used_for_sort_by is mark as yes, we have to get out some attributes and save it separately
438
-				if( (!empty($attribute_parameter['is_used_for_sort_by']) && ($attribute_parameter['is_used_for_sort_by'] == 'yes')) || (!empty($attribute_parameter['is_filterable']) && ($attribute_parameter['is_filterable'] == 'yes')) || (!empty($attribute_parameter['is_searchable']) && ($attribute_parameter['is_searchable'] == 'yes')) ){
438
+				if ((!empty($attribute_parameter['is_used_for_sort_by']) && ($attribute_parameter['is_used_for_sort_by'] == 'yes')) || (!empty($attribute_parameter['is_filterable']) && ($attribute_parameter['is_filterable'] == 'yes')) || (!empty($attribute_parameter['is_searchable']) && ($attribute_parameter['is_searchable'] == 'yes'))) {
439 439
 					$attribute_code = $attribute_parameter['code'];
440
-					if(!isset($attribute_parameter['code']) || ($attribute_parameter['code'] == '')){
440
+					if (!isset($attribute_parameter['code']) || ($attribute_parameter['code'] == '')) {
441 441
 						$attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id');
442 442
 						$attribute_code = $attribute->code;
443 443
 					}
444 444
 
445 445
 					$count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
446
-					for( $i = 0; $i <= $count_products->publish; $i+= 20 ) {
447
-						$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' );
448
-						$products = $wpdb->get_results( $query );
449
-						if ( !empty($products) ) {
450
-							foreach( $products as $product ) {
446
+					for ($i = 0; $i <= $count_products->publish; $i += 20) {
447
+						$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');
448
+						$products = $wpdb->get_results($query);
449
+						if (!empty($products)) {
450
+							foreach ($products as $product) {
451 451
 								$query = $wpdb->prepare("SELECT value FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attribute_parameter['data_type'] . " WHERE attribute_id = %d AND entity_type_id = %d AND entity_id = %d AND value != '' ORDER BY creation_date_value DESC", $id, $attribute_parameter['entity_id'], $product->ID);
452 452
 								$value = $wpdb->get_var($query);
453 453
 								update_post_meta($product->ID, '_' . $attribute_code, $value);
@@ -457,13 +457,13 @@  discard block
 block discarded – undo
457 457
 					wp_reset_query();
458 458
 				}
459 459
 
460
-				if ( $pageAction != 'delete' ) {/*	Add the new attribute in the additionnal informations attribute group	*/
461
-					if ( !empty($set_section) ) {
460
+				if ($pageAction != 'delete') {/*	Add the new attribute in the additionnal informations attribute group	*/
461
+					if (!empty($set_section)) {
462 462
 						$choosen_set_section = explode('_', $set_section);
463 463
 						$set_id = $choosen_set_section[0];
464 464
 						$group_id = $choosen_set_section[1];
465 465
 					}
466
-					else{
466
+					else {
467 467
 						$attribute_current_attribute_set = 0;
468 468
 						$query = $wpdb->prepare("
469 469
 								SELECT id
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 									AND ATTRIBUTE_SET_DETAILS.entity_type_id = %d", $id, $attribute_parameter['entity_id']);
474 474
 						$attribute_current_attribute_set = $wpdb->get_results($query);
475 475
 
476
-						if ( empty($attribute_current_attribute_set) ) {
476
+						if (empty($attribute_current_attribute_set)) {
477 477
 							$query = $wpdb->prepare("
478 478
 								SELECT
479 479
 									(
@@ -494,12 +494,12 @@  discard block
 block discarded – undo
494 494
 							$wpshop_default_group = $wpdb->get_row($query);
495 495
 
496 496
 							$set_id = $wpshop_default_group->attribute_set_id;
497
-							$default_group_id = ( !empty( $wpshop_default_group->default_attribute_group_id) ) ? $wpshop_default_group->default_attribute_group_id : '';
497
+							$default_group_id = (!empty($wpshop_default_group->default_attribute_group_id)) ? $wpshop_default_group->default_attribute_group_id : '';
498 498
 							$group_id = !empty($default_group_id) ? $default_group_id : $wpshop_default_group->attribute_group_id;
499 499
 						}
500 500
 					}
501 501
 
502
-					if ( !empty($set_id) && !empty($group_id) ) {
502
+					if (!empty($set_id) && !empty($group_id)) {
503 503
 						$query = $wpdb->prepare(
504 504
 								"SELECT (MAX(position) + 1) AS position
505 505
 								FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . "
@@ -511,12 +511,12 @@  discard block
 block discarded – undo
511 511
 								$attribute_parameter['entity_id']
512 512
 						);
513 513
 						$wpshopAttributePosition = $wpdb->get_var($query);
514
-						if($wpshopAttributePosition == 0)$wpshopAttributePosition = 1;
514
+						if ($wpshopAttributePosition == 0)$wpshopAttributePosition = 1;
515 515
 						$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_parameter['entity_id'], 'attribute_set_id' => $set_id, 'attribute_group_id' => $group_id, 'attribute_id' => $id, 'position' => $wpshopAttributePosition));
516 516
 					}
517 517
 				}
518 518
 
519
-				if ( !empty($wpshop_attribute_combo_values_list_order_def) ) {
519
+				if (!empty($wpshop_attribute_combo_values_list_order_def)) {
520 520
 					$post_order = explode(',', $wpshop_attribute_combo_values_list_order_def);
521 521
 					$position = 1;
522 522
 					foreach ($post_order as $post_id) {
@@ -532,19 +532,19 @@  discard block
 block discarded – undo
532 532
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id));
533 533
 				}
534 534
 				else */
535
-				if ( $pageAction == 'add' )
535
+				if ($pageAction == 'add')
536 536
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id));
537
-				elseif ( $pageAction == 'delete' )
537
+				elseif ($pageAction == 'delete')
538 538
 					wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id));
539 539
 			}
540
-			elseif(($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete')){
540
+			elseif (($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete')) {
541 541
 				$pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop');
542 542
 			}
543
-			elseif(($actionResult == 'unDeletableAtribute')){
543
+			elseif (($actionResult == 'unDeletableAtribute')) {
544 544
 				$pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('This attribute could not be deleted due to configuration', 'wpshop');
545 545
 			}
546 546
 
547
-			if(empty($attribute_parameter['frontend_label']) && ($pageAction!='delete')){
547
+			if (empty($attribute_parameter['frontend_label']) && ($pageAction != 'delete')) {
548 548
 				$pageMessage .= __('Please enter an label for the attribut', 'wpshop');
549 549
 			}
550 550
 		}
@@ -562,37 +562,37 @@  discard block
 block discarded – undo
562 562
 		//Create an instance of our package class...
563 563
 		$wpshop_list_table = new wpshop_attributes_custom_List_table();
564 564
 		//Fetch, prepare, sort, and filter our data...
565
-		$status="'valid'";
566
-		$attribute_status = !empty($_REQUEST['attribute_status']) ? sanitize_text_field( $_REQUEST['attribute_status'] ) : null;
567
-		$s = !empty($_REQUEST['s']) ? sanitize_text_field( $_REQUEST['s'] ) : null;
565
+		$status = "'valid'";
566
+		$attribute_status = !empty($_REQUEST['attribute_status']) ? sanitize_text_field($_REQUEST['attribute_status']) : null;
567
+		$s = !empty($_REQUEST['s']) ? sanitize_text_field($_REQUEST['s']) : null;
568 568
 		$order = !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : null;
569 569
 		$orderby = !empty($_REQUEST['orderby']) ? sanitize_text_field($_REQUEST['orderby']) : null;
570
-		if(!empty($attribute_status)){
571
-			switch($attribute_status){
570
+		if (!empty($attribute_status)) {
571
+			switch ($attribute_status) {
572 572
 				case 'unactive':
573
-					$status="'moderated', 'notused'";
574
-					if(empty($order_by) && empty($order)){
573
+					$status = "'moderated', 'notused'";
574
+					if (empty($order_by) && empty($order)) {
575 575
 						// @TODO : REQUEST
576 576
 						// $_REQUEST['orderby']='status';
577 577
 						// $_REQUEST['order']='asc';
578 578
 					}
579 579
 					break;
580 580
 				default:
581
-					$status="'".sanitize_text_field($_REQUEST['attribute_status'])."'";
581
+					$status = "'" . sanitize_text_field($_REQUEST['attribute_status']) . "'";
582 582
 					break;
583 583
 			}
584 584
 		}
585
-		if ( !empty($s) ) {
586
-			$query = $wpdb->prepare("SELECT * FROM " . self::dbTable . ' WHERE frontend_label LIKE "%%%1$s%%" OR frontend_label LIKE "%%%2$s%%" AND backend_label LIKE "%%%1$s%%" OR backend_label LIKE "%%%2$s%%" AND code LIKE "%%%1$s%%" OR code LIKE "%%%2$s%%"', $s, __($s, 'wpshop') );
587
-			$attr_set_list = $wpdb->get_results( $query );
585
+		if (!empty($s)) {
586
+			$query = $wpdb->prepare("SELECT * FROM " . self::dbTable . ' WHERE frontend_label LIKE "%%%1$s%%" OR frontend_label LIKE "%%%2$s%%" AND backend_label LIKE "%%%1$s%%" OR backend_label LIKE "%%%2$s%%" AND code LIKE "%%%1$s%%" OR code LIKE "%%%2$s%%"', $s, __($s, 'wpshop'));
587
+			$attr_set_list = $wpdb->get_results($query);
588 588
 		}
589 589
 		else {
590
-			$attr_set_list = self::getElement( '', $status );
590
+			$attr_set_list = self::getElement('', $status);
591 591
 		}
592
-		$i=0;
593
-		$attribute_set_list=array();
594
-		foreach($attr_set_list as $attr_set){
595
-			if(!empty($attr_set->id) && ($attr_set->code != 'product_attribute_set_id') ){
592
+		$i = 0;
593
+		$attribute_set_list = array();
594
+		foreach ($attr_set_list as $attr_set) {
595
+			if (!empty($attr_set->id) && ($attr_set->code != 'product_attribute_set_id')) {
596 596
 				$attribute_set_list[$i]['id'] = $attr_set->id;
597 597
 				$attribute_set_list[$i]['name'] = $attr_set->frontend_label;
598 598
 				$attribute_set_list[$i]['status'] = $attr_set->status;
@@ -640,31 +640,31 @@  discard block
 block discarded – undo
640 640
 		global $attribute_displayed_field, $attribute_options_group;
641 641
 		$dbFieldList = wpshop_database::fields_to_input(self::getDbTable());
642 642
 		$editedItem = '';
643
-		if($itemToEdit != '')
643
+		if ($itemToEdit != '')
644 644
 			$editedItem = self::getElement($itemToEdit);
645 645
 
646 646
 		$the_form_content_hidden = $the_form_general_content = '';
647 647
 		$the_form_option_content_list = array();
648
-		foreach($dbFieldList as $input_key => $input_def){
648
+		foreach ($dbFieldList as $input_key => $input_def) {
649 649
 
650
-			if(!isset($attribute_displayed_field) || !is_array($attribute_displayed_field) || in_array($input_def['name'], $attribute_displayed_field)){
650
+			if (!isset($attribute_displayed_field) || !is_array($attribute_displayed_field) || in_array($input_def['name'], $attribute_displayed_field)) {
651 651
 				$input_def['label'] = $input_def['name'];
652
-				$input_def_id=$input_def['id']='wpshop_' . self::currentPageCode . '_edition_table_field_id_'.$input_def['label'];
652
+				$input_def_id = $input_def['id'] = 'wpshop_' . self::currentPageCode . '_edition_table_field_id_' . $input_def['label'];
653 653
 
654 654
 				$pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? sanitize_text_field($_REQUEST[self::getDbTable() . '_action']) : '';
655 655
 				$requestFormValue = isset($_REQUEST[self::currentPageCode][$input_def['label']]) ? sanitize_text_field($_REQUEST[self::currentPageCode][$input_def['label']]) : '';
656 656
 				$currentFieldValue = $input_def['value'];
657
-				if(is_object($editedItem))
657
+				if (is_object($editedItem))
658 658
 					$currentFieldValue = $editedItem->{$input_def['label']};
659
-				elseif(($pageAction != '') && ($requestFormValue != ''))
659
+				elseif (($pageAction != '') && ($requestFormValue != ''))
660 660
 					$currentFieldValue = $requestFormValue;
661 661
 
662
-				if($input_def['label'] == 'status'){
663
-					if(in_array('notused', $input_def['possible_value'])){
662
+				if ($input_def['label'] == 'status') {
663
+					if (in_array('notused', $input_def['possible_value'])) {
664 664
 						$key = array_keys($input_def['possible_value'], 'notused');
665 665
 						unset($input_def['possible_value'][$key[0]]);
666 666
 					}
667
-					if(in_array('dbl', $input_def['possible_value'])){
667
+					if (in_array('dbl', $input_def['possible_value'])) {
668 668
 						$key = array_keys($input_def['possible_value'], 'dbl');
669 669
 						unset($input_def['possible_value'][$key[0]]);
670 670
 					}
@@ -672,94 +672,94 @@  discard block
 block discarded – undo
672 672
 					$input_def['type'] = 'checkbox';
673 673
 					$input_def['label'] = __('Use this attribute', 'wpshop');
674 674
 					$input_def['possible_value'] = array('valid');
675
-					$input_def_id.='_valid';
676
-					$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for using this attribute', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
675
+					$input_def_id .= '_valid';
676
+					$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for using this attribute', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
677 677
 				}
678 678
 
679
-				if ( (substr($input_def['label'], 0, 3) == 'is_') || ( $input_def['label'] == '_display_informations_about_value') ) {
679
+				if ((substr($input_def['label'], 0, 3) == 'is_') || ($input_def['label'] == '_display_informations_about_value')) {
680 680
 					$input_def['type'] = 'checkbox';
681 681
 					$input_def['possible_value'] = 'yes';
682 682
 				}
683
-				switch($input_def['label']){
683
+				switch ($input_def['label']) {
684 684
 					case 'is_requiring_unit':
685
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for using unit with this attribute', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
685
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for using unit with this attribute', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
686 686
 					break;
687 687
 					case 'is_visible_in_front':
688
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for displaying this attribute in shop', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
688
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for displaying this attribute in shop', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
689 689
 					break;
690 690
 					case 'is_visible_in_front_listing':
691
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for displaying this attribute in product listing in shop', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
691
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for displaying this attribute in product listing in shop', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
692 692
 					break;
693 693
 					case 'is_used_for_sort_by':
694
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for displaying this attribute into sortbar', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
694
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for displaying this attribute into sortbar', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
695 695
 					break;
696 696
 					case 'is_searchable':
697
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for including values of this attribute as search parameter', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
697
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for including values of this attribute as search parameter', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
698 698
 					break;
699 699
 					case 'is_visible_in_advanced_search':
700
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for using in advanced search form', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
700
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for using in advanced search form', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
701 701
 					break;
702 702
 					case 'frontend_css_class':
703
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Separate with a space each CSS Class', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
703
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Separate with a space each CSS Class', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
704 704
 					break;
705 705
 					case 'backend_css_class':
706
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Separate with a space each CSS Class', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
706
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Separate with a space each CSS Class', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
707 707
 					break;
708 708
 					case 'is_historisable':
709
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want to save the different value this attribute, each time it is modified', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
709
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want to save the different value this attribute, each time it is modified', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
710 710
 					break;
711 711
 					case 'is_filterable':
712
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want to use this attribute in the filter search', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
712
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want to use this attribute in the filter search', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
713 713
 					break;
714 714
 					case 'is_intrinsic':
715
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if this attribute is intrinsic for a product', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
715
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if this attribute is intrinsic for a product', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
716 716
 					break;
717 717
 					case 'is_used_for_variation':
718
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if this attribute is used for variation. It means that the user would be able to choose a value in frontend', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
718
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if this attribute is used for variation. It means that the user would be able to choose a value in frontend', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
719 719
 					break;
720 720
 					case 'is_used_in_variation':
721
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want to use this attribute for variation definition', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
722
-						if ( !empty($editedItem) && ($editedItem->is_used_for_variation == 'yes') ) {
721
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want to use this attribute for variation definition', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
722
+						if (!empty($editedItem) && ($editedItem->is_used_for_variation == 'yes')) {
723 723
 							$input_def['option'] = 'disabled="disabled"';
724 724
 						}
725 725
 					break;
726 726
 					case 'is_user_defined':
727
-						$input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want your customer to choose a value for this attribute into frontend product', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
727
+						$input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want your customer to choose a value for this attribute into frontend product', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
728 728
 					break;
729 729
 				}
730 730
 
731 731
 				$input_def['value'] = $currentFieldValue;
732
-				if($input_def['label'] == 'code')
732
+				if ($input_def['label'] == 'code')
733 733
 					$input_def['type'] = 'hidden';
734
-				elseif($input_def['label'] == 'entity_id'){
734
+				elseif ($input_def['label'] == 'entity_id') {
735 735
 					$input_def['possible_value'] = wpshop_entities::get_entities_list();
736 736
 					$input_def['valueToPut'] = 'index';
737 737
 					$input_def['type'] = 'select';
738 738
 
739
-					$i=0;
740
-					foreach($input_def['possible_value'] as $entity_id => $entity_name) {
741
-						if($i <= 0){
739
+					$i = 0;
740
+					foreach ($input_def['possible_value'] as $entity_id => $entity_name) {
741
+						if ($i <= 0) {
742 742
 							$current_entity_id = $entity_id;
743 743
 						}
744 744
 						$i++;
745 745
 					}
746 746
 				}
747
-				elseif($input_def['label'] == '_unit_group_id'){
747
+				elseif ($input_def['label'] == '_unit_group_id') {
748 748
 					$input_def['possible_value'] = wpshop_attributes_unit::get_unit_group();
749 749
 					$input_def['type'] = 'select';
750 750
 				}
751
-				elseif($input_def['label'] == '_default_unit'){
751
+				elseif ($input_def['label'] == '_default_unit') {
752 752
 					$unit_group_list = wpshop_attributes_unit::get_unit_group();
753
-					$input_def['possible_value'] = wpshop_attributes_unit::get_unit_list_for_group(!empty($editedItem->_unit_group_id)?$editedItem->_unit_group_id:(!empty($unit_group_list)?$unit_group_list[0]->id:''));
753
+					$input_def['possible_value'] = wpshop_attributes_unit::get_unit_list_for_group(!empty($editedItem->_unit_group_id) ? $editedItem->_unit_group_id : (!empty($unit_group_list) ? $unit_group_list[0]->id : ''));
754 754
 					$input_def['type'] = 'select';
755 755
 				}
756 756
 				elseif ($input_def['label'] == 'backend_input') {
757
-					if ( !is_object($editedItem) ) {
757
+					if (!is_object($editedItem)) {
758 758
 						$input_def['type'] = 'hidden';
759 759
 					}
760 760
 					else {
761 761
 						$new_possible_value = array();
762
-						switch ( $editedItem->data_type) {
762
+						switch ($editedItem->data_type) {
763 763
 							case 'integer':
764 764
 								$new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox';
765 765
 								$new_possible_value[__('Radio button', 'wpshop')] = 'radio';
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
 								$new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select';
768 768
 								break;
769 769
 							case 'varchar':
770
-								switch ( $input_def['value'] ) {
770
+								switch ($input_def['value']) {
771 771
 									case 'hidden':
772 772
 										$new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field';
773 773
 										break;
@@ -795,8 +795,8 @@  discard block
 block discarded – undo
795 795
 				elseif ($input_def['label'] == 'frontend_input') {
796 796
 					$new_possible_value = array();
797 797
 
798
-					if ( is_object($editedItem) ) {
799
-						switch ( $editedItem->data_type) {
798
+					if (is_object($editedItem)) {
799
+						switch ($editedItem->data_type) {
800 800
 							case 'integer':
801 801
 								$new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox';
802 802
 								$new_possible_value[__('Radio button', 'wpshop')] = 'radio';
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
 								$new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select';
805 805
 								break;
806 806
 							case 'varchar':
807
-									switch ( $input_def['value'] ) {
807
+									switch ($input_def['value']) {
808 808
 										case 'hidden':
809 809
 											$new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field';
810 810
 										break;
@@ -842,10 +842,10 @@  discard block
 block discarded – undo
842 842
 
843 843
 					$input_def['possible_value'] = $new_possible_value;
844 844
 
845
-					if ( !empty($editedItem->frontend_input) ) {
846
-						switch ( $editedItem->frontend_input ) {
845
+					if (!empty($editedItem->frontend_input)) {
846
+						switch ($editedItem->frontend_input) {
847 847
 							case 'text':
848
-								switch ( $editedItem->data_type ) {
848
+								switch ($editedItem->data_type) {
849 849
 									case 'varchar':
850 850
 										$input_def['value'] = 'short_text';
851 851
 									break;
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 					}
871 871
 				}
872 872
 
873
-				if(is_object($editedItem) && (($input_def['label'] == 'code') || ($input_def['label'] == 'data_type') || ($input_def['label'] == 'entity_id'))){
873
+				if (is_object($editedItem) && (($input_def['label'] == 'code') || ($input_def['label'] == 'data_type') || ($input_def['label'] == 'entity_id'))) {
874 874
 					// $input_def['type'] = 'hidden';
875 875
 					$input_def['option'] = ' disabled="disabled" ';
876 876
 					$the_form_content_hidden .= '<input type="hidden" name="' . self::getDbTable() . '[' . $input_def['name'] . ']" value="' . $input_def['value'] . '" />';
@@ -881,16 +881,16 @@  discard block
 block discarded – undo
881 881
 				$input_def['value'] = str_replace("\\", "", $input_def['value']);
882 882
 
883 883
 				$the_input = wpshop_form::check_input_type($input_def, self::getDbTable());
884
-				if ( $input_def['label'] == 'default_value' ) {
885
-					if ( !empty($editedItem->frontend_input) ) {
886
-						switch ( $editedItem->frontend_input ) {
884
+				if ($input_def['label'] == 'default_value') {
885
+					if (!empty($editedItem->frontend_input)) {
886
+						switch ($editedItem->frontend_input) {
887 887
 							case 'text':
888 888
 								$input_def['type'] = 'text';
889
-								switch ( $editedItem->data_type ) {
889
+								switch ($editedItem->data_type) {
890 890
 									case 'datetime':
891
-										$the_input = wpshop_attributes::attribute_type_date_config( unserialize($input_def['value']) );
891
+										$the_input = wpshop_attributes::attribute_type_date_config(unserialize($input_def['value']));
892 892
 
893
-										$input_def['label'] = __('Date field configuration','wpshop');
893
+										$input_def['label'] = __('Date field configuration', 'wpshop');
894 894
 									break;
895 895
 									default:
896 896
 										$the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
 							case 'multiple-select':
908 908
 							case 'radio':
909 909
 							case 'checkbox':
910
-								$input_def['label'] = __('Options list for attribute','wpshop') . '
910
+								$input_def['label'] = __('Options list for attribute', 'wpshop') . '
911 911
 <div class="alignright wpshop_change_select_data_type" >
912 912
 	+' . __('Change data type for this attribute', 'wpshop') . '
913 913
 </div>';
@@ -921,50 +921,50 @@  discard block
 block discarded – undo
921 921
 						}
922 922
 					}
923 923
 					else {
924
-						$input_def['type']='text';
924
+						$input_def['type'] = 'text';
925 925
 						$the_input = wpshop_form::check_input_type($input_def, self::getDbTable());
926 926
 					}
927 927
 				}
928
-				if( $input_def['label'] == '_unit_group_id') {
928
+				if ($input_def['label'] == '_unit_group_id') {
929 929
 					$the_input .= '<div id="wpshop_loader_input_group_unit"></div>';
930
-					$the_input .= '<a class="button-primary" href="#wpshop_unit_group_list" id="wpshop_attribute_group_unit_manager_opener" data-nonce="' . wp_create_nonce( 'load_unit_interface' ) . '">'.__('Manage group unit', 'wpshop').'</a>';
930
+					$the_input .= '<a class="button-primary" href="#wpshop_unit_group_list" id="wpshop_attribute_group_unit_manager_opener" data-nonce="' . wp_create_nonce('load_unit_interface') . '">' . __('Manage group unit', 'wpshop') . '</a>';
931 931
 				}
932 932
 
933
-				if( $input_def['label'] == '_default_unit') {
933
+				if ($input_def['label'] == '_default_unit') {
934 934
 					$the_input .= '<div id="wpshop_loader_input_unit"></div>';
935
-					$the_input .= '<a class="button-primary" href="#wpshop_unit_list" id="wpshop_attribute_unit_manager_opener" data-nonce="' . wp_create_nonce( 'load_unit_interface' ) . '">'.__('Manage units', 'wpshop').'</a>';
935
+					$the_input .= '<a class="button-primary" href="#wpshop_unit_list" id="wpshop_attribute_unit_manager_opener" data-nonce="' . wp_create_nonce('load_unit_interface') . '">' . __('Manage units', 'wpshop') . '</a>';
936 936
 					$the_input .= '<input type="hidden" name="input_wpshop_load_attribute_unit_list" id="input_wpshop_load_attribute_unit_list" value="' . wp_create_nonce("wpshop_load_attribute_unit_list") . '" />';
937 937
 					$the_input .= '<div id="wpshop_attribute_unit_manager" title="' . __('Unit management', 'wpshop') . '" class="wpshopHide" ><div class="loading_picture_container" id="product_chooser_picture" ><img src="' . WPSHOP_LOADING_ICON . '" alt="loading..." /></div></div>';
938 938
 				}
939 939
 
940 940
 
941
-				if($input_def['type'] != 'hidden'){
942
-					if ( ($input_def['label'] == 'entity_id') && is_object($editedItem) ) {
941
+				if ($input_def['type'] != 'hidden') {
942
+					if (($input_def['label'] == 'entity_id') && is_object($editedItem)) {
943 943
 						$the_input .= '<br/><span class="wpshop_duplicate_attribute" >' . __('Duplicate this attribute to . another entity', 'wpshop') . '</span>';
944 944
 					}
945 945
 					$input = '
946
-		<tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_'.$input_def['name'].'" >
947
-			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_'.$input_def['name'].'" ><label for="'.$input_def_id.'" >' . __($input_def['label'], 'wpshop') . '</label></td>
948
-			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_'.$input_def['name'].'" >' . $the_input . '</td>
946
+		<tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_' . $input_def['name'] . '" >
947
+			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_' . $input_def['name'] . '" ><label for="' . $input_def_id . '" >' . __($input_def['label'], 'wpshop') . '</label></td>
948
+			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_' . $input_def['name'] . '" >' . $the_input . '</td>
949 949
 		</tr>';
950
-					if ( (substr($input_def['label'], 0, 3) == 'is_') || (substr($input_def['label'], 0, 1) == '_') || in_array($input_def['label'], unserialize( WPSHOP_ATTRIBUTE_DEF_COLUMN_INTO_OPTIONS )) )
950
+					if ((substr($input_def['label'], 0, 3) == 'is_') || (substr($input_def['label'], 0, 1) == '_') || in_array($input_def['label'], unserialize(WPSHOP_ATTRIBUTE_DEF_COLUMN_INTO_OPTIONS)))
951 951
 						$the_form_option_content_list[$input_def['label']] = $input;
952 952
 					else {
953 953
 						$the_form_general_content .= $input;
954
-						if ( ($input_def['label'] == 'frontend_input') && !is_object($editedItem) ) {
954
+						if (($input_def['label'] == 'frontend_input') && !is_object($editedItem)) {
955 955
 
956
-							$the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id,  self::getDbTable(), self::currentPageCode);
956
+							$the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id, self::getDbTable(), self::currentPageCode);
957 957
 
958 958
 							$input = '
959 959
 		<tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_set_section" >
960
-			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_set_section" ><label for="'.self::currentPageCode.'_set_section" >' . __('Affect this new attribute to the set section', 'wpshop') . '</label></td>
960
+			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_set_section" ><label for="' . self::currentPageCode . '_set_section" >' . __('Affect this new attribute to the set section', 'wpshop') . '</label></td>
961 961
 			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_set_section" >' . $the_input . '</td>
962 962
 		</tr>';
963 963
 							$the_form_general_content .= $input;
964 964
 						}
965 965
 					}
966 966
 				}
967
-				else{
967
+				else {
968 968
 					$the_form_content_hidden .= '
969 969
 				' . $the_input;
970 970
 				}
@@ -980,17 +980,17 @@  discard block
 block discarded – undo
980 980
 		$section_content = $the_form_general_content;
981 981
 
982 982
 		ob_start();
983
-		include(WPSHOP_TEMPLATES_DIR.'admin/admin_box_section.tpl.php');
983
+		include(WPSHOP_TEMPLATES_DIR . 'admin/admin_box_section.tpl.php');
984 984
 		$the_form_general_content = ob_get_contents();
985 985
 		ob_end_clean();
986 986
 
987 987
 		/** It is attribute TVA, add a button to calcilate price in mass **/
988
-		if ( !empty($editedItem) && !empty($editedItem->code) && $editedItem->code == 'tx_tva' ) {
989
-			$the_form_general_content .= '<input type="button" data-nonce="' . wp_create_nonce( 'wps_update_products_prices' ) . '" id="wps_update_price_infos" value="' .__('Update all products price', 'wpshop').'" /> <img src="' .WPSHOP_LOADING_ICON. '" alt="" id="update_products_loader" /> <br/>';
990
-			$the_form_general_content .= __('If you have updated your VAT rates, save it and update your products price after', 'wpshop' );
988
+		if (!empty($editedItem) && !empty($editedItem->code) && $editedItem->code == 'tx_tva') {
989
+			$the_form_general_content .= '<input type="button" data-nonce="' . wp_create_nonce('wps_update_products_prices') . '" id="wps_update_price_infos" value="' . __('Update all products price', 'wpshop') . '" /> <img src="' . WPSHOP_LOADING_ICON . '" alt="" id="update_products_loader" /> <br/>';
990
+			$the_form_general_content .= __('If you have updated your VAT rates, save it and update your products price after', 'wpshop');
991 991
 		}
992 992
 		if (!empty($the_form_option_content_list)) {
993
-			$the_form_option_content_section='';
993
+			$the_form_option_content_section = '';
994 994
 			foreach ($attribute_options_group as $group_name => $group_content) {
995 995
 				$section_content = '';
996 996
 				foreach ($group_content as $group_code) {
@@ -999,23 +999,23 @@  discard block
 block discarded – undo
999 999
 						unset($the_form_option_content_list[$group_code]);
1000 1000
 					}
1001 1001
 				}
1002
-				$section_legend = __($group_name,'wpshop');
1002
+				$section_legend = __($group_name, 'wpshop');
1003 1003
 				$section_page_code = self::currentPageCode;
1004 1004
 
1005 1005
 				ob_start();
1006
-				include(WPSHOP_TEMPLATES_DIR.'admin/admin_box_section.tpl.php');
1006
+				include(WPSHOP_TEMPLATES_DIR . 'admin/admin_box_section.tpl.php');
1007 1007
 				$the_form_option_content_section .= ob_get_contents();
1008 1008
 				ob_end_clean();
1009 1009
 			}
1010 1010
 
1011 1011
 			/*	Check there are other attributes to display not in defined group	*/
1012 1012
 			if (!empty($the_form_option_content_list)) {
1013
-				$section_legend = __('General options','wpshop');
1013
+				$section_legend = __('General options', 'wpshop');
1014 1014
 				$section_content = implode('', $the_form_option_content_list);
1015 1015
 				$section_page_code = self::currentPageCode;
1016 1016
 
1017 1017
 				ob_start();
1018
-				include(WPSHOP_TEMPLATES_DIR.'admin/admin_box_section.tpl.php');
1018
+				include(WPSHOP_TEMPLATES_DIR . 'admin/admin_box_section.tpl.php');
1019 1019
 				$the_form_option_content = ob_get_contents();
1020 1020
 				ob_end_clean();
1021 1021
 
@@ -1025,17 +1025,17 @@  discard block
 block discarded – undo
1025 1025
 		}
1026 1026
 
1027 1027
 		/*	Default content for the current page	*/
1028
-		$bloc_list[self::currentPageCode]['main_info']['title']=__('Main informations', 'wpshop');
1028
+		$bloc_list[self::currentPageCode]['main_info']['title'] = __('Main informations', 'wpshop');
1029 1029
 		$bloc_list[self::currentPageCode]['main_info']['content'] = $the_form_general_content;
1030 1030
 
1031
-		$bloc_list[self::currentPageCode]['options']['title']=__('Options', 'wpshop');
1032
-		$bloc_list[self::currentPageCode]['options']['content']=$the_form_option_content;
1031
+		$bloc_list[self::currentPageCode]['options']['title'] = __('Options', 'wpshop');
1032
+		$bloc_list[self::currentPageCode]['options']['content'] = $the_form_option_content;
1033 1033
 
1034
-		$action = !empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action' ] ) : '';
1034
+		$action = !empty($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
1035 1035
 		$the_form = '
1036 1036
 <form name="' . self::getDbTable() . '_form" id="' . self::getDbTable() . '_form" method="post" action="#" >
1037
-	' . wpshop_form::form_input(self::getDbTable() . '_action', self::getDbTable() . '_action', (isset($action) && ($action != '') ? sanitize_text_field($action) : 'save') , 'hidden') . '
1038
-	' . wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no' , 'hidden') . $the_form_content_hidden . wpshop_display::custom_page_output_builder($bloc_list, WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT) . '
1037
+	' . wpshop_form::form_input(self::getDbTable() . '_action', self::getDbTable() . '_action', (isset($action) && ($action != '') ? sanitize_text_field($action) : 'save'), 'hidden') . '
1038
+	' . wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no', 'hidden') . $the_form_content_hidden . wpshop_display::custom_page_output_builder($bloc_list, WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT) . '
1039 1039
 </form>
1040 1040
 <div title="' . __('Change data type for selected attribute', 'wpshop') . '" id="wpshop_dialog_change_select_data_type" ><div id="wpshop_dialog_change_select_data_type_container" ></div></div>';
1041 1041
 		$input_def['possible_value'] = wpshop_entities::get_entities_list();
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 		$the_form .= '
1054 1054
 <script type="text/javascript" >
1055 1055
 	wpshop(document).ready(function(){
1056
-		wpshopMainInterface("'.self::getDbTable().'", "' . __('Are you sure you want to quit this page? You will loose all current modification', 'wpshop') . '", "' . __('Are you sure you want to delete this attributes group?', 'wpshop') . '");
1056
+		wpshopMainInterface("'.self::getDbTable() . '", "' . __('Are you sure you want to quit this page? You will loose all current modification', 'wpshop') . '", "' . __('Are you sure you want to delete this attributes group?', 'wpshop') . '");
1057 1057
 
1058 1058
 		jQuery("#wpshop_dialog_duplicate_attribute").dialog({
1059 1059
 			autoOpen: false,
@@ -1063,7 +1063,7 @@  discard block
 block discarded – undo
1063 1063
 			dialogClass: "wpshop_uidialog_box",
1064 1064
 			resizable: false,
1065 1065
 			buttons:{
1066
-				"'.__('Duplicate', 'wpshop').'": function(){
1066
+				"'.__('Duplicate', 'wpshop') . '": function(){
1067 1067
 					var data = {
1068 1068
 						action: "wpshop_duplicate_attribute",
1069 1069
 						wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_duplicate_attribute") . '",
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 						}
1080 1080
 					}, "json");
1081 1081
 				},
1082
-				"'.__('Cancel', 'wpshop').'": function(){
1082
+				"'.__('Cancel', 'wpshop') . '": function(){
1083 1083
 					jQuery(this).dialog("close");
1084 1084
 					jQuery(".wpshop_duplicate_attribute_result").remove();
1085 1085
 				}
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 			dialogClass: "wpshop_uidialog_box",
1098 1098
 			resizable: false,
1099 1099
 			buttons:{
1100
-				"'.__('Change type', 'wpshop').'": function(){
1100
+				"'.__('Change type', 'wpshop') . '": function(){
1101 1101
 					var delete_entity = false;
1102 1102
 					if(jQuery("#delete_entity").is(":checked")){
1103 1103
 						var delete_entity = true;
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 						jQuery("#wpshop_dialog_change_select_data_type").dialog("close");
1121 1121
 					}, "json");
1122 1122
 				},
1123
-				"'.__('Cancel', 'wpshop').'": function(){
1123
+				"'.__('Cancel', 'wpshop') . '": function(){
1124 1124
 					jQuery(this).dialog("close");
1125 1125
 				}
1126 1126
 			}
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
 			change_unit_list();
1161 1161
 		});';
1162 1162
 
1163
-		if ( !is_object($editedItem) )  {
1163
+		if (!is_object($editedItem)) {
1164 1164
 			$the_form .= '
1165 1165
 		jQuery("#wpshop_attributes_edition_table_field_id_frontend_input").change(function(){
1166 1166
 			jQuery(".wpshop_attributes_edition_table_field_input_default_value").html(jQuery("#wpshopLoadingPicture").html());
@@ -1243,23 +1243,23 @@  discard block
 block discarded – undo
1243 1243
 	 *
1244 1244
 	 *	@return string $currentPageButton The html output code with the different button to add to the interface
1245 1245
 	 */
1246
-	function getPageFormButton($element_id = 0){
1246
+	function getPageFormButton($element_id = 0) {
1247 1247
 		$action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : 'add';
1248 1248
 		$currentPageButton = '';
1249 1249
 
1250 1250
 		 //$currentPageButton .= '<h2 class="cancelButton alignleft" ><a href="' . admin_url('edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES.'&amp;page=' . self::getListingSlug()) . '" class="button add-new-h2" >' . __('Back', 'wpshop') . '</a></h2>';
1251 1251
 
1252
-		if(($action == 'add') && (current_user_can('wpshop_add_attributes')))
1252
+		if (($action == 'add') && (current_user_can('wpshop_add_attributes')))
1253 1253
 			$currentPageButton .= '<input type="button" class="button-primary" id="add" name="add" value="' . __('Add', 'wpshop') . '" />';
1254 1254
 
1255
-		elseif(current_user_can('wpshop_edit_attributes'))
1255
+		elseif (current_user_can('wpshop_edit_attributes'))
1256 1256
 		$currentPageButton .= '<input type="button" class="button-primary" id="save" name="save" value="' . __('Save', 'wpshop') . '" />';
1257 1257
 
1258 1258
 		$attribute_undeletable = unserialize(WPSHOP_ATTRIBUTE_UNDELETABLE);
1259 1259
 		$attribute = self::getElement($element_id, "'valid', 'moderated', 'notused'", 'id');
1260
-		$attribute_code = !empty($attribute->code)?$attribute->code:'';
1261
-		if(current_user_can('wpshop_delete_attributes') && ($action != 'add') && !in_array($attribute_code, $attribute_undeletable))
1262
-			$currentPageButton .= '<input type="button" class="button-secondary wpshop_delete_element_button wpshop_delete_element_button_'.self::currentPageCode.'" id="delete" name="delete" value="' . __('Delete', 'wpshop') . '" />';
1260
+		$attribute_code = !empty($attribute->code) ? $attribute->code : '';
1261
+		if (current_user_can('wpshop_delete_attributes') && ($action != 'add') && !in_array($attribute_code, $attribute_undeletable))
1262
+			$currentPageButton .= '<input type="button" class="button-secondary wpshop_delete_element_button wpshop_delete_element_button_' . self::currentPageCode . '" id="delete" name="delete" value="' . __('Delete', 'wpshop') . '" />';
1263 1263
 
1264 1264
 		return $currentPageButton;
1265 1265
 	}
@@ -1273,22 +1273,22 @@  discard block
 block discarded – undo
1273 1273
 	 *
1274 1274
 	 *	@return object $element_list A wordpress database object containing the attribute list
1275 1275
 	 */
1276
-	public static function getElement($element_id = '', $element_status = "'valid', 'moderated', 'notused'", $field_to_search = 'id', $list = false){
1276
+	public static function getElement($element_id = '', $element_status = "'valid', 'moderated', 'notused'", $field_to_search = 'id', $list = false) {
1277 1277
 
1278 1278
 		global $wpdb;
1279 1279
 		$element_list = array();
1280 1280
 		$moreQuery = "";
1281
-		$moreArgs = array( 1, );
1281
+		$moreArgs = array(1,);
1282 1282
 
1283
-		$orderby = !empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
1284
-		$order = !empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
1283
+		$orderby = !empty($_REQUEST['orderby']) ? sanitize_text_field($_REQUEST['orderby']) : '';
1284
+		$order = !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : '';
1285 1285
 
1286
-		if($element_id != ''){
1286
+		if ($element_id != '') {
1287 1287
 			$moreQuery .= "
1288 1288
 					AND CURRENT_ELEMENT." . $field_to_search . " = %s ";
1289 1289
 			$moreArgs[] = $element_id;
1290 1290
 		}
1291
-		if(!empty($orderby) && !empty($order)){
1291
+		if (!empty($orderby) && !empty($order)) {
1292 1292
 			$moreQuery .= "
1293 1293
 					ORDER BY " . $orderby . "  " . $order;
1294 1294
 		}
@@ -1297,15 +1297,15 @@  discard block
 block discarded – undo
1297 1297
 			"SELECT CURRENT_ELEMENT.*, ENTITIES.post_name as entity
1298 1298
 			FROM " . self::getDbTable() . " AS CURRENT_ELEMENT
1299 1299
 			INNER JOIN {$wpdb->posts} AS ENTITIES ON (ENTITIES.ID = CURRENT_ELEMENT.entity_id)
1300
-			WHERE %d AND CURRENT_ELEMENT.status IN (".$element_status.") " . $moreQuery,
1300
+			WHERE %d AND CURRENT_ELEMENT.status IN (" . $element_status . ") " . $moreQuery,
1301 1301
 			$moreArgs
1302 1302
 		);
1303 1303
 
1304 1304
 		/*	Get the query result regarding on the function parameters. If there must be only one result or a collection	*/
1305
-		if(($element_id == '') || $list){
1305
+		if (($element_id == '') || $list) {
1306 1306
 			$element_list = $wpdb->get_results($query);
1307 1307
 		}
1308
-		else{
1308
+		else {
1309 1309
 			$element_list = $wpdb->get_row($query);
1310 1310
 		}
1311 1311
 
@@ -1327,8 +1327,8 @@  discard block
 block discarded – undo
1327 1327
 		$user_id = function_exists('is_user_logged_in') && is_user_logged_in() ? get_current_user_id() : '0';
1328 1328
 		$sent_attribute_list = array();
1329 1329
 
1330
-		if ( !empty($attributeToSet) ) {
1331
-			$attributeToSet = apply_filters( 'save_attribute_for_entity', $attributeToSet, $entityTypeId, $entityId );
1330
+		if (!empty($attributeToSet)) {
1331
+			$attributeToSet = apply_filters('save_attribute_for_entity', $attributeToSet, $entityTypeId, $entityId);
1332 1332
 			$old_attribute_to_set = $attributeToSet;
1333 1333
 			$attribute_setted = array();
1334 1334
 			foreach ($attributeToSet as $attributeType => $attributeTypeDetails) {
@@ -1337,39 +1337,39 @@  discard block
 block discarded – undo
1337 1337
 					'entity_id' => $entityId,
1338 1338
 					'entity_type_id' => $entityTypeId
1339 1339
 				);
1340
-				if ( WPSHOP_ATTRIBUTE_VALUE_PER_USER ) {
1340
+				if (WPSHOP_ATTRIBUTE_VALUE_PER_USER) {
1341 1341
 					$delete_current_attribute_values_params['user_id'] = $user_id;
1342 1342
 				}
1343 1343
 
1344
-				if(!empty($attributeTypeDetails) && is_array($attributeTypeDetails)) {
1345
-					$attributeTypeDetails = apply_filters( "save_attribute_for_entity_{$attributeType}", $attributeTypeDetails, $entityTypeId, $entityId );
1346
-					foreach($attributeTypeDetails as $attribute_code => $attributeValue) {
1347
-						$attributeValue = apply_filters( "save_attribute_for_entity_{$attributeType}_{$attribute_code}", apply_filters( "save_attribute_for_entity__{$attribute_code}", $attributeValue, $entityTypeId, $entityId ), $entityTypeId, $entityId );
1344
+				if (!empty($attributeTypeDetails) && is_array($attributeTypeDetails)) {
1345
+					$attributeTypeDetails = apply_filters("save_attribute_for_entity_{$attributeType}", $attributeTypeDetails, $entityTypeId, $entityId);
1346
+					foreach ($attributeTypeDetails as $attribute_code => $attributeValue) {
1347
+						$attributeValue = apply_filters("save_attribute_for_entity_{$attributeType}_{$attribute_code}", apply_filters("save_attribute_for_entity__{$attribute_code}", $attributeValue, $entityTypeId, $entityId), $entityTypeId, $entityId);
1348 1348
 						$old_attribute_value = $attributeValue;
1349 1349
 
1350
-						if ( $attributeType == 'decimal' ) {
1350
+						if ($attributeType == 'decimal') {
1351 1351
 							$attributeValue = str_replace(',', '.', $attributeValue);
1352 1352
 						}
1353
-						if ( ($attributeType == 'integer') && !is_array($attributeValue) ) {
1353
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1354 1354
 							$attributeValue = (int)$attributeValue;
1355 1355
 						}
1356 1356
 						$more_query_params_values = array();
1357
-						if($attribute_code != 'unit') {
1357
+						if ($attribute_code != 'unit') {
1358 1358
 
1359 1359
 							$unit_id = 0;
1360
-							if(isset($attributeTypeDetails['unit'][$attribute_code])){
1360
+							if (isset($attributeTypeDetails['unit'][$attribute_code])) {
1361 1361
 								$unit_id = $attributeTypeDetails['unit'][$attribute_code];
1362 1362
 							}
1363 1363
 
1364 1364
 							$currentAttribute = self::getElement($attribute_code, "'valid'", 'code');
1365
-							if( !empty($currentAttribute) ){
1365
+							if (!empty($currentAttribute)) {
1366 1366
 								$sent_attribute_list[] = $currentAttribute->id;
1367 1367
 
1368 1368
 								/*	Enregistrement de la valeur actuelle de l'attribut dans la table d'historique si l'option historique est activee sur l'attribut courant	*/
1369
-								if (  $currentAttribute->is_historisable == 'yes') {
1369
+								if ($currentAttribute->is_historisable == 'yes') {
1370 1370
 									$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType . " WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d", $entityTypeId, $currentAttribute->id, $entityId);
1371 1371
 									$attribute_histo = $wpdb->get_results($query);
1372
-									if(!empty($attribute_histo)){
1372
+									if (!empty($attribute_histo)) {
1373 1373
 										$attribute_histo_content['status'] = 'valid';
1374 1374
 										$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1375 1375
 										$attribute_histo_content['creation_date_value'] = $attribute_histo[0]->creation_date_value;
@@ -1387,8 +1387,8 @@  discard block
 block discarded – undo
1387 1387
 								}
1388 1388
 								$attributeValue = str_replace("\\", "", $attributeValue);
1389 1389
 
1390
-								if ( empty($from) || (!empty($attributeValue)) ) {
1391
-									$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.$attributeType, array_merge($delete_current_attribute_values_params, array('attribute_id' => $currentAttribute->id)));
1390
+								if (empty($from) || (!empty($attributeValue))) {
1391
+									$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($delete_current_attribute_values_params, array('attribute_id' => $currentAttribute->id)));
1392 1392
 
1393 1393
 									/**	Insertion de la nouvelle valeur de l'attribut dans la base	*/
1394 1394
 									$query_params = array(
@@ -1402,66 +1402,66 @@  discard block
 block discarded – undo
1402 1402
 										'creation_date_value' => current_time('mysql', 0)
1403 1403
 									);
1404 1404
 									/**	Si l'attribut courant est contenu dans un tableau (exemple: select multiple) on lit tout le tableau et on enregistre chaque valeur separement	*/
1405
-									if(is_array($attributeValue)){
1406
-										foreach($attributeValue as $a){
1407
-											$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.$attributeType, array_merge($query_params, array('value' => $a)));
1405
+									if (is_array($attributeValue)) {
1406
+										foreach ($attributeValue as $a) {
1407
+											$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($query_params, array('value' => $a)));
1408 1408
 										}
1409 1409
 									}
1410
-									else{
1411
-										$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.$attributeType, array_merge($query_params, array('value' => $attributeValue)));
1412
-										wpeologs_ctr::log_datas_in_files( 'wpshop_attributes', array(
1410
+									else {
1411
+										$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($query_params, array('value' => $attributeValue)));
1412
+										wpeologs_ctr::log_datas_in_files('wpshop_attributes', array(
1413 1413
 											'object_id' 	=> $entityId,
1414
-											'message' 		=> __( 'Add the attribute : ' . $currentAttribute->code . ' with value : ' . $attributeValue , 'wpshop' ) ), 0
1414
+											'message' 		=> __('Add the attribute : ' . $currentAttribute->code . ' with value : ' . $attributeValue, 'wpshop') ), 0
1415 1415
 										);
1416 1416
 									}
1417 1417
 
1418 1418
 									/**	Dans le cas ou l'attribut courant est utilise dans l'interface permettant de trier les produits (option de l'attribut) on defini une meta specifique	*/
1419
-									if ( ( ($currentAttribute->is_used_for_sort_by == 'yes') || ($currentAttribute->is_searchable == 'yes'))  || ( $currentAttribute->is_filterable == 'yes') && !empty($attributeValue) ) :
1420
-										update_post_meta($entityId, '_'.$attribute_code, $attributeValue);
1419
+									if ((($currentAttribute->is_used_for_sort_by == 'yes') || ($currentAttribute->is_searchable == 'yes')) || ($currentAttribute->is_filterable == 'yes') && !empty($attributeValue)) :
1420
+										update_post_meta($entityId, '_' . $attribute_code, $attributeValue);
1421 1421
 									endif;
1422 1422
 
1423 1423
 									/**	Enregistrement de toutes les valeurs des attributs dans une meta du produit	*/
1424
-									$attribute_option = (!empty($_POST['attribute_option'][$attribute_code])) ? (array) $_POST['attribute_option'][$attribute_code] : null;
1424
+									$attribute_option = (!empty($_POST['attribute_option'][$attribute_code])) ? (array)$_POST['attribute_option'][$attribute_code] : null;
1425 1425
 									if (isset($attribute_option)) {
1426 1426
 										$value = self::get_attribute_type_select_option_info($attributeTypeDetails[$attribute_code], 'value');
1427 1427
 										if (strtolower($value) == 'yes') :
1428
-											update_post_meta($entityId, 'attribute_option_'.$attribute_code, $attribute_option);
1428
+											update_post_meta($entityId, 'attribute_option_' . $attribute_code, $attribute_option);
1429 1429
 										else :
1430
-											delete_post_meta($entityId, 'attribute_option_'.$attribute_code);
1430
+											delete_post_meta($entityId, 'attribute_option_' . $attribute_code);
1431 1431
 										endif;
1432 1432
 									}
1433 1433
 								}
1434 1434
 							}
1435 1435
 						}
1436
-						do_action( "saved_attribute_for_entity_{$attributeType}_{$attribute_code}", $attributeValue, $old_attribute_value, $entityTypeId, $entityId );
1437
-						do_action( "saved_attribute_for_entity__{$attribute_code}", $attributeValue, $old_attribute_value, $entityTypeId, $entityId );
1438
-						if ( isset( $attribute_setted[$attributeType][$attribute_code] ) ) {
1439
-							if( is_array( $attribute_setted[$attributeType][$attribute_code] )) {
1436
+						do_action("saved_attribute_for_entity_{$attributeType}_{$attribute_code}", $attributeValue, $old_attribute_value, $entityTypeId, $entityId);
1437
+						do_action("saved_attribute_for_entity__{$attribute_code}", $attributeValue, $old_attribute_value, $entityTypeId, $entityId);
1438
+						if (isset($attribute_setted[$attributeType][$attribute_code])) {
1439
+							if (is_array($attribute_setted[$attributeType][$attribute_code])) {
1440 1440
 								$attribute_setted[$attributeType][$attribute_code][] = $attributeValue;
1441 1441
 							} else {
1442
-								$attribute_setted[$attributeType][$attribute_code] = array( $attribute_setted[$attributeType][$attribute_code], $attributeValue );
1442
+								$attribute_setted[$attributeType][$attribute_code] = array($attribute_setted[$attributeType][$attribute_code], $attributeValue);
1443 1443
 							}
1444 1444
 						} else {
1445 1445
 							$attribute_setted[$attributeType][$attribute_code] = $attributeValue;
1446 1446
 						}
1447 1447
 					}
1448 1448
 
1449
-					if ( empty($from) ) {
1450
-						$query = $wpdb->prepare("SELECT value_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.$attributeType . " WHERE attribute_id NOT IN ('" . implode("', '", $sent_attribute_list) . "') AND entity_id = %d AND entity_type_id = %d", $entityId, $entityTypeId);
1449
+					if (empty($from)) {
1450
+						$query = $wpdb->prepare("SELECT value_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType . " WHERE attribute_id NOT IN ('" . implode("', '", $sent_attribute_list) . "') AND entity_id = %d AND entity_type_id = %d", $entityId, $entityTypeId);
1451 1451
 						$attr_to_delete = $wpdb->get_results($query);
1452
-						if(!empty($attr_to_delete)){
1452
+						if (!empty($attr_to_delete)) {
1453 1453
 							foreach ($attr_to_delete as $value) {
1454
-								$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.$attributeType, array_merge($delete_current_attribute_values_params, array('value_id' => $value->value_id)));
1455
-								wpeologs_ctr::log_datas_in_files( 'wpshop_attributes', array(
1454
+								$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($delete_current_attribute_values_params, array('value_id' => $value->value_id)));
1455
+								wpeologs_ctr::log_datas_in_files('wpshop_attributes', array(
1456 1456
 									'object_id' 	=> $entityId,
1457
-									'message' 		=> __( 'Remove the attribute : ' . $value->value_id, 'wpshop' ) ), 0
1457
+									'message' 		=> __('Remove the attribute : ' . $value->value_id, 'wpshop') ), 0
1458 1458
 								);
1459 1459
 							}
1460 1460
 						}
1461 1461
 					}
1462 1462
 				}
1463 1463
 			}
1464
-			do_action( "saved_attribute_for_entity", $attribute_setted, $old_attribute_to_set, $entityTypeId, $entityId );
1464
+			do_action("saved_attribute_for_entity", $attribute_setted, $old_attribute_to_set, $entityTypeId, $entityId);
1465 1465
 		}
1466 1466
 	}
1467 1467
 
@@ -1481,7 +1481,7 @@  discard block
 block discarded – undo
1481 1481
 
1482 1482
 		$query_params = "";
1483 1483
 		$query_params_values = array($attributeId, $entityTypeId, $entityId);
1484
-		if(WPSHOP_ATTRIBUTE_VALUE_PER_USER && (isset($atribute_params['intrinsic']) && ($atribute_params['intrinsic'] != 'yes'))){
1484
+		if (WPSHOP_ATTRIBUTE_VALUE_PER_USER && (isset($atribute_params['intrinsic']) && ($atribute_params['intrinsic'] != 'yes'))) {
1485 1485
 			$query_params = "
1486 1486
 				AND ATTR_VAL.user_id = %d";
1487 1487
 			$query_params_values[] = get_current_user_id();
@@ -1497,20 +1497,20 @@  discard block
 block discarded – undo
1497 1497
 		);
1498 1498
 		$attributeValue = $wpdb->get_results($query);
1499 1499
 
1500
-		if ( ( (count($attributeValue) <= 1 ) && !empty($attributeValue[0]) ) && ( empty($atribute_params['frontend_input']) || ($atribute_params['frontend_input'] != 'multiple-select') )) {
1500
+		if (((count($attributeValue) <= 1) && !empty($attributeValue[0])) && (empty($atribute_params['frontend_input']) || ($atribute_params['frontend_input'] != 'multiple-select'))) {
1501 1501
 			$attributeValue = $attributeValue[0];
1502 1502
 		}
1503
-		else{
1503
+		else {
1504 1504
 			$entity_meta = get_post_meta($entityId, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
1505
-			if ( !empty($entity_meta) ) {
1505
+			if (!empty($entity_meta)) {
1506 1506
 				$query = $wpdb->prepare("SELECT code FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE id = %d AND entity_id = %d ", $attributeId, $entityTypeId);
1507 1507
 				$attribute_code = $wpdb->get_var($query);
1508 1508
 				$attributeValue = !empty($entity_meta[$attribute_code]) ? $entity_meta[$attribute_code] : null;
1509 1509
 			}
1510
-			if ( is_array($attributeValue) ) {
1510
+			if (is_array($attributeValue)) {
1511 1511
 				$tmp_array = array();
1512
-				if ( !empty($attributeValue) ) {
1513
-					foreach ( $attributeValue as $att ) {
1512
+				if (!empty($attributeValue)) {
1513
+					foreach ($attributeValue as $att) {
1514 1514
 						$obj = new stdClass();
1515 1515
 						$obj->value = $att;
1516 1516
 						$obj->unit_id = 0;
@@ -1541,9 +1541,9 @@  discard block
 block discarded – undo
1541 1541
 		$elements = array();
1542 1542
 		$elementsWithAttributeAndValues = self::get_attribute_list_for_item($entityId, $elementId, $language);
1543 1543
 
1544
-		foreach ( $elementsWithAttributeAndValues as $elementDefinition ) {
1544
+		foreach ($elementsWithAttributeAndValues as $elementDefinition) {
1545 1545
 			$arrayKey = $elementDefinition->attribute_id;
1546
-			if ( $keyForArray == 'code' ) {
1546
+			if ($keyForArray == 'code') {
1547 1547
 				$arrayKey = $elementDefinition->attribute_code;
1548 1548
 			}
1549 1549
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['code'] = $elementDefinition->attribute_set_section_code;
@@ -1553,7 +1553,7 @@  discard block
 block discarded – undo
1553 1553
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['backend_table'] = $elementDefinition->backend_table;
1554 1554
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['backend_input'] = $elementDefinition->backend_input;
1555 1555
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['frontend_input'] = $elementDefinition->frontend_input;
1556
-			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['frontend_label'] = __( $elementDefinition->frontend_label, 'wpshop' );
1556
+			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['frontend_label'] = __($elementDefinition->frontend_label, 'wpshop');
1557 1557
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['attribute_code'] = $elementDefinition->attribute_code;
1558 1558
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['data_type_to_use'] = $elementDefinition->data_type_to_use;
1559 1559
 			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['is_visible_in_front'] = $elementDefinition->is_visible_in_front;
@@ -1563,29 +1563,29 @@  discard block
 block discarded – undo
1563 1563
 			$attributeValueField = 'attribute_value_' . $elementDefinition->data_type;
1564 1564
 
1565 1565
 			// Manage the value differently if it is an array or not
1566
-			if ( !empty($elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value']) ) {
1566
+			if (!empty($elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'])) {
1567 1567
 				if (is_array($elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'])) {
1568 1568
 					$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'][] = $elementDefinition->$attributeValueField;
1569 1569
 				}
1570 1570
 				else {
1571
-					$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'] = array($elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'],$elementDefinition->$attributeValueField);
1571
+					$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'] = array($elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'], $elementDefinition->$attributeValueField);
1572 1572
 				}
1573 1573
 			}
1574 1574
 			else {
1575 1575
 				$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['value'] = $elementDefinition->$attributeValueField;
1576 1576
 			}
1577 1577
 
1578
-			if ( $elementDefinition->backend_input == 'multiple-select' ) {
1578
+			if ($elementDefinition->backend_input == 'multiple-select') {
1579 1579
 				$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['select_value'] = self::get_attribute_type_select_option_info($attributeValueField, 'value');
1580 1580
 			}
1581 1581
 
1582 1582
 			$attributeUnitField = 'attribute_unit_' . $elementDefinition->data_type;
1583
-			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['unit'] = __( $elementDefinition->$attributeUnitField, 'wpshop' );
1584
-			if( !empty($elementDefinition->is_requiring_unit ) && ( $elementDefinition->is_requiring_unit == 'yes' ) && empty( $elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['unit'] ) ) {
1583
+			$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['unit'] = __($elementDefinition->$attributeUnitField, 'wpshop');
1584
+			if (!empty($elementDefinition->is_requiring_unit) && ($elementDefinition->is_requiring_unit == 'yes') && empty($elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['unit'])) {
1585 1585
 				$unit = '';
1586
-				$query = $wpdb->prepare( 'SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d AND status = %s', $elementDefinition->_default_unit, 'valid');
1587
-				$unit = $wpdb->get_var( $query );
1588
-				$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['unit'] = __( $unit, 'wpshop' );
1586
+				$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d AND status = %s', $elementDefinition->_default_unit, 'valid');
1587
+				$unit = $wpdb->get_var($query);
1588
+				$elements[$elementId][$elementDefinition->attribute_set_section_name]['attributes'][$arrayKey]['unit'] = __($unit, 'wpshop');
1589 1589
 			}
1590 1590
 
1591 1591
 		}
@@ -1597,7 +1597,7 @@  discard block
 block discarded – undo
1597 1597
 		$elementsWithAttributeAndValues = array();
1598 1598
 		$moreQuery = "";
1599 1599
 
1600
-		$entity_type = empty($defined_entity_type) ? get_post_type( $elementId ) : $defined_entity_type;
1600
+		$entity_type = empty($defined_entity_type) ? get_post_type($elementId) : $defined_entity_type;
1601 1601
 
1602 1602
 		$query = $wpdb->prepare(
1603 1603
 				"SELECT POST_META.*,
@@ -1646,23 +1646,23 @@  discard block
 block discarded – undo
1646 1646
 	 *
1647 1647
 	 * @return boolean The result to know if the element has to be displayed on frontend
1648 1648
 	 */
1649
-	public static function check_attribute_display( $attribute_main_config, $attribute_custom_config, $attribute_or_set, $attribute_code, $output_type) {
1650
-		if ( $attribute_main_config === 'yes' ) {
1649
+	public static function check_attribute_display($attribute_main_config, $attribute_custom_config, $attribute_or_set, $attribute_code, $output_type) {
1650
+		if ($attribute_main_config === 'yes') {
1651 1651
 			$attribute_output = true;
1652
-			if ( ( is_array($attribute_custom_config) && in_array($attribute_or_set, array('attribute', 'attribute_set_section', 'product_action_button')) && !empty($attribute_custom_config[$attribute_or_set]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) && $attribute_custom_config[$attribute_or_set][$attribute_code][$output_type] == 'yes' )
1653
-				 || empty($attribute_custom_config) ) {
1652
+			if ((is_array($attribute_custom_config) && in_array($attribute_or_set, array('attribute', 'attribute_set_section', 'product_action_button')) && !empty($attribute_custom_config[$attribute_or_set]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) && $attribute_custom_config[$attribute_or_set][$attribute_code][$output_type] == 'yes')
1653
+				 || empty($attribute_custom_config)) {
1654 1654
 				$attribute_output = true;
1655 1655
 			}
1656
-			else if ( empty($attribute_custom_config[$attribute_or_set][$attribute_code]) || empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) || (!empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) && ( $attribute_custom_config[$attribute_or_set][$attribute_code][$output_type] == 'no')) )  {
1656
+			else if (empty($attribute_custom_config[$attribute_or_set][$attribute_code]) || empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) || (!empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) && ($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type] == 'no'))) {
1657 1657
 				$attribute_output = false;
1658 1658
 			}
1659 1659
 		}
1660
-		elseif ( $attribute_main_config === 'no' ) {
1660
+		elseif ($attribute_main_config === 'no') {
1661 1661
 			$attribute_output = false;
1662
-			if ( empty($attribute_custom_config[$attribute_or_set]) || empty($attribute_custom_config[$attribute_or_set][$attribute_code]) ) {
1662
+			if (empty($attribute_custom_config[$attribute_or_set]) || empty($attribute_custom_config[$attribute_or_set][$attribute_code])) {
1663 1663
 				$attribute_output = false;
1664 1664
 			}
1665
-			else if ( !empty($attribute_custom_config) && !empty($attribute_custom_config[$attribute_or_set]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) && ( $attribute_custom_config[$attribute_or_set][$attribute_code][$output_type] == 'yes') )  {
1665
+			else if (!empty($attribute_custom_config) && !empty($attribute_custom_config[$attribute_or_set]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code]) && !empty($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type]) && ($attribute_custom_config[$attribute_or_set][$attribute_code][$output_type] == 'yes')) {
1666 1666
 				$attribute_output = true;
1667 1667
 			}
1668 1668
 		}
@@ -1679,22 +1679,22 @@  discard block
 block discarded – undo
1679 1679
 		global $wpdb;
1680 1680
 		global $wp_query;
1681 1681
 
1682
-		$attribute = self::getElement( $atts['attid'] );
1683
-		if(empty($atts['pid'])) $atts['pid'] = $wp_query->posts[0]->ID;
1684
-		$attribute_main_config = ( empty($atts['output_type']) || ($atts['output_type'] == 'complete_sheet') ) ? $attribute->is_visible_in_front : $attribute->is_visible_in_front_listing;
1685
-		$output_type = ( empty($atts['output_type']) || ($atts['output_type'] == 'complete_sheet') ) ? 'complete_sheet' : 'mini_output';
1682
+		$attribute = self::getElement($atts['attid']);
1683
+		if (empty($atts['pid'])) $atts['pid'] = $wp_query->posts[0]->ID;
1684
+		$attribute_main_config = (empty($atts['output_type']) || ($atts['output_type'] == 'complete_sheet')) ? $attribute->is_visible_in_front : $attribute->is_visible_in_front_listing;
1685
+		$output_type = (empty($atts['output_type']) || ($atts['output_type'] == 'complete_sheet')) ? 'complete_sheet' : 'mini_output';
1686 1686
 		$product_attribute_custom_config = get_post_meta($atts['pid'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1687
-		$display_attribute_value = wpshop_attributes::check_attribute_display( $attribute_main_config, $product_attribute_custom_config, 'attribute', $attribute->code, $output_type);
1687
+		$display_attribute_value = wpshop_attributes::check_attribute_display($attribute_main_config, $product_attribute_custom_config, 'attribute', $attribute->code, $output_type);
1688 1688
 
1689
-		if ( !empty( $attribute->data_type ) ) {
1689
+		if (!empty($attribute->data_type)) {
1690 1690
 			$attributeDefinition['unit'] = '';
1691 1691
 
1692 1692
 			$has_value = false;
1693
-			$query = $wpdb->prepare("SELECT value FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attribute->data_type . " WHERE entity_id=%s AND attribute_id=%d", $atts['pid'], $atts['attid'] );
1694
-			if ( in_array($attribute->backend_input, array('multiple-select', 'checkbox')) ) {
1693
+			$query = $wpdb->prepare("SELECT value FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attribute->data_type . " WHERE entity_id=%s AND attribute_id=%d", $atts['pid'], $atts['attid']);
1694
+			if (in_array($attribute->backend_input, array('multiple-select', 'checkbox'))) {
1695 1695
 				$list_of_value = $wpdb->get_results($query);
1696
-				if ( !empty($list_of_value) ) {
1697
-					foreach ( $list_of_value as $value ) {
1696
+				if (!empty($list_of_value)) {
1697
+					foreach ($list_of_value as $value) {
1698 1698
 						$data[] = $value->value;
1699 1699
 					}
1700 1700
 					$has_value = true;
@@ -1702,10 +1702,10 @@  discard block
 block discarded – undo
1702 1702
 			}
1703 1703
 			else {
1704 1704
 				$data = $wpdb->get_var($query);
1705
-				if ( !empty($data) ) {
1705
+				if (!empty($data)) {
1706 1706
 					$has_value = true;
1707 1707
 				}
1708
-				elseif( !empty($attribute->default_value) ) {
1708
+				elseif (!empty($attribute->default_value)) {
1709 1709
 					$has_value = true;
1710 1710
 					$data = $attribute->default_value;
1711 1711
 				}
@@ -1717,7 +1717,7 @@  discard block
 block discarded – undo
1717 1717
 			$attributeDefinition['is_requiring_unit'] = $attribute->is_requiring_unit;
1718 1718
 			$attributeDefinition['backend_input'] = $attribute->backend_input;
1719 1719
 			$attributeDefinition['data_type_to_use'] = $attribute->data_type_to_use;
1720
-			$attribute_display = wpshop_attributes::wps_attribute_values_display( $attributeDefinition );
1720
+			$attribute_display = wpshop_attributes::wps_attribute_values_display($attributeDefinition);
1721 1721
 			$attribute_value = $attribute_display[0];
1722 1722
 			$attributeDefinition['value'] = $attribute_display[1];
1723 1723
 			$attribute_unit_list = $attribute_display[2];
@@ -1737,13 +1737,13 @@  discard block
 block discarded – undo
1737 1737
 	 * @param array $specific_argument Optionnal The different parameters used for filter output
1738 1738
 	 * @return array The definition for the field used to display an attribute
1739 1739
 	 */
1740
-	public static function get_attribute_field_definition( $attribute, $attribute_value = '', $specific_argument = array() ) {
1740
+	public static function get_attribute_field_definition($attribute, $attribute_value = '', $specific_argument = array()) {
1741 1741
 		global $wpdb;
1742 1742
 		$wpshop_price_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
1743 1743
 		$wpshop_weight_attributes = unserialize(WPSHOP_ATTRIBUTE_WEIGHT);
1744 1744
 		$input_def = array();
1745 1745
 		$input_def['option'] = $input_def['field_container_class'] = '';
1746
-		$attributeInputDomain = (!empty($specific_argument['field_custom_name_prefix']) || (!empty($specific_argument['field_custom_name_prefix']) && ($specific_argument['field_custom_name_prefix'] == 'empty')) ) ? $specific_argument['field_custom_name_prefix'] : ((!empty($specific_argument['page_code']) ? $specific_argument['page_code'] . '_' : '' ) . 'attribute[' . $attribute->data_type . ']');
1746
+		$attributeInputDomain = (!empty($specific_argument['field_custom_name_prefix']) || (!empty($specific_argument['field_custom_name_prefix']) && ($specific_argument['field_custom_name_prefix'] == 'empty'))) ? $specific_argument['field_custom_name_prefix'] : ((!empty($specific_argument['page_code']) ? $specific_argument['page_code'] . '_' : '') . 'attribute[' . $attribute->data_type . ']');
1747 1747
 		$input_def['input_domain'] = $attributeInputDomain;
1748 1748
 		$input_def['id'] = (!empty($specific_argument) && !empty($specific_argument['field_id']) ? $specific_argument['field_id'] . '_' : '') . 'attribute_' . $attribute->id;
1749 1749
 		$input_def['intrinsec'] = $attribute->is_intrinsic;
@@ -1763,26 +1763,26 @@  discard block
 block discarded – undo
1763 1763
 		$input_def['frontend_type'] = $attribute->frontend_input;
1764 1764
 		$input_def['is_used_in_quick_add_form'] = $attribute->is_used_in_quick_add_form;
1765 1765
 
1766
-		if ( !empty($attribute_value) && !is_object($attribute_value) ) {
1766
+		if (!empty($attribute_value) && !is_object($attribute_value)) {
1767 1767
 			$input_def['value'] = $attribute_value;
1768 1768
 		}
1769
-		else if ( !empty($attribute_value->value) ) {
1769
+		else if (!empty($attribute_value->value)) {
1770 1770
 			$input_def['value'] = stripslashes($attribute_value->value);
1771 1771
 		}
1772
-		else if ( !empty($specific_argument['element_identifier']) && empty($attribute_value) && (get_post_status($specific_argument['element_identifier']) != 'auto-draft') ) {
1772
+		else if (!empty($specific_argument['element_identifier']) && empty($attribute_value) && (get_post_status($specific_argument['element_identifier']) != 'auto-draft')) {
1773 1773
 			$input_def['value'] = '';
1774 1774
 		}
1775 1775
 
1776 1776
 		$input_def['options'] = '';
1777 1777
 		$input_more_class = !empty($specific_argument['input_class']) ? $specific_argument['input_class'] : '';
1778 1778
 		if ($attribute->data_type == 'datetime') {
1779
-			$date_config = unserialize( $attribute->default_value );
1779
+			$date_config = unserialize($attribute->default_value);
1780 1780
 			if ((($date_config['default_value'] == '') || ($date_config['default_value'] == 'date_of_current_day')) && ($date_config['default_value'] == 'date_of_current_day')) {
1781 1781
 				$input_def['value'] = date('Y-m-d');
1782 1782
 			}
1783 1783
 			else {
1784 1784
 				/**	Modification due to a message on eoxia forum: http://www.eoxia.com/forums/topic/bug-attribut-de-type-date-dans-fiche-produit-admin/	*/
1785
-				$input_def['value'] = !empty($attribute_value->value) && is_string($attribute_value->value) ? str_replace( " 00:00:00", "", $attribute_value->value ) : ( !empty($attribute_value) && is_string($attribute_value) ? str_replace( " 00:00:00", "", $attribute_value ) : '' );
1785
+				$input_def['value'] = !empty($attribute_value->value) && is_string($attribute_value->value) ? str_replace(" 00:00:00", "", $attribute_value->value) : (!empty($attribute_value) && is_string($attribute_value) ? str_replace(" 00:00:00", "", $attribute_value) : '');
1786 1786
 			}
1787 1787
 			$input_more_class .= ' wpshop_input_datetime ';
1788 1788
 			$field_script = '<script type="text/javascript" >
@@ -1795,31 +1795,31 @@  discard block
 block discarded – undo
1795 1795
 		wpshop("#' . $input_def['id'] . '").datepicker("option", "navigationAsDateFormat", true);
1796 1796
 		wpshop("#' . $input_def['id'] . '").val("' . str_replace(" 00:00:00", "", $input_def['value']) . '");';
1797 1797
 
1798
-			if ( !empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']) ) {
1799
-				if ( !empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0]) ) {
1798
+			if (!empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur'])) {
1799
+				if (!empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0])) {
1800 1800
 					$field_script .= '
1801 1801
 		wpshop("#' . $input_def['id'] . '").datepicker("option", "minDate", "' . $date_config['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0] . '");';
1802 1802
 				}
1803
-				if ( !empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0]) ) {
1803
+				if (!empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0])) {
1804 1804
 					$field_script .= '
1805 1805
 		wpshop("#' . $input_def['id'] . '").datepicker("option", "maxDate", "' . $date_config['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0] . '");';
1806 1806
 				}
1807 1807
 			}
1808 1808
 
1809 1809
 			$script_options = $script_options_params = array();
1810
-			if ( !empty($date_config['field_options']['attribute_type_date_options_day_to_show']) ) {
1810
+			if (!empty($date_config['field_options']['attribute_type_date_options_day_to_show'])) {
1811 1811
 				$day_to_show_list = '    ';
1812
-				foreach ( $date_config['field_options']['attribute_type_date_options_day_to_show'] as $day_to_show ) {
1812
+				foreach ($date_config['field_options']['attribute_type_date_options_day_to_show'] as $day_to_show) {
1813 1813
 					$day_to_show_list .= '(date.getDay() == ' . $day_to_show . ') || ';
1814 1814
 				}
1815 1815
 				$script_options[] = '( ' . substr($day_to_show_list, 0, -4) . ' )';
1816 1816
 			}
1817 1817
 
1818
-			if ( !empty($date_config['field_options']['attribute_type_date_options_available_date_type'][0]) ) {
1819
-				if ( !empty($date_config['field_options']['attribute_type_date_options_available_date']) ) {
1818
+			if (!empty($date_config['field_options']['attribute_type_date_options_available_date_type'][0])) {
1819
+				if (!empty($date_config['field_options']['attribute_type_date_options_available_date'])) {
1820 1820
 					$available_date = ' ';
1821
-					foreach ( $date_config['field_options']['attribute_type_date_options_available_date'] as $avalaible_date_list ) {
1822
-						if ( !empty($avalaible_date_list) ) {
1821
+					foreach ($date_config['field_options']['attribute_type_date_options_available_date'] as $avalaible_date_list) {
1822
+						if (!empty($avalaible_date_list)) {
1823 1823
 							$available_date .= '"' . $avalaible_date_list . '",';
1824 1824
 						}
1825 1825
 					}
@@ -1828,7 +1828,7 @@  discard block
 block discarded – undo
1828 1828
 				}
1829 1829
 			}
1830 1830
 
1831
-			if ( !empty( $script_options ) ) {
1831
+			if (!empty($script_options)) {
1832 1832
 				$field_script .= '
1833 1833
 		wpshop("#' . $input_def['id'] . '").datepicker("option", "beforeShowDay", function(date){
1834 1834
 			' . implode(' ', $script_options_params) . ';
@@ -1856,37 +1856,37 @@  discard block
 block discarded – undo
1856 1856
 </script>';
1857 1857
 			$input_def['options'] .= $field_script;
1858 1858
 		}
1859
-		if ( in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'))) {
1860
-			$input_more_class .= (!empty($specific_argument['no_chosen']) ? '' : ' chosen_select ' );
1859
+		if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'))) {
1860
+			$input_more_class .= (!empty($specific_argument['no_chosen']) ? '' : ' chosen_select ');
1861 1861
 			$input_def['type'] = ((!empty($specific_argument['from']) && ($specific_argument['from'] == 'frontend')) || (!is_admin() && empty($specific_argument['from'])) ? $attribute->frontend_input : $attribute->backend_input);
1862 1862
 			$input_def['valueToPut'] = 'index';
1863 1863
 
1864 1864
 			$select_display = self::get_select_output($attribute, $specific_argument);
1865
-			if ( empty( $input_def[ 'options_label' ] ) && !empty( $specific_argument ) && (!empty($specific_argument['from']) && ($specific_argument['from'] == 'frontend') ) ) {
1866
-				$input_def[ 'options_label' ][ 'original' ] = true;
1865
+			if (empty($input_def['options_label']) && !empty($specific_argument) && (!empty($specific_argument['from']) && ($specific_argument['from'] == 'frontend'))) {
1866
+				$input_def['options_label']['original'] = true;
1867 1867
 			}
1868 1868
 			$input_def['options'] .= $select_display['more_input'];
1869 1869
 			$input_def['possible_value'] = (!empty($select_display) && !empty($select_display['possible_value'])) ? $select_display['possible_value'] : '';
1870
-			if ( !is_admin() ) {
1870
+			if (!is_admin()) {
1871 1871
 				$input_def['options'] .= '<input type="hidden" value="' . str_replace("\\", "", $input_def['value']) . '" name="wpshop_product_attribute_' . $attribute->code . '_current_value" id="wpshop_product_attribute_' . $attribute->code . '_current_value" />';
1872 1872
 			}
1873
-			if ( in_array($attribute->backend_input, array('multiple-select', 'checkbox')) && is_admin() && (empty($specific_argument['from']) || ($specific_argument['from'] != 'frontend')) ) {
1874
-				$input_def['options'] .= wpshop_display::display_template_element('select_list_multiple_bulk_action', array( 'CURRENT_ATTRIBUTE_ID' => $input_def['id'], 'CURRENT_ATTRIBUTE_CODE' => $attribute->code), array(), 'admin');
1873
+			if (in_array($attribute->backend_input, array('multiple-select', 'checkbox')) && is_admin() && (empty($specific_argument['from']) || ($specific_argument['from'] != 'frontend'))) {
1874
+				$input_def['options'] .= wpshop_display::display_template_element('select_list_multiple_bulk_action', array('CURRENT_ATTRIBUTE_ID' => $input_def['id'], 'CURRENT_ATTRIBUTE_CODE' => $attribute->code), array(), 'admin');
1875 1875
 			}
1876 1876
 		}
1877 1877
 		$input_def['label_pointer'] = 'for="' . $input_def['id'] . '"';
1878
-		if(($input_def['type'] == 'radio') || ($input_def['type'] == 'checkbox')){
1878
+		if (($input_def['type'] == 'radio') || ($input_def['type'] == 'checkbox')) {
1879 1879
 			$input_def['label_pointer'] = '';
1880 1880
 		}
1881 1881
 
1882 1882
 		/*
1883 1883
 		 * Specifc treatment for price attributes
1884 1884
 		 */
1885
-		if((WPSHOP_PRODUCT_PRICE_PILOT == 'HT') && ($attribute->code == WPSHOP_PRODUCT_PRICE_TTC) ){
1885
+		if ((WPSHOP_PRODUCT_PRICE_PILOT == 'HT') && ($attribute->code == WPSHOP_PRODUCT_PRICE_TTC)) {
1886 1886
 			$input_def['option'] .= ' readonly="readonly" ';
1887 1887
 			$input_more_class .= ' wpshop_prices_readonly';
1888 1888
 		}
1889
-		elseif((WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') && ($attribute->code == WPSHOP_PRODUCT_PRICE_HT) ){
1889
+		elseif ((WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') && ($attribute->code == WPSHOP_PRODUCT_PRICE_HT)) {
1890 1890
 			$input_def['option'] .= ' readonly="readonly" ';
1891 1891
 			$input_more_class .= ' wpshop_prices_readonly';
1892 1892
 		}
@@ -1897,7 +1897,7 @@  discard block
 block discarded – undo
1897 1897
 
1898 1898
 		$input_def['label'] = str_replace("\\", "", $input_def['label']);
1899 1899
 // 		$input_def['value'] = str_replace("\\", "", $input_def['value']);
1900
-		$input_def['option'] .= ' class="wpshop_product_attribute_' . $attribute->code . $input_more_class . ' ' . (( is_admin() ) ? $attribute->backend_css_class : $attribute->frontend_css_class) . ( !empty($attribute->frontend_verification) ? ' wps_attr_verification_' . $attribute->frontend_verification : '' ) . '" ';
1900
+		$input_def['option'] .= ' class="wpshop_product_attribute_' . $attribute->code . $input_more_class . ' ' . ((is_admin()) ? $attribute->backend_css_class : $attribute->frontend_css_class) . (!empty($attribute->frontend_verification) ? ' wps_attr_verification_' . $attribute->frontend_verification : '') . '" ';
1901 1901
 		$input_def['title'] = !empty($attribute->frontend_help_message) ? ' title="' . $attribute->frontend_help_message . '" ' : '';
1902 1902
 
1903 1903
 		if (($attribute->is_intrinsic == 'yes') && ((!empty($input_def['value'])) || ($input_def['value'] > 0))) {
@@ -1908,13 +1908,13 @@  discard block
 block discarded – undo
1908 1908
 		 * Add the unit to the attribute if attribute configuration is set to yes
1909 1909
 		 */
1910 1910
 		if ($attribute->is_requiring_unit == 'yes') {
1911
-			if ( in_array($attribute->code, $wpshop_price_attributes) || ( WPSHOP_COST_OF_POSTAGE == $attribute->code) ) {
1911
+			if (in_array($attribute->code, $wpshop_price_attributes) || (WPSHOP_COST_OF_POSTAGE == $attribute->code)) {
1912 1912
 				$input_def['options'] .= '&nbsp;<span class="attribute_currency" id="attribute_currency_' . $attribute->id . '" >' . wpshop_tools::wpshop_get_currency() . '</span>';
1913 1913
 			}
1914
-			elseif ( in_array($attribute->code, $wpshop_weight_attributes) ) {
1914
+			elseif (in_array($attribute->code, $wpshop_weight_attributes)) {
1915 1915
 				$weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity');
1916
-				$query = $wpdb->prepare('SELECT name FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
1917
-				$unity = $wpdb->get_var( $query );
1916
+				$query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
1917
+				$unity = $wpdb->get_var($query);
1918 1918
 				$input_def['options'] .= '&nbsp;<span class="attribute_weight" id="attribute_weight_' . $attribute->id . '" >' . __($unity, 'wpshop') . '</span>';
1919 1919
 			}
1920 1920
 			else {
@@ -1922,11 +1922,11 @@  discard block
 block discarded – undo
1922 1922
 				$unit_input_def['possible_value'] = wpshop_attributes_unit::get_unit_list_for_group($attribute->_unit_group_id);
1923 1923
 				$unit_input_def['type'] = 'select';
1924 1924
 				$unit_input_def['option'] = ' class="wpshop_attribute_unit_input chosen_select" ';
1925
-				$unit_input_def['id'] = ( !empty($specific_argument['page_code']) ? $specific_argument['page_code'] : null ) . '_' . ( !empty($specific_argument['element_identifier']) ? $specific_argument['element_identifier'] : null ) . '_unit_attribute_' . $attribute->id;
1925
+				$unit_input_def['id'] = (!empty($specific_argument['page_code']) ? $specific_argument['page_code'] : null) . '_' . (!empty($specific_argument['element_identifier']) ? $specific_argument['element_identifier'] : null) . '_unit_attribute_' . $attribute->id;
1926 1926
 				$unit_input_def['name'] = $attribute->code;
1927 1927
 				$unit_input_def['value'] = (!empty($attribute_value->unit_id) ? $attribute_value->unit_id : '');
1928
-				if($unit_input_def['value'] == ''){
1929
-					if ( $attribute->_default_unit > 0 ) {
1928
+				if ($unit_input_def['value'] == '') {
1929
+					if ($attribute->_default_unit > 0) {
1930 1930
 						$unit_input_def['value'] = $attribute->_default_unit;
1931 1931
 					}
1932 1932
 					else {
@@ -1940,18 +1940,18 @@  discard block
 block discarded – undo
1940 1940
 		/*
1941 1941
 		 * Add indication on postage cost tax
1942 1942
 		 */
1943
-		if ( $attribute->code == WPSHOP_COST_OF_POSTAGE ) {
1943
+		if ($attribute->code == WPSHOP_COST_OF_POSTAGE) {
1944 1944
 			$input_def['options'] .= ' <span class="attribute_currency" >' . __('ATI', 'wpshop') . '</span>';
1945 1945
 		}
1946 1946
 
1947 1947
 		/*
1948 1948
 		 * Create the field output
1949 1949
 		 */
1950
-		if ( is_admin() && ($attribute->data_type == 'datetime') && ($attribute->is_user_defined == 'yes') && (empty($specific_argument['from']) || ($specific_argument['from'] != 'frontend')) ) {
1951
-			$input_def['output'] = sprintf(__('You select this field to be defined by final customer into frontend part. To change this behaviour you have to change attribute option "%s"', 'wpshop'),__('is_user_defined', 'wpshop'));
1950
+		if (is_admin() && ($attribute->data_type == 'datetime') && ($attribute->is_user_defined == 'yes') && (empty($specific_argument['from']) || ($specific_argument['from'] != 'frontend'))) {
1951
+			$input_def['output'] = sprintf(__('You select this field to be defined by final customer into frontend part. To change this behaviour you have to change attribute option "%s"', 'wpshop'), __('is_user_defined', 'wpshop'));
1952 1952
 			$input_def['options'] = '';
1953 1953
 			$input_def['label_pointer'] = '';
1954
-			$input_def['option'] = substr( $input_def['option'], 0 , -2 ) . ' wpshop_attributes_is_user_defined_admin_field "';
1954
+			$input_def['option'] = substr($input_def['option'], 0, -2) . ' wpshop_attributes_is_user_defined_admin_field "';
1955 1955
 			$input_def['field_container_class'] .= 'wpshop_attributes_is_user_defined_admin_container';
1956 1956
 		}
1957 1957
 		else {
@@ -1966,7 +1966,7 @@  discard block
 block discarded – undo
1966 1966
 	 * @param string $output_from
1967 1967
 	 * @return string The output for
1968 1968
 	 */
1969
-	public static function display_attribute( $attribute_code, $output_from = 'admin', $output_specs = array() ) {
1969
+	public static function display_attribute($attribute_code, $output_from = 'admin', $output_specs = array()) {
1970 1970
 		$output = '';
1971 1971
 		/*	Get the page code	*/
1972 1972
 		$currentPageCode = !empty($output_specs['page_code']) ? $output_specs['page_code'] : '';
@@ -1977,17 +1977,17 @@  discard block
 block discarded – undo
1977 1977
 
1978 1978
 		/*	Get attribute input definition	*/
1979 1979
 		$current_value = (!empty($output_specs['current_value']) ? $output_specs['current_value'] : '');
1980
-		$input = wpshop_attributes::get_attribute_field_definition( $attribute_def, $current_value, array_merge($output_specs, array('input_class' => ' wpshop_attributes_display', 'from' => $output_from)) );
1980
+		$input = wpshop_attributes::get_attribute_field_definition($attribute_def, $current_value, array_merge($output_specs, array('input_class' => ' wpshop_attributes_display', 'from' => $output_from)));
1981 1981
 
1982 1982
 		/*	Create default output	*/
1983 1983
 		$input_to_display = $input['output'] . $input['options'];
1984 1984
 
1985 1985
 		/*	Check if current field is linked to an addon, and if the addon is activated	*/
1986 1986
 		$addons_list = unserialize(WPSHOP_ADDONS_LIST);
1987
-		foreach ( $addons_list as $addon_code => $addon_def ) {
1988
-			if ( in_array($attribute_code, $addon_def) ) {
1989
-				if ( constant($addon_code) === false ) {
1990
-					$input_to_display = '<a href="' . admin_url('options-general.php?page=wpshop_option#wpshop_addons_option') . '" >' . __("This addon isn't activated, click to activate",'wpshop') . '</a>';
1987
+		foreach ($addons_list as $addon_code => $addon_def) {
1988
+			if (in_array($attribute_code, $addon_def)) {
1989
+				if (constant($addon_code) === false) {
1990
+					$input_to_display = '<a href="' . admin_url('options-general.php?page=wpshop_option#wpshop_addons_option') . '" >' . __("This addon isn't activated, click to activate", 'wpshop') . '</a>';
1991 1991
 				}
1992 1992
 			}
1993 1993
 		}
@@ -2012,11 +2012,11 @@  discard block
 block discarded – undo
2012 2012
 		/*
2013 2013
 		 * Display attribute option if applicable
2014 2014
 		 */
2015
-		if ( $output_from == 'admin') {
2016
-			$attribute_option_display = $attribute_def->backend_input=='select' && (strtolower( __(self::get_attribute_type_select_option_info($input['value'], 'value'), 'wpshop') ) == strtolower(__('yes', 'wpshop'))) ? '' : ' wpshopHide';
2015
+		if ($output_from == 'admin') {
2016
+			$attribute_option_display = $attribute_def->backend_input == 'select' && (strtolower(__(self::get_attribute_type_select_option_info($input['value'], 'value'), 'wpshop')) == strtolower(__('yes', 'wpshop'))) ? '' : ' wpshopHide';
2017 2017
 
2018 2018
 			$output['field'] .= '
2019
-	<div class="attribute_option_'.$attribute_def->code.''.$attribute_option_display.'">'.self::get_attribute_option_fields($element_identifier, $attribute_def->code).'</div>';
2019
+	<div class="attribute_option_'.$attribute_def->code . '' . $attribute_option_display . '">' . self::get_attribute_option_fields($element_identifier, $attribute_def->code) . '</div>';
2020 2020
 		}
2021 2021
 
2022 2022
 		$output['field'] .= '</div>';
@@ -2034,36 +2034,36 @@  discard block
 block discarded – undo
2034 2034
 	 *
2035 2035
 	 * @return string The html code to output directly tabs
2036 2036
 	 */
2037
-	public static function attribute_of_entity_to_tab( $element_code, $element_id, $element_definition ) {
2037
+	public static function attribute_of_entity_to_tab($element_code, $element_id, $element_definition) {
2038 2038
 		$attributeContentOutput = '';
2039 2039
 
2040 2040
 		/**	Get the different attribute affected to the entity	*/
2041 2041
 		$element_atribute_list = wpshop_attributes::getElementWithAttributeAndValue($element_code, $element_id, WPSHOP_CURRENT_LOCALE, '', 'frontend');
2042 2042
 
2043 2043
 
2044
-		if ( is_array($element_atribute_list) && (count($element_atribute_list) > 0) ) {
2045
-			foreach ( $element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent ) {
2044
+		if (is_array($element_atribute_list) && (count($element_atribute_list) > 0)) {
2045
+			foreach ($element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent) {
2046 2046
 				$attributeToShowNumber = 0;
2047 2047
 				$attributeOutput = '';
2048 2048
 
2049
-				foreach ( $attributeSetContent['attributes'] as $attributeId => $attributeDefinition ) {
2049
+				foreach ($attributeSetContent['attributes'] as $attributeId => $attributeDefinition) {
2050 2050
 
2051 2051
 					/**	Check the value type to check if empty or not	*/
2052
-					if ( $attributeDefinition['data_type'] == 'int' ) {
2052
+					if ($attributeDefinition['data_type'] == 'int') {
2053 2053
 						$attributeDefinition['value'] = (int)$attributeDefinition['value'];
2054 2054
 					}
2055
-					else if ( $attributeDefinition['data_type'] == 'decimal' ) {
2055
+					else if ($attributeDefinition['data_type'] == 'decimal') {
2056 2056
 						$attributeDefinition['value'] = (float)$attributeDefinition['value'];
2057 2057
 					}
2058 2058
 
2059 2059
 					/** Check if the attribute is set to be displayed in frontend	*/
2060
-					$attribute_display_state = wpshop_attributes::check_attribute_display( $attributeDefinition['is_visible_in_front'], $element_definition['custom_display'], 'attribute', $attributeDefinition['code'], 'complete_sheet');
2060
+					$attribute_display_state = wpshop_attributes::check_attribute_display($attributeDefinition['is_visible_in_front'], $element_definition['custom_display'], 'attribute', $attributeDefinition['code'], 'complete_sheet');
2061 2061
 
2062 2062
 					/**	Output the field if the value is not null	*/
2063 2063
 
2064
-					if ( (is_array($attributeDefinition['value']) || ( !empty($attributeDefinition['value']) ) ) && $attribute_display_state) {
2064
+					if ((is_array($attributeDefinition['value']) || (!empty($attributeDefinition['value']))) && $attribute_display_state) {
2065 2065
 
2066
-						$attribute_display = wpshop_attributes::wps_attribute_values_display( $attributeDefinition );
2066
+						$attribute_display = wpshop_attributes::wps_attribute_values_display($attributeDefinition);
2067 2067
 						$attribute_value = $attribute_display[0];
2068 2068
 						$attributeDefinition['value'] = $attribute_display[1];
2069 2069
 						$attribute_unit_list = $attribute_display[2];
@@ -2074,8 +2074,8 @@  discard block
 block discarded – undo
2074 2074
 						$tpl_component['PDT_ENTITY_CODE'] = self::currentPageCode;
2075 2075
 						$tpl_component['ATTRIBUTE_CODE'] = $attributeDefinition['attribute_code'];
2076 2076
 						$tpl_component['ATTRIBUTE_LABEL'] = __($attributeDefinition['frontend_label'], 'wpshop');
2077
-						$tpl_component['ATTRIBUTE_VALUE'] = (  !is_array($attribute_value) ) ? stripslashes($attribute_value) : $attribute_value;
2078
-						$tpl_component['ATTRIBUTE_VALUE_UNIT'] =  $attribute_unit_list;
2077
+						$tpl_component['ATTRIBUTE_VALUE'] = (!is_array($attribute_value)) ? stripslashes($attribute_value) : $attribute_value;
2078
+						$tpl_component['ATTRIBUTE_VALUE_UNIT'] = $attribute_unit_list;
2079 2079
 
2080 2080
 						/** Build template	*/
2081 2081
 						$attributeOutput .= wpshop_display::display_template_element($template_part, $tpl_component);
@@ -2086,9 +2086,9 @@  discard block
 block discarded – undo
2086 2086
 				}
2087 2087
 
2088 2088
 				/** Check if the attribute set section is set to be displayed in frontend	*/
2089
-				$attribute_set_display_state = wpshop_attributes::check_attribute_display( $attributeSetContent['display_on_frontend'], $element_definition['custom_display'], 'attribute_set_section', $attributeSetContent['code'], 'complete_sheet');
2089
+				$attribute_set_display_state = wpshop_attributes::check_attribute_display($attributeSetContent['display_on_frontend'], $element_definition['custom_display'], 'attribute_set_section', $attributeSetContent['code'], 'complete_sheet');
2090 2090
 
2091
-				if ( !$attribute_set_display_state ) {
2091
+				if (!$attribute_set_display_state) {
2092 2092
 					$attributeToShowNumber = 0;
2093 2093
 					$attributeOutput = '';
2094 2094
 				}
@@ -2098,8 +2098,8 @@  discard block
 block discarded – undo
2098 2098
 
2099 2099
 			/** Gestion de l'affichage	*/
2100 2100
 			$tab_list = $content_list = '';
2101
-			foreach ( $element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent ) {
2102
-				if ( !empty($attributeSetContent['count']) > 0 ) {
2101
+			foreach ($element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent) {
2102
+				if (!empty($attributeSetContent['count']) > 0) {
2103 2103
 					/** Template parameters	*/
2104 2104
 					$template_part = 'product_attribute_tabs';
2105 2105
 					$tpl_component = array();
@@ -2108,7 +2108,7 @@  discard block
 block discarded – undo
2108 2108
 
2109 2109
 					/** Build template	*/
2110 2110
 					$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2111
-					if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
2111
+					if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2112 2112
 						/*	Include the old way template part	*/
2113 2113
 						ob_start();
2114 2114
 						require(wpshop_display::get_template_file($tpl_way_to_take[1]));
@@ -2128,7 +2128,7 @@  discard block
 block discarded – undo
2128 2128
 
2129 2129
 					/** Build template	*/
2130 2130
 					$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2131
-					if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
2131
+					if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2132 2132
 						/*	Include the old way template part	*/
2133 2133
 						ob_start();
2134 2134
 						require(wpshop_display::get_template_file($tpl_way_to_take[1]));
@@ -2142,16 +2142,16 @@  discard block
 block discarded – undo
2142 2142
 				}
2143 2143
 			}
2144 2144
 
2145
-			if ( $tab_list != '' ) {
2145
+			if ($tab_list != '') {
2146 2146
 				/** Template parameters	*/
2147 2147
 				$template_part = 'product_attribute_container';
2148 2148
 				$tpl_component = array();
2149
-				$tpl_component['PDT_TABS'] = apply_filters( 'wpshop_extra_tabs_menu_before', '' ).$tab_list.apply_filters( 'wpshop_extra_tabs_menu_after', '' );
2150
-				$tpl_component['PDT_TAB_DETAIL'] = apply_filters( 'wpshop_extra_tabs_content_before', '' ).$content_list.apply_filters( 'wpshop_extra_tabs_content_after', '' );
2149
+				$tpl_component['PDT_TABS'] = apply_filters('wpshop_extra_tabs_menu_before', '') . $tab_list . apply_filters('wpshop_extra_tabs_menu_after', '');
2150
+				$tpl_component['PDT_TAB_DETAIL'] = apply_filters('wpshop_extra_tabs_content_before', '') . $content_list . apply_filters('wpshop_extra_tabs_content_after', '');
2151 2151
 
2152 2152
 				/** Build template	*/
2153 2153
 				$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2154
-				if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
2154
+				if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2155 2155
 					/*	Include the old way template part	*/
2156 2156
 					ob_start();
2157 2157
 					require(wpshop_display::get_template_file($tpl_way_to_take[1]));
@@ -2174,9 +2174,9 @@  discard block
 block discarded – undo
2174 2174
 	 * @param unknown_type $attributeDefinition
2175 2175
 	 * @return multitype:Ambigous <unknown, string> Ambigous <string, string> Ambigous <>
2176 2176
 	 */
2177
-	public static function wps_attribute_values_display( $attributeDefinition ) {
2177
+	public static function wps_attribute_values_display($attributeDefinition) {
2178 2178
 		$attribute_unit_list = '';
2179
-		if ( !empty($attributeDefinition['unit']) ) {
2179
+		if (!empty($attributeDefinition['unit'])) {
2180 2180
 			/** Template parameters	*/
2181 2181
 			$template_part = 'product_attribute_unit';
2182 2182
 			$tpl_component = array();
@@ -2188,31 +2188,31 @@  discard block
 block discarded – undo
2188 2188
 		}
2189 2189
 
2190 2190
 		$attribute_value = $attributeDefinition['value'];
2191
-		if ( $attributeDefinition['data_type'] == 'decimal' ) {
2192
-			$attribute_value =(is_numeric($attribute_value) ) ? number_format($attribute_value, 2, ',', '') : $attribute_value;
2193
-			if ( in_array($attributeDefinition['code'], unserialize(WPSHOP_ATTRIBUTE_PRICES)) ) {
2194
-				if ( $attributeDefinition['is_requiring_unit'] == 'yes' ) {
2191
+		if ($attributeDefinition['data_type'] == 'decimal') {
2192
+			$attribute_value = (is_numeric($attribute_value)) ? number_format($attribute_value, 2, ',', '') : $attribute_value;
2193
+			if (in_array($attributeDefinition['code'], unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
2194
+				if ($attributeDefinition['is_requiring_unit'] == 'yes') {
2195 2195
 					$attribute_unit_list = ' ' . wpshop_tools::wpshop_get_currency();
2196 2196
 				}
2197 2197
 				$attributeDefinition['value'] = wpshop_display::format_field_output('wpshop_product_price', $attributeDefinition['value']);
2198 2198
 			}
2199 2199
 		}
2200
-		if ( $attributeDefinition['data_type'] == 'datetime' ) {
2200
+		if ($attributeDefinition['data_type'] == 'datetime') {
2201 2201
 			$attribute_value = mysql2date('d/m/Y', $attributeDefinition['value'], true);
2202 2202
 		}
2203
-		if ( $attributeDefinition['backend_input'] == 'select' ) {
2203
+		if ($attributeDefinition['backend_input'] == 'select') {
2204 2204
 			$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attributeDefinition['value'], 'label', $attributeDefinition['data_type_to_use']);
2205 2205
 		}
2206 2206
 		/** Manage differently if its an array of values or not	*/
2207
-		if ( $attributeDefinition['backend_input'] == 'multiple-select') {
2207
+		if ($attributeDefinition['backend_input'] == 'multiple-select') {
2208 2208
 			$attribute_value = '';
2209
-			if ( is_array($attributeDefinition['value']) ) {
2209
+			if (is_array($attributeDefinition['value'])) {
2210 2210
 				foreach ($attributeDefinition['value'] as $v) {
2211
-					$attribute_value .= ' / '.wpshop_attributes::get_attribute_type_select_option_info($v, 'label', $attributeDefinition['data_type_to_use']);
2211
+					$attribute_value .= ' / ' . wpshop_attributes::get_attribute_type_select_option_info($v, 'label', $attributeDefinition['data_type_to_use']);
2212 2212
 				}
2213 2213
 			}
2214
-			else $attribute_value = ' / '.wpshop_attributes::get_attribute_type_select_option_info($attributeDefinition['value'], 'label', $attributeDefinition['data_type_to_use']);
2215
-			$attribute_value = substr($attribute_value,3);
2214
+			else $attribute_value = ' / ' . wpshop_attributes::get_attribute_type_select_option_info($attributeDefinition['value'], 'label', $attributeDefinition['data_type_to_use']);
2215
+			$attribute_value = substr($attribute_value, 3);
2216 2216
 		}
2217 2217
 
2218 2218
 		return array($attribute_value, $attributeDefinition['value'], $attribute_unit_list);
@@ -2222,13 +2222,13 @@  discard block
 block discarded – undo
2222 2222
 	 * Manage display for the output when user uses a shortcode for attributes display
2223 2223
 	 * @param array $shorcode_args The list of argument passed through the shortcode
2224 2224
 	 */
2225
-	function wpshop_attributes_shortcode( $shorcode_args ) {
2225
+	function wpshop_attributes_shortcode($shorcode_args) {
2226 2226
 		$output = '';
2227 2227
 		/*
2228 2228
 		 * Read the attribute list
2229 2229
 		*/
2230
-		foreach ( explode(', ', $shorcode_args['attributes']) as $attribute_code ) {
2231
-			$attribute_output_def = wpshop_attributes::display_attribute( $attribute_code, $shorcode_args['from'] );
2230
+		foreach (explode(', ', $shorcode_args['attributes']) as $attribute_code) {
2231
+			$attribute_output_def = wpshop_attributes::display_attribute($attribute_code, $shorcode_args['from']);
2232 2232
 			$output .= $attribute_output_def['field'];
2233 2233
 		}
2234 2234
 
@@ -2250,7 +2250,7 @@  discard block
 block discarded – undo
2250 2250
 		$productAttributeSetDetails = wpshop_attributes_set::getAttributeSetDetails($attributeSetId, "'valid','deleted'");
2251 2251
 		$attribute_specification = array('page_code' => $currentPageCode, 'element_identifier' => $itemToEdit, 'field_id' => $currentPageCode . '_' . $itemToEdit . '_');
2252 2252
 
2253
-		if ( count($productAttributeSetDetails) > 0 ) {
2253
+		if (count($productAttributeSetDetails) > 0) {
2254 2254
 			/*	Read the attribute list in order to output	*/
2255 2255
 			$shortcodes_attr = '';
2256 2256
 			$shortcodes_to_display = false;
@@ -2260,80 +2260,80 @@  discard block
 block discarded – undo
2260 2260
 
2261 2261
 				$shortcodes = $currentTabContent = '';
2262 2262
 				$output_nb = 0;
2263
-				if(count($productAttributeSetDetail['attribut']) >= 1){
2264
-					foreach($productAttributeSetDetail['attribut'] as $attribute){
2263
+				if (count($productAttributeSetDetail['attribut']) >= 1) {
2264
+					foreach ($productAttributeSetDetail['attribut'] as $attribute) {
2265 2265
 
2266
-						if ( !empty($attribute->id) ) {
2267
-							if ( $attribute->code == 'product_attribute_set_id' ) {
2266
+						if (!empty($attribute->id)) {
2267
+							if ($attribute->code == 'product_attribute_set_id') {
2268 2268
 								$attribute_set_id_is_present = true;
2269 2269
 							}
2270 2270
 
2271 2271
 							/** Generic part for attribute field output	*/
2272 2272
 							$value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code($currentPageCode), $itemToEdit, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input));
2273
-							$product_meta = get_post_meta( $itemToEdit, '_wpshop_product_metadata', true);
2273
+							$product_meta = get_post_meta($itemToEdit, '_wpshop_product_metadata', true);
2274 2274
 
2275 2275
 							/**	Check if value is empty and get value in meta if not empty	*/
2276 2276
 							$value = (empty($value) && !empty($product_meta[$attribute->code])) ? $product_meta[$attribute->code] : (!empty($value) ? $value : null);
2277 2277
 
2278 2278
 							/*	Manage specific field as the attribute_set_id in product form	*/
2279
-							if ( $attribute->code == 'product_attribute_set_id' ) {
2279
+							if ($attribute->code == 'product_attribute_set_id') {
2280 2280
 
2281 2281
 								$value = empty($value) ? $attributeSetId : $value;
2282 2282
 							}
2283 2283
 							$attribute_specification['current_value'] = $value;
2284
-							$attribute_output_def = apply_filters( 'wpshop_attribute_output_def', wpshop_attributes::display_attribute( $attribute->code, 'admin', $attribute_specification), $itemToEdit );
2285
-							if ( ($attribute_output_def['field_definition']['type'] != 'hidden') && ($attribute->code != 'product_attribute_set_id') ) {
2284
+							$attribute_output_def = apply_filters('wpshop_attribute_output_def', wpshop_attributes::display_attribute($attribute->code, 'admin', $attribute_specification), $itemToEdit);
2285
+							if (($attribute_output_def['field_definition']['type'] != 'hidden') && ($attribute->code != 'product_attribute_set_id')) {
2286 2286
 								$currentTabContent .= $attribute_output_def['field'];
2287
-								$shortcode_code_def=array();
2288
-								$shortcode_code_def['attribute_'.str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['main_code'] = 'wpshop_att_val';
2289
-								$shortcode_code_def['attribute_'.str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['type'] = $attribute->data_type;
2290
-								$shortcode_code_def['attribute_'.str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['attid'] = $attribute->id;
2291
-								$shortcode_code_def['attribute_'.str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['pid'] = $itemToEdit;
2287
+								$shortcode_code_def = array();
2288
+								$shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['main_code'] = 'wpshop_att_val';
2289
+								$shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['type'] = $attribute->data_type;
2290
+								$shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['attid'] = $attribute->id;
2291
+								$shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['pid'] = $itemToEdit;
2292 2292
 								ob_start();
2293
-								wps_shortcodes_ctr::output_shortcode('attribute_'.str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])), $shortcode_code_def, 'wpshop_product_shortcode_display wpshop_product_attribute_shortcode_display wpshop_product_attribute_shortcode_display_'.str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])).' wpshop_cls');
2294
-								$shortcodes .= '<li class="wpshop_cls" >'.sprintf(__('Insertion code for the attribute %s for this product', 'wpshop'), '<span>'.__($attribute_output_def['field_definition']['label'], 'wpshop').'</span>').ob_get_contents().'</li>';
2293
+								wps_shortcodes_ctr::output_shortcode('attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])), $shortcode_code_def, 'wpshop_product_shortcode_display wpshop_product_attribute_shortcode_display wpshop_product_attribute_shortcode_display_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])) . ' wpshop_cls');
2294
+								$shortcodes .= '<li class="wpshop_cls" >' . sprintf(__('Insertion code for the attribute %s for this product', 'wpshop'), '<span>' . __($attribute_output_def['field_definition']['label'], 'wpshop') . '</span>') . ob_get_contents() . '</li>';
2295 2295
 								ob_end_clean();
2296 2296
 							}
2297 2297
 							else {
2298
-								if ( $attribute->code == 'product_attribute_set_id' ) {
2298
+								if ($attribute->code == 'product_attribute_set_id') {
2299 2299
 									$attribute_output_def['field_definition']['type'] = 'hidden';
2300 2300
 								}
2301
-								$currentTabContent .=  wpshop_form::check_input_type($attribute_output_def['field_definition'], $attribute_output_def['field_definition']['input_domain']);
2301
+								$currentTabContent .= wpshop_form::check_input_type($attribute_output_def['field_definition'], $attribute_output_def['field_definition']['input_domain']);
2302 2302
 							}
2303 2303
 							$output_nb++;
2304 2304
 						}
2305 2305
 					}
2306 2306
 
2307
-					$currentTabContent = apply_filters( 'wps_entity_attribute_edition', $currentTabContent, $itemToEdit, $productAttributeSetDetail );
2307
+					$currentTabContent = apply_filters('wps_entity_attribute_edition', $currentTabContent, $itemToEdit, $productAttributeSetDetail);
2308 2308
 
2309 2309
 					$shortcode_code['attributes_set']['main_code'] = 'wpshop_att_group';
2310 2310
 					$shortcode_code['attributes_set']['attrs_exemple']['pid'] = $itemToEdit;
2311 2311
 					$shortcode_code['attributes_set']['attrs_exemple']['sid'] = $productAttributeSetDetail['id'];
2312 2312
 					ob_start();
2313
-					wps_shortcodes_ctr::output_shortcode('attributes_set', $shortcode_code, 'wpshop_product_shortcode_display wpshop_product_attribute_group_shortcode_display wpshop_product_attribute_group_shortcode_display_'.str_replace('-', '_', sanitize_title($productAttributeSetDetail['name'])).' cls');
2314
-					$attribute_group_display = sprintf(__('Insertion code for attribute group %s for this product', 'wpshop'), '<span>'.$productAttributeSetDetail['name'].'</span>').ob_get_contents().'<ul class="" >'.$shortcodes.'</ul>';
2313
+					wps_shortcodes_ctr::output_shortcode('attributes_set', $shortcode_code, 'wpshop_product_shortcode_display wpshop_product_attribute_group_shortcode_display wpshop_product_attribute_group_shortcode_display_' . str_replace('-', '_', sanitize_title($productAttributeSetDetail['name'])) . ' cls');
2314
+					$attribute_group_display = sprintf(__('Insertion code for attribute group %s for this product', 'wpshop'), '<span>' . $productAttributeSetDetail['name'] . '</span>') . ob_get_contents() . '<ul class="" >' . $shortcodes . '</ul>';
2315 2315
 					ob_end_clean();
2316 2316
 
2317
-					if( WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE == 'each-box' )
2318
-						$currentTabContent .= '<div class="wpshop_cls" ><strong>'.__('Shortcodes','wpshop').'</strong> - <a href="#" class="show-hide-shortcodes">' . __('Display', 'wpshop') . '</a><div class="wpshop_product_shortcode_display wpshop_product_shortcode_display_container wpshopHide" >' . $attribute_group_display . '</div></div>';
2317
+					if (WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE == 'each-box')
2318
+						$currentTabContent .= '<div class="wpshop_cls" ><strong>' . __('Shortcodes', 'wpshop') . '</strong> - <a href="#" class="show-hide-shortcodes">' . __('Display', 'wpshop') . '</a><div class="wpshop_product_shortcode_display wpshop_product_shortcode_display_container wpshopHide" >' . $attribute_group_display . '</div></div>';
2319 2319
 					else
2320 2320
 						$shortcodes_attr .= $attribute_group_display;
2321 2321
 
2322
-					if ( $output_nb <= 0 ) {
2322
+					if ($output_nb <= 0) {
2323 2323
 						$currentTabContent = __('Nothing avaiblable here. You can go in attribute management interface in order to add content here.', 'wpshop');
2324 2324
 					}
2325 2325
 				}
2326 2326
 
2327 2327
 				if ($output_nb > 0) {
2328 2328
 					$shortcodes_to_display = true;
2329
-					if ( $outputType == 'box' ) {
2329
+					if ($outputType == 'box') {
2330 2330
 						$box['box'][$productAttributeSetDetail['code']] = $productAttributeSetDetail['name'];
2331
-						$box['box'][$productAttributeSetDetail['code'].'_backend_display_type'] = $productAttributeSetDetail['backend_display_type'];
2331
+						$box['box'][$productAttributeSetDetail['code'] . '_backend_display_type'] = $productAttributeSetDetail['backend_display_type'];
2332 2332
 						$box['boxContent'][$productAttributeSetDetail['code']] = '
2333 2333
 			<div id="wpshop_' . $currentPageCode . '_' . wpshop_tools::slugify($productAttributeSetDetail['code'], array('noAccent')) . '_form" >' . $currentTabContent . '
2334 2334
 							</div><div class="wpshop_cls" ></div>';
2335 2335
 					}
2336
-					else if ( $outputType == 'column' ) {
2336
+					else if ($outputType == 'column') {
2337 2337
 						$currentTabContent = str_replace('wpshop_form_input_element', 'wpshop_form_input_column', $currentTabContent);
2338 2338
 						$currentTabContent = str_replace('wpshop_form_label', 'wpshop_form_label_column', $currentTabContent);
2339 2339
 
@@ -2343,11 +2343,11 @@  discard block
 block discarded – undo
2343 2343
 				}
2344 2344
 			}
2345 2345
 
2346
-			if( !$attribute_set_id_is_present ) {
2346
+			if (!$attribute_set_id_is_present) {
2347 2347
 				/*	Get attribute definition	*/
2348 2348
 				$attribute_def = wpshop_attributes::getElement('product_attribute_set_id', "'valid'", 'code');
2349 2349
 				/*	Get attribute input definition	*/
2350
-				$input = wpshop_attributes::get_attribute_field_definition( $attribute_def, $attributeSetId, array_merge($attribute_specification, array('input_class' => ' wpshop_attributes_display', 'from' => 'admin')) );
2350
+				$input = wpshop_attributes::get_attribute_field_definition($attribute_def, $attributeSetId, array_merge($attribute_specification, array('input_class' => ' wpshop_attributes_display', 'from' => 'admin')));
2351 2351
 				$input['type'] = 'hidden';
2352 2352
 
2353 2353
 				$box['boxMore'] = wpshop_form::check_input_type($input, $input['input_domain']);
@@ -2358,13 +2358,13 @@  discard block
 block discarded – undo
2358 2358
 			$dialog_identifier = 'wpshop_new_attribute_option_value_add';
2359 2359
 			$dialog_input_identifier = 'wpshop_new_attribute_option_value';
2360 2360
 			ob_start();
2361
-			include(WPSHOP_TEMPLATES_DIR.'admin/add_new_element_dialog.tpl.php');
2361
+			include(WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php');
2362 2362
 			$box['boxMore'] .= ob_get_contents();
2363 2363
 			ob_end_clean();
2364 2364
 			$box['boxMore'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
2365 2365
 
2366
-			if ( $shortcodes_to_display ) {
2367
-				switch ( WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE ) {
2366
+			if ($shortcodes_to_display) {
2367
+				switch (WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE) {
2368 2368
 					case 'fixed-tab':
2369 2369
 					case 'movable-tab':
2370 2370
 						if ($outputType == 'box') {
@@ -2372,7 +2372,7 @@  discard block
 block discarded – undo
2372 2372
 							$box['boxContent']['shortcode'] = $shortcodes_attr;
2373 2373
 							$box['box']['shortcode_backend_display_type'] = WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE;
2374 2374
 						}
2375
-						else{
2375
+						else {
2376 2376
 							$box['columnTitle']['shortcode'] = __('Product Shortcodes', 'wpshop');
2377 2377
 							$box['columnContent']['shortcode'] = $shortcodes_attr;
2378 2378
 						}
@@ -2396,12 +2396,12 @@  discard block
 block discarded – undo
2396 2396
 		$ouput['more_input'] = '';
2397 2397
 
2398 2398
 		$attribute_default_value = $attribute->default_value;
2399
-		if ( !empty($attribute->default_value) && ($attribute->default_value == serialize(false) || wpshop_tools::is_serialized( $attribute->default_value ) ) ) {
2399
+		if (!empty($attribute->default_value) && ($attribute->default_value == serialize(false) || wpshop_tools::is_serialized($attribute->default_value))) {
2400 2400
 			$tmp_default_value = unserialize($attribute->default_value);
2401 2401
 			$attribute_default_value = !empty($tmp_default_value["default_value"]) ? $tmp_default_value["default_value"] : null;
2402 2402
 		}
2403 2403
 
2404
-		if ( $attribute->data_type_to_use == 'custom') {
2404
+		if ($attribute->data_type_to_use == 'custom') {
2405 2405
 			$query = $wpdb->prepare("SELECT id, label, value, '' as name FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' ORDER BY position", $attribute->id);
2406 2406
 			$attribute_select_options = $wpdb->get_results($query);
2407 2407
 
@@ -2413,11 +2413,11 @@  discard block
 block discarded – undo
2413 2413
 // 				}
2414 2414
 			endforeach;
2415 2415
 		}
2416
-		elseif ( $attribute->data_type_to_use == 'internal')  {
2416
+		elseif ($attribute->data_type_to_use == 'internal') {
2417 2417
 			switch ($attribute_default_value) {
2418 2418
 				case 'users':
2419 2419
 					$users = get_users('orderby=nicename');
2420
-					foreach($users as $user){
2420
+					foreach ($users as $user) {
2421 2421
 						$attribute_select_options_list[$user->ID] = $user->display_name;
2422 2422
 					}
2423 2423
 				break;
@@ -2426,11 +2426,11 @@  discard block
 block discarded – undo
2426 2426
 					$wpshop_attr_custom_post_query = new WP_Query(array(
2427 2427
 						'post_type' => $attribute_default_value,
2428 2428
 						'posts_per_page' => -1,
2429
-						'post_status' => array( 'publish', 'draft', 'future' ) ,
2429
+						'post_status' => array('publish', 'draft', 'future'),
2430 2430
 					));
2431 2431
 
2432
-					if($wpshop_attr_custom_post_query->have_posts()):
2433
-						foreach($wpshop_attr_custom_post_query->posts as $post){
2432
+					if ($wpshop_attr_custom_post_query->have_posts()):
2433
+						foreach ($wpshop_attr_custom_post_query->posts as $post) {
2434 2434
 							$attribute_select_options_list[$post->ID] = $post->post_title;
2435 2435
 						}
2436 2436
 					endif;
@@ -2441,27 +2441,27 @@  discard block
 block discarded – undo
2441 2441
 
2442 2442
 		/*	There is no value existing for this value	*/
2443 2443
 		if (empty($attribute_select_options_list)) :
2444
-			$ouput['more_input'].=__('Nothing found for this field', 'wpshop');
2444
+			$ouput['more_input'] .= __('Nothing found for this field', 'wpshop');
2445 2445
 		else:
2446 2446
 			/*	Add a default value to the combobox list	*/
2447 2447
 			$default_value_is_serial = false;
2448 2448
 			$attribute_list_first_element = $attribute->default_value;
2449
-			if ( !empty($attribute->default_value) && ($attribute->default_value == serialize(false) || wpshop_tools::is_serialized( $attribute->default_value ) ) ) {
2449
+			if (!empty($attribute->default_value) && ($attribute->default_value == serialize(false) || wpshop_tools::is_serialized($attribute->default_value))) {
2450 2450
 				$default_value_is_serial = true;
2451 2451
 				$tmp_default_value = unserialize($attribute->default_value);
2452 2452
 				$attribute_list_first_element = $tmp_default_value["field_options"]["label_for_first_item"];
2453 2453
 			}
2454 2454
 			//if ( !in_array($attribute->frontend_input, array('radio', 'checkbox')) || ($attribute_list_first_element != 'none') ) $ouput['possible_value'][] = ($default_value_is_serial && !empty($attribute_list_first_element)) ? $attribute_list_first_element : __('Choose a value', 'wpshop');
2455
-			foreach ( $attribute_select_options_list as $option_key => $option_value ) {
2455
+			foreach ($attribute_select_options_list as $option_key => $option_value) {
2456 2456
 				$ouput['possible_value'][$option_key] = stripslashes($option_value);
2457 2457
 			}
2458 2458
 		endif;
2459 2459
 
2460 2460
 		/*	Add a extra element to create a new element into list	*/
2461
-		if ( is_admin()  && ( empty($provenance['from']) || ($provenance['from'] != 'frontend')) ) {
2461
+		if (is_admin() && (empty($provenance['from']) || ($provenance['from'] != 'frontend'))) {
2462 2462
 			/**	$ouput['more_input'] .= '<img src="'.WPSHOP_MEDIAS_ICON_URL.'add.png" id="new_value_pict_' . $attribute->code . '" alt="'.__('Add a new value for this attribute', 'wpshop').'" title="'.__('Add a new value for this attribute', 'wpshop').'" class="wpshop_icons wpshop_icons_add_new_value_to_option_list wpshop_icons_add_new_value_to_option_list_'.$attribute->code.'" />';	*/
2463 2463
 		}
2464
-		else if ( 'yes' == $attribute->is_used_in_quick_add_form ) {
2464
+		else if ('yes' == $attribute->is_used_in_quick_add_form) {
2465 2465
 			$tpl_component = array();
2466 2466
 			$tpl_component['NEW_ELEMENT_CREATION_FIELD'] = 'attribute[new_value_creation][' . $attribute->code . ']';
2467 2467
 			$ouput['more_input'] .= wpshop_display::display_template_element('quick_entity_specific_field_new_element', $tpl_component);
@@ -2470,11 +2470,11 @@  discard block
 block discarded – undo
2470 2470
 		return $ouput;
2471 2471
 	}
2472 2472
 
2473
-	public static function get_affected_value_for_list( $attribute_code, $element_id, $attribute_data_type ) {
2473
+	public static function get_affected_value_for_list($attribute_code, $element_id, $attribute_data_type) {
2474 2474
 		global $wpdb;
2475 2475
 		$affected_value = array();
2476 2476
 
2477
-		if ( $attribute_data_type == 'custom' ) {
2477
+		if ($attribute_data_type == 'custom') {
2478 2478
 			$query = $wpdb->prepare("
2479 2479
 SELECT ATT_SELECT_OPTIONS_VALUE.id AS chosen_val, ATT_SELECT_OPTIONS_VALUE.value
2480 2480
 FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATT
@@ -2496,20 +2496,20 @@  discard block
 block discarded – undo
2496 2496
 		}
2497 2497
 
2498 2498
 		$attribute_values_for_variations = $wpdb->get_results($query);
2499
-		foreach ( $attribute_values_for_variations as $attribute_def ) {
2500
-			$affected_value[] = (int) $attribute_def->chosen_val;
2499
+		foreach ($attribute_values_for_variations as $attribute_def) {
2500
+			$affected_value[] = (int)$attribute_def->chosen_val;
2501 2501
 		}
2502 2502
 
2503 2503
 		return $affected_value;
2504 2504
 	}
2505 2505
 
2506 2506
 	public static function get_attribute_option_output($item, $attr_code, $attr_option, $additionnal_params = '') {
2507
-		switch($attr_code){
2507
+		switch ($attr_code) {
2508 2508
 			case 'is_downloadable_':
2509
-				$option = get_post_meta($item['item_id'], 'attribute_option_'.$attr_code, true);
2510
-				switch($attr_option){
2509
+				$option = get_post_meta($item['item_id'], 'attribute_option_' . $attr_code, true);
2510
+				switch ($attr_option) {
2511 2511
 					case 'file_url':
2512
-						if(in_array($additionnal_params['order_status'], array('completed', 'shipped')) && (!empty($item['item_'.$attr_code]) && (strtolower(__($item['item_'.$attr_code], 'wpshop')) == __('yes','wpshop'))) ){
2512
+						if (in_array($additionnal_params['order_status'], array('completed', 'shipped')) && (!empty($item['item_' . $attr_code]) && (strtolower(__($item['item_' . $attr_code], 'wpshop')) == __('yes', 'wpshop')))) {
2513 2513
 							$file_url = isset($option[$attr_option]) ? $option[$attr_option] : false;
2514 2514
 							return $file_url;
2515 2515
 						}
@@ -2522,17 +2522,17 @@  discard block
 block discarded – undo
2522 2522
 
2523 2523
 	public static function get_attribute_option_fields($postid, $code) {
2524 2524
 
2525
-		switch($code){
2525
+		switch ($code) {
2526 2526
 			case 'is_downloadable_':
2527
-				$data = get_post_meta($postid, 'attribute_option_'.$code, true);
2528
-				$data['file_url'] = !empty($data['file_url'])?$data['file_url']:__('No file selected', 'wpshop');
2529
-				$fields =  wp_nonce_field( 'ajax_wpshop_show_downloadable_interface_in_admin'.$postid, '_show_downloadable_interface_in_admin_wpnonce', true, false );
2527
+				$data = get_post_meta($postid, 'attribute_option_' . $code, true);
2528
+				$data['file_url'] = !empty($data['file_url']) ? $data['file_url'] : __('No file selected', 'wpshop');
2529
+				$fields = wp_nonce_field('ajax_wpshop_show_downloadable_interface_in_admin' . $postid, '_show_downloadable_interface_in_admin_wpnonce', true, false);
2530 2530
 				$fields .= '<div class="wpshop_form_label alignleft">&nbsp;</div>
2531 2531
 						<div class="wpshop_form_input_element alignleft">
2532
-						<div class="send_downloadable_file_dialog wpshop_add_box" data-post="'.$postid.'" title="' .__('Send the downloadable file', 'wpshop'). '"></div>
2533
-						<a data-nonce="' . wp_create_nonce( "ajax_wpshop_fill_the_downloadable_dialog".$postid ) . '"  class="send_downlodable_file wps-bton-first-mini-rounded">' .__('Send a file', 'wpshop').'</a>
2534
-						<input type="hidden" class="product_identifer_field" value="' .( !empty($postid) ? esc_attr( $postid ) : '') . '" /><br/><u>'.__('File url','wpshop').' :</u>
2535
-						<div class="is_downloadable_statut_'.$postid.'"><a href="' .$data['file_url']. '" target="_blank" download>'.basename($data['file_url']).'</a></div>
2532
+						<div class="send_downloadable_file_dialog wpshop_add_box" data-post="'.$postid . '" title="' . __('Send the downloadable file', 'wpshop') . '"></div>
2533
+						<a data-nonce="' . wp_create_nonce("ajax_wpshop_fill_the_downloadable_dialog" . $postid) . '"  class="send_downlodable_file wps-bton-first-mini-rounded">' . __('Send a file', 'wpshop') . '</a>
2534
+						<input type="hidden" class="product_identifer_field" value="' .(!empty($postid) ? esc_attr($postid) : '') . '" /><br/><u>' . __('File url', 'wpshop') . ' :</u>
2535
+						<div class="is_downloadable_statut_'.$postid . '"><a href="' . $data['file_url'] . '" target="_blank" download>' . basename($data['file_url']) . '</a></div>
2536 2536
 						</div>';
2537 2537
 				return $fields;
2538 2538
 				break;
@@ -2557,8 +2557,8 @@  discard block
 block discarded – undo
2557 2557
 		$attribute_value_content = '';
2558 2558
 
2559 2559
 		$atributes = self::getElement($attribute_code, "'valid'", 'code');
2560
-		if ( !empty($atributes) ) {
2561
-			$attribute_value_content = self::getAttributeValueForEntityInSet($atributes->data_type, $atributes->id,  wpshop_entities::get_entity_identifier_from_code($entity_type), $entity_id);
2560
+		if (!empty($atributes)) {
2561
+			$attribute_value_content = self::getAttributeValueForEntityInSet($atributes->data_type, $atributes->id, wpshop_entities::get_entity_identifier_from_code($entity_type), $entity_id);
2562 2562
 		}
2563 2563
 
2564 2564
 		return $attribute_value_content;
@@ -2570,14 +2570,14 @@  discard block
 block discarded – undo
2570 2570
 	 * @param mixed $value
2571 2571
 	 * @return string The complete interface allowing to manage datetime attribute field
2572 2572
 	 */
2573
-	function attribute_type_date_config( $value ) {
2573
+	function attribute_type_date_config($value) {
2574 2574
 		$date_config_output = '';
2575 2575
 
2576 2576
 		$input_def['name'] = 'default_value';
2577 2577
 		$input_def['type'] = 'checkbox';
2578 2578
 		$input_def['possible_value'] = 'date_of_current_day';
2579 2579
 		$input_def['value'] = !empty($value['default_value']) ? $value['default_value'] : '';
2580
-		$input_def['options_label']['custom'] = ' ' . __('Use the date of the day as default value', 'wpshop') . ' <a href="#" title="'.__('Check this box for using date of the day as value when editing a product', 'wpshop').'" class="wpshop_infobulle_marker">?</a>';
2580
+		$input_def['options_label']['custom'] = ' ' . __('Use the date of the day as default value', 'wpshop') . ' <a href="#" title="' . __('Check this box for using date of the day as value when editing a product', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
2581 2581
 		$date_config_output .= wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
2582 2582
 
2583 2583
 		$input_def = array();
@@ -2586,35 +2586,35 @@  discard block
 block discarded – undo
2586 2586
 		$input_def['type'] = 'checkbox';
2587 2587
 		$input_def['valueToPut'] = 'index';
2588 2588
 		$input_def['value'] = !empty($value['field_options']['attribute_type_date_options_day_to_show']) ? $value['field_options']['attribute_type_date_options_day_to_show'] : '';
2589
-		$input_def['possible_value'] = array('1' => ' ' . __('Monday', 'wpshop'), '2' => ' ' .__('Tuesday', 'wpshop'), '3' => ' ' .__('Wednesday', 'wpshop'), '4' => ' ' .__('Thursday', 'wpshop'), '5' => ' ' .__('Friday', 'wpshop'), '6' => ' ' .__('Saturday', 'wpshop'), '0' => ' ' .__('Sunday', 'wpshop'));
2589
+		$input_def['possible_value'] = array('1' => ' ' . __('Monday', 'wpshop'), '2' => ' ' . __('Tuesday', 'wpshop'), '3' => ' ' . __('Wednesday', 'wpshop'), '4' => ' ' . __('Thursday', 'wpshop'), '5' => ' ' . __('Friday', 'wpshop'), '6' => ' ' . __('Saturday', 'wpshop'), '0' => ' ' . __('Sunday', 'wpshop'));
2590 2590
 		$input_def['options_label']['original'] = true;
2591
-		$date_config_output .= '<div>' . __('Choose available days in date picker', 'wpshop') . '<a href="#" title="'.__('This option allows you to define the available day in final datepicker', 'wpshop').'" class="wpshop_infobulle_marker">?</a>' . '<br/>' . wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_day_to_show]') . '</div>';
2591
+		$date_config_output .= '<div>' . __('Choose available days in date picker', 'wpshop') . '<a href="#" title="' . __('This option allows you to define the available day in final datepicker', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br/>' . wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_day_to_show]') . '</div>';
2592 2592
 
2593 2593
 		/**	Past and futur date restriction	*/
2594 2594
 		$input_def = array();
2595 2595
 		$input_def['name'] = '';
2596 2596
 		$input_def['type'] = 'text';
2597
-		$date_config_output .= '<div id="wpshop_avalaible_date_for_past_and_futur" >' . __('Calendar past and futur date available', 'wpshop') . '<a href="#" title="'.__('Define if the end user is allowed to choose past and/or futur date', 'wpshop').'" class="wpshop_infobulle_marker">?</a><br/>';
2597
+		$date_config_output .= '<div id="wpshop_avalaible_date_for_past_and_futur" >' . __('Calendar past and futur date available', 'wpshop') . '<a href="#" title="' . __('Define if the end user is allowed to choose past and/or futur date', 'wpshop') . '" class="wpshop_infobulle_marker">?</a><br/>';
2598 2598
 		$available_type_input_def = array();
2599 2599
 		$available_type_input_def['name'] = '';
2600 2600
 		$available_type_input_def['id'] = 'wpshop_attributes_edition_table_field_attribute_type_date_options_available_date_past_futur_minimum';
2601 2601
 		$available_type_input_def['type'] = 'text';
2602 2602
 		$available_type_input_def['value'] = !empty($value['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0]) ? $value['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0] : '';
2603
-		$date_config_output .= __('Minimum date to show', 'wpshop') . '<a href="#" title="'.__('If you want the calendar to start today put only 0, if you want to show anterior date, put the number of Day or Month or Year (ex: -1D)', 'wpshop').'" class="wpshop_infobulle_marker">?</a>' . wpshop_form::check_input_type($available_type_input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date_past_futur][minDate]') . '<br/>';
2603
+		$date_config_output .= __('Minimum date to show', 'wpshop') . '<a href="#" title="' . __('If you want the calendar to start today put only 0, if you want to show anterior date, put the number of Day or Month or Year (ex: -1D)', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . wpshop_form::check_input_type($available_type_input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date_past_futur][minDate]') . '<br/>';
2604 2604
 		$available_type_input_def = array();
2605 2605
 		$available_type_input_def['name'] = '';
2606 2606
 		$available_type_input_def['id'] = 'wpshop_attributes_edition_table_field_attribute_type_date_options_available_date_past_futur_maximum';
2607 2607
 		$available_type_input_def['type'] = 'text';
2608 2608
 		$available_type_input_def['value'] = !empty($value['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0]) ? $value['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0] : '';
2609
-		$date_config_output .= __('Maximum date to show', 'wpshop') . '<a href="#" title="'.__('If you want the calendar to end today put only 0, if you want to show date in futur, put the number of Day or Month or Year (ex: +1M)', 'wpshop').'" class="wpshop_infobulle_marker">?</a>' . wpshop_form::check_input_type($available_type_input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date_past_futur][maxDate]') . '<br/>';
2609
+		$date_config_output .= __('Maximum date to show', 'wpshop') . '<a href="#" title="' . __('If you want the calendar to end today put only 0, if you want to show date in futur, put the number of Day or Month or Year (ex: +1M)', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . wpshop_form::check_input_type($available_type_input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date_past_futur][maxDate]') . '<br/>';
2610 2610
 		$date_config_output .= '</div>';
2611 2611
 
2612 2612
 		$input_def = array();
2613 2613
 		$input_def['name'] = '';
2614 2614
 		$input_def['type'] = 'text';
2615 2615
 		$date_config_output .= '
2616
-<div id="wpshop_attribute_date_empy_field" class="wpshopHide" ><br/>' . wpshop_form::check_input_type(array_merge($input_def, array('value' => '', 'id' => 'wpshop_attributes_edition_table_field_attribute_type_date_options_available_date_new_input')), WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date]') .'</div>
2617
-<div id="wpshop_avalaible_date_list_container" >' . __('Choose available date in date picker', 'wpshop') . '<a href="#" title="'.__('This option allows you to define the available date in final datepicker', 'wpshop').'" class="wpshop_infobulle_marker">?</a><br/>';
2616
+<div id="wpshop_attribute_date_empy_field" class="wpshopHide" ><br/>' . wpshop_form::check_input_type(array_merge($input_def, array('value' => '', 'id' => 'wpshop_attributes_edition_table_field_attribute_type_date_options_available_date_new_input')), WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date]') . '</div>
2617
+<div id="wpshop_avalaible_date_list_container" >' . __('Choose available date in date picker', 'wpshop') . '<a href="#" title="' . __('This option allows you to define the available date in final datepicker', 'wpshop') . '" class="wpshop_infobulle_marker">?</a><br/>';
2618 2618
 
2619 2619
 		$available_type_input_def = array();
2620 2620
 		$available_type_input_def['name'] = '';
@@ -2627,9 +2627,9 @@  discard block
 block discarded – undo
2627 2627
 		$date_config_output .= wpshop_form::check_input_type($available_type_input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date_type]') . '<br/>';
2628 2628
 
2629 2629
 		$existing = 0;
2630
-		if ( !empty($value['field_options']['attribute_type_date_options_available_date']) ) {
2631
-			foreach ( $value['field_options']['attribute_type_date_options_available_date'] as $index => $value ) {
2632
-				if ( !empty($value) ) {
2630
+		if (!empty($value['field_options']['attribute_type_date_options_available_date'])) {
2631
+			foreach ($value['field_options']['attribute_type_date_options_available_date'] as $index => $value) {
2632
+				if (!empty($value)) {
2633 2633
 					$input_def['value'] = $value;
2634 2634
 					$input_def['id'] = 'wpshop_attributes_edition_table_field_attribute_type_date_options_available_date_' . $index;
2635 2635
 					$date_config_output .= wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE . '_options[attribute_type_date_options_available_date]') . '<br/>';
@@ -2653,20 +2653,20 @@  discard block
 block discarded – undo
2653 2653
 	 * @param array $values Valeurs d'attributs
2654 2654
 	 * @return array
2655 2655
 	 */
2656
-	public static function setAttributesValuesForItem($entityId, $values=array(), $defaultValueForOthers=false, $from = 'webservice') {
2657
-		$message='';
2656
+	public static function setAttributesValuesForItem($entityId, $values = array(), $defaultValueForOthers = false, $from = 'webservice') {
2657
+		$message = '';
2658 2658
 		$attribute_available = array();
2659 2659
 		$attribute_final = array();
2660 2660
 		$entity_type = get_post_type($entityId);
2661
-		$data = self::get_attribute_list_for_item( wpshop_entities::get_entity_identifier_from_code($entity_type), $entityId, WPSHOP_CURRENT_LOCALE);
2662
-		foreach($data as $d) $attribute_available[$d->attribute_code] = array('attribute_id' => $d->attribute_id, 'data_type' => $d->data_type);
2661
+		$data = self::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code($entity_type), $entityId, WPSHOP_CURRENT_LOCALE);
2662
+		foreach ($data as $d) $attribute_available[$d->attribute_code] = array('attribute_id' => $d->attribute_id, 'data_type' => $d->data_type);
2663 2663
 
2664 2664
 		// Creation d'un array "propre" et valide pour la fonction self::saveAttributeForEntity
2665
-		foreach ( $values as $key => $value ) {
2666
-			if ( in_array( $key, array_keys( $attribute_available ) ) ) {
2665
+		foreach ($values as $key => $value) {
2666
+			if (in_array($key, array_keys($attribute_available))) {
2667 2667
 				$attribute_final[$attribute_available[$key]['data_type']][$key] = $value;
2668 2668
 			}
2669
-			else $message .= sprintf(__('Impossible to set "%s" attribute', 'wpshop'), $key)."\n";
2669
+			else $message .= sprintf(__('Impossible to set "%s" attribute', 'wpshop'), $key) . "\n";
2670 2670
 		}
2671 2671
 
2672 2672
 		// Pour les autres attributs non donné on leur affecte leur valeur par défaut
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
 			}
2688 2688
 		}
2689 2689
 
2690
-		switch ( $entity_type ) {
2690
+		switch ($entity_type) {
2691 2691
 			case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
2692 2692
 					$meta_key = WPSHOP_PRODUCT_ATTRIBUTE_META_KEY;
2693 2693
 				break;
@@ -2717,22 +2717,22 @@  discard block
 block discarded – undo
2717 2717
 	 */
2718 2718
 	public static function get_attribute_type_select_option_info($option_id, $field = 'label', $attribute_data_type = 'custom', $only_value = false) {
2719 2719
 		global $wpdb;
2720
-		if( ! is_numeric( $option_id ) ) {
2720
+		if (!is_numeric($option_id)) {
2721 2721
 			return '';
2722 2722
 		}
2723
-		$option_id = (int) $option_id;
2724
-		switch ( $attribute_data_type ) {
2723
+		$option_id = (int)$option_id;
2724
+		switch ($attribute_data_type) {
2725 2725
 			case 'internal':
2726 2726
 				$entity_infos = get_post($option_id);
2727
-				if ( !empty($entity_infos) ) {
2728
-					if ( !$only_value ) {
2727
+				if (!empty($entity_infos)) {
2728
+					if (!$only_value) {
2729 2729
 						/** Template parameters */
2730 2730
 						$template_part = 'product_attribute_value_internal';
2731 2731
 						$tpl_component = array();
2732 2732
 						$tpl_component['ATTRIBUTE_VALUE_POST_LINK'] = get_permalink($option_id);
2733 2733
 						$tpl_component['ATTRIBUTE_VALUE_POST_TITLE'] = $entity_infos->post_title;
2734 2734
 
2735
-						foreach ( $entity_infos as $post_definition_key => $post_definition_value ) {
2735
+						foreach ($entity_infos as $post_definition_key => $post_definition_value) {
2736 2736
 							$tpl_component['ATTRIBUTE_VALUE_' . strtoupper($post_definition_key)] = $entity_infos->$post_definition_key;
2737 2737
 						}
2738 2738
 
@@ -2747,8 +2747,8 @@  discard block
 block discarded – undo
2747 2747
 				break;
2748 2748
 
2749 2749
 			default:
2750
-				if ( ! array_key_exists( $option_id, self::$select_option_info_cache ) ) {
2751
-					$query = $wpdb->prepare("SELECT " . $field . " FROM ".WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS." WHERE id=%d LIMIT 1", $option_id);
2750
+				if (!array_key_exists($option_id, self::$select_option_info_cache)) {
2751
+					$query = $wpdb->prepare("SELECT " . $field . " FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE id=%d LIMIT 1", $option_id);
2752 2752
 					self::$select_option_info_cache[$option_id] = $wpdb->get_var($query);
2753 2753
 				}
2754 2754
 				$info = self::$select_option_info_cache[$option_id];
@@ -2788,39 +2788,39 @@  discard block
 block discarded – undo
2788 2788
 	 * @param string $data_type optionnal Le type de donnees choisi pour cet attribut (custom | internal)
2789 2789
 	 * @return string Le resultat sous forme de code html pour la liste des options
2790 2790
 	 */
2791
-	function get_select_options_list($attribute_id, $data_type='custom') {
2791
+	function get_select_options_list($attribute_id, $data_type = 'custom') {
2792 2792
 		global $wpdb;
2793 2793
 		$output = '';
2794 2794
 
2795 2795
 		$attribute_select_options = self::get_select_option_list_($attribute_id);
2796 2796
 
2797 2797
 		/*	Add possibily to choose datat type to use with list	*/
2798
-		if(empty($attribute_id) || (!empty($attribute_select_options) && empty($attribute_select_options[0]->data_type_to_use))){
2799
-			unset($input_def);$input_def=array();
2798
+		if (empty($attribute_id) || (!empty($attribute_select_options) && empty($attribute_select_options[0]->data_type_to_use))) {
2799
+			unset($input_def); $input_def = array();
2800 2800
 			$input_def['label'] = __('Type of data for list', 'wpshop');
2801 2801
 			$input_def['type'] = 'radio';
2802 2802
 			$input_def['name'] = 'data_type_to_use';
2803 2803
 			$input_def['valueToPut'] = 'index';
2804 2804
 			$input_def['possible_value'] = unserialize(WPSHOP_ATTR_SELECT_TYPE);
2805 2805
 			$input_def['option'] = 'class="wpshop_cls wpshop_attr_combo_data_type"';
2806
-			$input_def['value'] = $data_type.'_data';
2806
+			$input_def['value'] = $data_type . '_data';
2807 2807
 			$input_def['options_label']['original'] = true;
2808 2808
 			$output = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
2809 2809
 		}
2810 2810
 
2811
-		if(!empty($attribute_id) || !empty($data_type)){
2812
-			$defaut_value = ( !empty($attribute_select_options[0]) && !empty($attribute_select_options[0]->default_value) ) ? $attribute_select_options[0]->default_value : null;
2811
+		if (!empty($attribute_id) || !empty($data_type)) {
2812
+			$defaut_value = (!empty($attribute_select_options[0]) && !empty($attribute_select_options[0]->default_value)) ? $attribute_select_options[0]->default_value : null;
2813 2813
 			$default_is_serial = false;
2814
-			if ( !empty($attribute_select_options[0]->default_value) && ($attribute_select_options[0]->default_value == serialize(false) || wpshop_tools::is_serialized( $attribute_select_options[0]->default_value ) ) ) {
2814
+			if (!empty($attribute_select_options[0]->default_value) && ($attribute_select_options[0]->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_select_options[0]->default_value))) {
2815 2815
 				$defaut_value = unserialize($attribute_select_options[0]->default_value);
2816 2816
 				$default_is_serial = true;
2817 2817
 			}
2818 2818
 			/**	Add a custom text first item of list	*/
2819
-			$output .= '<div class="wpshop_cls" ><label for="text_for_empty_value" >' . __('Text displayed when no value selected', 'wpshop') . '</label> <input type="text" name="' . WPSHOP_DBT_ATTRIBUTE . '[default_value][field_options][label_for_first_item]" value="' . (($default_is_serial && is_array($defaut_value) && !empty($defaut_value["field_options"]["label_for_first_item"])) ? stripslashes( $defaut_value["field_options"]["label_for_first_item"] ) : __('Choose a value', 'wpshop')) . '" id="text_for_empty_value" /></div>';
2819
+			$output .= '<div class="wpshop_cls" ><label for="text_for_empty_value" >' . __('Text displayed when no value selected', 'wpshop') . '</label> <input type="text" name="' . WPSHOP_DBT_ATTRIBUTE . '[default_value][field_options][label_for_first_item]" value="' . (($default_is_serial && is_array($defaut_value) && !empty($defaut_value["field_options"]["label_for_first_item"])) ? stripslashes($defaut_value["field_options"]["label_for_first_item"]) : __('Choose a value', 'wpshop')) . '" id="text_for_empty_value" /></div>';
2820 2820
 
2821
-			if((($data_type == 'custom') && empty($attribute_select_options)) || (!empty($attribute_select_options) && !empty($attribute_select_options[0]->data_type_to_use) && ($attribute_select_options[0]->data_type_to_use == 'custom'))){
2821
+			if ((($data_type == 'custom') && empty($attribute_select_options)) || (!empty($attribute_select_options) && !empty($attribute_select_options[0]->data_type_to_use) && ($attribute_select_options[0]->data_type_to_use == 'custom'))) {
2822 2822
 				$sub_output = '';
2823
-				if ( !empty($attribute_select_options) && !empty($attribute_select_options[0]) && !empty($attribute_select_options[0]->id) ) {
2823
+				if (!empty($attribute_select_options) && !empty($attribute_select_options[0]) && !empty($attribute_select_options[0]->id)) {
2824 2824
 					$sub_output .= '
2825 2825
 					<li class="wpshop_attribute_combo_options_container ui-state-disabled" >
2826 2826
 						<input type="radio" name="' . WPSHOP_DBT_ATTRIBUTE . '[default_value][default_value]" value="" id="default_value_empty" ' . (($default_is_serial && is_array($defaut_value) && empty($defaut_value["default_value"])) || empty($defaut_value) ? 'checked ' : '') . '/> <label for="default_value_empty">' . __('No default value', 'wpshop') . '</label>
@@ -2833,7 +2833,7 @@  discard block
 block discarded – undo
2833 2833
 						$tpl_component['ADMIN_ATTRIBUTE_VALUES_OPTION_VALUE'] = str_replace(".", ",", $options->value);
2834 2834
 						$tpl_component['ADMIN_ATTRIBUTE_VALUES_OPTION_STATE'] = (!empty($options->id) && (($default_is_serial && is_array($defaut_value) && !empty($defaut_value["default_value"]) && ($defaut_value["default_value"] == $options->id))) ? ' checked="checked"' : '');
2835 2835
 						$tpl_component['ADMIN_ATTRIBUTE_VALUE_OPTIN_ACTIONS'] = '';
2836
-						if( current_user_can('wpshop_delete_attributes_select_values') && ($options->value_id >= 0) ):
2836
+						if (current_user_can('wpshop_delete_attributes_select_values') && ($options->value_id >= 0)):
2837 2837
 							$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_id), 'admin');
2838 2838
 						endif;
2839 2839
 						$sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_option_value_item', $tpl_component, array('type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_id), 'admin');
@@ -2841,13 +2841,13 @@  discard block
 block discarded – undo
2841 2841
 					}
2842 2842
 				}
2843 2843
 				$add_button = $add_dialog_box = $user_more_script = '';
2844
-				if( current_user_can('wpshop_add_attributes_select_values') ) {
2844
+				if (current_user_can('wpshop_add_attributes_select_values')) {
2845 2845
 
2846 2846
 					$dialog_title = __('New value for attribute', 'wpshop');
2847 2847
 					$dialog_identifier = 'wpshop_new_attribute_option_value_add';
2848 2848
 					$dialog_input_identifier = 'wpshop_new_attribute_option_value';
2849 2849
 					ob_start();
2850
-					include(WPSHOP_TEMPLATES_DIR.'admin/add_new_element_dialog.tpl.php');
2850
+					include(WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php');
2851 2851
 					$add_dialog_box = ob_get_contents();
2852 2852
 					ob_end_clean();
2853 2853
 
@@ -2855,23 +2855,23 @@  discard block
 block discarded – undo
2855 2855
 					$add_button_parent_class = 'wpshop_attribute_option_value_add';
2856 2856
 					$add_button_name = 'wpshop_add_option_to_select';
2857 2857
 					ob_start();
2858
-					include(WPSHOP_TEMPLATES_DIR.'admin/add_new_element_with_dialog.tpl.php');
2858
+					include(WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_with_dialog.tpl.php');
2859 2859
 					$add_button = ob_get_contents();
2860 2860
 					ob_end_clean();
2861 2861
 
2862 2862
 					$user_more_script = '
2863
-			jQuery("#'.$dialog_identifier.'").dialog({
2863
+			jQuery("#'.$dialog_identifier . '").dialog({
2864 2864
 				modal: true,
2865 2865
 				dialogClass: "wpshop_uidialog_box",
2866 2866
 				autoOpen:false,
2867 2867
 				show: "blind",
2868 2868
 				resizable: false,
2869 2869
 				buttons:{
2870
-					"'.__('Add', 'wpshop').'": function(){
2870
+					"'.__('Add', 'wpshop') . '": function(){
2871 2871
 						var data = {
2872 2872
 							action: "new_option_for_select",
2873 2873
 							wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_new_option_for_attribute_creation") . '",
2874
-							attribute_new_label: jQuery("#'.$dialog_input_identifier.'").val(),
2874
+							attribute_new_label: jQuery("#'.$dialog_input_identifier . '").val(),
2875 2875
 							attribute_identifier: "' . $attribute_id . '"
2876 2876
 						};
2877 2877
 						jQuery.post(ajaxurl, data, function(response) {
@@ -2887,21 +2887,21 @@  discard block
 block discarded – undo
2887 2887
 
2888 2888
 						jQuery(this).children("img").show();
2889 2889
 					},
2890
-					"'.__('Cancel', 'wpshop').'": function(){
2890
+					"'.__('Cancel', 'wpshop') . '": function(){
2891 2891
 						jQuery(this).dialog("close");
2892 2892
 					}
2893 2893
 				},
2894 2894
 				close:function(){
2895
-					jQuery("#'.$dialog_input_identifier.'").val("");
2895
+					jQuery("#'.$dialog_input_identifier . '").val("");
2896 2896
 				}
2897 2897
 			});
2898
-			jQuery(".'.$add_button_parent_class.' input").click(function(){
2899
-				jQuery("#'.$dialog_identifier.'").dialog("open");
2898
+			jQuery(".'.$add_button_parent_class . ' input").click(function(){
2899
+				jQuery("#'.$dialog_identifier . '").dialog("open");
2900 2900
 			});';
2901 2901
 
2902 2902
 				}
2903 2903
 				$output .= $add_dialog_box . '
2904
-	<ul id="sortable_attribute" class="wpshop_cls" >'.(count($attribute_select_options)>5 ? $add_button : '').$sub_output.$add_button.'
2904
+	<ul id="sortable_attribute" class="wpshop_cls" >'.(count($attribute_select_options) > 5 ? $add_button : '') . $sub_output . $add_button . '
2905 2905
 	</ul>
2906 2906
 	<input type="hidden" value="' . wp_create_nonce("wpshop_new_option_for_attribute_deletion") . '" name="wpshop_new_option_for_attribute_deletion_nonce" id="wpshop_new_option_for_attribute_deletion_nonce" />
2907 2907
 	<script type="text/javascript" >
@@ -2917,7 +2917,7 @@  discard block
 block discarded – undo
2917 2917
 					var data = {
2918 2918
 						action: "attribute_output_type",
2919 2919
 						current_type: jQuery("#wpshop_attributes_edition_table_field_id_frontend_input").val(),
2920
-						elementIdentifier: "'.$attribute_id.'",
2920
+						elementIdentifier: "'.$attribute_id . '",
2921 2921
 						data_type_to_use: jQuery(this).val(),
2922 2922
 						wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_output_type_selection") . '"
2923 2923
 					};
@@ -2932,10 +2932,10 @@  discard block
 block discarded – undo
2932 2932
 		});
2933 2933
 	</script>';
2934 2934
 			}
2935
-			elseif((($data_type == 'internal') && empty($attribute_select_options)) || (!empty($attribute_select_options) && !empty($attribute_select_options[0]->data_type_to_use) && ($attribute_select_options[0]->data_type_to_use == 'internal'))){
2936
-				$sub_output='';
2935
+			elseif ((($data_type == 'internal') && empty($attribute_select_options)) || (!empty($attribute_select_options) && !empty($attribute_select_options[0]->data_type_to_use) && ($attribute_select_options[0]->data_type_to_use == 'internal'))) {
2936
+				$sub_output = '';
2937 2937
 				$wp_types = unserialize(WPSHOP_INTERNAL_TYPES);
2938
-				unset($input_def);$input_def=array();
2938
+				unset($input_def); $input_def = array();
2939 2939
 				$input_def['label'] = __('Type of data for list', 'wpshop');
2940 2940
 				$input_def['type'] = 'select';
2941 2941
 				$input_def['name'] = 'default_value][default_value';
@@ -2944,20 +2944,20 @@  discard block
 block discarded – undo
2944 2944
 				$input_def['possible_value'] = $wp_types;
2945 2945
 				$input_def['value'] = (($default_is_serial && is_array($defaut_value) && !empty($defaut_value["default_value"])) ? $defaut_value["default_value"] : (!empty($defaut_value) ? $defaut_value : null));
2946 2946
 				$combo_wp_type = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
2947
-				$output .= '<div class="wpshop_cls">'.$combo_wp_type.'</div>';
2948
-				if ( !empty($attribute_id) ) {
2947
+				$output .= '<div class="wpshop_cls">' . $combo_wp_type . '</div>';
2948
+				if (!empty($attribute_id)) {
2949 2949
 					$option_list = '<div>' . __('You can reorder element for display them in the order you want into frontend part', 'wpshop') . '</div>';
2950
-					$options_for_current_attribute = query_posts( array('post_type' => $input_def['value'], 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC' ) );
2951
-					if ( !empty($options_for_current_attribute) ) {
2950
+					$options_for_current_attribute = query_posts(array('post_type' => $input_def['value'], 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC'));
2951
+					if (!empty($options_for_current_attribute)) {
2952 2952
 						$option_list .= '<ul class="wpshop_attribute_combo_values_list_container" >';
2953 2953
 						$current_order = ' ';
2954
-						foreach ( $options_for_current_attribute as $options_def ) {
2954
+						foreach ($options_for_current_attribute as $options_def) {
2955 2955
 							$current_order .= 'post_' . $options_def->ID . ',';
2956 2956
 							$option_list .= '<li id="post_' . $options_def->ID . '" class="wpshop_attribute_combo_values_list_item wpshop_attribute_combo_values_list_item_' . $options_def->ID . '" ><span class="wpshop_internal_value_for_option_list_identifier" >#' . $options_def->ID . '</span> ' . $options_def->post_title . '</li>';
2957 2957
 						}
2958 2958
 						$option_list .= '</ul><input type="hidden" value="' . substr($current_order, 0, -1) . '" name="' . WPSHOP_DBT_ATTRIBUTE . '[wpshop_attribute_combo_values_list_order_def]" id="wpshop_attribute_combo_values_list_order_def" />';
2959 2959
 					}
2960
-					$output .= '<div class="wpshop_cls">'.$option_list.'</div>';
2960
+					$output .= '<div class="wpshop_cls">' . $option_list . '</div>';
2961 2961
 				}
2962 2962
 			}
2963 2963
 		}
@@ -2985,8 +2985,8 @@  discard block
 block discarded – undo
2985 2985
 		$attribute_list_for_entity = self::getElement($entity_id, "'valid'", 'entity_id', true);
2986 2986
 
2987 2987
 		/*	Read the list	*/
2988
-		if ( !empty ($attribute_list_for_entity ) ) {
2989
-			foreach ( $attribute_list_for_entity as $attribute) {
2988
+		if (!empty ($attribute_list_for_entity)) {
2989
+			foreach ($attribute_list_for_entity as $attribute) {
2990 2990
 				switch ($list_for) {
2991 2991
 					case 'attribute_value':
2992 2992
 							$checkbox_state = ' ';
@@ -2995,8 +2995,8 @@  discard block
 block discarded – undo
2995 2995
 								<select id="wpshop_shortcode_element_attribute_value_product_list_' . $attribute->id . '" class="wpshop_shortcode_element_attribute_value_product_list" >';
2996 2996
 
2997 2997
 							global $post;
2998
-							$posts = get_posts( array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'numberposts' => -1) );
2999
-							foreach( $posts as $post ) :
2998
+							$posts = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'numberposts' => -1));
2999
+							foreach ($posts as $post) :
3000 3000
 								setup_postdata($post);
3001 3001
 								$attribute_possible_values .= '<option value="' . get_the_ID() . '" >' . get_the_ID() . ' - ' . get_the_title() . '</option>';
3002 3002
 							endforeach;
@@ -3012,23 +3012,23 @@  discard block
 block discarded – undo
3012 3012
 
3013 3013
 						$checkbox_state = 'disabled ';
3014 3014
 						$attribute_possible_values = '';
3015
-						if ( !empty($attribute_values) ) {
3015
+						if (!empty($attribute_values)) {
3016 3016
 							$checkbox_state = '';
3017 3017
 							$attribute_possible_values = '
3018 3018
 							<div class="wpshop_shortcode_element_product_listing_per_attribute_value wpshop_shortcode_element_prodcut_listing_per_attribute_value_' . $attribute->code . '_container" >
3019 3019
 								<select id="wpshop_attribute_value_for_shortcode_generation_' . $attribute->id . '" class="wpshop_shortcode_element_prodcut_listing_per_attribute_value hidden" >';
3020 3020
 
3021
-								if ( ($attribute->data_type == 'integer') && ( ($attribute->backend_input == 'select') || ($attribute->backend_input == 'multiple-select') ) ) {
3021
+								if (($attribute->data_type == 'integer') && (($attribute->backend_input == 'select') || ($attribute->backend_input == 'multiple-select'))) {
3022 3022
 									$query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id=%d ORDER BY position", $attribute->id);
3023 3023
 									$possible_values = $wpdb->get_results($query);
3024 3024
 									$already_selected_values = array();
3025 3025
 									foreach ($attribute_values as $attribute_value) {
3026
-										if ( !empty($attribute_value->value) ) {
3026
+										if (!empty($attribute_value->value)) {
3027 3027
 											$already_selected_values[] = $attribute_value->value;
3028 3028
 										}
3029 3029
 									}
3030 3030
 									foreach ($possible_values as $value) {
3031
-										if ( in_array( $value->id, $already_selected_values ) ) {
3031
+										if (in_array($value->id, $already_selected_values)) {
3032 3032
 											$attribute_possible_values .= '
3033 3033
 									<option value="' . $value->value . '" >' . $value->label . '</option>';
3034 3034
 										}
@@ -3036,7 +3036,7 @@  discard block
 block discarded – undo
3036 3036
 								}
3037 3037
 								else {
3038 3038
 									foreach ($attribute_values as $attribute_value) {
3039
-										if ( !empty($attribute_value->value) ) {
3039
+										if (!empty($attribute_value->value)) {
3040 3040
 											$attribute_possible_values .= '
3041 3041
 									<option value="' . $attribute_value->value . '" >' . $attribute_value->value . '</option>';
3042 3042
 										}
@@ -3065,23 +3065,23 @@  discard block
 block discarded – undo
3065 3065
 	 *
3066 3066
 	 * @return object The attribute list as a wordpress database object
3067 3067
 	 */
3068
-	function get_attribute_list_in_same_set_section( $attribute_code ) {
3068
+	function get_attribute_list_in_same_set_section($attribute_code) {
3069 3069
 		global $wpdb;
3070 3070
 
3071 3071
 		$attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3072 3072
 
3073 3073
 		/** Get the entire list of attribute in price set section for display	*/
3074
-		$query = $wpdb->prepare( "SELECT entity_type_id, attribute_set_id, attribute_group_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_id = %d AND status = 'valid'", $attribute_def->id);
3074
+		$query = $wpdb->prepare("SELECT entity_type_id, attribute_set_id, attribute_group_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_id = %d AND status = 'valid'", $attribute_def->id);
3075 3075
 		$attribute_attribution_def = $wpdb->get_row($query);
3076 3076
 
3077
-		$query = $wpdb->prepare( "
3077
+		$query = $wpdb->prepare("
3078 3078
 							SELECT ATTR.code, is_visible_in_front_listing, is_visible_in_front
3079 3079
 							FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS SET_SECTION_DETAIL
3080 3080
 								INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = SET_SECTION_DETAIL.attribute_id)
3081 3081
 							WHERE entity_type_id = %d
3082 3082
 								AND attribute_set_id = %d
3083 3083
 								AND attribute_group_id = %d",
3084
-				$attribute_attribution_def->entity_type_id, $attribute_attribution_def->attribute_set_id, $attribute_attribution_def->attribute_group_id );
3084
+				$attribute_attribution_def->entity_type_id, $attribute_attribution_def->attribute_set_id, $attribute_attribution_def->attribute_group_id);
3085 3085
 		$atribute_list = $wpdb->get_results($query);
3086 3086
 
3087 3087
 		return $atribute_list;
@@ -3092,7 +3092,7 @@  discard block
 block discarded – undo
3092 3092
 	 * @param unknown_type $current_entity_id
3093 3093
 	 * @return Ambigous <multitype:, multitype:NULL >
3094 3094
 	 */
3095
-	public static function get_variation_available_attribute( $current_entity_id ) {
3095
+	public static function get_variation_available_attribute($current_entity_id) {
3096 3096
 		global $wpdb;
3097 3097
 		$final_list = array();
3098 3098
 
@@ -3100,7 +3100,7 @@  discard block
 block discarded – undo
3100 3100
 		$query = $wpdb->prepare(
3101 3101
 				"SELECT ATT.*, ENTITY_META.meta_value
3102 3102
 				FROM " . self::getDbTable() . " AS ATT
3103
-					INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_DETAILS. " AS ATT_DETAILS ON ((ATT_DETAILS.attribute_id = ATT.id) AND (ATT_DETAILS.entity_type_id = %d) AND (ATT_DETAILS.status = 'valid'))
3103
+					INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DETAILS ON ((ATT_DETAILS.attribute_id = ATT.id) AND (ATT_DETAILS.entity_type_id = %d) AND (ATT_DETAILS.status = 'valid'))
3104 3104
 					INNER JOIN " . $wpdb->postmeta . " AS ENTITY_META ON ((ENTITY_META.meta_key = %s) AND (ENTITY_META.meta_value = ATT_DETAILS.attribute_set_id))
3105 3105
 				WHERE ATT.status IN ('valid')
3106 3106
 					AND ATT.is_used_for_variation = %s
@@ -3110,10 +3110,10 @@  discard block
 block discarded – undo
3110 3110
 		);
3111 3111
 		$attribute_list = $wpdb->get_results($query);
3112 3112
 		foreach ($attribute_list as $attribute) {
3113
-			if ( !in_array($attribute->code, unserialize(WPSHOP_VARIATION_ATTRIBUTE_TO_HIDE)) && in_array($attribute->backend_input, array('select', 'multiple-select')) ) {
3114
-				$attribute_values_for_variations = wpshop_attributes::get_affected_value_for_list( $attribute->code, $current_entity_id, $attribute->data_type_to_use );
3113
+			if (!in_array($attribute->code, unserialize(WPSHOP_VARIATION_ATTRIBUTE_TO_HIDE)) && in_array($attribute->backend_input, array('select', 'multiple-select'))) {
3114
+				$attribute_values_for_variations = wpshop_attributes::get_affected_value_for_list($attribute->code, $current_entity_id, $attribute->data_type_to_use);
3115 3115
 
3116
-				if ( empty($attribute_values_for_variations) ) {
3116
+				if (empty($attribute_values_for_variations)) {
3117 3117
 					$final_list['unavailable'][$attribute->code]['label'] = $attribute->frontend_label;
3118 3118
 					$final_list['unavailable'][$attribute->code]['values'] = array();
3119 3119
 					$final_list['unavailable'][$attribute->code]['attribute_complete_def'] = $attribute;
@@ -3133,16 +3133,16 @@  discard block
 block discarded – undo
3133 3133
 	 * @param integer $current_entity_id The current element edited
3134 3134
 	 * @return Ambigous <string, string, mixed>
3135 3135
 	 */
3136
-	public static function get_variation_available_attribute_display( $current_entity_id, $variation_type = 'multiple' ) {
3136
+	public static function get_variation_available_attribute_display($current_entity_id, $variation_type = 'multiple') {
3137 3137
 		$attribute_list = wpshop_attributes::get_variation_available_attribute($current_entity_id);
3138 3138
 
3139 3139
 		$attribute_defined_as_available_for_variation = '';
3140
-		if ( !empty($attribute_list) ) {
3140
+		if (!empty($attribute_list)) {
3141 3141
 			foreach ($attribute_list as $list_type => $attribute_list_by_type) {
3142 3142
 				$sub_attribute_list = '';
3143 3143
 				foreach ($attribute_list_by_type as $attribute_code => $attribute_def) {
3144 3144
 					$tpl_component = array();
3145
-					if ( $list_type == 'available' ) {
3145
+					if ($list_type == 'available') {
3146 3146
 						$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_LABEL_STATE'] = '';
3147 3147
 						$tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = '';
3148 3148
 						$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL_EXPLAINATION'] = '';
@@ -3156,13 +3156,13 @@  discard block
 block discarded – undo
3156 3156
 					$tpl_component['ADMIN_ATTRIBUTE_CODE_FOR_VARIATION'] = $attribute_code;
3157 3157
 					$tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_NAME'] = $attribute_code;
3158 3158
 					$tpl_component['ADMIN_VARIATION_ATTRIBUTE_CONTAINER_CLASS'] = ' wpshop_attribute_for_variation_' . $attribute_code;
3159
-					$tpl_component['ADMIN_VARIATION_NEW_SINGLE_LABEL'] = __( $attribute_def['label'], 'wpshop' );
3159
+					$tpl_component['ADMIN_VARIATION_NEW_SINGLE_LABEL'] = __($attribute_def['label'], 'wpshop');
3160 3160
 					$tpl_component['ADMIN_VARIATION_NEW_SINGLE_INPUT'] = '';
3161
-					if ( $variation_type == 'single' ) {
3162
-						$attribute_output_def = wpshop_attributes::get_attribute_field_definition( $attribute_def['attribute_complete_def'], $attribute_def['values'], array('from' => 'frontend', 'field_custom_name_prefix' => 'variation_attr', 'input_class' => ' variation_attribute_usable_input') );
3163
-						if ( !empty($attribute_output_def['possible_value']) ) {
3164
-							foreach( $attribute_output_def['possible_value'] as $value_id => $value ){
3165
-								if ( !in_array($value_id, $attribute_def['values']) ) {
3161
+					if ($variation_type == 'single') {
3162
+						$attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_def['attribute_complete_def'], $attribute_def['values'], array('from' => 'frontend', 'field_custom_name_prefix' => 'variation_attr', 'input_class' => ' variation_attribute_usable_input'));
3163
+						if (!empty($attribute_output_def['possible_value'])) {
3164
+							foreach ($attribute_output_def['possible_value'] as $value_id => $value) {
3165
+								if (!in_array($value_id, $attribute_def['values'])) {
3166 3166
 									unset($attribute_output_def['possible_value'][$value_id]);
3167 3167
 								}
3168 3168
 							}
@@ -3177,7 +3177,7 @@  discard block
 block discarded – undo
3177 3177
 			}
3178 3178
 		}
3179 3179
 
3180
-		return array($attribute_defined_as_available_for_variation, ( (!empty($attribute_list['available']) ) ? $attribute_list['available'] : ''), ( ( !empty($attribute_list['unavailable']) ) ? $attribute_list['unavailable'] : ''));
3180
+		return array($attribute_defined_as_available_for_variation, ((!empty($attribute_list['available'])) ? $attribute_list['available'] : ''), ((!empty($attribute_list['unavailable'])) ? $attribute_list['unavailable'] : ''));
3181 3181
 	}
3182 3182
 
3183 3183
 	/**
@@ -3186,18 +3186,18 @@  discard block
 block discarded – undo
3186 3186
 	 * @param array $variations_attribute_parameters Allows to give some parameters for customize list
3187 3187
 	 * @return string The output for all specific attribute in each product with option
3188 3188
 	 */
3189
-	public static function get_variation_attribute( $variations_attribute_parameters ) {
3189
+	public static function get_variation_attribute($variations_attribute_parameters) {
3190 3190
 		$output = '';
3191 3191
 
3192 3192
 		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_in_variation", true);
3193
-		if ( !empty( $attribute_list ) ) {
3193
+		if (!empty($attribute_list)) {
3194 3194
 			$tpl_component = array();
3195 3195
 			$tpl_component['ADMIN_VARIATION_DETAIL'] = '';
3196 3196
 			$price_piloting_option = get_option('wpshop_shop_price_piloting');
3197
-			foreach ( $attribute_list as $attribute_def ) {
3197
+			foreach ($attribute_list as $attribute_def) {
3198 3198
 
3199 3199
 				$variations_attribute_parameters['field_custom_name_prefix'] = $variations_attribute_parameters['field_name'] . '[attribute][' . $attribute_def->data_type . ']';
3200
-				$attribute_output_def = wpshop_attributes::get_attribute_field_definition( $attribute_def, (!empty($variations_attribute_parameters['variation_dif_values'][$attribute_def->code]) ? $variations_attribute_parameters['variation_dif_values'][$attribute_def->code] : ''), $variations_attribute_parameters );
3200
+				$attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_def, (!empty($variations_attribute_parameters['variation_dif_values'][$attribute_def->code]) ? $variations_attribute_parameters['variation_dif_values'][$attribute_def->code] : ''), $variations_attribute_parameters);
3201 3201
 
3202 3202
 				$field_output = $attribute_output_def['output'];
3203 3203
 
@@ -3209,9 +3209,9 @@  discard block
 block discarded – undo
3209 3209
 				$sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_ID'] = $attribute_output_def['id'];
3210 3210
 				$sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_LABEL'] = $attribute_output_def['label'];
3211 3211
 				$sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_INPUT'] = $field_output;
3212
-				if( isset( $variations_attribute_parameters['post_id'] ) ) {
3213
-					$attribute_option_display = $attribute_def->backend_input=='select' && (strtolower( __(self::get_attribute_type_select_option_info($attribute_output_def['value'], 'value'), 'wpshop') ) == strtolower( __('yes', 'wpshop') )) ? '' : ' wpshopHide';
3214
-					$sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_INPUT'] .= '<div class="attribute_option_'.$attribute_def->code.''.$attribute_option_display.'">'.self::get_attribute_option_fields($variations_attribute_parameters['post_id'], $attribute_def->code).'</div>';
3212
+				if (isset($variations_attribute_parameters['post_id'])) {
3213
+					$attribute_option_display = $attribute_def->backend_input == 'select' && (strtolower(__(self::get_attribute_type_select_option_info($attribute_output_def['value'], 'value'), 'wpshop')) == strtolower(__('yes', 'wpshop'))) ? '' : ' wpshopHide';
3214
+					$sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_INPUT'] .= '<div class="attribute_option_' . $attribute_def->code . '' . $attribute_option_display . '">' . self::get_attribute_option_fields($variations_attribute_parameters['post_id'], $attribute_def->code) . '</div>';
3215 3215
 				}
3216 3216
 				$tpl_component['ADMIN_VARIATION_DETAIL'] .= wpshop_display::display_template_element('wpshop_admin_variation_item_details_line', $sub_tpl_component, array(), 'admin');
3217 3217
 				unset($sub_tpl_component);
@@ -3222,7 +3222,7 @@  discard block
 block discarded – undo
3222 3222
 		return $output;
3223 3223
 	}
3224 3224
 
3225
-	public static function get_attribute_user_defined( $use_defined_parameters, $status = "'publish'" ) {
3225
+	public static function get_attribute_user_defined($use_defined_parameters, $status = "'publish'") {
3226 3226
 		global $wpdb;
3227 3227
 		$attribute_user_defined_list = array();
3228 3228
 
@@ -3249,12 +3249,12 @@  discard block
 block discarded – undo
3249 3249
 	 * @param string $post_type The current
3250 3250
 	 *
3251 3251
 	 */
3252
-	function quick_edit( $column_name, $entity ) {
3253
-		switch ( $entity ) {
3252
+	function quick_edit($column_name, $entity) {
3253
+		switch ($entity) {
3254 3254
 			case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
3255 3255
 				$attribute_def = wpshop_attributes::getElement($column_name, "'valid'", 'code');
3256
-				if ( !empty($attribute_def) ) {
3257
-					$input_def = self::get_attribute_field_definition( $attribute_def, '', array('input_class' => ' wpshop_bulk_and_quick_edit_input') );
3256
+				if (!empty($attribute_def)) {
3257
+					$input_def = self::get_attribute_field_definition($attribute_def, '', array('input_class' => ' wpshop_bulk_and_quick_edit_input'));
3258 3258
 					$input = wpshop_form::check_input_type($input_def, $input_def['input_domain']);
3259 3259
 ?>
3260 3260
 	<div class="wpshop_bulk_and_quick_edit_column_container wpshop_bulk_and_quick_edit_column_<?php echo $column_name; ?>_container">
@@ -3274,12 +3274,12 @@  discard block
 block discarded – undo
3274 3274
 	 * @param string $post_type The current
3275 3275
 	 *
3276 3276
 	 */
3277
-	public static function bulk_edit( $column_name, $entity ) {
3278
-		switch ( $entity ) {
3277
+	public static function bulk_edit($column_name, $entity) {
3278
+		switch ($entity) {
3279 3279
 			case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
3280 3280
 				$attribute_def = wpshop_attributes::getElement($column_name, "'valid'", 'code');
3281
-				if ( !empty($attribute_def) ) {
3282
-					$input_def = self::get_attribute_field_definition( $attribute_def, '', array('input_class' => ' wpshop_bulk_and_quick_edit_input') );
3281
+				if (!empty($attribute_def)) {
3282
+					$input_def = self::get_attribute_field_definition($attribute_def, '', array('input_class' => ' wpshop_bulk_and_quick_edit_input'));
3283 3283
 					$input = wpshop_form::check_input_type($input_def, $input_def['input_domain']);
3284 3284
 ?>
3285 3285
 	<div class="wpshop_bulk_and_quick_edit_column_container wpshop_bulk_and_quick_edit_column_<?php echo $column_name; ?>_container">
Please login to merge, or discard this patch.
includes/librairies/catalog/products.class.php 1 patch
Indentation   +3123 added lines, -3123 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
 /**
@@ -26,160 +26,160 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class wpshop_products
28 28
 {
29
-    /**
30
-     *    Définition du code de la classe courante
31
-     */
32
-    const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
33
-    const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION;
34
-
35
-    public function add_product_to_current_order_interface()
36
-    {
37
-        $output = '';
38
-        $output .= self::products_list_js();
39
-        $output .= '<input type="text" id="wps_order_search_product" />';
40
-        echo $output;
41
-        die();
42
-    }
29
+	/**
30
+	 *    Définition du code de la classe courante
31
+	 */
32
+	const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
33
+	const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION;
34
+
35
+	public function add_product_to_current_order_interface()
36
+	{
37
+		$output = '';
38
+		$output .= self::products_list_js();
39
+		$output .= '<input type="text" id="wps_order_search_product" />';
40
+		echo $output;
41
+		die();
42
+	}
43 43
 
44
-    public function products_list_js()
45
-    {
46
-        global $wpdb;
47
-        /** Create a JS Array of products **/
44
+	public function products_list_js()
45
+	{
46
+		global $wpdb;
47
+		/** Create a JS Array of products **/
48 48
 //         $query = $wpdb->prepare('SELECT ID, post_title FROM ' .$wpdb->posts. '  WHERE post_type = %s AND post_status = %s', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
49
-        //         $products_post = $wpdb->get_results( $query );
50
-
51
-        $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1));
52
-
53
-        if (!empty($products_post)) {
54
-            $products_js_array = 'var products = [';
55
-            foreach ($products_post as $product) {
56
-                $barcode = get_post_meta($product->ID, '_barcode', true);
57
-                $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", ';
58
-                $products_js_array .= 'value:"' . $product->ID . '", ';
59
-                $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},';
60
-            }
61
-            $products_js_array .= '];';
62
-        }
63
-        $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin');
64
-        return $output;
65
-    }
49
+		//         $products_post = $wpdb->get_results( $query );
50
+
51
+		$products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1));
52
+
53
+		if (!empty($products_post)) {
54
+			$products_js_array = 'var products = [';
55
+			foreach ($products_post as $product) {
56
+				$barcode = get_post_meta($product->ID, '_barcode', true);
57
+				$products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", ';
58
+				$products_js_array .= 'value:"' . $product->ID . '", ';
59
+				$products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},';
60
+			}
61
+			$products_js_array .= '];';
62
+		}
63
+		$output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin');
64
+		return $output;
65
+	}
66 66
 
67
-    /**
68
-     *    Déclaration des produits et variations en tant que "post" de wordpress
69
-     *
70
-     *    @see register_post_type()
71
-     */
72
-    public static function create_wpshop_products_type()
73
-    {
74
-
75
-        $options = get_option('wpshop_catalog_product_option', array());
76
-        //$options2 = get_option('wpshop_catalog_categories_option', array());
77
-        /*echo '<pre>'; print_r( $options ); echo '</pre>';
67
+	/**
68
+	 *    Déclaration des produits et variations en tant que "post" de wordpress
69
+	 *
70
+	 *    @see register_post_type()
71
+	 */
72
+	public static function create_wpshop_products_type()
73
+	{
74
+
75
+		$options = get_option('wpshop_catalog_product_option', array());
76
+		//$options2 = get_option('wpshop_catalog_categories_option', array());
77
+		/*echo '<pre>'; print_r( $options ); echo '</pre>';
78 78
         echo '<pre>'; print_r( $options2 ); echo '</pre>'; exit();*/
79 79
 
80
-        $slug = array(
81
-            'slug' => '',
82
-            'with_front' => false,
83
-        );
84
-
85
-        if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') {
86
-            $slug = false;
87
-        } else {
88
-            $slug['slug'] = $options['wpshop_catalog_product_slug'];
89
-            if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
90
-                $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%';
91
-            }
92
-        }
93
-        /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/
94
-
95
-        /*    Définition des produits     */
96
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array(
97
-            'labels' => array(
98
-                'name' => __('Products', 'wpshop'),
99
-                'singular_name' => __('Catalog', 'wpshop'),
100
-                'add_new_item' => __('Add new product', 'wpshop'),
101
-                'add_new' => __('Add new product', 'wpshop'),
102
-                'add_new_item' => __('Add new product', 'wpshop'),
103
-                'edit_item' => __('Edit product', 'wpshop'),
104
-                'new_item' => __('New product', 'wpshop'),
105
-                'view_item' => __('View product', 'wpshop'),
106
-                'search_items' => __('Search products', 'wpshop'),
107
-                'not_found' => __('No products found', 'wpshop'),
108
-                'not_found_in_trash' => __('No products found in Trash', 'wpshop'),
109
-                'parent_item_colon' => '',
110
-            ),
111
-            'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
112
-            'public' => true,
113
-            'has_archive' => true,
114
-            'show_in_nav_menus' => true,
115
-            //'rewrite'                 => false,    //    For information see below
116
-            'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES),
117
-            'menu_icon' => 'dashicons-archive',
118
-            'rewrite' => $slug,
119
-        )));
120
-
121
-        /*    Définition des variations de produit (Déclinaisons)    */
122
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array(
123
-            'labels' => array(
124
-                'name' => __('Variations', 'wpshop'),
125
-                'singular_name' => __('Variation', 'wpshop'),
126
-                'add_new' => __('Add Variation', 'wpshop'),
127
-                'add_new_item' => __('Add New Variation', 'wpshop'),
128
-                'edit' => __('Edit', 'wpshop'),
129
-                'edit_item' => __('Edit Variation', 'wpshop'),
130
-                'new_item' => __('New Variation', 'wpshop'),
131
-                'view' => __('View Variation', 'wpshop'),
132
-                'view_item' => __('View Variation', 'wpshop'),
133
-                'search_items' => __('Search Variations', 'wpshop'),
134
-                'not_found' => __('No Variations found', 'wpshop'),
135
-                'not_found_in_trash' => __('No Variations found in trash', 'wpshop'),
136
-                'parent_item_colon' => '',
137
-            ),
138
-            'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
139
-            'public' => true,
140
-            'has_archive' => true,
141
-            'show_in_nav_menus' => false,
142
-            'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
143
-
144
-            'publicly_queryable' => false,
145
-            'exclude_from_search' => true,
146
-            'hierarchical' => false,
147
-
148
-            //             'public'                 => true,
149
-            //             'show_ui'                 => false,
150
-            //             'rewrite'                 => false,
151
-            //             'query_var'                => true,
152
-            //             'supports'                 => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
153
-            //             'show_in_nav_menus'     => false
154
-        )
155
-        ));
156
-
157
-        // add to our plugin init function
158
-        //global $wp_rewrite;
159
-        /*    Slug url is set into option    */
160
-        /*$options = get_option('wpshop_catalog_product_option', array());
80
+		$slug = array(
81
+			'slug' => '',
82
+			'with_front' => false,
83
+		);
84
+
85
+		if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') {
86
+			$slug = false;
87
+		} else {
88
+			$slug['slug'] = $options['wpshop_catalog_product_slug'];
89
+			if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
90
+				$slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%';
91
+			}
92
+		}
93
+		/*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/
94
+
95
+		/*    Définition des produits     */
96
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array(
97
+			'labels' => array(
98
+				'name' => __('Products', 'wpshop'),
99
+				'singular_name' => __('Catalog', 'wpshop'),
100
+				'add_new_item' => __('Add new product', 'wpshop'),
101
+				'add_new' => __('Add new product', 'wpshop'),
102
+				'add_new_item' => __('Add new product', 'wpshop'),
103
+				'edit_item' => __('Edit product', 'wpshop'),
104
+				'new_item' => __('New product', 'wpshop'),
105
+				'view_item' => __('View product', 'wpshop'),
106
+				'search_items' => __('Search products', 'wpshop'),
107
+				'not_found' => __('No products found', 'wpshop'),
108
+				'not_found_in_trash' => __('No products found in Trash', 'wpshop'),
109
+				'parent_item_colon' => '',
110
+			),
111
+			'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
112
+			'public' => true,
113
+			'has_archive' => true,
114
+			'show_in_nav_menus' => true,
115
+			//'rewrite'                 => false,    //    For information see below
116
+			'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES),
117
+			'menu_icon' => 'dashicons-archive',
118
+			'rewrite' => $slug,
119
+		)));
120
+
121
+		/*    Définition des variations de produit (Déclinaisons)    */
122
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array(
123
+			'labels' => array(
124
+				'name' => __('Variations', 'wpshop'),
125
+				'singular_name' => __('Variation', 'wpshop'),
126
+				'add_new' => __('Add Variation', 'wpshop'),
127
+				'add_new_item' => __('Add New Variation', 'wpshop'),
128
+				'edit' => __('Edit', 'wpshop'),
129
+				'edit_item' => __('Edit Variation', 'wpshop'),
130
+				'new_item' => __('New Variation', 'wpshop'),
131
+				'view' => __('View Variation', 'wpshop'),
132
+				'view_item' => __('View Variation', 'wpshop'),
133
+				'search_items' => __('Search Variations', 'wpshop'),
134
+				'not_found' => __('No Variations found', 'wpshop'),
135
+				'not_found_in_trash' => __('No Variations found in trash', 'wpshop'),
136
+				'parent_item_colon' => '',
137
+			),
138
+			'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
139
+			'public' => true,
140
+			'has_archive' => true,
141
+			'show_in_nav_menus' => false,
142
+			'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
143
+
144
+			'publicly_queryable' => false,
145
+			'exclude_from_search' => true,
146
+			'hierarchical' => false,
147
+
148
+			//             'public'                 => true,
149
+			//             'show_ui'                 => false,
150
+			//             'rewrite'                 => false,
151
+			//             'query_var'                => true,
152
+			//             'supports'                 => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
153
+			//             'show_in_nav_menus'     => false
154
+		)
155
+		));
156
+
157
+		// add to our plugin init function
158
+		//global $wp_rewrite;
159
+		/*    Slug url is set into option    */
160
+		/*$options = get_option('wpshop_catalog_product_option', array());
161 161
         $gallery_structure = (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : 'catalog');
162 162
         $gallery_structure .= !empty($options['wpshop_catalog_product_slug_with_category']) ? '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%' : '';
163 163
         $gallery_structure .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';
164 164
         $wp_rewrite->add_permastruct(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $gallery_structure, false);
165 165
         $wp_rewrite->add_rewrite_tag('%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%', '([^/]+)', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "=");*/
166
-        //    flush_rewrite_rules();
167
-    }
166
+		//    flush_rewrite_rules();
167
+	}
168 168
 
169
-    public static function hidden_meta_boxes($hidden, $screen, $use_defaults)
170
-    {
171
-        global $wpdb;
172
-        if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) {
173
-            $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
174
-            foreach ($user_meta_for_wpshop as $meta_to_check) {
175
-                $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true);
176
-                if (empty($metas_hidden) && !is_array($metas_hidden)) {
177
-                    $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX);
178
-                }
179
-            }
180
-        }
181
-        return $hidden;
182
-    }
169
+	public static function hidden_meta_boxes($hidden, $screen, $use_defaults)
170
+	{
171
+		global $wpdb;
172
+		if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) {
173
+			$user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
174
+			foreach ($user_meta_for_wpshop as $meta_to_check) {
175
+				$metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true);
176
+				if (empty($metas_hidden) && !is_array($metas_hidden)) {
177
+					$hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX);
178
+				}
179
+			}
180
+		}
181
+		return $hidden;
182
+	}
183 183
 
184 184
 	public static function admin_menu() {
185 185
 		global $submenu;
@@ -206,35 +206,35 @@  discard block
 block discarded – undo
206 206
 		$submenu['edit.php?post_type=wpshop_product'] = $submenu_reorder;
207 207
 	}
208 208
 
209
-    /**
210
-     *    Create the different bow for the product management page looking for the attribute set to create the different boxes
211
-     */
212
-    public static function add_meta_boxes()
213
-    {
214
-        global $post, $currentTabContent;
215
-
216
-        if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) {
217
-            /*    Get the attribute set list for the current entity    */
218
-            $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
219
-            /*    Check if the meta information of the current product already exists     */
220
-            $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
221
-            /*    Check if the product has been saved without meta information set    */
222
-            $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode);
223
-            /*    Unset 'free_product' from list of attributes set    */
224
-            foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
225
-                if ($attribute_set->slug == 'free_product') {
226
-                    unset($attributeEntitySetList[$key_attribute_set]);
227
-                    break;
228
-                }
229
-            }
230
-
231
-            /*    Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing    */
232
-            if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) {
233
-                if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) {
234
-                    $post_attribute_set_id = $attributeEntitySetList[0]->id;
235
-                } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) {
236
-                    $post_attribute_set_id = $attribute_set_id->value;
237
-                }
209
+	/**
210
+	 *    Create the different bow for the product management page looking for the attribute set to create the different boxes
211
+	 */
212
+	public static function add_meta_boxes()
213
+	{
214
+		global $post, $currentTabContent;
215
+
216
+		if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) {
217
+			/*    Get the attribute set list for the current entity    */
218
+			$attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
219
+			/*    Check if the meta information of the current product already exists     */
220
+			$post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
221
+			/*    Check if the product has been saved without meta information set    */
222
+			$attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode);
223
+			/*    Unset 'free_product' from list of attributes set    */
224
+			foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
225
+				if ($attribute_set->slug == 'free_product') {
226
+					unset($attributeEntitySetList[$key_attribute_set]);
227
+					break;
228
+				}
229
+			}
230
+
231
+			/*    Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing    */
232
+			if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) {
233
+				if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) {
234
+					$post_attribute_set_id = $attributeEntitySetList[0]->id;
235
+				} elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) {
236
+					$post_attribute_set_id = $attribute_set_id->value;
237
+				}
238 238
 
239 239
 		/*$post_attribute_set_id = (int) get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
240 240
 
@@ -252,47 +252,47 @@  discard block
 block discarded – undo
252 252
 			}
253 253
 		}*/
254 254
 
255
-                $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID);
256
-
257
-                $fixed_box_exist = false;
258
-                /*    Get all the other attribute set for hte current entity    */
259
-                if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) {
260
-                    foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
261
-                        if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
262
-                            add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier));
263
-                        } else {
264
-                            $fixed_box_exist = true;
265
-                        }
266
-
267
-                    }
268
-                }
269
-                if ($fixed_box_exist) {
270
-                    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));
271
-                    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));
272
-                }
273
-
274
-                add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default');
275
-                // Actions
276
-                // @since 1.4.3.7 Deleted
277
-                //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
278
-
279
-                /**    Product option    */
280
-                add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
281
-            } else if (count($attributeEntitySetList) > 1) {
282
-                $input_def['id'] = 'product_attribute_set_id';
283
-                $input_def['name'] = 'product_attribute_set_id';
284
-                $input_def['value'] = '';
285
-                $input_def['type'] = 'select';
286
-                $input_def['possible_value'] = $attributeEntitySetList;
287
-
288
-                $input_def['value'] = '';
289
-                foreach ($attributeEntitySetList as $set) {
290
-                    if ($set->default_set == 'yes') {
291
-                        $input_def['value'] = $set->id;
292
-                    }
293
-                }
294
-
295
-                $currentTabContent['boxContent']['attribute_set_selector'] = '
255
+				$currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID);
256
+
257
+				$fixed_box_exist = false;
258
+				/*    Get all the other attribute set for hte current entity    */
259
+				if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) {
260
+					foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
261
+						if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
262
+							add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier));
263
+						} else {
264
+							$fixed_box_exist = true;
265
+						}
266
+
267
+					}
268
+				}
269
+				if ($fixed_box_exist) {
270
+					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));
271
+					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));
272
+				}
273
+
274
+				add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default');
275
+				// Actions
276
+				// @since 1.4.3.7 Deleted
277
+				//add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
278
+
279
+				/**    Product option    */
280
+				add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
281
+			} else if (count($attributeEntitySetList) > 1) {
282
+				$input_def['id'] = 'product_attribute_set_id';
283
+				$input_def['name'] = 'product_attribute_set_id';
284
+				$input_def['value'] = '';
285
+				$input_def['type'] = 'select';
286
+				$input_def['possible_value'] = $attributeEntitySetList;
287
+
288
+				$input_def['value'] = '';
289
+				foreach ($attributeEntitySetList as $set) {
290
+					if ($set->default_set == 'yes') {
291
+						$input_def['value'] = $set->id;
292
+					}
293
+				}
294
+
295
+				$currentTabContent['boxContent']['attribute_set_selector'] = '
296 296
 	<ul class="attribute_set_selector" >
297 297
 		<li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li>
298 298
 		<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>
@@ -300,792 +300,792 @@  discard block
 block discarded – undo
300 300
 		<li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li>
301 301
 	</ul>';
302 302
 
303
-                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'));
304
-            }
305
-        }
303
+				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'));
304
+			}
305
+		}
306 306
 
307
-    }
307
+	}
308 308
 
309
-    /**
310
-     * Add a box into product edition page for options on the product
311
-     *
312
-     * @param object $post
313
-     */
314
-    public static function product_options_meta_box_content($post)
315
-    {
316
-        $output = '';
309
+	/**
310
+	 * Add a box into product edition page for options on the product
311
+	 *
312
+	 * @param object $post
313
+	 */
314
+	public static function product_options_meta_box_content($post)
315
+	{
316
+		$output = '';
317 317
 
318
-        $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
318
+		$product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
319 319
 
320
-        $tpl_component = array();
321
-        $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
322
-        $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
320
+		$tpl_component = array();
321
+		$tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
322
+		$output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
323 323
 
324
-        echo $output;
325
-    }
324
+		echo $output;
325
+	}
326 326
 
327
-    /**
328
-     * Display the fixed box
329
-     */
330
-    public static function product_data_meta_box($post, $metaboxArgs)
331
-    {
332
-        $output = '';
327
+	/**
328
+	 * Display the fixed box
329
+	 */
330
+	public static function product_data_meta_box($post, $metaboxArgs)
331
+	{
332
+		$output = '';
333 333
 
334
-        $currentTabContent = $metaboxArgs['args']['currentTabContent'];
334
+		$currentTabContent = $metaboxArgs['args']['currentTabContent'];
335 335
 
336
-        echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
336
+		echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
337 337
 				<ul>';
338
-        if (!empty($currentTabContent['box'])) {
339
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
340
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
341
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
342
-                        echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
343
-                    }
344
-                }
345
-            }
346
-        }
347
-        echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
348
-        echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
349
-        echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
350
-        echo '</ul>';
351
-
352
-        if (!empty($currentTabContent['box'])) {
353
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
354
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
355
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
356
-                        echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
357
-                    }
358
-                }
359
-            }
360
-        }
338
+		if (!empty($currentTabContent['box'])) {
339
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
340
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
341
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
342
+						echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
343
+					}
344
+				}
345
+			}
346
+		}
347
+		echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
348
+		echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
349
+		echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
350
+		echo '</ul>';
351
+
352
+		if (!empty($currentTabContent['box'])) {
353
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
354
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
355
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
356
+						echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
357
+					}
358
+				}
359
+			}
360
+		}
361 361
 
362
-        echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
363
-        echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
364
-        echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
365
-        if (!empty($currentTabContent['boxMore'])) {
366
-            echo $currentTabContent['boxMore'];
367
-        }
368
-        echo '</div>';
362
+		echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
363
+		echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
364
+		echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
365
+		if (!empty($currentTabContent['boxMore'])) {
366
+			echo $currentTabContent['boxMore'];
367
+		}
368
+		echo '</div>';
369 369
 
370
-        echo $output;
371
-    }
370
+		echo $output;
371
+	}
372 372
 
373
-    /**
374
-     * Output the content for related product metabox
375
-     * @param object $post The current edited post
376
-     * @return string
377
-     */
378
-    public static function related_products_meta_box_content($post)
379
-    {
380
-        $content = $existing_selection = '';
381
-
382
-        if (!empty($post->ID)) {
383
-            $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
384
-            if (!empty($related_products_id) && !empty($related_products_id[0])) {
385
-                foreach ($related_products_id as $related_product_id) {
386
-                    $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
387
-                }
388
-            }
389
-        }
373
+	/**
374
+	 * Output the content for related product metabox
375
+	 * @param object $post The current edited post
376
+	 * @return string
377
+	 */
378
+	public static function related_products_meta_box_content($post)
379
+	{
380
+		$content = $existing_selection = '';
381
+
382
+		if (!empty($post->ID)) {
383
+			$related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
384
+			if (!empty($related_products_id) && !empty($related_products_id[0])) {
385
+				foreach ($related_products_id as $related_product_id) {
386
+					$existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
387
+				}
388
+			}
389
+		}
390 390
 
391
-        $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>
391
+		$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>
392 392
 			<select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select>
393 393
 			<input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" />
394 394
 			<input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
395 395
 
396
-        return $content;
397
-    }
396
+		return $content;
397
+	}
398 398
 
399
-    /**
400
-     * Output the content for related product metabox
401
-     * @param object $post The current edited post
402
-     * @return string
403
-     */
404
-    public static function provider_products_meta_box_content($post)
405
-    {
406
-        $content = $existing_selection = '';
407
-
408
-        if (!empty($post->ID)) {
409
-            $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
410
-            if (!empty($providers_id) && !empty($providers_id[0])) {
411
-                foreach ($providers_id as $provider_id) {
412
-                    $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
413
-                }
414
-            }
415
-        }
399
+	/**
400
+	 * Output the content for related product metabox
401
+	 * @param object $post The current edited post
402
+	 * @return string
403
+	 */
404
+	public static function provider_products_meta_box_content($post)
405
+	{
406
+		$content = $existing_selection = '';
407
+
408
+		if (!empty($post->ID)) {
409
+			$providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
410
+			if (!empty($providers_id) && !empty($providers_id[0])) {
411
+				foreach ($providers_id as $provider_id) {
412
+					$existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
413
+				}
414
+			}
415
+		}
416 416
 
417
-        $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
417
+		$content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
418 418
 			<select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select>
419 419
 			<input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" />
420 420
 			<input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
421 421
 
422
-        return $content;
423
-    }
422
+		return $content;
423
+	}
424 424
 
425
-    /**
426
-     * Define the metabox content for the action box
427
-     * @param obejct $post The current element being edited
428
-     */
429
-    public static function product_actions_meta_box_content($post)
430
-    {
431
-        $output = '';
432
-        /*
425
+	/**
426
+	 * Define the metabox content for the action box
427
+	 * @param obejct $post The current element being edited
428
+	 */
429
+	public static function product_actions_meta_box_content($post)
430
+	{
431
+		$output = '';
432
+		/*
433 433
          * Template parameters
434 434
          */
435
-        $template_part = 'wpshop_duplicate_product';
436
-        $tpl_component = array();
437
-        $tpl_component['PRODUCT_ID'] = $post->ID;
438
-        $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
439
-        /*
435
+		$template_part = 'wpshop_duplicate_product';
436
+		$tpl_component = array();
437
+		$tpl_component['PRODUCT_ID'] = $post->ID;
438
+		$tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
439
+		/*
440 440
          * Build template
441 441
          */
442
-        $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
443
-        unset($tpl_component);
442
+		$output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
443
+		unset($tpl_component);
444 444
 
445
-        echo $output;
446
-    }
445
+		echo $output;
446
+	}
447 447
 
448
-    /**
449
-     *    Define the content of the product main information box
450
-     */
451
-    public static function meta_box_content($post, $metaboxArgs)
452
-    {
453
-        global $currentTabContent;
448
+	/**
449
+	 *    Define the content of the product main information box
450
+	 */
451
+	public static function meta_box_content($post, $metaboxArgs)
452
+	{
453
+		global $currentTabContent;
454 454
 
455
-        /*    Add the extra fields defined by the default attribute group in the general section    */
456
-        echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
457
-    }
455
+		/*    Add the extra fields defined by the default attribute group in the general section    */
456
+		echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
457
+	}
458 458
 
459
-    /**
460
-     * Define the metabox content for product custom display in product
461
-     * @param object $post The current element being edited
462
-     * @return string The metabox content
463
-     */
464
-    public static function product_frontend_display_config_meta_box($post)
465
-    {
466
-        $content = '';
467
-
468
-        $product_attribute_frontend_display_config = null;
469
-        if (!empty($post->ID)) {
470
-            $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
471
-
472
-            $extra_options = get_option('wpshop_extra_options', array());
473
-            $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
474
-            $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
475
-            $column = 1;
476
-
477
-            if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
478
-                $sub_tpl_component = array();
479
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
480
-
481
-                $tpl_component = array();
482
-                $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
483
-                $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
484
-                $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
485
-                $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
486
-
487
-                $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"' : '';
488
-                $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"' : '';
489
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
490
-                unset($tpl_component);
491
-
492
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
493
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
494
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
495
-                $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
496
-            }
497
-
498
-            if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
499
-                foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
500
-                    if (!isset($sub_content[$column])) {
501
-                        $sub_content[$column] = '';
502
-                    }
503
-
504
-                    $attribute_sub_output = '';
505
-                    foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
506
-                        if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
507
-                            $tpl_component = array();
508
-                            $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
509
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
510
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
511
-                            $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"' : '';
512
-                            $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"' : '';
513
-                            $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
514
-                            unset($tpl_component);
515
-                        }
516
-                    }
517
-
518
-                    $tpl_component = array();
519
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
520
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
521
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
522
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
523
-                    $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"' : '';
524
-                    $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>';
525
-                    $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
526
-                    $column++;
527
-                    if ($column > $column_count) {
528
-                        $column = 1;
529
-                    }
530
-                }
531
-            }
532
-            $tpl_component = array();
533
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
534
-            for ($i = 1; $i <= $column_count; $i++) {
535
-                if (!empty($sub_content[$i])) {
536
-                    $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
537
-                }
538
-
539
-            }
540
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
541
-            $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
542
-            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
543
-
544
-            $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>';
545
-        }
459
+	/**
460
+	 * Define the metabox content for product custom display in product
461
+	 * @param object $post The current element being edited
462
+	 * @return string The metabox content
463
+	 */
464
+	public static function product_frontend_display_config_meta_box($post)
465
+	{
466
+		$content = '';
467
+
468
+		$product_attribute_frontend_display_config = null;
469
+		if (!empty($post->ID)) {
470
+			$product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
471
+
472
+			$extra_options = get_option('wpshop_extra_options', array());
473
+			$column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
474
+			$attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
475
+			$column = 1;
476
+
477
+			if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
478
+				$sub_tpl_component = array();
479
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
480
+
481
+				$tpl_component = array();
482
+				$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
483
+				$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
484
+				$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
485
+				$button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
486
+
487
+				$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"' : '';
488
+				$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"' : '';
489
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
490
+				unset($tpl_component);
491
+
492
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
493
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
494
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
495
+				$sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
496
+			}
546 497
 
547
-        return $content;
548
-    }
498
+			if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
499
+				foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
500
+					if (!isset($sub_content[$column])) {
501
+						$sub_content[$column] = '';
502
+					}
503
+
504
+					$attribute_sub_output = '';
505
+					foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
506
+						if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
507
+							$tpl_component = array();
508
+							$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
509
+							$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
510
+							$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
511
+							$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"' : '';
512
+							$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"' : '';
513
+							$attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
514
+							unset($tpl_component);
515
+						}
516
+					}
517
+
518
+					$tpl_component = array();
519
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
520
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
521
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
522
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
523
+					$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"' : '';
524
+					$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>';
525
+					$sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
526
+					$column++;
527
+					if ($column > $column_count) {
528
+						$column = 1;
529
+					}
530
+				}
531
+			}
532
+			$tpl_component = array();
533
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
534
+			for ($i = 1; $i <= $column_count; $i++) {
535
+				if (!empty($sub_content[$i])) {
536
+					$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
537
+				}
549 538
 
550
-    /**
551
-     * Retrieve the attribute list used for sorting product into frontend listing
552
-     * @return array The attribute list to use for listing sorting
553
-     */
554
-    public static function get_sorting_criteria()
555
-    {
556
-        global $wpdb;
539
+			}
540
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
541
+			$tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
542
+			$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
557 543
 
558
-        $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')));
544
+			$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>';
545
+		}
559 546
 
560
-        $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
561
-        $results = $wpdb->get_results($query, ARRAY_A);
562
-        if (!empty($results)) {
563
-            $data = array_merge($data, $results);
564
-        }
547
+		return $content;
548
+	}
565 549
 
566
-        return $data;
567
-    }
550
+	/**
551
+	 * Retrieve the attribute list used for sorting product into frontend listing
552
+	 * @return array The attribute list to use for listing sorting
553
+	 */
554
+	public static function get_sorting_criteria()
555
+	{
556
+		global $wpdb;
557
+
558
+		$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')));
559
+
560
+		$query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
561
+		$results = $wpdb->get_results($query, ARRAY_A);
562
+		if (!empty($results)) {
563
+			$data = array_merge($data, $results);
564
+		}
568 565
 
569
-    public static function get_products_matching_attribute($attr_name, $attr_value)
570
-    {
571
-        global $wpdb;
566
+		return $data;
567
+	}
568
+
569
+	public static function get_products_matching_attribute($attr_name, $attr_value)
570
+	{
571
+		global $wpdb;
572 572
 
573
-        $products = array();
574
-        $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
575
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
573
+		$products = array();
574
+		$query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
575
+		$data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
576 576
 
577
-        if (!empty($data)) {
578
-            if ($data['data_type_to_use'] == 'custom') {
579
-                // Find which table to take
580
-                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;}
577
+		if (!empty($data)) {
578
+			if ($data['data_type_to_use'] == 'custom') {
579
+				// Find which table to take
580
+				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;}
581 581
 
582
-                if (isset($table_name)) {
583
-                    // If the value is an id of a select, radio or checkbox
584
-                    if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
582
+				if (isset($table_name)) {
583
+					// If the value is an id of a select, radio or checkbox
584
+					if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
585 585
 
586
-                        $query = $wpdb->prepare("
586
+						$query = $wpdb->prepare("
587 587
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
588 588
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
589 589
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
590 590
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id
591 591
 							WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value
592
-                        );
593
-                        $data = $wpdb->get_results($query);
594
-                    } else {
592
+						);
593
+						$data = $wpdb->get_results($query);
594
+					} else {
595 595
 
596
-                        $query = $wpdb->prepare("
596
+						$query = $wpdb->prepare("
597 597
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
598 598
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
599 599
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
600 600
 								INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
601 601
 							WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000
602
-                        );
603
-                        $data = $wpdb->get_results($query);
604
-
605
-                    }
606
-                } else {
607
-                    return __('Incorrect shortcode', 'wpshop');
608
-                }
609
-
610
-            } elseif ($data['data_type_to_use'] == 'internal') {
611
-                /** Check the ID of manufacturer **/
612
-                $default_value = unserialize($data['default_value']);
613
-                if (!empty($default_value) && !empty($default_value['default_value'])) {
614
-                    $query = get_post($attr_value);
615
-                    $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
616
-                    if (!empty($pid)) {
617
-                        $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);
618
-                        $data = $wpdb->get_results($query);
619
-                    }
620
-                }
621
-            } else {
622
-                return __('Incorrect shortcode', 'wpshop');
623
-            }
624
-
625
-        } else {
626
-            return __('Incorrect shortcode', 'wpshop');
627
-        }
602
+						);
603
+						$data = $wpdb->get_results($query);
628 604
 
629
-        if (!empty($data)) {
630
-            foreach ($data as $p) {
631
-                if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
632
-                    $products[] = $p->entity_id;
633
-                }
634
-            }
635
-        }
636
-        return $products;
637
-    }
605
+					}
606
+				} else {
607
+					return __('Incorrect shortcode', 'wpshop');
608
+				}
638 609
 
639
-    /**
640
-     * Related product shortcode reader
641
-     *
642
-     * @param array $atts {
643
-     *    pid : Product idenfifier to get related element for
644
-     *    display_mode : The output mode if defined (grid || list)
645
-     * }
646
-     *
647
-     * @return string
648
-     *
649
-     */
650
-    public static function wpshop_related_products_func($atts)
651
-    {
652
-        global $wp_query;
610
+			} elseif ($data['data_type_to_use'] == 'internal') {
611
+				/** Check the ID of manufacturer **/
612
+				$default_value = unserialize($data['default_value']);
613
+				if (!empty($default_value) && !empty($default_value['default_value'])) {
614
+					$query = get_post($attr_value);
615
+					$pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
616
+					if (!empty($pid)) {
617
+						$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);
618
+						$data = $wpdb->get_results($query);
619
+					}
620
+				}
621
+			} else {
622
+				return __('Incorrect shortcode', 'wpshop');
623
+			}
653 624
 
654
-        $atts['product_type'] = 'related';
655
-        if (empty($atts['pid'])) {
656
-            $atts['pid'] = $wp_query->posts[0]->ID;
657
-        }
625
+		} else {
626
+			return __('Incorrect shortcode', 'wpshop');
627
+		}
658 628
 
659
-        $related_product_output = self::wpshop_products_func($atts);
629
+		if (!empty($data)) {
630
+			foreach ($data as $p) {
631
+				if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
632
+					$products[] = $p->entity_id;
633
+				}
634
+			}
635
+		}
636
+		return $products;
637
+	}
660 638
 
661
-        $output = '';
662
-        if (!empty($related_product_output)) {
663
-            ob_start();
664
-            require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
665
-            $output = ob_get_contents();
666
-            ob_end_clean();
667
-        }
639
+	/**
640
+	 * Related product shortcode reader
641
+	 *
642
+	 * @param array $atts {
643
+	 *    pid : Product idenfifier to get related element for
644
+	 *    display_mode : The output mode if defined (grid || list)
645
+	 * }
646
+	 *
647
+	 * @return string
648
+	 *
649
+	 */
650
+	public static function wpshop_related_products_func($atts)
651
+	{
652
+		global $wp_query;
653
+
654
+		$atts['product_type'] = 'related';
655
+		if (empty($atts['pid'])) {
656
+			$atts['pid'] = $wp_query->posts[0]->ID;
657
+		}
668 658
 
669
-        return $output;
670
-    }
659
+		$related_product_output = self::wpshop_products_func($atts);
671 660
 
672
-    /**
673
-     * Display a list of product from a shortcode
674
-     *
675
-     * @param array $atts {
676
-     *    limit : The number of element to display
677
-     *    order : The information to order list by
678
-     *    sorting : List order (ASC | DESC)
679
-     *    display : Display size (normal | mini)
680
-     *    type : Display tyep (grid | list) only work with display=normal
681
-     *    pagination : The number of element per page
682
-     * display_pagination : Display the pagination or not
683
-     * }
684
-     *
685
-     * @return string
686
-     *
687
-     **/
688
-    public static function wpshop_products_func($atts)
689
-    {
690
-        global $wpdb, $wp_query;
691
-
692
-        $string = '';
693
-        $have_results = false;
694
-        $output_results = true;
695
-        $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
696
-        $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
697
-        $cid = !empty($atts['cid']) ? $atts['cid'] : 0;
698
-        $pid = !empty($atts['pid']) ? $atts['pid'] : 0;
699
-        $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
700
-        $limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
701
-        $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;
702
-        $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
703
-        $attr = '';
704
-
705
-        $sorting_criteria = self::get_sorting_criteria();
706
-
707
-        /** Get products which have att_name equal to att_value    */
708
-        if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
709
-            $attr = $atts['att_name'] . ':' . $atts['att_value'];
710
-
711
-            $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
712
-
713
-            // Foreach on the found products
714
-            if (!empty($products)) {
715
-                $pid = implode(',', $products);
716
-                if (empty($pid)) {
717
-                    $output_results = false;
718
-                }
719
-
720
-            } else {
721
-                $output_results = false;
722
-            }
661
+		$output = '';
662
+		if (!empty($related_product_output)) {
663
+			ob_start();
664
+			require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
665
+			$output = ob_get_contents();
666
+			ob_end_clean();
667
+		}
723 668
 
724
-        }
669
+		return $output;
670
+	}
725 671
 
726
-        /** Get related products    */
727
-        if (!empty($atts['product_type'])) {
728
-            switch ($atts['product_type']) {
729
-                case 'related':
730
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
731
-                    $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
732
-                    $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;
733
-
734
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
735
-                    if (!empty($pids) && !empty($pids[0])) {
736
-                        $pid = implode(',', $pids);
737
-                    }
738
-                    if (empty($pid) || $pid == $product_id) {
739
-                        $output_results = false;
740
-                    }
741
-
742
-                    break;
743
-            }
744
-        }
672
+	/**
673
+	 * Display a list of product from a shortcode
674
+	 *
675
+	 * @param array $atts {
676
+	 *    limit : The number of element to display
677
+	 *    order : The information to order list by
678
+	 *    sorting : List order (ASC | DESC)
679
+	 *    display : Display size (normal | mini)
680
+	 *    type : Display tyep (grid | list) only work with display=normal
681
+	 *    pagination : The number of element per page
682
+	 * display_pagination : Display the pagination or not
683
+	 * }
684
+	 *
685
+	 * @return string
686
+	 *
687
+	 **/
688
+	public static function wpshop_products_func($atts)
689
+	{
690
+		global $wpdb, $wp_query;
691
+
692
+		$string = '';
693
+		$have_results = false;
694
+		$output_results = true;
695
+		$type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
696
+		$pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
697
+		$cid = !empty($atts['cid']) ? $atts['cid'] : 0;
698
+		$pid = !empty($atts['pid']) ? $atts['pid'] : 0;
699
+		$order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
700
+		$limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
701
+		$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;
702
+		$display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
703
+		$attr = '';
704
+
705
+		$sorting_criteria = self::get_sorting_criteria();
706
+
707
+		/** Get products which have att_name equal to att_value    */
708
+		if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
709
+			$attr = $atts['att_name'] . ':' . $atts['att_value'];
710
+
711
+			$products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
712
+
713
+			// Foreach on the found products
714
+			if (!empty($products)) {
715
+				$pid = implode(',', $products);
716
+				if (empty($pid)) {
717
+					$output_results = false;
718
+				}
745 719
 
746
-        /** Output all the products    */
747
-        if ($output_results) {
748
-            $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);
720
+			} else {
721
+				$output_results = false;
722
+			}
749 723
 
750
-            if ($data[0]) {
751
-                $have_results = true;
752
-                $string = $data[1];
753
-            }
754
-        }
724
+		}
755 725
 
756
-        /** If there are result to display    */
757
-        if ($have_results) {
758
-            $sorting = '';
759
-            if (!empty($pid)) {
760
-                $product_list = explode(',', $pid);
761
-                if (count($product_list) == 1) {
762
-                    $atts['sorting'] = 'no';
763
-                }
764
-            }
765
-
766
-            /*
726
+		/** Get related products    */
727
+		if (!empty($atts['product_type'])) {
728
+			switch ($atts['product_type']) {
729
+				case 'related':
730
+					$product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
731
+					$type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
732
+					$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;
733
+
734
+					$pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
735
+					if (!empty($pids) && !empty($pids[0])) {
736
+						$pid = implode(',', $pids);
737
+					}
738
+					if (empty($pid) || $pid == $product_id) {
739
+						$output_results = false;
740
+					}
741
+
742
+					break;
743
+			}
744
+		}
745
+
746
+		/** Output all the products    */
747
+		if ($output_results) {
748
+			$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);
749
+
750
+			if ($data[0]) {
751
+				$have_results = true;
752
+				$string = $data[1];
753
+			}
754
+		}
755
+
756
+		/** If there are result to display    */
757
+		if ($have_results) {
758
+			$sorting = '';
759
+			if (!empty($pid)) {
760
+				$product_list = explode(',', $pid);
761
+				if (count($product_list) == 1) {
762
+					$atts['sorting'] = 'no';
763
+				}
764
+			}
765
+
766
+			/*
767 767
              * Template parameters
768 768
              */
769
-            $template_part = 'product_listing_sorting';
770
-            $tpl_component = array();
769
+			$template_part = 'product_listing_sorting';
770
+			$tpl_component = array();
771 771
 
772
-            /*
772
+			/*
773 773
              * Build template
774 774
              */
775
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
776
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
777
-                /*    Include the old way template part    */
778
-                ob_start();
779
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
780
-                $sorting = ob_get_contents();
781
-                ob_end_clean();
782
-            } else {
783
-                /*
775
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
776
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
777
+				/*    Include the old way template part    */
778
+				ob_start();
779
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
780
+				$sorting = ob_get_contents();
781
+				ob_end_clean();
782
+			} else {
783
+				/*
784 784
                  * Display hidden field every times
785 785
                  */
786
-                $sub_template_part = 'product_listing_sorting_hidden_field';
787
-                $sub_tpl_component = array();
788
-                $sub_tpl_component['DISPLAY_TYPE'] = $type;
789
-                $sub_tpl_component['ORDER'] = $order_by_sorting;
790
-                $sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
791
-                $sub_tpl_component['CURRENT_PAGE'] = 1;
792
-                $sub_tpl_component['CATEGORY_ID'] = $cid;
793
-                $sub_tpl_component['PRODUCT_ID'] = $pid;
794
-                $sub_tpl_component['ATTR'] = $attr;
795
-                $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
796
-                unset($sub_tpl_component);
797
-
798
-                if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
799
-                    $sub_template_part = 'product_listing_sorting_criteria';
800
-                    $sub_tpl_component = array();
801
-                    $criteria = '';
802
-                    foreach ($sorting_criteria as $c):
786
+				$sub_template_part = 'product_listing_sorting_hidden_field';
787
+				$sub_tpl_component = array();
788
+				$sub_tpl_component['DISPLAY_TYPE'] = $type;
789
+				$sub_tpl_component['ORDER'] = $order_by_sorting;
790
+				$sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
791
+				$sub_tpl_component['CURRENT_PAGE'] = 1;
792
+				$sub_tpl_component['CATEGORY_ID'] = $cid;
793
+				$sub_tpl_component['PRODUCT_ID'] = $pid;
794
+				$sub_tpl_component['ATTR'] = $attr;
795
+				$tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
796
+				unset($sub_tpl_component);
797
+
798
+				if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
799
+					$sub_template_part = 'product_listing_sorting_criteria';
800
+					$sub_tpl_component = array();
801
+					$criteria = '';
802
+					foreach ($sorting_criteria as $c):
803 803
 						$selected = isset( $atts['order'] ) ? $atts['order'] : null;
804
-                        $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
805
-                    endforeach;
806
-                    $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
807
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
808
-                    unset($sub_tpl_component);
809
-                }
810
-
811
-                if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
812
-                    $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
813
-                    $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
814
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component);
815
-                } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
816
-                    $sub_template_part = 'product_listing_sorting_criteria_hidden';
817
-                    $sub_tpl_component = array();
818
-                    $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
819
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
820
-                    unset($sub_tpl_component);
821
-
822
-                    $template_part = 'product_listing_sorting_hidden';
823
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
824
-                }
825
-            }
826
-            unset($tpl_component);
827
-
828
-            if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
829
-                $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
830
-            } else {
831
-                $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>';
832
-            }
833
-        } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
834
-            $string = __('There is nothing to output here', 'wpshop');
835
-        }
804
+						$criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
805
+					endforeach;
806
+					$sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
807
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
808
+					unset($sub_tpl_component);
809
+				}
836 810
 
837
-        return do_shortcode($string);
838
-    }
811
+				if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
812
+					$tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
813
+					$tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
814
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component);
815
+				} else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
816
+					$sub_template_part = 'product_listing_sorting_criteria_hidden';
817
+					$sub_tpl_component = array();
818
+					$sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
819
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
820
+					unset($sub_tpl_component);
821
+
822
+					$template_part = 'product_listing_sorting_hidden';
823
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
824
+				}
825
+			}
826
+			unset($tpl_component);
839 827
 
840
-    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)
841
-    {
842
-        global $wpdb;
828
+			if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
829
+				$string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
830
+			} else {
831
+				$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>';
832
+			}
833
+		} else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
834
+			$string = __('There is nothing to output here', 'wpshop');
835
+		}
843 836
 
844
-        $string = '<span id="wpshop_loading">&nbsp;</span>';
845
-        $have_results = false;
846
-        $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
837
+		return do_shortcode($string);
838
+	}
847 839
 
848
-        /** Check if Discount are activated */
849
-        $discount_option = get_option('wpshop_catalog_product_option');
840
+	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)
841
+	{
842
+		global $wpdb;
850 843
 
851
-        if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
852
-            $criteria = 'wpshop_displayed_price';
853
-        }
844
+		$string = '<span id="wpshop_loading">&nbsp;</span>';
845
+		$have_results = false;
846
+		$display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
854 847
 
855
-        $query = array(
856
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
857
-            'order' => $order,
858
-            'posts_per_page' => $products_per_page,
859
-            'paged' => $page_number,
860
-            'post_status' => 'publish',
861
-        );
862
-
863
-        // If the limit is greater than zero, hide pagination and change posts_per_page var
864
-        if ($nb_of_product_limit > 0) {
865
-            $query['posts_per_page'] = $nb_of_product_limit;
866
-            unset($query['paged']);
867
-        }
868
-        if (!empty($pid)) {
869
-            if (!is_array($pid)) {
870
-                $pid = explode(',', $pid);
871
-            }
848
+		/** Check if Discount are activated */
849
+		$discount_option = get_option('wpshop_catalog_product_option');
872 850
 
873
-            $query['post__in'] = $pid;
874
-        }
875
-        if (!empty($cid)) {
876
-            $cid = explode(',', $cid);
877
-            $query['tax_query'] = array(array(
878
-                'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
879
-                'field' => 'id',
880
-                'terms' => $cid,
881
-                'operator' => 'IN',
882
-            ));
883
-        }
884
-        if ($criteria != null) {
885
-            switch ($criteria) {
886
-                case 'creator':
887
-                case 'author':
888
-                    $query['author'] = get_current_user_id();
889
-                    break;
890
-                case 'none':
891
-                case 'ID':
892
-                case 'title':
893
-                case 'date':
894
-                case 'modified':
895
-                case 'relevance':
896
-                case 'post__in':
897
-                case 'rand':
898
-                    $query['orderby'] = $criteria;
899
-                    break;
900
-                default:
901
-                    if (!empty($pid)) {
902
-                        $post_meta = get_post_meta($pid, '_' . $criteria, true);
903
-                    } else {
904
-                        $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
905
-                        $post_meta = $wpdb->get_var($check_meta);
906
-                    }
907
-                    if (!empty($post_meta)) {
908
-                        if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
909
-                            $query['orderby'] = 'meta_value_num';
910
-                        } else {
911
-                            $query['orderby'] = 'meta_value';
912
-                        }
913
-                        $query['meta_key'] = '_' . $criteria;
914
-                    }
915
-                    break;
916
-            }
917
-        } else {
918
-            $query['orderby'] = 'menu_order ID';
919
-        }
920
-        $post_per_page = $query['posts_per_page'];
921
-        $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
922
-        if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
923
-            $tmp_array = array();
924
-
925
-            if (empty($page_number) || $page_number == 1) {
926
-                for ($i = 0; $i < $query['posts_per_page']; $i++) {
927
-                    $tmp_array[] = $query['post__in'][$i];
928
-                }
929
-            } else {
930
-                $begin_number = (($page_number - 1) * $query['posts_per_page']);
931
-                for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
932
-                    if (!empty($query['post__in'][$i])) {
933
-                        $tmp_array[] = $query['post__in'][$i];
934
-                    }
935
-                }
936
-            }
937
-            unset($query['post__in']);
938
-            $query['post__in'] = $tmp_array;
939
-            $query['posts_per_page'] = -1;
940
-        }
851
+		if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
852
+			$criteria = 'wpshop_displayed_price';
853
+		}
941 854
 
942
-        $query['post_status'] = 'publish';
943
-
944
-        $custom_query = new WP_Query($query);
945
-
946
-        if ($custom_query->have_posts()) {
947
-            $have_results = true;
948
-
949
-            // ---------------- //
950
-            // Products listing //
951
-            // ---------------- //
952
-            $current_position = 1;
953
-            $product_list = '';
954
-            while ($custom_query->have_posts()): $custom_query->the_post();
955
-                $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
956
-                $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
957
-                $cat_id = empty($cats) ? 0 : $cats[0]->term_id;
958
-                $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
959
-                $current_position++;
960
-            endwhile;
961
-            $tpl_component = array();
962
-            $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
963
-            $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
964
-            $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
965
-            $tpl_component['PRODUCT_LIST'] = $product_list;
966
-            $tpl_component['CROSSED_OUT_PRICE'] = '';
967
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
968
-            $string = wpshop_display::display_template_element('product_list_container', $tpl_component);
969
-
970
-            // --------------------- //
971
-            // Pagination management //
972
-            // --------------------- //
973
-            if ( $display_pagination ) {
974
-                if ($nb_of_product_limit == 0) {
975
-
976
-                    $paginate = paginate_links(array(
977
-                        'base' => '%_%',
978
-                        'format' => '/?page_product=%#%',
979
-                        'current' => $page_number,
980
-                        'total' => $custom_query->max_num_pages,
981
-                        'type' => 'array',
982
-                        'prev_next' => false,
983
-                    ));
984
-                    if (!empty($paginate)) {
985
-                        $string .= '<ul class="pagination wps-pagination">';
986
-                        foreach ($paginate as $p) {
987
-                            $string .= '<li>' . $p . '</li>';
988
-                        }
989
-                        $string .= '</ul>';
990
-                    }
991
-                }
992
-
993
-                if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
994
-                    $paginate = paginate_links(array(
995
-                        'base' => '%_%',
996
-                        'format' => '/?page_product=%#%',
997
-                        'current' => $page_number,
998
-                        'total' => ceil(count($total_products) / $post_per_page),
999
-                        'type' => 'array',
1000
-                        'prev_next' => false,
1001
-                    ));
1002
-                    if (!empty($paginate)) {
1003
-                        $string .= '<ul class="pagination wps-pagination">';
1004
-                        foreach ($paginate as $p) {
1005
-                            $string .= '<li>' . $p . '</li>';
1006
-                        }
1007
-                        $string .= '</ul>';
1008
-                    }
1009
-                }
1010
-            }
855
+		$query = array(
856
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
857
+			'order' => $order,
858
+			'posts_per_page' => $products_per_page,
859
+			'paged' => $page_number,
860
+			'post_status' => 'publish',
861
+		);
862
+
863
+		// If the limit is greater than zero, hide pagination and change posts_per_page var
864
+		if ($nb_of_product_limit > 0) {
865
+			$query['posts_per_page'] = $nb_of_product_limit;
866
+			unset($query['paged']);
867
+		}
868
+		if (!empty($pid)) {
869
+			if (!is_array($pid)) {
870
+				$pid = explode(',', $pid);
871
+			}
1011 872
 
1012
-        }
1013
-        wp_reset_query(); // important
873
+			$query['post__in'] = $pid;
874
+		}
875
+		if (!empty($cid)) {
876
+			$cid = explode(',', $cid);
877
+			$query['tax_query'] = array(array(
878
+				'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
879
+				'field' => 'id',
880
+				'terms' => $cid,
881
+				'operator' => 'IN',
882
+			));
883
+		}
884
+		if ($criteria != null) {
885
+			switch ($criteria) {
886
+				case 'creator':
887
+				case 'author':
888
+					$query['author'] = get_current_user_id();
889
+					break;
890
+				case 'none':
891
+				case 'ID':
892
+				case 'title':
893
+				case 'date':
894
+				case 'modified':
895
+				case 'relevance':
896
+				case 'post__in':
897
+				case 'rand':
898
+					$query['orderby'] = $criteria;
899
+					break;
900
+				default:
901
+					if (!empty($pid)) {
902
+						$post_meta = get_post_meta($pid, '_' . $criteria, true);
903
+					} else {
904
+						$check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
905
+						$post_meta = $wpdb->get_var($check_meta);
906
+					}
907
+					if (!empty($post_meta)) {
908
+						if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
909
+							$query['orderby'] = 'meta_value_num';
910
+						} else {
911
+							$query['orderby'] = 'meta_value';
912
+						}
913
+						$query['meta_key'] = '_' . $criteria;
914
+					}
915
+					break;
916
+			}
917
+		} else {
918
+			$query['orderby'] = 'menu_order ID';
919
+		}
920
+		$post_per_page = $query['posts_per_page'];
921
+		$total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
922
+		if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
923
+			$tmp_array = array();
924
+
925
+			if (empty($page_number) || $page_number == 1) {
926
+				for ($i = 0; $i < $query['posts_per_page']; $i++) {
927
+					$tmp_array[] = $query['post__in'][$i];
928
+				}
929
+			} else {
930
+				$begin_number = (($page_number - 1) * $query['posts_per_page']);
931
+				for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
932
+					if (!empty($query['post__in'][$i])) {
933
+						$tmp_array[] = $query['post__in'][$i];
934
+					}
935
+				}
936
+			}
937
+			unset($query['post__in']);
938
+			$query['post__in'] = $tmp_array;
939
+			$query['posts_per_page'] = -1;
940
+		}
1014 941
 
1015
-        return array($have_results, $string);
1016
-    }
942
+		$query['post_status'] = 'publish';
943
+
944
+		$custom_query = new WP_Query($query);
945
+
946
+		if ($custom_query->have_posts()) {
947
+			$have_results = true;
948
+
949
+			// ---------------- //
950
+			// Products listing //
951
+			// ---------------- //
952
+			$current_position = 1;
953
+			$product_list = '';
954
+			while ($custom_query->have_posts()): $custom_query->the_post();
955
+				$cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
956
+				$cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
957
+				$cat_id = empty($cats) ? 0 : $cats[0]->term_id;
958
+				$product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
959
+				$current_position++;
960
+			endwhile;
961
+			$tpl_component = array();
962
+			$tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
963
+			$tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
964
+			$tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
965
+			$tpl_component['PRODUCT_LIST'] = $product_list;
966
+			$tpl_component['CROSSED_OUT_PRICE'] = '';
967
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
968
+			$string = wpshop_display::display_template_element('product_list_container', $tpl_component);
969
+
970
+			// --------------------- //
971
+			// Pagination management //
972
+			// --------------------- //
973
+			if ( $display_pagination ) {
974
+				if ($nb_of_product_limit == 0) {
975
+
976
+					$paginate = paginate_links(array(
977
+						'base' => '%_%',
978
+						'format' => '/?page_product=%#%',
979
+						'current' => $page_number,
980
+						'total' => $custom_query->max_num_pages,
981
+						'type' => 'array',
982
+						'prev_next' => false,
983
+					));
984
+					if (!empty($paginate)) {
985
+						$string .= '<ul class="pagination wps-pagination">';
986
+						foreach ($paginate as $p) {
987
+							$string .= '<li>' . $p . '</li>';
988
+						}
989
+						$string .= '</ul>';
990
+					}
991
+				}
1017 992
 
1018
-    /**
1019
-     * Update quantity for a product
1020
-     * @param integer $product_id The product we want to update quantity for
1021
-     * @param decimal $qty The new quantity
1022
-     */
1023
-    public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1024
-    {
1025
-        global $wpdb;
1026
-
1027
-        $product = self::get_product_data($product_id);
1028
-        /** Check if there is variation ***/
1029
-        if (!empty($variation_id) && $variation_id != $product_id) {
1030
-            $variation_post_type = get_post_type($variation_id);
1031
-            if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1032
-                /** Check if variation def is combined **/
1033
-                $variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1034
-                if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1035
-                    /** Get post meta of variation */
1036
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1037
-                    if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1038
-                        $product = self::get_product_data($variation_id);
1039
-                        $product_id = $variation_id;
1040
-                    }
1041
-                }
1042
-            }
1043
-        }
993
+				if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
994
+					$paginate = paginate_links(array(
995
+						'base' => '%_%',
996
+						'format' => '/?page_product=%#%',
997
+						'current' => $page_number,
998
+						'total' => ceil(count($total_products) / $post_per_page),
999
+						'type' => 'array',
1000
+						'prev_next' => false,
1001
+					));
1002
+					if (!empty($paginate)) {
1003
+						$string .= '<ul class="pagination wps-pagination">';
1004
+						foreach ($paginate as $p) {
1005
+							$string .= '<li>' . $p . '</li>';
1006
+						}
1007
+						$string .= '</ul>';
1008
+					}
1009
+				}
1010
+			}
1011
+
1012
+		}
1013
+		wp_reset_query(); // important
1014
+
1015
+		return array($have_results, $string);
1016
+	}
1017
+
1018
+	/**
1019
+	 * Update quantity for a product
1020
+	 * @param integer $product_id The product we want to update quantity for
1021
+	 * @param decimal $qty The new quantity
1022
+	 */
1023
+	public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1024
+	{
1025
+		global $wpdb;
1026
+
1027
+		$product = self::get_product_data($product_id);
1028
+		/** Check if there is variation ***/
1029
+		if (!empty($variation_id) && $variation_id != $product_id) {
1030
+			$variation_post_type = get_post_type($variation_id);
1031
+			if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1032
+				/** Check if variation def is combined **/
1033
+				$variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1034
+				if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1035
+					/** Get post meta of variation */
1036
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1037
+					if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1038
+						$product = self::get_product_data($variation_id);
1039
+						$product_id = $variation_id;
1040
+					}
1041
+				}
1042
+			}
1043
+		}
1044 1044
 
1045
-        if (!empty($product)) {
1046
-            $newQty = $product['product_stock'] - $qty;
1047
-            $value_id = 0;
1048
-            if ($newQty >= 0) {
1049
-                $query = '
1045
+		if (!empty($product)) {
1046
+			$newQty = $product['product_stock'] - $qty;
1047
+			$value_id = 0;
1048
+			if ($newQty >= 0) {
1049
+				$query = '
1050 1050
 					SELECT wp_wpshop__attribute_value_decimal.value_id
1051 1051
 					FROM wp_wpshop__attribute_value_decimal
1052 1052
 					LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
1053 1053
 					WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
1054 1054
 					LIMIT 1
1055 1055
 				';
1056
-                $value_id = $wpdb->get_var($query);
1057
-                $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1058
-            }
1059
-            // Historic
1060
-            $attribute_histo_content = array();
1061
-            $attribute_histo_content['status'] = 'valid';
1062
-            $attribute_histo_content['creation_date'] = current_time('mysql', 0);
1063
-            $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1064
-            $attribute_histo_content['original_value_id'] = $value_id;
1065
-            $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1066
-            $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1067
-            $attribute_histo_content['attribute_id'] = $stock_atribute->id;
1068
-            $attribute_histo_content['entity_id'] = $product_id;
1069
-            $attribute_histo_content['value'] = $product['product_stock'];
1070
-            $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1071
-            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1072
-
1073
-            $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1074
-            $product_meta['product_stock'] = $newQty;
1075
-            update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1076
-        }
1077
-    }
1056
+				$value_id = $wpdb->get_var($query);
1057
+				$update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1058
+			}
1059
+			// Historic
1060
+			$attribute_histo_content = array();
1061
+			$attribute_histo_content['status'] = 'valid';
1062
+			$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1063
+			$attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1064
+			$attribute_histo_content['original_value_id'] = $value_id;
1065
+			$attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1066
+			$stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1067
+			$attribute_histo_content['attribute_id'] = $stock_atribute->id;
1068
+			$attribute_histo_content['entity_id'] = $product_id;
1069
+			$attribute_histo_content['value'] = $product['product_stock'];
1070
+			$attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1071
+			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1072
+
1073
+			$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1074
+			$product_meta['product_stock'] = $newQty;
1075
+			update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1076
+		}
1077
+	}
1078 1078
 
1079
-    /**
1080
-     * Retrieve an array with complete information about a given product
1081
-     * @param integer $product_id
1082
-     * @param boolean $for_cart_storage
1083
-     * @return array Information about the product defined by first parameter
1084
-     */
1085
-    public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1086
-    {
1087
-        global $wpdb;
1088
-        $query = $wpdb->prepare('
1079
+	/**
1080
+	 * Retrieve an array with complete information about a given product
1081
+	 * @param integer $product_id
1082
+	 * @param boolean $for_cart_storage
1083
+	 * @return array Information about the product defined by first parameter
1084
+	 */
1085
+	public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1086
+	{
1087
+		global $wpdb;
1088
+		$query = $wpdb->prepare('
1089 1089
 			SELECT P.*, PM.meta_value AS attribute_set_id
1090 1090
 			FROM ' . $wpdb->posts . ' AS P
1091 1091
 				INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID)
@@ -1097,398 +1097,398 @@  discard block
 block discarded – undo
1097 1097
 			LIMIT 1
1098 1098
 		', $product_id);
1099 1099
 
1100
-        $product = $wpdb->get_row($query);
1101
-
1102
-        $product_data = array();
1103
-        $product_meta = array();
1104
-
1105
-        if (!empty($product)) {
1106
-            $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1107
-            $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1108
-            $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1109
-            $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1110
-
1111
-            $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1112
-            $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1113
-            $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1114
-            $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1115
-
1116
-            $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1117
-
1118
-            $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);
1119
-            if (!empty($data)) {
1120
-                foreach ($data as $attribute) {
1121
-                    $data_type = 'attribute_value_' . $attribute->data_type;
1122
-                    $value = $attribute->$data_type;
1123
-                    if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1124
-                        $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1125
-                    }
1126
-
1127
-                    /** Special traitment regarding attribute_code    */
1128
-                    switch ($attribute->attribute_code) {
1129
-                        case 'product_weight':
1130
-                            $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1131
-                            if (!empty($default_weight_unity)) {
1132
-                                $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1133
-                                $unity = $wpdb->get_var($query);
1134
-                                if ($unity == 'kg') {
1135
-                                    $value *= 1000;
1136
-                                }
1137
-
1138
-                            }
1139
-                            break;
1140
-                        default:
1141
-                            $value = !empty($value) ? $value : 0;
1142
-                            break;
1143
-                    }
1144
-                    $product_data[$attribute->attribute_code] = $value;
1145
-
1146
-                    if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1147
-                        $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1148
-                        if (!empty($meta)) {
1149
-                            $product_meta[$attribute->attribute_code] = $meta;
1150
-                        }
1151
-                    }
1152
-
1153
-                    if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1154
-                        $product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1155
-                    }
1156
-                    if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1157
-                        $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1158
-                    }
1159
-                }
1160
-            } else {
1161
-
1162
-            }
1163
-
1164
-            /**    Get datas about product options    */
1165
-            if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1166
-                $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1167
-
1168
-                foreach ($variation_details as $attribute_code => $attribute_value) {
1169
-                    $variation_id = $attribute_value;
1170
-                    $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1171
-
1172
-                    $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));
1173
-                    $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1174
-                    switch ($attribute_definition->backend_input) {
1175
-                        case 'select':
1176
-                        case 'multiple-select':
1177
-                        case 'radio':
1178
-                        case 'checkbox':
1179
-                            $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1180
-                            break;
1181
-                    }
1182
-                    $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1183
-                    $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1184
-                }
1185
-            }
1186
-
1187
-            $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1188
-
1189
-            /** Get the display definition for the current product for checking custom display    */
1190
-            $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1191
-        }
1100
+		$product = $wpdb->get_row($query);
1101
+
1102
+		$product_data = array();
1103
+		$product_meta = array();
1104
+
1105
+		if (!empty($product)) {
1106
+			$product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1107
+			$product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1108
+			$product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1109
+			$product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1110
+
1111
+			$product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1112
+			$product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1113
+			$product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1114
+			$product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1115
+
1116
+			$product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1117
+
1118
+			$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);
1119
+			if (!empty($data)) {
1120
+				foreach ($data as $attribute) {
1121
+					$data_type = 'attribute_value_' . $attribute->data_type;
1122
+					$value = $attribute->$data_type;
1123
+					if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1124
+						$value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1125
+					}
1126
+
1127
+					/** Special traitment regarding attribute_code    */
1128
+					switch ($attribute->attribute_code) {
1129
+						case 'product_weight':
1130
+							$default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1131
+							if (!empty($default_weight_unity)) {
1132
+								$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1133
+								$unity = $wpdb->get_var($query);
1134
+								if ($unity == 'kg') {
1135
+									$value *= 1000;
1136
+								}
1137
+
1138
+							}
1139
+							break;
1140
+						default:
1141
+							$value = !empty($value) ? $value : 0;
1142
+							break;
1143
+					}
1144
+					$product_data[$attribute->attribute_code] = $value;
1145
+
1146
+					if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1147
+						$meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1148
+						if (!empty($meta)) {
1149
+							$product_meta[$attribute->attribute_code] = $meta;
1150
+						}
1151
+					}
1152
+
1153
+					if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1154
+						$product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1155
+					}
1156
+					if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1157
+						$product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1158
+					}
1159
+				}
1160
+			} else {
1192 1161
 
1193
-        return $product_data;
1194
-    }
1162
+			}
1195 1163
 
1196
-    /**
1197
-     * Add a product into the db. This function is used for the EDI
1198
-     * @param $name Name of the product
1199
-     * @param $description Description of the product
1200
-     * @param $attrs List of the attributes and values of the product
1201
-     * @return boolean
1202
-     */
1203
-    public function addProduct($name, $description, $attrs = array())
1204
-    {
1205
-        $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1206
-        return $new_product[0];
1207
-    }
1164
+			/**    Get datas about product options    */
1165
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1166
+				$variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1167
+
1168
+				foreach ($variation_details as $attribute_code => $attribute_value) {
1169
+					$variation_id = $attribute_value;
1170
+					$attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1171
+
1172
+					$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));
1173
+					$product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1174
+					switch ($attribute_definition->backend_input) {
1175
+						case 'select':
1176
+						case 'multiple-select':
1177
+						case 'radio':
1178
+						case 'checkbox':
1179
+							$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1180
+							break;
1181
+					}
1182
+					$product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1183
+					$product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1184
+				}
1185
+			}
1208 1186
 
1209
-    /**
1210
-     * Retrieve a product listing
1211
-     * @param boolean $formated If the output have to be formated or not
1212
-     * @param string $product_search Optionnal Define a search term for request
1213
-     * @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
1214
-     */
1215
-    public static function product_list($formated = false, $product_search = null)
1216
-    {
1217
-        global $wpdb;
1218
-
1219
-        $query_extra_params = $query_extra_params_value = '';
1220
-        if (!empty($product_search)) {
1221
-            $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1222
-            if (is_array($product_search)) {
1223
-                $query_extra_params = " AND ID IN (%s)";
1224
-                $query_extra_params_value = implode(",", $product_search);
1225
-            }
1226
-        }
1187
+			$product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1188
+
1189
+			/** Get the display definition for the current product for checking custom display    */
1190
+			$product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1191
+		}
1192
+
1193
+		return $product_data;
1194
+	}
1195
+
1196
+	/**
1197
+	 * Add a product into the db. This function is used for the EDI
1198
+	 * @param $name Name of the product
1199
+	 * @param $description Description of the product
1200
+	 * @param $attrs List of the attributes and values of the product
1201
+	 * @return boolean
1202
+	 */
1203
+	public function addProduct($name, $description, $attrs = array())
1204
+	{
1205
+		$new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1206
+		return $new_product[0];
1207
+	}
1208
+
1209
+	/**
1210
+	 * Retrieve a product listing
1211
+	 * @param boolean $formated If the output have to be formated or not
1212
+	 * @param string $product_search Optionnal Define a search term for request
1213
+	 * @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
1214
+	 */
1215
+	public static function product_list($formated = false, $product_search = null)
1216
+	{
1217
+		global $wpdb;
1218
+
1219
+		$query_extra_params = $query_extra_params_value = '';
1220
+		if (!empty($product_search)) {
1221
+			$query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1222
+			if (is_array($product_search)) {
1223
+				$query_extra_params = " AND ID IN (%s)";
1224
+				$query_extra_params_value = implode(",", $product_search);
1225
+			}
1226
+		}
1227 1227
 
1228
-        $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);
1229
-        $data = $wpdb->get_results($query);
1228
+		$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);
1229
+		$data = $wpdb->get_results($query);
1230 1230
 
1231
-        /*
1231
+		/*
1232 1232
          * Make some arangement on output if parameter is given
1233 1233
          */
1234
-        if ($formated) {
1235
-            $product_string = '';
1236
-            foreach ($data as $d) {
1237
-                $product_string .= '
1234
+		if ($formated) {
1235
+			$product_string = '';
1236
+			foreach ($data as $d) {
1237
+				$product_string .= '
1238 1238
 					<li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" >
1239 1239
 						<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>
1240 1240
 					</li>';
1241
-            }
1242
-        }
1241
+			}
1242
+		}
1243 1243
 
1244
-        return $formated ? $product_string : $data;
1245
-    }
1244
+		return $formated ? $product_string : $data;
1245
+	}
1246 1246
 
1247
-    /**
1248
-     * Enregistrement des données pour le produit
1249
-     */
1250
-    public function save_product_custom_informations($post_id, $data_to_save = array())
1251
-    {
1252
-        global $wpdb;
1253
-
1254
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1255
-        // Apply a filter to extra actions
1256
-        $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1257
-
1258
-        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"))) {
1259
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1260
-                /*    Fill the product reference automatically if nothing is sent    */
1261
-                if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1262
-                    $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1263
-                    $last_ref = $wpdb->get_var($query);
1264
-                    $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;
1265
-                } else {
1266
-                    /* Check if the product reference existing in the database */
1267
-                    $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1268
-                    $query = $wpdb->prepare(
1269
-                        "SELECT value_id
1247
+	/**
1248
+	 * Enregistrement des données pour le produit
1249
+	 */
1250
+	public function save_product_custom_informations($post_id, $data_to_save = array())
1251
+	{
1252
+		global $wpdb;
1253
+
1254
+		$data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1255
+		// Apply a filter to extra actions
1256
+		$data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1257
+
1258
+		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"))) {
1259
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1260
+				/*    Fill the product reference automatically if nothing is sent    */
1261
+				if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1262
+					$query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1263
+					$last_ref = $wpdb->get_var($query);
1264
+					$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;
1265
+				} else {
1266
+					/* Check if the product reference existing in the database */
1267
+					$ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1268
+					$query = $wpdb->prepare(
1269
+						"SELECT value_id
1270 1270
 						FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
1271 1271
 							INNER JOIN {$wpdb->posts} ON ( ID = entity_id )
1272 1272
 						WHERE value = %s
1273 1273
 							AND entity_id != %d
1274 1274
 							AND entity_type_id = %d"
1275
-                        , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1276
-                    $existing_reference = $wpdb->get_var($query);
1277
-
1278
-                    /* If this product reference exist -> Create a new product reference */
1279
-                    if ($wpdb->num_rows > 0) {
1280
-                        $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1281
-                        $last_ref = $wpdb->get_var($query);
1282
-                        $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;
1283
-                    }
1284
-                }
1285
-
1286
-                /*    Save the attributes values into wpshop eav database    */
1287
-                $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1288
-                $lang = WPSHOP_CURRENT_LOCALE;
1289
-                if (!empty($data_to_save['icl_post_language'])) {
1290
-                    $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1291
-                    $lang = $wpdb->get_var($query);
1292
-                }
1293
-                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);
1294
-
1295
-                /*    Update product price looking for shop parameters    */
1296
-                wpshop_products::calculate_price($data_to_save['post_ID']);
1297
-
1298
-                /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1299
-                $productMetaDatas = array();
1300
-                foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1301
-                    foreach ($attributeValues as $attributeCode => $attributeValue) {
1302
-                        if ($attributeCode == 'product_attribute_set_id') {
1303
-                            /*    Update the attribute set id for the current product    */
1304
-                            update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1305
-                        }
1306
-                        if ($attributeType == 'decimal') {
1307
-                            $attributeValue = str_replace(',', '.', $attributeValue);
1308
-                        }
1309
-                        if (($attributeType == 'integer') && !is_array($attributeValue)) {
1310
-                            $attributeValue = (int) $attributeValue;
1311
-                        }
1312
-                        $productMetaDatas[$attributeCode] = $attributeValue;
1313
-                    }
1314
-                }
1315
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1316
-            }
1317
-
1318
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1319
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1320
-            } else if ($data_to_save['action'] != 'autosave') {
1321
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1322
-            }
1323
-
1324
-            $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1325
-            if (empty($product['product_id'])) {
1326
-                $product['product_id'] = $data_to_save['post_ID'];
1327
-            }
1328
-            $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1329
-            update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1330
-
1331
-            /**    Save product variation    */
1332
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1333
-                foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1334
-
1335
-                    foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1336
-                        $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1337
-                        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])) {
1338
-                            $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;
1339
-                        }
1340
-                    }
1341
-                    $lang = WPSHOP_CURRENT_LOCALE;
1342
-                    if (!empty($data_to_save['icl_post_language'])) {
1343
-                        $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1344
-                        $lang = $wpdb->get_var($query);
1345
-                    }
1346
-                    wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1347
-
1348
-                    /**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1349
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1350
-                    if (!empty($variation_metadata)) {
1351
-                        $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1352
-                        if (!empty($attributes_list)) {
1353
-                            foreach ($attributes_list as $attribute) {
1354
-                                $value_key = 'attribute_value_' . $attribute->data_type;
1355
-                                $attributeValue = $attribute->$value_key;
1356
-                                if ($attribute->data_type == 'decimal') {
1357
-                                    $attributeValue = str_replace(',', '.', $attribute->$value_key);
1358
-                                }
1359
-                                if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1360
-                                    $attributeValue = (int) $attribute->$value_key;
1361
-                                }
1362
-                                $variation_metadata[$attribute->code] = $attribute->$value_key;
1363
-                            }
1364
-                        }
1365
-                    }
1366
-
1367
-                    foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1368
-                        foreach ($attributeValues as $attributeCode => $attributeValue) {
1369
-                            if ($attributeType == 'decimal') {
1370
-                                $attributeValue = str_replace(',', '.', $attributeValue);
1371
-                            }
1372
-                            if (($attributeType == 'integer') && !is_array($attributeValue)) {
1373
-                                $attributeValue = (int) $attributeValue;
1374
-                            }
1375
-                            $variation_metadata[$attributeCode] = $attributeValue;
1376
-                        }
1377
-                    }
1378
-                    update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1379
-
1380
-                    /** Save attached picture id **/
1381
-                    $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']) : '';
1382
-                    $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1383
-
1384
-                    /*    Update product price looking for shop parameters    */
1385
-                    wpshop_products::calculate_price($variation_id);
1386
-                }
1387
-            }
1388
-
1389
-            /*    Update the related products list*/
1390
-            if (!empty($data_to_save['related_products_list'])) {
1391
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1392
-            } else if ($data_to_save['action'] != 'autosave') {
1393
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1394
-            }
1395
-            /*    Update the provider list*/
1396
-            if (!empty($data_to_save['provider_list'])) {
1397
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1398
-            } else if ($data_to_save['action'] != 'autosave') {
1399
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1400
-            }
1401
-
1402
-            /*    Update product options    */
1403
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1404
-                update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1405
-            } else if ($data_to_save['action'] != 'autosave') {
1406
-                delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1407
-            }
1408
-
1409
-            /** Add flag on variations to check which type of variation **/
1410
-            $check_product_have_variations = self::get_variation($post_id);
1411
-            if (!empty($check_product_have_variations)) {
1412
-                $variation_flag = self::check_variation_type($post_id);
1413
-                $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1414
-                $variation_defining['variation_type'] = $variation_flag;
1415
-                update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1416
-            }
1417
-            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);
1418
-        }
1275
+						, $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1276
+					$existing_reference = $wpdb->get_var($query);
1277
+
1278
+					/* If this product reference exist -> Create a new product reference */
1279
+					if ($wpdb->num_rows > 0) {
1280
+						$query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1281
+						$last_ref = $wpdb->get_var($query);
1282
+						$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;
1283
+					}
1284
+				}
1419 1285
 
1420
-        flush_rewrite_rules();
1421
-    }
1286
+				/*    Save the attributes values into wpshop eav database    */
1287
+				$update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1288
+				$lang = WPSHOP_CURRENT_LOCALE;
1289
+				if (!empty($data_to_save['icl_post_language'])) {
1290
+					$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1291
+					$lang = $wpdb->get_var($query);
1292
+				}
1293
+				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);
1294
+
1295
+				/*    Update product price looking for shop parameters    */
1296
+				wpshop_products::calculate_price($data_to_save['post_ID']);
1297
+
1298
+				/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1299
+				$productMetaDatas = array();
1300
+				foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1301
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
1302
+						if ($attributeCode == 'product_attribute_set_id') {
1303
+							/*    Update the attribute set id for the current product    */
1304
+							update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1305
+						}
1306
+						if ($attributeType == 'decimal') {
1307
+							$attributeValue = str_replace(',', '.', $attributeValue);
1308
+						}
1309
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1310
+							$attributeValue = (int) $attributeValue;
1311
+						}
1312
+						$productMetaDatas[$attributeCode] = $attributeValue;
1313
+					}
1314
+				}
1315
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1316
+			}
1422 1317
 
1423
-    /**
1424
-     * Return the variation type
1425
-     * @param integer $post_id
1426
-     * @return string
1427
-     */
1428
-    public function check_variation_type($post_id)
1429
-    {
1430
-        $variation_type = 'single';
1431
-        if (!empty($variation_type)) {
1432
-            $variations = self::get_variation($post_id);
1433
-            if (!empty($variations)) {
1434
-                foreach ($variations as $variation_id => $variation_data) {
1435
-                    if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1436
-                        return 'single';
1437
-                    } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1438
-                        $variation_type = 'combined';
1439
-                    }
1440
-                }
1441
-            }
1442
-        }
1443
-        return $variation_type;
1444
-    }
1318
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1319
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1320
+			} else if ($data_to_save['action'] != 'autosave') {
1321
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1322
+			}
1445 1323
 
1446
-    /**
1447
-     * Allows to define a specific permalink for each product by checking the parent categories
1448
-     *
1449
-     * @param mixed $permalink The actual permalink of the element
1450
-     * @param object $post The post we want to set the permalink for
1451
-     * @param void
1452
-     *
1453
-     * @return mixed The new permalink for the current element
1454
-     */
1455
-    public static function set_product_permalink($permalink, $post, $unknown)
1456
-    {
1457
-        $options = get_option('wpshop_catalog_product_option', array());
1458
-
1459
-        if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1460
-            if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1461
-                return $permalink;
1462
-            } else {
1463
-                $options_cats = get_option('wpshop_catalog_categories_option', array());
1464
-                $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1465
-                if (empty($product_categories)) {
1466
-                    $product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1467
-                } else {
1468
-                    $product_category_slug = $product_categories[0]->slug;
1469
-                }
1470
-                $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1471
-            }
1472
-        }
1324
+			$product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1325
+			if (empty($product['product_id'])) {
1326
+				$product['product_id'] = $data_to_save['post_ID'];
1327
+			}
1328
+			$price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1329
+			update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1330
+
1331
+			/**    Save product variation    */
1332
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1333
+				foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1334
+
1335
+					foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1336
+						$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1337
+						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])) {
1338
+							$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;
1339
+						}
1340
+					}
1341
+					$lang = WPSHOP_CURRENT_LOCALE;
1342
+					if (!empty($data_to_save['icl_post_language'])) {
1343
+						$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1344
+						$lang = $wpdb->get_var($query);
1345
+					}
1346
+					wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1347
+
1348
+					/**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1349
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1350
+					if (!empty($variation_metadata)) {
1351
+						$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1352
+						if (!empty($attributes_list)) {
1353
+							foreach ($attributes_list as $attribute) {
1354
+								$value_key = 'attribute_value_' . $attribute->data_type;
1355
+								$attributeValue = $attribute->$value_key;
1356
+								if ($attribute->data_type == 'decimal') {
1357
+									$attributeValue = str_replace(',', '.', $attribute->$value_key);
1358
+								}
1359
+								if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1360
+									$attributeValue = (int) $attribute->$value_key;
1361
+								}
1362
+								$variation_metadata[$attribute->code] = $attribute->$value_key;
1363
+							}
1364
+						}
1365
+					}
1366
+
1367
+					foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1368
+						foreach ($attributeValues as $attributeCode => $attributeValue) {
1369
+							if ($attributeType == 'decimal') {
1370
+								$attributeValue = str_replace(',', '.', $attributeValue);
1371
+							}
1372
+							if (($attributeType == 'integer') && !is_array($attributeValue)) {
1373
+								$attributeValue = (int) $attributeValue;
1374
+							}
1375
+							$variation_metadata[$attributeCode] = $attributeValue;
1376
+						}
1377
+					}
1378
+					update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1379
+
1380
+					/** Save attached picture id **/
1381
+					$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']) : '';
1382
+					$selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1383
+
1384
+					/*    Update product price looking for shop parameters    */
1385
+					wpshop_products::calculate_price($variation_id);
1386
+				}
1387
+			}
1388
+
1389
+			/*    Update the related products list*/
1390
+			if (!empty($data_to_save['related_products_list'])) {
1391
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1392
+			} else if ($data_to_save['action'] != 'autosave') {
1393
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1394
+			}
1395
+			/*    Update the provider list*/
1396
+			if (!empty($data_to_save['provider_list'])) {
1397
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1398
+			} else if ($data_to_save['action'] != 'autosave') {
1399
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1400
+			}
1401
+
1402
+			/*    Update product options    */
1403
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1404
+				update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1405
+			} else if ($data_to_save['action'] != 'autosave') {
1406
+				delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1407
+			}
1408
+
1409
+			/** Add flag on variations to check which type of variation **/
1410
+			$check_product_have_variations = self::get_variation($post_id);
1411
+			if (!empty($check_product_have_variations)) {
1412
+				$variation_flag = self::check_variation_type($post_id);
1413
+				$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1414
+				$variation_defining['variation_type'] = $variation_flag;
1415
+				update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1416
+			}
1417
+			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);
1418
+		}
1419
+
1420
+		flush_rewrite_rules();
1421
+	}
1422
+
1423
+	/**
1424
+	 * Return the variation type
1425
+	 * @param integer $post_id
1426
+	 * @return string
1427
+	 */
1428
+	public function check_variation_type($post_id)
1429
+	{
1430
+		$variation_type = 'single';
1431
+		if (!empty($variation_type)) {
1432
+			$variations = self::get_variation($post_id);
1433
+			if (!empty($variations)) {
1434
+				foreach ($variations as $variation_id => $variation_data) {
1435
+					if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1436
+						return 'single';
1437
+					} elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1438
+						$variation_type = 'combined';
1439
+					}
1440
+				}
1441
+			}
1442
+		}
1443
+		return $variation_type;
1444
+	}
1445
+
1446
+	/**
1447
+	 * Allows to define a specific permalink for each product by checking the parent categories
1448
+	 *
1449
+	 * @param mixed $permalink The actual permalink of the element
1450
+	 * @param object $post The post we want to set the permalink for
1451
+	 * @param void
1452
+	 *
1453
+	 * @return mixed The new permalink for the current element
1454
+	 */
1455
+	public static function set_product_permalink($permalink, $post, $unknown)
1456
+	{
1457
+		$options = get_option('wpshop_catalog_product_option', array());
1458
+
1459
+		if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1460
+			if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1461
+				return $permalink;
1462
+			} else {
1463
+				$options_cats = get_option('wpshop_catalog_categories_option', array());
1464
+				$product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1465
+				if (empty($product_categories)) {
1466
+					$product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1467
+				} else {
1468
+					$product_category_slug = $product_categories[0]->slug;
1469
+				}
1470
+				$permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1471
+			}
1472
+		}
1473 1473
 
1474
-        return $permalink;
1474
+		return $permalink;
1475 1475
 
1476
-        //echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1476
+		//echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1477 1477
 
1478
-        //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1478
+		//wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1479 1479
 
1480
-        /*if(false) {
1480
+		/*if(false) {
1481 1481
         global $wp_query;
1482 1482
         $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1483 1483
 
1484 1484
         if(count($product_categories) == 0){            /*    Product has only one category we get the only available slug    */
1485
-        /*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1485
+		/*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1486 1486
         }
1487 1487
         elseif(count($product_categories) == 1){    /*    Product has only one category we get the only available slug    */
1488
-        /*        $product_category_slug = $product_categories[0]->slug;
1488
+		/*        $product_category_slug = $product_categories[0]->slug;
1489 1489
         }
1490 1490
         else{                                                                            /*    Product has several categories choose the slug of the we want    */
1491
-        /*        $product_category_slugs = array();
1491
+		/*        $product_category_slugs = array();
1492 1492
     foreach($product_categories as $product_category){
1493 1493
     $product_category_slugs[] = $product_category->slug;
1494 1494
     }
@@ -1498,457 +1498,457 @@  discard block
 block discarded – undo
1498 1498
     $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1499 1499
     return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID );
1500 1500
     }*/
1501
-    }
1501
+	}
1502 1502
 
1503
-    public static function set_product_request_by_name($query)
1504
-    {
1505
-        $options = get_option('wpshop_catalog_product_option', array());
1503
+	public static function set_product_request_by_name($query)
1504
+	{
1505
+		$options = get_option('wpshop_catalog_product_option', array());
1506 1506
 
1507
-        if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1508
-        //    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1509
-    }
1507
+		if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1508
+		//    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1509
+	}
1510 1510
 
1511
-    /**
1512
-     *    Define output for product
1513
-     *
1514
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1515
-     *    @param integer $product_id The product identifier we want to get and output attribute for
1516
-     *
1517
-     *    @return mixed $content The content to add or to modify the product output in frontend
1518
-     */
1519
-    public static function product_complete_sheet_output($initialContent, $product_id)
1520
-    {
1521
-        $content = $attributeContentOutput = '';
1522
-        $wps_product_ctr = new wps_product_ctr();
1523
-        /** Log number of view for the current product    */
1524
-        $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1525
-        $product_view_number++;
1526
-        update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1527
-
1528
-        /** Get product definition    */
1529
-
1530
-        $product = self::get_product_data($product_id);
1531
-        wp_cache_set('wpshop_product_data_' . $product_id, $product);
1532
-
1533
-        /** Get the product thumbnail    */
1534
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1535
-        if (has_post_thumbnail($product_id)) {
1536
-            $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1537
-            $tpl_component = array();
1538
-            $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1539
-            $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1540
-            $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1541
-            $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1542
-            if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1543
-                foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1544
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1545
-                    $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;
1546
-                }
1547
-            }
1548
-            $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;
1549
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1550
-            unset($tpl_component);
1551
-        }
1511
+	/**
1512
+	 *    Define output for product
1513
+	 *
1514
+	 *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1515
+	 *    @param integer $product_id The product identifier we want to get and output attribute for
1516
+	 *
1517
+	 *    @return mixed $content The content to add or to modify the product output in frontend
1518
+	 */
1519
+	public static function product_complete_sheet_output($initialContent, $product_id)
1520
+	{
1521
+		$content = $attributeContentOutput = '';
1522
+		$wps_product_ctr = new wps_product_ctr();
1523
+		/** Log number of view for the current product    */
1524
+		$product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1525
+		$product_view_number++;
1526
+		update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1527
+
1528
+		/** Get product definition    */
1529
+
1530
+		$product = self::get_product_data($product_id);
1531
+		wp_cache_set('wpshop_product_data_' . $product_id, $product);
1532
+
1533
+		/** Get the product thumbnail    */
1534
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1535
+		if (has_post_thumbnail($product_id)) {
1536
+			$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1537
+			$tpl_component = array();
1538
+			$tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1539
+			$tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1540
+			$tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1541
+			$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1542
+			if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1543
+				foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1544
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1545
+					$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;
1546
+				}
1547
+			}
1548
+			$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;
1549
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1550
+			unset($tpl_component);
1551
+		}
1552 1552
 
1553
-        $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1554
-
1555
-        /**    Retrieve product attributes for output    */
1556
-        $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1557
-
1558
-        /** Retrieve product price */
1559
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1560
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1561
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1562
-        $productPrice = '';
1563
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1564
-        $check_product_price = wpshop_prices::check_product_price($product);
1565
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1566
-        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)) {
1567
-            $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1568
-        }
1553
+		$product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1554
+
1555
+		/**    Retrieve product attributes for output    */
1556
+		$attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1557
+
1558
+		/** Retrieve product price */
1559
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1560
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1561
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1562
+		$productPrice = '';
1563
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1564
+		$check_product_price = wpshop_prices::check_product_price($product);
1565
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1566
+		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)) {
1567
+			$productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1568
+		}
1569 1569
 
1570
-        /** Check if there is at less 1 product in stock    */
1571
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1572
-        $productStock = ($productStock === true) ? 1 : null;
1570
+		/** Check if there is at less 1 product in stock    */
1571
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1572
+		$productStock = ($productStock === true) ? 1 : null;
1573 1573
 
1574
-        /** if !product stock check product have variation with stock **/
1574
+		/** if !product stock check product have variation with stock **/
1575 1575
 //         if ( empty($productStock) ) {
1576
-        $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1577
-        if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1578
-            $variations = wpshop_products::get_variation($product_id);
1579
-            if (!empty($variations)) {
1580
-                foreach ($variations as $variation) {
1581
-                    if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1582
-                        $productStock = 1;
1583
-                    }
1584
-                }
1585
-            }
1586
-        }
1576
+		$product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1577
+		if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1578
+			$variations = wpshop_products::get_variation($product_id);
1579
+			if (!empty($variations)) {
1580
+				foreach ($variations as $variation) {
1581
+					if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1582
+						$productStock = 1;
1583
+					}
1584
+				}
1585
+			}
1586
+		}
1587 1587
 //         }
1588 1588
 
1589
-        /** Define "Add to cart" button     */
1590
-        $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');
1591
-        $display_price_state_when_price_is_empty = true;
1592
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1593
-            $display_price_state_when_price_is_empty = false;
1594
-        } else if (!empty($productPrice)) {
1595
-            $display_price_state_when_price_is_empty = true;
1596
-        }
1597
-        $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') : '';
1598
-        $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)) : '';
1599
-
1600
-        /** Define "Ask a quotation" button    */
1601
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1602
-
1603
-        /** Template parameters    */
1604
-        $template_part = 'product_complete_tpl';
1605
-        $tpl_component = array();
1606
-
1607
-        $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1608
-        $tpl_component['PRODUCT_ID'] = $product_id;
1609
-        $tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1610
-        $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1611
-        $tpl_component['PRODUCT_GALERY_PICS'] = '';
1612
-        $tpl_component['PRODUCT_PRICE'] = $productPrice;
1613
-        $modules_option = get_option('wpshop_modules');
1614
-        $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1615
-        if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1616
-            $wps_marketing_tools = new wps_marketing_tools_ctr();
1617
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1618
-        }
1589
+		/** Define "Add to cart" button     */
1590
+		$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');
1591
+		$display_price_state_when_price_is_empty = true;
1592
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1593
+			$display_price_state_when_price_is_empty = false;
1594
+		} else if (!empty($productPrice)) {
1595
+			$display_price_state_when_price_is_empty = true;
1596
+		}
1597
+		$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') : '';
1598
+		$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)) : '';
1599
+
1600
+		/** Define "Ask a quotation" button    */
1601
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1602
+
1603
+		/** Template parameters    */
1604
+		$template_part = 'product_complete_tpl';
1605
+		$tpl_component = array();
1606
+
1607
+		$tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1608
+		$tpl_component['PRODUCT_ID'] = $product_id;
1609
+		$tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1610
+		$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1611
+		$tpl_component['PRODUCT_GALERY_PICS'] = '';
1612
+		$tpl_component['PRODUCT_PRICE'] = $productPrice;
1613
+		$modules_option = get_option('wpshop_modules');
1614
+		$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1615
+		if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1616
+			$wps_marketing_tools = new wps_marketing_tools_ctr();
1617
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1618
+		}
1619 1619
 
1620
-        /** Gallery **/
1621
-        $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1622
-
1623
-        $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'] : ''));
1624
-
1625
-        $product_new = $product_new_def['output'];
1626
-        $product_class = $product_new_def['class'];
1627
-
1628
-        $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'] : ''));
1629
-        $product_featured = $product_featured_def['output'];
1630
-        $product_class .= $product_featured_def['class'];
1631
-
1632
-        $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1633
-        $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1634
-        $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1635
-
1636
-        $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1637
-        $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1638
-        $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1639
-        $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1640
-        $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1641
-        $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1642
-        $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1643
-        $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1644
-
1645
-        /** Build template    */
1646
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1647
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1648
-            /*    Include the old way template part    */
1649
-            ob_start();
1650
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
1651
-            $content = ob_get_contents();
1652
-            ob_end_clean();
1653
-        } else {
1654
-            $content = wpshop_display::display_template_element($template_part, $tpl_component);
1655
-        }
1656
-        unset($tpl_component);
1657
-        return $content;
1658
-    }
1620
+		/** Gallery **/
1621
+		$tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1622
+
1623
+		$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'] : ''));
1624
+
1625
+		$product_new = $product_new_def['output'];
1626
+		$product_class = $product_new_def['class'];
1627
+
1628
+		$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'] : ''));
1629
+		$product_featured = $product_featured_def['output'];
1630
+		$product_class .= $product_featured_def['class'];
1631
+
1632
+		$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1633
+		$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1634
+		$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1635
+
1636
+		$tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1637
+		$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1638
+		$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1639
+		$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1640
+		$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1641
+		$tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1642
+		$tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1643
+		$tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1644
+
1645
+		/** Build template    */
1646
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1647
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1648
+			/*    Include the old way template part    */
1649
+			ob_start();
1650
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
1651
+			$content = ob_get_contents();
1652
+			ob_end_clean();
1653
+		} else {
1654
+			$content = wpshop_display::display_template_element($template_part, $tpl_component);
1655
+		}
1656
+		unset($tpl_component);
1657
+		return $content;
1658
+	}
1659 1659
 
1660
-    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)
1661
-    {
1662
-        $content = '';
1663
-        $product_information = $product_class = '';
1660
+	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)
1661
+	{
1662
+		$content = '';
1663
+		$product_information = $product_class = '';
1664 1664
 
1665
-        /** Get the product thumbnail    */
1666
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1667
-        if (has_post_thumbnail($product_id)) {
1668
-            $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1669
-        }
1665
+		/** Get the product thumbnail    */
1666
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1667
+		if (has_post_thumbnail($product_id)) {
1668
+			$productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1669
+		}
1670 1670
 
1671
-        $product = self::get_product_data($product_id);
1671
+		$product = self::get_product_data($product_id);
1672 1672
 
1673
-        /**    Get the product information for output    */
1674
-        if (!empty($product)) {
1673
+		/**    Get the product information for output    */
1674
+		if (!empty($product)) {
1675 1675
 
1676
-            $product_title = $product['post_title'];
1677
-            $product_name = $product['post_name'];
1678
-            $product_link = get_permalink($product_id);
1679
-            $product_more_informations = $product['product_content'];
1680
-            $product_excerpt = $product['product_excerpt'];
1676
+			$product_title = $product['post_title'];
1677
+			$product_name = $product['post_name'];
1678
+			$product_link = get_permalink($product_id);
1679
+			$product_more_informations = $product['product_content'];
1680
+			$product_excerpt = $product['product_excerpt'];
1681 1681
 
1682
-            if (strpos($product['product_content'], '<!--more-->')) {
1683
-                $post_content = explode('<!--more-->', $product['product_content']);
1684
-                $product_more_informations = $post_content[0];
1685
-            }
1682
+			if (strpos($product['product_content'], '<!--more-->')) {
1683
+				$post_content = explode('<!--more-->', $product['product_content']);
1684
+				$product_more_informations = $post_content[0];
1685
+			}
1686 1686
 
1687
-        } else {
1688
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1689
-            $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1690
-            $product_link = '';
1691
-            $product_more_informations = '';
1692
-            $product_excerpt = '';
1693
-        }
1687
+		} else {
1688
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1689
+			$product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1690
+			$product_link = '';
1691
+			$product_more_informations = '';
1692
+			$product_excerpt = '';
1693
+		}
1694 1694
 
1695
-        /** Retrieve product price    */
1696
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1697
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1698
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1699
-        $productPrice = '';
1700
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1701
-        $check_product_price = wpshop_prices::check_product_price($product);
1702
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1703
-        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)) {
1704
-            $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1705
-
1706
-            if (!empty($product_price_infos)) {
1707
-                $tpl_component_price = array();
1708
-                /** Price piloting **/
1695
+		/** Retrieve product price    */
1696
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1697
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1698
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1699
+		$productPrice = '';
1700
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1701
+		$check_product_price = wpshop_prices::check_product_price($product);
1702
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1703
+		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)) {
1704
+			$product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1705
+
1706
+			if (!empty($product_price_infos)) {
1707
+				$tpl_component_price = array();
1708
+				/** Price piloting **/
1709 1709
 				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1710 1710
 				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1711
-                $price_ploting = get_option('wpshop_shop_price_piloting');
1712
-                $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'])) : '';
1713
-                $variations = wpshop_products::get_variation($product_id);
1711
+				$price_ploting = get_option('wpshop_shop_price_piloting');
1712
+				$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'])) : '';
1713
+				$variations = wpshop_products::get_variation($product_id);
1714 1714
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1715 1715
 				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1716 1716
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1717 1717
 				}
1718
-                $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1719
-                $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1720
-                $product_price_infos['MESSAGE_SAVE_MONEY'];
1721
-                $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1722
-            } else {
1723
-                $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1724
-            }
1725
-        }
1718
+				$tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1719
+				$tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1720
+				$product_price_infos['MESSAGE_SAVE_MONEY'];
1721
+				$productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1722
+			} else {
1723
+				$productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1724
+			}
1725
+		}
1726 1726
 
1727
-        /** Check if there is at less 1 product in stock    */
1728
-        $wps_product_ctr = new wps_product_ctr();
1729
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1730
-        $productStock = $productStock === true ? 1 : null;
1731
-
1732
-        /** Define "Add to cart" button    */
1733
-        $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');
1734
-        $display_price_state_when_price_is_empty = false;
1735
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1736
-            $display_price_state_when_price_is_empty = false;
1737
-        } else if (!empty($productPrice)) {
1738
-            $display_price_state_when_price_is_empty = true;
1739
-        }
1740
-        $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') : '';
1741
-        $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)) : '';
1727
+		/** Check if there is at less 1 product in stock    */
1728
+		$wps_product_ctr = new wps_product_ctr();
1729
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1730
+		$productStock = $productStock === true ? 1 : null;
1731
+
1732
+		/** Define "Add to cart" button    */
1733
+		$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');
1734
+		$display_price_state_when_price_is_empty = false;
1735
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1736
+			$display_price_state_when_price_is_empty = false;
1737
+		} else if (!empty($productPrice)) {
1738
+			$display_price_state_when_price_is_empty = true;
1739
+		}
1740
+		$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') : '';
1741
+		$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)) : '';
1742 1742
 
1743
-        /** Define "Ask a quotation" button    */
1744
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1745
-        $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'] : ''));
1743
+		/** Define "Ask a quotation" button    */
1744
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1745
+		$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'] : ''));
1746 1746
 
1747
-        $product_new = $product_new_def['output'];
1748
-        $product_class .= $product_new_def['class'];
1747
+		$product_new = $product_new_def['output'];
1748
+		$product_class .= $product_new_def['class'];
1749 1749
 
1750
-        $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'] : ''));
1751
-        $product_featured = $product_featured_def['output'];
1752
-        $product_class .= $product_featured_def['class'];
1750
+		$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'] : ''));
1751
+		$product_featured = $product_featured_def['output'];
1752
+		$product_class .= $product_featured_def['class'];
1753 1753
 
1754
-        if (!($current_item_position % $grid_element_nb_per_line)) {
1755
-            $product_class .= ' wpshop_last_product_of_line';
1756
-        }
1754
+		if (!($current_item_position % $grid_element_nb_per_line)) {
1755
+			$product_class .= ' wpshop_last_product_of_line';
1756
+		}
1757 1757
 
1758
-        if (!empty($product['product_id'])) {
1759
-            /** Template parameters    */
1760
-            $template_part = 'product_mini_' . $output_type;
1761
-            $tpl_component = array();
1762
-            $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1763
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1764
-            $tpl_component['PRODUCT_ID'] = $product_id;
1765
-            $tpl_component['PRODUCT_CLASS'] = $product_class;
1766
-            $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1767
-            $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1768
-            $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1769
-            $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1770
-            $tpl_component['PRODUCT_PRICE'] = $productPrice;
1771
-            $tpl_component['PRODUCT_PERMALINK'] = $product_link;
1772
-            $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1773
-            $tpl_component['PRODUCT_NAME'] = $product_name;
1774
-            $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1775
-            $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1776
-            $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1777
-            $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1778
-            $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1779
-
1780
-            if (has_post_thumbnail($product_id)) {
1781
-                $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1782
-                if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1783
-                    $existing_image_sizes = get_intermediate_image_sizes();
1784
-                    foreach ($existing_image_sizes as $size_name) {
1785
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1786
-                        $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;
1787
-                    }
1788
-                }
1789
-            }
1790
-
1791
-            $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1792
-            $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1793
-            $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1794
-
1795
-            /** Build template    */
1796
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1797
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1798
-                /**    Include the old way template part    */
1799
-                ob_start();
1800
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1801
-                $content = ob_get_contents();
1802
-                ob_end_clean();
1803
-            } else {
1804
-                $content = wpshop_display::display_template_element($template_part, $tpl_component);
1805
-            }
1806
-            unset($tpl_component);
1758
+		if (!empty($product['product_id'])) {
1759
+			/** Template parameters    */
1760
+			$template_part = 'product_mini_' . $output_type;
1761
+			$tpl_component = array();
1762
+			$tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1763
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1764
+			$tpl_component['PRODUCT_ID'] = $product_id;
1765
+			$tpl_component['PRODUCT_CLASS'] = $product_class;
1766
+			$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1767
+			$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1768
+			$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1769
+			$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1770
+			$tpl_component['PRODUCT_PRICE'] = $productPrice;
1771
+			$tpl_component['PRODUCT_PERMALINK'] = $product_link;
1772
+			$tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1773
+			$tpl_component['PRODUCT_NAME'] = $product_name;
1774
+			$tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1775
+			$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1776
+			$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1777
+			$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1778
+			$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1779
+
1780
+			if (has_post_thumbnail($product_id)) {
1781
+				$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1782
+				if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1783
+					$existing_image_sizes = get_intermediate_image_sizes();
1784
+					foreach ($existing_image_sizes as $size_name) {
1785
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1786
+						$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;
1787
+					}
1788
+				}
1789
+			}
1807 1790
 
1808
-        }
1791
+			$tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1792
+			$tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1793
+			$tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1794
+
1795
+			/** Build template    */
1796
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1797
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1798
+				/**    Include the old way template part    */
1799
+				ob_start();
1800
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1801
+				$content = ob_get_contents();
1802
+				ob_end_clean();
1803
+			} else {
1804
+				$content = wpshop_display::display_template_element($template_part, $tpl_component);
1805
+			}
1806
+			unset($tpl_component);
1809 1807
 
1810
-        return $content;
1811
-    }
1808
+		}
1812 1809
 
1813
-    /**
1814
-     *    Get the products (post) of a given category
1815
-     *
1816
-     *    @param string $category_slug The category slug we want to get the product list for
1817
-     *
1818
-     *    @return mixed $widget_content The output for the product list
1819
-     */
1820
-    public static function get_product_of_category($category_slug, $category_id)
1821
-    {
1822
-        global $top_categories;
1823
-        $widget_content = '';
1824
-        $products = wp_cache_get('wpshop_products_category_' . $category_id);
1825
-        if (false == $products) {
1826
-            $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1827
-            $products = get_posts($args);
1828
-            wp_cache_set('wpshop_products_category_' . $category_id, $products);
1829
-        }
1830
-        if (is_array($products) && (count($products) > 0)) {
1831
-            foreach ($products as $product) {
1832
-                if ($product->post_status == "publish") {
1833
-                    ob_start();
1834
-                    require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1835
-                    $widget_content .= ob_get_contents();
1836
-                    ob_end_clean();
1837
-                }
1838
-            }
1839
-        }
1810
+		return $content;
1811
+	}
1840 1812
 
1841
-        echo $widget_content;
1842
-    }
1813
+	/**
1814
+	 *    Get the products (post) of a given category
1815
+	 *
1816
+	 *    @param string $category_slug The category slug we want to get the product list for
1817
+	 *
1818
+	 *    @return mixed $widget_content The output for the product list
1819
+	 */
1820
+	public static function get_product_of_category($category_slug, $category_id)
1821
+	{
1822
+		global $top_categories;
1823
+		$widget_content = '';
1824
+		$products = wp_cache_get('wpshop_products_category_' . $category_id);
1825
+		if (false == $products) {
1826
+			$args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1827
+			$products = get_posts($args);
1828
+			wp_cache_set('wpshop_products_category_' . $category_id, $products);
1829
+		}
1830
+		if (is_array($products) && (count($products) > 0)) {
1831
+			foreach ($products as $product) {
1832
+				if ($product->post_status == "publish") {
1833
+					ob_start();
1834
+					require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1835
+					$widget_content .= ob_get_contents();
1836
+					ob_end_clean();
1837
+				}
1838
+			}
1839
+		}
1843 1840
 
1844
-    /**
1845
-     *
1846
-     * @param unknown_type $selected_product
1847
-     * @return string
1848
-     */
1849
-    public function custom_product_list($selected_product = array())
1850
-    {
1851
-        global $wpdb;
1852
-
1853
-        /*    Start the table definition    */
1854
-        $tableId = 'wpshop_product_list';
1855
-        $tableTitles = array();
1856
-        $tableTitles[] = '';
1857
-        $tableTitles[] = __('Id', 'wpshop');
1858
-        $tableTitles[] = __('Quantity', 'wpshop');
1859
-        $tableTitles[] = __('Reference', 'wpshop');
1860
-        $tableTitles[] = __('Product name', 'wpshop');
1861
-        $tableTitles[] = __('Actions', 'wpshop');
1862
-        $tableTitles[] = __('Price', 'wpshop');
1863
-        $tableClasses = array();
1864
-        $tableClasses[] = 'wpshop_product_selector_column';
1865
-        $tableClasses[] = 'wpshop_product_identifier_column';
1866
-        $tableClasses[] = 'wpshop_product_quantity_column';
1867
-        $tableClasses[] = 'wpshop_product_sku_column';
1868
-        $tableClasses[] = 'wpshop_product_name_column';
1869
-        $tableClasses[] = 'wpshop_product_link_column';
1870
-        $tableClasses[] = 'wpshop_product_price_column';
1871
-
1872
-        /*    Get post list    */
1873
-        $has_result = false;
1874
-        $current_line_index = 0;
1875
-        $posts = query_posts(array(
1876
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1877
-        ));
1878
-        if (!empty($posts)) {
1879
-            $has_result = true;
1880
-            foreach ($posts as $post) {
1881
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1882
-
1883
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1884
-
1885
-                unset($tableRowValue);
1886
-                $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 . '" />');
1887
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1888
-                $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>');
1889
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1890
-                $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1891
-                $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/>
1841
+		echo $widget_content;
1842
+	}
1843
+
1844
+	/**
1845
+	 *
1846
+	 * @param unknown_type $selected_product
1847
+	 * @return string
1848
+	 */
1849
+	public function custom_product_list($selected_product = array())
1850
+	{
1851
+		global $wpdb;
1852
+
1853
+		/*    Start the table definition    */
1854
+		$tableId = 'wpshop_product_list';
1855
+		$tableTitles = array();
1856
+		$tableTitles[] = '';
1857
+		$tableTitles[] = __('Id', 'wpshop');
1858
+		$tableTitles[] = __('Quantity', 'wpshop');
1859
+		$tableTitles[] = __('Reference', 'wpshop');
1860
+		$tableTitles[] = __('Product name', 'wpshop');
1861
+		$tableTitles[] = __('Actions', 'wpshop');
1862
+		$tableTitles[] = __('Price', 'wpshop');
1863
+		$tableClasses = array();
1864
+		$tableClasses[] = 'wpshop_product_selector_column';
1865
+		$tableClasses[] = 'wpshop_product_identifier_column';
1866
+		$tableClasses[] = 'wpshop_product_quantity_column';
1867
+		$tableClasses[] = 'wpshop_product_sku_column';
1868
+		$tableClasses[] = 'wpshop_product_name_column';
1869
+		$tableClasses[] = 'wpshop_product_link_column';
1870
+		$tableClasses[] = 'wpshop_product_price_column';
1871
+
1872
+		/*    Get post list    */
1873
+		$has_result = false;
1874
+		$current_line_index = 0;
1875
+		$posts = query_posts(array(
1876
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1877
+		));
1878
+		if (!empty($posts)) {
1879
+			$has_result = true;
1880
+			foreach ($posts as $post) {
1881
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1882
+
1883
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1884
+
1885
+				unset($tableRowValue);
1886
+				$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 . '" />');
1887
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1888
+				$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>');
1889
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1890
+				$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1891
+				$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/>
1892 1892
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1893
-                $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() : ''));
1894
-                $tableRows[] = $tableRowValue;
1893
+				$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() : ''));
1894
+				$tableRows[] = $tableRowValue;
1895 1895
 
1896
-                $current_line_index++;
1897
-            }
1898
-            wp_reset_query();
1899
-        }
1900
-        $posts = query_posts(array(
1901
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1902
-        ));
1903
-        if (!empty($posts)) {
1904
-            $has_result = true;
1905
-            foreach ($posts as $post) {
1906
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1907
-
1908
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1909
-
1910
-                unset($tableRowValue);
1911
-                $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 . '" />');
1912
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1913
-                $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>');
1914
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1915
-                $parent_product = wpshop_products::get_parent_variation($post->ID);
1916
-                if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1917
-                    $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1918
-                    $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1919
-                    $option_name = $wpdb->get_var($query);
1920
-                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1921
-                    $option_value = $wpdb->get_var($query);
1922
-                    $parent_post = $parent_product['parent_post'];
1923
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1924
-                } else {
1925
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1926
-                }
1927
-
1928
-                $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/>
1896
+				$current_line_index++;
1897
+			}
1898
+			wp_reset_query();
1899
+		}
1900
+		$posts = query_posts(array(
1901
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1902
+		));
1903
+		if (!empty($posts)) {
1904
+			$has_result = true;
1905
+			foreach ($posts as $post) {
1906
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1907
+
1908
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1909
+
1910
+				unset($tableRowValue);
1911
+				$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 . '" />');
1912
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1913
+				$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>');
1914
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1915
+				$parent_product = wpshop_products::get_parent_variation($post->ID);
1916
+				if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1917
+					$product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1918
+					$query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1919
+					$option_name = $wpdb->get_var($query);
1920
+					$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1921
+					$option_value = $wpdb->get_var($query);
1922
+					$parent_post = $parent_product['parent_post'];
1923
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1924
+				} else {
1925
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1926
+				}
1927
+
1928
+				$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/>
1929 1929
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1930
-                $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() : ''));
1931
-                $tableRows[] = $tableRowValue;
1930
+				$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() : ''));
1931
+				$tableRows[] = $tableRowValue;
1932 1932
 
1933
-                $current_line_index++;
1934
-            }
1935
-            wp_reset_query();
1936
-        }
1933
+				$current_line_index++;
1934
+			}
1935
+			wp_reset_query();
1936
+		}
1937 1937
 
1938
-        if (!$has_result) {
1939
-            $tableRowsId[] = 'no_product_found';
1940
-            unset($tableRowValue);
1941
-            $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1942
-            $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1943
-            $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1944
-            $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1945
-            $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1946
-            $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1947
-            $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1948
-            $tableRows[] = $tableRowValue;
1949
-        }
1938
+		if (!$has_result) {
1939
+			$tableRowsId[] = 'no_product_found';
1940
+			unset($tableRowValue);
1941
+			$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1942
+			$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1943
+			$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1944
+			$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1945
+			$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1946
+			$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1947
+			$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1948
+			$tableRows[] = $tableRowValue;
1949
+		}
1950 1950
 
1951
-        return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1951
+		return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1952 1952
 <script type="text/javascript" >
1953 1953
 	wpshop(document).ready(function(){
1954 1954
 		jQuery("#' . $tableId . '").dataTable( {
@@ -1957,1534 +1957,1534 @@  discard block
 block discarded – undo
1957 1957
 		});
1958 1958
 	});
1959 1959
 </script>';
1960
-    }
1960
+	}
1961 1961
 
1962
-    /**
1963
-     * Allows to manage output for special state for a product (New product/highlight product)
1964
-     *
1965
-     * @param string $special The type of special type we want to output
1966
-     * @param string $output_type The current display type (used for product listing)
1967
-     * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1968
-     * @param datetime $special_state_start The start date if applicable for the special state
1969
-     * @param datetime $special_state_end The end date if applicable for the special state
1970
-     *
1971
-     * @return array $product_special_state The product special state
1972
-     */
1973
-    public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1974
-    {
1975
-        $product_special_state = array();
1976
-        $product_special_state['output'] = $product_special_state['class'] = '';
1977
-
1978
-        /** Get product special state definition    */
1979
-        $special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1980
-        $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1981
-        $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1982
-
1983
-        /** Get current time    */
1984
-        $current_time = substr(current_time('mysql', 0), 0, 10);
1985
-
1986
-        /** PRODUCT MARK AS NEW */
1987
-        $show_product_special_state = false;
1988
-        if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1989
-            (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1990
-            (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1991
-            $show_product_special_state = true;
1992
-        }
1962
+	/**
1963
+	 * Allows to manage output for special state for a product (New product/highlight product)
1964
+	 *
1965
+	 * @param string $special The type of special type we want to output
1966
+	 * @param string $output_type The current display type (used for product listing)
1967
+	 * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1968
+	 * @param datetime $special_state_start The start date if applicable for the special state
1969
+	 * @param datetime $special_state_end The end date if applicable for the special state
1970
+	 *
1971
+	 * @return array $product_special_state The product special state
1972
+	 */
1973
+	public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1974
+	{
1975
+		$product_special_state = array();
1976
+		$product_special_state['output'] = $product_special_state['class'] = '';
1977
+
1978
+		/** Get product special state definition    */
1979
+		$special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1980
+		$special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1981
+		$special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1982
+
1983
+		/** Get current time    */
1984
+		$current_time = substr(current_time('mysql', 0), 0, 10);
1985
+
1986
+		/** PRODUCT MARK AS NEW */
1987
+		$show_product_special_state = false;
1988
+		if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1989
+			(empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1990
+			(empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1991
+			$show_product_special_state = true;
1992
+		}
1993 1993
 
1994
-        if ($show_product_special_state) {
1995
-            /** Check the type of special output needed    */
1996
-            switch ($special) {
1997
-                case 'declare_new':
1998
-                    $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1999
-                    $template_part = 'product_is_new_sticker';
2000
-                    break;
2001
-
2002
-                case 'highlight_product':
2003
-                    $product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2004
-                    $template_part = 'product_is_featured_sticker';
2005
-                    break;
2006
-            }
2007
-
2008
-            /** Template parameters    */
2009
-            $tpl_component = array();
2010
-
2011
-            /** Build template        */
2012
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2013
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2014
-                /**    Include the old way template part    */
2015
-                ob_start();
2016
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2017
-                $product_special_state['output'] = ob_get_contents();
2018
-                ob_end_clean();
2019
-            } else {
2020
-                $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2021
-            }
2022
-            unset($tpl_component);
2023
-        }
1994
+		if ($show_product_special_state) {
1995
+			/** Check the type of special output needed    */
1996
+			switch ($special) {
1997
+				case 'declare_new':
1998
+					$product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1999
+					$template_part = 'product_is_new_sticker';
2000
+					break;
2024 2001
 
2025
-        return $product_special_state;
2026
-    }
2002
+				case 'highlight_product':
2003
+					$product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2004
+					$template_part = 'product_is_featured_sticker';
2005
+					break;
2006
+			}
2027 2007
 
2028
-    /**
2029
-     * Prepare product price for saving and easier read later
2030
-     *
2031
-     * @param integer $element_id Identifier of current product
2032
-     */
2033
-    public static function calculate_price($element_id)
2034
-    {
2035
-        global $wpdb;
2036
-
2037
-        /**
2038
-         * Récupères les attributs suivants : product_price, price_ht et tva
2039
-         * par rapport à $element_id / Get the next attributes : product_price,
2040
-         * price_ht and tva
2041
-         */
2042
-        $query = $wpdb->prepare(
2043
-            "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2008
+			/** Template parameters    */
2009
+			$tpl_component = array();
2010
+
2011
+			/** Build template        */
2012
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2013
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2014
+				/**    Include the old way template part    */
2015
+				ob_start();
2016
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2017
+				$product_special_state['output'] = ob_get_contents();
2018
+				ob_end_clean();
2019
+			} else {
2020
+				$product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2021
+			}
2022
+			unset($tpl_component);
2023
+		}
2024
+
2025
+		return $product_special_state;
2026
+	}
2027
+
2028
+	/**
2029
+	 * Prepare product price for saving and easier read later
2030
+	 *
2031
+	 * @param integer $element_id Identifier of current product
2032
+	 */
2033
+	public static function calculate_price($element_id)
2034
+	{
2035
+		global $wpdb;
2036
+
2037
+		/**
2038
+		 * Récupères les attributs suivants : product_price, price_ht et tva
2039
+		 * par rapport à $element_id / Get the next attributes : product_price,
2040
+		 * price_ht and tva
2041
+		 */
2042
+		$query = $wpdb->prepare(
2043
+			"SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2044 2044
 			FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR
2045 2045
 				RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d))
2046 2046
 			WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')",
2047
-            $element_id
2048
-        );
2049
-        $prices_attribute = $wpdb->get_results($query, OBJECT_K);
2050
-
2051
-        /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2052
-        if (empty($prices_attribute)) {
2053
-            return false;
2054
-        } else {
2055
-            /**
2056
-             * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2057
-             * the base amount according on the shop price control
2058
-             */
2059
-            $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2060
-            $rate_vat = wpshop_prices::get_rate_vat($element_id);
2061
-            $divider_price_ttc = 1 + ($rate_vat->value / 100);
2062
-
2063
-            /**
2064
-             * Informations nécessaire pour crée un attribut / Information needed to
2065
-             * create an attribute
2066
-             */
2067
-            $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2068
-            $language = WPSHOP_CURRENT_LOCALE;
2069
-            $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2070
-
2071
-            if (!empty($icl_post_language)) {
2072
-                $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2073
-                $language = $wpdb->get_var($query);
2074
-            }
2075
-
2076
-            /**
2077
-             * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2078
-             * Check configuration to know how to make the calcul for the product
2079
-             */
2080
-            if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2081
-                $price_with_vat = ($base_price * $divider_price_ttc);
2082
-                $price_no_vat = $base_price;
2083
-            } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2084
-                $price_with_vat = $base_price;
2085
-                $price_no_vat = ($price_with_vat / $divider_price_ttc);
2086
-            }
2087
-
2088
-            /**
2089
-             * Le dernier paramètre permet de ne pas supprimer les attributs du même
2090
-             * type que celui-ci / The last parameter allows not to delete the
2091
-             * attributes of the same type as this one
2092
-             */
2093
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2094
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2095
-
2096
-            /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2097
-            $vat_amount = $price_with_vat - $price_no_vat;
2098
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2099
-
2100
-            /**    Update the product meta information with the calculated prices    */
2101
-            $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2102
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2103
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2104
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2105
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2106
-
2107
-            update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2047
+			$element_id
2048
+		);
2049
+		$prices_attribute = $wpdb->get_results($query, OBJECT_K);
2050
+
2051
+		/** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2052
+		if (empty($prices_attribute)) {
2053
+			return false;
2054
+		} else {
2055
+			/**
2056
+			 * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2057
+			 * the base amount according on the shop price control
2058
+			 */
2059
+			$base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2060
+			$rate_vat = wpshop_prices::get_rate_vat($element_id);
2061
+			$divider_price_ttc = 1 + ($rate_vat->value / 100);
2062
+
2063
+			/**
2064
+			 * Informations nécessaire pour crée un attribut / Information needed to
2065
+			 * create an attribute
2066
+			 */
2067
+			$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2068
+			$language = WPSHOP_CURRENT_LOCALE;
2069
+			$icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2070
+
2071
+			if (!empty($icl_post_language)) {
2072
+				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2073
+				$language = $wpdb->get_var($query);
2074
+			}
2108 2075
 
2109
-            /** Met à jour la meta _wps_price_infos */
2110
-            $p = wpshop_products::get_product_data($element_id);
2111
-            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2112
-            update_post_meta($element_id, '_wps_price_infos', $price);
2076
+			/**
2077
+			 * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2078
+			 * Check configuration to know how to make the calcul for the product
2079
+			 */
2080
+			if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2081
+				$price_with_vat = ($base_price * $divider_price_ttc);
2082
+				$price_no_vat = $base_price;
2083
+			} else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2084
+				$price_with_vat = $base_price;
2085
+				$price_no_vat = ($price_with_vat / $divider_price_ttc);
2086
+			}
2113 2087
 
2114
-            /** Met à jour la meta _wpshop_displayed_price */
2115
-            wps_filter_search::save_displayed_price_meta($element_id);
2116
-        }
2088
+			/**
2089
+			 * Le dernier paramètre permet de ne pas supprimer les attributs du même
2090
+			 * type que celui-ci / The last parameter allows not to delete the
2091
+			 * attributes of the same type as this one
2092
+			 */
2093
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2094
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2095
+
2096
+			/** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2097
+			$vat_amount = $price_with_vat - $price_no_vat;
2098
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2099
+
2100
+			/**    Update the product meta information with the calculated prices    */
2101
+			$product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2102
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2103
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2104
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2105
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2106
+
2107
+			update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2108
+
2109
+			/** Met à jour la meta _wps_price_infos */
2110
+			$p = wpshop_products::get_product_data($element_id);
2111
+			$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2112
+			update_post_meta($element_id, '_wps_price_infos', $price);
2113
+
2114
+			/** Met à jour la meta _wpshop_displayed_price */
2115
+			wps_filter_search::save_displayed_price_meta($element_id);
2116
+		}
2117 2117
 
2118
-        return true;
2119
-    }
2118
+		return true;
2119
+	}
2120 2120
 
2121
-    /**
2122
-     * Allows to get the good button for adding product to cart
2123
-     *
2124
-     * @param integer $product_id The product identifier
2125
-     * @param boolean $productStock If there is the possibility to add the given product to the cart
2126
-     *
2127
-     * @return string $button The html output for the button
2128
-     */
2129
-    public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2130
-    {
2131
-        $button = '';
2121
+	/**
2122
+	 * Allows to get the good button for adding product to cart
2123
+	 *
2124
+	 * @param integer $product_id The product identifier
2125
+	 * @param boolean $productStock If there is the possibility to add the given product to the cart
2126
+	 *
2127
+	 * @return string $button The html output for the button
2128
+	 */
2129
+	public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2130
+	{
2131
+		$button = '';
2132 2132
 //         $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true );
2133 2133
 
2134
-        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') ) */) {
2135
-            /*
2134
+		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') ) */) {
2135
+			/*
2136 2136
              * Check if current product has variation for button display
2137 2137
              */
2138
-            $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2139
-            $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2138
+			$variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2139
+			$variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2140 2140
 
2141
-            /*
2141
+			/*
2142 2142
              * Template parameters
2143 2143
              */
2144 2144
 
2145
-            if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2146
-                /** Check variation stock **/
2147
-                $variations = self::get_variation($product_id);
2148
-                if (!empty($variations)) {
2149
-                    foreach ($variations as $variation) {
2150
-                        if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2151
-                            $productStock += $variation['variation_dif']['product_stock'];
2152
-                        }
2153
-                    }
2154
-                }
2155
-            }
2156
-
2157
-            $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2145
+			if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2146
+				/** Check variation stock **/
2147
+				$variations = self::get_variation($product_id);
2148
+				if (!empty($variations)) {
2149
+					foreach ($variations as $variation) {
2150
+						if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2151
+							$productStock += $variation['variation_dif']['product_stock'];
2152
+						}
2153
+					}
2154
+				}
2155
+			}
2156
+
2157
+			$template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2158 2158
 						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2159 2159
 
2160
-            $tpl_component = array();
2161
-            $tpl_component['PRODUCT_ID'] = $product_id;
2162
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2163
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2160
+			$tpl_component = array();
2161
+			$tpl_component['PRODUCT_ID'] = $product_id;
2162
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2163
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2164 2164
 
2165
-            /*
2165
+			/*
2166 2166
              * Build template
2167 2167
              */
2168
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2169
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2170
-                /*    Include the old way template part    */
2171
-                ob_start();
2172
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2173
-                $button = ob_get_contents();
2174
-                ob_end_clean();
2175
-            } else {
2176
-                $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));
2177
-            }
2178
-            unset($tpl_component);
2179
-        }
2180
-        return $button;
2181
-    }
2182
-
2183
-    /**
2184
-     * Allows to get the good button for adding product to a quotation
2185
-     *
2186
-     * @param integer $product_id The product identifier
2187
-     * @param boolean $product_quotation_state The state of the quotation addons
2188
-     *
2189
-     * @return string $button The html output for the button
2190
-     */
2191
-    public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2192
-    {
2193
-        $quotation_button = '';
2194
-
2195
-        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'))) {
2196
-            $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();
2197
-            /**
2198
-             * Template parameters
2199
-             */
2200
-            $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2201
-            $tpl_component = array();
2202
-            $tpl_component['PRODUCT_ID'] = $product_id;
2203
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2204
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2168
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2169
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2170
+				/*    Include the old way template part    */
2171
+				ob_start();
2172
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2173
+				$button = ob_get_contents();
2174
+				ob_end_clean();
2175
+			} else {
2176
+				$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));
2177
+			}
2178
+			unset($tpl_component);
2179
+		}
2180
+		return $button;
2181
+	}
2205 2182
 
2206
-            /**
2207
-             * Build template
2208
-             */
2209
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2210
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2211
-                /*    Include the old way template part    */
2212
-                ob_start();
2213
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2214
-                $quotation_button = ob_get_contents();
2215
-                ob_end_clean();
2216
-            } else {
2217
-                $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2218
-            }
2219
-            unset($tpl_component);
2220
-        }
2183
+	/**
2184
+	 * Allows to get the good button for adding product to a quotation
2185
+	 *
2186
+	 * @param integer $product_id The product identifier
2187
+	 * @param boolean $product_quotation_state The state of the quotation addons
2188
+	 *
2189
+	 * @return string $button The html output for the button
2190
+	 */
2191
+	public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2192
+	{
2193
+		$quotation_button = '';
2194
+
2195
+		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'))) {
2196
+			$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();
2197
+			/**
2198
+			 * Template parameters
2199
+			 */
2200
+			$template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2201
+			$tpl_component = array();
2202
+			$tpl_component['PRODUCT_ID'] = $product_id;
2203
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2204
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2205
+
2206
+			/**
2207
+			 * Build template
2208
+			 */
2209
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2210
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2211
+				/*    Include the old way template part    */
2212
+				ob_start();
2213
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2214
+				$quotation_button = ob_get_contents();
2215
+				ob_end_clean();
2216
+			} else {
2217
+				$quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2218
+			}
2219
+			unset($tpl_component);
2220
+		}
2221 2221
 
2222
-        return $quotation_button;
2223
-    }
2222
+		return $quotation_button;
2223
+	}
2224 2224
 
2225
-    /**
2226
-     * Return the output for a product attachement gallery (picture or document)
2227
-     *
2228
-     * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2229
-     * @param string $content The gallery content build previously
2230
-     *
2231
-     * @return string The attachement gallery output
2232
-     */
2233
-    public static function display_attachment_gallery($attachement_type, $content)
2234
-    {
2235
-        $galery_output = '';
2236
-
2237
-        /*
2225
+	/**
2226
+	 * Return the output for a product attachement gallery (picture or document)
2227
+	 *
2228
+	 * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2229
+	 * @param string $content The gallery content build previously
2230
+	 *
2231
+	 * @return string The attachement gallery output
2232
+	 */
2233
+	public static function display_attachment_gallery($attachement_type, $content)
2234
+	{
2235
+		$galery_output = '';
2236
+
2237
+		/*
2238 2238
          * Get the template part for given galery type
2239 2239
          */
2240
-        switch ($attachement_type) {
2241
-            case 'picture':
2242
-                $template_part = 'product_attachment_picture_galery';
2243
-                break;
2244
-            case 'document':
2245
-                $template_part = 'product_attachment_galery';
2246
-                break;
2247
-        }
2240
+		switch ($attachement_type) {
2241
+			case 'picture':
2242
+				$template_part = 'product_attachment_picture_galery';
2243
+				break;
2244
+			case 'document':
2245
+				$template_part = 'product_attachment_galery';
2246
+				break;
2247
+		}
2248 2248
 
2249
-        /*
2249
+		/*
2250 2250
          * Template parameters
2251 2251
          */
2252
-        $tpl_component = array();
2253
-        $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2254
-        $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2252
+		$tpl_component = array();
2253
+		$tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2254
+		$tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2255 2255
 
2256
-        /*
2256
+		/*
2257 2257
          * Build template
2258 2258
          */
2259
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2260
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2261
-            /*    Include the old way template part    */
2262
-            ob_start();
2263
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
2264
-            $galery_output = ob_get_contents();
2265
-            ob_end_clean();
2266
-        } else {
2267
-            $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2268
-        }
2269
-        unset($tpl_component);
2259
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2260
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2261
+			/*    Include the old way template part    */
2262
+			ob_start();
2263
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
2264
+			$galery_output = ob_get_contents();
2265
+			ob_end_clean();
2266
+		} else {
2267
+			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2268
+		}
2269
+		unset($tpl_component);
2270 2270
 
2271
-        return $galery_output;
2272
-    }
2271
+		return $galery_output;
2272
+	}
2273 2273
 
2274
-    /**
2275
-     * Define the metabox to display in product edition page in backend
2276
-     * @param object $post The current element displayed for edition
2277
-     */
2278
-    public static function meta_box_variations($post)
2279
-    {
2280
-        $output = '';
2281
-        /*    Variations container    */
2282
-        $tpl_component = array();
2283
-        $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2284
-        $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2285
-        $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2286
-        echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2287
-    }
2274
+	/**
2275
+	 * Define the metabox to display in product edition page in backend
2276
+	 * @param object $post The current element displayed for edition
2277
+	 */
2278
+	public static function meta_box_variations($post)
2279
+	{
2280
+		$output = '';
2281
+		/*    Variations container    */
2282
+		$tpl_component = array();
2283
+		$tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2284
+		$tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2285
+		$output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2286
+		echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2287
+	}
2288 2288
 
2289
-    /**
2290
-     * Call variation creation function with a list of defined variation
2291
-     *
2292
-     * @param array $possible_variations A list of variation to create for the current element
2293
-     * @param integer $element_id The product we want to create variation for
2294
-     *
2295
-     * @return mixed The last created variation identifier
2296
-     */
2297
-    public static function creation_variation_callback($possible_variations, $element_id)
2298
-    {
2299
-        /** Get existing variation    */
2300
-        $existing_variations_in_db = wpshop_products::get_variation($element_id);
2301
-        $existing_variations = array();
2302
-        if (!empty($existing_variations_in_db)) {
2303
-            foreach ($existing_variations_in_db as $variations_def) {
2304
-                $existing_variations[] = $variations_def['variation_def'];
2305
-            }
2306
-        }
2307
-        /** New variation definition    */
2308
-        $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2309
-
2310
-        /**    Read possible values    */
2311
-        foreach ($possible_variations as $variation_definition) {
2312
-            if (in_array($variation_definition, $existing_variations)) {
2313
-                continue;
2314
-            }
2315
-
2316
-            $attribute_to_set = array();
2317
-            foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2318
-                $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2319
-                $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2320
-                if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2321
-                    $attribute_defining_variation['attributes'][] = $attribute_code;
2322
-                }
2323
-            }
2324
-            $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2325
-        }
2326
-        update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2289
+	/**
2290
+	 * Call variation creation function with a list of defined variation
2291
+	 *
2292
+	 * @param array $possible_variations A list of variation to create for the current element
2293
+	 * @param integer $element_id The product we want to create variation for
2294
+	 *
2295
+	 * @return mixed The last created variation identifier
2296
+	 */
2297
+	public static function creation_variation_callback($possible_variations, $element_id)
2298
+	{
2299
+		/** Get existing variation    */
2300
+		$existing_variations_in_db = wpshop_products::get_variation($element_id);
2301
+		$existing_variations = array();
2302
+		if (!empty($existing_variations_in_db)) {
2303
+			foreach ($existing_variations_in_db as $variations_def) {
2304
+				$existing_variations[] = $variations_def['variation_def'];
2305
+			}
2306
+		}
2307
+		/** New variation definition    */
2308
+		$attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2327 2309
 
2328
-        return !empty($variation_id) ? $variation_id : 0;
2329
-    }
2310
+		/**    Read possible values    */
2311
+		foreach ($possible_variations as $variation_definition) {
2312
+			if (in_array($variation_definition, $existing_variations)) {
2313
+				continue;
2314
+			}
2330 2315
 
2331
-    /**
2332
-     * Create a new variation for product
2333
-     *
2334
-     * @param integer $head_product The product identifier to create the new variation for
2335
-     * @param array $variation_attributes Attribute list for the variation
2336
-     *
2337
-     * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2338
-     */
2339
-    public static function create_variation($head_product, $variation_attributes)
2340
-    {
2341
-        /** Create custom title */
2342
-        $title_variation = "";
2343
-        if (!empty($variation_attributes)) {
2344
-            foreach ($variation_attributes as $type => $array) {
2345
-                if (!empty($array)) {
2346
-                    foreach ($array as $code => $value) {
2347
-                        $title_variation .= " " . $code . " " . $value;
2348
-                    }
2349
-                }
2350
-            }
2351
-        }
2316
+			$attribute_to_set = array();
2317
+			foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2318
+				$attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2319
+				$attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2320
+				if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2321
+					$attribute_defining_variation['attributes'][] = $attribute_code;
2322
+				}
2323
+			}
2324
+			$variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2325
+		}
2326
+		update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2352 2327
 
2353
-        $variation = array(
2354
-            'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2355
-            'post_content' => '',
2356
-            'post_status' => 'publish',
2357
-            'post_author' => get_current_user_id(),
2358
-            'post_parent' => $head_product,
2359
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2360
-        );
2361
-        $variation_id = wp_insert_post($variation);
2362
-
2363
-        wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2364
-
2365
-        /*    Update product price looking for shop parameters    */
2366
-        wpshop_products::calculate_price($variation_id);
2367
-
2368
-        /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2369
-        $productMetaDatas = array();
2370
-        foreach ($variation_attributes as $attributeType => $attributeValues) {
2371
-            foreach ($attributeValues as $attributeCode => $attributeValue) {
2372
-                if (!empty($attributeValue)) {
2373
-                    $productMetaDatas[$attributeCode] = $attributeValue;
2374
-                }
2375
-            }
2376
-        }
2377
-        update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2378
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2379
-        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));
2328
+		return !empty($variation_id) ? $variation_id : 0;
2329
+	}
2380 2330
 
2381
-        return $variation_id;
2382
-    }
2331
+	/**
2332
+	 * Create a new variation for product
2333
+	 *
2334
+	 * @param integer $head_product The product identifier to create the new variation for
2335
+	 * @param array $variation_attributes Attribute list for the variation
2336
+	 *
2337
+	 * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2338
+	 */
2339
+	public static function create_variation($head_product, $variation_attributes)
2340
+	{
2341
+		/** Create custom title */
2342
+		$title_variation = "";
2343
+		if (!empty($variation_attributes)) {
2344
+			foreach ($variation_attributes as $type => $array) {
2345
+				if (!empty($array)) {
2346
+					foreach ($array as $code => $value) {
2347
+						$title_variation .= " " . $code . " " . $value;
2348
+					}
2349
+				}
2350
+			}
2351
+		}
2383 2352
 
2384
-    /**
2385
-     * Get variation list for a given product
2386
-     *
2387
-     * @param integer $head_product The product identifier to get the variation for
2388
-     * @return object The variation list
2389
-     */
2390
-    public static function get_variation($head_product, $type = 'any')
2391
-    {
2392
-        global $wpdb;
2393
-        $variations_output = null;
2394
-        $args = array(
2395
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2396
-            'post_parent' => $head_product,
2397
-            'orderby' => 'ID',
2398
-            'order' => 'ASC',
2399
-            'posts_per_page' => -1,
2400
-            'post_status' => $type,
2401
-        );
2402
-        $variations = get_posts($args);
2403
-
2404
-        if (!empty($variations)) {
2405
-            $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2406
-
2407
-            foreach ($variations as $post_def) {
2408
-                $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'");
2409
-                foreach ($data as $content) {
2410
-                    $attribute_value = 'attribute_value_' . $content->data_type;
2411
-                    if (!empty($content->$attribute_value)) {
2412
-                        if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2413
-                            $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2414
-                        } else {
2415
-                            $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2416
-                        }
2417
-                    }
2418
-                }
2419
-                $variations_output[$post_def->ID]['post'] = $post_def;
2420
-            }
2421
-        }
2422
-        wp_reset_query();
2423
-        return $variations_output;
2424
-    }
2353
+		$variation = array(
2354
+			'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2355
+			'post_content' => '',
2356
+			'post_status' => 'publish',
2357
+			'post_author' => get_current_user_id(),
2358
+			'post_parent' => $head_product,
2359
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2360
+		);
2361
+		$variation_id = wp_insert_post($variation);
2362
+
2363
+		wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2364
+
2365
+		/*    Update product price looking for shop parameters    */
2366
+		wpshop_products::calculate_price($variation_id);
2367
+
2368
+		/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2369
+		$productMetaDatas = array();
2370
+		foreach ($variation_attributes as $attributeType => $attributeValues) {
2371
+			foreach ($attributeValues as $attributeCode => $attributeValue) {
2372
+				if (!empty($attributeValue)) {
2373
+					$productMetaDatas[$attributeCode] = $attributeValue;
2374
+				}
2375
+			}
2376
+		}
2377
+		update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2378
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2379
+		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));
2425 2380
 
2426
-    /**
2427
-     * Affichage des variations d'un produit dans l'administration
2428
-     *
2429
-     * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2430
-     * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2431
-     */
2432
-    public static function display_variation_admin($head_product)
2433
-    {
2434
-        $output = '';
2435
-        $productCurrency = wpshop_tools::wpshop_get_currency();
2436
-        /*    Récupération de la liste des variations pour le produit en cours d'édition    */
2437
-        $variations = self::get_variation($head_product);
2438
-        $price_piloting = get_option('wpshop_shop_price_piloting');
2439
-
2440
-        /*    Affichage de la liste des variations pour le produit en cours d'édition    */
2441
-        if (!empty($variations) && is_array($variations)) {
2442
-            $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2443
-
2444
-            foreach ($variations as $variation) {
2445
-                $tpl_component = array();
2446
-
2447
-                $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2448
-                $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2449
-                $tpl_component['VARIATION_DETAIL'] = '  ';
2450
-                $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;
2451
-                $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2452
-                if (!empty($price_piloting) && $price_piloting == 'HT') {
2453
-
2454
-                } else {
2455
-
2456
-                }
2457
-                $post_obj = $variation['post'];
2458
-
2459
-                $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2460
-                if (!empty($parent_product_infos)) {
2461
-                    $parent_post = $parent_product_infos['parent_post'];
2462
-                    $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2463
-                    if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2464
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2465
-                            $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2466
-                        } else {
2467
-                            $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2468
-                        }
2469
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2470
-                    } else {
2471
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2472
-                            $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2473
-                        } else {
2474
-                            $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2475
-                        }
2476
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2477
-                    }
2478
-                    $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2479
-                    $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2480
-                }
2481
-
2482
-                if (!empty($variation['variation_def'])) {
2483
-                    foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2484
-                        if (!empty($variation_value)) {
2485
-                            $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2486
-                            $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');
2487
-                            $tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2488
-
2489
-                            /** Define Link image to variation interface **/
2490
-                            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'))) {
2491
-                                $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2492
-
2493
-                                $media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2494
-                                if (!empty($media_id_data)) {
2495
-                                    $medias_ids = explode(',', $media_id_data);
2496
-
2497
-                                    if (!empty($medias_ids)) {
2498
-                                        foreach ($medias_ids as $media_id) {
2499
-                                            if (!empty($media_id)) {
2500
-                                                $pictures[] = get_post($media_id);
2501
-                                            }
2502
-                                        }
2503
-                                    }
2504
-                                }
2505
-
2506
-                                $pictures_data = '';
2507
-                                if (!empty($pictures)) {
2508
-                                    $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2509
-
2510
-                                    $done_picture = array();
2511
-                                    foreach ($pictures as $picture) {
2512
-                                        if (!in_array($picture->ID, $done_picture)) {
2513
-                                            if (wp_attachment_is_image($picture->ID)) {
2514
-                                                $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2515
-                                                $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');
2516
-
2517
-                                                $done_picture[] = $picture->ID;
2518
-                                            }
2519
-                                        }
2520
-                                    }
2521
-                                }
2522
-
2523
-                                $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');
2524
-                            }
2525
-
2526
-                        }
2527
-                    }
2528
-                }
2529
-
2530
-                $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2531
-
2532
-                $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2533
-                $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())));
2534
-                $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');
2535
-
2536
-                /*    Add the variation definition to output    */
2537
-                $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');
2538
-            }
2539
-
2540
-            $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');
2541
-            /*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2542
-            wp_reset_query();
2543
-        } else {
2544
-            $output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2545
-        }
2381
+		return $variation_id;
2382
+	}
2546 2383
 
2547
-        return $output;
2548
-    }
2384
+	/**
2385
+	 * Get variation list for a given product
2386
+	 *
2387
+	 * @param integer $head_product The product identifier to get the variation for
2388
+	 * @return object The variation list
2389
+	 */
2390
+	public static function get_variation($head_product, $type = 'any')
2391
+	{
2392
+		global $wpdb;
2393
+		$variations_output = null;
2394
+		$args = array(
2395
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2396
+			'post_parent' => $head_product,
2397
+			'orderby' => 'ID',
2398
+			'order' => 'ASC',
2399
+			'posts_per_page' => -1,
2400
+			'post_status' => $type,
2401
+		);
2402
+		$variations = get_posts($args);
2403
+
2404
+		if (!empty($variations)) {
2405
+			$head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2406
+
2407
+			foreach ($variations as $post_def) {
2408
+				$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'");
2409
+				foreach ($data as $content) {
2410
+					$attribute_value = 'attribute_value_' . $content->data_type;
2411
+					if (!empty($content->$attribute_value)) {
2412
+						if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2413
+							$variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2414
+						} else {
2415
+							$variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2416
+						}
2417
+					}
2418
+				}
2419
+				$variations_output[$post_def->ID]['post'] = $post_def;
2420
+			}
2421
+		}
2422
+		wp_reset_query();
2423
+		return $variations_output;
2424
+	}
2549 2425
 
2550
-    /**
2551
-     * Retrieve and display the variation for a given product
2552
-     * @param integer $product_id The product identifier to get variation for
2553
-     */
2554
-    public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2555
-    {
2556
-        global $wp_query;
2557
-        $output = '';
2558
-
2559
-        $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2560
-        $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2561
-        $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2562
-
2563
-        /**    Get attribute order for current product    */
2564
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2565
-        $output_order = array();
2566
-        if (count($product_attribute_order_detail) > 0) {
2567
-            if (!empty($product_attribute_order_detail)) {
2568
-                foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2569
-                    foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2570
-                        if (!empty($attribute_def->code)) {
2571
-                            $output_order[$attribute_def->code] = $position;
2572
-                        }
2573
-
2574
-                    }
2575
-                }
2576
-            }
2577
-        }
2426
+	/**
2427
+	 * Affichage des variations d'un produit dans l'administration
2428
+	 *
2429
+	 * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2430
+	 * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2431
+	 */
2432
+	public static function display_variation_admin($head_product)
2433
+	{
2434
+		$output = '';
2435
+		$productCurrency = wpshop_tools::wpshop_get_currency();
2436
+		/*    Récupération de la liste des variations pour le produit en cours d'édition    */
2437
+		$variations = self::get_variation($head_product);
2438
+		$price_piloting = get_option('wpshop_shop_price_piloting');
2439
+
2440
+		/*    Affichage de la liste des variations pour le produit en cours d'édition    */
2441
+		if (!empty($variations) && is_array($variations)) {
2442
+			$existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2443
+
2444
+			foreach ($variations as $variation) {
2445
+				$tpl_component = array();
2446
+
2447
+				$tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2448
+				$tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2449
+				$tpl_component['VARIATION_DETAIL'] = '  ';
2450
+				$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;
2451
+				$tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2452
+				if (!empty($price_piloting) && $price_piloting == 'HT') {
2453
+
2454
+				} else {
2578 2455
 
2579
-        $variations_params = array();
2580
-        $variation_attribute = array();
2581
-        $variation_attribute_ordered = array();
2582
-        $possible_values = array();
2583
-        $possible_values_for_selection_calculation = array();
2584
-
2585
-        /*    Vérification de l'existence de déclinaison pour le produit    */
2586
-        $wpshop_variation_list = self::get_variation($product_id);
2587
-        if (!empty($wpshop_variation_list)) {
2588
-            foreach ($wpshop_variation_list as $variation) {
2589
-                if (!empty($variation['variation_def'])) {
2590
-                    $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2591
-                    foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2592
-                        if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2593
-                            $tpl_component = array();
2594
-
2595
-                            $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2596
-                            $default_value_is_serial = false;
2597
-                            $attribute_list_first_element = $attribute_db_definition->default_value;
2598
-                            if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2599
-                                $default_value_is_serial = true;
2600
-                                $tmp_default_value = unserialize($attribute_db_definition->default_value);
2601
-                                $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2602
-                            }
2603
-
2604
-                            if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2605
-                                $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');
2606
-                            }
2607
-
2608
-                            if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2609
-                                $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2610
-                                $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2611
-                            } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2612
-                                $post_def = get_post($attribute_value);
2613
-                                $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2614
-                                $position = $post_def->menu_order;
2615
-                            }
2616
-
2617
-                            if (!empty($variation['variation_dif'])) {
2618
-                                foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2619
-                                    $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2620
-                                    $the_value = $attribute_dif_value;
2621
-                                    if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2622
-                                        $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2623
-                                    }
2624
-                                    $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2625
-                                }
2626
-                            }
2627
-                            if (!empty($attribute_value)) {
2628
-                                $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));
2629
-                                $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2630
-                            }
2631
-                            unset($tpl_component);
2632
-                        }
2633
-                    }
2634
-                }
2635
-            }
2636
-
2637
-            $variation_tpl = array();
2638
-            if (!empty($head_wpshop_variation_definition['attributes'])) {
2639
-                foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2640
-                    $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2641
-
2642
-                    if (!empty($attribute_db_definition)) {
2643
-                        $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');
2644
-
2645
-                        $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;
2646
-                        if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2647
-                            $is_required = true;
2648
-                        }
2649
-
2650
-                        $input_def = array();
2651
-                        $input_def['type'] = $attribute_db_definition->frontend_input;
2652
-                        $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);
2653
-                        if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2654
-                            unset($possible_values[$attribute_code][0]);
2655
-                            $value = array($value);
2656
-                        }
2657
-                        $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2658
-                        $input_def['name'] = $attribute_code;
2659
-                        $real_possible_values = array();
2660
-                        if (!empty($possible_values[$attribute_code])) {
2661
-                            ksort($possible_values[$attribute_code]);
2662
-                            foreach ($possible_values[$attribute_code] as $position => $def) {
2663
-                                foreach ($def as $attribute_value => $attribute_value_output) {
2664
-                                    $real_possible_values[$attribute_value] = $attribute_value_output;
2665
-                                    if (!empty($attribute_value)) {
2666
-                                        global $wpdb;
2667
-                                        $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);
2668
-                                        if ('draft' == $wpdb->get_var($query)) {
2669
-                                            unset($real_possible_values[$attribute_value]);
2670
-                                        }
2671
-                                    }
2672
-                                }
2673
-                            }
2674
-                        }
2675
-                        $input_def['possible_value'] = $real_possible_values;
2676
-                        $input_def['valueToPut'] = 'index';
2677
-                        $input_def['value'] = $value;
2678
-
2679
-                        $input_def['options']['more_input'] = '';
2680
-                        if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2681
-                            foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2682
-                                $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 . '" />';
2683
-                            }
2684
-                        }
2685
-
2686
-                        $input_def['options_label']['original'] = true;
2687
-                        $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) . '" ';
2688
-
2689
-                        if (!empty($real_possible_values)) {
2690
-                            $tpl_component = array();
2691
-                            $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'];
2692
-                            $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2693
-                            $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));
2694
-                            $tpl_component['VARIATION_CODE'] = $attribute_code;
2695
-                            $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2696
-                            $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2697
-                            $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2698
-                            $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2699
-                            $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2700
-                            $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;
2701
-                            $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2702
-                            $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2703
-                            $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2704
-                        }
2705
-
2706
-                        $variation_attribute[] = $attribute_code;
2707
-                    }
2708
-                }
2709
-            }
2456
+				}
2457
+				$post_obj = $variation['post'];
2458
+
2459
+				$parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2460
+				if (!empty($parent_product_infos)) {
2461
+					$parent_post = $parent_product_infos['parent_post'];
2462
+					$product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2463
+					if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2464
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2465
+							$product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2466
+						} else {
2467
+							$product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2468
+						}
2469
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2470
+					} else {
2471
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2472
+							$product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2473
+						} else {
2474
+							$product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2475
+						}
2476
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2477
+					}
2478
+					$product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2479
+					$tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2480
+				}
2710 2481
 
2711
-        }
2712
-        $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2713
-        wp_reset_query();
2714
-
2715
-        $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2716
-        if (!empty($attribute_defined_to_be_user_defined)) {
2717
-            foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2718
-                $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;
2719
-
2720
-                $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');
2721
-                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')) {
2722
-                    $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] : ''));
2723
-
2724
-                    $tpl_component = array();
2725
-                    $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) . '" ';
2726
-                    $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2727
-                    $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));
2728
-                    $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2729
-                    $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 . '" ' : '';
2730
-                    $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2731
-                    $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2732
-                    $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2733
-                    $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2734
-                    $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2735
-                    $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;
2736
-                    $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'];
2737
-                    $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)];
2738
-                }
2739
-            }
2740
-        }
2741
-        $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2742
-        if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2743
-            ksort($variation_attribute_ordered);
2744
-            foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2745
-                $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2746
-            }
2747
-        }
2748
-        $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2749
-        $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2750
-        if ($from_admin && !empty($order_id)) {
2751
-            $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2752
-            $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2753
-        }
2754
-        $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2482
+				if (!empty($variation['variation_def'])) {
2483
+					foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2484
+						if (!empty($variation_value)) {
2485
+							$attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2486
+							$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');
2487
+							$tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2488
+
2489
+							/** Define Link image to variation interface **/
2490
+							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'))) {
2491
+								$pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2492
+
2493
+								$media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2494
+								if (!empty($media_id_data)) {
2495
+									$medias_ids = explode(',', $media_id_data);
2496
+
2497
+									if (!empty($medias_ids)) {
2498
+										foreach ($medias_ids as $media_id) {
2499
+											if (!empty($media_id)) {
2500
+												$pictures[] = get_post($media_id);
2501
+											}
2502
+										}
2503
+									}
2504
+								}
2505
+
2506
+								$pictures_data = '';
2507
+								if (!empty($pictures)) {
2508
+									$selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2509
+
2510
+									$done_picture = array();
2511
+									foreach ($pictures as $picture) {
2512
+										if (!in_array($picture->ID, $done_picture)) {
2513
+											if (wp_attachment_is_image($picture->ID)) {
2514
+												$checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2515
+												$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');
2516
+
2517
+												$done_picture[] = $picture->ID;
2518
+											}
2519
+										}
2520
+									}
2521
+								}
2522
+
2523
+								$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');
2524
+							}
2525
+
2526
+						}
2527
+					}
2528
+				}
2755 2529
 
2756
-        return $output;
2757
-    }
2530
+				$tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2758 2531
 
2759
-    public static function get_parent_variation($variation_id)
2760
-    {
2761
-        $result = array();
2762
-        if (!empty($variation_id)) {
2763
-            $variation_post = get_post($variation_id);
2764
-            if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2765
-                $result['parent_post'] = get_post($variation_post->post_parent);
2766
-                $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2767
-            }
2768
-        }
2769
-        return $result;
2770
-    }
2532
+				$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2533
+				$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())));
2534
+				$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');
2771 2535
 
2772
-    /**
2773
-     * Display the current configuration for a given product
2774
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2775
-     */
2776
-    public function wpshop_product_variations_summary($shortcode_attribute)
2777
-    {
2778
-        $output = '';
2779
-
2780
-        $product_variations_selection_args = array(
2781
-            'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2782
-            'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2783
-        );
2784
-
2785
-        $current_user_id = get_current_user_id();
2786
-
2787
-        if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2788
-            foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2789
-                if (!empty($item) && !empty($item['item_id'])) {
2790
-
2791
-                    $free_variations = array();
2792
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2793
-                        foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2794
-                            $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2795
-                        }
2796
-                    }
2797
-
2798
-                    $variations = array();
2799
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2800
-                        foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2801
-
2802
-                            if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2803
-                                foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2804
-                                    $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2805
-                                }
2806
-                            }
2807
-                        }
2808
-                    }
2809
-                    $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2810
-
2811
-                    $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2812
-                }
2813
-            }
2814
-        }
2536
+				/*    Add the variation definition to output    */
2537
+				$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');
2538
+			}
2815 2539
 
2816
-        $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2540
+			$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');
2541
+			/*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2542
+			wp_reset_query();
2543
+		} else {
2544
+			$output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2545
+		}
2817 2546
 
2818
-        echo $output;
2819
-    }
2547
+		return $output;
2548
+	}
2549
+
2550
+	/**
2551
+	 * Retrieve and display the variation for a given product
2552
+	 * @param integer $product_id The product identifier to get variation for
2553
+	 */
2554
+	public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2555
+	{
2556
+		global $wp_query;
2557
+		$output = '';
2558
+
2559
+		$product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2560
+		$wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2561
+		$head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2562
+
2563
+		/**    Get attribute order for current product    */
2564
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2565
+		$output_order = array();
2566
+		if (count($product_attribute_order_detail) > 0) {
2567
+			if (!empty($product_attribute_order_detail)) {
2568
+				foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2569
+					foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2570
+						if (!empty($attribute_def->code)) {
2571
+							$output_order[$attribute_def->code] = $position;
2572
+						}
2573
+
2574
+					}
2575
+				}
2576
+			}
2577
+		}
2820 2578
 
2821
-    /**
2822
-     * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2823
-     *
2824
-     * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2825
-     * @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
2826
-     * @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
2827
-     * @param string $wpshop_current_for_display Inconnu / Unknown
2828
-     * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2829
-     *
2830
-     * @return array Le résultat du calcul pour l'affichage / Output result
2831
-     */
2832
-    public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2833
-    {
2834
-        global $wpdb;
2835
-
2836
-        $wpshop_cart = new wps_cart();
2837
-        $wpshop_products = new wpshop_products();
2838
-
2839
-        $response = '';
2840
-        $response_status = $has_variation = false;
2841
-        $tpl_component = array();
2842
-
2843
-        // Check if variations exists
2844
-        if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2845
-
2846
-            //Recover all selected variations
2847
-            $variations_selected = array();
2848
-            if (!empty($wpshop_variation_selected)) {
2849
-                foreach ($wpshop_variation_selected as $selected_variation) {
2850
-                    $variation_definition = explode('-_variation_val_-', $selected_variation);
2851
-                    $variations_selected[$variation_definition[0]] = $variation_definition[1];
2852
-                }
2853
-            }
2854
-
2855
-            // Check variations priority
2856
-            $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2857
-
2858
-            // Check if $product_with_variation have variations
2859
-            if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2860
-
2861
-                $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2862
-                $product_to_add_to_cart = $formatted_product[0];
2863
-                foreach ($formatted_product[0] as $pid => $product_more_content) {
2864
-                    $order_items[$pid]['product_id'] = $product_more_content['id'];
2865
-
2866
-                    /** For product with variation    */
2867
-                    $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2868
-                    $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2869
-                    $order_items[$pid]['product_variation'] = '';
2870
-                    if (!empty($product_more_content['variations'])) {
2871
-                        foreach ($product_more_content['variations'] as $variation_id) {
2872
-                            $order_items[$pid]['product_variation'][] = $variation_id;
2873
-                        }
2874
-                    }
2875
-                }
2876
-
2877
-                // If Product list is not empty, add products to order
2878
-                if (!empty($order_items)) {
2879
-                    foreach ($order_items as $product_id => $d) {
2880
-                        $product_key = $product_id;
2881
-
2882
-                        // Formate datas
2883
-                        $product_id = $head_product_id = $d['product_id'];
2884
-                        $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2885
-
2886
-                        // If product is a single variation product
2887
-                        if (!empty($product_variation) && (count($product_variation) == 1)) {
2888
-                            $product_id = $product_variation[0];
2889
-                        }
2890
-
2891
-                        // Construct final product
2892
-                        $product = wpshop_products::get_product_data($d['product_id'], true);
2893
-                        $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2579
+		$variations_params = array();
2580
+		$variation_attribute = array();
2581
+		$variation_attribute_ordered = array();
2582
+		$possible_values = array();
2583
+		$possible_values_for_selection_calculation = array();
2584
+
2585
+		/*    Vérification de l'existence de déclinaison pour le produit    */
2586
+		$wpshop_variation_list = self::get_variation($product_id);
2587
+		if (!empty($wpshop_variation_list)) {
2588
+			foreach ($wpshop_variation_list as $variation) {
2589
+				if (!empty($variation['variation_def'])) {
2590
+					$display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2591
+					foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2592
+						if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2593
+							$tpl_component = array();
2594
+
2595
+							$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2596
+							$default_value_is_serial = false;
2597
+							$attribute_list_first_element = $attribute_db_definition->default_value;
2598
+							if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2599
+								$default_value_is_serial = true;
2600
+								$tmp_default_value = unserialize($attribute_db_definition->default_value);
2601
+								$attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2602
+							}
2603
+
2604
+							if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2605
+								$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');
2606
+							}
2607
+
2608
+							if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2609
+								$tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2610
+								$position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2611
+							} else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2612
+								$post_def = get_post($attribute_value);
2613
+								$tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2614
+								$position = $post_def->menu_order;
2615
+							}
2616
+
2617
+							if (!empty($variation['variation_dif'])) {
2618
+								foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2619
+									$wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2620
+									$the_value = $attribute_dif_value;
2621
+									if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2622
+										$the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2623
+									}
2624
+									$tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2625
+								}
2626
+							}
2627
+							if (!empty($attribute_value)) {
2628
+								$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));
2629
+								$possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2630
+							}
2631
+							unset($tpl_component);
2632
+						}
2633
+					}
2634
+				}
2635
+			}
2636
+
2637
+			$variation_tpl = array();
2638
+			if (!empty($head_wpshop_variation_definition['attributes'])) {
2639
+				foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2640
+					$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2641
+
2642
+					if (!empty($attribute_db_definition)) {
2643
+						$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');
2644
+
2645
+						$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;
2646
+						if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2647
+							$is_required = true;
2648
+						}
2649
+
2650
+						$input_def = array();
2651
+						$input_def['type'] = $attribute_db_definition->frontend_input;
2652
+						$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);
2653
+						if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2654
+							unset($possible_values[$attribute_code][0]);
2655
+							$value = array($value);
2656
+						}
2657
+						$input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2658
+						$input_def['name'] = $attribute_code;
2659
+						$real_possible_values = array();
2660
+						if (!empty($possible_values[$attribute_code])) {
2661
+							ksort($possible_values[$attribute_code]);
2662
+							foreach ($possible_values[$attribute_code] as $position => $def) {
2663
+								foreach ($def as $attribute_value => $attribute_value_output) {
2664
+									$real_possible_values[$attribute_value] = $attribute_value_output;
2665
+									if (!empty($attribute_value)) {
2666
+										global $wpdb;
2667
+										$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);
2668
+										if ('draft' == $wpdb->get_var($query)) {
2669
+											unset($real_possible_values[$attribute_value]);
2670
+										}
2671
+									}
2672
+								}
2673
+							}
2674
+						}
2675
+						$input_def['possible_value'] = $real_possible_values;
2676
+						$input_def['valueToPut'] = 'index';
2677
+						$input_def['value'] = $value;
2678
+
2679
+						$input_def['options']['more_input'] = '';
2680
+						if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2681
+							foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2682
+								$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 . '" />';
2683
+							}
2684
+						}
2685
+
2686
+						$input_def['options_label']['original'] = true;
2687
+						$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) . '" ';
2688
+
2689
+						if (!empty($real_possible_values)) {
2690
+							$tpl_component = array();
2691
+							$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'];
2692
+							$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2693
+							$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));
2694
+							$tpl_component['VARIATION_CODE'] = $attribute_code;
2695
+							$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2696
+							$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2697
+							$tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2698
+							$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2699
+							$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2700
+							$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;
2701
+							$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2702
+							$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2703
+							$variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2704
+						}
2705
+
2706
+						$variation_attribute[] = $attribute_code;
2707
+					}
2708
+				}
2709
+			}
2710
+
2711
+		}
2712
+		$variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2713
+		wp_reset_query();
2714
+
2715
+		$attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2716
+		if (!empty($attribute_defined_to_be_user_defined)) {
2717
+			foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2718
+				$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;
2719
+
2720
+				$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');
2721
+				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')) {
2722
+					$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] : ''));
2723
+
2724
+					$tpl_component = array();
2725
+					$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) . '" ';
2726
+					$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2727
+					$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));
2728
+					$tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2729
+					$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 . '" ' : '';
2730
+					$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2731
+					$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2732
+					$tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2733
+					$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2734
+					$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2735
+					$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;
2736
+					$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'];
2737
+					$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)];
2738
+				}
2739
+			}
2740
+		}
2741
+		$variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2742
+		if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2743
+			ksort($variation_attribute_ordered);
2744
+			foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2745
+				$variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2746
+			}
2747
+		}
2748
+		$variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2749
+		$variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2750
+		if ($from_admin && !empty($order_id)) {
2751
+			$variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2752
+			$variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2753
+		}
2754
+		$output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2755
+
2756
+		return $output;
2757
+	}
2758
+
2759
+	public static function get_parent_variation($variation_id)
2760
+	{
2761
+		$result = array();
2762
+		if (!empty($variation_id)) {
2763
+			$variation_post = get_post($variation_id);
2764
+			if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2765
+				$result['parent_post'] = get_post($variation_post->post_parent);
2766
+				$result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2767
+			}
2768
+		}
2769
+		return $result;
2770
+	}
2771
+
2772
+	/**
2773
+	 * Display the current configuration for a given product
2774
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2775
+	 */
2776
+	public function wpshop_product_variations_summary($shortcode_attribute)
2777
+	{
2778
+		$output = '';
2779
+
2780
+		$product_variations_selection_args = array(
2781
+			'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2782
+			'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2783
+		);
2784
+
2785
+		$current_user_id = get_current_user_id();
2786
+
2787
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2788
+			foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2789
+				if (!empty($item) && !empty($item['item_id'])) {
2790
+
2791
+					$free_variations = array();
2792
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2793
+						foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2794
+							$free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2795
+						}
2796
+					}
2797
+
2798
+					$variations = array();
2799
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2800
+						foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2801
+
2802
+							if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2803
+								foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2804
+									$variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2805
+								}
2806
+							}
2807
+						}
2808
+					}
2809
+					$product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2810
+
2811
+					$product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2812
+				}
2813
+			}
2814
+		}
2815
+
2816
+		$output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2817
+
2818
+		echo $output;
2819
+	}
2820
+
2821
+	/**
2822
+	 * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2823
+	 *
2824
+	 * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2825
+	 * @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
2826
+	 * @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
2827
+	 * @param string $wpshop_current_for_display Inconnu / Unknown
2828
+	 * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2829
+	 *
2830
+	 * @return array Le résultat du calcul pour l'affichage / Output result
2831
+	 */
2832
+	public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2833
+	{
2834
+		global $wpdb;
2835
+
2836
+		$wpshop_cart = new wps_cart();
2837
+		$wpshop_products = new wpshop_products();
2838
+
2839
+		$response = '';
2840
+		$response_status = $has_variation = false;
2841
+		$tpl_component = array();
2842
+
2843
+		// Check if variations exists
2844
+		if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2845
+
2846
+			//Recover all selected variations
2847
+			$variations_selected = array();
2848
+			if (!empty($wpshop_variation_selected)) {
2849
+				foreach ($wpshop_variation_selected as $selected_variation) {
2850
+					$variation_definition = explode('-_variation_val_-', $selected_variation);
2851
+					$variations_selected[$variation_definition[0]] = $variation_definition[1];
2852
+				}
2853
+			}
2854
+
2855
+			// Check variations priority
2856
+			$product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2857
+
2858
+			// Check if $product_with_variation have variations
2859
+			if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2860
+
2861
+				$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2862
+				$product_to_add_to_cart = $formatted_product[0];
2863
+				foreach ($formatted_product[0] as $pid => $product_more_content) {
2864
+					$order_items[$pid]['product_id'] = $product_more_content['id'];
2865
+
2866
+					/** For product with variation    */
2867
+					$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2868
+					$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2869
+					$order_items[$pid]['product_variation'] = '';
2870
+					if (!empty($product_more_content['variations'])) {
2871
+						foreach ($product_more_content['variations'] as $variation_id) {
2872
+							$order_items[$pid]['product_variation'][] = $variation_id;
2873
+						}
2874
+					}
2875
+				}
2876
+
2877
+				// If Product list is not empty, add products to order
2878
+				if (!empty($order_items)) {
2879
+					foreach ($order_items as $product_id => $d) {
2880
+						$product_key = $product_id;
2881
+
2882
+						// Formate datas
2883
+						$product_id = $head_product_id = $d['product_id'];
2884
+						$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2885
+
2886
+						// If product is a single variation product
2887
+						if (!empty($product_variation) && (count($product_variation) == 1)) {
2888
+							$product_id = $product_variation[0];
2889
+						}
2890
+
2891
+						// Construct final product
2892
+						$product = wpshop_products::get_product_data($d['product_id'], true);
2893
+						$the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2894 2894
 						$the_product['text_from'] = $product_with_variation['text_from'];
2895 2895
 
2896
-                        //    Add variation to product into cart for storage
2897
-                        if (!empty($product_variation)) {
2898
-                            $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2899
-                        }
2900
-
2901
-                        // Free Variations Checking
2902
-                        if (!empty($d['free_variation'])) {
2903
-                            $the_product['item_meta']['free_variation'] = $d['free_variation'];
2904
-                            $head_product_id = $the_product['product_id'];
2905
-                        }
2906
-
2907
-                        // If product is a variation, we check parent product general
2908
-                        if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2909
-                            $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2910
-                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2911
-                                $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2912
-                                $parent_meta = $parent_def['parent_post_meta'];
2913
-                                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) {
2914
-                                    $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2915
-                                    $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2916
-                                    $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2917
-                                }
2918
-                            }
2919
-                        }
2920
-                    }
2921
-                }
2922
-
2923
-                if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2924
-                    $price_infos = wpshop_prices::check_product_price($the_product, true);
2925
-                    if (!empty($price_infos['discount']['discount_exist'])) {
2926
-                        $the_product['price_ttc_before_discount'] = $the_product['product_price'];
2927
-                        $the_product['price_ht_before_discount'] = $the_product['price_ht'];
2928
-                    }
2929
-                    $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'];
2930
-                    $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'];
2931
-                    $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'];
2932
-                }
2933
-
2934
-                $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2935
-                // Add free variations to product
2936
-                if (!empty($wpshop_free_variation)) {
2937
-                    $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2938
-                }
2939
-                // Change picture if have a selected variation
2940
-                $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;
2941
-                $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2942
-
2943
-                // Price Display
2944
-                $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2945
-                $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2946
-                $productPrice = '';
2947
-                if ($price_display) {
2948
-                    $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2949
-                }
2950
-
2951
-                //Get Summary cart
2952
-                $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2953
-                $response_status = true;
2954
-            } else {
2955
-                //Product without variations
2956
-                $product_data = wpshop_products::get_product_data($product_id);
2957
-                $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2896
+						//    Add variation to product into cart for storage
2897
+						if (!empty($product_variation)) {
2898
+							$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2899
+						}
2900
+
2901
+						// Free Variations Checking
2902
+						if (!empty($d['free_variation'])) {
2903
+							$the_product['item_meta']['free_variation'] = $d['free_variation'];
2904
+							$head_product_id = $the_product['product_id'];
2905
+						}
2906
+
2907
+						// If product is a variation, we check parent product general
2908
+						if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2909
+							$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2910
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2911
+								$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2912
+								$parent_meta = $parent_def['parent_post_meta'];
2913
+								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) {
2914
+									$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2915
+									$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2916
+									$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2917
+								}
2918
+							}
2919
+						}
2920
+					}
2921
+				}
2922
+
2923
+				if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2924
+					$price_infos = wpshop_prices::check_product_price($the_product, true);
2925
+					if (!empty($price_infos['discount']['discount_exist'])) {
2926
+						$the_product['price_ttc_before_discount'] = $the_product['product_price'];
2927
+						$the_product['price_ht_before_discount'] = $the_product['price_ht'];
2928
+					}
2929
+					$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'];
2930
+					$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'];
2931
+					$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'];
2932
+				}
2933
+
2934
+				$product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2935
+				// Add free variations to product
2936
+				if (!empty($wpshop_free_variation)) {
2937
+					$the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2938
+				}
2939
+				// Change picture if have a selected variation
2940
+				$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;
2941
+				$response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2942
+
2943
+				// Price Display
2944
+				$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2945
+				$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2946
+				$productPrice = '';
2947
+				if ($price_display) {
2948
+					$response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2949
+				}
2950
+
2951
+				//Get Summary cart
2952
+				$response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2958 2953
 				$response_status = true;
2959
-            }
2960
-        }
2954
+			} else {
2955
+				//Product without variations
2956
+				$product_data = wpshop_products::get_product_data($product_id);
2957
+				$response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2958
+				$response_status = true;
2959
+			}
2960
+		}
2961 2961
 
2962
-        return array($response_status, $response);
2963
-    }
2962
+		return array($response_status, $response);
2963
+	}
2964 2964
 
2965
-    /**
2966
-     * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2967
-     *
2968
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2969
-     */
2970
-    public function wpshop_product_variation_value_detail($shortcode_attribute)
2971
-    {
2972
-        echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2973
-    }
2965
+	/**
2966
+	 * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2967
+	 *
2968
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2969
+	 */
2970
+	public function wpshop_product_variation_value_detail($shortcode_attribute)
2971
+	{
2972
+		echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2973
+	}
2974 2974
 
2975
-    /**
2976
-     * Build the product structure with variation for product choosed by the user into frontend sheet
2977
-     *
2978
-     * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2979
-     * @param integer $product_id The basic product choose by the user in frontend
2980
-     *
2981
-     * @return array The product list for adding to the cart build by variation priority
2982
-     */
2983
-    public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2984
-    {
2985
-        global $wpdb;
2986
-        $all_required_variations_selected = $no_selected_variation = true;
2987
-        $single_variations = $combined_variations = $product_to_add_to_cart = array();
2988
-
2989
-        // Check if all required variations are selected
2990
-        $required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2991
-        foreach ($selected_variation as $k => $value) {
2992
-            if ($value == 0 && in_array($k, $required_attributes_list)) {
2993
-                $all_required_variations_selected = false;
2994
-            }
2995
-            if ($value != 0) {
2996
-                $no_selected_variation = false;
2997
-            }
2998
-        }
2999
-        if (!empty($selected_variation)) {
3000
-            //Check variations configuration
3001
-            $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3002
-            // Check variations type
3003
-            $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3004
-            $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3005
-
3006
-            //Check defined variation priority
3007
-            $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3008
-            $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3009
-
3010
-            // Recover all product variations
3011
-            $query_variation = $selected_variation;
3012
-            // Delete free variations
3013
-            unset($query_variation['free']);
3014
-
3015
-            if ($product_variation_type == 'single') {
3016
-                // Get single variations
3017
-                $single_variations = array();
3018
-                foreach ($selected_variation as $attribute_code => $attribute_value) {
3019
-                    if (isset($attribute_value) && $attribute_code != 'free') {
3020
-                        $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);
3021
-                        $single_variation_id = $wpdb->get_var($query);
3022
-                        if (!empty($single_variation_id)) {
3023
-                            $single_variations[] = $single_variation_id;
3024
-                            unset($query_variation[$attribute_code]);
3025
-                        }
3026
-                    }
3027
-                }
3028
-            } else {
3029
-                // Get combined variations
3030
-                $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);
3031
-                $combined_variation_id = $wpdb->get_var($query);
3032
-                if (!empty($combined_variation_id)) {
3033
-                    $combined_variations[] = $combined_variation_id;
3034
-                }
3035
-
3036
-            }
3037
-
3038
-            //If all required variations are not selected
3039
-            if (!$all_required_variations_selected || $no_selected_variation) {
3040
-                $product_to_add_to_cart['text_from'] = 'on';
3041
-                // If we choose to display lower price variation combinaison
3042
-                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']))) {
3043
-                    //Get lower price variation combinaison
3044
-                    $lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3045
-                    if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3046
-                        foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3047
-                            $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3048
-                        }
3049
-                    }
3050
-                    $product_to_add_to_cart['display_lower_price'] = true;
3051
-                } else {
3052
-                    $product_to_add_to_cart[$product_id]['variations'] = array();
3053
-                }
3054
-            } else {
3055
-                $product_to_add_to_cart['text_from'] = '';
3056
-                $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3057
-            }
3058
-        }
2975
+	/**
2976
+	 * Build the product structure with variation for product choosed by the user into frontend sheet
2977
+	 *
2978
+	 * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2979
+	 * @param integer $product_id The basic product choose by the user in frontend
2980
+	 *
2981
+	 * @return array The product list for adding to the cart build by variation priority
2982
+	 */
2983
+	public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2984
+	{
2985
+		global $wpdb;
2986
+		$all_required_variations_selected = $no_selected_variation = true;
2987
+		$single_variations = $combined_variations = $product_to_add_to_cart = array();
2988
+
2989
+		// Check if all required variations are selected
2990
+		$required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2991
+		foreach ($selected_variation as $k => $value) {
2992
+			if ($value == 0 && in_array($k, $required_attributes_list)) {
2993
+				$all_required_variations_selected = false;
2994
+			}
2995
+			if ($value != 0) {
2996
+				$no_selected_variation = false;
2997
+			}
2998
+		}
2999
+		if (!empty($selected_variation)) {
3000
+			//Check variations configuration
3001
+			$product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3002
+			// Check variations type
3003
+			$product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3004
+			$product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3005
+
3006
+			//Check defined variation priority
3007
+			$priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3008
+			$product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3009
+
3010
+			// Recover all product variations
3011
+			$query_variation = $selected_variation;
3012
+			// Delete free variations
3013
+			unset($query_variation['free']);
3014
+
3015
+			if ($product_variation_type == 'single') {
3016
+				// Get single variations
3017
+				$single_variations = array();
3018
+				foreach ($selected_variation as $attribute_code => $attribute_value) {
3019
+					if (isset($attribute_value) && $attribute_code != 'free') {
3020
+						$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);
3021
+						$single_variation_id = $wpdb->get_var($query);
3022
+						if (!empty($single_variation_id)) {
3023
+							$single_variations[] = $single_variation_id;
3024
+							unset($query_variation[$attribute_code]);
3025
+						}
3026
+					}
3027
+				}
3028
+			} else {
3029
+				// Get combined variations
3030
+				$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);
3031
+				$combined_variation_id = $wpdb->get_var($query);
3032
+				if (!empty($combined_variation_id)) {
3033
+					$combined_variations[] = $combined_variation_id;
3034
+				}
3059 3035
 
3060
-        return $product_to_add_to_cart;
3061
-    }
3036
+			}
3062 3037
 
3063
-    public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3064
-    {
3065
-        global $wpdb;
3066
-
3067
-        if (!empty($product_variations)) {
3068
-            // Initialize variations total price datas
3069
-            $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3070
-            $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3071
-            $vat_rate = 0;
3072
-            $discount_amount = $discount_rate = $special_price = 0;
3073
-            // Recover Head product metadata
3074
-            $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3075
-            $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3076
-            if (!empty($tva_rate_id)) {
3077
-                // Recover VAT Rate of product
3078
-                $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3079
-                $vat_rate = $wpdb->get_var($query);
3080
-            }
3081
-            $price_piloting = get_option('wpshop_shop_price_piloting');
3082
-            foreach ($product_variations as $product_variation) {
3083
-                $variation_metadata['product_price'] = 0;
3084
-                $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3085
-                if (!empty($variation_metadata)) {
3086
-                    $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']);
3087
-                    $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))));
3088
-
3089
-                    $variations_total_price['price_et'] += $p_et;
3090
-                    $variations_total_price['price_ati'] += $p_ati;
3091
-                    $variations_total_price['vat_amount'] += $p_ati - $p_et;
3092
-
3093
-                    $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3094
-
3095
-                    // Check discount
3096
-                    $discount_config = wpshop_prices::check_discount_for_product($product_variation);
3097
-                    if (!empty($discount_config) && !empty($discount_config['value'])) {
3098
-                        $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3099
-                        $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3100
-                        $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3101
-                        $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3102
-
3103
-                        if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3104
-                            $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3105
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3106
-                            $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3107
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3108
-                            $product_into_cart['special_price'] = $special_price + $discount_config['value'];
3109
-                        }
3110
-                    }
3111
-
3112
-                    $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3113
-                    $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3114
-                }
3115
-            }
3116
-
3117
-            // Check if add or replace variation price to head product
3118
-            /**
3119
-             * Since 1.4.3.7
3120
-             * L'option du produit remplace le prix du produit de tête.
3121
-             */
3038
+			//If all required variations are not selected
3039
+			if (!$all_required_variations_selected || $no_selected_variation) {
3040
+				$product_to_add_to_cart['text_from'] = 'on';
3041
+				// If we choose to display lower price variation combinaison
3042
+				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']))) {
3043
+					//Get lower price variation combinaison
3044
+					$lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3045
+					if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3046
+						foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3047
+							$product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3048
+						}
3049
+					}
3050
+					$product_to_add_to_cart['display_lower_price'] = true;
3051
+				} else {
3052
+					$product_to_add_to_cart[$product_id]['variations'] = array();
3053
+				}
3054
+			} else {
3055
+				$product_to_add_to_cart['text_from'] = '';
3056
+				$product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3057
+			}
3058
+		}
3059
+
3060
+		return $product_to_add_to_cart;
3061
+	}
3062
+
3063
+	public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3064
+	{
3065
+		global $wpdb;
3066
+
3067
+		if (!empty($product_variations)) {
3068
+			// Initialize variations total price datas
3069
+			$variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3070
+			$variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3071
+			$vat_rate = 0;
3072
+			$discount_amount = $discount_rate = $special_price = 0;
3073
+			// Recover Head product metadata
3074
+			$head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3075
+			$tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3076
+			if (!empty($tva_rate_id)) {
3077
+				// Recover VAT Rate of product
3078
+				$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3079
+				$vat_rate = $wpdb->get_var($query);
3080
+			}
3081
+			$price_piloting = get_option('wpshop_shop_price_piloting');
3082
+			foreach ($product_variations as $product_variation) {
3083
+				$variation_metadata['product_price'] = 0;
3084
+				$variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3085
+				if (!empty($variation_metadata)) {
3086
+					$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']);
3087
+					$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))));
3088
+
3089
+					$variations_total_price['price_et'] += $p_et;
3090
+					$variations_total_price['price_ati'] += $p_ati;
3091
+					$variations_total_price['vat_amount'] += $p_ati - $p_et;
3092
+
3093
+					$variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3094
+
3095
+					// Check discount
3096
+					$discount_config = wpshop_prices::check_discount_for_product($product_variation);
3097
+					if (!empty($discount_config) && !empty($discount_config['value'])) {
3098
+						$variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3099
+						$variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3100
+						$variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3101
+						$variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3102
+
3103
+						if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3104
+							$product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3105
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3106
+							$product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3107
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3108
+							$product_into_cart['special_price'] = $special_price + $discount_config['value'];
3109
+						}
3110
+					}
3111
+
3112
+					$product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3113
+					$product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3114
+				}
3115
+			}
3116
+
3117
+			// Check if add or replace variation price to head product
3118
+			/**
3119
+			 * Since 1.4.3.7
3120
+			 * L'option du produit remplace le prix du produit de tête.
3121
+			 */
3122 3122
 			if( true ) {
3123
-                //Replace the product price
3124
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3125
-                    $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3126
-                    $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3127
-
3128
-                    $product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3129
-                    $product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3130
-                    $product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3131
-                } else {
3132
-                    $product_into_cart['product_price'] = $variations_total_price['price_ati'];
3133
-                    $product_into_cart['price_ht'] = $variations_total_price['price_et'];
3134
-                    $product_into_cart['tva'] = $variations_total_price['vat_amount'];
3135
-                }
3136
-            } else {
3137
-                // Add variations price to product price
3138
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3139
-                    $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3140
-                    $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3141
-
3142
-                    $product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3143
-                    $product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3144
-                    $product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3145
-                } else {
3146
-                    $product_into_cart['product_price'] += $variations_total_price['price_ati'];
3147
-                    $product_into_cart['price_ht'] += $variations_total_price['price_et'];
3148
-                    $product_into_cart['tva'] += $variations_total_price['vat_amount'];
3149
-                }
3150
-                // Check parent discount
3151
-                $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3152
-                if (!empty($parent_discount_config)) {
3153
-                    $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'];
3154
-                    $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'];
3155
-                    $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3156
-
3157
-                    if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3158
-                        $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3159
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3160
-                        $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3161
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3162
-                        $product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3163
-                    }
3164
-                }
3165
-            }
3166
-        } else {
3167
-            // If product have just Free variations
3168
-            $discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3169
-            if (!empty($discount_config)) {
3170
-                $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'];
3171
-                $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'];
3172
-                $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3173
-            }
3174
-        }
3123
+				//Replace the product price
3124
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3125
+					$product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3126
+					$product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3127
+
3128
+					$product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3129
+					$product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3130
+					$product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3131
+				} else {
3132
+					$product_into_cart['product_price'] = $variations_total_price['price_ati'];
3133
+					$product_into_cart['price_ht'] = $variations_total_price['price_et'];
3134
+					$product_into_cart['tva'] = $variations_total_price['vat_amount'];
3135
+				}
3136
+			} else {
3137
+				// Add variations price to product price
3138
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3139
+					$product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3140
+					$product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3141
+
3142
+					$product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3143
+					$product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3144
+					$product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3145
+				} else {
3146
+					$product_into_cart['product_price'] += $variations_total_price['price_ati'];
3147
+					$product_into_cart['price_ht'] += $variations_total_price['price_et'];
3148
+					$product_into_cart['tva'] += $variations_total_price['vat_amount'];
3149
+				}
3150
+				// Check parent discount
3151
+				$parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3152
+				if (!empty($parent_discount_config)) {
3153
+					$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'];
3154
+					$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'];
3155
+					$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3156
+
3157
+					if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3158
+						$product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3159
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3160
+						$product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3161
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3162
+						$product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3163
+					}
3164
+				}
3165
+			}
3166
+		} else {
3167
+			// If product have just Free variations
3168
+			$discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3169
+			if (!empty($discount_config)) {
3170
+				$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'];
3171
+				$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'];
3172
+				$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3173
+			}
3174
+		}
3175 3175
 
3176
-        // Text From indicator
3177
-        if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3178
-            $product_into_cart['text_from'] = $variations_options['text_from'];
3179
-        }
3180
-        return $product_into_cart;
3181
-    }
3176
+		// Text From indicator
3177
+		if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3178
+			$product_into_cart['text_from'] = $variations_options['text_from'];
3179
+		}
3180
+		return $product_into_cart;
3181
+	}
3182 3182
 
3183
-    /**
3184
-     * Read an array with product options chosen by the customer, order into an array regarding admin definition
3185
-     *
3186
-     * @param array $product_definition_value The array with the selected product option to ordered
3187
-     * @param array $output_order The good order for attribute defined by administrator
3188
-     * @param dtring $from_page A string allowing to take a specific template regarding the current page
3189
-     *
3190
-     * @return array The array containing all product options ordered as the admin configure it
3191
-     */
3192
-    public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3193
-    {
3194
-        $variation_attribute_ordered = array();
3195
-        $variation_attribute_ordered['prices'] = array();
3196
-        $variation_attribute_ordered['attribute_list'] = array();
3197
-
3198
-        if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3199
-            foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3200
-                $variation_tpl_component = array();
3201
-                foreach ($variation_attribute_detail as $info_name => $info_value) {
3202
-                    $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);
3203
-                }
3204
-                $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3205
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3206
-                if (!empty($output_order[$variation_attribute_code])) {
3207
-                    $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);
3208
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3209
-                        $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3210
-                    }
3211
-                } else {
3212
-                    $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);
3213
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3214
-                        $variation_attribute_ordered['attribute_list'][] = $display_data;
3215
-                    }
3216
-                }
3217
-                unset($variation_tpl_component);
3218
-            }
3219
-        }
3183
+	/**
3184
+	 * Read an array with product options chosen by the customer, order into an array regarding admin definition
3185
+	 *
3186
+	 * @param array $product_definition_value The array with the selected product option to ordered
3187
+	 * @param array $output_order The good order for attribute defined by administrator
3188
+	 * @param dtring $from_page A string allowing to take a specific template regarding the current page
3189
+	 *
3190
+	 * @return array The array containing all product options ordered as the admin configure it
3191
+	 */
3192
+	public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3193
+	{
3194
+		$variation_attribute_ordered = array();
3195
+		$variation_attribute_ordered['prices'] = array();
3196
+		$variation_attribute_ordered['attribute_list'] = array();
3197
+
3198
+		if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3199
+			foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3200
+				$variation_tpl_component = array();
3201
+				foreach ($variation_attribute_detail as $info_name => $info_value) {
3202
+					$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);
3203
+				}
3204
+				$variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3205
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3206
+				if (!empty($output_order[$variation_attribute_code])) {
3207
+					$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);
3208
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3209
+						$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3210
+					}
3211
+				} else {
3212
+					$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);
3213
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3214
+						$variation_attribute_ordered['attribute_list'][] = $display_data;
3215
+					}
3216
+				}
3217
+				unset($variation_tpl_component);
3218
+			}
3219
+		}
3220 3220
 
3221
-        if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3222
-            foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3223
-                $variation_tpl_component = array();
3224
-                foreach ($variation_details as $info_name => $info_value) {
3225
-                    if ($info_name != 'item_meta') {
3226
-                        $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);
3227
-                    }
3228
-                }
3229
-                foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3230
-                    $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3231
-                    $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3232
-                    $variation_tpl_component['VARIATION_ID'] = $variation_id;
3233
-                    $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3234
-
3235
-                    $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3236
-                }
3237
-                if (!empty($output_order[$variation_attribute_code])) {
3238
-                    $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);
3239
-                }
3240
-                unset($variation_tpl_component);
3241
-            }
3242
-        }
3221
+		if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3222
+			foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3223
+				$variation_tpl_component = array();
3224
+				foreach ($variation_details as $info_name => $info_value) {
3225
+					if ($info_name != 'item_meta') {
3226
+						$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);
3227
+					}
3228
+				}
3229
+				foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3230
+					$variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3231
+					$variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3232
+					$variation_tpl_component['VARIATION_ID'] = $variation_id;
3233
+					$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3243 3234
 
3244
-        /**    Free Variation part    */
3245
-        if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3246
-            foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3247
-                if (strpos($build_variation, '-_variation_val_-')) {
3248
-                    $variation_definition = explode('-_variation_val_-', $build_variation);
3249
-                    $attribute_code = $variation_definition[0];
3250
-                    $attribute_selected_value = $variation_definition[1];
3251
-                } else {
3252
-                    $attribute_code = $build_variation_key;
3253
-                    $attribute_selected_value = $build_variation;
3254
-                }
3255
-
3256
-                $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3257
-                $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3258
-                $value_to_outut = $attribute_selected_value;
3259
-                switch ($free_variation_attribute_def->data_type) {
3260
-                    case 'datetime':
3261
-                        $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3262
-                        break;
3263
-                }
3264
-
3265
-                if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3266
-                    switch ($free_variation_attribute_def->data_type_to_use) {
3267
-                        case 'custom':
3268
-                        case 'internal':
3269
-                            $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3270
-                            $value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3271
-                            break;
3272
-                    }
3273
-                }
3274
-                $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3275
-                $variation_tpl_component['VARIATION_ID'] = $attribute_code;
3276
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3277
-                if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3278
-                    $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);
3279
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3280
-                        $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3281
-                    }
3282
-                }
3283
-                unset($variation_tpl_component);
3284
-            }
3285
-        }
3286
-        return $variation_attribute_ordered;
3287
-    }
3235
+					$variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3236
+				}
3237
+				if (!empty($output_order[$variation_attribute_code])) {
3238
+					$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);
3239
+				}
3240
+				unset($variation_tpl_component);
3241
+			}
3242
+		}
3288 3243
 
3289
-    public function wps_selected_variation_picture($head_product_id, $variations)
3290
-    {
3291
-        $response = array();
3292
-        /** Selected Product image **/
3293
-        $post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3294
-        if (!empty($post_thumbnail_id)) {
3295
-            $response['img_id'] = $post_thumbnail_id;
3296
-            $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3297
-            $response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3298
-        }
3244
+		/**    Free Variation part    */
3245
+		if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3246
+			foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3247
+				if (strpos($build_variation, '-_variation_val_-')) {
3248
+					$variation_definition = explode('-_variation_val_-', $build_variation);
3249
+					$attribute_code = $variation_definition[0];
3250
+					$attribute_selected_value = $variation_definition[1];
3251
+				} else {
3252
+					$attribute_code = $build_variation_key;
3253
+					$attribute_selected_value = $build_variation;
3254
+				}
3299 3255
 
3300
-        /** check if have one variation **/
3301
-        if (!empty($variations) && count($variations) == 1) {
3302
-            $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3303
-            if (!empty($variation_attached_image_id)) {
3304
-                $response['img_id'] = $variation_attached_image_id;
3305
-                $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3306
-                $response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3307
-            }
3308
-        }
3309
-        return $response;
3310
-    }
3256
+				$free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3257
+				$variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3258
+				$value_to_outut = $attribute_selected_value;
3259
+				switch ($free_variation_attribute_def->data_type) {
3260
+					case 'datetime':
3261
+						$value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3262
+						break;
3263
+				}
3311 3264
 
3312
-    /** Add a meta box of product sales history in product administration panel **/
3313
-    public function meta_box_product_sale_informations()
3314
-    {
3315
-        global $post;
3316
-        $product_id = $post->ID;
3317
-
3318
-        $variations = self::get_variation($product_id);
3319
-
3320
-        $sales_informations = array();
3321
-        /** Query **/
3322
-        $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3323
-        $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')));
3324
-        $orders = new WP_Query($query_args);
3325
-        if (!empty($orders) && !empty($orders->posts)) {
3326
-            foreach ($orders->posts as $order) {
3327
-                $order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3328
-                $order_info = get_post_meta($order->ID, '_order_info', true);
3329
-                $sales_informations[] = array(
3330
-                    'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3331
-                    'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3332
-                    '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'] : '',
3333
-                    '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'] : '',
3334
-                    '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'] : '',
3335
-                );
3336
-            }
3337
-        }
3265
+				if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3266
+					switch ($free_variation_attribute_def->data_type_to_use) {
3267
+						case 'custom':
3268
+						case 'internal':
3269
+							$possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3270
+							$value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3271
+							break;
3272
+					}
3273
+				}
3274
+				$variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3275
+				$variation_tpl_component['VARIATION_ID'] = $attribute_code;
3276
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3277
+				if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3278
+					$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);
3279
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3280
+						$variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3281
+					}
3282
+				}
3283
+				unset($variation_tpl_component);
3284
+			}
3285
+		}
3286
+		return $variation_attribute_ordered;
3287
+	}
3338 3288
 
3339
-        /** If product has been ordered **/
3340
-        $output = '';
3341
-        if (!empty($sales_informations)) {
3342
-            $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3343
-            $output .= '<ul>';
3344
-            foreach ($sales_informations as $sales_information) {
3345
-                $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>';
3346
-            }
3347
-            $output .= '</ul>';
3348
-        } else {
3349
-            $output .= __('This product has never been ordered', 'wpshop');
3350
-        }
3289
+	public function wps_selected_variation_picture($head_product_id, $variations)
3290
+	{
3291
+		$response = array();
3292
+		/** Selected Product image **/
3293
+		$post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3294
+		if (!empty($post_thumbnail_id)) {
3295
+			$response['img_id'] = $post_thumbnail_id;
3296
+			$response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3297
+			$response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3298
+		}
3351 3299
 
3352
-        echo $output;
3353
-    }
3300
+		/** check if have one variation **/
3301
+		if (!empty($variations) && count($variations) == 1) {
3302
+			$variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3303
+			if (!empty($variation_attached_image_id)) {
3304
+				$response['img_id'] = $variation_attached_image_id;
3305
+				$response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3306
+				$response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3307
+			}
3308
+		}
3309
+		return $response;
3310
+	}
3354 3311
 
3355
-    public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3356
-    {
3357
-        global $wpdb, $wpshop_payment;
3358
-        $output = '';
3359
-        $tpl_component = array();
3360
-        /**    Get attribute order for current product    */
3361
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3362
-        $output_order = array();
3363
-        if (count($product_attribute_order_detail) > 0) {
3364
-            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3365
-                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3366
-                    if (!empty($attribute_def->code)) {
3367
-                        $output_order[$attribute_def->code] = $position;
3368
-                    }
3369
-
3370
-                }
3371
-            }
3372
-        }
3373
-        $variation_attribute_ordered = array();
3374
-
3375
-        /** Check if product is a variation and change his name **/
3376
-        $product_post_type = get_post_type($the_product['product_id']);
3377
-        if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3378
-            $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3379
-            $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3380
-            $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3381
-        }
3312
+	/** Add a meta box of product sales history in product administration panel **/
3313
+	public function meta_box_product_sale_informations()
3314
+	{
3315
+		global $post;
3316
+		$product_id = $post->ID;
3317
+
3318
+		$variations = self::get_variation($product_id);
3319
+
3320
+		$sales_informations = array();
3321
+		/** Query **/
3322
+		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3323
+		$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')));
3324
+		$orders = new WP_Query($query_args);
3325
+		if (!empty($orders) && !empty($orders->posts)) {
3326
+			foreach ($orders->posts as $order) {
3327
+				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3328
+				$order_info = get_post_meta($order->ID, '_order_info', true);
3329
+				$sales_informations[] = array(
3330
+					'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3331
+					'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3332
+					'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'] : '',
3333
+					'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'] : '',
3334
+					'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'] : '',
3335
+				);
3336
+			}
3337
+		}
3382 3338
 
3383
-        foreach ($the_product as $product_definition_key => $product_definition_value) {
3384
-            if ($product_definition_key != 'item_meta') {
3385
-                $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3386
-                if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3387
-                    $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3388
-                }
3389
-            } else {
3390
-                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3391
-            }
3392
-        }
3339
+		/** If product has been ordered **/
3340
+		$output = '';
3341
+		if (!empty($sales_informations)) {
3342
+			$output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3343
+			$output .= '<ul>';
3344
+			foreach ($sales_informations as $sales_information) {
3345
+				$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>';
3346
+			}
3347
+			$output .= '</ul>';
3348
+		} else {
3349
+			$output .= __('This product has never been ordered', 'wpshop');
3350
+		}
3393 3351
 
3394
-        ksort($variation_attribute_ordered['attribute_list']);
3395
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3396
-        foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3397
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3398
-        }
3352
+		echo $output;
3353
+	}
3399 3354
 
3400
-        /**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3401
-        $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3402
-        if (!empty($attribute_list)) {
3403
-            foreach ($attribute_list as $attribute_def) {
3404
-                $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3405
-            }
3406
-        }
3355
+	public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3356
+	{
3357
+		global $wpdb, $wpshop_payment;
3358
+		$output = '';
3359
+		$tpl_component = array();
3360
+		/**    Get attribute order for current product    */
3361
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3362
+		$output_order = array();
3363
+		if (count($product_attribute_order_detail) > 0) {
3364
+			foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3365
+				foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3366
+					if (!empty($attribute_def->code)) {
3367
+						$output_order[$attribute_def->code] = $position;
3368
+					}
3407 3369
 
3408
-        /**    Fill the array with all prices for different variations    */
3409
-        foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3410
-            $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3411
-        }
3370
+				}
3371
+			}
3372
+		}
3373
+		$variation_attribute_ordered = array();
3374
+
3375
+		/** Check if product is a variation and change his name **/
3376
+		$product_post_type = get_post_type($the_product['product_id']);
3377
+		if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3378
+			$parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3379
+			$parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3380
+			$the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3381
+		}
3412 3382
 
3413
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3414
-        $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3415
-        $post_list_with_options = $wpdb->get_results($query);
3416
-        if (!empty($post_list_with_options)) {
3417
-            $additionnal_price = 0;
3418
-            foreach ($post_list_with_options as $product_info) {
3419
-                $product_meta = unserialize($product_info->meta_value);
3420
-                if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3421
-                    $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3422
-
3423
-                    $the_product = array_merge(array(
3424
-                        'product_id' => $product_info->post_id,
3425
-                        'product_qty' => 1,
3426
-                    ), $product);
3427
-
3428
-                    $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3429
-                    $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3430
-
3431
-                    $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));
3432
-                    $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3433
-                }
3434
-            }
3435
-        }
3383
+		foreach ($the_product as $product_definition_key => $product_definition_value) {
3384
+			if ($product_definition_key != 'item_meta') {
3385
+				$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3386
+				if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3387
+					$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3388
+				}
3389
+			} else {
3390
+				$variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3391
+			}
3392
+		}
3436 3393
 
3437
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3438
-        $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3439
-        if (!empty($additionnal_price)) {
3440
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3441
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3442
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3443
-        }
3394
+		ksort($variation_attribute_ordered['attribute_list']);
3395
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3396
+		foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3397
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3398
+		}
3444 3399
 
3445
-        /**    Call informtion for partial payment    */
3446
-        $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3447
-        $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3400
+		/**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3401
+		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3402
+		if (!empty($attribute_list)) {
3403
+			foreach ($attribute_list as $attribute_def) {
3404
+				$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3405
+			}
3406
+		}
3448 3407
 
3449
-        /**    Define the current selected currency for the order summary    */
3408
+		/**    Fill the array with all prices for different variations    */
3409
+		foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3410
+			$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3411
+		}
3412
+
3413
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3414
+		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3415
+		$post_list_with_options = $wpdb->get_results($query);
3416
+		if (!empty($post_list_with_options)) {
3417
+			$additionnal_price = 0;
3418
+			foreach ($post_list_with_options as $product_info) {
3419
+				$product_meta = unserialize($product_info->meta_value);
3420
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3421
+					$product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3422
+
3423
+					$the_product = array_merge(array(
3424
+						'product_id' => $product_info->post_id,
3425
+						'product_qty' => 1,
3426
+					), $product);
3427
+
3428
+					$additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3429
+					$tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3430
+
3431
+					$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));
3432
+					$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3433
+				}
3434
+			}
3435
+		}
3436
+
3437
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3438
+		$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3439
+		if (!empty($additionnal_price)) {
3440
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3441
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3442
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3443
+		}
3444
+
3445
+		/**    Call informtion for partial payment    */
3446
+		$partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3447
+		$tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3448
+
3449
+		/**    Define the current selected currency for the order summary    */
3450 3450
 //         $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3451
-        $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3452
-        return $output;
3453
-    }
3451
+		$output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3452
+		return $output;
3453
+	}
3454 3454
 
3455
-    /**
3456
-     * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3457
-     * @param string $ID ID product variations or not
3458
-     * @return string Return ID
3459
-     */
3460
-    public static function get_id_variation($ID)
3461
-    {
3462
-        $result = explode('__', $ID);
3463
-        return end($result);
3464
-    }
3455
+	/**
3456
+	 * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3457
+	 * @param string $ID ID product variations or not
3458
+	 * @return string Return ID
3459
+	 */
3460
+	public static function get_id_variation($ID)
3461
+	{
3462
+		$result = explode('__', $ID);
3463
+		return end($result);
3464
+	}
3465 3465
 
3466
-    /**
3467
-     * Update all variations definitions who not modified
3468
-     * @param array $new_value
3469
-     * @param array $old_value
3470
-     * @return array $new_value
3471
-     */
3472
-    public static function update_wpshop_catalog_product_option($new_value, $old_value)
3473
-    {
3474
-        global $wpdb;
3475
-        $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') . '%');
3476
-        foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3477
-            $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3478
-            $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3479
-            update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3480
-        }
3481
-        return $new_value;
3482
-    }
3466
+	/**
3467
+	 * Update all variations definitions who not modified
3468
+	 * @param array $new_value
3469
+	 * @param array $old_value
3470
+	 * @return array $new_value
3471
+	 */
3472
+	public static function update_wpshop_catalog_product_option($new_value, $old_value)
3473
+	{
3474
+		global $wpdb;
3475
+		$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') . '%');
3476
+		foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3477
+			$wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3478
+			$wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3479
+			update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3480
+		}
3481
+		return $new_value;
3482
+	}
3483 3483
 
3484
-    public static function variation_parameters_save($current_post_id, $options)
3485
-    {
3484
+	public static function variation_parameters_save($current_post_id, $options)
3485
+	{
3486 3486
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3487
-        $variation_post_meta['options'] = $options;
3487
+		$variation_post_meta['options'] = $options;
3488 3488
 		$variation_post_meta['follow_general_config'] = true;
3489 3489
 		if( $variation_post_meta['follow_general_config'] ) {
3490 3490
 			$shop_option = get_option('wpshop_catalog_product_option', array());
@@ -3500,6 +3500,6 @@  discard block
 block discarded – undo
3500 3500
 				}
3501 3501
 			}
3502 3502
 		}
3503
-        update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3504
-    }
3503
+		update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3504
+	}
3505 3505
 }
Please login to merge, or discard this patch.