Completed
Pull Request — master (#2)
by Jimmy
1216:52 queued 1185:43
created
modules/wps_media_manager/controller/wps_media_manager_frontend_ctr.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	/**
71 71
 	 * Get product Complete Sheet
72 72
 	 * @param integer $pid
73
-	 * @return Ambigous <string, string>
73
+	 * @return string <string, string>
74 74
 	 */
75 75
 	public static function get_product_complete_sheet_galery( $pid ) {
76 76
 		$output = '';
@@ -157,6 +157,9 @@  discard block
 block discarded – undo
157 157
 		return $output;
158 158
 	}
159 159
 
160
+	/**
161
+	 * @param integer $product_id
162
+	 */
160 163
 	public static function get_product_complete_sheet_attachments( $product_id ) {
161 164
 		$output = '';
162 165
 
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 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
 class wps_media_manager_frontend_ctr {
3 3
 
4
-	public static function get_attachments( $pid, $type = 'gallery' ) {
4
+	public static function get_attachments($pid, $type = 'gallery') {
5 5
 		$attachments = array();
6
-		$media_id_data = get_post_meta( $pid, '_wps_product_media', true );
7
-		if( !empty($media_id_data) ) {
8
-			$media_id = explode( ',', $media_id_data );
9
-			foreach($media_id as $id) {
10
-				if( ( ( wp_attachment_is_image( $id ) && $type == 'gallery' ) || ( !empty( $id ) && !wp_attachment_is_image( $id ) && $type == 'attachments' ) ) ) {
11
-					$attachment_data = get_post( $id );
12
-					if( !empty( $attachment_data ) && !empty($attachment_data->ID) ) {
6
+		$media_id_data = get_post_meta($pid, '_wps_product_media', true);
7
+		if (!empty($media_id_data)) {
8
+			$media_id = explode(',', $media_id_data);
9
+			foreach ($media_id as $id) {
10
+				if (((wp_attachment_is_image($id) && $type == 'gallery') || (!empty($id) && !wp_attachment_is_image($id) && $type == 'attachments'))) {
11
+					$attachment_data = get_post($id);
12
+					if (!empty($attachment_data) && !empty($attachment_data->ID)) {
13 13
 						$attachments[] = $attachment_data;
14 14
 					}
15 15
 				}
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return string The attachement gallery output
28 28
 	 */
29
-	public static function display_attachment_gallery( $attachement_type, $content ) {
29
+	public static function display_attachment_gallery($attachement_type, $content) {
30 30
 		$galery_output = '';
31 31
 
32 32
 		/*
33 33
 		 * Get the template part for given galery type
34 34
 		 */
35
-		switch ( $attachement_type ) {
35
+		switch ($attachement_type) {
36 36
 			case 'picture':
37 37
 					$template_part = 'product_attachment_picture_galery';
38 38
 				break;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		 * Build template
53 53
 		 */
54 54
 		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
55
-		if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
55
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
56 56
 			/*	Include the old way template part	*/
57 57
 			ob_start();
58 58
 			require(wpshop_display::get_template_file($tpl_way_to_take[1]));
@@ -72,81 +72,81 @@  discard block
 block discarded – undo
72 72
 	 * @param integer $pid
73 73
 	 * @return Ambigous <string, string>
74 74
 	 */
75
-	public static function get_product_complete_sheet_galery( $pid ) {
75
+	public static function get_product_complete_sheet_galery($pid) {
76 76
 		$output = '';
77
-		if( !empty($pid) ) {
77
+		if (!empty($pid)) {
78 78
 			$tpl_component = $sub_tpl_component = array();
79 79
 			$attachments = array();
80 80
 			$tpl_component['THUMBNAILS'] = '';
81 81
 			$tpl_component['SLIDER_CONTENT'] = '';
82 82
 
83 83
 			/**	Check and get the product thumbnail	*/
84
-			$principal_thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true);
85
-			if( !empty($principal_thumbnail_id) ) {
86
-				$attachments[0] = get_post( $principal_thumbnail_id );
84
+			$principal_thumbnail_id = get_post_meta($pid, '_thumbnail_id', true);
85
+			if (!empty($principal_thumbnail_id)) {
86
+				$attachments[0] = get_post($principal_thumbnail_id);
87 87
 			}
88 88
 			else {
89 89
 				$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = '';
90
-				$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
91
-				$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
90
+				$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
91
+				$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
92 92
 				$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL_ID'] = '';
93 93
 
94
-				$tpl_component[ 'SLIDER_CONTENT' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component );
95
-				$tpl_component[ 'THUMBNAILS' ] = '';
94
+				$tpl_component['SLIDER_CONTENT'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component);
95
+				$tpl_component['THUMBNAILS'] = '';
96 96
 			}
97 97
 
98 98
 			/**	Get product associated pictures	*/
99 99
 			$allowed_mime_type = get_allowed_mime_types();
100 100
 
101
-			$attachments = array_merge( $attachments, (array)self::get_attachments( $pid ) );
101
+			$attachments = array_merge($attachments, (array)self::get_attachments($pid));
102 102
 
103 103
 			/**	In case there are picture read and display them into product sheet	*/
104
-			if ( !empty($attachments) ) {
105
-				foreach( $attachments as $attachment) {
106
-					if( !empty($attachment) && !empty($attachment->post_mime_type) && in_array( $attachment->post_mime_type, $allowed_mime_type ) ) {
104
+			if (!empty($attachments)) {
105
+				foreach ($attachments as $attachment) {
106
+					if (!empty($attachment) && !empty($attachment->post_mime_type) && in_array($attachment->post_mime_type, $allowed_mime_type)) {
107 107
 						//IMAGE SLIDER
108
-						$image_attributes = wp_get_attachment_metadata( $attachment->ID );
108
+						$image_attributes = wp_get_attachment_metadata($attachment->ID);
109 109
 						$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = '';
110 110
 						$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL_ID'] = $attachment->ID;
111
-						if ( !empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes']) ) {
112
-							foreach ( $image_attributes['sizes'] as $size_name => $size_def) {
113
-								$p = wp_get_attachment_image( $attachment->ID, $size_name);
114
-								$src = wp_get_attachment_image_src( $attachment->ID, $size_name );
111
+						if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
112
+							foreach ($image_attributes['sizes'] as $size_name => $size_def) {
113
+								$p = wp_get_attachment_image($attachment->ID, $size_name);
114
+								$src = wp_get_attachment_image_src($attachment->ID, $size_name);
115 115
 								$sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = '';
116 116
 								$sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = '';
117
-								if( !empty($p) ) {
118
-									$sub_tpl_component['SRC_IMAGE_SLIDER_' . strtoupper($size_name)] = ( !empty($src) ) ? $src[0] : '';
119
-									$sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
120
-									$sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
117
+								if (!empty($p)) {
118
+									$sub_tpl_component['SRC_IMAGE_SLIDER_' . strtoupper($size_name)] = (!empty($src)) ? $src[0] : '';
119
+									$sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
120
+									$sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
121 121
 								}
122 122
 							}
123
-							$p = wp_get_attachment_image( $attachment->ID, 'full');
124
-							$src = wp_get_attachment_image_src( $attachment->ID, 'full' );
125
-							if( !empty($p) ) {
126
-								$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : '';
127
-								$sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty($p) ) ? $p : '';
128
-								$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty($p) ) ? $p : '';
123
+							$p = wp_get_attachment_image($attachment->ID, 'full');
124
+							$src = wp_get_attachment_image_src($attachment->ID, 'full');
125
+							if (!empty($p)) {
126
+								$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = (!empty($src)) ? $src[0] : '';
127
+								$sub_tpl_component['IMAGE_SLIDER_FULL'] = (!empty($p)) ? $p : '';
128
+								$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = (!empty($p)) ? $p : '';
129 129
 							}
130 130
 						}
131 131
 						else {
132
-							$p = wp_get_attachment_image( $attachment->ID, 'full' );
133
-							$src = wp_get_attachment_image_src( $attachment->ID, 'full' );
134
-							$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : '';
135
-							$sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
136
-							$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
132
+							$p = wp_get_attachment_image($attachment->ID, 'full');
133
+							$src = wp_get_attachment_image_src($attachment->ID, 'full');
134
+							$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = (!empty($src)) ? $src[0] : '';
135
+							$sub_tpl_component['IMAGE_SLIDER_FULL'] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
136
+							$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
137 137
 						}
138
-						if ( !empty( $sub_tpl_component['IMAGE_SLIDER_FULL'] ) ) {
139
-							$tpl_component[ 'SLIDER_CONTENT' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component );
140
-							if ( ( 1 < count( $attachments ) ) || ( ( 1 == count( $attachments ) ) && empty( $principal_thumbnail_id ) ) ) {
141
-								$tpl_component[ 'THUMBNAILS' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_thumbnail_element', $sub_tpl_component );
138
+						if (!empty($sub_tpl_component['IMAGE_SLIDER_FULL'])) {
139
+							$tpl_component['SLIDER_CONTENT'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component);
140
+							if ((1 < count($attachments)) || ((1 == count($attachments)) && empty($principal_thumbnail_id))) {
141
+								$tpl_component['THUMBNAILS'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_thumbnail_element', $sub_tpl_component);
142 142
 							}
143 143
 						}
144
-						unset( $sub_tpl_component );
144
+						unset($sub_tpl_component);
145 145
 					}
146 146
 					else {
147 147
 						$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = '';
148
-						$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
149
-						$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
148
+						$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
149
+						$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
150 150
 					}
151 151
 				}
152 152
 			}
@@ -157,35 +157,35 @@  discard block
 block discarded – undo
157 157
 		return $output;
158 158
 	}
159 159
 
160
-	public static function get_product_complete_sheet_attachments( $product_id ) {
160
+	public static function get_product_complete_sheet_attachments($product_id) {
161 161
 		$output = '';
162 162
 
163 163
 		/**	Get attachement file for the current product	*/
164 164
 		$product_picture_galery_content = $product_document_galery_content = '';
165 165
 		$picture_number = $document_number = $index_li = 0;
166 166
 
167
-		$attachments = self::get_attachments( $product_id, 'attachments' );
167
+		$attachments = self::get_attachments($product_id, 'attachments');
168 168
 
169
-		if ( is_array($attachments) && (count($attachments) > 0) ) {
169
+		if (is_array($attachments) && (count($attachments) > 0)) {
170 170
 			$picture_increment = $document_increment = 1;
171 171
 			foreach ($attachments as $attachment) {
172 172
 				$tpl_component = array();
173
-				$attachment_url = wp_get_attachment_url( $attachment->ID );
173
+				$attachment_url = wp_get_attachment_url($attachment->ID);
174 174
 				$attachment_extension = explode('.', $attachment_url);
175 175
 				$attachment_extension = $attachment_extension[1];
176 176
 				$tpl_component['ATTACHMENT_ITEM_GUID'] = $attachment_url;
177 177
 				$tpl_component['ATTACHMENT_ITEM_TITLE'] = $attachment->post_title;
178 178
 				$tpl_component['ATTACHMENT_ITEM_EXTENSION'] = $attachment_extension;
179
-				if(is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) {
179
+				if (is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) {
180 180
 					$tpl_component['ATTACHMENT_ITEM_TYPE'] = 'document';
181
-					$tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = (!($document_increment%WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE)) ? 'wpshop_gallery_document_last' : '';
181
+					$tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = (!($document_increment % WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE)) ? 'wpshop_gallery_document_last' : '';
182 182
 					/** Template parameters	*/
183 183
 					$template_part = 'product_attachment_item_document';
184 184
 					$tpl_component['PRODUCT_ID'] = $product_id;
185 185
 
186 186
 					/** Build template	*/
187 187
 					$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
188
-					if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
188
+					if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
189 189
 						/*	Include the old way template part	*/
190 190
 
191 191
 						ob_start();
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 			}
205 205
 
206 206
 			ob_start();
207
-			require( wpshop_tools::get_template_part( WPS_MEDIA_MANAGER_DIR, WPS_MEDIA_MANAGER_TEMPLATE_DIR, 'frontend', 'associated', 'document' ) );
207
+			require(wpshop_tools::get_template_part(WPS_MEDIA_MANAGER_DIR, WPS_MEDIA_MANAGER_TEMPLATE_DIR, 'frontend', 'associated', 'document'));
208 208
 			$output = ob_get_contents();
209 209
 			ob_end_clean();
210 210
 		}
Please login to merge, or discard this patch.
Braces   +8 added lines, -11 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_media_manager_frontend_ctr {
3 5
 
4 6
 	public static function get_attachments( $pid, $type = 'gallery' ) {
@@ -58,8 +60,7 @@  discard block
 block discarded – undo
58 60
 			require(wpshop_display::get_template_file($tpl_way_to_take[1]));
59 61
 			$galery_output = ob_get_contents();
60 62
 			ob_end_clean();
61
-		}
62
-		else {
63
+		} else {
63 64
 			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
64 65
 		}
65 66
 		unset($tpl_component);
@@ -84,8 +85,7 @@  discard block
 block discarded – undo
84 85
 			$principal_thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true);
85 86
 			if( !empty($principal_thumbnail_id) ) {
86 87
 				$attachments[0] = get_post( $principal_thumbnail_id );
87
-			}
88
-			else {
88
+			} else {
89 89
 				$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = '';
90 90
 				$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
91 91
 				$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
@@ -127,8 +127,7 @@  discard block
 block discarded – undo
127 127
 								$sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty($p) ) ? $p : '';
128 128
 								$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty($p) ) ? $p : '';
129 129
 							}
130
-						}
131
-						else {
130
+						} else {
132 131
 							$p = wp_get_attachment_image( $attachment->ID, 'full' );
133 132
 							$src = wp_get_attachment_image_src( $attachment->ID, 'full' );
134 133
 							$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : '';
@@ -142,8 +141,7 @@  discard block
 block discarded – undo
142 141
 							}
143 142
 						}
144 143
 						unset( $sub_tpl_component );
145
-					}
146
-					else {
144
+					} else {
147 145
 						$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = '';
148 146
 						$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
149 147
 						$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
@@ -192,8 +190,7 @@  discard block
 block discarded – undo
192 190
 						require(wpshop_display::get_template_file($tpl_way_to_take[1]));
193 191
 						$product_document_galery_content .= ob_get_contents();
194 192
 						ob_end_clean();
195
-					}
196
-					else {
193
+					} else {
197 194
 						$product_document_galery_content .= wpshop_display::display_template_element($template_part, $tpl_component);
198 195
 					}
199 196
 
Please login to merge, or discard this patch.
includes/modules/wps_message/controller/wps_message_ctr.php 3 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -299,7 +299,11 @@
 block discarded – undo
299 299
 	}
300 300
 
301 301
 	/** Store a new message
302
-	 * @return boolean
302
+	 * @param string $email
303
+	 * @param string $title
304
+	 * @param string $message
305
+	 * @param integer $model_id
306
+	 * @return boolean|null
303 307
 	 */
304 308
 	function add_message($recipient_id=0, $email, $title, $message, $model_id, $object, $date = null) {
305 309
 		$date = empty($date) ? current_time('mysql', 0) : $date;
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 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_message_ctr {
3 3
 	/** Define the main directory containing the template for the current plugin
4 4
 	 * @var string
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
 		$this->template_dir = WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . "/templates/";
21 21
 
22 22
 		// WP General actions
23
-		add_action( 'admin_init', array( $this, 'wps_messages_init_actions') );
24
-		add_action('add_meta_boxes', array( $this, 'add_meta_boxes') );
25
-		add_action('manage_'.WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE.'_posts_custom_column',  array( $this, 'messages_custom_columns'));
26
-		add_filter('manage_edit-'.WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE.'_columns', array( $this, 'messages_edit_columns'));
23
+		add_action('admin_init', array($this, 'wps_messages_init_actions'));
24
+		add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
25
+		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array($this, 'messages_custom_columns'));
26
+		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array($this, 'messages_edit_columns'));
27 27
 
28 28
 		// Shortcodes
29
-		add_shortcode( 'wps_message_histo', array( $this, 'display_message_histo_per_customer') );
30
-		add_shortcode( 'order_customer_personnal_informations', array( $this, 'order_personnal_informations') );
29
+		add_shortcode('wps_message_histo', array($this, 'display_message_histo_per_customer'));
30
+		add_shortcode('order_customer_personnal_informations', array($this, 'order_personnal_informations'));
31 31
 
32 32
 		/** Ajax */
33 33
 		add_action('wp_ajax_get_content_message', array($this, 'get_content_message'));
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	public function enqueue_scripts() {
40 40
 		/** Css */
41 41
 		add_thickbox();
42
-		wp_register_style( 'wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION );
43
-		wp_enqueue_style( 'wpeo-message-css' );
42
+		wp_register_style('wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION);
43
+		wp_enqueue_style('wpeo-message-css');
44 44
 
45 45
 		/** My js */
46
-		wp_enqueue_script( 'wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array("jquery", 'thickbox'), WPS_MESSAGE_VERSION);
46
+		wp_enqueue_script('wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array("jquery", 'thickbox'), WPS_MESSAGE_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 				'show_in_nav_menus' 		=> false,
85 85
 				'rewrite' 					=> false,
86 86
 				'query_var' 				=> true,
87
-				'supports' 					=> array('title','editor'),
87
+				'supports' 					=> array('title', 'editor'),
88 88
 				'has_archive' 				=> false
89 89
 		));
90 90
 	}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		add_meta_box(
98 98
 		'wpshop_message_histo',
99 99
 		__('Message historic', 'wpshop'),
100
-		array( $this, 'message_histo_box'),
100
+		array($this, 'message_histo_box'),
101 101
 		WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high'
102 102
 		);
103 103
 	}
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 	 * @param  integer $message_type_id : Message type ID
120 120
 	 * @return string
121 121
 	 */
122
-	function get_historic_message_by_type( $message_type_id ) {
122
+	function get_historic_message_by_type($message_type_id) {
123 123
 		global $wpdb;
124 124
 		$output = '';
125
-		if ( !empty($message_type_id) ) {
125
+		if (!empty($message_type_id)) {
126 126
 			// Recover all sended messages
127 127
 			$wps_message_mdl = new wps_message_mdl();
128
-			$messages = $wps_message_mdl->get_messages_histo( $message_type_id );
128
+			$messages = $wps_message_mdl->get_messages_histo($message_type_id);
129 129
 			ob_start();
130
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend", "message_historic") );
130
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend", "message_historic"));
131 131
 			$output .= ob_get_contents();
132 132
 			ob_end_clean();
133 133
 		}
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public static function create_default_message() {
141 141
 		// Get default messages defined into xml files
142
-		$xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' );
143
-		$default_emails = new SimpleXMLElement( $xml_default_emails );
142
+		$xml_default_emails = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml');
143
+		$default_emails = new SimpleXMLElement($xml_default_emails);
144 144
 
145 145
 		//Read default emails for options creation
146
-		foreach ( $default_emails->xpath( '//emails/email' ) as $email ) {
147
-			if (  ( WPSHOP_DEFINED_SHOP_TYPE == (string)$email->attributes()->shop_type ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) {
148
-				self::createMessage( (string)$email->attributes()->code, (string)$email->subject, (string)$email->content );
146
+		foreach ($default_emails->xpath('//emails/email') as $email) {
147
+			if ((WPSHOP_DEFINED_SHOP_TYPE == (string)$email->attributes()->shop_type) || ('sale' == WPSHOP_DEFINED_SHOP_TYPE)) {
148
+				self::createMessage((string)$email->attributes()->code, (string)$email->subject, (string)$email->content);
149 149
 			}
150 150
 		}
151 151
 	}
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 	 * @param string $message : Message content
158 158
 	 * @return integer message ID
159 159
 	 */
160
-	public static function createMessage( $code, $object = "", $message = "" ) {
160
+	public static function createMessage($code, $object = "", $message = "") {
161 161
 		$id = 0;
162 162
 
163
-		$object = empty( $object ) ? constant( $code . '_OBJECT' ) : $object;
164
-		$message = empty( $message ) ? constant( $code ) : $message;
165
-		$message_option = get_option( $code, null );
163
+		$object = empty($object) ? constant($code . '_OBJECT') : $object;
164
+		$message = empty($message) ? constant($code) : $message;
165
+		$message_option = get_option($code, null);
166 166
 
167
-		if ( empty( $message_option ) && !empty( $object ) && !empty( $message ) ) {
167
+		if (empty($message_option) && !empty($object) && !empty($message)) {
168 168
 			$new_message = array(
169
-				'post_title' 	=> __( $object , 'wpshop'),
170
-				'post_content' 	=> self::customize_message( __( $message, 'wpshop' ) ),
169
+				'post_title' 	=> __($object, 'wpshop'),
170
+				'post_content' 	=> self::customize_message(__($message, 'wpshop')),
171 171
 				'post_status' 	=> 'publish',
172 172
 				'post_author' 	=> 1,
173 173
 				'post_type' 	=> WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE
174 174
 			);
175
-			$id = wp_insert_post( $new_message );
175
+			$id = wp_insert_post($new_message);
176 176
 
177
-			update_option( $code, $id );
177
+			update_option($code, $id);
178 178
 		}
179 179
 		else {
180 180
 			$id = $message_option;
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 	function messages_custom_columns($column) {
191 191
 		global $post;
192 192
 		$metadata = get_post_custom();
193
-		switch($column){
193
+		switch ($column) {
194 194
 			case "extract":
195 195
 				echo wp_trim_words($post->post_content, 55);
196 196
 			break;
197 197
 			case "last_dispatch_date":
198
-				if(!empty($metadata['wpshop_message_last_dispatch_date'][0]))
199
-					echo mysql2date('d F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true);
198
+				if (!empty($metadata['wpshop_message_last_dispatch_date'][0]))
199
+					echo mysql2date('d F Y, H:i:s', $metadata['wpshop_message_last_dispatch_date'][0], true);
200 200
 				else
201 201
 					echo '-';
202 202
 			break;
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 		$columns = array(
212 212
 				'cb' => '<input type="checkbox" />',
213 213
 				'title' => __('Name', 'wpshop'),
214
-				'extract' =>__('Extract from the message','wpshop'),
215
-				'date' => __('Creation date','wpshop'),
216
-				'last_dispatch_date' => __('Last dispatch date','wpshop')
214
+				'extract' =>__('Extract from the message', 'wpshop'),
215
+				'date' => __('Creation date', 'wpshop'),
216
+				'last_dispatch_date' => __('Last dispatch date', 'wpshop')
217 217
 		);
218 218
 
219 219
 		return $columns;
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE,
230 230
 				'posts_per_page' => '-1',
231 231
 		));
232
-		$options='';
232
+		$options = '';
233 233
 		if (!empty($posts)) {
234
-			$options = '<option value="0">' .__('Select values from list', 'wpshop'). '</option>';
234
+			$options = '<option value="0">' . __('Select values from list', 'wpshop') . '</option>';
235 235
 			foreach ($posts as $p) {
236
-				$selected = $p->ID==$current ? ' selected="selected"': '';
237
-				$options .= '<option value="'.$p->ID.'"'.$selected.'>'.$p->post_title.'</option>';
236
+				$selected = $p->ID == $current ? ' selected="selected"' : '';
237
+				$options .= '<option value="' . $p->ID . '"' . $selected . '>' . $p->post_title . '</option>';
238 238
 			}
239 239
 		}
240 240
 		wp_reset_query();
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
 	 * @param integer $customer_id : ID to identifiate the customer
248 248
 	 * @return string
249 249
 	 */
250
-	function display_message_histo_per_customer( $args, $customer_id = '' ) {
251
-		$customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id();
252
-		$message_id = ( !empty($args) && !empty($args['message_id']) ) ? $args['message_id'] : '';
250
+	function display_message_histo_per_customer($args, $customer_id = '') {
251
+		$customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id();
252
+		$message_id = (!empty($args) && !empty($args['message_id'])) ? $args['message_id'] : '';
253 253
 		$message_elements = '';
254 254
 
255 255
 		$wps_message_mdl = new wps_message_mdl();
256
-		$messages_data = $wps_message_mdl->get_messages_histo( $message_id, $customer_id );
256
+		$messages_data = $wps_message_mdl->get_messages_histo($message_id, $customer_id);
257 257
 
258 258
 // 		ob_start();
259 259
 // 		require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "frontend", "messages") );
@@ -262,21 +262,21 @@  discard block
 block discarded – undo
262 262
 
263 263
 		/**	Order emails	*/
264 264
 		$messages_histo = array();
265
-		foreach( $messages_data as $meta_id => $messages ) :
265
+		foreach ($messages_data as $meta_id => $messages) :
266 266
 			$i = 0;
267
-			foreach ( $messages as $message ) :
268
-				$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'title' ] = $message[ 'mess_title' ];
269
-				$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'message' ] = $message[ 'mess_message' ];
270
-				$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'dates' ] = $message[ 'mess_dispatch_date' ];
271
-				if ( !empty( $message[ 'mess_object_id' ] ) ) {
272
-					$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'object' ] = $message[ 'mess_object_id' ];
267
+			foreach ($messages as $message) :
268
+				$messages_histo[$message['mess_dispatch_date'][0]][$i]['title'] = $message['mess_title'];
269
+				$messages_histo[$message['mess_dispatch_date'][0]][$i]['message'] = $message['mess_message'];
270
+				$messages_histo[$message['mess_dispatch_date'][0]][$i]['dates'] = $message['mess_dispatch_date'];
271
+				if (!empty($message['mess_object_id'])) {
272
+					$messages_histo[$message['mess_dispatch_date'][0]][$i]['object'] = $message['mess_object_id'];
273 273
 				}
274 274
 				$i++;
275 275
 			endforeach;
276 276
 		endforeach;
277
-		ksort( $messages_histo );
277
+		ksort($messages_histo);
278 278
 		ob_start();
279
-		require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "frontend", "customer", "messages") );
279
+		require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "frontend", "customer", "messages"));
280 280
 		$output = ob_get_contents();
281 281
 		ob_end_clean();
282 282
 
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
 	 * @param string $message : message content
289 289
 	 * @return string
290 290
 	 */
291
-	public static function customize_message( $message ) {
292
-		if( !empty($message) ) {
291
+	public static function customize_message($message) {
292
+		if (!empty($message)) {
293 293
 			ob_start();
294
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', "backend", "message_html_structure") );
294
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', "backend", "message_html_structure"));
295 295
 			$message = ob_get_contents();
296 296
 			ob_end_clean();
297 297
 		}
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
 	/** Store a new message
302 302
 	 * @return boolean
303 303
 	 */
304
-	function add_message($recipient_id=0, $email, $title, $message, $model_id, $object, $date = null) {
304
+	function add_message($recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null) {
305 305
 		$date = empty($date) ? current_time('mysql', 0) : $date;
306
-		$object_empty = array('object_type'=>'','object_id'=>0);
306
+		$object_empty = array('object_type'=>'', 'object_id'=>0);
307 307
 		$object = array_merge($object_empty, $object);
308 308
 
309
-		$historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' .$model_id. '_' .substr($date, 0, 7), true);
309
+		$historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), true);
310 310
 		$data_to_insert = array(
311 311
 				'mess_user_id' => $recipient_id,
312 312
 				'mess_user_email' => $email,
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 		);
319 319
 		$historic[] = $data_to_insert;
320 320
 
321
-		update_post_meta($recipient_id, '_wpshop_messages_histo_' .$model_id. '_' .substr($date, 0, 7), $historic);
321
+		update_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), $historic);
322 322
 	}
323 323
 
324 324
 	/**
@@ -329,37 +329,37 @@  discard block
 block discarded – undo
329 329
 	 * @param boolean $duplicate_message : Duplicate a light message for historic storage
330 330
 	 * @return string
331 331
 	 */
332
-	function customMessage($string, $data, $model_name='', $duplicate_message=false) {
332
+	function customMessage($string, $data, $model_name = '', $duplicate_message = false) {
333 333
 		$avant = array();
334 334
 		$apres = array();
335 335
 
336
-		$logo_option = get_option( 'wpshop_logo' );
336
+		$logo_option = get_option('wpshop_logo');
337 337
 
338
-		$data['your_shop_logo'] = ( !empty($logo_option) ) ? '<img src="'.$logo_option.'" alt="' .get_bloginfo('name'). '" />' : '';
338
+		$data['your_shop_logo'] = (!empty($logo_option)) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo('name') . '" />' : '';
339 339
 
340
-		foreach($data as $key => $value) {
341
-			$avant[] = '['.$key.']';
340
+		foreach ($data as $key => $value) {
341
+			$avant[] = '[' . $key . ']';
342 342
 			switch ($key) {
343 343
 				case 'order_content' :
344
-					$apres[] = ( $duplicate_message ) ? '[order_content]' : $this->order_content_template_for_mail ( $data['order_id'] );
344
+					$apres[] = ($duplicate_message) ? '[order_content]' : $this->order_content_template_for_mail($data['order_id']);
345 345
 					break;
346 346
 				case 'order_addresses' :
347
-					$apres[] = ( $duplicate_message ) ? '[order_addresses]' : $this->order_addresses_template_for_mail ( $data['order_id'] );
347
+					$apres[] = ($duplicate_message) ? '[order_addresses]' : $this->order_addresses_template_for_mail($data['order_id']);
348 348
 					break;
349 349
 
350 350
 				case 'order_billing_address' :
351
-					$apres[] = ( $duplicate_message ) ? '[order_billing_address]' : $this->order_addresses_template_for_mail ( $data['order_id'], 'billing' );
351
+					$apres[] = ($duplicate_message) ? '[order_billing_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'billing');
352 352
 					break;
353 353
 
354 354
 				case 'order_shipping_address' :
355
-					$apres[] = ( $duplicate_message ) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail ( $data['order_id'], 'shipping' );
355
+					$apres[] = ($duplicate_message) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'shipping');
356 356
 					break;
357 357
 
358 358
 				case 'order_customer_comments' :
359
-					$apres[] = ( $duplicate_message ) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail ( $data['order_id'] );
359
+					$apres[] = ($duplicate_message) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail($data['order_id']);
360 360
 					break;
361 361
 				case 'order_personnal_informations' :
362
-					$apres[] = ( $duplicate_message ) ? '[order_personnal_informations]' : $this->order_personnal_informations();
362
+					$apres[] = ($duplicate_message) ? '[order_personnal_informations]' : $this->order_personnal_informations();
363 363
 					break;
364 364
 				default :
365 365
 					$apres[] = $value;
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 		}
369 369
 		$string = str_replace($avant, $apres, $string);
370 370
 
371
-		$string = apply_filters( 'wps_more_customized_message', $string, $data, $duplicate_message );
371
+		$string = apply_filters('wps_more_customized_message', $string, $data, $duplicate_message);
372 372
 
373
-		if ( ($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE') ) {
373
+		if (($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE')) {
374 374
 			$string = preg_replace("/\[(.*)\]/Usi", '', $string);
375 375
 		}
376 376
 
@@ -385,21 +385,21 @@  discard block
 block discarded – undo
385 385
 	 * @param string $object : message object
386 386
 	 * @param file $attached_file : File to attached to e-mail
387 387
 	 */
388
-	function wpshop_prepared_email($email, $model_name, $data=array(), $object=array(), $attached_file = '') {
388
+	function wpshop_prepared_email($email, $model_name, $data = array(), $object = array(), $attached_file = '') {
389 389
 		global $wpdb;
390
-		$data = apply_filters( 'wps_extra_data_to_send_in_email', $data );
390
+		$data = apply_filters('wps_extra_data_to_send_in_email', $data);
391 391
 		$model_id = get_option($model_name, 0);
392
-		$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE ID = %s', $model_id);
393
-		$post_message = $wpdb->get_row( $query );
392
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id);
393
+		$post_message = $wpdb->get_row($query);
394 394
 		$duplicate_message = '';
395
-		if ( !empty($post_message) ) {
395
+		if (!empty($post_message)) {
396 396
 			$title = $this->customMessage($post_message->post_title, $data, $model_name);
397 397
 			$message = $this->customMessage($post_message->post_content, $data, $model_name);
398 398
 			/* On envoie le mail */
399
-			if ( array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data) ) {
399
+			if (array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data)) {
400 400
 				$duplicate_message = $this->customMessage($post_message->post_content, $data, $model_name, true);
401 401
 			}
402
-			if ( !empty($email) ) {
402
+			if (!empty($email)) {
403 403
 				$this->wpshop_email($email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message);
404 404
 			}
405 405
 		}
@@ -419,17 +419,17 @@  discard block
 block discarded – undo
419 419
 	function wpshop_email($email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '') {
420 420
 		global $wpdb;
421 421
 		// Sauvegarde
422
-		if($save) {
423
-			$user = $wpdb->get_row('SELECT ID FROM '.$wpdb->users.' WHERE user_email="'.$email.'";');
422
+		if ($save) {
423
+			$user = $wpdb->get_row('SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";');
424 424
 			$user_id = $user ? $user->ID : get_current_user_id();
425
-			$query = $wpdb->prepare('SELECT ID FROM ' .$wpdb->posts. ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
426
-			$user_post_id = $wpdb->get_var( $query );
425
+			$query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
426
+			$user_post_id = $wpdb->get_var($query);
427 427
 
428
-			if ( !empty($duplicate_message) ) {
429
-				$this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object );
428
+			if (!empty($duplicate_message)) {
429
+				$this->add_message($user_post_id, $email, $title, $duplicate_message, $model_id, $object);
430 430
 			}
431 431
 			else {
432
-				$this->add_message( $user_post_id, $email, $title, $message, $model_id, $object );
432
+				$this->add_message($user_post_id, $email, $title, $message, $model_id, $object);
433 433
 			}
434 434
 
435 435
 		}
@@ -437,19 +437,19 @@  discard block
 block discarded – undo
437 437
 		$emails = get_option('wpshop_emails', array());
438 438
 		$noreply_email = $emails['noreply_email'];
439 439
 		// Split the email to get the name
440
-		$vers_nom = substr($email, 0, strpos($email,'@'));
440
+		$vers_nom = substr($email, 0, strpos($email, '@'));
441 441
 
442 442
 		// Headers du mail
443 443
 		$headers = "MIME-Version: 1.0\r\n";
444 444
 		$headers .= "Content-type: text/html; charset=UTF-8\r\n";
445
-		$headers .= 'From: '.get_bloginfo('name').' <'.$noreply_email.'>' . "\r\n";
445
+		$headers .= 'From: ' . get_bloginfo('name') . ' <' . $noreply_email . '>' . "\r\n";
446 446
 
447 447
 		// Mail en HTML
448 448
 		@wp_mail($email, $title, $message, $headers, $attachments);
449 449
 
450 450
 
451
-		if ( !empty($attachments) ) {
452
-			unlink( $attachments );
451
+		if (!empty($attachments)) {
452
+			unlink($attachments);
453 453
 		}
454 454
 	}
455 455
 
@@ -458,13 +458,13 @@  discard block
 block discarded – undo
458 458
 	 * @param integer $order_id : Order ID
459 459
 	 * @return string
460 460
 	 */
461
-	function order_content_template_for_mail ( $order_id ) {
461
+	function order_content_template_for_mail($order_id) {
462 462
 		$message = '';
463
-		if ( !empty($order_id) ) {
463
+		if (!empty($order_id)) {
464 464
 			$currency_code = wpshop_tools::wpshop_get_currency(false);
465 465
 			$orders_infos = get_post_meta($order_id, '_order_postmeta', true);
466 466
 			ob_start();
467
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_content_mail_template" ) );
467
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_content_mail_template"));
468 468
 			$message .= ob_get_contents();
469 469
 			ob_end_clean();
470 470
 		}
@@ -477,44 +477,44 @@  discard block
 block discarded – undo
477 477
 	 * @param integer $address_type : Address type ID
478 478
 	 * @return string
479 479
 	 */
480
-	function order_addresses_template_for_mail ( $order_id, $address_type = '' ) {
480
+	function order_addresses_template_for_mail($order_id, $address_type = '') {
481 481
 		global $wpdb;
482
-		$shipping_option = get_option( 'wpshop_shipping_address_choice' );
483
-		$display_shipping = ( !empty($shipping_option) && !empty($shipping_option['activate']) ) ? true : false;
482
+		$shipping_option = get_option('wpshop_shipping_address_choice');
483
+		$display_shipping = (!empty($shipping_option) && !empty($shipping_option['activate'])) ? true : false;
484 484
 		$message = '';
485
-		if ( !empty($order_id) ) {
485
+		if (!empty($order_id)) {
486 486
 			$order_addresses = get_post_meta($order_id, '_order_info', true);
487
-			if ( !empty($order_addresses) ) {
488
-				foreach ( $order_addresses as $key=>$order_address ) {
489
-					if ( !empty($order_address) && ( empty($address_type) || $address_type == $key ) ) {
487
+			if (!empty($order_addresses)) {
488
+				foreach ($order_addresses as $key=>$order_address) {
489
+					if (!empty($order_address) && (empty($address_type) || $address_type == $key)) {
490 490
 
491
-						if( $key != 'shipping' || ($key == 'shipping' && $display_shipping) ) {
492
-							$address_type_title = ( !empty($key) && $key == 'billing' ) ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop');
491
+						if ($key != 'shipping' || ($key == 'shipping' && $display_shipping)) {
492
+							$address_type_title = (!empty($key) && $key == 'billing') ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop');
493 493
 							$civility = '';
494
-							if ( !empty($order_address['address']['civility']) ) {
495
-								$query = $wpdb->prepare('SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $order_address['address']['civility']);
496
-								$civility = $wpdb->get_var( $query );
494
+							if (!empty($order_address['address']['civility'])) {
495
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility']);
496
+								$civility = $wpdb->get_var($query);
497 497
 							}
498 498
 
499 499
 							// Address informations
500
-							$customer_last_name = (!empty($order_address['address']['address_last_name']) ) ? $order_address['address']['address_last_name'] : '';
501
-							$customer_firtsname = (!empty($order_address['address']['address_first_name']) ) ? $order_address['address']['address_first_name'] : '';
502
-							$customer_company = (!empty($order_address['address']['company']) ) ? $order_address['address']['company'] : '';
503
-							$customer_address = (!empty($order_address['address']['address']) ) ? $order_address['address']['address'] : '';
504
-							$customer_zip_code = (!empty($order_address['address']['postcode']) ) ? $order_address['address']['postcode'] : '';
505
-							$customer_city = (!empty($order_address['address']['city']) ) ? $order_address['address']['city'] : '';
506
-							$customer_state = (!empty($order_address['address']['state']) ) ? $order_address['address']['state'] : '';
507
-							$customer_phone = (!empty($order_address['address']['phone']) ) ? ' Tel. : '.$order_address['address']['phone'] : '';
500
+							$customer_last_name = (!empty($order_address['address']['address_last_name'])) ? $order_address['address']['address_last_name'] : '';
501
+							$customer_firtsname = (!empty($order_address['address']['address_first_name'])) ? $order_address['address']['address_first_name'] : '';
502
+							$customer_company = (!empty($order_address['address']['company'])) ? $order_address['address']['company'] : '';
503
+							$customer_address = (!empty($order_address['address']['address'])) ? $order_address['address']['address'] : '';
504
+							$customer_zip_code = (!empty($order_address['address']['postcode'])) ? $order_address['address']['postcode'] : '';
505
+							$customer_city = (!empty($order_address['address']['city'])) ? $order_address['address']['city'] : '';
506
+							$customer_state = (!empty($order_address['address']['state'])) ? $order_address['address']['state'] : '';
507
+							$customer_phone = (!empty($order_address['address']['phone'])) ? ' Tel. : ' . $order_address['address']['phone'] : '';
508 508
 							$country = '';
509
-							foreach ( unserialize(WPSHOP_COUNTRY_LIST) as $key => $value ) {
510
-								if ( !empty($order_address['address']['country']) && $key ==  $order_address['address']['country']) {
509
+							foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) {
510
+								if (!empty($order_address['address']['country']) && $key == $order_address['address']['country']) {
511 511
 									$country = $value;
512 512
 								}
513 513
 							}
514 514
 							$customer_country = $country;
515 515
 
516 516
 							ob_start();
517
-							require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_addresses_template_for_mail") );
517
+							require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_addresses_template_for_mail"));
518 518
 							$message .= ob_get_contents();
519 519
 							ob_end_clean();
520 520
 						}
@@ -530,21 +530,21 @@  discard block
 block discarded – undo
530 530
 	 * @param integer $order_id : Order ID
531 531
 	 * @return string
532 532
 	 */
533
-	function order_customer_comment_template_for_mail ( $order_id ) {
533
+	function order_customer_comment_template_for_mail($order_id) {
534 534
 		global $wpdb;
535 535
 		$message = '';
536
-		if ( !empty($order_id) ) {
537
-			$query = $wpdb->prepare('SELECT post_excerpt FROM ' .$wpdb->posts. ' WHERE ID = %d', $order_id);
538
-			$comment = $wpdb->get_var( $query );
536
+		if (!empty($order_id)) {
537
+			$query = $wpdb->prepare('SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id);
538
+			$comment = $wpdb->get_var($query);
539 539
 			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
540
-			if ( !empty($order_infos['order_key']) ) {
541
-				$comment_title =  __('Comments about the order', 'wpshop');
540
+			if (!empty($order_infos['order_key'])) {
541
+				$comment_title = __('Comments about the order', 'wpshop');
542 542
 			}
543 543
 			else {
544
-				$comment_title =  __('Comments about the quotation', 'wpshop');
544
+				$comment_title = __('Comments about the quotation', 'wpshop');
545 545
 			}
546 546
 			ob_start();
547
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_email_customer_comments") );
547
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_email_customer_comments"));
548 548
 			$message .= ob_get_contents();
549 549
 			ob_end_clean();
550 550
 		}
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
 		global $wpdb;
560 560
 		$user_id = get_current_user_id();
561 561
 		$message = '';
562
-		$customer_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
563
-		if( !empty($customer_entity) ) {
562
+		$customer_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
563
+		if (!empty($customer_entity)) {
564 564
 
565
-			$query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid' );
566
-			$attributes_sets = $wpdb->get_results( $query );
565
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid');
566
+			$attributes_sets = $wpdb->get_results($query);
567 567
 
568
-			if( !empty($attributes_sets) ) {
568
+			if (!empty($attributes_sets)) {
569 569
 				ob_start();
570
-				require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_personnal_informations_template_for_mail") );
570
+				require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_personnal_informations_template_for_mail"));
571 571
 				$message .= ob_get_contents();
572 572
 				ob_end_clean();
573 573
 			}
@@ -578,15 +578,15 @@  discard block
 block discarded – undo
578 578
 	/**
579 579
 	 * Support historic messages
580 580
 	 */
581
-	function wpshop_messages_historic_correction () {
581
+	function wpshop_messages_historic_correction() {
582 582
 		global $wpdb;
583
-		$query = $wpdb->prepare('SELECT * FROM ' .$wpdb->postmeta. ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%');
584
-		$messages_histo = $wpdb->get_results( $query );
583
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%');
584
+		$messages_histo = $wpdb->get_results($query);
585 585
 
586
-		foreach ( $messages_histo as $message ) {
587
-			$query_user = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_author = %d AND post_type = %s',  $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
588
-			$user_post_id = $wpdb->get_var( $query_user );
589
-			$wpdb->update($wpdb->postmeta, array('post_id' => $user_post_id ), array('meta_id' => $message->meta_id ) );
586
+		foreach ($messages_histo as $message) {
587
+			$query_user = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
588
+			$user_post_id = $wpdb->get_var($query_user);
589
+			$wpdb->update($wpdb->postmeta, array('post_id' => $user_post_id), array('meta_id' => $message->meta_id));
590 590
 		}
591 591
 	}
592 592
 
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 	 * Récupères le contenu du message
596 596
 	 */
597 597
 	public function get_content_message() {
598
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
598
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
599 599
 
600
-		if ( !wp_verify_nonce( $_wpnonce, 'get_content_message' ) )
600
+		if (!wp_verify_nonce($_wpnonce, 'get_content_message'))
601 601
 			wp_die();
602 602
 
603 603
 		global $wpdb;
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 		$result = unserialize($result[0]->meta_value);
608 608
 		$result = $result[0]['mess_message'];
609 609
 
610
-		wp_die( $result );
610
+		wp_die($result);
611 611
 	}
612 612
 
613 613
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -13 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_message_ctr {
3 5
 	/** Define the main directory containing the template for the current plugin
4 6
 	 * @var string
@@ -175,8 +177,7 @@  discard block
 block discarded – undo
175 177
 			$id = wp_insert_post( $new_message );
176 178
 
177 179
 			update_option( $code, $id );
178
-		}
179
-		else {
180
+		} else {
180 181
 			$id = $message_option;
181 182
 		}
182 183
 
@@ -195,10 +196,11 @@  discard block
 block discarded – undo
195 196
 				echo wp_trim_words($post->post_content, 55);
196 197
 			break;
197 198
 			case "last_dispatch_date":
198
-				if(!empty($metadata['wpshop_message_last_dispatch_date'][0]))
199
-					echo mysql2date('d F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true);
200
-				else
201
-					echo '-';
199
+				if(!empty($metadata['wpshop_message_last_dispatch_date'][0])) {
200
+									echo mysql2date('d F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true);
201
+				} else {
202
+									echo '-';
203
+				}
202 204
 			break;
203 205
 		}
204 206
 	}
@@ -427,8 +429,7 @@  discard block
 block discarded – undo
427 429
 
428 430
 			if ( !empty($duplicate_message) ) {
429 431
 				$this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object );
430
-			}
431
-			else {
432
+			} else {
432 433
 				$this->add_message( $user_post_id, $email, $title, $message, $model_id, $object );
433 434
 			}
434 435
 
@@ -539,8 +540,7 @@  discard block
 block discarded – undo
539 540
 			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
540 541
 			if ( !empty($order_infos['order_key']) ) {
541 542
 				$comment_title =  __('Comments about the order', 'wpshop');
542
-			}
543
-			else {
543
+			} else {
544 544
 				$comment_title =  __('Comments about the quotation', 'wpshop');
545 545
 			}
546 546
 			ob_start();
@@ -597,8 +597,9 @@  discard block
 block discarded – undo
597 597
 	public function get_content_message() {
598 598
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
599 599
 
600
-		if ( !wp_verify_nonce( $_wpnonce, 'get_content_message' ) )
601
-			wp_die();
600
+		if ( !wp_verify_nonce( $_wpnonce, 'get_content_message' ) ) {
601
+					wp_die();
602
+		}
602 603
 
603 604
 		global $wpdb;
604 605
 		$meta_id = (int)$_GET['meta_id'];
Please login to merge, or discard this patch.
includes/modules/wps_orders/controller/wps_orders_ctr.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		/**
130 130
 		 *	Build an array with the different items to add to an order
131 131
 		 *
132
-		 *	@param array $products The item list to add to the order
132
+		 *	@param array $product The item list to add to the order
133 133
 		 *
134 134
 		 *	@return array $item_list The item to add to order
135 135
 		 */
@@ -321,6 +321,9 @@  discard block
 block discarded – undo
321 321
 			wp_die();
322 322
 		}
323 323
 
324
+		/**
325
+		 * @param integer $order_id
326
+		 */
324 327
 		function pay_quotation( $order_id ) {
325 328
 			$status = true;
326 329
 			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
Please login to merge, or discard this patch.
Spacing   +123 added lines, -123 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_orders_ctr {
3 3
 	/** Define the main directory containing the template for the current plugin
4 4
 	 * @var string
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 			/** Template Load **/
18 18
 // 			add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) );
19 19
 
20
-			add_shortcode( 'order_customer_informations', array( &$this, 'display_order_customer_informations' ) );
21
-			add_shortcode( 'wps_orders_in_customer_account', array($this, 'display_orders_in_account') );
20
+			add_shortcode('order_customer_informations', array(&$this, 'display_order_customer_informations'));
21
+			add_shortcode('wps_orders_in_customer_account', array($this, 'display_orders_in_account'));
22 22
 
23
-			add_action( 'wp_enqueue_scripts', array( $this, 'wps_orders_scripts') );
23
+			add_action('wp_enqueue_scripts', array($this, 'wps_orders_scripts'));
24 24
 			/**	Include the different javascript	*/
25
-			add_action( 'admin_init', array(&$this, 'admin_js') );
25
+			add_action('admin_init', array(&$this, 'admin_js'));
26 26
 
27 27
 
28 28
 			/** Ajax Actions **/
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
 // 			add_action( 'wap_ajax_wps_orders_load_variations_container', array( &$this, 'wps_orders_load_variations_container') );
33 33
 // 			add_action( 'wap_ajax_wps_order_refresh_in_admin', array( &$this, 'wps_order_refresh_in_admin') );
34 34
 
35
-			add_action( 'wp_ajax_wps_orders_load_details', array( $this, 'wps_orders_load_details') );
35
+			add_action('wp_ajax_wps_orders_load_details', array($this, 'wps_orders_load_details'));
36 36
 
37 37
 			// Add a product sale historic in administration product panel
38
-			add_action( 'wp_ajax_wps_order_choose_customer', array( $this, 'wps_order_choose_customer' ) );
38
+			add_action('wp_ajax_wps_order_choose_customer', array($this, 'wps_order_choose_customer'));
39 39
 
40 40
 			/** For delete order */
41
-			add_action( 'wp_ajax_wps_delete_order', array( $this, 'wps_delete_order' ) );
41
+			add_action('wp_ajax_wps_delete_order', array($this, 'wps_delete_order'));
42 42
 
43 43
 			/** For pay billing */
44
-			add_action( 'wp_ajax_wps_checkout_quotation', array( $this, 'wps_checkout_quotation' ) );
45
-			add_action( 'wp_ajax_nopriv_wps_checkout_quotation', array( $this, 'wps_checkout_quotation_no_login' ) );
44
+			add_action('wp_ajax_wps_checkout_quotation', array($this, 'wps_checkout_quotation'));
45
+			add_action('wp_ajax_nopriv_wps_checkout_quotation', array($this, 'wps_checkout_quotation_no_login'));
46 46
 
47 47
 		}
48 48
 
@@ -58,24 +58,24 @@  discard block
 block discarded – undo
58 58
 		 * Add scripts
59 59
 		 */
60 60
 		function wps_orders_scripts() {
61
-			wp_enqueue_script( 'wps_orders_fronend', WPS_ORDERS_URL.WPS_ORDERS_DIR.'/assets/frontend/js/wps_orders.js' );
61
+			wp_enqueue_script('wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js');
62 62
 		}
63 63
 
64 64
 		function display_order_customer_informations() {
65 65
 			global $post_id; global $wpdb;
66 66
 			$output = '';
67
-			if ( !empty($post_id) ) {
68
-				$order_postmeta = get_post_meta( $post_id, '_order_postmeta', true );
69
-				$order_info = get_post_meta( $post_id, '_order_info', true );
67
+			if (!empty($post_id)) {
68
+				$order_postmeta = get_post_meta($post_id, '_order_postmeta', true);
69
+				$order_info = get_post_meta($post_id, '_order_info', true);
70 70
 
71 71
 				/** Check the order status **/
72
-				if ( !empty($order_postmeta) ) {
73
-					if ( !empty($order_postmeta['order_status'])  && $order_postmeta['order_status'] != 'awaiting_payment' ) {
74
-						$output = wps_address::display_an_address( $order_info['billing']['address'] );
75
-						$output .= wps_address::display_an_address( $order_info['shipping']['address'] );
72
+				if (!empty($order_postmeta)) {
73
+					if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] != 'awaiting_payment') {
74
+						$output = wps_address::display_an_address($order_info['billing']['address']);
75
+						$output .= wps_address::display_an_address($order_info['shipping']['address']);
76 76
 					}
77 77
 					else {
78
-						$output = wps_address::display_an_address( $order_info['billing']['address'] );
78
+						$output = wps_address::display_an_address($order_info['billing']['address']);
79 79
 					}
80 80
 				}
81 81
 			}
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 							'blog_id'                 => $GLOBALS['blog_id'],
100 100
 							'who'                     => null // string
101 101
 						);
102
-				$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users( $args );
102
+				$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users($args);
103 103
 				$output = wpshop_display::display_template_element('wps_orders_choose_customer_interface', $tpl_component, array(), 'admin');
104 104
 			}
105 105
 			return $output;
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 		 * @param integer $customer_id
111 111
 		 * @return string
112 112
 		 */
113
-		function display_orders_in_account( $customer_id = '' ) {
113
+		function display_orders_in_account($customer_id = '') {
114 114
 			$output = '';
115
-			$customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id();
116
-			$from_admin = ( !empty($customer_id) ) ? true : false;
115
+			$customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id();
116
+			$from_admin = (!empty($customer_id)) ? true : false;
117 117
 			$wps_orders_mdl = new wps_orders_mdl();
118
-			$orders = $wps_orders_mdl->get_customer_orders( $customer_id );
118
+			$orders = $wps_orders_mdl->get_customer_orders($customer_id);
119 119
 
120 120
 			// Display orders
121 121
 			ob_start();
122
-			require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "frontend", "orders_list_in_account") );
122
+			require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "frontend", "orders_list_in_account"));
123 123
 			$output = ob_get_contents();
124 124
 			ob_end_clean();
125 125
 
@@ -133,26 +133,26 @@  discard block
 block discarded – undo
133 133
 		 *
134 134
 		 *	@return array $item_list The item to add to order
135 135
 		 */
136
-		function add_product_to_order( $product ) {
136
+		function add_product_to_order($product) {
137 137
 			global $wpdb;
138 138
 
139
-			if( !empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount']) ) {
140
-				$price_infos = wpshop_prices::check_product_price( $product, true );
141
-				$product['price_ht'] = ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ?  $price_infos['discount']['discount_et_price'] : $price_infos['et'];
142
-				$product['product_price'] = ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
143
-				$product['tva'] = ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
139
+			if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) {
140
+				$price_infos = wpshop_prices::check_product_price($product, true);
141
+				$product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
142
+				$product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
143
+				$product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
144 144
 			}
145 145
 
146
-			$price_piloting = get_option( 'wpshop_shop_price_piloting' );
146
+			$price_piloting = get_option('wpshop_shop_price_piloting');
147 147
 
148
-			if ( !empty($price_piloting) && $price_piloting == 'HT') {
148
+			if (!empty($price_piloting) && $price_piloting == 'HT') {
149 149
 				$total_ht = $product['price_ht'] * $product['product_qty'];
150
-				$tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 );
150
+				$tva_total_amount = $total_ht * ($product['tx_tva'] / 100);
151 151
 				$total_ttc = $total_ht + $tva_total_amount;
152 152
 			}
153 153
 			else {
154 154
 				$total_ttc = $product['product_price'] * $product['product_qty'];
155
-				$total_ht  = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) );
155
+				$total_ht  = $total_ttc / (1 + ($product['tx_tva'] / 100));
156 156
 				$tva_total_amount = $total_ttc - $total_ht;
157 157
 			}
158 158
 
@@ -160,21 +160,21 @@  discard block
 block discarded – undo
160 160
 
161 161
 			$item_discount_type = $item_discount_value = $item_discount_amount = 0;
162 162
 
163
-			$d_amount = !empty( $product ) && !empty( $product[ 'discount_amount' ] ) ? wpshop_tools::formate_number( $product['discount_amount'] ) : null;
164
-			$d_rate = !empty( $product ) && !empty( $product[ 'discount_rate' ] ) ? wpshop_tools::formate_number( $product['discount_rate'] ) : null;
165
-			$d_special = !empty( $product ) && !empty( $product[ 'special_price' ] ) ? wpshop_tools::formate_number( $product['special_price'] ) : null;
163
+			$d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null;
164
+			$d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null;
165
+			$d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null;
166 166
 
167
-			if( !empty($d_amount) ) {
167
+			if (!empty($d_amount)) {
168 168
 				$item_discount_type = 'discount_amount';
169 169
 				$item_discount_amount = $product['discount_amount'];
170 170
 				$item_discount_value = $product['discount_amount'];
171 171
 			}
172
-			elseif(!empty($d_rate)) {
172
+			elseif (!empty($d_rate)) {
173 173
 				$item_discount_type = 'discount_rate';
174 174
 				$item_discount_amount = $product['discount_rate'];
175 175
 				$item_discount_value = $product['discount_rate'];
176 176
 			}
177
-			elseif(!empty($d_special)) {
177
+			elseif (!empty($d_special)) {
178 178
 				$item_discount_type = 'special_price';
179 179
 				$item_discount_amount = $product['special_price'];
180 180
 				$item_discount_value = $product['special_price'];
@@ -201,31 +201,31 @@  discard block
 block discarded – undo
201 201
 					'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array()
202 202
 			);
203 203
 
204
-			$array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT,WPSHOP_PRODUCT_PRICE_TTC,WPSHOP_PRODUCT_PRICE_TAX_AMOUNT,'product_qty',WPSHOP_PRODUCT_PRICE_TAX,'product_id','product_reference','product_name','variations');
204
+			$array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations');
205 205
 
206
-			if(!empty($product['item_meta'])) {
207
-				foreach($product['item_meta'] as $key=>$value) {
208
-					if( !isset($item['item_'.$key]) && !in_array($key, $array_not_to_do) && !empty($product[$key]) ) {
209
-						$item['item_'.$key] = $product[$key];
206
+			if (!empty($product['item_meta'])) {
207
+				foreach ($product['item_meta'] as $key=>$value) {
208
+					if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) {
209
+						$item['item_' . $key] = $product[$key];
210 210
 					}
211 211
 				}
212 212
 			}
213 213
 
214 214
 			/** Check if it's a variation product **/
215
-			if ( !empty($product) && !empty( $product['item_meta']) && !empty($product['item_meta']['variations']) ) {
216
-				foreach( $product['item_meta']['variations'] as $k => $variation ) {
217
-					$product_variation_def = get_post_meta( $k, '_wpshop_variations_attribute_def', true);
218
-					if ( !empty($product_variation_def) ) {
219
-						foreach( $product_variation_def as $attribute_code => $variation_id ) {
220
-							$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
221
-							if ( !empty($variation_attribute_def) ) {
215
+			if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) {
216
+				foreach ($product['item_meta']['variations'] as $k => $variation) {
217
+					$product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true);
218
+					if (!empty($product_variation_def)) {
219
+						foreach ($product_variation_def as $attribute_code => $variation_id) {
220
+							$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
221
+							if (!empty($variation_attribute_def)) {
222 222
 								$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
223
-								if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
224
-									$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
225
-									$variation_name = $wpdb->get_var( $query );
223
+								if ($variation_attribute_def->data_type_to_use == 'custom') {
224
+									$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
225
+									$variation_name = $wpdb->get_var($query);
226 226
 								}
227 227
 								else {
228
-									$variation_post = get_post( $variation_id );
228
+									$variation_post = get_post($variation_id);
229 229
 									$variation_name = $variation_post->post_title;
230 230
 								}
231 231
 								$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
@@ -237,19 +237,19 @@  discard block
 block discarded – undo
237 237
 			}
238 238
 			else {
239 239
 				/** Check if it's product with one variation **/
240
-				$product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true);
240
+				$product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true);
241 241
 
242
-				if ( !empty($product_variation_def) ) {
243
-					foreach( $product_variation_def as $attribute_code => $variation_id ) {
244
-						$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
245
-						if ( !empty($variation_attribute_def) ) {
242
+				if (!empty($product_variation_def)) {
243
+					foreach ($product_variation_def as $attribute_code => $variation_id) {
244
+						$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
245
+						if (!empty($variation_attribute_def)) {
246 246
 							$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
247
-							if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
248
-								$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
249
-								$variation_name = $wpdb->get_var( $query );
247
+							if ($variation_attribute_def->data_type_to_use == 'custom') {
248
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
249
+								$variation_name = $wpdb->get_var($query);
250 250
 							}
251 251
 							else {
252
-								$variation_post = get_post( $variation_id );
252
+								$variation_post = get_post($variation_id);
253 253
 								$variation_name = $variation_post->post_title;
254 254
 							}
255 255
 							$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 			}
261 261
 
262 262
 			/**	On ajoute la possibilité d'étendre les données produits ajoutées dans le panier / Add possibility to extends product data saved into cart	*/
263
-			$item = apply_filters( 'wpshop-add-product-to-order', $item, $product );
263
+			$item = apply_filters('wpshop-add-product-to-order', $item, $product);
264 264
 
265 265
 			return $item;
266 266
 		}
@@ -270,24 +270,24 @@  discard block
 block discarded – undo
270 270
 		 * AJAX - Load order details in customer account
271 271
 		 */
272 272
 		function wps_orders_load_details() {
273
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
273
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
274 274
 
275
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_load_details' ) )
275
+			if (!wp_verify_nonce($_wpnonce, 'wps_orders_load_details'))
276 276
 				wp_die();
277 277
 
278
-			$order_id = ( !empty($_POST['order_id']) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : '';
278
+			$order_id = (!empty($_POST['order_id'])) ? wpshop_tools::varSanitizer($_POST['order_id']) : '';
279 279
 			$user_id = get_current_user_id();
280 280
 			$status = false; $result = '';
281
-			if( !empty($order_id) ) {
282
-				$order = get_post( $order_id );
283
-				$order_infos = get_post_meta( $order_id, '_order_postmeta', true );
284
-				$order_key = ( !empty($order_infos['order_key']) ) ? $order_infos['order_key'] : '-';
285
-				if( !empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id ) {
286
-					$result = do_shortcode( '[wps_cart cart_type="summary" oid="' .$order_id. '"]' );
281
+			if (!empty($order_id)) {
282
+				$order = get_post($order_id);
283
+				$order_infos = get_post_meta($order_id, '_order_postmeta', true);
284
+				$order_key = (!empty($order_infos['order_key'])) ? $order_infos['order_key'] : '-';
285
+				if (!empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id) {
286
+					$result = do_shortcode('[wps_cart cart_type="summary" oid="' . $order_id . '"]');
287 287
 					$status = true;
288 288
 				}
289 289
 			}
290
-			echo json_encode( array( 'status' => $status, 'title' => sprintf( __( 'Order n° %s details', 'wpshop' ), $order_key ), 'content' => $result ) );
290
+			echo json_encode(array('status' => $status, 'title' => sprintf(__('Order n° %s details', 'wpshop'), $order_key), 'content' => $result));
291 291
 			wp_die();
292 292
 		}
293 293
 
@@ -295,83 +295,83 @@  discard block
 block discarded – undo
295 295
 		 * AJAX - Choose customer to create order
296 296
 		 */
297 297
 		function wps_order_choose_customer() {
298
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
298
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
299 299
 
300
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) )
300
+			if (!wp_verify_nonce($_wpnonce, 'wps_order_choose_customer'))
301 301
 				wp_die();
302 302
 
303 303
 			$status = false; $billing_data = $shipping_data = '';
304
-			$customer_id = ( !empty($_POST['customer_id']) ) ? intval( $_POST['customer_id'] ): null;
305
-			if( !empty($customer_id) ) {
304
+			$customer_id = (!empty($_POST['customer_id'])) ? intval($_POST['customer_id']) : null;
305
+			if (!empty($customer_id)) {
306 306
 				$wps_address = new wps_address();
307
-				$billing_option = get_option( 'wpshop_billing_address' );
308
-				$shipping_option = get_option( 'wpshop_shipping_address_choice' );
307
+				$billing_option = get_option('wpshop_billing_address');
308
+				$shipping_option = get_option('wpshop_shipping_address_choice');
309 309
 				$billing_option = $billing_option['choice'];
310
-				$customer_addresses_list = wps_address::get_addresses_list( $customer_id );
310
+				$customer_addresses_list = wps_address::get_addresses_list($customer_id);
311 311
 				$status = true;
312
-				$billing_data = '<div class="wps-alert-info">' .sprintf( __( 'No Billing address created, <a href="%s" title="' .__( 'Create a new billing address', 'wpshop' ). '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ). '?action=wps-add-an-address-in-admin&address_type='.$billing_option.'&customer_id='.$customer_id.'&height=600' ). '</div>';
312
+				$billing_data = '<div class="wps-alert-info">' . sprintf(__('No Billing address created, <a href="%s" title="' . __('Create a new billing address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
313 313
 
314
-				if( !empty($shipping_option) && !empty($shipping_option['activate']) ) {
314
+				if (!empty($shipping_option) && !empty($shipping_option['activate'])) {
315 315
 					$shipping_option = $shipping_option['choice'];
316
-					$shipping_data = '<div class="wps-alert-info">' .sprintf( __( 'No shipping address created, <a href="%s" title="' .__( 'Create a new shipping address', 'wpshop' ). '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ). '?action=wps-add-an-address-in-admin&address_type='.$shipping_option.'&customer_id='.$customer_id.'&height=600' ). '</div>';
316
+					$shipping_data = '<div class="wps-alert-info">' . sprintf(__('No shipping address created, <a href="%s" title="' . __('Create a new shipping address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
317 317
 				}
318 318
 
319
-				if( !empty($customer_addresses_list) ) {
320
-					foreach( $customer_addresses_list as $address_type => $customer_addresses ) {
321
-						if( $billing_option == $address_type ) {
322
-							$billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
319
+				if (!empty($customer_addresses_list)) {
320
+					foreach ($customer_addresses_list as $address_type => $customer_addresses) {
321
+						if ($billing_option == $address_type) {
322
+							$billing_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
323 323
 						}
324 324
 						else {
325
-							$shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
325
+							$shipping_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
326 326
 						}
327 327
 					}
328 328
 				}
329 329
 			}
330
-			echo json_encode( array( 'status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data) );
330
+			echo json_encode(array('status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data));
331 331
 			wp_die();
332 332
 		}
333 333
 
334
-		function pay_quotation( $order_id ) {
334
+		function pay_quotation($order_id) {
335 335
 			$status = true;
336
-			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
337
-			$order_info = get_post_meta( $order_id, '_order_info', true );
336
+			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
337
+			$order_info = get_post_meta($order_id, '_order_info', true);
338 338
 			$_SESSION['shipping_method'] = $order_meta['order_payment']['shipping_method'];
339
-			isset( $order_info['billing']['address_id'] ) ? $_SESSION['billing_address'] = $order_info['billing']['address_id'] : $status = false;
340
-			isset( $order_info['shipping']['address_id'] ) ? $_SESSION['shipping_address'] = $order_info['shipping']['address_id'] : false;
339
+			isset($order_info['billing']['address_id']) ? $_SESSION['billing_address'] = $order_info['billing']['address_id'] : $status = false;
340
+			isset($order_info['shipping']['address_id']) ? $_SESSION['shipping_address'] = $order_info['shipping']['address_id'] : false;
341 341
 			$_SESSION['cart'] = array();
342
-			$_SESSION['cart']['order_id'] = wpshop_tools::varSanitizer( $order_id );
342
+			$_SESSION['cart']['order_id'] = wpshop_tools::varSanitizer($order_id);
343 343
 			$_SESSION['cart']['cart_type'] = 'normal';
344 344
 			$_SESSION['cart']['order_amount_to_pay_now'] = $order_meta['order_amount_to_pay_now'];
345 345
 			$_SESSION['cart']['order_items'] = $order_meta['order_items'];
346
-			return array( 'status' => $status, 'permalink' => get_permalink( get_option('wpshop_cart_page_id') ) . '?order_step=5' );
346
+			return array('status' => $status, 'permalink' => get_permalink(get_option('wpshop_cart_page_id')) . '?order_step=5');
347 347
 		}
348 348
 		/**
349 349
 		 * AJAX - Delete order by order_id
350 350
 		 */
351 351
 		public function wps_delete_order() {
352
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
352
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
353 353
 
354
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) )
354
+			if (!wp_verify_nonce($_wpnonce, 'wps_delete_order'))
355 355
 				wp_die();
356 356
 
357 357
 			$status = false;
358 358
 			$output = '';
359
-			$order_id = !empty( $_POST['order_id'] ) ? (int) $_POST['order_id'] : 0;
360
-			if( $order_id ) {
361
-				$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
359
+			$order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : 0;
360
+			if ($order_id) {
361
+				$order_meta = get_post_meta($order_id, '_order_postmeta', true);
362 362
 				$wps_credit = new wps_credit();
363
-				$wps_credit->create_an_credit( $order_id );
363
+				$wps_credit->create_an_credit($order_id);
364 364
 				$order_meta['order_status'] = 'canceled';
365
-				$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0 );
365
+				$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0);
366 366
 				$order_meta['order_payment']['refunded_action']['author'] = get_current_user_id();
367
-				update_post_meta( $order_id, '_order_postmeta', $order_meta );
367
+				update_post_meta($order_id, '_order_postmeta', $order_meta);
368 368
 				ob_start();
369
-				require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "frontend", "order_row_in_account") );
369
+				require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "frontend", "order_row_in_account"));
370 370
 				$output = ob_get_contents();
371 371
 				ob_end_clean();
372 372
 				$status = true;
373 373
 			}
374
-			echo json_encode( array( 'status' => $status, 'row' => $output ) );
374
+			echo json_encode(array('status' => $status, 'row' => $output));
375 375
 			wp_die();
376 376
 		}
377 377
 
@@ -379,37 +379,37 @@  discard block
 block discarded – undo
379 379
 		 * AJAX - Pay billing
380 380
 		 */
381 381
 		public function wps_checkout_quotation() {
382
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
382
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
383 383
 
384
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
384
+			if (!wp_verify_nonce($_wpnonce, 'wps_checkout_quotation'))
385 385
 				wp_die();
386 386
 
387 387
 			$status = true;
388
-			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
388
+			$order_id = !empty($_REQUEST['order_id']) ? (int)$_REQUEST['order_id'] : 0;
389 389
 
390
-			if( !empty( $order_id ) ) {
391
-				$pay_quotation = self::pay_quotation( $order_id );
390
+			if (!empty($order_id)) {
391
+				$pay_quotation = self::pay_quotation($order_id);
392 392
 				$status = $pay_quotation['status'];
393 393
 			}
394 394
 
395
-			$is_link = !empty( $_REQUEST['is_link'] ) ? sanitize_text_field( $_REQUEST['is_link'] ) : '';
395
+			$is_link = !empty($_REQUEST['is_link']) ? sanitize_text_field($_REQUEST['is_link']) : '';
396 396
 
397
-			if( !empty( $is_link ) ) {
398
-				wp_redirect( $pay_quotation['permalink'] );
397
+			if (!empty($is_link)) {
398
+				wp_redirect($pay_quotation['permalink']);
399 399
 				exit();
400 400
 			} else {
401
-				echo json_encode( array( 'status' => $status, '301' => $pay_quotation['permalink'] ) );
401
+				echo json_encode(array('status' => $status, '301' => $pay_quotation['permalink']));
402 402
 				wp_die();
403 403
 			}
404 404
 		}
405 405
 		public function wps_checkout_quotation_no_login() {
406
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
406
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
407 407
 
408
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
408
+			if (!wp_verify_nonce($_wpnonce, 'wps_checkout_quotation'))
409 409
 				wp_die();
410 410
 
411
-			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
412
-			wp_redirect( home_url('/wp-login.php') . '?redirect_to=' . urlencode( admin_url() . 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $order_id . '&is_link=link' ) );
411
+			$order_id = !empty($_REQUEST['order_id']) ? (int)$_REQUEST['order_id'] : 0;
412
+			wp_redirect(home_url('/wp-login.php') . '?redirect_to=' . urlencode(admin_url() . 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $order_id . '&is_link=link'));
413 413
 			exit();
414 414
 		}
415 415
 }
Please login to merge, or discard this patch.
Braces   +27 added lines, -29 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_orders_ctr {
3 5
 	/** Define the main directory containing the template for the current plugin
4 6
 	 * @var string
@@ -73,13 +75,11 @@  discard block
 block discarded – undo
73 75
 					if ( !empty($order_postmeta['order_status'])  && $order_postmeta['order_status'] != 'awaiting_payment' ) {
74 76
 						$output = wps_address::display_an_address( $order_info['billing']['address'] );
75 77
 						$output .= wps_address::display_an_address( $order_info['shipping']['address'] );
76
-					}
77
-					else {
78
+					} else {
78 79
 						$output = wps_address::display_an_address( $order_info['billing']['address'] );
79 80
 					}
80 81
 				}
81
-			}
82
-			else {
82
+			} else {
83 83
 				/** Display  "Choose customer or create one" Interface **/
84 84
 				$tpl_component = array();
85 85
 				$args = array(
@@ -149,8 +149,7 @@  discard block
 block discarded – undo
149 149
 				$total_ht = $product['price_ht'] * $product['product_qty'];
150 150
 				$tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 );
151 151
 				$total_ttc = $total_ht + $tva_total_amount;
152
-			}
153
-			else {
152
+			} else {
154 153
 				$total_ttc = $product['product_price'] * $product['product_qty'];
155 154
 				$total_ht  = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) );
156 155
 				$tva_total_amount = $total_ttc - $total_ht;
@@ -168,13 +167,11 @@  discard block
 block discarded – undo
168 167
 				$item_discount_type = 'discount_amount';
169 168
 				$item_discount_amount = $product['discount_amount'];
170 169
 				$item_discount_value = $product['discount_amount'];
171
-			}
172
-			elseif(!empty($d_rate)) {
170
+			} elseif(!empty($d_rate)) {
173 171
 				$item_discount_type = 'discount_rate';
174 172
 				$item_discount_amount = $product['discount_rate'];
175 173
 				$item_discount_value = $product['discount_rate'];
176
-			}
177
-			elseif(!empty($d_special)) {
174
+			} elseif(!empty($d_special)) {
178 175
 				$item_discount_type = 'special_price';
179 176
 				$item_discount_amount = $product['special_price'];
180 177
 				$item_discount_value = $product['special_price'];
@@ -223,8 +220,7 @@  discard block
 block discarded – undo
223 220
 								if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
224 221
 									$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
225 222
 									$variation_name = $wpdb->get_var( $query );
226
-								}
227
-								else {
223
+								} else {
228 224
 									$variation_post = get_post( $variation_id );
229 225
 									$variation_name = $variation_post->post_title;
230 226
 								}
@@ -234,8 +230,7 @@  discard block
 block discarded – undo
234 230
 						}
235 231
 					}
236 232
 				}
237
-			}
238
-			else {
233
+			} else {
239 234
 				/** Check if it's product with one variation **/
240 235
 				$product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true);
241 236
 
@@ -247,8 +242,7 @@  discard block
 block discarded – undo
247 242
 							if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
248 243
 								$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
249 244
 								$variation_name = $wpdb->get_var( $query );
250
-							}
251
-							else {
245
+							} else {
252 246
 								$variation_post = get_post( $variation_id );
253 247
 								$variation_name = $variation_post->post_title;
254 248
 							}
@@ -272,8 +266,9 @@  discard block
 block discarded – undo
272 266
 		function wps_orders_load_details() {
273 267
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
274 268
 
275
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_load_details' ) )
276
-				wp_die();
269
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_load_details' ) ) {
270
+							wp_die();
271
+			}
277 272
 
278 273
 			$order_id = ( !empty($_POST['order_id']) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : '';
279 274
 			$user_id = get_current_user_id();
@@ -297,8 +292,9 @@  discard block
 block discarded – undo
297 292
 		function wps_order_choose_customer() {
298 293
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
299 294
 
300
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) )
301
-				wp_die();
295
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) ) {
296
+							wp_die();
297
+			}
302 298
 
303 299
 			$status = false; $billing_data = $shipping_data = '';
304 300
 			$customer_id = ( !empty($_POST['customer_id']) ) ? intval( $_POST['customer_id'] ): null;
@@ -320,8 +316,7 @@  discard block
 block discarded – undo
320 316
 					foreach( $customer_addresses_list as $address_type => $customer_addresses ) {
321 317
 						if( $billing_option == $address_type ) {
322 318
 							$billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
323
-						}
324
-						else {
319
+						} else {
325 320
 							$shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
326 321
 						}
327 322
 					}
@@ -351,8 +346,9 @@  discard block
 block discarded – undo
351 346
 		public function wps_delete_order() {
352 347
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
353 348
 
354
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) )
355
-				wp_die();
349
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) ) {
350
+							wp_die();
351
+			}
356 352
 
357 353
 			$status = false;
358 354
 			$output = '';
@@ -381,8 +377,9 @@  discard block
 block discarded – undo
381 377
 		public function wps_checkout_quotation() {
382 378
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
383 379
 
384
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
385
-				wp_die();
380
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) ) {
381
+							wp_die();
382
+			}
386 383
 
387 384
 			$status = true;
388 385
 			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
@@ -405,8 +402,9 @@  discard block
 block discarded – undo
405 402
 		public function wps_checkout_quotation_no_login() {
406 403
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
407 404
 
408
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
409
-				wp_die();
405
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) ) {
406
+							wp_die();
407
+			}
410 408
 
411 409
 			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
412 410
 			wp_redirect( home_url('/wp-login.php') . '?redirect_to=' . urlencode( admin_url() . 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $order_id . '&is_link=link' ) );
Please login to merge, or discard this patch.
includes/modules/wps_product/controller/wps_product_ajax_ctr.01.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * of the number of corrected product and the template of the method : ajax_checking_products_values if inconsistent product
31 31
 	 * already present.
32 32
 	 *
33
-	 * @param array $_POST['product_price'] List of the new price for the product like array( $id_product => $new_price )
34 33
 	 * @return JSON Response
35 34
 	 */
36 35
 	public function ajax_save_product_price() {
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 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
 class wps_product_ajax_ctr_01 {
3 3
 	public function __construct() {
4
-		add_action( 'wp_ajax_checking_products_values', array( &$this, 'ajax_render_inconsistent_product_price' ) );
5
-		add_action( 'wp_ajax_save_products_prices', array( &$this, 'ajax_save_product_price' ) );
4
+		add_action('wp_ajax_checking_products_values', array(&$this, 'ajax_render_inconsistent_product_price'));
5
+		add_action('wp_ajax_save_products_prices', array(&$this, 'ajax_save_product_price'));
6 6
 	}
7 7
 
8 8
 	/**
@@ -12,16 +12,16 @@  discard block
 block discarded – undo
12 12
 	 * list. Then display the template product_check_data
13 13
 	 */
14 14
 	public function ajax_render_inconsistent_product_price() {
15
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
15
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
16 16
 
17
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) )
17
+		if (!wp_verify_nonce($_wpnonce, 'ajax_render_inconsistent_product_price'))
18 18
 			wp_die();
19 19
 
20 20
 		$list_product = wps_product_ctr::get_inconsistent_product();
21 21
 
22 22
 		$inconsistent_product_number = count($list_product);
23 23
 
24
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data") );
24
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data"));
25 25
 		wp_die();
26 26
 	}
27 27
 
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
 	 * @return JSON Response
40 40
 	 */
41 41
 	public function ajax_save_product_price() {
42
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
42
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
43 43
 
44
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) )
44
+		if (!wp_verify_nonce($_wpnonce, 'ajax_save_product_price'))
45 45
 			wp_die();
46 46
 
47
-		header( 'Content-Type: application/json' );
47
+		header('Content-Type: application/json');
48 48
 		$response = array();
49 49
 
50
-		$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
50
+		$price_piloting_option = get_option('wpshop_shop_price_piloting');
51 51
 
52
-		$inconsistent_product_number 	= !empty( $_POST['product_price'] ) ? (int) count( $_POST['product_price'] ) : 0;
53
-		$consistent_product_number 		= 0;
52
+		$inconsistent_product_number = !empty($_POST['product_price']) ? (int)count($_POST['product_price']) : 0;
53
+		$consistent_product_number = 0;
54 54
 
55
-		$entity_type_id	= wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
56
-		$language 		= WPSHOP_CURRENT_LOCALE;
57
-		$icl_language = !empty( $_REQUEST['icl_post_language'] ) ? sanitize_text_field( $_REQUEST['icl_post_language'] ) : '';
55
+		$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
56
+		$language = WPSHOP_CURRENT_LOCALE;
57
+		$icl_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
58 58
 
59
-		if ( !empty($icl_language) ) {
60
-			$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_language );
59
+		if (!empty($icl_language)) {
60
+			$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_language);
61 61
 			$language = $wpdb->get_var($query);
62 62
 		}
63 63
 
64
-		$product_price = !empty( $_POST['product_price'] ) ? (array) $_POST['product_price'] : array();
64
+		$product_price = !empty($_POST['product_price']) ? (array)$_POST['product_price'] : array();
65 65
 
66
-		if( !empty( $product_price ) ) {
67
-			foreach( $product_price as $product_id => $price ) {
66
+		if (!empty($product_price)) {
67
+			foreach ($product_price as $product_id => $price) {
68 68
 				try {
69
-					if( $price_piloting_option == 'TTC' )
70
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' );
69
+					if ($price_piloting_option == 'TTC')
70
+						wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => sanitize_text_field($price))), $entity_type_id, (int)$product_id, $language, 'wpshop_products');
71 71
 					else
72
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' );
72
+						wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => sanitize_text_field($price))), $entity_type_id, (int)$product_id, $language, 'wpshop_product');
73 73
 
74
-					wpshop_products::calculate_price( $product_id );
74
+					wpshop_products::calculate_price($product_id);
75 75
 					$consistent_product_number++;
76 76
 
77 77
 				} catch (Exception $e) {
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 			}
80 80
 		}
81 81
 
82
-		$response['template_number'] = __( sprintf( 'Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number ), 'wps-product' );
82
+		$response['template_number'] = __(sprintf('Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number), 'wps-product');
83 83
 
84 84
 		$list_product = wps_product_ctr::get_inconsistent_product();
85 85
 		ob_start();
86
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data") );
86
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data"));
87 87
 		$response['template'] = ob_get_clean();
88 88
 
89
-		wp_die( json_encode( $response ) );
89
+		wp_die(json_encode($response));
90 90
 	}
91 91
 }
92 92
 
Please login to merge, or discard this patch.
Braces   +14 added lines, -9 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_ajax_ctr_01 {
3 5
 	public function __construct() {
4 6
 		add_action( 'wp_ajax_checking_products_values', array( &$this, 'ajax_render_inconsistent_product_price' ) );
@@ -14,8 +16,9 @@  discard block
 block discarded – undo
14 16
 	public function ajax_render_inconsistent_product_price() {
15 17
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
16 18
 
17
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) )
18
-			wp_die();
19
+		if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) ) {
20
+					wp_die();
21
+		}
19 22
 
20 23
 		$list_product = wps_product_ctr::get_inconsistent_product();
21 24
 
@@ -41,8 +44,9 @@  discard block
 block discarded – undo
41 44
 	public function ajax_save_product_price() {
42 45
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
43 46
 
44
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) )
45
-			wp_die();
47
+		if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) ) {
48
+					wp_die();
49
+		}
46 50
 
47 51
 		header( 'Content-Type: application/json' );
48 52
 		$response = array();
@@ -66,10 +70,11 @@  discard block
 block discarded – undo
66 70
 		if( !empty( $product_price ) ) {
67 71
 			foreach( $product_price as $product_id => $price ) {
68 72
 				try {
69
-					if( $price_piloting_option == 'TTC' )
70
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' );
71
-					else
72
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' );
73
+					if( $price_piloting_option == 'TTC' ) {
74
+											wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' );
75
+					} else {
76
+											wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' );
77
+					}
73 78
 
74 79
 					wpshop_products::calculate_price( $product_id );
75 80
 					$consistent_product_number++;
Please login to merge, or discard this patch.
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   +89 added lines, -89 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,16 +8,16 @@  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
 
23 23
 	/**
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
 		$module_folder = WPS_PRODUCT_PATH . '/modules/';
29 29
 
30 30
 		/**	Check if the defined directory exists for reading and including the different modules	*/
31
-		if( is_dir( $module_folder ) ) {
32
-			$parent_folder_content = scandir( $module_folder );
33
-			foreach ( $parent_folder_content as $folder ) {
34
-				if ( $folder && substr( $folder, 0, 1) != '.' && is_dir( $folder ) ) {
35
-					$child_folder_content = scandir( $module_folder . $folder );
36
-					if ( file_exists( $module_folder . $folder . '/' . $folder . '.php') ) {
37
-						$f =  $module_folder . $folder . '/' . $folder . '.php';
38
-						include( $f );
31
+		if (is_dir($module_folder)) {
32
+			$parent_folder_content = scandir($module_folder);
33
+			foreach ($parent_folder_content as $folder) {
34
+				if ($folder && substr($folder, 0, 1) != '.' && is_dir($folder)) {
35
+					$child_folder_content = scandir($module_folder . $folder);
36
+					if (file_exists($module_folder . $folder . '/' . $folder . '.php')) {
37
+						$f = $module_folder . $folder . '/' . $folder . '.php';
38
+						include($f);
39 39
 					}
40 40
 				}
41 41
 			}
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	}
44 44
 
45 45
 	public function callback_admin_enqueue_scripts() {
46
-		wp_enqueue_script( 'wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array( "jquery", "jquery-form" ), WPS_PRODUCT_VERSION );
46
+		wp_enqueue_script('wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array("jquery", "jquery-form"), WPS_PRODUCT_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	 * @param array $args
52 52
 	 * @return string
53 53
 	 */
54
-	function display_product_caracteristics_tab( $args ) {
54
+	function display_product_caracteristics_tab($args) {
55 55
 		$output = '';
56
-		if( !empty($args) && !empty($args['pid']) ) {
56
+		if (!empty($args) && !empty($args['pid'])) {
57 57
 			$wps_product_mdl = new wps_product_mdl();
58
-			$product_atts_def = $wps_product_mdl->get_product_atts_def( $args['pid'] );
59
-			if( !empty($product_atts_def) ) {
58
+			$product_atts_def = $wps_product_mdl->get_product_atts_def($args['pid']);
59
+			if (!empty($product_atts_def)) {
60 60
 				ob_start();
61
-				require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab") );
61
+				require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab"));
62 62
 				$output = ob_get_contents();
63 63
 				ob_end_clean();
64 64
 			}
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	 * @param array $args
72 72
 	 * @return string
73 73
 	 */
74
-	function display_discount_chip( $args ) {
74
+	function display_discount_chip($args) {
75 75
 		$output = '';
76
-		if( !empty($args) && !empty($args['pid']) ) {
76
+		if (!empty($args) && !empty($args['pid'])) {
77 77
 			$wps_price = new wpshop_prices();
78
-			$discount_data = wpshop_prices::check_discount_for_product( $args['pid'] );
79
-			if( !empty($discount_data) ) {
78
+			$discount_data = wpshop_prices::check_discount_for_product($args['pid']);
79
+			if (!empty($discount_data)) {
80 80
 				ob_start();
81
-				require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip") );
81
+				require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip"));
82 82
 				$output = ob_get_contents();
83 83
 				ob_end_clean();
84 84
 			}
@@ -96,36 +96,36 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	function check_stock($product_id, $cart_asked_quantity, $combined_variation_id = '') {
98 98
 		// Checking if combined variation ID exist and it is a simple option
99
-		if( !empty($combined_variation_id) && ( strpos($combined_variation_id, '__') !== false ) ) {
100
-			$var_id = explode( '__', $combined_variation_id);
99
+		if (!empty($combined_variation_id) && (strpos($combined_variation_id, '__') !== false)) {
100
+			$var_id = explode('__', $combined_variation_id);
101 101
 			$combined_variation_id = $var_id[1];
102 102
 		}
103 103
 
104 104
 
105
-		if ( !empty($combined_variation_id) ) {
105
+		if (!empty($combined_variation_id)) {
106 106
 
107
-			$variation_metadata = get_post_meta( $combined_variation_id, '_wpshop_product_metadata', true );
108
-			if ( isset($variation_metadata['product_stock']) ) {
107
+			$variation_metadata = get_post_meta($combined_variation_id, '_wpshop_product_metadata', true);
108
+			if (isset($variation_metadata['product_stock'])) {
109 109
 				$product_id = $combined_variation_id;
110 110
 			}
111 111
 		}
112 112
 		$product_data = wpshop_products::get_product_data($product_id, false, '"publish"');
113 113
 
114
-		if(!empty($product_data)) {
114
+		if (!empty($product_data)) {
115 115
 			$manage_stock = !empty($product_data['manage_stock']) ? $product_data['manage_stock'] : '';
116 116
 
117
-			$product_post_type = get_post_type( $product_id );
117
+			$product_post_type = get_post_type($product_id);
118 118
 
119
-			if ( $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
120
-				$parent_def = wpshop_products::get_parent_variation( $product_id );
121
-				if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
119
+			if ($product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
120
+				$parent_def = wpshop_products::get_parent_variation($product_id);
121
+				if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
122 122
 					$parent_post = $parent_def['parent_post'];
123 123
 					$parent_product_data = wpshop_products::get_product_data($parent_post->ID);
124
-					$manage_stock = empty( $manage_stock ) ? $parent_product_data['manage_stock'] : $manage_stock;
124
+					$manage_stock = empty($manage_stock) ? $parent_product_data['manage_stock'] : $manage_stock;
125 125
 				}
126 126
 			}
127
-			$manage_stock_is_activated = (!empty($manage_stock) && ( strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')) )) ? true : false;
128
-			$the_qty_is_in_stock = ( !empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity ) ? true : false ;
127
+			$manage_stock_is_activated = (!empty($manage_stock) && (strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')))) ? true : false;
128
+			$the_qty_is_in_stock = (!empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity) ? true : false;
129 129
 
130 130
 			if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) {
131 131
 				return true;
@@ -138,18 +138,18 @@  discard block
 block discarded – undo
138 138
 	}
139 139
 
140 140
 	public static function get_inconsistent_product() {
141
-		$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
141
+		$price_piloting_option = get_option('wpshop_shop_price_piloting');
142 142
 
143
-		$entity_id 		= wpshop_entities::get_entity_identifier_from_code( 'wpshop_product' );
143
+		$entity_id = wpshop_entities::get_entity_identifier_from_code('wpshop_product');
144 144
 
145
-		$attribute_def	= wpshop_attributes::getElement( ( $price_piloting_option == 'TTC' ) ? 'product_price' : 'price_ht', "'valid'", 'code' );
146
-		$attribute_id	= $attribute_def->id;
145
+		$attribute_def = wpshop_attributes::getElement(($price_piloting_option == 'TTC') ? 'product_price' : 'price_ht', "'valid'", 'code');
146
+		$attribute_id = $attribute_def->id;
147 147
 
148 148
 		global $wpdb;
149 149
 
150 150
 		$wpdb->query('SET SESSION group_concat_max_len = 10000');
151 151
 
152
-		$query			= "
152
+		$query = "
153 153
 		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
154 154
 			FROM 		$wpdb->posts as post
155 155
 		JOIN		$wpdb->postmeta as postmeta
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
 			AND			postmeta.meta_key IN( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata' )
163 163
 		GROUP BY	post.ID";
164 164
 
165
-		$list_product	= $wpdb->get_results( $wpdb->prepare( $query, array( $entity_id, $attribute_id ) ) );
165
+		$list_product = $wpdb->get_results($wpdb->prepare($query, array($entity_id, $attribute_id)));
166 166
 
167
-		if( !empty( $list_product ) ) {
168
-			foreach( $list_product as $key_product => &$product ) {
167
+		if (!empty($list_product)) {
168
+			foreach ($list_product as $key_product => &$product) {
169 169
 				$product->price = explode('&&,', $product->price);
170
-				if(!empty($product->price) && is_array($product->price)) {
170
+				if (!empty($product->price) && is_array($product->price)) {
171 171
 					$array_price = array();
172
-					foreach($product->price as &$price) {
173
-						if(strpos( $price, '&&' ))
172
+					foreach ($product->price as &$price) {
173
+						if (strpos($price, '&&'))
174 174
 							$price = substr($price, 0, -2);
175 175
 
176 176
 						$tmp_price = explode('&sep&', $price);
@@ -178,35 +178,35 @@  discard block
 block discarded – undo
178 178
 						$price = maybe_unserialize($tmp_price[1]);
179 179
 
180 180
 						/** _wpshop_product_metadata */
181
-						if( $key == '_wpshop_product_metadata' ) {
182
-							$array_price[$key] =  ( $price_piloting_option == 'TTC' ) ? $price['product_price'] : $price['price_ht'];
181
+						if ($key == '_wpshop_product_metadata') {
182
+							$array_price[$key] = ($price_piloting_option == 'TTC') ? $price['product_price'] : $price['price_ht'];
183 183
 						}
184 184
 
185 185
 						/** _wps_price_infos */
186
-						if( $key == '_wps_price_infos' ) {
187
-							$array_price[$key] = !empty( $price['PRODUCT_PRICE'] ) ? $price['PRODUCT_PRICE'] : '-';
186
+						if ($key == '_wps_price_infos') {
187
+							$array_price[$key] = !empty($price['PRODUCT_PRICE']) ? $price['PRODUCT_PRICE'] : '-';
188 188
 						}
189 189
 
190
-						if( $key == '_product_price' ) {
191
-							$array_price[$key] = ( $price_piloting_option == 'TTC' ) ? $price : '-';
190
+						if ($key == '_product_price') {
191
+							$array_price[$key] = ($price_piloting_option == 'TTC') ? $price : '-';
192 192
 						}
193 193
 
194
-						if ( $key == '_wpshop_displayed_price' ) {
194
+						if ($key == '_wpshop_displayed_price') {
195 195
 							$array_price[$key] = $price;
196 196
 						}
197 197
 						unset($price);
198 198
 					}
199 199
 
200
-					$array_meta_list = array( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata', );
200
+					$array_meta_list = array('_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata',);
201 201
 
202
-					foreach( $array_meta_list as $meta_list ) {
203
-						if( !array_key_exists( $meta_list, $array_price ) ) {
202
+					foreach ($array_meta_list as $meta_list) {
203
+						if (!array_key_exists($meta_list, $array_price)) {
204 204
 							$array_price[$meta_list] = 0;
205 205
 						}
206 206
 					}
207 207
 
208 208
 					$product->price = $array_price;
209
-					if( $product->price_attribute === $product->price['_wpshop_product_metadata'] ) {
209
+					if ($product->price_attribute === $product->price['_wpshop_product_metadata']) {
210 210
 						unset($list_product[$key_product]);
211 211
 					}
212 212
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 	 * @param int $pid L'id du produit
225 225
 	 * @return WP_Post
226 226
 	 */
227
-	public function get_thumbnail ( $pid ) {
228
-		if( empty( $pid ) )
227
+	public function get_thumbnail($pid) {
228
+		if (empty($pid))
229 229
 			return null;
230 230
 
231
-		$thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true );
231
+		$thumbnail_id = get_post_meta($pid, '_thumbnail_id', true);
232 232
 
233
-		if( empty( $thumbnail_id ) )
233
+		if (empty($thumbnail_id))
234 234
 			return null;
235 235
 
236 236
 		return $thumbnail_id;
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
 	 * @param array $array_data The array data [integer][barcode] = 0111100001
244 244
 	 */
245 245
 	public function update_attributes_for_product($product_id, $array_data) {
246
-		if(!empty($array_data)) {
247
-			foreach($array_data as $type => $array) {
248
-				foreach($array as $name_attribute => $value_attribute) {
246
+		if (!empty($array_data)) {
247
+			foreach ($array_data as $type => $array) {
248
+				foreach ($array as $name_attribute => $value_attribute) {
249 249
 					$this->update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute);
250 250
 				}
251 251
 			}
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 		$attribute_id = $wpdb->get_var($wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s"', array($name_attribute)));
270 270
 
271 271
 		/** On vérifie s'il existe si c'est le cas, on update sinon on insert */
272
-		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) {
272
+		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) {
273 273
 			$wpdb->query(
274 274
 				$wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' SET value="%s" WHERE entity_id=%d AND attribute_id=%d',
275 275
 					array($value_attribute, $product_id, $attribute_id)
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
 	 * @param array $args [ 'id' ] L'id du produit
296 296
 	 * @return string
297 297
 	 */
298
-	public function wpshop_product_title( $args ) {
299
-		$output = __( 'No product has been found.', 'wpshop' );
298
+	public function wpshop_product_title($args) {
299
+		$output = __('No product has been found.', 'wpshop');
300 300
 
301
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
301
+		if (!empty($args) && !empty($args['pid'])) {
302 302
 			global $wpdb;
303 303
 			$query = "SELECT post_title FROM {$wpdb->posts} WHERE ID = %d";
304
-			$output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) );
304
+			$output = $wpdb->get_var($wpdb->prepare($query, $args['pid']));
305 305
 		}
306 306
 
307 307
 		return $output;
@@ -312,16 +312,16 @@  discard block
 block discarded – undo
312 312
 	 * @param array $args [ 'id' ] L'id du produit
313 313
 	 * @return string
314 314
 	 */
315
-	public function wpshop_product_content( $args ) {
316
-		$output = __( 'No product has been found.', 'wpshop' );
315
+	public function wpshop_product_content($args) {
316
+		$output = __('No product has been found.', 'wpshop');
317 317
 
318
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
318
+		if (!empty($args) && !empty($args['pid'])) {
319 319
 			global $wpdb;
320 320
 			$query = "SELECT post_content FROM {$wpdb->posts} WHERE ID = %d";
321
-			$output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) );
321
+			$output = $wpdb->get_var($wpdb->prepare($query, $args['pid']));
322 322
 		}
323 323
 
324
-		return nl2br( $output );
324
+		return nl2br($output);
325 325
 	}
326 326
 
327 327
 	/**
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
 	 * 						[ size ] La taille de l'image. Peut être défini comme : small, medium ou full
332 332
 	 * @return string
333 333
 	 */
334
-	public function wpshop_product_thumbnail( $args ) {
334
+	public function wpshop_product_thumbnail($args) {
335 335
 		$url_thumbnail = WPSHOP_DEFAULT_PRODUCT_PICTURE;
336 336
 		$size = '20%';
337 337
 
338
-		if ( !empty( $args ) && !empty( $args['size'] ) ) {
339
-			switch ( $args['size'] ) {
338
+		if (!empty($args) && !empty($args['size'])) {
339
+			switch ($args['size']) {
340 340
 				case 'small':
341 341
 					$size = '20%';
342 342
 					break;
@@ -351,20 +351,20 @@  discard block
 block discarded – undo
351 351
 			}
352 352
 		}
353 353
 
354
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
355
-			$thumbnail_id = $this->get_thumbnail( $args['pid'] );
354
+		if (!empty($args) && !empty($args['pid'])) {
355
+			$thumbnail_id = $this->get_thumbnail($args['pid']);
356 356
 
357
-			if( !empty( $thumbnail_id ) ) {
358
-				$attachment = get_post( $thumbnail_id );
357
+			if (!empty($thumbnail_id)) {
358
+				$attachment = get_post($thumbnail_id);
359 359
 
360
-				if( !empty( $attachment ) && !empty( $attachment->guid ) ) {
360
+				if (!empty($attachment) && !empty($attachment->guid)) {
361 361
 					$url_thumbnail = $attachment->guid;
362 362
 				}
363 363
 			}
364 364
 		}
365 365
 
366 366
 		ob_start();
367
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail" ) );
367
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail"));
368 368
 		$output = ob_get_clean();
369 369
 
370 370
 		return $output;
Please login to merge, or discard this patch.
Braces   +14 added lines, -11 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
 	/**
@@ -129,8 +131,7 @@  discard block
 block discarded – undo
129 131
 
130 132
 			if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) {
131 133
 				return true;
132
-			}
133
-			else {
134
+			} else {
134 135
 				return __('You cannot add that amount to the cart since there is not enough stock.', 'wpshop');
135 136
 			}
136 137
 		}
@@ -170,8 +171,9 @@  discard block
 block discarded – undo
170 171
 				if(!empty($product->price) && is_array($product->price)) {
171 172
 					$array_price = array();
172 173
 					foreach($product->price as &$price) {
173
-						if(strpos( $price, '&&' ))
174
-							$price = substr($price, 0, -2);
174
+						if(strpos( $price, '&&' )) {
175
+													$price = substr($price, 0, -2);
176
+						}
175 177
 
176 178
 						$tmp_price = explode('&sep&', $price);
177 179
 						$key = $tmp_price[0];
@@ -225,13 +227,15 @@  discard block
 block discarded – undo
225 227
 	 * @return WP_Post
226 228
 	 */
227 229
 	public function get_thumbnail ( $pid ) {
228
-		if( empty( $pid ) )
229
-			return null;
230
+		if( empty( $pid ) ) {
231
+					return null;
232
+		}
230 233
 
231 234
 		$thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true );
232 235
 
233
-		if( empty( $thumbnail_id ) )
234
-			return null;
236
+		if( empty( $thumbnail_id ) ) {
237
+					return null;
238
+		}
235 239
 
236 240
 		return $thumbnail_id;
237 241
 	}
@@ -275,8 +279,7 @@  discard block
 block discarded – undo
275 279
 					array($value_attribute, $product_id, $attribute_id)
276 280
 				)
277 281
 			);
278
-		}
279
-		else {
282
+		} else {
280 283
 			/** Insert avec toutes les informations requise */
281 284
 			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE . '_value_' . $type, array(
282 285
 					'attribute_id' 			=> $attribute_id,
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
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	}
353 353
 
354 354
 	/**
355
-	* Delete product list
356
-	**/
355
+	 * Delete product list
356
+	 **/
357 357
 	function wps_mass_delete_file() {
358 358
 		$status = false;
359 359
 		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	}
367 367
 
368 368
 	/**
369
-	* Update product files list
370
-	*/
369
+	 * Update product files list
370
+	 */
371 371
 	function wps_mass_edit_update_files_list() {
372 372
 		$status = false; $response = '';
373 373
 		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 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
  *
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	function __construct() {
21 21
 		// Add submenu
22
-		add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 );
22
+		add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350);
23 23
 
24 24
 		// Declare Styles and JS Files
25
-		add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts') );
26
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_css' ) );
27
-		add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) );
25
+		add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts'));
26
+		add_action('admin_enqueue_scripts', array($this, 'admin_css'));
27
+		add_action('admin_print_scripts', array($this, 'admin_print_scripts'));
28 28
 
29 29
 		// Trigger ajax action
30
-		add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') );
31
-		add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') );
32
-		add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) );
33
-		add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) );
34
-		add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) );
30
+		add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page'));
31
+		add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface'));
32
+		add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation'));
33
+		add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file'));
34
+		add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list'));
35 35
 		// add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) );
36 36
 	}
37 37
 
38 38
 	function register_mass_products_edit_submenu() {
39
-		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'));
39
+		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'));
40 40
 	}
41 41
 
42 42
 	/**
43 43
 	 * Define the aministration pat styles
44 44
 	 */
45 45
 	function admin_css() {
46
-		wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL.'/assets/css/backend.css', '', WPS_PDCT_MASS_VERSION);
46
+		wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css', '', WPS_PDCT_MASS_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
50 50
 	 * Add javascript to administration
51 51
 	 */
52 52
 	function add_admin_scripts() {
53
-		wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL.'/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true);
53
+		wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true);
54 54
 		wp_enqueue_media();
55 55
 	}
56 56
 
57 57
 	function admin_print_scripts() {
58 58
 		$output = '<script type="text/javascript">';
59
-		$output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";';
60
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";';
61
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";';
62
-		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";';
59
+		$output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";';
60
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";';
61
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";';
62
+		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";';
63 63
 		$output .= '</script>';
64 64
 		echo $output;
65 65
 	}
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return array
73 73
 	 */
74
-	function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) {
75
-
76
-		if ( !empty( $attribute_list ) ) {
77
-			foreach( $attribute_list as $attributes_group ) {
78
-				foreach( $attributes_group as $attributes_sections ) {
79
-					if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) {
80
-						foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) {
81
-							if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) {
82
-								$quick_add_form_attributes[ $attribute_id ] = $att_def;
74
+	function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) {
75
+
76
+		if (!empty($attribute_list)) {
77
+			foreach ($attribute_list as $attributes_group) {
78
+				foreach ($attributes_group as $attributes_sections) {
79
+					if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) {
80
+						foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) {
81
+							if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') {
82
+								$quick_add_form_attributes[$attribute_id] = $att_def;
83 83
 							}
84 84
 						}
85 85
 					}
@@ -96,29 +96,29 @@  discard block
 block discarded – undo
96 96
 	 * @param integer $page
97 97
 	 * @return string
98 98
 	 */
99
-	function display_products_list( $default = 1, $page = 0  ) {
99
+	function display_products_list($default = 1, $page = 0) {
100 100
 		global $wpdb;
101 101
 		// Product entity
102
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
102
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
103 103
 
104 104
 		$user_id = get_current_user_id();
105 105
 		// Check product limit
106
-		$product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
107
-		$product_limit = ( !empty($product_limit) ) ? $product_limit : 20;
106
+		$product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
107
+		$product_limit = (!empty($product_limit)) ? $product_limit : 20;
108 108
 
109 109
 		// Get products for the current page
110 110
 		$wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl();
111
-		$products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit );
111
+		$products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit);
112 112
 
113 113
 		// Construct Table Head Data
114 114
 		$quick_add_form_attributes = array();
115 115
 		$get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form();
116
-		foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) {
116
+		foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) {
117 117
 			$quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute;
118 118
 		}
119 119
 
120 120
 		ob_start();
121
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) );
121
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list"));
122 122
 		$output = ob_get_contents();
123 123
 		ob_end_clean();
124 124
 		return $output;
@@ -134,25 +134,25 @@  discard block
 block discarded – undo
134 134
 		$products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets();
135 135
 
136 136
 		$default = '';
137
-		if( !empty($products_attributes_groups) ) {
138
-			foreach( $products_attributes_groups as $key => $products_attributes_group ) {
139
-				if( $products_attributes_group->slug == 'free_product' ) {
140
-					unset( $products_attributes_groups[$key] );
137
+		if (!empty($products_attributes_groups)) {
138
+			foreach ($products_attributes_groups as $key => $products_attributes_group) {
139
+				if ($products_attributes_group->slug == 'free_product') {
140
+					unset($products_attributes_groups[$key]);
141 141
 				}
142
-				if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) {
142
+				if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') {
143 143
 					$default = $products_attributes_group->id;
144 144
 				}
145 145
 			}
146 146
 		}
147 147
 		// Check page
148
-		$page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0;
148
+		$page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0;
149 149
 		// Display product tab
150
-		$product_list_interface = $this->display_products_list( $default, $page );
150
+		$product_list_interface = $this->display_products_list($default, $page);
151 151
 
152 152
 		// Get pagination
153
-		$pagination = $this->get_products_pagination( $page, $default );
153
+		$pagination = $this->get_products_pagination($page, $default);
154 154
 
155
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) );
155
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface"));
156 156
 	}
157 157
 
158 158
 	/**
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return string
162 162
 	 */
163
-	function get_products_pagination( $current_page, $attribute_set_id = 1 ) {
163
+	function get_products_pagination($current_page, $attribute_set_id = 1) {
164 164
 		global $wpdb;
165 165
 		$user_id = get_current_user_id();
166 166
 		$output = '';
167 167
 		/**	Define the element number per page. If the user change the default value, take this value	*/
168
-		$one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
169
-		$one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20;
168
+		$one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
169
+		$one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20;
170 170
 
171 171
 		/**	Count the number of product existing in the shop	*/
172 172
 		$query = $wpdb->prepare(
@@ -178,37 +178,37 @@  discard block
 block discarded – undo
178 178
 				AND meta_value = %s
179 179
 				AND post_status IN ( 'publish', 'draft' )",
180 180
 				WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id);
181
-		$products = $wpdb->get_var( $query );
181
+		$products = $wpdb->get_var($query);
182 182
 
183
-			if( !empty($products) ) {
183
+			if (!empty($products)) {
184 184
 			$args = array(
185 185
 			'base' => '%_%',
186
-			'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ),
187
-					'current' => ( $current_page + 1 ),
188
-					'total' => ceil( $products / $one_page_limit ),
186
+			'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'),
187
+					'current' => ($current_page + 1),
188
+					'total' => ceil($products / $one_page_limit),
189 189
 						'type' => 'array',
190 190
 						'prev_next' => false,
191 191
 						'show_all' => true,
192 192
 			);
193
-			$paginate = paginate_links( $args );
193
+			$paginate = paginate_links($args);
194 194
 
195 195
 				$wps_product_ctr = new wps_product_ctr();
196 196
 				ob_start();
197
-				require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) );
197
+				require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination"));
198 198
 				$output = ob_get_contents();
199 199
 			ob_end_clean();
200 200
 			}
201 201
 			return $output;
202 202
 			}
203 203
 
204
-	function wps_product_attached_files( $product_id ) {
204
+	function wps_product_attached_files($product_id) {
205 205
 		global $wpdb;
206 206
 		$output = '';
207
-		$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%' );
208
-		$files = $wpdb->get_results( $query );
209
-		if( !empty($files) ) {
207
+		$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%');
208
+		$files = $wpdb->get_results($query);
209
+		if (!empty($files)) {
210 210
 			ob_start();
211
-			require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) );
211
+			require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list"));
212 212
 			$output = ob_get_contents();
213 213
 			ob_end_clean();
214 214
 		}
@@ -220,23 +220,23 @@  discard block
 block discarded – undo
220 220
 	 * AJAX - Change page action on mass edit product interface
221 221
 	 */
222 222
 	function wps_mass_edit_change_page() {
223
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
223
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
224 224
 
225
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) )
225
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page'))
226 226
 			wp_die();
227 227
 
228 228
 		$status = false; $response = '';
229
-		$page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0;
230
-		$attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1;
231
-		if( !empty($attribute_set_id) ) {
229
+		$page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0;
230
+		$attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1;
231
+		if (!empty($attribute_set_id)) {
232 232
 			// Get tab
233
-			$response = $this->display_products_list( $attribute_set_id, $page );
234
-			$pagination = $this->get_products_pagination( $page, $attribute_set_id );
235
-			if( !empty($response) ) {
233
+			$response = $this->display_products_list($attribute_set_id, $page);
234
+			$pagination = $this->get_products_pagination($page, $attribute_set_id);
235
+			if (!empty($response)) {
236 236
 				$status = true;
237 237
 			}
238 238
 		}
239
-		echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) );
239
+		echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination));
240 240
 		wp_die();
241 241
 	}
242 242
 
@@ -244,30 +244,30 @@  discard block
 block discarded – undo
244 244
 	 * AJAX - Create a draft product and display the line allowing to edit informations for this product
245 245
 	 */
246 246
 	function wps_mass_interface_new_product_creation() {
247
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
247
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
248 248
 
249
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) )
249
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation'))
250 250
 			wp_die();
251 251
 
252 252
 		global $wpdb;
253 253
 		$output = $pagination = '';
254 254
 		$status = false;
255 255
 
256
-		$new_product_id = wp_insert_post( array(
256
+		$new_product_id = wp_insert_post(array(
257 257
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
258 258
 				'post_status' => 'publish',
259
-				'post_title' => __( 'New product', 'wpshop' ),
260
-		) );
259
+				'post_title' => __('New product', 'wpshop'),
260
+		));
261 261
 
262
-		if( !is_object($new_product_id) ) {
262
+		if (!is_object($new_product_id)) {
263 263
 			$status = true;
264 264
 		}
265
-		if ( !empty( $new_product_id ) ) {
266
-			$product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1;
267
-			update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id );
265
+		if (!empty($new_product_id)) {
266
+			$product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1;
267
+			update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id);
268 268
 		}
269 269
 
270
-		echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) );
270
+		echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination));
271 271
 		wp_die();
272 272
 	}
273 273
 
@@ -275,59 +275,59 @@  discard block
 block discarded – undo
275 275
 	 * AJAX - Save datas
276 276
 	 */
277 277
 	function wps_save_product_quick_interface() {
278
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
278
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
279 279
 
280
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) )
280
+		if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface'))
281 281
 			wp_die();
282 282
 
283 283
 		global $wpdb;
284 284
 		$response = ''; $status = false;
285 285
 		$count_products_to_update = 0; $total_updated_products = 0;
286 286
 
287
-		$wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array();
288
-		$wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array();
289
-		$wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array();
287
+		$wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array();
288
+		$wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array();
289
+		$wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array();
290 290
 
291
-		if( !empty($wps_product_quick_save) ) {
292
-			$count_products_to_update = count( $wps_product_quick_save );
293
-			foreach( $wps_product_quick_save as $product_to_save ) {
291
+		if (!empty($wps_product_quick_save)) {
292
+			$count_products_to_update = count($wps_product_quick_save);
293
+			foreach ($wps_product_quick_save as $product_to_save) {
294 294
 				$data_to_save = array();
295 295
 				// Update post
296
-				$updated_post = wp_update_post( array( 'ID' => $product_to_save,
297
-						'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ),
298
-						'post_content' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_content'] ),
296
+				$updated_post = wp_update_post(array('ID' => $product_to_save,
297
+						'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']),
298
+						'post_content' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_content']),
299 299
 						)
300 300
 				);
301 301
 				// Update attributes
302
-				if( !empty($updated_post) ) {
302
+				if (!empty($updated_post)) {
303 303
 					// Update Featured picture
304
-					if( !empty($wps_mass_interface[$product_to_save]['picture']) ) {
305
-						$thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true );
306
-						if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
307
-							wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) );
308
-							update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] );
304
+					if (!empty($wps_mass_interface[$product_to_save]['picture'])) {
305
+						$thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true);
306
+						if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
307
+							wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post));
308
+							update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']);
309 309
 						}
310
-						elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
311
-							delete_post_meta( $updated_post, '_thumbnail_id' );
310
+						elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
311
+							delete_post_meta($updated_post, '_thumbnail_id');
312 312
 						}
313 313
 					}
314 314
 
315 315
 					// Update files datas
316
-					if( !empty($wps_mass_interface[$product_to_save]['files']) ) {
317
-						$files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) );
318
-						if( !empty($files_data) && is_array($files_data) ) {
319
-							foreach( $files_data as $file_id ) {
320
-								if( !empty($file_id) ) {
321
-									wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) );
316
+					if (!empty($wps_mass_interface[$product_to_save]['files'])) {
317
+						$files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files']));
318
+						if (!empty($files_data) && is_array($files_data)) {
319
+							foreach ($files_data as $file_id) {
320
+								if (!empty($file_id)) {
321
+									wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post));
322 322
 								}
323 323
 							}
324 324
 						}
325 325
 					}
326 326
 
327
-					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save );
328
-					$data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array();
327
+					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save);
328
+					$data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array();
329 329
 
330
-					if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
330
+					if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
331 331
 						// Get current barcode
332 332
 						$wps_product_mdl = new wps_product_mdl();
333 333
 						$attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id;
@@ -338,34 +338,34 @@  discard block
 block discarded – undo
338 338
 					$data_to_save['user_ID'] = get_current_user_id();
339 339
 					$data_to_save['action'] = 'editpost';
340 340
 
341
-					if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) {
342
-						wp_trash_post( $product_to_save );
341
+					if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") {
342
+						wp_trash_post($product_to_save);
343 343
 					}
344 344
 
345
-					if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) {
345
+					if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) {
346 346
 						$product_class = new wpshop_products();
347
-						$product_class->save_product_custom_informations( $product_to_save, $data_to_save );
347
+						$product_class->save_product_custom_informations($product_to_save, $data_to_save);
348 348
 						$total_updated_products++;
349 349
 					}
350 350
 				}
351 351
 			}
352 352
 		}
353 353
 		// Checking status
354
-		$status = ( $total_updated_products == $count_products_to_update ) ? true : false;
354
+		$status = ($total_updated_products == $count_products_to_update) ? true : false;
355 355
 
356
-		if( $status ) {
357
-			$response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products );
356
+		if ($status) {
357
+			$response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products);
358 358
 		}
359 359
 		else {
360
-			if( !empty($total_updated_products) ) {
361
-				$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 );
360
+			if (!empty($total_updated_products)) {
361
+				$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 362
 			}
363 363
 			else {
364
-				$response = __( 'No product have been updated', 'wpshop');
364
+				$response = __('No product have been updated', 'wpshop');
365 365
 			}
366 366
 		}
367 367
 
368
-		echo json_encode( array('status' => $status, 'response' => $response ) );
368
+		echo json_encode(array('status' => $status, 'response' => $response));
369 369
 		wp_die();
370 370
 	}
371 371
 
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
 	* Delete product list
374 374
 	**/
375 375
 	function wps_mass_delete_file() {
376
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
376
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
377 377
 
378
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) )
378
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file'))
379 379
 			wp_die();
380 380
 
381 381
 		$status = false;
382
-		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
383
-		if( !empty($file_id) ) {
384
-			wp_update_post( array('ID' => $file_id, 'post_parent' => 0) );
382
+		$file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null;
383
+		if (!empty($file_id)) {
384
+			wp_update_post(array('ID' => $file_id, 'post_parent' => 0));
385 385
 			$status = true;
386 386
 		}
387
-		echo json_encode( array( 'status' => $status ) );
387
+		echo json_encode(array('status' => $status));
388 388
 		wp_die();
389 389
 	}
390 390
 
@@ -392,32 +392,32 @@  discard block
 block discarded – undo
392 392
 	* Update product files list
393 393
 	*/
394 394
 	function wps_mass_edit_update_files_list() {
395
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
395
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
396 396
 
397
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) )
397
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list'))
398 398
 			wp_die();
399 399
 
400 400
 		$status = false; $response = '';
401
-		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
402
-		$files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null;
403
-		if( !empty($product_id ) ) {
401
+		$product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null;
402
+		$files = (!empty($_POST['files'])) ? intval($_POST['files']) : null;
403
+		if (!empty($product_id)) {
404 404
 			// Update files datas
405
-			if( !empty($files) ) {
406
-				$files_data = explode( ',', $files );
407
-				if( !empty($files_data) && is_array($files_data) ) {
408
-					foreach( $files_data as $file_id ) {
409
-						if( !empty($file_id) ) {
410
-							wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) );
405
+			if (!empty($files)) {
406
+				$files_data = explode(',', $files);
407
+				if (!empty($files_data) && is_array($files_data)) {
408
+					foreach ($files_data as $file_id) {
409
+						if (!empty($file_id)) {
410
+							wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id));
411 411
 						}
412 412
 					}
413 413
 				}
414 414
 			}
415 415
 
416 416
 
417
-			$response = $this->wps_product_attached_files( $product_id );
417
+			$response = $this->wps_product_attached_files($product_id);
418 418
 			$status = true;
419 419
 		}
420
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
420
+		echo json_encode(array('status' => $status, 'response' => $response));
421 421
 		wp_die();
422 422
 	}
423 423
 
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
 		$_wponce = !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
 		$_wponce = !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
 		$_wponce = !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
 		$_wponce = !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
 		$_wponce = !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.
modules/wps_product_mass_interface/model/wps_product_mass_interface_mdl.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@
 block discarded – undo
16 16
 
17 17
 	/**
18 18
 	 * Returns Products with post data and its attributes configuration
19
-	 * @param integer $limit
20
-	 * @param integer $count_products
19
+	 * @param integer $attribute_set_id
21 20
 	 * @return array
22 21
 	 */
23 22
 	function get_quick_interface_products( $attribute_set_id, $start_limit = 0, $nb_product_per_page = 20 ) {
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 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
  * Model file for product mass modification module
4 4
  *
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @param integer $count_products
21 21
 	 * @return array
22 22
 	 */
23
-	function get_quick_interface_products( $attribute_set_id, $start_limit = 0, $nb_product_per_page = 20 ) {
23
+	function get_quick_interface_products($attribute_set_id, $start_limit = 0, $nb_product_per_page = 20) {
24 24
 		global $wpdb;
25 25
 
26 26
 		$products_data = array();
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 				AND meta_key = %s
35 35
 				AND meta_value = %s
36 36
 			ORDER BY ID DESC
37
-			LIMIT " . $start_limit * $nb_product_per_page . ", " .$nb_product_per_page .""
37
+			LIMIT " . $start_limit * $nb_product_per_page . ", " . $nb_product_per_page . ""
38 38
 			, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id );
39
-		$products = $wpdb->get_results( $query );
39
+		$products = $wpdb->get_results($query);
40 40
 
41
-		if( !empty($products) ) {
42
-			foreach( $products as $product ) {
41
+		if (!empty($products)) {
42
+			foreach ($products as $product) {
43 43
 				// For each product stock Post Datas and attributes definition
44 44
 				$tmp = array();
45 45
 				$tmp['post_datas'] = $product;
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 
55 55
 	function get_product_attributes_sets() {
56 56
 		global $wpdb;
57
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
58
-		$query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $product_entity_id, 'valid' );
59
-		$attributes_groups = $wpdb->get_results( $query );
57
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
58
+		$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $product_entity_id, 'valid');
59
+		$attributes_groups = $wpdb->get_results($query);
60 60
 
61 61
 		return $attributes_groups;
62 62
 	}
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 
65 65
 	function get_attributes_quick_add_form() {
66 66
 		global $wpdb;
67
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
68
-		$query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %d AND is_used_in_quick_add_form = %s AND status = %s', $product_entity_id, 'yes', 'valid' );
69
-		$attributes = $wpdb->get_results( $query, ARRAY_A );
67
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
68
+		$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %d AND is_used_in_quick_add_form = %s AND status = %s', $product_entity_id, 'yes', 'valid');
69
+		$attributes = $wpdb->get_results($query, ARRAY_A);
70 70
 	
71 71
 		return $attributes;
72 72
 	}
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
  * Fichier de définition du modèle des taxinomies / File for term model definition
4 6
  *
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
  * Fichier de définition du modèle des taxinomies / File for term model definition
4 6
  *
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
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php if ( !defined( 'ABSPATH' ) ) exit;
2 2
 class wps_account_ctr {
3 3
 	/** Define the main directory containing the template for the current plugin
4
-	* @var string
5
-	*/
4
+	 * @var string
5
+	 */
6 6
 	private $template_dir;
7 7
 	/**
8 8
 	 * 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
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
552
+	function wpshop_ajax_filter_search_action() {
553
+		$_wponce = !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] ) ? sanitize_text_field( $_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]) ? sanitize_text_field($_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) . '" container="no" ]' ) ;
722
+			$data['result'] = do_shortcode('[wpshop_products pid="' . implode(',', $final_result) . '" 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
 		$_wponce = !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) . '" 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.