Completed
Push — master ( 0b57c7...14700a )
by
unknown
13:14
created
includes/modules/wps_opinion/templates/frontend/posted_opinion.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 ?>
3 3
 <div class="wps-table-content wps-table-row">
4
-		<div class="wps-table-cell"><?php echo mysql2date( get_option('date_format'), $posted_opinion->opinion_date, true ); ?></div>
5
-		<div class="wps-table-cell"><a href="<?php echo get_permalink($posted_opinion->opinion_post_ID); ?>" target="_blank"><?php echo get_the_post_thumbnail( $posted_opinion->opinion_post_ID, 'thumbnail', array( 'class' => 'wps-circlerounded') ); ?></a></div>
4
+		<div class="wps-table-cell"><?php echo mysql2date(get_option('date_format'), $posted_opinion->opinion_date, true); ?></div>
5
+		<div class="wps-table-cell"><a href="<?php echo get_permalink($posted_opinion->opinion_post_ID); ?>" target="_blank"><?php echo get_the_post_thumbnail($posted_opinion->opinion_post_ID, 'thumbnail', array('class' => 'wps-circlerounded')); ?></a></div>
6 6
 		<div class="wps-table-cell">
7 7
 			<a href="<?php echo get_permalink($posted_opinion->opinion_post_ID); ?>" target="_blank">
8 8
 			<?php
9
-			$product = get_post( $posted_opinion->opinion_post_ID );
10
-			if( !empty($product) && !empty($product->post_type) ) :
11
-				if( $product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) :
12
-					$product = get_post( $product->post_parent );
9
+			$product = get_post($posted_opinion->opinion_post_ID);
10
+			if (!empty($product) && !empty($product->post_type)) :
11
+				if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) :
12
+					$product = get_post($product->post_parent);
13 13
 				endif;
14 14
 			endif;
15 15
 			echo $product->post_title;
@@ -17,5 +17,5 @@  discard block
 block discarded – undo
17 17
 			</a>
18 18
 		</div>
19 19
 		<div class="wps-table-cell"><?php echo $posted_opinion->opinion_content; ?></div>
20
-		<div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars( $posted_opinion->opinion_rate ); ?></div>
20
+		<div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars($posted_opinion->opinion_rate); ?></div>
21 21
 </div>
Please login to merge, or discard this patch.
includes/modules/wps_opinion/templates/frontend/posted_opinions.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
2
- if( !empty($posted_opinions) ) : ?>
3
-<span class="wps-h5"><?php _e( 'My opinions', 'wpshop'); ?></span>
1
+<?php if (!defined('ABSPATH')) exit;
2
+ if (!empty($posted_opinions)) : ?>
3
+<span class="wps-h5"><?php _e('My opinions', 'wpshop'); ?></span>
4 4
 <div class="wps-table">
5 5
 	<div class="wps-table-header wps-table-row">
6
-		<div class="wps-table-cell"><?php _e( 'Date', 'wps_opinion'); ?></div>
7
-		<div class="wps-table-cell"><?php _e( 'Picture', 'wps_opinion'); ?></div>
8
-		<div class="wps-table-cell"><?php _e( 'Product', 'wps_opinion'); ?></div>
9
-		<div class="wps-table-cell"><?php _e( 'Opinion', 'wps_opinion'); ?></div>
10
-		<div class="wps-table-cell"><?php _e( 'Rate', 'wps_opinion'); ?></div>
6
+		<div class="wps-table-cell"><?php _e('Date', 'wps_opinion'); ?></div>
7
+		<div class="wps-table-cell"><?php _e('Picture', 'wps_opinion'); ?></div>
8
+		<div class="wps-table-cell"><?php _e('Product', 'wps_opinion'); ?></div>
9
+		<div class="wps-table-cell"><?php _e('Opinion', 'wps_opinion'); ?></div>
10
+		<div class="wps-table-cell"><?php _e('Rate', 'wps_opinion'); ?></div>
11 11
 	</div>
12 12
 
13 13
 	<?php
14
-	if( !empty($posted_opinions) ) :
15
-		foreach( $posted_opinions as $posted_opinion ) :
16
-			require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir,"frontend", "posted_opinion") );
14
+	if (!empty($posted_opinions)) :
15
+		foreach ($posted_opinions as $posted_opinion) :
16
+			require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "posted_opinion"));
17 17
 		endforeach;
18 18
 	endif;
19 19
 	?>
20 20
 </div>
21 21
 <?php else : ?>
22
-<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop'); ?></div>
22
+<div class="wps-alert-info"><?php _e('You never posted an opinion on a product', 'wpshop'); ?></div>
23 23
 <?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($posted_opinions) ) : ?>
3 5
 <span class="wps-h5"><?php _e( 'My opinions', 'wpshop'); ?></span>
4 6
 <div class="wps-table">
@@ -18,6 +20,9 @@  discard block
 block discarded – undo
18 20
 	endif;
19 21
 	?>
20 22
 </div>
21
-<?php else : ?>
22
-<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop'); ?></div>
23
+<?php else {
24
+	: ?>
25
+<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop');
26
+}
27
+?></div>
23 28
 <?php endif; ?>
Please login to merge, or discard this patch.
modules/wps_customer/templates/frontend/account/account-dashboard.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
2
-$permalink_option = get_option( 'permalink_structure' );
3
-$account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' ) );
4
-$account_dashboard_part = !empty( $_GET['account_dashboard_part'] ) ? sanitize_text_field( $_GET['account_dashboard_part'] ) : '';
1
+<?php if (!defined('ABSPATH')) exit;
2
+$permalink_option = get_option('permalink_structure');
3
+$account_page_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'));
4
+$account_dashboard_part = !empty($_GET['account_dashboard_part']) ? sanitize_text_field($_GET['account_dashboard_part']) : '';
5 5
 ?>
6 6
 
7 7
 <?php $user_ID = get_current_user_id(); ?>
8 8
 
9
-<?php if ( 0 !== $user_ID ) : ?>
9
+<?php if (0 !== $user_ID) : ?>
10 10
 <div class="wps-user-dashboard">
11
-	<?php $account_user = get_userdata( $user_ID ); ?>
11
+	<?php $account_user = get_userdata($user_ID); ?>
12 12
 	<span class="wps-user-name">
13
-		<?php _e( 'Hello', 'wpshop' ); ?>
13
+		<?php _e('Hello', 'wpshop'); ?>
14 14
 		<strong><?php echo $account_user->data->user_login; ?></strong>
15 15
 	</span>
16 16
 	<span class="wps-user-thumbnail">
17
-		<?php echo get_avatar( $user_ID, 40 ); ?>
17
+		<?php echo get_avatar($user_ID, 40); ?>
18 18
 	</span>
19
-	<a href="<?php echo wp_logout_url( site_url() ); ?>" class="" title="<?php _e( 'Log out', 'wpshop' ); ?>">
19
+	<a href="<?php echo wp_logout_url(site_url()); ?>" class="" title="<?php _e('Log out', 'wpshop'); ?>">
20 20
 		<i class="wps-icon-power"></i>
21 21
 	</a>
22 22
 </div>
@@ -25,50 +25,50 @@  discard block
 block discarded – undo
25 25
 <section class="wps-section-account">
26 26
 	<div class="wps-section-taskbar">
27 27
 		<ul>
28
-			<li class="<?php echo ( ( empty($account_dashboard_part) || ( !empty($account_dashboard_part) && $account_dashboard_part == 'account' ) ) ? 'wps-activ' : '' ); ?>">
29
-				<a data-target="menu1" href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=account' ); ?>" title="" class="">
28
+			<li class="<?php echo ((empty($account_dashboard_part) || (!empty($account_dashboard_part) && $account_dashboard_part == 'account')) ? 'wps-activ' : ''); ?>">
29
+				<a data-target="menu1" href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=account'); ?>" title="" class="">
30 30
 					<i class="wps-icon-user"></i>
31
-					<span><?php _e( 'Account', 'wpshop'); ?></span>
31
+					<span><?php _e('Account', 'wpshop'); ?></span>
32 32
 				</a>
33 33
 			</li>
34
-			<li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'address') ? 'wps-activ' : '' ); ?>">
35
-				<a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=address' ); ?>" title="" class="">
34
+			<li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'address') ? 'wps-activ' : ''); ?>">
35
+				<a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=address'); ?>" title="" class="">
36 36
 					<i class="wps-icon-address"></i>
37
-					<span><?php _e( 'Addresses', 'wpshop'); ?></span>
37
+					<span><?php _e('Addresses', 'wpshop'); ?></span>
38 38
 				</a>
39 39
 			</li>
40
-			<li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'order') ? 'wps-activ' : '' ); ?>">
41
-				<a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=order' ); ?>" title="" class="">
40
+			<li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'order') ? 'wps-activ' : ''); ?>">
41
+				<a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=order'); ?>" title="" class="">
42 42
 					<i class="wps-icon-truck"></i>
43
-					<span><?php _e( 'Orders', 'wpshop'); ?></span>
43
+					<span><?php _e('Orders', 'wpshop'); ?></span>
44 44
 				</a>
45 45
 			</li>
46
-			<li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'coupon') ? 'wps-activ' : '' ); ?>">
47
-				<a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=coupon' ); ?>" title="" class="">
46
+			<li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'coupon') ? 'wps-activ' : ''); ?>">
47
+				<a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=coupon'); ?>" title="" class="">
48 48
 					<i class="wps-icon-promo"></i>
49
-					<span><?php _e( 'Coupons', 'wpshop'); ?></span>
49
+					<span><?php _e('Coupons', 'wpshop'); ?></span>
50 50
 				</a>
51 51
 			</li>
52
-			<?php $opinion_option = get_option( 'wps_opinion' );
53
-			if( !empty($opinion_option) && !empty($opinion_option['active']) ) : ?>
54
-			<li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'opinion') ? 'wps-activ' : '' ); ?>">
55
-				<a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=opinion' ); ?>" title="" class="">
52
+			<?php $opinion_option = get_option('wps_opinion');
53
+			if (!empty($opinion_option) && !empty($opinion_option['active'])) : ?>
54
+			<li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'opinion') ? 'wps-activ' : ''); ?>">
55
+				<a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=opinion'); ?>" title="" class="">
56 56
 					<i class="wps-icon-chat"></i>
57
-					<span><?php _e( 'Opinions', 'wpshop'); ?></span>
57
+					<span><?php _e('Opinions', 'wpshop'); ?></span>
58 58
 				</a>
59 59
 			</li>
60 60
 			<?php endif; ?>
61
-			<li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'messages') ? 'wps-activ' : '' ); ?>">
62
-				<a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=messages' ); ?>" title="" class="">
61
+			<li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'messages') ? 'wps-activ' : ''); ?>">
62
+				<a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=messages'); ?>" title="" class="">
63 63
 					<i class="wps-icon-email"></i>
64
-					<span><?php _e( 'Messages', 'wpshop' ); ?></span>
64
+					<span><?php _e('Messages', 'wpshop'); ?></span>
65 65
 				</a>
66 66
 			</li>
67 67
 			<?php echo apply_filters('wps_my_account_extra_part_menu', ''); ?>
68 68
 		</ul>
69 69
 	</div>
70 70
 	<div class="wps-section-content">
71
-		<div class="wps-activ" id="wps_dashboard_content" data-nonce="<?php echo wp_create_nonce( 'wps_refresh_add_opinion_list' ); ?>">
71
+		<div class="wps-activ" id="wps_dashboard_content" data-nonce="<?php echo wp_create_nonce('wps_refresh_add_opinion_list'); ?>">
72 72
 			<?php echo $content; ?>
73 73
 		</div>
74 74
 	</div>
Please login to merge, or discard this patch.
includes/modules/wps_cart/controller/wps_cart_ctr.php 2 patches
Spacing   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -1,48 +1,48 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_cart {
3 3
 
4 4
 	function __construct() {
5 5
 		/** WPShop Cart Shortcode **/
6
-		add_shortcode( 'wps_cart', array( &$this, 'display_cart' ) );
7
-		add_shortcode( 'wpshop_cart', array( &$this, 'display_cart' ) );
6
+		add_shortcode('wps_cart', array(&$this, 'display_cart'));
7
+		add_shortcode('wpshop_cart', array(&$this, 'display_cart'));
8 8
 		/** WPShop Mini Cart Shortcode **/
9
-		add_shortcode( 'wps_mini_cart', array( &$this, 'display_mini_cart' ) );
10
-		add_shortcode( 'wpshop_mini_cart', array( &$this, 'display_mini_cart' ) );
9
+		add_shortcode('wps_mini_cart', array(&$this, 'display_mini_cart'));
10
+		add_shortcode('wpshop_mini_cart', array(&$this, 'display_mini_cart'));
11 11
 		/** WPShop Resume Cart Shorcode **/
12
-		add_shortcode( 'wps_resume_cart', array( &$this, 'display_resume_cart' ) );
13
-		add_shortcode( 'wpshop_resume_cart', array( &$this, 'display_resume_cart' ) );
12
+		add_shortcode('wps_resume_cart', array(&$this, 'display_resume_cart'));
13
+		add_shortcode('wpshop_resume_cart', array(&$this, 'display_resume_cart'));
14 14
 		/** Apply Coupon Interface **/
15
-		add_shortcode( 'wps_apply_coupon', array( &$this, 'display_apply_coupon_interface' ) );
16
-		add_shortcode( 'wpshop_apply_coupon', array( &$this, 'display_apply_coupon_interface' ) );
15
+		add_shortcode('wps_apply_coupon', array(&$this, 'display_apply_coupon_interface'));
16
+		add_shortcode('wpshop_apply_coupon', array(&$this, 'display_apply_coupon_interface'));
17 17
 		/** NUmeration Cart **/
18
-		add_shortcode( 'wps-numeration-cart', array( &$this, 'display_wps_numeration_cart' ) );
19
-		add_shortcode( 'wpshop-numeration-cart', array( &$this, 'display_wps_numeration_cart' ) );
18
+		add_shortcode('wps-numeration-cart', array(&$this, 'display_wps_numeration_cart'));
19
+		add_shortcode('wpshop-numeration-cart', array(&$this, 'display_wps_numeration_cart'));
20 20
 		/** Button add to cart */
21
-		add_shortcode( 'wpshop_button_add_to_cart', array( &$this, 'display_button_add_to_cart' ) );
21
+		add_shortcode('wpshop_button_add_to_cart', array(&$this, 'display_button_add_to_cart'));
22 22
 
23
-		add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
24
-		add_action( 'init', array( $this, 'load_cart_from_db' ) );
23
+		add_action('wp_enqueue_scripts', array($this, 'add_scripts'));
24
+		add_action('init', array($this, 'load_cart_from_db'));
25 25
 
26 26
 		/** Ajax Actions **/
27
-		add_action( 'wp_ajax_wps_reload_cart', array( $this, 'wps_reload_cart' ) );
28
-		add_action( 'wp_ajax_nopriv_wps_reload_cart', array( $this, 'wps_reload_cart' ) );
27
+		add_action('wp_ajax_wps_reload_cart', array($this, 'wps_reload_cart'));
28
+		add_action('wp_ajax_nopriv_wps_reload_cart', array($this, 'wps_reload_cart'));
29 29
 
30
-		add_action( 'wp_ajax_wps_reload_mini_cart', array( &$this, 'wps_reload_mini_cart' ) );
31
-		add_action( 'wp_ajax_nopriv_wps_reload_mini_cart', array( &$this, 'wps_reload_mini_cart' ) );
30
+		add_action('wp_ajax_wps_reload_mini_cart', array(&$this, 'wps_reload_mini_cart'));
31
+		add_action('wp_ajax_nopriv_wps_reload_mini_cart', array(&$this, 'wps_reload_mini_cart'));
32 32
 
33
-		add_action( 'wp_ajax_wps_reload_summary_cart', array( &$this, 'wps_reload_summary_cart' ) );
34
-		add_action( 'wp_ajax_nopriv_wps_reload_summary_cart', array( &$this, 'wps_reload_summary_cart' ) );
33
+		add_action('wp_ajax_wps_reload_summary_cart', array(&$this, 'wps_reload_summary_cart'));
34
+		add_action('wp_ajax_nopriv_wps_reload_summary_cart', array(&$this, 'wps_reload_summary_cart'));
35 35
 
36
-		add_action( 'wp_ajax_wps_apply_coupon', array( &$this, 'wps_apply_coupon' ) );
37
-		add_action( 'wp_ajax_nopriv_wps_apply_coupon', array( &$this, 'wps_apply_coupon' ) );
36
+		add_action('wp_ajax_wps_apply_coupon', array(&$this, 'wps_apply_coupon'));
37
+		add_action('wp_ajax_nopriv_wps_apply_coupon', array(&$this, 'wps_apply_coupon'));
38 38
 
39
-		add_action( 'wp_ajax_wps_cart_pass_to_step_two', array( &$this, 'wps_cart_pass_to_step_two' ) );
40
-		add_action( 'wp_ajax_nopriv_wps_cart_pass_to_step_two', array( &$this, 'wps_cart_pass_to_step_two' ) );
39
+		add_action('wp_ajax_wps_cart_pass_to_step_two', array(&$this, 'wps_cart_pass_to_step_two'));
40
+		add_action('wp_ajax_nopriv_wps_cart_pass_to_step_two', array(&$this, 'wps_cart_pass_to_step_two'));
41 41
 
42
-		add_action( 'wp_ajax_wps_empty_cart', array( &$this, 'wps_empty_cart' ) );
43
-		add_action( 'wp_ajax_nopriv_wps_empty_cart', array( &$this, 'wps_empty_cart' ) );
42
+		add_action('wp_ajax_wps_empty_cart', array(&$this, 'wps_empty_cart'));
43
+		add_action('wp_ajax_nopriv_wps_empty_cart', array(&$this, 'wps_empty_cart'));
44 44
 
45
-		add_action( 'wsphop_options', array(&$this, 'declare_options' ), 8);
45
+		add_action('wsphop_options', array(&$this, 'declare_options'), 8);
46 46
 	}
47 47
 
48 48
 	/**
@@ -50,19 +50,19 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	function add_scripts() {
52 52
 		wp_enqueue_script('jquery');
53
-		wp_enqueue_script( 'wps_cart_js',  WPS_CART_URL . WPS_CART_DIR.'/assets/frontend/js/wps_cart.js' );
53
+		wp_enqueue_script('wps_cart_js', WPS_CART_URL . WPS_CART_DIR . '/assets/frontend/js/wps_cart.js');
54 54
 	}
55 55
 
56 56
 	/**
57 57
 	 * Declare Cart Options
58 58
 	 */
59
-	public static function declare_options () {
60
-		if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) {
61
-			$wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : '';
62
-			$old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : '';
59
+	public static function declare_options() {
60
+		if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
61
+			$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
62
+			$old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
63 63
 
64
-			if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' )
65
-				&& ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) {
64
+			if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
65
+				&& ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
66 66
 					/**	Add module option to wpshop general options	*/
67 67
 					register_setting('wpshop_options', 'wpshop_cart_option', array('wps_cart', 'wpshop_options_validate_cart_type'));
68 68
 					add_settings_field('wpshop_cart_type', __('Which type of cart do you want to display', 'wpshop'), array('wps_cart', 'wpshop_cart_type_field'), 'wpshop_cart_info', 'wpshop_cart_info');
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @param unknown_type $input
76 76
 	 * @return unknown
77 77
 	 */
78
-	public static function wpshop_options_validate_cart_type( $input ) {
78
+	public static function wpshop_options_validate_cart_type($input) {
79 79
 		return $input;
80 80
 	}
81 81
 
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
83 83
 	 * Cart Options Fields
84 84
 	 */
85 85
 	public static function wpshop_cart_type_field() {
86
-		$cart_option = get_option( 'wpshop_cart_option' );
86
+		$cart_option = get_option('wpshop_cart_option');
87 87
 
88 88
 		$output  = '<select name="wpshop_cart_option[cart_type]">';
89
-		$output .= '<option value="simplified_ati" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_ati' ) ? 'selected="selected"' : ''). ' >' .__( 'Simplified cart ATI', 'wpshop'). '</option>';
90
-		$output .= '<option value="simplified_et" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_et' ) ? 'selected="selected"' : ''). ' >' .__( 'Simplified cart ET', 'wpshop'). '</option>';
91
-		$output .= '<option value="full_cart" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'full_cart' ) ? 'selected="selected"' : ''). ' >' .__( 'Full cart', 'wpshop'). '</option>';
89
+		$output .= '<option value="simplified_ati" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_ati') ? 'selected="selected"' : '') . ' >' . __('Simplified cart ATI', 'wpshop') . '</option>';
90
+		$output .= '<option value="simplified_et" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_et') ? 'selected="selected"' : '') . ' >' . __('Simplified cart ET', 'wpshop') . '</option>';
91
+		$output .= '<option value="full_cart" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'full_cart') ? 'selected="selected"' : '') . ' >' . __('Full cart', 'wpshop') . '</option>';
92 92
 		$output .= '</select>';
93 93
 
94 94
 		echo $output;
95 95
 	}
96 96
 
97 97
 	/** Display Cart **/
98
-	function display_cart( $args ) {
99
-		$cart_type = ( !empty($args) && !empty($args['cart_type']) ) ?  $args['cart_type']: '';
100
-		$oid =  ( !empty($args) && !empty($args['oid']) ) ?  $args['oid'] : '';
101
-		$output  = '<div id="wps_cart_container" data-nonce="' . wp_create_nonce( 'wps_reload_cart' ) . '" class="wps-bloc-loader wps-cart-wrapper">';
98
+	function display_cart($args) {
99
+		$cart_type = (!empty($args) && !empty($args['cart_type'])) ? $args['cart_type'] : '';
100
+		$oid = (!empty($args) && !empty($args['oid'])) ? $args['oid'] : '';
101
+		$output  = '<div id="wps_cart_container" data-nonce="' . wp_create_nonce('wps_reload_cart') . '" class="wps-bloc-loader wps-cart-wrapper">';
102 102
 		$output .= self::cart_content($cart_type, $oid);
103 103
 		$output .= '</div>';
104 104
 
@@ -106,84 +106,84 @@  discard block
 block discarded – undo
106 106
 	}
107 107
 
108 108
 	/** Cart Content **/
109
-	public static function cart_content( $cart_type = '', $oid = '' ) {
109
+	public static function cart_content($cart_type = '', $oid = '') {
110 110
 		global $wpdb;
111 111
 		$output = '';
112 112
 		$account_origin = false;
113
-		$cart_option = get_option( 'wpshop_cart_option' );
114
-		$cart_option = ( !empty($cart_option) && !empty($cart_option['cart_type']) ) ? $cart_option['cart_type'] : 'simplified_ati';
113
+		$cart_option = get_option('wpshop_cart_option');
114
+		$cart_option = (!empty($cart_option) && !empty($cart_option['cart_type'])) ? $cart_option['cart_type'] : 'simplified_ati';
115 115
 
116
-		$price_piloting  = get_option( 'wpshop_shop_price_piloting' );
116
+		$price_piloting = get_option('wpshop_shop_price_piloting');
117 117
 
118 118
 		$coupon_title = $coupon_value = '';
119
-		$cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array();
120
-		if( !empty($oid) ) {
119
+		$cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array();
120
+		if (!empty($oid)) {
121 121
 			$account_origin = true;
122
-			$cart_content = get_post_meta( $oid, '_order_postmeta', true);
122
+			$cart_content = get_post_meta($oid, '_order_postmeta', true);
123 123
 		}
124
-		$currency = wpshop_tools::wpshop_get_currency( false );
124
+		$currency = wpshop_tools::wpshop_get_currency(false);
125 125
 
126
-		if ( !empty($cart_content) ) {
127
-			$cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array();
126
+		if (!empty($cart_content)) {
127
+			$cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array();
128 128
 
129
-			if ( !empty($cart_content['coupon_id']) ) {
130
-				$coupon_title = get_the_title( $cart_content['coupon_id']);
131
-				$coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] );
129
+			if (!empty($cart_content['coupon_id'])) {
130
+				$coupon_title = get_the_title($cart_content['coupon_id']);
131
+				$coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']);
132 132
 			}
133 133
 
134
-			if ( !empty($cart_items) ) {
134
+			if (!empty($cart_items)) {
135 135
 				/** Total values **/
136
-				$shipping_cost_et = ( !empty($cart_content['order_shipping_cost']) ) ? ( (!empty($price_piloting) && $price_piloting != 'HT') ? ( $cart_content['order_shipping_cost'] / ( 1 + ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ) ) : $cart_content['order_shipping_cost'] ) : 0;
137
-				$shipping_cost_vat = ( !empty( $shipping_cost_et) ) ? ( $shipping_cost_et * ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ) : 0;
138
-				$shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? ( (!empty($price_piloting) && $price_piloting != 'HT') ? $cart_content['order_shipping_cost'] : $cart_content['order_shipping_cost'] + $shipping_cost_vat ) : 0;
139
-				$total_et = ( !empty( $cart_content['order_total_ht']) ) ? $cart_content['order_total_ht'] : 0;
140
-				$order_totla_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0;
141
-				$order_amount_to_pay_now = wpshop_tools::formate_number( $cart_content['order_amount_to_pay_now'] );
142
-				$total_ati = ( !empty( $order_amount_to_pay_now ) && !empty($oid) && $order_amount_to_pay_now > 0 ) ? $cart_content['order_amount_to_pay_now'] : ( (!empty($cart_content['order_grand_total']) ) ? $cart_content['order_grand_total'] : 0 );
136
+				$shipping_cost_et = (!empty($cart_content['order_shipping_cost'])) ? ((!empty($price_piloting) && $price_piloting != 'HT') ? ($cart_content['order_shipping_cost'] / (1 + (WPSHOP_VAT_ON_SHIPPING_COST / 100))) : $cart_content['order_shipping_cost']) : 0;
137
+				$shipping_cost_vat = (!empty($shipping_cost_et)) ? ($shipping_cost_et * (WPSHOP_VAT_ON_SHIPPING_COST / 100)) : 0;
138
+				$shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? ((!empty($price_piloting) && $price_piloting != 'HT') ? $cart_content['order_shipping_cost'] : $cart_content['order_shipping_cost'] + $shipping_cost_vat) : 0;
139
+				$total_et = (!empty($cart_content['order_total_ht'])) ? $cart_content['order_total_ht'] : 0;
140
+				$order_totla_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0;
141
+				$order_amount_to_pay_now = wpshop_tools::formate_number($cart_content['order_amount_to_pay_now']);
142
+				$total_ati = (!empty($order_amount_to_pay_now) && !empty($oid) && $order_amount_to_pay_now > 0) ? $cart_content['order_amount_to_pay_now'] : ((!empty($cart_content['order_grand_total'])) ? $cart_content['order_grand_total'] : 0);
143 143
 				unset($tracking);
144
-				if( !empty($cart_content['order_trackingNumber']) ) {
144
+				if (!empty($cart_content['order_trackingNumber'])) {
145 145
 					$tracking['number'] = $cart_content['order_trackingNumber'];
146 146
 				}
147
-				if( !empty($cart_content['order_trackingLink']) ) {
147
+				if (!empty($cart_content['order_trackingLink'])) {
148 148
 					$tracking['link'] = $cart_content['order_trackingLink'];
149 149
 				}
150 150
 				ob_start();
151
-				require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart") );
151
+				require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart"));
152 152
 				$output = ob_get_contents();
153 153
 				ob_end_clean();
154 154
 			}
155 155
 			else {
156
-				return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';;
156
+				return '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; ;
157 157
 			}
158 158
 		}
159 159
 		else {
160
-			return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';;
160
+			return '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; ;
161 161
 		}
162 162
 		return $output;
163 163
 	}
164 164
 
165 165
 	/** Display mini cart **/
166
-	function display_mini_cart( $args ) {
166
+	function display_mini_cart($args) {
167 167
 		$total_cart_item = 0;
168
-		$cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array();
169
-		$type = ( !empty($args) && !empty($args['type']) ) ? $args['type'] : '';
168
+		$cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array();
169
+		$type = (!empty($args) && !empty($args['type'])) ? $args['type'] : '';
170 170
 
171 171
 
172
-		if ( !empty($cart_content) ) {
173
-			$cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array();
172
+		if (!empty($cart_content)) {
173
+			$cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array();
174 174
 			/** Count items **/
175
-			$total_cart_item = self::total_cart_items( $cart_items );
176
-			$mini_cart_body = self::mini_cart_content( $type );
175
+			$total_cart_item = self::total_cart_items($cart_items);
176
+			$mini_cart_body = self::mini_cart_content($type);
177 177
 		}
178 178
 		else {
179 179
 			$mini_cart_body = self::mini_cart_content();
180 180
 		}
181 181
 		ob_start();
182
-		if( !empty($type) && $type == 'fixed' ) {
183
-			require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart") );
182
+		if (!empty($type) && $type == 'fixed') {
183
+			require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart"));
184 184
 		}
185 185
 		else {
186
-			require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart") );
186
+			require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart"));
187 187
 		}
188 188
 
189 189
 		$output = ob_get_contents();
@@ -192,37 +192,37 @@  discard block
 block discarded – undo
192 192
 	}
193 193
 
194 194
 	/** Mini cart Content **/
195
-	public static function mini_cart_content( $type = '') {
196
-		$currency = wpshop_tools::wpshop_get_currency( false );
197
-		$cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array();
195
+	public static function mini_cart_content($type = '') {
196
+		$currency = wpshop_tools::wpshop_get_currency(false);
197
+		$cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array();
198 198
 		$output = '';
199
-		if ( !empty($cart_content) ) {
200
-			$cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array();
201
-			if ( !empty($cart_items) ) {
202
-				if ( !empty($cart_content['coupon_id']) ) {
203
-					$coupon_title = get_the_title( $cart_content['coupon_id']);
204
-					$coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] );
199
+		if (!empty($cart_content)) {
200
+			$cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array();
201
+			if (!empty($cart_items)) {
202
+				if (!empty($cart_content['coupon_id'])) {
203
+					$coupon_title = get_the_title($cart_content['coupon_id']);
204
+					$coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']);
205 205
 				}
206
-				$order_total_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0;
207
-				$shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? $cart_content['order_shipping_cost'] : 0;
208
-				$total_ati  = $total_cart = ( !empty($cart_content['order_amount_to_pay_now']) ) ? $cart_content['order_amount_to_pay_now'] : 0;
206
+				$order_total_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0;
207
+				$shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? $cart_content['order_shipping_cost'] : 0;
208
+				$total_ati = $total_cart = (!empty($cart_content['order_amount_to_pay_now'])) ? $cart_content['order_amount_to_pay_now'] : 0;
209 209
 
210 210
 				ob_start();
211
-				if( !empty($type) && $type == 'fixed' ) {
212
-					require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content") );
211
+				if (!empty($type) && $type == 'fixed') {
212
+					require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content"));
213 213
 				}
214 214
 				else {
215
-					require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content") );
215
+					require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content"));
216 216
 				}
217 217
 				$output = ob_get_contents();
218 218
 				ob_end_clean();
219 219
 			}
220 220
 			else {
221
-				$output = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';
221
+				$output = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>';
222 222
 			}
223 223
 		}
224 224
 		else {
225
-			$output = '<div class="wps-alert-info">' . __( 'Your cart is empty', 'wpshop' ).'</div>';
225
+			$output = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>';
226 226
 		}
227 227
 		return $output;
228 228
 	}
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	function display_resume_cart() {
232 232
 		$cart_summary_content = self::resume_cart_content();
233 233
 		ob_start();
234
-		require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart") );
234
+		require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart"));
235 235
 		$output = ob_get_contents();
236 236
 		ob_end_clean();
237 237
 		return $output;
@@ -240,29 +240,29 @@  discard block
 block discarded – undo
240 240
 	/** Resume cart Content **/
241 241
 	public static function resume_cart_content() {
242 242
 		$output = '';
243
-		$currency = wpshop_tools::wpshop_get_currency( false );
244
-		$cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array();
245
-		if ( !empty($cart_content) ) {
246
-			$cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array();
247
-			if ( !empty($cart_items) ) {
248
-				if ( !empty($cart_content['coupon_id']) ) {
249
-					$coupon_title = get_the_title( $cart_content['coupon_id']);
250
-					$coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] );
243
+		$currency = wpshop_tools::wpshop_get_currency(false);
244
+		$cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array();
245
+		if (!empty($cart_content)) {
246
+			$cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array();
247
+			if (!empty($cart_items)) {
248
+				if (!empty($cart_content['coupon_id'])) {
249
+					$coupon_title = get_the_title($cart_content['coupon_id']);
250
+					$coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']);
251 251
 				}
252
-				$order_total_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0;
253
-				$shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? $cart_content['order_shipping_cost'] : 0;
254
-				$total_ati  = $total_cart = ( !empty($cart_content['order_amount_to_pay_now']) ) ? $cart_content['order_amount_to_pay_now'] : 0;
252
+				$order_total_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0;
253
+				$shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? $cart_content['order_shipping_cost'] : 0;
254
+				$total_ati = $total_cart = (!empty($cart_content['order_amount_to_pay_now'])) ? $cart_content['order_amount_to_pay_now'] : 0;
255 255
 				ob_start();
256
-				require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content") );
256
+				require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content"));
257 257
 				$output = ob_get_contents();
258 258
 				ob_end_clean();
259 259
 			}
260 260
 			else {
261
-				$resume_cart_body = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';
261
+				$resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>';
262 262
 			}
263 263
 		}
264 264
 		else {
265
-			$resume_cart_body ='<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';
265
+			$resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>';
266 266
 		}
267 267
 		return $output;
268 268
 	}
@@ -272,10 +272,10 @@  discard block
 block discarded – undo
272 272
 	 * @param array cart
273 273
 	 * @return int total items
274 274
 	 */
275
-	public static function total_cart_items( $cart_items ) {
275
+	public static function total_cart_items($cart_items) {
276 276
 		$count = 0;
277
-		if( !empty($cart_items) && is_array( $cart_items )) {
278
-			foreach( $cart_items as $cart_item ) {
277
+		if (!empty($cart_items) && is_array($cart_items)) {
278
+			foreach ($cart_items as $cart_item) {
279 279
 				$count += $cart_item['item_qty'];
280 280
 			}
281 281
 		}
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * Reload Persistent cart for logged user and if a persistent cart exists
287 287
 	 */
288 288
 	function load_cart_from_db() {
289
-		if(empty($_SESSION['cart']) && get_current_user_id() ) {
289
+		if (empty($_SESSION['cart']) && get_current_user_id()) {
290 290
 			$cart = $this->get_persistent_cart();
291 291
 			$_SESSION['cart'] = $cart;
292 292
 			$_SESSION['coupon'] = 0;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	 * @return array()
299 299
 	 */
300 300
 	function get_persistent_cart() {
301
-		if(get_current_user_id())
301
+		if (get_current_user_id())
302 302
 			$cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true);
303 303
 		return empty($cart) ? array() : $cart;
304 304
 	}
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 	 * Save the persistent cart when updated
315 315
 	 */
316 316
 	function persistent_cart_update() {
317
-		if(get_current_user_id())
318
-			update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array(
317
+		if (get_current_user_id())
318
+			update_user_meta(get_current_user_id(), '_wpshop_persistent_cart', array(
319 319
 					'cart' => $_SESSION['cart'],
320 320
 			));
321 321
 	}
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	 * Delete the persistent cart
325 325
 	 */
326 326
 	function persistent_cart_destroy() {
327
-		delete_user_meta( get_current_user_id(), '_wpshop_persistent_cart' );
327
+		delete_user_meta(get_current_user_id(), '_wpshop_persistent_cart');
328 328
 	}
329 329
 
330 330
 	/**
@@ -344,60 +344,60 @@  discard block
 block discarded – undo
344 344
 	 *
345 345
 	 * @return mixed If an error occured return a alert message. In the other case if the quantity is correctly set return true
346 346
 	 */
347
-	function set_product_qty($product_id, $quantity, $combined_variation_id = '', $cart = array(), $from_admin = '', $order_id = '' ) {
347
+	function set_product_qty($product_id, $quantity, $combined_variation_id = '', $cart = array(), $from_admin = '', $order_id = '') {
348 348
 		// Init Cart var
349
-		$cart = ( !empty($cart) ) ? $cart : $_SESSION['cart'];
350
-		$wpshop_cart_type = ( !empty($cart) && !empty($cart['cart_type']) ) ? $cart['cart_type'] : 'normal';
349
+		$cart = (!empty($cart)) ? $cart : $_SESSION['cart'];
350
+		$wpshop_cart_type = (!empty($cart) && !empty($cart['cart_type'])) ? $cart['cart_type'] : 'normal';
351 351
 		$parent_product_id = $product_id;
352 352
 		$selected_variations = array();
353 353
 
354 354
 		// Test if Product exists
355
-		if( !empty($product_id) && !empty($cart['order_items']) && !empty( $cart['order_items'][ $product_id ] ) ) {
355
+		if (!empty($product_id) && !empty($cart['order_items']) && !empty($cart['order_items'][$product_id])) {
356 356
 			// Test if is composed product ID
357 357
 			$pid = $product_id;
358
-			if (strpos($pid,'__') !== false) {
359
-				$product_data_id = explode( '__', $pid );
360
-				$pid = ( !empty( $product_data_id ) && !empty( $product_data_id[1] ) ) ? $product_data_id[1] : $cart['order_items'][ $product_id ]['item_id'];
358
+			if (strpos($pid, '__') !== false) {
359
+				$product_data_id = explode('__', $pid);
360
+				$pid = (!empty($product_data_id) && !empty($product_data_id[1])) ? $product_data_id[1] : $cart['order_items'][$product_id]['item_id'];
361 361
 			}
362 362
 
363 363
 			// Checking stock
364 364
 			$wps_product_ctr = new wps_product_ctr();
365
-			$return = $wps_product_ctr->check_stock($pid, $quantity, $combined_variation_id );
366
-			if( $return !== true) {
365
+			$return = $wps_product_ctr->check_stock($pid, $quantity, $combined_variation_id);
366
+			if ($return !== true) {
367 367
 				return $return;
368 368
 			}
369 369
 
370 370
 			// Check Variations to construct product to add to cart
371
-			if( !empty($product_data_id) || get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
371
+			if (!empty($product_data_id) || get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
372 372
 				// Check Parent ID
373
-				if( get_post_type($cart['order_items'][ $product_id ]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
374
-					$parent_product_id = $cart['order_items'][ $product_id ]['item_id'];
373
+				if (get_post_type($cart['order_items'][$product_id]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
374
+					$parent_product_id = $cart['order_items'][$product_id]['item_id'];
375 375
 				}
376 376
 				else {
377
-					$parent_data = wpshop_products::get_parent_variation( $cart['order_items'][ $product_id ]['item_id'] );
377
+					$parent_data = wpshop_products::get_parent_variation($cart['order_items'][$product_id]['item_id']);
378 378
 					$parent_post = $parent_data['parent_post'];
379 379
 					$parent_product_id = $parent_post->ID;
380 380
 				}
381
-				if( !empty($product_data_id) ) {
382
-					unset( $product_data_id[0] );
383
-					if( !empty($product_data_id) ) {
384
-						foreach( $product_data_id as $i ) {
385
-							$mtdt = get_post_meta( $i, '_wpshop_variations_attribute_def', true );
386
-							if( !empty($mtdt) && is_array($mtdt) ) {
387
-								$selected_variations = array_merge( $selected_variations, $mtdt );
381
+				if (!empty($product_data_id)) {
382
+					unset($product_data_id[0]);
383
+					if (!empty($product_data_id)) {
384
+						foreach ($product_data_id as $i) {
385
+							$mtdt = get_post_meta($i, '_wpshop_variations_attribute_def', true);
386
+							if (!empty($mtdt) && is_array($mtdt)) {
387
+								$selected_variations = array_merge($selected_variations, $mtdt);
388 388
 							}
389 389
 						}
390 390
 					}
391 391
 				}
392 392
 				else {
393
-					$selected_variations = get_post_meta( $product_id, '_wpshop_variations_attribute_def', true );
393
+					$selected_variations = get_post_meta($product_id, '_wpshop_variations_attribute_def', true);
394 394
 				}
395 395
 			}
396 396
 
397
-			$formatted_product = $this->prepare_product_to_add_to_cart( $parent_product_id, $quantity, $selected_variations );
397
+			$formatted_product = $this->prepare_product_to_add_to_cart($parent_product_id, $quantity, $selected_variations);
398 398
 			$product_to_add_to_cart = $formatted_product[0];
399 399
 			$new_pid = $product_id;
400
-			$return = $this->add_to_cart( $product_to_add_to_cart, array( $new_pid => $quantity ), $wpshop_cart_type, array(), $from_admin, $cart, $order_id );
400
+			$return = $this->add_to_cart($product_to_add_to_cart, array($new_pid => $quantity), $wpshop_cart_type, array(), $from_admin, $cart, $order_id);
401 401
 			return $return;
402 402
 		}
403 403
 		else {
@@ -410,11 +410,11 @@  discard block
 block discarded – undo
410 410
 	 * @param   string	product_id	contains the id of the product to add to the cart
411 411
 	 * @param   string	quantity	contains the quantity of the item to add
412 412
 	 */
413
-	function add_to_cart( $product_list, $quantity, $type='normal', $extra_params=array(), $from_admin = '', $order_meta = '', $order_id = '' ) {
413
+	function add_to_cart($product_list, $quantity, $type = 'normal', $extra_params = array(), $from_admin = '', $order_meta = '', $order_id = '') {
414 414
 		global $wpdb;
415 415
 		/** Check if a cart already exist. If there is already a cart that is not the same type (could be a cart or a quotation)	*/
416
-		if ( empty( $from_admin ) ){
417
-			if(isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type'] ) {
416
+		if (empty($from_admin)) {
417
+			if (isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type']) {
418 418
 				return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop');
419 419
 			}
420 420
 			else {
@@ -427,19 +427,19 @@  discard block
 block discarded – undo
427 427
 		$order_items = array();
428 428
 
429 429
 		foreach ($product_list as $pid => $product_more_content) {
430
-			if ( count($product_list) == 1 ) {
431
-				if ( !isset( $quantity[$pid] ) ) $quantity[$pid] = 1;
430
+			if (count($product_list) == 1) {
431
+				if (!isset($quantity[$pid])) $quantity[$pid] = 1;
432 432
 				$product = wpshop_products::get_product_data($product_more_content['id'], false, '"publish", "free_product"');
433 433
 				/** Check if the selected product exist	*/
434
-				if ( $product === false ) return __('This product does not exist', 'wpshop');
434
+				if ($product === false) return __('This product does not exist', 'wpshop');
435 435
 
436 436
 				/** Get information about the product price	*/
437 437
 				$product_price_check = wpshop_prices::get_product_price($product, 'check_only');
438
-				if ( $product_price_check !== true ) return $product_price_check;
438
+				if ($product_price_check !== true) return $product_price_check;
439 439
 
440 440
 				$the_quantity = 1;
441 441
 
442
-				if ( !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) ) {
442
+				if (!empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0])) {
443 443
 					/** Get the asked quantity for each product and check if there is enough stock	*/
444 444
 					$the_quantity = $quantity[$pid];
445 445
 				}
@@ -451,14 +451,14 @@  discard block
 block discarded – undo
451 451
 				//$quantity[$pid] = $the_quantity;
452 452
 
453 453
 				$variation_id = 0;
454
-				if ( !empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' ){
454
+				if (!empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined') {
455 455
 					$variation_id = $product_more_content['variations'][0];
456 456
 				}
457 457
 				//$quantity_to_check = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($_SESSION['cart']['order_items'][$pid]) && !empty($_SESSION['cart']['order_items'][$pid]['item_qty'])  ) ? $_SESSION['cart']['order_items'][$pid]['item_qty'] : $the_quantity;
458 458
 
459 459
 				$wps_product_ctr = new wps_product_ctr();
460
-				$product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id );
461
-				if ( $product_stock !== true ) {
460
+				$product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id);
461
+				if ($product_stock !== true) {
462 462
 					return $product_stock;
463 463
 				}
464 464
 			}
@@ -467,99 +467,99 @@  discard block
 block discarded – undo
467 467
 			$order_items[$pid]['product_qty'] = $the_quantity;
468 468
 
469 469
 			/** For product with variation	*/
470
-			$order_items[$pid]['product_variation_type'] = !empty( $product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
470
+			$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
471 471
 			$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
472 472
 			$order_items[$pid]['product_variation'] = '';
473
-			if ( !empty($product_more_content['variations']) ) {
474
-				foreach ( $product_more_content['variations'] as $variation_id) {
473
+			if (!empty($product_more_content['variations'])) {
474
+				foreach ($product_more_content['variations'] as $variation_id) {
475 475
 					$order_items[$pid]['product_variation'][] = $variation_id;
476 476
 				}
477 477
 			}
478 478
 		}
479 479
 
480
-		$current_cart = ( !empty( $order_meta )) ? $order_meta : array();
481
-		$order = $this->calcul_cart_information($order_items, $extra_params, $current_cart );
480
+		$current_cart = (!empty($order_meta)) ? $order_meta : array();
481
+		$order = $this->calcul_cart_information($order_items, $extra_params, $current_cart);
482 482
 
483
-		if( empty($from_admin) ) {
483
+		if (empty($from_admin)) {
484 484
 			self::store_cart_in_session($order);
485 485
 			/** Store the cart into database for connected user */
486
-			if ( get_current_user_id() ) {
486
+			if (get_current_user_id()) {
487 487
 				$this->persistent_cart_update();
488 488
 			}
489 489
 		}
490 490
 		else {
491
-			update_post_meta($order_id, '_order_postmeta', $order );
491
+			update_post_meta($order_id, '_order_postmeta', $order);
492 492
 
493 493
 		}
494 494
 		return 'success';
495 495
 	}
496 496
 
497
-	function prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected = array() ) {
497
+	function prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected = array()) {
498 498
 		$product_price = '';
499 499
 		$product_data = wpshop_products::get_product_data($product_id);
500 500
 
501 501
 		// Free vars
502
-		if ( !empty($wpshop_variation_selected['free']) ){
502
+		if (!empty($wpshop_variation_selected['free'])) {
503 503
 			$free_variations = $wpshop_variation_selected['free'];
504 504
 			unset($wpshop_variation_selected['free']);
505 505
 		}
506 506
 
507 507
 		// If product have many variations
508
-		if ( count($wpshop_variation_selected ) > 1 ) {
509
-			if ( !empty($wpshop_variation_selected) ) {
510
-				$product_with_variation = wpshop_products::get_variation_by_priority( $wpshop_variation_selected, $product_id, true );
508
+		if (count($wpshop_variation_selected) > 1) {
509
+			if (!empty($wpshop_variation_selected)) {
510
+				$product_with_variation = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true);
511 511
 			}
512 512
 
513
-			if ( !empty($product_with_variation[$product_id]['variations']) ) {
513
+			if (!empty($product_with_variation[$product_id]['variations'])) {
514 514
 				$product = $product_data;
515 515
 				$has_variation = true;
516 516
 				$head_product_id = $product_id;
517 517
 
518
-				if ( !empty($product_with_variation[$product_id]['variations']) && ( count($product_with_variation[$product_id]['variations']) == 1 ) && ($product_with_variation[$product_id]['variation_priority'] != 'single') ) {
518
+				if (!empty($product_with_variation[$product_id]['variations']) && (count($product_with_variation[$product_id]['variations']) == 1) && ($product_with_variation[$product_id]['variation_priority'] != 'single')) {
519 519
 					$product_id = $product_with_variation[$product_id]['variations'][0];
520 520
 				}
521 521
 				$product = wpshop_products::get_product_data($product_id, true);
522 522
 
523
-				$the_product = array_merge( array(
523
+				$the_product = array_merge(array(
524 524
 						'product_id'	=> $product_id,
525 525
 						'product_qty' 	=> $product_qty
526 526
 				), $product);
527 527
 
528 528
 				/*	Add variation to product into cart for storage	*/
529
-				if ( !empty($product_with_variation[$head_product_id]['variations']) ) {
530
-					$the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority']) );
529
+				if (!empty($product_with_variation[$head_product_id]['variations'])) {
530
+					$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority']));
531 531
 				}
532 532
 
533 533
 				$product_data = $the_product;
534 534
 			}
535 535
 		}
536 536
 
537
-		$product_to_add_to_cart = array( $product_id => array( 'id' => $product_id, 'product_qty' => $product_qty ) );
537
+		$product_to_add_to_cart = array($product_id => array('id' => $product_id, 'product_qty' => $product_qty));
538 538
 
539
-		if ( !empty( $wpshop_variation_selected ) ) {
540
-			$variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true );
541
-			if ( !empty($variation_calculator[$product_id]) ) {
539
+		if (!empty($wpshop_variation_selected)) {
540
+			$variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true);
541
+			if (!empty($variation_calculator[$product_id])) {
542 542
 				$product_to_add_to_cart[$product_id] = array_merge($product_to_add_to_cart[$product_id], $variation_calculator[$product_id]);
543 543
 			}
544 544
 		}
545 545
 
546 546
 		$new_pid = $product_id;
547 547
 		//Create custom ID on single variations Product
548
-		if( !empty($product_to_add_to_cart[$product_id]['variations']) && count( $product_to_add_to_cart[$product_id]['variations'] ) && !empty( $product_to_add_to_cart[$product_id]['variation_priority'] ) && $product_to_add_to_cart[$product_id]['variation_priority'] == 'single' ) {
548
+		if (!empty($product_to_add_to_cart[$product_id]['variations']) && count($product_to_add_to_cart[$product_id]['variations']) && !empty($product_to_add_to_cart[$product_id]['variation_priority']) && $product_to_add_to_cart[$product_id]['variation_priority'] == 'single') {
549 549
 			$tmp_obj = $product_to_add_to_cart[$product_id];
550
-			unset( $product_to_add_to_cart[$product_id] );
550
+			unset($product_to_add_to_cart[$product_id]);
551 551
 			$key = $product_id;
552
-			foreach( $tmp_obj['variations'] as $variation_key) {
553
-				$key.= '__'. $variation_key;
552
+			foreach ($tmp_obj['variations'] as $variation_key) {
553
+				$key .= '__' . $variation_key;
554 554
 			}
555 555
 			$product_to_add_to_cart[$key] = $tmp_obj;
556 556
 			$new_pid = $key;
557 557
 		}
558 558
 		// Add free variations
559
-		if( !empty($free_variations) ) {
559
+		if (!empty($free_variations)) {
560 560
 			$product_to_add_to_cart[$new_pid]['free_variation'] = $free_variations;
561 561
 		}
562
-		return array( $product_to_add_to_cart, $new_pid );
562
+		return array($product_to_add_to_cart, $new_pid);
563 563
 	}
564 564
 
565 565
 	/**
@@ -570,67 +570,67 @@  discard block
 block discarded – undo
570 570
 	 * @param boolean $from_admin
571 571
 	 * @return array
572 572
 	 */
573
-	function calcul_cart_information( $product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false ) {
573
+	function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) {
574 574
 		// Price piloting option
575
-		$price_piloting = get_option( 'wpshop_shop_price_piloting' );
575
+		$price_piloting = get_option('wpshop_shop_price_piloting');
576 576
 
577 577
 		// Init vars
578
-		$cart_infos = ( !empty($current_cart) ) ? $current_cart : ( ( !empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ) ? $_SESSION['cart'] : array() );
579
-		$cart_items = ( !empty($current_cart) && !empty($current_cart['order_items']) ) ? $current_cart['order_items'] : array();
580
-		$cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ) ? $_SESSION['cart']['order_items'] : $cart_items;
578
+		$cart_infos = (!empty($current_cart)) ? $current_cart : ((!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin) ? $_SESSION['cart'] : array());
579
+		$cart_items = (!empty($current_cart) && !empty($current_cart['order_items'])) ? $current_cart['order_items'] : array();
580
+		$cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin) ? $_SESSION['cart']['order_items'] : $cart_items;
581 581
 		$order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array();
582 582
 		$total_weight = $nb_of_items = $order_shipping_cost_by_article = 0;
583 583
 		$order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0;
584 584
 		$cart_infos['order_amount_to_pay_now'] = 0;
585 585
 
586 586
 		// If Product list is not empty, add products to order
587
-		if( !empty($product_list) ) {
588
-			foreach ( $product_list as $product_id => $d ) {
587
+		if (!empty($product_list)) {
588
+			foreach ($product_list as $product_id => $d) {
589 589
 				$product_key = $product_id;
590
-				if( isset( $d['product_qty']) ) {
590
+				if (isset($d['product_qty'])) {
591 591
 					// Formate datas
592 592
 					$product_id = $head_product_id = $d['product_id'];
593 593
 					$product_qty = $d['product_qty'];
594 594
 					$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
595 595
 
596 596
 					// If product is a single variation product
597
-					if ( !empty($product_variation) && ( count($product_variation) == 1 ) ) {
597
+					if (!empty($product_variation) && (count($product_variation) == 1)) {
598 598
 						$product_id = $product_variation[0];
599 599
 					}
600 600
 
601 601
 					// Construct final product
602 602
 					$product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"');
603
-					$the_product = array_merge( array('product_id'	=> $d['product_id'], 'product_qty' 	=> $product_qty ), $product);
603
+					$the_product = array_merge(array('product_id'	=> $d['product_id'], 'product_qty' 	=> $product_qty), $product);
604 604
 
605 605
 					//	Add variation to product into cart for storage
606
-					if ( !empty($product_variation) ) {
607
-						$the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']) );
606
+					if (!empty($product_variation)) {
607
+						$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
608 608
 					}
609 609
 
610 610
 					// Free Variations Checking
611
-					if ( !empty( $d['free_variation'] ) ) {
611
+					if (!empty($d['free_variation'])) {
612 612
 						$the_product['item_meta']['free_variation'] = $d['free_variation'];
613 613
 						$head_product_id = $the_product['product_id'];
614 614
 					}
615 615
 
616 616
 					// If product is a variation, we check parent product general
617
-					if( get_post_type( $the_product['product_id'] )  == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
618
-						$parent_def = wpshop_products::get_parent_variation( $the_product['product_id'] );
619
-						if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
620
-							$variation_def = get_post_meta( $parent_def['parent_post']->ID, '_wpshop_variation_defining', true );
617
+					if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
618
+						$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
619
+						if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
620
+							$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
621 621
 							$parent_meta = $parent_def['parent_post_meta'];
622
-							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 ) {
623
-								$the_product['product_price'] += number_format( str_replace( ',', '.', $parent_meta['product_price'] ), 2, '.', '' );
624
-								$the_product['price_ht'] += number_format( str_replace( ',', '.',$parent_meta['price_ht']) , 2, '.', '' );
625
-								$the_product['tva'] += number_format( str_replace( ',', '.', $parent_meta['tva']) , 2, '.', '' );
622
+							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) {
623
+								$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
624
+								$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
625
+								$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
626 626
 							}
627 627
 						}
628 628
 					}
629 629
 
630 630
 					// Delete product if its qty is equals to zero, else add this product to order
631
-					if( empty( $d['product_qty'] ) ) {
632
-						unset( $cart_items[$product_key] );
633
-						unset( $cart_infos['order_items'][$product_key] );
631
+					if (empty($d['product_qty'])) {
632
+						unset($cart_items[$product_key]);
633
+						unset($cart_infos['order_items'][$product_key]);
634 634
 					}
635 635
 					else {
636 636
 						$wps_orders = new wps_orders_ctr();
@@ -641,16 +641,16 @@  discard block
 block discarded – undo
641 641
 		}
642 642
 
643 643
 		// Add automaticaly Add-to-cart Products
644
-		$cart_items = $this->add_automaticaly_product_to_cart( $cart_items );
644
+		$cart_items = $this->add_automaticaly_product_to_cart($cart_items);
645 645
 
646 646
 		// Calcul Cart Informations
647 647
 		$cart_has_special_product = false;
648
-		if( !empty($cart_items) && is_array($cart_items) ) {
649
-			foreach( $cart_items as $item_id => $item ) {
648
+		if (!empty($cart_items) && is_array($cart_items)) {
649
+			foreach ($cart_items as $item_id => $item) {
650 650
 
651
-				if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) {
651
+				if (!empty($item['item_amount_to_pay_now'])) {
652 652
 					$cart_has_special_product = true;
653
-					$cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] );
653
+					$cart_infos['order_amount_to_pay_now'] += ($item['item_amount_to_pay_now'] * $item['item_qty']);
654 654
 				}
655 655
 				else {
656 656
 					$cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc'];
@@ -659,11 +659,11 @@  discard block
 block discarded – undo
659 659
 				$order_total_ht += $item['item_total_ht'];
660 660
 				$order_total_ttc += $item['item_total_ttc'];
661 661
 				// VAT
662
-				if( !empty($order_tva[ $item['item_tva_rate'] ]) ) {
663
-					$order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount'];
662
+				if (!empty($order_tva[$item['item_tva_rate']])) {
663
+					$order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount'];
664 664
 				}
665 665
 				else {
666
-					$order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount'];
666
+					$order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount'];
667 667
 				}
668 668
 			}
669 669
 		}
@@ -677,13 +677,13 @@  discard block
 block discarded – undo
677 677
 		$cart_infos['order_total_ttc'] = $order_total_ttc;
678 678
 
679 679
 		// Calcul Shipping cost
680
-		if( !$from_admin && empty( $cart_infos['order_shipping_cost_fixe'] ) && empty($_SESSION[ 'wps-pos-addon' ]) ) {
680
+		if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe']) && empty($_SESSION['wps-pos-addon'])) {
681 681
 			$wps_shipping = new wps_shipping();
682
-			$total_cart_ht_or_ttc_regarding_config = ( !empty($price_piloting) && $price_piloting == 'HT' ) ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc'];
683
-			$cart_weight = $wps_shipping->calcul_cart_weight( $cart_infos['order_items'] );
684
-			$total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost( $cart_infos['order_items'] );
685
-			foreach( $cart_infos['order_items'] as $item ) {
686
-				if( !empty($item['item_is_downloadable_']) && ( __( $item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) {
682
+			$total_cart_ht_or_ttc_regarding_config = (!empty($price_piloting) && $price_piloting == 'HT') ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc'];
683
+			$cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']);
684
+			$total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']);
685
+			foreach ($cart_infos['order_items'] as $item) {
686
+				if (!empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) {
687 687
 					$is_downloadable_products = 'is_downloadable_';
688 688
 				} else {
689 689
 					$is_downloadable_products = '';
@@ -695,39 +695,39 @@  discard block
 block discarded – undo
695 695
 		}
696 696
 
697 697
 		// If Price piloting is ET, calcul VAT on Shipping cost
698
-		if ( !empty($price_piloting) && $price_piloting == 'HT') {
699
-			$shipping_cost_vat = ( !empty($cart_infos['order_shipping_cost']) ) ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * number_format(  $cart_infos['order_shipping_cost'], 2, '.', '') : 0;
698
+		if (!empty($price_piloting) && $price_piloting == 'HT') {
699
+			$shipping_cost_vat = (!empty($cart_infos['order_shipping_cost'])) ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0;
700 700
 			$order_tva['VAT_shipping_cost'] = $shipping_cost_vat;
701 701
 		}
702 702
 
703 703
 		// Calcul VAT Total
704
-		if( !empty($order_tva) ) {
705
-			foreach( $order_tva as $vat_rate => $vat_value ) {
704
+		if (!empty($order_tva)) {
705
+			foreach ($order_tva as $vat_rate => $vat_value) {
706 706
 				$total_vat += $vat_value;
707 707
 			}
708 708
 		}
709 709
 
710 710
 		// Recap totals
711
-		$cart_infos['order_total_ttc'] = ( $cart_infos['order_total_ht'] + ( !empty( $cart_infos ) && !empty( $cart_infos[ 'order_shipping_cost' ] )  ? $cart_infos['order_shipping_cost'] : 0 )  + $total_vat );
711
+		$cart_infos['order_total_ttc'] = ($cart_infos['order_total_ht'] + (!empty($cart_infos) && !empty($cart_infos['order_shipping_cost']) ? $cart_infos['order_shipping_cost'] : 0) + $total_vat);
712 712
 		$cart_infos['order_grand_total_before_discount'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc'];
713 713
 
714 714
 		// Total to pay now
715 715
 		$total_received = 0;
716
-		if( !empty( $cart_infos['order_payment']['received'] ) ) {
717
-			foreach( $cart_infos['order_payment']['received'] as $received ) {
718
-				$total_received += ( ( !empty($received['status']) && ( $received['status'] == 'payment_received') && !empty($received['received_amount']) ) ? $received['received_amount'] : 0 );
716
+		if (!empty($cart_infos['order_payment']['received'])) {
717
+			foreach ($cart_infos['order_payment']['received'] as $received) {
718
+				$total_received += ((!empty($received['status']) && ($received['status'] == 'payment_received') && !empty($received['received_amount'])) ? $received['received_amount'] : 0);
719 719
 			}
720 720
 		}
721 721
 		$cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] - $total_received;
722 722
 
723 723
 		// Apply cart rules
724
-		$cart_rule = wpshop_cart_rules::get_cart_rule( $cart_infos['order_grand_total'] );
725
-		if( $cart_rule['cart_rule_exist'] ) {
726
-			if ( !empty( $cart_rule['cart_rule_info']['discount_type'] ) ) {
727
-				if ( $cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount' ) {
724
+		$cart_rule = wpshop_cart_rules::get_cart_rule($cart_infos['order_grand_total']);
725
+		if ($cart_rule['cart_rule_exist']) {
726
+			if (!empty($cart_rule['cart_rule_info']['discount_type'])) {
727
+				if ($cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount') {
728 728
 					$cart_infos['order_discount_type'] = 'amount';
729 729
 				}
730
-				if ( $cart_rule['cart_rule_info']['discount_type'] == 'percent_discount' ) {
730
+				if ($cart_rule['cart_rule_info']['discount_type'] == 'percent_discount') {
731 731
 					$cart_infos['order_discount_type'] = 'percent';
732 732
 				}
733 733
 			}
@@ -735,15 +735,15 @@  discard block
 block discarded – undo
735 735
 		}
736 736
 
737 737
 		// Apply coupons
738
-		if( !empty( $_SESSION['cart']) && !$from_admin ) {
739
-			if( !empty($_SESSION['cart']['coupon_id']) ) {
738
+		if (!empty($_SESSION['cart']) && !$from_admin) {
739
+			if (!empty($_SESSION['cart']['coupon_id'])) {
740 740
 				$wps_coupon_mdl = new wps_coupon_model();
741
-				$coupon = $wps_coupon_mdl->get_coupon_data( $_SESSION['cart']['coupon_id'] );
742
-				if( !empty($coupon) && !empty($coupon['wpshop_coupon_code']) ) {
741
+				$coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']);
742
+				if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) {
743 743
 					$wps_coupon = new wps_coupon_ctr();
744
-					$coupon_checking = $wps_coupon->applyCoupon( $coupon['wpshop_coupon_code'] );
744
+					$coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']);
745 745
 					// If Coupon conditions are Ok
746
-					if( !empty($coupon_checking) && !empty( $coupon_checking['status'] ) && ( true == $coupon_checking['status'] ) ) {
746
+					if (!empty($coupon_checking) && !empty($coupon_checking['status']) && (true == $coupon_checking['status'])) {
747 747
 						$cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type'];
748 748
 						$cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value'];
749 749
 					}
@@ -752,51 +752,51 @@  discard block
 block discarded – undo
752 752
 		}
753 753
 
754 754
 		// Checking Discounts
755
-		if( !empty($cart_infos['order_discount_type']) && isset( $cart_infos['order_discount_value'] ) ) {
755
+		if (!empty($cart_infos['order_discount_type']) && isset($cart_infos['order_discount_value'])) {
756 756
 			// Calcul discount on Order
757 757
 			switch ($cart_infos['order_discount_type']) {
758 758
 				case 'amount':
759
-					$cart_infos['order_discount_amount_total_cart'] = number_format( str_replace( ',', '.', $cart_infos['order_discount_value'] ), 2, '.', '');
759
+					$cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '');
760 760
 				break;
761 761
 				case 'percent':
762
-					$cart_infos['order_discount_amount_total_cart'] = number_format( $cart_infos['order_grand_total'], 2, '.', '') * ( number_format( str_replace( ',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100);
762
+					$cart_infos['order_discount_amount_total_cart'] = number_format($cart_infos['order_grand_total'], 2, '.', '') * (number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100);
763 763
 				break;
764 764
 			}
765
-			if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) {
765
+			if (number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format($cart_infos['order_grand_total'], 2, '.', '')) {
766 766
 				$cart_infos['order_grand_total'] = 0;
767 767
 			}
768 768
 			else {
769
-				$cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '');
769
+				$cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '');
770 770
 			}
771
-			$cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', '');
771
+			$cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'] - $total_received, 2, '.', '');
772 772
 		}
773 773
 
774 774
 		// Apply Partial Payments
775 775
 		$wpshop_payment = new wpshop_payment();
776
-		if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) {
777
-			$partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' );
776
+		if (!empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation') {
777
+			$partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total'], 'for_quotation');
778 778
 		}
779 779
 		else {
780
-			$partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] );
780
+			$partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']);
781 781
 		}
782
-		if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) {
782
+		if (!empty($partial_payment['amount_to_pay']) && (empty($cart_infos['order_status']) || $cart_infos['order_status'] == 'awaiting_payment') && (empty($product_partial_payment_amount))) {
783 783
 			unset($partial_payment['display']);
784
-			$cart_infos['order_partial_payment'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', '');
785
-			$cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', '');
784
+			$cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', '');
785
+			$cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', '');
786 786
 		}
787 787
 		// Apply Partial Payments : Subscription part.
788
-		elseif ( ! empty( $cart_has_special_product ) ) {
789
-			$cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $cart_infos['order_amount_to_pay_now'] ), 2, '.', '');
788
+		elseif (!empty($cart_has_special_product)) {
789
+			$cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $cart_infos['order_amount_to_pay_now']), 2, '.', '');
790 790
 			$cart_infos['order_product_partial_payment'] = 'subscription';
791 791
 		}
792 792
 
793 793
 		// Cart Type
794
-		if ( isset( $_SESSION['cart']['cart_type'] ) ) {
794
+		if (isset($_SESSION['cart']['cart_type'])) {
795 795
 			$cart_infos['cart_type'] = $_SESSION['cart']['cart_type'];
796 796
 		}
797 797
 
798 798
 		// Apply Extra actions on cart infos
799
-		$cart_infos = apply_filters( 'wps_extra_calcul_in_cart', $cart_infos, $_SESSION );
799
+		$cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION);
800 800
 
801 801
 		return $cart_infos;
802 802
 	}
@@ -806,18 +806,18 @@  discard block
 block discarded – undo
806 806
 	 * @param array $cart_items
807 807
 	 * @return array
808 808
 	 */
809
-	function add_automaticaly_product_to_cart( $cart_items ) {
809
+	function add_automaticaly_product_to_cart($cart_items) {
810 810
 		global $wpdb;
811 811
 		// Recovery all products with options
812 812
 		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
813 813
 		$post_list_with_options = $wpdb->get_results($query);
814 814
 		$wps_orders = new wps_orders_ctr();
815
-		if ( !empty($post_list_with_options) && !empty($cart_items) ) {
816
-			foreach ( $post_list_with_options as $product_info) {
815
+		if (!empty($post_list_with_options) && !empty($cart_items)) {
816
+			foreach ($post_list_with_options as $product_info) {
817 817
 				$product_meta = unserialize($product_info->meta_value);
818
-				if ( !empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id]) ) {
818
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id])) {
819 819
 					$product = wpshop_products::get_product_data($product_info->post_id, true, '"draft", "publish"');
820
-					$the_product = array_merge( array(
820
+					$the_product = array_merge(array(
821 821
 							'product_id'	=> $product_info->post_id,
822 822
 							'product_qty' 	=> 1
823 823
 					), $product);
@@ -831,28 +831,28 @@  discard block
 block discarded – undo
831 831
 
832 832
 	/** Ajax action to reload cart **/
833 833
 	public static function wps_reload_cart() {
834
-		check_ajax_referer( 'wps_reload_cart' );
834
+		check_ajax_referer('wps_reload_cart');
835 835
 
836 836
 		$wps_cart = new wps_cart();
837 837
 		$result = $wps_cart->cart_content();
838 838
 
839
-		wp_die( json_encode( array( 'response' => $result) ) );
839
+		wp_die(json_encode(array('response' => $result)));
840 840
 	}
841 841
 
842 842
 
843 843
 	/** Ajax action to reload mini cart */
844 844
 	public function wps_reload_mini_cart() {
845
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
845
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
846 846
 
847
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) )
847
+		if (!wp_verify_nonce($_wpnonce, 'wps_reload_mini_cart'))
848 848
 			wp_die();
849 849
 
850 850
 		$wps_cart = new wps_cart();
851
-		$result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) );
852
-		$count_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])  ) ? $wps_cart->total_cart_items( $_SESSION['cart']['order_items'] ) : 0;
851
+		$result = $wps_cart->mini_cart_content(sanitize_title($_POST['type']));
852
+		$count_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0;
853 853
 		$free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert');
854 854
 
855
-		echo json_encode( array( 'response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert) );
855
+		echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert));
856 856
 		die();
857 857
 	}
858 858
 
@@ -862,35 +862,35 @@  discard block
 block discarded – undo
862 862
 	 * @return string
863 863
 	 */
864 864
 	function display_wps_numeration_cart() {
865
-		$cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $_SESSION['cart']['order_items'] : array();
866
-		$total_cart_item = self::total_cart_items( $cart_items );
865
+		$cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $_SESSION['cart']['order_items'] : array();
866
+		$total_cart_item = self::total_cart_items($cart_items);
867 867
 
868 868
 		ob_start();
869
-		require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart") );
869
+		require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart"));
870 870
 		$output = ob_get_contents();
871 871
 		ob_end_clean();
872 872
 		return $output;
873 873
 	}
874 874
 
875
-	public function display_button_add_to_cart( $args ) {
876
-		$button_text = __( 'Add to cart', 'wpshop' );
875
+	public function display_button_add_to_cart($args) {
876
+		$button_text = __('Add to cart', 'wpshop');
877 877
 		$use_button = true;
878
-		$output = __( 'No product has been found.', 'wpshop' );
878
+		$output = __('No product has been found.', 'wpshop');
879 879
 
880
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
880
+		if (!empty($args) && !empty($args['pid'])) {
881 881
 
882 882
 			/** The user send the text in argument */
883
-			if ( !empty( $args['text' ] ) ) {
883
+			if (!empty($args['text'])) {
884 884
 				$button_text = $args['text'];
885 885
 			}
886 886
 
887 887
 			/** The user send use input */
888
-			if ( !empty( $args['use_button'] ) && 'false' == $args['use_button'] ) {
888
+			if (!empty($args['use_button']) && 'false' == $args['use_button']) {
889 889
 				$use_button = false;
890 890
 			}
891 891
 
892 892
 			ob_start();
893
-			require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart' ) );
893
+			require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart'));
894 894
 			$output = ob_get_clean();
895 895
 		}
896 896
 
@@ -899,21 +899,21 @@  discard block
 block discarded – undo
899 899
 
900 900
 	/** Ajax action to reload summary cart */
901 901
 	public static function wps_reload_summary_cart() {
902
-		check_ajax_referer( 'wps_reload_summary_cart' );
902
+		check_ajax_referer('wps_reload_summary_cart');
903 903
 
904 904
 		$wps_cart = new wps_cart();
905 905
 		$result = $wps_cart->resume_cart_content();
906 906
 
907
-		wp_die( json_encode( array( 'response' => $result, ) ) );
907
+		wp_die(json_encode(array('response' => $result,)));
908 908
 	}
909 909
 
910 910
 
911 911
 	/** Display Apply Coupon Interface **/
912 912
 	function display_apply_coupon_interface() {
913 913
 		$output = '';
914
-		if ( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) {
914
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
915 915
 			ob_start();
916
-			require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon") );
916
+			require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon"));
917 917
 			$output = ob_get_contents();
918 918
 			ob_end_clean();
919 919
 		}
@@ -923,30 +923,30 @@  discard block
 block discarded – undo
923 923
 
924 924
 	/** AJAX - action to apply coupon **/
925 925
 	function wps_apply_coupon() {
926
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
926
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
927 927
 
928
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) )
928
+		if (!wp_verify_nonce($_wpnonce, 'wps_apply_coupon'))
929 929
 			wp_die();
930 930
 
931 931
 		$status = false; $response = '';
932
-		$coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null;
933
-		if( !empty($coupon) ) {
932
+		$coupon = (!empty($_POST['coupon_code'])) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null;
933
+		if (!empty($coupon)) {
934 934
 			$wps_coupon_ctr = new wps_coupon_ctr();
935 935
 			$result = $wps_coupon_ctr->applyCoupon($coupon);
936
-			if ($result['status']===true) {
936
+			if ($result['status'] === true) {
937 937
 				$order = $this->calcul_cart_information(array());
938 938
 				$this->store_cart_in_session($order);
939 939
 				$status = true;
940
-				$response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>';
940
+				$response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>';
941 941
 			}
942 942
 			else {
943
-				$response = '<div class="wps-alert-error">' .$result['message']. '</div>';
943
+				$response = '<div class="wps-alert-error">' . $result['message'] . '</div>';
944 944
 			}
945 945
 		}
946 946
 		else {
947
-			$response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>';
947
+			$response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>';
948 948
 		}
949
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
949
+		echo json_encode(array('status' => $status, 'response' => $response));
950 950
 		die();
951 951
 	}
952 952
 
@@ -955,24 +955,24 @@  discard block
 block discarded – undo
955 955
 	 * AJAX - Pass to step two in the Checkout tunnel
956 956
 	 */
957 957
 	public static function wps_cart_pass_to_step_two() {
958
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
958
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
959 959
 
960
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) )
960
+		if (!wp_verify_nonce($_wpnonce, 'wps_cart_pass_to_step_two'))
961 961
 			wp_die();
962 962
 
963 963
 		$status = false; $response = '';
964
-		$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) );
965
-		if( !empty($checkout_page_id) ) {
966
-			$permalink_option = get_option( 'permalink_structure' );
967
-			$step = ( get_current_user_id() != 0 ) ?  3 : 2;
968
-			$response = get_permalink( $checkout_page_id  ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step;
964
+		$checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'));
965
+		if (!empty($checkout_page_id)) {
966
+			$permalink_option = get_option('permalink_structure');
967
+			$step = (get_current_user_id() != 0) ? 3 : 2;
968
+			$response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step;
969 969
 			$response = apply_filters('wps_extra_signup_actions', $response);
970 970
 			$status = true;
971 971
 		}
972 972
 		else {
973
-			$response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>';
973
+			$response = '<div class="wps-alert-error">' . __('An error was occured, please retry later or contact the website administrator', 'wpshop') . '</div>';
974 974
 		}
975
-		echo json_encode( array( 'status' => $status, 'response' => $response));
975
+		echo json_encode(array('status' => $status, 'response' => $response));
976 976
 		die();
977 977
 	}
978 978
 
@@ -981,14 +981,14 @@  discard block
 block discarded – undo
981 981
 	 * AJAX - Empty the cart
982 982
 	 */
983 983
 	function wps_empty_cart() {
984
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
984
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
985 985
 
986
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) )
986
+		if (!wp_verify_nonce($_wpnonce, 'wps_empty_cart'))
987 987
 			wp_die();
988 988
 
989 989
 
990 990
 		$this->empty_cart();
991
-		echo json_encode( array( 'status' => true) );
991
+		echo json_encode(array('status' => true));
992 992
 		die();
993 993
 	}
994 994
 }
Please login to merge, or discard this patch.
Braces   +54 added lines, -64 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
 class wps_cart {
3 5
 
4 6
 	function __construct() {
@@ -151,12 +153,10 @@  discard block
 block discarded – undo
151 153
 				require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart") );
152 154
 				$output = ob_get_contents();
153 155
 				ob_end_clean();
154
-			}
155
-			else {
156
+			} else {
156 157
 				return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';;
157 158
 			}
158
-		}
159
-		else {
159
+		} else {
160 160
 			return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';;
161 161
 		}
162 162
 		return $output;
@@ -174,15 +174,13 @@  discard block
 block discarded – undo
174 174
 			/** Count items **/
175 175
 			$total_cart_item = self::total_cart_items( $cart_items );
176 176
 			$mini_cart_body = self::mini_cart_content( $type );
177
-		}
178
-		else {
177
+		} else {
179 178
 			$mini_cart_body = self::mini_cart_content();
180 179
 		}
181 180
 		ob_start();
182 181
 		if( !empty($type) && $type == 'fixed' ) {
183 182
 			require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart") );
184
-		}
185
-		else {
183
+		} else {
186 184
 			require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart") );
187 185
 		}
188 186
 
@@ -210,18 +208,15 @@  discard block
 block discarded – undo
210 208
 				ob_start();
211 209
 				if( !empty($type) && $type == 'fixed' ) {
212 210
 					require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content") );
213
-				}
214
-				else {
211
+				} else {
215 212
 					require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content") );
216 213
 				}
217 214
 				$output = ob_get_contents();
218 215
 				ob_end_clean();
219
-			}
220
-			else {
216
+			} else {
221 217
 				$output = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';
222 218
 			}
223
-		}
224
-		else {
219
+		} else {
225 220
 			$output = '<div class="wps-alert-info">' . __( 'Your cart is empty', 'wpshop' ).'</div>';
226 221
 		}
227 222
 		return $output;
@@ -256,12 +251,10 @@  discard block
 block discarded – undo
256 251
 				require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content") );
257 252
 				$output = ob_get_contents();
258 253
 				ob_end_clean();
259
-			}
260
-			else {
254
+			} else {
261 255
 				$resume_cart_body = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';
262 256
 			}
263
-		}
264
-		else {
257
+		} else {
265 258
 			$resume_cart_body ='<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';
266 259
 		}
267 260
 		return $output;
@@ -298,8 +291,9 @@  discard block
 block discarded – undo
298 291
 	 * @return array()
299 292
 	 */
300 293
 	function get_persistent_cart() {
301
-		if(get_current_user_id())
302
-			$cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true);
294
+		if(get_current_user_id()) {
295
+					$cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true);
296
+		}
303 297
 		return empty($cart) ? array() : $cart;
304 298
 	}
305 299
 
@@ -314,10 +308,11 @@  discard block
 block discarded – undo
314 308
 	 * Save the persistent cart when updated
315 309
 	 */
316 310
 	function persistent_cart_update() {
317
-		if(get_current_user_id())
318
-			update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array(
311
+		if(get_current_user_id()) {
312
+					update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array(
319 313
 					'cart' => $_SESSION['cart'],
320 314
 			));
315
+		}
321 316
 	}
322 317
 
323 318
 	/**
@@ -372,8 +367,7 @@  discard block
 block discarded – undo
372 367
 				// Check Parent ID
373 368
 				if( get_post_type($cart['order_items'][ $product_id ]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
374 369
 					$parent_product_id = $cart['order_items'][ $product_id ]['item_id'];
375
-				}
376
-				else {
370
+				} else {
377 371
 					$parent_data = wpshop_products::get_parent_variation( $cart['order_items'][ $product_id ]['item_id'] );
378 372
 					$parent_post = $parent_data['parent_post'];
379 373
 					$parent_product_id = $parent_post->ID;
@@ -388,8 +382,7 @@  discard block
 block discarded – undo
388 382
 							}
389 383
 						}
390 384
 					}
391
-				}
392
-				else {
385
+				} else {
393 386
 					$selected_variations = get_post_meta( $product_id, '_wpshop_variations_attribute_def', true );
394 387
 				}
395 388
 			}
@@ -399,8 +392,7 @@  discard block
 block discarded – undo
399 392
 			$new_pid = $product_id;
400 393
 			$return = $this->add_to_cart( $product_to_add_to_cart, array( $new_pid => $quantity ), $wpshop_cart_type, array(), $from_admin, $cart, $order_id );
401 394
 			return $return;
402
-		}
403
-		else {
395
+		} else {
404 396
 			return __('This product does not exist in the cart.', 'wpshop');
405 397
 		}
406 398
 	}
@@ -416,8 +408,7 @@  discard block
 block discarded – undo
416 408
 		if ( empty( $from_admin ) ){
417 409
 			if(isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type'] ) {
418 410
 				return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop');
419
-			}
420
-			else {
411
+			} else {
421 412
 				$_SESSION['cart']['cart_type'] = $type;
422 413
 			}
423 414
 			$order_meta = $_SESSION['cart'];
@@ -428,22 +419,27 @@  discard block
 block discarded – undo
428 419
 
429 420
 		foreach ($product_list as $pid => $product_more_content) {
430 421
 			if ( count($product_list) == 1 ) {
431
-				if ( !isset( $quantity[$pid] ) ) $quantity[$pid] = 1;
422
+				if ( !isset( $quantity[$pid] ) ) {
423
+					$quantity[$pid] = 1;
424
+				}
432 425
 				$product = wpshop_products::get_product_data($product_more_content['id'], false, '"publish", "free_product"');
433 426
 				/** Check if the selected product exist	*/
434
-				if ( $product === false ) return __('This product does not exist', 'wpshop');
427
+				if ( $product === false ) {
428
+					return __('This product does not exist', 'wpshop');
429
+				}
435 430
 
436 431
 				/** Get information about the product price	*/
437 432
 				$product_price_check = wpshop_prices::get_product_price($product, 'check_only');
438
-				if ( $product_price_check !== true ) return $product_price_check;
433
+				if ( $product_price_check !== true ) {
434
+					return $product_price_check;
435
+				}
439 436
 
440 437
 				$the_quantity = 1;
441 438
 
442 439
 				if ( !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) ) {
443 440
 					/** Get the asked quantity for each product and check if there is enough stock	*/
444 441
 					$the_quantity = $quantity[$pid];
445
-				}
446
-				else {
442
+				} else {
447 443
 					/** Get the asked quantity for each product and check if there is enough stock	*/
448 444
 					$the_quantity = $quantity[$pid];
449 445
 				}
@@ -486,8 +482,7 @@  discard block
 block discarded – undo
486 482
 			if ( get_current_user_id() ) {
487 483
 				$this->persistent_cart_update();
488 484
 			}
489
-		}
490
-		else {
485
+		} else {
491 486
 			update_post_meta($order_id, '_order_postmeta', $order );
492 487
 
493 488
 		}
@@ -631,8 +626,7 @@  discard block
 block discarded – undo
631 626
 					if( empty( $d['product_qty'] ) ) {
632 627
 						unset( $cart_items[$product_key] );
633 628
 						unset( $cart_infos['order_items'][$product_key] );
634
-					}
635
-					else {
629
+					} else {
636 630
 						$wps_orders = new wps_orders_ctr();
637 631
 						$cart_items[$product_key] = $wps_orders->add_product_to_order($the_product);
638 632
 					}
@@ -651,8 +645,7 @@  discard block
 block discarded – undo
651 645
 				if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) {
652 646
 					$cart_has_special_product = true;
653 647
 					$cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] );
654
-				}
655
-				else {
648
+				} else {
656 649
 					$cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc'];
657 650
 				}
658 651
 
@@ -661,13 +654,11 @@  discard block
 block discarded – undo
661 654
 				// VAT
662 655
 				if( !empty($order_tva[ $item['item_tva_rate'] ]) ) {
663 656
 					$order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount'];
664
-				}
665
-				else {
657
+				} else {
666 658
 					$order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount'];
667 659
 				}
668 660
 			}
669
-		}
670
-		else {
661
+		} else {
671 662
 			return array();
672 663
 		}
673 664
 
@@ -764,8 +755,7 @@  discard block
 block discarded – undo
764 755
 			}
765 756
 			if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) {
766 757
 				$cart_infos['order_grand_total'] = 0;
767
-			}
768
-			else {
758
+			} else {
769 759
 				$cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '');
770 760
 			}
771 761
 			$cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', '');
@@ -775,8 +765,7 @@  discard block
 block discarded – undo
775 765
 		$wpshop_payment = new wpshop_payment();
776 766
 		if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) {
777 767
 			$partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' );
778
-		}
779
-		else {
768
+		} else {
780 769
 			$partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] );
781 770
 		}
782 771
 		if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) {
@@ -844,8 +833,9 @@  discard block
 block discarded – undo
844 833
 	public function wps_reload_mini_cart() {
845 834
 		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
846 835
 
847
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) )
848
-			wp_die();
836
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) {
837
+					wp_die();
838
+		}
849 839
 
850 840
 		$wps_cart = new wps_cart();
851 841
 		$result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) );
@@ -925,8 +915,9 @@  discard block
 block discarded – undo
925 915
 	function wps_apply_coupon() {
926 916
 		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
927 917
 
928
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) )
929
-			wp_die();
918
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) {
919
+					wp_die();
920
+		}
930 921
 
931 922
 		$status = false; $response = '';
932 923
 		$coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null;
@@ -938,12 +929,10 @@  discard block
 block discarded – undo
938 929
 				$this->store_cart_in_session($order);
939 930
 				$status = true;
940 931
 				$response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>';
941
-			}
942
-			else {
932
+			} else {
943 933
 				$response = '<div class="wps-alert-error">' .$result['message']. '</div>';
944 934
 			}
945
-		}
946
-		else {
935
+		} else {
947 936
 			$response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>';
948 937
 		}
949 938
 		echo json_encode( array( 'status' => $status, 'response' => $response ) );
@@ -957,8 +946,9 @@  discard block
 block discarded – undo
957 946
 	public static function wps_cart_pass_to_step_two() {
958 947
 		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
959 948
 
960
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) )
961
-			wp_die();
949
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) {
950
+					wp_die();
951
+		}
962 952
 
963 953
 		$status = false; $response = '';
964 954
 		$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) );
@@ -968,8 +958,7 @@  discard block
 block discarded – undo
968 958
 			$response = get_permalink( $checkout_page_id  ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step;
969 959
 			$response = apply_filters('wps_extra_signup_actions', $response);
970 960
 			$status = true;
971
-		}
972
-		else {
961
+		} else {
973 962
 			$response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>';
974 963
 		}
975 964
 		echo json_encode( array( 'status' => $status, 'response' => $response));
@@ -983,8 +972,9 @@  discard block
 block discarded – undo
983 972
 	function wps_empty_cart() {
984 973
 		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
985 974
 
986
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) )
987
-			wp_die();
975
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) {
976
+					wp_die();
977
+		}
988 978
 
989 979
 
990 980
 		$this->empty_cart();
Please login to merge, or discard this patch.
includes/modules/billing/billing.php 1 patch
Indentation   +1099 added lines, -1099 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
 /**
@@ -13,217 +13,217 @@  discard block
 block discarded – undo
13 13
 
14 14
 /**    Check if billing class does not exist before creating the class    */
15 15
 if (!class_exists("wpshop_modules_billing")) {
16
-    /**
17
-     * Billing module utilities definition
18
-     *
19
-     * @author Alexandre Techer - Eoxia dev team <[email protected]>
20
-     * @version 0.1
21
-     * @package includes
22
-     * @subpackage modules
23
-     */
24
-    class wpshop_modules_billing
25
-    {
26
-        /**
27
-         * Create a new instance for the current module - Billing
28
-         */
29
-        public function __construct()
30
-        {
31
-            /**    Add custom template for current module    */
32
-            add_filter('wpshop_custom_template', array(&$this, 'custom_template_load'));
33
-
34
-            /**    In case wpshop is set on sale mode and not on view catalog only, Ad billign options    */
35
-            if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
36
-                $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
37
-                $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
38
-
39
-                if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
40
-                    && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
41
-                    /**    Add module option to wpshop general options    */
42
-                    add_filter('wpshop_options', array(&$this, 'add_options'), 9);
43
-                    add_action('wsphop_options', array(&$this, 'declare_options'), 8);
44
-                }
45
-            }
46
-
47
-            // Filter
48
-            add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2);
49
-        }
50
-
51
-        /**
52
-         * Load module/addon automatically to existing template list
53
-         *
54
-         * @param array $templates The current template definition
55
-         *
56
-         * @return array The template with new elements
57
-         */
58
-        public function custom_template_load($templates)
59
-        {
60
-            include 'templates/common/main_elements.tpl.php';
61
-            $wpshop_template = $tpl_element;
62
-            /*    Get custom frontend template    */
63
-            if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) {
64
-                require_once get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php';
65
-                if (!empty($tpl_element)) {
66
-                    $wpshop_template['common']['custom'] = ($tpl_element);
67
-                }
68
-                unset($tpl_element);
69
-            }
70
-            $wpshop_display = new wpshop_display();
71
-            $templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates);
72
-
73
-            unset($tpl_element);
74
-
75
-            return $templates;
76
-        }
77
-
78
-        /**
79
-         * Declare option groups for the module
80
-         */
81
-        public function add_options($option_group)
82
-        {
83
-            $option_group['wpshop_billing_info'] =
84
-            array('label' => __('Billing', 'wpshop'),
85
-                'subgroups' => array(
86
-                    'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'),
87
-                ),
88
-            );
89
-
90
-            return $option_group;
91
-        }
92
-
93
-        /**
94
-         * Declare the different options in groups for the module
95
-         */
96
-        public function declare_options()
97
-        {
98
-            add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info');
99
-
100
-            register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures'));
101
-            add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info');
102
-
103
-            register_setting('wpshop_options', 'wpshop_billing_address', array(&$this, 'wpshop_billing_address_validator'));
104
-            add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info');
105
-            add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info');
106
-
107
-            $quotation_option = get_option('wpshop_addons');
108
-            if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) {
109
-                add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info');
110
-
111
-                register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time'));
112
-                add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info');
113
-                $payment_option = get_option('wps_payment_mode');
114
-                if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) {
115
-                    register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation'));
116
-                    add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info');
117
-                }
118
-                register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation'));
119
-                add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info');
120
-            }
121
-
122
-        }
123
-
124
-        public function wpshop_options_validate_wpshop_bic_to_quotation($input)
125
-        {
126
-            return $input;
127
-        }
128
-
129
-        public function wpshop_bic_to_quotation_field()
130
-        {
131
-            $add_quotation_option = get_option('wpshop_paymentMethod_options');
132
-            $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]"  ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />';
133
-            echo $output;
134
-        }
135
-
136
-        public function billing_options_main_explanation()
137
-        {
138
-
139
-        }
140
-        public function quotation_options_main_explanation()
141
-        {
142
-
143
-        }
144
-
145
-        public function wpshop_options_validate_quotation_validate_time($input)
146
-        {
147
-            return $input;
148
-        }
149
-
150
-        public function wpshop_billing_number_figures_field()
151
-        {
152
-            $wpshop_billing_number_figures = get_option('wpshop_billing_number_figures');
153
-            $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null;
154
-            if (empty($wpshop_billing_number_figures)) {
155
-                $wpshop_billing_number_figures = 5;
156
-            }
157
-
158
-            echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' />
16
+	/**
17
+	 * Billing module utilities definition
18
+	 *
19
+	 * @author Alexandre Techer - Eoxia dev team <[email protected]>
20
+	 * @version 0.1
21
+	 * @package includes
22
+	 * @subpackage modules
23
+	 */
24
+	class wpshop_modules_billing
25
+	{
26
+		/**
27
+		 * Create a new instance for the current module - Billing
28
+		 */
29
+		public function __construct()
30
+		{
31
+			/**    Add custom template for current module    */
32
+			add_filter('wpshop_custom_template', array(&$this, 'custom_template_load'));
33
+
34
+			/**    In case wpshop is set on sale mode and not on view catalog only, Ad billign options    */
35
+			if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
36
+				$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
37
+				$old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
38
+
39
+				if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
40
+					&& ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
41
+					/**    Add module option to wpshop general options    */
42
+					add_filter('wpshop_options', array(&$this, 'add_options'), 9);
43
+					add_action('wsphop_options', array(&$this, 'declare_options'), 8);
44
+				}
45
+			}
46
+
47
+			// Filter
48
+			add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2);
49
+		}
50
+
51
+		/**
52
+		 * Load module/addon automatically to existing template list
53
+		 *
54
+		 * @param array $templates The current template definition
55
+		 *
56
+		 * @return array The template with new elements
57
+		 */
58
+		public function custom_template_load($templates)
59
+		{
60
+			include 'templates/common/main_elements.tpl.php';
61
+			$wpshop_template = $tpl_element;
62
+			/*    Get custom frontend template    */
63
+			if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) {
64
+				require_once get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php';
65
+				if (!empty($tpl_element)) {
66
+					$wpshop_template['common']['custom'] = ($tpl_element);
67
+				}
68
+				unset($tpl_element);
69
+			}
70
+			$wpshop_display = new wpshop_display();
71
+			$templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates);
72
+
73
+			unset($tpl_element);
74
+
75
+			return $templates;
76
+		}
77
+
78
+		/**
79
+		 * Declare option groups for the module
80
+		 */
81
+		public function add_options($option_group)
82
+		{
83
+			$option_group['wpshop_billing_info'] =
84
+			array('label' => __('Billing', 'wpshop'),
85
+				'subgroups' => array(
86
+					'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'),
87
+				),
88
+			);
89
+
90
+			return $option_group;
91
+		}
92
+
93
+		/**
94
+		 * Declare the different options in groups for the module
95
+		 */
96
+		public function declare_options()
97
+		{
98
+			add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info');
99
+
100
+			register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures'));
101
+			add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info');
102
+
103
+			register_setting('wpshop_options', 'wpshop_billing_address', array(&$this, 'wpshop_billing_address_validator'));
104
+			add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info');
105
+			add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info');
106
+
107
+			$quotation_option = get_option('wpshop_addons');
108
+			if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) {
109
+				add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info');
110
+
111
+				register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time'));
112
+				add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info');
113
+				$payment_option = get_option('wps_payment_mode');
114
+				if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) {
115
+					register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation'));
116
+					add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info');
117
+				}
118
+				register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation'));
119
+				add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info');
120
+			}
121
+
122
+		}
123
+
124
+		public function wpshop_options_validate_wpshop_bic_to_quotation($input)
125
+		{
126
+			return $input;
127
+		}
128
+
129
+		public function wpshop_bic_to_quotation_field()
130
+		{
131
+			$add_quotation_option = get_option('wpshop_paymentMethod_options');
132
+			$output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]"  ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />';
133
+			echo $output;
134
+		}
135
+
136
+		public function billing_options_main_explanation()
137
+		{
138
+
139
+		}
140
+		public function quotation_options_main_explanation()
141
+		{
142
+
143
+		}
144
+
145
+		public function wpshop_options_validate_quotation_validate_time($input)
146
+		{
147
+			return $input;
148
+		}
149
+
150
+		public function wpshop_billing_number_figures_field()
151
+		{
152
+			$wpshop_billing_number_figures = get_option('wpshop_billing_number_figures');
153
+			$readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null;
154
+			if (empty($wpshop_billing_number_figures)) {
155
+				$wpshop_billing_number_figures = 5;
156
+			}
157
+
158
+			echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' />
159 159
 		<a href="#" title="' . __('Number of figures to make appear on invoices', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
160
-        }
161
-
162
-        public function wpshop_options_validate_billing_number_figures($input)
163
-        {
164
-            return $input;
165
-        }
166
-
167
-        public function wpshop_billing_address_validator($input)
168
-        {
169
-            global $wpdb;
170
-            $t = wps_address::get_addresss_form_fields_by_type($input['choice']);
171
-
172
-            $the_code = '';
173
-            foreach ($t[$input['choice']] as $group_id => $group_def) {
174
-                if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) {
175
-                    $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name'];
176
-                    continue;
177
-                }
178
-            }
179
-            $the_code;
180
-
181
-            if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') {
182
-                if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') {
183
-                    $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code));
184
-                }
185
-            }
186
-
187
-            $billing_option = get_option('wpshop_billing_address');
188
-            if (!empty($billing_option) && !empty($billing_option['display_model'])) {
189
-                $input['display_model'] = $billing_option['display_model'];
190
-            }
191
-
192
-            return $input;
193
-        }
194
-
195
-        public function wpshop_billing_address_choice_field()
196
-        {
197
-            global $wpdb;
198
-            $output = '';
199
-
200
-            $wpshop_billing_address = get_option('wpshop_billing_address');
201
-
202
-            $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
203
-            $entity_id = $wpdb->get_var($query);
204
-
205
-            $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
206
-            $content = $wpdb->get_results($query);
207
-
208
-            /*    Field for billing address type choice    */
209
-            $input_def['name'] = 'wpshop_billing_address[choice]';
210
-            $input_def['id'] = 'wpshop_billing_address_choice';
211
-            $input_def['possible_value'] = $content;
212
-            $input_def['type'] = 'select';
213
-            $input_def['value'] = $wpshop_billing_address['choice'];
214
-            $output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>';
215
-
216
-            /*    Field for integrate billign form into register form    */
217
-            $input_def = array();
218
-            $input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]';
219
-            $input_def['id'] = 'wpshop_billing_address_integrate_into_register_form';
220
-            $input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop'));
221
-            $input_def['valueToPut'] = 'index';
222
-            $input_def['options_label']['original'] = true;
223
-            $input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" ';
224
-            $input_def['type'] = 'checkbox';
225
-            $input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : '');
226
-            $output .= '
160
+		}
161
+
162
+		public function wpshop_options_validate_billing_number_figures($input)
163
+		{
164
+			return $input;
165
+		}
166
+
167
+		public function wpshop_billing_address_validator($input)
168
+		{
169
+			global $wpdb;
170
+			$t = wps_address::get_addresss_form_fields_by_type($input['choice']);
171
+
172
+			$the_code = '';
173
+			foreach ($t[$input['choice']] as $group_id => $group_def) {
174
+				if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) {
175
+					$the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name'];
176
+					continue;
177
+				}
178
+			}
179
+			$the_code;
180
+
181
+			if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') {
182
+				if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') {
183
+					$wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code));
184
+				}
185
+			}
186
+
187
+			$billing_option = get_option('wpshop_billing_address');
188
+			if (!empty($billing_option) && !empty($billing_option['display_model'])) {
189
+				$input['display_model'] = $billing_option['display_model'];
190
+			}
191
+
192
+			return $input;
193
+		}
194
+
195
+		public function wpshop_billing_address_choice_field()
196
+		{
197
+			global $wpdb;
198
+			$output = '';
199
+
200
+			$wpshop_billing_address = get_option('wpshop_billing_address');
201
+
202
+			$query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
203
+			$entity_id = $wpdb->get_var($query);
204
+
205
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
206
+			$content = $wpdb->get_results($query);
207
+
208
+			/*    Field for billing address type choice    */
209
+			$input_def['name'] = 'wpshop_billing_address[choice]';
210
+			$input_def['id'] = 'wpshop_billing_address_choice';
211
+			$input_def['possible_value'] = $content;
212
+			$input_def['type'] = 'select';
213
+			$input_def['value'] = $wpshop_billing_address['choice'];
214
+			$output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>';
215
+
216
+			/*    Field for integrate billign form into register form    */
217
+			$input_def = array();
218
+			$input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]';
219
+			$input_def['id'] = 'wpshop_billing_address_integrate_into_register_form';
220
+			$input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop'));
221
+			$input_def['valueToPut'] = 'index';
222
+			$input_def['options_label']['original'] = true;
223
+			$input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" ';
224
+			$input_def['type'] = 'checkbox';
225
+			$input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : '');
226
+			$output .= '
227 227
 <div class="wpshop_include_billing_form_into_register_container" >
228 228
 	' . wpshop_form::check_input_type($input_def) . '
229 229
 	<input type="hidden" name="wpshop_ajax_integrate_billin_into_register" id="wpshop_ajax_integrate_billin_into_register" value="' . wp_create_nonce('wpshop_ajax_integrate_billin_into_register') . '" />
@@ -231,892 +231,892 @@  discard block
 block discarded – undo
231 231
 	<div class="wpshop_include_billing_form_into_register_where" ></div>
232 232
 </div>';
233 233
 
234
-            echo $output;
235
-        }
236
-
237
-        public function wpshop_billing_address_include_into_register_field()
238
-        {
239
-
240
-        }
241
-
242
-        public function wpshop_quotation_validate_time_field()
243
-        {
244
-            $quotation_option = get_option('wpshop_quotation_validate_time');
245
-            $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />';
246
-            $output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">';
247
-            $output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>';
248
-            $output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>';
249
-            $output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>';
250
-            $output .= '</select>';
251
-
252
-            echo $output;
253
-        }
254
-
255
-        /**
256
-         * Generate a new invoice number
257
-         *
258
-         * @param integer $order_id The order identifier we want to generate the new invoice number for
259
-         *
260
-         * @return string The new invoice number
261
-         */
262
-        public static function generate_invoice_number($order_id)
263
-        {
264
-            /**    Get configuration about the number of figure dor invoice number    */
265
-
266
-            $number_figures = get_option('wpshop_billing_number_figures', false);
267
-
268
-            /** If the number doesn't exist, we create a default one */
269
-            if (!$number_figures) {
270
-                update_option('wpshop_billing_number_figures', 5);
271
-            }
272
-
273
-            /** sleep my script, SLEEP I SAY ! **/
274
-            $rand_time = rand(1000, 200000);
275
-            usleep($rand_time);
276
-            /** GET UP !! **/
277
-
278
-            /**    Get last invoice number    */
279
-            $billing_current_number = get_option('wpshop_billing_current_number', false);
280
-
281
-            /** If the counter doesn't exist, we initiate it */
282
-            if (!$billing_current_number) {
283
-                $billing_current_number = 1;
284
-            } else {
285
-                $billing_current_number++;
286
-            }
287
-
288
-            /** Check if number exists **/
289
-            $billing_current_number_checking = get_option('wpshop_billing_current_number', false);
290
-            if ($billing_current_number_checking == $billing_current_number) {
291
-                $billing_current_number++;
292
-            }
293
-
294
-            update_option('wpshop_billing_current_number', $billing_current_number);
295
-
296
-            /**    Create the new invoice number with all parameters viewed above    */
297
-            $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number));
298
-
299
-            return $invoice_ref;
300
-        }
301
-
302
-        /**
303
-         * Generate output for an invoice
304
-         *
305
-         * @param integer $order_id
306
-         * @param string $invoice_ref
307
-         *
308
-         * @return string The invoice output in case no error is found. The error in other case
309
-         */
310
-        public static function generate_html_invoice($order_id, $invoice_ref)
311
-        {
312
-            global $wpdb;
313
-
314
-            $date_output_format = get_option('date_format') . ' ' . get_option('time_format');
315
-            $count_products = 0;
316
-
317
-            if (!empty($order_id)) {
318
-                $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
319
-
320
-                $discounts_exists = false;
321
-
322
-                $is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false;
323
-                /** Check if it's a partial payment bill **/
324
-                $is_partial_payment = false;
325
-                if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') {
326
-                    foreach ($order_postmeta['order_payment']['received'] as $key => $payment) {
327
-                        if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) {
328
-                            $is_partial_payment = true;
329
-                            break;
330
-                        }
331
-                    }
332
-                } elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) {
333
-                    $is_partial_payment = true;
334
-                } elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') {
335
-                    $is_partial_payment = true;
336
-                }
337
-
338
-                /** Check it is a shipping slip **/
339
-                $bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false;
340
-                if ($bon_colisage) {
341
-                    $bon_colisage = true;
342
-                }
343
-
344
-                if (!empty($order_postmeta)) {
345
-                    $tpl_component = array();
346
-
347
-                    /** Billing Header **/
348
-                    //Logo
349
-                    $logo_options = get_option('wpshop_logo');
350
-                    $tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : '';
351
-
352
-                    // Title
353
-                    $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop'));
234
+			echo $output;
235
+		}
236
+
237
+		public function wpshop_billing_address_include_into_register_field()
238
+		{
239
+
240
+		}
241
+
242
+		public function wpshop_quotation_validate_time_field()
243
+		{
244
+			$quotation_option = get_option('wpshop_quotation_validate_time');
245
+			$output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />';
246
+			$output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">';
247
+			$output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>';
248
+			$output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>';
249
+			$output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>';
250
+			$output .= '</select>';
251
+
252
+			echo $output;
253
+		}
254
+
255
+		/**
256
+		 * Generate a new invoice number
257
+		 *
258
+		 * @param integer $order_id The order identifier we want to generate the new invoice number for
259
+		 *
260
+		 * @return string The new invoice number
261
+		 */
262
+		public static function generate_invoice_number($order_id)
263
+		{
264
+			/**    Get configuration about the number of figure dor invoice number    */
265
+
266
+			$number_figures = get_option('wpshop_billing_number_figures', false);
267
+
268
+			/** If the number doesn't exist, we create a default one */
269
+			if (!$number_figures) {
270
+				update_option('wpshop_billing_number_figures', 5);
271
+			}
272
+
273
+			/** sleep my script, SLEEP I SAY ! **/
274
+			$rand_time = rand(1000, 200000);
275
+			usleep($rand_time);
276
+			/** GET UP !! **/
277
+
278
+			/**    Get last invoice number    */
279
+			$billing_current_number = get_option('wpshop_billing_current_number', false);
280
+
281
+			/** If the counter doesn't exist, we initiate it */
282
+			if (!$billing_current_number) {
283
+				$billing_current_number = 1;
284
+			} else {
285
+				$billing_current_number++;
286
+			}
287
+
288
+			/** Check if number exists **/
289
+			$billing_current_number_checking = get_option('wpshop_billing_current_number', false);
290
+			if ($billing_current_number_checking == $billing_current_number) {
291
+				$billing_current_number++;
292
+			}
293
+
294
+			update_option('wpshop_billing_current_number', $billing_current_number);
295
+
296
+			/**    Create the new invoice number with all parameters viewed above    */
297
+			$invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number));
298
+
299
+			return $invoice_ref;
300
+		}
301
+
302
+		/**
303
+		 * Generate output for an invoice
304
+		 *
305
+		 * @param integer $order_id
306
+		 * @param string $invoice_ref
307
+		 *
308
+		 * @return string The invoice output in case no error is found. The error in other case
309
+		 */
310
+		public static function generate_html_invoice($order_id, $invoice_ref)
311
+		{
312
+			global $wpdb;
313
+
314
+			$date_output_format = get_option('date_format') . ' ' . get_option('time_format');
315
+			$count_products = 0;
316
+
317
+			if (!empty($order_id)) {
318
+				$order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
319
+
320
+				$discounts_exists = false;
321
+
322
+				$is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false;
323
+				/** Check if it's a partial payment bill **/
324
+				$is_partial_payment = false;
325
+				if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') {
326
+					foreach ($order_postmeta['order_payment']['received'] as $key => $payment) {
327
+						if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) {
328
+							$is_partial_payment = true;
329
+							break;
330
+						}
331
+					}
332
+				} elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) {
333
+					$is_partial_payment = true;
334
+				} elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') {
335
+					$is_partial_payment = true;
336
+				}
337
+
338
+				/** Check it is a shipping slip **/
339
+				$bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false;
340
+				if ($bon_colisage) {
341
+					$bon_colisage = true;
342
+				}
343
+
344
+				if (!empty($order_postmeta)) {
345
+					$tpl_component = array();
346
+
347
+					/** Billing Header **/
348
+					//Logo
349
+					$logo_options = get_option('wpshop_logo');
350
+					$tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : '';
351
+
352
+					// Title
353
+					$tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop'));
354 354
 
355 355
 //                     if ( empty($order_postmeta['order_invoice_ref']) ) {
356
-                    //                         $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop');
357
-                    //                         $is_partial_payment = true;
358
-                    //                     }
359
-
360
-                    if ($bon_colisage) {
361
-                        $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop');
362
-                    }
363
-
364
-                    $tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null);
365
-                    if ($bon_colisage) {
366
-                        $tpl_component['INVOICE_ORDER_INVOICE_REF'] = '';
367
-                    }
368
-                    $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']);
369
-                    $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true));
370
-
371
-                    /** Validate period for Quotation **/
372
-                    if ($is_quotation) {
373
-                        $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']);
374
-                    } else {
375
-                        $tpl_component['INVOICE_VALIDATE_TIME'] = '';
376
-                    }
377
-
378
-                    $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME'];
379
-
380
-                    $tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : '';
381
-
382
-                    // Sender & receiver addresses
383
-                    $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part();
384
-                    $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage);
385
-
386
-                    $tpl_component['INVOICE_TRACKING'] = '';
387
-                    $first = false;
388
-                    if (!empty($order_postmeta['order_trackingNumber'])) {
389
-                        $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber'];
390
-                        $first = true;
391
-                    }
392
-                    if (!empty($order_postmeta['order_trackingLink'])) {
393
-                        if (!$first) {
394
-                            $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink'];
395
-                        } else {
396
-                            $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink'];
397
-                        }
398
-                    }
399
-
400
-                    /** Items Tab **/
401
-                    $order_tva = array();
402
-                    if ($bon_colisage) {
403
-                        $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common');
404
-                    } else {
405
-                        $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common');
406
-                        //if ( !$is_quotation ) {
407
-                        /** Check if products have discounts **/
408
-                        if (!empty($order_postmeta['order_items']) && !$is_partial_payment) {
409
-                            foreach ($order_postmeta['order_items'] as $item_id => $item) {
410
-                                if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) {
411
-                                    $discounts_exists = true;
412
-                                }
413
-                            }
414
-                        }
415
-
416
-                        if ($discounts_exists) {
417
-                            $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common');
418
-                        }
419
-
420
-                        //}
421
-                    }
422
-
423
-                    $total_discounted = 0;
424
-                    $tpl_component['INVOICE_ROWS'] = '';
425
-
426
-                    if (!$is_partial_payment) {
427
-                        if (!empty($order_postmeta['order_items'])) {
428
-                            foreach ($order_postmeta['order_items'] as $item_id => $item) {
429
-                                $sub_tpl_component = array();
430
-                                $count_products += $item['item_qty'];
431
-                                $barcode = get_post_meta($item['item_id'], '_barcode', true);
432
-                                if (empty($barcode)) {
433
-                                    $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true);
434
-                                    $barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : '';
435
-
436
-                                    if (empty($barcode)) {
437
-                                        $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
438
-                                        $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code');
439
-                                        $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']);
440
-                                        $barcode = $wpdb->get_var($query);
441
-                                    }
442
-                                }
443
-                                $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-';
444
-
445
-                                $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref'];
446
-
447
-                                /** Item name **/
448
-                                $is_variation = false;
449
-                                if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
450
-                                    $is_variation = true;
451
-                                    $parent_def = wpshop_products::get_parent_variation($item['item_id']);
452
-                                    if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
453
-                                        $parent_post = $parent_def['parent_post'];
454
-                                        $item_parent_id = $parent_post->ID;
455
-                                        $item_title = $parent_post->post_title;
456
-                                    }
457
-                                } else {
458
-                                    $item_title = $item['item_name'];
459
-                                }
460
-                                $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title;
461
-                                /**    Get attribute order for current product    */
462
-                                $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
463
-                                $output_order = array();
464
-                                if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) {
465
-                                    foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
466
-                                        foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
467
-                                            if (!empty($attribute_def->code)) {
468
-                                                $output_order[$attribute_def->code] = $position;
469
-                                            }
470
-
471
-                                        }
472
-                                    }
473
-                                }
474
-                                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common');
475
-                                ksort($variation_attribute_ordered['attribute_list']);
476
-                                $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = '';
477
-                                foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
478
-                                    $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output;
479
-                                }
480
-                                $post_content = get_post_field('post_content', $item['item_id']);
481
-                                if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/!empty($post_content) && false) {
482
-                                    if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) {
483
-                                        //$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>';
484
-                                    }
485
-                                    $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>';
486
-                                }
487
-                                $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : '';
488
-                                unset($detail_tpl_component);
489
-
490
-                                $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty'];
491
-                                $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', ''));
492
-                                $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', ''));
493
-                                $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', '');
494
-                                $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', '');
495
-                                /** TVA **/
496
-                                $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', '');
497
-                                $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate'];
498
-
499
-                                $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', '');
500
-
501
-                                /** Checking Rate amount **/
502
-                                if (!$bon_colisage) {
503
-                                    $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id);
504
-                                    if (!$checking) {
505
-                                        return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop');
506
-                                    }
507
-                                }
508
-
509
-                                if ($bon_colisage) {
510
-                                    $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common');
511
-                                } else {
512
-                                    if ($discounts_exists) {
513
-                                        $discounted_total_per_item = $item['item_total_ht'];
514
-                                        /** Unit Discount **/
515
-                                        if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) {
516
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', '');
517
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', '');
518
-                                            $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount'];
519
-                                        } else {
520
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
521
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
522
-                                        }
523
-
524
-                                        /** Global Discount **/
525
-                                        if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) {
526
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', '');
527
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', '');
528
-                                            $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount'];
529
-                                        } else {
530
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
531
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
532
-                                        }
533
-
534
-                                        $total_discounted += $discounted_total_per_item;
535
-                                        /** Total HT Discounted **/
536
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', '');
537
-
538
-                                        $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common');
539
-                                    } else {
540
-                                        $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
541
-                                    }
542
-                                }
543
-                                unset($sub_tpl_component);
544
-
545
-                                /** Check TVA **/
546
-                                if (empty($order_tva[$item['item_tva_rate']])) {
547
-                                    $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount'];
548
-                                } else {
549
-                                    $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount'];
550
-                                }
551
-
552
-                            }
553
-                        }
554
-
555
-                        /** Display Partials payments **/
556
-                        $total_partial_payment = 0;
557
-                        $last_payment = 0;
558
-                        $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : '';
559
-                        if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) {
560
-                            foreach ($order_postmeta['order_payment']['received'] as $received_payment) {
561
-                                if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) {
562
-                                    if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) {
563
-                                        $sub_tpl_component = array();
564
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref'];
565
-
566
-                                        /** Item name **/
567
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']);
568
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = '';
569
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1;
570
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
571
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
572
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
573
-
574
-                                        /** TVA **/
575
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '');
576
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0;
577
-                                        $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
578
-
579
-                                        if ($discounts_exists) {
580
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
581
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
582
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
583
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
584
-                                            $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
585
-
586
-                                            $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common');
587
-                                        } else {
588
-                                            $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
589
-                                        }
590
-                                    }
591
-
592
-                                    unset($sub_tpl_component);
593
-                                    $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0;
594
-                                } else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) {
595
-                                    $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0;
596
-                                }
597
-
598
-                            }
599
-                        }
600
-                    } else {
601
-                        /** Display Partials payments **/
602
-                        $total_partial_payment = 0;
603
-                        $last_payment = 0;
604
-                        if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) {
605
-                            foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) {
606
-                                if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) {
607
-                                    $sub_tpl_component = array();
608
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref'];
609
-                                    /** Item name **/
610
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1);
611
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = '';
612
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1;
613
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', '');
614
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
615
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', '');
616
-                                    /** TVA **/
617
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '');
618
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0;
619
-                                    $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', '');
620
-                                    $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
621
-                                    unset($sub_tpl_component);
622
-                                    $total_partial_payment += $received_payment['received_amount'];
623
-                                }
624
-                            }
625
-                        }
626
-                    }
627
-
628
-                    /** Summary of order **/
629
-                    $summary_tpl_component = array();
630
-                    $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = '';
631
-                    if (!$bon_colisage) {
632
-                        if (!empty($order_tva)) {
633
-                            foreach ($order_tva as $tax_rate => $tax_amount) {
634
-                                if ($tax_amount > 0) {
635
-                                    $tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate;
636
-                                    $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%');
637
-                                    $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency();
638
-                                    $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
639
-                                    unset($sub_tpl_component);
640
-                                } elseif ($is_partial_payment) {
641
-                                    $tax_rate = 0;
642
-                                    $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency();
643
-                                    $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%');
644
-                                    $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency();
645
-                                    $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
646
-                                    unset($sub_tpl_component);
647
-                                }
648
-                            }
649
-                        }
650
-
651
-                        /** If Discount Exist **/
652
-                        // Checking Discounts on order
653
-                        if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) {
654
-                            $discounts_exists = true;
655
-                            // Calcul discount on Order
656
-                            switch ($order_postmeta['order_discount_type']) {
657
-                                case 'amount':
658
-                                    $total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '');
659
-                                    break;
660
-                                case 'percent':
661
-                                    $total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100);
662
-                                    break;
663
-                            }
664
-                        }
665
-                        if (!empty($total_discounted) && $discounts_exists) {
666
-                            $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop');
667
-                            $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency();
668
-                            $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
669
-                            unset($sub_tpl_component);
670
-                        } else {
671
-                            $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = '';
672
-                        }
673
-
674
-                        $shipping_cost = 0;
675
-                        if (!$is_partial_payment) {
676
-                            if (!empty($order_postmeta['order_shipping_cost'])) {
677
-                                $shipping_cost = $order_postmeta['order_shipping_cost'];
678
-                            }
679
-                        }
680
-                        $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC');
681
-                        $shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100));
682
-                        $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', '');
683
-                        $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', '');
684
-                        //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' );
685
-
686
-                        $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' );
687
-                        $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', '');
688
-
689
-                        $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', '');
690
-
691
-                        $total_payment = 0;
692
-
693
-                        /** Amount paid **/
694
-                        if (empty($order_postmeta['order_invoice_ref'])) {
695
-                            foreach ($order_postmeta['order_payment']['received'] as $key => $value) {
696
-                                if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) {
697
-                                    $total_payment = number_format($value['received_amount'], 2, ',', '');
698
-                                }
699
-                            }
700
-                        } else {
701
-                            $total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total'];
702
-                        }
703
-
704
-                        $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop');
705
-                        $sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency();
706
-                        //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ?  number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency();
707
-                        $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
708
-                        unset($sub_tpl_component);
709
-
710
-                        $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop');
711
-                        $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products;
712
-                        $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
713
-                        unset($sub_tpl_component);
714
-
715
-                        /** If Discount Exist **/
716
-                        if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) {
717
-                            $tpl_discount_component = array();
718
-                            $tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', '');
719
-
720
-                            $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', '');
721
-                            $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common');
722
-                            unset($tpl_discount_component);
723
-                        } else {
724
-                            $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = '';
725
-                        }
726
-
727
-                        $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop');
728
-
729
-                        $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common');
730
-                        unset($summary_tpl_component);
731
-                    }
732
-
733
-                    /** IBAN Include on quotation **/
734
-                    if ($is_quotation) {
735
-                        /** If admin want to include his IBAN to quotation */
736
-                        $iban_options = get_option('wpshop_paymentMethod_options');
737
-                        $payment_options = get_option('wps_payment_mode');
738
-                        if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') {
739
-                            if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) {
740
-                                $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>';
741
-                                $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>';
742
-                                $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>';
743
-                                $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>';
744
-                                $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>';
745
-                            }
746
-                        } else {
747
-                            $tpl_component['IBAN_INFOS'] = '';
748
-                        }
749
-                    } else {
750
-                        $tpl_component['IBAN_INFOS'] = '';
751
-                    }
752
-
753
-                    /** Received payements **/
754
-                    if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) {
755
-                        $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id);
756
-                    } else {
757
-                        $tpl_component['RECEIVED_PAYMENT'] = '';
758
-                    }
759
-
760
-                    /** Invoice footer **/
761
-                    $tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice();
762
-
763
-                    $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common');
764
-                } else {
765
-                    $output = __('No order information has been found', 'wpshop');
766
-                }
767
-            } else {
768
-                $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop');
769
-            }
770
-            return $output;
771
-        }
772
-
773
-        /**
774
-         * Return the payment list part
775
-         * @param integer $order_id
776
-         * @return string
777
-         */
778
-        public static function generate_received_payment_part($order_id)
779
-        {
780
-            $date_ouput_format = get_option('date_format') . ' ' . get_option('time_format');
781
-            $output = '';
782
-            $tpl_component = array();
783
-            $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = '';
784
-            if (!empty($order_id)) {
785
-                $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
786
-                if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) {
787
-                    $wps_payment_option = get_option('wps_payment_mode');
788
-                    foreach ($order_postmeta['order_payment']['received'] as $payment) {
789
-                        if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) {
790
-                            $sub_tpl_component = array();
791
-                            $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0;
792
-                            $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : '';
793
-                            $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : ''));
794
-                            $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : '';
795
-                            $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : '';
796
-                            $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common');
797
-                        }
798
-                    }
799
-                }
800
-                $output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common');
801
-                unset($tpl_component);
802
-            }
803
-            return $output;
804
-        }
805
-
806
-        /** Return the validity period of a quotation **/
807
-        public static function quotation_validate_period($quotation_date)
808
-        {
809
-            $quotation_options = get_option('wpshop_quotation_validate_time');
810
-            if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) {
811
-                $timestamp_quotation = strtotime($quotation_date);
812
-                $timestamp_validity_date_quotation = 0;
813
-                $query = '';
814
-                $date = '';
815
-                global $wpdb;
816
-                switch ($quotation_options['time_type']) {
817
-                    case 'day':
818
-                        $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s DAY)", $quotation_date, $quotation_options['number']);
819
-                        break;
820
-                    case 'month':
821
-                        $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s MONTH)", $quotation_date, $quotation_options['number']);
822
-                        break;
823
-                    case 'year':
824
-                        $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s YEAR)", $quotation_date, $quotation_options['number']);
825
-                        break;
826
-                    default:
827
-                        $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL '15' DAY)", $quotation_date);
828
-                        break;
829
-                }
830
-                if ($query != null) {
831
-                    $date = mysql2date('d F Y', $wpdb->get_var($query), true);
832
-                }
833
-                return sprintf(__('Quotation validity date %s', 'wpshop'), $date);
834
-            }
835
-        }
836
-
837
-        /**
838
-         * Generate HTML invoice to be sended by email
839
-         * @param integer $order_id
840
-         * @param string $invoice_ref
841
-         * @return string
842
-         */
843
-        public static function generate_invoice_for_email($order_id, $invoice_ref = '')
844
-        {
845
-            /** Generate the PDF file for the invoice **/
846
-            $is_ok = false;
847
-            if (!empty($invoice_ref)) {
848
-                require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php';
849
-                try {
850
-                    $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref);
851
-                    $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
852
-                    $html2pdf = new HTML2PDF('P', 'A4', 'fr');
853
-
854
-                    $html2pdf->setDefaultFont('Arial');
855
-                    $html2pdf->writeHTML($html_content);
856
-                    $html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F');
857
-                    $is_ok = true;
858
-                } catch (HTML2PDF_exception $e) {
859
-                    echo $e;
860
-                    exit;
861
-                }
862
-            }
863
-            return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : '';
864
-        }
865
-
866
-        /**
867
-         * Generate Sender part invoice template
868
-         * @return Ambigous <string, string>
869
-         */
870
-        public static function generate_invoice_sender_part()
871
-        {
872
-            $output = '';
873
-            $company = get_option('wpshop_company_info', array());
874
-            $emails = get_option('wpshop_emails', array());
875
-            if (!empty($company)) {
876
-                $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : '';
877
-                $tpl_component['COMPANY_WEBSITE'] = get_option('siteurl');
878
-                foreach ($company as $company_info_key => $company_info_value) {
879
-                    switch ($company_info_key) {
880
-                        case 'company_rcs':
881
-                            $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : '';
882
-                            break;
883
-                        case 'company_capital':
884
-                            $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : '';
885
-                            break;
886
-                        case 'company_siren':
887
-                            $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : '';
888
-                            break;
889
-                        case 'company_siret':
890
-                            $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : '';
891
-                            break;
892
-                        case 'company_tva_intra':
893
-                            $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : '';
894
-                            break;
895
-                        case 'company_legal_statut':
896
-                            $array_state_compagny = wpshop_company_options::get_legal_status();
897
-                            $data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop');
898
-                            break;
899
-                        default:
900
-                            $data = $company_info_value;
901
-                            break;
902
-                    }
903
-                    $tpl_component[strtoupper($company_info_key)] = $data;
904
-                }
905
-                $output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common');
906
-            }
907
-            return $output;
908
-        }
909
-
910
-        /**
911
-         * Generate Receiver part template
912
-         * @param unknown_type $order_id
913
-         * @param unknown_type $bon_colisage
914
-         * @return Ambigous <string, string>
915
-         */
916
-        public static function generate_receiver_part($order_id, $bon_colisage = false)
917
-        {
918
-            $output = '';
919
-            $order_customer_postmeta = get_post_meta($order_id, '_order_info', true);
920
-            $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
921
-
922
-            if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) {
923
-                $address_info = $order_customer_postmeta['shipping']['address'];
924
-            } else {
925
-                if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) {
926
-                    $address_info = $order_customer_postmeta['billing']['address'];
927
-                } else {
928
-                    $address_info = array();
929
-                }
930
-            }
931
-
932
-            if (!empty($order_customer_postmeta) && !empty($address_info)) {
933
-                $default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY');
934
-                foreach ($default_address_attributes as $default_address_attribute) {
935
-                    $tpl_component[$default_address_attribute] = '';
936
-                }
937
-
938
-                foreach ($address_info as $order_customer_info_key => $order_customer_info_value) {
939
-                    $tpl_component[strtoupper($order_customer_info_key)] = '';
940
-                    if ($order_customer_info_key == 'civility') {
941
-                        global $wpdb;
942
-                        $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value);
943
-                        $civility = $wpdb->get_row($query);
944
-                        $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : '';
945
-                    } else if ($order_customer_info_key == 'country') {
946
-                        foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) {
947
-                            if ($order_customer_info_value == $key) {
948
-                                $tpl_component[strtoupper($order_customer_info_key)] = $value;
949
-                            }
950
-                        }
951
-                    } elseif ($order_customer_info_key == 'phone') {
952
-                        $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : '';
953
-                    } else {
954
-                        $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : '';
955
-                    }
956
-                }
957
-
958
-                if (empty($tpl_component['PHONE'])) {
959
-                    $tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : '';
960
-                }
961
-
962
-                if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) {
963
-                    $user_info = get_userdata($order_postmeta['customer_id']);
964
-                    $tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : '';
965
-                }
966
-
967
-                $output = wpshop_display::display_template_element('invoice_receiver_formatted_address', $tpl_component, array(), 'common');
968
-            }
969
-            return $output;
970
-        }
971
-
972
-        /**
973
-         * Genrate Footer invoice
974
-         * @return Ambigous <string, string>
975
-         */
976
-        public static function generate_footer_invoice()
977
-        {
978
-            $output = '';
979
-            $company = get_option('wpshop_company_info', array());
980
-            $emails = get_option('wpshop_emails', array());
981
-            if (!empty($company)) {
982
-                $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : '';
983
-                $tpl_component['COMPANY_WEBSITE'] = site_url();
984
-                foreach ($company as $company_info_key => $company_info_value) {
985
-
986
-                    switch ($company_info_key) {
987
-                        case 'company_rcs':
988
-                            $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : '';
989
-                            break;
990
-                        case 'company_capital':
991
-                            $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : '';
992
-                            break;
993
-                        case 'company_siren':
994
-                            $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : '';
995
-                            break;
996
-                        case 'company_siret':
997
-                            $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : '';
998
-                            break;
999
-                        case 'company_tva_intra':
1000
-                            $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : '';
1001
-                            break;
1002
-                        default:
1003
-                            $data = $company_info_value;
1004
-                            break;
1005
-                    }
1006
-                    $tpl_component[strtoupper($company_info_key)] = $data;
1007
-                }
1008
-                $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common');
1009
-            }
1010
-            return $output;
1011
-        }
1012
-
1013
-        /**
1014
-         * Check product price
1015
-         * @param float $price_ht
1016
-         * @param float $price_ati
1017
-         * @param float $tva_amount
1018
-         * @param float $tva_rate
1019
-         * @param id $product_id
1020
-         * @param string $invoice_ref
1021
-         */
1022
-        public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id)
1023
-        {
1024
-            $checking = true;
1025
-            $error_percent = 1;
1026
-
1027
-            /** Check VAT Amount **/
1028
-            $formatted_tva_amount = number_format($tva_amount, 2, '.', '');
1029
-            $formatted_price_ht = number_format($price_ht, 2, '.', '');
1030
-            $formatted_price_ati = number_format($price_ati, 2, '.', '');
1031
-            $calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100));
1032
-            $unformatted = $formatted_price_ati - $calculated_price_excluding_tax;
1033
-            $checked_tva_amount = number_format($unformatted, 2, '.', '');
1034
-
1035
-            if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) {
1036
-                $error_infos = array();
1037
-                $error_infos['real_datas']['price_ati'] = $formatted_price_ati;
1038
-                $error_infos['real_datas']['price_ht'] = $formatted_price_ht;
1039
-                $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount;
1040
-
1041
-                $error_infos['corrected_data'] = $checked_tva_amount;
1042
-                self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos);
1043
-                $checking = false;
1044
-            }
1045
-
1046
-            /** Check price ati **/
1047
-            $checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100));
1048
-            if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) {
1049
-                self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id);
1050
-                $checking = false;
1051
-            }
1052
-
1053
-            return $checking;
1054
-        }
1055
-
1056
-        /**
1057
-         * Alert administrator when have invoice error
1058
-         * @param string $invoice_ref
1059
-         * @param string $object
1060
-         * @param unknown_type $product_id
1061
-         */
1062
-        public function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array())
1063
-        {
1064
-            $wpshop_email_option = get_option('wpshop_emails');
1065
-            if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) {
1066
-                $headers = "MIME-Version: 1.0\r\n";
1067
-                $headers .= "Content-type: text/html; charset=UTF-8\r\n";
1068
-                $headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n";
1069
-                $message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>';
1070
-                $message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>';
1071
-                $message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>';
1072
-                $message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>';
1073
-
1074
-                if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) {
1075
-                    $message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>';
1076
-                    foreach ($errors_infos['real_datas'] as $k => $errors_info) {
1077
-                        $message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>';
1078
-                    }
1079
-                    $message .= '</ul>';
1080
-                    if (!empty($errors_infos['corrected_data'])) {
1081
-                        $message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data'];
1082
-                    }
1083
-                }
1084
-
1085
-                wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers);
1086
-            }
1087
-        }
1088
-
1089
-        /**
1090
-         * Force Invoice Generation. Function called on save order custom informations action
1091
-         * @param array $order_metadata
1092
-         * @param array $posted_datas
1093
-         * @return string
1094
-         */
1095
-        public function force_invoice_generation_on_order($order_metadata, $posted_datas)
1096
-        {
1097
-            if (!empty($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') {
1098
-                $order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']);
1099
-            }
1100
-            return $order_metadata;
1101
-        }
1102
-
1103
-        public function wpshop_quotation_payment_partial_validation($input)
1104
-        {
1105
-            return $input;
1106
-        }
1107
-
1108
-        public function wpshop_quotation_payment_partial()
1109
-        {
1110
-            $output = '';
1111
-
1112
-            $partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array()));
1113
-
1114
-            $partial_for_quotation_is_activate = false;
1115
-            if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) {
1116
-                $partial_for_quotation_is_activate = true;
1117
-            }
1118
-
1119
-            $output .= '
356
+					//                         $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop');
357
+					//                         $is_partial_payment = true;
358
+					//                     }
359
+
360
+					if ($bon_colisage) {
361
+						$tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop');
362
+					}
363
+
364
+					$tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null);
365
+					if ($bon_colisage) {
366
+						$tpl_component['INVOICE_ORDER_INVOICE_REF'] = '';
367
+					}
368
+					$tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']);
369
+					$tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true));
370
+
371
+					/** Validate period for Quotation **/
372
+					if ($is_quotation) {
373
+						$quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']);
374
+					} else {
375
+						$tpl_component['INVOICE_VALIDATE_TIME'] = '';
376
+					}
377
+
378
+					$tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME'];
379
+
380
+					$tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : '';
381
+
382
+					// Sender & receiver addresses
383
+					$tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part();
384
+					$tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage);
385
+
386
+					$tpl_component['INVOICE_TRACKING'] = '';
387
+					$first = false;
388
+					if (!empty($order_postmeta['order_trackingNumber'])) {
389
+						$tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber'];
390
+						$first = true;
391
+					}
392
+					if (!empty($order_postmeta['order_trackingLink'])) {
393
+						if (!$first) {
394
+							$tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink'];
395
+						} else {
396
+							$tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink'];
397
+						}
398
+					}
399
+
400
+					/** Items Tab **/
401
+					$order_tva = array();
402
+					if ($bon_colisage) {
403
+						$tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common');
404
+					} else {
405
+						$tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common');
406
+						//if ( !$is_quotation ) {
407
+						/** Check if products have discounts **/
408
+						if (!empty($order_postmeta['order_items']) && !$is_partial_payment) {
409
+							foreach ($order_postmeta['order_items'] as $item_id => $item) {
410
+								if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) {
411
+									$discounts_exists = true;
412
+								}
413
+							}
414
+						}
415
+
416
+						if ($discounts_exists) {
417
+							$tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common');
418
+						}
419
+
420
+						//}
421
+					}
422
+
423
+					$total_discounted = 0;
424
+					$tpl_component['INVOICE_ROWS'] = '';
425
+
426
+					if (!$is_partial_payment) {
427
+						if (!empty($order_postmeta['order_items'])) {
428
+							foreach ($order_postmeta['order_items'] as $item_id => $item) {
429
+								$sub_tpl_component = array();
430
+								$count_products += $item['item_qty'];
431
+								$barcode = get_post_meta($item['item_id'], '_barcode', true);
432
+								if (empty($barcode)) {
433
+									$product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true);
434
+									$barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : '';
435
+
436
+									if (empty($barcode)) {
437
+										$product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
438
+										$att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code');
439
+										$query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']);
440
+										$barcode = $wpdb->get_var($query);
441
+									}
442
+								}
443
+								$sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-';
444
+
445
+								$sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref'];
446
+
447
+								/** Item name **/
448
+								$is_variation = false;
449
+								if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
450
+									$is_variation = true;
451
+									$parent_def = wpshop_products::get_parent_variation($item['item_id']);
452
+									if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
453
+										$parent_post = $parent_def['parent_post'];
454
+										$item_parent_id = $parent_post->ID;
455
+										$item_title = $parent_post->post_title;
456
+									}
457
+								} else {
458
+									$item_title = $item['item_name'];
459
+								}
460
+								$sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title;
461
+								/**    Get attribute order for current product    */
462
+								$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
463
+								$output_order = array();
464
+								if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) {
465
+									foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
466
+										foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
467
+											if (!empty($attribute_def->code)) {
468
+												$output_order[$attribute_def->code] = $position;
469
+											}
470
+
471
+										}
472
+									}
473
+								}
474
+								$variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common');
475
+								ksort($variation_attribute_ordered['attribute_list']);
476
+								$detail_tpl_component['CART_PRODUCT_MORE_INFO'] = '';
477
+								foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
478
+									$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output;
479
+								}
480
+								$post_content = get_post_field('post_content', $item['item_id']);
481
+								if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/!empty($post_content) && false) {
482
+									if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) {
483
+										//$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>';
484
+									}
485
+									$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>';
486
+								}
487
+								$sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : '';
488
+								unset($detail_tpl_component);
489
+
490
+								$sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty'];
491
+								$sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', ''));
492
+								$sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', ''));
493
+								$sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', '');
494
+								$sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', '');
495
+								/** TVA **/
496
+								$sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', '');
497
+								$sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate'];
498
+
499
+								$sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', '');
500
+
501
+								/** Checking Rate amount **/
502
+								if (!$bon_colisage) {
503
+									$checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id);
504
+									if (!$checking) {
505
+										return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop');
506
+									}
507
+								}
508
+
509
+								if ($bon_colisage) {
510
+									$tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common');
511
+								} else {
512
+									if ($discounts_exists) {
513
+										$discounted_total_per_item = $item['item_total_ht'];
514
+										/** Unit Discount **/
515
+										if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) {
516
+											$sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', '');
517
+											$sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', '');
518
+											$discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount'];
519
+										} else {
520
+											$sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
521
+											$sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
522
+										}
523
+
524
+										/** Global Discount **/
525
+										if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) {
526
+											$sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', '');
527
+											$sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', '');
528
+											$discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount'];
529
+										} else {
530
+											$sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
531
+											$sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
532
+										}
533
+
534
+										$total_discounted += $discounted_total_per_item;
535
+										/** Total HT Discounted **/
536
+										$sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', '');
537
+
538
+										$tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common');
539
+									} else {
540
+										$tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
541
+									}
542
+								}
543
+								unset($sub_tpl_component);
544
+
545
+								/** Check TVA **/
546
+								if (empty($order_tva[$item['item_tva_rate']])) {
547
+									$order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount'];
548
+								} else {
549
+									$order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount'];
550
+								}
551
+
552
+							}
553
+						}
554
+
555
+						/** Display Partials payments **/
556
+						$total_partial_payment = 0;
557
+						$last_payment = 0;
558
+						$order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : '';
559
+						if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) {
560
+							foreach ($order_postmeta['order_payment']['received'] as $received_payment) {
561
+								if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) {
562
+									if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) {
563
+										$sub_tpl_component = array();
564
+										$sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref'];
565
+
566
+										/** Item name **/
567
+										$sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']);
568
+										$sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = '';
569
+										$sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1;
570
+										$sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
571
+										$sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
572
+										$sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
573
+
574
+										/** TVA **/
575
+										$sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '');
576
+										$sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0;
577
+										$sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
578
+
579
+										if ($discounts_exists) {
580
+											$sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
581
+											$sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
582
+											$sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
583
+											$sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
584
+											$sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
585
+
586
+											$tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common');
587
+										} else {
588
+											$tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
589
+										}
590
+									}
591
+
592
+									unset($sub_tpl_component);
593
+									$total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0;
594
+								} else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) {
595
+									$last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0;
596
+								}
597
+
598
+							}
599
+						}
600
+					} else {
601
+						/** Display Partials payments **/
602
+						$total_partial_payment = 0;
603
+						$last_payment = 0;
604
+						if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) {
605
+							foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) {
606
+								if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) {
607
+									$sub_tpl_component = array();
608
+									$sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref'];
609
+									/** Item name **/
610
+									$sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1);
611
+									$sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = '';
612
+									$sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1;
613
+									$sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', '');
614
+									$sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
615
+									$sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', '');
616
+									/** TVA **/
617
+									$sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '');
618
+									$sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0;
619
+									$sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', '');
620
+									$tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
621
+									unset($sub_tpl_component);
622
+									$total_partial_payment += $received_payment['received_amount'];
623
+								}
624
+							}
625
+						}
626
+					}
627
+
628
+					/** Summary of order **/
629
+					$summary_tpl_component = array();
630
+					$tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = '';
631
+					if (!$bon_colisage) {
632
+						if (!empty($order_tva)) {
633
+							foreach ($order_tva as $tax_rate => $tax_amount) {
634
+								if ($tax_amount > 0) {
635
+									$tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate;
636
+									$sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%');
637
+									$sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency();
638
+									$summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
639
+									unset($sub_tpl_component);
640
+								} elseif ($is_partial_payment) {
641
+									$tax_rate = 0;
642
+									$tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency();
643
+									$sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%');
644
+									$sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency();
645
+									$summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
646
+									unset($sub_tpl_component);
647
+								}
648
+							}
649
+						}
650
+
651
+						/** If Discount Exist **/
652
+						// Checking Discounts on order
653
+						if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) {
654
+							$discounts_exists = true;
655
+							// Calcul discount on Order
656
+							switch ($order_postmeta['order_discount_type']) {
657
+								case 'amount':
658
+									$total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '');
659
+									break;
660
+								case 'percent':
661
+									$total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100);
662
+									break;
663
+							}
664
+						}
665
+						if (!empty($total_discounted) && $discounts_exists) {
666
+							$sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop');
667
+							$sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency();
668
+							$summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
669
+							unset($sub_tpl_component);
670
+						} else {
671
+							$summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = '';
672
+						}
673
+
674
+						$shipping_cost = 0;
675
+						if (!$is_partial_payment) {
676
+							if (!empty($order_postmeta['order_shipping_cost'])) {
677
+								$shipping_cost = $order_postmeta['order_shipping_cost'];
678
+							}
679
+						}
680
+						$price_piloting = get_option('wpshop_shop_price_piloting', 'TTC');
681
+						$shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100));
682
+						$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', '');
683
+						$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', '');
684
+						//$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' );
685
+
686
+						$summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' );
687
+						$summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', '');
688
+
689
+						$summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', '');
690
+
691
+						$total_payment = 0;
692
+
693
+						/** Amount paid **/
694
+						if (empty($order_postmeta['order_invoice_ref'])) {
695
+							foreach ($order_postmeta['order_payment']['received'] as $key => $value) {
696
+								if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) {
697
+									$total_payment = number_format($value['received_amount'], 2, ',', '');
698
+								}
699
+							}
700
+						} else {
701
+							$total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total'];
702
+						}
703
+
704
+						$sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop');
705
+						$sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency();
706
+						//$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ?  number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency();
707
+						$summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
708
+						unset($sub_tpl_component);
709
+
710
+						$sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop');
711
+						$sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products;
712
+						$summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
713
+						unset($sub_tpl_component);
714
+
715
+						/** If Discount Exist **/
716
+						if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) {
717
+							$tpl_discount_component = array();
718
+							$tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', '');
719
+
720
+							$tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', '');
721
+							$summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common');
722
+							unset($tpl_discount_component);
723
+						} else {
724
+							$summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = '';
725
+						}
726
+
727
+						$summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop');
728
+
729
+						$tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common');
730
+						unset($summary_tpl_component);
731
+					}
732
+
733
+					/** IBAN Include on quotation **/
734
+					if ($is_quotation) {
735
+						/** If admin want to include his IBAN to quotation */
736
+						$iban_options = get_option('wpshop_paymentMethod_options');
737
+						$payment_options = get_option('wps_payment_mode');
738
+						if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') {
739
+							if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) {
740
+								$tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>';
741
+								$tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>';
742
+								$tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>';
743
+								$tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>';
744
+								$tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>';
745
+							}
746
+						} else {
747
+							$tpl_component['IBAN_INFOS'] = '';
748
+						}
749
+					} else {
750
+						$tpl_component['IBAN_INFOS'] = '';
751
+					}
752
+
753
+					/** Received payements **/
754
+					if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) {
755
+						$tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id);
756
+					} else {
757
+						$tpl_component['RECEIVED_PAYMENT'] = '';
758
+					}
759
+
760
+					/** Invoice footer **/
761
+					$tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice();
762
+
763
+					$output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common');
764
+				} else {
765
+					$output = __('No order information has been found', 'wpshop');
766
+				}
767
+			} else {
768
+				$output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop');
769
+			}
770
+			return $output;
771
+		}
772
+
773
+		/**
774
+		 * Return the payment list part
775
+		 * @param integer $order_id
776
+		 * @return string
777
+		 */
778
+		public static function generate_received_payment_part($order_id)
779
+		{
780
+			$date_ouput_format = get_option('date_format') . ' ' . get_option('time_format');
781
+			$output = '';
782
+			$tpl_component = array();
783
+			$tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = '';
784
+			if (!empty($order_id)) {
785
+				$order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
786
+				if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) {
787
+					$wps_payment_option = get_option('wps_payment_mode');
788
+					foreach ($order_postmeta['order_payment']['received'] as $payment) {
789
+						if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) {
790
+							$sub_tpl_component = array();
791
+							$sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0;
792
+							$sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : '';
793
+							$sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : ''));
794
+							$sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : '';
795
+							$sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : '';
796
+							$tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common');
797
+						}
798
+					}
799
+				}
800
+				$output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common');
801
+				unset($tpl_component);
802
+			}
803
+			return $output;
804
+		}
805
+
806
+		/** Return the validity period of a quotation **/
807
+		public static function quotation_validate_period($quotation_date)
808
+		{
809
+			$quotation_options = get_option('wpshop_quotation_validate_time');
810
+			if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) {
811
+				$timestamp_quotation = strtotime($quotation_date);
812
+				$timestamp_validity_date_quotation = 0;
813
+				$query = '';
814
+				$date = '';
815
+				global $wpdb;
816
+				switch ($quotation_options['time_type']) {
817
+					case 'day':
818
+						$query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s DAY)", $quotation_date, $quotation_options['number']);
819
+						break;
820
+					case 'month':
821
+						$query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s MONTH)", $quotation_date, $quotation_options['number']);
822
+						break;
823
+					case 'year':
824
+						$query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s YEAR)", $quotation_date, $quotation_options['number']);
825
+						break;
826
+					default:
827
+						$query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL '15' DAY)", $quotation_date);
828
+						break;
829
+				}
830
+				if ($query != null) {
831
+					$date = mysql2date('d F Y', $wpdb->get_var($query), true);
832
+				}
833
+				return sprintf(__('Quotation validity date %s', 'wpshop'), $date);
834
+			}
835
+		}
836
+
837
+		/**
838
+		 * Generate HTML invoice to be sended by email
839
+		 * @param integer $order_id
840
+		 * @param string $invoice_ref
841
+		 * @return string
842
+		 */
843
+		public static function generate_invoice_for_email($order_id, $invoice_ref = '')
844
+		{
845
+			/** Generate the PDF file for the invoice **/
846
+			$is_ok = false;
847
+			if (!empty($invoice_ref)) {
848
+				require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php';
849
+				try {
850
+					$html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref);
851
+					$html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
852
+					$html2pdf = new HTML2PDF('P', 'A4', 'fr');
853
+
854
+					$html2pdf->setDefaultFont('Arial');
855
+					$html2pdf->writeHTML($html_content);
856
+					$html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F');
857
+					$is_ok = true;
858
+				} catch (HTML2PDF_exception $e) {
859
+					echo $e;
860
+					exit;
861
+				}
862
+			}
863
+			return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : '';
864
+		}
865
+
866
+		/**
867
+		 * Generate Sender part invoice template
868
+		 * @return Ambigous <string, string>
869
+		 */
870
+		public static function generate_invoice_sender_part()
871
+		{
872
+			$output = '';
873
+			$company = get_option('wpshop_company_info', array());
874
+			$emails = get_option('wpshop_emails', array());
875
+			if (!empty($company)) {
876
+				$tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : '';
877
+				$tpl_component['COMPANY_WEBSITE'] = get_option('siteurl');
878
+				foreach ($company as $company_info_key => $company_info_value) {
879
+					switch ($company_info_key) {
880
+						case 'company_rcs':
881
+							$data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : '';
882
+							break;
883
+						case 'company_capital':
884
+							$data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : '';
885
+							break;
886
+						case 'company_siren':
887
+							$data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : '';
888
+							break;
889
+						case 'company_siret':
890
+							$data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : '';
891
+							break;
892
+						case 'company_tva_intra':
893
+							$data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : '';
894
+							break;
895
+						case 'company_legal_statut':
896
+							$array_state_compagny = wpshop_company_options::get_legal_status();
897
+							$data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop');
898
+							break;
899
+						default:
900
+							$data = $company_info_value;
901
+							break;
902
+					}
903
+					$tpl_component[strtoupper($company_info_key)] = $data;
904
+				}
905
+				$output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common');
906
+			}
907
+			return $output;
908
+		}
909
+
910
+		/**
911
+		 * Generate Receiver part template
912
+		 * @param unknown_type $order_id
913
+		 * @param unknown_type $bon_colisage
914
+		 * @return Ambigous <string, string>
915
+		 */
916
+		public static function generate_receiver_part($order_id, $bon_colisage = false)
917
+		{
918
+			$output = '';
919
+			$order_customer_postmeta = get_post_meta($order_id, '_order_info', true);
920
+			$order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
921
+
922
+			if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) {
923
+				$address_info = $order_customer_postmeta['shipping']['address'];
924
+			} else {
925
+				if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) {
926
+					$address_info = $order_customer_postmeta['billing']['address'];
927
+				} else {
928
+					$address_info = array();
929
+				}
930
+			}
931
+
932
+			if (!empty($order_customer_postmeta) && !empty($address_info)) {
933
+				$default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY');
934
+				foreach ($default_address_attributes as $default_address_attribute) {
935
+					$tpl_component[$default_address_attribute] = '';
936
+				}
937
+
938
+				foreach ($address_info as $order_customer_info_key => $order_customer_info_value) {
939
+					$tpl_component[strtoupper($order_customer_info_key)] = '';
940
+					if ($order_customer_info_key == 'civility') {
941
+						global $wpdb;
942
+						$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value);
943
+						$civility = $wpdb->get_row($query);
944
+						$tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : '';
945
+					} else if ($order_customer_info_key == 'country') {
946
+						foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) {
947
+							if ($order_customer_info_value == $key) {
948
+								$tpl_component[strtoupper($order_customer_info_key)] = $value;
949
+							}
950
+						}
951
+					} elseif ($order_customer_info_key == 'phone') {
952
+						$tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : '';
953
+					} else {
954
+						$tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : '';
955
+					}
956
+				}
957
+
958
+				if (empty($tpl_component['PHONE'])) {
959
+					$tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : '';
960
+				}
961
+
962
+				if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) {
963
+					$user_info = get_userdata($order_postmeta['customer_id']);
964
+					$tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : '';
965
+				}
966
+
967
+				$output = wpshop_display::display_template_element('invoice_receiver_formatted_address', $tpl_component, array(), 'common');
968
+			}
969
+			return $output;
970
+		}
971
+
972
+		/**
973
+		 * Genrate Footer invoice
974
+		 * @return Ambigous <string, string>
975
+		 */
976
+		public static function generate_footer_invoice()
977
+		{
978
+			$output = '';
979
+			$company = get_option('wpshop_company_info', array());
980
+			$emails = get_option('wpshop_emails', array());
981
+			if (!empty($company)) {
982
+				$tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : '';
983
+				$tpl_component['COMPANY_WEBSITE'] = site_url();
984
+				foreach ($company as $company_info_key => $company_info_value) {
985
+
986
+					switch ($company_info_key) {
987
+						case 'company_rcs':
988
+							$data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : '';
989
+							break;
990
+						case 'company_capital':
991
+							$data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : '';
992
+							break;
993
+						case 'company_siren':
994
+							$data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : '';
995
+							break;
996
+						case 'company_siret':
997
+							$data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : '';
998
+							break;
999
+						case 'company_tva_intra':
1000
+							$data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : '';
1001
+							break;
1002
+						default:
1003
+							$data = $company_info_value;
1004
+							break;
1005
+					}
1006
+					$tpl_component[strtoupper($company_info_key)] = $data;
1007
+				}
1008
+				$output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common');
1009
+			}
1010
+			return $output;
1011
+		}
1012
+
1013
+		/**
1014
+		 * Check product price
1015
+		 * @param float $price_ht
1016
+		 * @param float $price_ati
1017
+		 * @param float $tva_amount
1018
+		 * @param float $tva_rate
1019
+		 * @param id $product_id
1020
+		 * @param string $invoice_ref
1021
+		 */
1022
+		public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id)
1023
+		{
1024
+			$checking = true;
1025
+			$error_percent = 1;
1026
+
1027
+			/** Check VAT Amount **/
1028
+			$formatted_tva_amount = number_format($tva_amount, 2, '.', '');
1029
+			$formatted_price_ht = number_format($price_ht, 2, '.', '');
1030
+			$formatted_price_ati = number_format($price_ati, 2, '.', '');
1031
+			$calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100));
1032
+			$unformatted = $formatted_price_ati - $calculated_price_excluding_tax;
1033
+			$checked_tva_amount = number_format($unformatted, 2, '.', '');
1034
+
1035
+			if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) {
1036
+				$error_infos = array();
1037
+				$error_infos['real_datas']['price_ati'] = $formatted_price_ati;
1038
+				$error_infos['real_datas']['price_ht'] = $formatted_price_ht;
1039
+				$error_infos['real_datas']['tva_amount'] = $formatted_tva_amount;
1040
+
1041
+				$error_infos['corrected_data'] = $checked_tva_amount;
1042
+				self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos);
1043
+				$checking = false;
1044
+			}
1045
+
1046
+			/** Check price ati **/
1047
+			$checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100));
1048
+			if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) {
1049
+				self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id);
1050
+				$checking = false;
1051
+			}
1052
+
1053
+			return $checking;
1054
+		}
1055
+
1056
+		/**
1057
+		 * Alert administrator when have invoice error
1058
+		 * @param string $invoice_ref
1059
+		 * @param string $object
1060
+		 * @param unknown_type $product_id
1061
+		 */
1062
+		public function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array())
1063
+		{
1064
+			$wpshop_email_option = get_option('wpshop_emails');
1065
+			if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) {
1066
+				$headers = "MIME-Version: 1.0\r\n";
1067
+				$headers .= "Content-type: text/html; charset=UTF-8\r\n";
1068
+				$headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n";
1069
+				$message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>';
1070
+				$message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>';
1071
+				$message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>';
1072
+				$message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>';
1073
+
1074
+				if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) {
1075
+					$message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>';
1076
+					foreach ($errors_infos['real_datas'] as $k => $errors_info) {
1077
+						$message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>';
1078
+					}
1079
+					$message .= '</ul>';
1080
+					if (!empty($errors_infos['corrected_data'])) {
1081
+						$message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data'];
1082
+					}
1083
+				}
1084
+
1085
+				wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers);
1086
+			}
1087
+		}
1088
+
1089
+		/**
1090
+		 * Force Invoice Generation. Function called on save order custom informations action
1091
+		 * @param array $order_metadata
1092
+		 * @param array $posted_datas
1093
+		 * @return string
1094
+		 */
1095
+		public function force_invoice_generation_on_order($order_metadata, $posted_datas)
1096
+		{
1097
+			if (!empty($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') {
1098
+				$order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']);
1099
+			}
1100
+			return $order_metadata;
1101
+		}
1102
+
1103
+		public function wpshop_quotation_payment_partial_validation($input)
1104
+		{
1105
+			return $input;
1106
+		}
1107
+
1108
+		public function wpshop_quotation_payment_partial()
1109
+		{
1110
+			$output = '';
1111
+
1112
+			$partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array()));
1113
+
1114
+			$partial_for_quotation_is_activate = false;
1115
+			if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) {
1116
+				$partial_for_quotation_is_activate = true;
1117
+			}
1118
+
1119
+			$output .= '
1120 1120
 			<input type="checkbox" name="wpshop_payment_partial[for_quotation][activate]"' . ($partial_for_quotation_is_activate ? ' checked="checked"' : '') . ' id="wpshop_payment_partial_on_quotation_activation_state" /> <label for="wpshop_payment_partial_on_quotation_activation_state" >' . __('Activate partial command for quotations', 'wpshop') . '</label><a href="#" title="' . __('If you want that customer pay a part o f total amount of there order, check this box then fill fields below', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>
1121 1121
 			<div class="wpshop_partial_payment_quotation_config_container' . ($partial_for_quotation_is_activate ? '' : ' wpshopHide') . '" id="wpshop_partial_payment_quotation_config_container" >
1122 1122
 				<div class="alignleft" >
@@ -1132,13 +1132,13 @@  discard block
 block discarded – undo
1132 1132
 				</div>
1133 1133
 			</div>';
1134 1134
 
1135
-            echo $output;
1136
-        }
1137
-    }
1135
+			echo $output;
1136
+		}
1137
+	}
1138 1138
 
1139 1139
 }
1140 1140
 
1141 1141
 /**    Instanciate the module utilities if not    */
1142 1142
 if (class_exists("wpshop_modules_billing")) {
1143
-    $wpshop_modules_billing = new wpshop_modules_billing();
1143
+	$wpshop_modules_billing = new wpshop_modules_billing();
1144 1144
 }
Please login to merge, or discard this patch.
includes/modules/wpshop_prices/wpshop_prices.php 1 patch
Spacing   +325 added lines, -325 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /**
4 4
  * WPSHOP Prices bootstrap file
@@ -9,17 +9,17 @@  discard block
 block discarded – undo
9 9
  *
10 10
  */
11 11
 
12
-if ( !defined( 'WPSHOP_VERSION' ) ) {
13
-	die( __("You are not allowed to use this service.", 'wpshop') );
12
+if (!defined('WPSHOP_VERSION')) {
13
+	die(__("You are not allowed to use this service.", 'wpshop'));
14 14
 }
15
-if ( !class_exists("wpshop_prices") ) {
15
+if (!class_exists("wpshop_prices")) {
16 16
 	class wpshop_prices {
17 17
 
18 18
 		function __construct() {
19 19
 			add_action('wsphop_options', array('wpshop_prices', 'declare_options'));
20 20
 		}
21 21
 
22
-		public static function declare_options () {
22
+		public static function declare_options() {
23 23
 			register_setting('wpshop_options', 'wpshop_catalog_product_option', array('wpshop_prices', 'wpshop_options_validate_prices'));
24 24
 			add_settings_field('wpshop_catalog_product_option_discount', __('Activate the discount on products', 'wpshop'), array('wpshop_prices', 'wpshop_activate_discount_prices_field'), 'wpshop_catalog_product_option', 'wpshop_catalog_product_section');
25 25
 		}
@@ -29,37 +29,37 @@  discard block
 block discarded – undo
29 29
 
30 30
 			/** Price attribute Def **/
31 31
 			$price_piloting_option = get_option('wpshop_shop_price_piloting');
32
-			$price_attribute_def = wpshop_attributes::getElement( ( (!empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? 'price_ht' : 'product_price' ), "'valid'", 'code');
32
+			$price_attribute_def = wpshop_attributes::getElement(((!empty($price_piloting_option) && $price_piloting_option == 'HT') ? 'price_ht' : 'product_price'), "'valid'", 'code');
33 33
 
34 34
 			/** Discount attributes **/
35
-			$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s OR code = %s OR  code = %s OR code = %s OR code = %s', 'discount_amount', 'discount_rate', 'special_price', 'special_from', 'special_to' );
35
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s OR  code = %s OR code = %s OR code = %s', 'discount_amount', 'discount_rate', 'special_price', 'special_from', 'special_to');
36 36
 			$discount_attributes = $wpdb->get_results($query);
37 37
 
38 38
 			/** Check if discount is actived **/
39
-			if ( !empty( $input) && !empty($input['discount']) ) {
39
+			if (!empty($input) && !empty($input['discount'])) {
40 40
 				/** Activate the attributes **/
41
-				if ( !empty($discount_attributes) ) {
42
-					foreach ( $discount_attributes as $discount_attribute ) {
43
-						$update = $wpdb->prepare('UPDATE ' .WPSHOP_DBT_ATTRIBUTE. ' SET status = "valid" WHERE code = %s', $discount_attribute->code);
41
+				if (!empty($discount_attributes)) {
42
+					foreach ($discount_attributes as $discount_attribute) {
43
+						$update = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET status = "valid" WHERE code = %s', $discount_attribute->code);
44 44
 						$wpdb->query($update);
45 45
 					}
46 46
 				}
47 47
 
48 48
 				/** Affect discount attributes to All Attributes Set section where there is a Price attribute **/
49
-				$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_id = %d', $price_attribute_def->id);
50
-				$attributes_sections = $wpdb->get_results( $query );
51
-				if ( !empty($attributes_sections) ) {
52
-					foreach ( $attributes_sections as $attributes_section ) {
49
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %d', $price_attribute_def->id);
50
+				$attributes_sections = $wpdb->get_results($query);
51
+				if (!empty($attributes_sections)) {
52
+					foreach ($attributes_sections as $attributes_section) {
53 53
 						/** Check the Max Position for the Attribute section */
54
-						$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id);
55
-						$max_position = $wpdb->get_var( $query );
56
-						$max_position = ( !empty($max_position) ) ? $max_position : 0;
54
+						$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id);
55
+						$max_position = $wpdb->get_var($query);
56
+						$max_position = (!empty($max_position)) ? $max_position : 0;
57 57
 						/** Affect the discount attributes **/
58
-						foreach ( $discount_attributes as $discount_attribute) {
59
-							$query = $wpdb->prepare(' SELECT COUNT(*) AS count_attributes_affect FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s AND attribute_id = %d', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id, $discount_attribute->id);
60
-							$count_attribute_affectation = $wpdb->get_row( $query );
61
-							if ( !empty($count_attribute_affectation) && ( empty($count_attribute_affectation->count_attributes_affect) || $count_attribute_affectation->count_attributes_affect == 0 ) ) {
62
-								$result = $wpdb->insert( WPSHOP_DBT_ATTRIBUTE_DETAILS, array( 'status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id, 'position' => $max_position) );
58
+						foreach ($discount_attributes as $discount_attribute) {
59
+							$query = $wpdb->prepare(' SELECT COUNT(*) AS count_attributes_affect FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s AND attribute_id = %d', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id, $discount_attribute->id);
60
+							$count_attribute_affectation = $wpdb->get_row($query);
61
+							if (!empty($count_attribute_affectation) && (empty($count_attribute_affectation->count_attributes_affect) || $count_attribute_affectation->count_attributes_affect == 0)) {
62
+								$result = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id, 'position' => $max_position));
63 63
 								$max_position += 1;
64 64
 							}
65 65
 						}
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 			}
69 69
 			else {
70 70
 				/** Desactivate Discount Attributes **/
71
-				if ( !empty($discount_attributes) ) {
72
-					foreach ( $discount_attributes as $discount_attribute ) {
73
-						$update = $wpdb->prepare('UPDATE ' .WPSHOP_DBT_ATTRIBUTE. ' SET status = "notused" WHERE code = %s', $discount_attribute->code);
71
+				if (!empty($discount_attributes)) {
72
+					foreach ($discount_attributes as $discount_attribute) {
73
+						$update = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET status = "notused" WHERE code = %s', $discount_attribute->code);
74 74
 						$wpdb->query($update);
75 75
 					}
76 76
 				}
77 77
 
78 78
 				/** Delete the Price attribute set section affectation **/
79
-				$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_id = %d', $price_attribute_def->id);
80
-				$attributes_sections = $wpdb->get_results( $query );
81
-				if ( !empty($attributes_sections) ) {
82
-					foreach ( $attributes_sections as $attributes_section ) {
79
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %d', $price_attribute_def->id);
80
+				$attributes_sections = $wpdb->get_results($query);
81
+				if (!empty($attributes_sections)) {
82
+					foreach ($attributes_sections as $attributes_section) {
83 83
 						/** Affect the discount attributes **/
84
-						foreach ( $discount_attributes as $discount_attribute) {
85
-							$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_DETAILS, array( 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id ) );
84
+						foreach ($discount_attributes as $discount_attribute) {
85
+							$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id));
86 86
 						}
87 87
 					}
88 88
 				}
@@ -94,72 +94,72 @@  discard block
 block discarded – undo
94 94
 		public static function wpshop_activate_discount_prices_field() {
95 95
 			$product_discount_option = get_option('wpshop_catalog_product_option');
96 96
 
97
-			$output  = '<input type="checkbox" id="wpshop_catalog_product_option_discount" name="wpshop_catalog_product_option[discount]" ' .( (!empty($product_discount_option) && !empty($product_discount_option['discount'])) ? 'checked="checked"' : '' ). ' />';
98
-			$output .= '<a class="wpshop_infobulle_marker" title="' .__('Activate the possibility to create discount on products', 'wpshop'). '" href="#">?</a>';
97
+			$output  = '<input type="checkbox" id="wpshop_catalog_product_option_discount" name="wpshop_catalog_product_option[discount]" ' . ((!empty($product_discount_option) && !empty($product_discount_option['discount'])) ? 'checked="checked"' : '') . ' />';
98
+			$output .= '<a class="wpshop_infobulle_marker" title="' . __('Activate the possibility to create discount on products', 'wpshop') . '" href="#">?</a>';
99 99
 			echo $output;
100 100
 		}
101 101
 
102
-		public static function check_product_price( $product, $cart = false ) {
102
+		public static function check_product_price($product, $cart = false) {
103 103
 			$price_infos = array();
104 104
 			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
105
-			if ( !empty($product) ) {
106
-				if ( $cart ) {
107
-					$discount_config = self::check_discount_for_product($product['product_id'] );
108
-					if ( !empty($discount_config) ) {
105
+			if (!empty($product)) {
106
+				if ($cart) {
107
+					$discount_config = self::check_discount_for_product($product['product_id']);
108
+					if (!empty($discount_config)) {
109 109
 						$product['price_ttc_before_discount'] = $product['product_price'];
110 110
 						$product['price_ht_before_discount'] = $product['price_ht'];
111 111
 
112
-						if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) {
113
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
114
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
115
-							$product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100);
112
+						if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
113
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
114
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
115
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
116 116
 						}
117
-						elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
118
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
119
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value'];
120
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
117
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
118
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] - $discount_config['value']) : (($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100));
119
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value'];
120
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
121 121
 
122 122
 						}
123
-						elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
124
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 -  $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
125
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) );
126
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
123
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
124
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100)) : (($product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100));
125
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100));
126
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
127 127
 
128 128
 						}
129 129
 
130 130
 
131
-						$price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 2, '.', '') : number_format((float)$product['product_price'], 2, '.', '');
132
-						$price_infos['et'] = ( !empty($product['price_ht_before_discount'] ) ) ? number_format((float)$product['price_ht_before_discount'], 2, '.', '') : number_format((float)$product['price_ht'], 2, '.', '');
133
-						$price_infos['tva'] = $price_infos['et'] * ( $product['tx_tva'] / 100);
131
+						$price_infos['ati'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['price_ttc_before_discount'], 2, '.', '') : number_format((float)$product['product_price'], 2, '.', '');
132
+						$price_infos['et'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht_before_discount'], 2, '.', '') : number_format((float)$product['price_ht'], 2, '.', '');
133
+						$price_infos['tva'] = $price_infos['et'] * ($product['tx_tva'] / 100);
134 134
 
135
-						$price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount'])  && !empty($product['price_ht_before_discount'] ) ) ? true : false;
136
-						$price_infos['discount']['discount_ati_price'] = ( !empty($product['price_ttc_before_discount']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
137
-						$price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht_before_discount']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0;
138
-						$price_infos['discount']['discount_tva'] = ( !empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount']) ) ? number_format( ($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0;
135
+						$price_infos['discount']['discount_exist'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? true : false;
136
+						$price_infos['discount']['discount_ati_price'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
137
+						$price_infos['discount']['discount_et_price'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht'], 2, '.', '') : 0;
138
+						$price_infos['discount']['discount_tva'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? number_format(($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0;
139 139
 					}
140 140
 					else {
141
-						$price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
142
-						$price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
143
-						$price_infos['tva'] =  ( !empty($product['tva'] ) ) ? $product['tva'] : 0;
141
+						$price_infos['ati'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
142
+						$price_infos['et'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
143
+						$price_infos['tva'] = (!empty($product['tva'])) ? $product['tva'] : 0;
144 144
 					}
145 145
 
146 146
 
147 147
 				}
148 148
 				else {
149
-					if ( !empty( $product['price_ttc_before_discount']) && !empty( $product['price_ht_before_discount'] ) ) {
150
-						$price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount'])  && !empty($product['price_ht_before_discount'] ) ) ? true : false;
151
-						$price_infos['discount']['discount_ati_price'] = ( !empty($product['product_price']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
152
-						$price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0;
153
-						$price_infos['discount']['discount_tva'] = ( !empty($product['tva']) ) ? $product['tva'] : 0;
154
-
155
-						$price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0;
156
-						$price_infos['et'] = ( !empty($product['price_ht_before_discount']) ) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0;
157
-						$price_infos['tva'] =  $price_infos['ati'] - $price_infos['et'];
149
+					if (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) {
150
+						$price_infos['discount']['discount_exist'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? true : false;
151
+						$price_infos['discount']['discount_ati_price'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
152
+						$price_infos['discount']['discount_et_price'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 2, '.', '') : 0;
153
+						$price_infos['discount']['discount_tva'] = (!empty($product['tva'])) ? $product['tva'] : 0;
154
+
155
+						$price_infos['ati'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0;
156
+						$price_infos['et'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0;
157
+						$price_infos['tva'] = $price_infos['ati'] - $price_infos['et'];
158 158
 					}
159 159
 					else {
160
-						$price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
161
-						$price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
162
-						$price_infos['tva'] =  ( !empty($product['tva'] ) ) ? $product['tva'] : 0;
160
+						$price_infos['ati'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
161
+						$price_infos['et'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
162
+						$price_infos['tva'] = (!empty($product['tva'])) ? $product['tva'] : 0;
163 163
 					}
164 164
 				}
165 165
 			}
@@ -170,65 +170,65 @@  discard block
 block discarded – undo
170 170
 			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
171 171
 // 			$wpshop_price_piloting_option = 'TTC';
172 172
  			/** Price for Mini-output **/
173
-			if( !empty($product['product_id']) && !$price_checking_done ) {
173
+			if (!empty($product['product_id']) && !$price_checking_done) {
174 174
 
175 175
 				/** Checking if it's a product with variation **/
176
-				$variation_option_checking = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
176
+				$variation_option_checking = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
177 177
 
178
-				if( !empty($variation_option_checking) ) {
179
-					$variations_exists = wpshop_products::get_variation( $product['product_id'], 'publish' );
178
+				if (!empty($variation_option_checking)) {
179
+					$variations_exists = wpshop_products::get_variation($product['product_id'], 'publish');
180 180
 				}
181 181
 
182
-				if( !empty($variation_option_checking) && !empty($variations_exists) ) {
183
-					if ( !empty( $variation_option_checking['attributes']) ) {
184
-						foreach( $variation_option_checking['attributes'] as $attribute ) {
182
+				if (!empty($variation_option_checking) && !empty($variations_exists)) {
183
+					if (!empty($variation_option_checking['attributes'])) {
184
+						foreach ($variation_option_checking['attributes'] as $attribute) {
185 185
 							$selected_variation[$attribute] = 0;
186
-							if( !empty( $variation_option_checking['options'] ) && !empty( $variation_option_checking['options']['attributes_default_value'] ) && array_key_exists( $attribute, $variation_option_checking['options']['attributes_default_value']) ){
187
-								if ( $variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') {
186
+							if (!empty($variation_option_checking['options']) && !empty($variation_option_checking['options']['attributes_default_value']) && array_key_exists($attribute, $variation_option_checking['options']['attributes_default_value'])) {
187
+								if ($variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') {
188 188
 									$selected_variation[$attribute] = $variation_option_checking['options']['attributes_default_value'][$attribute];
189 189
 								}
190 190
 							}
191 191
 						}
192 192
 					}
193
-					if ( !empty($selected_variation) ) {
194
-						$product_with_variation = wpshop_products::get_variation_by_priority( $selected_variation, $product['product_id'] );
193
+					if (!empty($selected_variation)) {
194
+						$product_with_variation = wpshop_products::get_variation_by_priority($selected_variation, $product['product_id']);
195 195
 					}
196
-					if( empty($product_with_variation[$product['product_id']]['variations']) ) {
196
+					if (empty($product_with_variation[$product['product_id']]['variations'])) {
197 197
 						$product_with_variation[$product['product_id']]['variations'] = array();
198 198
 					}
199
-					if ( !empty($product_with_variation[$product['product_id']]['variation_priority']) ) {
200
-						$product =  wpshop_products::get_variation_price_behaviour( $product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : '' ) );
199
+					if (!empty($product_with_variation[$product['product_id']]['variation_priority'])) {
200
+						$product = wpshop_products::get_variation_price_behaviour($product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : ''));
201 201
 					}
202 202
 				}
203 203
 				else {
204 204
 					/** It's Simple product Check Discounts for products **/
205
-					$discount_config = self::check_discount_for_product( $product['product_id'] );
206
-					if ( !empty($discount_config) ) {
207
-						if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) {
205
+					$discount_config = self::check_discount_for_product($product['product_id']);
206
+					if (!empty($discount_config)) {
207
+						if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
208 208
 							$product['price_ttc_before_discount'] = $product['product_price'];
209 209
 							$product['price_ht_before_discount'] = $product['price_ht'];
210 210
 
211
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
212
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
213
-							$product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100);
211
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
212
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
213
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
214 214
 						}
215
-						elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
215
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
216 216
 							$product['price_ttc_before_discount'] = $product['product_price'];
217 217
 							$product['price_ht_before_discount'] = $product['price_ht'];
218 218
 
219
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
220
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value'];
221
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
219
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] - $discount_config['value']) : (($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100));
220
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value'];
221
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
222 222
 
223 223
 						}
224
-						elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
224
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
225 225
 							$product['price_ttc_before_discount'] = $product['product_price'];
226 226
 							$product['price_ht_before_discount'] = $product['price_ht'];
227 227
 
228 228
 
229
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 - $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
230
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) );
231
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
229
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100)) : (($product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100));
230
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100));
231
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
232 232
 
233 233
 						}
234 234
 					}
@@ -236,116 +236,116 @@  discard block
 block discarded – undo
236 236
 
237 237
 			}
238 238
 
239
-			$price_infos = self::check_product_price( $product );
240
-			$productCurrency = '<span class="wps-currency">'.wpshop_tools::wpshop_get_currency().'</span>';
239
+			$price_infos = self::check_product_price($product);
240
+			$productCurrency = '<span class="wps-currency">' . wpshop_tools::wpshop_get_currency() . '</span>';
241 241
 
242 242
 			$wps_marketing_tools = new wps_marketing_tools_ctr();
243 243
 
244
-			if ( !empty($price_infos) ) {
245
-				if ( $return_type == 'check_only' ) {
244
+			if (!empty($price_infos)) {
245
+				if ($return_type == 'check_only') {
246 246
 					/** Check if the product price has been set	*/
247
-					if( isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
247
+					if (isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
248 248
 					/** Check if the product price is coherent (not less than 0)	*/
249
-					if( isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop');
249
+					if (isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop');
250 250
 
251 251
 					return true;
252 252
 				}
253
-				elseif( $return_type == 'just_price_infos' ) {
253
+				elseif ($return_type == 'just_price_infos') {
254 254
 					$tpl_component = array();
255 255
 
256
-					$price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
257
-					$exploded_price = explode('.', number_format($price,2, '.', ''));
258
-					$price = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">,'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
256
+					$price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
257
+					$exploded_price = explode('.', number_format($price, 2, '.', ''));
258
+					$price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">,' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
259 259
 
260
-					$tpl_component['TAX_PILOTING'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT')  ? __('ET', 'wpshop') : '';
260
+					$tpl_component['TAX_PILOTING'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : '';
261 261
 
262 262
 					$tpl_component['CROSSED_OUT_PRICE'] = '';
263 263
 					$tpl_component['MESSAGE_SAVE_MONEY'] = '';
264 264
 
265 265
 
266 266
 
267
-					if( !empty($price_infos['discount']['discount_exist']) ) {
268
-						$crossed_out_price = ( (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2) ).' '. $productCurrency;
267
+					if (!empty($price_infos['discount']['discount_exist'])) {
268
+						$crossed_out_price = ((!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency;
269 269
 						$tpl_component['CROSSED_OUT_PRICE'] = $crossed_out_price;
270
-						if(!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') {
271
-							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', ''));
270
+						if (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') {
271
+							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', ''));
272 272
 						}
273 273
 						else {
274
-							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', ''));
274
+							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', ''));
275 275
 						}
276 276
 
277
-						$discount_price = $exploded_discount_price[0].'<span class="wpshop_price_centimes_display">,'.( (!empty($exploded_discount_price[1]) ) ? $exploded_discount_price[1] : '').'</span>';
278
-						$tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">'.$discount_price.'</span> '.$productCurrency;
277
+						$discount_price = $exploded_discount_price[0] . '<span class="wpshop_price_centimes_display">,' . ((!empty($exploded_discount_price[1])) ? $exploded_discount_price[1] : '') . '</span>';
278
+						$tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">' . $discount_price . '</span> ' . $productCurrency;
279 279
 
280
-						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_infos );
280
+						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_infos);
281 281
 					}
282 282
 					else {
283
-						$tpl_component['PRODUCT_PRICE'] = $price.' '.$productCurrency;
283
+						$tpl_component['PRODUCT_PRICE'] = $price . ' ' . $productCurrency;
284 284
 					}
285 285
 
286
-					$post_type = get_post_type( $product['product_id'] );
287
-					if (  $post_type ==  WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
288
-						$price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
286
+					$post_type = get_post_type($product['product_id']);
287
+					if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
288
+						$price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
289 289
 					}
290
-					elseif( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
291
-						$parent_def = wpshop_products::get_parent_variation ( $product['product_id'] );
292
-						if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
290
+					elseif ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
291
+						$parent_def = wpshop_products::get_parent_variation($product['product_id']);
292
+						if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
293 293
 							$parent_post = $parent_def['parent_post'];
294
-							$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
294
+							$price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
295 295
 						}
296 296
 					}
297
-					$price_display_option = get_option( 'wpshop_catalog_product_option' );
298
-					$tpl_component['PRICE_FROM'] = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? 'on' : '';
297
+					$price_display_option = get_option('wpshop_catalog_product_option');
298
+					$tpl_component['PRICE_FROM'] = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from'])))))) ? 'on' : '';
299 299
 
300 300
 					return $tpl_component;
301 301
 				}
302
-				else if ( $return_type == 'price_display' ) {
302
+				else if ($return_type == 'price_display') {
303 303
 					$tpl_component = array();
304
-					$price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
304
+					$price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
305 305
 
306 306
 					$price_data = $price_infos;
307 307
 
308
-					$exploded_price = explode('.', number_format($price,2, '.', ''));
309
-					$price = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
308
+					$exploded_price = explode('.', number_format($price, 2, '.', ''));
309
+					$price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
310 310
 
311
-					$tpl_component['TAX_PILOTING'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT')  ? __('ET', 'wpshop') : '';
311
+					$tpl_component['TAX_PILOTING'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : '';
312 312
 
313 313
 					$tpl_component['CROSSED_OUT_PRICE'] = '';
314 314
 					$tpl_component['MESSAGE_SAVE_MONEY'] = '';
315 315
 
316
-					if( !empty($price_infos['discount']['discount_exist']) ) {
316
+					if (!empty($price_infos['discount']['discount_exist'])) {
317 317
 						$text_from = false;
318 318
 						/** Get variation defining **/
319
-						$post_type = get_post_type( $product['product_id'] );
320
-						if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
321
-							$parent_def = wpshop_products::get_parent_variation ( $product['product_id'] );
322
-							if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
319
+						$post_type = get_post_type($product['product_id']);
320
+						if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
321
+							$parent_def = wpshop_products::get_parent_variation($product['product_id']);
322
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
323 323
 								$parent_post = $parent_def['parent_post'];
324
-								$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
324
+								$price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
325 325
 							}
326 326
 						}
327 327
 						else {
328
-							$price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
328
+							$price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
329 329
 						}
330
-						$text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) && !empty($product['text_from']) ) ? true : false;
330
+						$text_from = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']))))) && !empty($product['text_from'])) ? true : false;
331 331
 
332 332
 
333
-						$exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', ''));
334
-						$price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
333
+						$exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', ''));
334
+						$price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
335 335
 
336
-						$exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', ''));
337
-						$price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
336
+						$exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', ''));
337
+						$price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
338 338
 
339 339
 
340
-						$crossed_out_price = ( (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2) ).' '. $productCurrency;
341
-						$tpl_component['CROSSED_OUT_PRICE'] = str_replace( '.', ',', ( ( $text_from ) ? __('Price from', 'wpshop') . ' ' : '' ). wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price)) );
342
-						$tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">'. $price_infos['discount']['discount_et_price'].'</span> '.$productCurrency : '<span class="wps-absolute-price">'.$price_infos['discount']['discount_ati_price'].'</span> '.$productCurrency;
343
-						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_data );
340
+						$crossed_out_price = ((!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency;
341
+						$tpl_component['CROSSED_OUT_PRICE'] = str_replace('.', ',', (($text_from) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price)));
342
+						$tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">' . $price_infos['discount']['discount_et_price'] . '</span> ' . $productCurrency : '<span class="wps-absolute-price">' . $price_infos['discount']['discount_ati_price'] . '</span> ' . $productCurrency;
343
+						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_data);
344 344
 
345 345
 					}
346 346
 					else {
347
-						if( get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
348
-							$parent_def = wpshop_products::get_parent_variation( $product['product_id'] );
347
+						if (get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
348
+							$parent_def = wpshop_products::get_parent_variation($product['product_id']);
349 349
 							$pid = $parent_def['parent_post'];
350 350
 							$pid = $pid->ID;
351 351
 						}
@@ -355,35 +355,35 @@  discard block
 block discarded – undo
355 355
 
356 356
 						$text_from = false;
357 357
 						/** Get variation defining **/
358
-						$post_type = get_post_type( $pid );
359
-						if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
360
-							$parent_def = wpshop_products::get_parent_variation ( $pid );
361
-							if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
358
+						$post_type = get_post_type($pid);
359
+						if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
360
+							$parent_def = wpshop_products::get_parent_variation($pid);
361
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
362 362
 								$parent_post = $parent_def['parent_post'];
363
-								$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
363
+								$price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
364 364
 							}
365 365
 						}
366 366
 						else {
367
-							$price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true );
367
+							$price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true);
368 368
 						}
369 369
 
370
-						$price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true );
370
+						$price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true);
371 371
 
372
-						$text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? true : false;
372
+						$text_from = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from'])))))) ? true : false;
373 373
 
374
-						$tpl_component['PRODUCT_PRICE']  = ( $text_from && !empty($product['text_from']) ) ? __('Price from', 'wpshop') . ' ' : '';
375
-						$tpl_component['PRODUCT_PRICE'] .= $price.' '.$productCurrency;
374
+						$tpl_component['PRODUCT_PRICE']  = ($text_from && !empty($product['text_from'])) ? __('Price from', 'wpshop') . ' ' : '';
375
+						$tpl_component['PRODUCT_PRICE'] .= $price . ' ' . $productCurrency;
376 376
 					}
377 377
 
378 378
 
379 379
 					// Replace . by ,
380
-					$tpl_component['PRODUCT_PRICE'] = str_replace( '.',',', $tpl_component['PRODUCT_PRICE'] );
380
+					$tpl_component['PRODUCT_PRICE'] = str_replace('.', ',', $tpl_component['PRODUCT_PRICE']);
381 381
 
382
-					if ( $output_type == 'complete_sheet' ) {
383
-						$price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component );
382
+					if ($output_type == 'complete_sheet') {
383
+						$price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component);
384 384
 					}
385
-					elseif ( $output_type == 'mini_output' || in_array('mini_output', $output_type ) ) {
386
-						$price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component );
385
+					elseif ($output_type == 'mini_output' || in_array('mini_output', $output_type)) {
386
+						$price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component);
387 387
 					}
388 388
 					return $price_tpl;
389 389
 				}
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 		 * @return stdClass ( value, id ) L'id de l'attribut et le taux de TVA /
404 404
 		 * Attribute ID and the VAT rate
405 405
 		 */
406
-		public static function get_rate_vat( $product_id ) {
406
+		public static function get_rate_vat($product_id) {
407 407
 			global $wpdb;
408 408
 
409 409
 			/**
@@ -417,18 +417,18 @@  discard block
 block discarded – undo
417 417
 						INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . " as ATTR_VAL_INT ON ( ATTR_VAL_INT.attribute_id = ATTR.id AND ATTR_VAL_OPTIONS.id=ATTR_VAL_INT.value )
418 418
 					WHERE ATTR.code=%s AND ATTR_VAL_INT.entity_id=%d";
419 419
 
420
-			$request = $wpdb->prepare( $query, array( 'tx_tva',  $product_id ) );
421
-			$rate_vat = $wpdb->get_row( $request );
420
+			$request = $wpdb->prepare($query, array('tx_tva', $product_id));
421
+			$rate_vat = $wpdb->get_row($request);
422 422
 
423 423
 			/**
424 424
 			 * Vérifie ensuite si elle est vide, si elle est vide met la valeur par
425 425
 			 * défaut / Then checks if it is empty , if empty the value put the
426 426
 			 * default value
427 427
 			 */
428
-			if( empty( $rate_vat ) ) {
429
-				wpeologs_ctr::log_datas_in_files( 'wps_product', array(
428
+			if (empty($rate_vat)) {
429
+				wpeologs_ctr::log_datas_in_files('wps_product', array(
430 430
 					'object_id' 	=> $product_id,
431
-					'message' 		=> __( 'Use the default VAT rate', 'wpshop' ) ), 0
431
+					'message' 		=> __('Use the default VAT rate', 'wpshop') ), 0
432 432
 				);
433 433
 
434 434
 				$query = "
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " as ATTR_VAL_OPTIONS ON ATTR_VAL_OPTIONS.attribute_id = ATTR.id
438 438
 						WHERE ATTR.code=%s AND ATTR_VAL_OPTIONS.id=ATTR.default_value";
439 439
 
440
-				$request = $wpdb->prepare( $query, array( 'tx_tva' ) );
441
-				$rate_vat = $wpdb->get_row( $request );
440
+				$request = $wpdb->prepare($query, array('tx_tva'));
441
+				$rate_vat = $wpdb->get_row($request);
442 442
 			}
443 443
 
444 444
 			/**
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 			 * dans ce cas la on utilise le log / If it is still empty , it means that no
447 447
 			 * VAT rate found in this case the log is used
448 448
 			 */
449
-			if( empty( $rate_vat ) ) {
450
-				wpeologs_ctr::log_datas_in_files( 'wps_product', array(
449
+			if (empty($rate_vat)) {
450
+				wpeologs_ctr::log_datas_in_files('wps_product', array(
451 451
 					'object_id' 	=> $product_id,
452
-					'message' 		=> __( 'No VAT rate in the product and no default VAT rate found', 'wpshop' ) ), 2
452
+					'message' 		=> __('No VAT rate in the product and no default VAT rate found', 'wpshop') ), 2
453 453
 				);
454 454
 			}
455 455
 
@@ -459,19 +459,19 @@  discard block
 block discarded – undo
459 459
 		/**
460 460
 		 * Check if isset Required attributes
461 461
 		 */
462
-		public static function check_required_attributes( $product_id ) {
462
+		public static function check_required_attributes($product_id) {
463 463
 			$required_attributes_list = array();
464
-			$variation_option = get_post_meta( $product_id, '_wpshop_variation_defining', true);
465
-			if ( !empty($variation_option) && !empty($variation_option['attributes']) ) {
466
-				if( !empty($variation_option['options']) && !empty($variation_option['options']['required_attributes']) ) {
467
-					foreach( $variation_option['options']['required_attributes'] as $required_attribute ) {
468
-						$required_attributes_list[ $required_attribute ] = $required_attribute;
464
+			$variation_option = get_post_meta($product_id, '_wpshop_variation_defining', true);
465
+			if (!empty($variation_option) && !empty($variation_option['attributes'])) {
466
+				if (!empty($variation_option['options']) && !empty($variation_option['options']['required_attributes'])) {
467
+					foreach ($variation_option['options']['required_attributes'] as $required_attribute) {
468
+						$required_attributes_list[$required_attribute] = $required_attribute;
469 469
 					}
470 470
 				}
471 471
 				/** Check the attribute configuration **/
472
-				foreach ( $variation_option['attributes'] as $variation ) {
473
-					$attribute_def = wpshop_attributes::getElement( $variation, '"valid"', 'code' );
474
-					if ( is_object($attribute_def) && !empty($attribute_def->is_required) && $attribute_def->is_required == 'yes' ) {
472
+				foreach ($variation_option['attributes'] as $variation) {
473
+					$attribute_def = wpshop_attributes::getElement($variation, '"valid"', 'code');
474
+					if (is_object($attribute_def) && !empty($attribute_def->is_required) && $attribute_def->is_required == 'yes') {
475 475
 						$required_attributes_list[$attribute_def->code] = $attribute_def->code;
476 476
 					}
477 477
 				}
@@ -483,60 +483,60 @@  discard block
 block discarded – undo
483 483
 		}
484 484
 
485 485
 		/** Check the Product lower price **/
486
-		public static function check_product_lower_price ( $product_id ) {
486
+		public static function check_product_lower_price($product_id) {
487 487
 			global $wpdb;
488
-			$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
488
+			$price_piloting_option = get_option('wpshop_shop_price_piloting');
489 489
 			$lower_price_product = $min_price = 0;
490
-			$variations = wpshop_products::get_variation( $product_id, 'publish' );
490
+			$variations = wpshop_products::get_variation($product_id, 'publish');
491 491
 			$single_variations = $lower_price_product_combinaison = array();
492 492
 			$first = true;
493 493
 
494 494
 			/** Check variations type **/
495
-			$query = $wpdb->prepare( 'SELECT DISTINCT( SUBSTRING( m.meta_value, 3,1 ) ) AS attributes_count FROM ' .$wpdb->postmeta .' AS m INNER JOIN ' .$wpdb->posts. ' AS P ON ((P.ID = m.post_id) AND (P.post_parent = %d)) WHERE meta_key LIKE %s', $product_id, '_wpshop_variations_attribute_def' );
496
-			$variation_type = $wpdb->get_results( $query );
495
+			$query = $wpdb->prepare('SELECT DISTINCT( SUBSTRING( m.meta_value, 3,1 ) ) AS attributes_count FROM ' . $wpdb->postmeta . ' AS m INNER JOIN ' . $wpdb->posts . ' AS P ON ((P.ID = m.post_id) AND (P.post_parent = %d)) WHERE meta_key LIKE %s', $product_id, '_wpshop_variations_attribute_def');
496
+			$variation_type = $wpdb->get_results($query);
497 497
 
498 498
 
499 499
 			/** Check which type of variation contains the product **/
500 500
 			$contains_simple_variation = false;
501
-			if ( !empty($variation_type) ) {
502
-				foreach( $variation_type as $k => $value ) {
503
-					if( $value->attributes_count == '1' ) {
501
+			if (!empty($variation_type)) {
502
+				foreach ($variation_type as $k => $value) {
503
+					if ($value->attributes_count == '1') {
504 504
 						$contains_simple_variation = true;
505 505
 					}
506 506
 				}
507 507
 			}
508 508
 
509
-			if ( $contains_simple_variation ) {
509
+			if ($contains_simple_variation) {
510 510
 
511
-				if( !empty($variations) ) {
512
-					$attributes = get_post_meta( $product_id, '_wpshop_variation_defining', true);
513
-					if ( !empty($attributes) && !empty($attributes['attributes']) ) {
511
+				if (!empty($variations)) {
512
+					$attributes = get_post_meta($product_id, '_wpshop_variation_defining', true);
513
+					if (!empty($attributes) && !empty($attributes['attributes'])) {
514 514
 						/** Construct an array with all cheaper attributes **/
515
-						foreach( $attributes['attributes'] as $key=>$attribute ) {
515
+						foreach ($attributes['attributes'] as $key=>$attribute) {
516 516
 							$min_price = 0;
517 517
 							$first = true;
518
-							foreach( $variations as $k => $variation) {
519
-								if ( !empty($variation['variation_def']) && count($variation['variation_def']) == 1 ) {
520
-									if( array_key_exists($attribute, $variation['variation_def'] ) ) {
521
-										$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation['variation_dif']['price_ht'] : !empty( $variation['variation_dif']['product_price'] ) ? $variation['variation_dif']['product_price'] : 0;
518
+							foreach ($variations as $k => $variation) {
519
+								if (!empty($variation['variation_def']) && count($variation['variation_def']) == 1) {
520
+									if (array_key_exists($attribute, $variation['variation_def'])) {
521
+										$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation['variation_dif']['price_ht'] : !empty($variation['variation_dif']['product_price']) ? $variation['variation_dif']['product_price'] : 0;
522 522
 
523 523
 										/** Check Discount **/
524
-										$variation_price = ( !empty( $variation['variation_dif']['special_price'] ) && $variation['variation_dif']['special_price'] > 0 ) ? $variation['variation_dif']['special_price'] : $variation_price;
525
-										if( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_rate']) && $variation['variation_dif']['discount_rate'] > 0) {
526
-											$query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] );
527
-											$tx_tva = $wpdb->get_var( $query );
528
-											$variation_price =  $variation['variation_dif']['price_ht'] / ( 1 + ($variation['variation_dif']['discount_rate'] / 100 ) );
529
-											$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
524
+										$variation_price = (!empty($variation['variation_dif']['special_price']) && $variation['variation_dif']['special_price'] > 0) ? $variation['variation_dif']['special_price'] : $variation_price;
525
+										if (empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_rate']) && $variation['variation_dif']['discount_rate'] > 0) {
526
+											$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $variation['variation_dif']['tx_tva']);
527
+											$tx_tva = $wpdb->get_var($query);
528
+											$variation_price = $variation['variation_dif']['price_ht'] / (1 + ($variation['variation_dif']['discount_rate'] / 100));
529
+											$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
530 530
 										}
531
-										elseif( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0 ) {
532
-											$query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] );
533
-											$tx_tva = $wpdb->get_var( $query );
534
-											$variation_price =  $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount'];
535
-											$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
531
+										elseif (empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0) {
532
+											$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $variation['variation_dif']['tx_tva']);
533
+											$tx_tva = $wpdb->get_var($query);
534
+											$variation_price = $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount'];
535
+											$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
536 536
 										}
537 537
 
538 538
 										/** Check the Min-price **/
539
-										if( $first|| $min_price >= $variation_price ) {
539
+										if ($first || $min_price >= $variation_price) {
540 540
 											$first = false;
541 541
 											$min_price = $variation_price;
542 542
 											$lower_price_product_combinaison['variations'][$attribute] = $k;
@@ -550,22 +550,22 @@  discard block
 block discarded – undo
550 550
 				}
551 551
 			}
552 552
 			else {
553
-				if ( !empty($product_id) ) {
554
-					if( !empty($variations) ) {
553
+				if (!empty($product_id)) {
554
+					if (!empty($variations)) {
555 555
 
556
-						foreach( $variations as $variation_id => $variation) {
557
-							if ( !empty($variation['variation_dif']) && !empty($variation['variation_def']) && count($variation['variation_def']) > 1) {
558
-								$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? ( ( !empty($variation['variation_dif']['price_ht']) ) ? $variation['variation_dif']['price_ht'] : 0) : ( ( !empty($variation['variation_dif']['product_price']) ) ? $variation['variation_dif']['product_price'] : 0);
556
+						foreach ($variations as $variation_id => $variation) {
557
+							if (!empty($variation['variation_dif']) && !empty($variation['variation_def']) && count($variation['variation_def']) > 1) {
558
+								$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) : ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0);
559 559
 								/** Check the Min-price **/
560
-								if( $min_price >= $variation_price || $first ) {
560
+								if ($min_price >= $variation_price || $first) {
561 561
 									$min_price = $variation_price;
562 562
 									$var_id = $variation_id;
563 563
 								}
564 564
 							}
565
-							$first  = false;
565
+							$first = false;
566 566
 						}
567 567
 
568
-						if ( !empty($var_id) ) {
568
+						if (!empty($var_id)) {
569 569
 							$lower_price_product_combinaison['variations'][] = $var_id;
570 570
 							$lower_price_product_combinaison['variation_priority'] = 'combined';
571 571
 						}
@@ -581,25 +581,25 @@  discard block
 block discarded – undo
581 581
 		 * @param array $discount_config
582 582
 		 * @return array
583 583
 		 */
584
-		public static function calcul_discounted_price( $product, $discount_config ) {
585
-			$wpshop_price_piloting_option = get_option( 'wpshop_shop_price_piloting');
586
-			if( !empty($discount_config) ) {
584
+		public static function calcul_discounted_price($product, $discount_config) {
585
+			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
586
+			if (!empty($discount_config)) {
587 587
 
588
-				if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) {
589
-					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
590
-					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
588
+				if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
589
+					$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
590
+					$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
591 591
 					$product['tva'] = $product['product_price'] - $product['price_ht'];
592 592
 				}
593
-				elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
594
-					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] - $discount_config['value'] ) : ( ( $product['product_price'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
595
-					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['product_price'] - $discount_config['value'];
596
-					$product['tva'] =  $product['product_price'] - $product['price_ht'];
593
+				elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
594
+					$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht'] - $discount_config['value']) : (($product['product_price'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100));
595
+					$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['product_price'] - $discount_config['value'];
596
+					$product['tva'] = $product['product_price'] - $product['price_ht'];
597 597
 
598 598
 				}
599
-				elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
600
-					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] * ( 1 -  $discount_config['value'] / 100) ) : ( ( $product['product_price']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
601
-					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['product_price'] * ( 1 - ( $discount_config['value'] / 100 ) );
602
-					$product['tva'] =   $product['product_price'] - $product['price_ht'];
599
+				elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
600
+					$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht'] * (1 - $discount_config['value'] / 100)) : (($product['product_price'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100));
601
+					$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['product_price'] * (1 - ($discount_config['value'] / 100));
602
+					$product['tva'] = $product['product_price'] - $product['price_ht'];
603 603
 				}
604 604
 			}
605 605
 			return $product;
@@ -607,39 +607,39 @@  discard block
 block discarded – undo
607 607
 
608 608
 
609 609
 		/** Check Discount for Product **/
610
-		public static function check_discount_for_product( $product_id, $head_product_id = 0 ) {
610
+		public static function check_discount_for_product($product_id, $head_product_id = 0) {
611 611
 			$discount_config = array();
612 612
 			$time_def = array('0000-00-00 00:00:00', '0000-00-00');
613 613
 
614
-			if( !empty($product_id) ) {
615
-				if ( !empty($head_product_id) ) {
616
-					$product_meta = get_post_meta( $head_product_id, '_wpshop_product_metadata', true );
617
-					$product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0;
618
-					$product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0;
614
+			if (!empty($product_id)) {
615
+				if (!empty($head_product_id)) {
616
+					$product_meta = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
617
+					$product_discount_date_from = (!empty($product_meta['special_from'])) ? $product_meta['special_from'] : 0;
618
+					$product_discount_date_to = (!empty($product_meta['special_to'])) ? $product_meta['special_to'] : 0;
619 619
 
620
-					$product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true );
620
+					$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
621 621
 				}
622 622
 				else {
623
-					$product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true );
624
-					$product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0;
625
-					$product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0;
623
+					$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
624
+					$product_discount_date_from = (!empty($product_meta['special_from'])) ? $product_meta['special_from'] : 0;
625
+					$product_discount_date_to = (!empty($product_meta['special_to'])) ? $product_meta['special_to'] : 0;
626 626
 				}
627 627
 
628 628
 				$current_date = date('Y-m-d');
629 629
 
630
-				if ( !empty( $product_meta ) ) {
630
+				if (!empty($product_meta)) {
631 631
 
632
-					if( ( empty($product_discount_date_from) && empty($product_discount_date_to) ) || ( in_array($product_discount_date_from, $time_def)  && in_array( $product_discount_date_to, $time_def) ) || (strtotime($product_discount_date_from) < strtotime($current_date) && strtotime($current_date) < strtotime($product_discount_date_to) ) ) {
632
+					if ((empty($product_discount_date_from) && empty($product_discount_date_to)) || (in_array($product_discount_date_from, $time_def) && in_array($product_discount_date_to, $time_def)) || (strtotime($product_discount_date_from) < strtotime($current_date) && strtotime($current_date) < strtotime($product_discount_date_to))) {
633 633
 						/** Special Price **/
634
-						if ( !empty($product_meta['special_price']) && $product_meta['special_price'] > 0 ) {
634
+						if (!empty($product_meta['special_price']) && $product_meta['special_price'] > 0) {
635 635
 							$discount_config['type'] = 'special_price';
636 636
 							$discount_config['value'] = $product_meta['special_price'];
637 637
 						}
638
-						elseif( !empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) {
638
+						elseif (!empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) {
639 639
 							$discount_config['type'] = 'discount_amount';
640 640
 							$discount_config['value'] = $product_meta['discount_amount'];
641 641
 						}
642
-						elseif( !empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0 ) {
642
+						elseif (!empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0) {
643 643
 							$discount_config['type'] = 'discount_rate';
644 644
 							$discount_config['value'] = $product_meta['discount_rate'];
645 645
 						}
@@ -652,13 +652,13 @@  discard block
 block discarded – undo
652 652
 		/**
653 653
 		 * Check the parent product price
654 654
 		 */
655
-		function check_parent_product_price( $product ) {
655
+		function check_parent_product_price($product) {
656 656
 			$price_infos = array();
657
-			if( !empty($product) ) {
657
+			if (!empty($product)) {
658 658
 				$price_infos['ati'] = $product['product_price'];
659 659
 				$price_infos['et'] = $product['price_ht'];
660 660
 				$price_infos['tva'] = $product['tva'];
661
-				$price_infos['fork_price'] = array( 'have_fork_price' => false, 'min_product_price' => '', 'max_product_price' => '');
661
+				$price_infos['fork_price'] = array('have_fork_price' => false, 'min_product_price' => '', 'max_product_price' => '');
662 662
 			}
663 663
 			return $price_infos;
664 664
 		}
@@ -668,81 +668,81 @@  discard block
 block discarded – undo
668 668
 			global $wpdb;
669 669
 			$status = false; $result = '';
670 670
 			@ini_set('max_execution_time', '500');
671
-			$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
672
-			$output_type_option = get_option( 'wpshop_display_option' );
671
+			$price_piloting_option = get_option('wpshop_shop_price_piloting');
672
+			$output_type_option = get_option('wpshop_display_option');
673 673
 			$output_type = $output_type_option['wpshop_display_list_type'];
674 674
 
675 675
 			/** Get tx_tva attribute_id **/
676
-			$query = $wpdb->prepare( 'SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s', 'tx_tva' );
677
-			$tx_tva_attribute_id = $wpdb->get_var( $query );
676
+			$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', 'tx_tva');
677
+			$tx_tva_attribute_id = $wpdb->get_var($query);
678 678
 
679 679
 			/** Product entity Definition **/
680
-			$product_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
680
+			$product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
681 681
 
682 682
 			/** Attributes def **/
683
-			$tva_attribute_def = wpshop_attributes::getElement('tva',"'valid'", 'code');
684
-			$product_price_attribute_def = wpshop_attributes::getElement('product_price',"'valid'", 'code');
685
-			$price_ht_attribute_def = wpshop_attributes::getElement('price_ht',"'valid'", 'code');
683
+			$tva_attribute_def = wpshop_attributes::getElement('tva', "'valid'", 'code');
684
+			$product_price_attribute_def = wpshop_attributes::getElement('product_price', "'valid'", 'code');
685
+			$price_ht_attribute_def = wpshop_attributes::getElement('price_ht', "'valid'", 'code');
686 686
 
687
-			if ( !empty($tx_tva_attribute_id) ) {
688
-				$query = $wpdb->prepare( 'SELECT id, value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid' );
689
-				$tx_tva = $wpdb->get_results( $query );
687
+			if (!empty($tx_tva_attribute_id)) {
688
+				$query = $wpdb->prepare('SELECT id, value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid');
689
+				$tx_tva = $wpdb->get_results($query);
690 690
 
691 691
 				$tva_array = array();
692 692
 				/** Transform array to easy teatment **/
693
-				foreach( $tx_tva as $t ) {
694
-					$tva_array[ $t->id ] = $t->value;
693
+				foreach ($tx_tva as $t) {
694
+					$tva_array[$t->id] = $t->value;
695 695
 				}
696 696
 
697
-				if ( !empty($tx_tva) ) {
697
+				if (!empty($tx_tva)) {
698 698
 
699 699
 					$count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
700 700
 
701
-					for( $i = 0; $i <= $count_products->publish; $i+= 100 ) {
702
-					$query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish' );
703
-					$products = $wpdb->get_results( $query );
701
+					for ($i = 0; $i <= $count_products->publish; $i += 100) {
702
+					$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
703
+					$products = $wpdb->get_results($query);
704 704
 
705
-						if( !empty($products) ){
706
-	 						foreach( $products as $product ) {
707
-								$product_data = get_post_meta( $product->ID, '_wpshop_product_metadata', true);
708
-								if ( !empty($product_data) ) {
709
-									if ( !empty($product_data['tx_tva']) && array_key_exists( $product_data['tx_tva'], $tva_array) ) {
705
+						if (!empty($products)) {
706
+	 						foreach ($products as $product) {
707
+								$product_data = get_post_meta($product->ID, '_wpshop_product_metadata', true);
708
+								if (!empty($product_data)) {
709
+									if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) {
710 710
 
711
-										if ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) {
711
+										if (!empty($price_piloting_option) && $price_piloting_option == 'HT') {
712 712
 											/** Update post meta **/
713
-											$product_data['price_ht'] = (float)str_replace( ',', '.', $product_data['price_ht'] );
714
-											$product_data['product_price'] = $product_data['price_ht'] * ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
715
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
716
-											update_post_meta( $product->ID, '_wpshop_product_metadata', $product_data);
713
+											$product_data['price_ht'] = (float)str_replace(',', '.', $product_data['price_ht']);
714
+											$product_data['product_price'] = $product_data['price_ht'] * (1 + ($tva_array[$product_data['tx_tva']] / 100));
715
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
716
+											update_post_meta($product->ID, '_wpshop_product_metadata', $product_data);
717 717
 
718 718
 
719 719
 											/** Update attributes values **/
720
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID) );
721
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID) );
722
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID) );
720
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID));
721
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID));
722
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID));
723 723
 
724 724
 											/** Update Display price meta **/
725 725
 											$p = wpshop_products::get_product_data($product->ID);
726
-											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) );
727
-											update_post_meta( $product->ID, '_wps_price_infos', $price );
726
+											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
727
+											update_post_meta($product->ID, '_wps_price_infos', $price);
728 728
 										}
729 729
 										else {
730 730
 											/** Update post meta **/
731
-											$product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] );
732
-											$product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
733
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
734
-											update_post_meta( $product->ID, '_wpshop_product_metadata', $product_data);
731
+											$product_data['product_price'] = (float)str_replace(',', '.', $product_data['product_price']);
732
+											$product_data['price_ht'] = $product_data['product_price'] / (1 + ($tva_array[$product_data['tx_tva']] / 100));
733
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
734
+											update_post_meta($product->ID, '_wpshop_product_metadata', $product_data);
735 735
 
736 736
 											/** Update attributes values **/
737
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID) );
738
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID) );
739
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID) );
737
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID));
738
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID));
739
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID));
740 740
 
741 741
 
742 742
 											/** Update Display price meta **/
743 743
 											$p = wpshop_products::get_product_data($product->ID);
744
-											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) );
745
-											update_post_meta( $product->ID, '_wps_price_infos', $price );
744
+											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
745
+											update_post_meta($product->ID, '_wps_price_infos', $price);
746 746
 										}
747 747
 									}
748 748
 								}
@@ -750,41 +750,41 @@  discard block
 block discarded – undo
750 750
 
751 751
 						}
752 752
 					}
753
-					unset( $products );
753
+					unset($products);
754 754
 
755 755
 					$count_variations = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION);
756
-					for( $i = 0; $i <= $count_variations->publish; $i+= 100 ) {
757
-						$query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish' );
758
-						$product_variations = $wpdb->get_results( $query );
756
+					for ($i = 0; $i <= $count_variations->publish; $i += 100) {
757
+						$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish');
758
+						$product_variations = $wpdb->get_results($query);
759 759
 						/** Update Products Variations **/
760
-						if ( !empty($product_variations) ) {
761
-							foreach( $product_variations as $product_variation ) {
762
-								$product_data = get_post_meta( $product_variation->ID, '_wpshop_product_metadata', true);
763
-								if ( !empty($product_data) ) {
764
-									if ( !empty($product_data['tx_tva']) && array_key_exists( $product_data['tx_tva'], $tva_array) ) {
765
-										if ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) {
760
+						if (!empty($product_variations)) {
761
+							foreach ($product_variations as $product_variation) {
762
+								$product_data = get_post_meta($product_variation->ID, '_wpshop_product_metadata', true);
763
+								if (!empty($product_data)) {
764
+									if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) {
765
+										if (!empty($price_piloting_option) && $price_piloting_option == 'HT') {
766 766
 											/** Update post meta **/
767
-											$product_data['price_ht'] = (float)str_replace( ',', '.', $product_data['price_ht'] );
768
-											$product_data['product_price'] = $product_data['price_ht'] * ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
769
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
770
-											update_post_meta( $product_variation->ID, '_wpshop_product_metadata', $product_data);
767
+											$product_data['price_ht'] = (float)str_replace(',', '.', $product_data['price_ht']);
768
+											$product_data['product_price'] = $product_data['price_ht'] * (1 + ($tva_array[$product_data['tx_tva']] / 100));
769
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
770
+											update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data);
771 771
 
772 772
 											/** Update attributes values **/
773
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) );
774
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) );
775
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) );
773
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID));
774
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID));
775
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID));
776 776
 										}
777 777
 										else {
778 778
 											/** Update post meta **/
779
-											$product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] );
780
-											$product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
781
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
782
-											update_post_meta( $product_variation->ID, '_wpshop_product_metadata', $product_data);
779
+											$product_data['product_price'] = (float)str_replace(',', '.', $product_data['product_price']);
780
+											$product_data['price_ht'] = $product_data['product_price'] / (1 + ($tva_array[$product_data['tx_tva']] / 100));
781
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
782
+											update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data);
783 783
 
784 784
 											/** Update attributes values **/
785
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) );
786
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) );
787
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) );
785
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID));
786
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID));
787
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID));
788 788
 										}
789 789
 									}
790 790
 								}
@@ -801,15 +801,15 @@  discard block
 block discarded – undo
801 801
 				}
802 802
 			}
803 803
 			else {
804
-				$result = __( 'VAT rate attribute was not found', 'wpshop' );
804
+				$result = __('VAT rate attribute was not found', 'wpshop');
805 805
 			}
806
-			return array( $status, $result );
806
+			return array($status, $result);
807 807
 		}
808 808
 
809 809
 	}
810 810
 
811 811
 }
812 812
 /**	Instanciate the module utilities if not	*/
813
-if ( class_exists("wpshop_prices") ) {
813
+if (class_exists("wpshop_prices")) {
814 814
 	$wpshop_prices = new wpshop_prices();
815 815
 }
Please login to merge, or discard this patch.
includes/librairies/catalog/products.class.php 2 patches
Indentation   +3125 added lines, -3125 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,32 +252,32 @@  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');
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 281
 				/*add_meta_box('wpshop_histo_attrs', __('Historic attributes', 'wpshop'), function($post) {
282 282
 					global $wpdb;
283 283
 					$limit = 40;
@@ -310,21 +310,21 @@  discard block
 block discarded – undo
310 310
 						'total' => $max_page
311 311
 					) );
312 312
 				}, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');*/
313
-            } else if (count($attributeEntitySetList) > 1) {
314
-                $input_def['id'] = 'product_attribute_set_id';
315
-                $input_def['name'] = 'product_attribute_set_id';
316
-                $input_def['value'] = '';
317
-                $input_def['type'] = 'select';
318
-                $input_def['possible_value'] = $attributeEntitySetList;
319
-
320
-                $input_def['value'] = '';
321
-                foreach ($attributeEntitySetList as $set) {
322
-                    if ($set->default_set == 'yes') {
323
-                        $input_def['value'] = $set->id;
324
-                    }
325
-                }
326
-
327
-                $currentTabContent['boxContent']['attribute_set_selector'] = '
313
+			} else if (count($attributeEntitySetList) > 1) {
314
+				$input_def['id'] = 'product_attribute_set_id';
315
+				$input_def['name'] = 'product_attribute_set_id';
316
+				$input_def['value'] = '';
317
+				$input_def['type'] = 'select';
318
+				$input_def['possible_value'] = $attributeEntitySetList;
319
+
320
+				$input_def['value'] = '';
321
+				foreach ($attributeEntitySetList as $set) {
322
+					if ($set->default_set == 'yes') {
323
+						$input_def['value'] = $set->id;
324
+					}
325
+				}
326
+
327
+				$currentTabContent['boxContent']['attribute_set_selector'] = '
328 328
 	<ul class="attribute_set_selector" >
329 329
 		<li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li>
330 330
 		<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>
@@ -332,791 +332,791 @@  discard block
 block discarded – undo
332 332
 		<li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li>
333 333
 	</ul>';
334 334
 
335
-                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'));
336
-            }
337
-        }
335
+				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'));
336
+			}
337
+		}
338 338
 
339
-    }
339
+	}
340 340
 
341
-    /**
342
-     * Add a box into product edition page for options on the product
343
-     *
344
-     * @param object $post
345
-     */
346
-    public static function product_options_meta_box_content($post)
347
-    {
348
-        $output = '';
341
+	/**
342
+	 * Add a box into product edition page for options on the product
343
+	 *
344
+	 * @param object $post
345
+	 */
346
+	public static function product_options_meta_box_content($post)
347
+	{
348
+		$output = '';
349 349
 
350
-        $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
350
+		$product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
351 351
 
352
-        $tpl_component = array();
353
-        $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
354
-        $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
352
+		$tpl_component = array();
353
+		$tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
354
+		$output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
355 355
 
356
-        echo $output;
357
-    }
356
+		echo $output;
357
+	}
358 358
 
359
-    /**
360
-     * Display the fixed box
361
-     */
362
-    public static function product_data_meta_box($post, $metaboxArgs)
363
-    {
364
-        $output = '';
359
+	/**
360
+	 * Display the fixed box
361
+	 */
362
+	public static function product_data_meta_box($post, $metaboxArgs)
363
+	{
364
+		$output = '';
365 365
 
366
-        $currentTabContent = $metaboxArgs['args']['currentTabContent'];
366
+		$currentTabContent = $metaboxArgs['args']['currentTabContent'];
367 367
 
368
-        echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
368
+		echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
369 369
 				<ul>';
370
-        if (!empty($currentTabContent['box'])) {
371
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
372
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
373
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
374
-                        echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
375
-                    }
376
-                }
377
-            }
378
-        }
379
-        echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
380
-        echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
381
-        echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
382
-        echo '</ul>';
383
-
384
-        if (!empty($currentTabContent['box'])) {
385
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
386
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
387
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
388
-                        echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
389
-                    }
390
-                }
391
-            }
392
-        }
370
+		if (!empty($currentTabContent['box'])) {
371
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
372
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
373
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
374
+						echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
375
+					}
376
+				}
377
+			}
378
+		}
379
+		echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
380
+		echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
381
+		echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
382
+		echo '</ul>';
383
+
384
+		if (!empty($currentTabContent['box'])) {
385
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
386
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
387
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
388
+						echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
389
+					}
390
+				}
391
+			}
392
+		}
393 393
 
394
-        echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
395
-        echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
396
-        echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
397
-        if (!empty($currentTabContent['boxMore'])) {
398
-            echo $currentTabContent['boxMore'];
399
-        }
400
-        echo '</div>';
394
+		echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
395
+		echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
396
+		echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
397
+		if (!empty($currentTabContent['boxMore'])) {
398
+			echo $currentTabContent['boxMore'];
399
+		}
400
+		echo '</div>';
401 401
 
402
-        echo $output;
403
-    }
402
+		echo $output;
403
+	}
404 404
 
405
-    /**
406
-     * Output the content for related product metabox
407
-     * @param object $post The current edited post
408
-     * @return string
409
-     */
410
-    public static function related_products_meta_box_content($post)
411
-    {
412
-        $content = $existing_selection = '';
413
-
414
-        if (!empty($post->ID)) {
415
-            $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
416
-            if (!empty($related_products_id) && !empty($related_products_id[0])) {
417
-                foreach ($related_products_id as $related_product_id) {
418
-                    $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
419
-                }
420
-            }
421
-        }
405
+	/**
406
+	 * Output the content for related product metabox
407
+	 * @param object $post The current edited post
408
+	 * @return string
409
+	 */
410
+	public static function related_products_meta_box_content($post)
411
+	{
412
+		$content = $existing_selection = '';
413
+
414
+		if (!empty($post->ID)) {
415
+			$related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
416
+			if (!empty($related_products_id) && !empty($related_products_id[0])) {
417
+				foreach ($related_products_id as $related_product_id) {
418
+					$existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
419
+				}
420
+			}
421
+		}
422 422
 
423
-        $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>
423
+		$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>
424 424
 			<select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select>
425 425
 			<input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" />
426 426
 			<input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
427 427
 
428
-        return $content;
429
-    }
428
+		return $content;
429
+	}
430 430
 
431
-    /**
432
-     * Output the content for related product metabox
433
-     * @param object $post The current edited post
434
-     * @return string
435
-     */
436
-    public static function provider_products_meta_box_content($post)
437
-    {
438
-        $content = $existing_selection = '';
439
-
440
-        if (!empty($post->ID)) {
441
-            $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
442
-            if (!empty($providers_id) && !empty($providers_id[0])) {
443
-                foreach ($providers_id as $provider_id) {
444
-                    $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
445
-                }
446
-            }
447
-        }
431
+	/**
432
+	 * Output the content for related product metabox
433
+	 * @param object $post The current edited post
434
+	 * @return string
435
+	 */
436
+	public static function provider_products_meta_box_content($post)
437
+	{
438
+		$content = $existing_selection = '';
439
+
440
+		if (!empty($post->ID)) {
441
+			$providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
442
+			if (!empty($providers_id) && !empty($providers_id[0])) {
443
+				foreach ($providers_id as $provider_id) {
444
+					$existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
445
+				}
446
+			}
447
+		}
448 448
 
449
-        $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
449
+		$content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
450 450
 			<select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select>
451 451
 			<input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" />
452 452
 			<input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
453 453
 
454
-        return $content;
455
-    }
454
+		return $content;
455
+	}
456 456
 
457
-    /**
458
-     * Define the metabox content for the action box
459
-     * @param obejct $post The current element being edited
460
-     */
461
-    public static function product_actions_meta_box_content($post)
462
-    {
463
-        $output = '';
464
-        /*
457
+	/**
458
+	 * Define the metabox content for the action box
459
+	 * @param obejct $post The current element being edited
460
+	 */
461
+	public static function product_actions_meta_box_content($post)
462
+	{
463
+		$output = '';
464
+		/*
465 465
          * Template parameters
466 466
          */
467
-        $template_part = 'wpshop_duplicate_product';
468
-        $tpl_component = array();
469
-        $tpl_component['PRODUCT_ID'] = $post->ID;
470
-        $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
471
-        /*
467
+		$template_part = 'wpshop_duplicate_product';
468
+		$tpl_component = array();
469
+		$tpl_component['PRODUCT_ID'] = $post->ID;
470
+		$tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
471
+		/*
472 472
          * Build template
473 473
          */
474
-        $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
475
-        unset($tpl_component);
474
+		$output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
475
+		unset($tpl_component);
476 476
 
477
-        echo $output;
478
-    }
477
+		echo $output;
478
+	}
479 479
 
480
-    /**
481
-     *    Define the content of the product main information box
482
-     */
483
-    public static function meta_box_content($post, $metaboxArgs)
484
-    {
485
-        global $currentTabContent;
480
+	/**
481
+	 *    Define the content of the product main information box
482
+	 */
483
+	public static function meta_box_content($post, $metaboxArgs)
484
+	{
485
+		global $currentTabContent;
486 486
 
487
-        /*    Add the extra fields defined by the default attribute group in the general section    */
488
-        echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
489
-    }
487
+		/*    Add the extra fields defined by the default attribute group in the general section    */
488
+		echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
489
+	}
490 490
 
491
-    /**
492
-     * Define the metabox content for product custom display in product
493
-     * @param object $post The current element being edited
494
-     * @return string The metabox content
495
-     */
496
-    public static function product_frontend_display_config_meta_box($post)
497
-    {
498
-        $content = '';
499
-
500
-        $product_attribute_frontend_display_config = null;
501
-        if (!empty($post->ID)) {
502
-            $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
503
-
504
-            $extra_options = get_option('wpshop_extra_options', array());
505
-            $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
506
-            $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
507
-            $column = 1;
508
-
509
-            if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
510
-                $sub_tpl_component = array();
511
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
512
-
513
-                $tpl_component = array();
514
-                $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
515
-                $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
516
-                $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
517
-                $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
518
-
519
-                $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"' : '';
520
-                $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"' : '';
521
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
522
-                unset($tpl_component);
523
-
524
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
525
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
526
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
527
-                $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
528
-            }
529
-
530
-            if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
531
-                foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
532
-                    if (!isset($sub_content[$column])) {
533
-                        $sub_content[$column] = '';
534
-                    }
535
-
536
-                    $attribute_sub_output = '';
537
-                    foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
538
-                        if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
539
-                            $tpl_component = array();
540
-                            $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
541
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
542
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
543
-                            $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"' : '';
544
-                            $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"' : '';
545
-                            $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
546
-                            unset($tpl_component);
547
-                        }
548
-                    }
549
-
550
-                    $tpl_component = array();
551
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
552
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
553
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
554
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
555
-                    $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"' : '';
556
-                    $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>';
557
-                    $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
558
-                    $column++;
559
-                    if ($column > $column_count) {
560
-                        $column = 1;
561
-                    }
562
-                }
563
-            }
564
-            $tpl_component = array();
565
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
566
-            for ($i = 1; $i <= $column_count; $i++) {
567
-                if (!empty($sub_content[$i])) {
568
-                    $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
569
-                }
570
-
571
-            }
572
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
573
-            $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
574
-            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
575
-
576
-            $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>';
577
-        }
491
+	/**
492
+	 * Define the metabox content for product custom display in product
493
+	 * @param object $post The current element being edited
494
+	 * @return string The metabox content
495
+	 */
496
+	public static function product_frontend_display_config_meta_box($post)
497
+	{
498
+		$content = '';
499
+
500
+		$product_attribute_frontend_display_config = null;
501
+		if (!empty($post->ID)) {
502
+			$product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
503
+
504
+			$extra_options = get_option('wpshop_extra_options', array());
505
+			$column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
506
+			$attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
507
+			$column = 1;
508
+
509
+			if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
510
+				$sub_tpl_component = array();
511
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
512
+
513
+				$tpl_component = array();
514
+				$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
515
+				$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
516
+				$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
517
+				$button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
518
+
519
+				$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"' : '';
520
+				$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"' : '';
521
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
522
+				unset($tpl_component);
523
+
524
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
525
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
526
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
527
+				$sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
528
+			}
578 529
 
579
-        return $content;
580
-    }
530
+			if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
531
+				foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
532
+					if (!isset($sub_content[$column])) {
533
+						$sub_content[$column] = '';
534
+					}
535
+
536
+					$attribute_sub_output = '';
537
+					foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
538
+						if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
539
+							$tpl_component = array();
540
+							$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
541
+							$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
542
+							$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
543
+							$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"' : '';
544
+							$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"' : '';
545
+							$attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
546
+							unset($tpl_component);
547
+						}
548
+					}
581 549
 
582
-    /**
583
-     * Retrieve the attribute list used for sorting product into frontend listing
584
-     * @return array The attribute list to use for listing sorting
585
-     */
586
-    public static function get_sorting_criteria()
587
-    {
588
-        global $wpdb;
550
+					$tpl_component = array();
551
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
552
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
553
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
554
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
555
+					$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"' : '';
556
+					$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>';
557
+					$sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
558
+					$column++;
559
+					if ($column > $column_count) {
560
+						$column = 1;
561
+					}
562
+				}
563
+			}
564
+			$tpl_component = array();
565
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
566
+			for ($i = 1; $i <= $column_count; $i++) {
567
+				if (!empty($sub_content[$i])) {
568
+					$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
569
+				}
589 570
 
590
-        $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop')));
571
+			}
572
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
573
+			$tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
574
+			$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
591 575
 
592
-        $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
593
-        $results = $wpdb->get_results($query, ARRAY_A);
594
-        if (!empty($results)) {
595
-            $data = array_merge($data, $results);
596
-        }
576
+			$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>';
577
+		}
597 578
 
598
-        return $data;
599
-    }
579
+		return $content;
580
+	}
581
+
582
+	/**
583
+	 * Retrieve the attribute list used for sorting product into frontend listing
584
+	 * @return array The attribute list to use for listing sorting
585
+	 */
586
+	public static function get_sorting_criteria()
587
+	{
588
+		global $wpdb;
589
+
590
+		$data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop')));
591
+
592
+		$query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
593
+		$results = $wpdb->get_results($query, ARRAY_A);
594
+		if (!empty($results)) {
595
+			$data = array_merge($data, $results);
596
+		}
597
+
598
+		return $data;
599
+	}
600 600
 
601
-    public static function get_products_matching_attribute($attr_name, $attr_value)
602
-    {
603
-        global $wpdb;
601
+	public static function get_products_matching_attribute($attr_name, $attr_value)
602
+	{
603
+		global $wpdb;
604 604
 
605
-        $products = array();
606
-        $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
607
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
605
+		$products = array();
606
+		$query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
607
+		$data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
608 608
 
609
-        if (!empty($data)) {
610
-            if ($data['data_type_to_use'] == 'custom') {
611
-                // Find which table to take
612
-                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;}
609
+		if (!empty($data)) {
610
+			if ($data['data_type_to_use'] == 'custom') {
611
+				// Find which table to take
612
+				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;}
613 613
 
614
-                if (isset($table_name)) {
615
-                    // If the value is an id of a select, radio or checkbox
616
-                    if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
614
+				if (isset($table_name)) {
615
+					// If the value is an id of a select, radio or checkbox
616
+					if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
617 617
 
618
-                        $query = $wpdb->prepare("
618
+						$query = $wpdb->prepare("
619 619
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
620 620
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
621 621
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
622 622
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id
623 623
 							WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value
624
-                        );
625
-                        $data = $wpdb->get_results($query);
626
-                    } else {
624
+						);
625
+						$data = $wpdb->get_results($query);
626
+					} else {
627 627
 
628
-                        $query = $wpdb->prepare("
628
+						$query = $wpdb->prepare("
629 629
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
630 630
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
631 631
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
632 632
 								INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
633 633
 							WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000
634
-                        );
635
-                        $data = $wpdb->get_results($query);
636
-
637
-                    }
638
-                } else {
639
-                    return __('Incorrect shortcode', 'wpshop');
640
-                }
641
-
642
-            } elseif ($data['data_type_to_use'] == 'internal') {
643
-                /** Check the ID of manufacturer **/
644
-                $default_value = unserialize($data['default_value']);
645
-                if (!empty($default_value) && !empty($default_value['default_value'])) {
646
-                    $query = get_post($attr_value);
647
-                    $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
648
-                    if (!empty($pid)) {
649
-                        $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);
650
-                        $data = $wpdb->get_results($query);
651
-                    }
652
-                }
653
-            } else {
654
-                return __('Incorrect shortcode', 'wpshop');
655
-            }
656
-
657
-        } else {
658
-            return __('Incorrect shortcode', 'wpshop');
659
-        }
634
+						);
635
+						$data = $wpdb->get_results($query);
660 636
 
661
-        if (!empty($data)) {
662
-            foreach ($data as $p) {
663
-                if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
664
-                    $products[] = $p->entity_id;
665
-                }
666
-            }
667
-        }
668
-        return $products;
669
-    }
637
+					}
638
+				} else {
639
+					return __('Incorrect shortcode', 'wpshop');
640
+				}
670 641
 
671
-    /**
672
-     * Related product shortcode reader
673
-     *
674
-     * @param array $atts {
675
-     *    pid : Product idenfifier to get related element for
676
-     *    display_mode : The output mode if defined (grid || list)
677
-     * }
678
-     *
679
-     * @return string
680
-     *
681
-     */
682
-    public static function wpshop_related_products_func($atts)
683
-    {
684
-        global $wp_query;
642
+			} elseif ($data['data_type_to_use'] == 'internal') {
643
+				/** Check the ID of manufacturer **/
644
+				$default_value = unserialize($data['default_value']);
645
+				if (!empty($default_value) && !empty($default_value['default_value'])) {
646
+					$query = get_post($attr_value);
647
+					$pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
648
+					if (!empty($pid)) {
649
+						$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);
650
+						$data = $wpdb->get_results($query);
651
+					}
652
+				}
653
+			} else {
654
+				return __('Incorrect shortcode', 'wpshop');
655
+			}
685 656
 
686
-        $atts['product_type'] = 'related';
687
-        if (empty($atts['pid'])) {
688
-            $atts['pid'] = $wp_query->posts[0]->ID;
689
-        }
657
+		} else {
658
+			return __('Incorrect shortcode', 'wpshop');
659
+		}
660
+
661
+		if (!empty($data)) {
662
+			foreach ($data as $p) {
663
+				if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
664
+					$products[] = $p->entity_id;
665
+				}
666
+			}
667
+		}
668
+		return $products;
669
+	}
690 670
 
691
-        $related_product_output = self::wpshop_products_func($atts);
671
+	/**
672
+	 * Related product shortcode reader
673
+	 *
674
+	 * @param array $atts {
675
+	 *    pid : Product idenfifier to get related element for
676
+	 *    display_mode : The output mode if defined (grid || list)
677
+	 * }
678
+	 *
679
+	 * @return string
680
+	 *
681
+	 */
682
+	public static function wpshop_related_products_func($atts)
683
+	{
684
+		global $wp_query;
685
+
686
+		$atts['product_type'] = 'related';
687
+		if (empty($atts['pid'])) {
688
+			$atts['pid'] = $wp_query->posts[0]->ID;
689
+		}
692 690
 
693
-        $output = '';
694
-        if (!empty($related_product_output)) {
695
-            ob_start();
696
-            require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
697
-            $output = ob_get_contents();
698
-            ob_end_clean();
699
-        }
691
+		$related_product_output = self::wpshop_products_func($atts);
700 692
 
701
-        return $output;
702
-    }
693
+		$output = '';
694
+		if (!empty($related_product_output)) {
695
+			ob_start();
696
+			require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
697
+			$output = ob_get_contents();
698
+			ob_end_clean();
699
+		}
703 700
 
704
-    /**
705
-     * Display a list of product from a shortcode
706
-     *
707
-     * @param array $atts {
708
-     *    limit : The number of element to display
709
-     *    order : The information to order list by
710
-     *    sorting : List order (ASC | DESC)
711
-     *    display : Display size (normal | mini)
712
-     *    type : Display tyep (grid | list) only work with display=normal
713
-     *    pagination : The number of element per page
714
-     * display_pagination : Display the pagination or not
715
-     * }
716
-     *
717
-     * @return string
718
-     *
719
-     **/
720
-    public static function wpshop_products_func($atts)
721
-    {
722
-        global $wpdb, $wp_query;
723
-
724
-        $string = '';
725
-        $have_results = false;
726
-        $output_results = true;
727
-        $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
728
-        $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
729
-        $cid = !empty($atts['cid']) ? $atts['cid'] : 0;
730
-        $pid = !empty($atts['pid']) ? $atts['pid'] : 0;
731
-        $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
732
-        $limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
733
-        $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;
734
-        $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
735
-        $attr = '';
736
-
737
-        $sorting_criteria = self::get_sorting_criteria();
738
-
739
-        /** Get products which have att_name equal to att_value    */
740
-        if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
741
-            $attr = $atts['att_name'] . ':' . $atts['att_value'];
742
-
743
-            $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
744
-
745
-            // Foreach on the found products
746
-            if (!empty($products)) {
747
-                $pid = implode(',', $products);
748
-                if (empty($pid)) {
749
-                    $output_results = false;
750
-                }
751
-
752
-            } else {
753
-                $output_results = false;
754
-            }
701
+		return $output;
702
+	}
755 703
 
756
-        }
704
+	/**
705
+	 * Display a list of product from a shortcode
706
+	 *
707
+	 * @param array $atts {
708
+	 *    limit : The number of element to display
709
+	 *    order : The information to order list by
710
+	 *    sorting : List order (ASC | DESC)
711
+	 *    display : Display size (normal | mini)
712
+	 *    type : Display tyep (grid | list) only work with display=normal
713
+	 *    pagination : The number of element per page
714
+	 * display_pagination : Display the pagination or not
715
+	 * }
716
+	 *
717
+	 * @return string
718
+	 *
719
+	 **/
720
+	public static function wpshop_products_func($atts)
721
+	{
722
+		global $wpdb, $wp_query;
723
+
724
+		$string = '';
725
+		$have_results = false;
726
+		$output_results = true;
727
+		$type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
728
+		$pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
729
+		$cid = !empty($atts['cid']) ? $atts['cid'] : 0;
730
+		$pid = !empty($atts['pid']) ? $atts['pid'] : 0;
731
+		$order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
732
+		$limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
733
+		$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;
734
+		$display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
735
+		$attr = '';
736
+
737
+		$sorting_criteria = self::get_sorting_criteria();
738
+
739
+		/** Get products which have att_name equal to att_value    */
740
+		if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
741
+			$attr = $atts['att_name'] . ':' . $atts['att_value'];
742
+
743
+			$products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
744
+
745
+			// Foreach on the found products
746
+			if (!empty($products)) {
747
+				$pid = implode(',', $products);
748
+				if (empty($pid)) {
749
+					$output_results = false;
750
+				}
757 751
 
758
-        /** Get related products    */
759
-        if (!empty($atts['product_type'])) {
760
-            switch ($atts['product_type']) {
761
-                case 'related':
762
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
763
-                    $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
764
-                    $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;
765
-
766
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
767
-                    if (!empty($pids) && !empty($pids[0])) {
768
-                        $pid = implode(',', $pids);
769
-                    }
770
-                    if (empty($pid) || $pid == $product_id) {
771
-                        $output_results = false;
772
-                    }
773
-
774
-                    break;
775
-            }
776
-        }
752
+			} else {
753
+				$output_results = false;
754
+			}
755
+
756
+		}
777 757
 
778
-        /** Output all the products    */
779
-        if ($output_results) {
780
-            $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);
758
+		/** Get related products    */
759
+		if (!empty($atts['product_type'])) {
760
+			switch ($atts['product_type']) {
761
+				case 'related':
762
+					$product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
763
+					$type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
764
+					$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;
765
+
766
+					$pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
767
+					if (!empty($pids) && !empty($pids[0])) {
768
+						$pid = implode(',', $pids);
769
+					}
770
+					if (empty($pid) || $pid == $product_id) {
771
+						$output_results = false;
772
+					}
781 773
 
782
-            if ($data[0]) {
783
-                $have_results = true;
784
-                $string = $data[1];
785
-            }
786
-        }
774
+					break;
775
+			}
776
+		}
777
+
778
+		/** Output all the products    */
779
+		if ($output_results) {
780
+			$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);
781
+
782
+			if ($data[0]) {
783
+				$have_results = true;
784
+				$string = $data[1];
785
+			}
786
+		}
787
+
788
+		/** If there are result to display    */
789
+		if ($have_results) {
790
+			$sorting = '';
791
+			if (!empty($pid)) {
792
+				$product_list = explode(',', $pid);
793
+				if (count($product_list) == 1) {
794
+					$atts['sorting'] = 'no';
795
+				}
796
+			}
787 797
 
788
-        /** If there are result to display    */
789
-        if ($have_results) {
790
-            $sorting = '';
791
-            if (!empty($pid)) {
792
-                $product_list = explode(',', $pid);
793
-                if (count($product_list) == 1) {
794
-                    $atts['sorting'] = 'no';
795
-                }
796
-            }
797
-
798
-            /*
798
+			/*
799 799
              * Template parameters
800 800
              */
801
-            $template_part = 'product_listing_sorting';
802
-            $tpl_component = array();
801
+			$template_part = 'product_listing_sorting';
802
+			$tpl_component = array();
803 803
 
804
-            /*
804
+			/*
805 805
              * Build template
806 806
              */
807
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
808
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
809
-                /*    Include the old way template part    */
810
-                ob_start();
811
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
812
-                $sorting = ob_get_contents();
813
-                ob_end_clean();
814
-            } else {
815
-                /*
807
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
808
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
809
+				/*    Include the old way template part    */
810
+				ob_start();
811
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
812
+				$sorting = ob_get_contents();
813
+				ob_end_clean();
814
+			} else {
815
+				/*
816 816
                  * Display hidden field every times
817 817
                  */
818
-                $sub_template_part = 'product_listing_sorting_hidden_field';
819
-                $sub_tpl_component = array();
820
-                $sub_tpl_component['DISPLAY_TYPE'] = $type;
821
-                $sub_tpl_component['ORDER'] = $order_by_sorting;
822
-                $sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
823
-                $sub_tpl_component['CURRENT_PAGE'] = 1;
824
-                $sub_tpl_component['CATEGORY_ID'] = $cid;
825
-                $sub_tpl_component['PRODUCT_ID'] = $pid;
826
-                $sub_tpl_component['ATTR'] = $attr;
827
-                $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
828
-                unset($sub_tpl_component);
829
-
830
-                if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
831
-                    $sub_template_part = 'product_listing_sorting_criteria';
832
-                    $sub_tpl_component = array();
833
-                    $criteria = '';
834
-                    foreach ($sorting_criteria as $c):
835
-                        $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
836
-                    endforeach;
837
-                    $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
838
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
839
-                    unset($sub_tpl_component);
840
-                }
841
-
842
-                if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
843
-                    $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
844
-                    $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
845
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component);
846
-                } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
847
-                    $sub_template_part = 'product_listing_sorting_criteria_hidden';
848
-                    $sub_tpl_component = array();
849
-                    $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
850
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
851
-                    unset($sub_tpl_component);
852
-
853
-                    $template_part = 'product_listing_sorting_hidden';
854
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
855
-                }
856
-            }
857
-            unset($tpl_component);
858
-
859
-            if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
860
-                $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
861
-            } else {
862
-                $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>';
863
-            }
864
-        } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
865
-            $string = __('There is nothing to output here', 'wpshop');
866
-        }
818
+				$sub_template_part = 'product_listing_sorting_hidden_field';
819
+				$sub_tpl_component = array();
820
+				$sub_tpl_component['DISPLAY_TYPE'] = $type;
821
+				$sub_tpl_component['ORDER'] = $order_by_sorting;
822
+				$sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
823
+				$sub_tpl_component['CURRENT_PAGE'] = 1;
824
+				$sub_tpl_component['CATEGORY_ID'] = $cid;
825
+				$sub_tpl_component['PRODUCT_ID'] = $pid;
826
+				$sub_tpl_component['ATTR'] = $attr;
827
+				$tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
828
+				unset($sub_tpl_component);
829
+
830
+				if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
831
+					$sub_template_part = 'product_listing_sorting_criteria';
832
+					$sub_tpl_component = array();
833
+					$criteria = '';
834
+					foreach ($sorting_criteria as $c):
835
+						$criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
836
+					endforeach;
837
+					$sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
838
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
839
+					unset($sub_tpl_component);
840
+				}
867 841
 
868
-        return do_shortcode($string);
869
-    }
842
+				if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
843
+					$tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
844
+					$tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
845
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component);
846
+				} else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
847
+					$sub_template_part = 'product_listing_sorting_criteria_hidden';
848
+					$sub_tpl_component = array();
849
+					$sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
850
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
851
+					unset($sub_tpl_component);
852
+
853
+					$template_part = 'product_listing_sorting_hidden';
854
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
855
+				}
856
+			}
857
+			unset($tpl_component);
870 858
 
871
-    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)
872
-    {
873
-        global $wpdb;
859
+			if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
860
+				$string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
861
+			} else {
862
+				$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>';
863
+			}
864
+		} else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
865
+			$string = __('There is nothing to output here', 'wpshop');
866
+		}
874 867
 
875
-        $string = '<span id="wpshop_loading">&nbsp;</span>';
876
-        $have_results = false;
877
-        $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
868
+		return do_shortcode($string);
869
+	}
878 870
 
879
-        /** Check if Discount are activated */
880
-        $discount_option = get_option('wpshop_catalog_product_option');
871
+	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)
872
+	{
873
+		global $wpdb;
881 874
 
882
-        if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
883
-            $criteria = 'wpshop_displayed_price';
884
-        }
875
+		$string = '<span id="wpshop_loading">&nbsp;</span>';
876
+		$have_results = false;
877
+		$display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
885 878
 
886
-        $query = array(
887
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
888
-            'order' => $order,
889
-            'posts_per_page' => $products_per_page,
890
-            'paged' => $page_number,
891
-            'post_status' => 'publish',
892
-        );
893
-
894
-        // If the limit is greater than zero, hide pagination and change posts_per_page var
895
-        if ($nb_of_product_limit > 0) {
896
-            $query['posts_per_page'] = $nb_of_product_limit;
897
-            unset($query['paged']);
898
-        }
899
-        if (!empty($pid)) {
900
-            if (!is_array($pid)) {
901
-                $pid = explode(',', $pid);
902
-            }
879
+		/** Check if Discount are activated */
880
+		$discount_option = get_option('wpshop_catalog_product_option');
903 881
 
904
-            $query['post__in'] = $pid;
905
-        }
906
-        if (!empty($cid)) {
907
-            $cid = explode(',', $cid);
908
-            $query['tax_query'] = array(array(
909
-                'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
910
-                'field' => 'id',
911
-                'terms' => $cid,
912
-                'operator' => 'IN',
913
-            ));
914
-        }
915
-        if ($criteria != null) {
916
-            switch ($criteria) {
917
-                case 'creator':
918
-                case 'author':
919
-                    $query['author'] = get_current_user_id();
920
-                    break;
921
-                case 'none':
922
-                case 'ID':
923
-                case 'title':
924
-                case 'date':
925
-                case 'modified':
926
-                case 'relevance':
927
-                case 'post__in':
928
-                case 'rand':
929
-                    $query['orderby'] = $criteria;
930
-                    break;
931
-                default:
932
-                    if (!empty($pid)) {
933
-                        $post_meta = get_post_meta($pid, '_' . $criteria, true);
934
-                    } else {
935
-                        $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
936
-                        $post_meta = $wpdb->get_var($check_meta);
937
-                    }
938
-                    if (!empty($post_meta)) {
939
-                        if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
940
-                            $query['orderby'] = 'meta_value_num';
941
-                        } else {
942
-                            $query['orderby'] = 'meta_value';
943
-                        }
944
-                        $query['meta_key'] = '_' . $criteria;
945
-                    }
946
-                    break;
947
-            }
948
-        } else {
949
-            $query['orderby'] = 'menu_order ID';
950
-        }
951
-        $post_per_page = $query['posts_per_page'];
952
-        $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
953
-        if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
954
-            $tmp_array = array();
955
-
956
-            if (empty($page_number) || $page_number == 1) {
957
-                for ($i = 0; $i < $query['posts_per_page']; $i++) {
958
-                    $tmp_array[] = $query['post__in'][$i];
959
-                }
960
-            } else {
961
-                $begin_number = (($page_number - 1) * $query['posts_per_page']);
962
-                for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
963
-                    if (!empty($query['post__in'][$i])) {
964
-                        $tmp_array[] = $query['post__in'][$i];
965
-                    }
966
-                }
967
-            }
968
-            unset($query['post__in']);
969
-            $query['post__in'] = $tmp_array;
970
-            $query['posts_per_page'] = -1;
971
-        }
882
+		if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
883
+			$criteria = 'wpshop_displayed_price';
884
+		}
972 885
 
973
-        $query['post_status'] = 'publish';
974
-
975
-        $custom_query = new WP_Query($query);
976
-
977
-        if ($custom_query->have_posts()) {
978
-            $have_results = true;
979
-
980
-            // ---------------- //
981
-            // Products listing //
982
-            // ---------------- //
983
-            $current_position = 1;
984
-            $product_list = '';
985
-            while ($custom_query->have_posts()): $custom_query->the_post();
986
-                $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
987
-                $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
988
-                $cat_id = empty($cats) ? 0 : $cats[0]->term_id;
989
-                $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
990
-                $current_position++;
991
-            endwhile;
992
-            $tpl_component = array();
993
-            $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
994
-            $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
995
-            $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
996
-            $tpl_component['PRODUCT_LIST'] = $product_list;
997
-            $tpl_component['CROSSED_OUT_PRICE'] = '';
998
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
999
-            $string = wpshop_display::display_template_element('product_list_container', $tpl_component);
1000
-
1001
-            // --------------------- //
1002
-            // Pagination management //
1003
-            // --------------------- //
1004
-            if ( $display_pagination ) {
1005
-                if ($nb_of_product_limit == 0) {
1006
-
1007
-                    $paginate = paginate_links(array(
1008
-                        'base' => '%_%',
1009
-                        'format' => '/?page_product=%#%',
1010
-                        'current' => $page_number,
1011
-                        'total' => $custom_query->max_num_pages,
1012
-                        'type' => 'array',
1013
-                        'prev_next' => false,
1014
-                    ));
1015
-                    if (!empty($paginate)) {
1016
-                        $string .= '<ul class="pagination wps-pagination">';
1017
-                        foreach ($paginate as $p) {
1018
-                            $string .= '<li>' . $p . '</li>';
1019
-                        }
1020
-                        $string .= '</ul>';
1021
-                    }
1022
-                }
1023
-
1024
-                if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
1025
-                    $paginate = paginate_links(array(
1026
-                        'base' => '%_%',
1027
-                        'format' => '/?page_product=%#%',
1028
-                        'current' => $page_number,
1029
-                        'total' => ceil(count($total_products) / $post_per_page),
1030
-                        'type' => 'array',
1031
-                        'prev_next' => false,
1032
-                    ));
1033
-                    if (!empty($paginate)) {
1034
-                        $string .= '<ul class="pagination wps-pagination">';
1035
-                        foreach ($paginate as $p) {
1036
-                            $string .= '<li>' . $p . '</li>';
1037
-                        }
1038
-                        $string .= '</ul>';
1039
-                    }
1040
-                }
1041
-            }
886
+		$query = array(
887
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
888
+			'order' => $order,
889
+			'posts_per_page' => $products_per_page,
890
+			'paged' => $page_number,
891
+			'post_status' => 'publish',
892
+		);
893
+
894
+		// If the limit is greater than zero, hide pagination and change posts_per_page var
895
+		if ($nb_of_product_limit > 0) {
896
+			$query['posts_per_page'] = $nb_of_product_limit;
897
+			unset($query['paged']);
898
+		}
899
+		if (!empty($pid)) {
900
+			if (!is_array($pid)) {
901
+				$pid = explode(',', $pid);
902
+			}
1042 903
 
1043
-        }
1044
-        wp_reset_query(); // important
904
+			$query['post__in'] = $pid;
905
+		}
906
+		if (!empty($cid)) {
907
+			$cid = explode(',', $cid);
908
+			$query['tax_query'] = array(array(
909
+				'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
910
+				'field' => 'id',
911
+				'terms' => $cid,
912
+				'operator' => 'IN',
913
+			));
914
+		}
915
+		if ($criteria != null) {
916
+			switch ($criteria) {
917
+				case 'creator':
918
+				case 'author':
919
+					$query['author'] = get_current_user_id();
920
+					break;
921
+				case 'none':
922
+				case 'ID':
923
+				case 'title':
924
+				case 'date':
925
+				case 'modified':
926
+				case 'relevance':
927
+				case 'post__in':
928
+				case 'rand':
929
+					$query['orderby'] = $criteria;
930
+					break;
931
+				default:
932
+					if (!empty($pid)) {
933
+						$post_meta = get_post_meta($pid, '_' . $criteria, true);
934
+					} else {
935
+						$check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
936
+						$post_meta = $wpdb->get_var($check_meta);
937
+					}
938
+					if (!empty($post_meta)) {
939
+						if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
940
+							$query['orderby'] = 'meta_value_num';
941
+						} else {
942
+							$query['orderby'] = 'meta_value';
943
+						}
944
+						$query['meta_key'] = '_' . $criteria;
945
+					}
946
+					break;
947
+			}
948
+		} else {
949
+			$query['orderby'] = 'menu_order ID';
950
+		}
951
+		$post_per_page = $query['posts_per_page'];
952
+		$total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
953
+		if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
954
+			$tmp_array = array();
955
+
956
+			if (empty($page_number) || $page_number == 1) {
957
+				for ($i = 0; $i < $query['posts_per_page']; $i++) {
958
+					$tmp_array[] = $query['post__in'][$i];
959
+				}
960
+			} else {
961
+				$begin_number = (($page_number - 1) * $query['posts_per_page']);
962
+				for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
963
+					if (!empty($query['post__in'][$i])) {
964
+						$tmp_array[] = $query['post__in'][$i];
965
+					}
966
+				}
967
+			}
968
+			unset($query['post__in']);
969
+			$query['post__in'] = $tmp_array;
970
+			$query['posts_per_page'] = -1;
971
+		}
1045 972
 
1046
-        return array($have_results, $string);
1047
-    }
973
+		$query['post_status'] = 'publish';
974
+
975
+		$custom_query = new WP_Query($query);
976
+
977
+		if ($custom_query->have_posts()) {
978
+			$have_results = true;
979
+
980
+			// ---------------- //
981
+			// Products listing //
982
+			// ---------------- //
983
+			$current_position = 1;
984
+			$product_list = '';
985
+			while ($custom_query->have_posts()): $custom_query->the_post();
986
+				$cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
987
+				$cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
988
+				$cat_id = empty($cats) ? 0 : $cats[0]->term_id;
989
+				$product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
990
+				$current_position++;
991
+			endwhile;
992
+			$tpl_component = array();
993
+			$tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
994
+			$tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
995
+			$tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
996
+			$tpl_component['PRODUCT_LIST'] = $product_list;
997
+			$tpl_component['CROSSED_OUT_PRICE'] = '';
998
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
999
+			$string = wpshop_display::display_template_element('product_list_container', $tpl_component);
1000
+
1001
+			// --------------------- //
1002
+			// Pagination management //
1003
+			// --------------------- //
1004
+			if ( $display_pagination ) {
1005
+				if ($nb_of_product_limit == 0) {
1006
+
1007
+					$paginate = paginate_links(array(
1008
+						'base' => '%_%',
1009
+						'format' => '/?page_product=%#%',
1010
+						'current' => $page_number,
1011
+						'total' => $custom_query->max_num_pages,
1012
+						'type' => 'array',
1013
+						'prev_next' => false,
1014
+					));
1015
+					if (!empty($paginate)) {
1016
+						$string .= '<ul class="pagination wps-pagination">';
1017
+						foreach ($paginate as $p) {
1018
+							$string .= '<li>' . $p . '</li>';
1019
+						}
1020
+						$string .= '</ul>';
1021
+					}
1022
+				}
1048 1023
 
1049
-    /**
1050
-     * Update quantity for a product
1051
-     * @param integer $product_id The product we want to update quantity for
1052
-     * @param decimal $qty The new quantity
1053
-     */
1054
-    public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1055
-    {
1056
-        global $wpdb;
1057
-
1058
-        $product = self::get_product_data($product_id);
1059
-        /** Check if there is variation ***/
1060
-        if (!empty($variation_id) && $variation_id != $product_id) {
1061
-            $variation_post_type = get_post_type($variation_id);
1062
-            if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1063
-                /** Check if variation def is combined **/
1064
-                $variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1065
-                if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1066
-                    /** Get post meta of variation */
1067
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1068
-                    if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1069
-                        $product = self::get_product_data($variation_id);
1070
-                        $product_id = $variation_id;
1071
-                    }
1072
-                }
1073
-            }
1074
-        }
1024
+				if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
1025
+					$paginate = paginate_links(array(
1026
+						'base' => '%_%',
1027
+						'format' => '/?page_product=%#%',
1028
+						'current' => $page_number,
1029
+						'total' => ceil(count($total_products) / $post_per_page),
1030
+						'type' => 'array',
1031
+						'prev_next' => false,
1032
+					));
1033
+					if (!empty($paginate)) {
1034
+						$string .= '<ul class="pagination wps-pagination">';
1035
+						foreach ($paginate as $p) {
1036
+							$string .= '<li>' . $p . '</li>';
1037
+						}
1038
+						$string .= '</ul>';
1039
+					}
1040
+				}
1041
+			}
1042
+
1043
+		}
1044
+		wp_reset_query(); // important
1075 1045
 
1076
-        if (!empty($product)) {
1077
-            $newQty = $product['product_stock'] - $qty;
1078
-            $value_id = 0;
1079
-            if ($newQty >= 0) {
1080
-                $query = '
1046
+		return array($have_results, $string);
1047
+	}
1048
+
1049
+	/**
1050
+	 * Update quantity for a product
1051
+	 * @param integer $product_id The product we want to update quantity for
1052
+	 * @param decimal $qty The new quantity
1053
+	 */
1054
+	public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1055
+	{
1056
+		global $wpdb;
1057
+
1058
+		$product = self::get_product_data($product_id);
1059
+		/** Check if there is variation ***/
1060
+		if (!empty($variation_id) && $variation_id != $product_id) {
1061
+			$variation_post_type = get_post_type($variation_id);
1062
+			if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1063
+				/** Check if variation def is combined **/
1064
+				$variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1065
+				if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1066
+					/** Get post meta of variation */
1067
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1068
+					if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1069
+						$product = self::get_product_data($variation_id);
1070
+						$product_id = $variation_id;
1071
+					}
1072
+				}
1073
+			}
1074
+		}
1075
+
1076
+		if (!empty($product)) {
1077
+			$newQty = $product['product_stock'] - $qty;
1078
+			$value_id = 0;
1079
+			if ($newQty >= 0) {
1080
+				$query = '
1081 1081
 					SELECT wp_wpshop__attribute_value_decimal.value_id
1082 1082
 					FROM wp_wpshop__attribute_value_decimal
1083 1083
 					LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
1084 1084
 					WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
1085 1085
 					LIMIT 1
1086 1086
 				';
1087
-                $value_id = $wpdb->get_var($query);
1088
-                $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1089
-            }
1090
-            // Historic
1091
-            $attribute_histo_content = array();
1092
-            $attribute_histo_content['status'] = 'valid';
1093
-            $attribute_histo_content['creation_date'] = current_time('mysql', 0);
1094
-            $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1095
-            $attribute_histo_content['original_value_id'] = $value_id;
1096
-            $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1097
-            $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1098
-            $attribute_histo_content['attribute_id'] = $stock_atribute->id;
1099
-            $attribute_histo_content['entity_id'] = $product_id;
1100
-            $attribute_histo_content['value'] = $product['product_stock'];
1101
-            $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1102
-            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1103
-
1104
-            $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1105
-            $product_meta['product_stock'] = $newQty;
1106
-            update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1107
-        }
1108
-    }
1087
+				$value_id = $wpdb->get_var($query);
1088
+				$update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1089
+			}
1090
+			// Historic
1091
+			$attribute_histo_content = array();
1092
+			$attribute_histo_content['status'] = 'valid';
1093
+			$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1094
+			$attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1095
+			$attribute_histo_content['original_value_id'] = $value_id;
1096
+			$attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1097
+			$stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1098
+			$attribute_histo_content['attribute_id'] = $stock_atribute->id;
1099
+			$attribute_histo_content['entity_id'] = $product_id;
1100
+			$attribute_histo_content['value'] = $product['product_stock'];
1101
+			$attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1102
+			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1103
+
1104
+			$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1105
+			$product_meta['product_stock'] = $newQty;
1106
+			update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1107
+		}
1108
+	}
1109 1109
 
1110
-    /**
1111
-     * Retrieve an array with complete information about a given product
1112
-     * @param integer $product_id
1113
-     * @param boolean $for_cart_storage
1114
-     * @return array Information about the product defined by first parameter
1115
-     */
1116
-    public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1117
-    {
1118
-        global $wpdb;
1119
-        $query = $wpdb->prepare('
1110
+	/**
1111
+	 * Retrieve an array with complete information about a given product
1112
+	 * @param integer $product_id
1113
+	 * @param boolean $for_cart_storage
1114
+	 * @return array Information about the product defined by first parameter
1115
+	 */
1116
+	public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1117
+	{
1118
+		global $wpdb;
1119
+		$query = $wpdb->prepare('
1120 1120
 			SELECT P.*, PM.meta_value AS attribute_set_id
1121 1121
 			FROM ' . $wpdb->posts . ' AS P
1122 1122
 				INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID)
@@ -1128,398 +1128,398 @@  discard block
 block discarded – undo
1128 1128
 			LIMIT 1
1129 1129
 		', $product_id);
1130 1130
 
1131
-        $product = $wpdb->get_row($query);
1132
-
1133
-        $product_data = array();
1134
-        $product_meta = array();
1135
-
1136
-        if (!empty($product)) {
1137
-            $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1138
-            $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1139
-            $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1140
-            $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1141
-
1142
-            $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1143
-            $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1144
-            $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1145
-            $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1146
-
1147
-            $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1148
-
1149
-            $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);
1150
-            if (!empty($data)) {
1151
-                foreach ($data as $attribute) {
1152
-                    $data_type = 'attribute_value_' . $attribute->data_type;
1153
-                    $value = $attribute->$data_type;
1154
-                    if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1155
-                        $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1156
-                    }
1157
-
1158
-                    /** Special traitment regarding attribute_code    */
1159
-                    switch ($attribute->attribute_code) {
1160
-                        case 'product_weight':
1161
-                            $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1162
-                            if (!empty($default_weight_unity)) {
1163
-                                $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1164
-                                $unity = $wpdb->get_var($query);
1165
-                                if ($unity == 'kg') {
1166
-                                    $value *= 1000;
1167
-                                }
1168
-
1169
-                            }
1170
-                            break;
1171
-                        default:
1172
-                            $value = !empty($value) ? $value : 0;
1173
-                            break;
1174
-                    }
1175
-                    $product_data[$attribute->attribute_code] = $value;
1176
-
1177
-                    if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1178
-                        $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1179
-                        if (!empty($meta)) {
1180
-                            $product_meta[$attribute->attribute_code] = $meta;
1181
-                        }
1182
-                    }
1183
-
1184
-                    if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1185
-                        $product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1186
-                    }
1187
-                    if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1188
-                        $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1189
-                    }
1190
-                }
1191
-            } else {
1192
-
1193
-            }
1194
-
1195
-            /**    Get datas about product options    */
1196
-            if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1197
-                $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1198
-
1199
-                foreach ($variation_details as $attribute_code => $attribute_value) {
1200
-                    $variation_id = $attribute_value;
1201
-                    $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1202
-
1203
-                    $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));
1204
-                    $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1205
-                    switch ($attribute_definition->backend_input) {
1206
-                        case 'select':
1207
-                        case 'multiple-select':
1208
-                        case 'radio':
1209
-                        case 'checkbox':
1210
-                            $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1211
-                            break;
1212
-                    }
1213
-                    $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1214
-                    $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1215
-                }
1216
-            }
1217
-
1218
-            $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1219
-
1220
-            /** Get the display definition for the current product for checking custom display    */
1221
-            $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1222
-        }
1131
+		$product = $wpdb->get_row($query);
1223 1132
 
1224
-        return $product_data;
1225
-    }
1133
+		$product_data = array();
1134
+		$product_meta = array();
1226 1135
 
1227
-    /**
1228
-     * Add a product into the db. This function is used for the EDI
1229
-     * @param $name Name of the product
1230
-     * @param $description Description of the product
1231
-     * @param $attrs List of the attributes and values of the product
1232
-     * @return boolean
1233
-     */
1234
-    public function addProduct($name, $description, $attrs = array())
1235
-    {
1236
-        $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1237
-        return $new_product[0];
1238
-    }
1136
+		if (!empty($product)) {
1137
+			$product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1138
+			$product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1139
+			$product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1140
+			$product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1239 1141
 
1240
-    /**
1241
-     * Retrieve a product listing
1242
-     * @param boolean $formated If the output have to be formated or not
1243
-     * @param string $product_search Optionnal Define a search term for request
1244
-     * @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
1245
-     */
1246
-    public static function product_list($formated = false, $product_search = null)
1247
-    {
1248
-        global $wpdb;
1249
-
1250
-        $query_extra_params = $query_extra_params_value = '';
1251
-        if (!empty($product_search)) {
1252
-            $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1253
-            if (is_array($product_search)) {
1254
-                $query_extra_params = " AND ID IN (%s)";
1255
-                $query_extra_params_value = implode(",", $product_search);
1256
-            }
1257
-        }
1142
+			$product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1143
+			$product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1144
+			$product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1145
+			$product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1146
+
1147
+			$product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1148
+
1149
+			$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);
1150
+			if (!empty($data)) {
1151
+				foreach ($data as $attribute) {
1152
+					$data_type = 'attribute_value_' . $attribute->data_type;
1153
+					$value = $attribute->$data_type;
1154
+					if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1155
+						$value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1156
+					}
1157
+
1158
+					/** Special traitment regarding attribute_code    */
1159
+					switch ($attribute->attribute_code) {
1160
+						case 'product_weight':
1161
+							$default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1162
+							if (!empty($default_weight_unity)) {
1163
+								$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1164
+								$unity = $wpdb->get_var($query);
1165
+								if ($unity == 'kg') {
1166
+									$value *= 1000;
1167
+								}
1168
+
1169
+							}
1170
+							break;
1171
+						default:
1172
+							$value = !empty($value) ? $value : 0;
1173
+							break;
1174
+					}
1175
+					$product_data[$attribute->attribute_code] = $value;
1176
+
1177
+					if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1178
+						$meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1179
+						if (!empty($meta)) {
1180
+							$product_meta[$attribute->attribute_code] = $meta;
1181
+						}
1182
+					}
1183
+
1184
+					if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1185
+						$product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1186
+					}
1187
+					if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1188
+						$product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1189
+					}
1190
+				}
1191
+			} else {
1192
+
1193
+			}
1194
+
1195
+			/**    Get datas about product options    */
1196
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1197
+				$variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1198
+
1199
+				foreach ($variation_details as $attribute_code => $attribute_value) {
1200
+					$variation_id = $attribute_value;
1201
+					$attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1202
+
1203
+					$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));
1204
+					$product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1205
+					switch ($attribute_definition->backend_input) {
1206
+						case 'select':
1207
+						case 'multiple-select':
1208
+						case 'radio':
1209
+						case 'checkbox':
1210
+							$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1211
+							break;
1212
+					}
1213
+					$product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1214
+					$product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1215
+				}
1216
+			}
1217
+
1218
+			$product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1219
+
1220
+			/** Get the display definition for the current product for checking custom display    */
1221
+			$product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1222
+		}
1223
+
1224
+		return $product_data;
1225
+	}
1226
+
1227
+	/**
1228
+	 * Add a product into the db. This function is used for the EDI
1229
+	 * @param $name Name of the product
1230
+	 * @param $description Description of the product
1231
+	 * @param $attrs List of the attributes and values of the product
1232
+	 * @return boolean
1233
+	 */
1234
+	public function addProduct($name, $description, $attrs = array())
1235
+	{
1236
+		$new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1237
+		return $new_product[0];
1238
+	}
1239
+
1240
+	/**
1241
+	 * Retrieve a product listing
1242
+	 * @param boolean $formated If the output have to be formated or not
1243
+	 * @param string $product_search Optionnal Define a search term for request
1244
+	 * @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
1245
+	 */
1246
+	public static function product_list($formated = false, $product_search = null)
1247
+	{
1248
+		global $wpdb;
1249
+
1250
+		$query_extra_params = $query_extra_params_value = '';
1251
+		if (!empty($product_search)) {
1252
+			$query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1253
+			if (is_array($product_search)) {
1254
+				$query_extra_params = " AND ID IN (%s)";
1255
+				$query_extra_params_value = implode(",", $product_search);
1256
+			}
1257
+		}
1258 1258
 
1259
-        $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);
1260
-        $data = $wpdb->get_results($query);
1259
+		$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);
1260
+		$data = $wpdb->get_results($query);
1261 1261
 
1262
-        /*
1262
+		/*
1263 1263
          * Make some arangement on output if parameter is given
1264 1264
          */
1265
-        if ($formated) {
1266
-            $product_string = '';
1267
-            foreach ($data as $d) {
1268
-                $product_string .= '
1265
+		if ($formated) {
1266
+			$product_string = '';
1267
+			foreach ($data as $d) {
1268
+				$product_string .= '
1269 1269
 					<li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" >
1270 1270
 						<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>
1271 1271
 					</li>';
1272
-            }
1273
-        }
1272
+			}
1273
+		}
1274 1274
 
1275
-        return $formated ? $product_string : $data;
1276
-    }
1275
+		return $formated ? $product_string : $data;
1276
+	}
1277 1277
 
1278
-    /**
1279
-     * Enregistrement des données pour le produit
1280
-     */
1281
-    public function save_product_custom_informations($post_id, $data_to_save = array())
1282
-    {
1283
-        global $wpdb;
1284
-
1285
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1286
-        // Apply a filter to extra actions
1287
-        $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1288
-
1289
-        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"))) {
1290
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1291
-                /*    Fill the product reference automatically if nothing is sent    */
1292
-                if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1293
-                    $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1294
-                    $last_ref = $wpdb->get_var($query);
1295
-                    $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;
1296
-                } else {
1297
-                    /* Check if the product reference existing in the database */
1298
-                    $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1299
-                    $query = $wpdb->prepare(
1300
-                        "SELECT value_id
1278
+	/**
1279
+	 * Enregistrement des données pour le produit
1280
+	 */
1281
+	public function save_product_custom_informations($post_id, $data_to_save = array())
1282
+	{
1283
+		global $wpdb;
1284
+
1285
+		$data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1286
+		// Apply a filter to extra actions
1287
+		$data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1288
+
1289
+		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"))) {
1290
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1291
+				/*    Fill the product reference automatically if nothing is sent    */
1292
+				if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1293
+					$query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1294
+					$last_ref = $wpdb->get_var($query);
1295
+					$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;
1296
+				} else {
1297
+					/* Check if the product reference existing in the database */
1298
+					$ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1299
+					$query = $wpdb->prepare(
1300
+						"SELECT value_id
1301 1301
 						FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
1302 1302
 							INNER JOIN {$wpdb->posts} ON ( ID = entity_id )
1303 1303
 						WHERE value = %s
1304 1304
 							AND entity_id != %d
1305 1305
 							AND entity_type_id = %d"
1306
-                        , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1307
-                    $existing_reference = $wpdb->get_var($query);
1308
-
1309
-                    /* If this product reference exist -> Create a new product reference */
1310
-                    if ($wpdb->num_rows > 0) {
1311
-                        $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1312
-                        $last_ref = $wpdb->get_var($query);
1313
-                        $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;
1314
-                    }
1315
-                }
1316
-
1317
-                /*    Save the attributes values into wpshop eav database    */
1318
-                $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1319
-                $lang = WPSHOP_CURRENT_LOCALE;
1320
-                if (!empty($data_to_save['icl_post_language'])) {
1321
-                    $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1322
-                    $lang = $wpdb->get_var($query);
1323
-                }
1324
-                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);
1325
-
1326
-                /*    Update product price looking for shop parameters    */
1327
-                wpshop_products::calculate_price($data_to_save['post_ID']);
1328
-
1329
-                /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1330
-                $productMetaDatas = array();
1331
-                foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1332
-                    foreach ($attributeValues as $attributeCode => $attributeValue) {
1333
-                        if ($attributeCode == 'product_attribute_set_id') {
1334
-                            /*    Update the attribute set id for the current product    */
1335
-                            update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1336
-                        }
1337
-                        if ($attributeType == 'decimal') {
1338
-                            $attributeValue = str_replace(',', '.', $attributeValue);
1339
-                        }
1340
-                        if (($attributeType == 'integer') && !is_array($attributeValue)) {
1341
-                            $attributeValue = (int) $attributeValue;
1342
-                        }
1343
-                        $productMetaDatas[$attributeCode] = $attributeValue;
1344
-                    }
1345
-                }
1346
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1347
-            }
1348
-
1349
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1350
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1351
-            } else if ($data_to_save['action'] != 'autosave') {
1352
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1353
-            }
1354
-
1355
-            $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1356
-            if (empty($product['product_id'])) {
1357
-                $product['product_id'] = $data_to_save['post_ID'];
1358
-            }
1359
-            $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1360
-            update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1361
-
1362
-            /**    Save product variation    */
1363
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1364
-                foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1365
-
1366
-                    foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1367
-                        $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1368
-                        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])) {
1369
-                            $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;
1370
-                        }
1371
-                    }
1372
-                    $lang = WPSHOP_CURRENT_LOCALE;
1373
-                    if (!empty($data_to_save['icl_post_language'])) {
1374
-                        $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1375
-                        $lang = $wpdb->get_var($query);
1376
-                    }
1377
-                    wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1378
-
1379
-                    /**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1380
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1381
-                    if (!empty($variation_metadata)) {
1382
-                        $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1383
-                        if (!empty($attributes_list)) {
1384
-                            foreach ($attributes_list as $attribute) {
1385
-                                $value_key = 'attribute_value_' . $attribute->data_type;
1386
-                                $attributeValue = $attribute->$value_key;
1387
-                                if ($attribute->data_type == 'decimal') {
1388
-                                    $attributeValue = str_replace(',', '.', $attribute->$value_key);
1389
-                                }
1390
-                                if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1391
-                                    $attributeValue = (int) $attribute->$value_key;
1392
-                                }
1393
-                                $variation_metadata[$attribute->code] = $attribute->$value_key;
1394
-                            }
1395
-                        }
1396
-                    }
1397
-
1398
-                    foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1399
-                        foreach ($attributeValues as $attributeCode => $attributeValue) {
1400
-                            if ($attributeType == 'decimal') {
1401
-                                $attributeValue = str_replace(',', '.', $attributeValue);
1402
-                            }
1403
-                            if (($attributeType == 'integer') && !is_array($attributeValue)) {
1404
-                                $attributeValue = (int) $attributeValue;
1405
-                            }
1406
-                            $variation_metadata[$attributeCode] = $attributeValue;
1407
-                        }
1408
-                    }
1409
-                    update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1410
-
1411
-                    /** Save attached picture id **/
1412
-                    $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']) : '';
1413
-                    $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1414
-
1415
-                    /*    Update product price looking for shop parameters    */
1416
-                    wpshop_products::calculate_price($variation_id);
1417
-                }
1418
-            }
1419
-
1420
-            /*    Update the related products list*/
1421
-            if (!empty($data_to_save['related_products_list'])) {
1422
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1423
-            } else if ($data_to_save['action'] != 'autosave') {
1424
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1425
-            }
1426
-            /*    Update the provider list*/
1427
-            if (!empty($data_to_save['provider_list'])) {
1428
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1429
-            } else if ($data_to_save['action'] != 'autosave') {
1430
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1431
-            }
1432
-
1433
-            /*    Update product options    */
1434
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1435
-                update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1436
-            } else if ($data_to_save['action'] != 'autosave') {
1437
-                delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1438
-            }
1439
-
1440
-            /** Add flag on variations to check which type of variation **/
1441
-            $check_product_have_variations = self::get_variation($post_id);
1442
-            if (!empty($check_product_have_variations)) {
1443
-                $variation_flag = self::check_variation_type($post_id);
1444
-                $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1445
-                $variation_defining['variation_type'] = $variation_flag;
1446
-                update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1447
-            }
1448
-            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);
1449
-        }
1306
+						, $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1307
+					$existing_reference = $wpdb->get_var($query);
1308
+
1309
+					/* If this product reference exist -> Create a new product reference */
1310
+					if ($wpdb->num_rows > 0) {
1311
+						$query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1312
+						$last_ref = $wpdb->get_var($query);
1313
+						$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;
1314
+					}
1315
+				}
1450 1316
 
1451
-        flush_rewrite_rules();
1452
-    }
1317
+				/*    Save the attributes values into wpshop eav database    */
1318
+				$update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1319
+				$lang = WPSHOP_CURRENT_LOCALE;
1320
+				if (!empty($data_to_save['icl_post_language'])) {
1321
+					$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1322
+					$lang = $wpdb->get_var($query);
1323
+				}
1324
+				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);
1325
+
1326
+				/*    Update product price looking for shop parameters    */
1327
+				wpshop_products::calculate_price($data_to_save['post_ID']);
1328
+
1329
+				/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1330
+				$productMetaDatas = array();
1331
+				foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1332
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
1333
+						if ($attributeCode == 'product_attribute_set_id') {
1334
+							/*    Update the attribute set id for the current product    */
1335
+							update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1336
+						}
1337
+						if ($attributeType == 'decimal') {
1338
+							$attributeValue = str_replace(',', '.', $attributeValue);
1339
+						}
1340
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1341
+							$attributeValue = (int) $attributeValue;
1342
+						}
1343
+						$productMetaDatas[$attributeCode] = $attributeValue;
1344
+					}
1345
+				}
1346
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1347
+			}
1453 1348
 
1454
-    /**
1455
-     * Return the variation type
1456
-     * @param integer $post_id
1457
-     * @return string
1458
-     */
1459
-    public function check_variation_type($post_id)
1460
-    {
1461
-        $variation_type = 'single';
1462
-        if (!empty($variation_type)) {
1463
-            $variations = self::get_variation($post_id);
1464
-            if (!empty($variations)) {
1465
-                foreach ($variations as $variation_id => $variation_data) {
1466
-                    if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1467
-                        return 'single';
1468
-                    } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1469
-                        $variation_type = 'combined';
1470
-                    }
1471
-                }
1472
-            }
1473
-        }
1474
-        return $variation_type;
1475
-    }
1349
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1350
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1351
+			} else if ($data_to_save['action'] != 'autosave') {
1352
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1353
+			}
1476 1354
 
1477
-    /**
1478
-     * Allows to define a specific permalink for each product by checking the parent categories
1479
-     *
1480
-     * @param mixed $permalink The actual permalink of the element
1481
-     * @param object $post The post we want to set the permalink for
1482
-     * @param void
1483
-     *
1484
-     * @return mixed The new permalink for the current element
1485
-     */
1486
-    public static function set_product_permalink($permalink, $post, $unknown)
1487
-    {
1488
-        $options = get_option('wpshop_catalog_product_option', array());
1489
-
1490
-        if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1491
-            if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1492
-                return $permalink;
1493
-            } else {
1494
-                $options_cats = get_option('wpshop_catalog_categories_option', array());
1495
-                $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1496
-                if (empty($product_categories)) {
1497
-                    $product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1498
-                } else {
1499
-                    $product_category_slug = $product_categories[0]->slug;
1500
-                }
1501
-                $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1502
-            }
1503
-        }
1355
+			$product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1356
+			if (empty($product['product_id'])) {
1357
+				$product['product_id'] = $data_to_save['post_ID'];
1358
+			}
1359
+			$price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1360
+			update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1361
+
1362
+			/**    Save product variation    */
1363
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1364
+				foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1365
+
1366
+					foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1367
+						$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1368
+						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])) {
1369
+							$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;
1370
+						}
1371
+					}
1372
+					$lang = WPSHOP_CURRENT_LOCALE;
1373
+					if (!empty($data_to_save['icl_post_language'])) {
1374
+						$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1375
+						$lang = $wpdb->get_var($query);
1376
+					}
1377
+					wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1378
+
1379
+					/**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1380
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1381
+					if (!empty($variation_metadata)) {
1382
+						$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1383
+						if (!empty($attributes_list)) {
1384
+							foreach ($attributes_list as $attribute) {
1385
+								$value_key = 'attribute_value_' . $attribute->data_type;
1386
+								$attributeValue = $attribute->$value_key;
1387
+								if ($attribute->data_type == 'decimal') {
1388
+									$attributeValue = str_replace(',', '.', $attribute->$value_key);
1389
+								}
1390
+								if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1391
+									$attributeValue = (int) $attribute->$value_key;
1392
+								}
1393
+								$variation_metadata[$attribute->code] = $attribute->$value_key;
1394
+							}
1395
+						}
1396
+					}
1504 1397
 
1505
-        return $permalink;
1398
+					foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1399
+						foreach ($attributeValues as $attributeCode => $attributeValue) {
1400
+							if ($attributeType == 'decimal') {
1401
+								$attributeValue = str_replace(',', '.', $attributeValue);
1402
+							}
1403
+							if (($attributeType == 'integer') && !is_array($attributeValue)) {
1404
+								$attributeValue = (int) $attributeValue;
1405
+							}
1406
+							$variation_metadata[$attributeCode] = $attributeValue;
1407
+						}
1408
+					}
1409
+					update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1506 1410
 
1507
-        //echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1411
+					/** Save attached picture id **/
1412
+					$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']) : '';
1413
+					$selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1508 1414
 
1509
-        //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1415
+					/*    Update product price looking for shop parameters    */
1416
+					wpshop_products::calculate_price($variation_id);
1417
+				}
1418
+			}
1510 1419
 
1511
-        /*if(false) {
1512
-        global $wp_query;
1513
-        $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1420
+			/*    Update the related products list*/
1421
+			if (!empty($data_to_save['related_products_list'])) {
1422
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1423
+			} else if ($data_to_save['action'] != 'autosave') {
1424
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1425
+			}
1426
+			/*    Update the provider list*/
1427
+			if (!empty($data_to_save['provider_list'])) {
1428
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1429
+			} else if ($data_to_save['action'] != 'autosave') {
1430
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1431
+			}
1432
+
1433
+			/*    Update product options    */
1434
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1435
+				update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1436
+			} else if ($data_to_save['action'] != 'autosave') {
1437
+				delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1438
+			}
1439
+
1440
+			/** Add flag on variations to check which type of variation **/
1441
+			$check_product_have_variations = self::get_variation($post_id);
1442
+			if (!empty($check_product_have_variations)) {
1443
+				$variation_flag = self::check_variation_type($post_id);
1444
+				$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1445
+				$variation_defining['variation_type'] = $variation_flag;
1446
+				update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1447
+			}
1448
+			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);
1449
+		}
1450
+
1451
+		flush_rewrite_rules();
1452
+	}
1453
+
1454
+	/**
1455
+	 * Return the variation type
1456
+	 * @param integer $post_id
1457
+	 * @return string
1458
+	 */
1459
+	public function check_variation_type($post_id)
1460
+	{
1461
+		$variation_type = 'single';
1462
+		if (!empty($variation_type)) {
1463
+			$variations = self::get_variation($post_id);
1464
+			if (!empty($variations)) {
1465
+				foreach ($variations as $variation_id => $variation_data) {
1466
+					if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1467
+						return 'single';
1468
+					} elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1469
+						$variation_type = 'combined';
1470
+					}
1471
+				}
1472
+			}
1473
+		}
1474
+		return $variation_type;
1475
+	}
1476
+
1477
+	/**
1478
+	 * Allows to define a specific permalink for each product by checking the parent categories
1479
+	 *
1480
+	 * @param mixed $permalink The actual permalink of the element
1481
+	 * @param object $post The post we want to set the permalink for
1482
+	 * @param void
1483
+	 *
1484
+	 * @return mixed The new permalink for the current element
1485
+	 */
1486
+	public static function set_product_permalink($permalink, $post, $unknown)
1487
+	{
1488
+		$options = get_option('wpshop_catalog_product_option', array());
1489
+
1490
+		if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1491
+			if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1492
+				return $permalink;
1493
+			} else {
1494
+				$options_cats = get_option('wpshop_catalog_categories_option', array());
1495
+				$product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1496
+				if (empty($product_categories)) {
1497
+					$product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1498
+				} else {
1499
+					$product_category_slug = $product_categories[0]->slug;
1500
+				}
1501
+				$permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1502
+			}
1503
+		}
1504
+
1505
+		return $permalink;
1506
+
1507
+		//echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1508
+
1509
+		//wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1510
+
1511
+		/*if(false) {
1512
+        global $wp_query;
1513
+        $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1514 1514
 
1515 1515
         if(count($product_categories) == 0){            /*    Product has only one category we get the only available slug    */
1516
-        /*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1516
+		/*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1517 1517
         }
1518 1518
         elseif(count($product_categories) == 1){    /*    Product has only one category we get the only available slug    */
1519
-        /*        $product_category_slug = $product_categories[0]->slug;
1519
+		/*        $product_category_slug = $product_categories[0]->slug;
1520 1520
         }
1521 1521
         else{                                                                            /*    Product has several categories choose the slug of the we want    */
1522
-        /*        $product_category_slugs = array();
1522
+		/*        $product_category_slugs = array();
1523 1523
     foreach($product_categories as $product_category){
1524 1524
     $product_category_slugs[] = $product_category->slug;
1525 1525
     }
@@ -1529,457 +1529,457 @@  discard block
 block discarded – undo
1529 1529
     $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1530 1530
     return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID );
1531 1531
     }*/
1532
-    }
1532
+	}
1533 1533
 
1534
-    public static function set_product_request_by_name($query)
1535
-    {
1536
-        $options = get_option('wpshop_catalog_product_option', array());
1534
+	public static function set_product_request_by_name($query)
1535
+	{
1536
+		$options = get_option('wpshop_catalog_product_option', array());
1537 1537
 
1538
-        if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1539
-        //    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1540
-    }
1538
+		if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1539
+		//    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1540
+	}
1541 1541
 
1542
-    /**
1543
-     *    Define output for product
1544
-     *
1545
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1546
-     *    @param integer $product_id The product identifier we want to get and output attribute for
1547
-     *
1548
-     *    @return mixed $content The content to add or to modify the product output in frontend
1549
-     */
1550
-    public static function product_complete_sheet_output($initialContent, $product_id)
1551
-    {
1552
-        $content = $attributeContentOutput = '';
1553
-        $wps_product_ctr = new wps_product_ctr();
1554
-        /** Log number of view for the current product    */
1555
-        $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1556
-        $product_view_number++;
1557
-        update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1558
-
1559
-        /** Get product definition    */
1560
-
1561
-        $product = self::get_product_data($product_id);
1562
-        wp_cache_set('wpshop_product_data_' . $product_id, $product);
1563
-
1564
-        /** Get the product thumbnail    */
1565
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1566
-        if (has_post_thumbnail($product_id)) {
1567
-            $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1568
-            $tpl_component = array();
1569
-            $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1570
-            $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1571
-            $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1572
-            $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1573
-            if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1574
-                foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1575
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1576
-                    $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;
1577
-                }
1578
-            }
1579
-            $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;
1580
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1581
-            unset($tpl_component);
1582
-        }
1542
+	/**
1543
+	 *    Define output for product
1544
+	 *
1545
+	 *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1546
+	 *    @param integer $product_id The product identifier we want to get and output attribute for
1547
+	 *
1548
+	 *    @return mixed $content The content to add or to modify the product output in frontend
1549
+	 */
1550
+	public static function product_complete_sheet_output($initialContent, $product_id)
1551
+	{
1552
+		$content = $attributeContentOutput = '';
1553
+		$wps_product_ctr = new wps_product_ctr();
1554
+		/** Log number of view for the current product    */
1555
+		$product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1556
+		$product_view_number++;
1557
+		update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1558
+
1559
+		/** Get product definition    */
1560
+
1561
+		$product = self::get_product_data($product_id);
1562
+		wp_cache_set('wpshop_product_data_' . $product_id, $product);
1563
+
1564
+		/** Get the product thumbnail    */
1565
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1566
+		if (has_post_thumbnail($product_id)) {
1567
+			$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1568
+			$tpl_component = array();
1569
+			$tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1570
+			$tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1571
+			$tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1572
+			$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1573
+			if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1574
+				foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1575
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1576
+					$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;
1577
+				}
1578
+			}
1579
+			$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;
1580
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1581
+			unset($tpl_component);
1582
+		}
1583 1583
 
1584
-        $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1585
-
1586
-        /**    Retrieve product attributes for output    */
1587
-        $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1588
-
1589
-        /** Retrieve product price */
1590
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1591
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1592
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1593
-        $productPrice = '';
1594
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1595
-        $check_product_price = wpshop_prices::check_product_price($product);
1596
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1597
-        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)) {
1598
-            $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1599
-        }
1584
+		$product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1585
+
1586
+		/**    Retrieve product attributes for output    */
1587
+		$attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1588
+
1589
+		/** Retrieve product price */
1590
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1591
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1592
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1593
+		$productPrice = '';
1594
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1595
+		$check_product_price = wpshop_prices::check_product_price($product);
1596
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1597
+		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)) {
1598
+			$productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1599
+		}
1600 1600
 
1601
-        /** Check if there is at less 1 product in stock    */
1602
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1603
-        $productStock = ($productStock === true) ? 1 : null;
1601
+		/** Check if there is at less 1 product in stock    */
1602
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1603
+		$productStock = ($productStock === true) ? 1 : null;
1604 1604
 
1605
-        /** if !product stock check product have variation with stock **/
1605
+		/** if !product stock check product have variation with stock **/
1606 1606
 //         if ( empty($productStock) ) {
1607
-        $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1608
-        if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1609
-            $variations = wpshop_products::get_variation($product_id);
1610
-            if (!empty($variations)) {
1611
-                foreach ($variations as $variation) {
1612
-                    if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1613
-                        $productStock = 1;
1614
-                    }
1615
-                }
1616
-            }
1617
-        }
1607
+		$product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1608
+		if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1609
+			$variations = wpshop_products::get_variation($product_id);
1610
+			if (!empty($variations)) {
1611
+				foreach ($variations as $variation) {
1612
+					if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1613
+						$productStock = 1;
1614
+					}
1615
+				}
1616
+			}
1617
+		}
1618 1618
 //         }
1619 1619
 
1620
-        /** Define "Add to cart" button     */
1621
-        $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');
1622
-        $display_price_state_when_price_is_empty = true;
1623
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1624
-            $display_price_state_when_price_is_empty = false;
1625
-        } else if (!empty($productPrice)) {
1626
-            $display_price_state_when_price_is_empty = true;
1627
-        }
1628
-        $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') : '';
1629
-        $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)) : '';
1630
-
1631
-        /** Define "Ask a quotation" button    */
1632
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1633
-
1634
-        /** Template parameters    */
1635
-        $template_part = 'product_complete_tpl';
1636
-        $tpl_component = array();
1637
-
1638
-        $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1639
-        $tpl_component['PRODUCT_ID'] = $product_id;
1640
-        $tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1641
-        $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1642
-        $tpl_component['PRODUCT_GALERY_PICS'] = '';
1643
-        $tpl_component['PRODUCT_PRICE'] = $productPrice;
1644
-        $modules_option = get_option('wpshop_modules');
1645
-        $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1646
-        if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1647
-            $wps_marketing_tools = new wps_marketing_tools_ctr();
1648
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1649
-        }
1620
+		/** Define "Add to cart" button     */
1621
+		$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');
1622
+		$display_price_state_when_price_is_empty = true;
1623
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1624
+			$display_price_state_when_price_is_empty = false;
1625
+		} else if (!empty($productPrice)) {
1626
+			$display_price_state_when_price_is_empty = true;
1627
+		}
1628
+		$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') : '';
1629
+		$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)) : '';
1630
+
1631
+		/** Define "Ask a quotation" button    */
1632
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1633
+
1634
+		/** Template parameters    */
1635
+		$template_part = 'product_complete_tpl';
1636
+		$tpl_component = array();
1637
+
1638
+		$tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1639
+		$tpl_component['PRODUCT_ID'] = $product_id;
1640
+		$tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1641
+		$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1642
+		$tpl_component['PRODUCT_GALERY_PICS'] = '';
1643
+		$tpl_component['PRODUCT_PRICE'] = $productPrice;
1644
+		$modules_option = get_option('wpshop_modules');
1645
+		$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1646
+		if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1647
+			$wps_marketing_tools = new wps_marketing_tools_ctr();
1648
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1649
+		}
1650 1650
 
1651
-        /** Gallery **/
1652
-        $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1653
-
1654
-        $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'] : ''));
1655
-
1656
-        $product_new = $product_new_def['output'];
1657
-        $product_class = $product_new_def['class'];
1658
-
1659
-        $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'] : ''));
1660
-        $product_featured = $product_featured_def['output'];
1661
-        $product_class .= $product_featured_def['class'];
1662
-
1663
-        $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1664
-        $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1665
-        $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1666
-
1667
-        $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1668
-        $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1669
-        $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1670
-        $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1671
-        $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1672
-        $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1673
-        $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1674
-        $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1675
-
1676
-        /** Build template    */
1677
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1678
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1679
-            /*    Include the old way template part    */
1680
-            ob_start();
1681
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
1682
-            $content = ob_get_contents();
1683
-            ob_end_clean();
1684
-        } else {
1685
-            $content = wpshop_display::display_template_element($template_part, $tpl_component);
1686
-        }
1687
-        unset($tpl_component);
1688
-        return $content;
1689
-    }
1651
+		/** Gallery **/
1652
+		$tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1653
+
1654
+		$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'] : ''));
1655
+
1656
+		$product_new = $product_new_def['output'];
1657
+		$product_class = $product_new_def['class'];
1658
+
1659
+		$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'] : ''));
1660
+		$product_featured = $product_featured_def['output'];
1661
+		$product_class .= $product_featured_def['class'];
1662
+
1663
+		$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1664
+		$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1665
+		$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1666
+
1667
+		$tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1668
+		$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1669
+		$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1670
+		$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1671
+		$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1672
+		$tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1673
+		$tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1674
+		$tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1675
+
1676
+		/** Build template    */
1677
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1678
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1679
+			/*    Include the old way template part    */
1680
+			ob_start();
1681
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
1682
+			$content = ob_get_contents();
1683
+			ob_end_clean();
1684
+		} else {
1685
+			$content = wpshop_display::display_template_element($template_part, $tpl_component);
1686
+		}
1687
+		unset($tpl_component);
1688
+		return $content;
1689
+	}
1690 1690
 
1691
-    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)
1692
-    {
1693
-        $content = '';
1694
-        $product_information = $product_class = '';
1691
+	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)
1692
+	{
1693
+		$content = '';
1694
+		$product_information = $product_class = '';
1695 1695
 
1696
-        /** Get the product thumbnail    */
1697
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1698
-        if (has_post_thumbnail($product_id)) {
1699
-            $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1700
-        }
1696
+		/** Get the product thumbnail    */
1697
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1698
+		if (has_post_thumbnail($product_id)) {
1699
+			$productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1700
+		}
1701 1701
 
1702
-        $product = self::get_product_data($product_id);
1702
+		$product = self::get_product_data($product_id);
1703 1703
 
1704
-        /**    Get the product information for output    */
1705
-        if (!empty($product)) {
1704
+		/**    Get the product information for output    */
1705
+		if (!empty($product)) {
1706 1706
 
1707
-            $product_title = $product['post_title'];
1708
-            $product_name = $product['post_name'];
1709
-            $product_link = get_permalink($product_id);
1710
-            $product_more_informations = $product['product_content'];
1711
-            $product_excerpt = $product['product_excerpt'];
1707
+			$product_title = $product['post_title'];
1708
+			$product_name = $product['post_name'];
1709
+			$product_link = get_permalink($product_id);
1710
+			$product_more_informations = $product['product_content'];
1711
+			$product_excerpt = $product['product_excerpt'];
1712 1712
 
1713
-            if (strpos($product['product_content'], '<!--more-->')) {
1714
-                $post_content = explode('<!--more-->', $product['product_content']);
1715
-                $product_more_informations = $post_content[0];
1716
-            }
1713
+			if (strpos($product['product_content'], '<!--more-->')) {
1714
+				$post_content = explode('<!--more-->', $product['product_content']);
1715
+				$product_more_informations = $post_content[0];
1716
+			}
1717 1717
 
1718
-        } else {
1719
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1720
-            $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1721
-            $product_link = '';
1722
-            $product_more_informations = '';
1723
-            $product_excerpt = '';
1724
-        }
1718
+		} else {
1719
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1720
+			$product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1721
+			$product_link = '';
1722
+			$product_more_informations = '';
1723
+			$product_excerpt = '';
1724
+		}
1725 1725
 
1726
-        /** Retrieve product price    */
1727
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1728
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1729
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1730
-        $productPrice = '';
1731
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1732
-        $check_product_price = wpshop_prices::check_product_price($product);
1733
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1734
-        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)) {
1735
-            $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1736
-
1737
-            if (!empty($product_price_infos)) {
1738
-                $tpl_component_price = array();
1739
-                /** Price piloting **/
1726
+		/** Retrieve product price    */
1727
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1728
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1729
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1730
+		$productPrice = '';
1731
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1732
+		$check_product_price = wpshop_prices::check_product_price($product);
1733
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1734
+		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)) {
1735
+			$product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1736
+
1737
+			if (!empty($product_price_infos)) {
1738
+				$tpl_component_price = array();
1739
+				/** Price piloting **/
1740 1740
 				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1741 1741
 				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1742
-                $price_ploting = get_option('wpshop_shop_price_piloting');
1743
-                $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'])) : '';
1744
-                $variations = wpshop_products::get_variation($product_id);
1742
+				$price_ploting = get_option('wpshop_shop_price_piloting');
1743
+				$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'])) : '';
1744
+				$variations = wpshop_products::get_variation($product_id);
1745 1745
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1746 1746
 				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1747 1747
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1748 1748
 				}
1749
-                $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1750
-                $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1751
-                $product_price_infos['MESSAGE_SAVE_MONEY'];
1752
-                $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1753
-            } else {
1754
-                $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1755
-            }
1756
-        }
1749
+				$tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1750
+				$tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1751
+				$product_price_infos['MESSAGE_SAVE_MONEY'];
1752
+				$productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1753
+			} else {
1754
+				$productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1755
+			}
1756
+		}
1757 1757
 
1758
-        /** Check if there is at less 1 product in stock    */
1759
-        $wps_product_ctr = new wps_product_ctr();
1760
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1761
-        $productStock = $productStock === true ? 1 : null;
1762
-
1763
-        /** Define "Add to cart" button    */
1764
-        $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');
1765
-        $display_price_state_when_price_is_empty = false;
1766
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1767
-            $display_price_state_when_price_is_empty = false;
1768
-        } else if (!empty($productPrice)) {
1769
-            $display_price_state_when_price_is_empty = true;
1770
-        }
1771
-        $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') : '';
1772
-        $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)) : '';
1758
+		/** Check if there is at less 1 product in stock    */
1759
+		$wps_product_ctr = new wps_product_ctr();
1760
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1761
+		$productStock = $productStock === true ? 1 : null;
1762
+
1763
+		/** Define "Add to cart" button    */
1764
+		$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');
1765
+		$display_price_state_when_price_is_empty = false;
1766
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1767
+			$display_price_state_when_price_is_empty = false;
1768
+		} else if (!empty($productPrice)) {
1769
+			$display_price_state_when_price_is_empty = true;
1770
+		}
1771
+		$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') : '';
1772
+		$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)) : '';
1773 1773
 
1774
-        /** Define "Ask a quotation" button    */
1775
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1776
-        $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'] : ''));
1774
+		/** Define "Ask a quotation" button    */
1775
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1776
+		$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'] : ''));
1777 1777
 
1778
-        $product_new = $product_new_def['output'];
1779
-        $product_class .= $product_new_def['class'];
1778
+		$product_new = $product_new_def['output'];
1779
+		$product_class .= $product_new_def['class'];
1780 1780
 
1781
-        $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'] : ''));
1782
-        $product_featured = $product_featured_def['output'];
1783
-        $product_class .= $product_featured_def['class'];
1781
+		$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'] : ''));
1782
+		$product_featured = $product_featured_def['output'];
1783
+		$product_class .= $product_featured_def['class'];
1784 1784
 
1785
-        if (!($current_item_position % $grid_element_nb_per_line)) {
1786
-            $product_class .= ' wpshop_last_product_of_line';
1787
-        }
1785
+		if (!($current_item_position % $grid_element_nb_per_line)) {
1786
+			$product_class .= ' wpshop_last_product_of_line';
1787
+		}
1788 1788
 
1789
-        if (!empty($product['product_id'])) {
1790
-            /** Template parameters    */
1791
-            $template_part = 'product_mini_' . $output_type;
1792
-            $tpl_component = array();
1793
-            $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1794
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1795
-            $tpl_component['PRODUCT_ID'] = $product_id;
1796
-            $tpl_component['PRODUCT_CLASS'] = $product_class;
1797
-            $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1798
-            $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1799
-            $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1800
-            $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1801
-            $tpl_component['PRODUCT_PRICE'] = $productPrice;
1802
-            $tpl_component['PRODUCT_PERMALINK'] = $product_link;
1803
-            $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1804
-            $tpl_component['PRODUCT_NAME'] = $product_name;
1805
-            $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1806
-            $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1807
-            $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1808
-            $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1809
-            $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1810
-
1811
-            if (has_post_thumbnail($product_id)) {
1812
-                $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1813
-                if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1814
-                    $existing_image_sizes = get_intermediate_image_sizes();
1815
-                    foreach ($existing_image_sizes as $size_name) {
1816
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1817
-                        $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;
1818
-                    }
1819
-                }
1820
-            }
1821
-
1822
-            $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1823
-            $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1824
-            $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1825
-
1826
-            /** Build template    */
1827
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1828
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1829
-                /**    Include the old way template part    */
1830
-                ob_start();
1831
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1832
-                $content = ob_get_contents();
1833
-                ob_end_clean();
1834
-            } else {
1835
-                $content = wpshop_display::display_template_element($template_part, $tpl_component);
1836
-            }
1837
-            unset($tpl_component);
1789
+		if (!empty($product['product_id'])) {
1790
+			/** Template parameters    */
1791
+			$template_part = 'product_mini_' . $output_type;
1792
+			$tpl_component = array();
1793
+			$tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1794
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1795
+			$tpl_component['PRODUCT_ID'] = $product_id;
1796
+			$tpl_component['PRODUCT_CLASS'] = $product_class;
1797
+			$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1798
+			$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1799
+			$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1800
+			$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1801
+			$tpl_component['PRODUCT_PRICE'] = $productPrice;
1802
+			$tpl_component['PRODUCT_PERMALINK'] = $product_link;
1803
+			$tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1804
+			$tpl_component['PRODUCT_NAME'] = $product_name;
1805
+			$tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1806
+			$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1807
+			$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1808
+			$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1809
+			$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1810
+
1811
+			if (has_post_thumbnail($product_id)) {
1812
+				$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1813
+				if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1814
+					$existing_image_sizes = get_intermediate_image_sizes();
1815
+					foreach ($existing_image_sizes as $size_name) {
1816
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1817
+						$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;
1818
+					}
1819
+				}
1820
+			}
1838 1821
 
1839
-        }
1822
+			$tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1823
+			$tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1824
+			$tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1825
+
1826
+			/** Build template    */
1827
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1828
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1829
+				/**    Include the old way template part    */
1830
+				ob_start();
1831
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1832
+				$content = ob_get_contents();
1833
+				ob_end_clean();
1834
+			} else {
1835
+				$content = wpshop_display::display_template_element($template_part, $tpl_component);
1836
+			}
1837
+			unset($tpl_component);
1840 1838
 
1841
-        return $content;
1842
-    }
1839
+		}
1843 1840
 
1844
-    /**
1845
-     *    Get the products (post) of a given category
1846
-     *
1847
-     *    @param string $category_slug The category slug we want to get the product list for
1848
-     *
1849
-     *    @return mixed $widget_content The output for the product list
1850
-     */
1851
-    public static function get_product_of_category($category_slug, $category_id)
1852
-    {
1853
-        global $top_categories;
1854
-        $widget_content = '';
1855
-        $products = wp_cache_get('wpshop_products_category_' . $category_id);
1856
-        if (false == $products) {
1857
-            $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1858
-            $products = get_posts($args);
1859
-            wp_cache_set('wpshop_products_category_' . $category_id, $products);
1860
-        }
1861
-        if (is_array($products) && (count($products) > 0)) {
1862
-            foreach ($products as $product) {
1863
-                if ($product->post_status == "publish") {
1864
-                    ob_start();
1865
-                    require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1866
-                    $widget_content .= ob_get_contents();
1867
-                    ob_end_clean();
1868
-                }
1869
-            }
1870
-        }
1841
+		return $content;
1842
+	}
1871 1843
 
1872
-        echo $widget_content;
1873
-    }
1844
+	/**
1845
+	 *    Get the products (post) of a given category
1846
+	 *
1847
+	 *    @param string $category_slug The category slug we want to get the product list for
1848
+	 *
1849
+	 *    @return mixed $widget_content The output for the product list
1850
+	 */
1851
+	public static function get_product_of_category($category_slug, $category_id)
1852
+	{
1853
+		global $top_categories;
1854
+		$widget_content = '';
1855
+		$products = wp_cache_get('wpshop_products_category_' . $category_id);
1856
+		if (false == $products) {
1857
+			$args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1858
+			$products = get_posts($args);
1859
+			wp_cache_set('wpshop_products_category_' . $category_id, $products);
1860
+		}
1861
+		if (is_array($products) && (count($products) > 0)) {
1862
+			foreach ($products as $product) {
1863
+				if ($product->post_status == "publish") {
1864
+					ob_start();
1865
+					require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1866
+					$widget_content .= ob_get_contents();
1867
+					ob_end_clean();
1868
+				}
1869
+			}
1870
+		}
1871
+
1872
+		echo $widget_content;
1873
+	}
1874 1874
 
1875
-    /**
1876
-     *
1877
-     * @param unknown_type $selected_product
1878
-     * @return string
1879
-     */
1880
-    public function custom_product_list($selected_product = array())
1881
-    {
1882
-        global $wpdb;
1883
-
1884
-        /*    Start the table definition    */
1885
-        $tableId = 'wpshop_product_list';
1886
-        $tableTitles = array();
1887
-        $tableTitles[] = '';
1888
-        $tableTitles[] = __('Id', 'wpshop');
1889
-        $tableTitles[] = __('Quantity', 'wpshop');
1890
-        $tableTitles[] = __('Reference', 'wpshop');
1891
-        $tableTitles[] = __('Product name', 'wpshop');
1892
-        $tableTitles[] = __('Actions', 'wpshop');
1893
-        $tableTitles[] = __('Price', 'wpshop');
1894
-        $tableClasses = array();
1895
-        $tableClasses[] = 'wpshop_product_selector_column';
1896
-        $tableClasses[] = 'wpshop_product_identifier_column';
1897
-        $tableClasses[] = 'wpshop_product_quantity_column';
1898
-        $tableClasses[] = 'wpshop_product_sku_column';
1899
-        $tableClasses[] = 'wpshop_product_name_column';
1900
-        $tableClasses[] = 'wpshop_product_link_column';
1901
-        $tableClasses[] = 'wpshop_product_price_column';
1902
-
1903
-        /*    Get post list    */
1904
-        $has_result = false;
1905
-        $current_line_index = 0;
1906
-        $posts = query_posts(array(
1907
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1908
-        ));
1909
-        if (!empty($posts)) {
1910
-            $has_result = true;
1911
-            foreach ($posts as $post) {
1912
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1913
-
1914
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1915
-
1916
-                unset($tableRowValue);
1917
-                $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 . '" />');
1918
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1919
-                $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>');
1920
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1921
-                $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1922
-                $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/>
1875
+	/**
1876
+	 *
1877
+	 * @param unknown_type $selected_product
1878
+	 * @return string
1879
+	 */
1880
+	public function custom_product_list($selected_product = array())
1881
+	{
1882
+		global $wpdb;
1883
+
1884
+		/*    Start the table definition    */
1885
+		$tableId = 'wpshop_product_list';
1886
+		$tableTitles = array();
1887
+		$tableTitles[] = '';
1888
+		$tableTitles[] = __('Id', 'wpshop');
1889
+		$tableTitles[] = __('Quantity', 'wpshop');
1890
+		$tableTitles[] = __('Reference', 'wpshop');
1891
+		$tableTitles[] = __('Product name', 'wpshop');
1892
+		$tableTitles[] = __('Actions', 'wpshop');
1893
+		$tableTitles[] = __('Price', 'wpshop');
1894
+		$tableClasses = array();
1895
+		$tableClasses[] = 'wpshop_product_selector_column';
1896
+		$tableClasses[] = 'wpshop_product_identifier_column';
1897
+		$tableClasses[] = 'wpshop_product_quantity_column';
1898
+		$tableClasses[] = 'wpshop_product_sku_column';
1899
+		$tableClasses[] = 'wpshop_product_name_column';
1900
+		$tableClasses[] = 'wpshop_product_link_column';
1901
+		$tableClasses[] = 'wpshop_product_price_column';
1902
+
1903
+		/*    Get post list    */
1904
+		$has_result = false;
1905
+		$current_line_index = 0;
1906
+		$posts = query_posts(array(
1907
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1908
+		));
1909
+		if (!empty($posts)) {
1910
+			$has_result = true;
1911
+			foreach ($posts as $post) {
1912
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1913
+
1914
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1915
+
1916
+				unset($tableRowValue);
1917
+				$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 . '" />');
1918
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1919
+				$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>');
1920
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1921
+				$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1922
+				$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/>
1923 1923
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1924
-                $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() : ''));
1925
-                $tableRows[] = $tableRowValue;
1924
+				$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() : ''));
1925
+				$tableRows[] = $tableRowValue;
1926 1926
 
1927
-                $current_line_index++;
1928
-            }
1929
-            wp_reset_query();
1930
-        }
1931
-        $posts = query_posts(array(
1932
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1933
-        ));
1934
-        if (!empty($posts)) {
1935
-            $has_result = true;
1936
-            foreach ($posts as $post) {
1937
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1938
-
1939
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1940
-
1941
-                unset($tableRowValue);
1942
-                $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 . '" />');
1943
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1944
-                $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>');
1945
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1946
-                $parent_product = wpshop_products::get_parent_variation($post->ID);
1947
-                if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1948
-                    $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1949
-                    $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1950
-                    $option_name = $wpdb->get_var($query);
1951
-                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1952
-                    $option_value = $wpdb->get_var($query);
1953
-                    $parent_post = $parent_product['parent_post'];
1954
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1955
-                } else {
1956
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1957
-                }
1958
-
1959
-                $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/>
1927
+				$current_line_index++;
1928
+			}
1929
+			wp_reset_query();
1930
+		}
1931
+		$posts = query_posts(array(
1932
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1933
+		));
1934
+		if (!empty($posts)) {
1935
+			$has_result = true;
1936
+			foreach ($posts as $post) {
1937
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1938
+
1939
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1940
+
1941
+				unset($tableRowValue);
1942
+				$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 . '" />');
1943
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1944
+				$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>');
1945
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1946
+				$parent_product = wpshop_products::get_parent_variation($post->ID);
1947
+				if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1948
+					$product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1949
+					$query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1950
+					$option_name = $wpdb->get_var($query);
1951
+					$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1952
+					$option_value = $wpdb->get_var($query);
1953
+					$parent_post = $parent_product['parent_post'];
1954
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1955
+				} else {
1956
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1957
+				}
1958
+
1959
+				$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/>
1960 1960
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1961
-                $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() : ''));
1962
-                $tableRows[] = $tableRowValue;
1961
+				$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() : ''));
1962
+				$tableRows[] = $tableRowValue;
1963 1963
 
1964
-                $current_line_index++;
1965
-            }
1966
-            wp_reset_query();
1967
-        }
1964
+				$current_line_index++;
1965
+			}
1966
+			wp_reset_query();
1967
+		}
1968 1968
 
1969
-        if (!$has_result) {
1970
-            $tableRowsId[] = 'no_product_found';
1971
-            unset($tableRowValue);
1972
-            $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1973
-            $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1974
-            $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1975
-            $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1976
-            $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1977
-            $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1978
-            $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1979
-            $tableRows[] = $tableRowValue;
1980
-        }
1969
+		if (!$has_result) {
1970
+			$tableRowsId[] = 'no_product_found';
1971
+			unset($tableRowValue);
1972
+			$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1973
+			$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1974
+			$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1975
+			$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1976
+			$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1977
+			$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1978
+			$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1979
+			$tableRows[] = $tableRowValue;
1980
+		}
1981 1981
 
1982
-        return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1982
+		return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1983 1983
 <script type="text/javascript" >
1984 1984
 	wpshop(document).ready(function(){
1985 1985
 		jQuery("#' . $tableId . '").dataTable( {
@@ -1988,1533 +1988,1533 @@  discard block
 block discarded – undo
1988 1988
 		});
1989 1989
 	});
1990 1990
 </script>';
1991
-    }
1991
+	}
1992 1992
 
1993
-    /**
1994
-     * Allows to manage output for special state for a product (New product/highlight product)
1995
-     *
1996
-     * @param string $special The type of special type we want to output
1997
-     * @param string $output_type The current display type (used for product listing)
1998
-     * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1999
-     * @param datetime $special_state_start The start date if applicable for the special state
2000
-     * @param datetime $special_state_end The end date if applicable for the special state
2001
-     *
2002
-     * @return array $product_special_state The product special state
2003
-     */
2004
-    public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
2005
-    {
2006
-        $product_special_state = array();
2007
-        $product_special_state['output'] = $product_special_state['class'] = '';
2008
-
2009
-        /** Get product special state definition    */
2010
-        $special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
2011
-        $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
2012
-        $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
2013
-
2014
-        /** Get current time    */
2015
-        $current_time = substr(current_time('mysql', 0), 0, 10);
2016
-
2017
-        /** PRODUCT MARK AS NEW */
2018
-        $show_product_special_state = false;
2019
-        if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
2020
-            (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
2021
-            (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
2022
-            $show_product_special_state = true;
2023
-        }
1993
+	/**
1994
+	 * Allows to manage output for special state for a product (New product/highlight product)
1995
+	 *
1996
+	 * @param string $special The type of special type we want to output
1997
+	 * @param string $output_type The current display type (used for product listing)
1998
+	 * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1999
+	 * @param datetime $special_state_start The start date if applicable for the special state
2000
+	 * @param datetime $special_state_end The end date if applicable for the special state
2001
+	 *
2002
+	 * @return array $product_special_state The product special state
2003
+	 */
2004
+	public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
2005
+	{
2006
+		$product_special_state = array();
2007
+		$product_special_state['output'] = $product_special_state['class'] = '';
2008
+
2009
+		/** Get product special state definition    */
2010
+		$special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
2011
+		$special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
2012
+		$special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
2013
+
2014
+		/** Get current time    */
2015
+		$current_time = substr(current_time('mysql', 0), 0, 10);
2016
+
2017
+		/** PRODUCT MARK AS NEW */
2018
+		$show_product_special_state = false;
2019
+		if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
2020
+			(empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
2021
+			(empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
2022
+			$show_product_special_state = true;
2023
+		}
2024 2024
 
2025
-        if ($show_product_special_state) {
2026
-            /** Check the type of special output needed    */
2027
-            switch ($special) {
2028
-                case 'declare_new':
2029
-                    $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
2030
-                    $template_part = 'product_is_new_sticker';
2031
-                    break;
2032
-
2033
-                case 'highlight_product':
2034
-                    $product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2035
-                    $template_part = 'product_is_featured_sticker';
2036
-                    break;
2037
-            }
2038
-
2039
-            /** Template parameters    */
2040
-            $tpl_component = array();
2041
-
2042
-            /** Build template        */
2043
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2044
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2045
-                /**    Include the old way template part    */
2046
-                ob_start();
2047
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2048
-                $product_special_state['output'] = ob_get_contents();
2049
-                ob_end_clean();
2050
-            } else {
2051
-                $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2052
-            }
2053
-            unset($tpl_component);
2054
-        }
2025
+		if ($show_product_special_state) {
2026
+			/** Check the type of special output needed    */
2027
+			switch ($special) {
2028
+				case 'declare_new':
2029
+					$product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
2030
+					$template_part = 'product_is_new_sticker';
2031
+					break;
2055 2032
 
2056
-        return $product_special_state;
2057
-    }
2033
+				case 'highlight_product':
2034
+					$product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2035
+					$template_part = 'product_is_featured_sticker';
2036
+					break;
2037
+			}
2058 2038
 
2059
-    /**
2060
-     * Prepare product price for saving and easier read later
2061
-     *
2062
-     * @param integer $element_id Identifier of current product
2063
-     */
2064
-    public static function calculate_price($element_id)
2065
-    {
2066
-        global $wpdb;
2067
-
2068
-        /**
2069
-         * Récupères les attributs suivants : product_price, price_ht et tva
2070
-         * par rapport à $element_id / Get the next attributes : product_price,
2071
-         * price_ht and tva
2072
-         */
2073
-        $query = $wpdb->prepare(
2074
-            "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2039
+			/** Template parameters    */
2040
+			$tpl_component = array();
2041
+
2042
+			/** Build template        */
2043
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2044
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2045
+				/**    Include the old way template part    */
2046
+				ob_start();
2047
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2048
+				$product_special_state['output'] = ob_get_contents();
2049
+				ob_end_clean();
2050
+			} else {
2051
+				$product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2052
+			}
2053
+			unset($tpl_component);
2054
+		}
2055
+
2056
+		return $product_special_state;
2057
+	}
2058
+
2059
+	/**
2060
+	 * Prepare product price for saving and easier read later
2061
+	 *
2062
+	 * @param integer $element_id Identifier of current product
2063
+	 */
2064
+	public static function calculate_price($element_id)
2065
+	{
2066
+		global $wpdb;
2067
+
2068
+		/**
2069
+		 * Récupères les attributs suivants : product_price, price_ht et tva
2070
+		 * par rapport à $element_id / Get the next attributes : product_price,
2071
+		 * price_ht and tva
2072
+		 */
2073
+		$query = $wpdb->prepare(
2074
+			"SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2075 2075
 			FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR
2076 2076
 				RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d))
2077 2077
 			WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')",
2078
-            $element_id
2079
-        );
2080
-        $prices_attribute = $wpdb->get_results($query, OBJECT_K);
2081
-
2082
-        /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2083
-        if (empty($prices_attribute)) {
2084
-            return false;
2085
-        } else {
2086
-            /**
2087
-             * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2088
-             * the base amount according on the shop price control
2089
-             */
2090
-            $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2091
-            $rate_vat = wpshop_prices::get_rate_vat($element_id);
2092
-            $divider_price_ttc = 1 + ($rate_vat->value / 100);
2093
-
2094
-            /**
2095
-             * Informations nécessaire pour crée un attribut / Information needed to
2096
-             * create an attribute
2097
-             */
2098
-            $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2099
-            $language = WPSHOP_CURRENT_LOCALE;
2100
-            $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2101
-
2102
-            if (!empty($icl_post_language)) {
2103
-                $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2104
-                $language = $wpdb->get_var($query);
2105
-            }
2106
-
2107
-            /**
2108
-             * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2109
-             * Check configuration to know how to make the calcul for the product
2110
-             */
2111
-            if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2112
-                $price_with_vat = ($base_price * $divider_price_ttc);
2113
-                $price_no_vat = $base_price;
2114
-            } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2115
-                $price_with_vat = $base_price;
2116
-                $price_no_vat = ($price_with_vat / $divider_price_ttc);
2117
-            }
2118
-
2119
-            /**
2120
-             * Le dernier paramètre permet de ne pas supprimer les attributs du même
2121
-             * type que celui-ci / The last parameter allows not to delete the
2122
-             * attributes of the same type as this one
2123
-             */
2124
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2125
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2126
-
2127
-            /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2128
-            $vat_amount = $price_with_vat - $price_no_vat;
2129
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2130
-
2131
-            /**    Update the product meta information with the calculated prices    */
2132
-            $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2133
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2134
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2135
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2136
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2137
-
2138
-            update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2078
+			$element_id
2079
+		);
2080
+		$prices_attribute = $wpdb->get_results($query, OBJECT_K);
2081
+
2082
+		/** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2083
+		if (empty($prices_attribute)) {
2084
+			return false;
2085
+		} else {
2086
+			/**
2087
+			 * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2088
+			 * the base amount according on the shop price control
2089
+			 */
2090
+			$base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2091
+			$rate_vat = wpshop_prices::get_rate_vat($element_id);
2092
+			$divider_price_ttc = 1 + ($rate_vat->value / 100);
2093
+
2094
+			/**
2095
+			 * Informations nécessaire pour crée un attribut / Information needed to
2096
+			 * create an attribute
2097
+			 */
2098
+			$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2099
+			$language = WPSHOP_CURRENT_LOCALE;
2100
+			$icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2101
+
2102
+			if (!empty($icl_post_language)) {
2103
+				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2104
+				$language = $wpdb->get_var($query);
2105
+			}
2139 2106
 
2140
-            /** Met à jour la meta _wps_price_infos */
2141
-            $p = wpshop_products::get_product_data($element_id);
2142
-            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2143
-            update_post_meta($element_id, '_wps_price_infos', $price);
2107
+			/**
2108
+			 * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2109
+			 * Check configuration to know how to make the calcul for the product
2110
+			 */
2111
+			if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2112
+				$price_with_vat = ($base_price * $divider_price_ttc);
2113
+				$price_no_vat = $base_price;
2114
+			} else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2115
+				$price_with_vat = $base_price;
2116
+				$price_no_vat = ($price_with_vat / $divider_price_ttc);
2117
+			}
2144 2118
 
2145
-            /** Met à jour la meta _wpshop_displayed_price */
2146
-            wps_filter_search::save_displayed_price_meta($element_id);
2147
-        }
2119
+			/**
2120
+			 * Le dernier paramètre permet de ne pas supprimer les attributs du même
2121
+			 * type que celui-ci / The last parameter allows not to delete the
2122
+			 * attributes of the same type as this one
2123
+			 */
2124
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2125
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2126
+
2127
+			/** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2128
+			$vat_amount = $price_with_vat - $price_no_vat;
2129
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2130
+
2131
+			/**    Update the product meta information with the calculated prices    */
2132
+			$product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2133
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2134
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2135
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2136
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2137
+
2138
+			update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2139
+
2140
+			/** Met à jour la meta _wps_price_infos */
2141
+			$p = wpshop_products::get_product_data($element_id);
2142
+			$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2143
+			update_post_meta($element_id, '_wps_price_infos', $price);
2144
+
2145
+			/** Met à jour la meta _wpshop_displayed_price */
2146
+			wps_filter_search::save_displayed_price_meta($element_id);
2147
+		}
2148 2148
 
2149
-        return true;
2150
-    }
2149
+		return true;
2150
+	}
2151 2151
 
2152
-    /**
2153
-     * Allows to get the good button for adding product to cart
2154
-     *
2155
-     * @param integer $product_id The product identifier
2156
-     * @param boolean $productStock If there is the possibility to add the given product to the cart
2157
-     *
2158
-     * @return string $button The html output for the button
2159
-     */
2160
-    public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2161
-    {
2162
-        $button = '';
2152
+	/**
2153
+	 * Allows to get the good button for adding product to cart
2154
+	 *
2155
+	 * @param integer $product_id The product identifier
2156
+	 * @param boolean $productStock If there is the possibility to add the given product to the cart
2157
+	 *
2158
+	 * @return string $button The html output for the button
2159
+	 */
2160
+	public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2161
+	{
2162
+		$button = '';
2163 2163
 //         $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true );
2164 2164
 
2165
-        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') ) */) {
2166
-            /*
2165
+		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') ) */) {
2166
+			/*
2167 2167
              * Check if current product has variation for button display
2168 2168
              */
2169
-            $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2170
-            $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2169
+			$variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2170
+			$variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2171 2171
 
2172
-            /*
2172
+			/*
2173 2173
              * Template parameters
2174 2174
              */
2175 2175
 
2176
-            if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2177
-                /** Check variation stock **/
2178
-                $variations = self::get_variation($product_id);
2179
-                if (!empty($variations)) {
2180
-                    foreach ($variations as $variation) {
2181
-                        if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2182
-                            $productStock += $variation['variation_dif']['product_stock'];
2183
-                        }
2184
-                    }
2185
-                }
2186
-            }
2187
-
2188
-            $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2176
+			if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2177
+				/** Check variation stock **/
2178
+				$variations = self::get_variation($product_id);
2179
+				if (!empty($variations)) {
2180
+					foreach ($variations as $variation) {
2181
+						if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2182
+							$productStock += $variation['variation_dif']['product_stock'];
2183
+						}
2184
+					}
2185
+				}
2186
+			}
2187
+
2188
+			$template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2189 2189
 						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2190 2190
 
2191
-            $tpl_component = array();
2192
-            $tpl_component['PRODUCT_ID'] = $product_id;
2193
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2194
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2191
+			$tpl_component = array();
2192
+			$tpl_component['PRODUCT_ID'] = $product_id;
2193
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2194
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2195 2195
 
2196
-            /*
2196
+			/*
2197 2197
              * Build template
2198 2198
              */
2199
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2200
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2201
-                /*    Include the old way template part    */
2202
-                ob_start();
2203
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2204
-                $button = ob_get_contents();
2205
-                ob_end_clean();
2206
-            } else {
2207
-                $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));
2208
-            }
2209
-            unset($tpl_component);
2210
-        }
2211
-        return $button;
2212
-    }
2213
-
2214
-    /**
2215
-     * Allows to get the good button for adding product to a quotation
2216
-     *
2217
-     * @param integer $product_id The product identifier
2218
-     * @param boolean $product_quotation_state The state of the quotation addons
2219
-     *
2220
-     * @return string $button The html output for the button
2221
-     */
2222
-    public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2223
-    {
2224
-        $quotation_button = '';
2225
-
2226
-        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'))) {
2227
-            $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();
2228
-            /**
2229
-             * Template parameters
2230
-             */
2231
-            $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2232
-            $tpl_component = array();
2233
-            $tpl_component['PRODUCT_ID'] = $product_id;
2234
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2235
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2199
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2200
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2201
+				/*    Include the old way template part    */
2202
+				ob_start();
2203
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2204
+				$button = ob_get_contents();
2205
+				ob_end_clean();
2206
+			} else {
2207
+				$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));
2208
+			}
2209
+			unset($tpl_component);
2210
+		}
2211
+		return $button;
2212
+	}
2236 2213
 
2237
-            /**
2238
-             * Build template
2239
-             */
2240
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2241
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2242
-                /*    Include the old way template part    */
2243
-                ob_start();
2244
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2245
-                $quotation_button = ob_get_contents();
2246
-                ob_end_clean();
2247
-            } else {
2248
-                $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2249
-            }
2250
-            unset($tpl_component);
2251
-        }
2214
+	/**
2215
+	 * Allows to get the good button for adding product to a quotation
2216
+	 *
2217
+	 * @param integer $product_id The product identifier
2218
+	 * @param boolean $product_quotation_state The state of the quotation addons
2219
+	 *
2220
+	 * @return string $button The html output for the button
2221
+	 */
2222
+	public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2223
+	{
2224
+		$quotation_button = '';
2225
+
2226
+		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'))) {
2227
+			$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();
2228
+			/**
2229
+			 * Template parameters
2230
+			 */
2231
+			$template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2232
+			$tpl_component = array();
2233
+			$tpl_component['PRODUCT_ID'] = $product_id;
2234
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2235
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2236
+
2237
+			/**
2238
+			 * Build template
2239
+			 */
2240
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2241
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2242
+				/*    Include the old way template part    */
2243
+				ob_start();
2244
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2245
+				$quotation_button = ob_get_contents();
2246
+				ob_end_clean();
2247
+			} else {
2248
+				$quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2249
+			}
2250
+			unset($tpl_component);
2251
+		}
2252 2252
 
2253
-        return $quotation_button;
2254
-    }
2253
+		return $quotation_button;
2254
+	}
2255 2255
 
2256
-    /**
2257
-     * Return the output for a product attachement gallery (picture or document)
2258
-     *
2259
-     * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2260
-     * @param string $content The gallery content build previously
2261
-     *
2262
-     * @return string The attachement gallery output
2263
-     */
2264
-    public static function display_attachment_gallery($attachement_type, $content)
2265
-    {
2266
-        $galery_output = '';
2267
-
2268
-        /*
2256
+	/**
2257
+	 * Return the output for a product attachement gallery (picture or document)
2258
+	 *
2259
+	 * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2260
+	 * @param string $content The gallery content build previously
2261
+	 *
2262
+	 * @return string The attachement gallery output
2263
+	 */
2264
+	public static function display_attachment_gallery($attachement_type, $content)
2265
+	{
2266
+		$galery_output = '';
2267
+
2268
+		/*
2269 2269
          * Get the template part for given galery type
2270 2270
          */
2271
-        switch ($attachement_type) {
2272
-            case 'picture':
2273
-                $template_part = 'product_attachment_picture_galery';
2274
-                break;
2275
-            case 'document':
2276
-                $template_part = 'product_attachment_galery';
2277
-                break;
2278
-        }
2271
+		switch ($attachement_type) {
2272
+			case 'picture':
2273
+				$template_part = 'product_attachment_picture_galery';
2274
+				break;
2275
+			case 'document':
2276
+				$template_part = 'product_attachment_galery';
2277
+				break;
2278
+		}
2279 2279
 
2280
-        /*
2280
+		/*
2281 2281
          * Template parameters
2282 2282
          */
2283
-        $tpl_component = array();
2284
-        $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2285
-        $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2283
+		$tpl_component = array();
2284
+		$tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2285
+		$tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2286 2286
 
2287
-        /*
2287
+		/*
2288 2288
          * Build template
2289 2289
          */
2290
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2291
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2292
-            /*    Include the old way template part    */
2293
-            ob_start();
2294
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
2295
-            $galery_output = ob_get_contents();
2296
-            ob_end_clean();
2297
-        } else {
2298
-            $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2299
-        }
2300
-        unset($tpl_component);
2290
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2291
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2292
+			/*    Include the old way template part    */
2293
+			ob_start();
2294
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
2295
+			$galery_output = ob_get_contents();
2296
+			ob_end_clean();
2297
+		} else {
2298
+			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2299
+		}
2300
+		unset($tpl_component);
2301 2301
 
2302
-        return $galery_output;
2303
-    }
2302
+		return $galery_output;
2303
+	}
2304 2304
 
2305
-    /**
2306
-     * Define the metabox to display in product edition page in backend
2307
-     * @param object $post The current element displayed for edition
2308
-     */
2309
-    public static function meta_box_variations($post)
2310
-    {
2311
-        $output = '';
2312
-        /*    Variations container    */
2313
-        $tpl_component = array();
2314
-        $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2315
-        $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2316
-        $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2317
-        echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2318
-    }
2305
+	/**
2306
+	 * Define the metabox to display in product edition page in backend
2307
+	 * @param object $post The current element displayed for edition
2308
+	 */
2309
+	public static function meta_box_variations($post)
2310
+	{
2311
+		$output = '';
2312
+		/*    Variations container    */
2313
+		$tpl_component = array();
2314
+		$tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2315
+		$tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2316
+		$output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2317
+		echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2318
+	}
2319 2319
 
2320
-    /**
2321
-     * Call variation creation function with a list of defined variation
2322
-     *
2323
-     * @param array $possible_variations A list of variation to create for the current element
2324
-     * @param integer $element_id The product we want to create variation for
2325
-     *
2326
-     * @return mixed The last created variation identifier
2327
-     */
2328
-    public static function creation_variation_callback($possible_variations, $element_id)
2329
-    {
2330
-        /** Get existing variation    */
2331
-        $existing_variations_in_db = wpshop_products::get_variation($element_id);
2332
-        $existing_variations = array();
2333
-        if (!empty($existing_variations_in_db)) {
2334
-            foreach ($existing_variations_in_db as $variations_def) {
2335
-                $existing_variations[] = $variations_def['variation_def'];
2336
-            }
2337
-        }
2338
-        /** New variation definition    */
2339
-        $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2340
-
2341
-        /**    Read possible values    */
2342
-        foreach ($possible_variations as $variation_definition) {
2343
-            if (in_array($variation_definition, $existing_variations)) {
2344
-                continue;
2345
-            }
2346
-
2347
-            $attribute_to_set = array();
2348
-            foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2349
-                $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2350
-                $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2351
-                if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2352
-                    $attribute_defining_variation['attributes'][] = $attribute_code;
2353
-                }
2354
-            }
2355
-            $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2356
-        }
2357
-        update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2320
+	/**
2321
+	 * Call variation creation function with a list of defined variation
2322
+	 *
2323
+	 * @param array $possible_variations A list of variation to create for the current element
2324
+	 * @param integer $element_id The product we want to create variation for
2325
+	 *
2326
+	 * @return mixed The last created variation identifier
2327
+	 */
2328
+	public static function creation_variation_callback($possible_variations, $element_id)
2329
+	{
2330
+		/** Get existing variation    */
2331
+		$existing_variations_in_db = wpshop_products::get_variation($element_id);
2332
+		$existing_variations = array();
2333
+		if (!empty($existing_variations_in_db)) {
2334
+			foreach ($existing_variations_in_db as $variations_def) {
2335
+				$existing_variations[] = $variations_def['variation_def'];
2336
+			}
2337
+		}
2338
+		/** New variation definition    */
2339
+		$attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2358 2340
 
2359
-        return !empty($variation_id) ? $variation_id : 0;
2360
-    }
2341
+		/**    Read possible values    */
2342
+		foreach ($possible_variations as $variation_definition) {
2343
+			if (in_array($variation_definition, $existing_variations)) {
2344
+				continue;
2345
+			}
2361 2346
 
2362
-    /**
2363
-     * Create a new variation for product
2364
-     *
2365
-     * @param integer $head_product The product identifier to create the new variation for
2366
-     * @param array $variation_attributes Attribute list for the variation
2367
-     *
2368
-     * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2369
-     */
2370
-    public static function create_variation($head_product, $variation_attributes)
2371
-    {
2372
-        /** Create custom title */
2373
-        $title_variation = "";
2374
-        if (!empty($variation_attributes)) {
2375
-            foreach ($variation_attributes as $type => $array) {
2376
-                if (!empty($array)) {
2377
-                    foreach ($array as $code => $value) {
2378
-                        $title_variation .= " " . $code . " " . $value;
2379
-                    }
2380
-                }
2381
-            }
2382
-        }
2347
+			$attribute_to_set = array();
2348
+			foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2349
+				$attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2350
+				$attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2351
+				if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2352
+					$attribute_defining_variation['attributes'][] = $attribute_code;
2353
+				}
2354
+			}
2355
+			$variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2356
+		}
2357
+		update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2383 2358
 
2384
-        $variation = array(
2385
-            'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2386
-            'post_content' => '',
2387
-            'post_status' => 'publish',
2388
-            'post_author' => get_current_user_id(),
2389
-            'post_parent' => $head_product,
2390
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2391
-        );
2392
-        $variation_id = wp_insert_post($variation);
2393
-
2394
-        wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2395
-
2396
-        /*    Update product price looking for shop parameters    */
2397
-        wpshop_products::calculate_price($variation_id);
2398
-
2399
-        /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2400
-        $productMetaDatas = array();
2401
-        foreach ($variation_attributes as $attributeType => $attributeValues) {
2402
-            foreach ($attributeValues as $attributeCode => $attributeValue) {
2403
-                if (!empty($attributeValue)) {
2404
-                    $productMetaDatas[$attributeCode] = $attributeValue;
2405
-                }
2406
-            }
2407
-        }
2408
-        update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2409
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2410
-        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));
2359
+		return !empty($variation_id) ? $variation_id : 0;
2360
+	}
2411 2361
 
2412
-        return $variation_id;
2413
-    }
2362
+	/**
2363
+	 * Create a new variation for product
2364
+	 *
2365
+	 * @param integer $head_product The product identifier to create the new variation for
2366
+	 * @param array $variation_attributes Attribute list for the variation
2367
+	 *
2368
+	 * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2369
+	 */
2370
+	public static function create_variation($head_product, $variation_attributes)
2371
+	{
2372
+		/** Create custom title */
2373
+		$title_variation = "";
2374
+		if (!empty($variation_attributes)) {
2375
+			foreach ($variation_attributes as $type => $array) {
2376
+				if (!empty($array)) {
2377
+					foreach ($array as $code => $value) {
2378
+						$title_variation .= " " . $code . " " . $value;
2379
+					}
2380
+				}
2381
+			}
2382
+		}
2414 2383
 
2415
-    /**
2416
-     * Get variation list for a given product
2417
-     *
2418
-     * @param integer $head_product The product identifier to get the variation for
2419
-     * @return object The variation list
2420
-     */
2421
-    public static function get_variation($head_product, $type = 'any')
2422
-    {
2423
-        global $wpdb;
2424
-        $variations_output = null;
2425
-        $args = array(
2426
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2427
-            'post_parent' => $head_product,
2428
-            'orderby' => 'ID',
2429
-            'order' => 'ASC',
2430
-            'posts_per_page' => -1,
2431
-            'post_status' => $type,
2432
-        );
2433
-        $variations = get_posts($args);
2434
-
2435
-        if (!empty($variations)) {
2436
-            $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2437
-
2438
-            foreach ($variations as $post_def) {
2439
-                $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'");
2440
-                foreach ($data as $content) {
2441
-                    $attribute_value = 'attribute_value_' . $content->data_type;
2442
-                    if (!empty($content->$attribute_value)) {
2443
-                        if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2444
-                            $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2445
-                        } else {
2446
-                            $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2447
-                        }
2448
-                    }
2449
-                }
2450
-                $variations_output[$post_def->ID]['post'] = $post_def;
2451
-            }
2452
-        }
2453
-        wp_reset_query();
2454
-        return $variations_output;
2455
-    }
2384
+		$variation = array(
2385
+			'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2386
+			'post_content' => '',
2387
+			'post_status' => 'publish',
2388
+			'post_author' => get_current_user_id(),
2389
+			'post_parent' => $head_product,
2390
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2391
+		);
2392
+		$variation_id = wp_insert_post($variation);
2393
+
2394
+		wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2395
+
2396
+		/*    Update product price looking for shop parameters    */
2397
+		wpshop_products::calculate_price($variation_id);
2398
+
2399
+		/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2400
+		$productMetaDatas = array();
2401
+		foreach ($variation_attributes as $attributeType => $attributeValues) {
2402
+			foreach ($attributeValues as $attributeCode => $attributeValue) {
2403
+				if (!empty($attributeValue)) {
2404
+					$productMetaDatas[$attributeCode] = $attributeValue;
2405
+				}
2406
+			}
2407
+		}
2408
+		update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2409
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2410
+		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));
2456 2411
 
2457
-    /**
2458
-     * Affichage des variations d'un produit dans l'administration
2459
-     *
2460
-     * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2461
-     * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2462
-     */
2463
-    public static function display_variation_admin($head_product)
2464
-    {
2465
-        $output = '';
2466
-        $productCurrency = wpshop_tools::wpshop_get_currency();
2467
-        /*    Récupération de la liste des variations pour le produit en cours d'édition    */
2468
-        $variations = self::get_variation($head_product);
2469
-        $price_piloting = get_option('wpshop_shop_price_piloting');
2470
-
2471
-        /*    Affichage de la liste des variations pour le produit en cours d'édition    */
2472
-        if (!empty($variations) && is_array($variations)) {
2473
-            $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2474
-
2475
-            foreach ($variations as $variation) {
2476
-                $tpl_component = array();
2477
-
2478
-                $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2479
-                $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2480
-                $tpl_component['VARIATION_DETAIL'] = '  ';
2481
-                $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;
2482
-                $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2483
-                if (!empty($price_piloting) && $price_piloting == 'HT') {
2484
-
2485
-                } else {
2486
-
2487
-                }
2488
-                $post_obj = $variation['post'];
2489
-
2490
-                $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2491
-                if (!empty($parent_product_infos)) {
2492
-                    $parent_post = $parent_product_infos['parent_post'];
2493
-                    $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2494
-                    if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2495
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2496
-                            $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2497
-                        } else {
2498
-                            $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2499
-                        }
2500
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2501
-                    } else {
2502
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2503
-                            $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2504
-                        } else {
2505
-                            $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2506
-                        }
2507
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2508
-                    }
2509
-                    $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2510
-                    $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2511
-                }
2512
-
2513
-                if (!empty($variation['variation_def'])) {
2514
-                    foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2515
-                        if (!empty($variation_value)) {
2516
-                            $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2517
-                            $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');
2518
-                            $tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2519
-
2520
-                            /** Define Link image to variation interface **/
2521
-                            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'))) {
2522
-                                $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2523
-
2524
-                                $media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2525
-                                if (!empty($media_id_data)) {
2526
-                                    $medias_ids = explode(',', $media_id_data);
2527
-
2528
-                                    if (!empty($medias_ids)) {
2529
-                                        foreach ($medias_ids as $media_id) {
2530
-                                            if (!empty($media_id)) {
2531
-                                                $pictures[] = get_post($media_id);
2532
-                                            }
2533
-                                        }
2534
-                                    }
2535
-                                }
2536
-
2537
-                                $pictures_data = '';
2538
-                                if (!empty($pictures)) {
2539
-                                    $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2540
-
2541
-                                    $done_picture = array();
2542
-                                    foreach ($pictures as $picture) {
2543
-                                        if (!in_array($picture->ID, $done_picture)) {
2544
-                                            if (wp_attachment_is_image($picture->ID)) {
2545
-                                                $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2546
-                                                $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');
2547
-
2548
-                                                $done_picture[] = $picture->ID;
2549
-                                            }
2550
-                                        }
2551
-                                    }
2552
-                                }
2553
-
2554
-                                $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');
2555
-                            }
2556
-
2557
-                        }
2558
-                    }
2559
-                }
2560
-
2561
-                $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2562
-
2563
-                $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2564
-                $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())));
2565
-                $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');
2566
-
2567
-                /*    Add the variation definition to output    */
2568
-                $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');
2569
-            }
2570
-
2571
-            $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');
2572
-            /*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2573
-            wp_reset_query();
2574
-        } else {
2575
-            $output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2576
-        }
2412
+		return $variation_id;
2413
+	}
2577 2414
 
2578
-        return $output;
2579
-    }
2415
+	/**
2416
+	 * Get variation list for a given product
2417
+	 *
2418
+	 * @param integer $head_product The product identifier to get the variation for
2419
+	 * @return object The variation list
2420
+	 */
2421
+	public static function get_variation($head_product, $type = 'any')
2422
+	{
2423
+		global $wpdb;
2424
+		$variations_output = null;
2425
+		$args = array(
2426
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2427
+			'post_parent' => $head_product,
2428
+			'orderby' => 'ID',
2429
+			'order' => 'ASC',
2430
+			'posts_per_page' => -1,
2431
+			'post_status' => $type,
2432
+		);
2433
+		$variations = get_posts($args);
2434
+
2435
+		if (!empty($variations)) {
2436
+			$head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2437
+
2438
+			foreach ($variations as $post_def) {
2439
+				$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'");
2440
+				foreach ($data as $content) {
2441
+					$attribute_value = 'attribute_value_' . $content->data_type;
2442
+					if (!empty($content->$attribute_value)) {
2443
+						if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2444
+							$variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2445
+						} else {
2446
+							$variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2447
+						}
2448
+					}
2449
+				}
2450
+				$variations_output[$post_def->ID]['post'] = $post_def;
2451
+			}
2452
+		}
2453
+		wp_reset_query();
2454
+		return $variations_output;
2455
+	}
2580 2456
 
2581
-    /**
2582
-     * Retrieve and display the variation for a given product
2583
-     * @param integer $product_id The product identifier to get variation for
2584
-     */
2585
-    public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2586
-    {
2587
-        global $wp_query;
2588
-        $output = '';
2589
-
2590
-        $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2591
-        $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2592
-        $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2593
-
2594
-        /**    Get attribute order for current product    */
2595
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2596
-        $output_order = array();
2597
-        if (count($product_attribute_order_detail) > 0) {
2598
-            if (!empty($product_attribute_order_detail)) {
2599
-                foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2600
-                    foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2601
-                        if (!empty($attribute_def->code)) {
2602
-                            $output_order[$attribute_def->code] = $position;
2603
-                        }
2604
-
2605
-                    }
2606
-                }
2607
-            }
2608
-        }
2457
+	/**
2458
+	 * Affichage des variations d'un produit dans l'administration
2459
+	 *
2460
+	 * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2461
+	 * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2462
+	 */
2463
+	public static function display_variation_admin($head_product)
2464
+	{
2465
+		$output = '';
2466
+		$productCurrency = wpshop_tools::wpshop_get_currency();
2467
+		/*    Récupération de la liste des variations pour le produit en cours d'édition    */
2468
+		$variations = self::get_variation($head_product);
2469
+		$price_piloting = get_option('wpshop_shop_price_piloting');
2470
+
2471
+		/*    Affichage de la liste des variations pour le produit en cours d'édition    */
2472
+		if (!empty($variations) && is_array($variations)) {
2473
+			$existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2474
+
2475
+			foreach ($variations as $variation) {
2476
+				$tpl_component = array();
2477
+
2478
+				$tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2479
+				$tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2480
+				$tpl_component['VARIATION_DETAIL'] = '  ';
2481
+				$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;
2482
+				$tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2483
+				if (!empty($price_piloting) && $price_piloting == 'HT') {
2484
+
2485
+				} else {
2609 2486
 
2610
-        $variations_params = array();
2611
-        $variation_attribute = array();
2612
-        $variation_attribute_ordered = array();
2613
-        $possible_values = array();
2614
-        $possible_values_for_selection_calculation = array();
2615
-
2616
-        /*    Vérification de l'existence de déclinaison pour le produit    */
2617
-        $wpshop_variation_list = self::get_variation($product_id);
2618
-        if (!empty($wpshop_variation_list)) {
2619
-            foreach ($wpshop_variation_list as $variation) {
2620
-                if (!empty($variation['variation_def'])) {
2621
-                    $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2622
-                    foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2623
-                        if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2624
-                            $tpl_component = array();
2625
-
2626
-                            $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2627
-                            $default_value_is_serial = false;
2628
-                            $attribute_list_first_element = $attribute_db_definition->default_value;
2629
-                            if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2630
-                                $default_value_is_serial = true;
2631
-                                $tmp_default_value = unserialize($attribute_db_definition->default_value);
2632
-                                $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2633
-                            }
2634
-
2635
-                            if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2636
-                                $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');
2637
-                            }
2638
-
2639
-                            if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2640
-                                $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2641
-                                $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2642
-                            } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2643
-                                $post_def = get_post($attribute_value);
2644
-                                $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2645
-                                $position = $post_def->menu_order;
2646
-                            }
2647
-
2648
-                            if (!empty($variation['variation_dif'])) {
2649
-                                foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2650
-                                    $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2651
-                                    $the_value = $attribute_dif_value;
2652
-                                    if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2653
-                                        $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2654
-                                    }
2655
-                                    $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2656
-                                }
2657
-                            }
2658
-                            if (!empty($attribute_value)) {
2659
-                                $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));
2660
-                                $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2661
-                            }
2662
-                            unset($tpl_component);
2663
-                        }
2664
-                    }
2665
-                }
2666
-            }
2667
-
2668
-            $variation_tpl = array();
2669
-            if (!empty($head_wpshop_variation_definition['attributes'])) {
2670
-                foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2671
-                    $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2672
-
2673
-                    if (!empty($attribute_db_definition)) {
2674
-                        $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');
2675
-
2676
-                        $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;
2677
-                        if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2678
-                            $is_required = true;
2679
-                        }
2680
-
2681
-                        $input_def = array();
2682
-                        $input_def['type'] = $attribute_db_definition->frontend_input;
2683
-                        $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);
2684
-                        if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2685
-                            unset($possible_values[$attribute_code][0]);
2686
-                            $value = array($value);
2687
-                        }
2688
-                        $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2689
-                        $input_def['name'] = $attribute_code;
2690
-                        $real_possible_values = array();
2691
-                        if (!empty($possible_values[$attribute_code])) {
2692
-                            ksort($possible_values[$attribute_code]);
2693
-                            foreach ($possible_values[$attribute_code] as $position => $def) {
2694
-                                foreach ($def as $attribute_value => $attribute_value_output) {
2695
-                                    $real_possible_values[$attribute_value] = $attribute_value_output;
2696
-                                    if (!empty($attribute_value)) {
2697
-                                        global $wpdb;
2698
-                                        $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);
2699
-                                        if ('draft' == $wpdb->get_var($query)) {
2700
-                                            unset($real_possible_values[$attribute_value]);
2701
-                                        }
2702
-                                    }
2703
-                                }
2704
-                            }
2705
-                        }
2706
-                        $input_def['possible_value'] = $real_possible_values;
2707
-                        $input_def['valueToPut'] = 'index';
2708
-                        $input_def['value'] = $value;
2709
-
2710
-                        $input_def['options']['more_input'] = '';
2711
-                        if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2712
-                            foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2713
-                                $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 . '" />';
2714
-                            }
2715
-                        }
2716
-
2717
-                        $input_def['options_label']['original'] = true;
2718
-                        $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) . '" ';
2719
-
2720
-                        if (!empty($real_possible_values)) {
2721
-                            $tpl_component = array();
2722
-                            $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'];
2723
-                            $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2724
-                            $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));
2725
-                            $tpl_component['VARIATION_CODE'] = $attribute_code;
2726
-                            $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2727
-                            $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2728
-                            $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2729
-                            $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2730
-                            $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2731
-                            $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;
2732
-                            $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2733
-                            $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2734
-                            $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2735
-                        }
2736
-
2737
-                        $variation_attribute[] = $attribute_code;
2738
-                    }
2739
-                }
2740
-            }
2487
+				}
2488
+				$post_obj = $variation['post'];
2489
+
2490
+				$parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2491
+				if (!empty($parent_product_infos)) {
2492
+					$parent_post = $parent_product_infos['parent_post'];
2493
+					$product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2494
+					if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2495
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2496
+							$product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2497
+						} else {
2498
+							$product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2499
+						}
2500
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2501
+					} else {
2502
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2503
+							$product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2504
+						} else {
2505
+							$product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2506
+						}
2507
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2508
+					}
2509
+					$product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2510
+					$tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2511
+				}
2741 2512
 
2742
-        }
2743
-        $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2744
-        wp_reset_query();
2745
-
2746
-        $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2747
-        if (!empty($attribute_defined_to_be_user_defined)) {
2748
-            foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2749
-                $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;
2750
-
2751
-                $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');
2752
-                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')) {
2753
-                    $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] : ''));
2754
-
2755
-                    $tpl_component = array();
2756
-                    $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) . '" ';
2757
-                    $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2758
-                    $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));
2759
-                    $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2760
-                    $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 . '" ' : '';
2761
-                    $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2762
-                    $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2763
-                    $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2764
-                    $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2765
-                    $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2766
-                    $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;
2767
-                    $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'];
2768
-                    $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)];
2769
-                }
2770
-            }
2771
-        }
2772
-        $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2773
-        if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2774
-            ksort($variation_attribute_ordered);
2775
-            foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2776
-                $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2777
-            }
2778
-        }
2779
-        $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2780
-        $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2781
-        if ($from_admin && !empty($order_id)) {
2782
-            $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2783
-            $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2784
-        }
2785
-        $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2513
+				if (!empty($variation['variation_def'])) {
2514
+					foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2515
+						if (!empty($variation_value)) {
2516
+							$attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2517
+							$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');
2518
+							$tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2519
+
2520
+							/** Define Link image to variation interface **/
2521
+							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'))) {
2522
+								$pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2523
+
2524
+								$media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2525
+								if (!empty($media_id_data)) {
2526
+									$medias_ids = explode(',', $media_id_data);
2527
+
2528
+									if (!empty($medias_ids)) {
2529
+										foreach ($medias_ids as $media_id) {
2530
+											if (!empty($media_id)) {
2531
+												$pictures[] = get_post($media_id);
2532
+											}
2533
+										}
2534
+									}
2535
+								}
2536
+
2537
+								$pictures_data = '';
2538
+								if (!empty($pictures)) {
2539
+									$selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2540
+
2541
+									$done_picture = array();
2542
+									foreach ($pictures as $picture) {
2543
+										if (!in_array($picture->ID, $done_picture)) {
2544
+											if (wp_attachment_is_image($picture->ID)) {
2545
+												$checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2546
+												$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');
2547
+
2548
+												$done_picture[] = $picture->ID;
2549
+											}
2550
+										}
2551
+									}
2552
+								}
2553
+
2554
+								$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');
2555
+							}
2556
+
2557
+						}
2558
+					}
2559
+				}
2786 2560
 
2787
-        return $output;
2788
-    }
2561
+				$tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2789 2562
 
2790
-    public static function get_parent_variation($variation_id)
2791
-    {
2792
-        $result = array();
2793
-        if (!empty($variation_id)) {
2794
-            $variation_post = get_post($variation_id);
2795
-            if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2796
-                $result['parent_post'] = get_post($variation_post->post_parent);
2797
-                $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2798
-            }
2799
-        }
2800
-        return $result;
2801
-    }
2563
+				$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2564
+				$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())));
2565
+				$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');
2802 2566
 
2803
-    /**
2804
-     * Display the current configuration for a given product
2805
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2806
-     */
2807
-    public function wpshop_product_variations_summary($shortcode_attribute)
2808
-    {
2809
-        $output = '';
2810
-
2811
-        $product_variations_selection_args = array(
2812
-            'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2813
-            'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2814
-        );
2815
-
2816
-        $current_user_id = get_current_user_id();
2817
-
2818
-        if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2819
-            foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2820
-                if (!empty($item) && !empty($item['item_id'])) {
2821
-
2822
-                    $free_variations = array();
2823
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2824
-                        foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2825
-                            $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2826
-                        }
2827
-                    }
2828
-
2829
-                    $variations = array();
2830
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2831
-                        foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2832
-
2833
-                            if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2834
-                                foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2835
-                                    $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2836
-                                }
2837
-                            }
2838
-                        }
2839
-                    }
2840
-                    $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2841
-
2842
-                    $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2843
-                }
2844
-            }
2845
-        }
2567
+				/*    Add the variation definition to output    */
2568
+				$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');
2569
+			}
2846 2570
 
2847
-        $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2571
+			$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');
2572
+			/*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2573
+			wp_reset_query();
2574
+		} else {
2575
+			$output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2576
+		}
2848 2577
 
2849
-        echo $output;
2850
-    }
2578
+		return $output;
2579
+	}
2580
+
2581
+	/**
2582
+	 * Retrieve and display the variation for a given product
2583
+	 * @param integer $product_id The product identifier to get variation for
2584
+	 */
2585
+	public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2586
+	{
2587
+		global $wp_query;
2588
+		$output = '';
2589
+
2590
+		$product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2591
+		$wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2592
+		$head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2593
+
2594
+		/**    Get attribute order for current product    */
2595
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2596
+		$output_order = array();
2597
+		if (count($product_attribute_order_detail) > 0) {
2598
+			if (!empty($product_attribute_order_detail)) {
2599
+				foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2600
+					foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2601
+						if (!empty($attribute_def->code)) {
2602
+							$output_order[$attribute_def->code] = $position;
2603
+						}
2604
+
2605
+					}
2606
+				}
2607
+			}
2608
+		}
2609
+
2610
+		$variations_params = array();
2611
+		$variation_attribute = array();
2612
+		$variation_attribute_ordered = array();
2613
+		$possible_values = array();
2614
+		$possible_values_for_selection_calculation = array();
2615
+
2616
+		/*    Vérification de l'existence de déclinaison pour le produit    */
2617
+		$wpshop_variation_list = self::get_variation($product_id);
2618
+		if (!empty($wpshop_variation_list)) {
2619
+			foreach ($wpshop_variation_list as $variation) {
2620
+				if (!empty($variation['variation_def'])) {
2621
+					$display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2622
+					foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2623
+						if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2624
+							$tpl_component = array();
2625
+
2626
+							$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2627
+							$default_value_is_serial = false;
2628
+							$attribute_list_first_element = $attribute_db_definition->default_value;
2629
+							if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2630
+								$default_value_is_serial = true;
2631
+								$tmp_default_value = unserialize($attribute_db_definition->default_value);
2632
+								$attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2633
+							}
2634
+
2635
+							if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2636
+								$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');
2637
+							}
2638
+
2639
+							if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2640
+								$tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2641
+								$position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2642
+							} else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2643
+								$post_def = get_post($attribute_value);
2644
+								$tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2645
+								$position = $post_def->menu_order;
2646
+							}
2647
+
2648
+							if (!empty($variation['variation_dif'])) {
2649
+								foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2650
+									$wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2651
+									$the_value = $attribute_dif_value;
2652
+									if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2653
+										$the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2654
+									}
2655
+									$tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2656
+								}
2657
+							}
2658
+							if (!empty($attribute_value)) {
2659
+								$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));
2660
+								$possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2661
+							}
2662
+							unset($tpl_component);
2663
+						}
2664
+					}
2665
+				}
2666
+			}
2667
+
2668
+			$variation_tpl = array();
2669
+			if (!empty($head_wpshop_variation_definition['attributes'])) {
2670
+				foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2671
+					$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2672
+
2673
+					if (!empty($attribute_db_definition)) {
2674
+						$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');
2675
+
2676
+						$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;
2677
+						if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2678
+							$is_required = true;
2679
+						}
2680
+
2681
+						$input_def = array();
2682
+						$input_def['type'] = $attribute_db_definition->frontend_input;
2683
+						$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);
2684
+						if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2685
+							unset($possible_values[$attribute_code][0]);
2686
+							$value = array($value);
2687
+						}
2688
+						$input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2689
+						$input_def['name'] = $attribute_code;
2690
+						$real_possible_values = array();
2691
+						if (!empty($possible_values[$attribute_code])) {
2692
+							ksort($possible_values[$attribute_code]);
2693
+							foreach ($possible_values[$attribute_code] as $position => $def) {
2694
+								foreach ($def as $attribute_value => $attribute_value_output) {
2695
+									$real_possible_values[$attribute_value] = $attribute_value_output;
2696
+									if (!empty($attribute_value)) {
2697
+										global $wpdb;
2698
+										$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);
2699
+										if ('draft' == $wpdb->get_var($query)) {
2700
+											unset($real_possible_values[$attribute_value]);
2701
+										}
2702
+									}
2703
+								}
2704
+							}
2705
+						}
2706
+						$input_def['possible_value'] = $real_possible_values;
2707
+						$input_def['valueToPut'] = 'index';
2708
+						$input_def['value'] = $value;
2709
+
2710
+						$input_def['options']['more_input'] = '';
2711
+						if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2712
+							foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2713
+								$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 . '" />';
2714
+							}
2715
+						}
2716
+
2717
+						$input_def['options_label']['original'] = true;
2718
+						$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) . '" ';
2719
+
2720
+						if (!empty($real_possible_values)) {
2721
+							$tpl_component = array();
2722
+							$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'];
2723
+							$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2724
+							$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));
2725
+							$tpl_component['VARIATION_CODE'] = $attribute_code;
2726
+							$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2727
+							$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2728
+							$tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2729
+							$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2730
+							$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2731
+							$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;
2732
+							$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2733
+							$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2734
+							$variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2735
+						}
2736
+
2737
+						$variation_attribute[] = $attribute_code;
2738
+					}
2739
+				}
2740
+			}
2741
+
2742
+		}
2743
+		$variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2744
+		wp_reset_query();
2745
+
2746
+		$attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2747
+		if (!empty($attribute_defined_to_be_user_defined)) {
2748
+			foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2749
+				$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;
2750
+
2751
+				$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');
2752
+				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')) {
2753
+					$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] : ''));
2754
+
2755
+					$tpl_component = array();
2756
+					$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) . '" ';
2757
+					$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2758
+					$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));
2759
+					$tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2760
+					$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 . '" ' : '';
2761
+					$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2762
+					$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2763
+					$tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2764
+					$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2765
+					$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2766
+					$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;
2767
+					$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'];
2768
+					$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)];
2769
+				}
2770
+			}
2771
+		}
2772
+		$variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2773
+		if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2774
+			ksort($variation_attribute_ordered);
2775
+			foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2776
+				$variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2777
+			}
2778
+		}
2779
+		$variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2780
+		$variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2781
+		if ($from_admin && !empty($order_id)) {
2782
+			$variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2783
+			$variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2784
+		}
2785
+		$output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2786
+
2787
+		return $output;
2788
+	}
2789
+
2790
+	public static function get_parent_variation($variation_id)
2791
+	{
2792
+		$result = array();
2793
+		if (!empty($variation_id)) {
2794
+			$variation_post = get_post($variation_id);
2795
+			if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2796
+				$result['parent_post'] = get_post($variation_post->post_parent);
2797
+				$result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2798
+			}
2799
+		}
2800
+		return $result;
2801
+	}
2802
+
2803
+	/**
2804
+	 * Display the current configuration for a given product
2805
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2806
+	 */
2807
+	public function wpshop_product_variations_summary($shortcode_attribute)
2808
+	{
2809
+		$output = '';
2810
+
2811
+		$product_variations_selection_args = array(
2812
+			'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2813
+			'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2814
+		);
2815
+
2816
+		$current_user_id = get_current_user_id();
2817
+
2818
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2819
+			foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2820
+				if (!empty($item) && !empty($item['item_id'])) {
2821
+
2822
+					$free_variations = array();
2823
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2824
+						foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2825
+							$free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2826
+						}
2827
+					}
2851 2828
 
2852
-    /**
2853
-     * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2854
-     *
2855
-     * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2856
-     * @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
2857
-     * @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
2858
-     * @param string $wpshop_current_for_display Inconnu / Unknown
2859
-     * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2860
-     *
2861
-     * @return array Le résultat du calcul pour l'affichage / Output result
2862
-     */
2863
-    public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2864
-    {
2865
-        global $wpdb;
2866
-
2867
-        $wpshop_cart = new wps_cart();
2868
-        $wpshop_products = new wpshop_products();
2869
-
2870
-        $response = '';
2871
-        $response_status = $has_variation = false;
2872
-        $tpl_component = array();
2873
-
2874
-        // Check if variations exists
2875
-        if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2876
-
2877
-            //Recover all selected variations
2878
-            $variations_selected = array();
2879
-            if (!empty($wpshop_variation_selected)) {
2880
-                foreach ($wpshop_variation_selected as $selected_variation) {
2881
-                    $variation_definition = explode('-_variation_val_-', $selected_variation);
2882
-                    $variations_selected[$variation_definition[0]] = $variation_definition[1];
2883
-                }
2884
-            }
2885
-
2886
-            // Check variations priority
2887
-            $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2888
-
2889
-            // Check if $product_with_variation have variations
2890
-            if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2891
-
2892
-                $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2893
-                $product_to_add_to_cart = $formatted_product[0];
2894
-                foreach ($formatted_product[0] as $pid => $product_more_content) {
2895
-                    $order_items[$pid]['product_id'] = $product_more_content['id'];
2896
-
2897
-                    /** For product with variation    */
2898
-                    $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2899
-                    $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2900
-                    $order_items[$pid]['product_variation'] = '';
2901
-                    if (!empty($product_more_content['variations'])) {
2902
-                        foreach ($product_more_content['variations'] as $variation_id) {
2903
-                            $order_items[$pid]['product_variation'][] = $variation_id;
2904
-                        }
2905
-                    }
2906
-                }
2907
-
2908
-                // If Product list is not empty, add products to order
2909
-                if (!empty($order_items)) {
2910
-                    foreach ($order_items as $product_id => $d) {
2911
-                        $product_key = $product_id;
2912
-
2913
-                        // Formate datas
2914
-                        $product_id = $head_product_id = $d['product_id'];
2915
-                        $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2916
-
2917
-                        // If product is a single variation product
2918
-                        if (!empty($product_variation) && (count($product_variation) == 1)) {
2919
-                            $product_id = $product_variation[0];
2920
-                        }
2921
-
2922
-                        // Construct final product
2923
-                        $product = wpshop_products::get_product_data($d['product_id'], true);
2924
-                        $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2829
+					$variations = array();
2830
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2831
+						foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2832
+
2833
+							if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2834
+								foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2835
+									$variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2836
+								}
2837
+							}
2838
+						}
2839
+					}
2840
+					$product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2841
+
2842
+					$product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2843
+				}
2844
+			}
2845
+		}
2846
+
2847
+		$output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2848
+
2849
+		echo $output;
2850
+	}
2851
+
2852
+	/**
2853
+	 * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2854
+	 *
2855
+	 * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2856
+	 * @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
2857
+	 * @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
2858
+	 * @param string $wpshop_current_for_display Inconnu / Unknown
2859
+	 * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2860
+	 *
2861
+	 * @return array Le résultat du calcul pour l'affichage / Output result
2862
+	 */
2863
+	public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2864
+	{
2865
+		global $wpdb;
2866
+
2867
+		$wpshop_cart = new wps_cart();
2868
+		$wpshop_products = new wpshop_products();
2869
+
2870
+		$response = '';
2871
+		$response_status = $has_variation = false;
2872
+		$tpl_component = array();
2873
+
2874
+		// Check if variations exists
2875
+		if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2876
+
2877
+			//Recover all selected variations
2878
+			$variations_selected = array();
2879
+			if (!empty($wpshop_variation_selected)) {
2880
+				foreach ($wpshop_variation_selected as $selected_variation) {
2881
+					$variation_definition = explode('-_variation_val_-', $selected_variation);
2882
+					$variations_selected[$variation_definition[0]] = $variation_definition[1];
2883
+				}
2884
+			}
2885
+
2886
+			// Check variations priority
2887
+			$product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2888
+
2889
+			// Check if $product_with_variation have variations
2890
+			if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2891
+
2892
+				$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2893
+				$product_to_add_to_cart = $formatted_product[0];
2894
+				foreach ($formatted_product[0] as $pid => $product_more_content) {
2895
+					$order_items[$pid]['product_id'] = $product_more_content['id'];
2896
+
2897
+					/** For product with variation    */
2898
+					$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2899
+					$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2900
+					$order_items[$pid]['product_variation'] = '';
2901
+					if (!empty($product_more_content['variations'])) {
2902
+						foreach ($product_more_content['variations'] as $variation_id) {
2903
+							$order_items[$pid]['product_variation'][] = $variation_id;
2904
+						}
2905
+					}
2906
+				}
2907
+
2908
+				// If Product list is not empty, add products to order
2909
+				if (!empty($order_items)) {
2910
+					foreach ($order_items as $product_id => $d) {
2911
+						$product_key = $product_id;
2912
+
2913
+						// Formate datas
2914
+						$product_id = $head_product_id = $d['product_id'];
2915
+						$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2916
+
2917
+						// If product is a single variation product
2918
+						if (!empty($product_variation) && (count($product_variation) == 1)) {
2919
+							$product_id = $product_variation[0];
2920
+						}
2921
+
2922
+						// Construct final product
2923
+						$product = wpshop_products::get_product_data($d['product_id'], true);
2924
+						$the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2925 2925
 						$the_product['text_from'] = $product_with_variation['text_from'];
2926 2926
 
2927
-                        //    Add variation to product into cart for storage
2928
-                        if (!empty($product_variation)) {
2929
-                            $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2930
-                        }
2931
-
2932
-                        // Free Variations Checking
2933
-                        if (!empty($d['free_variation'])) {
2934
-                            $the_product['item_meta']['free_variation'] = $d['free_variation'];
2935
-                            $head_product_id = $the_product['product_id'];
2936
-                        }
2937
-
2938
-                        // If product is a variation, we check parent product general
2939
-                        if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2940
-                            $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2941
-                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2942
-                                $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2943
-                                $parent_meta = $parent_def['parent_post_meta'];
2944
-                                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) {
2945
-                                    $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2946
-                                    $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2947
-                                    $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2948
-                                }
2949
-                            }
2950
-                        }
2951
-                    }
2952
-                }
2953
-
2954
-                if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2955
-                    $price_infos = wpshop_prices::check_product_price($the_product, true);
2956
-                    if (!empty($price_infos['discount']['discount_exist'])) {
2957
-                        $the_product['price_ttc_before_discount'] = $the_product['product_price'];
2958
-                        $the_product['price_ht_before_discount'] = $the_product['price_ht'];
2959
-                    }
2960
-                    $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'];
2961
-                    $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'];
2962
-                    $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'];
2963
-                }
2964
-
2965
-                $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2966
-                // Add free variations to product
2967
-                if (!empty($wpshop_free_variation)) {
2968
-                    $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2969
-                }
2970
-                // Change picture if have a selected variation
2971
-                $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;
2972
-                $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2973
-
2974
-                // Price Display
2975
-                $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2976
-                $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2977
-                $productPrice = '';
2978
-                if ($price_display) {
2979
-                    $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2980
-                }
2981
-
2982
-                //Get Summary cart
2983
-                $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2984
-                $response_status = true;
2985
-            } else {
2986
-                //Product without variations
2987
-                $product_data = wpshop_products::get_product_data($product_id);
2988
-                $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2989
-            }
2990
-        }
2927
+						//    Add variation to product into cart for storage
2928
+						if (!empty($product_variation)) {
2929
+							$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2930
+						}
2931
+
2932
+						// Free Variations Checking
2933
+						if (!empty($d['free_variation'])) {
2934
+							$the_product['item_meta']['free_variation'] = $d['free_variation'];
2935
+							$head_product_id = $the_product['product_id'];
2936
+						}
2937
+
2938
+						// If product is a variation, we check parent product general
2939
+						if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2940
+							$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2941
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2942
+								$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2943
+								$parent_meta = $parent_def['parent_post_meta'];
2944
+								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) {
2945
+									$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2946
+									$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2947
+									$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2948
+								}
2949
+							}
2950
+						}
2951
+					}
2952
+				}
2991 2953
 
2992
-        return array($response_status, $response);
2993
-    }
2954
+				if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2955
+					$price_infos = wpshop_prices::check_product_price($the_product, true);
2956
+					if (!empty($price_infos['discount']['discount_exist'])) {
2957
+						$the_product['price_ttc_before_discount'] = $the_product['product_price'];
2958
+						$the_product['price_ht_before_discount'] = $the_product['price_ht'];
2959
+					}
2960
+					$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'];
2961
+					$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'];
2962
+					$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'];
2963
+				}
2994 2964
 
2995
-    /**
2996
-     * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2997
-     *
2998
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2999
-     */
3000
-    public function wpshop_product_variation_value_detail($shortcode_attribute)
3001
-    {
3002
-        echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
3003
-    }
2965
+				$product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2966
+				// Add free variations to product
2967
+				if (!empty($wpshop_free_variation)) {
2968
+					$the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2969
+				}
2970
+				// Change picture if have a selected variation
2971
+				$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;
2972
+				$response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2973
+
2974
+				// Price Display
2975
+				$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2976
+				$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2977
+				$productPrice = '';
2978
+				if ($price_display) {
2979
+					$response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2980
+				}
3004 2981
 
3005
-    /**
3006
-     * Build the product structure with variation for product choosed by the user into frontend sheet
3007
-     *
3008
-     * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
3009
-     * @param integer $product_id The basic product choose by the user in frontend
3010
-     *
3011
-     * @return array The product list for adding to the cart build by variation priority
3012
-     */
3013
-    public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
3014
-    {
3015
-        global $wpdb;
3016
-        $all_required_variations_selected = $no_selected_variation = true;
3017
-        $single_variations = $combined_variations = $product_to_add_to_cart = array();
3018
-
3019
-        // Check if all required variations are selected
3020
-        $required_attributes_list = wpshop_prices::check_required_attributes($product_id);
3021
-        foreach ($selected_variation as $k => $value) {
3022
-            if ($value == 0 && in_array($k, $required_attributes_list)) {
3023
-                $all_required_variations_selected = false;
3024
-            }
3025
-            if ($value != 0) {
3026
-                $no_selected_variation = false;
3027
-            }
3028
-        }
3029
-        if (!empty($selected_variation)) {
3030
-            //Check variations configuration
3031
-            $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3032
-            // Check variations type
3033
-            $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3034
-            $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3035
-
3036
-            //Check defined variation priority
3037
-            $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3038
-            $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3039
-
3040
-            // Recover all product variations
3041
-            $query_variation = $selected_variation;
3042
-            // Delete free variations
3043
-            unset($query_variation['free']);
3044
-
3045
-            if ($product_variation_type == 'single') {
3046
-                // Get single variations
3047
-                $single_variations = array();
3048
-                foreach ($selected_variation as $attribute_code => $attribute_value) {
3049
-                    if (isset($attribute_value) && $attribute_code != 'free') {
3050
-                        $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);
3051
-                        $single_variation_id = $wpdb->get_var($query);
3052
-                        if (!empty($single_variation_id)) {
3053
-                            $single_variations[] = $single_variation_id;
3054
-                            unset($query_variation[$attribute_code]);
3055
-                        }
3056
-                    }
3057
-                }
3058
-            } else {
3059
-                // Get combined variations
3060
-                $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);
3061
-                $combined_variation_id = $wpdb->get_var($query);
3062
-                if (!empty($combined_variation_id)) {
3063
-                    $combined_variations[] = $combined_variation_id;
3064
-                }
3065
-
3066
-            }
3067
-
3068
-            //If all required variations are not selected
3069
-            if (!$all_required_variations_selected || $no_selected_variation) {
3070
-                $product_to_add_to_cart['text_from'] = 'on';
3071
-                // If we choose to display lower price variation combinaison
3072
-                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']))) {
3073
-                    //Get lower price variation combinaison
3074
-                    $lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3075
-                    if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3076
-                        foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3077
-                            $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3078
-                        }
3079
-                    }
3080
-                    $product_to_add_to_cart['display_lower_price'] = true;
3081
-                } else {
3082
-                    $product_to_add_to_cart[$product_id]['variations'] = array();
3083
-                }
3084
-            } else {
3085
-                $product_to_add_to_cart['text_from'] = '';
3086
-                $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3087
-            }
3088
-        }
2982
+				//Get Summary cart
2983
+				$response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2984
+				$response_status = true;
2985
+			} else {
2986
+				//Product without variations
2987
+				$product_data = wpshop_products::get_product_data($product_id);
2988
+				$response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2989
+			}
2990
+		}
3089 2991
 
3090
-        return $product_to_add_to_cart;
3091
-    }
2992
+		return array($response_status, $response);
2993
+	}
3092 2994
 
3093
-    public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3094
-    {
3095
-        global $wpdb;
3096
-
3097
-        if (!empty($product_variations)) {
3098
-            // Initialize variations total price datas
3099
-            $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3100
-            $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3101
-            $vat_rate = 0;
3102
-            $discount_amount = $discount_rate = $special_price = 0;
3103
-            // Recover Head product metadata
3104
-            $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3105
-            $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3106
-            if (!empty($tva_rate_id)) {
3107
-                // Recover VAT Rate of product
3108
-                $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3109
-                $vat_rate = $wpdb->get_var($query);
3110
-            }
3111
-            $price_piloting = get_option('wpshop_shop_price_piloting');
3112
-            foreach ($product_variations as $product_variation) {
3113
-                $variation_metadata['product_price'] = 0;
3114
-                $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3115
-                if (!empty($variation_metadata)) {
3116
-                    $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']);
3117
-                    $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))));
3118
-
3119
-                    $variations_total_price['price_et'] += $p_et;
3120
-                    $variations_total_price['price_ati'] += $p_ati;
3121
-                    $variations_total_price['vat_amount'] += $p_ati - $p_et;
3122
-
3123
-                    $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3124
-
3125
-                    // Check discount
3126
-                    $discount_config = wpshop_prices::check_discount_for_product($product_variation);
3127
-                    if (!empty($discount_config) && !empty($discount_config['value'])) {
3128
-                        $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3129
-                        $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3130
-                        $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3131
-                        $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3132
-
3133
-                        if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3134
-                            $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3135
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3136
-                            $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3137
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3138
-                            $product_into_cart['special_price'] = $special_price + $discount_config['value'];
3139
-                        }
3140
-                    }
3141
-
3142
-                    $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3143
-                    $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3144
-                }
3145
-            }
3146
-
3147
-            // Check if add or replace variation price to head product
3148
-            /**
3149
-             * Since 1.4.3.7
3150
-             * L'option du produit remplace le prix du produit de tête.
3151
-             */
2995
+	/**
2996
+	 * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2997
+	 *
2998
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2999
+	 */
3000
+	public function wpshop_product_variation_value_detail($shortcode_attribute)
3001
+	{
3002
+		echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
3003
+	}
3004
+
3005
+	/**
3006
+	 * Build the product structure with variation for product choosed by the user into frontend sheet
3007
+	 *
3008
+	 * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
3009
+	 * @param integer $product_id The basic product choose by the user in frontend
3010
+	 *
3011
+	 * @return array The product list for adding to the cart build by variation priority
3012
+	 */
3013
+	public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
3014
+	{
3015
+		global $wpdb;
3016
+		$all_required_variations_selected = $no_selected_variation = true;
3017
+		$single_variations = $combined_variations = $product_to_add_to_cart = array();
3018
+
3019
+		// Check if all required variations are selected
3020
+		$required_attributes_list = wpshop_prices::check_required_attributes($product_id);
3021
+		foreach ($selected_variation as $k => $value) {
3022
+			if ($value == 0 && in_array($k, $required_attributes_list)) {
3023
+				$all_required_variations_selected = false;
3024
+			}
3025
+			if ($value != 0) {
3026
+				$no_selected_variation = false;
3027
+			}
3028
+		}
3029
+		if (!empty($selected_variation)) {
3030
+			//Check variations configuration
3031
+			$product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3032
+			// Check variations type
3033
+			$product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3034
+			$product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3035
+
3036
+			//Check defined variation priority
3037
+			$priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3038
+			$product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3039
+
3040
+			// Recover all product variations
3041
+			$query_variation = $selected_variation;
3042
+			// Delete free variations
3043
+			unset($query_variation['free']);
3044
+
3045
+			if ($product_variation_type == 'single') {
3046
+				// Get single variations
3047
+				$single_variations = array();
3048
+				foreach ($selected_variation as $attribute_code => $attribute_value) {
3049
+					if (isset($attribute_value) && $attribute_code != 'free') {
3050
+						$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);
3051
+						$single_variation_id = $wpdb->get_var($query);
3052
+						if (!empty($single_variation_id)) {
3053
+							$single_variations[] = $single_variation_id;
3054
+							unset($query_variation[$attribute_code]);
3055
+						}
3056
+					}
3057
+				}
3058
+			} else {
3059
+				// Get combined variations
3060
+				$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);
3061
+				$combined_variation_id = $wpdb->get_var($query);
3062
+				if (!empty($combined_variation_id)) {
3063
+					$combined_variations[] = $combined_variation_id;
3064
+				}
3065
+
3066
+			}
3067
+
3068
+			//If all required variations are not selected
3069
+			if (!$all_required_variations_selected || $no_selected_variation) {
3070
+				$product_to_add_to_cart['text_from'] = 'on';
3071
+				// If we choose to display lower price variation combinaison
3072
+				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']))) {
3073
+					//Get lower price variation combinaison
3074
+					$lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3075
+					if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3076
+						foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3077
+							$product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3078
+						}
3079
+					}
3080
+					$product_to_add_to_cart['display_lower_price'] = true;
3081
+				} else {
3082
+					$product_to_add_to_cart[$product_id]['variations'] = array();
3083
+				}
3084
+			} else {
3085
+				$product_to_add_to_cart['text_from'] = '';
3086
+				$product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3087
+			}
3088
+		}
3089
+
3090
+		return $product_to_add_to_cart;
3091
+	}
3092
+
3093
+	public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3094
+	{
3095
+		global $wpdb;
3096
+
3097
+		if (!empty($product_variations)) {
3098
+			// Initialize variations total price datas
3099
+			$variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3100
+			$variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3101
+			$vat_rate = 0;
3102
+			$discount_amount = $discount_rate = $special_price = 0;
3103
+			// Recover Head product metadata
3104
+			$head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3105
+			$tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3106
+			if (!empty($tva_rate_id)) {
3107
+				// Recover VAT Rate of product
3108
+				$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3109
+				$vat_rate = $wpdb->get_var($query);
3110
+			}
3111
+			$price_piloting = get_option('wpshop_shop_price_piloting');
3112
+			foreach ($product_variations as $product_variation) {
3113
+				$variation_metadata['product_price'] = 0;
3114
+				$variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3115
+				if (!empty($variation_metadata)) {
3116
+					$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']);
3117
+					$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))));
3118
+
3119
+					$variations_total_price['price_et'] += $p_et;
3120
+					$variations_total_price['price_ati'] += $p_ati;
3121
+					$variations_total_price['vat_amount'] += $p_ati - $p_et;
3122
+
3123
+					$variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3124
+
3125
+					// Check discount
3126
+					$discount_config = wpshop_prices::check_discount_for_product($product_variation);
3127
+					if (!empty($discount_config) && !empty($discount_config['value'])) {
3128
+						$variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3129
+						$variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3130
+						$variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3131
+						$variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3132
+
3133
+						if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3134
+							$product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3135
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3136
+							$product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3137
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3138
+							$product_into_cart['special_price'] = $special_price + $discount_config['value'];
3139
+						}
3140
+					}
3141
+
3142
+					$product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3143
+					$product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3144
+				}
3145
+			}
3146
+
3147
+			// Check if add or replace variation price to head product
3148
+			/**
3149
+			 * Since 1.4.3.7
3150
+			 * L'option du produit remplace le prix du produit de tête.
3151
+			 */
3152 3152
 			if( true ) {
3153
-                //Replace the product price
3154
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3155
-                    $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3156
-                    $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3157
-
3158
-                    $product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3159
-                    $product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3160
-                    $product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3161
-                } else {
3162
-                    $product_into_cart['product_price'] = $variations_total_price['price_ati'];
3163
-                    $product_into_cart['price_ht'] = $variations_total_price['price_et'];
3164
-                    $product_into_cart['tva'] = $variations_total_price['vat_amount'];
3165
-                }
3166
-            } else {
3167
-                // Add variations price to product price
3168
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3169
-                    $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3170
-                    $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3171
-
3172
-                    $product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3173
-                    $product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3174
-                    $product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3175
-                } else {
3176
-                    $product_into_cart['product_price'] += $variations_total_price['price_ati'];
3177
-                    $product_into_cart['price_ht'] += $variations_total_price['price_et'];
3178
-                    $product_into_cart['tva'] += $variations_total_price['vat_amount'];
3179
-                }
3180
-                // Check parent discount
3181
-                $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3182
-                if (!empty($parent_discount_config)) {
3183
-                    $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'];
3184
-                    $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'];
3185
-                    $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3186
-
3187
-                    if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3188
-                        $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3189
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3190
-                        $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3191
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3192
-                        $product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3193
-                    }
3194
-                }
3195
-            }
3196
-        } else {
3197
-            // If product have just Free variations
3198
-            $discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3199
-            if (!empty($discount_config)) {
3200
-                $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'];
3201
-                $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'];
3202
-                $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3203
-            }
3204
-        }
3153
+				//Replace the product price
3154
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3155
+					$product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3156
+					$product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3157
+
3158
+					$product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3159
+					$product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3160
+					$product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3161
+				} else {
3162
+					$product_into_cart['product_price'] = $variations_total_price['price_ati'];
3163
+					$product_into_cart['price_ht'] = $variations_total_price['price_et'];
3164
+					$product_into_cart['tva'] = $variations_total_price['vat_amount'];
3165
+				}
3166
+			} else {
3167
+				// Add variations price to product price
3168
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3169
+					$product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3170
+					$product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3171
+
3172
+					$product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3173
+					$product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3174
+					$product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3175
+				} else {
3176
+					$product_into_cart['product_price'] += $variations_total_price['price_ati'];
3177
+					$product_into_cart['price_ht'] += $variations_total_price['price_et'];
3178
+					$product_into_cart['tva'] += $variations_total_price['vat_amount'];
3179
+				}
3180
+				// Check parent discount
3181
+				$parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3182
+				if (!empty($parent_discount_config)) {
3183
+					$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'];
3184
+					$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'];
3185
+					$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3186
+
3187
+					if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3188
+						$product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3189
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3190
+						$product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3191
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3192
+						$product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3193
+					}
3194
+				}
3195
+			}
3196
+		} else {
3197
+			// If product have just Free variations
3198
+			$discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3199
+			if (!empty($discount_config)) {
3200
+				$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'];
3201
+				$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'];
3202
+				$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3203
+			}
3204
+		}
3205 3205
 
3206
-        // Text From indicator
3207
-        if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3208
-            $product_into_cart['text_from'] = $variations_options['text_from'];
3209
-        }
3210
-        return $product_into_cart;
3211
-    }
3206
+		// Text From indicator
3207
+		if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3208
+			$product_into_cart['text_from'] = $variations_options['text_from'];
3209
+		}
3210
+		return $product_into_cart;
3211
+	}
3212 3212
 
3213
-    /**
3214
-     * Read an array with product options chosen by the customer, order into an array regarding admin definition
3215
-     *
3216
-     * @param array $product_definition_value The array with the selected product option to ordered
3217
-     * @param array $output_order The good order for attribute defined by administrator
3218
-     * @param dtring $from_page A string allowing to take a specific template regarding the current page
3219
-     *
3220
-     * @return array The array containing all product options ordered as the admin configure it
3221
-     */
3222
-    public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3223
-    {
3224
-        $variation_attribute_ordered = array();
3225
-        $variation_attribute_ordered['prices'] = array();
3226
-        $variation_attribute_ordered['attribute_list'] = array();
3227
-
3228
-        if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3229
-            foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3230
-                $variation_tpl_component = array();
3231
-                foreach ($variation_attribute_detail as $info_name => $info_value) {
3232
-                    $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);
3233
-                }
3234
-                $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3235
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3236
-                if (!empty($output_order[$variation_attribute_code])) {
3237
-                    $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);
3238
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3239
-                        $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3240
-                    }
3241
-                } else {
3242
-                    $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);
3243
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3244
-                        $variation_attribute_ordered['attribute_list'][] = $display_data;
3245
-                    }
3246
-                }
3247
-                unset($variation_tpl_component);
3248
-            }
3249
-        }
3213
+	/**
3214
+	 * Read an array with product options chosen by the customer, order into an array regarding admin definition
3215
+	 *
3216
+	 * @param array $product_definition_value The array with the selected product option to ordered
3217
+	 * @param array $output_order The good order for attribute defined by administrator
3218
+	 * @param dtring $from_page A string allowing to take a specific template regarding the current page
3219
+	 *
3220
+	 * @return array The array containing all product options ordered as the admin configure it
3221
+	 */
3222
+	public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3223
+	{
3224
+		$variation_attribute_ordered = array();
3225
+		$variation_attribute_ordered['prices'] = array();
3226
+		$variation_attribute_ordered['attribute_list'] = array();
3227
+
3228
+		if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3229
+			foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3230
+				$variation_tpl_component = array();
3231
+				foreach ($variation_attribute_detail as $info_name => $info_value) {
3232
+					$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);
3233
+				}
3234
+				$variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3235
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3236
+				if (!empty($output_order[$variation_attribute_code])) {
3237
+					$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);
3238
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3239
+						$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3240
+					}
3241
+				} else {
3242
+					$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);
3243
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3244
+						$variation_attribute_ordered['attribute_list'][] = $display_data;
3245
+					}
3246
+				}
3247
+				unset($variation_tpl_component);
3248
+			}
3249
+		}
3250 3250
 
3251
-        if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3252
-            foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3253
-                $variation_tpl_component = array();
3254
-                foreach ($variation_details as $info_name => $info_value) {
3255
-                    if ($info_name != 'item_meta') {
3256
-                        $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);
3257
-                    }
3258
-                }
3259
-                foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3260
-                    $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3261
-                    $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3262
-                    $variation_tpl_component['VARIATION_ID'] = $variation_id;
3263
-                    $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3264
-
3265
-                    $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3266
-                }
3267
-                if (!empty($output_order[$variation_attribute_code])) {
3268
-                    $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);
3269
-                }
3270
-                unset($variation_tpl_component);
3271
-            }
3272
-        }
3251
+		if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3252
+			foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3253
+				$variation_tpl_component = array();
3254
+				foreach ($variation_details as $info_name => $info_value) {
3255
+					if ($info_name != 'item_meta') {
3256
+						$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);
3257
+					}
3258
+				}
3259
+				foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3260
+					$variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3261
+					$variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3262
+					$variation_tpl_component['VARIATION_ID'] = $variation_id;
3263
+					$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3273 3264
 
3274
-        /**    Free Variation part    */
3275
-        if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3276
-            foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3277
-                if (strpos($build_variation, '-_variation_val_-')) {
3278
-                    $variation_definition = explode('-_variation_val_-', $build_variation);
3279
-                    $attribute_code = $variation_definition[0];
3280
-                    $attribute_selected_value = $variation_definition[1];
3281
-                } else {
3282
-                    $attribute_code = $build_variation_key;
3283
-                    $attribute_selected_value = $build_variation;
3284
-                }
3285
-
3286
-                $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3287
-                $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3288
-                $value_to_outut = $attribute_selected_value;
3289
-                switch ($free_variation_attribute_def->data_type) {
3290
-                    case 'datetime':
3291
-                        $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3292
-                        break;
3293
-                }
3294
-
3295
-                if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3296
-                    switch ($free_variation_attribute_def->data_type_to_use) {
3297
-                        case 'custom':
3298
-                        case 'internal':
3299
-                            $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3300
-                            $value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3301
-                            break;
3302
-                    }
3303
-                }
3304
-                $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3305
-                $variation_tpl_component['VARIATION_ID'] = $attribute_code;
3306
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3307
-                if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3308
-                    $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);
3309
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3310
-                        $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3311
-                    }
3312
-                }
3313
-                unset($variation_tpl_component);
3314
-            }
3315
-        }
3316
-        return $variation_attribute_ordered;
3317
-    }
3265
+					$variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3266
+				}
3267
+				if (!empty($output_order[$variation_attribute_code])) {
3268
+					$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);
3269
+				}
3270
+				unset($variation_tpl_component);
3271
+			}
3272
+		}
3318 3273
 
3319
-    public function wps_selected_variation_picture($head_product_id, $variations)
3320
-    {
3321
-        $response = array();
3322
-        /** Selected Product image **/
3323
-        $post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3324
-        if (!empty($post_thumbnail_id)) {
3325
-            $response['img_id'] = $post_thumbnail_id;
3326
-            $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3327
-            $response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3328
-        }
3274
+		/**    Free Variation part    */
3275
+		if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3276
+			foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3277
+				if (strpos($build_variation, '-_variation_val_-')) {
3278
+					$variation_definition = explode('-_variation_val_-', $build_variation);
3279
+					$attribute_code = $variation_definition[0];
3280
+					$attribute_selected_value = $variation_definition[1];
3281
+				} else {
3282
+					$attribute_code = $build_variation_key;
3283
+					$attribute_selected_value = $build_variation;
3284
+				}
3329 3285
 
3330
-        /** check if have one variation **/
3331
-        if (!empty($variations) && count($variations) == 1) {
3332
-            $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3333
-            if (!empty($variation_attached_image_id)) {
3334
-                $response['img_id'] = $variation_attached_image_id;
3335
-                $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3336
-                $response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3337
-            }
3338
-        }
3339
-        return $response;
3340
-    }
3286
+				$free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3287
+				$variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3288
+				$value_to_outut = $attribute_selected_value;
3289
+				switch ($free_variation_attribute_def->data_type) {
3290
+					case 'datetime':
3291
+						$value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3292
+						break;
3293
+				}
3341 3294
 
3342
-    /** Add a meta box of product sales history in product administration panel **/
3343
-    public function meta_box_product_sale_informations()
3344
-    {
3345
-        global $post;
3346
-        $product_id = $post->ID;
3347
-
3348
-        $variations = self::get_variation($product_id);
3349
-
3350
-        $sales_informations = array();
3351
-        /** Query **/
3352
-        $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3353
-        $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')));
3354
-        $orders = new WP_Query($query_args);
3355
-        if (!empty($orders) && !empty($orders->posts)) {
3356
-            foreach ($orders->posts as $order) {
3357
-                $order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3358
-                $order_info = get_post_meta($order->ID, '_order_info', true);
3359
-                $sales_informations[] = array(
3360
-                    'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3361
-                    'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3362
-                    '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'] : '',
3363
-                    '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'] : '',
3364
-                    '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'] : '',
3365
-                );
3366
-            }
3367
-        }
3295
+				if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3296
+					switch ($free_variation_attribute_def->data_type_to_use) {
3297
+						case 'custom':
3298
+						case 'internal':
3299
+							$possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3300
+							$value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3301
+							break;
3302
+					}
3303
+				}
3304
+				$variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3305
+				$variation_tpl_component['VARIATION_ID'] = $attribute_code;
3306
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3307
+				if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3308
+					$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);
3309
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3310
+						$variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3311
+					}
3312
+				}
3313
+				unset($variation_tpl_component);
3314
+			}
3315
+		}
3316
+		return $variation_attribute_ordered;
3317
+	}
3368 3318
 
3369
-        /** If product has been ordered **/
3370
-        $output = '';
3371
-        if (!empty($sales_informations)) {
3372
-            $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3373
-            $output .= '<ul>';
3374
-            foreach ($sales_informations as $sales_information) {
3375
-                $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>';
3376
-            }
3377
-            $output .= '</ul>';
3378
-        } else {
3379
-            $output .= __('This product has never been ordered', 'wpshop');
3380
-        }
3319
+	public function wps_selected_variation_picture($head_product_id, $variations)
3320
+	{
3321
+		$response = array();
3322
+		/** Selected Product image **/
3323
+		$post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3324
+		if (!empty($post_thumbnail_id)) {
3325
+			$response['img_id'] = $post_thumbnail_id;
3326
+			$response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3327
+			$response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3328
+		}
3381 3329
 
3382
-        echo $output;
3383
-    }
3330
+		/** check if have one variation **/
3331
+		if (!empty($variations) && count($variations) == 1) {
3332
+			$variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3333
+			if (!empty($variation_attached_image_id)) {
3334
+				$response['img_id'] = $variation_attached_image_id;
3335
+				$response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3336
+				$response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3337
+			}
3338
+		}
3339
+		return $response;
3340
+	}
3384 3341
 
3385
-    public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3386
-    {
3387
-        global $wpdb, $wpshop_payment;
3388
-        $output = '';
3389
-        $tpl_component = array();
3390
-        /**    Get attribute order for current product    */
3391
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3392
-        $output_order = array();
3393
-        if (count($product_attribute_order_detail) > 0) {
3394
-            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3395
-                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3396
-                    if (!empty($attribute_def->code)) {
3397
-                        $output_order[$attribute_def->code] = $position;
3398
-                    }
3399
-
3400
-                }
3401
-            }
3402
-        }
3403
-        $variation_attribute_ordered = array();
3404
-
3405
-        /** Check if product is a variation and change his name **/
3406
-        $product_post_type = get_post_type($the_product['product_id']);
3407
-        if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3408
-            $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3409
-            $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3410
-            $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3411
-        }
3342
+	/** Add a meta box of product sales history in product administration panel **/
3343
+	public function meta_box_product_sale_informations()
3344
+	{
3345
+		global $post;
3346
+		$product_id = $post->ID;
3347
+
3348
+		$variations = self::get_variation($product_id);
3349
+
3350
+		$sales_informations = array();
3351
+		/** Query **/
3352
+		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3353
+		$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')));
3354
+		$orders = new WP_Query($query_args);
3355
+		if (!empty($orders) && !empty($orders->posts)) {
3356
+			foreach ($orders->posts as $order) {
3357
+				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3358
+				$order_info = get_post_meta($order->ID, '_order_info', true);
3359
+				$sales_informations[] = array(
3360
+					'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3361
+					'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3362
+					'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'] : '',
3363
+					'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'] : '',
3364
+					'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'] : '',
3365
+				);
3366
+			}
3367
+		}
3412 3368
 
3413
-        foreach ($the_product as $product_definition_key => $product_definition_value) {
3414
-            if ($product_definition_key != 'item_meta') {
3415
-                $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3416
-                if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3417
-                    $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3418
-                }
3419
-            } else {
3420
-                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3421
-            }
3422
-        }
3369
+		/** If product has been ordered **/
3370
+		$output = '';
3371
+		if (!empty($sales_informations)) {
3372
+			$output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3373
+			$output .= '<ul>';
3374
+			foreach ($sales_informations as $sales_information) {
3375
+				$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>';
3376
+			}
3377
+			$output .= '</ul>';
3378
+		} else {
3379
+			$output .= __('This product has never been ordered', 'wpshop');
3380
+		}
3423 3381
 
3424
-        ksort($variation_attribute_ordered['attribute_list']);
3425
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3426
-        foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3427
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3428
-        }
3382
+		echo $output;
3383
+	}
3429 3384
 
3430
-        /**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3431
-        $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3432
-        if (!empty($attribute_list)) {
3433
-            foreach ($attribute_list as $attribute_def) {
3434
-                $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3435
-            }
3436
-        }
3385
+	public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3386
+	{
3387
+		global $wpdb, $wpshop_payment;
3388
+		$output = '';
3389
+		$tpl_component = array();
3390
+		/**    Get attribute order for current product    */
3391
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3392
+		$output_order = array();
3393
+		if (count($product_attribute_order_detail) > 0) {
3394
+			foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3395
+				foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3396
+					if (!empty($attribute_def->code)) {
3397
+						$output_order[$attribute_def->code] = $position;
3398
+					}
3437 3399
 
3438
-        /**    Fill the array with all prices for different variations    */
3439
-        foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3440
-            $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3441
-        }
3400
+				}
3401
+			}
3402
+		}
3403
+		$variation_attribute_ordered = array();
3404
+
3405
+		/** Check if product is a variation and change his name **/
3406
+		$product_post_type = get_post_type($the_product['product_id']);
3407
+		if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3408
+			$parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3409
+			$parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3410
+			$the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3411
+		}
3442 3412
 
3443
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3444
-        $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3445
-        $post_list_with_options = $wpdb->get_results($query);
3446
-        if (!empty($post_list_with_options)) {
3447
-            $additionnal_price = 0;
3448
-            foreach ($post_list_with_options as $product_info) {
3449
-                $product_meta = unserialize($product_info->meta_value);
3450
-                if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3451
-                    $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3452
-
3453
-                    $the_product = array_merge(array(
3454
-                        'product_id' => $product_info->post_id,
3455
-                        'product_qty' => 1,
3456
-                    ), $product);
3457
-
3458
-                    $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3459
-                    $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3460
-
3461
-                    $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));
3462
-                    $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3463
-                }
3464
-            }
3465
-        }
3413
+		foreach ($the_product as $product_definition_key => $product_definition_value) {
3414
+			if ($product_definition_key != 'item_meta') {
3415
+				$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3416
+				if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3417
+					$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3418
+				}
3419
+			} else {
3420
+				$variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3421
+			}
3422
+		}
3466 3423
 
3467
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3468
-        $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3469
-        if (!empty($additionnal_price)) {
3470
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3471
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3472
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3473
-        }
3424
+		ksort($variation_attribute_ordered['attribute_list']);
3425
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3426
+		foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3427
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3428
+		}
3429
+
3430
+		/**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3431
+		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3432
+		if (!empty($attribute_list)) {
3433
+			foreach ($attribute_list as $attribute_def) {
3434
+				$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3435
+			}
3436
+		}
3437
+
3438
+		/**    Fill the array with all prices for different variations    */
3439
+		foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3440
+			$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3441
+		}
3442
+
3443
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3444
+		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3445
+		$post_list_with_options = $wpdb->get_results($query);
3446
+		if (!empty($post_list_with_options)) {
3447
+			$additionnal_price = 0;
3448
+			foreach ($post_list_with_options as $product_info) {
3449
+				$product_meta = unserialize($product_info->meta_value);
3450
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3451
+					$product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3452
+
3453
+					$the_product = array_merge(array(
3454
+						'product_id' => $product_info->post_id,
3455
+						'product_qty' => 1,
3456
+					), $product);
3457
+
3458
+					$additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3459
+					$tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3460
+
3461
+					$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));
3462
+					$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3463
+				}
3464
+			}
3465
+		}
3474 3466
 
3475
-        /**    Call informtion for partial payment    */
3476
-        $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3477
-        $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3467
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3468
+		$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3469
+		if (!empty($additionnal_price)) {
3470
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3471
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3472
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3473
+		}
3478 3474
 
3479
-        /**    Define the current selected currency for the order summary    */
3475
+		/**    Call informtion for partial payment    */
3476
+		$partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3477
+		$tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3478
+
3479
+		/**    Define the current selected currency for the order summary    */
3480 3480
 //         $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3481
-        $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3482
-        return $output;
3483
-    }
3481
+		$output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3482
+		return $output;
3483
+	}
3484 3484
 
3485
-    /**
3486
-     * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3487
-     * @param string $ID ID product variations or not
3488
-     * @return string Return ID
3489
-     */
3490
-    public static function get_id_variation($ID)
3491
-    {
3492
-        $result = explode('__', $ID);
3493
-        return end($result);
3494
-    }
3485
+	/**
3486
+	 * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3487
+	 * @param string $ID ID product variations or not
3488
+	 * @return string Return ID
3489
+	 */
3490
+	public static function get_id_variation($ID)
3491
+	{
3492
+		$result = explode('__', $ID);
3493
+		return end($result);
3494
+	}
3495 3495
 
3496
-    /**
3497
-     * Update all variations definitions who not modified
3498
-     * @param array $new_value
3499
-     * @param array $old_value
3500
-     * @return array $new_value
3501
-     */
3502
-    public static function update_wpshop_catalog_product_option($new_value, $old_value)
3503
-    {
3504
-        global $wpdb;
3505
-        $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') . '%');
3506
-        foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3507
-            $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3508
-            $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3509
-            update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3510
-        }
3511
-        return $new_value;
3512
-    }
3496
+	/**
3497
+	 * Update all variations definitions who not modified
3498
+	 * @param array $new_value
3499
+	 * @param array $old_value
3500
+	 * @return array $new_value
3501
+	 */
3502
+	public static function update_wpshop_catalog_product_option($new_value, $old_value)
3503
+	{
3504
+		global $wpdb;
3505
+		$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') . '%');
3506
+		foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3507
+			$wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3508
+			$wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3509
+			update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3510
+		}
3511
+		return $new_value;
3512
+	}
3513 3513
 
3514
-    public static function variation_parameters_save($current_post_id, $options)
3515
-    {
3514
+	public static function variation_parameters_save($current_post_id, $options)
3515
+	{
3516 3516
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3517
-        $variation_post_meta['options'] = $options;
3517
+		$variation_post_meta['options'] = $options;
3518 3518
 		$variation_post_meta['follow_general_config'] = true;
3519 3519
 		if( $variation_post_meta['follow_general_config'] ) {
3520 3520
 			$shop_option = get_option('wpshop_catalog_product_option', array());
@@ -3530,6 +3530,6 @@  discard block
 block discarded – undo
3530 3530
 				}
3531 3531
 			}
3532 3532
 		}
3533
-        update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3534
-    }
3533
+		update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3534
+	}
3535 3535
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 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;
@@ -604,12 +604,12 @@  discard block
 block discarded – undo
604 604
 
605 605
         $products = array();
606 606
         $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
607
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
607
+        $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name));
608 608
 
609 609
         if (!empty($data)) {
610 610
             if ($data['data_type_to_use'] == 'custom') {
611 611
                 // Find which table to take
612
-                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;}
612
+                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; }
613 613
 
614 614
                 if (isset($table_name)) {
615 615
                     // If the value is an id of a select, radio or checkbox
@@ -759,11 +759,11 @@  discard block
 block discarded – undo
759 759
         if (!empty($atts['product_type'])) {
760 760
             switch ($atts['product_type']) {
761 761
                 case 'related':
762
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
762
+                    $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID();
763 763
                     $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
764 764
                     $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;
765 765
 
766
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
766
+                    $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
767 767
                     if (!empty($pids) && !empty($pids[0])) {
768 768
                         $pid = implode(',', $pids);
769 769
                     }
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
                     $sub_tpl_component = array();
833 833
                     $criteria = '';
834 834
                     foreach ($sorting_criteria as $c):
835
-                        $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
835
+                        $criteria .= '<option value="' . $c['code'] . '" ' . selected($atts['order'], $c['code'], false) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
836 836
                     endforeach;
837 837
                     $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
838 838
                     $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
             // --------------------- //
1002 1002
             // Pagination management //
1003 1003
             // --------------------- //
1004
-            if ( $display_pagination ) {
1004
+            if ($display_pagination) {
1005 1005
                 if ($nb_of_product_limit == 0) {
1006 1006
 
1007 1007
                     $paginate = paginate_links(array(
@@ -1282,7 +1282,7 @@  discard block
 block discarded – undo
1282 1282
     {
1283 1283
         global $wpdb;
1284 1284
 
1285
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1285
+        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST;
1286 1286
         // Apply a filter to extra actions
1287 1287
         $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1288 1288
 
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
                             $attributeValue = str_replace(',', '.', $attributeValue);
1339 1339
                         }
1340 1340
                         if (($attributeType == 'integer') && !is_array($attributeValue)) {
1341
-                            $attributeValue = (int) $attributeValue;
1341
+                            $attributeValue = (int)$attributeValue;
1342 1342
                         }
1343 1343
                         $productMetaDatas[$attributeCode] = $attributeValue;
1344 1344
                     }
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
                                     $attributeValue = str_replace(',', '.', $attribute->$value_key);
1389 1389
                                 }
1390 1390
                                 if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1391
-                                    $attributeValue = (int) $attribute->$value_key;
1391
+                                    $attributeValue = (int)$attribute->$value_key;
1392 1392
                                 }
1393 1393
                                 $variation_metadata[$attribute->code] = $attribute->$value_key;
1394 1394
                             }
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
                                 $attributeValue = str_replace(',', '.', $attributeValue);
1402 1402
                             }
1403 1403
                             if (($attributeType == 'integer') && !is_array($attributeValue)) {
1404
-                                $attributeValue = (int) $attributeValue;
1404
+                                $attributeValue = (int)$attributeValue;
1405 1405
                             }
1406 1406
                             $variation_metadata[$attributeCode] = $attributeValue;
1407 1407
                         }
@@ -1737,13 +1737,13 @@  discard block
 block discarded – undo
1737 1737
             if (!empty($product_price_infos)) {
1738 1738
                 $tpl_component_price = array();
1739 1739
                 /** Price piloting **/
1740
-				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1741
-				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1740
+				$price_display_option = get_option('wpshop_catalog_product_option');
1741
+				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : '';
1742 1742
                 $price_ploting = get_option('wpshop_shop_price_piloting');
1743 1743
                 $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'])) : '';
1744 1744
                 $variations = wpshop_products::get_variation($product_id);
1745 1745
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1746
-				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1746
+				if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) {
1747 1747
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1748 1748
 				}
1749 1749
                 $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
@@ -2186,7 +2186,7 @@  discard block
 block discarded – undo
2186 2186
             }
2187 2187
 
2188 2188
             $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2189
-						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2189
+						$template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id);
2190 2190
 
2191 2191
             $tpl_component = array();
2192 2192
             $tpl_component['PRODUCT_ID'] = $product_id;
@@ -3149,7 +3149,7 @@  discard block
 block discarded – undo
3149 3149
              * Since 1.4.3.7
3150 3150
              * L'option du produit remplace le prix du produit de tête.
3151 3151
              */
3152
-			if( true ) {
3152
+			if (true) {
3153 3153
                 //Replace the product price
3154 3154
                 if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3155 3155
                     $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
@@ -3516,16 +3516,16 @@  discard block
 block discarded – undo
3516 3516
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3517 3517
         $variation_post_meta['options'] = $options;
3518 3518
 		$variation_post_meta['follow_general_config'] = true;
3519
-		if( $variation_post_meta['follow_general_config'] ) {
3519
+		if ($variation_post_meta['follow_general_config']) {
3520 3520
 			$shop_option = get_option('wpshop_catalog_product_option', array());
3521
-			if( isset( $shop_option ) ) {
3521
+			if (isset($shop_option)) {
3522 3522
 				$variation_post_meta['options']['price_display'] = $shop_option['price_display'];
3523 3523
 			}
3524 3524
 		}
3525 3525
 		$variations = wpshop_attributes::get_variation_available_attribute($current_post_id);
3526
-		if( !empty( $variations['available'] ) ) {
3527
-			foreach( $variations['available'] as $key => $value ) {
3528
-				if( !in_array( $value['attribute_complete_def']->code, $variation_post_meta['attributes'] ) ) {
3526
+		if (!empty($variations['available'])) {
3527
+			foreach ($variations['available'] as $key => $value) {
3528
+				if (!in_array($value['attribute_complete_def']->code, $variation_post_meta['attributes'])) {
3529 3529
 					$variation_post_meta['attributes'][] = $value['attribute_complete_def']->code;
3530 3530
 				}
3531 3531
 			}
Please login to merge, or discard this patch.