Completed
Push — master ( 34f707...e944e6 )
by
unknown
18:43
created
includes/modules/wps_orders/controller/wps_orders_ctr.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'ABSPATH' ) ) { exit;
1
+<?php if (!defined('ABSPATH')) { exit;
2 2
 }
3 3
 class wps_orders_ctr {
4 4
 
@@ -20,24 +20,24 @@  discard block
 block discarded – undo
20 20
 
21 21
 		/** Template Load */
22 22
 		// add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) );
23
-		add_shortcode( 'order_customer_informations', array( &$this, 'display_order_customer_informations' ) );
24
-		add_shortcode( 'wps_orders_in_customer_account', array( $this, 'display_orders_in_account' ) );
25
-		add_action( 'wp_enqueue_scripts', array( $this, 'wps_orders_scripts' ) );
23
+		add_shortcode('order_customer_informations', array(&$this, 'display_order_customer_informations'));
24
+		add_shortcode('wps_orders_in_customer_account', array($this, 'display_orders_in_account'));
25
+		add_action('wp_enqueue_scripts', array($this, 'wps_orders_scripts'));
26 26
 		/**	Include the different javascript	*/
27
-		add_action( 'admin_init', array( &$this, 'admin_js' ) );
27
+		add_action('admin_init', array(&$this, 'admin_js'));
28 28
 
29 29
 		/** Ajax Actions */
30 30
 		// add_action( 'wp_ajax_wps_add_product_to_quotation', array( &$this, 'wps_add_product_to_quotation') );
31 31
 		// add_action( 'wap_ajax_wps_change_product_list', array( &$this, 'wps_change_product_list') );
32 32
 		// add_action( 'wap_ajax_wps_orders_load_variations_container', array( &$this, 'wps_orders_load_variations_container') );
33 33
 		// add_action( 'wap_ajax_wps_order_refresh_in_admin', array( &$this, 'wps_order_refresh_in_admin') );
34
-		add_action( 'wp_ajax_wps_orders_load_details', array( $this, 'wps_orders_load_details' ) );
34
+		add_action('wp_ajax_wps_orders_load_details', array($this, 'wps_orders_load_details'));
35 35
 		// Add a product sale historic in administration product panel
36
-		add_action( 'wp_ajax_wps_order_choose_customer', array( $this, 'wps_order_choose_customer' ) );
36
+		add_action('wp_ajax_wps_order_choose_customer', array($this, 'wps_order_choose_customer'));
37 37
 		/** For delete order */
38
-		add_action( 'wp_ajax_wps_delete_order', array( $this, 'wps_delete_order' ) );
38
+		add_action('wp_ajax_wps_delete_order', array($this, 'wps_delete_order'));
39 39
 		/** Invoice Page */
40
-		add_action( 'admin_post_wps_invoice', array( $this, 'wps_invoice_output' ) );
40
+		add_action('admin_post_wps_invoice', array($this, 'wps_invoice_output'));
41 41
 	}
42 42
 
43 43
 		/**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		 */
55 55
 	function wps_orders_scripts() {
56 56
 
57
-		wp_enqueue_script( 'wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js' );
57
+		wp_enqueue_script('wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js');
58 58
 	}
59 59
 
60 60
 	function display_order_customer_informations() {
@@ -62,23 +62,23 @@  discard block
 block discarded – undo
62 62
 		global $post_id;
63 63
 		global $wpdb;
64 64
 		$output = '';
65
-		if ( ! empty( $post_id ) ) {
66
-			$order_postmeta = get_post_meta( $post_id, '_order_postmeta', true );
67
-			$order_info = get_post_meta( $post_id, '_order_info', true );
65
+		if (!empty($post_id)) {
66
+			$order_postmeta = get_post_meta($post_id, '_order_postmeta', true);
67
+			$order_info = get_post_meta($post_id, '_order_info', true);
68 68
 			/** Check the order status */
69
-			if ( ! empty( $order_postmeta ) ) {
70
-				if ( ! empty( $order_postmeta['order_status'] )  && $order_postmeta['order_status'] != 'awaiting_payment' ) {
71
-					$output = wps_address::display_an_address( $order_info['billing']['address'] );
72
-					$output .= wps_address::display_an_address( $order_info['shipping']['address'] );
69
+			if (!empty($order_postmeta)) {
70
+				if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] != 'awaiting_payment') {
71
+					$output = wps_address::display_an_address($order_info['billing']['address']);
72
+					$output .= wps_address::display_an_address($order_info['shipping']['address']);
73 73
 				} else {
74
-					$output = wps_address::display_an_address( $order_info['billing']['address'] );
74
+					$output = wps_address::display_an_address($order_info['billing']['address']);
75 75
 				}
76 76
 			}
77 77
 		} else {
78 78
 			/** Display  "Choose customer or create one" Interface */
79 79
 			$tpl_component = array();
80 80
 			$args = array(
81
-			'show_option_all' => __( 'Choose a customer', 'wpshop' ),
81
+			'show_option_all' => __('Choose a customer', 'wpshop'),
82 82
 			'orderby' => 'display_name',
83 83
 			'order' => 'ASC',
84 84
 			'include' => null, // string
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 						'id' => null, // integer
93 93
 						'class' => 'chosen_select', // string
94 94
 						'blog_id' => $GLOBALS['blog_id'],
95
-			'who' => null,// string
95
+			'who' => null, // string
96 96
 			);
97
-			$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users( $args );
98
-			$output = wpshop_display::display_template_element( 'wps_orders_choose_customer_interface', $tpl_component, array(), 'admin' );
97
+			$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users($args);
98
+			$output = wpshop_display::display_template_element('wps_orders_choose_customer_interface', $tpl_component, array(), 'admin');
99 99
 		}
100 100
 		return $output;
101 101
 	}
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
 		 * @param integer $customer_id
107 107
 		 * @return string
108 108
 		 */
109
-	function display_orders_in_account( $customer_id = '' ) {
109
+	function display_orders_in_account($customer_id = '') {
110 110
 
111 111
 		$output = '';
112
-		$customer_id = ( ! empty( $customer_id ) ) ? $customer_id : get_current_user_id();
113
-		$from_admin = ( ! empty( $customer_id ) ) ? true : false;
112
+		$customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id();
113
+		$from_admin = (!empty($customer_id)) ? true : false;
114 114
 		$wps_orders_mdl = new wps_orders_mdl();
115
-		$orders = $wps_orders_mdl->get_customer_orders( $customer_id );
115
+		$orders = $wps_orders_mdl->get_customer_orders($customer_id);
116 116
 		// Display orders
117 117
 		ob_start();
118
-		require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'orders_list_in_account' ) );
118
+		require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'orders_list_in_account'));
119 119
 		$output = ob_get_contents();
