Completed
Push — master ( d9c250...8cb6bf )
by
unknown
19:03
created
includes/modules/wps_cart/controller/wps_cart_ctr.php 1 patch
Spacing   +307 added lines, -307 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,129 +451,129 @@  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
-				$count_items += (int) $product_more_content['product_qty'];
464
+				$count_items += (int)$product_more_content['product_qty'];
465 465
 			}
466 466
 
467 467
 			$order_items[$pid]['product_id'] = $product_more_content['id'];
468 468
 			$order_items[$pid]['product_qty'] = $the_quantity;
469 469
 
470 470
 			/** For product with variation	*/
471
-			$order_items[$pid]['product_variation_type'] = !empty( $product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
471
+			$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
472 472
 			$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
473 473
 			$order_items[$pid]['product_variation'] = '';
474
-			if ( !empty($product_more_content['variations']) ) {
475
-				foreach ( $product_more_content['variations'] as $variation_id) {
474
+			if (!empty($product_more_content['variations'])) {
475
+				foreach ($product_more_content['variations'] as $variation_id) {
476 476
 					$order_items[$pid]['product_variation'][] = $variation_id;
477 477
 				}
478 478
 			}
479 479
 		}
480 480
 
481
-		$current_cart = ( !empty( $order_meta )) ? $order_meta : array();
481
+		$current_cart = (!empty($order_meta)) ? $order_meta : array();
482 482
 
483
-		$current_cart_order_items = isset( $current_cart['order_items'] ) ? $current_cart['order_items'] : array();
483
+		$current_cart_order_items = isset($current_cart['order_items']) ? $current_cart['order_items'] : array();
484 484
 
485
-		foreach( $current_cart_order_items as $item_id => $item ) {
486
-			if( !array_key_exists( $item_id, $order_items ) ) {
485
+		foreach ($current_cart_order_items as $item_id => $item) {
486
+			if (!array_key_exists($item_id, $order_items)) {
487 487
 				$count_items += $item['item_qty'];
488 488
 			}
489 489
 		}
490
-		$wpshop_cart_option = get_option( 'wpshop_cart_option' );
491
-		if( !empty( $wpshop_cart_option ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) && (int) $count_items > (int) $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) {
490
+		$wpshop_cart_option = get_option('wpshop_cart_option');
491
+		if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed']) && !empty($wpshop_cart_option['total_nb_of_item_allowed'][0]) && (int)$count_items > (int)$wpshop_cart_option['total_nb_of_item_allowed'][0]) {
492 492
 			return __('No more products can be added to your cart.', 'wpshop');
493 493
 		}
494 494
 
495
-		$order = $this->calcul_cart_information($order_items, $extra_params, $current_cart );
495
+		$order = $this->calcul_cart_information($order_items, $extra_params, $current_cart);
496 496
 
497
-		if( empty($from_admin) ) {
497
+		if (empty($from_admin)) {
498 498
 			self::store_cart_in_session($order);
499 499
 			/** Store the cart into database for connected user */
500
-			if ( get_current_user_id() ) {
500
+			if (get_current_user_id()) {
501 501
 				$this->persistent_cart_update();
502 502
 			}
503 503
 		}
504 504
 		else {
505
-			update_post_meta($order_id, '_order_postmeta', $order );
505
+			update_post_meta($order_id, '_order_postmeta', $order);
506 506
 
507 507
 		}
508 508
 		return 'success';
509 509
 	}
510 510
 
511
-	function prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected = array() ) {
511
+	function prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected = array()) {
512 512
 		$product_price = '';
513 513
 		$product_data = wpshop_products::get_product_data($product_id);
514 514
 
515 515
 		// Free vars
516
-		if ( !empty($wpshop_variation_selected['free']) ){
516
+		if (!empty($wpshop_variation_selected['free'])) {
517 517
 			$free_variations = $wpshop_variation_selected['free'];
518 518
 			unset($wpshop_variation_selected['free']);
519 519
 		}
520 520
 
521 521
 		// If product have many variations
522
-		if ( count($wpshop_variation_selected ) > 1 ) {
523
-			if ( !empty($wpshop_variation_selected) ) {
524
-				$product_with_variation = wpshop_products::get_variation_by_priority( $wpshop_variation_selected, $product_id, true );
522
+		if (count($wpshop_variation_selected) > 1) {
523
+			if (!empty($wpshop_variation_selected)) {
524
+				$product_with_variation = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true);
525 525
 			}
526 526
 
527
-			if ( !empty($product_with_variation[$product_id]['variations']) ) {
527
+			if (!empty($product_with_variation[$product_id]['variations'])) {
528 528
 				$product = $product_data;
529 529
 				$has_variation = true;
530 530
 				$head_product_id = $product_id;
531 531
 
532
-				if ( !empty($product_with_variation[$product_id]['variations']) && ( count($product_with_variation[$product_id]['variations']) == 1 ) && ($product_with_variation[$product_id]['variation_priority'] != 'single') ) {
532
+				if (!empty($product_with_variation[$product_id]['variations']) && (count($product_with_variation[$product_id]['variations']) == 1) && ($product_with_variation[$product_id]['variation_priority'] != 'single')) {
533 533
 					$product_id = $product_with_variation[$product_id]['variations'][0];
534 534
 				}
535 535
 				$product = wpshop_products::get_product_data($product_id, true);
536 536
 
537
-				$the_product = array_merge( array(
537
+				$the_product = array_merge(array(
538 538
 						'product_id'	=> $product_id,
539 539
 						'product_qty' 	=> $product_qty
540 540
 				), $product);
541 541
 
542 542
 				/*	Add variation to product into cart for storage	*/
543
-				if ( !empty($product_with_variation[$head_product_id]['variations']) ) {
544
-					$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']) );
543
+				if (!empty($product_with_variation[$head_product_id]['variations'])) {
544
+					$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']));
545 545
 				}
546 546
 
547 547
 				$product_data = $the_product;
548 548
 			}
549 549
 		}
550 550
 
551
-		$product_to_add_to_cart = array( $product_id => array( 'id' => $product_id, 'product_qty' => $product_qty ) );
551
+		$product_to_add_to_cart = array($product_id => array('id' => $product_id, 'product_qty' => $product_qty));
552 552
 
553
-		if ( !empty( $wpshop_variation_selected ) ) {
554
-			$variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true );
555
-			if ( !empty($variation_calculator[$product_id]) ) {
553
+		if (!empty($wpshop_variation_selected)) {
554
+			$variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true);
555
+			if (!empty($variation_calculator[$product_id])) {
556 556
 				$product_to_add_to_cart[$product_id] = array_merge($product_to_add_to_cart[$product_id], $variation_calculator[$product_id]);
557 557
 			}
558 558
 		}
559 559
 
560 560
 		$new_pid = $product_id;
561 561
 		//Create custom ID on single variations Product
562
-		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' ) {
562
+		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') {
563 563
 			$tmp_obj = $product_to_add_to_cart[$product_id];
564
-			unset( $product_to_add_to_cart[$product_id] );
564
+			unset($product_to_add_to_cart[$product_id]);
565 565
 			$key = $product_id;
566
-			foreach( $tmp_obj['variations'] as $variation_key) {
567
-				$key.= '__'. $variation_key;
566
+			foreach ($tmp_obj['variations'] as $variation_key) {
567
+				$key .= '__' . $variation_key;
568 568
 			}
569 569
 			$product_to_add_to_cart[$key] = $tmp_obj;
570 570
 			$new_pid = $key;
571 571
 		}
572 572
 		// Add free variations
573
-		if( !empty($free_variations) ) {
573
+		if (!empty($free_variations)) {
574 574
 			$product_to_add_to_cart[$new_pid]['free_variation'] = $free_variations;
575 575
 		}
576
-		return array( $product_to_add_to_cart, $new_pid );
576
+		return array($product_to_add_to_cart, $new_pid);
577 577
 	}
578 578
 
579 579
 	/**
@@ -584,67 +584,67 @@  discard block
 block discarded – undo
584 584
 	 * @param boolean $from_admin
585 585
 	 * @return array
586 586
 	 */
587
-	function calcul_cart_information( $product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false ) {
587
+	function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) {
588 588
 		// Price piloting option
589
-		$price_piloting = get_option( 'wpshop_shop_price_piloting' );
589
+		$price_piloting = get_option('wpshop_shop_price_piloting');
590 590
 
591 591
 		// Init vars
592
-		$cart_infos = ( !empty($current_cart) ) ? $current_cart : ( ( !empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ) ? $_SESSION['cart'] : array() );
593
-		$cart_items = ( !empty($current_cart) && !empty($current_cart['order_items']) ) ? $current_cart['order_items'] : array();
594
-		$cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ) ? $_SESSION['cart']['order_items'] : $cart_items;
592
+		$cart_infos = (!empty($current_cart)) ? $current_cart : ((!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin) ? $_SESSION['cart'] : array());
593
+		$cart_items = (!empty($current_cart) && !empty($current_cart['order_items'])) ? $current_cart['order_items'] : array();
594
+		$cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin) ? $_SESSION['cart']['order_items'] : $cart_items;
595 595
 		$order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array();
596 596
 		$total_weight = $nb_of_items = $order_shipping_cost_by_article = 0;
597 597
 		$order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0;
598 598
 		$cart_infos['order_amount_to_pay_now'] = 0;
599 599
 
600 600
 		// If Product list is not empty, add products to order
601
-		if( !empty($product_list) ) {
602
-			foreach ( $product_list as $product_id => $d ) {
601
+		if (!empty($product_list)) {
602
+			foreach ($product_list as $product_id => $d) {
603 603
 				$product_key = $product_id;
604
-				if( isset( $d['product_qty']) ) {
604
+				if (isset($d['product_qty'])) {
605 605
 					// Formate datas
606 606
 					$product_id = $head_product_id = $d['product_id'];
607 607
 					$product_qty = $d['product_qty'];
608 608
 					$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
609 609
 
610 610
 					// If product is a single variation product
611
-					if ( !empty($product_variation) && ( count($product_variation) == 1 ) ) {
611
+					if (!empty($product_variation) && (count($product_variation) == 1)) {
612 612
 						$product_id = $product_variation[0];
613 613
 					}
614 614
 
615 615
 					// Construct final product
616 616
 					$product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"');
617
-					$the_product = array_merge( array('product_id'	=> $d['product_id'], 'product_qty' 	=> $product_qty ), $product);
617
+					$the_product = array_merge(array('product_id'	=> $d['product_id'], 'product_qty' 	=> $product_qty), $product);
618 618
 
619 619
 					//	Add variation to product into cart for storage
620
-					if ( !empty($product_variation) ) {
621
-						$the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']) );
620
+					if (!empty($product_variation)) {
621
+						$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
622 622
 					}
623 623
 
624 624
 					// Free Variations Checking
625
-					if ( !empty( $d['free_variation'] ) ) {
625
+					if (!empty($d['free_variation'])) {
626 626
 						$the_product['item_meta']['free_variation'] = $d['free_variation'];
627 627
 						$head_product_id = $the_product['product_id'];
628 628
 					}
629 629
 
630 630
 					// If product is a variation, we check parent product general
631
-					if( get_post_type( $the_product['product_id'] )  == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
632
-						$parent_def = wpshop_products::get_parent_variation( $the_product['product_id'] );
633
-						if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
634
-							$variation_def = get_post_meta( $parent_def['parent_post']->ID, '_wpshop_variation_defining', true );
631
+					if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
632
+						$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
633
+						if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
634
+							$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
635 635
 							$parent_meta = $parent_def['parent_post_meta'];
636
-							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 ) {
637
-								$the_product['product_price'] += number_format( str_replace( ',', '.', $parent_meta['product_price'] ), 2, '.', '' );
638
-								$the_product['price_ht'] += number_format( str_replace( ',', '.',$parent_meta['price_ht']) , 2, '.', '' );
639
-								$the_product['tva'] += number_format( str_replace( ',', '.', $parent_meta['tva']) , 2, '.', '' );
636
+							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) {
637
+								$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
638
+								$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
639
+								$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
640 640
 							}
641 641
 						}
642 642
 					}
643 643
 
644 644
 					// Delete product if its qty is equals to zero, else add this product to order
645
-					if( empty( $d['product_qty'] ) ) {
646
-						unset( $cart_items[$product_key] );
647
-						unset( $cart_infos['order_items'][$product_key] );
645
+					if (empty($d['product_qty'])) {
646
+						unset($cart_items[$product_key]);
647
+						unset($cart_infos['order_items'][$product_key]);
648 648
 					}
649 649
 					else {
650 650
 						$wps_orders = new wps_orders_ctr();
@@ -655,16 +655,16 @@  discard block
 block discarded – undo
655 655
 		}
656 656
 
657 657
 		// Add automaticaly Add-to-cart Products
658
-		$cart_items = $this->add_automaticaly_product_to_cart( $cart_items );
658
+		$cart_items = $this->add_automaticaly_product_to_cart($cart_items);
659 659
 
660 660
 		// Calcul Cart Informations
661 661
 		$cart_has_special_product = false;
662
-		if( !empty($cart_items) && is_array($cart_items) ) {
663
-			foreach( $cart_items as $item_id => $item ) {
662
+		if (!empty($cart_items) && is_array($cart_items)) {
663
+			foreach ($cart_items as $item_id => $item) {
664 664
 
665
-				if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) {
665
+				if (!empty($item['item_amount_to_pay_now'])) {
666 666
 					$cart_has_special_product = true;
667
-					$cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] );
667
+					$cart_infos['order_amount_to_pay_now'] += ($item['item_amount_to_pay_now'] * $item['item_qty']);
668 668
 				}
669 669
 				else {
670 670
 					$cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc'];
@@ -673,11 +673,11 @@  discard block
 block discarded – undo
673 673
 				$order_total_ht += $item['item_total_ht'];
674 674
 				$order_total_ttc += $item['item_total_ttc'];
675 675
 				// VAT
676
-				if( !empty($order_tva[ $item['item_tva_rate'] ]) ) {
677
-					$order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount'];
676
+				if (!empty($order_tva[$item['item_tva_rate']])) {
677
+					$order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount'];
678 678
 				}
679 679
 				else {
680
-					$order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount'];
680
+					$order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount'];
681 681
 				}
682 682
 			}
683 683
 		}
@@ -691,13 +691,13 @@  discard block
 block discarded – undo
691 691
 		$cart_infos['order_total_ttc'] = $order_total_ttc;
692 692
 
693 693
 		// Calcul Shipping cost
694
-		if( !$from_admin && empty( $cart_infos['order_shipping_cost_fixe'] ) && empty($_SESSION[ 'wps-pos-addon' ]) ) {
694
+		if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe']) && empty($_SESSION['wps-pos-addon'])) {
695 695
 			$wps_shipping = new wps_shipping();
696
-			$total_cart_ht_or_ttc_regarding_config = ( !empty($price_piloting) && $price_piloting == 'HT' ) ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc'];
697
-			$cart_weight = $wps_shipping->calcul_cart_weight( $cart_infos['order_items'] );
698
-			$total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost( $cart_infos['order_items'] );
699
-			foreach( $cart_infos['order_items'] as $item ) {
700
-				if( !empty($item['item_is_downloadable_']) && ( __( $item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) {
696
+			$total_cart_ht_or_ttc_regarding_config = (!empty($price_piloting) && $price_piloting == 'HT') ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc'];
697
+			$cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']);
698
+			$total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']);
699
+			foreach ($cart_infos['order_items'] as $item) {
700
+				if (!empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) {
701 701
 					$is_downloadable_products = 'is_downloadable_';
702 702
 				} else {
703 703
 					$is_downloadable_products = '';
@@ -709,39 +709,39 @@  discard block
 block discarded – undo
709 709
 		}
710 710
 
711 711
 		// If Price piloting is ET, calcul VAT on Shipping cost
712
-		if ( !empty($price_piloting) && $price_piloting == 'HT') {
713
-			$shipping_cost_vat = ( !empty($cart_infos['order_shipping_cost']) ) ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * number_format(  $cart_infos['order_shipping_cost'], 2, '.', '') : 0;
712
+		if (!empty($price_piloting) && $price_piloting == 'HT') {
713
+			$shipping_cost_vat = (!empty($cart_infos['order_shipping_cost'])) ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0;
714 714
 			$order_tva['VAT_shipping_cost'] = $shipping_cost_vat;
715 715
 		}
716 716
 
717 717
 		// Calcul VAT Total
718
-		if( !empty($order_tva) ) {
719
-			foreach( $order_tva as $vat_rate => $vat_value ) {
718
+		if (!empty($order_tva)) {
719
+			foreach ($order_tva as $vat_rate => $vat_value) {
720 720
 				$total_vat += $vat_value;
721 721
 			}
722 722
 		}
723 723
 
724 724
 		// Recap totals
725
-		$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 );
725
+		$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);
726 726
 		$cart_infos['order_grand_total_before_discount'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc'];
727 727
 
728 728
 		// Total to pay now
729 729
 		$total_received = 0;
730
-		if( !empty( $cart_infos['order_payment']['received'] ) ) {
731
-			foreach( $cart_infos['order_payment']['received'] as $received ) {
732
-				$total_received += ( ( !empty($received['status']) && ( $received['status'] == 'payment_received') && !empty($received['received_amount']) ) ? $received['received_amount'] : 0 );
730
+		if (!empty($cart_infos['order_payment']['received'])) {
731
+			foreach ($cart_infos['order_payment']['received'] as $received) {
732
+				$total_received += ((!empty($received['status']) && ($received['status'] == 'payment_received') && !empty($received['received_amount'])) ? $received['received_amount'] : 0);
733 733
 			}
734 734
 		}
735 735
 		$cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] - $total_received;
736 736
 
737 737
 		// Apply cart rules
738
-		$cart_rule = wpshop_cart_rules::get_cart_rule( $cart_infos['order_grand_total'] );
739
-		if( $cart_rule['cart_rule_exist'] ) {
740
-			if ( !empty( $cart_rule['cart_rule_info']['discount_type'] ) ) {
741
-				if ( $cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount' ) {
738
+		$cart_rule = wpshop_cart_rules::get_cart_rule($cart_infos['order_grand_total']);
739
+		if ($cart_rule['cart_rule_exist']) {
740
+			if (!empty($cart_rule['cart_rule_info']['discount_type'])) {
741
+				if ($cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount') {
742 742
 					$cart_infos['order_discount_type'] = 'amount';
743 743
 				}
744
-				if ( $cart_rule['cart_rule_info']['discount_type'] == 'percent_discount' ) {
744
+				if ($cart_rule['cart_rule_info']['discount_type'] == 'percent_discount') {
745 745
 					$cart_infos['order_discount_type'] = 'percent';
746 746
 				}
747 747
 			}
@@ -749,15 +749,15 @@  discard block
 block discarded – undo
749 749
 		}
750 750
 
751 751
 		// Apply coupons
752
-		if( !empty( $_SESSION['cart']) && !$from_admin ) {
753
-			if( !empty($_SESSION['cart']['coupon_id']) ) {
752
+		if (!empty($_SESSION['cart']) && !$from_admin) {
753
+			if (!empty($_SESSION['cart']['coupon_id'])) {
754 754
 				$wps_coupon_mdl = new wps_coupon_model();
755
-				$coupon = $wps_coupon_mdl->get_coupon_data( $_SESSION['cart']['coupon_id'] );
756
-				if( !empty($coupon) && !empty($coupon['wpshop_coupon_code']) ) {
755
+				$coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']);
756
+				if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) {
757 757
 					$wps_coupon = new wps_coupon_ctr();
758
-					$coupon_checking = $wps_coupon->applyCoupon( $coupon['wpshop_coupon_code'] );
758
+					$coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']);
759 759
 					// If Coupon conditions are Ok
760
-					if( !empty($coupon_checking) && !empty( $coupon_checking['status'] ) && ( true == $coupon_checking['status'] ) ) {
760
+					if (!empty($coupon_checking) && !empty($coupon_checking['status']) && (true == $coupon_checking['status'])) {
761 761
 						$cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type'];
762 762
 						$cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value'];
763 763
 					}
@@ -766,51 +766,51 @@  discard block
 block discarded – undo
766 766
 		}
767 767
 
768 768
 		// Checking Discounts
769
-		if( !empty($cart_infos['order_discount_type']) && isset( $cart_infos['order_discount_value'] ) ) {
769
+		if (!empty($cart_infos['order_discount_type']) && isset($cart_infos['order_discount_value'])) {
770 770
 			// Calcul discount on Order
771 771
 			switch ($cart_infos['order_discount_type']) {
772 772
 				case 'amount':
773
-					$cart_infos['order_discount_amount_total_cart'] = number_format( str_replace( ',', '.', $cart_infos['order_discount_value'] ), 2, '.', '');
773
+					$cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '');
774 774
 				break;
775 775
 				case 'percent':
776
-					$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);
776
+					$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);
777 777
 				break;
778 778
 			}
779
-			if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) {
779
+			if (number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format($cart_infos['order_grand_total'], 2, '.', '')) {
780 780
 				$cart_infos['order_grand_total'] = 0;
781 781
 			}
782 782
 			else {
783
-				$cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '');
783
+				$cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '');
784 784
 			}
785
-			$cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', '');
785
+			$cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'] - $total_received, 2, '.', '');
786 786
 		}
787 787
 
788 788
 		// Apply Partial Payments
789 789
 		$wpshop_payment = new wpshop_payment();
790
-		if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) {
791
-			$partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' );
790
+		if (!empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation') {
791
+			$partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total'], 'for_quotation');
792 792
 		}
793 793
 		else {
794
-			$partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] );
794
+			$partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']);
795 795
 		}
796
-		if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) {
796
+		if (!empty($partial_payment['amount_to_pay']) && (empty($cart_infos['order_status']) || $cart_infos['order_status'] == 'awaiting_payment') && (empty($product_partial_payment_amount))) {
797 797
 			unset($partial_payment['display']);
798
-			$cart_infos['order_partial_payment'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', '');
799
-			$cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', '');
798
+			$cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', '');
799
+			$cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', '');
800 800
 		}
801 801
 		// Apply Partial Payments : Subscription part.
802
-		elseif ( ! empty( $cart_has_special_product ) ) {
803
-			$cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $cart_infos['order_amount_to_pay_now'] ), 2, '.', '');
802
+		elseif (!empty($cart_has_special_product)) {
803
+			$cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $cart_infos['order_amount_to_pay_now']), 2, '.', '');
804 804
 			$cart_infos['order_product_partial_payment'] = 'subscription';
805 805
 		}
806 806
 
807 807
 		// Cart Type
808
-		if ( isset( $_SESSION['cart']['cart_type'] ) ) {
808
+		if (isset($_SESSION['cart']['cart_type'])) {
809 809
 			$cart_infos['cart_type'] = $_SESSION['cart']['cart_type'];
810 810
 		}
811 811
 
812 812
 		// Apply Extra actions on cart infos
813
-		$cart_infos = apply_filters( 'wps_extra_calcul_in_cart', $cart_infos, $_SESSION );
813
+		$cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION);
814 814
 
815 815
 		return $cart_infos;
816 816
 	}
@@ -820,18 +820,18 @@  discard block
 block discarded – undo
820 820
 	 * @param array $cart_items
821 821
 	 * @return array
822 822
 	 */
823
-	function add_automaticaly_product_to_cart( $cart_items ) {
823
+	function add_automaticaly_product_to_cart($cart_items) {
824 824
 		global $wpdb;
825 825
 		// Recovery all products with options
826 826
 		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
827 827
 		$post_list_with_options = $wpdb->get_results($query);
828 828
 		$wps_orders = new wps_orders_ctr();
829
-		if ( !empty($post_list_with_options) && !empty($cart_items) ) {
830
-			foreach ( $post_list_with_options as $product_info) {
829
+		if (!empty($post_list_with_options) && !empty($cart_items)) {
830
+			foreach ($post_list_with_options as $product_info) {
831 831
 				$product_meta = unserialize($product_info->meta_value);
832
-				if ( !empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id]) ) {
832
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id])) {
833 833
 					$product = wpshop_products::get_product_data($product_info->post_id, true, '"draft", "publish"');
834
-					$the_product = array_merge( array(
834
+					$the_product = array_merge(array(
835 835
 							'product_id'	=> $product_info->post_id,
836 836
 							'product_qty' 	=> 1
837 837
 					), $product);
@@ -845,28 +845,28 @@  discard block
 block discarded – undo
845 845
 
846 846
 	/** Ajax action to reload cart **/
847 847
 	public static function wps_reload_cart() {
848
-		check_ajax_referer( 'wps_reload_cart' );
848
+		check_ajax_referer('wps_reload_cart');
849 849
 
850 850
 		$wps_cart = new wps_cart();
851 851
 		$result = $wps_cart->cart_content();
852 852
 
853
-		wp_die( json_encode( array( 'response' => $result) ) );
853
+		wp_die(json_encode(array('response' => $result)));
854 854
 	}
855 855
 
856 856
 
857 857
 	/** Ajax action to reload mini cart */
858 858
 	public function wps_reload_mini_cart() {
859
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
859
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
860 860
 
861
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) )
861
+		if (!wp_verify_nonce($_wpnonce, 'wps_reload_mini_cart'))
862 862
 			wp_die();
863 863
 
864 864
 		$wps_cart = new wps_cart();
865
-		$result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) );
866
-		$count_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])  ) ? $wps_cart->total_cart_items( $_SESSION['cart']['order_items'] ) : 0;
865
+		$result = $wps_cart->mini_cart_content(sanitize_title($_POST['type']));
866
+		$count_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0;
867 867
 		$free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert');
868 868
 
869
-		echo json_encode( array( 'response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert) );
869
+		echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert));
870 870
 		die();
871 871
 	}
872 872
 
@@ -876,35 +876,35 @@  discard block
 block discarded – undo
876 876
 	 * @return string
877 877
 	 */
878 878
 	function display_wps_numeration_cart() {
879
-		$cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $_SESSION['cart']['order_items'] : array();
880
-		$total_cart_item = self::total_cart_items( $cart_items );
879
+		$cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $_SESSION['cart']['order_items'] : array();
880
+		$total_cart_item = self::total_cart_items($cart_items);
881 881
 
882 882
 		ob_start();
883
-		require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart") );
883
+		require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart"));
884 884
 		$output = ob_get_contents();
885 885
 		ob_end_clean();
886 886
 		return $output;
887 887
 	}
888 888
 
889
-	public function display_button_add_to_cart( $args ) {
890
-		$button_text = __( 'Add to cart', 'wpshop' );
889
+	public function display_button_add_to_cart($args) {
890
+		$button_text = __('Add to cart', 'wpshop');
891 891
 		$use_button = true;
892
-		$output = __( 'No product has been found.', 'wpshop' );
892
+		$output = __('No product has been found.', 'wpshop');
893 893
 
894
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
894
+		if (!empty($args) && !empty($args['pid'])) {
895 895
 
896 896
 			/** The user send the text in argument */
897
-			if ( !empty( $args['text' ] ) ) {
897
+			if (!empty($args['text'])) {
898 898
 				$button_text = $args['text'];
899 899
 			}
900 900
 
901 901
 			/** The user send use input */
902
-			if ( !empty( $args['use_button'] ) && 'false' == $args['use_button'] ) {
902
+			if (!empty($args['use_button']) && 'false' == $args['use_button']) {
903 903
 				$use_button = false;
904 904
 			}
905 905
 
906 906
 			ob_start();
907
-			require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart' ) );
907
+			require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart'));
908 908
 			$output = ob_get_clean();
909 909
 		}
910 910
 
@@ -913,21 +913,21 @@  discard block
 block discarded – undo
913 913
 
914 914
 	/** Ajax action to reload summary cart */
915 915
 	public static function wps_reload_summary_cart() {
916
-		check_ajax_referer( 'wps_reload_summary_cart' );
916
+		check_ajax_referer('wps_reload_summary_cart');
917 917
 
918 918
 		$wps_cart = new wps_cart();
919 919
 		$result = $wps_cart->resume_cart_content();
920 920
 
921
-		wp_die( json_encode( array( 'response' => $result, ) ) );
921
+		wp_die(json_encode(array('response' => $result,)));
922 922
 	}
923 923
 
924 924
 
925 925
 	/** Display Apply Coupon Interface **/
926 926
 	function display_apply_coupon_interface() {
927 927
 		$output = '';
928
-		if ( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) {
928
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
929 929
 			ob_start();
930
-			require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon") );
930
+			require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon"));
931 931
 			$output = ob_get_contents();
932 932
 			ob_end_clean();
933 933
 		}
@@ -937,30 +937,30 @@  discard block
 block discarded – undo
937 937
 
938 938
 	/** AJAX - action to apply coupon **/
939 939
 	function wps_apply_coupon() {
940
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
940
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
941 941
 
942
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) )
942
+		if (!wp_verify_nonce($_wpnonce, 'wps_apply_coupon'))
943 943
 			wp_die();
944 944
 
945 945
 		$status = false; $response = '';
946
-		$coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null;
947
-		if( !empty($coupon) ) {
946
+		$coupon = (!empty($_POST['coupon_code'])) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null;
947
+		if (!empty($coupon)) {
948 948
 			$wps_coupon_ctr = new wps_coupon_ctr();
949 949
 			$result = $wps_coupon_ctr->applyCoupon($coupon);
950
-			if ($result['status']===true) {
950
+			if ($result['status'] === true) {
951 951
 				$order = $this->calcul_cart_information(array());
952 952
 				$this->store_cart_in_session($order);
953 953
 				$status = true;
954
-				$response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>';
954
+				$response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>';
955 955
 			}
956 956
 			else {
957
-				$response = '<div class="wps-alert-error">' .$result['message']. '</div>';
957
+				$response = '<div class="wps-alert-error">' . $result['message'] . '</div>';
958 958
 			}
959 959
 		}
960 960
 		else {
961
-			$response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>';
961
+			$response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>';
962 962
 		}
963
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
963
+		echo json_encode(array('status' => $status, 'response' => $response));
964 964
 		die();
965 965
 	}
966 966
 
@@ -969,24 +969,24 @@  discard block
 block discarded – undo
969 969
 	 * AJAX - Pass to step two in the Checkout tunnel
970 970
 	 */
971 971
 	public static function wps_cart_pass_to_step_two() {
972
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
972
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
973 973
 
974
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) )
974
+		if (!wp_verify_nonce($_wpnonce, 'wps_cart_pass_to_step_two'))
975 975
 			wp_die();
976 976
 
977 977
 		$status = false; $response = '';
978
-		$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) );
979
-		if( !empty($checkout_page_id) ) {
980
-			$permalink_option = get_option( 'permalink_structure' );
981
-			$step = ( get_current_user_id() != 0 ) ?  3 : 2;
982
-			$response = get_permalink( $checkout_page_id  ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step;
978
+		$checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'));
979
+		if (!empty($checkout_page_id)) {
980
+			$permalink_option = get_option('permalink_structure');
981
+			$step = (get_current_user_id() != 0) ? 3 : 2;
982
+			$response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step;
983 983
 			$response = apply_filters('wps_extra_signup_actions', $response);
984 984
 			$status = true;
985 985
 		}
986 986
 		else {
987
-			$response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>';
987
+			$response = '<div class="wps-alert-error">' . __('An error was occured, please retry later or contact the website administrator', 'wpshop') . '</div>';
988 988
 		}
989
-		echo json_encode( array( 'status' => $status, 'response' => $response));
989
+		echo json_encode(array('status' => $status, 'response' => $response));
990 990
 		die();
991 991
 	}
992 992
 
@@ -995,14 +995,14 @@  discard block
 block discarded – undo
995 995
 	 * AJAX - Empty the cart
996 996
 	 */
997 997
 	function wps_empty_cart() {
998
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
998
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
999 999
 
1000
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) )
1000
+		if (!wp_verify_nonce($_wpnonce, 'wps_empty_cart'))
1001 1001
 			wp_die();
1002 1002
 
1003 1003
 
1004 1004
 		$this->empty_cart();
1005
-		echo json_encode( array( 'status' => true) );
1005
+		echo json_encode(array('status' => true));
1006 1006
 		die();
1007 1007
 	}
1008 1008
 }
Please login to merge, or discard this patch.