Completed
Push — master ( 480ce0...8a2d70 )
by
unknown
15:04
created
includes/modules/wps_product/controller/wps_product_ctr.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -257,8 +257,6 @@
 block discarded – undo
257 257
 	 *
258 258
 	 * @param int $product_id L'id du produit
259 259
 	 * @param string $type Peut être varchar, integer, text, options, decimal, datetime
260
-	 * @param string $attribute_name Le code d'un attribut
261
-	 * @param string $attribute_value La valeur à mêttre à jour
262 260
 	 */
263 261
 	public function update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute) {
264 262
 		global $wpdb;
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 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
 class wps_product_ctr {
3 3
 
4 4
 	/**
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
8 8
 	 * @return void
9 9
 	 */
10 10
 	function __construct() {
11
-		add_action( 'admin_enqueue_scripts', array( &$this, 'callback_admin_enqueue_scripts' ) );
11
+		add_action('admin_enqueue_scripts', array(&$this, 'callback_admin_enqueue_scripts'));
12 12
 
13
-		add_shortcode( 'wps_product_caracteristics', array( $this, 'display_product_caracteristics_tab' ) );
14
-		add_shortcode( 'wpshop_product_caracteristics', array( $this, 'display_product_caracteristics_tab' ) );
15
-		add_shortcode( 'wps_product_discount_chip', array( $this, 'display_discount_chip' ) );
16
-		add_shortcode( 'wpshop_product_discount_chip', array( $this, 'display_discount_chip' ) );
13
+		add_shortcode('wps_product_caracteristics', array($this, 'display_product_caracteristics_tab'));
14
+		add_shortcode('wpshop_product_caracteristics', array($this, 'display_product_caracteristics_tab'));
15
+		add_shortcode('wps_product_discount_chip', array($this, 'display_discount_chip'));
16
+		add_shortcode('wpshop_product_discount_chip', array($this, 'display_discount_chip'));
17 17
 
18
-		add_shortcode( 'wpshop_product_title', array( $this, 'wpshop_product_title' ) );
19
-		add_shortcode( 'wpshop_product_content', array( $this, 'wpshop_product_content' ) );
20
-		add_shortcode( 'wpshop_product_thumbnail', array( $this, 'wpshop_product_thumbnail' ) );
18
+		add_shortcode('wpshop_product_title', array($this, 'wpshop_product_title'));
19
+		add_shortcode('wpshop_product_content', array($this, 'wpshop_product_content'));
20
+		add_shortcode('wpshop_product_thumbnail', array($this, 'wpshop_product_thumbnail'));
21 21
 
22 22
 		/** Product sheet Page **/
23
-		add_action( 'admin_post_wps_product_sheet', array( $this, 'wpshop_product_sheet_output' ) );
23
+		add_action('admin_post_wps_product_sheet', array($this, 'wpshop_product_sheet_output'));
24 24
 	}
25 25
 
26 26
 	/**
@@ -31,25 +31,25 @@  discard block
 block discarded – undo
31 31
 		$module_folder = WPS_PRODUCT_PATH . '/modules/';
32 32
 
33 33
 		/**	Check if the defined directory exists for reading and including the different modules	*/
34
-		if( is_dir( $module_folder ) ) {
35
-			$parent_folder_content = scandir( $module_folder );
36
-			foreach ( $parent_folder_content as $folder ) {
37
-				if ( $folder && substr( $folder, 0, 1) != '.' && is_dir( $module_folder . $folder ) ) {
38
-					$child_folder_content = scandir( $module_folder . $folder );
39
-					if ( file_exists( $module_folder . $folder . '/' . $folder . '.php') ) {
40
-						$f =  $module_folder . $folder . '/' . $folder . '.php';
41
-						include( $f );
34
+		if (is_dir($module_folder)) {
35
+			$parent_folder_content = scandir($module_folder);
36
+			foreach ($parent_folder_content as $folder) {
37
+				if ($folder && substr($folder, 0, 1) != '.' && is_dir($module_folder . $folder)) {
38
+					$child_folder_content = scandir($module_folder . $folder);
39
+					if (file_exists($module_folder . $folder . '/' . $folder . '.php')) {
40
+						$f = $module_folder . $folder . '/' . $folder . '.php';
41
+						include($f);
42 42
 					}
43 43
 				}
44 44
 			}
45 45
 		}
46 46
 	}
47 47
 
48
-	public function callback_admin_enqueue_scripts( $hook ) {
49
-		if( $hook != 'tools_page_wpshop_tools' )
48
+	public function callback_admin_enqueue_scripts($hook) {
49
+		if ($hook != 'tools_page_wpshop_tools')
50 50
 			return;
51 51
 
52
-		wp_enqueue_script( 'wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array( "jquery", "jquery-form" ), WPS_PRODUCT_VERSION );
52
+		wp_enqueue_script('wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array("jquery", "jquery-form"), WPS_PRODUCT_VERSION);
53 53
 	}
54 54
 
55 55
 	/**
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 	 * @param array $args
58 58
 	 * @return string
59 59
 	 */
60
-	function display_product_caracteristics_tab( $args ) {
60
+	function display_product_caracteristics_tab($args) {
61 61
 		$output = '';
62
-		if( !empty($args) && !empty($args['pid']) ) {
62
+		if (!empty($args) && !empty($args['pid'])) {
63 63
 			$wps_product_mdl = new wps_product_mdl();
64
-			$product_atts_def = $wps_product_mdl->get_product_atts_def( $args['pid'] );
65
-			if( !empty($product_atts_def) ) {
64
+			$product_atts_def = $wps_product_mdl->get_product_atts_def($args['pid']);
65
+			if (!empty($product_atts_def)) {
66 66
 				ob_start();
67
-				require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab") );
67
+				require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab"));
68 68
 				$output = ob_get_contents();
69 69
 				ob_end_clean();
70 70
 			}
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 	 * @param array $args
78 78
 	 * @return string
79 79
 	 */
80
-	function display_discount_chip( $args ) {
80
+	function display_discount_chip($args) {
81 81
 		$output = '';
82
-		if( !empty($args) && !empty($args['pid']) ) {
82
+		if (!empty($args) && !empty($args['pid'])) {
83 83
 			$wps_price = new wpshop_prices();
84
-			$discount_data = wpshop_prices::check_discount_for_product( $args['pid'] );
85
-			if( !empty($discount_data) ) {
84
+			$discount_data = wpshop_prices::check_discount_for_product($args['pid']);
85
+			if (!empty($discount_data)) {
86 86
 				ob_start();
87
-				require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip") );
87
+				require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip"));
88 88
 				$output = ob_get_contents();
89 89
 				ob_end_clean();
90 90
 			}
@@ -102,39 +102,39 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	function check_stock($product_id, $cart_asked_quantity, $combined_variation_id = '') {
104 104
 		// Checking if combined variation ID exist and it is a simple option
105
-		if( !empty($combined_variation_id) && ( strpos($combined_variation_id, '__') !== false ) ) {
106
-			$var_id = explode( '__', $combined_variation_id);
105
+		if (!empty($combined_variation_id) && (strpos($combined_variation_id, '__') !== false)) {
106
+			$var_id = explode('__', $combined_variation_id);
107 107
 			$combined_variation_id = $var_id[1];
108 108
 		}
109 109
 
110 110
 
111
-		if ( !empty($combined_variation_id) ) {
111
+		if (!empty($combined_variation_id)) {
112 112
 
113
-			$variation_metadata = get_post_meta( $combined_variation_id, '_wpshop_product_metadata', true );
114
-			if ( isset($variation_metadata['product_stock']) ) {
113
+			$variation_metadata = get_post_meta($combined_variation_id, '_wpshop_product_metadata', true);
114
+			if (isset($variation_metadata['product_stock'])) {
115 115
 				$product_id = $combined_variation_id;
116 116
 			} else {
117
-				$product_id = wp_get_post_parent_id( $combined_variation_id );
118
-				$product_id = ( $product_id ) ? $product_id : $combined_variation_id;
117
+				$product_id = wp_get_post_parent_id($combined_variation_id);
118
+				$product_id = ($product_id) ? $product_id : $combined_variation_id;
119 119
 			}
120 120
 		}
121 121
 		$product_data = wpshop_products::get_product_data($product_id, false, '"publish", "free_product"');
122 122
 
123
-		if(!empty($product_data)) {
123
+		if (!empty($product_data)) {
124 124
 			$manage_stock = !empty($product_data['manage_stock']) ? $product_data['manage_stock'] : '';
125 125
 
126
-			$product_post_type = get_post_type( $product_id );
126
+			$product_post_type = get_post_type($product_id);
127 127
 
128
-			if ( $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
129
-				$parent_def = wpshop_products::get_parent_variation( $product_id );
130
-				if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
128
+			if ($product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
129
+				$parent_def = wpshop_products::get_parent_variation($product_id);
130
+				if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
131 131
 					$parent_post = $parent_def['parent_post'];
132 132
 					$parent_product_data = wpshop_products::get_product_data($parent_post->ID);
133
-					$manage_stock = empty( $manage_stock ) ? $parent_product_data['manage_stock'] : $manage_stock;
133
+					$manage_stock = empty($manage_stock) ? $parent_product_data['manage_stock'] : $manage_stock;
134 134
 				}
135 135
 			}
136
-			$manage_stock_is_activated = (!empty($manage_stock) && ( strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')) )) ? true : false;
137
-			$the_qty_is_in_stock = ( !empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity ) ? true : false ;
136
+			$manage_stock_is_activated = (!empty($manage_stock) && (strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')))) ? true : false;
137
+			$the_qty_is_in_stock = (!empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity) ? true : false;
138 138
 
139 139
 			if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) {
140 140
 				return true;
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
 	}
148 148
 
149 149
 	public static function get_inconsistent_product() {
150
-		$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
150
+		$price_piloting_option = get_option('wpshop_shop_price_piloting');
151 151
 
152
-		$entity_id 		= wpshop_entities::get_entity_identifier_from_code( 'wpshop_product' );
152
+		$entity_id = wpshop_entities::get_entity_identifier_from_code('wpshop_product');
153 153
 
154
-		$attribute_def	= wpshop_attributes::getElement( ( $price_piloting_option == 'TTC' ) ? 'product_price' : 'price_ht', "'valid'", 'code' );
155
-		$attribute_id	= $attribute_def->id;
154
+		$attribute_def = wpshop_attributes::getElement(($price_piloting_option == 'TTC') ? 'product_price' : 'price_ht', "'valid'", 'code');
155
+		$attribute_id = $attribute_def->id;
156 156
 
157 157
 		global $wpdb;
158 158
 
159 159
 		$wpdb->query('SET SESSION group_concat_max_len = 10000');
160 160
 
161
-		$query			= "
161
+		$query = "
162 162
 		SELECT 		post.ID, post.post_title, attr_val_dec.value as price_attribute, GROUP_CONCAT(postmeta.meta_key, '&sep&', postmeta.meta_value, '&&' ORDER BY postmeta.meta_key) as price
163 163
 			FROM 		$wpdb->posts as post
164 164
 		JOIN		$wpdb->postmeta as postmeta
@@ -171,15 +171,15 @@  discard block
 block discarded – undo
171 171
 			AND			postmeta.meta_key IN( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata' )
172 172
 		GROUP BY	post.ID";
173 173
 
174
-		$list_product	= $wpdb->get_results( $wpdb->prepare( $query, array( $entity_id, $attribute_id ) ) );
174
+		$list_product = $wpdb->get_results($wpdb->prepare($query, array($entity_id, $attribute_id)));
175 175
 
176
-		if( !empty( $list_product ) ) {
177
-			foreach( $list_product as $key_product => &$product ) {
176
+		if (!empty($list_product)) {
177
+			foreach ($list_product as $key_product => &$product) {
178 178
 				$product->price = explode('&&,', $product->price);
179
-				if(!empty($product->price) && is_array($product->price)) {
179
+				if (!empty($product->price) && is_array($product->price)) {
180 180
 					$array_price = array();
181
-					foreach($product->price as &$price) {
182
-						if(strpos( $price, '&&' ))
181
+					foreach ($product->price as &$price) {
182
+						if (strpos($price, '&&'))
183 183
 							$price = substr($price, 0, -2);
184 184
 
185 185
 						$tmp_price = explode('&sep&', $price);
@@ -187,35 +187,35 @@  discard block
 block discarded – undo
187 187
 						$price = maybe_unserialize($tmp_price[1]);
188 188
 
189 189
 						/** _wpshop_product_metadata */
190
-						if( $key == '_wpshop_product_metadata' ) {
191
-							$array_price[$key] =  ( $price_piloting_option == 'TTC' ) ? $price['product_price'] : $price['price_ht'];
190
+						if ($key == '_wpshop_product_metadata') {
191
+							$array_price[$key] = ($price_piloting_option == 'TTC') ? $price['product_price'] : $price['price_ht'];
192 192
 						}
193 193
 
194 194
 						/** _wps_price_infos */
195
-						if( $key == '_wps_price_infos' ) {
196
-							$array_price[$key] = !empty( $price['PRODUCT_PRICE'] ) ? $price['PRODUCT_PRICE'] : '-';
195
+						if ($key == '_wps_price_infos') {
196
+							$array_price[$key] = !empty($price['PRODUCT_PRICE']) ? $price['PRODUCT_PRICE'] : '-';
197 197
 						}
198 198
 
199
-						if( $key == '_product_price' ) {
200
-							$array_price[$key] = ( $price_piloting_option == 'TTC' ) ? $price : '-';
199
+						if ($key == '_product_price') {
200
+							$array_price[$key] = ($price_piloting_option == 'TTC') ? $price : '-';
201 201
 						}
202 202
 
203
-						if ( $key == '_wpshop_displayed_price' ) {
203
+						if ($key == '_wpshop_displayed_price') {
204 204
 							$array_price[$key] = $price;
205 205
 						}
206 206
 						unset($price);
207 207
 					}
208 208
 
209
-					$array_meta_list = array( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata', );
209
+					$array_meta_list = array('_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata',);
210 210
 
211
-					foreach( $array_meta_list as $meta_list ) {
212
-						if( !array_key_exists( $meta_list, $array_price ) ) {
211
+					foreach ($array_meta_list as $meta_list) {
212
+						if (!array_key_exists($meta_list, $array_price)) {
213 213
 							$array_price[$meta_list] = 0;
214 214
 						}
215 215
 					}
216 216
 
217 217
 					$product->price = $array_price;
218
-					if( $product->price_attribute === $product->price['_wpshop_product_metadata'] ) {
218
+					if ($product->price_attribute === $product->price['_wpshop_product_metadata']) {
219 219
 						unset($list_product[$key_product]);
220 220
 					}
221 221
 
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 	 * @param int $pid L'id du produit
234 234
 	 * @return WP_Post
235 235
 	 */
236
-	public function get_thumbnail ( $pid ) {
237
-		if( empty( $pid ) )
236
+	public function get_thumbnail($pid) {
237
+		if (empty($pid))
238 238
 			return null;
239 239
 
240
-		$thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true );
240
+		$thumbnail_id = get_post_meta($pid, '_thumbnail_id', true);
241 241
 
242
-		if( empty( $thumbnail_id ) )
242
+		if (empty($thumbnail_id))
243 243
 			return null;
244 244
 
245 245
 		return $thumbnail_id;
@@ -252,9 +252,9 @@  discard block
 block discarded – undo
252 252
 	 * @param array $array_data The array data [integer][barcode] = 0111100001
253 253
 	 */
254 254
 	public function update_attributes_for_product($product_id, $array_data) {
255
-		if(!empty($array_data)) {
256
-			foreach($array_data as $type => $array) {
257
-				foreach($array as $name_attribute => $value_attribute) {
255
+		if (!empty($array_data)) {
256
+			foreach ($array_data as $type => $array) {
257
+				foreach ($array as $name_attribute => $value_attribute) {
258 258
 					$this->update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute);
259 259
 				}
260 260
 			}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		$attribute_id = $wpdb->get_var($wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s"', array($name_attribute)));
279 279
 
280 280
 		/** On vérifie s'il existe si c'est le cas, on update sinon on insert */
281
-		if(count($wpdb->get_row($wpdb->prepare('SELECT value_id FROM ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' WHERE entity_id=%d AND attribute_id IN(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s")', array($product_id, $name_attribute)))) > 0) {
281
+		if (count($wpdb->get_row($wpdb->prepare('SELECT value_id FROM ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' WHERE entity_id=%d AND attribute_id IN(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s")', array($product_id, $name_attribute)))) > 0) {
282 282
 			$wpdb->query(
283 283
 				$wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' SET value="%s" WHERE entity_id=%d AND attribute_id=%d',
284 284
 					array($value_attribute, $product_id, $attribute_id)
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 	 * @param array $args [ 'id' ] L'id du produit
305 305
 	 * @return string
306 306
 	 */
307
-	public function wpshop_product_title( $args ) {
308
-		$output = __( 'No product has been found.', 'wpshop' );
307
+	public function wpshop_product_title($args) {
308
+		$output = __('No product has been found.', 'wpshop');
309 309
 
310
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
310
+		if (!empty($args) && !empty($args['pid'])) {
311 311
 			global $wpdb;
312 312
 			$query = "SELECT post_title FROM {$wpdb->posts} WHERE ID = %d";
313
-			$output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) );
313
+			$output = $wpdb->get_var($wpdb->prepare($query, $args['pid']));
314 314
 		}
315 315
 
316 316
 		return $output;
@@ -321,16 +321,16 @@  discard block
 block discarded – undo
321 321
 	 * @param array $args [ 'id' ] L'id du produit
322 322
 	 * @return string
323 323
 	 */
324
-	public function wpshop_product_content( $args ) {
325
-		$output = __( 'No product has been found.', 'wpshop' );
324
+	public function wpshop_product_content($args) {
325
+		$output = __('No product has been found.', 'wpshop');
326 326
 
327
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
327
+		if (!empty($args) && !empty($args['pid'])) {
328 328
 			global $wpdb;
329 329
 			$query = "SELECT post_content FROM {$wpdb->posts} WHERE ID = %d";
330
-			$output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) );
330
+			$output = $wpdb->get_var($wpdb->prepare($query, $args['pid']));
331 331
 		}
332 332
 
333
-		return nl2br( $output );
333
+		return nl2br($output);
334 334
 	}
335 335
 
336 336
 	/**
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 	 * 						[ size ] La taille de l'image. Peut être défini comme : small, medium ou full
341 341
 	 * @return string
342 342
 	 */
343
-	public function wpshop_product_thumbnail( $args ) {
343
+	public function wpshop_product_thumbnail($args) {
344 344
 		$url_thumbnail = WPSHOP_DEFAULT_PRODUCT_PICTURE;
345 345
 		$size = '20%';
346 346
 
347
-		if ( !empty( $args ) && !empty( $args['size'] ) ) {
348
-			switch ( $args['size'] ) {
347
+		if (!empty($args) && !empty($args['size'])) {
348
+			switch ($args['size']) {
349 349
 				case 'small':
350 350
 					$size = '20%';
351 351
 					break;
@@ -360,20 +360,20 @@  discard block
 block discarded – undo
360 360
 			}
361 361
 		}
362 362
 
363
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
364
-			$thumbnail_id = $this->get_thumbnail( $args['pid'] );
363
+		if (!empty($args) && !empty($args['pid'])) {
364
+			$thumbnail_id = $this->get_thumbnail($args['pid']);
365 365
 
366
-			if( !empty( $thumbnail_id ) ) {
367
-				$attachment = get_post( $thumbnail_id );
366
+			if (!empty($thumbnail_id)) {
367
+				$attachment = get_post($thumbnail_id);
368 368
 
369
-				if( !empty( $attachment ) && !empty( $attachment->guid ) ) {
369
+				if (!empty($attachment) && !empty($attachment->guid)) {
370 370
 					$url_thumbnail = $attachment->guid;
371 371
 				}
372 372
 			}
373 373
 		}
374 374
 
375 375
 		ob_start();
376
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail" ) );
376
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail"));
377 377
 		$output = ob_get_clean();
378 378
 
379 379
 		return $output;
@@ -383,19 +383,19 @@  discard block
 block discarded – undo
383 383
 	 *	Output product sheet to PDF
384 384
 	 */
385 385
 	public function wpshop_product_sheet_output() {
386
-		$product_id = ( !empty($_GET['pid']) ) ? (int) $_GET['pid'] : null;
386
+		$product_id = (!empty($_GET['pid'])) ? (int)$_GET['pid'] : null;
387 387
 		$user_id = get_current_user_id();
388
-		if( !empty($product_id) && get_post_type( $product_id ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT && $user_id != 0 && current_user_can( 'manage_options' ) ) {
388
+		if (!empty($product_id) && get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT && $user_id != 0 && current_user_can('manage_options')) {
389 389
 			$wps_product_administration_ctr = new wps_product_administration_ctr();
390
-			$html_content = $wps_product_administration_ctr->generate_product_sheet_datas( $product_id );
391
-			$product_post = get_post( $product_id );
392
-			require_once(WPSHOP_LIBRAIRIES_DIR.'HTML2PDF/html2pdf.class.php');
390
+			$html_content = $wps_product_administration_ctr->generate_product_sheet_datas($product_id);
391
+			$product_post = get_post($product_id);
392
+			require_once(WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php');
393 393
 			try {
394 394
 				$html2pdf = new HTML2PDF('P', 'A4', 'fr');
395 395
 				$html2pdf->pdf->SetDisplayMode('fullpage');
396 396
 				$html2pdf->setDefaultFont('Arial');
397 397
 				$html2pdf->writeHTML($html_content);
398
-				$html2pdf->Output('product-' .$product_id.'-'.$product_post->post_name.'.pdf', 'D');
398
+				$html2pdf->Output('product-' . $product_id . '-' . $product_post->post_name . '.pdf', 'D');
399 399
 			}
400 400
 			catch (HTML2PDF_exception $e) {
401 401
 				echo $e;
Please login to merge, or discard this patch.
Braces   +18 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_product_ctr {
3 5
 
4 6
 	/**
@@ -46,8 +48,9 @@  discard block
 block discarded – undo
46 48
 	}
47 49
 
48 50
 	public function callback_admin_enqueue_scripts( $hook ) {
49
-		if( $hook != 'tools_page_wpshop_tools' )
50
-			return;
51
+		if( $hook != 'tools_page_wpshop_tools' ) {
52
+					return;
53
+		}
51 54
 
52 55
 		wp_enqueue_script( 'wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array( "jquery", "jquery-form" ), WPS_PRODUCT_VERSION );
53 56
 	}
@@ -138,8 +141,7 @@  discard block
 block discarded – undo
138 141
 
139 142
 			if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) {
140 143
 				return true;
141
-			}
142
-			else {
144
+			} else {
143 145
 				return __('You cannot add that amount to the cart since there is not enough stock.', 'wpshop');
144 146
 			}
145 147
 		}
@@ -179,8 +181,9 @@  discard block
 block discarded – undo
179 181
 				if(!empty($product->price) && is_array($product->price)) {
180 182
 					$array_price = array();
181 183
 					foreach($product->price as &$price) {
182
-						if(strpos( $price, '&&' ))
183
-							$price = substr($price, 0, -2);
184
+						if(strpos( $price, '&&' )) {
185
+													$price = substr($price, 0, -2);
186
+						}
184 187
 
185 188
 						$tmp_price = explode('&sep&', $price);
186 189
 						$key = $tmp_price[0];
@@ -234,13 +237,15 @@  discard block
 block discarded – undo
234 237
 	 * @return WP_Post
235 238
 	 */
236 239
 	public function get_thumbnail ( $pid ) {
237
-		if( empty( $pid ) )
238
-			return null;
240
+		if( empty( $pid ) ) {
241
+					return null;
242
+		}
239 243
 
240 244
 		$thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true );
241 245
 
242
-		if( empty( $thumbnail_id ) )
243
-			return null;
246
+		if( empty( $thumbnail_id ) ) {
247
+					return null;
248
+		}
244 249
 
245 250
 		return $thumbnail_id;
246 251
 	}
@@ -284,8 +289,7 @@  discard block
 block discarded – undo
284 289
 					array($value_attribute, $product_id, $attribute_id)
285 290
 				)
286 291
 			);
287
-		}
288
-		else {
292
+		} else {
289 293
 			/** Insert avec toutes les informations requise */
290 294
 			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE . '_value_' . $type, array(
291 295
 					'attribute_id' 			=> $attribute_id,
@@ -396,8 +400,7 @@  discard block
 block discarded – undo
396 400
 				$html2pdf->setDefaultFont('Arial');
397 401
 				$html2pdf->writeHTML($html_content);
398 402
 				$html2pdf->Output('product-' .$product_id.'-'.$product_post->post_name.'.pdf', 'D');
399
-			}
400
-			catch (HTML2PDF_exception $e) {
403
+			} catch (HTML2PDF_exception $e) {
401 404
 				echo $e;
402 405
 			}
403 406
 		}
Please login to merge, or discard this patch.
wps_product_mass_interface/controller/wps_product_mass_interface_ctr.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -158,6 +158,7 @@  discard block
 block discarded – undo
158 158
 	/**
159 159
 	 * Display pagination
160 160
 	 *
161
+	 * @param integer $current_page
161 162
 	 * @return string
162 163
 	 */
163 164
 	function get_products_pagination( $current_page, $attribute_set_id = 1 ) {
@@ -201,6 +202,9 @@  discard block
 block discarded – undo
201 202
 			return $output;
202 203
 			}
203 204
 
205
+	/**
206
+	 * @param integer $product_id
207
+	 */
204 208
 	function wps_product_attached_files( $product_id ) {
205 209
 		global $wpdb;
206 210
 		$output = '';
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
 	}
371 371
 
372 372
 	/**
373
-	* Delete product list
374
-	**/
373
+	 * Delete product list
374
+	 **/
375 375
 	function wps_mass_delete_file() {
376 376
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
377 377
 
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
 	}
390 390
 
391 391
 	/**
392
-	* Update product files list
393
-	*/
392
+	 * Update product files list
393
+	 */
394 394
 	function wps_mass_edit_update_files_list() {
395 395
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
396 396
 
Please login to merge, or discard this patch.
Braces   +21 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 /**
3 5
  * Main controller file for product mass modification module
4 6
  *
@@ -222,8 +224,9 @@  discard block
 block discarded – undo
222 224
 	function wps_mass_edit_change_page() {
223 225
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
224 226
 
225
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) )
226
-			wp_die();
227
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) {
228
+					wp_die();
229
+		}
227 230
 
228 231
 		$status = false; $response = '';
229 232
 		$page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0;
@@ -246,8 +249,9 @@  discard block
 block discarded – undo
246 249
 	function wps_mass_interface_new_product_creation() {
247 250
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
248 251
 
249
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) )
250
-			wp_die();
252
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) {
253
+					wp_die();
254
+		}
251 255
 
252 256
 		global $wpdb;
253 257
 		$output = $pagination = '';
@@ -277,8 +281,9 @@  discard block
 block discarded – undo
277 281
 	function wps_save_product_quick_interface() {
278 282
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
279 283
 
280
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) )
281
-			wp_die();
284
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) {
285
+					wp_die();
286
+		}
282 287
 
283 288
 		global $wpdb;
284 289
 		$response = ''; $status = false;
@@ -306,8 +311,7 @@  discard block
 block discarded – undo
306 311
 						if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
307 312
 							wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) );
308 313
 							update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] );
309
-						}
310
-						elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
314
+						} elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
311 315
 							delete_post_meta( $updated_post, '_thumbnail_id' );
312 316
 						}
313 317
 					}
@@ -355,12 +359,10 @@  discard block
 block discarded – undo
355 359
 
356 360
 		if( $status ) {
357 361
 			$response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products );
358
-		}
359
-		else {
362
+		} else {
360 363
 			if( !empty($total_updated_products) ) {
361 364
 				$response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update );
362
-			}
363
-			else {
365
+			} else {
364 366
 				$response = __( 'No product have been updated', 'wpshop');
365 367
 			}
366 368
 		}
@@ -375,8 +377,9 @@  discard block
 block discarded – undo
375 377
 	function wps_mass_delete_file() {
376 378
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
377 379
 
378
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) )
379
-			wp_die();
380
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) {
381
+					wp_die();
382
+		}
380 383
 
381 384
 		$status = false;
382 385
 		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
@@ -394,8 +397,9 @@  discard block
 block discarded – undo
394 397
 	function wps_mass_edit_update_files_list() {
395 398
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
396 399
 
397
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) )
398
-			wp_die();
400
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) {
401
+					wp_die();
402
+		}
399 403
 
400 404
 		$status = false; $response = '';
401 405
 		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 /**
3 3
  * Main controller file for product mass modification module
4 4
  *
@@ -21,29 +21,29 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	function __construct() {
23 23
 		// Add submenu
24
-		add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 );
24
+		add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350);
25 25
 
26 26
 		// Trigger ajax action
27
-		add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') );
28
-		add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') );
29
-		add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) );
30
-		add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) );
31
-		add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) );
27
+		add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page'));
28
+		add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface'));
29
+		add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation'));
30
+		add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file'));
31
+		add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list'));
32 32
 		// add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) );
33 33
 	}
34 34
 
35 35
 	function register_mass_products_edit_submenu() {
36
-		$this->submenu = add_submenu_page( 'edit.php?post_type=wpshop_product', __( 'Mass product edit', 'wpshop' ), __( 'Mass product edit', 'wpshop' ), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface' ) );
36
+		$this->submenu = add_submenu_page('edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop'), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface'));
37 37
 		// Declare Styles and JS Files.
38
-		add_action( 'admin_print_styles-' . $this->submenu, array( $this, 'admin_print_styles' ) );
39
-		add_action( 'admin_print_scripts-' . $this->submenu, array( $this, 'admin_print_scripts' ) );
38
+		add_action('admin_print_styles-' . $this->submenu, array($this, 'admin_print_styles'));
39
+		add_action('admin_print_scripts-' . $this->submenu, array($this, 'admin_print_scripts'));
40 40
 	}
41 41
 
42 42
 	/**
43 43
 	 * Add css to administration
44 44
 	 */
45 45
 	function admin_print_styles() {
46
-		wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css' );
46
+		wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css');
47 47
 	}
48 48
 
49 49
 	/**
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	function admin_print_scripts() {
53 53
 		wp_enqueue_media();
54
-		wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true );
54
+		wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true);
55 55
 		$output = '<script type="text/javascript">';
56
-		$output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";';
57
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";';
58
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";';
59
-		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";';
56
+		$output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";';
57
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";';
58
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";';
59
+		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";';
60 60
 		$output .= '</script>';
61 61
 		echo $output;
62 62
 	}
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 	 *
69 69
 	 * @return array
70 70
 	 */
71
-	function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) {
72
-
73
-		if ( !empty( $attribute_list ) ) {
74
-			foreach( $attribute_list as $attributes_group ) {
75
-				foreach( $attributes_group as $attributes_sections ) {
76
-					if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) {
77
-						foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) {
78
-							if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) {
79
-								$quick_add_form_attributes[ $attribute_id ] = $att_def;
71
+	function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) {
72
+
73
+		if (!empty($attribute_list)) {
74
+			foreach ($attribute_list as $attributes_group) {
75
+				foreach ($attributes_group as $attributes_sections) {
76
+					if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) {
77
+						foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) {
78
+							if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') {
79
+								$quick_add_form_attributes[$attribute_id] = $att_def;
80 80
 							}
81 81
 						}
82 82
 					}
@@ -93,29 +93,29 @@  discard block
 block discarded – undo
93 93
 	 * @param integer $page
94 94
 	 * @return string
95 95
 	 */
96
-	function display_products_list( $default = 1, $page = 0, $order_by = 'date', $order = 'ASC' ) {
96
+	function display_products_list($default = 1, $page = 0, $order_by = 'date', $order = 'ASC') {
97 97
 		global $wpdb;
98 98
 		// Product entity
99
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
99
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
100 100
 
101 101
 		$user_id = get_current_user_id();
102 102
 		// Check product limit
103
-		$product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
104
-		$product_limit = ( !empty($product_limit) ) ? $product_limit : 20;
103
+		$product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
104
+		$product_limit = (!empty($product_limit)) ? $product_limit : 20;
105 105
 
106 106
 		// Get products for the current page
107 107
 		$wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl();
108
-		$products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit );
108
+		$products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit);
109 109
 
110 110
 		// Construct Table Head Data
111 111
 		$quick_add_form_attributes = array();
112 112
 		$get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form();
113
-		foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) {
113
+		foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) {
114 114
 			$quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute;
115 115
 		}
116 116
 
117 117
 		ob_start();
118
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) );
118
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list"));
119 119
 		$output = ob_get_contents();
120 120
 		ob_end_clean();
121 121
 		return $output;
@@ -131,27 +131,27 @@  discard block
 block discarded – undo
131 131
 		$products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets();
132 132
 
133 133
 		$default = '';
134
-		if( !empty($products_attributes_groups) ) {
135
-			foreach( $products_attributes_groups as $key => $products_attributes_group ) {
136
-				if( $products_attributes_group->slug == 'free_product' ) {
137
-					unset( $products_attributes_groups[$key] );
134
+		if (!empty($products_attributes_groups)) {
135
+			foreach ($products_attributes_groups as $key => $products_attributes_group) {
136
+				if ($products_attributes_group->slug == 'free_product') {
137
+					unset($products_attributes_groups[$key]);
138 138
 				}
139
-				if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) {
139
+				if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') {
140 140
 					$default = $products_attributes_group->id;
141 141
 				}
142 142
 			}
143 143
 		}
144 144
 		// Check page
145
-		$page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0;
145
+		$page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0;
146 146
 		// Display product tab
147
-		$order_by = !empty( $_GET[ 'order_by' ] ) ? sanitize_title( $_GET[ 'order_by' ] ) : 'date';
148
-		$order = !empty( $_GET[ 'order' ] ) ? sanitize_title( $_GET[ 'order' ] ) : 'ASC';
149
-		$product_list_interface = $this->display_products_list( $default, $page, $order_by, $order );
147
+		$order_by = !empty($_GET['order_by']) ? sanitize_title($_GET['order_by']) : 'date';
148
+		$order = !empty($_GET['order']) ? sanitize_title($_GET['order']) : 'ASC';
149
+		$product_list_interface = $this->display_products_list($default, $page, $order_by, $order);
150 150
 
151 151
 		// Get pagination
152
-		$pagination = $this->get_products_pagination( $page, $default );
152
+		$pagination = $this->get_products_pagination($page, $default);
153 153
 
154
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) );
154
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface"));
155 155
 	}
156 156
 
157 157
 	/**
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @return string
161 161
 	 */
162
-	function get_products_pagination( $current_page, $attribute_set_id = 1 ) {
162
+	function get_products_pagination($current_page, $attribute_set_id = 1) {
163 163
 		global $wpdb;
164 164
 		$user_id = get_current_user_id();
165 165
 		$output = '';
166 166
 		/**	Define the element number per page. If the user change the default value, take this value	*/
167
-		$one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
168
-		$one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20;
167
+		$one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
168
+		$one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20;
169 169
 
170 170
 		/**	Count the number of product existing in the shop	*/
171 171
 		$query = $wpdb->prepare(
@@ -177,37 +177,37 @@  discard block
 block discarded – undo
177 177
 				AND meta_value = %s
178 178
 				AND post_status IN ( 'publish', 'draft' )",
179 179
 				WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id);
180
-		$products = $wpdb->get_var( $query );
180
+		$products = $wpdb->get_var($query);
181 181
 
182
-			if( !empty($products) ) {
182
+			if (!empty($products)) {
183 183
 			$args = array(
184 184
 			'base' => '%_%',
185
-			'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ),
186
-					'current' => ( $current_page + 1 ),
187
-					'total' => ceil( $products / $one_page_limit ),
185
+			'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'),
186
+					'current' => ($current_page + 1),
187
+					'total' => ceil($products / $one_page_limit),
188 188
 						'type' => 'array',
189 189
 						'prev_next' => false,
190 190
 						'show_all' => true,
191 191
 			);
192
-			$paginate = paginate_links( $args );
192
+			$paginate = paginate_links($args);
193 193
 
194 194
 				$wps_product_ctr = new wps_product_ctr();
195 195
 				ob_start();
196
-				require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) );
196
+				require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination"));
197 197
 				$output = ob_get_contents();
198 198
 			ob_end_clean();
199 199
 			}
200 200
 			return $output;
201 201
 			}
202 202
 
203
-	function wps_product_attached_files( $product_id ) {
203
+	function wps_product_attached_files($product_id) {
204 204
 		global $wpdb;
205 205
 		$output = '';
206
-		$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%' );
207
-		$files = $wpdb->get_results( $query );
208
-		if( !empty($files) ) {
206
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%');
207
+		$files = $wpdb->get_results($query);
208
+		if (!empty($files)) {
209 209
 			ob_start();
210
-			require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) );
210
+			require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list"));
211 211
 			$output = ob_get_contents();
212 212
 			ob_end_clean();
213 213
 		}
@@ -219,23 +219,23 @@  discard block
 block discarded – undo
219 219
 	 * AJAX - Change page action on mass edit product interface
220 220
 	 */
221 221
 	function wps_mass_edit_change_page() {
222
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
222
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
223 223
 
224
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) )
224
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page'))
225 225
 			wp_die();
226 226
 
227 227
 		$status = false; $response = '';
228
-		$page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0;
229
-		$attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1;
230
-		if( !empty($attribute_set_id) ) {
228
+		$page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0;
229
+		$attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1;
230
+		if (!empty($attribute_set_id)) {
231 231
 			// Get tab
232
-			$response = $this->display_products_list( $attribute_set_id, $page );
233
-			$pagination = $this->get_products_pagination( $page, $attribute_set_id );
234
-			if( !empty($response) ) {
232
+			$response = $this->display_products_list($attribute_set_id, $page);
233
+			$pagination = $this->get_products_pagination($page, $attribute_set_id);
234
+			if (!empty($response)) {
235 235
 				$status = true;
236 236
 			}
237 237
 		}
238
-		echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) );
238
+		echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination));
239 239
 		wp_die();
240 240
 	}
241 241
 
@@ -243,30 +243,30 @@  discard block
 block discarded – undo
243 243
 	 * AJAX - Create a draft product and display the line allowing to edit informations for this product
244 244
 	 */
245 245
 	function wps_mass_interface_new_product_creation() {
246
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
246
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
247 247
 
248
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) )
248
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation'))
249 249
 			wp_die();
250 250
 
251 251
 		global $wpdb;
252 252
 		$output = $pagination = '';
253 253
 		$status = false;
254 254
 
255
-		$new_product_id = wp_insert_post( array(
255
+		$new_product_id = wp_insert_post(array(
256 256
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
257 257
 				'post_status' => 'publish',
258
-				'post_title' => __( 'New product', 'wpshop' ),
259
-		) );
258
+				'post_title' => __('New product', 'wpshop'),
259
+		));
260 260
 
261
-		if( !is_object($new_product_id) ) {
261
+		if (!is_object($new_product_id)) {
262 262
 			$status = true;
263 263
 		}
264
-		if ( !empty( $new_product_id ) ) {
265
-			$product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1;
266
-			update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id );
264
+		if (!empty($new_product_id)) {
265
+			$product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1;
266
+			update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id);
267 267
 		}
268 268
 
269
-		echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) );
269
+		echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination));
270 270
 		wp_die();
271 271
 	}
272 272
 
@@ -274,32 +274,32 @@  discard block
 block discarded – undo
274 274
 	 * AJAX - Save datas
275 275
 	 */
276 276
 	function wps_save_product_quick_interface() {
277
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
277
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
278 278
 
279
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) )
279
+		if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface'))
280 280
 			wp_die();
281 281
 
282 282
 		global $wpdb;
283 283
 		$response = ''; $status = false;
284 284
 		$count_products_to_update = 0; $total_updated_products = 0;
285 285
 
286
-		$wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array();
287
-		$wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array();
288
-		$wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array();
286
+		$wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array();
287
+		$wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array();
288
+		$wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array();
289 289
 
290 290
 		// ------------------------------------------------------------------------------------------------------
291 291
 
292
-		foreach( $_REQUEST['concur'] as $post_id => $columns ) {
292
+		foreach ($_REQUEST['concur'] as $post_id => $columns) {
293 293
 			$concur = array();
294
-			for( $i = $count = 0; $i <= $count; $i++ ) {
295
-				foreach( $columns as $key => $rows ) {
296
-					$count = count( $rows )-1;
294
+			for ($i = $count = 0; $i <= $count; $i++) {
295
+				foreach ($columns as $key => $rows) {
296
+					$count = count($rows) - 1;
297 297
 					$concur[$i][$key] = $rows[$i];
298 298
 				}
299
-				if( empty( $concur[$i]['is_row'] ) ) {
300
-					unset( $concur[$i] );
299
+				if (empty($concur[$i]['is_row'])) {
300
+					unset($concur[$i]);
301 301
 				} else {
302
-					unset( $concur[$i]['is_row'] );
302
+					unset($concur[$i]['is_row']);
303 303
 
304 304
 					$dotPos = strrpos($concur[$i]['price'], '.');
305 305
 					$commaPos = strrpos($concur[$i]['price'], ',');
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 					} else {
310 310
 						$concur[$i]['price'] = floatval(
311 311
 							preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], 0, $sep)) . '.' .
312
-							preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep+1, strlen($concur[$i]['price'])))
312
+							preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep + 1, strlen($concur[$i]['price'])))
313 313
 						);
314 314
 					}
315 315
 
@@ -317,51 +317,51 @@  discard block
 block discarded – undo
317 317
 					$concur[$i]['price'] = $concur[$i]['price'];
318 318
 				}
319 319
 			}
320
-			update_post_meta( $post_id, '_concur', $concur );
320
+			update_post_meta($post_id, '_concur', $concur);
321 321
 		}
322 322
 
323 323
 		// ------------------------------------------------------------------------------------------------------
324 324
 
325
-		if( !empty($wps_product_quick_save) ) {
326
-			$count_products_to_update = count( $wps_product_quick_save );
327
-			foreach( $wps_product_quick_save as $product_to_save ) {
325
+		if (!empty($wps_product_quick_save)) {
326
+			$count_products_to_update = count($wps_product_quick_save);
327
+			foreach ($wps_product_quick_save as $product_to_save) {
328 328
 				$data_to_save = array();
329 329
 				// Update post
330
-				$updated_post = wp_update_post( array( 'ID' => $product_to_save,
331
-						'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ),
332
-						'post_content' => wp_kses_post( $wps_mass_interface[$product_to_save]['post_content'] ),
330
+				$updated_post = wp_update_post(array('ID' => $product_to_save,
331
+						'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']),
332
+						'post_content' => wp_kses_post($wps_mass_interface[$product_to_save]['post_content']),
333 333
 						)
334 334
 				);
335 335
 				// Update attributes
336
-				if( !empty($updated_post) ) {
336
+				if (!empty($updated_post)) {
337 337
 					// Update Featured picture
338
-					if( !empty($wps_mass_interface[$product_to_save]['picture']) ) {
339
-						$thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true );
340
-						if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
341
-							wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) );
342
-							update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] );
338
+					if (!empty($wps_mass_interface[$product_to_save]['picture'])) {
339
+						$thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true);
340
+						if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
341
+							wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post));
342
+							update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']);
343 343
 						}
344
-						elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
345
-							delete_post_meta( $updated_post, '_thumbnail_id' );
344
+						elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
345
+							delete_post_meta($updated_post, '_thumbnail_id');
346 346
 						}
347 347
 					}
348 348
 
349 349
 					// Update files datas
350
-					if( !empty($wps_mass_interface[$product_to_save]['files']) ) {
351
-						$files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) );
352
-						if( !empty($files_data) && is_array($files_data) ) {
353
-							foreach( $files_data as $file_id ) {
354
-								if( !empty($file_id) ) {
355
-									wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) );
350
+					if (!empty($wps_mass_interface[$product_to_save]['files'])) {
351
+						$files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files']));
352
+						if (!empty($files_data) && is_array($files_data)) {
353
+							foreach ($files_data as $file_id) {
354
+								if (!empty($file_id)) {
355
+									wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post));
356 356
 								}
357 357
 							}
358 358
 						}
359 359
 					}
360 360
 
361
-					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save );
362
-					$data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array();
361
+					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save);
362
+					$data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array();
363 363
 
364
-					if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
364
+					if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
365 365
 						// Get current barcode
366 366
 						$wps_product_mdl = new wps_product_mdl();
367 367
 						$attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id;
@@ -372,34 +372,34 @@  discard block
 block discarded – undo
372 372
 					$data_to_save['user_ID'] = get_current_user_id();
373 373
 					$data_to_save['action'] = 'editpost';
374 374
 
375
-					if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) {
376
-						wp_trash_post( $product_to_save );
375
+					if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") {
376
+						wp_trash_post($product_to_save);
377 377
 					}
378 378
 
379
-					if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) {
379
+					if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) {
380 380
 						$product_class = new wpshop_products();
381
-						$product_class->save_product_custom_informations( $product_to_save, $data_to_save );
381
+						$product_class->save_product_custom_informations($product_to_save, $data_to_save);
382 382
 						$total_updated_products++;
383 383
 					}
384 384
 				}
385 385
 			}
386 386
 		}
387 387
 		// Checking status
388
-		$status = ( $total_updated_products == $count_products_to_update ) ? true : false;
388
+		$status = ($total_updated_products == $count_products_to_update) ? true : false;
389 389
 
390
-		if( $status ) {
391
-			$response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products );
390
+		if ($status) {
391
+			$response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products);
392 392
 		}
393 393
 		else {
394
-			if( !empty($total_updated_products) ) {
395
-				$response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update );
394
+			if (!empty($total_updated_products)) {
395
+				$response = sprintf(__('All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update);
396 396
 			}
397 397
 			else {
398
-				$response = __( 'No product have been updated', 'wpshop');
398
+				$response = __('No product have been updated', 'wpshop');
399 399
 			}
400 400
 		}
401 401
 
402
-		echo json_encode( array('status' => $status, 'response' => $response ) );
402
+		echo json_encode(array('status' => $status, 'response' => $response));
403 403
 		wp_die();
404 404
 	}
405 405
 
@@ -407,18 +407,18 @@  discard block
 block discarded – undo
407 407
 	* Delete product list
408 408
 	**/
409 409
 	function wps_mass_delete_file() {
410
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
410
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
411 411
 
412
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) )
412
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file'))
413 413
 			wp_die();
414 414
 
415 415
 		$status = false;
416
-		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
417
-		if( !empty($file_id) ) {
418
-			wp_update_post( array('ID' => $file_id, 'post_parent' => 0) );
416
+		$file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null;
417
+		if (!empty($file_id)) {
418
+			wp_update_post(array('ID' => $file_id, 'post_parent' => 0));
419 419
 			$status = true;
420 420
 		}
421
-		echo json_encode( array( 'status' => $status ) );
421
+		echo json_encode(array('status' => $status));
422 422
 		wp_die();
423 423
 	}
424 424
 
@@ -426,32 +426,32 @@  discard block
 block discarded – undo
426 426
 	* Update product files list
427 427
 	*/
428 428
 	function wps_mass_edit_update_files_list() {
429
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
429
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
430 430
 
431
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) )
431
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list'))
432 432
 			wp_die();
433 433
 
434 434
 		$status = false; $response = '';
435
-		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
436
-		$files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null;
437
-		if( !empty($product_id ) ) {
435
+		$product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null;
436
+		$files = (!empty($_POST['files'])) ? intval($_POST['files']) : null;
437
+		if (!empty($product_id)) {
438 438
 			// Update files datas
439
-			if( !empty($files) ) {
440
-				$files_data = explode( ',', $files );
441
-				if( !empty($files_data) && is_array($files_data) ) {
442
-					foreach( $files_data as $file_id ) {
443
-						if( !empty($file_id) ) {
444
-							wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) );
439
+			if (!empty($files)) {
440
+				$files_data = explode(',', $files);
441
+				if (!empty($files_data) && is_array($files_data)) {
442
+					foreach ($files_data as $file_id) {
443
+						if (!empty($file_id)) {
444
+							wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id));
445 445
 						}
446 446
 					}
447 447
 				}
448 448
 			}
449 449
 
450 450
 
451
-			$response = $this->wps_product_attached_files( $product_id );
451
+			$response = $this->wps_product_attached_files($product_id);
452 452
 			$status = true;
453 453
 		}
454
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
454
+		echo json_encode(array('status' => $status, 'response' => $response));
455 455
 		wp_die();
456 456
 	}
457 457
 
Please login to merge, or discard this patch.
includes/modules/wps_rewrites/wps_rewrites.php 3 patches
Doc Comments   +20 added lines patch added patch discarded remove patch
@@ -78,6 +78,11 @@  discard block
 block discarded – undo
78 78
 			}
79 79
 		}
80 80
 	}
81
+
82
+	/**
83
+	 * @param string $slug
84
+	 * @param string $separator
85
+	 */
81 86
 	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
82 87
 		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
83 88
 		foreach( $childs as $child ) {
@@ -115,6 +120,11 @@  discard block
 block discarded – undo
115 120
 		}
116 121
 		return $permalink;
117 122
 	}
123
+
124
+	/**
125
+	 * @param string $permalink
126
+	 * @param string $separator
127
+	 */
118 128
 	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
119 129
 		if( $term->parent == 0 ) {
120 130
 			$permalink = $term->slug . $separator . $permalink;
@@ -220,6 +230,11 @@  discard block
 block discarded – undo
220 230
 			}
221 231
 		}
222 232
 	}
233
+
234
+	/**
235
+	 * @param string $slug
236
+	 * @param string $separator
237
+	 */
223 238
 	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
224 239
 		$rewrite[] = $slug . $parent->slug . $separator;
225 240
 		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
@@ -281,6 +296,11 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 		return $permalink;
283 298
 	}
299
+
300
+	/**
301
+	 * @param string $permalink
302
+	 * @param string $separator
303
+	 */
284 304
 	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
285 305
 		if( $term->parent == 0 ) {
286 306
 			$permalink = $term->slug . $separator . $permalink;
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 // Rewrite wpshop_categories
4
-$options = get_option( 'wpshop_catalog_categories_option', null );
4
+$options = get_option('wpshop_catalog_categories_option', null);
5 5
 $slug = !empty($options['wpshop_catalog_categories_slug']) ? $options['wpshop_catalog_categories_slug'] : WPSHOP_CATALOG_PRODUCT_NO_CATEGORY;
6
-( empty( $options['wpshop_catalog_categories_slug'] ) || $options['wpshop_catalog_categories_slug'] == '/' ) ? new Custom_Taxonomy_Rewrite( WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $slug, false ) : false;
6
+(empty($options['wpshop_catalog_categories_slug']) || $options['wpshop_catalog_categories_slug'] == '/') ? new Custom_Taxonomy_Rewrite(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $slug, false) : false;
7 7
 
8 8
 // Rewrite wpshop_products
9
-$options = get_option( 'wpshop_catalog_product_option', null );
10
-$slug = !empty( $options['wpshop_catalog_product_slug'] ) ? $options['wpshop_catalog_product_slug'] : '/';
11
-$categories = !empty( $options['wpshop_catalog_product_slug_with_category'] );
12
-( empty( $options['wpshop_catalog_product_slug'] ) || $options['wpshop_catalog_product_slug'] == '/' ) ? new Custom_Post_Type_Rewrite( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, $slug, $categories ) : false;
9
+$options = get_option('wpshop_catalog_product_option', null);
10
+$slug = !empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : '/';
11
+$categories = !empty($options['wpshop_catalog_product_slug_with_category']);
12
+(empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') ? new Custom_Post_Type_Rewrite(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, $slug, $categories) : false;
13 13
 
14 14
 class Custom_Taxonomy_Rewrite {
15 15
 	private $post_type;
@@ -17,95 +17,95 @@  discard block
 block discarded – undo
17 17
 	private $enable_rewrites;
18 18
 	private $use_slug;
19 19
 	private $use_hierarchy_cat_slug;
20
-	public function __construct( $taxonomy, $post_type, $slug = '/', $hierarchy = false ) {
20
+	public function __construct($taxonomy, $post_type, $slug = '/', $hierarchy = false) {
21 21
 		$this->post_type = $post_type;
22 22
 		$this->taxonomy = $taxonomy;
23 23
 		$this->use_slug = $slug;
24 24
 		$this->use_hierarchy_cat_slug = $hierarchy;
25
-		add_action( 'init', array( $this, 'rewrite' ), 11 );
26
-		add_action( 'created_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
27
-		add_action( 'edited_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
28
-		add_action( 'delete_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
29
-		add_filter( 'term_link', array( $this, 'permalink' ), 10, 3 );
25
+		add_action('init', array($this, 'rewrite'), 11);
26
+		add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite'));
27
+		add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite'));
28
+		add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite'));
29
+		add_filter('term_link', array($this, 'permalink'), 10, 3);
30 30
 	}
31 31
 	public function rewrite() {
32 32
 		global $wp_rewrite;
33 33
 		$this->enable_rewrites = $wp_rewrite->use_trailing_slashes;
34
-		if( $this->enable_rewrites ) {
35
-			if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
36
-				if( $this->use_hierarchy_cat_slug ) {
34
+		if ($this->enable_rewrites) {
35
+			if (empty($this->use_slug) || $this->use_slug == '/') {
36
+				if ($this->use_hierarchy_cat_slug) {
37 37
 					$slug = '';
38 38
 					$rewrite = array();
39
-					$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
40
-					foreach( $terms as $term ) {
41
-						$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
39
+					$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
40
+					foreach ($terms as $term) {
41
+						$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
42 42
 					}
43
-					foreach( $rewrite as $way ) {
44
-						add_rewrite_rule( $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
45
-						add_rewrite_rule( $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
46
-						add_rewrite_rule( $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
47
-						add_rewrite_rule( $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
43
+					foreach ($rewrite as $way) {
44
+						add_rewrite_rule($way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
45
+						add_rewrite_rule($way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
46
+						add_rewrite_rule($way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
47
+						add_rewrite_rule($way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
48 48
 					}
49 49
 				} else {
50
-					$terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) );
51
-					foreach( $terms as $term ) {
52
-						add_rewrite_rule( '(' . $term . ')/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
53
-						add_rewrite_rule( '(' . $term . ')/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
54
-						add_rewrite_rule( '(' . $term . ')/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
55
-						add_rewrite_rule( '(' . $term . ')/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
50
+					$terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false));
51
+					foreach ($terms as $term) {
52
+						add_rewrite_rule('(' . $term . ')/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
53
+						add_rewrite_rule('(' . $term . ')/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
54
+						add_rewrite_rule('(' . $term . ')/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
55
+						add_rewrite_rule('(' . $term . ')/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
56 56
 					}
57 57
 				}
58 58
 			} else {
59
-				if( $this->use_hierarchy_cat_slug ) {
59
+				if ($this->use_hierarchy_cat_slug) {
60 60
 					$slug = '/';
61 61
 					$rewrite = array();
62
-					$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
63
-					foreach( $terms as $term ) {
64
-						$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
62
+					$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
63
+					foreach ($terms as $term) {
64
+						$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
65 65
 					}
66
-					foreach( $rewrite as $way ) {
67
-						add_rewrite_rule( $this->use_slug . $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
68
-						add_rewrite_rule( $this->use_slug . $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
69
-						add_rewrite_rule( $this->use_slug . $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
70
-						add_rewrite_rule( $this->use_slug . $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
66
+					foreach ($rewrite as $way) {
67
+						add_rewrite_rule($this->use_slug . $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
68
+						add_rewrite_rule($this->use_slug . $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
69
+						add_rewrite_rule($this->use_slug . $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
70
+						add_rewrite_rule($this->use_slug . $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
71 71
 					}
72 72
 				} else {
73
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
74
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
75
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
76
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
73
+					add_rewrite_rule($this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
74
+					add_rewrite_rule($this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
75
+					add_rewrite_rule($this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
76
+					add_rewrite_rule($this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
77 77
 				}
78 78
 			}
79 79
 		}
80 80
 	}
81
-	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
82
-		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
83
-		foreach( $childs as $child ) {
84
-			$this->rewrite_term_hierarchy( $child, $rewrite, $slug . $parent->slug . $separator, $separator );
81
+	private function rewrite_term_hierarchy($parent, &$rewrite, $slug, $separator) {
82
+		$childs = get_terms($this->taxonomy, array('parent' => $parent->term_id, 'hide_empty' => false));
83
+		foreach ($childs as $child) {
84
+			$this->rewrite_term_hierarchy($child, $rewrite, $slug . $parent->slug . $separator, $separator);
85 85
 		}
86 86
 		$rewrite[] = $slug . '(' . $parent->slug . ')' . $separator;
87 87
 	}
88 88
 	public function flush_rewrite() {
89
-		if( $this->enable_rewrites ) {
89
+		if ($this->enable_rewrites) {
90 90
 			$this->rewrite();
91 91
 			flush_rewrite_rules();
92 92
 		}
93 93
 	}
94
-	public function permalink( $permalink, $term, $taxonomy ) {
95
-		if( $this->enable_rewrites ) {
96
-			if( $taxonomy === $this->taxonomy ) {
97
-				if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
98
-					if( $this->use_hierarchy_cat_slug ) {
94
+	public function permalink($permalink, $term, $taxonomy) {
95
+		if ($this->enable_rewrites) {
96
+			if ($taxonomy === $this->taxonomy) {
97
+				if (empty($this->use_slug) || $this->use_slug == '/') {
98
+					if ($this->use_hierarchy_cat_slug) {
99 99
 						$term_permalink = '';
100
-						$this->permalink_term_hierarchy( $term, $term_permalink, $taxonomy, '/' );
100
+						$this->permalink_term_hierarchy($term, $term_permalink, $taxonomy, '/');
101 101
 						$permalink = get_site_url() . '/' . $term_permalink;
102 102
 					} else {
103 103
 						$permalink = get_site_url() . '/' . $term->slug;
104 104
 					}
105 105
 				} else {
106
-					if( $this->use_hierarchy_cat_slug ) {
106
+					if ($this->use_hierarchy_cat_slug) {
107 107
 						$term_permalink = '';
108
-						$this->permalink_term_hierarchy( $term, $term_permalink, $taxonomy, '/' );
108
+						$this->permalink_term_hierarchy($term, $term_permalink, $taxonomy, '/');
109 109
 						$permalink = get_site_url() . '/' . $this->use_slug . '/' . $term_permalink;
110 110
 					} else {
111 111
 						$permalink = get_site_url() . '/' . $this->use_slug . '/' . $term->slug;
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 		}
116 116
 		return $permalink;
117 117
 	}
118
-	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
119
-		if( $term->parent == 0 ) {
118
+	private function permalink_term_hierarchy($term, &$permalink, $taxonomy, $separator) {
119
+		if ($term->parent == 0) {
120 120
 			$permalink = $term->slug . $separator . $permalink;
121 121
 		} else {
122 122
 			$permalink = $term->slug . $separator . $permalink;
123
-			$term_parent = get_term( $term->parent, $taxonomy );
124
-			$this->permalink_term_hierarchy( $term_parent, $permalink, $taxonomy, $separator );
123
+			$term_parent = get_term($term->parent, $taxonomy);
124
+			$this->permalink_term_hierarchy($term_parent, $permalink, $taxonomy, $separator);
125 125
 		}
126 126
 	}
127 127
 }
@@ -133,122 +133,122 @@  discard block
 block discarded – undo
133 133
 	private $use_slug;
134 134
 	private $use_cat_slug;
135 135
 	private $use_hierarchy_cat_slug;
136
-	public function __construct( $post_type, $taxonomy, $slug = '/', $categories = false ) {
136
+	public function __construct($post_type, $taxonomy, $slug = '/', $categories = false) {
137 137
 		$this->post_type = $post_type;
138 138
 		$this->taxonomy = $taxonomy;
139 139
 		$this->use_slug = $slug;
140
-		if( is_bool( $categories ) ) {
140
+		if (is_bool($categories)) {
141 141
 			$this->use_cat_slug = $categories;
142 142
 			$this->use_hierarchy_cat_slug = false;
143
-		} elseif( $categories == 'hierarchy' ) {
143
+		} elseif ($categories == 'hierarchy') {
144 144
 			$this->use_cat_slug = true;
145 145
 			$this->use_hierarchy_cat_slug = true;
146 146
 		}
147
-		add_action( 'init', array( $this, 'rewrite' ), 11 );
148
-		add_action( 'created_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
149
-		add_action( 'edited_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
150
-		add_action( 'delete_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
151
-		add_filter( 'post_type_link', array( $this, 'permalink' ), 10, 3 );
152
-		add_action( 'pre_get_posts', array( $this, 'query' ) );
147
+		add_action('init', array($this, 'rewrite'), 11);
148
+		add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite'));
149
+		add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite'));
150
+		add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite'));
151
+		add_filter('post_type_link', array($this, 'permalink'), 10, 3);
152
+		add_action('pre_get_posts', array($this, 'query'));
153 153
 	}
154 154
 	public function rewrite() {
155 155
 		global $wp_rewrite;
156 156
 		$this->enable_rewrites = $wp_rewrite->use_trailing_slashes;
157
-		if( $this->enable_rewrites ) {
158
-			if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
159
-				if( $this->use_cat_slug ) {
160
-					if( $this->use_hierarchy_cat_slug ) {
157
+		if ($this->enable_rewrites) {
158
+			if (empty($this->use_slug) || $this->use_slug == '/') {
159
+				if ($this->use_cat_slug) {
160
+					if ($this->use_hierarchy_cat_slug) {
161 161
 						add_rewrite_tag('%taxonomies%', '(.*)');
162 162
 						$slug = '(';
163 163
 						$rewrite = array();
164
-						$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
165
-						foreach( $terms as $term ) {
166
-							$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
164
+						$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
165
+						foreach ($terms as $term) {
166
+							$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
167 167
 						}
168
-						foreach( array_reverse( $rewrite ) as $way ) {
169
-							add_rewrite_rule( $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
170
-							add_rewrite_rule( $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
171
-							add_rewrite_rule( $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
172
-							add_rewrite_rule( $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
168
+						foreach (array_reverse($rewrite) as $way) {
169
+							add_rewrite_rule($way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
170
+							add_rewrite_rule($way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
171
+							add_rewrite_rule($way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
172
+							add_rewrite_rule($way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
173 173
 						}
174 174
 					} else {
175 175
 						add_rewrite_tag('%taxonomies%', '(.*)');
176
-						$terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) );
177
-						foreach( $terms as $term ) {
178
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
179
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
180
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
181
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
176
+						$terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false));
177
+						foreach ($terms as $term) {
178
+							add_rewrite_rule('(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
179
+							add_rewrite_rule('(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
180
+							add_rewrite_rule('(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
181
+							add_rewrite_rule('(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
182 182
 						}
183 183
 					}
184 184
 				} /*else {
185 185
 					Only in the query func
186 186
 				} */
187 187
 			} else {
188
-				if( $this->use_cat_slug ) {
189
-					if( $this->use_hierarchy_cat_slug ) {
188
+				if ($this->use_cat_slug) {
189
+					if ($this->use_hierarchy_cat_slug) {
190 190
 						add_rewrite_tag('%taxonomies%', '(.*)');
191 191
 						$slug = '/(';
192 192
 						$rewrite = array();
193
-						$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
194
-						foreach( $terms as $term ) {
195
-							$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
193
+						$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
194
+						foreach ($terms as $term) {
195
+							$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
196 196
 						}
197
-						foreach( array_reverse( $rewrite ) as $way ) {
198
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
199
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
200
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
201
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
197
+						foreach (array_reverse($rewrite) as $way) {
198
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
199
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
200
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
201
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
202 202
 						}
203 203
 					} else {
204 204
 						add_rewrite_tag('%taxonomies%', '(.*)');
205
-						$terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) );
206
-						foreach( $terms as $term ) {
207
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
208
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
209
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
210
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
205
+						$terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false));
206
+						foreach ($terms as $term) {
207
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
208
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
209
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
210
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
211 211
 						}
212 212
 					}
213 213
 				} else {
214
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top' );
215
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top' );
216
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->post_type . '=$matches[1]&paged=$matches[2]', 'top' );
217
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->post_type . '=$matches[1]', 'top' );
214
+					add_rewrite_rule($this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top');
215
+					add_rewrite_rule($this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top');
216
+					add_rewrite_rule($this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->post_type . '=$matches[1]&paged=$matches[2]', 'top');
217
+					add_rewrite_rule($this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->post_type . '=$matches[1]', 'top');
218 218
 					//'rewrite' => array( 'slug' => $this->post_type ) || true
219 219
 				}
220 220
 			}
221 221
 		}
222 222
 	}
223
-	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
223
+	private function rewrite_term_hierarchy($parent, &$rewrite, $slug, $separator) {
224 224
 		$rewrite[] = $slug . $parent->slug . $separator;
225
-		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
226
-		foreach( $childs as $child ) {
227
-			$this->rewrite_term_hierarchy( $child, $rewrite, $slug . $parent->slug . $separator, $separator );
225
+		$childs = get_terms($this->taxonomy, array('parent' => $parent->term_id, 'hide_empty' => false));
226
+		foreach ($childs as $child) {
227
+			$this->rewrite_term_hierarchy($child, $rewrite, $slug . $parent->slug . $separator, $separator);
228 228
 		}
229 229
 	}
230 230
 	public function flush_rewrite() {
231
-		if( $this->enable_rewrites ) {
231
+		if ($this->enable_rewrites) {
232 232
 			$this->rewrite();
233 233
 			flush_rewrite_rules();
234 234
 		}
235 235
 	}
236
-	public function permalink( $permalink, $post, $leavename ) {
237
-		if( $this->enable_rewrites ) {
238
-			if( $post->post_type == $this->post_type ) {
239
-				if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
240
-					if( $this->use_cat_slug ) {
241
-						if( $this->use_hierarchy_cat_slug ) {
242
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
243
-							if( !empty( $terms ) ) {
236
+	public function permalink($permalink, $post, $leavename) {
237
+		if ($this->enable_rewrites) {
238
+			if ($post->post_type == $this->post_type) {
239
+				if (empty($this->use_slug) || $this->use_slug == '/') {
240
+					if ($this->use_cat_slug) {
241
+						if ($this->use_hierarchy_cat_slug) {
242
+							$terms = get_the_terms($post->ID, $this->taxonomy);
243
+							if (!empty($terms)) {
244 244
 								$term = $terms[0];
245 245
 								$post_permalink = '';
246
-								$this->permalink_term_hierarchy( $term, $post_permalink, $this->taxonomy, '/' );
246
+								$this->permalink_term_hierarchy($term, $post_permalink, $this->taxonomy, '/');
247 247
 								$permalink = get_site_url() . '/' . $post_permalink . $post->post_name . '/';
248 248
 							}
249 249
 						} else {
250
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
251
-							if( !empty( $terms ) ) {
250
+							$terms = get_the_terms($post->ID, $this->taxonomy);
251
+							if (!empty($terms)) {
252 252
 								$term = $terms[0];
253 253
 								$permalink = get_site_url() . '/' . $term->slug . '/' . $post->post_name . '/';
254 254
 							}
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
 						$permalink = get_site_url() . '/' . $post->post_name . '/';
258 258
 					}
259 259
 				} else {
260
-					if( $this->use_cat_slug ) {
261
-						if( $this->use_hierarchy_cat_slug ) {
262
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
263
-							if( !empty( $terms ) ) {
260
+					if ($this->use_cat_slug) {
261
+						if ($this->use_hierarchy_cat_slug) {
262
+							$terms = get_the_terms($post->ID, $this->taxonomy);
263
+							if (!empty($terms)) {
264 264
 								$term = $terms[0];
265 265
 								$post_permalink = '';
266
-								$this->permalink_term_hierarchy( $term, $post_permalink, $this->taxonomy, '/' );
266
+								$this->permalink_term_hierarchy($term, $post_permalink, $this->taxonomy, '/');
267 267
 								$permalink = get_site_url() . '/' . $this->use_slug . '/' . $post_permalink . $post->post_name . '/';
268 268
 							}
269 269
 						} else {
270
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
271
-							if( !empty( $terms ) ) {
270
+							$terms = get_the_terms($post->ID, $this->taxonomy);
271
+							if (!empty($terms)) {
272 272
 								$term = $terms[0];
273 273
 								$permalink = get_site_url() . '/' . $this->use_slug . '/' . $term->slug . '/' . $post->post_name . '/';
274 274
 							}
@@ -281,20 +281,20 @@  discard block
 block discarded – undo
281 281
 		}
282 282
 		return $permalink;
283 283
 	}
284
-	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
285
-		if( $term->parent == 0 ) {
284
+	private function permalink_term_hierarchy($term, &$permalink, $taxonomy, $separator) {
285
+		if ($term->parent == 0) {
286 286
 			$permalink = $term->slug . $separator . $permalink;
287 287
 		} else {
288 288
 			$permalink = $term->slug . $separator . $permalink;
289
-			$term_parent = get_term( $term->parent, $taxonomy );
290
-			$this->permalink_term_hierarchy( $term_parent, $permalink, $taxonomy, $separator );
289
+			$term_parent = get_term($term->parent, $taxonomy);
290
+			$this->permalink_term_hierarchy($term_parent, $permalink, $taxonomy, $separator);
291 291
 		}
292 292
 	}
293
-	public function query( $query ) {
294
-		if( $this->enable_rewrites ) {
295
-			if ( empty( $this->use_slug ) || $this->use_slug == '/' && !$this->use_cat_slug ) {
296
-				if ( !is_admin() && $query->is_main_query() && !isset( $query->page ) && count( $query->query ) == 2 ) {
297
-					$query->set('post_type', array( 'page', 'post', $this->post_type ) );
293
+	public function query($query) {
294
+		if ($this->enable_rewrites) {
295
+			if (empty($this->use_slug) || $this->use_slug == '/' && !$this->use_cat_slug) {
296
+				if (!is_admin() && $query->is_main_query() && !isset($query->page) && count($query->query) == 2) {
297
+					$query->set('post_type', array('page', 'post', $this->post_type));
298 298
 				}
299 299
 			}
300 300
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 
3 5
 // Rewrite wpshop_categories
4 6
 $options = get_option( 'wpshop_catalog_categories_option', null );
Please login to merge, or discard this patch.
includes/modules/wps_search/controller/wps_filter_search.php 4 patches
Doc Comments   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -131,6 +131,7 @@  discard block
 block discarded – undo
131 131
 	/**
132 132
 	 * Construct the element when it's a text Data
133 133
 	 * @param StdObject $attribute_def
134
+	 * @param integer $category_id
134 135
 	 * @return string
135 136
 	 */
136 137
 	function get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_child  ) {
@@ -155,6 +156,7 @@  discard block
 block discarded – undo
155 156
 	/**
156 157
 	 * Construct the element when it's a list Data
157 158
 	 * @param StdObject $attribute_def
159
+	 * @param integer $category_id
158 160
 	 * @return string
159 161
 	 */
160 162
 	function get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') {
@@ -241,6 +243,7 @@  discard block
 block discarded – undo
241 243
 	/**
242 244
 	 * Construct the element when it's a decimal Data
243 245
 	 * @param StdObject $attribute_def
246
+	 * @param integer $category_id
244 247
 	 * @return string
245 248
 	 */
246 249
 	function get_filter_element_for_integer_data ( $attribute_def, $category_id, $current_category_children  ) {
@@ -268,7 +271,7 @@  discard block
 block discarded – undo
268 271
 	 * Save Products attribute values for List attribute data for a products category
269 272
 	 * @param integer $category_id
270 273
 	 * @param std_object $attribute_def
271
-	 * @param array $current_category_child
274
+	 * @param array $current_category_children
272 275
 	 */
273 276
 	function save_values_for_list_filterable_attribute( $category_id, $attribute_def, $current_category_children ) {
274 277
 		global $wpdb;
@@ -462,7 +465,6 @@  discard block
 block discarded – undo
462 465
 
463 466
 	/**
464 467
 	 * Save values for attributes
465
-	 * @param unknown_type $values
466 468
 	 */
467 469
 	function stock_values_for_attribute( $categories_id = array() ) {
468 470
 		@set_time_limit( 900 );
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 class wps_filter_search {
3 3
 
4 4
 	/** Define the main directory containing the template for the current plugin
5
-	* @var string
6
-	*/
5
+	 * @var string
6
+	 */
7 7
 	private $template_dir;
8 8
 	/**
9 9
 	 * Define the directory name for the module in order to check into frontend
Please login to merge, or discard this patch.
Spacing   +230 added lines, -230 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
 class wps_filter_search {
3 3
 
4 4
 	/** Define the main directory containing the template for the current plugin
@@ -16,24 +16,24 @@  discard block
 block discarded – undo
16 16
 		// Template Load
17 17
 		$this->template_dir = WPS_SEARCH_PATH . WPS_SEARCH_DIR . "/templates/";
18 18
 		// Display Filter search
19
-		add_shortcode('wpshop_filter_search', array( $this, 'display_filter_search'));
19
+		add_shortcode('wpshop_filter_search', array($this, 'display_filter_search'));
20 20
 
21 21
 		// WP General actions
22 22
 		add_action('save_post', 'wps_filter_search::save_displayed_price_meta');
23 23
 		add_action('save_post', array(&$this, 'stock_values_for_attribute'));
24 24
 
25 25
 		// Add scripts
26
-		add_action( 'wp_enqueue_scripts', array( &$this, 'add_frontend_scripts' ) );
26
+		add_action('wp_enqueue_scripts', array(&$this, 'add_frontend_scripts'));
27 27
 
28 28
 		// Ajax Actions
29
-		add_action('wp_ajax_filter_search_action',array(&$this, 'wpshop_ajax_filter_search_action'));
30
-		add_action('wp_ajax_nopriv_filter_search_action',array(&$this, 'wpshop_ajax_filter_search_action'));
29
+		add_action('wp_ajax_filter_search_action', array(&$this, 'wpshop_ajax_filter_search_action'));
30
+		add_action('wp_ajax_nopriv_filter_search_action', array(&$this, 'wpshop_ajax_filter_search_action'));
31 31
 	}
32 32
 
33 33
 
34 34
 	function add_frontend_scripts() {
35
-		wp_enqueue_script( 'wpshop_filter_search_chosen', WPSHOP_JS_URL.'jquery-libs/chosen.jquery.min.js' );
36
-		wp_enqueue_script( 'wpshop_filter_search_js', WPS_SEARCH_URL.WPS_SEARCH_DIR.'/assets/filter_search/js/wpshop_filter_search.js' );
35
+		wp_enqueue_script('wpshop_filter_search_chosen', WPSHOP_JS_URL . 'jquery-libs/chosen.jquery.min.js');
36
+		wp_enqueue_script('wpshop_filter_search_js', WPS_SEARCH_URL . WPS_SEARCH_DIR . '/assets/filter_search/js/wpshop_filter_search.js');
37 37
 	}
38 38
 
39 39
 
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 	 * Display Filter search interface
42 42
 	 * @return string
43 43
 	 */
44
-	function display_filter_search () {
44
+	function display_filter_search() {
45 45
 		global $wp_query;
46 46
 		$output = '';
47
-		if ( !empty($wp_query) && !empty($wp_query->queried_object_id) ) {
47
+		if (!empty($wp_query) && !empty($wp_query->queried_object_id)) {
48 48
 			$category_id = $wp_query->queried_object_id;
49
-			$category_option =  get_option('wpshop_product_category_'.$category_id);
50
-			if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) ) {
51
-				$output = $this->construct_wpshop_filter_search_interface( $category_id );
49
+			$category_option = get_option('wpshop_product_category_' . $category_id);
50
+			if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes'])) {
51
+				$output = $this->construct_wpshop_filter_search_interface($category_id);
52 52
 			}
53 53
 		}
54 54
 		return $output;
@@ -59,19 +59,19 @@  discard block
 block discarded – undo
59 59
 	 * @param integer $category_id
60 60
 	 * @return string
61 61
 	 */
62
-	function construct_wpshop_filter_search_interface ( $category_id ) {
62
+	function construct_wpshop_filter_search_interface($category_id) {
63 63
 		global $wpdb;
64 64
 		$filter_elements = '';
65
-		if ( !empty($category_id) ) {
66
-			$category_option =  get_option('wpshop_product_category_'.$category_id);
67
-			if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes']) ) {
68
-				foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $attribute ) {
65
+		if (!empty($category_id)) {
66
+			$category_option = get_option('wpshop_product_category_' . $category_id);
67
+			if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes'])) {
68
+				foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $attribute) {
69 69
 					$attribute_def = wpshop_attributes::getElement($k);
70
-					$filter_elements .= $this->construct_element( $attribute_def, $category_id );
70
+					$filter_elements .= $this->construct_element($attribute_def, $category_id);
71 71
 					$unity = '';
72
-					if ( !empty($attribute_def->_default_unit) ) {
73
-						$query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id= %d', $attribute_def->_default_unit);
74
-						$unity = $wpdb->get_var( $query );
72
+					if (!empty($attribute_def->_default_unit)) {
73
+						$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id= %d', $attribute_def->_default_unit);
74
+						$unity = $wpdb->get_var($query);
75 75
 					}
76 76
 
77 77
 					//$tpl_component['DEFAULT_UNITY'.'_'.$attribute_def->code] = $unity;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 			}
80 80
 		}
81 81
 		ob_start();
82
-		require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_search_interface") );
82
+		require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_search_interface"));
83 83
 		$filter_search_interface = ob_get_contents();
84 84
 		ob_end_clean();
85 85
 		return $filter_search_interface;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @param integer $category_id
92 92
 	 * @return string
93 93
 	 */
94
-	function construct_element ( $attribute_def, $category_id ) {
94
+	function construct_element($attribute_def, $category_id) {
95 95
 		global $wpdb;
96 96
 		$current_category_children = array();
97 97
 		$args = array(
@@ -101,27 +101,27 @@  discard block
 block discarded – undo
101 101
 		);
102 102
 		$current_category_children = get_categories($args);
103 103
 
104
-		if ( !empty( $attribute_def ) ) {
105
-			switch ( $attribute_def->frontend_input ) {
104
+		if (!empty($attribute_def)) {
105
+			switch ($attribute_def->frontend_input) {
106 106
 				case 'text' :
107
-					if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') {
108
-						return $this->get_filter_element_for_integer_data( $attribute_def, $category_id, $current_category_children );
107
+					if ($attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') {
108
+						return $this->get_filter_element_for_integer_data($attribute_def, $category_id, $current_category_children);
109 109
 					}
110 110
 					else {
111
-						return $this->get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_children );
111
+						return $this->get_filter_element_for_text_data($attribute_def, $category_id, $current_category_children);
112 112
 					}
113 113
 					break;
114 114
 
115 115
 				case 'select' : case 'multiple-select' :
116
-					return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'select');
116
+					return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'select');
117 117
 				break;
118 118
 
119 119
 				case 'checkbox' :
120
-					return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'checkbox');
120
+					return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'checkbox');
121 121
 				break;
122 122
 
123 123
 				case 'radio' :
124
-					return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'radio' );
124
+					return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'radio');
125 125
 				break;
126 126
 
127 127
 			}
@@ -133,20 +133,20 @@  discard block
 block discarded – undo
133 133
 	 * @param StdObject $attribute_def
134 134
 	 * @return string
135 135
 	 */
136
-	function get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_child  ) {
136
+	function get_filter_element_for_text_data($attribute_def, $category_id, $current_category_child) {
137 137
 		global $wpdb;
138 138
 		$output = '';
139
-		$category_option = get_option('wpshop_product_category_'.$category_id);
139
+		$category_option = get_option('wpshop_product_category_' . $category_id);
140 140
 		$list_values = '';
141 141
 
142
-		if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) && is_array($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) {
143
-			foreach( $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] as $attribute_value ) {
144
-				$list_values .= '<option value="' .$attribute_value. '">' .$attribute_value. '</option>';
142
+		if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) && is_array($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
143
+			foreach ($category_option['wpshop_category_filterable_attributes'][$attribute_def->id] as $attribute_value) {
144
+				$list_values .= '<option value="' . $attribute_value . '">' . $attribute_value . '</option>';
145 145
 			}
146 146
 
147 147
 		}
148 148
 		ob_start();
149
-		require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") );
149
+		require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox"));
150 150
 		$output = ob_get_contents();
151 151
 		ob_end_clean();
152 152
 		return $output;
@@ -157,77 +157,77 @@  discard block
 block discarded – undo
157 157
 	 * @param StdObject $attribute_def
158 158
 	 * @return string
159 159
 	 */
160
-	function get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') {
160
+	function get_filter_element_for_list_data($attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') {
161 161
 		global $wpdb;
162 162
 		$output = $list_values = '';
163
-		$category_option = get_option('wpshop_product_category_'.$category_id);
164
-		if ( !empty( $attribute_def) ){
163
+		$category_option = get_option('wpshop_product_category_' . $category_id);
164
+		if (!empty($attribute_def)) {
165 165
 			// Recovery values
166
-			if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) {
166
+			if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
167 167
 				$available_attribute_values = $category_option['wpshop_category_filterable_attributes'][$attribute_def->id];
168 168
 			}
169 169
 
170 170
 			// Store options for attribute
171 171
 			$stored_available_attribute_values = array();
172
-			$query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS .' WHERE attribute_id = %d ORDER BY position ASC', $attribute_def->id);
173
-			$attributes_options = $wpdb->get_results( $query );
174
-			if ( $attribute_def->data_type_to_use == 'internal') {
175
-				if ( !empty( $attribute_def->default_value ) ) {
172
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d ORDER BY position ASC', $attribute_def->id);
173
+			$attributes_options = $wpdb->get_results($query);
174
+			if ($attribute_def->data_type_to_use == 'internal') {
175
+				if (!empty($attribute_def->default_value)) {
176 176
 					$attribute_default_value = $attribute_def->default_value;
177 177
 					$attribute_default_value = unserialize($attribute_default_value);
178 178
 
179
-					$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_type = %s ORDER BY menu_order ASC', $attribute_default_value['default_value']);
180
-					$elements = $wpdb->get_results( $query );
179
+					$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s ORDER BY menu_order ASC', $attribute_default_value['default_value']);
180
+					$elements = $wpdb->get_results($query);
181 181
 
182
-					if ( !empty( $elements) ) {
183
-						foreach ( $elements as $element ) {
184
-							if ( array_key_exists($element->ID,$available_attribute_values ) ) {
185
-								$stored_available_attribute_values[] = array( 'option_id' => $element->ID, 'option_label' => $element->post_title );
182
+					if (!empty($elements)) {
183
+						foreach ($elements as $element) {
184
+							if (array_key_exists($element->ID, $available_attribute_values)) {
185
+								$stored_available_attribute_values[] = array('option_id' => $element->ID, 'option_label' => $element->post_title);
186 186
 							}
187 187
 						}
188 188
 					}
189 189
 				}
190 190
 			}
191 191
 			else {
192
-				foreach ( $attributes_options as $attributes_option ) {
193
-					if ( in_array($attributes_option->label, $available_attribute_values) ) {
194
-						$key_value = array_search( $attributes_option->label, $available_attribute_values);
195
-						$stored_available_attribute_values[] = array('option_id' => $key_value, 'option_label' => $attributes_option->label );
192
+				foreach ($attributes_options as $attributes_option) {
193
+					if (in_array($attributes_option->label, $available_attribute_values)) {
194
+						$key_value = array_search($attributes_option->label, $available_attribute_values);
195
+						$stored_available_attribute_values[] = array('option_id' => $key_value, 'option_label' => $attributes_option->label);
196 196
 					}
197 197
 				}
198 198
 			}
199 199
 			// Sort Stored values
200
-			ksort( $stored_available_attribute_values);
201
-			if ( !empty($stored_available_attribute_values) && is_array($stored_available_attribute_values) ) {
200
+			ksort($stored_available_attribute_values);
201
+			if (!empty($stored_available_attribute_values) && is_array($stored_available_attribute_values)) {
202 202
 				// Construct List values
203
-				foreach( $stored_available_attribute_values as $stored_available_attribute_value ) {
204
-					$list_values .= '<option value="' .$stored_available_attribute_value['option_id']. '">' .$stored_available_attribute_value['option_label']. '</option>';
203
+				foreach ($stored_available_attribute_values as $stored_available_attribute_value) {
204
+					$list_values .= '<option value="' . $stored_available_attribute_value['option_id'] . '">' . $stored_available_attribute_value['option_label'] . '</option>';
205 205
 				}
206 206
 
207 207
 				// Display the good template file
208
-				switch( $type ) {
208
+				switch ($type) {
209 209
 					case 'radio' :
210 210
 						ob_start();
211
-						require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_radiobox") );
211
+						require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_radiobox"));
212 212
 						$output = ob_get_contents();
213 213
 						ob_end_clean();
214 214
 					break;
215 215
 					case 'checkbox' :
216 216
 						ob_start();
217
-						require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_checkbox") );
217
+						require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_checkbox"));
218 218
 						$output = ob_get_contents();
219 219
 						ob_end_clean();
220 220
 						break;
221 221
 					default :
222
-						if ( $field_type == 'multiple-select' ) {
222
+						if ($field_type == 'multiple-select') {
223 223
 							ob_start();
224
-							require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select") );
224
+							require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select"));
225 225
 							$output = ob_get_contents();
226 226
 							ob_end_clean();
227 227
 						}
228 228
 						else {
229 229
 							ob_start();
230
-							require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") );
230
+							require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox"));
231 231
 							$output = ob_get_contents();
232 232
 							ob_end_clean();
233 233
 						}
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 	 * @param StdObject $attribute_def
244 244
 	 * @return string
245 245
 	 */
246
-	function get_filter_element_for_integer_data ( $attribute_def, $category_id, $current_category_children  ) {
246
+	function get_filter_element_for_integer_data($attribute_def, $category_id, $current_category_children) {
247 247
 		$min_value = $max_value = 0;
248 248
 		$sub_tpl_component = array();
249 249
 		$output = '';
250 250
 		$first  = true;
251 251
 		/** Get allproducts of category **/
252
-		$category_product_ids = wpshop_categories::get_product_of_category( $category_id );
253
-		$category_option = get_option('wpshop_product_category_'.$category_id );
254
-		$amount_min =  ( !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min']) ) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'],2, '.', '') : 0;
255
-		$amount_max =  ( !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max']) ) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'],2, '.', '') : 0;
252
+		$category_product_ids = wpshop_categories::get_product_of_category($category_id);
253
+		$category_option = get_option('wpshop_product_category_' . $category_id);
254
+		$amount_min = (!empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'])) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'], 2, '.', '') : 0;
255
+		$amount_max = (!empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'])) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'], 2, '.', '') : 0;
256 256
 
257
-		if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) {
257
+		if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
258 258
 			ob_start();
259
-			require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_slider") );
259
+			require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_slider"));
260 260
 			$output = ob_get_contents();
261 261
 			ob_end_clean();
262 262
 
@@ -270,17 +270,17 @@  discard block
 block discarded – undo
270 270
 	 * @param std_object $attribute_def
271 271
 	 * @param array $current_category_child
272 272
 	 */
273
-	function save_values_for_list_filterable_attribute( $category_id, $attribute_def, $current_category_children ) {
273
+	function save_values_for_list_filterable_attribute($category_id, $attribute_def, $current_category_children) {
274 274
 		global $wpdb;
275
-		$category_option = get_option('wpshop_product_category_'.$category_id);
276
-		$products = wpshop_categories::get_product_of_category( $category_id );
275
+		$category_option = get_option('wpshop_product_category_' . $category_id);
276
+		$products = wpshop_categories::get_product_of_category($category_id);
277 277
 		/** If there are sub-categories take all products of sub-categories **/
278
-		if ( !empty($current_category_children) ) {
279
-			foreach ( $current_category_children as $current_category_child ) {
280
-				$sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id );
281
-				if ( !empty($sub_categories_product_ids) ) {
282
-					foreach ( $sub_categories_product_ids as $sub_categories_product_id ) {
283
-						if ( !in_array($sub_categories_product_id, $products) ) {
278
+		if (!empty($current_category_children)) {
279
+			foreach ($current_category_children as $current_category_child) {
280
+				$sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id);
281
+				if (!empty($sub_categories_product_ids)) {
282
+					foreach ($sub_categories_product_ids as $sub_categories_product_id) {
283
+						if (!in_array($sub_categories_product_id, $products)) {
284 284
 							$products[] = $sub_categories_product_id;
285 285
 						}
286 286
 					}
@@ -289,33 +289,33 @@  discard block
 block discarded – undo
289 289
 		}
290 290
 
291 291
 
292
-		if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) {
292
+		if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
293 293
 			$category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = array();
294 294
 		}
295 295
 
296 296
 
297
-		if ( !empty( $attribute_def) ){
297
+		if (!empty($attribute_def)) {
298 298
 			$available_attribute_values = array();
299 299
 			$test = array();
300
-			foreach ( $products as $product ) {
301
-				$available_attribute_values = array_merge( $available_attribute_values, wpshop_attributes::get_affected_value_for_list( $attribute_def->code, $product, $attribute_def->data_type_to_use) ) ;
300
+			foreach ($products as $product) {
301
+				$available_attribute_values = array_merge($available_attribute_values, wpshop_attributes::get_affected_value_for_list($attribute_def->code, $product, $attribute_def->data_type_to_use));
302 302
 			}
303 303
 
304 304
 			$available_attribute_values = array_flip($available_attribute_values);
305 305
 			$data_to_save = array();
306
-			if ( !empty($available_attribute_values) ) {
306
+			if (!empty($available_attribute_values)) {
307 307
 				$data_to_save = array();
308
-				foreach( $available_attribute_values as $k => $available_attribute_value ) {
309
-					if (  $attribute_def->data_type_to_use == 'internal' ) {
310
-						$attribute_name = get_the_title( $k );
308
+				foreach ($available_attribute_values as $k => $available_attribute_value) {
309
+					if ($attribute_def->data_type_to_use == 'internal') {
310
+						$attribute_name = get_the_title($k);
311 311
 					}
312 312
 					else {
313
-						$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k);
313
+						$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k);
314 314
 
315
-						$attribute_name = $wpdb->get_var( $query );
315
+						$attribute_name = $wpdb->get_var($query);
316 316
 					}
317
-					if (!empty($attribute_name) && !empty($k) ) {
318
-						if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) {
317
+					if (!empty($attribute_name) && !empty($k)) {
318
+						if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
319 319
 							$data_to_save[$k] = $attribute_name;
320 320
 							$category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = $data_to_save;
321 321
 						}
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 				}
324 324
 			}
325 325
 		}
326
-		update_option('wpshop_product_category_'.$category_id, $category_option);
326
+		update_option('wpshop_product_category_' . $category_id, $category_option);
327 327
 	}
328 328
 
329 329
 	/**
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
 	 * @param std_object $attribute_def
333 333
 	 * @param array $current_category_child
334 334
 	 */
335
-	function save_values_for_integer_filterable_attribute ( $category_id, $attribute_def, $current_category_child ) {
335
+	function save_values_for_integer_filterable_attribute($category_id, $attribute_def, $current_category_child) {
336 336
 		$first = true;
337
-		$category_option = get_option('wpshop_product_category_'.$category_id);
338
-		$category_product_ids = wpshop_categories::get_product_of_category( $category_id );
337
+		$category_option = get_option('wpshop_product_category_' . $category_id);
338
+		$category_product_ids = wpshop_categories::get_product_of_category($category_id);
339 339
 		$min_value = $max_value = 0;
340 340
 		/** If there are sub-categories take all products of sub-categories **/
341
-		if ( !empty($current_category_children) ) {
342
-			foreach ( $current_category_children as $current_category_child ) {
343
-				$sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id );
344
-				if ( !empty($sub_categories_product_ids) ) {
345
-					foreach ( $sub_categories_product_ids as $sub_categories_product_id ) {
346
-						if ( !in_array($sub_categories_product_id, $category_product_ids) ) {
341
+		if (!empty($current_category_children)) {
342
+			foreach ($current_category_children as $current_category_child) {
343
+				$sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id);
344
+				if (!empty($sub_categories_product_ids)) {
345
+					foreach ($sub_categories_product_ids as $sub_categories_product_id) {
346
+						if (!in_array($sub_categories_product_id, $category_product_ids)) {
347 347
 							$category_product_ids[] = $sub_categories_product_id;
348 348
 						}
349 349
 					}
@@ -352,45 +352,45 @@  discard block
 block discarded – undo
352 352
 		}
353 353
 
354 354
 		/** For each product of category check the value **/
355
-		if ( !empty( $category_product_ids ) ) {
355
+		if (!empty($category_product_ids)) {
356 356
 			$price_piloting_option = get_option('wpshop_shop_price_piloting');
357 357
 			foreach ($category_product_ids as $category_product_id) {
358 358
 
359
-				if ( $attribute_def->code == WPSHOP_PRODUCT_PRICE_TTC || $attribute_def->code == WPSHOP_PRODUCT_PRICE_HT ) {
359
+				if ($attribute_def->code == WPSHOP_PRODUCT_PRICE_TTC || $attribute_def->code == WPSHOP_PRODUCT_PRICE_HT) {
360 360
 
361 361
 					$product_infos = wpshop_products::get_product_data($category_product_id);
362 362
 					$product_price_infos = wpshop_prices::check_product_price($product_infos);
363
-					if (!empty($product_price_infos) && !empty($product_price_infos['fork_price']) && !empty($product_price_infos['fork_price']['have_fork_price']) && $product_price_infos['fork_price']['have_fork_price'] ) {
363
+					if (!empty($product_price_infos) && !empty($product_price_infos['fork_price']) && !empty($product_price_infos['fork_price']['have_fork_price']) && $product_price_infos['fork_price']['have_fork_price']) {
364 364
 
365 365
 
366
-						$max_value = ( !empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value ) ? $product_price_infos['fork_price']['max_product_price'] : $max_value;
367
-						$min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && ( ( $product_price_infos['fork_price']['min_product_price'] < $min_value) || $first ) ) ?  $product_price_infos['fork_price']['min_product_price'] : $min_value;
366
+						$max_value = (!empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value) ? $product_price_infos['fork_price']['max_product_price'] : $max_value;
367
+						$min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && (($product_price_infos['fork_price']['min_product_price'] < $min_value) || $first)) ? $product_price_infos['fork_price']['min_product_price'] : $min_value;
368 368
 					}
369 369
 					else {
370
-						if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist'] ) && $product_price_infos['discount']['discount_exist'] ) {
371
-							$product_data = (!empty($price_piloting_option) &&  $price_piloting_option == 'HT')  ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price'];
370
+						if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist']) && $product_price_infos['discount']['discount_exist']) {
371
+							$product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price'];
372 372
 
373 373
 						}
374 374
 						else {
375 375
 
376
-							$product_data = (!empty($price_piloting_option) &&  $price_piloting_option == 'HT')  ? $product_price_infos['et'] : $product_price_infos['ati'];
376
+							$product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati'];
377 377
 						}
378
-						$max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value;
379
-						$min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first )  ) ?  $product_data : $min_value;
378
+						$max_value = (!empty($product_data) && $product_data > $max_value) ? $product_data : $max_value;
379
+						$min_value = (!empty($product_data) && (($product_data < $min_value) || $first)) ? $product_data : $min_value;
380 380
 					}
381 381
 				}
382 382
 				else {
383 383
 					$product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
384 384
 					$product_data = $product_postmeta[$attribute_def->code];
385
-					$max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value;
386
-					$min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ?  $product_data : $min_value;
385
+					$max_value = (!empty($product_data) && $product_data > $max_value) ? $product_data : $max_value;
386
+					$min_value = (!empty($product_data) && (($product_data < $min_value) || $first)) ? $product_data : $min_value;
387 387
 				}
388 388
 				$first = false;
389 389
 			}
390 390
 			$category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = array('min' => $min_value, 'max' => $max_value);
391 391
 		}
392 392
 		/** Update the category option **/
393
-		update_option('wpshop_product_category_'.$category_id, $category_option);
393
+		update_option('wpshop_product_category_' . $category_id, $category_option);
394 394
 	}
395 395
 
396 396
 	/**
@@ -399,66 +399,66 @@  discard block
 block discarded – undo
399 399
 	 * @param std_object $attribute_def
400 400
 	 * @param array $current_category_child
401 401
 	 */
402
-	function save_values_for_text_filterable_attribute ( $category_id, $attribute_def, $current_category_child ) {
403
-		$category_option = get_option('wpshop_product_category_'.$category_id);
404
-		$category_product_ids = wpshop_categories::get_product_of_category( $category_id );
402
+	function save_values_for_text_filterable_attribute($category_id, $attribute_def, $current_category_child) {
403
+		$category_option = get_option('wpshop_product_category_' . $category_id);
404
+		$category_product_ids = wpshop_categories::get_product_of_category($category_id);
405 405
 		/** If there are sub-categories take all products of sub-categories **/
406 406
 		$list_values = array();
407
-		if ( !empty($current_category_children) ) {
408
-			foreach ( $current_category_children as $current_category_child ) {
409
-				$sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id );
410
-				if ( !empty($sub_categories_product_ids) ) {
411
-					foreach ( $sub_categories_product_ids as $sub_categories_product_id ) {
412
-						if ( !in_array($sub_categories_product_id, $category_product_ids) ) {
407
+		if (!empty($current_category_children)) {
408
+			foreach ($current_category_children as $current_category_child) {
409
+				$sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id);
410
+				if (!empty($sub_categories_product_ids)) {
411
+					foreach ($sub_categories_product_ids as $sub_categories_product_id) {
412
+						if (!in_array($sub_categories_product_id, $category_product_ids)) {
413 413
 							$category_product_ids[] = $sub_categories_product_id;
414 414
 						}
415 415
 					}
416 416
 				}
417 417
 			}
418 418
 		}
419
-		if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) {
420
-			if ( !empty( $category_product_ids ) ) {
419
+		if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
420
+			if (!empty($category_product_ids)) {
421 421
 				$product_data = '';
422
-				foreach ( $category_product_ids as $category_product_id ) {
422
+				foreach ($category_product_ids as $category_product_id) {
423 423
 					$product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
424
-					$product_data = ( !empty($product_postmeta[$attribute_def->code]) ) ? $product_postmeta[$attribute_def->code] : '';
425
-					if ( !in_array( $product_data,  $list_values) ) {
424
+					$product_data = (!empty($product_postmeta[$attribute_def->code])) ? $product_postmeta[$attribute_def->code] : '';
425
+					if (!in_array($product_data, $list_values)) {
426 426
 						$list_values[] = $product_data;
427
-						if ( !empty($product_data) ) {
427
+						if (!empty($product_data)) {
428 428
 							$category_option['wpshop_category_filterable_attributes'][$attribute_def->id][] = $product_data;
429 429
 						}
430 430
 					}
431 431
 				}
432 432
 			}
433 433
 		}
434
-		update_option('wpshop_product_category_'.$category_id, $category_option);
434
+		update_option('wpshop_product_category_' . $category_id, $category_option);
435 435
 	}
436 436
 
437 437
 	/**
438 438
 	 * Save the price which is displayed on website
439 439
 	 */
440
-	public static function save_displayed_price_meta( $product_id = 0 ) {
441
-		$ID = !empty( $_POST['ID'] ) ? (int) $_POST['ID'] : 0;
442
-		$post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : '';
440
+	public static function save_displayed_price_meta($product_id = 0) {
441
+		$ID = !empty($_POST['ID']) ? (int)$_POST['ID'] : 0;
442
+		$post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : '';
443 443
 
444
-		if ( !empty( $product_id ) || ( !empty( $ID ) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) ) {
445
-			$product_id = !empty( $product_id ) ? $product_id : $ID;
444
+		if (!empty($product_id) || (!empty($ID) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)) {
445
+			$product_id = !empty($product_id) ? $product_id : $ID;
446 446
 
447 447
 			$price_piloting = get_option('wpshop_shop_price_piloting');
448 448
 			$product_data = wpshop_products::get_product_data($product_id);
449 449
 			$price_infos = wpshop_prices::check_product_price($product_data);
450 450
 
451
-			if ( !empty($price_infos) ) {
452
-				if ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) ) {
453
-					$displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price'];
451
+			if (!empty($price_infos)) {
452
+				if (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist'])) {
453
+					$displayed_price = (!empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price'];
454 454
 				}
455
-				else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) {
455
+				else if (!empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price'])) {
456 456
 					$displayed_price = $price_infos['fork_price']['min_product_price'];
457 457
 				}
458 458
 				else {
459
-					$displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati'];
459
+					$displayed_price = (!empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati'];
460 460
 				}
461
-				update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price,2, '.','') );
461
+				update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price, 2, '.', ''));
462 462
 			}
463 463
 		}
464 464
 	}
@@ -467,19 +467,19 @@  discard block
 block discarded – undo
467 467
 	 * Save values for attributes
468 468
 	 * @param unknown_type $values
469 469
 	 */
470
-	function stock_values_for_attribute( $categories_id = array() ) {
471
-		@set_time_limit( 900 );
470
+	function stock_values_for_attribute($categories_id = array()) {
471
+		@set_time_limit(900);
472 472
 
473
-		$tax_input = ( !empty( $_POST['tax_input'] ) && !empty( $_POST['tax_input']['wpshop_product_category'] ) ) ? (int) $_POST['tax_input']['wpshop_product_category'] : '';
474
-		$post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : '';
475
-		if (  !empty( $tax_input ) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
473
+		$tax_input = (!empty($_POST['tax_input']) && !empty($_POST['tax_input']['wpshop_product_category'])) ? (int)$_POST['tax_input']['wpshop_product_category'] : '';
474
+		$post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : '';
475
+		if (!empty($tax_input) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
476 476
 			$categories_id = $tax_input;
477 477
 		}
478 478
 
479
-		if ( !empty( $categories_id )  ) {
480
-			if ( $categories_id && is_array($categories_id) ) {
481
-				foreach( $categories_id as $taxonomy_id ) {
482
-					if ( $taxonomy_id != 0 ) {
479
+		if (!empty($categories_id)) {
480
+			if ($categories_id && is_array($categories_id)) {
481
+				foreach ($categories_id as $taxonomy_id) {
482
+					if ($taxonomy_id != 0) {
483 483
 						$current_category_children = array();
484 484
 						$args = array(
485 485
 								'type'		=> WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
 						);
489 489
 						$current_category_children = get_categories($args);
490 490
 
491
-						$category_option = get_option('wpshop_product_category_'.$taxonomy_id);
492
-						if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes']) ) {
493
-							foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $filterable_attribute ) {
491
+						$category_option = get_option('wpshop_product_category_' . $taxonomy_id);
492
+						if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes'])) {
493
+							foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $filterable_attribute) {
494 494
 								$attribute_def = wpshop_attributes::getElement($k);
495
-								if ( !empty( $attribute_def) ) {
496
-									switch ( $attribute_def->frontend_input ) {
495
+								if (!empty($attribute_def)) {
496
+									switch ($attribute_def->frontend_input) {
497 497
 										case 'text' :
498
-											if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') {
499
-												$this->save_values_for_integer_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children );
498
+											if ($attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') {
499
+												$this->save_values_for_integer_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children);
500 500
 											}
501 501
 											else {
502
-												$this->save_values_for_text_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children );
502
+												$this->save_values_for_text_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children);
503 503
 											}
504 504
 											break;
505 505
 
506 506
 										case 'select' : case 'checkbox' : case 'radio' : case 'multiple-select' :
507
-											$this->save_values_for_list_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children );
507
+											$this->save_values_for_list_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children);
508 508
 											break;
509 509
 
510 510
 									}
@@ -522,22 +522,22 @@  discard block
 block discarded – undo
522 522
 	 * @param integer $category_id
523 523
 	 * @return array
524 524
 	 */
525
-	function pick_up_filter_search_elements_type ( $category_id ) {
525
+	function pick_up_filter_search_elements_type($category_id) {
526 526
 		$filter_search_elements = array();
527
-		if ( !empty($category_id) ) {
528
-			$category_option =  get_option('wpshop_product_category_'.$category_id);
529
-			if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) ) {
530
-				foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $attribute ) {
527
+		if (!empty($category_id)) {
528
+			$category_option = get_option('wpshop_product_category_' . $category_id);
529
+			if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes'])) {
530
+				foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $attribute) {
531 531
 					$attribute_def = wpshop_attributes::getElement($k);
532
-					if ( !empty($attribute_def) ) {
533
-						if ( $attribute_def->frontend_input == 'text' ) {
534
-							$filter_search_elements['_'.$attribute_def->code] = array('type' => 'fork_values');
532
+					if (!empty($attribute_def)) {
533
+						if ($attribute_def->frontend_input == 'text') {
534
+							$filter_search_elements['_' . $attribute_def->code] = array('type' => 'fork_values');
535 535
 						}
536
-						elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) {
537
-							$filter_search_elements['_'.$attribute_def->code] = array('type' => 'multiple_select_value');
536
+						elseif (in_array($attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select'))) {
537
+							$filter_search_elements['_' . $attribute_def->code] = array('type' => 'multiple_select_value');
538 538
 						}
539
-						elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) )  {
540
-							$filter_search_elements['_'.$attribute_def->code] = array('type' => 'select_value');
539
+						elseif (!in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password'))) {
540
+							$filter_search_elements['_' . $attribute_def->code] = array('type' => 'select_value');
541 541
 						}
542 542
 					}
543 543
 				}
@@ -549,28 +549,28 @@  discard block
 block discarded – undo
549 549
 	/**
550 550
 	 * AJAX - Action to search with selected attributes values
551 551
 	 */
552
-	function wpshop_ajax_filter_search_action () {
553
-		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
552
+	function wpshop_ajax_filter_search_action() {
553
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
554 554
 
555
-		if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) )
555
+		if (!wp_verify_nonce($_wpnonce, 'wpshop_ajax_filter_search_action'))
556 556
 			wp_die();
557 557
 
558 558
 		global $wpdb;
559
-		$category_id =  !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_category_id'] ) : 0;
559
+		$category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_category_id']) : 0;
560 560
 		$filter_search_elements = $this->pick_up_filter_search_elements_type($category_id);
561
-		$page_id = ( !empty( $_POST['wpshop_filter_search_current_page_id']) ) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_current_page_id'] ) : 1;
561
+		$page_id = (!empty($_POST['wpshop_filter_search_current_page_id'])) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_current_page_id']) : 1;
562 562
 		$request_cmd = '';
563 563
 		$status = false;
564 564
 		$data = array();
565
-		foreach ( $filter_search_elements as $k=>$filter_search_element) {
566
-			$search = isset( $_REQUEST['filter_search'.$k] ) ? sanitize_text_field( $_REQUEST['filter_search'.$k] ) : '';
567
-			$amount_min = !isset( $_REQUEST['amount_min'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_min'.$k] );
568
-			$amount_max = !isset( $_REQUEST['amount_max'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_max'.$k] );
569
-			$datatype_element = array( 'select_value', 'multiple_select_value', 'fork_values');
570
-			if ( (in_array($filter_search_element['type'], $datatype_element) && ( isset($search) && $search == 'all_attribute_values' ) ) ||
571
-				( ($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value' ) &&  $search == '' ) ||
572
-				( $filter_search_element['type'] == 'fork_values' && ( $amount_min == 0 || $amount_max == 0 ) ) ) {
573
-				unset( $filter_search_elements[$k]);
565
+		foreach ($filter_search_elements as $k=>$filter_search_element) {
566
+			$search = isset($_REQUEST['filter_search' . $k]) ? sanitize_text_field($_REQUEST['filter_search' . $k]) : '';
567
+			$amount_min = !isset($_REQUEST['amount_min' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_min' . $k]);
568
+			$amount_max = !isset($_REQUEST['amount_max' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_max' . $k]);
569
+			$datatype_element = array('select_value', 'multiple_select_value', 'fork_values');
570
+			if ((in_array($filter_search_element['type'], $datatype_element) && (isset($search) && $search == 'all_attribute_values')) ||
571
+				(($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value') && $search == '') ||
572
+				($filter_search_element['type'] == 'fork_values' && ($amount_min == 0 || $amount_max == 0))) {
573
+				unset($filter_search_elements[$k]);
574 574
 			}
575 575
 		}
576 576
 		$request_cmd = '';
@@ -589,8 +589,8 @@  discard block
 block discarded – undo
589 589
 		/** Construct the array for SELECT query IN **/
590 590
 		$categories_id = array();
591 591
 		$categories_id[] = $category_id;
592
-		if ( !empty($current_category_children) ) {
593
-			foreach ( $current_category_children as $current_category_child ) {
592
+		if (!empty($current_category_children)) {
593
+			foreach ($current_category_children as $current_category_child) {
594 594
 				$categories_id[] = $current_category_child->term_taxonomy_id;
595 595
 			}
596 596
 		}
@@ -599,55 +599,55 @@  discard block
 block discarded – undo
599 599
 		$array_for_query = implode(',', $categories_id);
600 600
 
601 601
 		/** SQL request Construct for pick up all product with one of filter search element value **/
602
-		if ( !empty( $filter_search_elements ) ) {
603
-			foreach ( $filter_search_elements as $k=>$filter_search_element ) {
604
-				$search = isset( $_REQUEST['filter_search'.$k] ) ? $_REQUEST['filter_search'.$k] : '';
605
-				$amount_min = !isset( $_REQUEST['amount_min'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_min'.$k] );
606
-				$amount_max = !isset( $_REQUEST['amount_max'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_max'.$k] );
607
-
608
-				if ( !empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') {
609
-					$request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON  post_id = ID WHERE (meta_key = "'.$k.'" AND meta_value = "'.$search.'") AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish" ';
610
-					$request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) ';
602
+		if (!empty($filter_search_elements)) {
603
+			foreach ($filter_search_elements as $k=>$filter_search_element) {
604
+				$search = isset($_REQUEST['filter_search' . $k]) ? $_REQUEST['filter_search' . $k] : '';
605
+				$amount_min = !isset($_REQUEST['amount_min' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_min' . $k]);
606
+				$amount_max = !isset($_REQUEST['amount_max' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_max' . $k]);
607
+
608
+				if (!empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') {
609
+					$request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON  post_id = ID WHERE (meta_key = "' . $k . '" AND meta_value = "' . $search . '") AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish" ';
610
+					$request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) ';
611 611
 				}
612
-				else if($filter_search_element['type'] == 'fork_values') {
613
-					$request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON  post_id = ID WHERE (meta_key = "'.( ( !empty($k) && $k == '_product_price' ) ? '_wpshop_displayed_price' : $k).'" AND meta_value BETWEEN '.$amount_min.' AND '.$amount_max.') AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish"';
614
-					$request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) ';
612
+				else if ($filter_search_element['type'] == 'fork_values') {
613
+					$request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON  post_id = ID WHERE (meta_key = "' . ((!empty($k) && $k == '_product_price') ? '_wpshop_displayed_price' : $k) . '" AND meta_value BETWEEN ' . $amount_min . ' AND ' . $amount_max . ') AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish"';
614
+					$request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) ';
615 615
 				}
616
-				else if( $filter_search_element['type'] == 'multiple_select_value' ) {
616
+				else if ($filter_search_element['type'] == 'multiple_select_value') {
617 617
 					/** Check the attribute id **/
618 618
 					$attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code');
619
-					if ( !empty($attribute_def) ) {
620
-						$request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' .WPSHOP_DBT_ATTRIBUTE. ', '.WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER.' AS ATT_INT WHERE attribute_id = id AND attribute_id = '.$attribute_def->id;
619
+					if (!empty($attribute_def)) {
620
+						$request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' . WPSHOP_DBT_ATTRIBUTE . ', ' . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . ' AS ATT_INT WHERE attribute_id = id AND attribute_id = ' . $attribute_def->id;
621 621
 						$first = true;
622
-						if ( !empty($search) && is_array($search) ){
623
-							foreach ( $search as $r ) {
624
-								if ( $first) {
625
-									$request_cmd .= ' AND (value ="' . $r. '"';
622
+						if (!empty($search) && is_array($search)) {
623
+							foreach ($search as $r) {
624
+								if ($first) {
625
+									$request_cmd .= ' AND (value ="' . $r . '"';
626 626
 									$first = false;
627 627
 								}
628 628
 								else {
629
-									$request_cmd .= ' OR value ="' . $r. '"';
629
+									$request_cmd .= ' OR value ="' . $r . '"';
630 630
 								}
631 631
 							}
632 632
 							$request_cmd .= ')';
633 633
 						}
634
-						elseif(  !empty($search) )  {
634
+						elseif (!empty($search)) {
635 635
 							$request_cmd .= ' AND (value ="' . $search . '" )';
636 636
 						}
637
-						$request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) ';
637
+						$request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) ';
638 638
 
639 639
 
640 640
 					}
641 641
 				}
642 642
 
643 643
 
644
-				if ($i < count($filter_search_elements) ) {
644
+				if ($i < count($filter_search_elements)) {
645 645
 					$request_cmd .= ' UNION ';
646 646
 				}
647 647
 				$i++;
648 648
 			}
649 649
 		} else {
650
-			$request_cmd .= 'SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.')';
650
+			$request_cmd .= 'SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ')';
651 651
 		}
652 652
 		/** SQL Request execution **/
653 653
 		$query = $wpdb->prepare($request_cmd, '');
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
 
662 662
 		$last = '';
663 663
 		/** Transform the query result array **/
664
-		foreach ( $results as $result ) {
665
-			$result->meta_key = ( !empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price' ) ? '_product_price' : $result->meta_key;
666
-			if ( $last != $result->meta_key ){
664
+		foreach ($results as $result) {
665
+			$result->meta_key = (!empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price') ? '_product_price' : $result->meta_key;
666
+			if ($last != $result->meta_key) {
667 667
 				$filter_search_elements[$result->meta_key]['count'] = 1;
668 668
 				$last = $result->meta_key;
669 669
 			}
@@ -677,12 +677,12 @@  discard block
 block discarded – undo
677 677
 		/** Check the smaller array of attributes **/
678 678
 		$smaller_array = '';
679 679
 		$smaller_array_count = -1;
680
-		foreach ( $filter_search_elements as $k=>$filter_search_element ) {
681
-			if ( empty($filter_search_element['count']) ) {
680
+		foreach ($filter_search_elements as $k=>$filter_search_element) {
681
+			if (empty($filter_search_element['count'])) {
682 682
 				$smaller_array_count = 0;
683 683
 				$smaller_array = $k;
684 684
 			}
685
-			elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) {
685
+			elseif ($smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count) {
686 686
 				$smaller_array_count = $filter_search_element['count'];
687 687
 				$smaller_array = $k;
688 688
 			}
@@ -690,21 +690,21 @@  discard block
 block discarded – undo
690 690
 		}
691 691
 
692 692
 		/** Compare the smaller array with the others **/
693
-		if ( !empty($smaller_array_count) ) {
693
+		if (!empty($smaller_array_count)) {
694 694
 			$temp_tab = $filter_search_elements[$smaller_array]['values'];
695
-			foreach ( $filter_search_elements as $filter_search) {
696
-				foreach ( $temp_tab as $value ) {
697
-					if ( !in_array($value, $filter_search['values']) ) {
695
+			foreach ($filter_search_elements as $filter_search) {
696
+				foreach ($temp_tab as $value) {
697
+					if (!in_array($value, $filter_search['values'])) {
698 698
 						/** If value don't exist in the smaller array, delete it **/
699 699
 						$key = array_key_exists($value, $temp_tab);
700
-						if ( $key ) {
700
+						if ($key) {
701 701
 							unset($temp_tab[$value]);
702 702
 						}
703 703
 					}
704 704
 				}
705 705
 			}
706 706
 			/** Final result to display the products **/
707
-			if ( !empty( $temp_tab) ) {
707
+			if (!empty($temp_tab)) {
708 708
 				$final_result = $temp_tab;
709 709
 			}
710 710
 		}
@@ -713,21 +713,21 @@  discard block
 block discarded – undo
713 713
 		}
714 714
 
715 715
 		$products_count = count($final_result);
716
-		$products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'),$products_count) ;
716
+		$products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'), $products_count);
717 717
 
718 718
 		/** If there is products for this filter search **/
719 719
 		$status = true;
720
-		if ( !empty($final_result) ) {
720
+		if (!empty($final_result)) {
721 721
 			$data['status'] = true;
722
-			$data['result']  = do_shortcode( '[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]' ) ;
722
+			$data['result'] = do_shortcode('[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]');
723 723
 			$data['products_count'] = $products_count;
724 724
 		}
725 725
 		else {
726 726
 			$data['status'] = false;
727
-			$data['result'] = '<div class="container_product_listing">'.__('There is no product for this filter search.', 'wpshop').'</div>';
727
+			$data['result'] = '<div class="container_product_listing">' . __('There is no product for this filter search.', 'wpshop') . '</div>';
728 728
 			$data['products_count'] = __('No products corresponds to your search', 'wpshop');
729 729
 		}
730
-		echo json_encode( $data );
730
+		echo json_encode($data);
731 731
 		die();
732 732
 	}
733 733
 }
Please login to merge, or discard this patch.
Braces   +27 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_filter_search {
3 5
 
4 6
 	/** Define the main directory containing the template for the current plugin
@@ -106,8 +108,7 @@  discard block
 block discarded – undo
106 108
 				case 'text' :
107 109
 					if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') {
108 110
 						return $this->get_filter_element_for_integer_data( $attribute_def, $category_id, $current_category_children );
109
-					}
110
-					else {
111
+					} else {
111 112
 						return $this->get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_children );
112 113
 					}
113 114
 					break;
@@ -187,8 +188,7 @@  discard block
 block discarded – undo
187 188
 						}
188 189
 					}
189 190
 				}
190
-			}
191
-			else {
191
+			} else {
192 192
 				foreach ( $attributes_options as $attributes_option ) {
193 193
 					if ( in_array($attributes_option->label, $available_attribute_values) ) {
194 194
 						$key_value = array_search( $attributes_option->label, $available_attribute_values);
@@ -224,8 +224,7 @@  discard block
 block discarded – undo
224 224
 							require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select") );
225 225
 							$output = ob_get_contents();
226 226
 							ob_end_clean();
227
-						}
228
-						else {
227
+						} else {
229 228
 							ob_start();
230 229
 							require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") );
231 230
 							$output = ob_get_contents();
@@ -308,8 +307,7 @@  discard block
 block discarded – undo
308 307
 				foreach( $available_attribute_values as $k => $available_attribute_value ) {
309 308
 					if (  $attribute_def->data_type_to_use == 'internal' ) {
310 309
 						$attribute_name = get_the_title( $k );
311
-					}
312
-					else {
310
+					} else {
313 311
 						$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k);
314 312
 
315 313
 						$attribute_name = $wpdb->get_var( $query );
@@ -365,21 +363,18 @@  discard block
 block discarded – undo
365 363
 
366 364
 						$max_value = ( !empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value ) ? $product_price_infos['fork_price']['max_product_price'] : $max_value;
367 365
 						$min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && ( ( $product_price_infos['fork_price']['min_product_price'] < $min_value) || $first ) ) ?  $product_price_infos['fork_price']['min_product_price'] : $min_value;
368
-					}
369
-					else {
366
+					} else {
370 367
 						if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist'] ) && $product_price_infos['discount']['discount_exist'] ) {
371 368
 							$product_data = (!empty($price_piloting_option) &&  $price_piloting_option == 'HT')  ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price'];
372 369
 
373
-						}
374
-						else {
370
+						} else {
375 371
 
376 372
 							$product_data = (!empty($price_piloting_option) &&  $price_piloting_option == 'HT')  ? $product_price_infos['et'] : $product_price_infos['ati'];
377 373
 						}
378 374
 						$max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value;
379 375
 						$min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first )  ) ?  $product_data : $min_value;
380 376
 					}
381
-				}
382
-				else {
377
+				} else {
383 378
 					$product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
384 379
 					$product_data = $product_postmeta[$attribute_def->code];
385 380
 					$max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value;
@@ -451,11 +446,9 @@  discard block
 block discarded – undo
451 446
 			if ( !empty($price_infos) ) {
452 447
 				if ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) ) {
453 448
 					$displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price'];
454
-				}
455
-				else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) {
449
+				} else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) {
456 450
 					$displayed_price = $price_infos['fork_price']['min_product_price'];
457
-				}
458
-				else {
451
+				} else {
459 452
 					$displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati'];
460 453
 				}
461 454
 				update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price,2, '.','') );
@@ -497,8 +490,7 @@  discard block
 block discarded – undo
497 490
 										case 'text' :
498 491
 											if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') {
499 492
 												$this->save_values_for_integer_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children );
500
-											}
501
-											else {
493
+											} else {
502 494
 												$this->save_values_for_text_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children );
503 495
 											}
504 496
 											break;
@@ -532,11 +524,9 @@  discard block
 block discarded – undo
532 524
 					if ( !empty($attribute_def) ) {
533 525
 						if ( $attribute_def->frontend_input == 'text' ) {
534 526
 							$filter_search_elements['_'.$attribute_def->code] = array('type' => 'fork_values');
535
-						}
536
-						elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) {
527
+						} elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) {
537 528
 							$filter_search_elements['_'.$attribute_def->code] = array('type' => 'multiple_select_value');
538
-						}
539
-						elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) )  {
529
+						} elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) )  {
540 530
 							$filter_search_elements['_'.$attribute_def->code] = array('type' => 'select_value');
541 531
 						}
542 532
 					}
@@ -552,8 +542,9 @@  discard block
 block discarded – undo
552 542
 	function wpshop_ajax_filter_search_action () {
553 543
 		$_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
554 544
 
555
-		if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) )
556
-			wp_die();
545
+		if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) {
546
+					wp_die();
547
+		}
557 548
 
558 549
 		global $wpdb;
559 550
 		$category_id =  !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_category_id'] ) : 0;
@@ -608,12 +599,10 @@  discard block
 block discarded – undo
608 599
 				if ( !empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') {
609 600
 					$request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON  post_id = ID WHERE (meta_key = "'.$k.'" AND meta_value = "'.$search.'") AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish" ';
610 601
 					$request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) ';
611
-				}
612
-				else if($filter_search_element['type'] == 'fork_values') {
602
+				} else if($filter_search_element['type'] == 'fork_values') {
613 603
 					$request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON  post_id = ID WHERE (meta_key = "'.( ( !empty($k) && $k == '_product_price' ) ? '_wpshop_displayed_price' : $k).'" AND meta_value BETWEEN '.$amount_min.' AND '.$amount_max.') AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish"';
614 604
 					$request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) ';
615
-				}
616
-				else if( $filter_search_element['type'] == 'multiple_select_value' ) {
605
+				} else if( $filter_search_element['type'] == 'multiple_select_value' ) {
617 606
 					/** Check the attribute id **/
618 607
 					$attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code');
619 608
 					if ( !empty($attribute_def) ) {
@@ -624,14 +613,12 @@  discard block
 block discarded – undo
624 613
 								if ( $first) {
625 614
 									$request_cmd .= ' AND (value ="' . $r. '"';
626 615
 									$first = false;
627
-								}
628
-								else {
616
+								} else {
629 617
 									$request_cmd .= ' OR value ="' . $r. '"';
630 618
 								}
631 619
 							}
632 620
 							$request_cmd .= ')';
633
-						}
634
-						elseif(  !empty($search) )  {
621
+						} elseif(  !empty($search) )  {
635 622
 							$request_cmd .= ' AND (value ="' . $search . '" )';
636 623
 						}
637 624
 						$request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) ';
@@ -666,9 +653,9 @@  discard block
 block discarded – undo
666 653
 			if ( $last != $result->meta_key ){
667 654
 				$filter_search_elements[$result->meta_key]['count'] = 1;
668 655
 				$last = $result->meta_key;
656
+			} else {
657
+							$filter_search_elements[$result->meta_key]['count']++;
669 658
 			}
670
-			else
671
-				$filter_search_elements[$result->meta_key]['count']++;
672 659
 
673 660
 			$filter_search_elements[$result->meta_key]['values'][$result->post_id] = $result->post_id;
674 661
 		}
@@ -681,8 +668,7 @@  discard block
 block discarded – undo
681 668
 			if ( empty($filter_search_element['count']) ) {
682 669
 				$smaller_array_count = 0;
683 670
 				$smaller_array = $k;
684
-			}
685
-			elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) {
671
+			} elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) {
686 672
 				$smaller_array_count = $filter_search_element['count'];
687 673
 				$smaller_array = $k;
688 674
 			}
@@ -707,8 +693,7 @@  discard block
 block discarded – undo
707 693
 			if ( !empty( $temp_tab) ) {
708 694
 				$final_result = $temp_tab;
709 695
 			}
710
-		}
711
-		else {
696
+		} else {
712 697
 			$final_result = array();
713 698
 		}
714 699
 
@@ -721,8 +706,7 @@  discard block
 block discarded – undo
721 706
 			$data['status'] = true;
722 707
 			$data['result']  = do_shortcode( '[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]' ) ;
723 708
 			$data['products_count'] = $products_count;
724
-		}
725
-		else {
709
+		} else {
726 710
 			$data['status'] = false;
727 711
 			$data['result'] = '<div class="container_product_listing">'.__('There is no product for this filter search.', 'wpshop').'</div>';
728 712
 			$data['products_count'] = __('No products corresponds to your search', 'wpshop');
Please login to merge, or discard this patch.
includes/modules/wpshop_prices/wpshop_prices.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -166,6 +166,9 @@  discard block
 block discarded – undo
166 166
 			return $price_infos;
167 167
 		}
168 168
 
169
+		/**
170
+		 * @param string $return_type
171
+		 */
169 172
 		public static function get_product_price($product, $return_type, $output_type = '', $only_price = false, $price_checking_done = false) {
170 173
 			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
171 174
 // 			$wpshop_price_piloting_option = 'TTC';
@@ -458,6 +461,7 @@  discard block
 block discarded – undo
458 461
 
459 462
 		/**
460 463
 		 * Check if isset Required attributes
464
+		 * @param integer $product_id
461 465
 		 */
462 466
 		public static function check_required_attributes( $product_id ) {
463 467
 			$required_attributes_list = array();
Please login to merge, or discard this patch.
Braces   +39 added lines, -63 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 
3 5
 /**
4 6
  * WPSHOP Prices bootstrap file
@@ -65,8 +67,7 @@  discard block
 block discarded – undo
65 67
 						}
66 68
 					}
67 69
 				}
68
-			}
69
-			else {
70
+			} else {
70 71
 				/** Desactivate Discount Attributes **/
71 72
 				if ( !empty($discount_attributes) ) {
72 73
 					foreach ( $discount_attributes as $discount_attribute ) {
@@ -113,14 +114,12 @@  discard block
 block discarded – undo
113 114
 							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
114 115
 							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
115 116
 							$product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100);
116
-						}
117
-						elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
117
+						} elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
118 118
 							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
119 119
 							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value'];
120 120
 							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
121 121
 
122
-						}
123
-						elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
122
+						} elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
124 123
 							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 -  $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
125 124
 							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) );
126 125
 							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
@@ -136,16 +135,14 @@  discard block
 block discarded – undo
136 135
 						$price_infos['discount']['discount_ati_price'] = ( !empty($product['price_ttc_before_discount']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
137 136
 						$price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht_before_discount']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0;
138 137
 						$price_infos['discount']['discount_tva'] = ( !empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount']) ) ? number_format( ($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0;
139
-					}
140
-					else {
138
+					} else {
141 139
 						$price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
142 140
 						$price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
143 141
 						$price_infos['tva'] =  ( !empty($product['tva'] ) ) ? $product['tva'] : 0;
144 142
 					}
145 143
 
146 144
 
147
-				}
148
-				else {
145
+				} else {
149 146
 					if ( !empty( $product['price_ttc_before_discount']) && !empty( $product['price_ht_before_discount'] ) ) {
150 147
 						$price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount'])  && !empty($product['price_ht_before_discount'] ) ) ? true : false;
151 148
 						$price_infos['discount']['discount_ati_price'] = ( !empty($product['product_price']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
@@ -155,8 +152,7 @@  discard block
 block discarded – undo
155 152
 						$price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0;
156 153
 						$price_infos['et'] = ( !empty($product['price_ht_before_discount']) ) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0;
157 154
 						$price_infos['tva'] =  $price_infos['ati'] - $price_infos['et'];
158
-					}
159
-					else {
155
+					} else {
160 156
 						$price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
161 157
 						$price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
162 158
 						$price_infos['tva'] =  ( !empty($product['tva'] ) ) ? $product['tva'] : 0;
@@ -199,8 +195,7 @@  discard block
 block discarded – undo
199 195
 					if ( !empty($product_with_variation[$product['product_id']]['variation_priority']) ) {
200 196
 						$product =  wpshop_products::get_variation_price_behaviour( $product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : '' ) );
201 197
 					}
202
-				}
203
-				else {
198
+				} else {
204 199
 					/** It's Simple product Check Discounts for products **/
205 200
 					$discount_config = self::check_discount_for_product( $product['product_id'] );
206 201
 					if ( !empty($discount_config) ) {
@@ -211,8 +206,7 @@  discard block
 block discarded – undo
211 206
 							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
212 207
 							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
213 208
 							$product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100);
214
-						}
215
-						elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
209
+						} elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
216 210
 							$product['price_ttc_before_discount'] = $product['product_price'];
217 211
 							$product['price_ht_before_discount'] = $product['price_ht'];
218 212
 
@@ -220,8 +214,7 @@  discard block
 block discarded – undo
220 214
 							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value'];
221 215
 							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
222 216
 
223
-						}
224
-						elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
217
+						} elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
225 218
 							$product['price_ttc_before_discount'] = $product['product_price'];
226 219
 							$product['price_ht_before_discount'] = $product['price_ht'];
227 220
 
@@ -244,13 +237,16 @@  discard block
 block discarded – undo
244 237
 			if ( !empty($price_infos) ) {
245 238
 				if ( $return_type == 'check_only' ) {
246 239
 					/** Check if the product price has been set	*/
247
-					if( isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
240
+					if( isset($price_infos['ati']) && $price_infos['ati'] === '') {
241
+						return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
242
+					}
248 243
 					/** Check if the product price is coherent (not less than 0)	*/
249
-					if( isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop');
244
+					if( isset($price_infos['ati']) && $price_infos['ati'] < 0) {
245
+						return __('This product cannot be purchased - its price is negative', 'wpshop');
246
+					}
250 247
 
251 248
 					return true;
252
-				}
253
-				elseif( $return_type == 'just_price_infos' ) {
249
+				} elseif( $return_type == 'just_price_infos' ) {
254 250
 					$tpl_component = array();
255 251
 
256 252
 					$price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
@@ -269,8 +265,7 @@  discard block
 block discarded – undo
269 265
 						$tpl_component['CROSSED_OUT_PRICE'] = $crossed_out_price;
270 266
 						if(!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') {
271 267
 							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', ''));
272
-						}
273
-						else {
268
+						} else {
274 269
 							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', ''));
275 270
 						}
276 271
 
@@ -278,16 +273,14 @@  discard block
 block discarded – undo
278 273
 						$tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">'.$discount_price.'</span> '.$productCurrency;
279 274
 
280 275
 						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_infos );
281
-					}
282
-					else {
276
+					} else {
283 277
 						$tpl_component['PRODUCT_PRICE'] = $price.' '.$productCurrency;
284 278
 					}
285 279
 
286 280
 					$post_type = get_post_type( $product['product_id'] );
287 281
 					if (  $post_type ==  WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
288 282
 						$price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
289
-					}
290
-					elseif( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
283
+					} elseif( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
291 284
 						$parent_def = wpshop_products::get_parent_variation ( $product['product_id'] );
292 285
 						if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
293 286
 							$parent_post = $parent_def['parent_post'];
@@ -298,8 +291,7 @@  discard block
 block discarded – undo
298 291
 					$tpl_component['PRICE_FROM'] = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? 'on' : '';
299 292
 
300 293
 					return $tpl_component;
301
-				}
302
-				else if ( $return_type == 'price_display' ) {
294
+				} else if ( $return_type == 'price_display' ) {
303 295
 					$tpl_component = array();
304 296
 					$price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
305 297
 
@@ -323,8 +315,7 @@  discard block
 block discarded – undo
323 315
 								$parent_post = $parent_def['parent_post'];
324 316
 								$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
325 317
 							}
326
-						}
327
-						else {
318
+						} else {
328 319
 							$price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
329 320
 						}
330 321
 						$text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) && !empty($product['text_from']) ) ? true : false;
@@ -342,14 +333,12 @@  discard block
 block discarded – undo
342 333
 						$tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">'. $price_infos['discount']['discount_et_price'].'</span> '.$productCurrency : '<span class="wps-absolute-price">'.$price_infos['discount']['discount_ati_price'].'</span> '.$productCurrency;
343 334
 						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_data );
344 335
 
345
-					}
346
-					else {
336
+					} else {
347 337
 						if( get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
348 338
 							$parent_def = wpshop_products::get_parent_variation( $product['product_id'] );
349 339
 							$pid = $parent_def['parent_post'];
350 340
 							$pid = $pid->ID;
351
-						}
352
-						else {
341
+						} else {
353 342
 							$pid = $product['product_id'];
354 343
 						}
355 344
 
@@ -362,8 +351,7 @@  discard block
 block discarded – undo
362 351
 								$parent_post = $parent_def['parent_post'];
363 352
 								$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
364 353
 							}
365
-						}
366
-						else {
354
+						} else {
367 355
 							$price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true );
368 356
 						}
369 357
 
@@ -381,8 +369,7 @@  discard block
 block discarded – undo
381 369
 
382 370
 					if ( $output_type == 'complete_sheet' ) {
383 371
 						$price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component );
384
-					}
385
-					elseif ( $output_type == 'mini_output' || in_array('mini_output', $output_type ) ) {
372
+					} elseif ( $output_type == 'mini_output' || in_array('mini_output', $output_type ) ) {
386 373
 						$price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component );
387 374
 					}
388 375
 					return $price_tpl;
@@ -527,8 +514,7 @@  discard block
 block discarded – undo
527 514
 											$tx_tva = $wpdb->get_var( $query );
528 515
 											$variation_price =  $variation['variation_dif']['price_ht'] / ( 1 + ($variation['variation_dif']['discount_rate'] / 100 ) );
529 516
 											$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
530
-										}
531
-										elseif( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0 ) {
517
+										} elseif( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0 ) {
532 518
 											$query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] );
533 519
 											$tx_tva = $wpdb->get_var( $query );
534 520
 											$variation_price =  $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount'];
@@ -548,8 +534,7 @@  discard block
 block discarded – undo
548 534
 						}
549 535
 					}
550 536
 				}
551
-			}
552
-			else {
537
+			} else {
553 538
 				if ( !empty($product_id) ) {
554 539
 					if( !empty($variations) ) {
555 540
 
@@ -589,14 +574,12 @@  discard block
 block discarded – undo
589 574
 					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
590 575
 					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
591 576
 					$product['tva'] = $product['product_price'] - $product['price_ht'];
592
-				}
593
-				elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
577
+				} elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
594 578
 					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] - $discount_config['value'] ) : ( ( $product['product_price'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
595 579
 					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['product_price'] - $discount_config['value'];
596 580
 					$product['tva'] =  $product['product_price'] - $product['price_ht'];
597 581
 
598
-				}
599
-				elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
582
+				} elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
600 583
 					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] * ( 1 -  $discount_config['value'] / 100) ) : ( ( $product['product_price']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
601 584
 					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['product_price'] * ( 1 - ( $discount_config['value'] / 100 ) );
602 585
 					$product['tva'] =   $product['product_price'] - $product['price_ht'];
@@ -618,8 +601,7 @@  discard block
 block discarded – undo
618 601
 					$product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0;
619 602
 
620 603
 					$product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true );
621
-				}
622
-				else {
604
+				} else {
623 605
 					$product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true );
624 606
 					$product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0;
625 607
 					$product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0;
@@ -634,12 +616,10 @@  discard block
 block discarded – undo
634 616
 						if ( !empty($product_meta['special_price']) && $product_meta['special_price'] > 0 ) {
635 617
 							$discount_config['type'] = 'special_price';
636 618
 							$discount_config['value'] = $product_meta['special_price'];
637
-						}
638
-						elseif( !empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) {
619
+						} elseif( !empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) {
639 620
 							$discount_config['type'] = 'discount_amount';
640 621
 							$discount_config['value'] = $product_meta['discount_amount'];
641
-						}
642
-						elseif( !empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0 ) {
622
+						} elseif( !empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0 ) {
643 623
 							$discount_config['type'] = 'discount_rate';
644 624
 							$discount_config['value'] = $product_meta['discount_rate'];
645 625
 						}
@@ -725,8 +705,7 @@  discard block
 block discarded – undo
725 705
 											$p = wpshop_products::get_product_data($product->ID);
726 706
 											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) );
727 707
 											update_post_meta( $product->ID, '_wps_price_infos', $price );
728
-										}
729
-										else {
708
+										} else {
730 709
 											/** Update post meta **/
731 710
 											$product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] );
732 711
 											$product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
@@ -773,8 +752,7 @@  discard block
 block discarded – undo
773 752
 											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) );
774 753
 											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) );
775 754
 											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) );
776
-										}
777
-										else {
755
+										} else {
778 756
 											/** Update post meta **/
779 757
 											$product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] );
780 758
 											$product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
@@ -795,12 +773,10 @@  discard block
 block discarded – undo
795 773
 
796 774
 					$result = __('Prices updated', 'wpshop');
797 775
 					$status = true;
798
-				}
799
-				else {
776
+				} else {
800 777
 					$result = __('No VAT rates was found', 'wpshop');
801 778
 				}
802
-			}
803
-			else {
779
+			} else {
804 780
 				$result = __( 'VAT rate attribute was not found', 'wpshop' );
805 781
 			}
806 782
 			return array( $status, $result );
Please login to merge, or discard this patch.
Spacing   +325 added lines, -325 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /**
4 4
  * WPSHOP Prices bootstrap file
@@ -9,17 +9,17 @@  discard block
 block discarded – undo
9 9
  *
10 10
  */
11 11
 
12
-if ( !defined( 'WPSHOP_VERSION' ) ) {
13
-	die( __("You are not allowed to use this service.", 'wpshop') );
12
+if (!defined('WPSHOP_VERSION')) {
13
+	die(__("You are not allowed to use this service.", 'wpshop'));
14 14
 }
15
-if ( !class_exists("wpshop_prices") ) {
15
+if (!class_exists("wpshop_prices")) {
16 16
 	class wpshop_prices {
17 17
 
18 18
 		function __construct() {
19 19
 			add_action('wsphop_options', array('wpshop_prices', 'declare_options'));
20 20
 		}
21 21
 
22
-		public static function declare_options () {
22
+		public static function declare_options() {
23 23
 			register_setting('wpshop_options', 'wpshop_catalog_product_option', array('wpshop_prices', 'wpshop_options_validate_prices'));
24 24
 			add_settings_field('wpshop_catalog_product_option_discount', __('Activate the discount on products', 'wpshop'), array('wpshop_prices', 'wpshop_activate_discount_prices_field'), 'wpshop_catalog_product_option', 'wpshop_catalog_product_section');
25 25
 		}
@@ -29,37 +29,37 @@  discard block
 block discarded – undo
29 29
 
30 30
 			/** Price attribute Def **/
31 31
 			$price_piloting_option = get_option('wpshop_shop_price_piloting');
32
-			$price_attribute_def = wpshop_attributes::getElement( ( (!empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? 'price_ht' : 'product_price' ), "'valid'", 'code');
32
+			$price_attribute_def = wpshop_attributes::getElement(((!empty($price_piloting_option) && $price_piloting_option == 'HT') ? 'price_ht' : 'product_price'), "'valid'", 'code');
33 33
 
34 34
 			/** Discount attributes **/
35
-			$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s OR code = %s OR  code = %s OR code = %s OR code = %s', 'discount_amount', 'discount_rate', 'special_price', 'special_from', 'special_to' );
35
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s OR  code = %s OR code = %s OR code = %s', 'discount_amount', 'discount_rate', 'special_price', 'special_from', 'special_to');
36 36
 			$discount_attributes = $wpdb->get_results($query);
37 37
 
38 38
 			/** Check if discount is actived **/
39
-			if ( !empty( $input) && !empty($input['discount']) ) {
39
+			if (!empty($input) && !empty($input['discount'])) {
40 40
 				/** Activate the attributes **/
41
-				if ( !empty($discount_attributes) ) {
42
-					foreach ( $discount_attributes as $discount_attribute ) {
43
-						$update = $wpdb->prepare('UPDATE ' .WPSHOP_DBT_ATTRIBUTE. ' SET status = "valid" WHERE code = %s', $discount_attribute->code);
41
+				if (!empty($discount_attributes)) {
42
+					foreach ($discount_attributes as $discount_attribute) {
43
+						$update = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET status = "valid" WHERE code = %s', $discount_attribute->code);
44 44
 						$wpdb->query($update);
45 45
 					}
46 46
 				}
47 47
 
48 48
 				/** Affect discount attributes to All Attributes Set section where there is a Price attribute **/
49
-				$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_id = %d', $price_attribute_def->id);
50
-				$attributes_sections = $wpdb->get_results( $query );
51
-				if ( !empty($attributes_sections) ) {
52
-					foreach ( $attributes_sections as $attributes_section ) {
49
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %d', $price_attribute_def->id);
50
+				$attributes_sections = $wpdb->get_results($query);
51
+				if (!empty($attributes_sections)) {
52
+					foreach ($attributes_sections as $attributes_section) {
53 53
 						/** Check the Max Position for the Attribute section */
54
-						$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id);
55
-						$max_position = $wpdb->get_var( $query );
56
-						$max_position = ( !empty($max_position) ) ? $max_position : 0;
54
+						$query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id);
55
+						$max_position = $wpdb->get_var($query);
56
+						$max_position = (!empty($max_position)) ? $max_position : 0;
57 57
 						/** Affect the discount attributes **/
58
-						foreach ( $discount_attributes as $discount_attribute) {
59
-							$query = $wpdb->prepare(' SELECT COUNT(*) AS count_attributes_affect FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s AND attribute_id = %d', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id, $discount_attribute->id);
60
-							$count_attribute_affectation = $wpdb->get_row( $query );
61
-							if ( !empty($count_attribute_affectation) && ( empty($count_attribute_affectation->count_attributes_affect) || $count_attribute_affectation->count_attributes_affect == 0 ) ) {
62
-								$result = $wpdb->insert( WPSHOP_DBT_ATTRIBUTE_DETAILS, array( 'status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id, 'position' => $max_position) );
58
+						foreach ($discount_attributes as $discount_attribute) {
59
+							$query = $wpdb->prepare(' SELECT COUNT(*) AS count_attributes_affect FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s AND attribute_id = %d', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id, $discount_attribute->id);
60
+							$count_attribute_affectation = $wpdb->get_row($query);
61
+							if (!empty($count_attribute_affectation) && (empty($count_attribute_affectation->count_attributes_affect) || $count_attribute_affectation->count_attributes_affect == 0)) {
62
+								$result = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id, 'position' => $max_position));
63 63
 								$max_position += 1;
64 64
 							}
65 65
 						}
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 			}
69 69
 			else {
70 70
 				/** Desactivate Discount Attributes **/
71
-				if ( !empty($discount_attributes) ) {
72
-					foreach ( $discount_attributes as $discount_attribute ) {
73
-						$update = $wpdb->prepare('UPDATE ' .WPSHOP_DBT_ATTRIBUTE. ' SET status = "notused" WHERE code = %s', $discount_attribute->code);
71
+				if (!empty($discount_attributes)) {
72
+					foreach ($discount_attributes as $discount_attribute) {
73
+						$update = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET status = "notused" WHERE code = %s', $discount_attribute->code);
74 74
 						$wpdb->query($update);
75 75
 					}
76 76
 				}
77 77
 
78 78
 				/** Delete the Price attribute set section affectation **/
79
-				$query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_id = %d', $price_attribute_def->id);
80
-				$attributes_sections = $wpdb->get_results( $query );
81
-				if ( !empty($attributes_sections) ) {
82
-					foreach ( $attributes_sections as $attributes_section ) {
79
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %d', $price_attribute_def->id);
80
+				$attributes_sections = $wpdb->get_results($query);
81
+				if (!empty($attributes_sections)) {
82
+					foreach ($attributes_sections as $attributes_section) {
83 83
 						/** Affect the discount attributes **/
84
-						foreach ( $discount_attributes as $discount_attribute) {
85
-							$wpdb->delete( WPSHOP_DBT_ATTRIBUTE_DETAILS, array( 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id ) );
84
+						foreach ($discount_attributes as $discount_attribute) {
85
+							$wpdb->delete(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id));
86 86
 						}
87 87
 					}
88 88
 				}
@@ -94,72 +94,72 @@  discard block
 block discarded – undo
94 94
 		public static function wpshop_activate_discount_prices_field() {
95 95
 			$product_discount_option = get_option('wpshop_catalog_product_option');
96 96
 
97
-			$output  = '<input type="checkbox" id="wpshop_catalog_product_option_discount" name="wpshop_catalog_product_option[discount]" ' .( (!empty($product_discount_option) && !empty($product_discount_option['discount'])) ? 'checked="checked"' : '' ). ' />';
98
-			$output .= '<a class="wpshop_infobulle_marker" title="' .__('Activate the possibility to create discount on products', 'wpshop'). '" href="#">?</a>';
97
+			$output  = '<input type="checkbox" id="wpshop_catalog_product_option_discount" name="wpshop_catalog_product_option[discount]" ' . ((!empty($product_discount_option) && !empty($product_discount_option['discount'])) ? 'checked="checked"' : '') . ' />';
98
+			$output .= '<a class="wpshop_infobulle_marker" title="' . __('Activate the possibility to create discount on products', 'wpshop') . '" href="#">?</a>';
99 99
 			echo $output;
100 100
 		}
101 101
 
102
-		public static function check_product_price( $product, $cart = false ) {
102
+		public static function check_product_price($product, $cart = false) {
103 103
 			$price_infos = array();
104 104
 			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
105
-			if ( !empty($product) ) {
106
-				if ( $cart ) {
107
-					$discount_config = self::check_discount_for_product($product['product_id'] );
108
-					if ( !empty($discount_config) ) {
105
+			if (!empty($product)) {
106
+				if ($cart) {
107
+					$discount_config = self::check_discount_for_product($product['product_id']);
108
+					if (!empty($discount_config)) {
109 109
 						$product['price_ttc_before_discount'] = $product['product_price'];
110 110
 						$product['price_ht_before_discount'] = $product['price_ht'];
111 111
 
112
-						if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) {
113
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
114
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
115
-							$product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100);
112
+						if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
113
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
114
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
115
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
116 116
 						}
117
-						elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
118
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
119
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value'];
120
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
117
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
118
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] - $discount_config['value']) : (($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100));
119
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value'];
120
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
121 121
 
122 122
 						}
123
-						elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
124
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 -  $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
125
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) );
126
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
123
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
124
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100)) : (($product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100));
125
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100));
126
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
127 127
 
128 128
 						}
129 129
 
130 130
 
131
-						$price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 2, '.', '') : number_format((float)$product['product_price'], 2, '.', '');
132
-						$price_infos['et'] = ( !empty($product['price_ht_before_discount'] ) ) ? number_format((float)$product['price_ht_before_discount'], 2, '.', '') : number_format((float)$product['price_ht'], 2, '.', '');
133
-						$price_infos['tva'] = $price_infos['et'] * ( $product['tx_tva'] / 100);
131
+						$price_infos['ati'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['price_ttc_before_discount'], 2, '.', '') : number_format((float)$product['product_price'], 2, '.', '');
132
+						$price_infos['et'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht_before_discount'], 2, '.', '') : number_format((float)$product['price_ht'], 2, '.', '');
133
+						$price_infos['tva'] = $price_infos['et'] * ($product['tx_tva'] / 100);
134 134
 
135
-						$price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount'])  && !empty($product['price_ht_before_discount'] ) ) ? true : false;
136
-						$price_infos['discount']['discount_ati_price'] = ( !empty($product['price_ttc_before_discount']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
137
-						$price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht_before_discount']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0;
138
-						$price_infos['discount']['discount_tva'] = ( !empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount']) ) ? number_format( ($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0;
135
+						$price_infos['discount']['discount_exist'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? true : false;
136
+						$price_infos['discount']['discount_ati_price'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
137
+						$price_infos['discount']['discount_et_price'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht'], 2, '.', '') : 0;
138
+						$price_infos['discount']['discount_tva'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? number_format(($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0;
139 139
 					}
140 140
 					else {
141
-						$price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
142
-						$price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
143
-						$price_infos['tva'] =  ( !empty($product['tva'] ) ) ? $product['tva'] : 0;
141
+						$price_infos['ati'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
142
+						$price_infos['et'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
143
+						$price_infos['tva'] = (!empty($product['tva'])) ? $product['tva'] : 0;
144 144
 					}
145 145
 
146 146
 
147 147
 				}
148 148
 				else {
149
-					if ( !empty( $product['price_ttc_before_discount']) && !empty( $product['price_ht_before_discount'] ) ) {
150
-						$price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount'])  && !empty($product['price_ht_before_discount'] ) ) ? true : false;
151
-						$price_infos['discount']['discount_ati_price'] = ( !empty($product['product_price']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
152
-						$price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0;
153
-						$price_infos['discount']['discount_tva'] = ( !empty($product['tva']) ) ? $product['tva'] : 0;
154
-
155
-						$price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0;
156
-						$price_infos['et'] = ( !empty($product['price_ht_before_discount']) ) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0;
157
-						$price_infos['tva'] =  $price_infos['ati'] - $price_infos['et'];
149
+					if (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) {
150
+						$price_infos['discount']['discount_exist'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? true : false;
151
+						$price_infos['discount']['discount_ati_price'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 2, '.', '') : 0;
152
+						$price_infos['discount']['discount_et_price'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 2, '.', '') : 0;
153
+						$price_infos['discount']['discount_tva'] = (!empty($product['tva'])) ? $product['tva'] : 0;
154
+
155
+						$price_infos['ati'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0;
156
+						$price_infos['et'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0;
157
+						$price_infos['tva'] = $price_infos['ati'] - $price_infos['et'];
158 158
 					}
159 159
 					else {
160
-						$price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
161
-						$price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
162
-						$price_infos['tva'] =  ( !empty($product['tva'] ) ) ? $product['tva'] : 0;
160
+						$price_infos['ati'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 5, '.', '') : 0;
161
+						$price_infos['et'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 5, '.', '') : 0;
162
+						$price_infos['tva'] = (!empty($product['tva'])) ? $product['tva'] : 0;
163 163
 					}
164 164
 				}
165 165
 			}
@@ -170,65 +170,65 @@  discard block
 block discarded – undo
170 170
 			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
171 171
 // 			$wpshop_price_piloting_option = 'TTC';
172 172
  			/** Price for Mini-output **/
173
-			if( !empty($product['product_id']) && !$price_checking_done ) {
173
+			if (!empty($product['product_id']) && !$price_checking_done) {
174 174
 
175 175
 				/** Checking if it's a product with variation **/
176
-				$variation_option_checking = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
176
+				$variation_option_checking = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
177 177
 
178
-				if( !empty($variation_option_checking) ) {
179
-					$variations_exists = wpshop_products::get_variation( $product['product_id'], 'publish' );
178
+				if (!empty($variation_option_checking)) {
179
+					$variations_exists = wpshop_products::get_variation($product['product_id'], 'publish');
180 180
 				}
181 181
 
182
-				if( !empty($variation_option_checking) && !empty($variations_exists) ) {
183
-					if ( !empty( $variation_option_checking['attributes']) ) {
184
-						foreach( $variation_option_checking['attributes'] as $attribute ) {
182
+				if (!empty($variation_option_checking) && !empty($variations_exists)) {
183
+					if (!empty($variation_option_checking['attributes'])) {
184
+						foreach ($variation_option_checking['attributes'] as $attribute) {
185 185
 							$selected_variation[$attribute] = 0;
186
-							if( !empty( $variation_option_checking['options'] ) && !empty( $variation_option_checking['options']['attributes_default_value'] ) && array_key_exists( $attribute, $variation_option_checking['options']['attributes_default_value']) ){
187
-								if ( $variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') {
186
+							if (!empty($variation_option_checking['options']) && !empty($variation_option_checking['options']['attributes_default_value']) && array_key_exists($attribute, $variation_option_checking['options']['attributes_default_value'])) {
187
+								if ($variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') {
188 188
 									$selected_variation[$attribute] = $variation_option_checking['options']['attributes_default_value'][$attribute];
189 189
 								}
190 190
 							}
191 191
 						}
192 192
 					}
193
-					if ( !empty($selected_variation) ) {
194
-						$product_with_variation = wpshop_products::get_variation_by_priority( $selected_variation, $product['product_id'] );
193
+					if (!empty($selected_variation)) {
194
+						$product_with_variation = wpshop_products::get_variation_by_priority($selected_variation, $product['product_id']);
195 195
 					}
196
-					if( empty($product_with_variation[$product['product_id']]['variations']) ) {
196
+					if (empty($product_with_variation[$product['product_id']]['variations'])) {
197 197
 						$product_with_variation[$product['product_id']]['variations'] = array();
198 198
 					}
199
-					if ( !empty($product_with_variation[$product['product_id']]['variation_priority']) ) {
200
-						$product =  wpshop_products::get_variation_price_behaviour( $product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : '' ) );
199
+					if (!empty($product_with_variation[$product['product_id']]['variation_priority'])) {
200
+						$product = wpshop_products::get_variation_price_behaviour($product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : ''));
201 201
 					}
202 202
 				}
203 203
 				else {
204 204
 					/** It's Simple product Check Discounts for products **/
205
-					$discount_config = self::check_discount_for_product( $product['product_id'] );
206
-					if ( !empty($discount_config) ) {
207
-						if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) {
205
+					$discount_config = self::check_discount_for_product($product['product_id']);
206
+					if (!empty($discount_config)) {
207
+						if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
208 208
 							$product['price_ttc_before_discount'] = $product['product_price'];
209 209
 							$product['price_ht_before_discount'] = $product['price_ht'];
210 210
 
211
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
212
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
213
-							$product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100);
211
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
212
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
213
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
214 214
 						}
215
-						elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
215
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
216 216
 							$product['price_ttc_before_discount'] = $product['product_price'];
217 217
 							$product['price_ht_before_discount'] = $product['price_ht'];
218 218
 
219
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
220
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value'];
221
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
219
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] - $discount_config['value']) : (($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100));
220
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value'];
221
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
222 222
 
223 223
 						}
224
-						elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
224
+						elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
225 225
 							$product['price_ttc_before_discount'] = $product['product_price'];
226 226
 							$product['price_ht_before_discount'] = $product['price_ht'];
227 227
 
228 228
 
229
-							$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 - $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
230
-							$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) );
231
-							$product['tva'] =  $product['price_ht'] * ( $product['tx_tva'] / 100);
229
+							$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100)) : (($product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100));
230
+							$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100));
231
+							$product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
232 232
 
233 233
 						}
234 234
 					}
@@ -236,116 +236,116 @@  discard block
 block discarded – undo
236 236
 
237 237
 			}
238 238
 
239
-			$price_infos = self::check_product_price( $product );
240
-			$productCurrency = '<span class="wps-currency">'.wpshop_tools::wpshop_get_currency().'</span>';
239
+			$price_infos = self::check_product_price($product);
240
+			$productCurrency = '<span class="wps-currency">' . wpshop_tools::wpshop_get_currency() . '</span>';
241 241
 
242 242
 			$wps_marketing_tools = new wps_marketing_tools_ctr();
243 243
 
244
-			if ( !empty($price_infos) ) {
245
-				if ( $return_type == 'check_only' ) {
244
+			if (!empty($price_infos)) {
245
+				if ($return_type == 'check_only') {
246 246
 					/** Check if the product price has been set	*/
247
-					if( isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
247
+					if (isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
248 248
 					/** Check if the product price is coherent (not less than 0)	*/
249
-					if( isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop');
249
+					if (isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop');
250 250
 
251 251
 					return true;
252 252
 				}
253
-				elseif( $return_type == 'just_price_infos' ) {
253
+				elseif ($return_type == 'just_price_infos') {
254 254
 					$tpl_component = array();
255 255
 
256
-					$price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
257
-					$exploded_price = explode('.', number_format($price,2, '.', ''));
258
-					$price = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">,'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
256
+					$price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
257
+					$exploded_price = explode('.', number_format($price, 2, '.', ''));
258
+					$price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">,' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
259 259
 
260
-					$tpl_component['TAX_PILOTING'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT')  ? __('ET', 'wpshop') : '';
260
+					$tpl_component['TAX_PILOTING'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : '';
261 261
 
262 262
 					$tpl_component['CROSSED_OUT_PRICE'] = '';
263 263
 					$tpl_component['MESSAGE_SAVE_MONEY'] = '';
264 264
 
265 265
 
266 266
 
267
-					if( !empty($price_infos['discount']['discount_exist']) ) {
268
-						$crossed_out_price = ( (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2) ).' '. $productCurrency;
267
+					if (!empty($price_infos['discount']['discount_exist'])) {
268
+						$crossed_out_price = ((!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency;
269 269
 						$tpl_component['CROSSED_OUT_PRICE'] = $crossed_out_price;
270
-						if(!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') {
271
-							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', ''));
270
+						if (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') {
271
+							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', ''));
272 272
 						}
273 273
 						else {
274
-							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', ''));
274
+							$exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', ''));
275 275
 						}
276 276
 
277
-						$discount_price = $exploded_discount_price[0].'<span class="wpshop_price_centimes_display">,'.( (!empty($exploded_discount_price[1]) ) ? $exploded_discount_price[1] : '').'</span>';
278
-						$tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">'.$discount_price.'</span> '.$productCurrency;
277
+						$discount_price = $exploded_discount_price[0] . '<span class="wpshop_price_centimes_display">,' . ((!empty($exploded_discount_price[1])) ? $exploded_discount_price[1] : '') . '</span>';
278
+						$tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">' . $discount_price . '</span> ' . $productCurrency;
279 279
 
280
-						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_infos );
280
+						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_infos);
281 281
 					}
282 282
 					else {
283
-						$tpl_component['PRODUCT_PRICE'] = $price.' '.$productCurrency;
283
+						$tpl_component['PRODUCT_PRICE'] = $price . ' ' . $productCurrency;
284 284
 					}
285 285
 
286
-					$post_type = get_post_type( $product['product_id'] );
287
-					if (  $post_type ==  WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) {
288
-						$price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
286
+					$post_type = get_post_type($product['product_id']);
287
+					if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
288
+						$price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
289 289
 					}
290
-					elseif( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
291
-						$parent_def = wpshop_products::get_parent_variation ( $product['product_id'] );
292
-						if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
290
+					elseif ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
291
+						$parent_def = wpshop_products::get_parent_variation($product['product_id']);
292
+						if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
293 293
 							$parent_post = $parent_def['parent_post'];
294
-							$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
294
+							$price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
295 295
 						}
296 296
 					}
297
-					$price_display_option = get_option( 'wpshop_catalog_product_option' );
298
-					$tpl_component['PRICE_FROM'] = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? 'on' : '';
297
+					$price_display_option = get_option('wpshop_catalog_product_option');
298
+					$tpl_component['PRICE_FROM'] = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from'])))))) ? 'on' : '';
299 299
 
300 300
 					return $tpl_component;
301 301
 				}
302
-				else if ( $return_type == 'price_display' ) {
302
+				else if ($return_type == 'price_display') {
303 303
 					$tpl_component = array();
304
-					$price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
304
+					$price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati'];
305 305
 
306 306
 					$price_data = $price_infos;
307 307
 
308
-					$exploded_price = explode('.', number_format($price,2, '.', ''));
309
-					$price = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
308
+					$exploded_price = explode('.', number_format($price, 2, '.', ''));
309
+					$price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
310 310
 
311
-					$tpl_component['TAX_PILOTING'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT')  ? __('ET', 'wpshop') : '';
311
+					$tpl_component['TAX_PILOTING'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : '';
312 312
 
313 313
 					$tpl_component['CROSSED_OUT_PRICE'] = '';
314 314
 					$tpl_component['MESSAGE_SAVE_MONEY'] = '';
315 315
 
316
-					if( !empty($price_infos['discount']['discount_exist']) ) {
316
+					if (!empty($price_infos['discount']['discount_exist'])) {
317 317
 						$text_from = false;
318 318
 						/** Get variation defining **/
319
-						$post_type = get_post_type( $product['product_id'] );
320
-						if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
321
-							$parent_def = wpshop_products::get_parent_variation ( $product['product_id'] );
322
-							if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
319
+						$post_type = get_post_type($product['product_id']);
320
+						if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
321
+							$parent_def = wpshop_products::get_parent_variation($product['product_id']);
322
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
323 323
 								$parent_post = $parent_def['parent_post'];
324
-								$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
324
+								$price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
325 325
 							}
326 326
 						}
327 327
 						else {
328
-							$price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true );
328
+							$price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
329 329
 						}
330
-						$text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) && !empty($product['text_from']) ) ? true : false;
330
+						$text_from = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']))))) && !empty($product['text_from'])) ? true : false;
331 331
 
332 332
 
333
-						$exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', ''));
334
-						$price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
333
+						$exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', ''));
334
+						$price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
335 335
 
336
-						$exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', ''));
337
-						$price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>';
336
+						$exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', ''));
337
+						$price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>';
338 338
 
339 339
 
340
-						$crossed_out_price = ( (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2) ).' '. $productCurrency;
341
-						$tpl_component['CROSSED_OUT_PRICE'] = str_replace( '.', ',', ( ( $text_from ) ? __('Price from', 'wpshop') . ' ' : '' ). wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price)) );
342
-						$tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">'. $price_infos['discount']['discount_et_price'].'</span> '.$productCurrency : '<span class="wps-absolute-price">'.$price_infos['discount']['discount_ati_price'].'</span> '.$productCurrency;
343
-						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_data );
340
+						$crossed_out_price = ((!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency;
341
+						$tpl_component['CROSSED_OUT_PRICE'] = str_replace('.', ',', (($text_from) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price)));
342
+						$tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">' . $price_infos['discount']['discount_et_price'] . '</span> ' . $productCurrency : '<span class="wps-absolute-price">' . $price_infos['discount']['discount_ati_price'] . '</span> ' . $productCurrency;
343
+						$tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_data);
344 344
 
345 345
 					}
346 346
 					else {
347
-						if( get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
348
-							$parent_def = wpshop_products::get_parent_variation( $product['product_id'] );
347
+						if (get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
348
+							$parent_def = wpshop_products::get_parent_variation($product['product_id']);
349 349
 							$pid = $parent_def['parent_post'];
350 350
 							$pid = $pid->ID;
351 351
 						}
@@ -355,35 +355,35 @@  discard block
 block discarded – undo
355 355
 
356 356
 						$text_from = false;
357 357
 						/** Get variation defining **/
358
-						$post_type = get_post_type( $pid );
359
-						if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
360
-							$parent_def = wpshop_products::get_parent_variation ( $pid );
361
-							if( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
358
+						$post_type = get_post_type($pid);
359
+						if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
360
+							$parent_def = wpshop_products::get_parent_variation($pid);
361
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
362 362
 								$parent_post = $parent_def['parent_post'];
363
-								$price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true );
363
+								$price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
364 364
 							}
365 365
 						}
366 366
 						else {
367
-							$price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true );
367
+							$price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true);
368 368
 						}
369 369
 
370
-						$price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true );
370
+						$price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true);
371 371
 
372
-						$text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])  ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? true : false;
372
+						$text_from = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from'])))))) ? true : false;
373 373
 
374
-						$tpl_component['PRODUCT_PRICE']  = ( $text_from && !empty($product['text_from']) ) ? __('Price from', 'wpshop') . ' ' : '';
375
-						$tpl_component['PRODUCT_PRICE'] .= $price.' '.$productCurrency;
374
+						$tpl_component['PRODUCT_PRICE']  = ($text_from && !empty($product['text_from'])) ? __('Price from', 'wpshop') . ' ' : '';
375
+						$tpl_component['PRODUCT_PRICE'] .= $price . ' ' . $productCurrency;
376 376
 					}
377 377
 
378 378
 
379 379
 					// Replace . by ,
380
-					$tpl_component['PRODUCT_PRICE'] = str_replace( '.',',', $tpl_component['PRODUCT_PRICE'] );
380
+					$tpl_component['PRODUCT_PRICE'] = str_replace('.', ',', $tpl_component['PRODUCT_PRICE']);
381 381
 
382
-					if ( $output_type == 'complete_sheet' ) {
383
-						$price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component );
382
+					if ($output_type == 'complete_sheet') {
383
+						$price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component);
384 384
 					}
385
-					elseif ( $output_type == 'mini_output' || in_array('mini_output', $output_type ) ) {
386
-						$price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component );
385
+					elseif ($output_type == 'mini_output' || in_array('mini_output', $output_type)) {
386
+						$price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component);
387 387
 					}
388 388
 					return $price_tpl;
389 389
 				}
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 		 * @return stdClass ( value, id ) L'id de l'attribut et le taux de TVA /
404 404
 		 * Attribute ID and the VAT rate
405 405
 		 */
406
-		public static function get_rate_vat( $product_id ) {
406
+		public static function get_rate_vat($product_id) {
407 407
 			global $wpdb;
408 408
 
409 409
 			/**
@@ -417,18 +417,18 @@  discard block
 block discarded – undo
417 417
 						INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . " as ATTR_VAL_INT ON ( ATTR_VAL_INT.attribute_id = ATTR.id AND ATTR_VAL_OPTIONS.id=ATTR_VAL_INT.value )
418 418
 					WHERE ATTR.code=%s AND ATTR_VAL_INT.entity_id=%d";
419 419
 
420
-			$request = $wpdb->prepare( $query, array( 'tx_tva',  $product_id ) );
421
-			$rate_vat = $wpdb->get_row( $request );
420
+			$request = $wpdb->prepare($query, array('tx_tva', $product_id));
421
+			$rate_vat = $wpdb->get_row($request);
422 422
 
423 423
 			/**
424 424
 			 * Vérifie ensuite si elle est vide, si elle est vide met la valeur par
425 425
 			 * défaut / Then checks if it is empty , if empty the value put the
426 426
 			 * default value
427 427
 			 */
428
-			if( empty( $rate_vat ) ) {
429
-				wpeologs_ctr::log_datas_in_files( 'wps_product', array(
428
+			if (empty($rate_vat)) {
429
+				wpeologs_ctr::log_datas_in_files('wps_product', array(
430 430
 					'object_id' 	=> $product_id,
431
-					'message' 		=> __( 'Use the default VAT rate', 'wpshop' ) ), 0
431
+					'message' 		=> __('Use the default VAT rate', 'wpshop') ), 0
432 432
 				);
433 433
 
434 434
 				$query = "
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " as ATTR_VAL_OPTIONS ON ATTR_VAL_OPTIONS.attribute_id = ATTR.id
438 438
 						WHERE ATTR.code=%s AND ATTR_VAL_OPTIONS.id=ATTR.default_value";
439 439
 
440
-				$request = $wpdb->prepare( $query, array( 'tx_tva' ) );
441
-				$rate_vat = $wpdb->get_row( $request );
440
+				$request = $wpdb->prepare($query, array('tx_tva'));
441
+				$rate_vat = $wpdb->get_row($request);
442 442
 			}
443 443
 
444 444
 			/**
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 			 * dans ce cas la on utilise le log / If it is still empty , it means that no
447 447
 			 * VAT rate found in this case the log is used
448 448
 			 */
449
-			if( empty( $rate_vat ) ) {
450
-				wpeologs_ctr::log_datas_in_files( 'wps_product', array(
449
+			if (empty($rate_vat)) {
450
+				wpeologs_ctr::log_datas_in_files('wps_product', array(
451 451
 					'object_id' 	=> $product_id,
452
-					'message' 		=> __( 'No VAT rate in the product and no default VAT rate found', 'wpshop' ) ), 2
452
+					'message' 		=> __('No VAT rate in the product and no default VAT rate found', 'wpshop') ), 2
453 453
 				);
454 454
 			}
455 455
 
@@ -459,19 +459,19 @@  discard block
 block discarded – undo
459 459
 		/**
460 460
 		 * Check if isset Required attributes
461 461
 		 */
462
-		public static function check_required_attributes( $product_id ) {
462
+		public static function check_required_attributes($product_id) {
463 463
 			$required_attributes_list = array();
464
-			$variation_option = get_post_meta( $product_id, '_wpshop_variation_defining', true);
465
-			if ( !empty($variation_option) && !empty($variation_option['attributes']) ) {
466
-				if( !empty($variation_option['options']) && !empty($variation_option['options']['required_attributes']) ) {
467
-					foreach( $variation_option['options']['required_attributes'] as $required_attribute ) {
468
-						$required_attributes_list[ $required_attribute ] = $required_attribute;
464
+			$variation_option = get_post_meta($product_id, '_wpshop_variation_defining', true);
465
+			if (!empty($variation_option) && !empty($variation_option['attributes'])) {
466
+				if (!empty($variation_option['options']) && !empty($variation_option['options']['required_attributes'])) {
467
+					foreach ($variation_option['options']['required_attributes'] as $required_attribute) {
468
+						$required_attributes_list[$required_attribute] = $required_attribute;
469 469
 					}
470 470
 				}
471 471
 				/** Check the attribute configuration **/
472
-				foreach ( $variation_option['attributes'] as $variation ) {
473
-					$attribute_def = wpshop_attributes::getElement( $variation, '"valid"', 'code' );
474
-					if ( is_object($attribute_def) && !empty($attribute_def->is_required) && $attribute_def->is_required == 'yes' ) {
472
+				foreach ($variation_option['attributes'] as $variation) {
473
+					$attribute_def = wpshop_attributes::getElement($variation, '"valid"', 'code');
474
+					if (is_object($attribute_def) && !empty($attribute_def->is_required) && $attribute_def->is_required == 'yes') {
475 475
 						$required_attributes_list[$attribute_def->code] = $attribute_def->code;
476 476
 					}
477 477
 				}
@@ -483,60 +483,60 @@  discard block
 block discarded – undo
483 483
 		}
484 484
 
485 485
 		/** Check the Product lower price **/
486
-		public static function check_product_lower_price ( $product_id ) {
486
+		public static function check_product_lower_price($product_id) {
487 487
 			global $wpdb;
488
-			$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
488
+			$price_piloting_option = get_option('wpshop_shop_price_piloting');
489 489
 			$lower_price_product = $min_price = 0;
490
-			$variations = wpshop_products::get_variation( $product_id, 'publish' );
490
+			$variations = wpshop_products::get_variation($product_id, 'publish');
491 491
 			$single_variations = $lower_price_product_combinaison = array();
492 492
 			$first = true;
493 493
 
494 494
 			/** Check variations type **/
495
-			$query = $wpdb->prepare( 'SELECT DISTINCT( SUBSTRING( m.meta_value, 3,1 ) ) AS attributes_count FROM ' .$wpdb->postmeta .' AS m INNER JOIN ' .$wpdb->posts. ' AS P ON ((P.ID = m.post_id) AND (P.post_parent = %d)) WHERE meta_key LIKE %s', $product_id, '_wpshop_variations_attribute_def' );
496
-			$variation_type = $wpdb->get_results( $query );
495
+			$query = $wpdb->prepare('SELECT DISTINCT( SUBSTRING( m.meta_value, 3,1 ) ) AS attributes_count FROM ' . $wpdb->postmeta . ' AS m INNER JOIN ' . $wpdb->posts . ' AS P ON ((P.ID = m.post_id) AND (P.post_parent = %d)) WHERE meta_key LIKE %s', $product_id, '_wpshop_variations_attribute_def');
496
+			$variation_type = $wpdb->get_results($query);
497 497
 
498 498
 
499 499
 			/** Check which type of variation contains the product **/
500 500
 			$contains_simple_variation = false;
501
-			if ( !empty($variation_type) ) {
502
-				foreach( $variation_type as $k => $value ) {
503
-					if( $value->attributes_count == '1' ) {
501
+			if (!empty($variation_type)) {
502
+				foreach ($variation_type as $k => $value) {
503
+					if ($value->attributes_count == '1') {
504 504
 						$contains_simple_variation = true;
505 505
 					}
506 506
 				}
507 507
 			}
508 508
 
509
-			if ( $contains_simple_variation ) {
509
+			if ($contains_simple_variation) {
510 510
 
511
-				if( !empty($variations) ) {
512
-					$attributes = get_post_meta( $product_id, '_wpshop_variation_defining', true);
513
-					if ( !empty($attributes) && !empty($attributes['attributes']) ) {
511
+				if (!empty($variations)) {
512
+					$attributes = get_post_meta($product_id, '_wpshop_variation_defining', true);
513
+					if (!empty($attributes) && !empty($attributes['attributes'])) {
514 514
 						/** Construct an array with all cheaper attributes **/
515
-						foreach( $attributes['attributes'] as $key=>$attribute ) {
515
+						foreach ($attributes['attributes'] as $key=>$attribute) {
516 516
 							$min_price = 0;
517 517
 							$first = true;
518
-							foreach( $variations as $k => $variation) {
519
-								if ( !empty($variation['variation_def']) && count($variation['variation_def']) == 1 ) {
520
-									if( array_key_exists($attribute, $variation['variation_def'] ) ) {
521
-										$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation['variation_dif']['price_ht'] : !empty( $variation['variation_dif']['product_price'] ) ? $variation['variation_dif']['product_price'] : 0;
518
+							foreach ($variations as $k => $variation) {
519
+								if (!empty($variation['variation_def']) && count($variation['variation_def']) == 1) {
520
+									if (array_key_exists($attribute, $variation['variation_def'])) {
521
+										$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation['variation_dif']['price_ht'] : !empty($variation['variation_dif']['product_price']) ? $variation['variation_dif']['product_price'] : 0;
522 522
 
523 523
 										/** Check Discount **/
524
-										$variation_price = ( !empty( $variation['variation_dif']['special_price'] ) && $variation['variation_dif']['special_price'] > 0 ) ? $variation['variation_dif']['special_price'] : $variation_price;
525
-										if( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_rate']) && $variation['variation_dif']['discount_rate'] > 0) {
526
-											$query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] );
527
-											$tx_tva = $wpdb->get_var( $query );
528
-											$variation_price =  $variation['variation_dif']['price_ht'] / ( 1 + ($variation['variation_dif']['discount_rate'] / 100 ) );
529
-											$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
524
+										$variation_price = (!empty($variation['variation_dif']['special_price']) && $variation['variation_dif']['special_price'] > 0) ? $variation['variation_dif']['special_price'] : $variation_price;
525
+										if (empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_rate']) && $variation['variation_dif']['discount_rate'] > 0) {
526
+											$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $variation['variation_dif']['tx_tva']);
527
+											$tx_tva = $wpdb->get_var($query);
528
+											$variation_price = $variation['variation_dif']['price_ht'] / (1 + ($variation['variation_dif']['discount_rate'] / 100));
529
+											$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
530 530
 										}
531
-										elseif( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0 ) {
532
-											$query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] );
533
-											$tx_tva = $wpdb->get_var( $query );
534
-											$variation_price =  $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount'];
535
-											$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
531
+										elseif (empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0) {
532
+											$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $variation['variation_dif']['tx_tva']);
533
+											$tx_tva = $wpdb->get_var($query);
534
+											$variation_price = $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount'];
535
+											$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation_price : $variation_price * 1 + ($tx_tva / 100);
536 536
 										}
537 537
 
538 538
 										/** Check the Min-price **/
539
-										if( $first|| $min_price >= $variation_price ) {
539
+										if ($first || $min_price >= $variation_price) {
540 540
 											$first = false;
541 541
 											$min_price = $variation_price;
542 542
 											$lower_price_product_combinaison['variations'][$attribute] = $k;
@@ -550,22 +550,22 @@  discard block
 block discarded – undo
550 550
 				}
551 551
 			}
552 552
 			else {
553
-				if ( !empty($product_id) ) {
554
-					if( !empty($variations) ) {
553
+				if (!empty($product_id)) {
554
+					if (!empty($variations)) {
555 555
 
556
-						foreach( $variations as $variation_id => $variation) {
557
-							if ( !empty($variation['variation_dif']) && !empty($variation['variation_def']) && count($variation['variation_def']) > 1) {
558
-								$variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? ( ( !empty($variation['variation_dif']['price_ht']) ) ? $variation['variation_dif']['price_ht'] : 0) : ( ( !empty($variation['variation_dif']['product_price']) ) ? $variation['variation_dif']['product_price'] : 0);
556
+						foreach ($variations as $variation_id => $variation) {
557
+							if (!empty($variation['variation_dif']) && !empty($variation['variation_def']) && count($variation['variation_def']) > 1) {
558
+								$variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) : ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0);
559 559
 								/** Check the Min-price **/
560
-								if( $min_price >= $variation_price || $first ) {
560
+								if ($min_price >= $variation_price || $first) {
561 561
 									$min_price = $variation_price;
562 562
 									$var_id = $variation_id;
563 563
 								}
564 564
 							}
565
-							$first  = false;
565
+							$first = false;
566 566
 						}
567 567
 
568
-						if ( !empty($var_id) ) {
568
+						if (!empty($var_id)) {
569 569
 							$lower_price_product_combinaison['variations'][] = $var_id;
570 570
 							$lower_price_product_combinaison['variation_priority'] = 'combined';
571 571
 						}
@@ -581,25 +581,25 @@  discard block
 block discarded – undo
581 581
 		 * @param array $discount_config
582 582
 		 * @return array
583 583
 		 */
584
-		public static function calcul_discounted_price( $product, $discount_config ) {
585
-			$wpshop_price_piloting_option = get_option( 'wpshop_shop_price_piloting');
586
-			if( !empty($discount_config) ) {
584
+		public static function calcul_discounted_price($product, $discount_config) {
585
+			$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
586
+			if (!empty($discount_config)) {
587 587
 
588
-				if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) {
589
-					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100);
590
-					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value'];
588
+				if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
589
+					$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
590
+					$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
591 591
 					$product['tva'] = $product['product_price'] - $product['price_ht'];
592 592
 				}
593
-				elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) {
594
-					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] - $discount_config['value'] ) : ( ( $product['product_price'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ;
595
-					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['product_price'] - $discount_config['value'];
596
-					$product['tva'] =  $product['product_price'] - $product['price_ht'];
593
+				elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
594
+					$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht'] - $discount_config['value']) : (($product['product_price'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100));
595
+					$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['product_price'] - $discount_config['value'];
596
+					$product['tva'] = $product['product_price'] - $product['price_ht'];
597 597
 
598 598
 				}
599
-				elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
600
-					$product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] * ( 1 -  $discount_config['value'] / 100) ) : ( ( $product['product_price']  * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ;
601
-					$product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['product_price'] * ( 1 - ( $discount_config['value'] / 100 ) );
602
-					$product['tva'] =   $product['product_price'] - $product['price_ht'];
599
+				elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
600
+					$product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht'] * (1 - $discount_config['value'] / 100)) : (($product['product_price'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100));
601
+					$product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['product_price'] * (1 - ($discount_config['value'] / 100));
602
+					$product['tva'] = $product['product_price'] - $product['price_ht'];
603 603
 				}
604 604
 			}
605 605
 			return $product;
@@ -607,39 +607,39 @@  discard block
 block discarded – undo
607 607
 
608 608
 
609 609
 		/** Check Discount for Product **/
610
-		public static function check_discount_for_product( $product_id, $head_product_id = 0 ) {
610
+		public static function check_discount_for_product($product_id, $head_product_id = 0) {
611 611
 			$discount_config = array();
612 612
 			$time_def = array('0000-00-00 00:00:00', '0000-00-00');
613 613
 
614
-			if( !empty($product_id) ) {
615
-				if ( !empty($head_product_id) ) {
616
-					$product_meta = get_post_meta( $head_product_id, '_wpshop_product_metadata', true );
617
-					$product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0;
618
-					$product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0;
614
+			if (!empty($product_id)) {
615
+				if (!empty($head_product_id)) {
616
+					$product_meta = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
617
+					$product_discount_date_from = (!empty($product_meta['special_from'])) ? $product_meta['special_from'] : 0;
618
+					$product_discount_date_to = (!empty($product_meta['special_to'])) ? $product_meta['special_to'] : 0;
619 619
 
620
-					$product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true );
620
+					$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
621 621
 				}
622 622
 				else {
623
-					$product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true );
624
-					$product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0;
625
-					$product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0;
623
+					$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
624
+					$product_discount_date_from = (!empty($product_meta['special_from'])) ? $product_meta['special_from'] : 0;
625
+					$product_discount_date_to = (!empty($product_meta['special_to'])) ? $product_meta['special_to'] : 0;
626 626
 				}
627 627
 
628 628
 				$current_date = date('Y-m-d');
629 629
 
630
-				if ( !empty( $product_meta ) ) {
630
+				if (!empty($product_meta)) {
631 631
 
632
-					if( ( empty($product_discount_date_from) && empty($product_discount_date_to) ) || ( in_array($product_discount_date_from, $time_def)  && in_array( $product_discount_date_to, $time_def) ) || (strtotime($product_discount_date_from) < strtotime($current_date) && strtotime($current_date) < strtotime($product_discount_date_to) ) ) {
632
+					if ((empty($product_discount_date_from) && empty($product_discount_date_to)) || (in_array($product_discount_date_from, $time_def) && in_array($product_discount_date_to, $time_def)) || (strtotime($product_discount_date_from) < strtotime($current_date) && strtotime($current_date) < strtotime($product_discount_date_to))) {
633 633
 						/** Special Price **/
634
-						if ( !empty($product_meta['special_price']) && $product_meta['special_price'] > 0 ) {
634
+						if (!empty($product_meta['special_price']) && $product_meta['special_price'] > 0) {
635 635
 							$discount_config['type'] = 'special_price';
636 636
 							$discount_config['value'] = $product_meta['special_price'];
637 637
 						}
638
-						elseif( !empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) {
638
+						elseif (!empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) {
639 639
 							$discount_config['type'] = 'discount_amount';
640 640
 							$discount_config['value'] = $product_meta['discount_amount'];
641 641
 						}
642
-						elseif( !empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0 ) {
642
+						elseif (!empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0) {
643 643
 							$discount_config['type'] = 'discount_rate';
644 644
 							$discount_config['value'] = $product_meta['discount_rate'];
645 645
 						}
@@ -652,13 +652,13 @@  discard block
 block discarded – undo
652 652
 		/**
653 653
 		 * Check the parent product price
654 654
 		 */
655
-		function check_parent_product_price( $product ) {
655
+		function check_parent_product_price($product) {
656 656
 			$price_infos = array();
657
-			if( !empty($product) ) {
657
+			if (!empty($product)) {
658 658
 				$price_infos['ati'] = $product['product_price'];
659 659
 				$price_infos['et'] = $product['price_ht'];
660 660
 				$price_infos['tva'] = $product['tva'];
661
-				$price_infos['fork_price'] = array( 'have_fork_price' => false, 'min_product_price' => '', 'max_product_price' => '');
661
+				$price_infos['fork_price'] = array('have_fork_price' => false, 'min_product_price' => '', 'max_product_price' => '');
662 662
 			}
663 663
 			return $price_infos;
664 664
 		}
@@ -668,81 +668,81 @@  discard block
 block discarded – undo
668 668
 			global $wpdb;
669 669
 			$status = false; $result = '';
670 670
 			@ini_set('max_execution_time', '500');
671
-			$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
672
-			$output_type_option = get_option( 'wpshop_display_option' );
671
+			$price_piloting_option = get_option('wpshop_shop_price_piloting');
672
+			$output_type_option = get_option('wpshop_display_option');
673 673
 			$output_type = $output_type_option['wpshop_display_list_type'];
674 674
 
675 675
 			/** Get tx_tva attribute_id **/
676
-			$query = $wpdb->prepare( 'SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s', 'tx_tva' );
677
-			$tx_tva_attribute_id = $wpdb->get_var( $query );
676
+			$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', 'tx_tva');
677
+			$tx_tva_attribute_id = $wpdb->get_var($query);
678 678
 
679 679
 			/** Product entity Definition **/
680
-			$product_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
680
+			$product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
681 681
 
682 682
 			/** Attributes def **/
683
-			$tva_attribute_def = wpshop_attributes::getElement('tva',"'valid'", 'code');
684
-			$product_price_attribute_def = wpshop_attributes::getElement('product_price',"'valid'", 'code');
685
-			$price_ht_attribute_def = wpshop_attributes::getElement('price_ht',"'valid'", 'code');
683
+			$tva_attribute_def = wpshop_attributes::getElement('tva', "'valid'", 'code');
684
+			$product_price_attribute_def = wpshop_attributes::getElement('product_price', "'valid'", 'code');
685
+			$price_ht_attribute_def = wpshop_attributes::getElement('price_ht', "'valid'", 'code');
686 686
 
687
-			if ( !empty($tx_tva_attribute_id) ) {
688
-				$query = $wpdb->prepare( 'SELECT id, value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid' );
689
-				$tx_tva = $wpdb->get_results( $query );
687
+			if (!empty($tx_tva_attribute_id)) {
688
+				$query = $wpdb->prepare('SELECT id, value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid');
689
+				$tx_tva = $wpdb->get_results($query);
690 690
 
691 691
 				$tva_array = array();
692 692
 				/** Transform array to easy teatment **/
693
-				foreach( $tx_tva as $t ) {
694
-					$tva_array[ $t->id ] = $t->value;
693
+				foreach ($tx_tva as $t) {
694
+					$tva_array[$t->id] = $t->value;
695 695
 				}
696 696
 
697
-				if ( !empty($tx_tva) ) {
697
+				if (!empty($tx_tva)) {
698 698
 
699 699
 					$count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
700 700
 
701
-					for( $i = 0; $i <= $count_products->publish; $i+= 100 ) {
702
-					$query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish' );
703
-					$products = $wpdb->get_results( $query );
701
+					for ($i = 0; $i <= $count_products->publish; $i += 100) {
702
+					$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
703
+					$products = $wpdb->get_results($query);
704 704
 
705
-						if( !empty($products) ){
706
-	 						foreach( $products as $product ) {
707
-								$product_data = get_post_meta( $product->ID, '_wpshop_product_metadata', true);
708
-								if ( !empty($product_data) ) {
709
-									if ( !empty($product_data['tx_tva']) && array_key_exists( $product_data['tx_tva'], $tva_array) ) {
705
+						if (!empty($products)) {
706
+	 						foreach ($products as $product) {
707
+								$product_data = get_post_meta($product->ID, '_wpshop_product_metadata', true);
708
+								if (!empty($product_data)) {
709
+									if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) {
710 710
 
711
-										if ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) {
711
+										if (!empty($price_piloting_option) && $price_piloting_option == 'HT') {
712 712
 											/** Update post meta **/
713
-											$product_data['price_ht'] = (float)str_replace( ',', '.', $product_data['price_ht'] );
714
-											$product_data['product_price'] = $product_data['price_ht'] * ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
715
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
716
-											update_post_meta( $product->ID, '_wpshop_product_metadata', $product_data);
713
+											$product_data['price_ht'] = (float)str_replace(',', '.', $product_data['price_ht']);
714
+											$product_data['product_price'] = $product_data['price_ht'] * (1 + ($tva_array[$product_data['tx_tva']] / 100));
715
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
716
+											update_post_meta($product->ID, '_wpshop_product_metadata', $product_data);
717 717
 
718 718
 
719 719
 											/** Update attributes values **/
720
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID) );
721
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID) );
722
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID) );
720
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID));
721
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID));
722
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID));
723 723
 
724 724
 											/** Update Display price meta **/
725 725
 											$p = wpshop_products::get_product_data($product->ID);
726
-											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) );
727
-											update_post_meta( $product->ID, '_wps_price_infos', $price );
726
+											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
727
+											update_post_meta($product->ID, '_wps_price_infos', $price);
728 728
 										}
729 729
 										else {
730 730
 											/** Update post meta **/
731
-											$product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] );
732
-											$product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
733
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
734
-											update_post_meta( $product->ID, '_wpshop_product_metadata', $product_data);
731
+											$product_data['product_price'] = (float)str_replace(',', '.', $product_data['product_price']);
732
+											$product_data['price_ht'] = $product_data['product_price'] / (1 + ($tva_array[$product_data['tx_tva']] / 100));
733
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
734
+											update_post_meta($product->ID, '_wpshop_product_metadata', $product_data);
735 735
 
736 736
 											/** Update attributes values **/
737
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID) );
738
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID) );
739
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID) );
737
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID));
738
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID));
739
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID));
740 740
 
741 741
 
742 742
 											/** Update Display price meta **/
743 743
 											$p = wpshop_products::get_product_data($product->ID);
744
-											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) );
745
-											update_post_meta( $product->ID, '_wps_price_infos', $price );
744
+											$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
745
+											update_post_meta($product->ID, '_wps_price_infos', $price);
746 746
 										}
747 747
 									}
748 748
 								}
@@ -750,41 +750,41 @@  discard block
 block discarded – undo
750 750
 
751 751
 						}
752 752
 					}
753
-					unset( $products );
753
+					unset($products);
754 754
 
755 755
 					$count_variations = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION);
756
-					for( $i = 0; $i <= $count_variations->publish; $i+= 100 ) {
757
-						$query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish' );
758
-						$product_variations = $wpdb->get_results( $query );
756
+					for ($i = 0; $i <= $count_variations->publish; $i += 100) {
757
+						$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish');
758
+						$product_variations = $wpdb->get_results($query);
759 759
 						/** Update Products Variations **/
760
-						if ( !empty($product_variations) ) {
761
-							foreach( $product_variations as $product_variation ) {
762
-								$product_data = get_post_meta( $product_variation->ID, '_wpshop_product_metadata', true);
763
-								if ( !empty($product_data) ) {
764
-									if ( !empty($product_data['tx_tva']) && array_key_exists( $product_data['tx_tva'], $tva_array) ) {
765
-										if ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) {
760
+						if (!empty($product_variations)) {
761
+							foreach ($product_variations as $product_variation) {
762
+								$product_data = get_post_meta($product_variation->ID, '_wpshop_product_metadata', true);
763
+								if (!empty($product_data)) {
764
+									if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) {
765
+										if (!empty($price_piloting_option) && $price_piloting_option == 'HT') {
766 766
 											/** Update post meta **/
767
-											$product_data['price_ht'] = (float)str_replace( ',', '.', $product_data['price_ht'] );
768
-											$product_data['product_price'] = $product_data['price_ht'] * ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
769
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
770
-											update_post_meta( $product_variation->ID, '_wpshop_product_metadata', $product_data);
767
+											$product_data['price_ht'] = (float)str_replace(',', '.', $product_data['price_ht']);
768
+											$product_data['product_price'] = $product_data['price_ht'] * (1 + ($tva_array[$product_data['tx_tva']] / 100));
769
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
770
+											update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data);
771 771
 
772 772
 											/** Update attributes values **/
773
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) );
774
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) );
775
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) );
773
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID));
774
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID));
775
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID));
776 776
 										}
777 777
 										else {
778 778
 											/** Update post meta **/
779
-											$product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] );
780
-											$product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) );
781
-											$product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) );
782
-											update_post_meta( $product_variation->ID, '_wpshop_product_metadata', $product_data);
779
+											$product_data['product_price'] = (float)str_replace(',', '.', $product_data['product_price']);
780
+											$product_data['price_ht'] = $product_data['product_price'] / (1 + ($tva_array[$product_data['tx_tva']] / 100));
781
+											$product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100));
782
+											update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data);
783 783
 
784 784
 											/** Update attributes values **/
785
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) );
786
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) );
787
-											$wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) );
785
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID));
786
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID));
787
+											$wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID));
788 788
 										}
789 789
 									}
790 790
 								}
@@ -801,15 +801,15 @@  discard block
 block discarded – undo
801 801
 				}
802 802
 			}
803 803
 			else {
804
-				$result = __( 'VAT rate attribute was not found', 'wpshop' );
804
+				$result = __('VAT rate attribute was not found', 'wpshop');
805 805
 			}
806
-			return array( $status, $result );
806
+			return array($status, $result);
807 807
 		}
808 808
 
809 809
 	}
810 810
 
811 811
 }
812 812
 /**	Instanciate the module utilities if not	*/
813
-if ( class_exists("wpshop_prices") ) {
813
+if (class_exists("wpshop_prices")) {
814 814
 	$wpshop_prices = new wpshop_prices();
815 815
 }
Please login to merge, or discard this patch.
script/wp-emulator.script.php 4 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -110,11 +110,17 @@  discard block
 block discarded – undo
110 110
 		echo "[+] Registering actiovation hook -> " . $file . " in " . $hooked . PHP_EOL;
111 111
 	}
112 112
 
113
+	/**
114
+	 * @param string $name
115
+	 */
113 116
 	function add_filter( $name, $fn, $nbr = "")
114 117
 	{
115 118
 		echo "[+] Adding filter -> " . $name . " X" . $nbr . PHP_EOL;
116 119
 	}
117 120
 
121
+	/**
122
+	 * @param string $name
123
+	 */
118 124
 	function add_shortcode( $name )
119 125
 	{
120 126
 		echo "[+] Adding shortcode -> " . $name . PHP_EOL;
@@ -150,6 +156,9 @@  discard block
 block discarded – undo
150 156
 		echo "[+] Loading text domain" . PHP_EOL;
151 157
 	}
152 158
 
159
+	/**
160
+	 * @param string $path
161
+	 */
153 162
 	function plugin_dir_path($path)
154 163
 	{
155 164
 		echo "[+] Plugin path -> " . $path . PHP_EOL;
@@ -249,6 +258,9 @@  discard block
 block discarded – undo
249 258
 		return "";
250 259
 	}
251 260
 
261
+	/**
262
+	 * @param string $str
263
+	 */
252 264
 	function current_time( $str )
253 265
 	{
254 266
 		$time = " 2005-08-05 10:41:13";
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 
159 159
 	function trailingslashit( $string )
160 160
 	{
161
-	    return untrailingslashit( $string ) . '/';
161
+		return untrailingslashit( $string ) . '/';
162 162
 	}
163 163
 
164 164
 	function untrailingslashit( $string )
165 165
 	{
166
-	        return rtrim( $string, '/\\' );
166
+			return rtrim( $string, '/\\' );
167 167
 	}
168 168
 
169 169
 	function site_url()
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 		public $term_relationships = "term_relationship";
289 289
 		public $term_taxonomy = "term_taxonomy";
290 290
 
291
-    }
291
+	}
292 292
 
293 293
 	class WP_Widget
294 294
 	{
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 	define('ABSPATH', dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR);
3
-	define('WP_PLUGIN_DIR', dirname(dirname(dirname(__FILE__))) );
3
+	define('WP_PLUGIN_DIR', dirname(dirname(dirname(__FILE__))));
4 4
 	define('WP_LANG_DIR', 'FR');
5 5
 	define('WP_CONTENT_DIR', 'wp-content');
6 6
 
7
-	function __( $str )
7
+	function __($str)
8 8
 	{
9 9
 		$translate = "Result Testing text";
10 10
 		echo "[+] Requesting __ -> " . $str . PHP_EOL;
11 11
 		return $translate;
12 12
 	}
13 13
 
14
-	function add_action( $init, $object )
14
+	function add_action($init, $object)
15 15
 	{
16 16
 		$length = 0;
17 17
 		$hooked = "";
18 18
 		$oType = gettype($object);
19
-		if($oType == "object" || $oType == "array")
19
+		if ($oType == "object" || $oType == "array")
20 20
 		{
21 21
 			$hooked = "[";
22
-			foreach($object as $hook)
22
+			foreach ($object as $hook)
23 23
 			{
24 24
 				$length++;
25 25
 				$type = gettype($hook);
26 26
 
27
-				switch($type)
27
+				switch ($type)
28 28
 				{
29 29
 					case "integer":
30 30
 					case "boolean":
@@ -37,27 +37,27 @@  discard block
 block discarded – undo
37 37
 						break;
38 38
 				}
39 39
 			}
40
-			if($length > 0) $hooked = rtrim($hooked, ",");
40
+			if ($length > 0) $hooked = rtrim($hooked, ",");
41 41
 			$hooked .= "]";
42 42
 		}
43 43
 		else $hooked .= $object;
44 44
 		echo "[+] Adding action -> " . $init . " in " . $hooked . PHP_EOL;
45 45
 	}
46 46
 
47
-	function register_activation_hook( $file , $object )
47
+	function register_activation_hook($file, $object)
48 48
 	{
49 49
 		$length = 0;
50 50
 		$hooked = "";
51 51
 		$oType = gettype($object);
52
-		if($oType == "object" || $oType == "array")
52
+		if ($oType == "object" || $oType == "array")
53 53
 		{
54 54
 			$hooked = "[";
55
-			foreach($object as $hook)
55
+			foreach ($object as $hook)
56 56
 			{
57 57
 				$length++;
58 58
 				$type = gettype($hook);
59 59
 
60
-				switch($type)
60
+				switch ($type)
61 61
 				{
62 62
 					case "integer":
63 63
 					case "boolean":
@@ -70,27 +70,27 @@  discard block
 block discarded – undo
70 70
 						break;
71 71
 				}
72 72
 			}
73
-			if($length > 0) $hooked = rtrim($hooked, ",");
73
+			if ($length > 0) $hooked = rtrim($hooked, ",");
74 74
 			$hooked .= "]";
75 75
 		}
76 76
 		else $hooked .= $object;
77 77
 		echo "[+] Registering actiovation hook -> " . $file . " in " . $hooked . PHP_EOL;
78 78
 	}
79 79
 
80
-	function register_deactivation_hook( $file , $object )
80
+	function register_deactivation_hook($file, $object)
81 81
 	{
82 82
 		$length = 0;
83 83
 		$hooked = "";
84 84
 		$oType = gettype($object);
85
-		if($oType == "object" || $oType == "array")
85
+		if ($oType == "object" || $oType == "array")
86 86
 		{
87 87
 			$hooked = "[";
88
-			foreach($object as $hook)
88
+			foreach ($object as $hook)
89 89
 			{
90 90
 				$length++;
91 91
 				$type = gettype($hook);
92 92
 
93
-				switch($type)
93
+				switch ($type)
94 94
 				{
95 95
 					case "integer":
96 96
 					case "boolean":
@@ -103,29 +103,29 @@  discard block
 block discarded – undo
103 103
 						break;
104 104
 				}
105 105
 			}
106
-			if($length > 0) $hooked = rtrim($hooked, ",");
106
+			if ($length > 0) $hooked = rtrim($hooked, ",");
107 107
 			$hooked .= "]";
108 108
 		}
109 109
 		else $hooked .= $object;
110 110
 		echo "[+] Registering actiovation hook -> " . $file . " in " . $hooked . PHP_EOL;
111 111
 	}
112 112
 
113
-	function add_filter( $name, $fn, $nbr = "")
113
+	function add_filter($name, $fn, $nbr = "")
114 114
 	{
115 115
 		echo "[+] Adding filter -> " . $name . " X" . $nbr . PHP_EOL;
116 116
 	}
117 117
 
118
-	function add_shortcode( $name )
118
+	function add_shortcode($name)
119 119
 	{
120 120
 		echo "[+] Adding shortcode -> " . $name . PHP_EOL;
121 121
 	}
122 122
 
123
-	function add_option( $name, $conf)
123
+	function add_option($name, $conf)
124 124
 	{
125 125
 		echo "[+] Adding option -> " . $name . " conf:" . $conf . PHP_EOL;
126 126
 	}
127 127
 
128
-	function update_option( $name, $conf)
128
+	function update_option($name, $conf)
129 129
 	{
130 130
 		echo "[+] Updating option -> " . $name . " conf:" . $conf . PHP_EOL;
131 131
 	}
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
 	function plugin_dir_path($path)
154 154
 	{
155 155
 		echo "[+] Plugin path -> " . $path . PHP_EOL;
156
-		return trailingslashit( dirname( $path ) );
156
+		return trailingslashit(dirname($path));
157 157
 	}
158 158
 
159
-	function trailingslashit( $string )
159
+	function trailingslashit($string)
160 160
 	{
161
-	    return untrailingslashit( $string ) . '/';
161
+	    return untrailingslashit($string) . '/';
162 162
 	}
163 163
 
164
-	function untrailingslashit( $string )
164
+	function untrailingslashit($string)
165 165
 	{
166
-	        return rtrim( $string, '/\\' );
166
+	        return rtrim($string, '/\\');
167 167
 	}
168 168
 
169 169
 	function site_url()
@@ -215,12 +215,12 @@  discard block
 block discarded – undo
215 215
 		return $dir;
216 216
 	}
217 217
 
218
-	function add_theme_support( $theme )
218
+	function add_theme_support($theme)
219 219
 	{
220 220
 		echo "[+] Adding theme support -> " . $theme . PHP_EOL;
221 221
 	}
222 222
 
223
-	function add_image_size( $image, $x, $y, $bool )
223
+	function add_image_size($image, $x, $y, $bool)
224 224
 	{
225 225
 		echo "[+] Adding image size -> " . $image . " x:" . $x . " y:" . $y . " bool:" . $bool . PHP_EOL;
226 226
 	}
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
 		return $lang;
233 233
 	}
234 234
 
235
-	function load_plugin_textdomain( $name, $bool, $dir)
235
+	function load_plugin_textdomain($name, $bool, $dir)
236 236
 	{
237 237
 		echo "[+] Loading plugin textdomain -> " . $name . " bool:" . $bool . " dir:" . $dir . PHP_EOL;
238 238
 	}
239 239
 
240
-	function get_option( $name, $int = 0 )
240
+	function get_option($name, $int = 0)
241 241
 	{
242 242
 		echo "[+] Getting option -> " . $name . " int:" . $int . PHP_EOL;
243 243
 		return "";
244 244
 	}
245 245
 
246
-	function get_site_option( $name, $int = 0 )
246
+	function get_site_option($name, $int = 0)
247 247
 	{
248 248
 		echo "[+] Getting site option -> " . $name . " int:" . $int . PHP_EOL;
249 249
 		return "";
250 250
 	}
251 251
 
252
-	function current_time( $str )
252
+	function current_time($str)
253 253
 	{
254 254
 		$time = " 2005-08-05 10:41:13";
255 255
 		echo "[+] Requesting current_time -> " . $str . PHP_EOL;
@@ -258,17 +258,17 @@  discard block
 block discarded – undo
258 258
 
259 259
 	class WPDB
260 260
 	{
261
-		function prepare( $request = "" )
261
+		function prepare($request = "")
262 262
 		{
263 263
 			echo "[+] Preparing -> " . $request . PHP_EOL;
264 264
 		}
265 265
 
266
-		public static function get_var( $request = "" )
266
+		public static function get_var($request = "")
267 267
 		{
268 268
 			echo "[+] Requesting get var -> " . $request . PHP_EOL;
269 269
 		}
270 270
 
271
-		public static function get_charset_collate( $request = "" )
271
+		public static function get_charset_collate($request = "")
272 272
 		{
273 273
 			echo "[+] Requesting get charset collate -> " . $request . PHP_EOL;
274 274
 		}
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,10 +37,13 @@  discard block
 block discarded – undo
37 37
 						break;
38 38
 				}
39 39
 			}
40
-			if($length > 0) $hooked = rtrim($hooked, ",");
40
+			if($length > 0) {
41
+				$hooked = rtrim($hooked, ",");
42
+			}
41 43
 			$hooked .= "]";
44
+		} else {
45
+			$hooked .= $object;
42 46
 		}
43
-		else $hooked .= $object;
44 47
 		echo "[+] Adding action -> " . $init . " in " . $hooked . PHP_EOL;
45 48
 	}
46 49
 
@@ -70,10 +73,13 @@  discard block
 block discarded – undo
70 73
 						break;
71 74
 				}
72 75
 			}
73
-			if($length > 0) $hooked = rtrim($hooked, ",");
76
+			if($length > 0) {
77
+				$hooked = rtrim($hooked, ",");
78
+			}
74 79
 			$hooked .= "]";
80
+		} else {
81
+			$hooked .= $object;
75 82
 		}
76
-		else $hooked .= $object;
77 83
 		echo "[+] Registering actiovation hook -> " . $file . " in " . $hooked . PHP_EOL;
78 84
 	}
79 85
 
@@ -103,10 +109,13 @@  discard block
 block discarded – undo
103 109
 						break;
104 110
 				}
105 111
 			}
106
-			if($length > 0) $hooked = rtrim($hooked, ",");
112
+			if($length > 0) {
113
+				$hooked = rtrim($hooked, ",");
114
+			}
107 115
 			$hooked .= "]";
116
+		} else {
117
+			$hooked .= $object;
108 118
 		}
109
-		else $hooked .= $object;
110 119
 		echo "[+] Registering actiovation hook -> " . $file . " in " . $hooked . PHP_EOL;
111 120
 	}
112 121
 
Please login to merge, or discard this patch.
script/unit.script.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $unitList = searchFiles('.' . DIRECTORY_SEPARATOR, END_TEST);
11 11
 
12 12
 // Loop on unitList
13
-foreach($unitList as $test)
13
+foreach ($unitList as $test)
14 14
 {
15 15
 	echo "[+] Testing -> " . $test . PHP_EOL;
16 16
 	include($test);
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	$ite = new RecursiveIteratorIterator($dir);
29 29
 	$files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
30 30
 	$fileList = array();
31
-	foreach($files as $file)
31
+	foreach ($files as $file)
32 32
 	{
33 33
 		$fileList[] = $file[0];
34 34
 	}
Please login to merge, or discard this patch.
includes/librairies/eav/wp_list_custom_attributes.class.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 		 * to keep hidden, and a list of columns that are sortable. Each of these
315 315
 		 * can be defined in another method (as we've done here) before being
316 316
 		 * used to build the value for our _column_headers property.
317
-		*/
317
+		 */
318 318
 		$columns = $this->get_columns();
319 319
 		$hidden = array();
320 320
 		$sortable = $this->get_sortable_columns();
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
 		 * headers. The $this->_column_headers property takes an array which contains
325 325
 		 * 3 other arrays. One for all columns, one for hidden columns, and one
326 326
 		 * for sortable columns.
327
-		*/
327
+		 */
328 328
 		$this->_column_headers = array($columns, $hidden, $sortable);
329 329
 
330 330
 		/**
331 331
 		 * Optional. You can handle your bulk actions however you see fit. In this
332 332
 		 * case, we'll handle them within our package just to keep things clean.
333
-		*/
333
+		 */
334 334
 		$this->process_bulk_action();
335 335
 
336 336
 		/**
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
 		 * our data. In a real-world implementation, you will probably want to
342 342
 		 * use sort and pagination data to build a custom query instead, as you'll
343 343
 		 * be able to use your precisely-queried data immediately.
344
-		*/
344
+		 */
345 345
 		$data = $this->datas;
346 346
 
347 347
 		/**
348 348
 		 * REQUIRED for pagination. Let's figure out what page the user is currently
349 349
 		 * looking at. We'll need this later, so you should always include it in
350 350
 		 * your own package classes.
351
-		*/
351
+		 */
352 352
 		$current_page = $this->get_pagenum();
353 353
 
354 354
 		/**
@@ -356,20 +356,20 @@  discard block
 block discarded – undo
356 356
 		 * In real-world use, this would be the total number of items in your database,
357 357
 		 * without filtering. We'll need this later, so you should always include it
358 358
 		 * in your own package classes.
359
-		*/
359
+		 */
360 360
 		$total_items = count($data);
361 361
 
362 362
 		/**
363 363
 		 * The WP_List_Table class does not handle pagination for us, so we need
364 364
 		 * to ensure that the data is trimmed to only the current page. We can use
365 365
 		 * array_slice() to
366
-		*/
366
+		 */
367 367
 		$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
368 368
 
369 369
 		/**
370 370
 		 * REQUIRED. Now we can add our *sorted* data to the items property, where
371 371
 		 * it can be used by the rest of the class.
372
-		*/
372
+		 */
373 373
 		$this->items = $data;
374 374
 
375 375
 		/*	REQUIRED. We also have to register our pagination options & calculations.	*/
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 
3 5
 /*	Check if file is include. No direct access possible with file url	*/
4 6
 if ( !defined( 'WPSHOP_VERSION' ) ) {
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 
@@ -12,38 +12,38 @@  discard block
 block discarded – undo
12 12
  * @package wpshop
13 13
  * @subpackage librairies
14 14
  */
15
-class wpshop_attributes_custom_List_table extends WP_List_Table{
15
+class wpshop_attributes_custom_List_table extends WP_List_Table {
16 16
 	var $datas;
17 17
 
18 18
 	/** ************************************************************************
19 19
 	 * REQUIRED. Set up a constructor that references the parent constructor. We
20 20
 	 * use the parent reference to set some default configs.
21 21
 	 ***************************************************************************/
22
-	function __construct(){
22
+	function __construct() {
23 23
 		global $status, $page;
24 24
 
25 25
 		//Set parent defaults
26
-		parent::__construct( array(
27
-			'singular'  => __('attribute\'s', 'wpshop'),    //singular name of the listed records
28
-			'plural'    => __('attributes\'', 'wpshop'),    //plural name of the listed records
26
+		parent::__construct(array(
27
+			'singular'  => __('attribute\'s', 'wpshop'), //singular name of the listed records
28
+			'plural'    => __('attributes\'', 'wpshop'), //plural name of the listed records
29 29
 			'ajax'     => true       //does this table support ajax?
30
-		) );
30
+		));
31 31
 	}
32 32
 
33 33
 	/*	Allows to set different listings for attributes	*/
34
-	function get_views(){
34
+	function get_views() {
35 35
 		$wpshop_attribute_links = array();
36 36
 
37 37
 		$active_nb = wpshop_attributes::getElement('', "'valid'");
38 38
 		$unactive_nb = wpshop_attributes::getElement('', "'moderated', 'notused'");
39 39
 		$deleted_nb = wpshop_attributes::getElement('', "'deleted'");
40 40
 
41
-		$attribute_status = !empty( $_REQUEST['attribute_status'] ) ? sanitize_text_field( $_REQUEST['attribute_status'] ) : '';
41
+		$attribute_status = !empty($_REQUEST['attribute_status']) ? sanitize_text_field($_REQUEST['attribute_status']) : '';
42 42
 
43
-		$wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_valid'.(empty($attribute_status)?' current':'')] = '<a href="'.admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING).'" >'.__('Used attributes', 'wpshop').' ('.count($active_nb).')</a>';
44
-		$wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_moderated'.(!empty($attribute_status) && ($attribute_status=='unactive')?' current':'')] = '<a href="'.admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING.'&attribute_status=unactive').'" >'.__('Unactive attributes', 'wpshop').' ('.count($unactive_nb).')</a>';
45
-		$wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_deleted'.(!empty($attribute_status) && ($attribute_status=='deleted')?' current':'')] = '<a href="'.admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING.'&attribute_status=deleted').'" >'.__('Trashed attributes', 'wpshop').' ('.count($deleted_nb).')</a>';
46
-		$wpshop_attribute_links['unit_management_link'] = '<a href="#" id="wpshop_attribute_unit_manager_opener" data-nonce="' . wp_create_nonce( 'load_unit_interface' ) . '">'.__('Unit management', 'wpshop').'</a>';
43
+		$wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_valid' . (empty($attribute_status) ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING) . '" >' . __('Used attributes', 'wpshop') . ' (' . count($active_nb) . ')</a>';
44
+		$wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_moderated' . (!empty($attribute_status) && ($attribute_status == 'unactive') ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING . '&attribute_status=unactive') . '" >' . __('Unactive attributes', 'wpshop') . ' (' . count($unactive_nb) . ')</a>';
45
+		$wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_deleted' . (!empty($attribute_status) && ($attribute_status == 'deleted') ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING . '&attribute_status=deleted') . '" >' . __('Trashed attributes', 'wpshop') . ' (' . count($deleted_nb) . ')</a>';
46
+		$wpshop_attribute_links['unit_management_link'] = '<a href="#" id="wpshop_attribute_unit_manager_opener" data-nonce="' . wp_create_nonce('load_unit_interface') . '">' . __('Unit management', 'wpshop') . '</a>';
47 47
 		$wpshop_attribute_links['unit_management_dialog'] = '<div id="wpshop_attribute_unit_manager"title="' . __('Unit management', 'wpshop') . '" class="wpshopHide" ><div class="loading_picture_container" id="product_chooser_picture" ><img src="' . WPSHOP_LOADING_ICON . '" alt="loading..." /></div></div>';
48 48
 		return $wpshop_attribute_links;
49 49
 	}
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	 * @see WP_List_Table::::single_row_columns()
62 62
 	 * @return array An associative array containing column information: 'slugs'=>'Visible Titles'
63 63
 	 **************************************************************************/
64
-	function get_columns(){
64
+	function get_columns() {
65 65
 		$columns = array(
66
-			'cb'       	=> '',//'<input type="checkbox" />', //Render a checkbox instead of text
66
+			'cb'       	=> '', //'<input type="checkbox" />', //Render a checkbox instead of text
67 67
 			'id'       	=> __('Id.', 'wpshop'),
68 68
 			'name'    	=> __('Name', 'wpshop'),
69 69
 			'status'    => __('Status', 'wpshop'),
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 	 * @param array $column_name The name/slug of the column to be processed
95 95
 	 * @return string Text or HTML to be placed inside the column <td>
96 96
 	 **************************************************************************/
97
-	function column_default($item, $column_name){
98
-		switch($column_name){
97
+	function column_default($item, $column_name) {
98
+		switch ($column_name) {
99 99
 			default:
100
-				return print_r($item,true); //Show the whole array for troubleshooting purposes
100
+				return print_r($item, true); //Show the whole array for troubleshooting purposes
101 101
 		}
102 102
 	}
103 103
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @param array $item A singular item (one full row's worth of data)
118 118
 	 * @return string Text to be placed inside the column <td> (movie title only)
119 119
 	 **************************************************************************/
120
-	function column_id($item){
120
+	function column_id($item) {
121 121
 		return $item['id'];
122 122
 	}
123 123
 	/** ************************************************************************
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 * @param array $item A singular item (one full row's worth of data)
137 137
 	 * @return string Text to be placed inside the column <td> (movie title only)
138 138
 	 **************************************************************************/
139
-	function column_status($item){
139
+	function column_status($item) {
140 140
 		return __($item['status'], 'wpshop');
141 141
 	}
142 142
 	/** ************************************************************************
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @param array $item A singular item (one full row's worth of data)
156 156
 	 * @return string Text to be placed inside the column <td> (movie title only)
157 157
 	 **************************************************************************/
158
-	function column_code($item){
158
+	function column_code($item) {
159 159
 		return $item['code'];
160 160
 	}
161 161
 	/** ************************************************************************
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 	 * @param array $item A singular item (one full row's worth of data)
175 175
 	 * @return string Text to be placed inside the column <td> (movie title only)
176 176
 	 **************************************************************************/
177
-	function column_entity($item){
178
-		return __($item['entity'],'wpshop');
177
+	function column_entity($item) {
178
+		return __($item['entity'], 'wpshop');
179 179
 	}
180 180
 	/** ************************************************************************
181 181
 	 * Recommended. This is a custom column method and is responsible for what
@@ -193,28 +193,28 @@  discard block
 block discarded – undo
193 193
 	 * @param array $item A singular item (one full row's worth of data)
194 194
 	 * @return string Text to be placed inside the column <td> (movie title only)
195 195
 	 **************************************************************************/
196
-	function column_name($item){
196
+	function column_name($item) {
197 197
 		$attribute_undeletable = unserialize(WPSHOP_ATTRIBUTE_UNDELETABLE);
198 198
 
199
-		$link_format = admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s';
200
-		$default_action='edit';
201
-		$default_action_text=__('Edit', 'wpshop');
202
-		$attribute_status = !empty( $_REQUEST['attribute_status'] ) ? sanitize_text_field( $_REQUEST['attribute_status'] ) : '';
203
-		if(!empty($attribute_status) && ($attribute_status=='deleted')){
204
-			$default_action='activate';
205
-			$default_action_text=__('Restore', 'wpshop');
199
+		$link_format = admin_url('admin.php') . '?page=%2$s&amp;action=%3$s&amp;id=%4$s';
200
+		$default_action = 'edit';
201
+		$default_action_text = __('Edit', 'wpshop');
202
+		$attribute_status = !empty($_REQUEST['attribute_status']) ? sanitize_text_field($_REQUEST['attribute_status']) : '';
203
+		if (!empty($attribute_status) && ($attribute_status == 'deleted')) {
204
+			$default_action = 'activate';
205
+			$default_action_text = __('Restore', 'wpshop');
206 206
 		}
207 207
 		//Build row actions
208 208
 		$actions = array(
209
-			'edit'     => sprintf('<a href="'.$link_format.'">'.$default_action_text.'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_LISTING,$default_action,$item['id'])
209
+			'edit'     => sprintf('<a href="' . $link_format . '">' . $default_action_text . '</a>', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, $default_action, $item['id'])
210 210
 		);
211
-		if(empty($attribute_status) && (!in_array($item['code'], $attribute_undeletable))){
212
-			$actions['delete'] = sprintf('<a href="'.$link_format.'">'.__('Delete', 'wpshop').'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_LISTING,'delete',$item['id']);
211
+		if (empty($attribute_status) && (!in_array($item['code'], $attribute_undeletable))) {
212
+			$actions['delete'] = sprintf('<a href="' . $link_format . '">' . __('Delete', 'wpshop') . '</a>', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, 'delete', $item['id']);
213 213
 		}
214 214
 
215 215
 		//Return the title contents
216 216
 		return sprintf('%1$s%2$s',
217
-			/*$1%s*/ sprintf('<a href="'.$link_format.'">'.__($item['name'], 'wpshop').'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_LISTING,$default_action,$item['id']),
217
+			/*$1%s*/ sprintf('<a href="' . $link_format . '">' . __($item['name'], 'wpshop') . '</a>', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, $default_action, $item['id']),
218 218
 			/*$3%s*/ $this->row_actions($actions)
219 219
 		);
220 220
 	}
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 	 * @param array $item A singular item (one full row's worth of data)
228 228
 	 * @return string Text to be placed inside the column <td> (movie title only)
229 229
 	 **************************************************************************/
230
-	function column_cb($item){
230
+	function column_cb($item) {
231 231
 		return '';
232 232
 		return sprintf(
233 233
 			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
234
-			/*$1%s*/ $this->_args['singular'],  //Let's simply repurpose the table's singular label ("movie")
234
+			/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
235 235
 			/*$2%s*/ $item['id']             //The value of the checkbox should be the record's id
236 236
 		);
237 237
 	}
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 **************************************************************************/
253 253
 	function get_sortable_columns() {
254 254
 		$sortable_columns = array(
255
-			'name'    => array('frontend_label',true),    //true means its already sorted
256
-			'status'  => array('status',true)
255
+			'name'    => array('frontend_label', true), //true means its already sorted
256
+			'status'  => array('status', true)
257 257
 		);
258 258
 		return $sortable_columns;
259 259
 	}
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 	 **************************************************************************/
289 289
 	function process_bulk_action() {
290 290
 		//Detect when a bulk action is being triggered...
291
-		if( 'delete'===$this->current_action() ) {
291
+		if ('delete' === $this->current_action()) {
292 292
 			wp_die('Items deleted (or they would be if we had items to delete)!');
293 293
 		}
294 294
 	}
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 **************************************************************************/
310 310
 	function prepare_items() {
311 311
 		/*	First, lets decide how many records per page to show	*/
312
-		$per_page = 10;//$this->get_items_per_page('attributes_per_page', 10);
312
+		$per_page = 10; //$this->get_items_per_page('attributes_per_page', 10);
313 313
 
314 314
 		/**
315 315
 		 * REQUIRED. Now we need to define our column headers. This includes a complete
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		 * to ensure that the data is trimmed to only the current page. We can use
368 368
 		 * array_slice() to
369 369
 		*/
370
-		$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
370
+		$data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
371 371
 
372 372
 		/**
373 373
 		 * REQUIRED. Now we can add our *sorted* data to the items property, where
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 		$this->items = $data;
377 377
 
378 378
 		/*	REQUIRED. We also have to register our pagination options & calculations.	*/
379
-		$this->set_pagination_args( array(
380
-			'total_items' => $total_items,               		//WE have to calculate the total number of items
381
-			'per_page'    => $per_page,                 		//WE have to determine how many items to show on a page
382
-			'total_pages' => ceil($total_items/$per_page)   //WE have to calculate the total number of pages
383
-		) );
379
+		$this->set_pagination_args(array(
380
+			'total_items' => $total_items, //WE have to calculate the total number of items
381
+			'per_page'    => $per_page, //WE have to determine how many items to show on a page
382
+			'total_pages' => ceil($total_items / $per_page)   //WE have to calculate the total number of pages
383
+		));
384 384
 	}
385 385
 }
Please login to merge, or discard this patch.
includes/librairies/eav/wp_list_custom_attributes_set.class.php 3 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 	var $datas;
17 17
 
18 18
 	/** ************************************************************************
19
-	* REQUIRED. Set up a constructor that references the parent constructor. We
20
-	* use the parent reference to set some default configs.
21
-	***************************************************************************/
19
+	 * REQUIRED. Set up a constructor that references the parent constructor. We
20
+	 * use the parent reference to set some default configs.
21
+	 ***************************************************************************/
22 22
 	function __construct(){
23 23
 		global $status, $page;
24 24
 
@@ -44,18 +44,18 @@  discard block
 block discarded – undo
44 44
 	}
45 45
 
46 46
 	/** ************************************************************************
47
-	* REQUIRED! This method dictates the table's columns and titles. This should
48
-	* return an array where the key is the column slug (and class) and the value
49
-	* is the column's title text. If you need a checkbox for bulk actions, refer
50
-	* to the $columns array below.
51
-	*
52
-	* The 'cb' column is treated differently than the rest. If including a checkbox
53
-	* column in your table you must create a column_cb() method. If you don't need
54
-	* bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
55
-	*
56
-	* @see WP_List_Table::::single_row_columns()
57
-	* @return array An associative array containing column information: 'slugs'=>'Visible Titles'
58
-	**************************************************************************/
47
+	 * REQUIRED! This method dictates the table's columns and titles. This should
48
+	 * return an array where the key is the column slug (and class) and the value
49
+	 * is the column's title text. If you need a checkbox for bulk actions, refer
50
+	 * to the $columns array below.
51
+	 *
52
+	 * The 'cb' column is treated differently than the rest. If including a checkbox
53
+	 * column in your table you must create a column_cb() method. If you don't need
54
+	 * bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
55
+	 *
56
+	 * @see WP_List_Table::::single_row_columns()
57
+	 * @return array An associative array containing column information: 'slugs'=>'Visible Titles'
58
+	 **************************************************************************/
59 59
 	function get_columns(){
60 60
 		$columns = array(
61 61
 			'cb'       => '',//'<input type="checkbox" />', //Render a checkbox instead of text
@@ -69,26 +69,26 @@  discard block
 block discarded – undo
69 69
 	}
70 70
 
71 71
 	/** ************************************************************************
72
-	* Recommended. This method is called when the parent class can't find a method
73
-	* specifically build for a given column. Generally, it's recommended to include
74
-	* one method for each column you want to render, keeping your package class
75
-	* neat and organized. For example, if the class needs to process a column
76
-	* named 'title', it would first see if a method named $this->column_title()
77
-	* exists - if it does, that method will be used. If it doesn't, this one will
78
-	* be used. Generally, you should try to use custom column methods as much as
79
-	* possible.
80
-	*
81
-	* Since we have defined a column_title() method later on, this method doesn't
82
-	* need to concern itself with any column with a name of 'title'. Instead, it
83
-	* needs to handle everything else.
84
-	*
85
-	* For more detailed insight into how columns are handled, take a look at
86
-	* WP_List_Table::single_row_columns()
87
-	*
88
-	* @param array $item A singular item (one full row's worth of data)
89
-	* @param array $column_name The name/slug of the column to be processed
90
-	* @return string Text or HTML to be placed inside the column <td>
91
-	**************************************************************************/
72
+	 * Recommended. This method is called when the parent class can't find a method
73
+	 * specifically build for a given column. Generally, it's recommended to include
74
+	 * one method for each column you want to render, keeping your package class
75
+	 * neat and organized. For example, if the class needs to process a column
76
+	 * named 'title', it would first see if a method named $this->column_title()
77
+	 * exists - if it does, that method will be used. If it doesn't, this one will
78
+	 * be used. Generally, you should try to use custom column methods as much as
79
+	 * possible.
80
+	 *
81
+	 * Since we have defined a column_title() method later on, this method doesn't
82
+	 * need to concern itself with any column with a name of 'title'. Instead, it
83
+	 * needs to handle everything else.
84
+	 *
85
+	 * For more detailed insight into how columns are handled, take a look at
86
+	 * WP_List_Table::single_row_columns()
87
+	 *
88
+	 * @param array $item A singular item (one full row's worth of data)
89
+	 * @param array $column_name The name/slug of the column to be processed
90
+	 * @return string Text or HTML to be placed inside the column <td>
91
+	 **************************************************************************/
92 92
 	function column_default($item, $column_name){
93 93
 		switch($column_name){
94 94
 			default:
@@ -97,97 +97,97 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	/** ************************************************************************
100
-	* Recommended. This is a custom column method and is responsible for what
101
-	* is rendered in any column with a name/slug of 'title'. Every time the class
102
-	* needs to render a column, it first looks for a method named
103
-	* column_{$column_title} - if it exists, that method is run. If it doesn't
104
-	* exist, column_default() is called instead.
105
-	*
106
-	* This example also illustrates how to implement rollover actions. Actions
107
-	* should be an associative array formatted as 'slug'=>'link html' - and you
108
-	* will need to generate the URLs yourself. You could even ensure the links
109
-	*
110
-	*
111
-	* @see WP_List_Table::::single_row_columns()
112
-	* @param array $item A singular item (one full row's worth of data)
113
-	* @return string Text to be placed inside the column <td> (movie title only)
114
-	**************************************************************************/
100
+	 * Recommended. This is a custom column method and is responsible for what
101
+	 * is rendered in any column with a name/slug of 'title'. Every time the class
102
+	 * needs to render a column, it first looks for a method named
103
+	 * column_{$column_title} - if it exists, that method is run. If it doesn't
104
+	 * exist, column_default() is called instead.
105
+	 *
106
+	 * This example also illustrates how to implement rollover actions. Actions
107
+	 * should be an associative array formatted as 'slug'=>'link html' - and you
108
+	 * will need to generate the URLs yourself. You could even ensure the links
109
+	 *
110
+	 *
111
+	 * @see WP_List_Table::::single_row_columns()
112
+	 * @param array $item A singular item (one full row's worth of data)
113
+	 * @return string Text to be placed inside the column <td> (movie title only)
114
+	 **************************************************************************/
115 115
 	function column_id($item){
116 116
 		return $item['id'];
117 117
 	}
118 118
 	/** ************************************************************************
119
-	* Recommended. This is a custom column method and is responsible for what
120
-	* is rendered in any column with a name/slug of 'title'. Every time the class
121
-	* needs to render a column, it first looks for a method named
122
-	* column_{$column_title} - if it exists, that method is run. If it doesn't
123
-	* exist, column_default() is called instead.
124
-	*
125
-	* This example also illustrates how to implement rollover actions. Actions
126
-	* should be an associative array formatted as 'slug'=>'link html' - and you
127
-	* will need to generate the URLs yourself. You could even ensure the links
128
-	*
129
-	*
130
-	* @see WP_List_Table::::single_row_columns()
131
-	* @param array $item A singular item (one full row's worth of data)
132
-	* @return string Text to be placed inside the column <td> (movie title only)
133
-	**************************************************************************/
119
+	 * Recommended. This is a custom column method and is responsible for what
120
+	 * is rendered in any column with a name/slug of 'title'. Every time the class
121
+	 * needs to render a column, it first looks for a method named
122
+	 * column_{$column_title} - if it exists, that method is run. If it doesn't
123
+	 * exist, column_default() is called instead.
124
+	 *
125
+	 * This example also illustrates how to implement rollover actions. Actions
126
+	 * should be an associative array formatted as 'slug'=>'link html' - and you
127
+	 * will need to generate the URLs yourself. You could even ensure the links
128
+	 *
129
+	 *
130
+	 * @see WP_List_Table::::single_row_columns()
131
+	 * @param array $item A singular item (one full row's worth of data)
132
+	 * @return string Text to be placed inside the column <td> (movie title only)
133
+	 **************************************************************************/
134 134
 	function column_status($item){
135 135
 		return __($item['status'], 'wpshop');
136 136
 	}
137 137
 	/** ************************************************************************
138
-	* Recommended. This is a custom column method and is responsible for what
139
-	* is rendered in any column with a name/slug of 'title'. Every time the class
140
-	* needs to render a column, it first looks for a method named
141
-	* column_{$column_title} - if it exists, that method is run. If it doesn't
142
-	* exist, column_default() is called instead.
143
-	*
144
-	* This example also illustrates how to implement rollover actions. Actions
145
-	* should be an associative array formatted as 'slug'=>'link html' - and you
146
-	* will need to generate the URLs yourself. You could even ensure the links
147
-	*
148
-	*
149
-	* @see WP_List_Table::::single_row_columns()
150
-	* @param array $item A singular item (one full row's worth of data)
151
-	* @return string Text to be placed inside the column <td> (movie title only)
152
-	**************************************************************************/
138
+	 * Recommended. This is a custom column method and is responsible for what
139
+	 * is rendered in any column with a name/slug of 'title'. Every time the class
140
+	 * needs to render a column, it first looks for a method named
141
+	 * column_{$column_title} - if it exists, that method is run. If it doesn't
142
+	 * exist, column_default() is called instead.
143
+	 *
144
+	 * This example also illustrates how to implement rollover actions. Actions
145
+	 * should be an associative array formatted as 'slug'=>'link html' - and you
146
+	 * will need to generate the URLs yourself. You could even ensure the links
147
+	 *
148
+	 *
149
+	 * @see WP_List_Table::::single_row_columns()
150
+	 * @param array $item A singular item (one full row's worth of data)
151
+	 * @return string Text to be placed inside the column <td> (movie title only)
152
+	 **************************************************************************/
153 153
 	function column_content($item){
154 154
 		return $item['content'];
155 155
 	}
156 156
 	/** ************************************************************************
157
-	* Recommended. This is a custom column method and is responsible for what
158
-	* is rendered in any column with a name/slug of 'title'. Every time the class
159
-	* needs to render a column, it first looks for a method named
160
-	* column_{$column_title} - if it exists, that method is run. If it doesn't
161
-	* exist, column_default() is called instead.
162
-	*
163
-	* This example also illustrates how to implement rollover actions. Actions
164
-	* should be an associative array formatted as 'slug'=>'link html' - and you
165
-	* will need to generate the URLs yourself. You could even ensure the links
166
-	*
167
-	*
168
-	* @see WP_List_Table::::single_row_columns()
169
-	* @param array $item A singular item (one full row's worth of data)
170
-	* @return string Text to be placed inside the column <td> (movie title only)
171
-	**************************************************************************/
157
+	 * Recommended. This is a custom column method and is responsible for what
158
+	 * is rendered in any column with a name/slug of 'title'. Every time the class
159
+	 * needs to render a column, it first looks for a method named
160
+	 * column_{$column_title} - if it exists, that method is run. If it doesn't
161
+	 * exist, column_default() is called instead.
162
+	 *
163
+	 * This example also illustrates how to implement rollover actions. Actions
164
+	 * should be an associative array formatted as 'slug'=>'link html' - and you
165
+	 * will need to generate the URLs yourself. You could even ensure the links
166
+	 *
167
+	 *
168
+	 * @see WP_List_Table::::single_row_columns()
169
+	 * @param array $item A singular item (one full row's worth of data)
170
+	 * @return string Text to be placed inside the column <td> (movie title only)
171
+	 **************************************************************************/
172 172
 	function column_entity($item){
173 173
 		return __($item['entity'],'wpshop');
174 174
 	}
175 175
 	/** ************************************************************************
176
-	* Recommended. This is a custom column method and is responsible for what
177
-	* is rendered in any column with a name/slug of 'title'. Every time the class
178
-	* needs to render a column, it first looks for a method named
179
-	* column_{$column_title} - if it exists, that method is run. If it doesn't
180
-	* exist, column_default() is called instead.
181
-	*
182
-	* This example also illustrates how to implement rollover actions. Actions
183
-	* should be an associative array formatted as 'slug'=>'link html' - and you
184
-	* will need to generate the URLs yourself. You could even ensure the links
185
-	*
186
-	*
187
-	* @see WP_List_Table::::single_row_columns()
188
-	* @param array $item A singular item (one full row's worth of data)
189
-	* @return string Text to be placed inside the column <td> (movie title only)
190
-	**************************************************************************/
176
+	 * Recommended. This is a custom column method and is responsible for what
177
+	 * is rendered in any column with a name/slug of 'title'. Every time the class
178
+	 * needs to render a column, it first looks for a method named
179
+	 * column_{$column_title} - if it exists, that method is run. If it doesn't
180
+	 * exist, column_default() is called instead.
181
+	 *
182
+	 * This example also illustrates how to implement rollover actions. Actions
183
+	 * should be an associative array formatted as 'slug'=>'link html' - and you
184
+	 * will need to generate the URLs yourself. You could even ensure the links
185
+	 *
186
+	 *
187
+	 * @see WP_List_Table::::single_row_columns()
188
+	 * @param array $item A singular item (one full row's worth of data)
189
+	 * @return string Text to be placed inside the column <td> (movie title only)
190
+	 **************************************************************************/
191 191
 	function column_name($item){
192 192
 		//Build row actions
193 193
 		$default_action='edit';
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 		);
209 209
 	}
210 210
 	/** ************************************************************************
211
-	* REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column
212
-	* is given special treatment when columns are processed. It ALWAYS needs to
213
-	* have it's own method.
214
-	*
215
-	* @see WP_List_Table::::single_row_columns()
216
-	* @param array $item A singular item (one full row's worth of data)
217
-	* @return string Text to be placed inside the column <td> (movie title only)
218
-	**************************************************************************/
211
+	 * REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column
212
+	 * is given special treatment when columns are processed. It ALWAYS needs to
213
+	 * have it's own method.
214
+	 *
215
+	 * @see WP_List_Table::::single_row_columns()
216
+	 * @param array $item A singular item (one full row's worth of data)
217
+	 * @return string Text to be placed inside the column <td> (movie title only)
218
+	 **************************************************************************/
219 219
 	function column_cb($item){
220 220
 		return '';
221 221
 		return sprintf(
@@ -226,19 +226,19 @@  discard block
 block discarded – undo
226 226
 	}
227 227
 
228 228
 	/** ************************************************************************
229
-	* Optional. If you want one or more columns to be sortable (ASC/DESC toggle),
230
-	* you will need to register it here. This should return an array where the
231
-	* key is the column that needs to be sortable, and the value is db column to
232
-	* sort by. Often, the key and value will be the same, but this is not always
233
-	* the case (as the value is a column name from the database, not the list table).
234
-	*
235
-	* This method merely defines which columns should be sortable and makes them
236
-	* clickable - it does not handle the actual sorting. You still need to detect
237
-	* the ORDERBY and ORDER querystring variables within prepare_items() and sort
238
-	* your data accordingly (usually by modifying your query).
239
-	*
240
-	* @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool)
241
-	**************************************************************************/
229
+	 * Optional. If you want one or more columns to be sortable (ASC/DESC toggle),
230
+	 * you will need to register it here. This should return an array where the
231
+	 * key is the column that needs to be sortable, and the value is db column to
232
+	 * sort by. Often, the key and value will be the same, but this is not always
233
+	 * the case (as the value is a column name from the database, not the list table).
234
+	 *
235
+	 * This method merely defines which columns should be sortable and makes them
236
+	 * clickable - it does not handle the actual sorting. You still need to detect
237
+	 * the ORDERBY and ORDER querystring variables within prepare_items() and sort
238
+	 * your data accordingly (usually by modifying your query).
239
+	 *
240
+	 * @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool)
241
+	 **************************************************************************/
242 242
 	function get_sortable_columns() {
243 243
 		$sortable_columns = array(
244 244
 			//'name'    => array('name',true)    //true means its already sorted
@@ -247,19 +247,19 @@  discard block
 block discarded – undo
247 247
 	}
248 248
 
249 249
 	/** ************************************************************************
250
-	* Optional. If you need to include bulk actions in your list table, this is
251
-	* the place to define them. Bulk actions are an associative array in the format
252
-	* 'slug'=>'Visible Title'
253
-	*
254
-	* If this method returns an empty value, no bulk action will be rendered. If
255
-	* you specify any bulk actions, the bulk actions box will be rendered with
256
-	* the table automatically on display().
257
-	*
258
-	* Also note that list tables are not automatically wrapped in <form> elements,
259
-	* so you will need to create those manually in order for bulk actions to function.
260
-	*
261
-	* @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles'
262
-	**************************************************************************/
250
+	 * Optional. If you need to include bulk actions in your list table, this is
251
+	 * the place to define them. Bulk actions are an associative array in the format
252
+	 * 'slug'=>'Visible Title'
253
+	 *
254
+	 * If this method returns an empty value, no bulk action will be rendered. If
255
+	 * you specify any bulk actions, the bulk actions box will be rendered with
256
+	 * the table automatically on display().
257
+	 *
258
+	 * Also note that list tables are not automatically wrapped in <form> elements,
259
+	 * so you will need to create those manually in order for bulk actions to function.
260
+	 *
261
+	 * @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles'
262
+	 **************************************************************************/
263 263
 	function get_bulk_actions() {
264 264
 		$actions = array(
265 265
 			// 'delete'    => __('Delete','wpshop')
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 	}
269 269
 
270 270
 	/** ************************************************************************
271
-	* Optional. You can handle your bulk actions anywhere or anyhow you prefer.
272
-	* For this example package, we will handle it in the class to keep things
273
-	* clean and organized.
274
-	*
275
-	* @see $this->prepare_items()
276
-	**************************************************************************/
271
+	 * Optional. You can handle your bulk actions anywhere or anyhow you prefer.
272
+	 * For this example package, we will handle it in the class to keep things
273
+	 * clean and organized.
274
+	 *
275
+	 * @see $this->prepare_items()
276
+	 **************************************************************************/
277 277
 	function process_bulk_action() {
278 278
 		//Detect when a bulk action is being triggered...
279 279
 		if( 'delete'===$this->current_action() ) {
@@ -282,90 +282,90 @@  discard block
 block discarded – undo
282 282
 	}
283 283
 
284 284
 	/** ************************************************************************
285
-	* REQUIRED! This is where you prepare your data for display. This method will
286
-	* usually be used to query the database, sort and filter the data, and generally
287
-	* get it ready to be displayed. At a minimum, we should set $this->items and
288
-	* $this->set_pagination_args(), although the following properties and methods
289
-	* are frequently interacted with here...
290
-	*
291
-	* @uses $this->_column_headers
292
-	* @uses $this->items
293
-	* @uses $this->get_columns()
294
-	* @uses $this->get_sortable_columns()
295
-	* @uses $this->get_pagenum()
296
-	* @uses $this->set_pagination_args()
297
-	**************************************************************************/
285
+	 * REQUIRED! This is where you prepare your data for display. This method will
286
+	 * usually be used to query the database, sort and filter the data, and generally
287
+	 * get it ready to be displayed. At a minimum, we should set $this->items and
288
+	 * $this->set_pagination_args(), although the following properties and methods
289
+	 * are frequently interacted with here...
290
+	 *
291
+	 * @uses $this->_column_headers
292
+	 * @uses $this->items
293
+	 * @uses $this->get_columns()
294
+	 * @uses $this->get_sortable_columns()
295
+	 * @uses $this->get_pagenum()
296
+	 * @uses $this->set_pagination_args()
297
+	 **************************************************************************/
298 298
 	function prepare_items() {
299 299
 		/*	First, lets decide how many records per page to show	*/
300 300
 		$per_page = 10;
301 301
 
302 302
 		/**
303
-		* REQUIRED. Now we need to define our column headers. This includes a complete
304
-		* array of columns to be displayed (slugs & titles), a list of columns
305
-		* to keep hidden, and a list of columns that are sortable. Each of these
306
-		* can be defined in another method (as we've done here) before being
307
-		* used to build the value for our _column_headers property.
308
-		*/
303
+		 * REQUIRED. Now we need to define our column headers. This includes a complete
304
+		 * array of columns to be displayed (slugs & titles), a list of columns
305
+		 * to keep hidden, and a list of columns that are sortable. Each of these
306
+		 * can be defined in another method (as we've done here) before being
307
+		 * used to build the value for our _column_headers property.
308
+		 */
309 309
 		$columns = $this->get_columns();
310 310
 		$hidden = array();
311 311
 		$sortable = $this->get_sortable_columns();
312 312
 
313 313
 		/**
314
-		* REQUIRED. Finally, we build an array to be used by the class for column
315
-		* headers. The $this->_column_headers property takes an array which contains
316
-		* 3 other arrays. One for all columns, one for hidden columns, and one
317
-		* for sortable columns.
318
-		*/
314
+		 * REQUIRED. Finally, we build an array to be used by the class for column
315
+		 * headers. The $this->_column_headers property takes an array which contains
316
+		 * 3 other arrays. One for all columns, one for hidden columns, and one
317
+		 * for sortable columns.
318
+		 */
319 319
 		$this->_column_headers = array($columns, $hidden, $sortable);
320 320
 
321 321
 		/**
322
-		* Optional. You can handle your bulk actions however you see fit. In this
323
-		* case, we'll handle them within our package just to keep things clean.
324
-		*/
322
+		 * Optional. You can handle your bulk actions however you see fit. In this
323
+		 * case, we'll handle them within our package just to keep things clean.
324
+		 */
325 325
 		$this->process_bulk_action();
326 326
 
327 327
 		/**
328
-		* Instead of querying a database, we're going to fetch the example data
329
-		* property we created for use in this plugin. This makes this example
330
-		* package slightly different than one you might build on your own. In
331
-		* this example, we'll be using array manipulation to sort and paginate
332
-		* our data. In a real-world implementation, you will probably want to
333
-		* use sort and pagination data to build a custom query instead, as you'll
334
-		* be able to use your precisely-queried data immediately.
335
-		*/
328
+		 * Instead of querying a database, we're going to fetch the example data
329
+		 * property we created for use in this plugin. This makes this example
330
+		 * package slightly different than one you might build on your own. In
331
+		 * this example, we'll be using array manipulation to sort and paginate
332
+		 * our data. In a real-world implementation, you will probably want to
333
+		 * use sort and pagination data to build a custom query instead, as you'll
334
+		 * be able to use your precisely-queried data immediately.
335
+		 */
336 336
 		$data = $this->datas;
337 337
 
338 338
 		/**
339
-		* REQUIRED for pagination. Let's figure out what page the user is currently
340
-		* looking at. We'll need this later, so you should always include it in
341
-		* your own package classes.
342
-		*/
339
+		 * REQUIRED for pagination. Let's figure out what page the user is currently
340
+		 * looking at. We'll need this later, so you should always include it in
341
+		 * your own package classes.
342
+		 */
343 343
 		$current_page = $this->get_pagenum();
344 344
 
345 345
 		/**
346
-		* REQUIRED for pagination. Let's check how many items are in our data array.
347
-		* In real-world use, this would be the total number of items in your database,
348
-		* without filtering. We'll need this later, so you should always include it
349
-		* in your own package classes.
350
-		*/
346
+		 * REQUIRED for pagination. Let's check how many items are in our data array.
347
+		 * In real-world use, this would be the total number of items in your database,
348
+		 * without filtering. We'll need this later, so you should always include it
349
+		 * in your own package classes.
350
+		 */
351 351
 		$total_items = count($data);
352 352
 
353 353
 		/**
354
-		* The WP_List_Table class does not handle pagination for us, so we need
355
-		* to ensure that the data is trimmed to only the current page. We can use
356
-		* array_slice() to
357
-		*/
354
+		 * The WP_List_Table class does not handle pagination for us, so we need
355
+		 * to ensure that the data is trimmed to only the current page. We can use
356
+		 * array_slice() to
357
+		 */
358 358
 		$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
359 359
 
360 360
 		/**
361
-		* REQUIRED. Now we can add our *sorted* data to the items property, where
362
-		* it can be used by the rest of the class.
363
-		*/
361
+		 * REQUIRED. Now we can add our *sorted* data to the items property, where
362
+		 * it can be used by the rest of the class.
363
+		 */
364 364
 		$this->items = $data;
365 365
 
366 366
 		/**
367
-		* REQUIRED. We also have to register our pagination options & calculations.
368
-		*/
367
+		 * REQUIRED. We also have to register our pagination options & calculations.
368
+		 */
369 369
 		$this->set_pagination_args( array(
370 370
 			'total_items' => $total_items,               		//WE have to calculate the total number of items
371 371
 			'per_page'    => $per_page,                 		//WE have to determine how many items to show on a page
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 /*	Check if file is include. No direct access possible with file url	*/
4
-if ( !defined( 'WPSHOP_VERSION' ) ) {
5
-	die( __('Access is not allowed by this way', 'wpshop') );
4
+if (!defined('WPSHOP_VERSION')) {
5
+	die(__('Access is not allowed by this way', 'wpshop'));
6 6
 }
7 7
 
8 8
 
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 * @package wpshop
12 12
 * @subpackage librairies
13 13
 */
14
-class wpshop_attributes_set_custom_List_table extends WP_List_Table{
14
+class wpshop_attributes_set_custom_List_table extends WP_List_Table {
15 15
 
16 16
 	var $datas;
17 17
 
@@ -19,28 +19,28 @@  discard block
 block discarded – undo
19 19
 	* REQUIRED. Set up a constructor that references the parent constructor. We
20 20
 	* use the parent reference to set some default configs.
21 21
 	***************************************************************************/
22
-	function __construct(){
22
+	function __construct() {
23 23
 		global $status, $page;
24 24
 
25 25
 		//Set parent defaults
26
-		parent::__construct( array(
27
-			'singular'  => __('attribute\'s set', 'wpshop'),    //singular name of the listed records
28
-			'plural'    => __('attributes\' set', 'wpshop'),    //plural name of the listed records
26
+		parent::__construct(array(
27
+			'singular'  => __('attribute\'s set', 'wpshop'), //singular name of the listed records
28
+			'plural'    => __('attributes\' set', 'wpshop'), //plural name of the listed records
29 29
 			'ajax'     => true       //does this table support ajax?
30
-		) );
30
+		));
31 31
 	}
32 32
 
33 33
 	/*	Allows to set different listings for attributes	*/
34
-	function get_views(){
34
+	function get_views() {
35 35
 		$wpshop_attribute_links = array();
36 36
 
37 37
 		$active_nb = wpshop_attributes_set::getElement('', "'moderated','valid'");
38 38
 		$deleted_nb = wpshop_attributes_set::getElement('', "'deleted'");
39 39
 
40
-		$attribute_group_status = !empty( $_REQUEST['attribute_groups_status'] ) ? sanitize_text_field( $_REQUEST['attribute_groups_status'] ) : '';
40
+		$attribute_group_status = !empty($_REQUEST['attribute_groups_status']) ? sanitize_text_field($_REQUEST['attribute_groups_status']) : '';
41 41
 
42
-		$wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_valid'.(empty($attribute_group_status)?' current':'')] = '<a href="'.admin_url('admin.php?page='.wpshop_attributes_set::getEditionSlug()).'" >'.__('Attribute groups', 'wpshop').' ('.count($active_nb).')</a>';
43
-		$wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_deleted'.(!empty($attribute_group_status) && ($attribute_group_status=='deleted')?' current':'')] = '<a href="'.admin_url('admin.php?page='.wpshop_attributes_set::getEditionSlug().'&attribute_groups_status=deleted').'" >'.__('Trashed attribute groups', 'wpshop').' ('.count($deleted_nb).')</a>';
42
+		$wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_valid' . (empty($attribute_group_status) ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . wpshop_attributes_set::getEditionSlug()) . '" >' . __('Attribute groups', 'wpshop') . ' (' . count($active_nb) . ')</a>';
43
+		$wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_deleted' . (!empty($attribute_group_status) && ($attribute_group_status == 'deleted') ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . wpshop_attributes_set::getEditionSlug() . '&attribute_groups_status=deleted') . '" >' . __('Trashed attribute groups', 'wpshop') . ' (' . count($deleted_nb) . ')</a>';
44 44
 
45 45
 		return $wpshop_attribute_links;
46 46
 	}
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	* @see WP_List_Table::::single_row_columns()
59 59
 	* @return array An associative array containing column information: 'slugs'=>'Visible Titles'
60 60
 	**************************************************************************/
61
-	function get_columns(){
61
+	function get_columns() {
62 62
 		$columns = array(
63
-			'cb'       => '',//'<input type="checkbox" />', //Render a checkbox instead of text
63
+			'cb'       => '', //'<input type="checkbox" />', //Render a checkbox instead of text
64 64
 			'id'       => 'Id.',
65 65
 			'name'    => 'Nom',
66 66
 			'status'    => 'Statut',
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 	* @param array $column_name The name/slug of the column to be processed
92 92
 	* @return string Text or HTML to be placed inside the column <td>
93 93
 	**************************************************************************/
94
-	function column_default($item, $column_name){
95
-		switch($column_name){
94
+	function column_default($item, $column_name) {
95
+		switch ($column_name) {
96 96
 			default:
97
-				return print_r($item,true); //Show the whole array for troubleshooting purposes
97
+				return print_r($item, true); //Show the whole array for troubleshooting purposes
98 98
 		}
99 99
 	}
100 100
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	* @param array $item A singular item (one full row's worth of data)
115 115
 	* @return string Text to be placed inside the column <td> (movie title only)
116 116
 	**************************************************************************/
117
-	function column_id($item){
117
+	function column_id($item) {
118 118
 		return $item['id'];
119 119
 	}
120 120
 	/** ************************************************************************
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	* @param array $item A singular item (one full row's worth of data)
134 134
 	* @return string Text to be placed inside the column <td> (movie title only)
135 135
 	**************************************************************************/
136
-	function column_status($item){
136
+	function column_status($item) {
137 137
 		return __($item['status'], 'wpshop');
138 138
 	}
139 139
 	/** ************************************************************************
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	* @param array $item A singular item (one full row's worth of data)
153 153
 	* @return string Text to be placed inside the column <td> (movie title only)
154 154
 	**************************************************************************/
155
-	function column_content($item){
155
+	function column_content($item) {
156 156
 		return $item['content'];
157 157
 	}
158 158
 	/** ************************************************************************
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
 	* @param array $item A singular item (one full row's worth of data)
172 172
 	* @return string Text to be placed inside the column <td> (movie title only)
173 173
 	**************************************************************************/
174
-	function column_entity($item){
175
-		return __($item['entity'],'wpshop');
174
+	function column_entity($item) {
175
+		return __($item['entity'], 'wpshop');
176 176
 	}
177 177
 	/** ************************************************************************
178 178
 	* Recommended. This is a custom column method and is responsible for what
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
 	* @param array $item A singular item (one full row's worth of data)
191 191
 	* @return string Text to be placed inside the column <td> (movie title only)
192 192
 	**************************************************************************/
193
-	function column_name($item){
193
+	function column_name($item) {
194 194
 		//Build row actions
195
-		$default_action='edit';
196
-		$default_action_text=__('Edit', 'wpshop');
197
-		$attribute_groups_status = !empty( $_REQUEST['attribute_groups_status'] ) ? sanitize_text_field( $_REQUEST['attribute_groups_status'] ) : '';
198
-		if( !empty( $attribute_groups_status ) && ( $attribute_groups_status=='deleted' ) ){
199
-			$default_action='activate';
200
-			$default_action_text=__('Restore', 'wpshop');
195
+		$default_action = 'edit';
196
+		$default_action_text = __('Edit', 'wpshop');
197
+		$attribute_groups_status = !empty($_REQUEST['attribute_groups_status']) ? sanitize_text_field($_REQUEST['attribute_groups_status']) : '';
198
+		if (!empty($attribute_groups_status) && ($attribute_groups_status == 'deleted')) {
199
+			$default_action = 'activate';
200
+			$default_action_text = __('Restore', 'wpshop');
201 201
 		}
202
-		$actions['edit']=sprintf('<a href="'.admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s">'.$default_action_text.'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING,$default_action,$item['id']);
202
+		$actions['edit'] = sprintf('<a href="' . admin_url('admin.php') . '?page=%2$s&amp;action=%3$s&amp;id=%4$s">' . $default_action_text . '</a>', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING, $default_action, $item['id']);
203 203
 
204 204
 		if (empty($attribute_groups_status))
205
-			$actions['delete']=sprintf('<a href="'.admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s">'.__('Delete', 'wpshop').'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING,'delete',$item['id']);
205
+			$actions['delete'] = sprintf('<a href="' . admin_url('admin.php') . '?page=%2$s&amp;action=%3$s&amp;id=%4$s">' . __('Delete', 'wpshop') . '</a>', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING, 'delete', $item['id']);
206 206
 
207 207
 		//Return the title contents
208 208
 		return sprintf('%1$s%2$s',
209
-			/*$1%s*/ sprintf('<a href="'.admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s">'.__($item['name'], 'wpshop').'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING,'edit',$item['id']),
209
+			/*$1%s*/ sprintf('<a href="' . admin_url('admin.php') . '?page=%2$s&amp;action=%3$s&amp;id=%4$s">' . __($item['name'], 'wpshop') . '</a>', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING, 'edit', $item['id']),
210 210
 			/*$3%s*/ $this->row_actions($actions)
211 211
 		);
212 212
 	}
@@ -219,11 +219,11 @@  discard block
 block discarded – undo
219 219
 	* @param array $item A singular item (one full row's worth of data)
220 220
 	* @return string Text to be placed inside the column <td> (movie title only)
221 221
 	**************************************************************************/
222
-	function column_cb($item){
222
+	function column_cb($item) {
223 223
 		return '';
224 224
 		return sprintf(
225 225
 			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
226
-			/*$1%s*/ $this->_args['singular'],  //Let's simply repurpose the table's singular label ("movie")
226
+			/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
227 227
 			/*$2%s*/ $item['id']             //The value of the checkbox should be the record's id
228 228
 		);
229 229
 	}
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	**************************************************************************/
280 280
 	function process_bulk_action() {
281 281
 		//Detect when a bulk action is being triggered...
282
-		if( 'delete'===$this->current_action() ) {
282
+		if ('delete' === $this->current_action()) {
283 283
 			wp_die('Items deleted (or they would be if we had items to delete)!');
284 284
 		}
285 285
 	}
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 		* to ensure that the data is trimmed to only the current page. We can use
359 359
 		* array_slice() to
360 360
 		*/
361
-		$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
361
+		$data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
362 362
 
363 363
 		/**
364 364
 		* REQUIRED. Now we can add our *sorted* data to the items property, where
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
 		/**
370 370
 		* REQUIRED. We also have to register our pagination options & calculations.
371 371
 		*/
372
-		$this->set_pagination_args( array(
373
-			'total_items' => $total_items,               		//WE have to calculate the total number of items
374
-			'per_page'    => $per_page,                 		//WE have to determine how many items to show on a page
375
-			'total_pages' => ceil($total_items/$per_page)   //WE have to calculate the total number of pages
376
-		) );
372
+		$this->set_pagination_args(array(
373
+			'total_items' => $total_items, //WE have to calculate the total number of items
374
+			'per_page'    => $per_page, //WE have to determine how many items to show on a page
375
+			'total_pages' => ceil($total_items / $per_page)   //WE have to calculate the total number of pages
376
+		));
377 377
 	}
378 378
 
379 379
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 
3 5
 /*	Check if file is include. No direct access possible with file url	*/
4 6
 if ( !defined( 'WPSHOP_VERSION' ) ) {
@@ -201,8 +203,9 @@  discard block
 block discarded – undo
201 203
 		}
202 204
 		$actions['edit']=sprintf('<a href="'.admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s">'.$default_action_text.'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING,$default_action,$item['id']);
203 205
 
204
-		if (empty($attribute_groups_status))
205
-			$actions['delete']=sprintf('<a href="'.admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s">'.__('Delete', 'wpshop').'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING,'delete',$item['id']);
206
+		if (empty($attribute_groups_status)) {
207
+					$actions['delete']=sprintf('<a href="'.admin_url('admin.php').'?page=%2$s&amp;action=%3$s&amp;id=%4$s">'.__('Delete', 'wpshop').'</a>',WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING,'delete',$item['id']);
208
+		}
206 209
 
207 210
 		//Return the title contents
208 211
 		return sprintf('%1$s%2$s',
Please login to merge, or discard this patch.