@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_shipping { |
3 | 3 | function __construct() { |
4 | 4 | |
@@ -11,41 +11,41 @@ discard block |
||
11 | 11 | */ |
12 | 12 | function shipping_fees_string_2_array($fees_string) { |
13 | 13 | $data = array(); |
14 | - if(!empty($fees_string) && !is_array($fees_string) ) { |
|
15 | - if(preg_match_all('#{[^{]+}#', $fees_string, $cont)){ |
|
16 | - foreach($cont[0] as $c) { |
|
14 | + if (!empty($fees_string) && !is_array($fees_string)) { |
|
15 | + if (preg_match_all('#{[^{]+}#', $fees_string, $cont)) { |
|
16 | + foreach ($cont[0] as $c) { |
|
17 | 17 | preg_match_all('#([a-z]+) ?: ?"(.+)"#', $c, $atts); |
18 | 18 | $temp_data = array(); |
19 | 19 | $country_code = ''; |
20 | - foreach($atts[1] as $key => $value) { |
|
21 | - $temp_data[$value] = $atts[2][$key]; |
|
22 | - if($value=='destination') { |
|
20 | + foreach ($atts[1] as $key => $value) { |
|
21 | + $temp_data[$value] = $atts[2][$key]; |
|
22 | + if ($value == 'destination') { |
|
23 | 23 | $country_code = $atts[2][$key]; |
24 | 24 | } |
25 | - elseif($value=='fees') { |
|
25 | + elseif ($value == 'fees') { |
|
26 | 26 | $fees_data = array(); |
27 | 27 | $fees = explode(',', $atts[2][$key]); |
28 | - foreach($fees as $fee){ |
|
28 | + foreach ($fees as $fee) { |
|
29 | 29 | $fee_element = explode(':', $fee); |
30 | - $fees_data[trim($fee_element[0])] = trim($fee_element[1]); |
|
30 | + $fees_data[trim($fee_element[0])] = trim($fee_element[1]); |
|
31 | 31 | } |
32 | 32 | $number = count($fees_data); |
33 | 33 | |
34 | 34 | $fees_data_1 = array(); |
35 | 35 | preg_match_all('#([0-9]+\.?[0-9]?+) ?: ?([0-9]+\.?[0-9]?+)#', $atts[2][$key], $fees); |
36 | - foreach($fees[1] as $_key => $_value) { |
|
37 | - $fees_data_1[$_value] = $fees[2][$_key]; |
|
36 | + foreach ($fees[1] as $_key => $_value) { |
|
37 | + $fees_data_1[$_value] = $fees[2][$_key]; |
|
38 | 38 | } |
39 | 39 | $number_1 = count($fees_data_1); |
40 | 40 | if ($number == $number_1) { |
41 | - $temp_data[$value] = $fees_data; |
|
41 | + $temp_data[$value] = $fees_data; |
|
42 | 42 | } |
43 | 43 | else { |
44 | - $temp_data[$value] = $fees_data_1; |
|
44 | + $temp_data[$value] = $fees_data_1; |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | - if(!empty($country_code)) { |
|
48 | + if (!empty($country_code)) { |
|
49 | 49 | $data[$country_code] = $temp_data; |
50 | 50 | } |
51 | 51 | } |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function shipping_fees_array_2_string($fees_array) { |
64 | 64 | $string = ''; |
65 | - if(!empty($fees_array)) { |
|
66 | - foreach($fees_array as $d) { |
|
67 | - $string .= '{'."\n"; |
|
68 | - foreach($d as $att => $value) { |
|
65 | + if (!empty($fees_array)) { |
|
66 | + foreach ($fees_array as $d) { |
|
67 | + $string .= '{' . "\n"; |
|
68 | + foreach ($d as $att => $value) { |
|
69 | 69 | $val = ''; |
70 | - if($att=='fees') { |
|
71 | - foreach($value as $_k=>$_value) $val .= $_k.':'.$_value.', '; |
|
72 | - $val = substr($val,0,-2); |
|
70 | + if ($att == 'fees') { |
|
71 | + foreach ($value as $_k=>$_value) $val .= $_k . ':' . $_value . ', '; |
|
72 | + $val = substr($val, 0, -2); |
|
73 | 73 | } else $val = $value; |
74 | - $string .= $att.': "'.$val.'",'."\n"; |
|
74 | + $string .= $att . ': "' . $val . '",' . "\n"; |
|
75 | 75 | } |
76 | - $string = substr($string,0,-2)."\n"; |
|
77 | - $string .= '},'."\n"; |
|
76 | + $string = substr($string, 0, -2) . "\n"; |
|
77 | + $string .= '},' . "\n"; |
|
78 | 78 | } |
79 | - $string = substr($string,0,-2); |
|
79 | + $string = substr($string, 0, -2); |
|
80 | 80 | return $string; |
81 | 81 | } |
82 | 82 | else return false; |
@@ -92,23 +92,23 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return number|string The sipping cost for the current cart |
94 | 94 | */ |
95 | - function get_shipping_cost( $nb_of_items, $total_cart, $total_shipping_cost, $total_weight, $selected_method = '' ) { |
|
95 | + function get_shipping_cost($nb_of_items, $total_cart, $total_shipping_cost, $total_weight, $selected_method = '') { |
|
96 | 96 | global $wpdb; |
97 | 97 | |
98 | 98 | $shipping_cost = 0; |
99 | 99 | |
100 | - $shipping_mode_state = get_option( 'wpshop_shipping_address_choice' ); |
|
101 | - if ( ! empty( $shipping_mode_state ) && isset( $shipping_mode_state['activate'] ) && ( 'on' === $shipping_mode_state['activate'] ) ) { |
|
102 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
103 | - if( ( !empty($selected_method) || isset( $_SESSION['shipping_address'] ) && empty( $_SESSION['shipping_method'] ) ) ) { |
|
104 | - if( !empty($selected_method) ) { |
|
100 | + $shipping_mode_state = get_option('wpshop_shipping_address_choice'); |
|
101 | + if (!empty($shipping_mode_state) && isset($shipping_mode_state['activate']) && ('on' === $shipping_mode_state['activate'])) { |
|
102 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
103 | + if ((!empty($selected_method) || isset($_SESSION['shipping_address']) && empty($_SESSION['shipping_method']))) { |
|
104 | + if (!empty($selected_method)) { |
|
105 | 105 | $chosen_shipping_mode = $selected_method; |
106 | 106 | } else { |
107 | 107 | $ship_mod = new wps_shipping_mode_ctr(); |
108 | - $shipping_modes = $ship_mod->get_shipping_mode_for_address( $_SESSION['shipping_address'] ); |
|
109 | - if( !empty( $shipping_modes ) ) { |
|
108 | + $shipping_modes = $ship_mod->get_shipping_mode_for_address($_SESSION['shipping_address']); |
|
109 | + if (!empty($shipping_modes)) { |
|
110 | 110 | $shipping_modes = $shipping_modes['modes']; |
111 | - foreach( $shipping_modes as $key => $shipping_mode ) { |
|
111 | + foreach ($shipping_modes as $key => $shipping_mode) { |
|
112 | 112 | $chosen_shipping_mode = $key; |
113 | 113 | break; |
114 | 114 | } |
@@ -118,37 +118,37 @@ discard block |
||
118 | 118 | } |
119 | 119 | } |
120 | 120 | else { |
121 | - if( !empty( $_SESSION['shipping_method'] ) ) { |
|
122 | - $chosen_shipping_mode = wpshop_tools::varSanitizer( $_SESSION['shipping_method'] ); |
|
121 | + if (!empty($_SESSION['shipping_method'])) { |
|
122 | + $chosen_shipping_mode = wpshop_tools::varSanitizer($_SESSION['shipping_method']); |
|
123 | 123 | } else { |
124 | 124 | $chosen_shipping_mode = 'default_choice'; |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - $default_weight_unity = get_option( 'wpshop_shop_default_weight_unity' ); |
|
129 | - if ( !empty($default_weight_unity) ) { |
|
130 | - $query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id = %d', $default_weight_unity); |
|
131 | - $weight_unity = $wpdb->get_var( $query ); |
|
128 | + $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
129 | + if (!empty($default_weight_unity)) { |
|
130 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
131 | + $weight_unity = $wpdb->get_var($query); |
|
132 | 132 | |
133 | - if ( !empty($weight_unity) && $weight_unity == 'kg' ) { |
|
133 | + if (!empty($weight_unity) && $weight_unity == 'kg') { |
|
134 | 134 | |
135 | 135 | $total_weight = $total_weight * 1000; |
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - if ( ( !empty($_SESSION['shipping_method']) && $_SESSION['shipping_method'] == 'shipping-partners' ) || !empty( $_SESSION['wps-pos-addon']) ) { |
|
139 | + if ((!empty($_SESSION['shipping_method']) && $_SESSION['shipping_method'] == 'shipping-partners') || !empty($_SESSION['wps-pos-addon'])) { |
|
140 | 140 | return 0; |
141 | 141 | } |
142 | 142 | |
143 | 143 | /** Take the selected shipping mode **/ |
144 | - if( $chosen_shipping_mode == 'default_choice' ) { |
|
145 | - if( !empty( $shipping_mode_option['modes'][ $shipping_mode_option['default_choice'] ]) ) { |
|
146 | - $selected_shipping_mode_config = $shipping_mode_option['modes'][ $shipping_mode_option['default_choice'] ]; |
|
144 | + if ($chosen_shipping_mode == 'default_choice') { |
|
145 | + if (!empty($shipping_mode_option['modes'][$shipping_mode_option['default_choice']])) { |
|
146 | + $selected_shipping_mode_config = $shipping_mode_option['modes'][$shipping_mode_option['default_choice']]; |
|
147 | 147 | } else { |
148 | 148 | $selected_shipping_mode_config = ''; |
149 | 149 | } |
150 | 150 | } else { |
151 | - if( !empty( $shipping_mode_option['modes'][$chosen_shipping_mode]) ) { |
|
151 | + if (!empty($shipping_mode_option['modes'][$chosen_shipping_mode])) { |
|
152 | 152 | $selected_shipping_mode_config = $shipping_mode_option['modes'][$chosen_shipping_mode]; |
153 | 153 | } else { |
154 | 154 | $selected_shipping_mode_config = ''; |
@@ -157,41 +157,41 @@ discard block |
||
157 | 157 | $shipping_cost = $total_shipping_cost; |
158 | 158 | |
159 | 159 | /** Free Shipping **/ |
160 | - if ( ( !empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_shipping']) ) || ( $selected_method == 'is_downloadable_' ) ) { |
|
160 | + if ((!empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_shipping'])) || ($selected_method == 'is_downloadable_')) { |
|
161 | 161 | $shipping_cost = 0; |
162 | 162 | } |
163 | 163 | /** Free Shipping From **/ |
164 | - elseif( !empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_from']) && $selected_shipping_mode_config['free_from'] >= 0 && $selected_shipping_mode_config['free_from'] <= number_format( $total_cart, 2, '.', '') ) { |
|
164 | + elseif (!empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_from']) && $selected_shipping_mode_config['free_from'] >= 0 && $selected_shipping_mode_config['free_from'] <= number_format($total_cart, 2, '.', '')) { |
|
165 | 165 | $shipping_cost = 0; |
166 | 166 | } |
167 | 167 | else { |
168 | 168 | /** Check Custom Shipping Cost **/ |
169 | 169 | |
170 | - if ( !empty($selected_shipping_mode_config['custom_shipping_rules']) && !empty($selected_shipping_mode_config['custom_shipping_rules']['active']) ) { |
|
170 | + if (!empty($selected_shipping_mode_config['custom_shipping_rules']) && !empty($selected_shipping_mode_config['custom_shipping_rules']['active'])) { |
|
171 | 171 | $address_infos = ''; |
172 | - if( !empty( $_SESSION['shipping_address'] ) ) { |
|
173 | - $address_infos = get_post_meta($_SESSION['shipping_address'],'_wpshop_address_metadata', true); |
|
172 | + if (!empty($_SESSION['shipping_address'])) { |
|
173 | + $address_infos = get_post_meta($_SESSION['shipping_address'], '_wpshop_address_metadata', true); |
|
174 | 174 | } |
175 | - $country = ( !empty($address_infos['country']) ) ? $address_infos['country'] : ''; |
|
175 | + $country = (!empty($address_infos['country'])) ? $address_infos['country'] : ''; |
|
176 | 176 | /** Check Active Postcode option **/ |
177 | - if ( !empty($selected_shipping_mode_config['custom_shipping_rules']['active_cp']) ) { |
|
177 | + if (!empty($selected_shipping_mode_config['custom_shipping_rules']['active_cp'])) { |
|
178 | 178 | $postcode = $address_infos['postcode']; |
179 | - if ( array_key_exists($country.'-'.$postcode, $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) { |
|
180 | - $country = $country.'-'.$postcode; |
|
179 | + if (array_key_exists($country . '-' . $postcode, $selected_shipping_mode_config['custom_shipping_rules']['fees'])) { |
|
180 | + $country = $country . '-' . $postcode; |
|
181 | 181 | } |
182 | - elseif( array_key_exists($country.'-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) { |
|
183 | - $country = $country.'-OTHERS'; |
|
182 | + elseif (array_key_exists($country . '-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees'])) { |
|
183 | + $country = $country . '-OTHERS'; |
|
184 | 184 | } |
185 | 185 | } |
186 | - $shipping_cost += $this->calculate_custom_shipping_cost($country, array('weight'=>$total_weight,'price'=> $total_cart), $selected_shipping_mode_config['custom_shipping_rules']['fees'], $chosen_shipping_mode); |
|
186 | + $shipping_cost += $this->calculate_custom_shipping_cost($country, array('weight'=>$total_weight, 'price'=> $total_cart), $selected_shipping_mode_config['custom_shipping_rules']['fees'], $chosen_shipping_mode); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** Min- Max config **/ |
190 | - if ( !empty($selected_shipping_mode_config['min_max']) && !empty($selected_shipping_mode_config['min_max']['activate']) ) { |
|
191 | - if ( !empty($selected_shipping_mode_config['min_max']['min']) && $shipping_cost < $selected_shipping_mode_config['min_max']['min'] ) { |
|
190 | + if (!empty($selected_shipping_mode_config['min_max']) && !empty($selected_shipping_mode_config['min_max']['activate'])) { |
|
191 | + if (!empty($selected_shipping_mode_config['min_max']['min']) && $shipping_cost < $selected_shipping_mode_config['min_max']['min']) { |
|
192 | 192 | $shipping_cost = $selected_shipping_mode_config['min_max']['min']; |
193 | 193 | } |
194 | - elseif( !empty($selected_shipping_mode_config['min_max']['max']) &&$shipping_cost > $selected_shipping_mode_config['min_max']['max']) { |
|
194 | + elseif (!empty($selected_shipping_mode_config['min_max']['max']) && $shipping_cost > $selected_shipping_mode_config['min_max']['max']) { |
|
195 | 195 | $shipping_cost = $selected_shipping_mode_config['min_max']['max']; |
196 | 196 | } |
197 | 197 | |
@@ -209,40 +209,40 @@ discard block |
||
209 | 209 | * @param array $fees |
210 | 210 | * @return number|boolean|Ambigous <number, unknown> |
211 | 211 | */ |
212 | - function calculate_custom_shipping_cost($dest='', $data, $fees, $shipping_method = false) { |
|
212 | + function calculate_custom_shipping_cost($dest = '', $data, $fees, $shipping_method = false) { |
|
213 | 213 | $fees_table = array(); |
214 | 214 | $key = ''; $price = 0; |
215 | 215 | |
216 | - if ( !empty($_SESSION['shipping_partner_id']) ) { |
|
216 | + if (!empty($_SESSION['shipping_partner_id'])) { |
|
217 | 217 | return 0; |
218 | 218 | } |
219 | 219 | |
220 | - if($shipping_method === false) { |
|
220 | + if ($shipping_method === false) { |
|
221 | 221 | $shipping_method = $_SESSION['shipping_method']; |
222 | 222 | } |
223 | 223 | |
224 | - if(!empty($fees) || !empty($dest) ) { |
|
225 | - $custom_shipping_option = get_option( 'wpshop_custom_shipping', true ); |
|
226 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
224 | + if (!empty($fees) || !empty($dest)) { |
|
225 | + $custom_shipping_option = get_option('wpshop_custom_shipping', true); |
|
226 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
227 | 227 | |
228 | - if ( !empty($shipping_method) ) { |
|
229 | - if ( !empty($shipping_modes) && !empty($shipping_modes['modes']) && !empty($shipping_modes['modes'][ $shipping_method ]) ) { |
|
230 | - $custom_shipping_option = $shipping_modes['modes'][ $shipping_method ]['custom_shipping_rules']; |
|
228 | + if (!empty($shipping_method)) { |
|
229 | + if (!empty($shipping_modes) && !empty($shipping_modes['modes']) && !empty($shipping_modes['modes'][$shipping_method])) { |
|
230 | + $custom_shipping_option = $shipping_modes['modes'][$shipping_method]['custom_shipping_rules']; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | $found_active_cp_rule = $found_active_departement_rule = false; |
234 | - $shipping_address_def = get_post_meta( $_SESSION['shipping_address'], '_wpshop_address_metadata', true ); |
|
234 | + $shipping_address_def = get_post_meta($_SESSION['shipping_address'], '_wpshop_address_metadata', true); |
|
235 | 235 | $postcode = ''; |
236 | - if ( !empty($shipping_address_def) ) { |
|
236 | + if (!empty($shipping_address_def)) { |
|
237 | 237 | $postcode = $shipping_address_def['postcode']; |
238 | 238 | } |
239 | 239 | |
240 | 240 | /** Search Postcode custom fees **/ |
241 | - if ( !empty($custom_shipping_option) && !empty($custom_shipping_option['active_cp']) ) { |
|
242 | - $key = $dest.'-'.$postcode; |
|
243 | - if ( array_key_exists($key, $fees) ) { |
|
241 | + if (!empty($custom_shipping_option) && !empty($custom_shipping_option['active_cp'])) { |
|
242 | + $key = $dest . '-' . $postcode; |
|
243 | + if (array_key_exists($key, $fees)) { |
|
244 | 244 | foreach ($fees[$key]['fees'] as $k => $shipping_price) { |
245 | - if ( $data['weight'] <= $k) { |
|
245 | + if ($data['weight'] <= $k) { |
|
246 | 246 | break; |
247 | 247 | } |
248 | 248 | } |
@@ -251,13 +251,13 @@ discard block |
||
251 | 251 | } |
252 | 252 | |
253 | 253 | /** Search Department custom fees **/ |
254 | - if( !empty($custom_shipping_option) && !empty($custom_shipping_option['active_department']) && !$found_active_cp_rule ) { |
|
255 | - $department = substr( $postcode, 0,2 ); |
|
256 | - $key = $dest.'-'.$department; |
|
254 | + if (!empty($custom_shipping_option) && !empty($custom_shipping_option['active_department']) && !$found_active_cp_rule) { |
|
255 | + $department = substr($postcode, 0, 2); |
|
256 | + $key = $dest . '-' . $department; |
|
257 | 257 | /** Check if a rule exists **/ |
258 | - if ( array_key_exists($key, $fees) ) { |
|
258 | + if (array_key_exists($key, $fees)) { |
|
259 | 259 | foreach ($fees[$key]['fees'] as $k => $shipping_price) { |
260 | - if ( $data['weight'] <= $k) { |
|
260 | + if ($data['weight'] <= $k) { |
|
261 | 261 | break; |
262 | 262 | } |
263 | 263 | } |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | } |
267 | 267 | |
268 | 268 | /** Search general custom fees **/ |
269 | - if( !$found_active_cp_rule && !$found_active_departement_rule ){ |
|
270 | - if ( array_key_exists($dest, $fees) ) { |
|
269 | + if (!$found_active_cp_rule && !$found_active_departement_rule) { |
|
270 | + if (array_key_exists($dest, $fees)) { |
|
271 | 271 | $key = $dest; |
272 | 272 | } |
273 | - elseif( array_key_exists( 'OTHERS', $fees) ) { |
|
273 | + elseif (array_key_exists('OTHERS', $fees)) { |
|
274 | 274 | $key = 'OTHERS'; |
275 | 275 | } |
276 | 276 | else { |
@@ -279,10 +279,10 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | //Search fees |
282 | - if ( !empty($key) ) { |
|
283 | - ksort( $fees[$key]['fees'] ); |
|
282 | + if (!empty($key)) { |
|
283 | + ksort($fees[$key]['fees']); |
|
284 | 284 | foreach ($fees[$key]['fees'] as $k => $shipping_price) { |
285 | - if ( $data['weight'] <= $k) { |
|
285 | + if ($data['weight'] <= $k) { |
|
286 | 286 | $price = $shipping_price; |
287 | 287 | break; |
288 | 288 | } |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | * @param array $cart_items |
305 | 305 | * @return number |
306 | 306 | */ |
307 | - function calcul_cart_items_shipping_cost( $cart_items ) { |
|
307 | + function calcul_cart_items_shipping_cost($cart_items) { |
|
308 | 308 | $shipping_cost = 0; |
309 | - if( !empty($cart_items) ) { |
|
310 | - foreach( $cart_items as $cart_item ) { |
|
311 | - $product_data = get_post_meta( $cart_item['item_id'], '_wpshop_product_metadata', true ); |
|
309 | + if (!empty($cart_items)) { |
|
310 | + foreach ($cart_items as $cart_item) { |
|
311 | + $product_data = get_post_meta($cart_item['item_id'], '_wpshop_product_metadata', true); |
|
312 | 312 | |
313 | - if ( !empty( $product_data ) && !empty( $product_data['cost_of_postage'] ) ) { |
|
314 | - $shipping_cost += ( $product_data['cost_of_postage'] * $cart_item['item_qty'] ); |
|
313 | + if (!empty($product_data) && !empty($product_data['cost_of_postage'])) { |
|
314 | + $shipping_cost += ($product_data['cost_of_postage'] * $cart_item['item_qty']); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | } |
@@ -324,32 +324,32 @@ discard block |
||
324 | 324 | * @param array $cart_items |
325 | 325 | * @return number |
326 | 326 | */ |
327 | - function calcul_cart_weight( $cart_items ) { |
|
327 | + function calcul_cart_weight($cart_items) { |
|
328 | 328 | $cart_weight = 0; |
329 | - if ( !empty( $cart_items) ) { |
|
330 | - foreach( $cart_items as $id_item => $cart_item ) { |
|
329 | + if (!empty($cart_items)) { |
|
330 | + foreach ($cart_items as $id_item => $cart_item) { |
|
331 | 331 | $id_item = wpshop_products::get_id_variation($id_item); |
332 | - if ( get_post_type($id_item) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
333 | - $product_data = get_post_meta( $id_item, '_wpshop_product_metadata', true ); |
|
334 | - if ( !empty($product_data) && !empty($product_data['product_weight']) ) { |
|
335 | - $cart_weight += ( $product_data['product_weight'] * $cart_item['item_qty'] ); |
|
332 | + if (get_post_type($id_item) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
333 | + $product_data = get_post_meta($id_item, '_wpshop_product_metadata', true); |
|
334 | + if (!empty($product_data) && !empty($product_data['product_weight'])) { |
|
335 | + $cart_weight += ($product_data['product_weight'] * $cart_item['item_qty']); |
|
336 | 336 | } |
337 | 337 | else { |
338 | - $parent_def = wpshop_products::get_parent_variation( $id_item ); |
|
339 | - if ( !empty($parent_def) && !empty( $parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight']) ) { |
|
340 | - $cart_weight += ( $parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty'] ); |
|
338 | + $parent_def = wpshop_products::get_parent_variation($id_item); |
|
339 | + if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight'])) { |
|
340 | + $cart_weight += ($parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty']); |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | } |
344 | 344 | else { |
345 | - $product_data = get_post_meta( $cart_item['item_id'], '_wpshop_product_metadata', true ); |
|
346 | - if ( !empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty']) ) { |
|
347 | - $cart_weight += ( $product_data['product_weight'] * $cart_item['item_qty'] ); |
|
345 | + $product_data = get_post_meta($cart_item['item_id'], '_wpshop_product_metadata', true); |
|
346 | + if (!empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty'])) { |
|
347 | + $cart_weight += ($product_data['product_weight'] * $cart_item['item_qty']); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | } |
351 | 351 | } |
352 | - $cart_weight = apply_filters( 'extra_cart_weight_calcul', $cart_weight, $cart_items ); |
|
352 | + $cart_weight = apply_filters('extra_cart_weight_calcul', $cart_weight, $cart_items); |
|
353 | 353 | return $cart_weight; |
354 | 354 | } |
355 | 355 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | class wps_shipping { |
3 | 5 | function __construct() { |
4 | 6 | |
@@ -21,8 +23,7 @@ discard block |
||
21 | 23 | $temp_data[$value] = $atts[2][$key]; |
22 | 24 | if($value=='destination') { |
23 | 25 | $country_code = $atts[2][$key]; |
24 | - } |
|
25 | - elseif($value=='fees') { |
|
26 | + } elseif($value=='fees') { |
|
26 | 27 | $fees_data = array(); |
27 | 28 | $fees = explode(',', $atts[2][$key]); |
28 | 29 | foreach($fees as $fee){ |
@@ -39,8 +40,7 @@ discard block |
||
39 | 40 | $number_1 = count($fees_data_1); |
40 | 41 | if ($number == $number_1) { |
41 | 42 | $temp_data[$value] = $fees_data; |
42 | - } |
|
43 | - else { |
|
43 | + } else { |
|
44 | 44 | $temp_data[$value] = $fees_data_1; |
45 | 45 | } |
46 | 46 | } |
@@ -68,9 +68,13 @@ discard block |
||
68 | 68 | foreach($d as $att => $value) { |
69 | 69 | $val = ''; |
70 | 70 | if($att=='fees') { |
71 | - foreach($value as $_k=>$_value) $val .= $_k.':'.$_value.', '; |
|
71 | + foreach($value as $_k=>$_value) { |
|
72 | + $val .= $_k.':'.$_value.', '; |
|
73 | + } |
|
72 | 74 | $val = substr($val,0,-2); |
73 | - } else $val = $value; |
|
75 | + } else { |
|
76 | + $val = $value; |
|
77 | + } |
|
74 | 78 | $string .= $att.': "'.$val.'",'."\n"; |
75 | 79 | } |
76 | 80 | $string = substr($string,0,-2)."\n"; |
@@ -78,8 +82,9 @@ discard block |
||
78 | 82 | } |
79 | 83 | $string = substr($string,0,-2); |
80 | 84 | return $string; |
81 | - } |
|
82 | - else return false; |
|
85 | + } else { |
|
86 | + return false; |
|
87 | + } |
|
83 | 88 | } |
84 | 89 | |
85 | 90 | /** |
@@ -116,8 +121,7 @@ discard block |
||
116 | 121 | $chosen_shipping_mode = 'default_choice'; |
117 | 122 | } |
118 | 123 | } |
119 | - } |
|
120 | - else { |
|
124 | + } else { |
|
121 | 125 | if( !empty( $_SESSION['shipping_method'] ) ) { |
122 | 126 | $chosen_shipping_mode = wpshop_tools::varSanitizer( $_SESSION['shipping_method'] ); |
123 | 127 | } else { |
@@ -163,8 +167,7 @@ discard block |
||
163 | 167 | /** Free Shipping From **/ |
164 | 168 | elseif( !empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_from']) && $selected_shipping_mode_config['free_from'] >= 0 && $selected_shipping_mode_config['free_from'] <= number_format( $total_cart, 2, '.', '') ) { |
165 | 169 | $shipping_cost = 0; |
166 | - } |
|
167 | - else { |
|
170 | + } else { |
|
168 | 171 | /** Check Custom Shipping Cost **/ |
169 | 172 | |
170 | 173 | if ( !empty($selected_shipping_mode_config['custom_shipping_rules']) && !empty($selected_shipping_mode_config['custom_shipping_rules']['active']) ) { |
@@ -178,8 +181,7 @@ discard block |
||
178 | 181 | $postcode = $address_infos['postcode']; |
179 | 182 | if ( array_key_exists($country.'-'.$postcode, $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) { |
180 | 183 | $country = $country.'-'.$postcode; |
181 | - } |
|
182 | - elseif( array_key_exists($country.'-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) { |
|
184 | + } elseif( array_key_exists($country.'-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) { |
|
183 | 185 | $country = $country.'-OTHERS'; |
184 | 186 | } |
185 | 187 | } |
@@ -190,8 +192,7 @@ discard block |
||
190 | 192 | if ( !empty($selected_shipping_mode_config['min_max']) && !empty($selected_shipping_mode_config['min_max']['activate']) ) { |
191 | 193 | if ( !empty($selected_shipping_mode_config['min_max']['min']) && $shipping_cost < $selected_shipping_mode_config['min_max']['min'] ) { |
192 | 194 | $shipping_cost = $selected_shipping_mode_config['min_max']['min']; |
193 | - } |
|
194 | - elseif( !empty($selected_shipping_mode_config['min_max']['max']) &&$shipping_cost > $selected_shipping_mode_config['min_max']['max']) { |
|
195 | + } elseif( !empty($selected_shipping_mode_config['min_max']['max']) &&$shipping_cost > $selected_shipping_mode_config['min_max']['max']) { |
|
195 | 196 | $shipping_cost = $selected_shipping_mode_config['min_max']['max']; |
196 | 197 | } |
197 | 198 | |
@@ -269,11 +270,9 @@ discard block |
||
269 | 270 | if( !$found_active_cp_rule && !$found_active_departement_rule ){ |
270 | 271 | if ( array_key_exists($dest, $fees) ) { |
271 | 272 | $key = $dest; |
272 | - } |
|
273 | - elseif( array_key_exists( 'OTHERS', $fees) ) { |
|
273 | + } elseif( array_key_exists( 'OTHERS', $fees) ) { |
|
274 | 274 | $key = 'OTHERS'; |
275 | - } |
|
276 | - else { |
|
275 | + } else { |
|
277 | 276 | return false; |
278 | 277 | } |
279 | 278 | } |
@@ -290,8 +289,7 @@ discard block |
||
290 | 289 | $price = $shipping_price; |
291 | 290 | } |
292 | 291 | } |
293 | - } |
|
294 | - else { |
|
292 | + } else { |
|
295 | 293 | return false; |
296 | 294 | } |
297 | 295 | return $price; |
@@ -333,15 +331,13 @@ discard block |
||
333 | 331 | $product_data = get_post_meta( $id_item, '_wpshop_product_metadata', true ); |
334 | 332 | if ( !empty($product_data) && !empty($product_data['product_weight']) ) { |
335 | 333 | $cart_weight += ( $product_data['product_weight'] * $cart_item['item_qty'] ); |
336 | - } |
|
337 | - else { |
|
334 | + } else { |
|
338 | 335 | $parent_def = wpshop_products::get_parent_variation( $id_item ); |
339 | 336 | if ( !empty($parent_def) && !empty( $parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight']) ) { |
340 | 337 | $cart_weight += ( $parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty'] ); |
341 | 338 | } |
342 | 339 | } |
343 | - } |
|
344 | - else { |
|
340 | + } else { |
|
345 | 341 | $product_data = get_post_meta( $cart_item['item_id'], '_wpshop_product_metadata', true ); |
346 | 342 | if ( !empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty']) ) { |
347 | 343 | $cart_weight += ( $product_data['product_weight'] * $cart_item['item_qty'] ); |
@@ -1,48 +1,48 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_cart { |
3 | 3 | |
4 | 4 | function __construct() { |
5 | 5 | /** WPShop Cart Shortcode **/ |
6 | - add_shortcode( 'wps_cart', array( &$this, 'display_cart' ) ); |
|
7 | - add_shortcode( 'wpshop_cart', array( &$this, 'display_cart' ) ); |
|
6 | + add_shortcode('wps_cart', array(&$this, 'display_cart')); |
|
7 | + add_shortcode('wpshop_cart', array(&$this, 'display_cart')); |
|
8 | 8 | /** WPShop Mini Cart Shortcode **/ |
9 | - add_shortcode( 'wps_mini_cart', array( &$this, 'display_mini_cart' ) ); |
|
10 | - add_shortcode( 'wpshop_mini_cart', array( &$this, 'display_mini_cart' ) ); |
|
9 | + add_shortcode('wps_mini_cart', array(&$this, 'display_mini_cart')); |
|
10 | + add_shortcode('wpshop_mini_cart', array(&$this, 'display_mini_cart')); |
|
11 | 11 | /** WPShop Resume Cart Shorcode **/ |
12 | - add_shortcode( 'wps_resume_cart', array( &$this, 'display_resume_cart' ) ); |
|
13 | - add_shortcode( 'wpshop_resume_cart', array( &$this, 'display_resume_cart' ) ); |
|
12 | + add_shortcode('wps_resume_cart', array(&$this, 'display_resume_cart')); |
|
13 | + add_shortcode('wpshop_resume_cart', array(&$this, 'display_resume_cart')); |
|
14 | 14 | /** Apply Coupon Interface **/ |
15 | - add_shortcode( 'wps_apply_coupon', array( &$this, 'display_apply_coupon_interface' ) ); |
|
16 | - add_shortcode( 'wpshop_apply_coupon', array( &$this, 'display_apply_coupon_interface' ) ); |
|
15 | + add_shortcode('wps_apply_coupon', array(&$this, 'display_apply_coupon_interface')); |
|
16 | + add_shortcode('wpshop_apply_coupon', array(&$this, 'display_apply_coupon_interface')); |
|
17 | 17 | /** NUmeration Cart **/ |
18 | - add_shortcode( 'wps-numeration-cart', array( &$this, 'display_wps_numeration_cart' ) ); |
|
19 | - add_shortcode( 'wpshop-numeration-cart', array( &$this, 'display_wps_numeration_cart' ) ); |
|
18 | + add_shortcode('wps-numeration-cart', array(&$this, 'display_wps_numeration_cart')); |
|
19 | + add_shortcode('wpshop-numeration-cart', array(&$this, 'display_wps_numeration_cart')); |
|
20 | 20 | /** Button add to cart */ |
21 | - add_shortcode( 'wpshop_button_add_to_cart', array( &$this, 'display_button_add_to_cart' ) ); |
|
21 | + add_shortcode('wpshop_button_add_to_cart', array(&$this, 'display_button_add_to_cart')); |
|
22 | 22 | |
23 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) ); |
|
24 | - add_action( 'init', array( $this, 'load_cart_from_db' ) ); |
|
23 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
24 | + add_action('init', array($this, 'load_cart_from_db')); |
|
25 | 25 | |
26 | 26 | /** Ajax Actions **/ |
27 | - add_action( 'wp_ajax_wps_reload_cart', array( $this, 'wps_reload_cart' ) ); |
|
28 | - add_action( 'wp_ajax_nopriv_wps_reload_cart', array( $this, 'wps_reload_cart' ) ); |
|
27 | + add_action('wp_ajax_wps_reload_cart', array($this, 'wps_reload_cart')); |
|
28 | + add_action('wp_ajax_nopriv_wps_reload_cart', array($this, 'wps_reload_cart')); |
|
29 | 29 | |
30 | - add_action( 'wp_ajax_wps_reload_mini_cart', array( &$this, 'wps_reload_mini_cart' ) ); |
|
31 | - add_action( 'wp_ajax_nopriv_wps_reload_mini_cart', array( &$this, 'wps_reload_mini_cart' ) ); |
|
30 | + add_action('wp_ajax_wps_reload_mini_cart', array(&$this, 'wps_reload_mini_cart')); |
|
31 | + add_action('wp_ajax_nopriv_wps_reload_mini_cart', array(&$this, 'wps_reload_mini_cart')); |
|
32 | 32 | |
33 | - add_action( 'wp_ajax_wps_reload_summary_cart', array( &$this, 'wps_reload_summary_cart' ) ); |
|
34 | - add_action( 'wp_ajax_nopriv_wps_reload_summary_cart', array( &$this, 'wps_reload_summary_cart' ) ); |
|
33 | + add_action('wp_ajax_wps_reload_summary_cart', array(&$this, 'wps_reload_summary_cart')); |
|
34 | + add_action('wp_ajax_nopriv_wps_reload_summary_cart', array(&$this, 'wps_reload_summary_cart')); |
|
35 | 35 | |
36 | - add_action( 'wp_ajax_wps_apply_coupon', array( &$this, 'wps_apply_coupon' ) ); |
|
37 | - add_action( 'wp_ajax_nopriv_wps_apply_coupon', array( &$this, 'wps_apply_coupon' ) ); |
|
36 | + add_action('wp_ajax_wps_apply_coupon', array(&$this, 'wps_apply_coupon')); |
|
37 | + add_action('wp_ajax_nopriv_wps_apply_coupon', array(&$this, 'wps_apply_coupon')); |
|
38 | 38 | |
39 | - add_action( 'wp_ajax_wps_cart_pass_to_step_two', array( &$this, 'wps_cart_pass_to_step_two' ) ); |
|
40 | - add_action( 'wp_ajax_nopriv_wps_cart_pass_to_step_two', array( &$this, 'wps_cart_pass_to_step_two' ) ); |
|
39 | + add_action('wp_ajax_wps_cart_pass_to_step_two', array(&$this, 'wps_cart_pass_to_step_two')); |
|
40 | + add_action('wp_ajax_nopriv_wps_cart_pass_to_step_two', array(&$this, 'wps_cart_pass_to_step_two')); |
|
41 | 41 | |
42 | - add_action( 'wp_ajax_wps_empty_cart', array( &$this, 'wps_empty_cart' ) ); |
|
43 | - add_action( 'wp_ajax_nopriv_wps_empty_cart', array( &$this, 'wps_empty_cart' ) ); |
|
42 | + add_action('wp_ajax_wps_empty_cart', array(&$this, 'wps_empty_cart')); |
|
43 | + add_action('wp_ajax_nopriv_wps_empty_cart', array(&$this, 'wps_empty_cart')); |
|
44 | 44 | |
45 | - add_action( 'wsphop_options', array(&$this, 'declare_options' ), 8); |
|
45 | + add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,19 +50,19 @@ discard block |
||
50 | 50 | */ |
51 | 51 | function add_scripts() { |
52 | 52 | wp_enqueue_script('jquery'); |
53 | - wp_enqueue_script( 'wps_cart_js', WPS_CART_URL . WPS_CART_DIR.'/assets/frontend/js/wps_cart.js' ); |
|
53 | + wp_enqueue_script('wps_cart_js', WPS_CART_URL . WPS_CART_DIR . '/assets/frontend/js/wps_cart.js'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Declare Cart Options |
58 | 58 | */ |
59 | - public static function declare_options () { |
|
60 | - if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) { |
|
61 | - $wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : ''; |
|
62 | - $old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : ''; |
|
59 | + public static function declare_options() { |
|
60 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
61 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
62 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
63 | 63 | |
64 | - if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' ) |
|
65 | - && ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) { |
|
64 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
65 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
66 | 66 | /** Add module option to wpshop general options */ |
67 | 67 | register_setting('wpshop_options', 'wpshop_cart_option', array('wps_cart', 'wpshop_options_validate_cart_type')); |
68 | 68 | add_settings_field('wpshop_cart_type', __('Which type of cart do you want to display', 'wpshop'), array('wps_cart', 'wpshop_cart_type_field'), 'wpshop_cart_info', 'wpshop_cart_info'); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @param unknown_type $input |
76 | 76 | * @return unknown |
77 | 77 | */ |
78 | - public static function wpshop_options_validate_cart_type( $input ) { |
|
78 | + public static function wpshop_options_validate_cart_type($input) { |
|
79 | 79 | return $input; |
80 | 80 | } |
81 | 81 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * Cart Options Fields |
84 | 84 | */ |
85 | 85 | public static function wpshop_cart_type_field() { |
86 | - $cart_option = get_option( 'wpshop_cart_option' ); |
|
86 | + $cart_option = get_option('wpshop_cart_option'); |
|
87 | 87 | |
88 | 88 | $output = '<select name="wpshop_cart_option[cart_type]">'; |
89 | - $output .= '<option value="simplified_ati" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_ati' ) ? 'selected="selected"' : ''). ' >' .__( 'Simplified cart ATI', 'wpshop'). '</option>'; |
|
90 | - $output .= '<option value="simplified_et" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_et' ) ? 'selected="selected"' : ''). ' >' .__( 'Simplified cart ET', 'wpshop'). '</option>'; |
|
91 | - $output .= '<option value="full_cart" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'full_cart' ) ? 'selected="selected"' : ''). ' >' .__( 'Full cart', 'wpshop'). '</option>'; |
|
89 | + $output .= '<option value="simplified_ati" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_ati') ? 'selected="selected"' : '') . ' >' . __('Simplified cart ATI', 'wpshop') . '</option>'; |
|
90 | + $output .= '<option value="simplified_et" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_et') ? 'selected="selected"' : '') . ' >' . __('Simplified cart ET', 'wpshop') . '</option>'; |
|
91 | + $output .= '<option value="full_cart" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'full_cart') ? 'selected="selected"' : '') . ' >' . __('Full cart', 'wpshop') . '</option>'; |
|
92 | 92 | $output .= '</select>'; |
93 | 93 | |
94 | 94 | echo $output; |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** Display Cart **/ |
98 | - function display_cart( $args ) { |
|
99 | - $cart_type = ( !empty($args) && !empty($args['cart_type']) ) ? $args['cart_type']: ''; |
|
100 | - $oid = ( !empty($args) && !empty($args['oid']) ) ? $args['oid'] : ''; |
|
101 | - $output = '<div id="wps_cart_container" data-nonce="' . wp_create_nonce( 'wps_reload_cart' ) . '" class="wps-bloc-loader wps-cart-wrapper">'; |
|
98 | + function display_cart($args) { |
|
99 | + $cart_type = (!empty($args) && !empty($args['cart_type'])) ? $args['cart_type'] : ''; |
|
100 | + $oid = (!empty($args) && !empty($args['oid'])) ? $args['oid'] : ''; |
|
101 | + $output = '<div id="wps_cart_container" data-nonce="' . wp_create_nonce('wps_reload_cart') . '" class="wps-bloc-loader wps-cart-wrapper">'; |
|
102 | 102 | $output .= self::cart_content($cart_type, $oid); |
103 | 103 | $output .= '</div>'; |
104 | 104 | |
@@ -106,84 +106,84 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | /** Cart Content **/ |
109 | - public static function cart_content( $cart_type = '', $oid = '' ) { |
|
109 | + public static function cart_content($cart_type = '', $oid = '') { |
|
110 | 110 | global $wpdb; |
111 | 111 | $output = ''; |
112 | 112 | $account_origin = false; |
113 | - $cart_option = get_option( 'wpshop_cart_option' ); |
|
114 | - $cart_option = ( !empty($cart_option) && !empty($cart_option['cart_type']) ) ? $cart_option['cart_type'] : 'simplified_ati'; |
|
113 | + $cart_option = get_option('wpshop_cart_option'); |
|
114 | + $cart_option = (!empty($cart_option) && !empty($cart_option['cart_type'])) ? $cart_option['cart_type'] : 'simplified_ati'; |
|
115 | 115 | |
116 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
116 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
117 | 117 | |
118 | 118 | $coupon_title = $coupon_value = ''; |
119 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
120 | - if( !empty($oid) ) { |
|
119 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
120 | + if (!empty($oid)) { |
|
121 | 121 | $account_origin = true; |
122 | - $cart_content = get_post_meta( $oid, '_order_postmeta', true); |
|
122 | + $cart_content = get_post_meta($oid, '_order_postmeta', true); |
|
123 | 123 | } |
124 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
124 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
125 | 125 | |
126 | - if ( !empty($cart_content) ) { |
|
127 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
126 | + if (!empty($cart_content)) { |
|
127 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
128 | 128 | |
129 | - if ( !empty($cart_content['coupon_id']) ) { |
|
130 | - $coupon_title = get_the_title( $cart_content['coupon_id']); |
|
131 | - $coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] ); |
|
129 | + if (!empty($cart_content['coupon_id'])) { |
|
130 | + $coupon_title = get_the_title($cart_content['coupon_id']); |
|
131 | + $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); |
|
132 | 132 | } |
133 | 133 | |
134 | - if ( !empty($cart_items) ) { |
|
134 | + if (!empty($cart_items)) { |
|
135 | 135 | /** Total values **/ |
136 | - $shipping_cost_et = ( !empty($cart_content['order_shipping_cost']) ) ? ( (!empty($price_piloting) && $price_piloting != 'HT') ? ( $cart_content['order_shipping_cost'] / ( 1 + ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ) ) : $cart_content['order_shipping_cost'] ) : 0; |
|
137 | - $shipping_cost_vat = ( !empty( $shipping_cost_et) ) ? ( $shipping_cost_et * ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ) : 0; |
|
138 | - $shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? ( (!empty($price_piloting) && $price_piloting != 'HT') ? $cart_content['order_shipping_cost'] : $cart_content['order_shipping_cost'] + $shipping_cost_vat ) : 0; |
|
139 | - $total_et = ( !empty( $cart_content['order_total_ht']) ) ? $cart_content['order_total_ht'] : 0; |
|
140 | - $order_totla_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
141 | - $order_amount_to_pay_now = wpshop_tools::formate_number( $cart_content['order_amount_to_pay_now'] ); |
|
142 | - $total_ati = ( !empty( $order_amount_to_pay_now ) && !empty($oid) && $order_amount_to_pay_now > 0 ) ? $cart_content['order_amount_to_pay_now'] : ( (!empty($cart_content['order_grand_total']) ) ? $cart_content['order_grand_total'] : 0 ); |
|
136 | + $shipping_cost_et = (!empty($cart_content['order_shipping_cost'])) ? ((!empty($price_piloting) && $price_piloting != 'HT') ? ($cart_content['order_shipping_cost'] / (1 + (WPSHOP_VAT_ON_SHIPPING_COST / 100))) : $cart_content['order_shipping_cost']) : 0; |
|
137 | + $shipping_cost_vat = (!empty($shipping_cost_et)) ? ($shipping_cost_et * (WPSHOP_VAT_ON_SHIPPING_COST / 100)) : 0; |
|
138 | + $shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? ((!empty($price_piloting) && $price_piloting != 'HT') ? $cart_content['order_shipping_cost'] : $cart_content['order_shipping_cost'] + $shipping_cost_vat) : 0; |
|
139 | + $total_et = (!empty($cart_content['order_total_ht'])) ? $cart_content['order_total_ht'] : 0; |
|
140 | + $order_totla_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
141 | + $order_amount_to_pay_now = wpshop_tools::formate_number($cart_content['order_amount_to_pay_now']); |
|
142 | + $total_ati = (!empty($order_amount_to_pay_now) && !empty($oid) && $order_amount_to_pay_now > 0) ? $cart_content['order_amount_to_pay_now'] : ((!empty($cart_content['order_grand_total'])) ? $cart_content['order_grand_total'] : 0); |
|
143 | 143 | unset($tracking); |
144 | - if( !empty($cart_content['order_trackingNumber']) ) { |
|
144 | + if (!empty($cart_content['order_trackingNumber'])) { |
|
145 | 145 | $tracking['number'] = $cart_content['order_trackingNumber']; |
146 | 146 | } |
147 | - if( !empty($cart_content['order_trackingLink']) ) { |
|
147 | + if (!empty($cart_content['order_trackingLink'])) { |
|
148 | 148 | $tracking['link'] = $cart_content['order_trackingLink']; |
149 | 149 | } |
150 | 150 | ob_start(); |
151 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart") ); |
|
151 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart")); |
|
152 | 152 | $output = ob_get_contents(); |
153 | 153 | ob_end_clean(); |
154 | 154 | } |
155 | 155 | else { |
156 | - return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';; |
|
156 | + return '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; ; |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | else { |
160 | - return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';; |
|
160 | + return '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; ; |
|
161 | 161 | } |
162 | 162 | return $output; |
163 | 163 | } |
164 | 164 | |
165 | 165 | /** Display mini cart **/ |
166 | - function display_mini_cart( $args ) { |
|
166 | + function display_mini_cart($args) { |
|
167 | 167 | $total_cart_item = 0; |
168 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
169 | - $type = ( !empty($args) && !empty($args['type']) ) ? $args['type'] : ''; |
|
168 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
169 | + $type = (!empty($args) && !empty($args['type'])) ? $args['type'] : ''; |
|
170 | 170 | |
171 | 171 | |
172 | - if ( !empty($cart_content) ) { |
|
173 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
172 | + if (!empty($cart_content)) { |
|
173 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
174 | 174 | /** Count items **/ |
175 | - $total_cart_item = self::total_cart_items( $cart_items ); |
|
176 | - $mini_cart_body = self::mini_cart_content( $type ); |
|
175 | + $total_cart_item = self::total_cart_items($cart_items); |
|
176 | + $mini_cart_body = self::mini_cart_content($type); |
|
177 | 177 | } |
178 | 178 | else { |
179 | 179 | $mini_cart_body = self::mini_cart_content(); |
180 | 180 | } |
181 | 181 | ob_start(); |
182 | - if( !empty($type) && $type == 'fixed' ) { |
|
183 | - require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart") ); |
|
182 | + if (!empty($type) && $type == 'fixed') { |
|
183 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart")); |
|
184 | 184 | } |
185 | 185 | else { |
186 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart") ); |
|
186 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart")); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $output = ob_get_contents(); |
@@ -192,37 +192,37 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | /** Mini cart Content **/ |
195 | - public static function mini_cart_content( $type = '') { |
|
196 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
197 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
195 | + public static function mini_cart_content($type = '') { |
|
196 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
197 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
198 | 198 | $output = ''; |
199 | - if ( !empty($cart_content) ) { |
|
200 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
201 | - if ( !empty($cart_items) ) { |
|
202 | - if ( !empty($cart_content['coupon_id']) ) { |
|
203 | - $coupon_title = get_the_title( $cart_content['coupon_id']); |
|
204 | - $coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] ); |
|
199 | + if (!empty($cart_content)) { |
|
200 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
201 | + if (!empty($cart_items)) { |
|
202 | + if (!empty($cart_content['coupon_id'])) { |
|
203 | + $coupon_title = get_the_title($cart_content['coupon_id']); |
|
204 | + $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); |
|
205 | 205 | } |
206 | - $order_total_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
207 | - $shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? $cart_content['order_shipping_cost'] : 0; |
|
208 | - $total_ati = $total_cart = ( !empty($cart_content['order_amount_to_pay_now']) ) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
206 | + $order_total_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
207 | + $shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? $cart_content['order_shipping_cost'] : 0; |
|
208 | + $total_ati = $total_cart = (!empty($cart_content['order_amount_to_pay_now'])) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
209 | 209 | |
210 | 210 | ob_start(); |
211 | - if( !empty($type) && $type == 'fixed' ) { |
|
212 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content") ); |
|
211 | + if (!empty($type) && $type == 'fixed') { |
|
212 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content")); |
|
213 | 213 | } |
214 | 214 | else { |
215 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content") ); |
|
215 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content")); |
|
216 | 216 | } |
217 | 217 | $output = ob_get_contents(); |
218 | 218 | ob_end_clean(); |
219 | 219 | } |
220 | 220 | else { |
221 | - $output = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
221 | + $output = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | else { |
225 | - $output = '<div class="wps-alert-info">' . __( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
225 | + $output = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
226 | 226 | } |
227 | 227 | return $output; |
228 | 228 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | function display_resume_cart() { |
232 | 232 | $cart_summary_content = self::resume_cart_content(); |
233 | 233 | ob_start(); |
234 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart") ); |
|
234 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart")); |
|
235 | 235 | $output = ob_get_contents(); |
236 | 236 | ob_end_clean(); |
237 | 237 | return $output; |
@@ -240,29 +240,29 @@ discard block |
||
240 | 240 | /** Resume cart Content **/ |
241 | 241 | public static function resume_cart_content() { |
242 | 242 | $output = ''; |
243 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
244 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
245 | - if ( !empty($cart_content) ) { |
|
246 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
247 | - if ( !empty($cart_items) ) { |
|
248 | - if ( !empty($cart_content['coupon_id']) ) { |
|
249 | - $coupon_title = get_the_title( $cart_content['coupon_id']); |
|
250 | - $coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] ); |
|
243 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
244 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
245 | + if (!empty($cart_content)) { |
|
246 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
247 | + if (!empty($cart_items)) { |
|
248 | + if (!empty($cart_content['coupon_id'])) { |
|
249 | + $coupon_title = get_the_title($cart_content['coupon_id']); |
|
250 | + $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); |
|
251 | 251 | } |
252 | - $order_total_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
253 | - $shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? $cart_content['order_shipping_cost'] : 0; |
|
254 | - $total_ati = $total_cart = ( !empty($cart_content['order_amount_to_pay_now']) ) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
252 | + $order_total_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
253 | + $shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? $cart_content['order_shipping_cost'] : 0; |
|
254 | + $total_ati = $total_cart = (!empty($cart_content['order_amount_to_pay_now'])) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
255 | 255 | ob_start(); |
256 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content") ); |
|
256 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content")); |
|
257 | 257 | $output = ob_get_contents(); |
258 | 258 | ob_end_clean(); |
259 | 259 | } |
260 | 260 | else { |
261 | - $resume_cart_body = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
261 | + $resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | else { |
265 | - $resume_cart_body ='<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
265 | + $resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
266 | 266 | } |
267 | 267 | return $output; |
268 | 268 | } |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | * @param array cart |
273 | 273 | * @return int total items |
274 | 274 | */ |
275 | - public static function total_cart_items( $cart_items ) { |
|
275 | + public static function total_cart_items($cart_items) { |
|
276 | 276 | $count = 0; |
277 | - if( !empty($cart_items) && is_array( $cart_items )) { |
|
278 | - foreach( $cart_items as $cart_item ) { |
|
277 | + if (!empty($cart_items) && is_array($cart_items)) { |
|
278 | + foreach ($cart_items as $cart_item) { |
|
279 | 279 | $count += $cart_item['item_qty']; |
280 | 280 | } |
281 | 281 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * Reload Persistent cart for logged user and if a persistent cart exists |
287 | 287 | */ |
288 | 288 | function load_cart_from_db() { |
289 | - if(empty($_SESSION['cart']) && get_current_user_id() ) { |
|
289 | + if (empty($_SESSION['cart']) && get_current_user_id()) { |
|
290 | 290 | $cart = $this->get_persistent_cart(); |
291 | 291 | $_SESSION['cart'] = $cart; |
292 | 292 | $_SESSION['coupon'] = 0; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @return array() |
299 | 299 | */ |
300 | 300 | function get_persistent_cart() { |
301 | - if(get_current_user_id()) |
|
301 | + if (get_current_user_id()) |
|
302 | 302 | $cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true); |
303 | 303 | return empty($cart) ? array() : $cart; |
304 | 304 | } |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * Save the persistent cart when updated |
315 | 315 | */ |
316 | 316 | function persistent_cart_update() { |
317 | - if(get_current_user_id()) |
|
318 | - update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array( |
|
317 | + if (get_current_user_id()) |
|
318 | + update_user_meta(get_current_user_id(), '_wpshop_persistent_cart', array( |
|
319 | 319 | 'cart' => $_SESSION['cart'], |
320 | 320 | )); |
321 | 321 | } |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * Delete the persistent cart |
325 | 325 | */ |
326 | 326 | function persistent_cart_destroy() { |
327 | - delete_user_meta( get_current_user_id(), '_wpshop_persistent_cart' ); |
|
327 | + delete_user_meta(get_current_user_id(), '_wpshop_persistent_cart'); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -344,60 +344,60 @@ discard block |
||
344 | 344 | * |
345 | 345 | * @return mixed If an error occured return a alert message. In the other case if the quantity is correctly set return true |
346 | 346 | */ |
347 | - function set_product_qty($product_id, $quantity, $combined_variation_id = '', $cart = array(), $from_admin = '', $order_id = '' ) { |
|
347 | + function set_product_qty($product_id, $quantity, $combined_variation_id = '', $cart = array(), $from_admin = '', $order_id = '') { |
|
348 | 348 | // Init Cart var |
349 | - $cart = ( !empty($cart) ) ? $cart : $_SESSION['cart']; |
|
350 | - $wpshop_cart_type = ( !empty($cart) && !empty($cart['cart_type']) ) ? $cart['cart_type'] : 'normal'; |
|
349 | + $cart = (!empty($cart)) ? $cart : $_SESSION['cart']; |
|
350 | + $wpshop_cart_type = (!empty($cart) && !empty($cart['cart_type'])) ? $cart['cart_type'] : 'normal'; |
|
351 | 351 | $parent_product_id = $product_id; |
352 | 352 | $selected_variations = array(); |
353 | 353 | |
354 | 354 | // Test if Product exists |
355 | - if( !empty($product_id) && !empty($cart['order_items']) && !empty( $cart['order_items'][ $product_id ] ) ) { |
|
355 | + if (!empty($product_id) && !empty($cart['order_items']) && !empty($cart['order_items'][$product_id])) { |
|
356 | 356 | // Test if is composed product ID |
357 | 357 | $pid = $product_id; |
358 | - if (strpos($pid,'__') !== false) { |
|
359 | - $product_data_id = explode( '__', $pid ); |
|
360 | - $pid = ( !empty( $product_data_id ) && !empty( $product_data_id[1] ) ) ? $product_data_id[1] : $cart['order_items'][ $product_id ]['item_id']; |
|
358 | + if (strpos($pid, '__') !== false) { |
|
359 | + $product_data_id = explode('__', $pid); |
|
360 | + $pid = (!empty($product_data_id) && !empty($product_data_id[1])) ? $product_data_id[1] : $cart['order_items'][$product_id]['item_id']; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | // Checking stock |
364 | 364 | $wps_product_ctr = new wps_product_ctr(); |
365 | - $return = $wps_product_ctr->check_stock($pid, $quantity, $combined_variation_id ); |
|
366 | - if( $return !== true) { |
|
365 | + $return = $wps_product_ctr->check_stock($pid, $quantity, $combined_variation_id); |
|
366 | + if ($return !== true) { |
|
367 | 367 | return $return; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // Check Variations to construct product to add to cart |
371 | - if( !empty($product_data_id) || get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
371 | + if (!empty($product_data_id) || get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
372 | 372 | // Check Parent ID |
373 | - if( get_post_type($cart['order_items'][ $product_id ]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) { |
|
374 | - $parent_product_id = $cart['order_items'][ $product_id ]['item_id']; |
|
373 | + if (get_post_type($cart['order_items'][$product_id]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
374 | + $parent_product_id = $cart['order_items'][$product_id]['item_id']; |
|
375 | 375 | } |
376 | 376 | else { |
377 | - $parent_data = wpshop_products::get_parent_variation( $cart['order_items'][ $product_id ]['item_id'] ); |
|
377 | + $parent_data = wpshop_products::get_parent_variation($cart['order_items'][$product_id]['item_id']); |
|
378 | 378 | $parent_post = $parent_data['parent_post']; |
379 | 379 | $parent_product_id = $parent_post->ID; |
380 | 380 | } |
381 | - if( !empty($product_data_id) ) { |
|
382 | - unset( $product_data_id[0] ); |
|
383 | - if( !empty($product_data_id) ) { |
|
384 | - foreach( $product_data_id as $i ) { |
|
385 | - $mtdt = get_post_meta( $i, '_wpshop_variations_attribute_def', true ); |
|
386 | - if( !empty($mtdt) && is_array($mtdt) ) { |
|
387 | - $selected_variations = array_merge( $selected_variations, $mtdt ); |
|
381 | + if (!empty($product_data_id)) { |
|
382 | + unset($product_data_id[0]); |
|
383 | + if (!empty($product_data_id)) { |
|
384 | + foreach ($product_data_id as $i) { |
|
385 | + $mtdt = get_post_meta($i, '_wpshop_variations_attribute_def', true); |
|
386 | + if (!empty($mtdt) && is_array($mtdt)) { |
|
387 | + $selected_variations = array_merge($selected_variations, $mtdt); |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
391 | 391 | } |
392 | 392 | else { |
393 | - $selected_variations = get_post_meta( $product_id, '_wpshop_variations_attribute_def', true ); |
|
393 | + $selected_variations = get_post_meta($product_id, '_wpshop_variations_attribute_def', true); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | - $formatted_product = $this->prepare_product_to_add_to_cart( $parent_product_id, $quantity, $selected_variations ); |
|
397 | + $formatted_product = $this->prepare_product_to_add_to_cart($parent_product_id, $quantity, $selected_variations); |
|
398 | 398 | $product_to_add_to_cart = $formatted_product[0]; |
399 | 399 | $new_pid = $product_id; |
400 | - $return = $this->add_to_cart( $product_to_add_to_cart, array( $new_pid => $quantity ), $wpshop_cart_type, array(), $from_admin, $cart, $order_id ); |
|
400 | + $return = $this->add_to_cart($product_to_add_to_cart, array($new_pid => $quantity), $wpshop_cart_type, array(), $from_admin, $cart, $order_id); |
|
401 | 401 | return $return; |
402 | 402 | } |
403 | 403 | else { |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | * @param string product_id contains the id of the product to add to the cart |
411 | 411 | * @param string quantity contains the quantity of the item to add |
412 | 412 | */ |
413 | - function add_to_cart( $product_list, $quantity, $type='normal', $extra_params=array(), $from_admin = '', $order_meta = '', $order_id = '' ) { |
|
413 | + function add_to_cart($product_list, $quantity, $type = 'normal', $extra_params = array(), $from_admin = '', $order_meta = '', $order_id = '') { |
|
414 | 414 | global $wpdb; |
415 | 415 | |
416 | 416 | $count_items = 0; |
417 | 417 | |
418 | 418 | /** Check if a cart already exist. If there is already a cart that is not the same type (could be a cart or a quotation) */ |
419 | - if ( empty( $from_admin ) ){ |
|
420 | - if(isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type'] ) { |
|
419 | + if (empty($from_admin)) { |
|
420 | + if (isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type']) { |
|
421 | 421 | return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop'); |
422 | 422 | } |
423 | 423 | else { |
@@ -430,19 +430,19 @@ discard block |
||
430 | 430 | $order_items = array(); |
431 | 431 | |
432 | 432 | foreach ($product_list as $pid => $product_more_content) { |
433 | - if ( count($product_list) == 1 ) { |
|
434 | - if ( !isset( $quantity[$pid] ) ) $quantity[$pid] = 1; |
|
433 | + if (count($product_list) == 1) { |
|
434 | + if (!isset($quantity[$pid])) $quantity[$pid] = 1; |
|
435 | 435 | $product = wpshop_products::get_product_data($product_more_content['id'], false, '"publish", "free_product"'); |
436 | 436 | /** Check if the selected product exist */ |
437 | - if ( $product === false ) return __('This product does not exist', 'wpshop'); |
|
437 | + if ($product === false) return __('This product does not exist', 'wpshop'); |
|
438 | 438 | |
439 | 439 | /** Get information about the product price */ |
440 | 440 | $product_price_check = wpshop_prices::get_product_price($product, 'check_only'); |
441 | - if ( $product_price_check !== true ) return $product_price_check; |
|
441 | + if ($product_price_check !== true) return $product_price_check; |
|
442 | 442 | |
443 | 443 | $the_quantity = 1; |
444 | 444 | |
445 | - if ( !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) ) { |
|
445 | + if (!empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0])) { |
|
446 | 446 | /** Get the asked quantity for each product and check if there is enough stock */ |
447 | 447 | $the_quantity = $quantity[$pid]; |
448 | 448 | } |
@@ -454,129 +454,129 @@ discard block |
||
454 | 454 | //$quantity[$pid] = $the_quantity; |
455 | 455 | |
456 | 456 | $variation_id = 0; |
457 | - if ( !empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' ){ |
|
457 | + if (!empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined') { |
|
458 | 458 | $variation_id = $product_more_content['variations'][0]; |
459 | 459 | } |
460 | 460 | //$quantity_to_check = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($_SESSION['cart']['order_items'][$pid]) && !empty($_SESSION['cart']['order_items'][$pid]['item_qty']) ) ? $_SESSION['cart']['order_items'][$pid]['item_qty'] : $the_quantity; |
461 | 461 | |
462 | 462 | $wps_product_ctr = new wps_product_ctr(); |
463 | - $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id ); |
|
464 | - if ( $product_stock !== true ) { |
|
463 | + $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id); |
|
464 | + if ($product_stock !== true) { |
|
465 | 465 | return $product_stock; |
466 | 466 | } |
467 | - $count_items += (int) $product_more_content['product_qty']; |
|
467 | + $count_items += (int)$product_more_content['product_qty']; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | $order_items[$pid]['product_id'] = $product_more_content['id']; |
471 | 471 | $order_items[$pid]['product_qty'] = $the_quantity; |
472 | 472 | |
473 | 473 | /** For product with variation */ |
474 | - $order_items[$pid]['product_variation_type'] = !empty( $product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
474 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
475 | 475 | $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
476 | 476 | $order_items[$pid]['product_variation'] = ''; |
477 | - if ( !empty($product_more_content['variations']) ) { |
|
478 | - foreach ( $product_more_content['variations'] as $variation_id) { |
|
477 | + if (!empty($product_more_content['variations'])) { |
|
478 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
479 | 479 | $order_items[$pid]['product_variation'][] = $variation_id; |
480 | 480 | } |
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - $current_cart = ( !empty( $order_meta )) ? $order_meta : array(); |
|
484 | + $current_cart = (!empty($order_meta)) ? $order_meta : array(); |
|
485 | 485 | |
486 | - $current_cart_order_items = isset( $current_cart['order_items'] ) ? $current_cart['order_items'] : array(); |
|
486 | + $current_cart_order_items = isset($current_cart['order_items']) ? $current_cart['order_items'] : array(); |
|
487 | 487 | |
488 | - foreach( $current_cart_order_items as $item_id => $item ) { |
|
489 | - if( !array_key_exists( $item_id, $order_items ) ) { |
|
488 | + foreach ($current_cart_order_items as $item_id => $item) { |
|
489 | + if (!array_key_exists($item_id, $order_items)) { |
|
490 | 490 | $count_items += $item['item_qty']; |
491 | 491 | } |
492 | 492 | } |
493 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
494 | - if( !empty( $wpshop_cart_option ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) && (int) $count_items > (int) $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) { |
|
493 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
494 | + if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed']) && !empty($wpshop_cart_option['total_nb_of_item_allowed'][0]) && (int)$count_items > (int)$wpshop_cart_option['total_nb_of_item_allowed'][0]) { |
|
495 | 495 | return __('No more products can be added to your cart.', 'wpshop'); |
496 | 496 | } |
497 | 497 | |
498 | - $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart ); |
|
498 | + $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart); |
|
499 | 499 | |
500 | - if( empty($from_admin) ) { |
|
500 | + if (empty($from_admin)) { |
|
501 | 501 | self::store_cart_in_session($order); |
502 | 502 | /** Store the cart into database for connected user */ |
503 | - if ( get_current_user_id() ) { |
|
503 | + if (get_current_user_id()) { |
|
504 | 504 | $this->persistent_cart_update(); |
505 | 505 | } |
506 | 506 | } |
507 | 507 | else { |
508 | - update_post_meta($order_id, '_order_postmeta', $order ); |
|
508 | + update_post_meta($order_id, '_order_postmeta', $order); |
|
509 | 509 | |
510 | 510 | } |
511 | 511 | return 'success'; |
512 | 512 | } |
513 | 513 | |
514 | - function prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected = array() ) { |
|
514 | + function prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected = array()) { |
|
515 | 515 | $product_price = ''; |
516 | 516 | $product_data = wpshop_products::get_product_data($product_id); |
517 | 517 | |
518 | 518 | // Free vars |
519 | - if ( !empty($wpshop_variation_selected['free']) ){ |
|
519 | + if (!empty($wpshop_variation_selected['free'])) { |
|
520 | 520 | $free_variations = $wpshop_variation_selected['free']; |
521 | 521 | unset($wpshop_variation_selected['free']); |
522 | 522 | } |
523 | 523 | |
524 | 524 | // If product have many variations |
525 | - if ( count($wpshop_variation_selected ) > 1 ) { |
|
526 | - if ( !empty($wpshop_variation_selected) ) { |
|
527 | - $product_with_variation = wpshop_products::get_variation_by_priority( $wpshop_variation_selected, $product_id, true ); |
|
525 | + if (count($wpshop_variation_selected) > 1) { |
|
526 | + if (!empty($wpshop_variation_selected)) { |
|
527 | + $product_with_variation = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
528 | 528 | } |
529 | 529 | |
530 | - if ( !empty($product_with_variation[$product_id]['variations']) ) { |
|
530 | + if (!empty($product_with_variation[$product_id]['variations'])) { |
|
531 | 531 | $product = $product_data; |
532 | 532 | $has_variation = true; |
533 | 533 | $head_product_id = $product_id; |
534 | 534 | |
535 | - if ( !empty($product_with_variation[$product_id]['variations']) && ( count($product_with_variation[$product_id]['variations']) == 1 ) && ($product_with_variation[$product_id]['variation_priority'] != 'single') ) { |
|
535 | + if (!empty($product_with_variation[$product_id]['variations']) && (count($product_with_variation[$product_id]['variations']) == 1) && ($product_with_variation[$product_id]['variation_priority'] != 'single')) { |
|
536 | 536 | $product_id = $product_with_variation[$product_id]['variations'][0]; |
537 | 537 | } |
538 | 538 | $product = wpshop_products::get_product_data($product_id, true); |
539 | 539 | |
540 | - $the_product = array_merge( array( |
|
540 | + $the_product = array_merge(array( |
|
541 | 541 | 'product_id' => $product_id, |
542 | 542 | 'product_qty' => $product_qty |
543 | 543 | ), $product); |
544 | 544 | |
545 | 545 | /* Add variation to product into cart for storage */ |
546 | - if ( !empty($product_with_variation[$head_product_id]['variations']) ) { |
|
547 | - $the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority']) ); |
|
546 | + if (!empty($product_with_variation[$head_product_id]['variations'])) { |
|
547 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority'])); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | $product_data = $the_product; |
551 | 551 | } |
552 | 552 | } |
553 | 553 | |
554 | - $product_to_add_to_cart = array( $product_id => array( 'id' => $product_id, 'product_qty' => $product_qty ) ); |
|
554 | + $product_to_add_to_cart = array($product_id => array('id' => $product_id, 'product_qty' => $product_qty)); |
|
555 | 555 | |
556 | - if ( !empty( $wpshop_variation_selected ) ) { |
|
557 | - $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true ); |
|
558 | - if ( !empty($variation_calculator[$product_id]) ) { |
|
556 | + if (!empty($wpshop_variation_selected)) { |
|
557 | + $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
558 | + if (!empty($variation_calculator[$product_id])) { |
|
559 | 559 | $product_to_add_to_cart[$product_id] = array_merge($product_to_add_to_cart[$product_id], $variation_calculator[$product_id]); |
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | 563 | $new_pid = $product_id; |
564 | 564 | //Create custom ID on single variations Product |
565 | - if( !empty($product_to_add_to_cart[$product_id]['variations']) && count( $product_to_add_to_cart[$product_id]['variations'] ) && !empty( $product_to_add_to_cart[$product_id]['variation_priority'] ) && $product_to_add_to_cart[$product_id]['variation_priority'] == 'single' ) { |
|
565 | + if (!empty($product_to_add_to_cart[$product_id]['variations']) && count($product_to_add_to_cart[$product_id]['variations']) && !empty($product_to_add_to_cart[$product_id]['variation_priority']) && $product_to_add_to_cart[$product_id]['variation_priority'] == 'single') { |
|
566 | 566 | $tmp_obj = $product_to_add_to_cart[$product_id]; |
567 | - unset( $product_to_add_to_cart[$product_id] ); |
|
567 | + unset($product_to_add_to_cart[$product_id]); |
|
568 | 568 | $key = $product_id; |
569 | - foreach( $tmp_obj['variations'] as $variation_key) { |
|
570 | - $key.= '__'. $variation_key; |
|
569 | + foreach ($tmp_obj['variations'] as $variation_key) { |
|
570 | + $key .= '__' . $variation_key; |
|
571 | 571 | } |
572 | 572 | $product_to_add_to_cart[$key] = $tmp_obj; |
573 | 573 | $new_pid = $key; |
574 | 574 | } |
575 | 575 | // Add free variations |
576 | - if( !empty($free_variations) ) { |
|
576 | + if (!empty($free_variations)) { |
|
577 | 577 | $product_to_add_to_cart[$new_pid]['free_variation'] = $free_variations; |
578 | 578 | } |
579 | - return array( $product_to_add_to_cart, $new_pid ); |
|
579 | + return array($product_to_add_to_cart, $new_pid); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -587,67 +587,67 @@ discard block |
||
587 | 587 | * @param boolean $from_admin |
588 | 588 | * @return array |
589 | 589 | */ |
590 | - function calcul_cart_information( $product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false ) { |
|
590 | + function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) { |
|
591 | 591 | // Price piloting option |
592 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
592 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
593 | 593 | |
594 | 594 | // Init vars |
595 | - $cart_infos = ( !empty($current_cart) ) ? $current_cart : ( ( !empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ) ? $_SESSION['cart'] : array() ); |
|
596 | - $cart_items = ( !empty($current_cart) && !empty($current_cart['order_items']) ) ? $current_cart['order_items'] : array(); |
|
597 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
595 | + $cart_infos = (!empty($current_cart)) ? $current_cart : ((!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin) ? $_SESSION['cart'] : array()); |
|
596 | + $cart_items = (!empty($current_cart) && !empty($current_cart['order_items'])) ? $current_cart['order_items'] : array(); |
|
597 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
598 | 598 | $order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array(); |
599 | 599 | $total_weight = $nb_of_items = $order_shipping_cost_by_article = 0; |
600 | 600 | $order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0; |
601 | 601 | $cart_infos['order_amount_to_pay_now'] = 0; |
602 | 602 | |
603 | 603 | // If Product list is not empty, add products to order |
604 | - if( !empty($product_list) ) { |
|
605 | - foreach ( $product_list as $product_id => $d ) { |
|
604 | + if (!empty($product_list)) { |
|
605 | + foreach ($product_list as $product_id => $d) { |
|
606 | 606 | $product_key = $product_id; |
607 | - if( isset( $d['product_qty']) ) { |
|
607 | + if (isset($d['product_qty'])) { |
|
608 | 608 | // Formate datas |
609 | 609 | $product_id = $head_product_id = $d['product_id']; |
610 | 610 | $product_qty = $d['product_qty']; |
611 | 611 | $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
612 | 612 | |
613 | 613 | // If product is a single variation product |
614 | - if ( !empty($product_variation) && ( count($product_variation) == 1 ) ) { |
|
614 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
615 | 615 | $product_id = $product_variation[0]; |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Construct final product |
619 | 619 | $product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"'); |
620 | - $the_product = array_merge( array('product_id' => $d['product_id'], 'product_qty' => $product_qty ), $product); |
|
620 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => $product_qty), $product); |
|
621 | 621 | |
622 | 622 | // Add variation to product into cart for storage |
623 | - if ( !empty($product_variation) ) { |
|
624 | - $the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']) ); |
|
623 | + if (!empty($product_variation)) { |
|
624 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | // Free Variations Checking |
628 | - if ( !empty( $d['free_variation'] ) ) { |
|
628 | + if (!empty($d['free_variation'])) { |
|
629 | 629 | $the_product['item_meta']['free_variation'] = $d['free_variation']; |
630 | 630 | $head_product_id = $the_product['product_id']; |
631 | 631 | } |
632 | 632 | |
633 | 633 | // If product is a variation, we check parent product general |
634 | - if( get_post_type( $the_product['product_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
635 | - $parent_def = wpshop_products::get_parent_variation( $the_product['product_id'] ); |
|
636 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
637 | - $variation_def = get_post_meta( $parent_def['parent_post']->ID, '_wpshop_variation_defining', true ); |
|
634 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
635 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
636 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
637 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
638 | 638 | $parent_meta = $parent_def['parent_post_meta']; |
639 | - if( !empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority'] ) && !empty($variation_def['options']['price_behaviour']) && in_array( 'addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1 ) { |
|
640 | - $the_product['product_price'] += number_format( str_replace( ',', '.', $parent_meta['product_price'] ), 2, '.', '' ); |
|
641 | - $the_product['price_ht'] += number_format( str_replace( ',', '.',$parent_meta['price_ht']) , 2, '.', '' ); |
|
642 | - $the_product['tva'] += number_format( str_replace( ',', '.', $parent_meta['tva']) , 2, '.', '' ); |
|
639 | + if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) { |
|
640 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
641 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
642 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
643 | 643 | } |
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
647 | 647 | // Delete product if its qty is equals to zero, else add this product to order |
648 | - if( empty( $d['product_qty'] ) ) { |
|
649 | - unset( $cart_items[$product_key] ); |
|
650 | - unset( $cart_infos['order_items'][$product_key] ); |
|
648 | + if (empty($d['product_qty'])) { |
|
649 | + unset($cart_items[$product_key]); |
|
650 | + unset($cart_infos['order_items'][$product_key]); |
|
651 | 651 | } |
652 | 652 | else { |
653 | 653 | $wps_orders = new wps_orders_ctr(); |
@@ -658,16 +658,16 @@ discard block |
||
658 | 658 | } |
659 | 659 | |
660 | 660 | // Add automaticaly Add-to-cart Products |
661 | - $cart_items = $this->add_automaticaly_product_to_cart( $cart_items ); |
|
661 | + $cart_items = $this->add_automaticaly_product_to_cart($cart_items); |
|
662 | 662 | |
663 | 663 | // Calcul Cart Informations |
664 | 664 | $cart_has_special_product = false; |
665 | - if( !empty($cart_items) && is_array($cart_items) ) { |
|
666 | - foreach( $cart_items as $item_id => $item ) { |
|
665 | + if (!empty($cart_items) && is_array($cart_items)) { |
|
666 | + foreach ($cart_items as $item_id => $item) { |
|
667 | 667 | |
668 | - if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) { |
|
668 | + if (!empty($item['item_amount_to_pay_now'])) { |
|
669 | 669 | $cart_has_special_product = true; |
670 | - $cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] ); |
|
670 | + $cart_infos['order_amount_to_pay_now'] += ($item['item_amount_to_pay_now'] * $item['item_qty']); |
|
671 | 671 | } |
672 | 672 | else { |
673 | 673 | $cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc']; |
@@ -676,11 +676,11 @@ discard block |
||
676 | 676 | $order_total_ht += $item['item_total_ht']; |
677 | 677 | $order_total_ttc += $item['item_total_ttc']; |
678 | 678 | // VAT |
679 | - if( !empty($order_tva[ $item['item_tva_rate'] ]) ) { |
|
680 | - $order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount']; |
|
679 | + if (!empty($order_tva[$item['item_tva_rate']])) { |
|
680 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
681 | 681 | } |
682 | 682 | else { |
683 | - $order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount']; |
|
683 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
684 | 684 | } |
685 | 685 | } |
686 | 686 | } |
@@ -694,13 +694,13 @@ discard block |
||
694 | 694 | $cart_infos['order_total_ttc'] = $order_total_ttc; |
695 | 695 | |
696 | 696 | // Calcul Shipping cost |
697 | - if( !$from_admin && empty( $cart_infos['order_shipping_cost_fixe'] ) && empty($_SESSION[ 'wps-pos-addon' ]) ) { |
|
697 | + if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe']) && empty($_SESSION['wps-pos-addon'])) { |
|
698 | 698 | $wps_shipping = new wps_shipping(); |
699 | - $total_cart_ht_or_ttc_regarding_config = ( !empty($price_piloting) && $price_piloting == 'HT' ) ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
700 | - $cart_weight = $wps_shipping->calcul_cart_weight( $cart_infos['order_items'] ); |
|
701 | - $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost( $cart_infos['order_items'] ); |
|
702 | - foreach( $cart_infos['order_items'] as $item ) { |
|
703 | - if( !empty($item['item_is_downloadable_']) && ( __( $item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
|
699 | + $total_cart_ht_or_ttc_regarding_config = (!empty($price_piloting) && $price_piloting == 'HT') ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
700 | + $cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']); |
|
701 | + $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']); |
|
702 | + foreach ($cart_infos['order_items'] as $item) { |
|
703 | + if (!empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) { |
|
704 | 704 | $is_downloadable_products = 'is_downloadable_'; |
705 | 705 | } else { |
706 | 706 | $is_downloadable_products = ''; |
@@ -712,39 +712,39 @@ discard block |
||
712 | 712 | } |
713 | 713 | |
714 | 714 | // If Price piloting is ET, calcul VAT on Shipping cost |
715 | - if ( !empty($price_piloting) && $price_piloting == 'HT') { |
|
716 | - $shipping_cost_vat = ( !empty($cart_infos['order_shipping_cost']) ) ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * number_format( $cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
715 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
716 | + $shipping_cost_vat = (!empty($cart_infos['order_shipping_cost'])) ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
717 | 717 | $order_tva['VAT_shipping_cost'] = $shipping_cost_vat; |
718 | 718 | } |
719 | 719 | |
720 | 720 | // Calcul VAT Total |
721 | - if( !empty($order_tva) ) { |
|
722 | - foreach( $order_tva as $vat_rate => $vat_value ) { |
|
721 | + if (!empty($order_tva)) { |
|
722 | + foreach ($order_tva as $vat_rate => $vat_value) { |
|
723 | 723 | $total_vat += $vat_value; |
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | 727 | // Recap totals |
728 | - $cart_infos['order_total_ttc'] = ( $cart_infos['order_total_ht'] + ( !empty( $cart_infos ) && !empty( $cart_infos[ 'order_shipping_cost' ] ) ? $cart_infos['order_shipping_cost'] : 0 ) + $total_vat ); |
|
728 | + $cart_infos['order_total_ttc'] = ($cart_infos['order_total_ht'] + (!empty($cart_infos) && !empty($cart_infos['order_shipping_cost']) ? $cart_infos['order_shipping_cost'] : 0) + $total_vat); |
|
729 | 729 | $cart_infos['order_grand_total_before_discount'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc']; |
730 | 730 | |
731 | 731 | // Total to pay now |
732 | 732 | $total_received = 0; |
733 | - if( !empty( $cart_infos['order_payment']['received'] ) ) { |
|
734 | - foreach( $cart_infos['order_payment']['received'] as $received ) { |
|
735 | - $total_received += ( ( !empty($received['status']) && ( $received['status'] == 'payment_received') && !empty($received['received_amount']) ) ? $received['received_amount'] : 0 ); |
|
733 | + if (!empty($cart_infos['order_payment']['received'])) { |
|
734 | + foreach ($cart_infos['order_payment']['received'] as $received) { |
|
735 | + $total_received += ((!empty($received['status']) && ($received['status'] == 'payment_received') && !empty($received['received_amount'])) ? $received['received_amount'] : 0); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | $cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] - $total_received; |
739 | 739 | |
740 | 740 | // Apply cart rules |
741 | - $cart_rule = wpshop_cart_rules::get_cart_rule( $cart_infos['order_grand_total'] ); |
|
742 | - if( $cart_rule['cart_rule_exist'] ) { |
|
743 | - if ( !empty( $cart_rule['cart_rule_info']['discount_type'] ) ) { |
|
744 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount' ) { |
|
741 | + $cart_rule = wpshop_cart_rules::get_cart_rule($cart_infos['order_grand_total']); |
|
742 | + if ($cart_rule['cart_rule_exist']) { |
|
743 | + if (!empty($cart_rule['cart_rule_info']['discount_type'])) { |
|
744 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount') { |
|
745 | 745 | $cart_infos['order_discount_type'] = 'amount'; |
746 | 746 | } |
747 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'percent_discount' ) { |
|
747 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'percent_discount') { |
|
748 | 748 | $cart_infos['order_discount_type'] = 'percent'; |
749 | 749 | } |
750 | 750 | } |
@@ -752,15 +752,15 @@ discard block |
||
752 | 752 | } |
753 | 753 | |
754 | 754 | // Apply coupons |
755 | - if( !empty( $_SESSION['cart']) && !$from_admin ) { |
|
756 | - if( !empty($_SESSION['cart']['coupon_id']) ) { |
|
755 | + if (!empty($_SESSION['cart']) && !$from_admin) { |
|
756 | + if (!empty($_SESSION['cart']['coupon_id'])) { |
|
757 | 757 | $wps_coupon_mdl = new wps_coupon_model(); |
758 | - $coupon = $wps_coupon_mdl->get_coupon_data( $_SESSION['cart']['coupon_id'] ); |
|
759 | - if( !empty($coupon) && !empty($coupon['wpshop_coupon_code']) ) { |
|
758 | + $coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']); |
|
759 | + if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) { |
|
760 | 760 | $wps_coupon = new wps_coupon_ctr(); |
761 | - $coupon_checking = $wps_coupon->applyCoupon( $coupon['wpshop_coupon_code'] ); |
|
761 | + $coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']); |
|
762 | 762 | // If Coupon conditions are Ok |
763 | - if( !empty($coupon_checking) && !empty( $coupon_checking['status'] ) && ( true == $coupon_checking['status'] ) ) { |
|
763 | + if (!empty($coupon_checking) && !empty($coupon_checking['status']) && (true == $coupon_checking['status'])) { |
|
764 | 764 | $cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type']; |
765 | 765 | $cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value']; |
766 | 766 | } |
@@ -769,51 +769,51 @@ discard block |
||
769 | 769 | } |
770 | 770 | |
771 | 771 | // Checking Discounts |
772 | - if( !empty($cart_infos['order_discount_type']) && isset( $cart_infos['order_discount_value'] ) ) { |
|
772 | + if (!empty($cart_infos['order_discount_type']) && isset($cart_infos['order_discount_value'])) { |
|
773 | 773 | // Calcul discount on Order |
774 | 774 | switch ($cart_infos['order_discount_type']) { |
775 | 775 | case 'amount': |
776 | - $cart_infos['order_discount_amount_total_cart'] = number_format( str_replace( ',', '.', $cart_infos['order_discount_value'] ), 2, '.', ''); |
|
776 | + $cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', ''); |
|
777 | 777 | break; |
778 | 778 | case 'percent': |
779 | - $cart_infos['order_discount_amount_total_cart'] = number_format( $cart_infos['order_grand_total'], 2, '.', '') * ( number_format( str_replace( ',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100); |
|
779 | + $cart_infos['order_discount_amount_total_cart'] = number_format($cart_infos['order_grand_total'], 2, '.', '') * (number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100); |
|
780 | 780 | break; |
781 | 781 | } |
782 | - if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) { |
|
782 | + if (number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format($cart_infos['order_grand_total'], 2, '.', '')) { |
|
783 | 783 | $cart_infos['order_grand_total'] = 0; |
784 | 784 | } |
785 | 785 | else { |
786 | - $cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
786 | + $cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
787 | 787 | } |
788 | - $cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
788 | + $cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | // Apply Partial Payments |
792 | 792 | $wpshop_payment = new wpshop_payment(); |
793 | - if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) { |
|
794 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' ); |
|
793 | + if (!empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation') { |
|
794 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total'], 'for_quotation'); |
|
795 | 795 | } |
796 | 796 | else { |
797 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] ); |
|
797 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']); |
|
798 | 798 | } |
799 | - if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) { |
|
799 | + if (!empty($partial_payment['amount_to_pay']) && (empty($cart_infos['order_status']) || $cart_infos['order_status'] == 'awaiting_payment') && (empty($product_partial_payment_amount))) { |
|
800 | 800 | unset($partial_payment['display']); |
801 | - $cart_infos['order_partial_payment'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
802 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
801 | + $cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
802 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
803 | 803 | } |
804 | 804 | // Apply Partial Payments : Subscription part. |
805 | - elseif ( ! empty( $cart_has_special_product ) ) { |
|
806 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $cart_infos['order_amount_to_pay_now'] ), 2, '.', ''); |
|
805 | + elseif (!empty($cart_has_special_product)) { |
|
806 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $cart_infos['order_amount_to_pay_now']), 2, '.', ''); |
|
807 | 807 | $cart_infos['order_product_partial_payment'] = 'subscription'; |
808 | 808 | } |
809 | 809 | |
810 | 810 | // Cart Type |
811 | - if ( isset( $_SESSION['cart']['cart_type'] ) ) { |
|
811 | + if (isset($_SESSION['cart']['cart_type'])) { |
|
812 | 812 | $cart_infos['cart_type'] = $_SESSION['cart']['cart_type']; |
813 | 813 | } |
814 | 814 | |
815 | 815 | // Apply Extra actions on cart infos |
816 | - $cart_infos = apply_filters( 'wps_extra_calcul_in_cart', $cart_infos, $_SESSION ); |
|
816 | + $cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION); |
|
817 | 817 | |
818 | 818 | return $cart_infos; |
819 | 819 | } |
@@ -823,18 +823,18 @@ discard block |
||
823 | 823 | * @param array $cart_items |
824 | 824 | * @return array |
825 | 825 | */ |
826 | - function add_automaticaly_product_to_cart( $cart_items ) { |
|
826 | + function add_automaticaly_product_to_cart($cart_items) { |
|
827 | 827 | global $wpdb; |
828 | 828 | // Recovery all products with options |
829 | 829 | $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
830 | 830 | $post_list_with_options = $wpdb->get_results($query); |
831 | 831 | $wps_orders = new wps_orders_ctr(); |
832 | - if ( !empty($post_list_with_options) && !empty($cart_items) ) { |
|
833 | - foreach ( $post_list_with_options as $product_info) { |
|
832 | + if (!empty($post_list_with_options) && !empty($cart_items)) { |
|
833 | + foreach ($post_list_with_options as $product_info) { |
|
834 | 834 | $product_meta = unserialize($product_info->meta_value); |
835 | - if ( !empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id]) ) { |
|
835 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id])) { |
|
836 | 836 | $product = wpshop_products::get_product_data($product_info->post_id, true, '"draft", "publish"'); |
837 | - $the_product = array_merge( array( |
|
837 | + $the_product = array_merge(array( |
|
838 | 838 | 'product_id' => $product_info->post_id, |
839 | 839 | 'product_qty' => 1 |
840 | 840 | ), $product); |
@@ -848,28 +848,28 @@ discard block |
||
848 | 848 | |
849 | 849 | /** Ajax action to reload cart **/ |
850 | 850 | public static function wps_reload_cart() { |
851 | - check_ajax_referer( 'wps_reload_cart' ); |
|
851 | + check_ajax_referer('wps_reload_cart'); |
|
852 | 852 | |
853 | 853 | $wps_cart = new wps_cart(); |
854 | 854 | $result = $wps_cart->cart_content(); |
855 | 855 | |
856 | - wp_die( json_encode( array( 'response' => $result) ) ); |
|
856 | + wp_die(json_encode(array('response' => $result))); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | |
860 | 860 | /** Ajax action to reload mini cart */ |
861 | 861 | public function wps_reload_mini_cart() { |
862 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
862 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
863 | 863 | |
864 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) |
|
864 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_mini_cart')) |
|
865 | 865 | wp_die(); |
866 | 866 | |
867 | 867 | $wps_cart = new wps_cart(); |
868 | - $result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) ); |
|
869 | - $count_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $wps_cart->total_cart_items( $_SESSION['cart']['order_items'] ) : 0; |
|
868 | + $result = $wps_cart->mini_cart_content(sanitize_title($_POST['type'])); |
|
869 | + $count_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0; |
|
870 | 870 | $free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert'); |
871 | 871 | |
872 | - echo json_encode( array( 'response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert) ); |
|
872 | + echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert)); |
|
873 | 873 | die(); |
874 | 874 | } |
875 | 875 | |
@@ -879,35 +879,35 @@ discard block |
||
879 | 879 | * @return string |
880 | 880 | */ |
881 | 881 | function display_wps_numeration_cart() { |
882 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $_SESSION['cart']['order_items'] : array(); |
|
883 | - $total_cart_item = self::total_cart_items( $cart_items ); |
|
882 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $_SESSION['cart']['order_items'] : array(); |
|
883 | + $total_cart_item = self::total_cart_items($cart_items); |
|
884 | 884 | |
885 | 885 | ob_start(); |
886 | - require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart") ); |
|
886 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart")); |
|
887 | 887 | $output = ob_get_contents(); |
888 | 888 | ob_end_clean(); |
889 | 889 | return $output; |
890 | 890 | } |
891 | 891 | |
892 | - public function display_button_add_to_cart( $args ) { |
|
893 | - $button_text = __( 'Add to cart', 'wpshop' ); |
|
892 | + public function display_button_add_to_cart($args) { |
|
893 | + $button_text = __('Add to cart', 'wpshop'); |
|
894 | 894 | $use_button = true; |
895 | - $output = __( 'No product has been found.', 'wpshop' ); |
|
895 | + $output = __('No product has been found.', 'wpshop'); |
|
896 | 896 | |
897 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
897 | + if (!empty($args) && !empty($args['pid'])) { |
|
898 | 898 | |
899 | 899 | /** The user send the text in argument */ |
900 | - if ( !empty( $args['text' ] ) ) { |
|
900 | + if (!empty($args['text'])) { |
|
901 | 901 | $button_text = $args['text']; |
902 | 902 | } |
903 | 903 | |
904 | 904 | /** The user send use input */ |
905 | - if ( !empty( $args['use_button'] ) && 'false' == $args['use_button'] ) { |
|
905 | + if (!empty($args['use_button']) && 'false' == $args['use_button']) { |
|
906 | 906 | $use_button = false; |
907 | 907 | } |
908 | 908 | |
909 | 909 | ob_start(); |
910 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart' ) ); |
|
910 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart')); |
|
911 | 911 | $output = ob_get_clean(); |
912 | 912 | } |
913 | 913 | |
@@ -916,21 +916,21 @@ discard block |
||
916 | 916 | |
917 | 917 | /** Ajax action to reload summary cart */ |
918 | 918 | public static function wps_reload_summary_cart() { |
919 | - check_ajax_referer( 'wps_reload_summary_cart' ); |
|
919 | + check_ajax_referer('wps_reload_summary_cart'); |
|
920 | 920 | |
921 | 921 | $wps_cart = new wps_cart(); |
922 | 922 | $result = $wps_cart->resume_cart_content(); |
923 | 923 | |
924 | - wp_die( json_encode( array( 'response' => $result, ) ) ); |
|
924 | + wp_die(json_encode(array('response' => $result,))); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | |
928 | 928 | /** Display Apply Coupon Interface **/ |
929 | 929 | function display_apply_coupon_interface() { |
930 | 930 | $output = ''; |
931 | - if ( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
931 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
932 | 932 | ob_start(); |
933 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon") ); |
|
933 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon")); |
|
934 | 934 | $output = ob_get_contents(); |
935 | 935 | ob_end_clean(); |
936 | 936 | } |
@@ -940,30 +940,30 @@ discard block |
||
940 | 940 | |
941 | 941 | /** AJAX - action to apply coupon **/ |
942 | 942 | function wps_apply_coupon() { |
943 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
943 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
944 | 944 | |
945 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) |
|
945 | + if (!wp_verify_nonce($_wpnonce, 'wps_apply_coupon')) |
|
946 | 946 | wp_die(); |
947 | 947 | |
948 | 948 | $status = false; $response = ''; |
949 | - $coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null; |
|
950 | - if( !empty($coupon) ) { |
|
949 | + $coupon = (!empty($_POST['coupon_code'])) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null; |
|
950 | + if (!empty($coupon)) { |
|
951 | 951 | $wps_coupon_ctr = new wps_coupon_ctr(); |
952 | 952 | $result = $wps_coupon_ctr->applyCoupon($coupon); |
953 | - if ($result['status']===true) { |
|
953 | + if ($result['status'] === true) { |
|
954 | 954 | $order = $this->calcul_cart_information(array()); |
955 | 955 | $this->store_cart_in_session($order); |
956 | 956 | $status = true; |
957 | - $response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>'; |
|
957 | + $response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>'; |
|
958 | 958 | } |
959 | 959 | else { |
960 | - $response = '<div class="wps-alert-error">' .$result['message']. '</div>'; |
|
960 | + $response = '<div class="wps-alert-error">' . $result['message'] . '</div>'; |
|
961 | 961 | } |
962 | 962 | } |
963 | 963 | else { |
964 | - $response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>'; |
|
964 | + $response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>'; |
|
965 | 965 | } |
966 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
966 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
967 | 967 | die(); |
968 | 968 | } |
969 | 969 | |
@@ -972,24 +972,24 @@ discard block |
||
972 | 972 | * AJAX - Pass to step two in the Checkout tunnel |
973 | 973 | */ |
974 | 974 | public static function wps_cart_pass_to_step_two() { |
975 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
975 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
976 | 976 | |
977 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) |
|
977 | + if (!wp_verify_nonce($_wpnonce, 'wps_cart_pass_to_step_two')) |
|
978 | 978 | wp_die(); |
979 | 979 | |
980 | 980 | $status = false; $response = ''; |
981 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
982 | - if( !empty($checkout_page_id) ) { |
|
983 | - $permalink_option = get_option( 'permalink_structure' ); |
|
984 | - $step = ( get_current_user_id() != 0 ) ? 3 : 2; |
|
985 | - $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
|
981 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
982 | + if (!empty($checkout_page_id)) { |
|
983 | + $permalink_option = get_option('permalink_structure'); |
|
984 | + $step = (get_current_user_id() != 0) ? 3 : 2; |
|
985 | + $response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step; |
|
986 | 986 | $response = apply_filters('wps_extra_signup_actions', $response); |
987 | 987 | $status = true; |
988 | 988 | } |
989 | 989 | else { |
990 | - $response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>'; |
|
990 | + $response = '<div class="wps-alert-error">' . __('An error was occured, please retry later or contact the website administrator', 'wpshop') . '</div>'; |
|
991 | 991 | } |
992 | - echo json_encode( array( 'status' => $status, 'response' => $response)); |
|
992 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
993 | 993 | die(); |
994 | 994 | } |
995 | 995 | |
@@ -998,14 +998,14 @@ discard block |
||
998 | 998 | * AJAX - Empty the cart |
999 | 999 | */ |
1000 | 1000 | function wps_empty_cart() { |
1001 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
1001 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
1002 | 1002 | |
1003 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) |
|
1003 | + if (!wp_verify_nonce($_wpnonce, 'wps_empty_cart')) |
|
1004 | 1004 | wp_die(); |
1005 | 1005 | |
1006 | 1006 | |
1007 | 1007 | $this->empty_cart(); |
1008 | - echo json_encode( array( 'status' => true) ); |
|
1008 | + echo json_encode(array('status' => true)); |
|
1009 | 1009 | die(); |
1010 | 1010 | } |
1011 | 1011 | } |