120 120
 		ob_end_clean();
121 121
 		return $output;
@@ -128,41 +128,41 @@  discard block
 block discarded – undo
128 128
 		 *
129 129
 		 *	@return array $item_list The item to add to order
130 130
 		 */
131
-	function add_product_to_order( $product ) {
131
+	function add_product_to_order($product) {
132 132
 
133 133
 		global $wpdb;
134
-		if ( ! empty( $product ) && empty( $product['price_ttc_before_discount'] ) && empty( $product['price_ht_before_discount'] ) ) {
135
-			$price_infos = wpshop_prices::check_product_price( $product, true );
136
-			$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'];
137
-			$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'];
138
-			$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'];
134
+		if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) {
135
+			$price_infos = wpshop_prices::check_product_price($product, true);
136
+			$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'];
137
+			$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'];
138
+			$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'];
139 139
 		}
140 140
 
141
-		$price_piloting = get_option( 'wpshop_shop_price_piloting' );
142
-		if ( ! empty( $price_piloting ) && $price_piloting == 'HT' ) {
141
+		$price_piloting = get_option('wpshop_shop_price_piloting');
142
+		if (!empty($price_piloting) && $price_piloting == 'HT') {
143 143
 			$total_ht = $product['price_ht'] * $product['product_qty'];
144
-			$tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 );
144
+			$tva_total_amount = $total_ht * ($product['tx_tva'] / 100);
145 145
 			$total_ttc = $total_ht + $tva_total_amount;
146 146
 		} else {
147 147
 			$total_ttc = $product['product_price'] * $product['product_qty'];
148
-			$total_ht  = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) );
148
+			$total_ht  = $total_ttc / (1 + ($product['tx_tva'] / 100));
149 149
 			$tva_total_amount = $total_ttc - $total_ht;
150 150
 		}
