Completed
Push — master ( fba304...e3db56 )
by
unknown
38:37
created
includes/librairies/purchase/orders.class.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 	/** Generate the billing reference regarding the order $order_id
245 245
 	 * @return void
246
-	*/
246
+	 */
247 247
 	function order_generate_billing_number($order_id, $force_invoicing = false){
248 248
 		global $wpdb, $wpshop_modules_billing;
249 249
 
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 
265 265
 
266 266
 	/** Renvoi une nouvelle r�f�rence unique pour une commande
267
-	* @return int
268
-	*/
267
+	 * @return int
268
+	 */
269 269
 	public static function get_new_order_reference(){
270 270
 		$number_figures = get_option('wpshop_order_number_figures', false);
271 271
 		/* If the number doesn't exist, we create a default one */
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	}
286 286
 
287 287
 	/** Renvoi une nouvelle r�f�rence unique pour un devis
288
-	* @return int
289
-	*/
288
+	 * @return int
289
+	 */
290 290
 	public static function get_new_pre_order_reference($save = true){
291 291
 		$number_figures = get_option('wpshop_order_number_figures', false);
292 292
 		/* If the number doesn't exist, we create a default one */
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 
349 349
 	/** Set the custom colums
350 350
 	 * @return array
351
-	*/
351
+	 */
352 352
 	static function orders_edit_columns($columns){
353 353
 	  $columns = array(
354 354
 		'cb' => '<input type="checkbox" />',
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 
368 368
 	/** Give the content by column
369 369
 	 * @return array
370
-	*/
370
+	 */
371 371
 	public static function orders_custom_columns($column, $post_id) {
372 372
 		if ( get_post_type( $post_id ) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) {
373 373
 			global $civility, $order_status;
Please login to merge, or discard this patch.
Braces   +14 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 /**
3 5
  * Products management method file
4 6
  *
@@ -132,8 +134,7 @@  discard block
 block discarded – undo
132 134
 		$order_main_info .= '<div class="wps-product-section">';
133 135
 		if(empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))){
134 136
 			$order_main_info .=  '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Temporary quotation reference','wpshop').': </strong>'.self::get_new_pre_order_reference(false).'<br/>';
135
-		}
136
-		else{
137
+		} else{
137 138
 			if(!empty($order_postmeta['order_key'])){
138 139
 				$order_main_info .=  '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Order reference','wpshop').' : </strong>'.$order_postmeta['order_key'].'<br/>';
139 140
 			}
@@ -146,8 +147,7 @@  discard block
 block discarded – undo
146 147
 				$sub_tpl_component = array();
147 148
 				$order_invoice_download = '<a href="' . admin_url( 'admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&invoice_ref=' . $order_postmeta['order_invoice_ref'] . '&mode=pdf' ) . '">' . __('Download invoice', 'wpshop') . '</a><br />';
148 149
 				$order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'. __('Invoice number','wpshop').': </strong>'.$order_postmeta['order_invoice_ref'].'<br/>' . $order_invoice_download . '';
149
-			}
150
-			else {
150
+			} else {
151 151
 				$order_main_info .= wpshop_display::display_template_element('wpshop_admin_order_generate_invoice_button', array(), array(), 'admin');
152 152
 			}
153 153
 		}
@@ -201,8 +201,7 @@  discard block
 block discarded – undo
201 201
 			if ( empty($credit_meta) && (float) 0 !== $total_received ) {
202 202
 				if( $order_postmeta['order_status'] == 'refunded') {
203 203
 					$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container">' .__('Credit Slip number', 'wpshop'). ' : <strong>'. ( (!empty($order_postmeta) && !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['refunded_action']) && !empty($order_postmeta['order_payment']['refunded_action']['credit_slip_ref']) ) ? '<a href="' .admin_url( 'admin-post.php?action=wps_invoice&order_id=' .$order->ID. '&amp;invoice_ref=' .$order_postmeta['order_payment']['refunded_action']['credit_slip_ref'].'&credit_slip=ok' ). '" target="_blank">'.$order_postmeta['order_payment']['refunded_action']['credit_slip_ref'].'</a>' : '') .'</strong></div>';
204
-				}
205
-				else {
204
+				} else {
206 205
 					$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container" ><button class="wps-bton-second-mini-rounded markAsRefunded order_' .$order->ID. '">' .__('Refund this order', 'wpshop'). '</button><input type="hidden" id="markasrefunded_order_hidden_indicator" name="markasrefunded_order_hidden_indicator" /></div>';
207 206
 				}
208 207
 			}
@@ -283,8 +282,7 @@  discard block
 block discarded – undo
283 282
 
284 283
 		$order_current_number = get_option('wpshop_order_current_number', false);
285 284
 		/* If the counter doesn't exist, we initiate it */
286
-		if(!$order_current_number) { $order_current_number = 1; }
287
-		else { $order_current_number++; }
285
+		if(!$order_current_number) { $order_current_number = 1; } else { $order_current_number++; }
288 286
 		update_option('wpshop_order_current_number', $order_current_number);
289 287
 
290 288
 		$order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number);
@@ -304,8 +302,7 @@  discard block
 block discarded – undo
304 302
 
305 303
 		$order_current_number = get_option('wpshop_preorder_current_number', false);
306 304
 		/* If the counter doesn't exist, we initiate it */
307
-		if(!$order_current_number) { $order_current_number = 1; }
308
-		else { $order_current_number++; }
305
+		if(!$order_current_number) { $order_current_number = 1; } else { $order_current_number++; }
309 306
 		if($save){
310 307
 			update_option('wpshop_preorder_current_number', $order_current_number);
311 308
 		}
@@ -339,8 +336,7 @@  discard block
 block discarded – undo
339 336
 					$shipping_info['address'] = get_post_meta( $address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true);
340 337
 				}
341 338
 			}
342
-		}
343
-		else {
339
+		} else {
344 340
 			$shipping_info['id'] = get_post_meta($shipping_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true);
345 341
 			$shipping_info['address'] = get_post_meta($shipping_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true);
346 342
 			$shipping_info['address_id'] = ( !empty($_SESSION['shipping_address']) ) ? intval( $_SESSION['shipping_address'] ) : '';
@@ -403,8 +399,7 @@  discard block
 block discarded – undo
403 399
 				case "order_billing":
404 400
 					if ( !empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address']) ) {
405 401
 						$billing = $addresses['billing']['address'];
406
-					}
407
-					else if ( !empty($addresses['billing']) ) {
402
+					} else if ( !empty($addresses['billing']) ) {
408 403
 						$billing = $addresses['billing'];
409 404
 					}
410 405
 					if ( !empty($billing) ) {
@@ -415,8 +410,7 @@  discard block
 block discarded – undo
415 410
 						echo !empty($billing['city']) ? $billing['city'] . ', ' : null;
416 411
 						echo !empty($billing['country']) ? $billing['country'] : null;
417 412
 						echo (!empty($billing['phone']) ? '<br /><b>' . $billing['phone'] . '</b>' : '');
418
-					}
419
-					else {
413
+					} else {
420 414
 						echo __('No information available for user billing', 'wpshop');
421 415
 					}
422 416
 				break;
@@ -424,8 +418,7 @@  discard block
 block discarded – undo
424 418
 				case "order_shipping":
425 419
 					if ( !empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address']) ) {
426 420
 						$shipping = $addresses['shipping']['address'];
427
-					}
428
-					else if ( !empty($addresses['shipping']) ) {
421
+					} else if ( !empty($addresses['shipping']) ) {
429 422
 						$shipping = $addresses['shipping'];
430 423
 					}
431 424
 					if ( !empty($shipping) ) {
@@ -435,8 +428,7 @@  discard block
 block discarded – undo
435 428
 						echo !empty($billing['postcode']) ? '<br />' . $billing['postcode'] . ' ' : null;
436 429
 						echo !empty($billing['city']) ? $billing['city'] . ', ' : null;
437 430
 						echo !empty($billing['country']) ? $billing['country'] : null;
438
-					}
439
-					else{
431
+					} else{
440 432
 						echo __('No information available for user shipping', 'wpshop');
441 433
 					}
442 434
 				break;
@@ -449,8 +441,7 @@  discard block
 block discarded – undo
449 441
 						// Marquer comme envoy�
450 442
 						if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'completed')) {
451 443
 							$buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_'.$post_id.' wps-bton-loader">'.__('Mark as shipped', 'wpshop').'</a> ';
452
-						}
453
-						else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment' )) {
444
+						} else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment' )) {
454 445
 							//		$buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' ';
455 446
 						}
456 447
 						$buttons .= '</p>';
Please login to merge, or discard this patch.
Spacing   +138 added lines, -138 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
  * Products management method file
4 4
  *
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 /*	Check if file is include. No direct access possible with file url	*/
13
-if ( !defined( 'WPSHOP_VERSION' ) ) {
14
-	die( __('Access is not allowed by this way', 'wpshop') );
13
+if (!defined('WPSHOP_VERSION')) {
14
+	die(__('Access is not allowed by this way', 'wpshop'));
15 15
 }
16 16
 
17 17
 /**
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
 		/**	Add action button	*/
71 71
 		add_meta_box(
72 72
 			'wpshop_order_actions',
73
-			'<span class="dashicons dashicons-info"></span> '.__('Actions on order', 'wpshop'),
73
+			'<span class="dashicons dashicons-info"></span> ' . __('Actions on order', 'wpshop'),
74 74
 			array('wpshop_orders', 'order_actions'),
75 75
 				WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'high'
76 76
 		);
77 77
 
78
-		if ( !in_array( $post->post_status, array( 'auto-draft' ) ) ) {
78
+		if (!in_array($post->post_status, array('auto-draft'))) {
79 79
 			add_meta_box('wpshop_credit_actions', __('Credit on order', 'wpshop'), array('wps_credit', 'wps_credit_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low');
80 80
 		}
81 81
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @param object $order The current order being edited
102 102
 	 */
103
-	public static function order_actions( $order ) {
103
+	public static function order_actions($order) {
104 104
 		$output = '';
105 105
 
106 106
 		$order_status = unserialize(WPSHOP_ORDER_STATUS);
@@ -108,34 +108,34 @@  discard block
 block discarded – undo
108 108
 
109 109
 		$tpl_component = array();
110 110
 
111
-		$delete_button = wpshop_display::display_template_element('wpshop_admin_order_action_del_button', array('ADMIN_ORDER_DELETE_LINK' => esc_url( get_delete_post_link($order->ID) ) , 'ADMIN_ORDER_DELETE_TEXT' => (!EMPTY_TRASH_DAYS ? __('Delete Permanently', 'wpshop') :  __('Move to Trash', 'wpshop'))), array(), 'admin');
112
-		$tpl_component['ADMIN_ORDER_DELETE_ORDER'] = current_user_can( "delete_post", $order->ID ) ? $delete_button : '';
111
+		$delete_button = wpshop_display::display_template_element('wpshop_admin_order_action_del_button', array('ADMIN_ORDER_DELETE_LINK' => esc_url(get_delete_post_link($order->ID)), 'ADMIN_ORDER_DELETE_TEXT' => (!EMPTY_TRASH_DAYS ? __('Delete Permanently', 'wpshop') : __('Move to Trash', 'wpshop'))), array(), 'admin');
112
+		$tpl_component['ADMIN_ORDER_DELETE_ORDER'] = current_user_can("delete_post", $order->ID) ? $delete_button : '';
113 113
 
114 114
 		/**	Add an action list	*/
115 115
 		$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = '';
116 116
 
117 117
 		/**	Display main information about the order	*/
118 118
 		$order_main_info = '';
119
-		if(!empty($order_postmeta['order_date'])){
120
-			$order_main_info .=  '<div class="wps-product-section"><span class="dashicons dashicons-calendar-alt"></span> <strong>'.__('Order date','wpshop').' : </strong><br/>'.mysql2date('d F Y H:i:s', $order_postmeta['order_date'], true).'</div>';
119
+		if (!empty($order_postmeta['order_date'])) {
120
+			$order_main_info .= '<div class="wps-product-section"><span class="dashicons dashicons-calendar-alt"></span> <strong>' . __('Order date', 'wpshop') . ' : </strong><br/>' . mysql2date('d F Y H:i:s', $order_postmeta['order_date'], true) . '</div>';
121 121
 		}
122 122
 		$order_main_info .= '<div class="wps-product-section">';
123
-		if(empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))){
124
-			$order_main_info .=  '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Temporary quotation reference','wpshop').': </strong>'.self::get_new_pre_order_reference(false).'<br/>';
123
+		if (empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))) {
124
+			$order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Temporary quotation reference', 'wpshop') . ': </strong>' . self::get_new_pre_order_reference(false) . '<br/>';
125 125
 		}
126
-		else{
127
-			if(!empty($order_postmeta['order_key'])){
128
-				$order_main_info .=  '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Order reference','wpshop').' : </strong>'.$order_postmeta['order_key'].'<br/>';
126
+		else {
127
+			if (!empty($order_postmeta['order_key'])) {
128
+				$order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Order reference', 'wpshop') . ' : </strong>' . $order_postmeta['order_key'] . '<br/>';
129 129
 			}
130
-			if(!empty($order_postmeta['order_temporary_key'])){
131
-				$order_main_info .=  '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Pre-order reference','wpshop').': </strong>'.$order_postmeta['order_temporary_key'].'<br/>';
132
-				$post_ID = !empty( $_GET['post'] ) ? (int) $_GET['post'] : 0;
133
-				$order_main_info .= '<a href="' .admin_url( 'admin-post.php?action=wps_invoice&order_id=' . $post_ID . '&mode=pdf' ) . '">' .__('Download the quotation', 'wpshop'). '</a><br />';
130
+			if (!empty($order_postmeta['order_temporary_key'])) {
131
+				$order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Pre-order reference', 'wpshop') . ': </strong>' . $order_postmeta['order_temporary_key'] . '<br/>';
132
+				$post_ID = !empty($_GET['post']) ? (int)$_GET['post'] : 0;
133
+				$order_main_info .= '<a href="' . admin_url('admin-post.php?action=wps_invoice&order_id=' . $post_ID . '&mode=pdf') . '">' . __('Download the quotation', 'wpshop') . '</a><br />';
134 134
 			}
135
-			if(!empty($order_postmeta['order_invoice_ref'])){
135
+			if (!empty($order_postmeta['order_invoice_ref'])) {
136 136
 				$sub_tpl_component = array();
137
-				$order_invoice_download = '<a href="' . admin_url( 'admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&invoice_ref=' . $order_postmeta['order_invoice_ref'] . '&mode=pdf' ) . '">' . __('Download invoice', 'wpshop') . '</a><br />';
138
-				$order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'. __('Invoice number','wpshop').': </strong>'.$order_postmeta['order_invoice_ref'].'<br/>' . $order_invoice_download . '';
137
+				$order_invoice_download = '<a href="' . admin_url('admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&invoice_ref=' . $order_postmeta['order_invoice_ref'] . '&mode=pdf') . '">' . __('Download invoice', 'wpshop') . '</a><br />';
138
+				$order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Invoice number', 'wpshop') . ': </strong>' . $order_postmeta['order_invoice_ref'] . '<br/>' . $order_invoice_download . '';
139 139
 			}
140 140
 			else {
141 141
 				$order_main_info .= wpshop_display::display_template_element('wpshop_admin_order_generate_invoice_button', array(), array(), 'admin');
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
 
147 147
 		/*Add the current order status in display**/
148
-			$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= ( !empty($order_postmeta['order_status']) ) ? (sprintf('<span class="order_status_' . $order->ID . ' wpshop_order_status_container wpshop_order_status_%1$s ">%2$s</span>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) ) : '';
148
+			$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= (!empty($order_postmeta['order_status'])) ? (sprintf('<span class="order_status_' . $order->ID . ' wpshop_order_status_container wpshop_order_status_%1$s ">%2$s</span>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop'))) : '';
149 149
 
150 150
 			$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= $order_main_info;
151 151
 
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
 			</div>';
164 164
 		}*/
165 165
 
166
-		if( ( ( !empty($order_postmeta['cart_type']) && $order_postmeta['cart_type'] == 'quotation' ) || !empty( $order_postmeta['order_temporary_key'] ) ) && in_array( $order_postmeta['order_status'], array( 'awaiting_payment', 'partially_paid' ) ) && (float) $order_postmeta['order_amount_to_pay_now'] != (float) 0 ) {
167
-			$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section">' . self::display_customer_pay_quotation( isset( $order_postmeta['pay_quotation'] ), $order->ID ) . '</div>';
166
+		if (((!empty($order_postmeta['cart_type']) && $order_postmeta['cart_type'] == 'quotation') || !empty($order_postmeta['order_temporary_key'])) && in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid')) && (float)$order_postmeta['order_amount_to_pay_now'] != (float)0) {
167
+			$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section">' . self::display_customer_pay_quotation(isset($order_postmeta['pay_quotation']), $order->ID) . '</div>';
168 168
 		}
169 169
 
170 170
 		/**
@@ -175,30 +175,30 @@  discard block
 block discarded – undo
175 175
 		}*/
176 176
 
177 177
 		/*Add the button regarding the order status**/
178
-		if ( !empty($order_postmeta['order_status']) ) {
179
-			if( $order_postmeta['order_status'] == 'awaiting_payment' ) {
180
-				$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section"><button class="wps-bton-second-mini-rounded markAsCanceled order_'.$order->ID.'" >'.__('Cancel this order', 'wpshop').'</button><input type="hidden" id="markascanceled_order_hidden_indicator" name="markascanceled_order_hidden_indicator" /></div>';
178
+		if (!empty($order_postmeta['order_status'])) {
179
+			if ($order_postmeta['order_status'] == 'awaiting_payment') {
180
+				$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section"><button class="wps-bton-second-mini-rounded markAsCanceled order_' . $order->ID . '" >' . __('Cancel this order', 'wpshop') . '</button><input type="hidden" id="markascanceled_order_hidden_indicator" name="markascanceled_order_hidden_indicator" /></div>';
181 181
 			}
182
-			$credit_meta = get_post_meta( $order->ID, '_wps_order_credit', true );
182
+			$credit_meta = get_post_meta($order->ID, '_wps_order_credit', true);
183 183
 
184
-			$total_received = (float) 0;
185
-			if ( ! empty( $order_postmeta['order_payment'] ) && ! empty( $order_postmeta['order_payment']['received'] ) ) {
186
-				foreach( $order_postmeta['order_payment']['received'] as $received ) {
187
-					$total_received += (float) isset( $received['received_amount'] ) ? $received['received_amount'] : 0;
184
+			$total_received = (float)0;
185
+			if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) {
186
+				foreach ($order_postmeta['order_payment']['received'] as $received) {
187
+					$total_received += (float)isset($received['received_amount']) ? $received['received_amount'] : 0;
188 188
 				}
189 189
 			}
190 190
 
191
-			if ( empty($credit_meta) && (float) 0 !== $total_received ) {
192
-				if( $order_postmeta['order_status'] == 'refunded') {
193
-					$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container">' .__('Credit Slip number', 'wpshop'). ' : <strong>'. ( (!empty($order_postmeta) && !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['refunded_action']) && !empty($order_postmeta['order_payment']['refunded_action']['credit_slip_ref']) ) ? '<a href="' .admin_url( 'admin-post.php?action=wps_invoice&order_id=' .$order->ID. '&amp;invoice_ref=' .$order_postmeta['order_payment']['refunded_action']['credit_slip_ref'].'&credit_slip=ok' ). '" target="_blank">'.$order_postmeta['order_payment']['refunded_action']['credit_slip_ref'].'</a>' : '') .'</strong></div>';
191
+			if (empty($credit_meta) && (float)0 !== $total_received) {
192
+				if ($order_postmeta['order_status'] == 'refunded') {
193
+					$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container">' . __('Credit Slip number', 'wpshop') . ' : <strong>' . ((!empty($order_postmeta) && !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['refunded_action']) && !empty($order_postmeta['order_payment']['refunded_action']['credit_slip_ref'])) ? '<a href="' . admin_url('admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&amp;invoice_ref=' . $order_postmeta['order_payment']['refunded_action']['credit_slip_ref'] . '&credit_slip=ok') . '" target="_blank">' . $order_postmeta['order_payment']['refunded_action']['credit_slip_ref'] . '</a>' : '') . '</strong></div>';
194 194
 				}
195 195
 				else {
196
-					$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container" ><button class="wps-bton-second-mini-rounded markAsRefunded order_' .$order->ID. '">' .__('Refund this order', 'wpshop'). '</button><input type="hidden" id="markasrefunded_order_hidden_indicator" name="markasrefunded_order_hidden_indicator" /></div>';
196
+					$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container" ><button class="wps-bton-second-mini-rounded markAsRefunded order_' . $order->ID . '">' . __('Refund this order', 'wpshop') . '</button><input type="hidden" id="markasrefunded_order_hidden_indicator" name="markasrefunded_order_hidden_indicator" /></div>';
197 197
 				}
198 198
 			}
199 199
 		}
200
-		$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = strrev( preg_replace( strrev( '/wps-product-section/' ), '', strrev( $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] ), 1 ) );
201
-		echo wpshop_display::display_template_element( 'wpshop_admin_order_action_box', $tpl_component, array( 'type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'id' => $order->ID ), 'admin' );
200
+		$tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = strrev(preg_replace(strrev('/wps-product-section/'), '', strrev($tpl_component['ADMIN_ORDER_ACTIONS_LIST']), 1));
201
+		echo wpshop_display::display_template_element('wpshop_admin_order_action_box', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'id' => $order->ID), 'admin');
202 202
 	}
203 203
 
204 204
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	function order_container_in_admin() {
207 207
 		global $post;
208 208
 		$output  = '<div id="wps_order_content_container">';
209
-		$output .= self::order_content( $post );
209
+		$output .= self::order_content($post);
210 210
 		$output .= '</div>';
211 211
 		echo $output;
212 212
 	}
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param order $post The complete order content
219 219
 	 */
220
-	function order_content( $post ) {
220
+	function order_content($post) {
221 221
 		$order_content = '';
222 222
 
223 223
 		$order = get_post_meta($post->ID, '_order_postmeta', true);
224 224
 
225 225
 		$order_content .= '<div id="order_product_container" class="order_product_container wpshop_cls" >';
226
-		if($order){/*	Read the order content if the order has product	*/
226
+		if ($order) {/*	Read the order content if the order has product	*/
227 227
 			$order_content .= '<input type="hidden" value="" name="order_products_to_delete" id="order_products_to_delete" />' . wpshop_cart::display_cart(true, $order, 'admin');
228 228
 			if (empty($order['order_invoice_ref'])) {
229 229
 				$order_content .= '<div id="order_refresh_button_container" class="wpshop_clear_block" ><input type="button" class="button-primary alignright wpshopHide" id="wpshop_admin_order_recalculate" value="' . __('Refresh order informations', 'wpshop') . '" /></div>';
@@ -241,18 +241,18 @@  discard block
 block discarded – undo
241 241
 	/** Generate the billing reference regarding the order $order_id
242 242
 	 * @return void
243 243
 	*/
244
-	function order_generate_billing_number($order_id, $force_invoicing = false){
244
+	function order_generate_billing_number($order_id, $force_invoicing = false) {
245 245
 		global $wpdb, $wpshop_modules_billing;
246 246
 
247 247
 		// Get the order from the db
248 248
 		$order = get_post_meta($order_id, '_order_postmeta', true);
249 249
 
250 250
 		// If the payment is completed
251
-		if(($order['order_status']=='completed') || $force_invoicing) {
251
+		if (($order['order_status'] == 'completed') || $force_invoicing) {
252 252
 
253 253
 			// If the reference hasn't been generated yet
254
-			if(empty($order['order_invoice_ref'])) {
255
-				$order['order_invoice_ref'] = $wpshop_modules_billing->generate_invoice_number( $order_id );
254
+			if (empty($order['order_invoice_ref'])) {
255
+				$order['order_invoice_ref'] = $wpshop_modules_billing->generate_invoice_number($order_id);
256 256
 
257 257
 				update_post_meta($order_id, '_order_postmeta', $order);
258 258
 			}
@@ -263,45 +263,45 @@  discard block
 block discarded – undo
263 263
 	/** Renvoi une nouvelle r�f�rence unique pour une commande
264 264
 	* @return int
265 265
 	*/
266
-	public static function get_new_order_reference(){
266
+	public static function get_new_order_reference() {
267 267
 		$number_figures = get_option('wpshop_order_number_figures', false);
268 268
 		/* If the number doesn't exist, we create a default one */
269
-		if(!$number_figures){
269
+		if (!$number_figures) {
270 270
 			$number_figures = 5;
271 271
 			update_option('wpshop_order_number_figures', $number_figures);
272 272
 		}
273 273
 
274 274
 		$order_current_number = get_option('wpshop_order_current_number', false);
275 275
 		/* If the counter doesn't exist, we initiate it */
276
-		if(!$order_current_number) { $order_current_number = 1; }
276
+		if (!$order_current_number) { $order_current_number = 1; }
277 277
 		else { $order_current_number++; }
278 278
 		update_option('wpshop_order_current_number', $order_current_number);
279 279
 
280
-		$order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number);
281
-		return WPSHOP_ORDER_REFERENCE_PREFIX.$order_ref;
280
+		$order_ref = (string)sprintf('%0' . $number_figures . 'd', $order_current_number);
281
+		return WPSHOP_ORDER_REFERENCE_PREFIX . $order_ref;
282 282
 	}
283 283
 
284 284
 	/** Renvoi une nouvelle r�f�rence unique pour un devis
285 285
 	* @return int
286 286
 	*/
287
-	public static function get_new_pre_order_reference($save = true){
287
+	public static function get_new_pre_order_reference($save = true) {
288 288
 		$number_figures = get_option('wpshop_order_number_figures', false);
289 289
 		/* If the number doesn't exist, we create a default one */
290
-		if(!$number_figures){
290
+		if (!$number_figures) {
291 291
 			$number_figures = 5;
292 292
 			update_option('wpshop_order_number_figures', $number_figures);
293 293
 		}
294 294
 
295 295
 		$order_current_number = get_option('wpshop_preorder_current_number', false);
296 296
 		/* If the counter doesn't exist, we initiate it */
297
-		if(!$order_current_number) { $order_current_number = 1; }
297
+		if (!$order_current_number) { $order_current_number = 1; }
298 298
 		else { $order_current_number++; }
299
-		if($save){
299
+		if ($save) {
300 300
 			update_option('wpshop_preorder_current_number', $order_current_number);
301 301
 		}
302 302
 
303
-		$order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number);
304
-		return WPSHOP_PREORDER_REFERENCE_PREFIX.$order_ref;
303
+		$order_ref = (string)sprintf('%0' . $number_figures . 'd', $order_current_number);
304
+		return WPSHOP_PREORDER_REFERENCE_PREFIX . $order_ref;
305 305
 	}
306 306
 
307 307
 
@@ -316,24 +316,24 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 *	@return void
318 318
 	 */
319
-	public static function set_order_customer_addresses($user_id, $order_id, $shipping_address_id='', $billing_address_id=''){
319
+	public static function set_order_customer_addresses($user_id, $order_id, $shipping_address_id = '', $billing_address_id = '') {
320 320
 		/**	Get order informations	*/
321 321
 		$billing_info['id'] = get_post_meta($billing_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true);
322
-		$billing_info['address'] = get_post_meta($billing_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true);
323
-		$billing_info['address_id'] = ( !empty($_SESSION['billing_address']) ) ? intval( $_SESSION['billing_address'] ) : '';
324
-		if ( !empty($_SESSION['shipping_partner_id']) ) {
325
-			$partner_address_id = get_post_meta( $_SESSION['shipping_partner_id'], '_wpshop_attached_address', true);
322
+		$billing_info['address'] = get_post_meta($billing_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true);
323
+		$billing_info['address_id'] = (!empty($_SESSION['billing_address'])) ? intval($_SESSION['billing_address']) : '';
324
+		if (!empty($_SESSION['shipping_partner_id'])) {
325
+			$partner_address_id = get_post_meta($_SESSION['shipping_partner_id'], '_wpshop_attached_address', true);
326 326
 			if (!empty($partner_address_id)) {
327
-				foreach( $partner_address_id as $address_id ) {
327
+				foreach ($partner_address_id as $address_id) {
328 328
 					$shipping_info['id'] = get_post_meta($address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true);
329
-					$shipping_info['address'] = get_post_meta( $address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true);
329
+					$shipping_info['address'] = get_post_meta($address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true);
330 330
 				}
331 331
 			}
332 332
 		}
333 333
 		else {
334 334
 			$shipping_info['id'] = get_post_meta($shipping_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true);
335
-			$shipping_info['address'] = get_post_meta($shipping_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true);
336
-			$shipping_info['address_id'] = ( !empty($_SESSION['shipping_address']) ) ? intval( $_SESSION['shipping_address'] ) : '';
335
+			$shipping_info['address'] = get_post_meta($shipping_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true);
336
+			$shipping_info['address_id'] = (!empty($_SESSION['shipping_address'])) ? intval($_SESSION['shipping_address']) : '';
337 337
 		}
338 338
 
339 339
 		$order_info = array('billing' => $billing_info, 'shipping' => $shipping_info);
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	/** Set the custom colums
347 347
 	 * @return array
348 348
 	*/
349
-	static function orders_edit_columns($columns){
349
+	static function orders_edit_columns($columns) {
350 350
 	  $columns = array(
351 351
 		'cb' => '<input type="checkbox" />',
352 352
 		'order_identifier' => __('Identifiers', 'wpshop'),
@@ -366,40 +366,40 @@  discard block
 block discarded – undo
366 366
 	 * @return array
367 367
 	*/
368 368
 	public static function orders_custom_columns($column, $post_id) {
369
-		if ( get_post_type( $post_id ) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) {
369
+		if (get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
370 370
 			global $civility, $order_status;
371 371
 
372 372
 			$metadata = get_post_custom();
373 373
 
374
-			$order_postmeta = isset($metadata['_order_postmeta'][0])?unserialize($metadata['_order_postmeta'][0]):'';
375
-			$addresses = get_post_meta($post_id,'_order_info', true);
374
+			$order_postmeta = isset($metadata['_order_postmeta'][0]) ? unserialize($metadata['_order_postmeta'][0]) : '';
375
+			$addresses = get_post_meta($post_id, '_order_info', true);
376 376
 
377
-			switch($column){
377
+			switch ($column) {
378 378
 				case "order_identifier":
379
-					if( !empty( $order_postmeta['order_key'] ) ) {
379
+					if (!empty($order_postmeta['order_key'])) {
380 380
 						echo '<b>' . $order_postmeta['order_key'] . '</b><br>';
381 381
 					}
382
-					if( !empty( $order_postmeta['order_invoice_ref'] ) ) {
382
+					if (!empty($order_postmeta['order_invoice_ref'])) {
383 383
 						echo '<i>' . $order_postmeta['order_invoice_ref'] . '</i>';
384
-					} elseif( !empty($order_postmeta['order_temporary_key'] ) ) {
384
+					} elseif (!empty($order_postmeta['order_temporary_key'])) {
385 385
 						echo '<b>' . $order_postmeta['order_temporary_key'] . '</b>';
386 386
 					}
387 387
 				break;
388 388
 
389 389
 				case "order_status":
390
-					echo !empty($order_postmeta['order_status']) ? sprintf('<mark class="%s" id="order_status_'.$post_id.'">%s</mark>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) : __('Unknown Status', 'wpshop');
390
+					echo !empty($order_postmeta['order_status']) ? sprintf('<mark class="%s" id="order_status_' . $post_id . '">%s</mark>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) : __('Unknown Status', 'wpshop');
391 391
 				break;
392 392
 
393 393
 				case "order_billing":
394
-					if ( !empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address']) ) {
394
+					if (!empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address'])) {
395 395
 						$billing = $addresses['billing']['address'];
396 396
 					}
397
-					else if ( !empty($addresses['billing']) ) {
397
+					else if (!empty($addresses['billing'])) {
398 398
 						$billing = $addresses['billing'];
399 399
 					}
400
-					if ( !empty($billing) ) {
401
-						echo (!empty($billing['civility']) ? __(wpshop_attributes::get_attribute_type_select_option_info($billing['civility'], 'label', 'custom'), 'wpshop') : null).' <strong>'.(!empty($billing['address_first_name']) ? $billing['address_first_name'] : null).' '.(!empty($billing['address_last_name']) ? $billing['address_last_name'] : null).'</strong>';
402
-						echo empty($billing['company']) ?'<br />' : ', <i>'.$billing['company'].'</i><br />';
400
+					if (!empty($billing)) {
401
+						echo (!empty($billing['civility']) ? __(wpshop_attributes::get_attribute_type_select_option_info($billing['civility'], 'label', 'custom'), 'wpshop') : null) . ' <strong>' . (!empty($billing['address_first_name']) ? $billing['address_first_name'] : null) . ' ' . (!empty($billing['address_last_name']) ? $billing['address_last_name'] : null) . '</strong>';
402
+						echo empty($billing['company']) ? '<br />' : ', <i>' . $billing['company'] . '</i><br />';
403 403
 						echo !empty($billing['address']) ? $billing['address'] : null;
404 404
 						echo !empty($billing['postcode']) ? '<br />' . $billing['postcode'] . ' ' : null;
405 405
 						echo !empty($billing['city']) ? $billing['city'] . ', ' : null;
@@ -412,35 +412,35 @@  discard block
 block discarded – undo
412 412
 				break;
413 413
 
414 414
 				case "order_shipping":
415
-					if ( !empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address']) ) {
415
+					if (!empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address'])) {
416 416
 						$shipping = $addresses['shipping']['address'];
417 417
 					}
418
-					else if ( !empty($addresses['shipping']) ) {
418
+					else if (!empty($addresses['shipping'])) {
419 419
 						$shipping = $addresses['shipping'];
420 420
 					}
421
-					if ( !empty($shipping) ) {
422
-						echo '<strong>'.(!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null).' '.(!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null).'</strong>';
423
-						echo empty($shipping['company'])?'<br />':', <i>'.$shipping['company'].'</i><br />';
421
+					if (!empty($shipping)) {
422
+						echo '<strong>' . (!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null) . ' ' . (!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null) . '</strong>';
423
+						echo empty($shipping['company']) ? '<br />' : ', <i>' . $shipping['company'] . '</i><br />';
424 424
 						echo (!empty($shipping['address']) ? $shipping['address'] : null);
425 425
 						echo !empty($billing['postcode']) ? '<br />' . $billing['postcode'] . ' ' : null;
426 426
 						echo !empty($billing['city']) ? $billing['city'] . ', ' : null;
427 427
 						echo !empty($billing['country']) ? $billing['country'] : null;
428 428
 					}
429
-					else{
429
+					else {
430 430
 						echo __('No information available for user shipping', 'wpshop');
431 431
 					}
432 432
 				break;
433 433
 
434 434
 				case "order_type":
435
-						echo '<a href="'.admin_url('post.php?post='.$post_id.'&action=edit').'">'.(!empty($order_postmeta['order_temporary_key']) ? __('Quotation','wpshop') :  __('Basic order','wpshop')).'</a>';
435
+						echo '<a href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . (!empty($order_postmeta['order_temporary_key']) ? __('Quotation', 'wpshop') : __('Basic order', 'wpshop')) . '</a>';
436 436
 						$buttons = '<p class="row-actions">';
437 437
 						// Voir la commande
438
-						$buttons .= '<a class="button button-small" href="'.admin_url('post.php?post='.$post_id.'&action=edit').'">'.__('View', 'wpshop').'</a>';
438
+						$buttons .= '<a class="button button-small" href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . __('View', 'wpshop') . '</a>';
439 439
 						// Marquer comme envoy�
440 440
 						if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'completed')) {
441
-							$buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_'.$post_id.' wps-bton-loader">'.__('Mark as shipped', 'wpshop').'</a> ';
441
+							$buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_' . $post_id . ' wps-bton-loader">' . __('Mark as shipped', 'wpshop') . '</a> ';
442 442
 						}
443
-						else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment' )) {
443
+						else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment')) {
444 444
 							//		$buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' ';
445 445
 						}
446 446
 						$buttons .= '</p>';
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 
454 454
 				case "order_total":
455 455
 					$currency = !empty($order_postmeta['order_currency']) ? $order_postmeta['order_currency'] : get_option('wpshop_shop_default_currency');
456
-					echo isset( $order_postmeta['order_grand_total'] ) ? number_format( $order_postmeta['order_grand_total'], 2, '.', '' ).' '.  wpshop_tools::wpshop_get_sigle($currency) : 'NaN';
456
+					echo isset($order_postmeta['order_grand_total']) ? number_format($order_postmeta['order_grand_total'], 2, '.', '') . ' ' . wpshop_tools::wpshop_get_sigle($currency) : 'NaN';
457 457
 				break;
458 458
 
459 459
 				/*case "order_actions":
@@ -481,10 +481,10 @@  discard block
 block discarded – undo
481 481
 	}
482 482
 
483 483
 	public static function list_table_filters() {
484
-		$post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '';
485
-		$entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : '';
486
-		$entity_filter_btpf = !empty( $_GET['entity_filter_btpf'] ) ? sanitize_text_field( $_GET['entity_filter_btpf'] ) : '';
487
-		$entity_filter_btps = !empty( $_GET['entity_filter_btps'] ) ? sanitize_text_field( $_GET['entity_filter_btps'] ) : '';
484
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
485
+		$entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
486
+		$entity_filter_btpf = !empty($_GET['entity_filter_btpf']) ? sanitize_text_field($_GET['entity_filter_btpf']) : '';
487
+		$entity_filter_btps = !empty($_GET['entity_filter_btps']) ? sanitize_text_field($_GET['entity_filter_btps']) : '';
488 488
 
489 489
 		if (isset($post_type)) {
490 490
 			if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER)) {
@@ -496,23 +496,23 @@  discard block
 block discarded – undo
496 496
 				echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, $entity_filter, '', 'index');
497 497
 				$min = $entity_filter_btpf;
498 498
 				$max = $entity_filter_btps;
499
-				echo ' <label for="entity_filter_btpf">'.__('Between two prices', 'wpshop').'</label> ';
500
-				echo wpshop_form::form_input('entity_filter_btpf', 'entity_filter_btpf', $min, 'text', 'placeholder="'.__('Minimum price', 'wpshop').'"', null);
501
-				echo wpshop_form::form_input('entity_filter_btps', 'entity_filter_btps', $max, 'text', 'placeholder="'.__('Maximum price', 'wpshop').'"', null);
499
+				echo ' <label for="entity_filter_btpf">' . __('Between two prices', 'wpshop') . '</label> ';
500
+				echo wpshop_form::form_input('entity_filter_btpf', 'entity_filter_btpf', $min, 'text', 'placeholder="' . __('Minimum price', 'wpshop') . '"', null);
501
+				echo wpshop_form::form_input('entity_filter_btps', 'entity_filter_btps', $max, 'text', 'placeholder="' . __('Maximum price', 'wpshop') . '"', null);
502 502
 			}
503 503
 		}
504 504
 	}
505 505
 
506 506
 	public static function list_table_filter_parse_query($query) {
507 507
 		global $pagenow, $wpdb;
508
-		$post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '';
509
-		$entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : '';
510
-		$entity_filter_btpf = !empty( $_GET['entity_filter_btpf'] ) ? sanitize_text_field( $_GET['entity_filter_btpf'] ) : '';
511
-		$entity_filter_btps = !empty( $_GET['entity_filter_btps'] ) ? sanitize_text_field( $_GET['entity_filter_btps'] ) : '';
508
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
509
+		$entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
510
+		$entity_filter_btpf = !empty($_GET['entity_filter_btpf']) ? sanitize_text_field($_GET['entity_filter_btpf']) : '';
511
+		$entity_filter_btps = !empty($_GET['entity_filter_btps']) ? sanitize_text_field($_GET['entity_filter_btps']) : '';
512 512
 
513
-		if ( is_admin() && ($pagenow == 'edit.php') && !empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) && !empty( $entity_filter ) ) {
513
+		if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) && !empty($entity_filter)) {
514 514
 			$check = null;
515
-			switch ( $entity_filter ) {
515
+			switch ($entity_filter) {
516 516
 				case 'all':
517 517
 					$sql_query = $wpdb->prepare(
518 518
 						"SELECT ID
@@ -576,27 +576,27 @@  discard block
 block discarded – undo
576 576
 						break;
577 577
 			}
578 578
 
579
-			if ( !empty( $check ) ) {
580
-				if( !empty($no_btp) && $no_btp == 'yes' ) {
579
+			if (!empty($check)) {
580
+				if (!empty($no_btp) && $no_btp == 'yes') {
581 581
 					$min = 'minimum';
582 582
 					$max = 'maximum';
583 583
 				} else {
584
-					$min = ( !empty($_GET['entity_filter_btpf']) && is_numeric($_GET['entity_filter_btpf']) ) ? sanitize_text_field( $_GET['entity_filter_btpf'] ) : 'minimum';
585
-					$max = ( !empty($_GET['entity_filter_btps']) && is_numeric($_GET['entity_filter_btps']) ) ? sanitize_text_field( $_GET['entity_filter_btps'] ) : 'maximum';
584
+					$min = (!empty($_GET['entity_filter_btpf']) && is_numeric($_GET['entity_filter_btpf'])) ? sanitize_text_field($_GET['entity_filter_btpf']) : 'minimum';
585
+					$max = (!empty($_GET['entity_filter_btps']) && is_numeric($_GET['entity_filter_btps'])) ? sanitize_text_field($_GET['entity_filter_btps']) : 'maximum';
586 586
 				}
587 587
 				$results = $wpdb->get_results($sql_query);
588 588
 				$post_id_list = array();
589 589
 				$i = 0;
590
-				foreach($results as $item){
590
+				foreach ($results as $item) {
591 591
 					$meta_value = get_post_meta($item->ID, '_order_postmeta');
592
-					$price = ( !empty( $meta_value[0]['order_grand_total'] ) ) ? $meta_value[0]['order_grand_total'] : '';
593
-					if( $price >= $min || $min == 'minimum' ) {
594
-						if( $price <= $max || $max == 'maximum' ) {
592
+					$price = (!empty($meta_value[0]['order_grand_total'])) ? $meta_value[0]['order_grand_total'] : '';
593
+					if ($price >= $min || $min == 'minimum') {
594
+						if ($price <= $max || $max == 'maximum') {
595 595
 							$post_id_list[] = $item->ID;
596 596
 						}
597 597
 					}
598 598
 				}
599
-				if( empty($post_id_list) ) {
599
+				if (empty($post_id_list)) {
600 600
 					$post_id_list[] = 'no_result';
601 601
 				}
602 602
 				$query->query_vars[$check] = $post_id_list;
@@ -607,67 +607,67 @@  discard block
 block discarded – undo
607 607
 
608 608
 
609 609
 
610
-	function latest_products_ordered ( $orders ) {
610
+	function latest_products_ordered($orders) {
611 611
 		global $wpdb;
612 612
 		$product_id = $output = '';
613 613
 		$products = array();
614 614
 		$display_option = get_option('wpshop_display_option');
615
-		if ( !empty($orders) && !empty($display_option) && !empty($display_option['latest_products_ordered']) ) {
616
-			foreach( $orders as $order ) {
617
-				$order_content = get_post_meta( $order->ID, '_order_postmeta', true );
618
-				if ( !empty($order_content) && !empty( $order_content['order_items']) ) {
615
+		if (!empty($orders) && !empty($display_option) && !empty($display_option['latest_products_ordered'])) {
616
+			foreach ($orders as $order) {
617
+				$order_content = get_post_meta($order->ID, '_order_postmeta', true);
618
+				if (!empty($order_content) && !empty($order_content['order_items'])) {
619 619
 
620
-					foreach( $order_content['order_items'] as $item ) {
621
-						if ( count( $products) >= $display_option['latest_products_ordered'] ) {
620
+					foreach ($order_content['order_items'] as $item) {
621
+						if (count($products) >= $display_option['latest_products_ordered']) {
622 622
 							continue;
623 623
 						}
624 624
 						$product_id = $item['item_id'];
625
-						if ( !empty( $item) && !empty($item['item_meta']) && !empty($item['item_meta']['variation_definition']) ) {
626
-							$parent_def = wpshop_products::get_parent_variation( $item['item_id'] );
627
-							if ( !empty( $parent_def ) ) {
625
+						if (!empty($item) && !empty($item['item_meta']) && !empty($item['item_meta']['variation_definition'])) {
626
+							$parent_def = wpshop_products::get_parent_variation($item['item_id']);
627
+							if (!empty($parent_def)) {
628 628
 								$parent_post = $parent_def['parent_post'];
629 629
 								$product_id = $parent_post->ID;
630 630
 							}
631 631
 						}
632 632
 
633
-						if ( !in_array($product_id, $products) ) {
633
+						if (!in_array($product_id, $products)) {
634 634
 							$products[] = $product_id;
635 635
 						}
636 636
 					}
637 637
 				}
638 638
 			}
639
-			if ( !empty($products) ) {
639
+			if (!empty($products)) {
640 640
 				$products_id = implode(",", $products);
641
-				$output = wpshop_display::display_template_element('latest_products_ordered', array('LATEST_PRODUCTS_ORDERED' => do_shortcode('[wpshop_products pid="' .$products_id. '"]')) );
641
+				$output = wpshop_display::display_template_element('latest_products_ordered', array('LATEST_PRODUCTS_ORDERED' => do_shortcode('[wpshop_products pid="' . $products_id . '"]')));
642 642
 			}
643 643
 		}
644 644
 		return $output;
645 645
 	}
646 646
 
647
-	function get_order_list_for_customer( $customer_id ) {
647
+	function get_order_list_for_customer($customer_id) {
648 648
 		global $wpdb;
649 649
 		$output = '';
650 650
 
651
-		if( !empty($customer_id) ) {
652
-			 $query = $wpdb->prepare( 'SELECT *
653
-							 		   FROM ' .$wpdb->posts. '
651
+		if (!empty($customer_id)) {
652
+			 $query = $wpdb->prepare('SELECT *
653
+							 		   FROM ' .$wpdb->posts . '
654 654
 							 		   WHERE post_author = %d
655
-							 		   AND post_type = %s', $customer_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
656
-			 $orders = $wpdb->get_results( $query );
655
+							 		   AND post_type = %s', $customer_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
656
+			 $orders = $wpdb->get_results($query);
657 657
 
658
-			 foreach( $orders as $order ) {
658
+			 foreach ($orders as $order) {
659 659
 
660 660
 			 }
661 661
 		}
662 662
 
663 663
 		return $output;
664 664
 	}
665
-	static function display_customer_pay_quotation( $state, $oid ) {
666
-		$label = ( ( $state ) ? __('Invalid quotation', 'wpshop') : __('Valid quotation', 'wpshop') );
667
-		$btn = '<p><a role="button" data-nonce="' . wp_create_nonce( 'wps_quotation_is_payable_by_customer' ) . '" class="wps-bton-' . ( ( $state ) ? 'third' : 'second' ) . '-mini-rounded quotation_is_payable_by_customer" href="#" >'.$label.'</a></p>';
668
-		if( $state ) {
665
+	static function display_customer_pay_quotation($state, $oid) {
666
+		$label = (($state) ? __('Invalid quotation', 'wpshop') : __('Valid quotation', 'wpshop'));
667
+		$btn = '<p><a role="button" data-nonce="' . wp_create_nonce('wps_quotation_is_payable_by_customer') . '" class="wps-bton-' . (($state) ? 'third' : 'second') . '-mini-rounded quotation_is_payable_by_customer" href="#" >' . $label . '</a></p>';
668
+		if ($state) {
669 669
 			//$btn .= '<a target="_blank" href="' . admin_url( 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $oid . '&is_link=link' ) . '">' . __( 'Pay link', 'wpshop' ) . '</a>';
670
-			$btn .= '<span><input id="wps_direct_link_url" type="text" value="' . wpshop_checkout::wps_direct_payment_link_url( $oid ) . '"/><a class="button" data-copy-target="#wps_direct_link_url" title="' . __( 'Copy', 'wpshop' ) . '"><span class="dashicons dashicons-clipboard"></span></a><a data-nonce="' . wp_create_nonce( 'wps_send_direct_payment_link' ) . '" role="button" class="button" href="#" title="' . __( 'Send by mail', 'wpshop' ) . '"><span class="dashicons dashicons-email"></span></a></span><span>' . sprintf( __( 'Link is valid until %s', 'wpshop' ), mysql2date( get_option( 'date_format' ), date_format( date_create( date('Y-m') . ' + 2month - 1day' ), 'Y-m-d H:i:s' ), true ) ) . '</span>';
670
+			$btn .= '<span><input id="wps_direct_link_url" type="text" value="' . wpshop_checkout::wps_direct_payment_link_url($oid) . '"/><a class="button" data-copy-target="#wps_direct_link_url" title="' . __('Copy', 'wpshop') . '"><span class="dashicons dashicons-clipboard"></span></a><a data-nonce="' . wp_create_nonce('wps_send_direct_payment_link') . '" role="button" class="button" href="#" title="' . __('Send by mail', 'wpshop') . '"><span class="dashicons dashicons-email"></span></a></span><span>' . sprintf(__('Link is valid until %s', 'wpshop'), mysql2date(get_option('date_format'), date_format(date_create(date('Y-m') . ' + 2month - 1day'), 'Y-m-d H:i:s'), true)) . '</span>';
671 671
 		}
672 672
 		return $btn;
673 673
 	}
Please login to merge, or discard this patch.
includes/librairies/catalog/products.class.php 2 patches
Indentation   +3124 added lines, -3124 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' => false,
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' => false,
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,791 +300,791 @@  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')));
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')));
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):
803
-                        $criteria .= '<option value="' . $c['code'] . '">' . __($c['frontend_label'], 'wpshop') . '</option>';
804
-                    endforeach;
805
-                    $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
806
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
807
-                    unset($sub_tpl_component);
808
-                }
809
-
810
-                if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
811
-                    $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
812
-                    $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
813
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component);
814
-                } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
815
-                    $sub_template_part = 'product_listing_sorting_criteria_hidden';
816
-                    $sub_tpl_component = array();
817
-                    $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
818
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
819
-                    unset($sub_tpl_component);
820
-
821
-                    $template_part = 'product_listing_sorting_hidden';
822
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
823
-                }
824
-            }
825
-            unset($tpl_component);
826
-
827
-            if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
828
-                $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
829
-            } else {
830
-                $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>';
831
-            }
832
-        } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
833
-            $string = __('There is nothing to output here', 'wpshop');
834
-        }
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
+						$criteria .= '<option value="' . $c['code'] . '">' . __($c['frontend_label'], 'wpshop') . '</option>';
804
+					endforeach;
805
+					$sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
806
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
807
+					unset($sub_tpl_component);
808
+				}
835 809
 
836
-        return do_shortcode($string);
837
-    }
810
+				if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
811
+					$tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
812
+					$tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
813
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component);
814
+				} else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
815
+					$sub_template_part = 'product_listing_sorting_criteria_hidden';
816
+					$sub_tpl_component = array();
817
+					$sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
818
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
819
+					unset($sub_tpl_component);
820
+
821
+					$template_part = 'product_listing_sorting_hidden';
822
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
823
+				}
824
+			}
825
+			unset($tpl_component);
838 826
 
839
-    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)
840
-    {
841
-        global $wpdb;
827
+			if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
828
+				$string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
829
+			} else {
830
+				$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>';
831
+			}
832
+		} else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
833
+			$string = __('There is nothing to output here', 'wpshop');
834
+		}
842 835
 
843
-        $string = '<span id="wpshop_loading">&nbsp;</span>';
844
-        $have_results = false;
845
-        $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
836
+		return do_shortcode($string);
837
+	}
846 838
 
847
-        /** Check if Discount are activated */
848
-        $discount_option = get_option('wpshop_catalog_product_option');
839
+	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)
840
+	{
841
+		global $wpdb;
849 842
 
850
-        if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
851
-            $criteria = 'wpshop_displayed_price';
852
-        }
843
+		$string = '<span id="wpshop_loading">&nbsp;</span>';
844
+		$have_results = false;
845
+		$display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
853 846
 
854
-        $query = array(
855
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
856
-            'order' => $order,
857
-            'posts_per_page' => $products_per_page,
858
-            'paged' => $page_number,
859
-            'post_status' => 'publish',
860
-        );
861
-
862
-        // If the limit is greater than zero, hide pagination and change posts_per_page var
863
-        if ($nb_of_product_limit > 0) {
864
-            $query['posts_per_page'] = $nb_of_product_limit;
865
-            unset($query['paged']);
866
-        }
867
-        if (!empty($pid)) {
868
-            if (!is_array($pid)) {
869
-                $pid = explode(',', $pid);
870
-            }
847
+		/** Check if Discount are activated */
848
+		$discount_option = get_option('wpshop_catalog_product_option');
871 849
 
872
-            $query['post__in'] = $pid;
873
-        }
874
-        if (!empty($cid)) {
875
-            $cid = explode(',', $cid);
876
-            $query['tax_query'] = array(array(
877
-                'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
878
-                'field' => 'id',
879
-                'terms' => $cid,
880
-                'operator' => 'IN',
881
-            ));
882
-        }
883
-        if ($criteria != null) {
884
-            switch ($criteria) {
885
-                case 'creator':
886
-                case 'author':
887
-                    $query['author'] = get_current_user_id();
888
-                    break;
889
-                case 'none':
890
-                case 'ID':
891
-                case 'title':
892
-                case 'date':
893
-                case 'modified':
894
-                case 'relevance':
895
-                case 'post__in':
896
-                case 'rand':
897
-                    $query['orderby'] = $criteria;
898
-                    break;
899
-                default:
900
-                    if (!empty($pid)) {
901
-                        $post_meta = get_post_meta($pid, '_' . $criteria, true);
902
-                    } else {
903
-                        $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
904
-                        $post_meta = $wpdb->get_var($check_meta);
905
-                    }
906
-                    if (!empty($post_meta)) {
907
-                        if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
908
-                            $query['orderby'] = 'meta_value_num';
909
-                        } else {
910
-                            $query['orderby'] = 'meta_value';
911
-                        }
912
-                        $query['meta_key'] = '_' . $criteria;
913
-                    }
914
-                    break;
915
-            }
916
-        } else {
917
-            $query['orderby'] = 'menu_order ID';
918
-        }
919
-        $post_per_page = $query['posts_per_page'];
920
-        $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
921
-        if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
922
-            $tmp_array = array();
923
-
924
-            if (empty($page_number) || $page_number == 1) {
925
-                for ($i = 0; $i < $query['posts_per_page']; $i++) {
926
-                    $tmp_array[] = $query['post__in'][$i];
927
-                }
928
-            } else {
929
-                $begin_number = (($page_number - 1) * $query['posts_per_page']);
930
-                for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
931
-                    if (!empty($query['post__in'][$i])) {
932
-                        $tmp_array[] = $query['post__in'][$i];
933
-                    }
934
-                }
935
-            }
936
-            unset($query['post__in']);
937
-            $query['post__in'] = $tmp_array;
938
-            $query['posts_per_page'] = -1;
939
-        }
850
+		if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
851
+			$criteria = 'wpshop_displayed_price';
852
+		}
940 853
 
941
-        $query['post_status'] = 'publish';
942
-
943
-        $custom_query = new WP_Query($query);
944
-
945
-        if ($custom_query->have_posts()) {
946
-            $have_results = true;
947
-
948
-            // ---------------- //
949
-            // Products listing //
950
-            // ---------------- //
951
-            $current_position = 1;
952
-            $product_list = '';
953
-            while ($custom_query->have_posts()): $custom_query->the_post();
954
-                $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
955
-                $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
956
-                $cat_id = empty($cats) ? 0 : $cats[0]->term_id;
957
-                $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
958
-                $current_position++;
959
-            endwhile;
960
-            $tpl_component = array();
961
-            $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
962
-            $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
963
-            $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
964
-            $tpl_component['PRODUCT_LIST'] = $product_list;
965
-            $tpl_component['CROSSED_OUT_PRICE'] = '';
966
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
967
-            $string = wpshop_display::display_template_element('product_list_container', $tpl_component);
968
-
969
-            // --------------------- //
970
-            // Pagination management //
971
-            // --------------------- //
972
-            if ($display_pagination) {
973
-                if ($nb_of_product_limit == 0) {
974
-
975
-                    $paginate = paginate_links(array(
976
-                        'base' => '%_%',
977
-                        'format' => '/?page_product=%#%',
978
-                        'current' => $page_number,
979
-                        'total' => $custom_query->max_num_pages,
980
-                        'type' => 'array',
981
-                        'prev_next' => false,
982
-                    ));
983
-                    if (!empty($paginate)) {
984
-                        $string .= '<ul class="pagination wps-pagination">';
985
-                        foreach ($paginate as $p) {
986
-                            $string .= '<li>' . $p . '</li>';
987
-                        }
988
-                        $string .= '</ul>';
989
-                    }
990
-                }
991
-
992
-                if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
993
-                    $paginate = paginate_links(array(
994
-                        'base' => '%_%',
995
-                        'format' => '/?page_product=%#%',
996
-                        'current' => $page_number,
997
-                        'total' => ceil(count($total_products) / $post_per_page),
998
-                        'type' => 'array',
999
-                        'prev_next' => false,
1000
-                    ));
1001
-                    if (!empty($paginate)) {
1002
-                        $string .= '<ul class="pagination wps-pagination">';
1003
-                        foreach ($paginate as $p) {
1004
-                            $string .= '<li>' . $p . '</li>';
1005
-                        }
1006
-                        $string .= '</ul>';
1007
-                    }
1008
-                }
1009
-            }
854
+		$query = array(
855
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
856
+			'order' => $order,
857
+			'posts_per_page' => $products_per_page,
858
+			'paged' => $page_number,
859
+			'post_status' => 'publish',
860
+		);
861
+
862
+		// If the limit is greater than zero, hide pagination and change posts_per_page var
863
+		if ($nb_of_product_limit > 0) {
864
+			$query['posts_per_page'] = $nb_of_product_limit;
865
+			unset($query['paged']);
866
+		}
867
+		if (!empty($pid)) {
868
+			if (!is_array($pid)) {
869
+				$pid = explode(',', $pid);
870
+			}
1010 871
 
1011
-        }
1012
-        wp_reset_query(); // important
872
+			$query['post__in'] = $pid;
873
+		}
874
+		if (!empty($cid)) {
875
+			$cid = explode(',', $cid);
876
+			$query['tax_query'] = array(array(
877
+				'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
878
+				'field' => 'id',
879
+				'terms' => $cid,
880
+				'operator' => 'IN',
881
+			));
882
+		}
883
+		if ($criteria != null) {
884
+			switch ($criteria) {
885
+				case 'creator':
886
+				case 'author':
887
+					$query['author'] = get_current_user_id();
888
+					break;
889
+				case 'none':
890
+				case 'ID':
891
+				case 'title':
892
+				case 'date':
893
+				case 'modified':
894
+				case 'relevance':
895
+				case 'post__in':
896
+				case 'rand':
897
+					$query['orderby'] = $criteria;
898
+					break;
899
+				default:
900
+					if (!empty($pid)) {
901
+						$post_meta = get_post_meta($pid, '_' . $criteria, true);
902
+					} else {
903
+						$check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
904
+						$post_meta = $wpdb->get_var($check_meta);
905
+					}
906
+					if (!empty($post_meta)) {
907
+						if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
908
+							$query['orderby'] = 'meta_value_num';
909
+						} else {
910
+							$query['orderby'] = 'meta_value';
911
+						}
912
+						$query['meta_key'] = '_' . $criteria;
913
+					}
914
+					break;
915
+			}
916
+		} else {
917
+			$query['orderby'] = 'menu_order ID';
918
+		}
919
+		$post_per_page = $query['posts_per_page'];
920
+		$total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
921
+		if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
922
+			$tmp_array = array();
923
+
924
+			if (empty($page_number) || $page_number == 1) {
925
+				for ($i = 0; $i < $query['posts_per_page']; $i++) {
926
+					$tmp_array[] = $query['post__in'][$i];
927
+				}
928
+			} else {
929
+				$begin_number = (($page_number - 1) * $query['posts_per_page']);
930
+				for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
931
+					if (!empty($query['post__in'][$i])) {
932
+						$tmp_array[] = $query['post__in'][$i];
933
+					}
934
+				}
935
+			}
936
+			unset($query['post__in']);
937
+			$query['post__in'] = $tmp_array;
938
+			$query['posts_per_page'] = -1;
939
+		}
1013 940
 
1014
-        return array($have_results, $string);
1015
-    }
941
+		$query['post_status'] = 'publish';
942
+
943
+		$custom_query = new WP_Query($query);
944
+
945
+		if ($custom_query->have_posts()) {
946
+			$have_results = true;
947
+
948
+			// ---------------- //
949
+			// Products listing //
950
+			// ---------------- //
951
+			$current_position = 1;
952
+			$product_list = '';
953
+			while ($custom_query->have_posts()): $custom_query->the_post();
954
+				$cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
955
+				$cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
956
+				$cat_id = empty($cats) ? 0 : $cats[0]->term_id;
957
+				$product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
958
+				$current_position++;
959
+			endwhile;
960
+			$tpl_component = array();
961
+			$tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
962
+			$tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
963
+			$tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
964
+			$tpl_component['PRODUCT_LIST'] = $product_list;
965
+			$tpl_component['CROSSED_OUT_PRICE'] = '';
966
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
967
+			$string = wpshop_display::display_template_element('product_list_container', $tpl_component);
968
+
969
+			// --------------------- //
970
+			// Pagination management //
971
+			// --------------------- //
972
+			if ($display_pagination) {
973
+				if ($nb_of_product_limit == 0) {
974
+
975
+					$paginate = paginate_links(array(
976
+						'base' => '%_%',
977
+						'format' => '/?page_product=%#%',
978
+						'current' => $page_number,
979
+						'total' => $custom_query->max_num_pages,
980
+						'type' => 'array',
981
+						'prev_next' => false,
982
+					));
983
+					if (!empty($paginate)) {
984
+						$string .= '<ul class="pagination wps-pagination">';
985
+						foreach ($paginate as $p) {
986
+							$string .= '<li>' . $p . '</li>';
987
+						}
988
+						$string .= '</ul>';
989
+					}
990
+				}
1016 991
 
1017
-    /**
1018
-     * Update quantity for a product
1019
-     * @param integer $product_id The product we want to update quantity for
1020
-     * @param decimal $qty The new quantity
1021
-     */
1022
-    public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1023
-    {
1024
-        global $wpdb;
1025
-
1026
-        $product = self::get_product_data($product_id);
1027
-        /** Check if there is variation ***/
1028
-        if (!empty($variation_id) && $variation_id != $product_id) {
1029
-            $variation_post_type = get_post_type($variation_id);
1030
-            if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1031
-                /** Check if variation def is combined **/
1032
-                $variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1033
-                if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1034
-                    /** Get post meta of variation */
1035
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1036
-                    if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1037
-                        $product = self::get_product_data($variation_id);
1038
-                        $product_id = $variation_id;
1039
-                    }
1040
-                }
1041
-            }
1042
-        }
992
+				if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
993
+					$paginate = paginate_links(array(
994
+						'base' => '%_%',
995
+						'format' => '/?page_product=%#%',
996
+						'current' => $page_number,
997
+						'total' => ceil(count($total_products) / $post_per_page),
998
+						'type' => 'array',
999
+						'prev_next' => false,
1000
+					));
1001
+					if (!empty($paginate)) {
1002
+						$string .= '<ul class="pagination wps-pagination">';
1003
+						foreach ($paginate as $p) {
1004
+							$string .= '<li>' . $p . '</li>';
1005
+						}
1006
+						$string .= '</ul>';
1007
+					}
1008
+				}
1009
+			}
1010
+
1011
+		}
1012
+		wp_reset_query(); // important
1013
+
1014
+		return array($have_results, $string);
1015
+	}
1016
+
1017
+	/**
1018
+	 * Update quantity for a product
1019
+	 * @param integer $product_id The product we want to update quantity for
1020
+	 * @param decimal $qty The new quantity
1021
+	 */
1022
+	public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1023
+	{
1024
+		global $wpdb;
1025
+
1026
+		$product = self::get_product_data($product_id);
1027
+		/** Check if there is variation ***/
1028
+		if (!empty($variation_id) && $variation_id != $product_id) {
1029
+			$variation_post_type = get_post_type($variation_id);
1030
+			if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1031
+				/** Check if variation def is combined **/
1032
+				$variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1033
+				if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1034
+					/** Get post meta of variation */
1035
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1036
+					if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1037
+						$product = self::get_product_data($variation_id);
1038
+						$product_id = $variation_id;
1039
+					}
1040
+				}
1041
+			}
1042
+		}
1043 1043
 
1044
-        if (!empty($product)) {
1045
-            $newQty = $product['product_stock'] - $qty;
1046
-            $value_id = 0;
1047
-            if ($newQty >= 0) {
1048
-                $query = '
1044
+		if (!empty($product)) {
1045
+			$newQty = $product['product_stock'] - $qty;
1046
+			$value_id = 0;
1047
+			if ($newQty >= 0) {
1048
+				$query = '
1049 1049
 					SELECT wp_wpshop__attribute_value_decimal.value_id
1050 1050
 					FROM wp_wpshop__attribute_value_decimal
1051 1051
 					LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
1052 1052
 					WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
1053 1053
 					LIMIT 1
1054 1054
 				';
1055
-                $value_id = $wpdb->get_var($query);
1056
-                $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1057
-            }
1058
-            // Historic
1059
-            $attribute_histo_content = array();
1060
-            $attribute_histo_content['status'] = 'valid';
1061
-            $attribute_histo_content['creation_date'] = current_time('mysql', 0);
1062
-            $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1063
-            $attribute_histo_content['original_value_id'] = $value_id;
1064
-            $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1065
-            $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1066
-            $attribute_histo_content['attribute_id'] = $stock_atribute->id;
1067
-            $attribute_histo_content['entity_id'] = $product_id;
1068
-            $attribute_histo_content['value'] = $product['product_stock'];
1069
-            $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1070
-            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1071
-
1072
-            $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1073
-            $product_meta['product_stock'] = $newQty;
1074
-            update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1075
-        }
1076
-    }
1055
+				$value_id = $wpdb->get_var($query);
1056
+				$update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1057
+			}
1058
+			// Historic
1059
+			$attribute_histo_content = array();
1060
+			$attribute_histo_content['status'] = 'valid';
1061
+			$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1062
+			$attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1063
+			$attribute_histo_content['original_value_id'] = $value_id;
1064
+			$attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1065
+			$stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1066
+			$attribute_histo_content['attribute_id'] = $stock_atribute->id;
1067
+			$attribute_histo_content['entity_id'] = $product_id;
1068
+			$attribute_histo_content['value'] = $product['product_stock'];
1069
+			$attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1070
+			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1071
+
1072
+			$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1073
+			$product_meta['product_stock'] = $newQty;
1074
+			update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1075
+		}
1076
+	}
1077 1077
 
1078
-    /**
1079
-     * Retrieve an array with complete information about a given product
1080
-     * @param integer $product_id
1081
-     * @param boolean $for_cart_storage
1082
-     * @return array Information about the product defined by first parameter
1083
-     */
1084
-    public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1085
-    {
1086
-        global $wpdb;
1087
-        $query = $wpdb->prepare('
1078
+	/**
1079
+	 * Retrieve an array with complete information about a given product
1080
+	 * @param integer $product_id
1081
+	 * @param boolean $for_cart_storage
1082
+	 * @return array Information about the product defined by first parameter
1083
+	 */
1084
+	public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1085
+	{
1086
+		global $wpdb;
1087
+		$query = $wpdb->prepare('
1088 1088
 			SELECT P.*, PM.meta_value AS attribute_set_id
1089 1089
 			FROM ' . $wpdb->posts . ' AS P
1090 1090
 				INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID)
@@ -1096,398 +1096,398 @@  discard block
 block discarded – undo
1096 1096
 			LIMIT 1
1097 1097
 		', $product_id);
1098 1098
 
1099
-        $product = $wpdb->get_row($query);
1100
-
1101
-        $product_data = array();
1102
-        $product_meta = array();
1103
-
1104
-        if (!empty($product)) {
1105
-            $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1106
-            $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1107
-            $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1108
-            $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1109
-
1110
-            $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1111
-            $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1112
-            $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1113
-            $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1114
-
1115
-            $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1116
-
1117
-            $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);
1118
-            if (!empty($data)) {
1119
-                foreach ($data as $attribute) {
1120
-                    $data_type = 'attribute_value_' . $attribute->data_type;
1121
-                    $value = $attribute->$data_type;
1122
-                    if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1123
-                        $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1124
-                    }
1125
-
1126
-                    /** Special traitment regarding attribute_code    */
1127
-                    switch ($attribute->attribute_code) {
1128
-                        case 'product_weight':
1129
-                            $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1130
-                            if (!empty($default_weight_unity)) {
1131
-                                $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1132
-                                $unity = $wpdb->get_var($query);
1133
-                                if ($unity == 'kg') {
1134
-                                    $value *= 1000;
1135
-                                }
1136
-
1137
-                            }
1138
-                            break;
1139
-                        default:
1140
-                            $value = !empty($value) ? $value : 0;
1141
-                            break;
1142
-                    }
1143
-                    $product_data[$attribute->attribute_code] = $value;
1144
-
1145
-                    if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1146
-                        $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1147
-                        if (!empty($meta)) {
1148
-                            $product_meta[$attribute->attribute_code] = $meta;
1149
-                        }
1150
-                    }
1151
-
1152
-                    if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1153
-                        $product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1154
-                    }
1155
-                    if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1156
-                        $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1157
-                    }
1158
-                }
1159
-            } else {
1160
-
1161
-            }
1162
-
1163
-            /**    Get datas about product options    */
1164
-            if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1165
-                $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1166
-
1167
-                foreach ($variation_details as $attribute_code => $attribute_value) {
1168
-                    $variation_id = $attribute_value;
1169
-                    $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1170
-
1171
-                    $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));
1172
-                    $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1173
-                    switch ($attribute_definition->backend_input) {
1174
-                        case 'select':
1175
-                        case 'multiple-select':
1176
-                        case 'radio':
1177
-                        case 'checkbox':
1178
-                            $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1179
-                            break;
1180
-                    }
1181
-                    $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1182
-                    $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1183
-                }
1184
-            }
1185
-
1186
-            $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1187
-
1188
-            /** Get the display definition for the current product for checking custom display    */
1189
-            $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1190
-        }
1099
+		$product = $wpdb->get_row($query);
1100
+
1101
+		$product_data = array();
1102
+		$product_meta = array();
1103
+
1104
+		if (!empty($product)) {
1105
+			$product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1106
+			$product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1107
+			$product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1108
+			$product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1109
+
1110
+			$product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1111
+			$product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1112
+			$product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1113
+			$product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1114
+
1115
+			$product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1116
+
1117
+			$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);
1118
+			if (!empty($data)) {
1119
+				foreach ($data as $attribute) {
1120
+					$data_type = 'attribute_value_' . $attribute->data_type;
1121
+					$value = $attribute->$data_type;
1122
+					if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1123
+						$value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1124
+					}
1125
+
1126
+					/** Special traitment regarding attribute_code    */
1127
+					switch ($attribute->attribute_code) {
1128
+						case 'product_weight':
1129
+							$default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1130
+							if (!empty($default_weight_unity)) {
1131
+								$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1132
+								$unity = $wpdb->get_var($query);
1133
+								if ($unity == 'kg') {
1134
+									$value *= 1000;
1135
+								}
1136
+
1137
+							}
1138
+							break;
1139
+						default:
1140
+							$value = !empty($value) ? $value : 0;
1141
+							break;
1142
+					}
1143
+					$product_data[$attribute->attribute_code] = $value;
1144
+
1145
+					if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1146
+						$meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1147
+						if (!empty($meta)) {
1148
+							$product_meta[$attribute->attribute_code] = $meta;
1149
+						}
1150
+					}
1151
+
1152
+					if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1153
+						$product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1154
+					}
1155
+					if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1156
+						$product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1157
+					}
1158
+				}
1159
+			} else {
1191 1160
 
1192
-        return $product_data;
1193
-    }
1161
+			}
1194 1162
 
1195
-    /**
1196
-     * Add a product into the db. This function is used for the EDI
1197
-     * @param $name Name of the product
1198
-     * @param $description Description of the product
1199
-     * @param $attrs List of the attributes and values of the product
1200
-     * @return boolean
1201
-     */
1202
-    public function addProduct($name, $description, $attrs = array())
1203
-    {
1204
-        $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1205
-        return $new_product[0];
1206
-    }
1163
+			/**    Get datas about product options    */
1164
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1165
+				$variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1166
+
1167
+				foreach ($variation_details as $attribute_code => $attribute_value) {
1168
+					$variation_id = $attribute_value;
1169
+					$attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1170
+
1171
+					$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));
1172
+					$product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1173
+					switch ($attribute_definition->backend_input) {
1174
+						case 'select':
1175
+						case 'multiple-select':
1176
+						case 'radio':
1177
+						case 'checkbox':
1178
+							$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1179
+							break;
1180
+					}
1181
+					$product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1182
+					$product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1183
+				}
1184
+			}
1207 1185
 
1208
-    /**
1209
-     * Retrieve a product listing
1210
-     * @param boolean $formated If the output have to be formated or not
1211
-     * @param string $product_search Optionnal Define a search term for request
1212
-     * @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
1213
-     */
1214
-    public static function product_list($formated = false, $product_search = null)
1215
-    {
1216
-        global $wpdb;
1217
-
1218
-        $query_extra_params = $query_extra_params_value = '';
1219
-        if (!empty($product_search)) {
1220
-            $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1221
-            if (is_array($product_search)) {
1222
-                $query_extra_params = " AND ID IN (%s)";
1223
-                $query_extra_params_value = implode(",", $product_search);
1224
-            }
1225
-        }
1186
+			$product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1187
+
1188
+			/** Get the display definition for the current product for checking custom display    */
1189
+			$product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1190
+		}
1191
+
1192
+		return $product_data;
1193
+	}
1194
+
1195
+	/**
1196
+	 * Add a product into the db. This function is used for the EDI
1197
+	 * @param $name Name of the product
1198
+	 * @param $description Description of the product
1199
+	 * @param $attrs List of the attributes and values of the product
1200
+	 * @return boolean
1201
+	 */
1202
+	public function addProduct($name, $description, $attrs = array())
1203
+	{
1204
+		$new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1205
+		return $new_product[0];
1206
+	}
1207
+
1208
+	/**
1209
+	 * Retrieve a product listing
1210
+	 * @param boolean $formated If the output have to be formated or not
1211
+	 * @param string $product_search Optionnal Define a search term for request
1212
+	 * @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
1213
+	 */
1214
+	public static function product_list($formated = false, $product_search = null)
1215
+	{
1216
+		global $wpdb;
1217
+
1218
+		$query_extra_params = $query_extra_params_value = '';
1219
+		if (!empty($product_search)) {
1220
+			$query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1221
+			if (is_array($product_search)) {
1222
+				$query_extra_params = " AND ID IN (%s)";
1223
+				$query_extra_params_value = implode(",", $product_search);
1224
+			}
1225
+		}
1226 1226
 
1227
-        $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);
1228
-        $data = $wpdb->get_results($query);
1227
+		$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);
1228
+		$data = $wpdb->get_results($query);
1229 1229
 
1230
-        /*
1230
+		/*
1231 1231
          * Make some arangement on output if parameter is given
1232 1232
          */
1233
-        if ($formated) {
1234
-            $product_string = '';
1235
-            foreach ($data as $d) {
1236
-                $product_string .= '
1233
+		if ($formated) {
1234
+			$product_string = '';
1235
+			foreach ($data as $d) {
1236
+				$product_string .= '
1237 1237
 					<li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" >
1238 1238
 						<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>
1239 1239
 					</li>';
1240
-            }
1241
-        }
1240
+			}
1241
+		}
1242 1242
 
1243
-        return $formated ? $product_string : $data;
1244
-    }
1243
+		return $formated ? $product_string : $data;
1244
+	}
1245 1245
 
1246
-    /**
1247
-     * Enregistrement des données pour le produit
1248
-     */
1249
-    public function save_product_custom_informations($post_id, $data_to_save = array())
1250
-    {
1251
-        global $wpdb;
1252
-
1253
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1254
-        // Apply a filter to extra actions
1255
-        $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1256
-
1257
-        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"))) {
1258
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1259
-                /*    Fill the product reference automatically if nothing is sent    */
1260
-                if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1261
-                    $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1262
-                    $last_ref = $wpdb->get_var($query);
1263
-                    $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;
1264
-                } else {
1265
-                    /* Check if the product reference existing in the database */
1266
-                    $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1267
-                    $query = $wpdb->prepare(
1268
-                        "SELECT value_id
1246
+	/**
1247
+	 * Enregistrement des données pour le produit
1248
+	 */
1249
+	public function save_product_custom_informations($post_id, $data_to_save = array())
1250
+	{
1251
+		global $wpdb;
1252
+
1253
+		$data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1254
+		// Apply a filter to extra actions
1255
+		$data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1256
+
1257
+		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"))) {
1258
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1259
+				/*    Fill the product reference automatically if nothing is sent    */
1260
+				if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1261
+					$query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1262
+					$last_ref = $wpdb->get_var($query);
1263
+					$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;
1264
+				} else {
1265
+					/* Check if the product reference existing in the database */
1266
+					$ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1267
+					$query = $wpdb->prepare(
1268
+						"SELECT value_id
1269 1269
 						FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
1270 1270
 							INNER JOIN {$wpdb->posts} ON ( ID = entity_id )
1271 1271
 						WHERE value = %s
1272 1272
 							AND entity_id != %d
1273 1273
 							AND entity_type_id = %d"
1274
-                        , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1275
-                    $existing_reference = $wpdb->get_var($query);
1276
-
1277
-                    /* If this product reference exist -> Create a new product reference */
1278
-                    if ($wpdb->num_rows > 0) {
1279
-                        $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1280
-                        $last_ref = $wpdb->get_var($query);
1281
-                        $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;
1282
-                    }
1283
-                }
1284
-
1285
-                /*    Save the attributes values into wpshop eav database    */
1286
-                $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1287
-                $lang = WPSHOP_CURRENT_LOCALE;
1288
-                if (!empty($data_to_save['icl_post_language'])) {
1289
-                    $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1290
-                    $lang = $wpdb->get_var($query);
1291
-                }
1292
-                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);
1293
-
1294
-                /*    Update product price looking for shop parameters    */
1295
-                wpshop_products::calculate_price($data_to_save['post_ID']);
1296
-
1297
-                /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1298
-                $productMetaDatas = array();
1299
-                foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1300
-                    foreach ($attributeValues as $attributeCode => $attributeValue) {
1301
-                        if ($attributeCode == 'product_attribute_set_id') {
1302
-                            /*    Update the attribute set id for the current product    */
1303
-                            update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1304
-                        }
1305
-                        if ($attributeType == 'decimal') {
1306
-                            $attributeValue = str_replace(',', '.', $attributeValue);
1307
-                        }
1308
-                        if (($attributeType == 'integer') && !is_array($attributeValue)) {
1309
-                            $attributeValue = (int) $attributeValue;
1310
-                        }
1311
-                        $productMetaDatas[$attributeCode] = $attributeValue;
1312
-                    }
1313
-                }
1314
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1315
-            }
1316
-
1317
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1318
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1319
-            } else if ($data_to_save['action'] != 'autosave') {
1320
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1321
-            }
1322
-
1323
-            $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1324
-            if (empty($product['product_id'])) {
1325
-                $product['product_id'] = $data_to_save['post_ID'];
1326
-            }
1327
-            $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1328
-            update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1329
-
1330
-            /**    Save product variation    */
1331
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1332
-                foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1333
-
1334
-                    foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1335
-                        $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1336
-                        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])) {
1337
-                            $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;
1338
-                        }
1339
-                    }
1340
-                    $lang = WPSHOP_CURRENT_LOCALE;
1341
-                    if (!empty($data_to_save['icl_post_language'])) {
1342
-                        $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1343
-                        $lang = $wpdb->get_var($query);
1344
-                    }
1345
-                    wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1346
-
1347
-                    /**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1348
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1349
-                    if (!empty($variation_metadata)) {
1350
-                        $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1351
-                        if (!empty($attributes_list)) {
1352
-                            foreach ($attributes_list as $attribute) {
1353
-                                $value_key = 'attribute_value_' . $attribute->data_type;
1354
-                                $attributeValue = $attribute->$value_key;
1355
-                                if ($attribute->data_type == 'decimal') {
1356
-                                    $attributeValue = str_replace(',', '.', $attribute->$value_key);
1357
-                                }
1358
-                                if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1359
-                                    $attributeValue = (int) $attribute->$value_key;
1360
-                                }
1361
-                                $variation_metadata[$attribute->code] = $attribute->$value_key;
1362
-                            }
1363
-                        }
1364
-                    }
1365
-
1366
-                    foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1367
-                        foreach ($attributeValues as $attributeCode => $attributeValue) {
1368
-                            if ($attributeType == 'decimal') {
1369
-                                $attributeValue = str_replace(',', '.', $attributeValue);
1370
-                            }
1371
-                            if (($attributeType == 'integer') && !is_array($attributeValue)) {
1372
-                                $attributeValue = (int) $attributeValue;
1373
-                            }
1374
-                            $variation_metadata[$attributeCode] = $attributeValue;
1375
-                        }
1376
-                    }
1377
-                    update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1378
-
1379
-                    /** Save attached picture id **/
1380
-                    $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']) : '';
1381
-                    $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1382
-
1383
-                    /*    Update product price looking for shop parameters    */
1384
-                    wpshop_products::calculate_price($variation_id);
1385
-                }
1386
-            }
1387
-
1388
-            /*    Update the related products list*/
1389
-            if (!empty($data_to_save['related_products_list'])) {
1390
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1391
-            } else if ($data_to_save['action'] != 'autosave') {
1392
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1393
-            }
1394
-            /*    Update the provider list*/
1395
-            if (!empty($data_to_save['provider_list'])) {
1396
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1397
-            } else if ($data_to_save['action'] != 'autosave') {
1398
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1399
-            }
1400
-
1401
-            /*    Update product options    */
1402
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1403
-                update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1404
-            } else if ($data_to_save['action'] != 'autosave') {
1405
-                delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1406
-            }
1407
-
1408
-            /** Add flag on variations to check which type of variation **/
1409
-            $check_product_have_variations = self::get_variation($post_id);
1410
-            if (!empty($check_product_have_variations)) {
1411
-                $variation_flag = self::check_variation_type($post_id);
1412
-                $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1413
-                $variation_defining['variation_type'] = $variation_flag;
1414
-                update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1415
-            }
1416
-            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);
1417
-        }
1274
+						, $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1275
+					$existing_reference = $wpdb->get_var($query);
1276
+
1277
+					/* If this product reference exist -> Create a new product reference */
1278
+					if ($wpdb->num_rows > 0) {
1279
+						$query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1280
+						$last_ref = $wpdb->get_var($query);
1281
+						$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;
1282
+					}
1283
+				}
1418 1284
 
1419
-        flush_rewrite_rules();
1420
-    }
1285
+				/*    Save the attributes values into wpshop eav database    */
1286
+				$update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1287
+				$lang = WPSHOP_CURRENT_LOCALE;
1288
+				if (!empty($data_to_save['icl_post_language'])) {
1289
+					$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1290
+					$lang = $wpdb->get_var($query);
1291
+				}
1292
+				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);
1293
+
1294
+				/*    Update product price looking for shop parameters    */
1295
+				wpshop_products::calculate_price($data_to_save['post_ID']);
1296
+
1297
+				/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1298
+				$productMetaDatas = array();
1299
+				foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1300
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
1301
+						if ($attributeCode == 'product_attribute_set_id') {
1302
+							/*    Update the attribute set id for the current product    */
1303
+							update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1304
+						}
1305
+						if ($attributeType == 'decimal') {
1306
+							$attributeValue = str_replace(',', '.', $attributeValue);
1307
+						}
1308
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1309
+							$attributeValue = (int) $attributeValue;
1310
+						}
1311
+						$productMetaDatas[$attributeCode] = $attributeValue;
1312
+					}
1313
+				}
1314
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1315
+			}
1421 1316
 
1422
-    /**
1423
-     * Return the variation type
1424
-     * @param integer $post_id
1425
-     * @return string
1426
-     */
1427
-    public function check_variation_type($post_id)
1428
-    {
1429
-        $variation_type = 'single';
1430
-        if (!empty($variation_type)) {
1431
-            $variations = self::get_variation($post_id);
1432
-            if (!empty($variations)) {
1433
-                foreach ($variations as $variation_id => $variation_data) {
1434
-                    if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1435
-                        return 'single';
1436
-                    } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1437
-                        $variation_type = 'combined';
1438
-                    }
1439
-                }
1440
-            }
1441
-        }
1442
-        return $variation_type;
1443
-    }
1317
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1318
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1319
+			} else if ($data_to_save['action'] != 'autosave') {
1320
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1321
+			}
1444 1322
 
1445
-    /**
1446
-     * Allows to define a specific permalink for each product by checking the parent categories
1447
-     *
1448
-     * @param mixed $permalink The actual permalink of the element
1449
-     * @param object $post The post we want to set the permalink for
1450
-     * @param void
1451
-     *
1452
-     * @return mixed The new permalink for the current element
1453
-     */
1454
-    public static function set_product_permalink($permalink, $post, $unknown)
1455
-    {
1456
-        $options = get_option('wpshop_catalog_product_option', array());
1457
-
1458
-        if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1459
-            if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1460
-                return $permalink;
1461
-            } else {
1462
-                $options_cats = get_option('wpshop_catalog_categories_option', array());
1463
-                $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1464
-                if (empty($product_categories)) {
1465
-                    $product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1466
-                } else {
1467
-                    $product_category_slug = $product_categories[0]->slug;
1468
-                }
1469
-                $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1470
-            }
1471
-        }
1323
+			$product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1324
+			if (empty($product['product_id'])) {
1325
+				$product['product_id'] = $data_to_save['post_ID'];
1326
+			}
1327
+			$price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1328
+			update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1329
+
1330
+			/**    Save product variation    */
1331
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1332
+				foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1333
+
1334
+					foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1335
+						$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1336
+						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])) {
1337
+							$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;
1338
+						}
1339
+					}
1340
+					$lang = WPSHOP_CURRENT_LOCALE;
1341
+					if (!empty($data_to_save['icl_post_language'])) {
1342
+						$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1343
+						$lang = $wpdb->get_var($query);
1344
+					}
1345
+					wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1346
+
1347
+					/**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1348
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1349
+					if (!empty($variation_metadata)) {
1350
+						$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1351
+						if (!empty($attributes_list)) {
1352
+							foreach ($attributes_list as $attribute) {
1353
+								$value_key = 'attribute_value_' . $attribute->data_type;
1354
+								$attributeValue = $attribute->$value_key;
1355
+								if ($attribute->data_type == 'decimal') {
1356
+									$attributeValue = str_replace(',', '.', $attribute->$value_key);
1357
+								}
1358
+								if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1359
+									$attributeValue = (int) $attribute->$value_key;
1360
+								}
1361
+								$variation_metadata[$attribute->code] = $attribute->$value_key;
1362
+							}
1363
+						}
1364
+					}
1365
+
1366
+					foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1367
+						foreach ($attributeValues as $attributeCode => $attributeValue) {
1368
+							if ($attributeType == 'decimal') {
1369
+								$attributeValue = str_replace(',', '.', $attributeValue);
1370
+							}
1371
+							if (($attributeType == 'integer') && !is_array($attributeValue)) {
1372
+								$attributeValue = (int) $attributeValue;
1373
+							}
1374
+							$variation_metadata[$attributeCode] = $attributeValue;
1375
+						}
1376
+					}
1377
+					update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1378
+
1379
+					/** Save attached picture id **/
1380
+					$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']) : '';
1381
+					$selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1382
+
1383
+					/*    Update product price looking for shop parameters    */
1384
+					wpshop_products::calculate_price($variation_id);
1385
+				}
1386
+			}
1387
+
1388
+			/*    Update the related products list*/
1389
+			if (!empty($data_to_save['related_products_list'])) {
1390
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1391
+			} else if ($data_to_save['action'] != 'autosave') {
1392
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1393
+			}
1394
+			/*    Update the provider list*/
1395
+			if (!empty($data_to_save['provider_list'])) {
1396
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1397
+			} else if ($data_to_save['action'] != 'autosave') {
1398
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1399
+			}
1400
+
1401
+			/*    Update product options    */
1402
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1403
+				update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1404
+			} else if ($data_to_save['action'] != 'autosave') {
1405
+				delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1406
+			}
1407
+
1408
+			/** Add flag on variations to check which type of variation **/
1409
+			$check_product_have_variations = self::get_variation($post_id);
1410
+			if (!empty($check_product_have_variations)) {
1411
+				$variation_flag = self::check_variation_type($post_id);
1412
+				$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1413
+				$variation_defining['variation_type'] = $variation_flag;
1414
+				update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1415
+			}
1416
+			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);
1417
+		}
1418
+
1419
+		flush_rewrite_rules();
1420
+	}
1421
+
1422
+	/**
1423
+	 * Return the variation type
1424
+	 * @param integer $post_id
1425
+	 * @return string
1426
+	 */
1427
+	public function check_variation_type($post_id)
1428
+	{
1429
+		$variation_type = 'single';
1430
+		if (!empty($variation_type)) {
1431
+			$variations = self::get_variation($post_id);
1432
+			if (!empty($variations)) {
1433
+				foreach ($variations as $variation_id => $variation_data) {
1434
+					if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1435
+						return 'single';
1436
+					} elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1437
+						$variation_type = 'combined';
1438
+					}
1439
+				}
1440
+			}
1441
+		}
1442
+		return $variation_type;
1443
+	}
1444
+
1445
+	/**
1446
+	 * Allows to define a specific permalink for each product by checking the parent categories
1447
+	 *
1448
+	 * @param mixed $permalink The actual permalink of the element
1449
+	 * @param object $post The post we want to set the permalink for
1450
+	 * @param void
1451
+	 *
1452
+	 * @return mixed The new permalink for the current element
1453
+	 */
1454
+	public static function set_product_permalink($permalink, $post, $unknown)
1455
+	{
1456
+		$options = get_option('wpshop_catalog_product_option', array());
1457
+
1458
+		if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1459
+			if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1460
+				return $permalink;
1461
+			} else {
1462
+				$options_cats = get_option('wpshop_catalog_categories_option', array());
1463
+				$product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1464
+				if (empty($product_categories)) {
1465
+					$product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1466
+				} else {
1467
+					$product_category_slug = $product_categories[0]->slug;
1468
+				}
1469
+				$permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1470
+			}
1471
+		}
1472 1472
 
1473
-        return $permalink;
1473
+		return $permalink;
1474 1474
 
1475
-        //echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1475
+		//echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1476 1476
 
1477
-        //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1477
+		//wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1478 1478
 
1479
-        /*if(false) {
1479
+		/*if(false) {
1480 1480
         global $wp_query;
1481 1481
         $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1482 1482
 
1483 1483
         if(count($product_categories) == 0){            /*    Product has only one category we get the only available slug    */
1484
-        /*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1484
+		/*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1485 1485
         }
1486 1486
         elseif(count($product_categories) == 1){    /*    Product has only one category we get the only available slug    */
1487
-        /*        $product_category_slug = $product_categories[0]->slug;
1487
+		/*        $product_category_slug = $product_categories[0]->slug;
1488 1488
         }
1489 1489
         else{                                                                            /*    Product has several categories choose the slug of the we want    */
1490
-        /*        $product_category_slugs = array();
1490
+		/*        $product_category_slugs = array();
1491 1491
     foreach($product_categories as $product_category){
1492 1492
     $product_category_slugs[] = $product_category->slug;
1493 1493
     }
@@ -1497,457 +1497,457 @@  discard block
 block discarded – undo
1497 1497
     $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1498 1498
     return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID );
1499 1499
     }*/
1500
-    }
1500
+	}
1501 1501
 
1502
-    public static function set_product_request_by_name($query)
1503
-    {
1504
-        $options = get_option('wpshop_catalog_product_option', array());
1502
+	public static function set_product_request_by_name($query)
1503
+	{
1504
+		$options = get_option('wpshop_catalog_product_option', array());
1505 1505
 
1506
-        if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1507
-        //    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1508
-    }
1506
+		if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1507
+		//    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1508
+	}
1509 1509
 
1510
-    /**
1511
-     *    Define output for product
1512
-     *
1513
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1514
-     *    @param integer $product_id The product identifier we want to get and output attribute for
1515
-     *
1516
-     *    @return mixed $content The content to add or to modify the product output in frontend
1517
-     */
1518
-    public static function product_complete_sheet_output($initialContent, $product_id)
1519
-    {
1520
-        $content = $attributeContentOutput = '';
1521
-        $wps_product_ctr = new wps_product_ctr();
1522
-        /** Log number of view for the current product    */
1523
-        $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1524
-        $product_view_number++;
1525
-        update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1526
-
1527
-        /** Get product definition    */
1528
-
1529
-        $product = self::get_product_data($product_id);
1530
-        wp_cache_set('wpshop_product_data_' . $product_id, $product);
1531
-
1532
-        /** Get the product thumbnail    */
1533
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1534
-        if (has_post_thumbnail($product_id)) {
1535
-            $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1536
-            $tpl_component = array();
1537
-            $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1538
-            $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1539
-            $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1540
-            $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1541
-            if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1542
-                foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1543
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1544
-                    $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;
1545
-                }
1546
-            }
1547
-            $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;
1548
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1549
-            unset($tpl_component);
1550
-        }
1510
+	/**
1511
+	 *    Define output for product
1512
+	 *
1513
+	 *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1514
+	 *    @param integer $product_id The product identifier we want to get and output attribute for
1515
+	 *
1516
+	 *    @return mixed $content The content to add or to modify the product output in frontend
1517
+	 */
1518
+	public static function product_complete_sheet_output($initialContent, $product_id)
1519
+	{
1520
+		$content = $attributeContentOutput = '';
1521
+		$wps_product_ctr = new wps_product_ctr();
1522
+		/** Log number of view for the current product    */
1523
+		$product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1524
+		$product_view_number++;
1525
+		update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1526
+
1527
+		/** Get product definition    */
1528
+
1529
+		$product = self::get_product_data($product_id);
1530
+		wp_cache_set('wpshop_product_data_' . $product_id, $product);
1531
+
1532
+		/** Get the product thumbnail    */
1533
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1534
+		if (has_post_thumbnail($product_id)) {
1535
+			$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1536
+			$tpl_component = array();
1537
+			$tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1538
+			$tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1539
+			$tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1540
+			$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1541
+			if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1542
+				foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1543
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1544
+					$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;
1545
+				}
1546
+			}
1547
+			$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;
1548
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1549
+			unset($tpl_component);
1550
+		}
1551 1551
 
1552
-        $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1553
-
1554
-        /**    Retrieve product attributes for output    */
1555
-        $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1556
-
1557
-        /** Retrieve product price */
1558
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1559
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1560
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1561
-        $productPrice = '';
1562
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1563
-        $check_product_price = wpshop_prices::check_product_price($product);
1564
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1565
-        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)) {
1566
-            $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1567
-        }
1552
+		$product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1553
+
1554
+		/**    Retrieve product attributes for output    */
1555
+		$attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1556
+
1557
+		/** Retrieve product price */
1558
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1559
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1560
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1561
+		$productPrice = '';
1562
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1563
+		$check_product_price = wpshop_prices::check_product_price($product);
1564
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1565
+		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)) {
1566
+			$productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1567
+		}
1568 1568
 
1569
-        /** Check if there is at less 1 product in stock    */
1570
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1571
-        $productStock = ($productStock === true) ? 1 : null;
1569
+		/** Check if there is at less 1 product in stock    */
1570
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1571
+		$productStock = ($productStock === true) ? 1 : null;
1572 1572
 
1573
-        /** if !product stock check product have variation with stock **/
1573
+		/** if !product stock check product have variation with stock **/
1574 1574
 //         if ( empty($productStock) ) {
1575
-        $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1576
-        if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1577
-            $variations = wpshop_products::get_variation($product_id);
1578
-            if (!empty($variations)) {
1579
-                foreach ($variations as $variation) {
1580
-                    if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1581
-                        $productStock = 1;
1582
-                    }
1583
-                }
1584
-            }
1585
-        }
1575
+		$product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1576
+		if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1577
+			$variations = wpshop_products::get_variation($product_id);
1578
+			if (!empty($variations)) {
1579
+				foreach ($variations as $variation) {
1580
+					if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1581
+						$productStock = 1;
1582
+					}
1583
+				}
1584
+			}
1585
+		}
1586 1586
 //         }
1587 1587
 
1588
-        /** Define "Add to cart" button     */
1589
-        $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');
1590
-        $display_price_state_when_price_is_empty = true;
1591
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1592
-            $display_price_state_when_price_is_empty = false;
1593
-        } else if (!empty($productPrice)) {
1594
-            $display_price_state_when_price_is_empty = true;
1595
-        }
1596
-        $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') : '';
1597
-        $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)) : '';
1598
-
1599
-        /** Define "Ask a quotation" button    */
1600
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1601
-
1602
-        /** Template parameters    */
1603
-        $template_part = 'product_complete_tpl';
1604
-        $tpl_component = array();
1605
-
1606
-        $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1607
-        $tpl_component['PRODUCT_ID'] = $product_id;
1608
-        $tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1609
-        $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1610
-        $tpl_component['PRODUCT_GALERY_PICS'] = '';
1611
-        $tpl_component['PRODUCT_PRICE'] = $productPrice;
1612
-        $modules_option = get_option('wpshop_modules');
1613
-        $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1614
-        if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1615
-            $wps_marketing_tools = new wps_marketing_tools_ctr();
1616
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1617
-        }
1588
+		/** Define "Add to cart" button     */
1589
+		$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');
1590
+		$display_price_state_when_price_is_empty = true;
1591
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1592
+			$display_price_state_when_price_is_empty = false;
1593
+		} else if (!empty($productPrice)) {
1594
+			$display_price_state_when_price_is_empty = true;
1595
+		}
1596
+		$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') : '';
1597
+		$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)) : '';
1598
+
1599
+		/** Define "Ask a quotation" button    */
1600
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1601
+
1602
+		/** Template parameters    */
1603
+		$template_part = 'product_complete_tpl';
1604
+		$tpl_component = array();
1605
+
1606
+		$tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1607
+		$tpl_component['PRODUCT_ID'] = $product_id;
1608
+		$tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1609
+		$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1610
+		$tpl_component['PRODUCT_GALERY_PICS'] = '';
1611
+		$tpl_component['PRODUCT_PRICE'] = $productPrice;
1612
+		$modules_option = get_option('wpshop_modules');
1613
+		$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1614
+		if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1615
+			$wps_marketing_tools = new wps_marketing_tools_ctr();
1616
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1617
+		}
1618 1618
 
1619
-        /** Gallery **/
1620
-        $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1621
-
1622
-        $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'] : ''));
1623
-
1624
-        $product_new = $product_new_def['output'];
1625
-        $product_class = $product_new_def['class'];
1626
-
1627
-        $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'] : ''));
1628
-        $product_featured = $product_featured_def['output'];
1629
-        $product_class .= $product_featured_def['class'];
1630
-
1631
-        $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1632
-        $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1633
-        $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1634
-
1635
-        $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1636
-        $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1637
-        $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1638
-        $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1639
-        $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1640
-        $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1641
-        $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1642
-        $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1643
-
1644
-        /** Build template    */
1645
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1646
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1647
-            /*    Include the old way template part    */
1648
-            ob_start();
1649
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
1650
-            $content = ob_get_contents();
1651
-            ob_end_clean();
1652
-        } else {
1653
-            $content = wpshop_display::display_template_element($template_part, $tpl_component);
1654
-        }
1655
-        unset($tpl_component);
1656
-        return $content;
1657
-    }
1619
+		/** Gallery **/
1620
+		$tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1621
+
1622
+		$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'] : ''));
1623
+
1624
+		$product_new = $product_new_def['output'];
1625
+		$product_class = $product_new_def['class'];
1626
+
1627
+		$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'] : ''));
1628
+		$product_featured = $product_featured_def['output'];
1629
+		$product_class .= $product_featured_def['class'];
1630
+
1631
+		$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1632
+		$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1633
+		$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1634
+
1635
+		$tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1636
+		$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1637
+		$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1638
+		$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1639
+		$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1640
+		$tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1641
+		$tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1642
+		$tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1643
+
1644
+		/** Build template    */
1645
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1646
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1647
+			/*    Include the old way template part    */
1648
+			ob_start();
1649
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
1650
+			$content = ob_get_contents();
1651
+			ob_end_clean();
1652
+		} else {
1653
+			$content = wpshop_display::display_template_element($template_part, $tpl_component);
1654
+		}
1655
+		unset($tpl_component);
1656
+		return $content;
1657
+	}
1658 1658
 
1659
-    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)
1660
-    {
1661
-        $content = '';
1662
-        $product_information = $product_class = '';
1659
+	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)
1660
+	{
1661
+		$content = '';
1662
+		$product_information = $product_class = '';
1663 1663
 
1664
-        /** Get the product thumbnail    */
1665
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1666
-        if (has_post_thumbnail($product_id)) {
1667
-            $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1668
-        }
1664
+		/** Get the product thumbnail    */
1665
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1666
+		if (has_post_thumbnail($product_id)) {
1667
+			$productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1668
+		}
1669 1669
 
1670
-        $product = self::get_product_data($product_id);
1670
+		$product = self::get_product_data($product_id);
1671 1671
 
1672
-        /**    Get the product information for output    */
1673
-        if (!empty($product)) {
1672
+		/**    Get the product information for output    */
1673
+		if (!empty($product)) {
1674 1674
 
1675
-            $product_title = $product['post_title'];
1676
-            $product_name = $product['post_name'];
1677
-            $product_link = get_permalink($product_id);
1678
-            $product_more_informations = $product['product_content'];
1679
-            $product_excerpt = $product['product_excerpt'];
1675
+			$product_title = $product['post_title'];
1676
+			$product_name = $product['post_name'];
1677
+			$product_link = get_permalink($product_id);
1678
+			$product_more_informations = $product['product_content'];
1679
+			$product_excerpt = $product['product_excerpt'];
1680 1680
 
1681
-            if (strpos($product['product_content'], '<!--more-->')) {
1682
-                $post_content = explode('<!--more-->', $product['product_content']);
1683
-                $product_more_informations = $post_content[0];
1684
-            }
1681
+			if (strpos($product['product_content'], '<!--more-->')) {
1682
+				$post_content = explode('<!--more-->', $product['product_content']);
1683
+				$product_more_informations = $post_content[0];
1684
+			}
1685 1685
 
1686
-        } else {
1687
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1688
-            $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1689
-            $product_link = '';
1690
-            $product_more_informations = '';
1691
-            $product_excerpt = '';
1692
-        }
1686
+		} else {
1687
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1688
+			$product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1689
+			$product_link = '';
1690
+			$product_more_informations = '';
1691
+			$product_excerpt = '';
1692
+		}
1693 1693
 
1694
-        /** Retrieve product price    */
1695
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1696
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1697
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1698
-        $productPrice = '';
1699
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1700
-        $check_product_price = wpshop_prices::check_product_price($product);
1701
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1702
-        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)) {
1703
-            $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1704
-
1705
-            if (!empty($product_price_infos)) {
1706
-                $tpl_component_price = array();
1707
-                /** Price piloting **/
1694
+		/** Retrieve product price    */
1695
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1696
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1697
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1698
+		$productPrice = '';
1699
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1700
+		$check_product_price = wpshop_prices::check_product_price($product);
1701
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1702
+		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)) {
1703
+			$product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1704
+
1705
+			if (!empty($product_price_infos)) {
1706
+				$tpl_component_price = array();
1707
+				/** Price piloting **/
1708 1708
 				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1709 1709
 				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1710
-                $price_ploting = get_option('wpshop_shop_price_piloting');
1711
-                $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'])) : '';
1712
-                $variations = wpshop_products::get_variation($product_id);
1710
+				$price_ploting = get_option('wpshop_shop_price_piloting');
1711
+				$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'])) : '';
1712
+				$variations = wpshop_products::get_variation($product_id);
1713 1713
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1714 1714
 				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1715 1715
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1716 1716
 				}
1717
-                $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1718
-                $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1719
-                $product_price_infos['MESSAGE_SAVE_MONEY'];
1720
-                $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1721
-            } else {
1722
-                $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1723
-            }
1724
-        }
1717
+				$tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1718
+				$tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1719
+				$product_price_infos['MESSAGE_SAVE_MONEY'];
1720
+				$productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1721
+			} else {
1722
+				$productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1723
+			}
1724
+		}
1725 1725
 
1726
-        /** Check if there is at less 1 product in stock    */
1727
-        $wps_product_ctr = new wps_product_ctr();
1728
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1729
-        $productStock = $productStock === true ? 1 : null;
1730
-
1731
-        /** Define "Add to cart" button    */
1732
-        $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');
1733
-        $display_price_state_when_price_is_empty = false;
1734
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1735
-            $display_price_state_when_price_is_empty = false;
1736
-        } else if (!empty($productPrice)) {
1737
-            $display_price_state_when_price_is_empty = true;
1738
-        }
1739
-        $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') : '';
1740
-        $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)) : '';
1726
+		/** Check if there is at less 1 product in stock    */
1727
+		$wps_product_ctr = new wps_product_ctr();
1728
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1729
+		$productStock = $productStock === true ? 1 : null;
1730
+
1731
+		/** Define "Add to cart" button    */
1732
+		$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');
1733
+		$display_price_state_when_price_is_empty = false;
1734
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1735
+			$display_price_state_when_price_is_empty = false;
1736
+		} else if (!empty($productPrice)) {
1737
+			$display_price_state_when_price_is_empty = true;
1738
+		}
1739
+		$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') : '';
1740
+		$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)) : '';
1741 1741
 
1742
-        /** Define "Ask a quotation" button    */
1743
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1744
-        $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'] : ''));
1742
+		/** Define "Ask a quotation" button    */
1743
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1744
+		$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'] : ''));
1745 1745
 
1746
-        $product_new = $product_new_def['output'];
1747
-        $product_class .= $product_new_def['class'];
1746
+		$product_new = $product_new_def['output'];
1747
+		$product_class .= $product_new_def['class'];
1748 1748
 
1749
-        $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'] : ''));
1750
-        $product_featured = $product_featured_def['output'];
1751
-        $product_class .= $product_featured_def['class'];
1749
+		$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'] : ''));
1750
+		$product_featured = $product_featured_def['output'];
1751
+		$product_class .= $product_featured_def['class'];
1752 1752
 
1753
-        if (!($current_item_position % $grid_element_nb_per_line)) {
1754
-            $product_class .= ' wpshop_last_product_of_line';
1755
-        }
1753
+		if (!($current_item_position % $grid_element_nb_per_line)) {
1754
+			$product_class .= ' wpshop_last_product_of_line';
1755
+		}
1756 1756
 
1757
-        if (!empty($product['product_id'])) {
1758
-            /** Template parameters    */
1759
-            $template_part = 'product_mini_' . $output_type;
1760
-            $tpl_component = array();
1761
-            $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1762
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1763
-            $tpl_component['PRODUCT_ID'] = $product_id;
1764
-            $tpl_component['PRODUCT_CLASS'] = $product_class;
1765
-            $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1766
-            $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1767
-            $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1768
-            $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1769
-            $tpl_component['PRODUCT_PRICE'] = $productPrice;
1770
-            $tpl_component['PRODUCT_PERMALINK'] = $product_link;
1771
-            $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1772
-            $tpl_component['PRODUCT_NAME'] = $product_name;
1773
-            $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1774
-            $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1775
-            $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1776
-            $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1777
-            $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1778
-
1779
-            if (has_post_thumbnail($product_id)) {
1780
-                $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1781
-                if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1782
-                    $existing_image_sizes = get_intermediate_image_sizes();
1783
-                    foreach ($existing_image_sizes as $size_name) {
1784
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1785
-                        $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;
1786
-                    }
1787
-                }
1788
-            }
1789
-
1790
-            $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1791
-            $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1792
-            $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1793
-
1794
-            /** Build template    */
1795
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1796
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1797
-                /**    Include the old way template part    */
1798
-                ob_start();
1799
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1800
-                $content = ob_get_contents();
1801
-                ob_end_clean();
1802
-            } else {
1803
-                $content = wpshop_display::display_template_element($template_part, $tpl_component);
1804
-            }
1805
-            unset($tpl_component);
1757
+		if (!empty($product['product_id'])) {
1758
+			/** Template parameters    */
1759
+			$template_part = 'product_mini_' . $output_type;
1760
+			$tpl_component = array();
1761
+			$tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1762
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1763
+			$tpl_component['PRODUCT_ID'] = $product_id;
1764
+			$tpl_component['PRODUCT_CLASS'] = $product_class;
1765
+			$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1766
+			$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1767
+			$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1768
+			$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1769
+			$tpl_component['PRODUCT_PRICE'] = $productPrice;
1770
+			$tpl_component['PRODUCT_PERMALINK'] = $product_link;
1771
+			$tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1772
+			$tpl_component['PRODUCT_NAME'] = $product_name;
1773
+			$tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1774
+			$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1775
+			$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1776
+			$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1777
+			$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1778
+
1779
+			if (has_post_thumbnail($product_id)) {
1780
+				$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1781
+				if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1782
+					$existing_image_sizes = get_intermediate_image_sizes();
1783
+					foreach ($existing_image_sizes as $size_name) {
1784
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1785
+						$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;
1786
+					}
1787
+				}
1788
+			}
1806 1789
 
1807
-        }
1790
+			$tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1791
+			$tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1792
+			$tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1793
+
1794
+			/** Build template    */
1795
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1796
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1797
+				/**    Include the old way template part    */
1798
+				ob_start();
1799
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1800
+				$content = ob_get_contents();
1801
+				ob_end_clean();
1802
+			} else {
1803
+				$content = wpshop_display::display_template_element($template_part, $tpl_component);
1804
+			}
1805
+			unset($tpl_component);
1808 1806
 
1809
-        return $content;
1810
-    }
1807
+		}
1811 1808
 
1812
-    /**
1813
-     *    Get the products (post) of a given category
1814
-     *
1815
-     *    @param string $category_slug The category slug we want to get the product list for
1816
-     *
1817
-     *    @return mixed $widget_content The output for the product list
1818
-     */
1819
-    public static function get_product_of_category($category_slug, $category_id)
1820
-    {
1821
-        global $top_categories;
1822
-        $widget_content = '';
1823
-        $products = wp_cache_get('wpshop_products_category_' . $category_id);
1824
-        if (false == $products) {
1825
-            $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1826
-            $products = get_posts($args);
1827
-            wp_cache_set('wpshop_products_category_' . $category_id, $products);
1828
-        }
1829
-        if (is_array($products) && (count($products) > 0)) {
1830
-            foreach ($products as $product) {
1831
-                if ($product->post_status == "publish") {
1832
-                    ob_start();
1833
-                    require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1834
-                    $widget_content .= ob_get_contents();
1835
-                    ob_end_clean();
1836
-                }
1837
-            }
1838
-        }
1809
+		return $content;
1810
+	}
1839 1811
 
1840
-        echo $widget_content;
1841
-    }
1812
+	/**
1813
+	 *    Get the products (post) of a given category
1814
+	 *
1815
+	 *    @param string $category_slug The category slug we want to get the product list for
1816
+	 *
1817
+	 *    @return mixed $widget_content The output for the product list
1818
+	 */
1819
+	public static function get_product_of_category($category_slug, $category_id)
1820
+	{
1821
+		global $top_categories;
1822
+		$widget_content = '';
1823
+		$products = wp_cache_get('wpshop_products_category_' . $category_id);
1824
+		if (false == $products) {
1825
+			$args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1826
+			$products = get_posts($args);
1827
+			wp_cache_set('wpshop_products_category_' . $category_id, $products);
1828
+		}
1829
+		if (is_array($products) && (count($products) > 0)) {
1830
+			foreach ($products as $product) {
1831
+				if ($product->post_status == "publish") {
1832
+					ob_start();
1833
+					require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1834
+					$widget_content .= ob_get_contents();
1835
+					ob_end_clean();
1836
+				}
1837
+			}
1838
+		}
1842 1839
 
1843
-    /**
1844
-     *
1845
-     * @param unknown_type $selected_product
1846
-     * @return string
1847
-     */
1848
-    public function custom_product_list($selected_product = array())
1849
-    {
1850
-        global $wpdb;
1851
-
1852
-        /*    Start the table definition    */
1853
-        $tableId = 'wpshop_product_list';
1854
-        $tableTitles = array();
1855
-        $tableTitles[] = '';
1856
-        $tableTitles[] = __('Id', 'wpshop');
1857
-        $tableTitles[] = __('Quantity', 'wpshop');
1858
-        $tableTitles[] = __('Reference', 'wpshop');
1859
-        $tableTitles[] = __('Product name', 'wpshop');
1860
-        $tableTitles[] = __('Actions', 'wpshop');
1861
-        $tableTitles[] = __('Price', 'wpshop');
1862
-        $tableClasses = array();
1863
-        $tableClasses[] = 'wpshop_product_selector_column';
1864
-        $tableClasses[] = 'wpshop_product_identifier_column';
1865
-        $tableClasses[] = 'wpshop_product_quantity_column';
1866
-        $tableClasses[] = 'wpshop_product_sku_column';
1867
-        $tableClasses[] = 'wpshop_product_name_column';
1868
-        $tableClasses[] = 'wpshop_product_link_column';
1869
-        $tableClasses[] = 'wpshop_product_price_column';
1870
-
1871
-        /*    Get post list    */
1872
-        $has_result = false;
1873
-        $current_line_index = 0;
1874
-        $posts = query_posts(array(
1875
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1876
-        ));
1877
-        if (!empty($posts)) {
1878
-            $has_result = true;
1879
-            foreach ($posts as $post) {
1880
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1881
-
1882
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1883
-
1884
-                unset($tableRowValue);
1885
-                $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 . '" />');
1886
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1887
-                $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>');
1888
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1889
-                $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1890
-                $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/>
1840
+		echo $widget_content;
1841
+	}
1842
+
1843
+	/**
1844
+	 *
1845
+	 * @param unknown_type $selected_product
1846
+	 * @return string
1847
+	 */
1848
+	public function custom_product_list($selected_product = array())
1849
+	{
1850
+		global $wpdb;
1851
+
1852
+		/*    Start the table definition    */
1853
+		$tableId = 'wpshop_product_list';
1854
+		$tableTitles = array();
1855
+		$tableTitles[] = '';
1856
+		$tableTitles[] = __('Id', 'wpshop');
1857
+		$tableTitles[] = __('Quantity', 'wpshop');
1858
+		$tableTitles[] = __('Reference', 'wpshop');
1859
+		$tableTitles[] = __('Product name', 'wpshop');
1860
+		$tableTitles[] = __('Actions', 'wpshop');
1861
+		$tableTitles[] = __('Price', 'wpshop');
1862
+		$tableClasses = array();
1863
+		$tableClasses[] = 'wpshop_product_selector_column';
1864
+		$tableClasses[] = 'wpshop_product_identifier_column';
1865
+		$tableClasses[] = 'wpshop_product_quantity_column';
1866
+		$tableClasses[] = 'wpshop_product_sku_column';
1867
+		$tableClasses[] = 'wpshop_product_name_column';
1868
+		$tableClasses[] = 'wpshop_product_link_column';
1869
+		$tableClasses[] = 'wpshop_product_price_column';
1870
+
1871
+		/*    Get post list    */
1872
+		$has_result = false;
1873
+		$current_line_index = 0;
1874
+		$posts = query_posts(array(
1875
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1876
+		));
1877
+		if (!empty($posts)) {
1878
+			$has_result = true;
1879
+			foreach ($posts as $post) {
1880
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1881
+
1882
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1883
+
1884
+				unset($tableRowValue);
1885
+				$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 . '" />');
1886
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1887
+				$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>');
1888
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1889
+				$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1890
+				$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/>
1891 1891
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1892
-                $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() : ''));
1893
-                $tableRows[] = $tableRowValue;
1892
+				$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() : ''));
1893
+				$tableRows[] = $tableRowValue;
1894 1894
 
1895
-                $current_line_index++;
1896
-            }
1897
-            wp_reset_query();
1898
-        }
1899
-        $posts = query_posts(array(
1900
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1901
-        ));
1902
-        if (!empty($posts)) {
1903
-            $has_result = true;
1904
-            foreach ($posts as $post) {
1905
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1906
-
1907
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1908
-
1909
-                unset($tableRowValue);
1910
-                $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 . '" />');
1911
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1912
-                $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>');
1913
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1914
-                $parent_product = wpshop_products::get_parent_variation($post->ID);
1915
-                if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1916
-                    $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1917
-                    $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1918
-                    $option_name = $wpdb->get_var($query);
1919
-                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1920
-                    $option_value = $wpdb->get_var($query);
1921
-                    $parent_post = $parent_product['parent_post'];
1922
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1923
-                } else {
1924
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1925
-                }
1926
-
1927
-                $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1895
+				$current_line_index++;
1896
+			}
1897
+			wp_reset_query();
1898
+		}
1899
+		$posts = query_posts(array(
1900
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1901
+		));
1902
+		if (!empty($posts)) {
1903
+			$has_result = true;
1904
+			foreach ($posts as $post) {
1905
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1906
+
1907
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1908
+
1909
+				unset($tableRowValue);
1910
+				$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 . '" />');
1911
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1912
+				$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>');
1913
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1914
+				$parent_product = wpshop_products::get_parent_variation($post->ID);
1915
+				if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1916
+					$product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1917
+					$query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1918
+					$option_name = $wpdb->get_var($query);
1919
+					$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1920
+					$option_value = $wpdb->get_var($query);
1921
+					$parent_post = $parent_product['parent_post'];
1922
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1923
+				} else {
1924
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1925
+				}
1926
+
1927
+				$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/>
1928 1928
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1929
-                $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() : ''));
1930
-                $tableRows[] = $tableRowValue;
1929
+				$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() : ''));
1930
+				$tableRows[] = $tableRowValue;
1931 1931
 
1932
-                $current_line_index++;
1933
-            }
1934
-            wp_reset_query();
1935
-        }
1932
+				$current_line_index++;
1933
+			}
1934
+			wp_reset_query();
1935
+		}
1936 1936
 
1937
-        if (!$has_result) {
1938
-            $tableRowsId[] = 'no_product_found';
1939
-            unset($tableRowValue);
1940
-            $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1941
-            $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1942
-            $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1943
-            $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1944
-            $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1945
-            $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1946
-            $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1947
-            $tableRows[] = $tableRowValue;
1948
-        }
1937
+		if (!$has_result) {
1938
+			$tableRowsId[] = 'no_product_found';
1939
+			unset($tableRowValue);
1940
+			$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1941
+			$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1942
+			$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1943
+			$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1944
+			$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1945
+			$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1946
+			$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1947
+			$tableRows[] = $tableRowValue;
1948
+		}
1949 1949
 
1950
-        return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1950
+		return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1951 1951
 <script type="text/javascript" >
1952 1952
 	wpshop(document).ready(function(){
1953 1953
 		jQuery("#' . $tableId . '").dataTable( {
@@ -1956,1535 +1956,1535 @@  discard block
 block discarded – undo
1956 1956
 		});
1957 1957
 	});
1958 1958
 </script>';
1959
-    }
1959
+	}
1960 1960
 
1961
-    /**
1962
-     * Allows to manage output for special state for a product (New product/highlight product)
1963
-     *
1964
-     * @param string $special The type of special type we want to output
1965
-     * @param string $output_type The current display type (used for product listing)
1966
-     * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1967
-     * @param datetime $special_state_start The start date if applicable for the special state
1968
-     * @param datetime $special_state_end The end date if applicable for the special state
1969
-     *
1970
-     * @return array $product_special_state The product special state
1971
-     */
1972
-    public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1973
-    {
1974
-        $product_special_state = array();
1975
-        $product_special_state['output'] = $product_special_state['class'] = '';
1976
-
1977
-        /** Get product special state definition    */
1978
-        $special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1979
-        $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1980
-        $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1981
-
1982
-        /** Get current time    */
1983
-        $current_time = substr(current_time('mysql', 0), 0, 10);
1984
-
1985
-        /** PRODUCT MARK AS NEW */
1986
-        $show_product_special_state = false;
1987
-        if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1988
-            (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1989
-            (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1990
-            $show_product_special_state = true;
1991
-        }
1961
+	/**
1962
+	 * Allows to manage output for special state for a product (New product/highlight product)
1963
+	 *
1964
+	 * @param string $special The type of special type we want to output
1965
+	 * @param string $output_type The current display type (used for product listing)
1966
+	 * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1967
+	 * @param datetime $special_state_start The start date if applicable for the special state
1968
+	 * @param datetime $special_state_end The end date if applicable for the special state
1969
+	 *
1970
+	 * @return array $product_special_state The product special state
1971
+	 */
1972
+	public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1973
+	{
1974
+		$product_special_state = array();
1975
+		$product_special_state['output'] = $product_special_state['class'] = '';
1976
+
1977
+		/** Get product special state definition    */
1978
+		$special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1979
+		$special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1980
+		$special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1981
+
1982
+		/** Get current time    */
1983
+		$current_time = substr(current_time('mysql', 0), 0, 10);
1984
+
1985
+		/** PRODUCT MARK AS NEW */
1986
+		$show_product_special_state = false;
1987
+		if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1988
+			(empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1989
+			(empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1990
+			$show_product_special_state = true;
1991
+		}
1992 1992
 
1993
-        if ($show_product_special_state) {
1994
-            /** Check the type of special output needed    */
1995
-            switch ($special) {
1996
-                case 'declare_new':
1997
-                    $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1998
-                    $template_part = 'product_is_new_sticker';
1999
-                    break;
2000
-
2001
-                case 'highlight_product':
2002
-                    $product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2003
-                    $template_part = 'product_is_featured_sticker';
2004
-                    break;
2005
-            }
2006
-
2007
-            /** Template parameters    */
2008
-            $tpl_component = array();
2009
-
2010
-            /** Build template        */
2011
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2012
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2013
-                /**    Include the old way template part    */
2014
-                ob_start();
2015
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2016
-                $product_special_state['output'] = ob_get_contents();
2017
-                ob_end_clean();
2018
-            } else {
2019
-                $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2020
-            }
2021
-            unset($tpl_component);
2022
-        }
1993
+		if ($show_product_special_state) {
1994
+			/** Check the type of special output needed    */
1995
+			switch ($special) {
1996
+				case 'declare_new':
1997
+					$product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1998
+					$template_part = 'product_is_new_sticker';
1999
+					break;
2023 2000
 
2024
-        return $product_special_state;
2025
-    }
2001
+				case 'highlight_product':
2002
+					$product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2003
+					$template_part = 'product_is_featured_sticker';
2004
+					break;
2005
+			}
2026 2006
 
2027
-    /**
2028
-     * Prepare product price for saving and easier read later
2029
-     *
2030
-     * @param integer $element_id Identifier of current product
2031
-     */
2032
-    public static function calculate_price($element_id)
2033
-    {
2034
-        global $wpdb;
2035
-
2036
-        /**
2037
-         * Récupères les attributs suivants : product_price, price_ht et tva
2038
-         * par rapport à $element_id / Get the next attributes : product_price,
2039
-         * price_ht and tva
2040
-         */
2041
-        $query = $wpdb->prepare(
2042
-            "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2007
+			/** Template parameters    */
2008
+			$tpl_component = array();
2009
+
2010
+			/** Build template        */
2011
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2012
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2013
+				/**    Include the old way template part    */
2014
+				ob_start();
2015
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2016
+				$product_special_state['output'] = ob_get_contents();
2017
+				ob_end_clean();
2018
+			} else {
2019
+				$product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2020
+			}
2021
+			unset($tpl_component);
2022
+		}
2023
+
2024
+		return $product_special_state;
2025
+	}
2026
+
2027
+	/**
2028
+	 * Prepare product price for saving and easier read later
2029
+	 *
2030
+	 * @param integer $element_id Identifier of current product
2031
+	 */
2032
+	public static function calculate_price($element_id)
2033
+	{
2034
+		global $wpdb;
2035
+
2036
+		/**
2037
+		 * Récupères les attributs suivants : product_price, price_ht et tva
2038
+		 * par rapport à $element_id / Get the next attributes : product_price,
2039
+		 * price_ht and tva
2040
+		 */
2041
+		$query = $wpdb->prepare(
2042
+			"SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2043 2043
 			FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR
2044 2044
 				RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d))
2045 2045
 			WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')",
2046
-            $element_id
2047
-        );
2048
-        $prices_attribute = $wpdb->get_results($query, OBJECT_K);
2049
-
2050
-        /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2051
-        if (empty($prices_attribute)) {
2052
-            return false;
2053
-        } else {
2054
-            /**
2055
-             * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2056
-             * the base amount according on the shop price control
2057
-             */
2058
-            $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2059
-            $rate_vat = wpshop_prices::get_rate_vat($element_id);
2060
-            $divider_price_ttc = 1 + ($rate_vat->value / 100);
2061
-
2062
-            /**
2063
-             * Informations nécessaire pour crée un attribut / Information needed to
2064
-             * create an attribute
2065
-             */
2066
-            $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2067
-            $language = WPSHOP_CURRENT_LOCALE;
2068
-            $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2069
-
2070
-            if (!empty($icl_post_language)) {
2071
-                $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2072
-                $language = $wpdb->get_var($query);
2073
-            }
2074
-
2075
-            /**
2076
-             * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2077
-             * Check configuration to know how to make the calcul for the product
2078
-             */
2079
-            if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2080
-                $price_with_vat = ($base_price * $divider_price_ttc);
2081
-                $price_no_vat = $base_price;
2082
-            } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2083
-                $price_with_vat = $base_price;
2084
-                $price_no_vat = ($price_with_vat / $divider_price_ttc);
2085
-            }
2086
-
2087
-            /**
2088
-             * Le dernier paramètre permet de ne pas supprimer les attributs du même
2089
-             * type que celui-ci / The last parameter allows not to delete the
2090
-             * attributes of the same type as this one
2091
-             */
2092
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2093
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2094
-
2095
-            /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2096
-            $vat_amount = $price_with_vat - $price_no_vat;
2097
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2098
-
2099
-            /**    Update the product meta information with the calculated prices    */
2100
-            $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2101
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2102
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2103
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2104
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2105
-
2106
-            update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2046
+			$element_id
2047
+		);
2048
+		$prices_attribute = $wpdb->get_results($query, OBJECT_K);
2049
+
2050
+		/** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2051
+		if (empty($prices_attribute)) {
2052
+			return false;
2053
+		} else {
2054
+			/**
2055
+			 * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2056
+			 * the base amount according on the shop price control
2057
+			 */
2058
+			$base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2059
+			$rate_vat = wpshop_prices::get_rate_vat($element_id);
2060
+			$divider_price_ttc = 1 + ($rate_vat->value / 100);
2061
+
2062
+			/**
2063
+			 * Informations nécessaire pour crée un attribut / Information needed to
2064
+			 * create an attribute
2065
+			 */
2066
+			$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2067
+			$language = WPSHOP_CURRENT_LOCALE;
2068
+			$icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2069
+
2070
+			if (!empty($icl_post_language)) {
2071
+				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2072
+				$language = $wpdb->get_var($query);
2073
+			}
2107 2074
 
2108
-            /** Met à jour la meta _wps_price_infos */
2109
-            $p = wpshop_products::get_product_data($element_id);
2110
-            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2111
-            update_post_meta($element_id, '_wps_price_infos', $price);
2075
+			/**
2076
+			 * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2077
+			 * Check configuration to know how to make the calcul for the product
2078
+			 */
2079
+			if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2080
+				$price_with_vat = ($base_price * $divider_price_ttc);
2081
+				$price_no_vat = $base_price;
2082
+			} else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2083
+				$price_with_vat = $base_price;
2084
+				$price_no_vat = ($price_with_vat / $divider_price_ttc);
2085
+			}
2112 2086
 
2113
-            /** Met à jour la meta _wpshop_displayed_price */
2114
-            wps_filter_search::save_displayed_price_meta($element_id);
2115
-        }
2087
+			/**
2088
+			 * Le dernier paramètre permet de ne pas supprimer les attributs du même
2089
+			 * type que celui-ci / The last parameter allows not to delete the
2090
+			 * attributes of the same type as this one
2091
+			 */
2092
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2093
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2094
+
2095
+			/** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2096
+			$vat_amount = $price_with_vat - $price_no_vat;
2097
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2098
+
2099
+			/**    Update the product meta information with the calculated prices    */
2100
+			$product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2101
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2102
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2103
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2104
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2105
+
2106
+			update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2107
+
2108
+			/** Met à jour la meta _wps_price_infos */
2109
+			$p = wpshop_products::get_product_data($element_id);
2110
+			$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2111
+			update_post_meta($element_id, '_wps_price_infos', $price);
2112
+
2113
+			/** Met à jour la meta _wpshop_displayed_price */
2114
+			wps_filter_search::save_displayed_price_meta($element_id);
2115
+		}
2116 2116
 
2117
-        return true;
2118
-    }
2117
+		return true;
2118
+	}
2119 2119
 
2120
-    /**
2121
-     * Allows to get the good button for adding product to cart
2122
-     *
2123
-     * @param integer $product_id The product identifier
2124
-     * @param boolean $productStock If there is the possibility to add the given product to the cart
2125
-     *
2126
-     * @return string $button The html output for the button
2127
-     */
2128
-    public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2129
-    {
2130
-        $button = '';
2120
+	/**
2121
+	 * Allows to get the good button for adding product to cart
2122
+	 *
2123
+	 * @param integer $product_id The product identifier
2124
+	 * @param boolean $productStock If there is the possibility to add the given product to the cart
2125
+	 *
2126
+	 * @return string $button The html output for the button
2127
+	 */
2128
+	public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2129
+	{
2130
+		$button = '';
2131 2131
 //         $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true );
2132 2132
 
2133
-        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') ) */) {
2134
-            /*
2133
+		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') ) */) {
2134
+			/*
2135 2135
              * Check if current product has variation for button display
2136 2136
              */
2137
-            $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2138
-            $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2137
+			$variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2138
+			$variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2139 2139
 
2140
-            /*
2140
+			/*
2141 2141
              * Template parameters
2142 2142
              */
2143 2143
 
2144
-            if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2145
-                /** Check variation stock **/
2146
-                $variations = self::get_variation($product_id);
2147
-                if (!empty($variations)) {
2148
-                    foreach ($variations as $variation) {
2149
-                        if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2150
-                            $productStock += $variation['variation_dif']['product_stock'];
2151
-                        }
2152
-                    }
2153
-                }
2154
-            }
2155
-
2156
-            $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2144
+			if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2145
+				/** Check variation stock **/
2146
+				$variations = self::get_variation($product_id);
2147
+				if (!empty($variations)) {
2148
+					foreach ($variations as $variation) {
2149
+						if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2150
+							$productStock += $variation['variation_dif']['product_stock'];
2151
+						}
2152
+					}
2153
+				}
2154
+			}
2155
+
2156
+			$template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2157 2157
 						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2158 2158
 
2159
-            $tpl_component = array();
2160
-            $tpl_component['PRODUCT_ID'] = $product_id;
2161
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2162
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2159
+			$tpl_component = array();
2160
+			$tpl_component['PRODUCT_ID'] = $product_id;
2161
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2162
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2163 2163
 
2164
-            /*
2164
+			/*
2165 2165
              * Build template
2166 2166
              */
2167
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2168
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2169
-                /*    Include the old way template part    */
2170
-                ob_start();
2171
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2172
-                $button = ob_get_contents();
2173
-                ob_end_clean();
2174
-            } else {
2175
-                $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));
2176
-            }
2177
-            unset($tpl_component);
2178
-        }
2179
-        return $button;
2180
-    }
2181
-
2182
-    /**
2183
-     * Allows to get the good button for adding product to a quotation
2184
-     *
2185
-     * @param integer $product_id The product identifier
2186
-     * @param boolean $product_quotation_state The state of the quotation addons
2187
-     *
2188
-     * @return string $button The html output for the button
2189
-     */
2190
-    public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2191
-    {
2192
-        $quotation_button = '';
2193
-
2194
-        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'))) {
2195
-            $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();
2196
-            /**
2197
-             * Template parameters
2198
-             */
2199
-            $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2200
-            $tpl_component = array();
2201
-            $tpl_component['PRODUCT_ID'] = $product_id;
2202
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2203
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2167
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2168
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2169
+				/*    Include the old way template part    */
2170
+				ob_start();
2171
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2172
+				$button = ob_get_contents();
2173
+				ob_end_clean();
2174
+			} else {
2175
+				$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));
2176
+			}
2177
+			unset($tpl_component);
2178
+		}
2179
+		return $button;
2180
+	}
2204 2181
 
2205
-            /**
2206
-             * Build template
2207
-             */
2208
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2209
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2210
-                /*    Include the old way template part    */
2211
-                ob_start();
2212
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2213
-                $quotation_button = ob_get_contents();
2214
-                ob_end_clean();
2215
-            } else {
2216
-                $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2217
-            }
2218
-            unset($tpl_component);
2219
-        }
2182
+	/**
2183
+	 * Allows to get the good button for adding product to a quotation
2184
+	 *
2185
+	 * @param integer $product_id The product identifier
2186
+	 * @param boolean $product_quotation_state The state of the quotation addons
2187
+	 *
2188
+	 * @return string $button The html output for the button
2189
+	 */
2190
+	public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2191
+	{
2192
+		$quotation_button = '';
2193
+
2194
+		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'))) {
2195
+			$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();
2196
+			/**
2197
+			 * Template parameters
2198
+			 */
2199
+			$template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2200
+			$tpl_component = array();
2201
+			$tpl_component['PRODUCT_ID'] = $product_id;
2202
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2203
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2204
+
2205
+			/**
2206
+			 * Build template
2207
+			 */
2208
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2209
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2210
+				/*    Include the old way template part    */
2211
+				ob_start();
2212
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2213
+				$quotation_button = ob_get_contents();
2214
+				ob_end_clean();
2215
+			} else {
2216
+				$quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2217
+			}
2218
+			unset($tpl_component);
2219
+		}
2220 2220
 
2221
-        return $quotation_button;
2222
-    }
2221
+		return $quotation_button;
2222
+	}
2223 2223
 
2224
-    /**
2225
-     * Return the output for a product attachement gallery (picture or document)
2226
-     *
2227
-     * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2228
-     * @param string $content The gallery content build previously
2229
-     *
2230
-     * @return string The attachement gallery output
2231
-     */
2232
-    public static function display_attachment_gallery($attachement_type, $content)
2233
-    {
2234
-        $galery_output = '';
2235
-
2236
-        /*
2224
+	/**
2225
+	 * Return the output for a product attachement gallery (picture or document)
2226
+	 *
2227
+	 * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2228
+	 * @param string $content The gallery content build previously
2229
+	 *
2230
+	 * @return string The attachement gallery output
2231
+	 */
2232
+	public static function display_attachment_gallery($attachement_type, $content)
2233
+	{
2234
+		$galery_output = '';
2235
+
2236
+		/*
2237 2237
          * Get the template part for given galery type
2238 2238
          */
2239
-        switch ($attachement_type) {
2240
-            case 'picture':
2241
-                $template_part = 'product_attachment_picture_galery';
2242
-                break;
2243
-            case 'document':
2244
-                $template_part = 'product_attachment_galery';
2245
-                break;
2246
-        }
2239
+		switch ($attachement_type) {
2240
+			case 'picture':
2241
+				$template_part = 'product_attachment_picture_galery';
2242
+				break;
2243
+			case 'document':
2244
+				$template_part = 'product_attachment_galery';
2245
+				break;
2246
+		}
2247 2247
 
2248
-        /*
2248
+		/*
2249 2249
          * Template parameters
2250 2250
          */
2251
-        $tpl_component = array();
2252
-        $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2253
-        $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2251
+		$tpl_component = array();
2252
+		$tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2253
+		$tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2254 2254
 
2255
-        /*
2255
+		/*
2256 2256
          * Build template
2257 2257
          */
2258
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2259
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2260
-            /*    Include the old way template part    */
2261
-            ob_start();
2262
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
2263
-            $galery_output = ob_get_contents();
2264
-            ob_end_clean();
2265
-        } else {
2266
-            $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2267
-        }
2268
-        unset($tpl_component);
2258
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2259
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2260
+			/*    Include the old way template part    */
2261
+			ob_start();
2262
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
2263
+			$galery_output = ob_get_contents();
2264
+			ob_end_clean();
2265
+		} else {
2266
+			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2267
+		}
2268
+		unset($tpl_component);
2269 2269
 
2270
-        return $galery_output;
2271
-    }
2270
+		return $galery_output;
2271
+	}
2272 2272
 
2273
-    /**
2274
-     * Define the metabox to display in product edition page in backend
2275
-     * @param object $post The current element displayed for edition
2276
-     */
2277
-    public static function meta_box_variations($post)
2278
-    {
2279
-        $output = '';
2280
-        /*    Variations container    */
2281
-        $tpl_component = array();
2282
-        $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2283
-        $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2284
-        $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2285
-        echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2286
-    }
2273
+	/**
2274
+	 * Define the metabox to display in product edition page in backend
2275
+	 * @param object $post The current element displayed for edition
2276
+	 */
2277
+	public static function meta_box_variations($post)
2278
+	{
2279
+		$output = '';
2280
+		/*    Variations container    */
2281
+		$tpl_component = array();
2282
+		$tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2283
+		$tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2284
+		$output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2285
+		echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2286
+	}
2287 2287
 
2288
-    /**
2289
-     * Call variation creation function with a list of defined variation
2290
-     *
2291
-     * @param array $possible_variations A list of variation to create for the current element
2292
-     * @param integer $element_id The product we want to create variation for
2293
-     *
2294
-     * @return mixed The last created variation identifier
2295
-     */
2296
-    public static function creation_variation_callback($possible_variations, $element_id)
2297
-    {
2298
-        /** Get existing variation    */
2299
-        $existing_variations_in_db = wpshop_products::get_variation($element_id);
2300
-        $existing_variations = array();
2301
-        if (!empty($existing_variations_in_db)) {
2302
-            foreach ($existing_variations_in_db as $variations_def) {
2303
-                $existing_variations[] = $variations_def['variation_def'];
2304
-            }
2305
-        }
2306
-        /** New variation definition    */
2307
-        $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2308
-
2309
-        /**    Read possible values    */
2310
-        foreach ($possible_variations as $variation_definition) {
2311
-            if (in_array($variation_definition, $existing_variations)) {
2312
-                continue;
2313
-            }
2314
-
2315
-            $attribute_to_set = array();
2316
-            foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2317
-                $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2318
-                $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2319
-                if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2320
-                    $attribute_defining_variation['attributes'][] = $attribute_code;
2321
-                }
2322
-            }
2323
-            $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2324
-        }
2325
-        update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2288
+	/**
2289
+	 * Call variation creation function with a list of defined variation
2290
+	 *
2291
+	 * @param array $possible_variations A list of variation to create for the current element
2292
+	 * @param integer $element_id The product we want to create variation for
2293
+	 *
2294
+	 * @return mixed The last created variation identifier
2295
+	 */
2296
+	public static function creation_variation_callback($possible_variations, $element_id)
2297
+	{
2298
+		/** Get existing variation    */
2299
+		$existing_variations_in_db = wpshop_products::get_variation($element_id);
2300
+		$existing_variations = array();
2301
+		if (!empty($existing_variations_in_db)) {
2302
+			foreach ($existing_variations_in_db as $variations_def) {
2303
+				$existing_variations[] = $variations_def['variation_def'];
2304
+			}
2305
+		}
2306
+		/** New variation definition    */
2307
+		$attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2326 2308
 
2327
-        return !empty($variation_id) ? $variation_id : 0;
2328
-    }
2309
+		/**    Read possible values    */
2310
+		foreach ($possible_variations as $variation_definition) {
2311
+			if (in_array($variation_definition, $existing_variations)) {
2312
+				continue;
2313
+			}
2329 2314
 
2330
-    /**
2331
-     * Create a new variation for product
2332
-     *
2333
-     * @param integer $head_product The product identifier to create the new variation for
2334
-     * @param array $variation_attributes Attribute list for the variation
2335
-     *
2336
-     * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2337
-     */
2338
-    public static function create_variation($head_product, $variation_attributes)
2339
-    {
2340
-        /** Create custom title */
2341
-        $title_variation = "";
2342
-        if (!empty($variation_attributes)) {
2343
-            foreach ($variation_attributes as $type => $array) {
2344
-                if (!empty($array)) {
2345
-                    foreach ($array as $code => $value) {
2346
-                        $title_variation .= " " . $code . " " . $value;
2347
-                    }
2348
-                }
2349
-            }
2350
-        }
2315
+			$attribute_to_set = array();
2316
+			foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2317
+				$attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2318
+				$attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2319
+				if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2320
+					$attribute_defining_variation['attributes'][] = $attribute_code;
2321
+				}
2322
+			}
2323
+			$variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2324
+		}
2325
+		update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2351 2326
 
2352
-        $variation = array(
2353
-            'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2354
-            'post_content' => '',
2355
-            'post_status' => 'publish',
2356
-            'post_author' => get_current_user_id(),
2357
-            'post_parent' => $head_product,
2358
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2359
-        );
2360
-        $variation_id = wp_insert_post($variation);
2361
-
2362
-        wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2363
-
2364
-        /*    Update product price looking for shop parameters    */
2365
-        wpshop_products::calculate_price($variation_id);
2366
-
2367
-        /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2368
-        $productMetaDatas = array();
2369
-        foreach ($variation_attributes as $attributeType => $attributeValues) {
2370
-            foreach ($attributeValues as $attributeCode => $attributeValue) {
2371
-                if (!empty($attributeValue)) {
2372
-                    $productMetaDatas[$attributeCode] = $attributeValue;
2373
-                }
2374
-            }
2375
-        }
2376
-        update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2377
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2378
-        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));
2327
+		return !empty($variation_id) ? $variation_id : 0;
2328
+	}
2379 2329
 
2380
-        return $variation_id;
2381
-    }
2330
+	/**
2331
+	 * Create a new variation for product
2332
+	 *
2333
+	 * @param integer $head_product The product identifier to create the new variation for
2334
+	 * @param array $variation_attributes Attribute list for the variation
2335
+	 *
2336
+	 * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2337
+	 */
2338
+	public static function create_variation($head_product, $variation_attributes)
2339
+	{
2340
+		/** Create custom title */
2341
+		$title_variation = "";
2342
+		if (!empty($variation_attributes)) {
2343
+			foreach ($variation_attributes as $type => $array) {
2344
+				if (!empty($array)) {
2345
+					foreach ($array as $code => $value) {
2346
+						$title_variation .= " " . $code . " " . $value;
2347
+					}
2348
+				}
2349
+			}
2350
+		}
2382 2351
 
2383
-    /**
2384
-     * Get variation list for a given product
2385
-     *
2386
-     * @param integer $head_product The product identifier to get the variation for
2387
-     * @return object The variation list
2388
-     */
2389
-    public static function get_variation($head_product)
2390
-    {
2391
-        global $wpdb;
2392
-        $variations_output = null;
2393
-        $args = array(
2394
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2395
-            'post_parent' => $head_product,
2396
-            'orderby' => 'ID',
2397
-            'order' => 'ASC',
2398
-            'posts_per_page' => -1,
2399
-            'post_status' => 'any',
2400
-        );
2401
-        $variations = get_posts($args);
2402
-
2403
-        if (!empty($variations)) {
2404
-            $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2405
-
2406
-            foreach ($variations as $post_def) {
2407
-                $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'");
2408
-                foreach ($data as $content) {
2409
-                    $attribute_value = 'attribute_value_' . $content->data_type;
2410
-                    if (!empty($content->$attribute_value)) {
2411
-                        if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2412
-                            $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2413
-                        } else {
2414
-                            $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2415
-                        }
2416
-                    }
2417
-                }
2418
-                $variations_output[$post_def->ID]['post'] = $post_def;
2419
-            }
2420
-        }
2421
-        wp_reset_query();
2422
-        return $variations_output;
2423
-    }
2352
+		$variation = array(
2353
+			'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2354
+			'post_content' => '',
2355
+			'post_status' => 'publish',
2356
+			'post_author' => get_current_user_id(),
2357
+			'post_parent' => $head_product,
2358
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2359
+		);
2360
+		$variation_id = wp_insert_post($variation);
2361
+
2362
+		wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2363
+
2364
+		/*    Update product price looking for shop parameters    */
2365
+		wpshop_products::calculate_price($variation_id);
2366
+
2367
+		/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2368
+		$productMetaDatas = array();
2369
+		foreach ($variation_attributes as $attributeType => $attributeValues) {
2370
+			foreach ($attributeValues as $attributeCode => $attributeValue) {
2371
+				if (!empty($attributeValue)) {
2372
+					$productMetaDatas[$attributeCode] = $attributeValue;
2373
+				}
2374
+			}
2375
+		}
2376
+		update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2377
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2378
+		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));
2424 2379
 
2425
-    /**
2426
-     * Affichage des variations d'un produit dans l'administration
2427
-     *
2428
-     * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2429
-     * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2430
-     */
2431
-    public static function display_variation_admin($head_product)
2432
-    {
2433
-        $output = '';
2434
-        $productCurrency = wpshop_tools::wpshop_get_currency();
2435
-        /*    Récupération de la liste des variations pour le produit en cours d'édition    */
2436
-        $variations = self::get_variation($head_product);
2437
-        $price_piloting = get_option('wpshop_shop_price_piloting');
2438
-
2439
-        /*    Affichage de la liste des variations pour le produit en cours d'édition    */
2440
-        if (!empty($variations) && is_array($variations)) {
2441
-            $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2442
-
2443
-            foreach ($variations as $variation) {
2444
-                $tpl_component = array();
2445
-
2446
-                $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2447
-                $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2448
-                $tpl_component['VARIATION_DETAIL'] = '  ';
2449
-                $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;
2450
-                $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2451
-                if (!empty($price_piloting) && $price_piloting == 'HT') {
2452
-
2453
-                } else {
2454
-
2455
-                }
2456
-                $post_obj = $variation['post'];
2457
-
2458
-                $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2459
-                if (!empty($parent_product_infos)) {
2460
-                    $parent_post = $parent_product_infos['parent_post'];
2461
-                    $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2462
-                    if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2463
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2464
-                            $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2465
-                        } else {
2466
-                            $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2467
-                        }
2468
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2469
-                    } else {
2470
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2471
-                            $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2472
-                        } else {
2473
-                            $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2474
-                        }
2475
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2476
-                    }
2477
-                    $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2478
-                    $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2479
-                }
2480
-
2481
-                if (!empty($variation['variation_def'])) {
2482
-                    foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2483
-                        if (!empty($variation_value)) {
2484
-                            $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2485
-                            $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');
2486
-                            $tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2487
-
2488
-                            /** Define Link image to variation interface **/
2489
-                            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'))) {
2490
-                                $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2491
-
2492
-                                $media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2493
-                                if (!empty($media_id_data)) {
2494
-                                    $medias_ids = explode(',', $media_id_data);
2495
-
2496
-                                    if (!empty($medias_ids)) {
2497
-                                        foreach ($medias_ids as $media_id) {
2498
-                                            if (!empty($media_id)) {
2499
-                                                $pictures[] = get_post($media_id);
2500
-                                            }
2501
-                                        }
2502
-                                    }
2503
-                                }
2504
-
2505
-                                $pictures_data = '';
2506
-                                if (!empty($pictures)) {
2507
-                                    $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2508
-
2509
-                                    $done_picture = array();
2510
-                                    foreach ($pictures as $picture) {
2511
-                                        if (!in_array($picture->ID, $done_picture)) {
2512
-                                            if (wp_attachment_is_image($picture->ID)) {
2513
-                                                $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2514
-                                                $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');
2515
-
2516
-                                                $done_picture[] = $picture->ID;
2517
-                                            }
2518
-                                        }
2519
-                                    }
2520
-                                }
2521
-
2522
-                                $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');
2523
-                            }
2524
-
2525
-                        }
2526
-                    }
2527
-                }
2528
-
2529
-                $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2530
-
2531
-                $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2532
-                $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())));
2533
-                $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');
2534
-
2535
-                /*    Add the variation definition to output    */
2536
-                $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');
2537
-            }
2538
-
2539
-            $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');
2540
-            /*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2541
-            wp_reset_query();
2542
-        } else {
2543
-            $output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2544
-        }
2380
+		return $variation_id;
2381
+	}
2545 2382
 
2546
-        return $output;
2547
-    }
2383
+	/**
2384
+	 * Get variation list for a given product
2385
+	 *
2386
+	 * @param integer $head_product The product identifier to get the variation for
2387
+	 * @return object The variation list
2388
+	 */
2389
+	public static function get_variation($head_product)
2390
+	{
2391
+		global $wpdb;
2392
+		$variations_output = null;
2393
+		$args = array(
2394
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2395
+			'post_parent' => $head_product,
2396
+			'orderby' => 'ID',
2397
+			'order' => 'ASC',
2398
+			'posts_per_page' => -1,
2399
+			'post_status' => 'any',
2400
+		);
2401
+		$variations = get_posts($args);
2402
+
2403
+		if (!empty($variations)) {
2404
+			$head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2405
+
2406
+			foreach ($variations as $post_def) {
2407
+				$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'");
2408
+				foreach ($data as $content) {
2409
+					$attribute_value = 'attribute_value_' . $content->data_type;
2410
+					if (!empty($content->$attribute_value)) {
2411
+						if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2412
+							$variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2413
+						} else {
2414
+							$variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2415
+						}
2416
+					}
2417
+				}
2418
+				$variations_output[$post_def->ID]['post'] = $post_def;
2419
+			}
2420
+		}
2421
+		wp_reset_query();
2422
+		return $variations_output;
2423
+	}
2548 2424
 
2549
-    /**
2550
-     * Retrieve and display the variation for a given product
2551
-     * @param integer $product_id The product identifier to get variation for
2552
-     */
2553
-    public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2554
-    {
2555
-        global $wp_query;
2556
-        $output = '';
2557
-
2558
-        $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2559
-        $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2560
-        $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2561
-
2562
-        /**    Get attribute order for current product    */
2563
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2564
-        $output_order = array();
2565
-        if (count($product_attribute_order_detail) > 0) {
2566
-            if (!empty($product_attribute_order_detail)) {
2567
-                foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2568
-                    foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2569
-                        if (!empty($attribute_def->code)) {
2570
-                            $output_order[$attribute_def->code] = $position;
2571
-                        }
2572
-
2573
-                    }
2574
-                }
2575
-            }
2576
-        }
2425
+	/**
2426
+	 * Affichage des variations d'un produit dans l'administration
2427
+	 *
2428
+	 * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2429
+	 * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2430
+	 */
2431
+	public static function display_variation_admin($head_product)
2432
+	{
2433
+		$output = '';
2434
+		$productCurrency = wpshop_tools::wpshop_get_currency();
2435
+		/*    Récupération de la liste des variations pour le produit en cours d'édition    */
2436
+		$variations = self::get_variation($head_product);
2437
+		$price_piloting = get_option('wpshop_shop_price_piloting');
2438
+
2439
+		/*    Affichage de la liste des variations pour le produit en cours d'édition    */
2440
+		if (!empty($variations) && is_array($variations)) {
2441
+			$existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2442
+
2443
+			foreach ($variations as $variation) {
2444
+				$tpl_component = array();
2445
+
2446
+				$tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2447
+				$tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2448
+				$tpl_component['VARIATION_DETAIL'] = '  ';
2449
+				$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;
2450
+				$tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2451
+				if (!empty($price_piloting) && $price_piloting == 'HT') {
2452
+
2453
+				} else {
2577 2454
 
2578
-        $variations_params = array();
2579
-        $variation_attribute = array();
2580
-        $variation_attribute_ordered = array();
2581
-        $possible_values = array();
2582
-        $possible_values_for_selection_calculation = array();
2583
-
2584
-        /*    Vérification de l'existence de déclinaison pour le produit    */
2585
-        $wpshop_variation_list = self::get_variation($product_id);
2586
-        if (!empty($wpshop_variation_list)) {
2587
-            foreach ($wpshop_variation_list as $variation) {
2588
-                if (!empty($variation['variation_def'])) {
2589
-                    $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2590
-                    foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2591
-                        if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2592
-                            $tpl_component = array();
2593
-
2594
-                            $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2595
-                            $default_value_is_serial = false;
2596
-                            $attribute_list_first_element = $attribute_db_definition->default_value;
2597
-                            if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2598
-                                $default_value_is_serial = true;
2599
-                                $tmp_default_value = unserialize($attribute_db_definition->default_value);
2600
-                                $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2601
-                            }
2602
-
2603
-                            if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2604
-                                $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');
2605
-                            }
2606
-
2607
-                            if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2608
-                                $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2609
-                                $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2610
-                            } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2611
-                                $post_def = get_post($attribute_value);
2612
-                                $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2613
-                                $position = $post_def->menu_order;
2614
-                            }
2615
-
2616
-                            if (!empty($variation['variation_dif'])) {
2617
-                                foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2618
-                                    $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2619
-                                    $the_value = $attribute_dif_value;
2620
-                                    if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2621
-                                        $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2622
-                                    }
2623
-                                    $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2624
-                                }
2625
-                            }
2626
-                            if (!empty($attribute_value)) {
2627
-                                $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));
2628
-                                $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2629
-                            }
2630
-                            unset($tpl_component);
2631
-                        }
2632
-                    }
2633
-                }
2634
-            }
2635
-
2636
-            $variation_tpl = array();
2637
-            if (!empty($head_wpshop_variation_definition['attributes'])) {
2638
-                foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2639
-                    $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2640
-
2641
-                    if (!empty($attribute_db_definition)) {
2642
-                        $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');
2643
-
2644
-                        $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;
2645
-                        if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2646
-                            $is_required = true;
2647
-                        }
2648
-
2649
-                        $input_def = array();
2650
-                        $input_def['type'] = $attribute_db_definition->frontend_input;
2651
-                        $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);
2652
-                        if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2653
-                            unset($possible_values[$attribute_code][0]);
2654
-                            $value = array($value);
2655
-                        }
2656
-                        $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2657
-                        $input_def['name'] = $attribute_code;
2658
-                        $real_possible_values = array();
2659
-                        if (!empty($possible_values[$attribute_code])) {
2660
-                            ksort($possible_values[$attribute_code]);
2661
-                            foreach ($possible_values[$attribute_code] as $position => $def) {
2662
-                                foreach ($def as $attribute_value => $attribute_value_output) {
2663
-                                    $real_possible_values[$attribute_value] = $attribute_value_output;
2664
-                                    if (!empty($attribute_value)) {
2665
-                                        global $wpdb;
2666
-                                        $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);
2667
-                                        if ('draft' == $wpdb->get_var($query)) {
2668
-                                            unset($real_possible_values[$attribute_value]);
2669
-                                        }
2670
-                                    }
2671
-                                }
2672
-                            }
2673
-                        }
2674
-                        $input_def['possible_value'] = $real_possible_values;
2675
-                        $input_def['valueToPut'] = 'index';
2676
-                        $input_def['value'] = $value;
2677
-
2678
-                        $input_def['options']['more_input'] = '';
2679
-                        if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2680
-                            foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2681
-                                $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 . '" />';
2682
-                            }
2683
-                        }
2684
-
2685
-                        $input_def['options_label']['original'] = true;
2686
-                        $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) . '" ';
2687
-
2688
-                        if (!empty($real_possible_values)) {
2689
-                            $tpl_component = array();
2690
-                            $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'];
2691
-                            $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2692
-                            $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));
2693
-                            $tpl_component['VARIATION_CODE'] = $attribute_code;
2694
-                            $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2695
-                            $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2696
-                            $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2697
-                            $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2698
-                            $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2699
-                            $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;
2700
-                            $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2701
-                            $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2702
-                            $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2703
-                        }
2704
-
2705
-                        $variation_attribute[] = $attribute_code;
2706
-                    }
2707
-                }
2708
-            }
2455
+				}
2456
+				$post_obj = $variation['post'];
2457
+
2458
+				$parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2459
+				if (!empty($parent_product_infos)) {
2460
+					$parent_post = $parent_product_infos['parent_post'];
2461
+					$product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2462
+					if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2463
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2464
+							$product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2465
+						} else {
2466
+							$product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2467
+						}
2468
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2469
+					} else {
2470
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2471
+							$product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2472
+						} else {
2473
+							$product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2474
+						}
2475
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2476
+					}
2477
+					$product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2478
+					$tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2479
+				}
2709 2480
 
2710
-        }
2711
-        $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2712
-        wp_reset_query();
2713
-
2714
-        $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2715
-        if (!empty($attribute_defined_to_be_user_defined)) {
2716
-            foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2717
-                $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;
2718
-
2719
-                $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');
2720
-                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')) {
2721
-                    $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] : ''));
2722
-
2723
-                    $tpl_component = array();
2724
-                    $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) . '" ';
2725
-                    $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2726
-                    $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));
2727
-                    $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2728
-                    $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 . '" ' : '';
2729
-                    $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2730
-                    $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2731
-                    $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2732
-                    $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2733
-                    $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2734
-                    $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;
2735
-                    $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'];
2736
-                    $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)];
2737
-                }
2738
-            }
2739
-        }
2740
-        $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2741
-        if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2742
-            ksort($variation_attribute_ordered);
2743
-            foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2744
-                $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2745
-            }
2746
-        }
2747
-        $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2748
-        $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2749
-        if ($from_admin && !empty($order_id)) {
2750
-            $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2751
-            $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2752
-        }
2753
-        $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2481
+				if (!empty($variation['variation_def'])) {
2482
+					foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2483
+						if (!empty($variation_value)) {
2484
+							$attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2485
+							$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');
2486
+							$tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2487
+
2488
+							/** Define Link image to variation interface **/
2489
+							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'))) {
2490
+								$pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2491
+
2492
+								$media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2493
+								if (!empty($media_id_data)) {
2494
+									$medias_ids = explode(',', $media_id_data);
2495
+
2496
+									if (!empty($medias_ids)) {
2497
+										foreach ($medias_ids as $media_id) {
2498
+											if (!empty($media_id)) {
2499
+												$pictures[] = get_post($media_id);
2500
+											}
2501
+										}
2502
+									}
2503
+								}
2504
+
2505
+								$pictures_data = '';
2506
+								if (!empty($pictures)) {
2507
+									$selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2508
+
2509
+									$done_picture = array();
2510
+									foreach ($pictures as $picture) {
2511
+										if (!in_array($picture->ID, $done_picture)) {
2512
+											if (wp_attachment_is_image($picture->ID)) {
2513
+												$checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2514
+												$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');
2515
+
2516
+												$done_picture[] = $picture->ID;
2517
+											}
2518
+										}
2519
+									}
2520
+								}
2521
+
2522
+								$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');
2523
+							}
2524
+
2525
+						}
2526
+					}
2527
+				}
2754 2528
 
2755
-        return $output;
2756
-    }
2529
+				$tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2757 2530
 
2758
-    public static function get_parent_variation($variation_id)
2759
-    {
2760
-        $result = array();
2761
-        if (!empty($variation_id)) {
2762
-            $variation_post = get_post($variation_id);
2763
-            if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2764
-                $result['parent_post'] = get_post($variation_post->post_parent);
2765
-                $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2766
-            }
2767
-        }
2768
-        return $result;
2769
-    }
2531
+				$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2532
+				$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())));
2533
+				$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');
2770 2534
 
2771
-    /**
2772
-     * Display the current configuration for a given product
2773
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2774
-     */
2775
-    public function wpshop_product_variations_summary($shortcode_attribute)
2776
-    {
2777
-        $output = '';
2778
-
2779
-        $product_variations_selection_args = array(
2780
-            'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2781
-            'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2782
-        );
2783
-
2784
-        $current_user_id = get_current_user_id();
2785
-
2786
-        if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2787
-            foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2788
-                if (!empty($item) && !empty($item['item_id'])) {
2789
-
2790
-                    $free_variations = array();
2791
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2792
-                        foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2793
-                            $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2794
-                        }
2795
-                    }
2796
-
2797
-                    $variations = array();
2798
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2799
-                        foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2800
-
2801
-                            if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2802
-                                foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2803
-                                    $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2804
-                                }
2805
-                            }
2806
-                        }
2807
-                    }
2808
-                    $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2809
-
2810
-                    $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2811
-                }
2812
-            }
2813
-        }
2535
+				/*    Add the variation definition to output    */
2536
+				$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');
2537
+			}
2814 2538
 
2815
-        $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2539
+			$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');
2540
+			/*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2541
+			wp_reset_query();
2542
+		} else {
2543
+			$output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2544
+		}
2816 2545
 
2817
-        echo $output;
2818
-    }
2546
+		return $output;
2547
+	}
2548
+
2549
+	/**
2550
+	 * Retrieve and display the variation for a given product
2551
+	 * @param integer $product_id The product identifier to get variation for
2552
+	 */
2553
+	public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2554
+	{
2555
+		global $wp_query;
2556
+		$output = '';
2557
+
2558
+		$product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2559
+		$wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2560
+		$head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2561
+
2562
+		/**    Get attribute order for current product    */
2563
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2564
+		$output_order = array();
2565
+		if (count($product_attribute_order_detail) > 0) {
2566
+			if (!empty($product_attribute_order_detail)) {
2567
+				foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2568
+					foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2569
+						if (!empty($attribute_def->code)) {
2570
+							$output_order[$attribute_def->code] = $position;
2571
+						}
2572
+
2573
+					}
2574
+				}
2575
+			}
2576
+		}
2577
+
2578
+		$variations_params = array();
2579
+		$variation_attribute = array();
2580
+		$variation_attribute_ordered = array();
2581
+		$possible_values = array();
2582
+		$possible_values_for_selection_calculation = array();
2583
+
2584
+		/*    Vérification de l'existence de déclinaison pour le produit    */
2585
+		$wpshop_variation_list = self::get_variation($product_id);
2586
+		if (!empty($wpshop_variation_list)) {
2587
+			foreach ($wpshop_variation_list as $variation) {
2588
+				if (!empty($variation['variation_def'])) {
2589
+					$display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2590
+					foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2591
+						if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2592
+							$tpl_component = array();
2593
+
2594
+							$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2595
+							$default_value_is_serial = false;
2596
+							$attribute_list_first_element = $attribute_db_definition->default_value;
2597
+							if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2598
+								$default_value_is_serial = true;
2599
+								$tmp_default_value = unserialize($attribute_db_definition->default_value);
2600
+								$attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2601
+							}
2602
+
2603
+							if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2604
+								$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');
2605
+							}
2606
+
2607
+							if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2608
+								$tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2609
+								$position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2610
+							} else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2611
+								$post_def = get_post($attribute_value);
2612
+								$tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2613
+								$position = $post_def->menu_order;
2614
+							}
2615
+
2616
+							if (!empty($variation['variation_dif'])) {
2617
+								foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2618
+									$wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2619
+									$the_value = $attribute_dif_value;
2620
+									if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2621
+										$the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2622
+									}
2623
+									$tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2624
+								}
2625
+							}
2626
+							if (!empty($attribute_value)) {
2627
+								$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));
2628
+								$possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2629
+							}
2630
+							unset($tpl_component);
2631
+						}
2632
+					}
2633
+				}
2634
+			}
2635
+
2636
+			$variation_tpl = array();
2637
+			if (!empty($head_wpshop_variation_definition['attributes'])) {
2638
+				foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2639
+					$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2640
+
2641
+					if (!empty($attribute_db_definition)) {
2642
+						$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');
2643
+
2644
+						$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;
2645
+						if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2646
+							$is_required = true;
2647
+						}
2648
+
2649
+						$input_def = array();
2650
+						$input_def['type'] = $attribute_db_definition->frontend_input;
2651
+						$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);
2652
+						if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2653
+							unset($possible_values[$attribute_code][0]);
2654
+							$value = array($value);
2655
+						}
2656
+						$input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2657
+						$input_def['name'] = $attribute_code;
2658
+						$real_possible_values = array();
2659
+						if (!empty($possible_values[$attribute_code])) {
2660
+							ksort($possible_values[$attribute_code]);
2661
+							foreach ($possible_values[$attribute_code] as $position => $def) {
2662
+								foreach ($def as $attribute_value => $attribute_value_output) {
2663
+									$real_possible_values[$attribute_value] = $attribute_value_output;
2664
+									if (!empty($attribute_value)) {
2665
+										global $wpdb;
2666
+										$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);
2667
+										if ('draft' == $wpdb->get_var($query)) {
2668
+											unset($real_possible_values[$attribute_value]);
2669
+										}
2670
+									}
2671
+								}
2672
+							}
2673
+						}
2674
+						$input_def['possible_value'] = $real_possible_values;
2675
+						$input_def['valueToPut'] = 'index';
2676
+						$input_def['value'] = $value;
2677
+
2678
+						$input_def['options']['more_input'] = '';
2679
+						if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2680
+							foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2681
+								$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 . '" />';
2682
+							}
2683
+						}
2684
+
2685
+						$input_def['options_label']['original'] = true;
2686
+						$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) . '" ';
2687
+
2688
+						if (!empty($real_possible_values)) {
2689
+							$tpl_component = array();
2690
+							$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'];
2691
+							$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2692
+							$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));
2693
+							$tpl_component['VARIATION_CODE'] = $attribute_code;
2694
+							$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2695
+							$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2696
+							$tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2697
+							$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2698
+							$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2699
+							$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;
2700
+							$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2701
+							$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2702
+							$variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2703
+						}
2704
+
2705
+						$variation_attribute[] = $attribute_code;
2706
+					}
2707
+				}
2708
+			}
2709
+
2710
+		}
2711
+		$variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2712
+		wp_reset_query();
2713
+
2714
+		$attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2715
+		if (!empty($attribute_defined_to_be_user_defined)) {
2716
+			foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2717
+				$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;
2718
+
2719
+				$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');
2720
+				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')) {
2721
+					$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] : ''));
2722
+
2723
+					$tpl_component = array();
2724
+					$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) . '" ';
2725
+					$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2726
+					$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));
2727
+					$tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2728
+					$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 . '" ' : '';
2729
+					$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2730
+					$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2731
+					$tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2732
+					$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2733
+					$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2734
+					$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;
2735
+					$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'];
2736
+					$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)];
2737
+				}
2738
+			}
2739
+		}
2740
+		$variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2741
+		if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2742
+			ksort($variation_attribute_ordered);
2743
+			foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2744
+				$variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2745
+			}
2746
+		}
2747
+		$variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2748
+		$variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2749
+		if ($from_admin && !empty($order_id)) {
2750
+			$variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2751
+			$variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2752
+		}
2753
+		$output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2754
+
2755
+		return $output;
2756
+	}
2757
+
2758
+	public static function get_parent_variation($variation_id)
2759
+	{
2760
+		$result = array();
2761
+		if (!empty($variation_id)) {
2762
+			$variation_post = get_post($variation_id);
2763
+			if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2764
+				$result['parent_post'] = get_post($variation_post->post_parent);
2765
+				$result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2766
+			}
2767
+		}
2768
+		return $result;
2769
+	}
2770
+
2771
+	/**
2772
+	 * Display the current configuration for a given product
2773
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2774
+	 */
2775
+	public function wpshop_product_variations_summary($shortcode_attribute)
2776
+	{
2777
+		$output = '';
2778
+
2779
+		$product_variations_selection_args = array(
2780
+			'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2781
+			'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2782
+		);
2783
+
2784
+		$current_user_id = get_current_user_id();
2785
+
2786
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2787
+			foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2788
+				if (!empty($item) && !empty($item['item_id'])) {
2789
+
2790
+					$free_variations = array();
2791
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2792
+						foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2793
+							$free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2794
+						}
2795
+					}
2796
+
2797
+					$variations = array();
2798
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2799
+						foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2800
+
2801
+							if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2802
+								foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2803
+									$variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2804
+								}
2805
+							}
2806
+						}
2807
+					}
2808
+					$product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2809
+
2810
+					$product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2811
+				}
2812
+			}
2813
+		}
2814
+
2815
+		$output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2816
+
2817
+		echo $output;
2818
+	}
2819
+
2820
+	/**
2821
+	 * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2822
+	 *
2823
+	 * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2824
+	 * @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
2825
+	 * @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
2826
+	 * @param string $wpshop_current_for_display Inconnu / Unknown
2827
+	 * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2828
+	 *
2829
+	 * @return array Le résultat du calcul pour l'affichage / Output result
2830
+	 */
2831
+	public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2832
+	{
2833
+		global $wpdb;
2834
+
2835
+		$wpshop_cart = new wps_cart();
2836
+		$wpshop_products = new wpshop_products();
2837
+
2838
+		$response = '';
2839
+		$response_status = $has_variation = false;
2840
+		$tpl_component = array();
2841
+
2842
+		// Check if variations exists
2843
+		if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2844
+
2845
+			//Recover all selected variations
2846
+			$variations_selected = array();
2847
+			if (!empty($wpshop_variation_selected)) {
2848
+				foreach ($wpshop_variation_selected as $selected_variation) {
2849
+					$variation_definition = explode('-_variation_val_-', $selected_variation);
2850
+					$variations_selected[$variation_definition[0]] = $variation_definition[1];
2851
+				}
2852
+			}
2853
+
2854
+			// Check variations priority
2855
+			$product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2856
+
2857
+			// Check if $product_with_variation have variations
2858
+			if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2859
+
2860
+				$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2861
+				$product_to_add_to_cart = $formatted_product[0];
2862
+				foreach ($formatted_product[0] as $pid => $product_more_content) {
2863
+					$order_items[$pid]['product_id'] = $product_more_content['id'];
2864
+
2865
+					/** For product with variation    */
2866
+					$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2867
+					$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2868
+					$order_items[$pid]['product_variation'] = '';
2869
+					if (!empty($product_more_content['variations'])) {
2870
+						foreach ($product_more_content['variations'] as $variation_id) {
2871
+							$order_items[$pid]['product_variation'][] = $variation_id;
2872
+						}
2873
+					}
2874
+				}
2875
+
2876
+				// If Product list is not empty, add products to order
2877
+				if (!empty($order_items)) {
2878
+					foreach ($order_items as $product_id => $d) {
2879
+						$product_key = $product_id;
2880
+
2881
+						// Formate datas
2882
+						$product_id = $head_product_id = $d['product_id'];
2883
+						$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2819 2884
 
2820
-    /**
2821
-     * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2822
-     *
2823
-     * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2824
-     * @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
2825
-     * @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
2826
-     * @param string $wpshop_current_for_display Inconnu / Unknown
2827
-     * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2828
-     *
2829
-     * @return array Le résultat du calcul pour l'affichage / Output result
2830
-     */
2831
-    public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2832
-    {
2833
-        global $wpdb;
2834
-
2835
-        $wpshop_cart = new wps_cart();
2836
-        $wpshop_products = new wpshop_products();
2837
-
2838
-        $response = '';
2839
-        $response_status = $has_variation = false;
2840
-        $tpl_component = array();
2841
-
2842
-        // Check if variations exists
2843
-        if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2844
-
2845
-            //Recover all selected variations
2846
-            $variations_selected = array();
2847
-            if (!empty($wpshop_variation_selected)) {
2848
-                foreach ($wpshop_variation_selected as $selected_variation) {
2849
-                    $variation_definition = explode('-_variation_val_-', $selected_variation);
2850
-                    $variations_selected[$variation_definition[0]] = $variation_definition[1];
2851
-                }
2852
-            }
2853
-
2854
-            // Check variations priority
2855
-            $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2856
-
2857
-            // Check if $product_with_variation have variations
2858
-            if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2859
-
2860
-                $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2861
-                $product_to_add_to_cart = $formatted_product[0];
2862
-                foreach ($formatted_product[0] as $pid => $product_more_content) {
2863
-                    $order_items[$pid]['product_id'] = $product_more_content['id'];
2864
-
2865
-                    /** For product with variation    */
2866
-                    $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2867
-                    $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2868
-                    $order_items[$pid]['product_variation'] = '';
2869
-                    if (!empty($product_more_content['variations'])) {
2870
-                        foreach ($product_more_content['variations'] as $variation_id) {
2871
-                            $order_items[$pid]['product_variation'][] = $variation_id;
2872
-                        }
2873
-                    }
2874
-                }
2875
-
2876
-                // If Product list is not empty, add products to order
2877
-                if (!empty($order_items)) {
2878
-                    foreach ($order_items as $product_id => $d) {
2879
-                        $product_key = $product_id;
2880
-
2881
-                        // Formate datas
2882
-                        $product_id = $head_product_id = $d['product_id'];
2883
-                        $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2884
-
2885
-                        // If product is a single variation product
2886
-                        if (!empty($product_variation) && (count($product_variation) == 1)) {
2887
-                            $product_id = $product_variation[0];
2888
-                        }
2889
-
2890
-                        // Construct final product
2891
-                        $product = wpshop_products::get_product_data($d['product_id'], true);
2892
-                        $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2885
+						// If product is a single variation product
2886
+						if (!empty($product_variation) && (count($product_variation) == 1)) {
2887
+							$product_id = $product_variation[0];
2888
+						}
2889
+
2890
+						// Construct final product
2891
+						$product = wpshop_products::get_product_data($d['product_id'], true);
2892
+						$the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2893 2893
 						$the_product['text_from'] = $product_with_variation['text_from'];
2894 2894
 
2895
-                        //    Add variation to product into cart for storage
2896
-                        if (!empty($product_variation)) {
2897
-                            $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2898
-                        }
2899
-
2900
-                        // Free Variations Checking
2901
-                        if (!empty($d['free_variation'])) {
2902
-                            $the_product['item_meta']['free_variation'] = $d['free_variation'];
2903
-                            $head_product_id = $the_product['product_id'];
2904
-                        }
2905
-
2906
-                        // If product is a variation, we check parent product general
2907
-                        if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2908
-                            $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2909
-                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2910
-                                $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2911
-                                $parent_meta = $parent_def['parent_post_meta'];
2912
-                                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) {
2913
-                                    $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2914
-                                    $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2915
-                                    $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2916
-                                }
2917
-                            }
2918
-                        }
2919
-                    }
2920
-                }
2921
-
2922
-                if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2923
-                    $price_infos = wpshop_prices::check_product_price($the_product, true);
2924
-                    if (!empty($price_infos['discount']['discount_exist'])) {
2925
-                        $the_product['price_ttc_before_discount'] = $the_product['product_price'];
2926
-                        $the_product['price_ht_before_discount'] = $the_product['price_ht'];
2927
-                    }
2928
-                    $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'];
2929
-                    $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'];
2930
-                    $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'];
2931
-                }
2932
-
2933
-                $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2934
-                // Add free variations to product
2935
-                if (!empty($wpshop_free_variation)) {
2936
-                    $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2937
-                }
2938
-                // Change picture if have a selected variation
2939
-                $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;
2940
-                $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2941
-
2942
-                // Price Display
2943
-                $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2944
-                $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2945
-                $productPrice = '';
2946
-                if ($price_display) {
2947
-                    $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2948
-                }
2949
-
2950
-                //Get Summary cart
2951
-                $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2952
-                $response_status = true;
2953
-            } else {
2954
-                //Product without variations
2955
-                $product_data = wpshop_products::get_product_data($product_id);
2956
-                $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2957
-            }
2958
-        }
2895
+						//    Add variation to product into cart for storage
2896
+						if (!empty($product_variation)) {
2897
+							$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2898
+						}
2899
+
2900
+						// Free Variations Checking
2901
+						if (!empty($d['free_variation'])) {
2902
+							$the_product['item_meta']['free_variation'] = $d['free_variation'];
2903
+							$head_product_id = $the_product['product_id'];
2904
+						}
2905
+
2906
+						// If product is a variation, we check parent product general
2907
+						if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2908
+							$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2909
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2910
+								$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2911
+								$parent_meta = $parent_def['parent_post_meta'];
2912
+								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) {
2913
+									$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2914
+									$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2915
+									$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2916
+								}
2917
+							}
2918
+						}
2919
+					}
2920
+				}
2959 2921
 
2960
-        return array($response_status, $response);
2961
-    }
2922
+				if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2923
+					$price_infos = wpshop_prices::check_product_price($the_product, true);
2924
+					if (!empty($price_infos['discount']['discount_exist'])) {
2925
+						$the_product['price_ttc_before_discount'] = $the_product['product_price'];
2926
+						$the_product['price_ht_before_discount'] = $the_product['price_ht'];
2927
+					}
2928
+					$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'];
2929
+					$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'];
2930
+					$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'];
2931
+				}
2962 2932
 
2963
-    /**
2964
-     * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2965
-     *
2966
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2967
-     */
2968
-    public function wpshop_product_variation_value_detail($shortcode_attribute)
2969
-    {
2970
-        echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2971
-    }
2933
+				$product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2934
+				// Add free variations to product
2935
+				if (!empty($wpshop_free_variation)) {
2936
+					$the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2937
+				}
2938
+				// Change picture if have a selected variation
2939
+				$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;
2940
+				$response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2941
+
2942
+				// Price Display
2943
+				$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2944
+				$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2945
+				$productPrice = '';
2946
+				if ($price_display) {
2947
+					$response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2948
+				}
2972 2949
 
2973
-    /**
2974
-     * Build the product structure with variation for product choosed by the user into frontend sheet
2975
-     *
2976
-     * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2977
-     * @param integer $product_id The basic product choose by the user in frontend
2978
-     *
2979
-     * @return array The product list for adding to the cart build by variation priority
2980
-     */
2981
-    public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2982
-    {
2983
-        global $wpdb;
2984
-        $all_required_variations_selected = $no_selected_variation = true;
2985
-        $single_variations = $combined_variations = $product_to_add_to_cart = array();
2986
-
2987
-        // Check if all required variations are selected
2988
-        $required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2989
-        foreach ($selected_variation as $k => $value) {
2990
-            if ($value == 0 && in_array($k, $required_attributes_list)) {
2991
-                $all_required_variations_selected = false;
2992
-            }
2993
-            if ($value != 0) {
2994
-                $no_selected_variation = false;
2995
-            }
2996
-        }
2997
-        if (!empty($selected_variation)) {
2998
-            //Check variations configuration
2999
-            $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3000
-            // Check variations type
3001
-            $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3002
-            $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3003
-
3004
-            //Check defined variation priority
3005
-            $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3006
-            $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3007
-
3008
-            // Recover all product variations
3009
-            $query_variation = $selected_variation;
3010
-            // Delete free variations
3011
-            unset($query_variation['free']);
3012
-
3013
-            if ($product_variation_type == 'single') {
3014
-                // Get single variations
3015
-                $single_variations = array();
3016
-                foreach ($selected_variation as $attribute_code => $attribute_value) {
3017
-                    if (isset($attribute_value) && $attribute_code != 'free') {
3018
-                        $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)) . "'", $product_id);
3019
-                        $single_variation_id = $wpdb->get_var($query);
3020
-                        if (!empty($single_variation_id)) {
3021
-                            $single_variations[] = $single_variation_id;
3022
-                            unset($query_variation[$attribute_code]);
3023
-                        }
3024
-                    }
3025
-                }
3026
-            } else {
3027
-                // Get combined variations
3028
-                $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);
3029
-                $combined_variation_id = $wpdb->get_var($query);
3030
-                if (!empty($combined_variation_id)) {
3031
-                    $combined_variations[] = $combined_variation_id;
3032
-                }
3033
-
3034
-            }
3035
-
3036
-            //If all required variations are not selected
3037
-            if (!$all_required_variations_selected || $no_selected_variation) {
3038
-                $product_to_add_to_cart['text_from'] = 'on';
3039
-                // If we choose to display lower price variation combinaison
3040
-                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']))) {
3041
-                    //Get lower price variation combinaison
3042
-                    $lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3043
-                    if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3044
-                        foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3045
-                            $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3046
-                        }
3047
-                    }
3048
-                    $product_to_add_to_cart['display_lower_price'] = true;
3049
-                } else {
3050
-                    $product_to_add_to_cart[$product_id]['variations'] = array();
3051
-                }
3052
-            } else {
3053
-                $product_to_add_to_cart['text_from'] = '';
3054
-                $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3055
-            }
3056
-        }
2950
+				//Get Summary cart
2951
+				$response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2952
+				$response_status = true;
2953
+			} else {
2954
+				//Product without variations
2955
+				$product_data = wpshop_products::get_product_data($product_id);
2956
+				$response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2957
+			}
2958
+		}
3057 2959
 
3058
-        return $product_to_add_to_cart;
3059
-    }
2960
+		return array($response_status, $response);
2961
+	}
3060 2962
 
3061
-    public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3062
-    {
3063
-        global $wpdb;
3064
-
3065
-        if (!empty($product_variations)) {
3066
-            // Initialize variations total price datas
3067
-            $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3068
-            $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3069
-            $vat_rate = 0;
3070
-            $discount_amount = $discount_rate = $special_price = 0;
3071
-            // Recover Head product metadata
3072
-            $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3073
-            $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3074
-            if (!empty($tva_rate_id)) {
3075
-                // Recover VAT Rate of product
3076
-                $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3077
-                $vat_rate = $wpdb->get_var($query);
3078
-            }
3079
-            $price_piloting = get_option('wpshop_shop_price_piloting');
3080
-            foreach ($product_variations as $product_variation) {
3081
-                $variation_metadata['product_price'] = 0;
3082
-                $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3083
-                if (!empty($variation_metadata)) {
3084
-                    $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']);
3085
-                    $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))));
3086
-
3087
-                    $variations_total_price['price_et'] += $p_et;
3088
-                    $variations_total_price['price_ati'] += $p_ati;
3089
-                    $variations_total_price['vat_amount'] += $p_ati - $p_et;
3090
-
3091
-                    $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3092
-
3093
-                    // Check discount
3094
-                    $discount_config = wpshop_prices::check_discount_for_product($product_variation);
3095
-                    if (!empty($discount_config) && !empty($discount_config['value'])) {
3096
-                        $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3097
-                        $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3098
-                        $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3099
-                        $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3100
-
3101
-                        if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3102
-                            $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3103
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3104
-                            $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3105
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3106
-                            $product_into_cart['special_price'] = $special_price + $discount_config['value'];
3107
-                        }
3108
-                    }
3109
-
3110
-                    $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3111
-                    $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3112
-                }
3113
-            }
3114
-
3115
-            // Check if add or replace variation price to head product
3116
-            /**
3117
-             * Since 1.4.3.7
3118
-             * L'option du produit remplace le prix du produit de tête.
3119
-             */
2963
+	/**
2964
+	 * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2965
+	 *
2966
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2967
+	 */
2968
+	public function wpshop_product_variation_value_detail($shortcode_attribute)
2969
+	{
2970
+		echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2971
+	}
2972
+
2973
+	/**
2974
+	 * Build the product structure with variation for product choosed by the user into frontend sheet
2975
+	 *
2976
+	 * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2977
+	 * @param integer $product_id The basic product choose by the user in frontend
2978
+	 *
2979
+	 * @return array The product list for adding to the cart build by variation priority
2980
+	 */
2981
+	public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2982
+	{
2983
+		global $wpdb;
2984
+		$all_required_variations_selected = $no_selected_variation = true;
2985
+		$single_variations = $combined_variations = $product_to_add_to_cart = array();
2986
+
2987
+		// Check if all required variations are selected
2988
+		$required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2989
+		foreach ($selected_variation as $k => $value) {
2990
+			if ($value == 0 && in_array($k, $required_attributes_list)) {
2991
+				$all_required_variations_selected = false;
2992
+			}
2993
+			if ($value != 0) {
2994
+				$no_selected_variation = false;
2995
+			}
2996
+		}
2997
+		if (!empty($selected_variation)) {
2998
+			//Check variations configuration
2999
+			$product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3000
+			// Check variations type
3001
+			$product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3002
+			$product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3003
+
3004
+			//Check defined variation priority
3005
+			$priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3006
+			$product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3007
+
3008
+			// Recover all product variations
3009
+			$query_variation = $selected_variation;
3010
+			// Delete free variations
3011
+			unset($query_variation['free']);
3012
+
3013
+			if ($product_variation_type == 'single') {
3014
+				// Get single variations
3015
+				$single_variations = array();
3016
+				foreach ($selected_variation as $attribute_code => $attribute_value) {
3017
+					if (isset($attribute_value) && $attribute_code != 'free') {
3018
+						$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)) . "'", $product_id);
3019
+						$single_variation_id = $wpdb->get_var($query);
3020
+						if (!empty($single_variation_id)) {
3021
+							$single_variations[] = $single_variation_id;
3022
+							unset($query_variation[$attribute_code]);
3023
+						}
3024
+					}
3025
+				}
3026
+			} else {
3027
+				// Get combined variations
3028
+				$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);
3029
+				$combined_variation_id = $wpdb->get_var($query);
3030
+				if (!empty($combined_variation_id)) {
3031
+					$combined_variations[] = $combined_variation_id;
3032
+				}
3033
+
3034
+			}
3035
+
3036
+			//If all required variations are not selected
3037
+			if (!$all_required_variations_selected || $no_selected_variation) {
3038
+				$product_to_add_to_cart['text_from'] = 'on';
3039
+				// If we choose to display lower price variation combinaison
3040
+				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']))) {
3041
+					//Get lower price variation combinaison
3042
+					$lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3043
+					if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3044
+						foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3045
+							$product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3046
+						}
3047
+					}
3048
+					$product_to_add_to_cart['display_lower_price'] = true;
3049
+				} else {
3050
+					$product_to_add_to_cart[$product_id]['variations'] = array();
3051
+				}
3052
+			} else {
3053
+				$product_to_add_to_cart['text_from'] = '';
3054
+				$product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3055
+			}
3056
+		}
3057
+
3058
+		return $product_to_add_to_cart;
3059
+	}
3060
+
3061
+	public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3062
+	{
3063
+		global $wpdb;
3064
+
3065
+		if (!empty($product_variations)) {
3066
+			// Initialize variations total price datas
3067
+			$variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3068
+			$variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3069
+			$vat_rate = 0;
3070
+			$discount_amount = $discount_rate = $special_price = 0;
3071
+			// Recover Head product metadata
3072
+			$head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3073
+			$tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3074
+			if (!empty($tva_rate_id)) {
3075
+				// Recover VAT Rate of product
3076
+				$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3077
+				$vat_rate = $wpdb->get_var($query);
3078
+			}
3079
+			$price_piloting = get_option('wpshop_shop_price_piloting');
3080
+			foreach ($product_variations as $product_variation) {
3081
+				$variation_metadata['product_price'] = 0;
3082
+				$variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3083
+				if (!empty($variation_metadata)) {
3084
+					$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']);
3085
+					$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))));
3086
+
3087
+					$variations_total_price['price_et'] += $p_et;
3088
+					$variations_total_price['price_ati'] += $p_ati;
3089
+					$variations_total_price['vat_amount'] += $p_ati - $p_et;
3090
+
3091
+					$variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3092
+
3093
+					// Check discount
3094
+					$discount_config = wpshop_prices::check_discount_for_product($product_variation);
3095
+					if (!empty($discount_config) && !empty($discount_config['value'])) {
3096
+						$variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3097
+						$variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3098
+						$variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3099
+						$variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3100
+
3101
+						if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3102
+							$product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3103
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3104
+							$product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3105
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3106
+							$product_into_cart['special_price'] = $special_price + $discount_config['value'];
3107
+						}
3108
+					}
3109
+
3110
+					$product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3111
+					$product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3112
+				}
3113
+			}
3114
+
3115
+			// Check if add or replace variation price to head product
3116
+			/**
3117
+			 * Since 1.4.3.7
3118
+			 * L'option du produit remplace le prix du produit de tête.
3119
+			 */
3120 3120
 			if( true ) {
3121
-                //Replace the product price
3122
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3123
-                    $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3124
-                    $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3125
-
3126
-                    $product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3127
-                    $product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3128
-                    $product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3129
-                } else {
3130
-                    $product_into_cart['product_price'] = $variations_total_price['price_ati'];
3131
-                    $product_into_cart['price_ht'] = $variations_total_price['price_et'];
3132
-                    $product_into_cart['tva'] = $variations_total_price['vat_amount'];
3133
-                }
3134
-            } else {
3135
-                // Add variations price to product price
3136
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3137
-                    $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3138
-                    $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3139
-
3140
-                    $product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3141
-                    $product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3142
-                    $product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3143
-                } else {
3144
-                    $product_into_cart['product_price'] += $variations_total_price['price_ati'];
3145
-                    $product_into_cart['price_ht'] += $variations_total_price['price_et'];
3146
-                    $product_into_cart['tva'] += $variations_total_price['vat_amount'];
3147
-                }
3148
-                // Check parent discount
3149
-                $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3150
-                if (!empty($parent_discount_config)) {
3151
-                    $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'];
3152
-                    $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'];
3153
-                    $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3154
-
3155
-                    if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3156
-                        $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3157
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3158
-                        $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3159
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3160
-                        $product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3161
-                    }
3162
-                }
3163
-            }
3164
-        } else {
3165
-            // If product have just Free variations
3166
-            $discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3167
-            if (!empty($discount_config)) {
3168
-                $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'];
3169
-                $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'];
3170
-                $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3171
-            }
3172
-        }
3121
+				//Replace the product price
3122
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3123
+					$product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3124
+					$product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3125
+
3126
+					$product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3127
+					$product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3128
+					$product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3129
+				} else {
3130
+					$product_into_cart['product_price'] = $variations_total_price['price_ati'];
3131
+					$product_into_cart['price_ht'] = $variations_total_price['price_et'];
3132
+					$product_into_cart['tva'] = $variations_total_price['vat_amount'];
3133
+				}
3134
+			} else {
3135
+				// Add variations price to product price
3136
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3137
+					$product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3138
+					$product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3139
+
3140
+					$product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3141
+					$product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3142
+					$product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3143
+				} else {
3144
+					$product_into_cart['product_price'] += $variations_total_price['price_ati'];
3145
+					$product_into_cart['price_ht'] += $variations_total_price['price_et'];
3146
+					$product_into_cart['tva'] += $variations_total_price['vat_amount'];
3147
+				}
3148
+				// Check parent discount
3149
+				$parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3150
+				if (!empty($parent_discount_config)) {
3151
+					$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'];
3152
+					$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'];
3153
+					$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3154
+
3155
+					if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3156
+						$product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3157
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3158
+						$product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3159
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3160
+						$product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3161
+					}
3162
+				}
3163
+			}
3164
+		} else {
3165
+			// If product have just Free variations
3166
+			$discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3167
+			if (!empty($discount_config)) {
3168
+				$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'];
3169
+				$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'];
3170
+				$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3171
+			}
3172
+		}
3173 3173
 
3174
-        // Text From indicator
3175
-        if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3176
-            $product_into_cart['text_from'] = $variations_options['text_from'];
3177
-        }
3178
-        return $product_into_cart;
3179
-    }
3174
+		// Text From indicator
3175
+		if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3176
+			$product_into_cart['text_from'] = $variations_options['text_from'];
3177
+		}
3178
+		return $product_into_cart;
3179
+	}
3180 3180
 
3181
-    /**
3182
-     * Read an array with product options chosen by the customer, order into an array regarding admin definition
3183
-     *
3184
-     * @param array $product_definition_value The array with the selected product option to ordered
3185
-     * @param array $output_order The good order for attribute defined by administrator
3186
-     * @param dtring $from_page A string allowing to take a specific template regarding the current page
3187
-     *
3188
-     * @return array The array containing all product options ordered as the admin configure it
3189
-     */
3190
-    public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3191
-    {
3192
-        $variation_attribute_ordered = array();
3193
-        $variation_attribute_ordered['prices'] = array();
3194
-        $variation_attribute_ordered['attribute_list'] = array();
3195
-
3196
-        if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3197
-            foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3198
-                $variation_tpl_component = array();
3199
-                foreach ($variation_attribute_detail as $info_name => $info_value) {
3200
-                    $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);
3201
-                }
3202
-                $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3203
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3204
-                if (!empty($output_order[$variation_attribute_code])) {
3205
-                    $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);
3206
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3207
-                        $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3208
-                    }
3209
-                } else {
3210
-                    $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);
3211
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3212
-                        $variation_attribute_ordered['attribute_list'][] = $display_data;
3213
-                    }
3214
-                }
3215
-                unset($variation_tpl_component);
3216
-            }
3217
-        }
3181
+	/**
3182
+	 * Read an array with product options chosen by the customer, order into an array regarding admin definition
3183
+	 *
3184
+	 * @param array $product_definition_value The array with the selected product option to ordered
3185
+	 * @param array $output_order The good order for attribute defined by administrator
3186
+	 * @param dtring $from_page A string allowing to take a specific template regarding the current page
3187
+	 *
3188
+	 * @return array The array containing all product options ordered as the admin configure it
3189
+	 */
3190
+	public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3191
+	{
3192
+		$variation_attribute_ordered = array();
3193
+		$variation_attribute_ordered['prices'] = array();
3194
+		$variation_attribute_ordered['attribute_list'] = array();
3195
+
3196
+		if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3197
+			foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3198
+				$variation_tpl_component = array();
3199
+				foreach ($variation_attribute_detail as $info_name => $info_value) {
3200
+					$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);
3201
+				}
3202
+				$variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3203
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3204
+				if (!empty($output_order[$variation_attribute_code])) {
3205
+					$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);
3206
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3207
+						$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3208
+					}
3209
+				} else {
3210
+					$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);
3211
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3212
+						$variation_attribute_ordered['attribute_list'][] = $display_data;
3213
+					}
3214
+				}
3215
+				unset($variation_tpl_component);
3216
+			}
3217
+		}
3218 3218
 
3219
-        if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3220
-            foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3221
-                $variation_tpl_component = array();
3222
-                foreach ($variation_details as $info_name => $info_value) {
3223
-                    if ($info_name != 'item_meta') {
3224
-                        $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);
3225
-                    }
3226
-                }
3227
-                foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3228
-                    $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3229
-                    $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3230
-                    $variation_tpl_component['VARIATION_ID'] = $variation_id;
3231
-                    $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3232
-
3233
-                    $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3234
-                }
3235
-                if (!empty($output_order[$variation_attribute_code])) {
3236
-                    $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);
3237
-                }
3238
-                unset($variation_tpl_component);
3239
-            }
3240
-        }
3219
+		if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3220
+			foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3221
+				$variation_tpl_component = array();
3222
+				foreach ($variation_details as $info_name => $info_value) {
3223
+					if ($info_name != 'item_meta') {
3224
+						$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);
3225
+					}
3226
+				}
3227
+				foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3228
+					$variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3229
+					$variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3230
+					$variation_tpl_component['VARIATION_ID'] = $variation_id;
3231
+					$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3241 3232
 
3242
-        /**    Free Variation part    */
3243
-        if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3244
-            foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3245
-                if (strpos($build_variation, '-_variation_val_-')) {
3246
-                    $variation_definition = explode('-_variation_val_-', $build_variation);
3247
-                    $attribute_code = $variation_definition[0];
3248
-                    $attribute_selected_value = $variation_definition[1];
3249
-                } else {
3250
-                    $attribute_code = $build_variation_key;
3251
-                    $attribute_selected_value = $build_variation;
3252
-                }
3253
-
3254
-                $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3255
-                $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3256
-                $value_to_outut = $attribute_selected_value;
3257
-                switch ($free_variation_attribute_def->data_type) {
3258
-                    case 'datetime':
3259
-                        $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3260
-                        break;
3261
-                }
3262
-
3263
-                if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3264
-                    switch ($free_variation_attribute_def->data_type_to_use) {
3265
-                        case 'custom':
3266
-                        case 'internal':
3267
-                            $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3268
-                            $value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3269
-                            break;
3270
-                    }
3271
-                }
3272
-                $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3273
-                $variation_tpl_component['VARIATION_ID'] = $attribute_code;
3274
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3275
-                if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3276
-                    $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);
3277
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3278
-                        $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3279
-                    }
3280
-                }
3281
-                unset($variation_tpl_component);
3282
-            }
3283
-        }
3284
-        return $variation_attribute_ordered;
3285
-    }
3233
+					$variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3234
+				}
3235
+				if (!empty($output_order[$variation_attribute_code])) {
3236
+					$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);
3237
+				}
3238
+				unset($variation_tpl_component);
3239
+			}
3240
+		}
3286 3241
 
3287
-    public function wps_selected_variation_picture($head_product_id, $variations)
3288
-    {
3289
-        $response = array();
3290
-        /** Selected Product image **/
3291
-        $post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3292
-        if (!empty($post_thumbnail_id)) {
3293
-            $response['img_id'] = $post_thumbnail_id;
3294
-            $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3295
-            $response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3296
-        }
3242
+		/**    Free Variation part    */
3243
+		if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3244
+			foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3245
+				if (strpos($build_variation, '-_variation_val_-')) {
3246
+					$variation_definition = explode('-_variation_val_-', $build_variation);
3247
+					$attribute_code = $variation_definition[0];
3248
+					$attribute_selected_value = $variation_definition[1];
3249
+				} else {
3250
+					$attribute_code = $build_variation_key;
3251
+					$attribute_selected_value = $build_variation;
3252
+				}
3297 3253
 
3298
-        /** check if have one variation **/
3299
-        if (!empty($variations) && count($variations) == 1) {
3300
-            $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3301
-            if (!empty($variation_attached_image_id)) {
3302
-                $response['img_id'] = $variation_attached_image_id;
3303
-                $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3304
-                $response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3305
-            }
3306
-        }
3307
-        return $response;
3308
-    }
3254
+				$free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3255
+				$variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3256
+				$value_to_outut = $attribute_selected_value;
3257
+				switch ($free_variation_attribute_def->data_type) {
3258
+					case 'datetime':
3259
+						$value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3260
+						break;
3261
+				}
3309 3262
 
3310
-    /** Add a meta box of product sales history in product administration panel **/
3311
-    public function meta_box_product_sale_informations()
3312
-    {
3313
-        global $post;
3314
-        $product_id = $post->ID;
3315
-
3316
-        $variations = self::get_variation($product_id);
3317
-
3318
-        $sales_informations = array();
3319
-        /** Query **/
3320
-        $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3321
-        $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')));
3322
-        $orders = new WP_Query($query_args);
3323
-        if (!empty($orders) && !empty($orders->posts)) {
3324
-            foreach ($orders->posts as $order) {
3325
-                $order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3326
-                $order_info = get_post_meta($order->ID, '_order_info', true);
3327
-                $sales_informations[] = array(
3328
-                    'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3329
-                    'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3330
-                    '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'] : '',
3331
-                    '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'] : '',
3332
-                    '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'] : '',
3333
-                );
3334
-            }
3335
-        }
3263
+				if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3264
+					switch ($free_variation_attribute_def->data_type_to_use) {
3265
+						case 'custom':
3266
+						case 'internal':
3267
+							$possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3268
+							$value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3269
+							break;
3270
+					}
3271
+				}
3272
+				$variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3273
+				$variation_tpl_component['VARIATION_ID'] = $attribute_code;
3274
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3275
+				if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3276
+					$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);
3277
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3278
+						$variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3279
+					}
3280
+				}
3281
+				unset($variation_tpl_component);
3282
+			}
3283
+		}
3284
+		return $variation_attribute_ordered;
3285
+	}
3336 3286
 
3337
-        /** If product has been ordered **/
3338
-        $output = '';
3339
-        if (!empty($sales_informations)) {
3340
-            $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3341
-            $output .= '<ul>';
3342
-            foreach ($sales_informations as $sales_information) {
3343
-                $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>';
3344
-            }
3345
-            $output .= '</ul>';
3346
-        } else {
3347
-            $output .= __('This product has never been ordered', 'wpshop');
3348
-        }
3287
+	public function wps_selected_variation_picture($head_product_id, $variations)
3288
+	{
3289
+		$response = array();
3290
+		/** Selected Product image **/
3291
+		$post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3292
+		if (!empty($post_thumbnail_id)) {
3293
+			$response['img_id'] = $post_thumbnail_id;
3294
+			$response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3295
+			$response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3296
+		}
3349 3297
 
3350
-        echo $output;
3351
-    }
3298
+		/** check if have one variation **/
3299
+		if (!empty($variations) && count($variations) == 1) {
3300
+			$variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3301
+			if (!empty($variation_attached_image_id)) {
3302
+				$response['img_id'] = $variation_attached_image_id;
3303
+				$response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3304
+				$response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3305
+			}
3306
+		}
3307
+		return $response;
3308
+	}
3352 3309
 
3353
-    public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3354
-    {
3355
-        global $wpdb, $wpshop_payment;
3356
-        $output = '';
3357
-        $tpl_component = array();
3358
-        /**    Get attribute order for current product    */
3359
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3360
-        $output_order = array();
3361
-        if (count($product_attribute_order_detail) > 0) {
3362
-            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3363
-                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3364
-                    if (!empty($attribute_def->code)) {
3365
-                        $output_order[$attribute_def->code] = $position;
3366
-                    }
3367
-
3368
-                }
3369
-            }
3370
-        }
3371
-        $variation_attribute_ordered = array();
3372
-
3373
-        /** Check if product is a variation and change his name **/
3374
-        $product_post_type = get_post_type($the_product['product_id']);
3375
-        if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3376
-            $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3377
-            $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3378
-            $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3379
-        }
3310
+	/** Add a meta box of product sales history in product administration panel **/
3311
+	public function meta_box_product_sale_informations()
3312
+	{
3313
+		global $post;
3314
+		$product_id = $post->ID;
3315
+
3316
+		$variations = self::get_variation($product_id);
3317
+
3318
+		$sales_informations = array();
3319
+		/** Query **/
3320
+		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3321
+		$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')));
3322
+		$orders = new WP_Query($query_args);
3323
+		if (!empty($orders) && !empty($orders->posts)) {
3324
+			foreach ($orders->posts as $order) {
3325
+				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3326
+				$order_info = get_post_meta($order->ID, '_order_info', true);
3327
+				$sales_informations[] = array(
3328
+					'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3329
+					'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3330
+					'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'] : '',
3331
+					'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'] : '',
3332
+					'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'] : '',
3333
+				);
3334
+			}
3335
+		}
3380 3336
 
3381
-        foreach ($the_product as $product_definition_key => $product_definition_value) {
3382
-            if ($product_definition_key != 'item_meta') {
3383
-                $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3384
-                if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3385
-                    $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3386
-                }
3387
-            } else {
3388
-                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3389
-            }
3390
-        }
3337
+		/** If product has been ordered **/
3338
+		$output = '';
3339
+		if (!empty($sales_informations)) {
3340
+			$output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3341
+			$output .= '<ul>';
3342
+			foreach ($sales_informations as $sales_information) {
3343
+				$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>';
3344
+			}
3345
+			$output .= '</ul>';
3346
+		} else {
3347
+			$output .= __('This product has never been ordered', 'wpshop');
3348
+		}
3391 3349
 
3392
-        ksort($variation_attribute_ordered['attribute_list']);
3393
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3394
-        foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3395
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3396
-        }
3350
+		echo $output;
3351
+	}
3397 3352
 
3398
-        /**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3399
-        $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3400
-        if (!empty($attribute_list)) {
3401
-            foreach ($attribute_list as $attribute_def) {
3402
-                $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3403
-            }
3404
-        }
3353
+	public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3354
+	{
3355
+		global $wpdb, $wpshop_payment;
3356
+		$output = '';
3357
+		$tpl_component = array();
3358
+		/**    Get attribute order for current product    */
3359
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3360
+		$output_order = array();
3361
+		if (count($product_attribute_order_detail) > 0) {
3362
+			foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3363
+				foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3364
+					if (!empty($attribute_def->code)) {
3365
+						$output_order[$attribute_def->code] = $position;
3366
+					}
3405 3367
 
3406
-        /**    Fill the array with all prices for different variations    */
3407
-        foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3408
-            $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3409
-        }
3368
+				}
3369
+			}
3370
+		}
3371
+		$variation_attribute_ordered = array();
3372
+
3373
+		/** Check if product is a variation and change his name **/
3374
+		$product_post_type = get_post_type($the_product['product_id']);
3375
+		if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3376
+			$parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3377
+			$parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3378
+			$the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3379
+		}
3410 3380
 
3411
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3412
-        $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3413
-        $post_list_with_options = $wpdb->get_results($query);
3414
-        if (!empty($post_list_with_options)) {
3415
-            $additionnal_price = 0;
3416
-            foreach ($post_list_with_options as $product_info) {
3417
-                $product_meta = unserialize($product_info->meta_value);
3418
-                if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3419
-                    $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3420
-
3421
-                    $the_product = array_merge(array(
3422
-                        'product_id' => $product_info->post_id,
3423
-                        'product_qty' => 1,
3424
-                    ), $product);
3425
-
3426
-                    $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3427
-                    $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3428
-
3429
-                    $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));
3430
-                    $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3431
-                }
3432
-            }
3433
-        }
3381
+		foreach ($the_product as $product_definition_key => $product_definition_value) {
3382
+			if ($product_definition_key != 'item_meta') {
3383
+				$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3384
+				if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3385
+					$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3386
+				}
3387
+			} else {
3388
+				$variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3389
+			}
3390
+		}
3434 3391
 
3435
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3436
-        $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3437
-        if (!empty($additionnal_price)) {
3438
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3439
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3440
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3441
-        }
3392
+		ksort($variation_attribute_ordered['attribute_list']);
3393
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3394
+		foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3395
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3396
+		}
3442 3397
 
3443
-        /**    Call informtion for partial payment    */
3444
-        $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3445
-        $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3398
+		/**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3399
+		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3400
+		if (!empty($attribute_list)) {
3401
+			foreach ($attribute_list as $attribute_def) {
3402
+				$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3403
+			}
3404
+		}
3446 3405
 
3447
-        /**    Define the current selected currency for the order summary    */
3406
+		/**    Fill the array with all prices for different variations    */
3407
+		foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3408
+			$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3409
+		}
3410
+
3411
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3412
+		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3413
+		$post_list_with_options = $wpdb->get_results($query);
3414
+		if (!empty($post_list_with_options)) {
3415
+			$additionnal_price = 0;
3416
+			foreach ($post_list_with_options as $product_info) {
3417
+				$product_meta = unserialize($product_info->meta_value);
3418
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3419
+					$product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3420
+
3421
+					$the_product = array_merge(array(
3422
+						'product_id' => $product_info->post_id,
3423
+						'product_qty' => 1,
3424
+					), $product);
3425
+
3426
+					$additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3427
+					$tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3428
+
3429
+					$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));
3430
+					$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3431
+				}
3432
+			}
3433
+		}
3434
+
3435
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3436
+		$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3437
+		if (!empty($additionnal_price)) {
3438
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3439
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3440
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3441
+		}
3442
+
3443
+		/**    Call informtion for partial payment    */
3444
+		$partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3445
+		$tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3446
+
3447
+		/**    Define the current selected currency for the order summary    */
3448 3448
 //         $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3449
-        $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3450
-        return $output;
3451
-    }
3449
+		$output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3450
+		return $output;
3451
+	}
3452 3452
 
3453
-    /**
3454
-     * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3455
-     * @param string $ID ID product variations or not
3456
-     * @return string Return ID
3457
-     */
3458
-    public static function get_id_variation($ID)
3459
-    {
3460
-        $result = explode('__', $ID);
3461
-        return end($result);
3462
-    }
3453
+	/**
3454
+	 * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3455
+	 * @param string $ID ID product variations or not
3456
+	 * @return string Return ID
3457
+	 */
3458
+	public static function get_id_variation($ID)
3459
+	{
3460
+		$result = explode('__', $ID);
3461
+		return end($result);
3462
+	}
3463 3463
 
3464
-    /**
3465
-     * Update all variations definitions who not modified
3466
-     * @param array $new_value
3467
-     * @param array $old_value
3468
-     * @return array $new_value
3469
-     */
3470
-    public static function update_wpshop_catalog_product_option($new_value, $old_value)
3471
-    {
3472
-        global $wpdb;
3473
-        $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') . '%');
3474
-        foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3475
-            $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3476
-            $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3477
-            update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3478
-        }
3479
-        return $new_value;
3480
-    }
3464
+	/**
3465
+	 * Update all variations definitions who not modified
3466
+	 * @param array $new_value
3467
+	 * @param array $old_value
3468
+	 * @return array $new_value
3469
+	 */
3470
+	public static function update_wpshop_catalog_product_option($new_value, $old_value)
3471
+	{
3472
+		global $wpdb;
3473
+		$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') . '%');
3474
+		foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3475
+			$wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3476
+			$wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3477
+			update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3478
+		}
3479
+		return $new_value;
3480
+	}
3481 3481
 
3482
-    public static function variation_parameters_save($current_post_id, $options)
3483
-    {
3482
+	public static function variation_parameters_save($current_post_id, $options)
3483
+	{
3484 3484
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3485
-        $variation_post_meta['options'] = $options;
3486
-        //unset($variation_post_meta['follow_general_config']);
3485
+		$variation_post_meta['options'] = $options;
3486
+		//unset($variation_post_meta['follow_general_config']);
3487 3487
 		$variation_post_meta['follow_general_config'] = true;
3488
-        update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3489
-    }
3488
+		update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3489
+	}
3490 3490
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -184,20 +184,20 @@  discard block
 block discarded – undo
184 184
 	public static function admin_menu() {
185 185
 		global $submenu;
186 186
 		$attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
187
-		$entities_to_unset = array( 'free_product', 'default' );
187
+		$entities_to_unset = array('free_product', 'default');
188 188
 		$submenu_before = $submenu['edit.php?post_type=wpshop_product'];
189 189
 		foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
190
-			if ( !( in_array( $attribute_set->slug, $entities_to_unset ) || in_array( $attribute_set->name, $entities_to_unset ) ) ) {
191
-				add_submenu_page( 'edit.php?post_type=wpshop_product', sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product');
190
+			if (!(in_array($attribute_set->slug, $entities_to_unset) || in_array($attribute_set->name, $entities_to_unset))) {
191
+				add_submenu_page('edit.php?post_type=wpshop_product', sprintf(__('Add %s', 'wpshop'), $attribute_set->name), sprintf(__('Add %s', 'wpshop'), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product');
192 192
 			}
193 193
 		}
194
-		$submenu_new_elements = array_diff_key ( $submenu['edit.php?post_type=wpshop_product'], $submenu_before );
194
+		$submenu_new_elements = array_diff_key($submenu['edit.php?post_type=wpshop_product'], $submenu_before);
195 195
 		$submenu_reorder = array();
196
-		foreach( $submenu_before as $key => $element ) {
197
-			if( empty( $submenu_reorder[$key] ) ) {
196
+		foreach ($submenu_before as $key => $element) {
197
+			if (empty($submenu_reorder[$key])) {
198 198
 				$submenu_reorder[$key] = $element;
199
-				if( in_array( 'post-new.php?post_type=wpshop_product', $element ) ) {
200
-					$submenu_reorder = array_merge( $submenu_reorder, array_values( $submenu_new_elements ) );
199
+				if (in_array('post-new.php?post_type=wpshop_product', $element)) {
200
+					$submenu_reorder = array_merge($submenu_reorder, array_values($submenu_new_elements));
201 201
 				}
202 202
 			} else {
203 203
 				$submenu_reorder[] = $element;
@@ -572,12 +572,12 @@  discard block
 block discarded – undo
572 572
 
573 573
         $products = array();
574 574
         $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
575
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
575
+        $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name));
576 576
 
577 577
         if (!empty($data)) {
578 578
             if ($data['data_type_to_use'] == 'custom') {
579 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;}
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 582
                 if (isset($table_name)) {
583 583
                     // If the value is an id of a select, radio or checkbox
@@ -727,11 +727,11 @@  discard block
 block discarded – undo
727 727
         if (!empty($atts['product_type'])) {
728 728
             switch ($atts['product_type']) {
729 729
                 case 'related':
730
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
730
+                    $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID();
731 731
                     $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
732 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 733
 
734
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
734
+                    $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
735 735
                     if (!empty($pids) && !empty($pids[0])) {
736 736
                         $pid = implode(',', $pids);
737 737
                     }
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
     {
1251 1251
         global $wpdb;
1252 1252
 
1253
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1253
+        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST;
1254 1254
         // Apply a filter to extra actions
1255 1255
         $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1256 1256
 
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
                             $attributeValue = str_replace(',', '.', $attributeValue);
1307 1307
                         }
1308 1308
                         if (($attributeType == 'integer') && !is_array($attributeValue)) {
1309
-                            $attributeValue = (int) $attributeValue;
1309
+                            $attributeValue = (int)$attributeValue;
1310 1310
                         }
1311 1311
                         $productMetaDatas[$attributeCode] = $attributeValue;
1312 1312
                     }
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
                                     $attributeValue = str_replace(',', '.', $attribute->$value_key);
1357 1357
                                 }
1358 1358
                                 if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1359
-                                    $attributeValue = (int) $attribute->$value_key;
1359
+                                    $attributeValue = (int)$attribute->$value_key;
1360 1360
                                 }
1361 1361
                                 $variation_metadata[$attribute->code] = $attribute->$value_key;
1362 1362
                             }
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
                                 $attributeValue = str_replace(',', '.', $attributeValue);
1370 1370
                             }
1371 1371
                             if (($attributeType == 'integer') && !is_array($attributeValue)) {
1372
-                                $attributeValue = (int) $attributeValue;
1372
+                                $attributeValue = (int)$attributeValue;
1373 1373
                             }
1374 1374
                             $variation_metadata[$attributeCode] = $attributeValue;
1375 1375
                         }
@@ -1705,13 +1705,13 @@  discard block
 block discarded – undo
1705 1705
             if (!empty($product_price_infos)) {
1706 1706
                 $tpl_component_price = array();
1707 1707
                 /** Price piloting **/
1708
-				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1709
-				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1708
+				$price_display_option = get_option('wpshop_catalog_product_option');
1709
+				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : '';
1710 1710
                 $price_ploting = get_option('wpshop_shop_price_piloting');
1711 1711
                 $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'])) : '';
1712 1712
                 $variations = wpshop_products::get_variation($product_id);
1713 1713
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1714
-				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1714
+				if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) {
1715 1715
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1716 1716
 				}
1717 1717
                 $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
@@ -2154,7 +2154,7 @@  discard block
 block discarded – undo
2154 2154
             }
2155 2155
 
2156 2156
             $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2157
-						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2157
+						$template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id);
2158 2158
 
2159 2159
             $tpl_component = array();
2160 2160
             $tpl_component['PRODUCT_ID'] = $product_id;
@@ -3117,7 +3117,7 @@  discard block
 block discarded – undo
3117 3117
              * Since 1.4.3.7
3118 3118
              * L'option du produit remplace le prix du produit de tête.
3119 3119
              */
3120
-			if( true ) {
3120
+			if (true) {
3121 3121
                 //Replace the product price
3122 3122
                 if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3123 3123
                     $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
Please login to merge, or discard this patch.
includes/modules/wps_orders/templates/backend/product_order_historic.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
2
- if( !empty($sales_informations) ): ?>
1
+<?php if (!defined('ABSPATH')) exit;
2
+ if (!empty($sales_informations)): ?>
3 3
 <div class="wps-table">
4 4
 	<div class="wps-table-header wps-table-row">
5
-		<div class="wps-table-cell"><?php _e( 'Date', 'wpshop'); ?></div>
6
-		<div class="wps-table-cell"><?php _e( 'Order ID', 'wpshop'); ?></div>
7
-		<div class="wps-table-cell"><?php _e( 'Customer', 'wpshop'); ?></div>
8
-		<div class="wps-table-cell"><?php _e( 'Order Status', 'wpshop'); ?></div>
5
+		<div class="wps-table-cell"><?php _e('Date', 'wpshop'); ?></div>
6
+		<div class="wps-table-cell"><?php _e('Order ID', 'wpshop'); ?></div>
7
+		<div class="wps-table-cell"><?php _e('Customer', 'wpshop'); ?></div>
8
+		<div class="wps-table-cell"><?php _e('Order Status', 'wpshop'); ?></div>
9 9
 		<div class="wps-table-cell"></div>
10 10
 	</div>
11
-	<?php foreach( $sales_informations as $sale_informations) : ?>
11
+	<?php foreach ($sales_informations as $sale_informations) : ?>
12 12
 		<div class="wps-table-content wps-table-row">
13
-			<div class="wps-table-cell"><?php echo mysql2date('d F Y, H:i:s',$sale_informations['order_date'], true);?></div>
13
+			<div class="wps-table-cell"><?php echo mysql2date('d F Y, H:i:s', $sale_informations['order_date'], true); ?></div>
14 14
 			<div class="wps-table-cell"><?php echo $sale_informations['order_key']; ?></div>
15
-			<div class="wps-table-cell"><?php echo $sale_informations['customer_name']. ' '.$sale_informations['customer_firstname'].' ('.$sale_informations['customer_email'].')'; ?></div>
16
-			<div class="wps-table-cell"><span class="wps-label-<?php echo $color_label[ strtolower($sale_informations['order_status']) ]; ?>"><?php _e( $order_status[ strtolower($sale_informations['order_status']) ], 'wpshop' ); ?></span></div>
17
-			<div class="wps-table-cell"><a href="<?php echo admin_url('post.php?post=' .$sale_informations['order_id']. '&action=edit'); ?>" class="wps-bton-mini-rounded-first" target="_blank"><?php _e( 'See the order', 'wpshop'); ?></a></div>
15
+			<div class="wps-table-cell"><?php echo $sale_informations['customer_name'] . ' ' . $sale_informations['customer_firstname'] . ' (' . $sale_informations['customer_email'] . ')'; ?></div>
16
+			<div class="wps-table-cell"><span class="wps-label-<?php echo $color_label[strtolower($sale_informations['order_status'])]; ?>"><?php _e($order_status[strtolower($sale_informations['order_status'])], 'wpshop'); ?></span></div>
17
+			<div class="wps-table-cell"><a href="<?php echo admin_url('post.php?post=' . $sale_informations['order_id'] . '&action=edit'); ?>" class="wps-bton-mini-rounded-first" target="_blank"><?php _e('See the order', 'wpshop'); ?></a></div>
18 18
 		</div>
19 19
 	<?php endforeach; ?>
20 20
 </div>
21 21
 <?php $big = 999999999; // need an unlikely integer
22
-echo paginate_links( array(
22
+echo paginate_links(array(
23 23
 	'base' => '%_%',
24 24
 	'format' => '?paged_sales=%#%',
25
-	'current' => absint( isset( $_GET['paged_sales'] ) ? $_GET['paged_sales'] : 1 ),
25
+	'current' => absint(isset($_GET['paged_sales']) ? $_GET['paged_sales'] : 1),
26 26
 	'total' => $orders->max_num_pages
27
-) ); ?>
27
+)); ?>
28 28
 <?php else : ?>
29
-	<div class="wps-alert-info"><?php _e( 'This product has never been ordered', 'wpshop'); ?></div>
29
+	<div class="wps-alert-info"><?php _e('This product has never been ordered', 'wpshop'); ?></div>
30 30
 <?php endif; ?>
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
  if( !empty($sales_informations) ): ?>
3 5
 <div class="wps-table">
4 6
 	<div class="wps-table-header wps-table-row">
@@ -25,6 +27,9 @@  discard block
 block discarded – undo
25 27
 	'current' => absint( isset( $_GET['paged_sales'] ) ? $_GET['paged_sales'] : 1 ),
26 28
 	'total' => $orders->max_num_pages
27 29
 ) ); ?>
28
-<?php else : ?>
29
-	<div class="wps-alert-info"><?php _e( 'This product has never been ordered', 'wpshop'); ?></div>
30
+<?php else {
31
+	: ?>
32
+	<div class="wps-alert-info"><?php _e( 'This product has never been ordered', 'wpshop');
33
+}
34
+?></div>
30 35
 <?php endif; ?>
Please login to merge, or discard this patch.
includes/modules/wps_orders/controller/wps_orders_in_back_office.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_orders_in_back_office {
3 3
 
4 4
 	function __construct() {
5 5
 		// Template loading
6 6
 		$this->template_dir = WPS_ORDERS_PATH . WPS_ORDERS_DIR . "/templates/";
7
-		add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes') );
7
+		add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
8 8
 
9 9
 		// Ajax actions
10
-		add_action('wp_ajax_wpshop_add_private_comment_to_order', array( $this, 'wpshop_add_private_comment_to_order' ) );
11
-		add_action('wp_ajax_wps_order_refresh_product_listing', array( $this, 'refresh_product_list' ) );
12
-		add_action('wp_ajax_wps_add_product_to_order_admin', array( $this, 'wps_add_product_to_order_admin' ) );
13
-		add_action('wp_ajax_wps_refresh_cart_order', array( $this, 'refresh_cart_order' ) );
14
-		add_action('wp_ajax_wps_refresh_payments_order', array( $this, 'refresh_payments_order' ) );
15
-		add_action('wp_ajax_wps_update_product_qty_in_admin', array( $this, 'wps_update_product_qty_in_admin' ) );
16
-		add_action('wp_ajax_wps_order_load_product_variations', array( $this, 'wps_order_load_product_variations' ) );
17
-		add_action('wp_ajax_wps-orders-update-cart-informations', array( $this, 'wps_orders_update_cart_informations' ) );
18
-		add_action('wp_ajax_wps_reverify_payment_invoice_ref', array( $this, 'wps_reverify_payment_invoice_ref' ) );
10
+		add_action('wp_ajax_wpshop_add_private_comment_to_order', array($this, 'wpshop_add_private_comment_to_order'));
11
+		add_action('wp_ajax_wps_order_refresh_product_listing', array($this, 'refresh_product_list'));
12
+		add_action('wp_ajax_wps_add_product_to_order_admin', array($this, 'wps_add_product_to_order_admin'));
13
+		add_action('wp_ajax_wps_refresh_cart_order', array($this, 'refresh_cart_order'));
14
+		add_action('wp_ajax_wps_refresh_payments_order', array($this, 'refresh_payments_order'));
15
+		add_action('wp_ajax_wps_update_product_qty_in_admin', array($this, 'wps_update_product_qty_in_admin'));
16
+		add_action('wp_ajax_wps_order_load_product_variations', array($this, 'wps_order_load_product_variations'));
17
+		add_action('wp_ajax_wps-orders-update-cart-informations', array($this, 'wps_orders_update_cart_informations'));
18
+		add_action('wp_ajax_wps_reverify_payment_invoice_ref', array($this, 'wps_reverify_payment_invoice_ref'));
19 19
 
20 20
 		// WP General actions
21
-		add_action( 'admin_enqueue_scripts', array( $this, 'wps_orders_scripts') );
22
-		add_action( 'admin_enqueue_scripts', array( $this, 'wps_orders_scripts_texts' ), 20 );
23
-		add_action('save_post', array( $this, 'save_order_custom_informations'));
21
+		add_action('admin_enqueue_scripts', array($this, 'wps_orders_scripts'));
22
+		add_action('admin_enqueue_scripts', array($this, 'wps_orders_scripts_texts'), 20);
23
+		add_action('save_post', array($this, 'save_order_custom_informations'));
24 24
 
25 25
 		// WP Filters
26 26
 		//add_filter( 'wps_order_saving_admin_extra_action', array( $this, 'wps_notif_user_on_order_saving'), 100, 2 );
@@ -31,51 +31,51 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	function wps_orders_scripts() {
33 33
 		global $current_screen;
34
-		if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) )
34
+		if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER), true))
35 35
 			return;
36 36
 
37
-		wp_enqueue_script( 'wps_orders_backend', WPS_ORDERS_URL.WPS_ORDERS_DIR.'/assets/backend/js/wps_orders.js' );
37
+		wp_enqueue_script('wps_orders_backend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/backend/js/wps_orders.js');
38 38
 	}
39 39
 
40 40
 	function wps_orders_scripts_texts() {
41
-		wp_localize_script( 'wps_orders_backend', 'message_confirm_reload', __( 'Are you sure you want to refresh your browser?', 'wpshop' ) );
42
-		wp_localize_script( 'wps_orders_backend', 'message_error_reverify_payment_invoice_ref', __( 'Error detected.', 'wpshop' ) );
41
+		wp_localize_script('wps_orders_backend', 'message_confirm_reload', __('Are you sure you want to refresh your browser?', 'wpshop'));
42
+		wp_localize_script('wps_orders_backend', 'message_error_reverify_payment_invoice_ref', __('Error detected.', 'wpshop'));
43 43
 	}
44 44
 	/**
45 45
 	 * Add meta boxes
46 46
 	 */
47 47
 	function add_meta_boxes() {
48 48
 		global $post;
49
-		$order_meta = get_post_meta( $post->ID, '_order_postmeta', true );
49
+		$order_meta = get_post_meta($post->ID, '_order_postmeta', true);
50 50
 		/** Box  Order Payments **/
51
-		if( !in_array( $post->post_status, array( 'auto-draft' ) ) ) {
52
-			add_meta_box('wpshop_order_payment', '<span class="dashicons dashicons-money"></span> '.__('Order payment', 'wpshop'),array($this, 'display_order_payments_box'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low');
51
+		if (!in_array($post->post_status, array('auto-draft'))) {
52
+			add_meta_box('wpshop_order_payment', '<span class="dashicons dashicons-money"></span> ' . __('Order payment', 'wpshop'), array($this, 'display_order_payments_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low');
53 53
 		}
54 54
 		/**	Box for customer order comment */
55
-		if ( ! empty( $post->post_excerpt ) ) {
56
-			add_meta_box('wpshop_order_customer_comment', '<span class="dashicons dashicons-format-status"></span> '.__('Order customer comment', 'wpshop'),array( $this, 'order_customer_comment_box'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low');
55
+		if (!empty($post->post_excerpt)) {
56
+			add_meta_box('wpshop_order_customer_comment', '<span class="dashicons dashicons-format-status"></span> ' . __('Order customer comment', 'wpshop'), array($this, 'order_customer_comment_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low');
57 57
 		}
58 58
 		/** Historic sales **/
59
-		add_meta_box('wpshop_product_order_historic', __('Sales informations', 'wpshop'), array( $this, 'meta_box_product_sale_informations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low');
59
+		add_meta_box('wpshop_product_order_historic', __('Sales informations', 'wpshop'), array($this, 'meta_box_product_sale_informations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low');
60 60
 		/**	Box with the complete order content	*/
61 61
 		$payment_started = false;
62
-		if ( ! empty( $order_meta['order_payment'] ) && ! empty( $order_meta['order_payment']['received'] ) ) {
63
-			foreach ( $order_meta['order_payment']['received'] as $received ) {
64
-				if ( empty( $received['received_amount'] ) ) {
62
+		if (!empty($order_meta['order_payment']) && !empty($order_meta['order_payment']['received'])) {
63
+			foreach ($order_meta['order_payment']['received'] as $received) {
64
+				if (empty($received['received_amount'])) {
65 65
 					continue;
66 66
 				}
67 67
 				$payment_started = true;
68 68
 				break;
69 69
 			}
70 70
 		}
71
-		if ( ! $payment_started ) {
72
-			add_meta_box( 'wpshop_product_list', '<span class="dashicons dashicons-archive"></span> ' . __( 'Product List', 'wpshop' ), array( $this, 'wps_products_listing_for_quotation' ), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low' );
71
+		if (!$payment_started) {
72
+			add_meta_box('wpshop_product_list', '<span class="dashicons dashicons-archive"></span> ' . __('Product List', 'wpshop'), array($this, 'wps_products_listing_for_quotation'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low');
73 73
 		}
74 74
 		/**	Box with the complete order content	*/
75
-		add_meta_box( 'wpshop_order_content', '<span class="dashicons dashicons-cart"></span> '.__('Order content', 'wpshop'), array( $this, 'meta_box_order_content'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low');
75
+		add_meta_box('wpshop_order_content', '<span class="dashicons dashicons-cart"></span> ' . __('Order content', 'wpshop'), array($this, 'meta_box_order_content'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low');
76 76
 		/** Box Private order comments **/
77
-		if( !in_array( $post->post_status, array( 'auto-draft' ) ) ) {
78
-			add_meta_box('wpshop_order_private_comments', '<span class="dashicons dashicons-format-chat"></span> '.__('Comments', 'wpshop'), array( $this, 'meta_box_private_comment'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low');
77
+		if (!in_array($post->post_status, array('auto-draft'))) {
78
+			add_meta_box('wpshop_order_private_comments', '<span class="dashicons dashicons-format-chat"></span> ' . __('Comments', 'wpshop'), array($this, 'meta_box_private_comment'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low');
79 79
 		}
80 80
 	}
81 81
 
@@ -83,65 +83,65 @@  discard block
 block discarded – undo
83 83
 	 * METABOX CONTENT - Display Customer comments on order in administration panel
84 84
 	 * @param object $order
85 85
 	 */
86
-	function order_customer_comment_box( $order ) {
87
-		if ( !empty($order) && !empty($order->ID) ) {
88
-			require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "customer_comment_on_order_box") );
86
+	function order_customer_comment_box($order) {
87
+		if (!empty($order) && !empty($order->ID)) {
88
+			require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "customer_comment_on_order_box"));
89 89
 		}
90 90
 	}
91 91
 
92 92
 	/**
93 93
 	 * METABOX CONTENT - Display an order historic of product in administration product panel
94 94
 	 */
95
-	function meta_box_product_sale_informations () {
95
+	function meta_box_product_sale_informations() {
96 96
  		global $post;
97 97
  		$product_id = $post->ID;
98
- 		$variations = wpshop_products::get_variation( $product_id );
99
- 		$order_status = unserialize( WPSHOP_ORDER_STATUS );
100
- 		$color_label = array( 'awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge', 'pos' => 'bleu');
98
+ 		$variations = wpshop_products::get_variation($product_id);
99
+ 		$order_status = unserialize(WPSHOP_ORDER_STATUS);
100
+ 		$color_label = array('awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge', 'pos' => 'bleu');
101 101
  		// Get datas
102 102
  		$sales_informations = array();
103 103
  		/** Query **/
104
- 		$data_to_compare = '"item_id";s:' .strlen($product_id). ':"' .$product_id. '";';
105
- 		$query_args = array( 'posts_per_page' => 10, 'paged' => absint( isset( $_GET['paged_sales'] ) ? $_GET['paged_sales'] : 1 ), 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array( array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE') ) );
106
- 		$orders = new WP_Query( $query_args );
107
- 		if ( !empty($orders) && !empty($orders->posts) ) {
108
- 			foreach( $orders->posts as $order ) {
109
- 				$order_meta = get_post_meta( $order->ID, '_order_postmeta', true );
110
- 				$order_info = get_post_meta( $order->ID, '_order_info', true );
104
+ 		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
105
+ 		$query_args = array('posts_per_page' => 10, 'paged' => absint(isset($_GET['paged_sales']) ? $_GET['paged_sales'] : 1), 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE')));
106
+ 		$orders = new WP_Query($query_args);
107
+ 		if (!empty($orders) && !empty($orders->posts)) {
108
+ 			foreach ($orders->posts as $order) {
109
+ 				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
110
+ 				$order_info = get_post_meta($order->ID, '_order_info', true);
111 111
  				$sales_informations[] = array(
112
- 						'order_key' => ( !empty($order_meta) && !empty($order_meta['order_key']) ) ? $order_meta['order_key'] : '',
113
- 						'order_date' => ( !empty($order_meta) && !empty($order_meta['order_date']) ) ? $order_meta['order_date'] : '',
114
- 						'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'] : '',
115
- 						'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'] : '',
116
- 						'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'] : '',
112
+ 						'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
113
+ 						'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
114
+ 						'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'] : '',
115
+ 						'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'] : '',
116
+ 						'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'] : '',
117 117
  						'order_id' => $order->ID,
118 118
  						'order_status' => $order_meta['order_status']
119 119
  				);
120 120
  			}
121 121
  		}
122 122
  		// Display results
123
- 		require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product_order_historic") );
123
+ 		require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product_order_historic"));
124 124
  	}
125 125
 
126 126
 	/**
127 127
 	 * METABOX CONTENT - Payments Box in Orders panel
128 128
 	 * @param string $order
129 129
 	 */
130
-	function display_order_payments_box( $order ) {
130
+	function display_order_payments_box($order) {
131 131
 		$order_status = unserialize(WPSHOP_ORDER_STATUS);
132 132
 		$order_postmeta = get_post_meta($order->ID, '_order_postmeta', true);
133
-		require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "wps_order_payment_box") );
133
+		require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "wps_order_payment_box"));
134 134
 	}
135 135
 
136 136
 	/**
137 137
 	 * METABOX CONTENT - Display an lsiting of products to make quotation in backend
138 138
 	 */
139 139
 	function wps_products_listing_for_quotation($post) {
140
-		$letters = array( 'ALL', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
141
-		$current_letter = sanitize_title( $letters[1] );
140
+		$letters = array('ALL', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
141
+		$current_letter = sanitize_title($letters[1]);
142 142
 		$wps_product_mdl = new wps_product_mdl();
143
-		$products = $wps_product_mdl->get_products_by_letter( $current_letter );
144
-		require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing") );
143
+		$products = $wps_product_mdl->get_products_by_letter($current_letter);
144
+		require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing"));
145 145
 	}
146 146
 
147 147
 	/**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	function meta_box_private_comment() {
151 151
 		global $post;
152
-		require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_private_comments") );
152
+		require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_private_comments"));
153 153
 	}
154 154
 
155 155
 	/**
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 */
158 158
 	function meta_box_order_content() {
159 159
 		global $post_id;
160
-		unset( $_SESSION['cart'] );
161
-		echo do_shortcode( '[wps_cart oid="' .$post_id. '" cart_type="admin-panel"]');
160
+		unset($_SESSION['cart']);
161
+		echo do_shortcode('[wps_cart oid="' . $post_id . '" cart_type="admin-panel"]');
162 162
 	}
163 163
 
164 164
 
@@ -168,68 +168,68 @@  discard block
 block discarded – undo
168 168
 	function save_order_custom_informations() {
169 169
 		global $wpdb;
170 170
 
171
-		$post_ID = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0;
171
+		$post_ID = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0;
172 172
 		// Check if it is an order save action
173
-		if ( !empty($post_ID) && ( get_post_type($post_ID) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) ) {
173
+		if (!empty($post_ID) && (get_post_type($post_ID) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER)) {
174 174
 			//Define Customer ID
175
-			$user_id = ( !empty( $_REQUEST['wps_customer_id'] ) ) ? (int) $_REQUEST['wps_customer_id'] : get_current_user_id();
175
+			$user_id = (!empty($_REQUEST['wps_customer_id'])) ? (int)$_REQUEST['wps_customer_id'] : get_current_user_id();
176 176
 
177 177
 			// Order MetaData
178
-			$order_meta = get_post_meta( $post_ID, '_order_postmeta', true);
178
+			$order_meta = get_post_meta($post_ID, '_order_postmeta', true);
179 179
 
180 180
 			// Save General information of order's attached customer
181
-			$wpdb->update( $wpdb->posts, array('post_author' => $user_id, 'post_parent' => $user_id, 'post_status' => 'publish'),  array('ID' => $post_ID) );
182
-			update_post_meta( $post_ID, '_wpshop_order_customer_id', $user_id );
181
+			$wpdb->update($wpdb->posts, array('post_author' => $user_id, 'post_parent' => $user_id, 'post_status' => 'publish'), array('ID' => $post_ID));
182
+			update_post_meta($post_ID, '_wpshop_order_customer_id', $user_id);
183 183
 			$order_meta['customer_id'] = $user_id;
184
-			if ( empty($order_meta['order_key']) ) {
185
-				$order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && ($order_meta['order_status']!='awaiting_payment') ? wpshop_orders::get_new_order_reference() : '');
184
+			if (empty($order_meta['order_key'])) {
185
+				$order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && ($order_meta['order_status'] != 'awaiting_payment') ? wpshop_orders::get_new_order_reference() : '');
186 186
 				$order_meta['order_temporary_key'] = (isset($order_meta['order_temporary_key']) && ($order_meta['order_temporary_key'] != '')) ? $order_meta['order_temporary_key'] : wpshop_orders::get_new_pre_order_reference();
187 187
 			}
188 188
 			$order_meta['order_status'] = (isset($order_meta['order_status']) && ($order_meta['order_status'] != '')) ? $order_meta['order_status'] : 'awaiting_payment';
189 189
 			$order_meta['order_date'] = (isset($order_meta['order_date']) && ($order_meta['order_date'] != '')) ? $order_meta['order_date'] : current_time('mysql', 0);
190 190
 			$order_meta['order_currency'] = wpshop_tools::wpshop_get_currency(true);
191 191
 
192
-			$billing_adress_id = ( !empty( $_REQUEST['wps_order_selected_address'] ) && !empty( $_REQUEST['wps_order_selected_address']['billing'] ) ) ? (int) $_REQUEST['wps_order_selected_address']['billing'] : 0;
192
+			$billing_adress_id = (!empty($_REQUEST['wps_order_selected_address']) && !empty($_REQUEST['wps_order_selected_address']['billing'])) ? (int)$_REQUEST['wps_order_selected_address']['billing'] : 0;
193 193
 
194 194
 			// Order Attached Addresses save
195
-			if( !empty( $billing_adress_id ) ) {
195
+			if (!empty($billing_adress_id)) {
196 196
 				// Informations
197
-				$order_informations = get_post_meta( $post_ID, '_order_info', true );
198
-				$order_informations = ( !empty($order_informations) ) ? $order_informations : array();
199
-				$billing_address_option = get_option( 'wpshop_billing_address' );
200
-				$billing_address_option = ( !empty($billing_address_option) && !empty( $billing_address_option['choice'] ) ) ? $billing_address_option['choice'] : '';
197
+				$order_informations = get_post_meta($post_ID, '_order_info', true);
198
+				$order_informations = (!empty($order_informations)) ? $order_informations : array();
199
+				$billing_address_option = get_option('wpshop_billing_address');
200
+				$billing_address_option = (!empty($billing_address_option) && !empty($billing_address_option['choice'])) ? $billing_address_option['choice'] : '';
201 201
 
202 202
 				// Billing datas
203
-				$order_informations['billing'] = array( 'id' => $billing_address_option,
203
+				$order_informations['billing'] = array('id' => $billing_address_option,
204 204
 						'address_id' => $billing_adress_id,
205
-						'address' => get_post_meta( $billing_adress_id, '_wpshop_address_metadata', true )
205
+						'address' => get_post_meta($billing_adress_id, '_wpshop_address_metadata', true)
206 206
 				);
207 207
 				// Shipping datas
208
-				$shipping_adress_id = ( !empty( $_REQUEST['wps_order_selected_address'] ) && !empty( $_REQUEST['wps_order_selected_address']['shipping'] ) ) ? (int) $_REQUEST['wps_order_selected_address']['shipping'] : 0;
208
+				$shipping_adress_id = (!empty($_REQUEST['wps_order_selected_address']) && !empty($_REQUEST['wps_order_selected_address']['shipping'])) ? (int)$_REQUEST['wps_order_selected_address']['shipping'] : 0;
209 209
 
210
-				if( !empty( $shipping_adress_id ) ) {
211
-					$shipping_address_option = get_option( 'wpshop_shipping_address_choice' );
212
-					$shipping_address_option = ( !empty($shipping_address_option) && !empty($shipping_address_option['choice']) ) ? $shipping_address_option['choice'] : '';
213
-					$order_informations['shipping'] = array( 'id' => $shipping_address_option,
210
+				if (!empty($shipping_adress_id)) {
211
+					$shipping_address_option = get_option('wpshop_shipping_address_choice');
212
+					$shipping_address_option = (!empty($shipping_address_option) && !empty($shipping_address_option['choice'])) ? $shipping_address_option['choice'] : '';
213
+					$order_informations['shipping'] = array('id' => $shipping_address_option,
214 214
 							'address_id' => $shipping_adress_id,
215
-							'address' => get_post_meta( $shipping_adress_id, '_wpshop_address_metadata', true )
215
+							'address' => get_post_meta($shipping_adress_id, '_wpshop_address_metadata', true)
216 216
 					);
217 217
 				}
218
-				update_post_meta( $post_ID, '_order_info', $order_informations );
218
+				update_post_meta($post_ID, '_order_info', $order_informations);
219 219
 			}
220 220
 
221
-			$wpshop_admin_order_payment_received = !empty( $_REQUEST['wpshop_admin_order_payment_received'] ) ? (array)$_REQUEST['wpshop_admin_order_payment_received'] : array();
222
-			$wpshop_admin_order_payment_received['method'] = !empty( $wpshop_admin_order_payment_received['method'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['method'] ) : '';
223
-			$wpshop_admin_order_payment_received['payment_reference'] = !empty( $wpshop_admin_order_payment_received['payment_reference'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['payment_reference'] ) : '';
224
-			$wpshop_admin_order_payment_received['date'] = !empty( $wpshop_admin_order_payment_received['date'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['date'] ) : '';
225
-			$wpshop_admin_order_payment_received['received_amount'] = !empty( $wpshop_admin_order_payment_received['received_amount'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['received_amount'] ) : '';
226
-			$action_triggered_from = !empty( $_REQUEST['action_triggered_from'] ) ? sanitize_text_field( $_REQUEST['action_triggered_from'] ) : '';
227
-			$wshop_admin_order_payment_reference = !empty( $_REQUEST['wpshop_admin_order_payment_reference'] ) ? sanitize_text_field( $_REQUEST['wpshop_admin_order_payment_reference'] ) : '';
221
+			$wpshop_admin_order_payment_received = !empty($_REQUEST['wpshop_admin_order_payment_received']) ? (array)$_REQUEST['wpshop_admin_order_payment_received'] : array();
222
+			$wpshop_admin_order_payment_received['method'] = !empty($wpshop_admin_order_payment_received['method']) ? sanitize_text_field($wpshop_admin_order_payment_received['method']) : '';
223
+			$wpshop_admin_order_payment_received['payment_reference'] = !empty($wpshop_admin_order_payment_received['payment_reference']) ? sanitize_text_field($wpshop_admin_order_payment_received['payment_reference']) : '';
224
+			$wpshop_admin_order_payment_received['date'] = !empty($wpshop_admin_order_payment_received['date']) ? sanitize_text_field($wpshop_admin_order_payment_received['date']) : '';
225
+			$wpshop_admin_order_payment_received['received_amount'] = !empty($wpshop_admin_order_payment_received['received_amount']) ? sanitize_text_field($wpshop_admin_order_payment_received['received_amount']) : '';
226
+			$action_triggered_from = !empty($_REQUEST['action_triggered_from']) ? sanitize_text_field($_REQUEST['action_triggered_from']) : '';
227
+			$wshop_admin_order_payment_reference = !empty($_REQUEST['wpshop_admin_order_payment_reference']) ? sanitize_text_field($_REQUEST['wpshop_admin_order_payment_reference']) : '';
228 228
 
229 229
 			// Add a Payment to Order MetaData
230
-			if ( !empty($wpshop_admin_order_payment_received) && !empty($wpshop_admin_order_payment_received['method'])
230
+			if (!empty($wpshop_admin_order_payment_received) && !empty($wpshop_admin_order_payment_received['method'])
231 231
 					&& !empty($wpshop_admin_order_payment_received['date']) && !empty($wpshop_admin_order_payment_received['received_amount']) &&
232
-					( $action_triggered_from == 'add_payment' || !empty($wshop_admin_order_payment_reference) ) ) {
232
+					($action_triggered_from == 'add_payment' || !empty($wshop_admin_order_payment_reference))) {
233 233
 
234 234
 				$received_payment_amount = $wpshop_admin_order_payment_received['received_amount'];
235 235
 				// Payment Params
@@ -242,36 +242,36 @@  discard block
 block discarded – undo
242 242
 						'date' 				=> current_time('mysql', 0),
243 243
 						'received_amount' 	=> $received_payment_amount
244 244
 				);
245
-				$order_meta = wpshop_payment::check_order_payment_total_amount($post_ID, $params_array, 'completed', $order_meta, false );
245
+				$order_meta = wpshop_payment::check_order_payment_total_amount($post_ID, $params_array, 'completed', $order_meta, false);
246 246
 			}
247 247
 
248 248
 			//Round final amount
249
-			$order_meta['order_grand_total'] = number_format( round($order_meta['order_grand_total'], 2), 2, '.', '');
250
-			$order_meta['order_total_ttc'] = number_format( round($order_meta['order_total_ttc'], 2), 2, '.', '');
251
-			$order_meta['order_amount_to_pay_now'] = number_format( round($order_meta['order_amount_to_pay_now'], 2), 2, '.', '');
249
+			$order_meta['order_grand_total'] = number_format(round($order_meta['order_grand_total'], 2), 2, '.', '');
250
+			$order_meta['order_total_ttc'] = number_format(round($order_meta['order_total_ttc'], 2), 2, '.', '');
251
+			$order_meta['order_amount_to_pay_now'] = number_format(round($order_meta['order_amount_to_pay_now'], 2), 2, '.', '');
252 252
 
253 253
 			// Payment Pre-Fill
254
-			if ( empty( $order_meta['order_payment'] ) ) {
254
+			if (empty($order_meta['order_payment'])) {
255 255
 				$order_meta['order_payment']['customer_choice']['method'] = '';
256
-				$order_meta['order_payment']['received'][] = array('waited_amount' => ( !empty($order_meta) && !empty($order_meta['order_grand_total']) ) ? number_format($order_meta['order_grand_total'],2,'.', '') : 0 );
256
+				$order_meta['order_payment']['received'][] = array('waited_amount' => (!empty($order_meta) && !empty($order_meta['order_grand_total'])) ? number_format($order_meta['order_grand_total'], 2, '.', '') : 0);
257 257
 			}
258 258
 
259
-			$data['post_ID'] = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0;
260
-			$data['markascanceled_order_hidden_indicator'] = !empty( $_REQUEST['markascanceled_order_hidden_indicator' ] ) ? sanitize_text_field( $_REQUEST['markascanceled_order_hidden_indicator'] ) : '';
261
-			$data['resendordertocustomer_order_hidden_indicator'] = !empty( $_REQUEST['resendordertocustomer_order_hidden_indicator' ] ) ? sanitize_text_field( $_REQUEST['resendordertocustomer_order_hidden_indicator'] ) : '';
262
-			$data['action_triggered_from'] = !empty( $_REQUEST['action_triggered_from' ] ) ? sanitize_text_field( $_REQUEST['action_triggered_from'] ) : '';
263
-			$data['notif_the_customer'] = !empty( $_REQUEST['notif_the_customer' ] ) ? sanitize_text_field( $_REQUEST['notif_the_customer'] ) : '';
259
+			$data['post_ID'] = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0;
260
+			$data['markascanceled_order_hidden_indicator'] = !empty($_REQUEST['markascanceled_order_hidden_indicator']) ? sanitize_text_field($_REQUEST['markascanceled_order_hidden_indicator']) : '';
261
+			$data['resendordertocustomer_order_hidden_indicator'] = !empty($_REQUEST['resendordertocustomer_order_hidden_indicator']) ? sanitize_text_field($_REQUEST['resendordertocustomer_order_hidden_indicator']) : '';
262
+			$data['action_triggered_from'] = !empty($_REQUEST['action_triggered_from']) ? sanitize_text_field($_REQUEST['action_triggered_from']) : '';
263
+			$data['notif_the_customer'] = !empty($_REQUEST['notif_the_customer']) ? sanitize_text_field($_REQUEST['notif_the_customer']) : '';
264 264
 			// Apply a filter to make credit, notificate the customer and generate billing actions
265
-			$order_meta = apply_filters( 'wps_order_saving_admin_extra_action', $order_meta, $data );
265
+			$order_meta = apply_filters('wps_order_saving_admin_extra_action', $order_meta, $data);
266 266
 
267 267
 			// Save Shipping informations & Order status
268
-			if ( isset( $order_meta['order_shipping_date'] ) ) {
269
-				update_post_meta( $post_ID, '_wpshop_order_shipping_date', $order_meta['order_shipping_date']);
268
+			if (isset($order_meta['order_shipping_date'])) {
269
+				update_post_meta($post_ID, '_wpshop_order_shipping_date', $order_meta['order_shipping_date']);
270 270
 			}
271
-			update_post_meta( $post_ID, '_wpshop_order_status', $order_meta['order_status']);
271
+			update_post_meta($post_ID, '_wpshop_order_status', $order_meta['order_status']);
272 272
 
273 273
 			// Save Metadata
274
-			update_post_meta( $post_ID, '_order_postmeta', $order_meta);
274
+			update_post_meta($post_ID, '_order_postmeta', $order_meta);
275 275
 		}
276 276
 	}
277 277
 
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 	 * @param array $posted_datas
283 283
 	 * @return array
284 284
 	 */
285
-	function wps_notif_user_on_order_saving( $order_metadata, $posted_datas ) {
286
-		if( !empty($posted_datas['notif_the_customer']) && $posted_datas['notif_the_customer']=='on' ) {
285
+	function wps_notif_user_on_order_saving($order_metadata, $posted_datas) {
286
+		if (!empty($posted_datas['notif_the_customer']) && $posted_datas['notif_the_customer'] == 'on') {
287 287
 			$wps_message = new wps_message_ctr();
288 288
 			/*	Get order current content	*/
289 289
 			$user = get_post_meta($posted_datas['post_ID'], '_order_info', true);
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
 			$first_name = $user['billing']['address']['address_first_name'];
293 293
 			$last_name = $user['billing']['address']['address_last_name'];
294 294
 
295
-			$object = array('object_type'=>'order','object_id'=>(int)$_REQUEST['post_ID']);
295
+			$object = array('object_type'=>'order', 'object_id'=>(int)$_REQUEST['post_ID']);
296 296
 			/* Envoie du message de confirmation de commande au client	*/
297
-			if ( empty( $order_metadata['order_key'] ) ) {
297
+			if (empty($order_metadata['order_key'])) {
298 298
 				$wps_message->wpshop_prepared_email($email,
299 299
 						'WPSHOP_QUOTATION_UPDATE_MESSAGE',
300
-						array(  'order_id' => $object['object_id'],
300
+						array('order_id' => $object['object_id'],
301 301
 							    'customer_first_name' => $first_name,
302 302
 								'customer_last_name' => $last_name,
303 303
 								'order_date' => current_time('mysql', 0),
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 				$wps_message->wpshop_prepared_email(
313 313
 						$email,
314 314
 						'WPSHOP_ORDER_UPDATE_MESSAGE',
315
-						array(  'customer_first_name' => $first_name,
315
+						array('customer_first_name' => $first_name,
316 316
 								'customer_last_name' => $last_name,
317 317
 								'order_key' => $order_metadata['order_key'],
318 318
 								'order_billing_address' => '',
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 								'order_addresses' => '',
321 321
 								'order_addresses' => '',
322 322
 								'order_billing_address' => '',
323
-								'order_shipping_address' => '' ),
323
+								'order_shipping_address' => ''),
324 324
 						$object);
325 325
 			}
326 326
 		}
@@ -331,25 +331,25 @@  discard block
 block discarded – undo
331 331
 	 * AJAX - Add a private comment to order
332 332
 	 */
333 333
 	function wpshop_add_private_comment_to_order() {
334
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
334
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
335 335
 
336
-		if ( !wp_verify_nonce( $_wpnonce, 'wpshop_add_private_comment_to_order' ) )
336
+		if (!wp_verify_nonce($_wpnonce, 'wpshop_add_private_comment_to_order'))
337 337
 			wp_die();
338 338
 
339 339
 		$status = false; $result = '';
340
-		$order_id = ( !empty($_POST['oid']) ) ? intval($_POST['oid']) : null;
341
-		$comment = ( !empty($_POST['comment']) ) ? wpshop_tools::varSanitizer($_POST['comment']) : null;
342
-		$send_email = ( !empty($_POST['send_email']) ) ? wpshop_tools::varSanitizer($_POST['send_email']) : null;
343
-		$copy_to_administrator = ( !empty($_POST['copy_to_administrator']) ) ? wpshop_tools::varSanitizer($_POST['copy_to_administrator']) : null;
340
+		$order_id = (!empty($_POST['oid'])) ? intval($_POST['oid']) : null;
341
+		$comment = (!empty($_POST['comment'])) ? wpshop_tools::varSanitizer($_POST['comment']) : null;
342
+		$send_email = (!empty($_POST['send_email'])) ? wpshop_tools::varSanitizer($_POST['send_email']) : null;
343
+		$copy_to_administrator = (!empty($_POST['copy_to_administrator'])) ? wpshop_tools::varSanitizer($_POST['copy_to_administrator']) : null;
344 344
 
345
-		if ( !empty($comment) && !empty($order_id) ) {
345
+		if (!empty($comment) && !empty($order_id)) {
346 346
 			$wps_back_office_orders_mdl = new wps_back_office_orders_mdl();
347
-			$new_comment = $wps_back_office_orders_mdl->add_private_comment($order_id, $comment, $send_email, false, $copy_to_administrator );
348
-			if($new_comment) {
349
-				$order_private_comment = get_post_meta( $order_id, '_order_private_comments', true );
347
+			$new_comment = $wps_back_office_orders_mdl->add_private_comment($order_id, $comment, $send_email, false, $copy_to_administrator);
348
+			if ($new_comment) {
349
+				$order_private_comment = get_post_meta($order_id, '_order_private_comments', true);
350 350
 				$oid = $order_id;
351 351
 				ob_start();
352
-				require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_sended_private_comments") );
352
+				require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_sended_private_comments"));
353 353
 				$result = ob_get_contents();
354 354
 				ob_end_clean();
355 355
 				$status = true;
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
 			$result = __('An error was occured', 'wpshop');
360 360
 		}
361 361
 
362
-		$response = array( 'status' => $status, 'response' => $result );
363
-		echo json_encode( $response );
362
+		$response = array('status' => $status, 'response' => $result);
363
+		echo json_encode($response);
364 364
 		wp_die();
365 365
 	}
366 366
 
@@ -368,29 +368,29 @@  discard block
 block discarded – undo
368 368
 	 * AJAX - Refresh product listing in order back-office
369 369
 	 */
370 370
 	function refresh_product_list() {
371
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
372
-		$letter = ( !empty($_POST['letter']) ) ? sanitize_title( $_POST['letter'] ) : '';
371
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
372
+		$letter = (!empty($_POST['letter'])) ? sanitize_title($_POST['letter']) : '';
373 373
 
374
-		if ( !wp_verify_nonce( $_wpnonce, 'refresh_product_list_'.strtolower($letter) ) )
374
+		if (!wp_verify_nonce($_wpnonce, 'refresh_product_list_' . strtolower($letter)))
375 375
 			wp_die();
376 376
 
377 377
 		$status = false; $response = '';
378
-		$oid = !empty( $_POST['oid'] ) ? (int) $_POST['oid'] : 0;
378
+		$oid = !empty($_POST['oid']) ? (int)$_POST['oid'] : 0;
379 379
 
380
-		if( !empty($oid) ) {
381
-			$post = get_post( $oid );
380
+		if (!empty($oid)) {
381
+			$post = get_post($oid);
382 382
 		}
383
-		if( !empty($letter) ) {
383
+		if (!empty($letter)) {
384 384
 			$current_letter = $letter;
385 385
 			$wps_product_mdl = new wps_product_mdl();
386
-			$products = $wps_product_mdl->get_products_by_letter( $letter );
386
+			$products = $wps_product_mdl->get_products_by_letter($letter);
387 387
 			ob_start();
388
-			require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing_table") );
388
+			require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing_table"));
389 389
 			$response = ob_get_contents();
390 390
 			ob_end_clean();
391 391
 			$status = true;
392 392
 		}
393
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
393
+		echo json_encode(array('status' => $status, 'response' => $response));
394 394
 		wp_die();
395 395
 	}
396 396
 
@@ -398,38 +398,38 @@  discard block
 block discarded – undo
398 398
 	 * AJAX - Add product to order in back-office panel
399 399
 	 */
400 400
 	function wps_add_product_to_order_admin() {
401
-		check_ajax_referer( 'wps_add_product_to_order_admin' );
401
+		check_ajax_referer('wps_add_product_to_order_admin');
402 402
 
403 403
 		$status = false; $response = ''; $product_have_variations = false;
404 404
 		// Sended vars
405
-		$product_id = ( !empty($_POST['pid']) ) ? intval( $_POST['pid']) : null;
406
-		$order_id = ( !empty($_POST['oid']) ) ? intval( $_POST['oid']) : null;
407
-		$product_qty = ( !empty($_POST['qty']) ) ? intval( $_POST['qty']) : 1;
405
+		$product_id = (!empty($_POST['pid'])) ? intval($_POST['pid']) : null;
406
+		$order_id = (!empty($_POST['oid'])) ? intval($_POST['oid']) : null;
407
+		$product_qty = (!empty($_POST['qty'])) ? intval($_POST['qty']) : 1;
408 408
 
409
-		if( !empty($order_id) && !empty($product_id) ) {
409
+		if (!empty($order_id) && !empty($product_id)) {
410 410
 			$wps_orders = new wps_orders_ctr();
411 411
 			$product_datas = wpshop_products::get_product_data($product_id, false, '"publish", "free_product"');
412 412
 			// Check if product have variations
413
-			$have_variations_checking = wpshop_products::get_variation( $product_id );
414
-			if( !empty($have_variations_checking) ) {
413
+			$have_variations_checking = wpshop_products::get_variation($product_id);
414
+			if (!empty($have_variations_checking)) {
415 415
 				$product_have_variations = true;
416 416
 			}
417 417
 			else {
418 418
 				// Get Metadatas
419
-				$order_metadata = get_post_meta( $order_id, '_order_postmeta', true );
419
+				$order_metadata = get_post_meta($order_id, '_order_postmeta', true);
420 420
 				// Calcul cart informations
421 421
 				$wps_cart = new wps_cart();
422
-				$order_metadata = $wps_cart->calcul_cart_information( array( $product_id => array( 'product_id' => $product_id, 'product_qty' => $product_qty ) ), '', $order_metadata, true, false );
422
+				$order_metadata = $wps_cart->calcul_cart_information(array($product_id => array('product_id' => $product_id, 'product_qty' => $product_qty)), '', $order_metadata, true, false);
423 423
 				// Update Metadatas
424
-				update_post_meta( $order_id, '_order_postmeta', $order_metadata );
424
+				update_post_meta($order_id, '_order_postmeta', $order_metadata);
425 425
 				$status = true;
426 426
 			}
427 427
 			$status = true;
428 428
 		}
429 429
 
430
-		$_wpnonce = wp_create_nonce( 'wps_order_load_product_variations' );
430
+		$_wpnonce = wp_create_nonce('wps_order_load_product_variations');
431 431
 
432
-		echo json_encode( array( '_wpnonce' => $_wpnonce, 'status' => $status, 'response' => $response, 'variations_exist' => $product_have_variations ) );
432
+		echo json_encode(array('_wpnonce' => $_wpnonce, 'status' => $status, 'response' => $response, 'variations_exist' => $product_have_variations));
433 433
 		wp_die();
434 434
 	}
435 435
 
@@ -437,15 +437,15 @@  discard block
 block discarded – undo
437 437
 	 * AJAX - Refresh cart in administration
438 438
 	 */
439 439
 	function refresh_cart_order() {
440
-		check_ajax_referer( 'wps_reload_cart' );
440
+		check_ajax_referer('wps_reload_cart');
441 441
 
442 442
 		$status = false; $response = '';
443
-		$order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null;
444
-		if( !empty($order_id) ) {
445
-			$response = do_shortcode( '[wps_cart oid="' .$order_id. '" cart_type="admin-panel"]');
443
+		$order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null;
444
+		if (!empty($order_id)) {
445
+			$response = do_shortcode('[wps_cart oid="' . $order_id . '" cart_type="admin-panel"]');
446 446
 			$status = true;
447 447
 		}
448
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
448
+		echo json_encode(array('status' => $status, 'response' => $response));
449 449
 		wp_die();
450 450
 	}
451 451
 
@@ -453,17 +453,17 @@  discard block
 block discarded – undo
453 453
 	 * AJAX - Refresh cart in administration
454 454
 	 */
455 455
 	function refresh_payments_order() {
456
-		check_ajax_referer( 'wps_reload_cart' );
456
+		check_ajax_referer('wps_reload_cart');
457 457
 		$status = false; $response = '';
458
-		$order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null;
459
-		if( !empty($order_id) ) {
458
+		$order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null;
459
+		if (!empty($order_id)) {
460 460
 			ob_start();
461
-			echo $this->display_order_payments_box( get_post( $order_id ) );
461
+			echo $this->display_order_payments_box(get_post($order_id));
462 462
 			$response = ob_get_contents();
463 463
 			ob_end_clean();
464 464
 			$status = true;
465 465
 		}
466
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
466
+		echo json_encode(array('status' => $status, 'response' => $response));
467 467
 		wp_die();
468 468
 	}
469 469
 
@@ -471,25 +471,25 @@  discard block
 block discarded – undo
471 471
 	 * AJAX - Update product Quantity in Back-office Panel
472 472
 	 */
473 473
 	function wps_update_product_qty_in_admin() {
474
-		check_ajax_referer( 'wps_reload_cart' );
474
+		check_ajax_referer('wps_reload_cart');
475 475
 
476 476
 		$status = false; $response = '';
477
-		$product_id = ( !empty($_POST['product_id']) ) ? wpshop_tools::varSanitizer( $_POST['product_id'] ) : null;
478
-		$order_id = ( !empty($_POST['order_id']) ) ? intval( $_POST['order_id'] ) : null;
479
-		$product_qty = ( !empty($_POST['qty']) ) ? intval( $_POST['qty'] ) : 0;
477
+		$product_id = (!empty($_POST['product_id'])) ? wpshop_tools::varSanitizer($_POST['product_id']) : null;
478
+		$order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null;
479
+		$product_qty = (!empty($_POST['qty'])) ? intval($_POST['qty']) : 0;
480 480
 
481
-		if( !empty($product_id) && !empty($order_id) ) {
481
+		if (!empty($product_id) && !empty($order_id)) {
482 482
 			// Get Metadatas
483
-			$order_metadata = get_post_meta( $order_id, '_order_postmeta', true );
483
+			$order_metadata = get_post_meta($order_id, '_order_postmeta', true);
484 484
 			// Calcul cart informations
485 485
 			$wps_cart = new wps_cart();
486
-			$order_metadata = $wps_cart->calcul_cart_information( array( $product_id => array( 'product_id' => $product_id, 'product_qty' => $product_qty ) ), '', $order_metadata, true, false );
486
+			$order_metadata = $wps_cart->calcul_cart_information(array($product_id => array('product_id' => $product_id, 'product_qty' => $product_qty)), '', $order_metadata, true, false);
487 487
 			// Update Metadatas
488
-			update_post_meta( $order_id, '_order_postmeta', $order_metadata );
488
+			update_post_meta($order_id, '_order_postmeta', $order_metadata);
489 489
 			$status = true;
490 490
 		}
491 491
 
492
-		echo json_encode( array( 'status' => $status ) );
492
+		echo json_encode(array('status' => $status));
493 493
 		wp_die();
494 494
 	}
495 495
 
@@ -497,15 +497,15 @@  discard block
 block discarded – undo
497 497
 	 * AJAX - Load Product Variations in ThickBox on Add product to order action
498 498
 	 */
499 499
 	function wps_order_load_product_variations() {
500
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
500
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
501 501
 
502
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_order_load_product_variations' ) )
502
+		if (!wp_verify_nonce($_wpnonce, 'wps_order_load_product_variations'))
503 503
 			wp_die();
504 504
 
505
-		$product_id = ( !empty($_GET['pid']) ) ? intval( $_GET['pid']) : null;
506
-		$order_id = ( !empty($_GET['oid']) ) ? intval( $_GET['oid']) : null;
507
-		$qty = ( !empty($_GET['qty']) ) ? intval( $_GET['qty']) : 1;
508
-		echo '<div class="wps-boxed"><span class="wps-h5">'.__( 'Select your variations', 'wpshop' ).'</span>'.wpshop_products::wpshop_variation($product_id, true, $order_id, $qty ).'<a href="#" class="wps-bton-first-mini-rounded alignRight wps-orders-add_variation_product"><i class="wps-icon-basket"></i> ' .__( 'Add to cart', 'wpshop' ). '</a>'.'</div>';
505
+		$product_id = (!empty($_GET['pid'])) ? intval($_GET['pid']) : null;
506
+		$order_id = (!empty($_GET['oid'])) ? intval($_GET['oid']) : null;
507
+		$qty = (!empty($_GET['qty'])) ? intval($_GET['qty']) : 1;
508
+		echo '<div class="wps-boxed"><span class="wps-h5">' . __('Select your variations', 'wpshop') . '</span>' . wpshop_products::wpshop_variation($product_id, true, $order_id, $qty) . '<a href="#" class="wps-bton-first-mini-rounded alignRight wps-orders-add_variation_product"><i class="wps-icon-basket"></i> ' . __('Add to cart', 'wpshop') . '</a>' . '</div>';
509 509
 		wp_die();
510 510
 	}
511 511
 
@@ -513,67 +513,67 @@  discard block
 block discarded – undo
513 513
 	 * AJAX - Update cart informations
514 514
 	 */
515 515
 	function wps_orders_update_cart_informations() {
516
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
516
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
517 517
 
518
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_update_cart_informations' ) )
518
+		if (!wp_verify_nonce($_wpnonce, 'wps_orders_update_cart_informations'))
519 519
 			wp_die();
520 520
 
521 521
 		$status = false;
522
-		$order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : '';
522
+		$order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : '';
523 523
 		$shipping_cost = isset($_POST['shipping_cost']) ? wpshop_tools::varSanitizer($_POST['shipping_cost']) : '';
524 524
 		$discount_value = isset($_POST['discount_amount']) ? wpshop_tools::varSanitizer($_POST['discount_amount']) : '';
525 525
 		$discount_type = isset($_POST['discount_type']) ? wpshop_tools::varSanitizer($_POST['discount_type']) : '';
526 526
 
527 527
 
528
-		if( !empty($order_id) ) {
529
-			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
528
+		if (!empty($order_id)) {
529
+			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
530 530
 			$order_meta['order_shipping_cost'] = $shipping_cost;
531 531
 
532 532
 			//Add discounts if exists
533
-			if( isset($discount_value) && !empty($discount_type) ) {
533
+			if (isset($discount_value) && !empty($discount_type)) {
534 534
 				$order_meta['order_discount_type'] = $discount_type;
535 535
 				$order_meta['order_discount_value'] = $discount_value;
536 536
 			}
537 537
 			$wps_cart = new wps_cart();
538
-			$order_meta = $wps_cart->calcul_cart_information( array(), '', $order_meta, true );
539
-			update_post_meta( $order_id, '_order_postmeta', $order_meta );
538
+			$order_meta = $wps_cart->calcul_cart_information(array(), '', $order_meta, true);
539
+			update_post_meta($order_id, '_order_postmeta', $order_meta);
540 540
 			$status = true;
541 541
 		}
542 542
 
543
-		echo json_encode( array( 'status' => $status) );
543
+		echo json_encode(array('status' => $status));
544 544
 		wp_die();
545 545
 	}
546 546
 
547 547
 	function wps_reverify_payment_invoice_ref() {
548
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
548
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
549 549
 
550
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_reverify_payment_invoice_ref' ) )
550
+		if (!wp_verify_nonce($_wpnonce, 'wps_reverify_payment_invoice_ref'))
551 551
 			wp_die();
552 552
 
553 553
 		$status = true;
554
-		$inputs = !empty( $_POST['inputs'] ) ? (array) $_POST['inputs'] : false;
554
+		$inputs = !empty($_POST['inputs']) ? (array)$_POST['inputs'] : false;
555 555
 
556 556
 		if (!$inputs)
557 557
 			$status = false;
558 558
 
559
-		if( $status ) {
559
+		if ($status) {
560 560
 			$inputs_clone = $inputs;
561 561
 			$inputs = array();
562
-			foreach( $inputs_clone as $var ) {
563
-				if( isset( $var['key'] ) && isset( $var['value'] ) ) {
562
+			foreach ($inputs_clone as $var) {
563
+				if (isset($var['key']) && isset($var['value'])) {
564 564
 					$inputs[$var['key']] = $var['value'];
565 565
 				}
566 566
 			}
567 567
 
568
-			( isset( $inputs['order_id'] ) ) ? $order_id = $inputs['order_id'] : $status = $order_id = false;
569
-			( isset( $inputs['index_payment'] ) ) ? $index_payment = $inputs['index_payment'] : $status = $index_payment = false;
568
+			(isset($inputs['order_id'])) ? $order_id = $inputs['order_id'] : $status = $order_id = false;
569
+			(isset($inputs['index_payment'])) ? $index_payment = $inputs['index_payment'] : $status = $index_payment = false;
570 570
 		}
571 571
 
572
-		if( $status ) {
573
-			$status = wpshop_payment::reverify_payment_invoice_ref( $order_id, $index_payment );
572
+		if ($status) {
573
+			$status = wpshop_payment::reverify_payment_invoice_ref($order_id, $index_payment);
574 574
 		}
575 575
 
576
-		echo json_encode( array( 'status' => $status ) );
576
+		echo json_encode(array('status' => $status));
577 577
 		wp_die();
578 578
 	}
579 579
 
Please login to merge, or discard this patch.
includes/modules/wps_barcode/controller/wps_barcode_metabox.ctr.php 1 patch
Spacing   +143 added lines, -144 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 class wps_barcode_metabox {
4 4
 	public function __construct() {
5
-		add_action( 'add_meta_boxes', array($this, 'add_meta_box'), 10, 10 );
6
-		add_action( 'admin_enqueue_scripts', array($this, 'add_scripts') );
5
+		add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 10);
6
+		add_action('admin_enqueue_scripts', array($this, 'add_scripts'));
7 7
 	}
8 8
 
9 9
 	/**
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 	 */
12 12
 	public function add_scripts() {
13 13
 		global $current_screen;
14
-	    if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_COUPON ), true ) )
14
+	    if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_COUPON), true))
15 15
 	        return;
16 16
 
17
-		wp_enqueue_script( 'jquery' );
18
-		wp_enqueue_script( 'wps_barcode_printelement',  WPS_BARCODE_JSCRIPTS.'/jquery.printElement.js' );
19
-		wp_enqueue_script( 'wps_barcode',  WPS_BARCODE_JSCRIPTS.'/wps.backend.wps_barcode.js' );
17
+		wp_enqueue_script('jquery');
18
+		wp_enqueue_script('wps_barcode_printelement', WPS_BARCODE_JSCRIPTS . '/jquery.printElement.js');
19
+		wp_enqueue_script('wps_barcode', WPS_BARCODE_JSCRIPTS . '/wps.backend.wps_barcode.js');
20 20
 	}
21 21
 
22 22
 	/**
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 
28 28
 		$conf = get_option('wps_barcode');
29 29
 
30
-		$post = get_post( get_the_ID() );
31
-		if ( !empty($post) ) {
32
-			$query = $wpdb->prepare( "
30
+		$post = get_post(get_the_ID());
31
+		if (!empty($post)) {
32
+			$query = $wpdb->prepare("
33 33
 				SELECT *
34 34
 				FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
35 35
 				WHERE entity_id = %d
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 						SELECT id
38 38
 						FROM " . WPSHOP_DBT_ATTRIBUTE . "
39 39
 						WHERE code = %s
40
-					)" , $post->ID, 'barcode' );
41
-				$result = $wpdb->get_results( $query, ARRAY_A );
40
+					)" , $post->ID, 'barcode');
41
+				$result = $wpdb->get_results($query, ARRAY_A);
42 42
 
43 43
 				/*add_meta_box('wps_barcode_product', __('Barcode Manager', 'wps_barcode' ),
44 44
 				array( $this, 'meta_box_product' ), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 		}
47 47
 
48 48
 		if ($conf['type'] === 'internal') {
49
-			add_meta_box('wps_barcode_invoice_client', __('Barcode Manager', 'wps_barcode' ),
50
-			array( $this, 'meta_box_invoice_client' ), WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
51
-			'side','default');
49
+			add_meta_box('wps_barcode_invoice_client', __('Barcode Manager', 'wps_barcode'),
50
+			array($this, 'meta_box_invoice_client'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
51
+			'side', 'default');
52 52
 
53
-			add_meta_box('wps_barcode_coupons', __('Barcode Manager', 'wps_barcode' ),
54
-			array( $this, 'meta_box_coupons' ), WPSHOP_NEWTYPE_IDENTIFIER_COUPON,
55
-			'side','default');
53
+			add_meta_box('wps_barcode_coupons', __('Barcode Manager', 'wps_barcode'),
54
+			array($this, 'meta_box_coupons'), WPSHOP_NEWTYPE_IDENTIFIER_COUPON,
55
+			'side', 'default');
56 56
 		}
57 57
 	}
58 58
 
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
 
74 74
 		/*Select value of barcode*/
75 75
 		$result = $wpdb->get_results(
76
-				'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR.
77
-				' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE.
78
-				' WHERE code = "barcode") AND entity_id="'.$post_ID.'"', ARRAY_A);
76
+				'SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR .
77
+				' WHERE attribute_id=(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE .
78
+				' WHERE code = "barcode") AND entity_id="' . $post_ID . '"', ARRAY_A);
79 79
 		$meta = !empty($result) ? $result[0]['value'] : '';
80 80
 
81 81
 		/*Get price of product*/
82
-		$result = $wpdb->get_results('SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL.
83
-				' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE.
84
-				' WHERE code="'.WPSHOP_PRODUCT_PRICE_TTC.'") AND entity_id='.$post_ID, ARRAY_A);
82
+		$result = $wpdb->get_results('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL .
83
+				' WHERE attribute_id=(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE .
84
+				' WHERE code="' . WPSHOP_PRODUCT_PRICE_TTC . '") AND entity_id=' . $post_ID, ARRAY_A);
85 85
 
86
-		if ( !empty($result) && $result[0]['value'] >= 0) {
86
+		if (!empty($result) && $result[0]['value'] >= 0) {
87 87
 			$price = $result[0]['value'];
88 88
 
89 89
 			/*Get title of product*/
@@ -91,28 +91,28 @@  discard block
 block discarded – undo
91 91
 			$ref = substr($post['post_title'], 0, 10);
92 92
 
93 93
 			chdir('..');
94
-			chdir( plugin_dir_path(__FILE__) );
94
+			chdir(plugin_dir_path(__FILE__));
95 95
 			chdir('..');
96 96
 
97 97
 			$conf = get_option('wps_barcode');
98 98
 
99
-			if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) {
99
+			if (isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on') {
100 100
 				echo $ajax->generate_image($barcode, $meta, __('product', 'wps_barcode'),
101 101
 						$price, $ref);
102 102
 			}
103 103
 			else {
104
-				echo '<p style="text-align: center"><button class="button '.
105
-					'button-primary button-large" type="button"'.
106
-					'id="display_barcode" data-nonce=' . wp_create_nonce( 'imgProduct' ) . '>'.
107
-					__('Display', 'wps_barcode').'</button></p>';
104
+				echo '<p style="text-align: center"><button class="button ' .
105
+					'button-primary button-large" type="button"' .
106
+					'id="display_barcode" data-nonce=' . wp_create_nonce('imgProduct') . '>' .
107
+					__('Display', 'wps_barcode') . '</button></p>';
108 108
 			}
109 109
 		}
110 110
 		else {
111 111
 			$conf = get_option('wps_barcode');
112 112
 
113
-			if ( $conf['generate_barcode'] === 'true' ) {
114
-				echo '<p>'.sprintf( __('None bardcode generated as you did create %s.',
115
-					'wps_barcode'), __('product', 'wps_barcode')).'</p>';
113
+			if ($conf['generate_barcode'] === 'true') {
114
+				echo '<p>' . sprintf(__('None bardcode generated as you did create %s.',
115
+					'wps_barcode'), __('product', 'wps_barcode')) . '</p>';
116 116
 			}
117 117
 		}
118 118
 	}
@@ -132,21 +132,20 @@  discard block
 block discarded – undo
132 132
 		$country = '000';
133 133
 		$result = get_post_meta($post_ID);
134 134
 
135
-		if ( !empty($result) ) {
136
-			$order_postmeta = isset( $result['_order_postmeta'] ) ? unserialize($result['_order_postmeta'][0]) : array();
135
+		if (!empty($result)) {
136
+			$order_postmeta = isset($result['_order_postmeta']) ? unserialize($result['_order_postmeta'][0]) : array();
137 137
 
138
-			if ( !empty($order_postmeta['order_invoice_date']) ) {
138
+			if (!empty($order_postmeta['order_invoice_date'])) {
139 139
 				$conf = get_option('wps_barcode');
140 140
 				if ($conf['type'] === 'internal') {
141 141
 					$type = $conf['internal_invoice_client'];
142 142
 
143 143
 					$order_date = isset($order_postmeta['order_invoice_date']) ?
144
-						$order_postmeta['order_invoice_date'] :
145
-						$order_postmeta['order_date'];
144
+						$order_postmeta['order_invoice_date'] : $order_postmeta['order_date'];
146 145
 					$pDate = new DateTime($order_date);
147 146
 					$date = $pDate->format('my');
148 147
 
149
-					if ( empty($order_postmeta['order_invoice_ref']) ) {
148
+					if (empty($order_postmeta['order_invoice_ref'])) {
150 149
 						$continue = false;
151 150
 					}
152 151
 					else {
@@ -155,9 +154,9 @@  discard block
 block discarded – undo
155 154
 					}
156 155
 				}
157 156
 				if ($continue === true) {
158
-					$code = $type.$date.$id;
157
+					$code = $type . $date . $id;
159 158
 
160
-					if ( empty($result['_order_barcode']) ) {
159
+					if (empty($result['_order_barcode'])) {
161 160
 						$meta = $barcode->checksum($code);
162 161
 						add_post_meta($post_ID, '_order_barcode', $meta);
163 162
 					}
@@ -166,32 +165,32 @@  discard block
 block discarded – undo
166 165
 					}
167 166
 
168 167
 					chdir('..');
169
-					chdir( plugin_dir_path(__FILE__) );
168
+					chdir(plugin_dir_path(__FILE__));
170 169
 					chdir('..');
171 170
 					$order_meta = unserialize($result['_order_postmeta'][0]);
172
-					$title = ( !empty($order_meta['order_invoice_ref']) ) ? $order_meta['order_invoice_ref'] : $order_meta['order_key'];
171
+					$title = (!empty($order_meta['order_invoice_ref'])) ? $order_meta['order_invoice_ref'] : $order_meta['order_key'];
173 172
 					$price = $order_meta['order_grand_total'];
174 173
 
175 174
 
176
-					if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) {
175
+					if (isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on') {
177 176
 						$this->generate_image($barcode, $meta[0], __('order client', 'wps_barcode'),
178
-							$price, $title );
177
+							$price, $title);
179 178
 					}
180 179
 				}
181 180
 				else {
182
-					echo '<p>'.__('None bardcode generated as customer can not get his bill.',
183
-							'wps_barcode').'</p>';
181
+					echo '<p>' . __('None bardcode generated as customer can not get his bill.',
182
+							'wps_barcode') . '</p>';
184 183
 				}
185 184
 
186 185
 			}
187 186
 			else {
188
-				echo '<p>'.__('None bardcode generated as customer can not get his bill.',
189
-						'wps_barcode').'</p>';
187
+				echo '<p>' . __('None bardcode generated as customer can not get his bill.',
188
+						'wps_barcode') . '</p>';
190 189
 			}
191 190
 		}
192 191
 		else {
193
-			echo '<p>'.sprintf( __('None bardcode generated as you did create %s.',
194
-					'wps_barcode'), 'order client').'</p>';
192
+			echo '<p>' . sprintf(__('None bardcode generated as you did create %s.',
193
+					'wps_barcode'), 'order client') . '</p>';
195 194
 		}
196 195
 	}
197 196
 
@@ -210,14 +209,14 @@  discard block
 block discarded – undo
210 209
 		$country = '000';
211 210
 		$result = get_post_meta($post_ID);
212 211
 
213
-		if ( !empty($result) ) {
214
-			if ( empty($result['wpshop_coupon_barcode']) ) {
212
+		if (!empty($result)) {
213
+			if (empty($result['wpshop_coupon_barcode'])) {
215 214
 				$conf = get_option('wps_barcode');
216 215
 				if ($conf['type'] === 'internal') {
217 216
 					$type = $conf['internal_coupons'];
218 217
 
219
-					$query = $wpdb->get_results('SELECT post_date FROM '.
220
-							$table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A);
218
+					$query = $wpdb->get_results('SELECT post_date FROM ' .
219
+							$table_prefix . 'posts WHERE ID=' . $post_ID, ARRAY_A);
221 220
 
222 221
 					$pDate = new DateTime($query[0]['post_date']);
223 222
 					$date = $pDate->format('my');
@@ -225,13 +224,13 @@  discard block
 block discarded – undo
225 224
 
226 225
 				$len = strlen($post_ID);
227 226
 				$ref = '';
228
-				if ( $len < 5 ) {
229
-					for ($i=0; $i <= $len; $i++) {
227
+				if ($len < 5) {
228
+					for ($i = 0; $i <= $len; $i++) {
230 229
 						$ref .= '0';
231 230
 					}
232 231
 				}
233
-				$id = $ref.$post_ID;
234
-				$code = $type.$date.$id;
232
+				$id = $ref . $post_ID;
233
+				$code = $type . $date . $id;
235 234
 				$meta = $barcode->checksum($code);
236 235
 				add_post_meta($post_ID, 'wpshop_coupon_barcode', $meta);
237 236
 			}
@@ -239,24 +238,24 @@  discard block
 block discarded – undo
239 238
 				$meta = $result['wpshop_coupon_barcode'][0];
240 239
 			}
241 240
 
242
-			$query = $wpdb->get_results('SELECT post_title FROM '.
243
-					$table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A);
241
+			$query = $wpdb->get_results('SELECT post_title FROM ' .
242
+					$table_prefix . 'posts WHERE ID=' . $post_ID, ARRAY_A);
244 243
 
245 244
 			$post = get_post($post_ID, ARRAY_A);
246
-			if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) {
245
+			if (isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on') {
247 246
 				$ajax->generate_image($barcode, $meta, __('coupon', 'wps_barcode'),
248 247
 					$result['wpshop_coupon_discount_value'][0], $query[0]['post_title'], $post_ID);
249 248
 			}
250 249
 			else {
251
-				echo '<p style="text-align: center"><button class="button '.
252
-					'button-primary button-large" type="button"'.
253
-					'id="display_barcode">'.
254
-					__('Display', 'wps_barcode').'</button></p>';
250
+				echo '<p style="text-align: center"><button class="button ' .
251
+					'button-primary button-large" type="button"' .
252
+					'id="display_barcode">' .
253
+					__('Display', 'wps_barcode') . '</button></p>';
255 254
 			}
256 255
 		}
257 256
 		else {
258
-			echo '<p>'.__('None bardcode generated as coupon has not created.',
259
-					'wps_barcode').'</p>';
257
+			echo '<p>' . __('None bardcode generated as coupon has not created.',
258
+					'wps_barcode') . '</p>';
260 259
 		}
261 260
 	}
262 261
 
@@ -269,44 +268,44 @@  discard block
 block discarded – undo
269 268
 	 * @param string $title Title of product
270 269
 	 */
271 270
 	public function generate_image(&$barcode, $meta, $type, $price, $title, $post_ID = 0) {
272
-		if ( !extension_loaded('gd') ) {
273
-			return '<p>'.__('Library GD is requiered.', 'wps_barcode').'</p>';
271
+		if (!extension_loaded('gd')) {
272
+			return '<p>' . __('Library GD is requiered.', 'wps_barcode') . '</p>';
274 273
 		}
275
-		if ( !empty($meta) ) {
274
+		if (!empty($meta)) {
276 275
 			$barcode->setGenerateCode($meta);
277 276
 			$binCode = $barcode->getBinCode();
278 277
 
279 278
 			$px = 3.779528;
280
-			$x = round(66*$px); //249.449 px
281
-			$y = round(50*$px); //188.976 px
282
-			$bar_size = round(63.393/72); //0.880 px
279
+			$x = round(66 * $px); //249.449 px
280
+			$y = round(50 * $px); //188.976 px
281
+			$bar_size = round(63.393 / 72); //0.880 px
283 282
 
284 283
 			$len = 0;
285 284
 			$test = '';
286 285
 
287
-			while ($len !== strlen($binCode) ) {
288
-				$test .= substr($binCode, $len, 7).' ';
289
-				$len = $len+7;
286
+			while ($len !== strlen($binCode)) {
287
+				$test .= substr($binCode, $len, 7) . ' ';
288
+				$len = $len + 7;
290 289
 			}
291 290
 
292 291
 			$im = imagecreate($x, $y);
293 292
 			$background_color = imagecolorallocate($im, 255, 255, 255);
294
-			$start = round(5.79*$px); //21.883
293
+			$start = round(5.79 * $px); //21.883
295 294
 
296 295
 			/*Write First left guard*/
297
-			$this->imgNormalGuard($im, $start, $start+$bar_size,
296
+			$this->imgNormalGuard($im, $start, $start + $bar_size,
298 297
 					imagecolorallocate($im, 0, 0, 0));
299
-			$this->imgNormalGuard($im, $start+($bar_size*2),
300
-					$start+($bar_size*3), imagecolorallocate($im, 255, 255, 255));
301
-			$this->imgNormalGuard($im, $start+($bar_size*4),
302
-					$start+($bar_size*5), imagecolorallocate($im, 0, 0, 0));
298
+			$this->imgNormalGuard($im, $start + ($bar_size * 2),
299
+					$start + ($bar_size * 3), imagecolorallocate($im, 255, 255, 255));
300
+			$this->imgNormalGuard($im, $start + ($bar_size * 4),
301
+					$start + ($bar_size * 5), imagecolorallocate($im, 0, 0, 0));
303 302
 
304
-			$pos = $start+($bar_size*7);
305
-			$newPos = $pos+$bar_size;
303
+			$pos = $start + ($bar_size * 7);
304
+			$newPos = $pos + $bar_size;
306 305
 
307 306
 			/*Write left barcode*/
308
-			for ($i=0; $i<42 ; $i++) {
309
-				if( substr($binCode, $i, 1) === '0' ) {
307
+			for ($i = 0; $i < 42; $i++) {
308
+				if (substr($binCode, $i, 1) === '0') {
310 309
 					$color = imagecolorallocate($im, 255, 255, 255);
311 310
 				}
312 311
 				else {
@@ -314,128 +313,128 @@  discard block
 block discarded – undo
314 313
 				}
315 314
 
316 315
 				$this->imgSymbole($im, $pos, $newPos, $color);
317
-				$newPos = $pos+$bar_size;
318
-				$pos = $newPos+$bar_size;
316
+				$newPos = $pos + $bar_size;
317
+				$pos = $newPos + $bar_size;
319 318
 			}
320 319
 
321 320
 			/*Writer center guard*/
322 321
 			$pos = $newPos;
323
-			$this->imgNormalGuard($im, $pos, $newPos+$bar_size,
322
+			$this->imgNormalGuard($im, $pos, $newPos + $bar_size,
324 323
 					imagecolorallocate($im, 255, 255, 255));
325
-			$this->imgNormalGuard($im, $pos+($bar_size*2),
326
-					$newPos+($bar_size*3), imagecolorallocate($im, 0, 0, 0));
327
-			$this->imgNormalGuard($im, $pos+($bar_size*4),
328
-					$newPos+($bar_size*5), imagecolorallocate($im, 255, 255, 255));
329
-			$this->imgNormalGuard($im, $pos+($bar_size*6),
330
-					$newPos+($bar_size*7), imagecolorallocate($im, 0, 0, 0));
331
-			$this->imgNormalGuard($im, $pos+($bar_size*8),
332
-					$newPos+($bar_size*9), imagecolorallocate($im, 255, 255, 255));
324
+			$this->imgNormalGuard($im, $pos + ($bar_size * 2),
325
+					$newPos + ($bar_size * 3), imagecolorallocate($im, 0, 0, 0));
326
+			$this->imgNormalGuard($im, $pos + ($bar_size * 4),
327
+					$newPos + ($bar_size * 5), imagecolorallocate($im, 255, 255, 255));
328
+			$this->imgNormalGuard($im, $pos + ($bar_size * 6),
329
+					$newPos + ($bar_size * 7), imagecolorallocate($im, 0, 0, 0));
330
+			$this->imgNormalGuard($im, $pos + ($bar_size * 8),
331
+					$newPos + ($bar_size * 9), imagecolorallocate($im, 255, 255, 255));
333 332
 
334
-			$pos = $newPos+($bar_size*10);
333
+			$pos = $newPos + ($bar_size * 10);
335 334
 
336 335
 			/*Write right barcode*/
337
-			for ($i=42; $i<84 ; $i++) {
338
-				if( substr($binCode, $i, 1) === '0' ) {
336
+			for ($i = 42; $i < 84; $i++) {
337
+				if (substr($binCode, $i, 1) === '0') {
339 338
 					$color = imagecolorallocate($im, 255, 255, 255);
340 339
 				}
341 340
 				else {
342 341
 					$color = imagecolorallocate($im, 0, 0, 0);
343 342
 				}
344 343
 
345
-				$newPos = $pos+$bar_size;
344
+				$newPos = $pos + $bar_size;
346 345
 
347 346
 				$this->imgSymbole($im, $pos, $newPos, $color);
348
-				$pos = $newPos+$bar_size;
347
+				$pos = $newPos + $bar_size;
349 348
 			}
350 349
 
351 350
 			/*Write right guard*/
352
-			$pos = $newPos+$bar_size;
353
-			$this->imgNormalGuard($im, $pos, $pos+$bar_size,
351
+			$pos = $newPos + $bar_size;
352
+			$this->imgNormalGuard($im, $pos, $pos + $bar_size,
354 353
 					imagecolorallocate($im, 0, 0, 0));
355
-			$this->imgNormalGuard($im, $pos+($bar_size*2),
356
-					$pos+($bar_size*3), imagecolorallocate($im, 255, 255, 255));
357
-			$this->imgNormalGuard($im, $pos+($bar_size*4),
358
-					$pos+($bar_size*5), imagecolorallocate($im, 0, 0, 0));
354
+			$this->imgNormalGuard($im, $pos + ($bar_size * 2),
355
+					$pos + ($bar_size * 3), imagecolorallocate($im, 255, 255, 255));
356
+			$this->imgNormalGuard($im, $pos + ($bar_size * 4),
357
+					$pos + ($bar_size * 5), imagecolorallocate($im, 0, 0, 0));
359 358
 
360 359
 			$textSize = 16;
361 360
 			$font = 'assets/fonts/arialbd.ttf';
362
-			imagettftext($im, $textSize, 0, 8, $y-$start-5,
361
+			imagettftext($im, $textSize, 0, 8, $y - $start - 5,
363 362
 			imagecolorallocate($im, 0, 0, 0), $font, substr($meta, 0, 1));
364 363
 
365 364
 			$continue = true;
366 365
 			$i = 28; $j = 0;
367 366
 
368 367
 			/*Write left number code*/
369
-			while ($j<5) {
370
-				$j=$j+1;
371
-				imagettftext($im, $textSize, 0, $i, $y-$start-5,
368
+			while ($j < 5) {
369
+				$j = $j + 1;
370
+				imagettftext($im, $textSize, 0, $i, $y - $start - 5,
372 371
 				imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1));
373
-				$i = $i+14;
372
+				$i = $i + 14;
374 373
 			}
375 374
 
376 375
 			/*Write right number code*/
377
-			while ($j<11) {
378
-				$j=$j+1;
379
-				imagettftext($im, $textSize, 0, $i+6, $y-$start-5,
376
+			while ($j < 11) {
377
+				$j = $j + 1;
378
+				imagettftext($im, $textSize, 0, $i + 6, $y - $start - 5,
380 379
 					imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1));
381
-				$i = $i+15;
380
+				$i = $i + 15;
382 381
 			}
383
-			imagettftext($im, $textSize, 0, $i+4, $y-$start-5,
384
-				imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j+1, 1));
382
+			imagettftext($im, $textSize, 0, $i + 4, $y - $start - 5,
383
+				imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j + 1, 1));
385 384
 
386 385
 			/*Write ref product and price*/
387 386
 			$textSize = 12;
388 387
 			$currency = (wpshop_tools::wpshop_get_currency() === '&euro;') ? "€" : wpshop_tools::wpshop_get_currency();
389 388
 
390
-			if ( $type === __('coupon', 'wps_barcode') ) {
389
+			if ($type === __('coupon', 'wps_barcode')) {
391 390
 				$coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type');
392
-				if ( $coupon_postmeta[0] === 'percent' ) {
393
-					$price = $price.' %';
391
+				if ($coupon_postmeta[0] === 'percent') {
392
+					$price = $price . ' %';
394 393
 				}
395 394
 				else {
396
-					$price = sprintf( number_format( $price, 2 ). ' '.$currency);
395
+					$price = sprintf(number_format($price, 2) . ' ' . $currency);
397 396
 				}
398 397
 			}
399 398
 			else {
400
-				$price = sprintf( number_format( $price, 2 ). ' '.$currency);
399
+				$price = sprintf(number_format($price, 2) . ' ' . $currency);
401 400
 			}
402 401
 
403
-			imagettftext($im, $textSize, 0, 20, round(6*$px),
402
+			imagettftext($im, $textSize, 0, 20, round(6 * $px),
404 403
 				imagecolorallocate($im, 0, 0, 0), $font, $title);
405
-			imagettftext($im, $textSize, 0, ($x/2)+40, round(6*$px),
404
+			imagettftext($im, $textSize, 0, ($x / 2) + 40, round(6 * $px),
406 405
 				imagecolorallocate($im, 0, 0, 0), $font, $price);
407 406
 
408 407
 			ob_start();
409 408
 			imagepng($im);
410 409
 			$img = ob_get_clean();
411 410
 
412
-			echo '<p><img src="data:image/png;base64,'.base64_encode($img).
411
+			echo '<p><img src="data:image/png;base64,' . base64_encode($img) .
413 412
 				'" id="barcode" width="160" height="90" /></p>';
414 413
 
415
-			echo '<p style="text-align: right"><button class="button '.
416
-					'button-primary button-large" type="button"'.
417
-					'id="print_barcode">'.
418
-					__('Print', 'wps_barcode').'</button></p>';
414
+			echo '<p style="text-align: right"><button class="button ' .
415
+					'button-primary button-large" type="button"' .
416
+					'id="print_barcode">' .
417
+					__('Print', 'wps_barcode') . '</button></p>';
419 418
 
420
-			wp_mkdir_p( WPS_BARCODE_UPLOAD );
419
+			wp_mkdir_p(WPS_BARCODE_UPLOAD);
421 420
 
422
-			file_put_contents(WPS_BARCODE_UPLOAD.$meta.'.png', $img);
421
+			file_put_contents(WPS_BARCODE_UPLOAD . $meta . '.png', $img);
423 422
 
424 423
 			/*Generate ODT File*/
425 424
 			try {
426
-				if( !class_exists('Odf') ) {
427
-					require_once(WPS_BARCODE_PATH.'/librairies/odtphp/odf.php');
425
+				if (!class_exists('Odf')) {
426
+					require_once(WPS_BARCODE_PATH . '/librairies/odtphp/odf.php');
428 427
 				}
429
-				$odf = new Odf(WPS_BARCODE_PATH.'assets/medias/avery_a4_991_677.ott');
430
-				$odf->setImage('barcode', WPS_BARCODE_UPLOAD.$meta.'.png');
431
-				$odf->saveToDisk(WPS_BARCODE_UPLOAD.$meta.'.odt');
428
+				$odf = new Odf(WPS_BARCODE_PATH . 'assets/medias/avery_a4_991_677.ott');
429
+				$odf->setImage('barcode', WPS_BARCODE_UPLOAD . $meta . '.png');
430
+				$odf->saveToDisk(WPS_BARCODE_UPLOAD . $meta . '.odt');
432 431
 			} catch (Exception $e) {
433 432
 				echo __('Generation problem', 'wps_barcode');
434 433
 			}
435 434
 		}
436 435
 		else {
437
-			echo '<p>'.sprintf( __('None bardcode generated as you did create %s.',
438
-					'wps_barcode'), $type).'</p>';
436
+			echo '<p>' . sprintf(__('None bardcode generated as you did create %s.',
437
+					'wps_barcode'), $type) . '</p>';
439 438
 		}
440 439
 	}
441 440
 
@@ -451,7 +450,7 @@  discard block
 block discarded – undo
451 450
 	 * @param integer $color Color of rectangle
452 451
 	 */
453 452
 	private function imgNormalGuard(&$image, $pos, $size, $color) {
454
-		imagefilledrectangle($image, $pos, 180*0.25,$size, 180-10, $color );
453
+		imagefilledrectangle($image, $pos, 180 * 0.25, $size, 180 - 10, $color);
455 454
 	}
456 455
 
457 456
 	/**
@@ -462,7 +461,7 @@  discard block
 block discarded – undo
462 461
 	 * @param integer $color Color of rectangle
463 462
 	 */
464 463
 	private function imgSymbole(&$image, $pos, $size, $color) {
465
-		imagefilledrectangle($image, $pos, 180*0.25,$size, 180-40, $color );
464
+		imagefilledrectangle($image, $pos, 180 * 0.25, $size, 180 - 40, $color);
466 465
 	}
467 466
 
468 467
 }
Please login to merge, or discard this patch.
templates/backend/quick_add_interface-product_list.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,27 +1,27 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
2
- if( !empty($products) ) : ?>
1
+<?php if (!defined('ABSPATH')) exit;
2
+ if (!empty($products)) : ?>
3 3
 	<?php $tab_def = array(); ?>
4 4
 	<?php
5
-		foreach( $quick_add_form_attributes as $id_att => $att ) {
5
+		foreach ($quick_add_form_attributes as $id_att => $att) {
6 6
 			$tab_def[$id_att]['name'] = $att['frontend_label'];
7 7
 		}
8 8
 	?>
9 9
 
10
-	<form method="post" id="wps_mass_edit_product_form" action="<?php echo admin_url( 'admin-ajax.php' ); ?>">
10
+	<form method="post" id="wps_mass_edit_product_form" action="<?php echo admin_url('admin-ajax.php'); ?>">
11 11
 		<input type="hidden" name="action" value="wps_mass_edit_product_save_action" />
12
-    <?php wp_nonce_field( 'wps_save_product_quick_interface' ); ?>
12
+    <?php wp_nonce_field('wps_save_product_quick_interface'); ?>
13 13
 		<table class="wp-list-table widefat wps-product-mass-interface-table">
14 14
 			<thead>
15 15
 				<tr>
16 16
 					<th class="check-column manage-column column-cb check-column">
17 17
 						<input type="checkbox" class="wps-save-product-checkbox" name="wps_product_quick_save_checkbox_column" />
18 18
 					</th>
19
-					<th><?php _e( 'Picture', 'wpshop'); ?></th>
20
-					<th class="title"><?php _e( 'Title', 'wpshop'); ?></th>
21
-					<th class="description"><?php _e( 'Description', 'wpshop'); ?></th>
19
+					<th><?php _e('Picture', 'wpshop'); ?></th>
20
+					<th class="title"><?php _e('Title', 'wpshop'); ?></th>
21
+					<th class="description"><?php _e('Description', 'wpshop'); ?></th>
22 22
 					<?php /*<th width="80"><?php _e( 'Files', 'wpshop'); ?></th>*/ ?>
23
-					<?php if( !empty($tab_def) ) : ?>
24
-					<?php foreach( $tab_def as $col ) : ?>
23
+					<?php if (!empty($tab_def)) : ?>
24
+					<?php foreach ($tab_def as $col) : ?>
25 25
 						<th ><?php echo $col['name']; ?></th>
26 26
 					<?php endforeach; ?>
27 27
 					<?php endif; ?>
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 
32 32
 			<?php
33 33
 				$count_product = 1;
34
-				foreach( $products as $product ) :
35
-					$product_attribute_set_id = get_post_meta( $product['post_datas']->ID, '_wpshop_product_attribute_set_id', true );
34
+				foreach ($products as $product) :
35
+					$product_attribute_set_id = get_post_meta($product['post_datas']->ID, '_wpshop_product_attribute_set_id', true);
36 36
 					$class = ($count_product % 2) ? 'alternate' : '';
37 37
 			?>
38 38
 
39
-			<?php require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_line" ) ); ?>
39
+			<?php require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_line")); ?>
40 40
 
41 41
 			<?php
42 42
 				$count_product++;
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
 					<th class="check-column manage-column column-cb check-column">
48 48
 						<input type="checkbox" class="wps-save-product-checkbox" name="wps_product_quick_save_checkbox_column" />
49 49
 					</th>
50
-					<th><?php _e( 'Picture', 'wpshop'); ?></th>
51
-					<th><?php _e( 'Title', 'wpshop'); ?></th>
52
-					<th><?php _e( 'Description', 'wpshop'); ?></th>
50
+					<th><?php _e('Picture', 'wpshop'); ?></th>
51
+					<th><?php _e('Title', 'wpshop'); ?></th>
52
+					<th><?php _e('Description', 'wpshop'); ?></th>
53 53
 					<?php /*<th width="80"><?php _e( 'Files', 'wpshop'); ?></th>*/ ?>
54
-					<?php if( !empty($tab_def) ) : ?>
55
-					<?php foreach( $tab_def as $col ) : ?>
54
+					<?php if (!empty($tab_def)) : ?>
55
+					<?php foreach ($tab_def as $col) : ?>
56 56
 						<th><?php echo $col['name']; ?></th>
57 57
 					<?php endforeach; ?>
58 58
 					<?php endif; ?>
@@ -64,5 +64,5 @@  discard block
 block discarded – undo
64 64
 		jQuery("select.chosen_select").chosen( WPSHOP_CHOSEN_ATTRS );
65 65
 	} );</script>
66 66
 <?php else: ?>
67
-	<div class="wps-alert-info"><?php _e( 'You don\'t have any product for the moment', 'wpshop' ); ?></div>
67
+	<div class="wps-alert-info"><?php _e('You don\'t have any product for the moment', 'wpshop'); ?></div>
68 68
 <?php endif; ?>
Please login to merge, or discard this patch.
wps_product_mass_interface/controller/wps_product_mass_interface_ctr.php 1 patch
Spacing   +145 added lines, -145 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
  * Main controller file for product mass modification module
4 4
  *
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	function __construct() {
23 23
 		// Add submenu
24
-		add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 );
24
+		add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350);
25 25
 
26 26
 		// Declare Styles and JS Files
27
-		add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts') );
28
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_css' ) );
29
-		add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) );
27
+		add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts'));
28
+		add_action('admin_enqueue_scripts', array($this, 'admin_css'));
29
+		add_action('admin_print_scripts', array($this, 'admin_print_scripts'));
30 30
 
31 31
 		// Trigger ajax action
32
-		add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') );
33
-		add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') );
34
-		add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) );
35
-		add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) );
36
-		add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) );
32
+		add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page'));
33
+		add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface'));
34
+		add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation'));
35
+		add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file'));
36
+		add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list'));
37 37
 		// add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) );
38 38
 	}
39 39
 
40 40
 	function register_mass_products_edit_submenu() {
41
-		$this->submenu = add_submenu_page( 'edit.php?post_type=wpshop_product', __( 'Mass product edit', 'wpshop' ), __( 'Mass product edit', 'wpshop' ), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface' ) );
41
+		$this->submenu = add_submenu_page('edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop'), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface'));
42 42
 		// Declare Styles and JS Files.
43
-		add_action( 'admin_print_styles-' . $this->submenu, array( $this, 'admin_print_styles' ) );
44
-		add_action( 'admin_print_scripts-' . $this->submenu, array( $this, 'admin_print_scripts' ) );
43
+		add_action('admin_print_styles-' . $this->submenu, array($this, 'admin_print_styles'));
44
+		add_action('admin_print_scripts-' . $this->submenu, array($this, 'admin_print_scripts'));
45 45
 	}
46 46
 
47 47
 	/**
48 48
 	 * Add css to administration
49 49
 	 */
50 50
 	function admin_print_styles() {
51
-		wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css' );
51
+		wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css');
52 52
 	}
53 53
 
54 54
 	/**
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	function admin_print_scripts() {
58 58
 		wp_enqueue_media();
59
-		wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true );
59
+		wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true);
60 60
 		$output = '<script type="text/javascript">';
61
-		$output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";';
62
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";';
63
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";';
64
-		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";';
61
+		$output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";';
62
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";';
63
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";';
64
+		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";';
65 65
 		$output .= '</script>';
66 66
 		echo $output;
67 67
 	}
@@ -73,15 +73,15 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return array
75 75
 	 */
76
-	function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) {
77
-
78
-		if ( !empty( $attribute_list ) ) {
79
-			foreach( $attribute_list as $attributes_group ) {
80
-				foreach( $attributes_group as $attributes_sections ) {
81
-					if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) {
82
-						foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) {
83
-							if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) {
84
-								$quick_add_form_attributes[ $attribute_id ] = $att_def;
76
+	function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) {
77
+
78
+		if (!empty($attribute_list)) {
79
+			foreach ($attribute_list as $attributes_group) {
80
+				foreach ($attributes_group as $attributes_sections) {
81
+					if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) {
82
+						foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) {
83
+							if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') {
84
+								$quick_add_form_attributes[$attribute_id] = $att_def;
85 85
 							}
86 86
 						}
87 87
 					}
@@ -98,29 +98,29 @@  discard block
 block discarded – undo
98 98
 	 * @param integer $page
99 99
 	 * @return string
100 100
 	 */
101
-	function display_products_list( $default = 1, $page = 0  ) {
101
+	function display_products_list($default = 1, $page = 0) {
102 102
 		global $wpdb;
103 103
 		// Product entity
104
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
104
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
105 105
 
106 106
 		$user_id = get_current_user_id();
107 107
 		// Check product limit
108
-		$product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
109
-		$product_limit = ( !empty($product_limit) ) ? $product_limit : 20;
108
+		$product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
109
+		$product_limit = (!empty($product_limit)) ? $product_limit : 20;
110 110
 
111 111
 		// Get products for the current page
112 112
 		$wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl();
113
-		$products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit );
113
+		$products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit);
114 114
 
115 115
 		// Construct Table Head Data
116 116
 		$quick_add_form_attributes = array();
117 117
 		$get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form();
118
-		foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) {
118
+		foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) {
119 119
 			$quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute;
120 120
 		}
121 121
 
122 122
 		ob_start();
123
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) );
123
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list"));
124 124
 		$output = ob_get_contents();
125 125
 		ob_end_clean();
126 126
 		return $output;
@@ -136,25 +136,25 @@  discard block
 block discarded – undo
136 136
 		$products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets();
137 137
 
138 138
 		$default = '';
139
-		if( !empty($products_attributes_groups) ) {
140
-			foreach( $products_attributes_groups as $key => $products_attributes_group ) {
141
-				if( $products_attributes_group->slug == 'free_product' ) {
142
-					unset( $products_attributes_groups[$key] );
139
+		if (!empty($products_attributes_groups)) {
140
+			foreach ($products_attributes_groups as $key => $products_attributes_group) {
141
+				if ($products_attributes_group->slug == 'free_product') {
142
+					unset($products_attributes_groups[$key]);
143 143
 				}
144
-				if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) {
144
+				if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') {
145 145
 					$default = $products_attributes_group->id;
146 146
 				}
147 147
 			}
148 148
 		}
149 149
 		// Check page
150
-		$page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0;
150
+		$page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0;
151 151
 		// Display product tab
152
-		$product_list_interface = $this->display_products_list( $default, $page );
152
+		$product_list_interface = $this->display_products_list($default, $page);
153 153
 
154 154
 		// Get pagination
155
-		$pagination = $this->get_products_pagination( $page, $default );
155
+		$pagination = $this->get_products_pagination($page, $default);
156 156
 
157
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) );
157
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface"));
158 158
 	}
159 159
 
160 160
 	/**
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 * @return string
164 164
 	 */
165
-	function get_products_pagination( $current_page, $attribute_set_id = 1 ) {
165
+	function get_products_pagination($current_page, $attribute_set_id = 1) {
166 166
 		global $wpdb;
167 167
 		$user_id = get_current_user_id();
168 168
 		$output = '';
169 169
 		/**	Define the element number per page. If the user change the default value, take this value	*/
170
-		$one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
171
-		$one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20;
170
+		$one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
171
+		$one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20;
172 172
 
173 173
 		/**	Count the number of product existing in the shop	*/
174 174
 		$query = $wpdb->prepare(
@@ -180,37 +180,37 @@  discard block
 block discarded – undo
180 180
 				AND meta_value = %s
181 181
 				AND post_status IN ( 'publish', 'draft' )",
182 182
 				WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id);
183
-		$products = $wpdb->get_var( $query );
183
+		$products = $wpdb->get_var($query);
184 184
 
185
-			if( !empty($products) ) {
185
+			if (!empty($products)) {
186 186
 			$args = array(
187 187
 			'base' => '%_%',
188
-			'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ),
189
-					'current' => ( $current_page + 1 ),
190
-					'total' => ceil( $products / $one_page_limit ),
188
+			'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'),
189
+					'current' => ($current_page + 1),
190
+					'total' => ceil($products / $one_page_limit),
191 191
 						'type' => 'array',
192 192
 						'prev_next' => false,
193 193
 						'show_all' => true,
194 194
 			);
195
-			$paginate = paginate_links( $args );
195
+			$paginate = paginate_links($args);
196 196
 
197 197
 				$wps_product_ctr = new wps_product_ctr();
198 198
 				ob_start();
199
-				require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) );
199
+				require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination"));
200 200
 				$output = ob_get_contents();
201 201
 			ob_end_clean();
202 202
 			}
203 203
 			return $output;
204 204
 			}
205 205
 
206
-	function wps_product_attached_files( $product_id ) {
206
+	function wps_product_attached_files($product_id) {
207 207
 		global $wpdb;
208 208
 		$output = '';
209
-		$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%' );
210
-		$files = $wpdb->get_results( $query );
211
-		if( !empty($files) ) {
209
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%');
210
+		$files = $wpdb->get_results($query);
211
+		if (!empty($files)) {
212 212
 			ob_start();
213
-			require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) );
213
+			require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list"));
214 214
 			$output = ob_get_contents();
215 215
 			ob_end_clean();
216 216
 		}
@@ -222,23 +222,23 @@  discard block
 block discarded – undo
222 222
 	 * AJAX - Change page action on mass edit product interface
223 223
 	 */
224 224
 	function wps_mass_edit_change_page() {
225
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
225
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
226 226
 
227
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) )
227
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page'))
228 228
 			wp_die();
229 229
 
230 230
 		$status = false; $response = '';
231
-		$page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0;
232
-		$attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1;
233
-		if( !empty($attribute_set_id) ) {
231
+		$page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0;
232
+		$attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1;
233
+		if (!empty($attribute_set_id)) {
234 234
 			// Get tab
235
-			$response = $this->display_products_list( $attribute_set_id, $page );
236
-			$pagination = $this->get_products_pagination( $page, $attribute_set_id );
237
-			if( !empty($response) ) {
235
+			$response = $this->display_products_list($attribute_set_id, $page);
236
+			$pagination = $this->get_products_pagination($page, $attribute_set_id);
237
+			if (!empty($response)) {
238 238
 				$status = true;
239 239
 			}
240 240
 		}
241
-		echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) );
241
+		echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination));
242 242
 		wp_die();
243 243
 	}
244 244
 
@@ -246,30 +246,30 @@  discard block
 block discarded – undo
246 246
 	 * AJAX - Create a draft product and display the line allowing to edit informations for this product
247 247
 	 */
248 248
 	function wps_mass_interface_new_product_creation() {
249
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
249
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
250 250
 
251
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) )
251
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation'))
252 252
 			wp_die();
253 253
 
254 254
 		global $wpdb;
255 255
 		$output = $pagination = '';
256 256
 		$status = false;
257 257
 
258
-		$new_product_id = wp_insert_post( array(
258
+		$new_product_id = wp_insert_post(array(
259 259
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
260 260
 				'post_status' => 'publish',
261
-				'post_title' => __( 'New product', 'wpshop' ),
262
-		) );
261
+				'post_title' => __('New product', 'wpshop'),
262
+		));
263 263
 
264
-		if( !is_object($new_product_id) ) {
264
+		if (!is_object($new_product_id)) {
265 265
 			$status = true;
266 266
 		}
267
-		if ( !empty( $new_product_id ) ) {
268
-			$product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1;
269
-			update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id );
267
+		if (!empty($new_product_id)) {
268
+			$product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1;
269
+			update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id);
270 270
 		}
271 271
 
272
-		echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) );
272
+		echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination));
273 273
 		wp_die();
274 274
 	}
275 275
 
@@ -277,32 +277,32 @@  discard block
 block discarded – undo
277 277
 	 * AJAX - Save datas
278 278
 	 */
279 279
 	function wps_save_product_quick_interface() {
280
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
280
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
281 281
 
282
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) )
282
+		if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface'))
283 283
 			wp_die();
284 284
 
285 285
 		global $wpdb;
286 286
 		$response = ''; $status = false;
287 287
 		$count_products_to_update = 0; $total_updated_products = 0;
288 288
 
289
-		$wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array();
290
-		$wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array();
291
-		$wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array();
289
+		$wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array();
290
+		$wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array();
291
+		$wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array();
292 292
 
293 293
 		// ------------------------------------------------------------------------------------------------------
294 294
 
295
-		foreach( $_REQUEST['concur'] as $post_id => $columns ) {
295
+		foreach ($_REQUEST['concur'] as $post_id => $columns) {
296 296
 			$concur = array();
297
-			for( $i = $count = 0; $i <= $count; $i++ ) {
298
-				foreach( $columns as $key => $rows ) {
299
-					$count = count( $rows )-1;
297
+			for ($i = $count = 0; $i <= $count; $i++) {
298
+				foreach ($columns as $key => $rows) {
299
+					$count = count($rows) - 1;
300 300
 					$concur[$i][$key] = $rows[$i];
301 301
 				}
302
-				if( empty( $concur[$i]['is_row'] ) ) {
303
-					unset( $concur[$i] );
302
+				if (empty($concur[$i]['is_row'])) {
303
+					unset($concur[$i]);
304 304
 				} else {
305
-					unset( $concur[$i]['is_row'] );
305
+					unset($concur[$i]['is_row']);
306 306
 
307 307
 					$dotPos = strrpos($concur[$i]['price'], '.');
308 308
 					$commaPos = strrpos($concur[$i]['price'], ',');
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 					} else {
313 313
 						$concur[$i]['price'] = floatval(
314 314
 							preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], 0, $sep)) . '.' .
315
-							preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep+1, strlen($concur[$i]['price'])))
315
+							preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep + 1, strlen($concur[$i]['price'])))
316 316
 						);
317 317
 					}
318 318
 
@@ -320,51 +320,51 @@  discard block
 block discarded – undo
320 320
 					$concur[$i]['price'] = $concur[$i]['price'];
321 321
 				}
322 322
 			}
323
-			update_post_meta( $post_id, '_concur', $concur );
323
+			update_post_meta($post_id, '_concur', $concur);
324 324
 		}
325 325
 
326 326
 		// ------------------------------------------------------------------------------------------------------
327 327
 
328
-		if( !empty($wps_product_quick_save) ) {
329
-			$count_products_to_update = count( $wps_product_quick_save );
330
-			foreach( $wps_product_quick_save as $product_to_save ) {
328
+		if (!empty($wps_product_quick_save)) {
329
+			$count_products_to_update = count($wps_product_quick_save);
330
+			foreach ($wps_product_quick_save as $product_to_save) {
331 331
 				$data_to_save = array();
332 332
 				// Update post
333
-				$updated_post = wp_update_post( array( 'ID' => $product_to_save,
334
-						'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ),
335
-						'post_content' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_content'] ),
333
+				$updated_post = wp_update_post(array('ID' => $product_to_save,
334
+						'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']),
335
+						'post_content' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_content']),
336 336
 						)
337 337
 				);
338 338
 				// Update attributes
339
-				if( !empty($updated_post) ) {
339
+				if (!empty($updated_post)) {
340 340
 					// Update Featured picture
341
-					if( !empty($wps_mass_interface[$product_to_save]['picture']) ) {
342
-						$thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true );
343
-						if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
344
-							wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) );
345
-							update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] );
341
+					if (!empty($wps_mass_interface[$product_to_save]['picture'])) {
342
+						$thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true);
343
+						if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
344
+							wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post));
345
+							update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']);
346 346
 						}
347
-						elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
348
-							delete_post_meta( $updated_post, '_thumbnail_id' );
347
+						elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
348
+							delete_post_meta($updated_post, '_thumbnail_id');
349 349
 						}
350 350
 					}
351 351
 
352 352
 					// Update files datas
353
-					if( !empty($wps_mass_interface[$product_to_save]['files']) ) {
354
-						$files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) );
355
-						if( !empty($files_data) && is_array($files_data) ) {
356
-							foreach( $files_data as $file_id ) {
357
-								if( !empty($file_id) ) {
358
-									wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) );
353
+					if (!empty($wps_mass_interface[$product_to_save]['files'])) {
354
+						$files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files']));
355
+						if (!empty($files_data) && is_array($files_data)) {
356
+							foreach ($files_data as $file_id) {
357
+								if (!empty($file_id)) {
358
+									wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post));
359 359
 								}
360 360
 							}
361 361
 						}
362 362
 					}
363 363
 
364
-					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save );
365
-					$data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array();
364
+					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save);
365
+					$data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array();
366 366
 
367
-					if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
367
+					if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
368 368
 						// Get current barcode
369 369
 						$wps_product_mdl = new wps_product_mdl();
370 370
 						$attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id;
@@ -375,34 +375,34 @@  discard block
 block discarded – undo
375 375
 					$data_to_save['user_ID'] = get_current_user_id();
376 376
 					$data_to_save['action'] = 'editpost';
377 377
 
378
-					if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) {
379
-						wp_trash_post( $product_to_save );
378
+					if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") {
379
+						wp_trash_post($product_to_save);
380 380
 					}
381 381
 
382
-					if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) {
382
+					if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) {
383 383
 						$product_class = new wpshop_products();
384
-						$product_class->save_product_custom_informations( $product_to_save, $data_to_save );
384
+						$product_class->save_product_custom_informations($product_to_save, $data_to_save);
385 385
 						$total_updated_products++;
386 386
 					}
387 387
 				}
388 388
 			}
389 389
 		}
390 390
 		// Checking status
391
-		$status = ( $total_updated_products == $count_products_to_update ) ? true : false;
391
+		$status = ($total_updated_products == $count_products_to_update) ? true : false;
392 392
 
393
-		if( $status ) {
394
-			$response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products );
393
+		if ($status) {
394
+			$response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products);
395 395
 		}
396 396
 		else {
397
-			if( !empty($total_updated_products) ) {
398
-				$response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update );
397
+			if (!empty($total_updated_products)) {
398
+				$response = sprintf(__('All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update);
399 399
 			}
400 400
 			else {
401
-				$response = __( 'No product have been updated', 'wpshop');
401
+				$response = __('No product have been updated', 'wpshop');
402 402
 			}
403 403
 		}
404 404
 
405
-		echo json_encode( array('status' => $status, 'response' => $response ) );
405
+		echo json_encode(array('status' => $status, 'response' => $response));
406 406
 		wp_die();
407 407
 	}
408 408
 
@@ -410,18 +410,18 @@  discard block
 block discarded – undo
410 410
 	* Delete product list
411 411
 	**/
412 412
 	function wps_mass_delete_file() {
413
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
413
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
414 414
 
415
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) )
415
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file'))
416 416
 			wp_die();
417 417
 
418 418
 		$status = false;
419
-		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
420
-		if( !empty($file_id) ) {
421
-			wp_update_post( array('ID' => $file_id, 'post_parent' => 0) );
419
+		$file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null;
420
+		if (!empty($file_id)) {
421
+			wp_update_post(array('ID' => $file_id, 'post_parent' => 0));
422 422
 			$status = true;
423 423
 		}
424
-		echo json_encode( array( 'status' => $status ) );
424
+		echo json_encode(array('status' => $status));
425 425
 		wp_die();
426 426
 	}
427 427
 
@@ -429,32 +429,32 @@  discard block
 block discarded – undo
429 429
 	* Update product files list
430 430
 	*/
431 431
 	function wps_mass_edit_update_files_list() {
432
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
432
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
433 433
 
434
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) )
434
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list'))
435 435
 			wp_die();
436 436
 
437 437
 		$status = false; $response = '';
438
-		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
439
-		$files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null;
440
-		if( !empty($product_id ) ) {
438
+		$product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null;
439
+		$files = (!empty($_POST['files'])) ? intval($_POST['files']) : null;
440
+		if (!empty($product_id)) {
441 441
 			// Update files datas
442
-			if( !empty($files) ) {
443
-				$files_data = explode( ',', $files );
444
-				if( !empty($files_data) && is_array($files_data) ) {
445
-					foreach( $files_data as $file_id ) {
446
-						if( !empty($file_id) ) {
447
-							wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) );
442
+			if (!empty($files)) {
443
+				$files_data = explode(',', $files);
444
+				if (!empty($files_data) && is_array($files_data)) {
445
+					foreach ($files_data as $file_id) {
446
+						if (!empty($file_id)) {
447
+							wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id));
448 448
 						}
449 449
 					}
450 450
 				}
451 451
 			}
452 452
 
453 453
 
454
-			$response = $this->wps_product_attached_files( $product_id );
454
+			$response = $this->wps_product_attached_files($product_id);
455 455
 			$status = true;
456 456
 		}
457
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
457
+		echo json_encode(array('status' => $status, 'response' => $response));
458 458
 		wp_die();
459 459
 	}
460 460
 
Please login to merge, or discard this patch.
wps_product_variation_interface/templates/backend/meta_box_variation.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <div id="wps_variations_summary">
2
-	<div data-view-model="wps_variations_options_summary" id="wps_variations_summary_display"><b>%summary%</b></div><a id="wps_variations_parameters" href="<?php print wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=false', 'wps_remove_variation_interface');?>" title="<?php _e('Back to old interface', 'wpshop'); ?>"><span class="dashicons dashicons-admin-generic"></span></a>
2
+	<div data-view-model="wps_variations_options_summary" id="wps_variations_summary_display"><b>%summary%</b></div><a id="wps_variations_parameters" href="<?php print wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=false', 'wps_remove_variation_interface'); ?>" title="<?php _e('Back to old interface', 'wpshop'); ?>"><span class="dashicons dashicons-admin-generic"></span></a>
3 3
 </div>
4 4
 <div id="wps_variations_options">
5 5
 	<ul id="wps_variations_options_title">
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 		<li class="wps_variations_price_weight_col"><input type="text" pattern="[0-9]+(\.[0-9][0-9]?)?" onchange="wps_variations_price_option_raw.control.weight(this)" name="wps_pdt_variations[%ID%][attribute][decimal][product_weight]" align="right" value="%weight%"></li>
58 58
 <<<<<<< HEAD
59 59
 		<li class="wps_variations_price_reference_col"><input type="text" onchange="wps_variations_price_option_raw.control.reference(this)" name="wps_pdt_variations[%ID%][attribute][varchar][product_reference]" align="right" value="%reference%"></li>
60
-		<li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"><span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span><input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)"><?php wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce');?><a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"><span class="dashicons dashicons-download"></span></a></li>
60
+		<li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"><span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span><input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)"><?php wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce'); ?><a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"><span class="dashicons dashicons-download"></span></a></li>
61 61
 =======
62
-		<li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"><?php echo apply_filters('wpshop_new_interface_variation_download_file_dialog', '<span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span><input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)">' . wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce') . '<a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"><span class="dashicons dashicons-download"></span></a>' ); ?></li>
62
+		<li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"><?php echo apply_filters('wpshop_new_interface_variation_download_file_dialog', '<span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span><input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)">' . wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce') . '<a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"><span class="dashicons dashicons-download"></span></a>'); ?></li>
63 63
 >>>>>>> origin/master
64 64
 		<li class="wps_variations_price_active_col"><input name="wps_pdt_variations[%ID%][status]" onclick="wps_variations_price_option_raw.control.activate(this)" type="checkbox" %price_option_activate%></li>
65 65
 	</ul>
Please login to merge, or discard this patch.
controller/wps_product_variation_interface.ctr.php 5 patches
Indentation   +1 added lines, -4 removed lines patch added patch discarded remove patch
@@ -364,7 +364,4 @@
 block discarded – undo
364 364
                 $output['field'] = '';
365 365
             }
366 366
         }
367
-        return $output;
368
-    }
369
->>>>>>> origin/master
370
-}
367
+        return $output
371 368
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -4 removed lines patch added patch discarded remove patch
@@ -364,7 +364,4 @@
 block discarded – undo
364 364
                 $output['field'] = '';
365 365
             }
366 366
         }
367
-        return $output;
368
-    }
369
->>>>>>> origin/master
370
-}
367
+        return $output
371 368
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 /**
3 3
  * Controller new interface for variation
4 4
  */
5
-<<<<<<< HEAD
5
+<< << <<< HEAD
6 6
 class wps_product_variation_interface {
7 7
 
8 8
 	/**
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
                     $attribute->possible_value = $values['possible_value'];
304 304
                 }
305 305
             }
306
-            $attribute_list[$attribute->code] = $attribute;
306
+            $attribute_list[$attribute - >code] = $attribute;
307 307
         }
308 308
         $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true);
309 309
         $variations_saved = wpshop_products::get_variation($post->ID);
@@ -364,7 +364,4 @@  discard block
 block discarded – undo
364 364
                 $output['field'] = '';
365 365
             }
366 366
         }
367
-        return $output;
368
-    }
369
->>>>>>> origin/master
370
-}
367
+        return $output
371 368
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -4 removed lines patch added patch discarded remove patch
@@ -364,7 +364,4 @@
 block discarded – undo
364 364
                 $output['field'] = '';
365 365
             }
366 366
         }
367
-        return $output;
368
-    }
369
->>>>>>> origin/master
370
-}
367
+        return $output
371 368
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -4 removed lines patch added patch discarded remove patch
@@ -364,7 +364,4 @@
 block discarded – undo
364 364
                 $output['field'] = '';
365 365
             }
366 366
         }
367
-        return $output;
368
-    }
369
->>>>>>> origin/master
370
-}
367
+        return $output
371 368
\ No newline at end of file
Please login to merge, or discard this patch.