151 151
 
152
-		$tva = ! empty( $product[ WPSHOP_PRODUCT_PRICE_TAX ] ) ? $product[ WPSHOP_PRODUCT_PRICE_TAX ] : null;
152
+		$tva = !empty($product[WPSHOP_PRODUCT_PRICE_TAX]) ? $product[WPSHOP_PRODUCT_PRICE_TAX] : null;
153 153
 		$item_discount_type = $item_discount_value = $item_discount_amount = 0;
154
-		$d_amount = ! empty( $product ) && ! empty( $product['discount_amount'] ) ? wpshop_tools::formate_number( $product['discount_amount'] ) : null;
155
-		$d_rate = ! empty( $product ) && ! empty( $product['discount_rate'] ) ? wpshop_tools::formate_number( $product['discount_rate'] ) : null;
156
-		$d_special = ! empty( $product ) && ! empty( $product['special_price'] ) ? wpshop_tools::formate_number( $product['special_price'] ) : null;
157
-		if ( ! empty( $d_amount ) ) {
154
+		$d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null;
155
+		$d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null;
156
+		$d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null;
157
+		if (!empty($d_amount)) {
158 158
 			$item_discount_type = 'discount_amount';
159 159
 			$item_discount_amount = $product['discount_amount'];
160 160
 			$item_discount_value = $product['discount_amount'];
161
-		} elseif ( ! empty( $d_rate ) ) {
161
+		} elseif (!empty($d_rate)) {
162 162
 			$item_discount_type = 'discount_rate';
163 163
 			$item_discount_amount = $product['discount_rate'];
164 164
 			$item_discount_value = $product['discount_rate'];
165
-		} elseif ( ! empty( $d_special ) ) {
165
+		} elseif (!empty($d_special)) {
166 166
 			$item_discount_type = 'special_price';
167 167
 			$item_discount_amount = $product['special_price'];
168 168
 			$item_discount_value = $product['special_price'];
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 
171 171
 		$item = array(
172 172
 			'item_id' => $product['product_id'],
173
-			'item_ref' => ! empty( $product['product_reference'] ) ? $product['product_reference'] : null,
174
-			'item_name' => ! empty( $product['product_name'] ) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'],
173
+			'item_ref' => !empty($product['product_reference']) ? $product['product_reference'] : null,
174
+			'item_name' => !empty($product['product_name']) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'],
175 175
 			'item_qty' => $product['product_qty'],
176 176
 			'item_pu_ht' => $product['price_ht'],
177 177
 			'item_pu_ttc' => $product['product_price'],
@@ -186,66 +186,66 @@  discard block
 block discarded – undo
186 186
 			'item_total_ht' => $total_ht,
187 187
 			'item_tva_total_amount' => $tva_total_amount,
188 188
 			'item_total_ttc' => $total_ttc,
189
-			'item_meta' => ! empty( $product['item_meta'] ) ? $product['item_meta'] : array(),
189
+			'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array(),
190 190
 		);
191
-		if ( isset( $product['is_downloadable_'] ) ) {
191
+		if (isset($product['is_downloadable_'])) {
192 192
 			$item['item_is_downloadable_'] = $product['is_downloadable_'];
193 193
 		}
194
-		$array_not_to_do = array( WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations' );
195
-		if ( ! empty( $product['item_meta'] ) ) {
196
-			foreach ( $product['item_meta'] as $key => $value ) {
197
-				if ( ! isset( $item[ 'item_' . $key ] ) && ! in_array( $key, $array_not_to_do ) && ! empty( $product[ $key ] ) ) {
198
-					$item[ 'item_' . $key ] = $product[ $key ];
194
+		$array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations');
195
+		if (!empty($product['item_meta'])) {
196
+			foreach ($product['item_meta'] as $key => $value) {
197
+				if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) {
198
+					$item['item_' . $key] = $product[$key];
199 199
 				}
200 200
 			}
201 201
 		}
202 202
 
203 203
 		/** Check if it's a variation product */
204
-		if ( ! empty( $product ) && ! empty( $product['item_meta'] ) && ! empty( $product['item_meta']['variations'] ) ) {
205
-			foreach ( $product['item_meta']['variations'] as $k => $variation ) {
206
-				$product_variation_def = get_post_meta( $k, '_wpshop_variations_attribute_def', true );
207
-				if ( ! empty( $product_variation_def ) ) {
208
-					foreach ( $product_variation_def as $attribute_code => $variation_id ) {
209
-						$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
210
-						if ( ! empty( $variation_attribute_def ) ) {
211
-							$item['item_meta']['variation_definition'][ $attribute_code ]['NAME'] = $variation_attribute_def->frontend_label;
212
-							if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
213
-								$query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id );
214
-								$variation_name = $wpdb->get_var( $query );
204
+		if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) {
205
+			foreach ($product['item_meta']['variations'] as $k => $variation) {
206
+				$product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true);
207
+				if (!empty($product_variation_def)) {
208
+					foreach ($product_variation_def as $attribute_code => $variation_id) {
209
+						$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
210
+						if (!empty($variation_attribute_def)) {
211
+							$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
212
+							if ($variation_attribute_def->data_type_to_use == 'custom') {
213
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
214
+								$variation_name = $wpdb->get_var($query);
215 215
 							} else {
216
-								$variation_post = get_post( $variation_id );
216
+								$variation_post = get_post($variation_id);
217 217
 								$variation_name = $variation_post->post_title;
218 218
 							}
219
-							$item['item_meta']['variation_definition'][ $attribute_code ]['UNSTYLED_VALUE'] = $variation_name;
220
-							$item['item_meta']['variation_definition'][ $attribute_code ]['VALUE'] = $variation_name;
219
+							$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
220
+							$item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name;
221 221
 						}
222 222
 					}
223 223
 				}
224 224
 			}
225 225
 		} else {
226 226
 				/** Check if it's product with one variation */
227
-				$product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true );
228
-			if ( ! empty( $product_variation_def ) ) {
229
-				foreach ( $product_variation_def as $attribute_code => $variation_id ) {
230
-					$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
231
-					if ( ! empty( $variation_attribute_def ) ) {
232
-							$item['item_meta']['variation_definition'][ $attribute_code ]['NAME'] = $variation_attribute_def->frontend_label;
233
-						if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
234
-								$query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id );
235
-							$variation_name = $wpdb->get_var( $query );
227
+				$product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true);
228
+			if (!empty($product_variation_def)) {
229
+				foreach ($product_variation_def as $attribute_code => $variation_id) {
230
+					$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
231
+					if (!empty($variation_attribute_def)) {
232
+							$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
233
+						if ($variation_attribute_def->data_type_to_use == 'custom') {
234
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
235
+							$variation_name = $wpdb->get_var($query);
236 236
 						} else {
237
-							$variation_post = get_post( $variation_id );
237
+							$variation_post = get_post($variation_id);
238 238
 							$variation_name = $variation_post->post_title;
239 239
 						}
240
-						$item['item_meta']['variation_definition'][ $attribute_code ]['UNSTYLED_VALUE'] = $variation_name;
241
-						$item['item_meta']['variation_definition'][ $attribute_code ]['VALUE'] = $variation_name;
240
+						$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
241
+						$item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name;
242 242
 					}
243 243
 				}
244 244
 			}
245 245
 		}
246 246
 
247 247
 		/**	On ajoute la possibilité d'étendre les données produits ajoutées dans le panier / Add possibility to extends product data saved into cart	*/
248
-		$item = apply_filters( 'wpshop-add-product-to-order', $item, $product );
248
+		$item = apply_filters('wpshop-add-product-to-order', $item, $product);
249 249
 		return $item;
250 250
 	}
251 251
 
@@ -254,43 +254,43 @@  discard block
 block discarded – undo
254 254
 		 */
255 255
 	function wps_invoice_output() {
256 256
 
257
-		$order_id = ( ! empty( $_GET['order_id'] )) ? (int) $_GET['order_id'] : null;
258
-		$invoice_ref = ( ! empty( $_GET['invoice_ref'] )) ? sanitize_text_field( $_GET['invoice_ref'] ) : null;
259
-		$mode = ( ! empty( $_GET['mode'] )) ? sanitize_text_field( $_GET['mode'] ) : 'html';
260
-		$is_credit_slip = ( ! empty( $_GET['credit_slip'] )) ? sanitize_text_field( $_GET['credit_slip'] ) : null;
257
+		$order_id = (!empty($_GET['order_id'])) ? (int)$_GET['order_id'] : null;
258
+		$invoice_ref = (!empty($_GET['invoice_ref'])) ? sanitize_text_field($_GET['invoice_ref']) : null;
259
+		$mode = (!empty($_GET['mode'])) ? sanitize_text_field($_GET['mode']) : 'html';
260
+		$is_credit_slip = (!empty($_GET['credit_slip'])) ? sanitize_text_field($_GET['credit_slip']) : null;
261 261
 		$user_id = get_current_user_id();
262
-		if ( ! empty( $order_id ) && $user_id != 0 ) {
262
+		if (!empty($order_id) && $user_id != 0) {
263 263
 			/**	Order reading	*/
264
-			$order_postmeta = get_post_meta( $order_id, '_order_postmeta', true );
264
+			$order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
265 265
 			/**	Start invoice display	*/
266
-			if ( ! empty( $is_credit_slip ) ) {
267
-				$html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref, 'credit_slip' );
266
+			if (!empty($is_credit_slip)) {
267
+				$html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref, 'credit_slip');
268 268
 			} else {
269
-				$html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref );
269
+				$html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref);
270 270
 			}
271 271
 
272 272
 			/**
273 273
 			 * Génération de la facture au format PDF
274 274
 			 */
275
-			if ( 'pdf' === $mode ) {
276
-				require_once( WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php' );
275
+			if ('pdf' === $mode) {
276
+				require_once(WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php');
277 277
 				try {
278 278
 					// $html_content = wpshop_display::display_template_element('invoice_print_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
279
-					$html_content = wpshop_display::display_template_element( 'invoice_page_content_css', array(), array(), 'common' ) . '<page>' . $html_content . '</page>';
280
-					$html2pdf = new HTML2PDF( 'P', 'A4', 'fr' );
281
-					$html2pdf->setDefaultFont( 'Arial' );
282
-					$html2pdf->writeHTML( $html_content );
283
-					$html2pdf->Output( 'order_' . $order_id . '.pdf', 'D' );
279
+					$html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
280
+					$html2pdf = new HTML2PDF('P', 'A4', 'fr');
281
+					$html2pdf->setDefaultFont('Arial');
282
+					$html2pdf->writeHTML($html_content);
283
+					$html2pdf->Output('order_' . $order_id . '.pdf', 'D');
284 284
 				} catch (HTML2PDF_exception $e) {
285 285
 					echo $e;
286 286
 					exit;
287 287
 				}
288 288
 			} else {
289
-				$order_invoice_ref = ( ! empty( $order_postmeta['order_invoice_ref'] ) ) ? $order_postmeta['order_invoice_ref'] : '';
290
-				$tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element( 'invoice_page_content_css', array(), array(), 'common' );
289
+				$order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : '';
290
+				$tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common');
291 291
 				$tpl_component['INVOICE_MAIN_PAGE'] = $html_content;
292
-				$tpl_component['INVOICE_TITLE_PAGE'] = sprintf( __( 'Invoice %1$s for order %3$s (#%2$s)', 'wpshop' ), $order_invoice_ref, $order_id, $order_postmeta['order_key'] );
293
-				echo wpshop_display::display_template_element( 'invoice_page', $tpl_component, array(), 'common' );
292
+				$tpl_component['INVOICE_TITLE_PAGE'] = sprintf(__('Invoice %1$s for order %3$s (#%2$s)', 'wpshop'), $order_invoice_ref, $order_id, $order_postmeta['order_key']);
293
+				echo wpshop_display::display_template_element('invoice_page', $tpl_component, array(), 'common');
294 294
 			}
295 295
 		}
296 296
 		die();
@@ -302,21 +302,21 @@  discard block
 block discarded – undo
302 302
 		 */
303 303
 	function wps_orders_load_details() {
304 304
 
305
-		check_ajax_referer( 'wps_orders_load_details' );
306
-		$order_id = ( ! empty( $_POST['order_id'] ) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : '';
305
+		check_ajax_referer('wps_orders_load_details');
306
+		$order_id = (!empty($_POST['order_id'])) ? wpshop_tools::varSanitizer($_POST['order_id']) : '';
307 307
 		$user_id = get_current_user_id();
308 308
 		$status = false;
309 309
 		$result = '';
310
-		if ( ! empty( $order_id ) ) {
311
-			$order = get_post( $order_id );
312
-			$order_infos = get_post_meta( $order_id, '_order_postmeta', true );
313
-			$order_key = ( ! empty( $order_infos['order_key'] ) ) ? $order_infos['order_key'] : '-';
314
-			if ( ! empty( $order ) && ! empty( $user_id ) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id ) {
315
-				$result = do_shortcode( '[wps_cart cart_type="summary" oid="' . $order_id . '"]' );
310
+		if (!empty($order_id)) {
311
+			$order = get_post($order_id);
312
+			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
313
+			$order_key = (!empty($order_infos['order_key'])) ? $order_infos['order_key'] : '-';
314
+			if (!empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id) {
315
+				$result = do_shortcode('[wps_cart cart_type="summary" oid="' . $order_id . '"]');
316 316
 				$status = true;
317 317
 			}
318 318
 		}
319
-		echo json_encode( array( 'status' => $status, 'title' => sprintf( __( 'Order n° %s details', 'wpshop' ), $order_key ), 'content' => $result ) );
319
+		echo json_encode(array('status' => $status, 'title' => sprintf(__('Order n° %s details', 'wpshop'), $order_key), 'content' => $result));
320 320
 		wp_die();
321 321
 	}
322 322
 
@@ -325,60 +325,60 @@  discard block
 block discarded – undo
325 325
 		 */
326 326
 	function wps_order_choose_customer() {
327 327
 
328
-		$_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
329
-		if ( ! wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) ) {
328
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
329
+		if (!wp_verify_nonce($_wpnonce, 'wps_order_choose_customer')) {
330 330
 				wp_die();
331 331
 		}
332 332
 
333 333
 		$status = false;
334 334
 		$billing_data = $shipping_data = '';
335
-		$customer_id = ( ! empty( $_POST['customer_id'] ) ) ? intval( $_POST['customer_id'] ): null;
336
-		if ( ! empty( $customer_id ) ) {
335
+		$customer_id = (!empty($_POST['customer_id'])) ? intval($_POST['customer_id']) : null;
336
+		if (!empty($customer_id)) {
337 337
 			$wps_address = new wps_address();
338
-			$billing_option = get_option( 'wpshop_billing_address' );
339
-			$shipping_option = get_option( 'wpshop_shipping_address_choice' );
338
+			$billing_option = get_option('wpshop_billing_address');
339
+			$shipping_option = get_option('wpshop_shipping_address_choice');
340 340
 			$billing_option = $billing_option['choice'];
341
-			$customer_addresses_list = wps_address::get_addresses_list( $customer_id );
341
+			$customer_addresses_list = wps_address::get_addresses_list($customer_id);
342 342
 			$status = true;
343
-			$billing_data = '<div class="wps-alert-info">' . sprintf( __( 'No Billing address created, <a href="%s" title="' . __( 'Create a new billing address', 'wpshop' ) . '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ) . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600' ) . '</div>';
344
-			if ( ! empty( $shipping_option ) && ! empty( $shipping_option['activate'] ) ) {
343
+			$billing_data = '<div class="wps-alert-info">' . sprintf(__('No Billing address created, <a href="%s" title="' . __('Create a new billing address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
344
+			if (!empty($shipping_option) && !empty($shipping_option['activate'])) {
345 345
 				$shipping_option = $shipping_option['choice'];
346
-				$shipping_data = '<div class="wps-alert-info">' . sprintf( __( 'No shipping address created, <a href="%s" title="' . __( 'Create a new shipping address', 'wpshop' ) . '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ) . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600' ) . '</div>';
346
+				$shipping_data = '<div class="wps-alert-info">' . sprintf(__('No shipping address created, <a href="%s" title="' . __('Create a new shipping address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
347 347
 			}
348 348
 
349
-			if ( ! empty( $customer_addresses_list ) ) {
350
-				foreach ( $customer_addresses_list as $address_type => $customer_addresses ) {
351
-					if ( $billing_option == $address_type ) {
352
-						$billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
349
+			if (!empty($customer_addresses_list)) {
350
+				foreach ($customer_addresses_list as $address_type => $customer_addresses) {
351
+					if ($billing_option == $address_type) {
352
+						$billing_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
353 353
 					} else {
354
-						$shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
354
+						$shipping_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
355 355
 					}
356 356
 				}
357 357
 			}
358 358
 		}
359
-		echo json_encode( array( 'status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data ) );
359
+		echo json_encode(array('status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data));
360 360
 		wp_die();
361 361
 	}
362 362
 
363
-	static function pay_quotation( $order_id ) {
363
+	static function pay_quotation($order_id) {
364 364
 
365 365
 		$status = true;
366
-		$order_id = (int) $order_id;
367
-		$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
368
-		$order_info = get_post_meta( $order_id, '_order_info', true );
369
-		$_SESSION['shipping_method'] = isset( $order_meta['order_payment']['shipping_method'] ) ? $order_meta['order_payment']['shipping_method'] : 'No Shipping method required';
370
-		if ( isset( $order_info['billing']['address_id'] ) ) {
366
+		$order_id = (int)$order_id;
367
+		$order_meta = get_post_meta($order_id, '_order_postmeta', true);
368
+		$order_info = get_post_meta($order_id, '_order_info', true);
369
+		$_SESSION['shipping_method'] = isset($order_meta['order_payment']['shipping_method']) ? $order_meta['order_payment']['shipping_method'] : 'No Shipping method required';
370
+		if (isset($order_info['billing']['address_id'])) {
371 371
 			$_SESSION['billing_address'] = $order_info['billing']['address_id'];
372 372
 			$_SESSION['cart'] = $order_meta;
373 373
 			$_SESSION['cart']['order_id'] = $order_id;
374 374
     		$_SESSION['cart']['cart_type'] = 'cart';
375 375
 			$_SESSION['cart']['order_shipping_cost_fixe'] = 'on';
376
-			$permalink = get_permalink( get_option( 'wpshop_cart_page_id' ) ) . '?order_step=5';
376
+			$permalink = get_permalink(get_option('wpshop_cart_page_id')) . '?order_step=5';
377 377
 		} else {
378
-			$status = self::add_order_to_session( $order_id );
379
-			$permalink = get_permalink( wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ) );
378
+			$status = self::add_order_to_session($order_id);
379
+			$permalink = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')));
380 380
 		}
381
-		return array( 'status' => $status, 'permalink' => $permalink );
381
+		return array('status' => $status, 'permalink' => $permalink);
382 382
 	}
383 383
 
384 384
 	/**
@@ -387,54 +387,54 @@  discard block
 block discarded – undo
387 387
 	 * @method add_order_to_session
388 388
 	 * @param  int $order_id Id of order.
389 389
 	 */
390
-	public static function add_order_to_session( $order_id ) {
390
+	public static function add_order_to_session($order_id) {
391 391
 
392
-		$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
393
-		if ( $order_meta != false ) {
392
+		$order_meta = get_post_meta($order_id, '_order_postmeta', true);
393
+		if ($order_meta != false) {
394 394
 			$_SESSION['cart'] = array();
395 395
 			$_SESSION['cart']['order_amount_to_pay_now'] = $order_meta['order_amount_to_pay_now'];
396 396
 			$_SESSION['cart']['order_items'] = array();
397
-			if ( ! empty( $order_meta ) && ! empty( $order_meta['order_items'] ) ) {
397
+			if (!empty($order_meta) && !empty($order_meta['order_items'])) {
398 398
 				$wpshop_cart_type = 'cart';
399
-				foreach ( $order_meta['order_items'] as $item ) {
400
-					$_SESSION['cart']['order_items'][ $item['item_id'] ] = $item;
399
+				foreach ($order_meta['order_items'] as $item) {
400
+					$_SESSION['cart']['order_items'][$item['item_id']] = $item;
401 401
 				}
402 402
 				$wps_cart_ctr = new wps_cart();
403
-				$order = $wps_cart_ctr->calcul_cart_information( array() );
404
-				$wps_cart_ctr->store_cart_in_session( $order );
403
+				$order = $wps_cart_ctr->calcul_cart_information(array());
404
+				$wps_cart_ctr->store_cart_in_session($order);
405 405
 			}
406 406
 			$_SESSION['order_id'] = $order_id;
407 407
 		}
408
-		return (bool) ($order_meta != false);
408
+		return (bool)($order_meta != false);
409 409
 	}
410 410
 	/**
411 411
 	 * AJAX - Delete order by order_id
412 412
 	 */
413 413
 	public function wps_delete_order() {
414 414
 
415
-		$_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
416
-		if ( ! wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) ) {
415
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
416
+		if (!wp_verify_nonce($_wpnonce, 'wps_delete_order')) {
417 417
 				wp_die();
418 418
 		}
419 419
 
420 420
 		$status = false;
421 421
 		$output = '';
422
-		$order_id = ! empty( $_POST['order_id'] ) ? (int) $_POST['order_id'] : 0;
423
-		if ( $order_id ) {
424
-			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
422
+		$order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : 0;
423
+		if ($order_id) {
424
+			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
425 425
 			$wps_credit = new wps_credit();
426
-			$wps_credit->create_an_credit( $order_id );
426
+			$wps_credit->create_an_credit($order_id);
427 427
 			$order_meta['order_status'] = 'canceled';
428
-			$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time( 'mysql', 0 );
428
+			$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0);
429 429
 			$order_meta['order_payment']['refunded_action']['author'] = get_current_user_id();
430
-			update_post_meta( $order_id, '_order_postmeta', $order_meta );
430
+			update_post_meta($order_id, '_order_postmeta', $order_meta);
431 431
 			ob_start();
432
-			require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'order_row_in_account' ) );
432
+			require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'order_row_in_account'));
433 433
 			$output = ob_get_contents();
434 434
 			ob_end_clean();
435 435
 			$status = true;
436 436
 		}
437
-		echo json_encode( array( 'status' => $status, 'row' => $output ) );
437
+		echo json_encode(array('status' => $status, 'row' => $output));
438 438
 		wp_die();
439 439
 	}
440 440
 
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
 	 * @param  int $order_id OrderID.
446 446
 	 * @return mixed sha1 or false.
447 447
 	 */
448
-	public static function wps_token_order_customer( $order_id, $date = null ) {
449
-		$date = isset( $date ) ? $date : date( 'Ym' );
450
-		$order_metadata = get_post_meta( $order_id, '_order_postmeta', true );
451
-		if ( ! isset( $order_metadata['customer_id'] ) ) {
448
+	public static function wps_token_order_customer($order_id, $date = null) {
449
+		$date = isset($date) ? $date : date('Ym');
450
+		$order_metadata = get_post_meta($order_id, '_order_postmeta', true);
451
+		if (!isset($order_metadata['customer_id'])) {
452 452
 			return false;
453 453
 		}
454
-		return sha1( site_url() . '_' . $order_id . '_' . $order_metadata['customer_id'] . '_' . $date );
454
+		return sha1(site_url() . '_' . $order_id . '_' . $order_metadata['customer_id'] . '_' . $date);
455 455
 	}
456 456
 
457 457
 	/**
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
 	 * @param	int    $order_id	OrderID.
463 463
 	 * @return	boolean
464 464
 	 */
465
-	public static function wps_verify_token_order( $token, $order_id ) {
466
-		$current_month = self::wps_token_order_customer( $order_id );
467
-		$last_month = self::wps_token_order_customer( $order_id, date_format( date_create( date( 'Y-m' ) . ' - 1month' ), 'Ym' ) );
468
-		return (bool) ( (bool) $current_month && (bool) $last_month && ( $token === $current_month || $token === $last_month ) );
465
+	public static function wps_verify_token_order($token, $order_id) {
466
+		$current_month = self::wps_token_order_customer($order_id);
467
+		$last_month = self::wps_token_order_customer($order_id, date_format(date_create(date('Y-m') . ' - 1month'), 'Ym'));
468
+		return (bool)((bool)$current_month && (bool)$last_month && ($token === $current_month || $token === $last_month));
469 469
 	}
470 470
 }
Please login to merge, or discard this patch.