@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Main controller file for product mass modification module |
| 4 | 4 | * |
@@ -30,56 +30,56 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string The template file path to use |
| 32 | 32 | */ |
| 33 | - public static function get_template_part( $plugin_dir_name, $main_template_dir, $side, $slug, $name=null, $debug = null ) { |
|
| 33 | + public static function get_template_part($plugin_dir_name, $main_template_dir, $side, $slug, $name = null, $debug = null) { |
|
| 34 | 34 | $path = ''; |
| 35 | 35 | |
| 36 | 36 | $templates = array(); |
| 37 | 37 | $name = (string)$name; |
| 38 | - if ( '' !== $name ) |
|
| 38 | + if ('' !== $name) |
|
| 39 | 39 | $templates[] = "{$side}/{$slug}-{$name}.php"; |
| 40 | 40 | $templates[] = "{$side}/{$slug}.php"; |
| 41 | 41 | |
| 42 | 42 | /** Check if required template exists into current theme */ |
| 43 | 43 | $check_theme_template = array(); |
| 44 | - foreach ( $templates as $template ) { |
|
| 44 | + foreach ($templates as $template) { |
|
| 45 | 45 | $check_theme_template = $plugin_dir_name . "/" . $template; |
| 46 | - $path = locate_template( $check_theme_template, false ); |
|
| 47 | - if( !empty($path) ) { |
|
| 46 | + $path = locate_template($check_theme_template, false); |
|
| 47 | + if (!empty($path)) { |
|
| 48 | 48 | break; |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** Allow debugging */ |
| 53 | - if ( !empty( $debug ) ) { |
|
| 53 | + if (!empty($debug)) { |
|
| 54 | 54 | echo '--- Debug mode ON - Start ---<br/>'; |
| 55 | 55 | echo __FILE__ . '<br/>'; |
| 56 | 56 | echo 'Debug for display method<br/>'; |
| 57 | 57 | echo 'Asked path ' . $path . '<br/>'; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( empty( $path ) ) { |
|
| 61 | - foreach ( (array) $templates as $template_name ) { |
|
| 62 | - if ( !$template_name ) |
|
| 60 | + if (empty($path)) { |
|
| 61 | + foreach ((array)$templates as $template_name) { |
|
| 62 | + if (!$template_name) |
|
| 63 | 63 | continue; |
| 64 | 64 | |
| 65 | - if ( !empty( $debug ) ) { |
|
| 65 | + if (!empty($debug)) { |
|
| 66 | 66 | echo __LINE__ . ' - ' . $main_template_dir . $template_name . '<hr/>'; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $file_exists = file_exists( $main_template_dir . $template_name ); |
|
| 70 | - if ( $file_exists ) { |
|
| 69 | + $file_exists = file_exists($main_template_dir . $template_name); |
|
| 70 | + if ($file_exists) { |
|
| 71 | 71 | $path = $main_template_dir . $template_name; |
| 72 | 72 | break; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( !empty( $debug ) ) { |
|
| 75 | + if (!empty($debug)) { |
|
| 76 | 76 | echo __LINE__ . ' - ' . (bool)$file_exists . '<hr/>'; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** Allow debugging */ |
| 82 | - if ( !empty( $debug ) ) { |
|
| 82 | + if (!empty($debug)) { |
|
| 83 | 83 | echo '--- Debug mode ON - END ---<br/><br/>'; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return mixed $sanitizedVar The var after treatment |
| 104 | 104 | */ |
| 105 | 105 | public static function varSanitizer($varToSanitize, $varDefaultValue = '', $varType = '') { |
| 106 | - $sanitizedVar = is_string( $varToSanitize ) && (trim(strip_tags(stripslashes($varToSanitize))) != '') ? trim(strip_tags(stripslashes(($varToSanitize)))) : $varDefaultValue ; |
|
| 106 | + $sanitizedVar = is_string($varToSanitize) && (trim(strip_tags(stripslashes($varToSanitize))) != '') ? trim(strip_tags(stripslashes(($varToSanitize)))) : $varDefaultValue; |
|
| 107 | 107 | |
| 108 | 108 | return $sanitizedVar; |
| 109 | 109 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | public static function forceDownload($Fichier_a_telecharger, $delete_after_download = false) { |
| 117 | 117 | |
| 118 | 118 | $nom_fichier = basename($Fichier_a_telecharger); |
| 119 | - switch(strrchr($nom_fichier, ".")) { |
|
| 119 | + switch (strrchr($nom_fichier, ".")) { |
|
| 120 | 120 | case ".gz": $type = "application/x-gzip"; break; |
| 121 | 121 | case ".tgz": $type = "application/x-gzip"; break; |
| 122 | 122 | case ".zip": $type = "application/zip"; break; |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | header("Content-disposition: attachment; filename=$nom_fichier"); |
| 134 | 134 | header("Content-Type: application/force-download"); |
| 135 | 135 | header("Content-Transfer-Encoding: $type\n"); // Surtout ne pas enlever le \n |
| 136 | - header("Content-Length: ".filesize($Fichier_a_telecharger)); |
|
| 136 | + header("Content-Length: " . filesize($Fichier_a_telecharger)); |
|
| 137 | 137 | header("Pragma: no-cache"); |
| 138 | 138 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public"); |
| 139 | 139 | header("Expires: 0"); |
| 140 | 140 | ob_end_clean(); |
| 141 | 141 | readfile($Fichier_a_telecharger); |
| 142 | - if ( $delete_after_download ) { |
|
| 143 | - unlink( $Fichier_a_telecharger ); |
|
| 142 | + if ($delete_after_download) { |
|
| 143 | + unlink($Fichier_a_telecharger); |
|
| 144 | 144 | } |
| 145 | 145 | exit; |
| 146 | 146 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @return boolean |
| 151 | 151 | */ |
| 152 | 152 | public static function is_sendsms_actived() { |
| 153 | - if(is_plugin_active('wordpress-send-sms/Send-SMS.php')) { |
|
| 153 | + if (is_plugin_active('wordpress-send-sms/Send-SMS.php')) { |
|
| 154 | 154 | $configOption = get_option('sendsms_config', ''); |
| 155 | 155 | $ligne = unserialize($configOption); |
| 156 | 156 | $nicOVH = $ligne['nicOVH']; |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param unknown_type $input |
| 168 | 168 | * @return Ambigous <multitype:, multitype:multitype:unknown > |
| 169 | 169 | */ |
| 170 | - public static function search_all_possibilities( $input ) { |
|
| 170 | + public static function search_all_possibilities($input) { |
|
| 171 | 171 | $result = array(); |
| 172 | 172 | |
| 173 | 173 | while (list($key, $values) = each($input)) { |
@@ -176,17 +176,17 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | if (empty($result)) { |
| 179 | - foreach($values as $value) { |
|
| 179 | + foreach ($values as $value) { |
|
| 180 | 180 | $result[] = array($key => $value); |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | else { |
| 184 | 184 | $append = array(); |
| 185 | - foreach($result as &$product) { |
|
| 185 | + foreach ($result as &$product) { |
|
| 186 | 186 | $product[$key] = array_shift($values); |
| 187 | 187 | $copy = $product; |
| 188 | 188 | |
| 189 | - foreach($values as $item) { |
|
| 189 | + foreach ($values as $item) { |
|
| 190 | 190 | $copy[$key] = $item; |
| 191 | 191 | $append[] = $copy; |
| 192 | 192 | } |
@@ -206,16 +206,16 @@ discard block |
||
| 206 | 206 | * @param boolean $code : false return sigle, true return code (€ or EUR) |
| 207 | 207 | * @return string currency code or sigle |
| 208 | 208 | */ |
| 209 | - public static function wpshop_get_currency($code=false) { |
|
| 209 | + public static function wpshop_get_currency($code = false) { |
|
| 210 | 210 | // Currency |
| 211 | - if( is_null( self::$currency_cache ) ) { |
|
| 211 | + if (is_null(self::$currency_cache)) { |
|
| 212 | 212 | global $wpdb; |
| 213 | 213 | $current_currency = get_option('wpshop_shop_default_currency'); |
| 214 | - $query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id =%d ', $current_currency ); |
|
| 215 | - self::$currency_cache = $wpdb->get_row( $query ); |
|
| 214 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id =%d ', $current_currency); |
|
| 215 | + self::$currency_cache = $wpdb->get_row($query); |
|
| 216 | 216 | } |
| 217 | - if ( !empty(self::$currency_cache) ) { |
|
| 218 | - $code = ($code) ? self::$currency_cache->name : self::$currency_cache->unit; |
|
| 217 | + if (!empty(self::$currency_cache)) { |
|
| 218 | + $code = ($code) ? self::$currency_cache->name : self::$currency_cache->unit; |
|
| 219 | 219 | return $code; |
| 220 | 220 | } |
| 221 | 221 | else { |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | public static function wpshop_get_sigle($code, $column_to_return = "unit") { |
| 232 | 232 | $tmp_code = (int)$code; |
| 233 | 233 | $key_to_get = 'name'; |
| 234 | - if ( is_int($tmp_code) && !empty($tmp_code) ) { |
|
| 234 | + if (is_int($tmp_code) && !empty($tmp_code)) { |
|
| 235 | 235 | $key_to_get = 'id'; |
| 236 | 236 | } |
| 237 | 237 | $old_way_currencies = unserialize(WPSHOP_SHOP_CURRENCIES); |
| 238 | - if ( array_key_exists( $code, $old_way_currencies)) { |
|
| 238 | + if (array_key_exists($code, $old_way_currencies)) { |
|
| 239 | 239 | $code = $old_way_currencies[$code]; |
| 240 | 240 | $key_to_get = 'name'; |
| 241 | 241 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param string $var : variable to clean |
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | - public static function wpshop_clean( $var ) { |
|
| 253 | + public static function wpshop_clean($var) { |
|
| 254 | 254 | return trim(strip_tags(stripslashes($var))); |
| 255 | 255 | } |
| 256 | 256 | |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @param string phone number |
| 260 | 260 | * @return boolean |
| 261 | 261 | */ |
| 262 | - public static function is_phone( $phone ) { |
|
| 263 | - return preg_match( '/(?=.*[0-9])([ 0-9\-\+\(\)]+)/', $phone ); |
|
| 262 | + public static function is_phone($phone) { |
|
| 263 | + return preg_match('/(?=.*[0-9])([ 0-9\-\+\(\)]+)/', $phone); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -268,8 +268,8 @@ discard block |
||
| 268 | 268 | * @param string postcode |
| 269 | 269 | * @return boolean |
| 270 | 270 | */ |
| 271 | - public static function is_postcode( $postcode ) { |
|
| 272 | - return preg_match( '/(?=.*[0-9A-Za-z])([ \-A-Za-z0-9]+)/', $postcode ); |
|
| 271 | + public static function is_postcode($postcode) { |
|
| 272 | + return preg_match('/(?=.*[0-9A-Za-z])([ \-A-Za-z0-9]+)/', $postcode); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -279,14 +279,14 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return string $type The form input type to use for the given field |
| 281 | 281 | */ |
| 282 | - public static function defineFieldType($dataFieldType, $input_type, $frontend_verification){ |
|
| 282 | + public static function defineFieldType($dataFieldType, $input_type, $frontend_verification) { |
|
| 283 | 283 | $type = 'text'; |
| 284 | 284 | |
| 285 | - if ( $dataFieldType == 'datetime' ) { |
|
| 285 | + if ($dataFieldType == 'datetime') { |
|
| 286 | 286 | $type = 'text'; |
| 287 | 287 | } |
| 288 | 288 | else { |
| 289 | - switch ( $frontend_verification ) { |
|
| 289 | + switch ($frontend_verification) { |
|
| 290 | 290 | case 'phone': |
| 291 | 291 | $type = 'tel'; |
| 292 | 292 | break; |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * |
| 307 | 307 | * @return array The different element send by request method |
| 308 | 308 | */ |
| 309 | - public static function getMethode(){ |
|
| 309 | + public static function getMethode() { |
|
| 310 | 310 | $request_method = null; |
| 311 | 311 | if ($_SERVER["REQUEST_METHOD"] == "GET") { |
| 312 | 312 | $request_method = (array)$_GET; |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | $request_method = (array)$_POST; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - if ( null === $request_method ) { |
|
| 318 | + if (null === $request_method) { |
|
| 319 | 319 | die ('Invalid REQUEST_METHOD (not GET, not POST).'); |
| 320 | 320 | } |
| 321 | 321 | else { |
@@ -331,36 +331,36 @@ discard block |
||
| 331 | 331 | * |
| 332 | 332 | * @return string $slugified The input string that was slugified with the selected method |
| 333 | 333 | */ |
| 334 | - public static function slugify($toSlugify, $slugifyType){ |
|
| 334 | + public static function slugify($toSlugify, $slugifyType) { |
|
| 335 | 335 | $slugified = ''; |
| 336 | 336 | |
| 337 | - if($toSlugify != '') |
|
| 337 | + if ($toSlugify != '') |
|
| 338 | 338 | { |
| 339 | 339 | $slugified = $toSlugify; |
| 340 | - foreach($slugifyType as $type) |
|
| 340 | + foreach ($slugifyType as $type) |
|
| 341 | 341 | { |
| 342 | - if($type == 'noAccent') |
|
| 342 | + if ($type == 'noAccent') |
|
| 343 | 343 | { |
| 344 | - $pattern = array("/é/", "/è/", "/ê/", "/ç/", "/à/", "/â/", "/î/", "/ï/", "/û/", "/ô/", "/È/", "/É/", "/Ê/", "/Ë/", "/Ì/", "/Í/", "/Î/", "/Ï/", "/Ö/", "/Ù/", "/Û/", "/Ü/","/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/"); |
|
| 345 | - $rep_pat = array("e", "e", "e", "c", "a", "a", "i", "i", "u", "o", "E", "E", "E", "E", "I", "I", "I", "I", "O", "U", "U", "U","e", "e", "e", "c", "a", "a", "i", "i", "u", "o", "E", "E", "E", "E", "I", "I", "I", "I", "O", "U", "U", "U"); |
|
| 344 | + $pattern = array("/é/", "/è/", "/ê/", "/ç/", "/à/", "/â/", "/î/", "/ï/", "/û/", "/ô/", "/È/", "/É/", "/Ê/", "/Ë/", "/Ì/", "/Í/", "/Î/", "/Ï/", "/Ö/", "/Ù/", "/Û/", "/Ü/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/", "/�/"); |
|
| 345 | + $rep_pat = array("e", "e", "e", "c", "a", "a", "i", "i", "u", "o", "E", "E", "E", "E", "I", "I", "I", "I", "O", "U", "U", "U", "e", "e", "e", "c", "a", "a", "i", "i", "u", "o", "E", "E", "E", "E", "I", "I", "I", "I", "O", "U", "U", "U"); |
|
| 346 | 346 | } |
| 347 | - elseif($type == 'noSpaces') |
|
| 347 | + elseif ($type == 'noSpaces') |
|
| 348 | 348 | { |
| 349 | 349 | $pattern = array('/\s/'); |
| 350 | 350 | $rep_pat = array('_'); |
| 351 | 351 | $slugified = trim($slugified); |
| 352 | 352 | } |
| 353 | - elseif($type == 'lowerCase') |
|
| 353 | + elseif ($type == 'lowerCase') |
|
| 354 | 354 | { |
| 355 | 355 | $slugified = strtolower($slugified); |
| 356 | 356 | } |
| 357 | - elseif($type == 'noPunctuation') |
|
| 357 | + elseif ($type == 'noPunctuation') |
|
| 358 | 358 | { |
| 359 | 359 | $pattern = array("/#/", "/\{/", "/\[/", "/\(/", "/\)/", "/\]/", "/\}/", "/&/", "/~/", "/�/", "/`/", "/\^/", "/@/", "/=/", "/�/", "/�/", "/%/", "/�/", "/!/", "/�/", "/:/", "/\$/", "/;/", "/\./", "/,/", "/\?/", "/\\\/", "/\//"); |
| 360 | 360 | $rep_pat = array("_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"); |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if(is_array($pattern) && is_array($rep_pat)) |
|
| 363 | + if (is_array($pattern) && is_array($rep_pat)) |
|
| 364 | 364 | { |
| 365 | 365 | $slugified = preg_replace($pattern, $rep_pat, utf8_decode($slugified)); |
| 366 | 366 | } |
@@ -379,17 +379,17 @@ discard block |
||
| 379 | 379 | * @return string $string The output string that was trunk if necessary |
| 380 | 380 | */ |
| 381 | 381 | public static function trunk($string, $maxlength) { |
| 382 | - if(strlen($string)>$maxlength+3) |
|
| 383 | - return substr($string,0,$maxlength).'...'; |
|
| 382 | + if (strlen($string) > $maxlength + 3) |
|
| 383 | + return substr($string, 0, $maxlength) . '...'; |
|
| 384 | 384 | else return $string; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * Run a safe redirect in javascript |
| 389 | 389 | */ |
| 390 | - public static function wpshop_safe_redirect($url='') { |
|
| 391 | - $url = empty($url) ? admin_url('admin.php?page='.WPSHOP_URL_SLUG_DASHBOARD) : $url; |
|
| 392 | - echo '<script type="text/javascript">window.top.location.href = "'.$url.'"</script>'; |
|
| 390 | + public static function wpshop_safe_redirect($url = '') { |
|
| 391 | + $url = empty($url) ? admin_url('admin.php?page=' . WPSHOP_URL_SLUG_DASHBOARD) : $url; |
|
| 392 | + echo '<script type="text/javascript">window.top.location.href = "' . $url . '"</script>'; |
|
| 393 | 393 | exit; |
| 394 | 394 | } |
| 395 | 395 | |
@@ -399,9 +399,9 @@ discard block |
||
| 399 | 399 | * @param array $args : Hook arguments |
| 400 | 400 | * @return string |
| 401 | 401 | */ |
| 402 | - public static function create_custom_hook ($hook_name, $args = '') { |
|
| 402 | + public static function create_custom_hook($hook_name, $args = '') { |
|
| 403 | 403 | ob_start(); |
| 404 | - if ( !empty($args) ) { |
|
| 404 | + if (!empty($args)) { |
|
| 405 | 405 | do_action($hook_name, $args); |
| 406 | 406 | } |
| 407 | 407 | else { |
@@ -420,16 +420,16 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | public static function get_plugin_validation_code($plugin_name, $encrypt_base_attribute) { |
| 422 | 422 | $code = ''; |
| 423 | - if ( !function_exists( 'get_plugin_data') ) |
|
| 424 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
| 425 | - $plug = get_plugin_data( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/wpshop.php' ); |
|
| 423 | + if (!function_exists('get_plugin_data')) |
|
| 424 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 425 | + $plug = get_plugin_data(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/wpshop.php'); |
|
| 426 | 426 | $code_part = array(); |
| 427 | - $code_part[] = substr(hash ( "sha256" , $plugin_name ), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 428 | - $code_part[] = substr(hash ( "sha256" , $plug['Name'] ), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 429 | - $code_part[] = substr(hash ( "sha256" , 'addons' ), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 427 | + $code_part[] = substr(hash("sha256", $plugin_name), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 428 | + $code_part[] = substr(hash("sha256", $plug['Name']), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 429 | + $code_part[] = substr(hash("sha256", 'addons'), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 430 | 430 | $code = $code_part[1] . '-' . $code_part[2] . '-' . $code_part[0]; |
| 431 | 431 | $att = $encrypt_base_attribute; |
| 432 | - $code .= '-' . substr(hash ( "sha256" , $att ), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 432 | + $code .= '-' . substr(hash("sha256", $att), WPSHOP_ADDONS_KEY_IS, 5); |
|
| 433 | 433 | |
| 434 | 434 | return $code; |
| 435 | 435 | } |
@@ -440,15 +440,15 @@ discard block |
||
| 440 | 440 | * @param string $encrypt_base_attribute |
| 441 | 441 | * @return boolean |
| 442 | 442 | */ |
| 443 | - public static function check_plugin_activation_code( $plugin_name, $encrypt_base_attribute, $from = 'file') { |
|
| 443 | + public static function check_plugin_activation_code($plugin_name, $encrypt_base_attribute, $from = 'file') { |
|
| 444 | 444 | $is_valid = false; |
| 445 | 445 | $valid_activation_code = self::get_plugin_validation_code($plugin_name, $encrypt_base_attribute); |
| 446 | - $activation_code_filename = WP_PLUGIN_DIR .'/'. $plugin_name.'/encoder.txt'; |
|
| 447 | - if ( is_file($activation_code_filename) ) { |
|
| 448 | - $activation_code_file = fopen($activation_code_filename, 'r' ); |
|
| 449 | - if ( $activation_code_file !== false) { |
|
| 450 | - $activation_code = fread( $activation_code_file, filesize($activation_code_filename)); |
|
| 451 | - if ( $activation_code == $valid_activation_code ) { |
|
| 446 | + $activation_code_filename = WP_PLUGIN_DIR . '/' . $plugin_name . '/encoder.txt'; |
|
| 447 | + if (is_file($activation_code_filename)) { |
|
| 448 | + $activation_code_file = fopen($activation_code_filename, 'r'); |
|
| 449 | + if ($activation_code_file !== false) { |
|
| 450 | + $activation_code = fread($activation_code_file, filesize($activation_code_filename)); |
|
| 451 | + if ($activation_code == $valid_activation_code) { |
|
| 452 | 452 | $is_valid = true; |
| 453 | 453 | } |
| 454 | 454 | } |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | * @param unknown_type $number |
| 462 | 462 | * @return string |
| 463 | 463 | */ |
| 464 | - public static function formate_number( $number ) { |
|
| 465 | - $number = number_format( $number, 2, '.', '' ); |
|
| 466 | - $exploded_number = explode( '.', $number ); |
|
| 464 | + public static function formate_number($number) { |
|
| 465 | + $number = number_format($number, 2, '.', ''); |
|
| 466 | + $exploded_number = explode('.', $number); |
|
| 467 | 467 | $number = $exploded_number[0]; |
| 468 | - if( $exploded_number[1] != '00' ) { |
|
| 469 | - $number .= '<span class="wps_number_cents">,' . $exploded_number[1]. '</span>'; |
|
| 468 | + if ($exploded_number[1] != '00') { |
|
| 469 | + $number .= '<span class="wps_number_cents">,' . $exploded_number[1] . '</span>'; |
|
| 470 | 470 | } |
| 471 | 471 | return $number; |
| 472 | 472 | } |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | * @param int $page_id |
| 477 | 477 | * @return int |
| 478 | 478 | */ |
| 479 | - public static function get_page_id( $page_id ) { |
|
| 480 | - if( !empty($page_id) ) { |
|
| 481 | - if ( function_exists( 'icl_object_id' ) && defined('ICL_LANGUAGE_CODE') ) { |
|
| 482 | - $element_post_type = get_post_type( $page_id ); |
|
| 483 | - $translated_element_id = icl_object_id( $page_id, $element_post_type, true, ICL_LANGUAGE_CODE ); |
|
| 484 | - if( !empty($translated_element_id) ) { |
|
| 479 | + public static function get_page_id($page_id) { |
|
| 480 | + if (!empty($page_id)) { |
|
| 481 | + if (function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE')) { |
|
| 482 | + $element_post_type = get_post_type($page_id); |
|
| 483 | + $translated_element_id = icl_object_id($page_id, $element_post_type, true, ICL_LANGUAGE_CODE); |
|
| 484 | + if (!empty($translated_element_id)) { |
|
| 485 | 485 | $page_id = $translated_element_id; |
| 486 | 486 | } |
| 487 | 487 | } |
@@ -489,65 +489,65 @@ discard block |
||
| 489 | 489 | return $page_id; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - public static function minutes_to_time( $minutes, $format = '%hh %imin' ) { |
|
| 493 | - $dtF = new \DateTime( '@0' ); |
|
| 494 | - $dtT = new \DateTime( '@' . ( $minutes * 60 ) ); |
|
| 495 | - return $dtF->diff($dtT)->format( $format ); |
|
| 492 | + public static function minutes_to_time($minutes, $format = '%hh %imin') { |
|
| 493 | + $dtF = new \DateTime('@0'); |
|
| 494 | + $dtT = new \DateTime('@' . ($minutes * 60)); |
|
| 495 | + return $dtF->diff($dtT)->format($format); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | public static function number_format_hack($n) { |
| 499 | 499 | return number_format($n, 5, '.', ''); |
| 500 | 500 | } |
| 501 | - public static function is_serialized( $data, $strict = true ) { |
|
| 502 | - if ( ! is_string( $data ) ) { |
|
| 501 | + public static function is_serialized($data, $strict = true) { |
|
| 502 | + if (!is_string($data)) { |
|
| 503 | 503 | return false; |
| 504 | 504 | } |
| 505 | - $data = trim( $data ); |
|
| 506 | - if ( 'N;' == $data ) { |
|
| 505 | + $data = trim($data); |
|
| 506 | + if ('N;' == $data) { |
|
| 507 | 507 | return true; |
| 508 | 508 | } |
| 509 | - if ( strlen( $data ) < 4 ) { |
|
| 509 | + if (strlen($data) < 4) { |
|
| 510 | 510 | return false; |
| 511 | 511 | } |
| 512 | - if ( ':' !== $data[1] ) { |
|
| 512 | + if (':' !== $data[1]) { |
|
| 513 | 513 | return false; |
| 514 | 514 | } |
| 515 | - if ( $strict ) { |
|
| 516 | - $lastc = substr( $data, -1 ); |
|
| 517 | - if ( ';' !== $lastc && '}' !== $lastc ) { |
|
| 515 | + if ($strict) { |
|
| 516 | + $lastc = substr($data, -1); |
|
| 517 | + if (';' !== $lastc && '}' !== $lastc) { |
|
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | } else { |
| 521 | - $semicolon = strpos( $data, ';' ); |
|
| 522 | - $brace = strpos( $data, '}' ); |
|
| 523 | - if ( false === $semicolon && false === $brace ) { |
|
| 521 | + $semicolon = strpos($data, ';'); |
|
| 522 | + $brace = strpos($data, '}'); |
|
| 523 | + if (false === $semicolon && false === $brace) { |
|
| 524 | 524 | return false; |
| 525 | 525 | } |
| 526 | - if ( false !== $semicolon && $semicolon < 3 ) { |
|
| 526 | + if (false !== $semicolon && $semicolon < 3) { |
|
| 527 | 527 | return false; |
| 528 | 528 | } |
| 529 | - if ( false !== $brace && $brace < 4 ) { |
|
| 529 | + if (false !== $brace && $brace < 4) { |
|
| 530 | 530 | return false; |
| 531 | 531 | } |
| 532 | 532 | } |
| 533 | 533 | $token = $data[0]; |
| 534 | - switch ( $token ) { |
|
| 534 | + switch ($token) { |
|
| 535 | 535 | case 's' : |
| 536 | - if ( $strict ) { |
|
| 537 | - if ( '"' !== substr( $data, -2, 1 ) ) { |
|
| 536 | + if ($strict) { |
|
| 537 | + if ('"' !== substr($data, -2, 1)) { |
|
| 538 | 538 | return false; |
| 539 | 539 | } |
| 540 | - } elseif ( false === strpos( $data, '"' ) ) { |
|
| 540 | + } elseif (false === strpos($data, '"')) { |
|
| 541 | 541 | return false; |
| 542 | 542 | } |
| 543 | 543 | case 'a' : |
| 544 | 544 | case 'O' : |
| 545 | - return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); |
|
| 545 | + return (bool)preg_match("/^{$token}:[0-9]+:/s", $data); |
|
| 546 | 546 | case 'b' : |
| 547 | 547 | case 'i' : |
| 548 | 548 | case 'd' : |
| 549 | 549 | $end = $strict ? '$' : ''; |
| 550 | - return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data ); |
|
| 550 | + return (bool)preg_match("/^{$token}:[0-9.E-]+;$end/", $data); |
|
| 551 | 551 | } |
| 552 | 552 | return false; |
| 553 | 553 | } |
@@ -1,78 +1,78 @@ |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 2 | - $order_post_meta = !empty($post) ? get_post_meta( $post->ID, '_wpshop_order_status', true ) : ""; ?> |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | + $order_post_meta = !empty($post) ? get_post_meta($post->ID, '_wpshop_order_status', true) : ""; ?> |
|
| 3 | 3 | <div class="wps-table"> |
| 4 | 4 | <div class="wps-table-header wps-table-row"> |
| 5 | - <div class="wps-table-cell"><?php _e( 'Picture', 'wpshop'); ?></div> |
|
| 6 | - <div class="wps-table-cell"><?php _e( 'Product reference', 'wpshop'); ?></div> |
|
| 7 | - <div class="wps-table-cell"><?php _e( 'Product name', 'wpshop'); ?></div> |
|
| 8 | - <div class="wps-table-cell"><?php _e( 'Price', 'wpshop'); ?></div> |
|
| 5 | + <div class="wps-table-cell"><?php _e('Picture', 'wpshop'); ?></div> |
|
| 6 | + <div class="wps-table-cell"><?php _e('Product reference', 'wpshop'); ?></div> |
|
| 7 | + <div class="wps-table-cell"><?php _e('Product name', 'wpshop'); ?></div> |
|
| 8 | + <div class="wps-table-cell"><?php _e('Price', 'wpshop'); ?></div> |
|
| 9 | 9 | |
| 10 | - <?php if ( 'completed' != $order_post_meta ) : ?> |
|
| 11 | - <div class="wps-table-cell"><?php _e( 'Quantity', 'wpshop'); ?></div> |
|
| 12 | - <div class="wps-table-cell"><?php _e( 'Add to order', 'wpshop'); ?></div> |
|
| 10 | + <?php if ('completed' != $order_post_meta) : ?> |
|
| 11 | + <div class="wps-table-cell"><?php _e('Quantity', 'wpshop'); ?></div> |
|
| 12 | + <div class="wps-table-cell"><?php _e('Add to order', 'wpshop'); ?></div> |
|
| 13 | 13 | <?php endif; ?> |
| 14 | 14 | </div> |
| 15 | - <?php if( !empty($products) ) : |
|
| 16 | - $total_products = count( $products ); |
|
| 15 | + <?php if (!empty($products)) : |
|
| 16 | + $total_products = count($products); |
|
| 17 | 17 | $i = 0; |
| 18 | 18 | $elements_per_page = 20; |
| 19 | - $paged = absint( isset( $_REQUEST['paged_order'] ) ? $_REQUEST['paged_order'] : 1 ); |
|
| 20 | - $paginate_links = paginate_links( array( |
|
| 19 | + $paged = absint(isset($_REQUEST['paged_order']) ? $_REQUEST['paged_order'] : 1); |
|
| 20 | + $paginate_links = paginate_links(array( |
|
| 21 | 21 | 'base' => '%_%', |
| 22 | 22 | 'format' => '?paged_order=%#%', |
| 23 | 23 | 'current' => $paged, |
| 24 | - 'total' => ceil( $total_products / $elements_per_page ) |
|
| 25 | - ) ); |
|
| 26 | - foreach ( $products as $product ) : |
|
| 27 | - if( ( $elements_per_page * ( $paged - 1 ) ) > $i ) { |
|
| 24 | + 'total' => ceil($total_products / $elements_per_page) |
|
| 25 | + )); |
|
| 26 | + foreach ($products as $product) : |
|
| 27 | + if (($elements_per_page * ($paged - 1)) > $i) { |
|
| 28 | 28 | $i++; |
| 29 | 29 | continue; |
| 30 | - } elseif ( ( $elements_per_page * $paged ) <= $i ) { |
|
| 30 | + } elseif (($elements_per_page * $paged) <= $i) { |
|
| 31 | 31 | break; |
| 32 | 32 | } |
| 33 | 33 | $i++; |
| 34 | 34 | $pid = $product->ID; |
| 35 | 35 | ?> |
| 36 | - <?php $product_metadata = get_post_meta( $product->ID, '_wpshop_product_metadata', true ); ?> |
|
| 36 | + <?php $product_metadata = get_post_meta($product->ID, '_wpshop_product_metadata', true); ?> |
|
| 37 | 37 | <div class="wps-table-content wps-table-row"> |
| 38 | - <div class="wps-table-cell wps-cart-item-img"><?php echo get_the_post_thumbnail( $product->ID, 'thumbnail' ); ?></div> |
|
| 39 | - <div class="wps-table-cell"><?php echo ( !empty( $product_metadata) && $product_metadata['product_reference']) ? $product_metadata['product_reference'] : ''; ?></div> |
|
| 38 | + <div class="wps-table-cell wps-cart-item-img"><?php echo get_the_post_thumbnail($product->ID, 'thumbnail'); ?></div> |
|
| 39 | + <div class="wps-table-cell"><?php echo (!empty($product_metadata) && $product_metadata['product_reference']) ? $product_metadata['product_reference'] : ''; ?></div> |
|
| 40 | 40 | <div class="wps-table-cell"><?php echo $product->post_title; ?></div> |
| 41 | 41 | <div class="wps-table-cell"> |
| 42 | 42 | <?php |
| 43 | 43 | $product = wpshop_products::get_product_data($product->ID); |
| 44 | - echo wpshop_prices::get_product_price($product, 'price_display', array('mini_output', 'grid') ); |
|
| 44 | + echo wpshop_prices::get_product_price($product, 'price_display', array('mini_output', 'grid')); |
|
| 45 | 45 | ?> |
| 46 | 46 | </div> |
| 47 | - <?php if ( 'completed' != $order_post_meta ) : ?> |
|
| 47 | + <?php if ('completed' != $order_post_meta) : ?> |
|
| 48 | 48 | <div class="wps-table-cell"> |
| 49 | - <a class="wps-bton-icon-minus-small wps-cart-reduce-product-qty" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_set_qty_for_product_into_cart' ); ?>" href=""></a> |
|
| 49 | + <a class="wps-bton-icon-minus-small wps-cart-reduce-product-qty" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_set_qty_for_product_into_cart'); ?>" href=""></a> |
|
| 50 | 50 | <input id="wps-cart-product-qty-<?php echo $pid; ?>" class="wps-cart-product-qty" type="text" value="1" name="french-hens" size="3" style="text-align : center"> |
| 51 | - <a class="wps-bton-icon-plus-small wps-cart-add-product-qty" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_set_qty_for_product_into_cart' ); ?>" href=""></a> |
|
| 51 | + <a class="wps-bton-icon-plus-small wps-cart-add-product-qty" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_set_qty_for_product_into_cart'); ?>" href=""></a> |
|
| 52 | 52 | </div> |
| 53 | 53 | <div class="wps-table-cell"> |
| 54 | - <a href="#" data-nonce="<?php echo wp_create_nonce( 'wps_add_product_to_order_admin' ); ?>" class="wps-bton-first-mini-rounded wps-order-add-product" id="wps-order-add-product-<?php echo $pid; ?>"><i class="wps-icon-basket"></i> <?php _e( 'Add to order', 'wpshop'); ?></a> |
|
| 54 | + <a href="#" data-nonce="<?php echo wp_create_nonce('wps_add_product_to_order_admin'); ?>" class="wps-bton-first-mini-rounded wps-order-add-product" id="wps-order-add-product-<?php echo $pid; ?>"><i class="wps-icon-basket"></i> <?php _e('Add to order', 'wpshop'); ?></a> |
|
| 55 | 55 | </div> |
| 56 | 56 | <?php endif; ?> |
| 57 | 57 | </div> |
| 58 | 58 | <?php endforeach; |
| 59 | 59 | else : |
| 60 | - if( !empty( $research ) ) : ?> |
|
| 61 | - <div class="wps-alert-info"><?php printf( __( 'No products corresponds to the search <strong>"%s"</strong>', 'wpshop'), $research ); ?></div> |
|
| 60 | + if (!empty($research)) : ?> |
|
| 61 | + <div class="wps-alert-info"><?php printf(__('No products corresponds to the search <strong>"%s"</strong>', 'wpshop'), $research); ?></div> |
|
| 62 | 62 | <?php else : |
| 63 | - $letter_display = ( strtoupper( $current_letter ) != 'ALL' ) ? $current_letter : __('ALL', 'wpshop' ); ?> |
|
| 64 | - <div class="wps-alert-info"><?php printf( __( 'No products corresponds to the letter <strong>"%s"</strong> search', 'wpshop'), strtoupper( $letter_display ) ); ?></div> |
|
| 63 | + $letter_display = (strtoupper($current_letter) != 'ALL') ? $current_letter : __('ALL', 'wpshop'); ?> |
|
| 64 | + <div class="wps-alert-info"><?php printf(__('No products corresponds to the letter <strong>"%s"</strong> search', 'wpshop'), strtoupper($letter_display)); ?></div> |
|
| 65 | 65 | <?php endif; |
| 66 | 66 | endif; ?> |
| 67 | 67 | </div> |
| 68 | 68 | <?php |
| 69 | -if( !empty($products) && $total_products > $elements_per_page ) : |
|
| 69 | +if (!empty($products) && $total_products > $elements_per_page) : |
|
| 70 | 70 | echo $paginate_links; |
| 71 | 71 | ?> |
| 72 | 72 | <input type="hidden" name="last_query[oid]" value="<?php echo $post->ID; ?>"> |
| 73 | - <input type="hidden" name="last_query[letter]" value="<?php echo strtoupper( $current_letter ); ?>"> |
|
| 73 | + <input type="hidden" name="last_query[letter]" value="<?php echo strtoupper($current_letter); ?>"> |
|
| 74 | 74 | <input type="hidden" name="last_query[research]" value="<?php echo $research; ?>"> |
| 75 | - <input type="hidden" name="last_query[_wpnonce]" value="<?php echo wp_create_nonce( 'refresh_product_list_'.strtolower($current_letter) ); ?>"> |
|
| 75 | + <input type="hidden" name="last_query[_wpnonce]" value="<?php echo wp_create_nonce('refresh_product_list_' . strtolower($current_letter)); ?>"> |
|
| 76 | 76 | <?php |
| 77 | 77 | endif; |
| 78 | 78 | ?> |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) { exit; |
|
| 2 | 2 | } |
| 3 | 3 | ?> |
| 4 | -<div><span class="wps-h2"><?php _e( 'Payment mode choice', 'wpshop' ); ?> :</span></div> |
|
| 5 | -<?php if ( ! empty( $payment_modes ) ) : ?> |
|
| 6 | -<?php $count_payment_mode = count( $payment_modes ); ?> |
|
| 7 | -<ul class="wps-itemList" id="wps-shipping-method-list-container" data-nonce="<?php echo wp_create_nonce( 'wps_load_shipping_methods' ); ?>"> |
|
| 8 | - <?php foreach ( $payment_modes as $payment_mode_id => $payment_mode ) : ?> |
|
| 9 | - <?php if ( $default_choice == $payment_mode_id ) : |
|
| 4 | +<div><span class="wps-h2"><?php _e('Payment mode choice', 'wpshop'); ?> :</span></div> |
|
| 5 | +<?php if (!empty($payment_modes)) : ?> |
|
| 6 | +<?php $count_payment_mode = count($payment_modes); ?> |
|
| 7 | +<ul class="wps-itemList" id="wps-shipping-method-list-container" data-nonce="<?php echo wp_create_nonce('wps_load_shipping_methods'); ?>"> |
|
| 8 | + <?php foreach ($payment_modes as $payment_mode_id => $payment_mode) : ?> |
|
| 9 | + <?php if ($default_choice == $payment_mode_id) : |
|
| 10 | 10 | $class = 'wps-activ'; |
| 11 | 11 | $checked = 'checked="checked"'; |
| 12 | 12 | else : |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | endif; ?> |
| 15 | 15 | <li class="<?php echo $class; ?> wps-bloc-loader"> |
| 16 | 16 | <label> |
| 17 | - <span><input type="radio" name="wps-payment-method" value="<?php echo $payment_mode_id; ?>" id="<?php echo $payment_mode_id ; ?>" <?php echo $checked; ?> /></span> |
|
| 17 | + <span><input type="radio" name="wps-payment-method" value="<?php echo $payment_mode_id; ?>" id="<?php echo $payment_mode_id; ?>" <?php echo $checked; ?> /></span> |
|
| 18 | 18 | <span class="wps-shipping-method-logo"> |
| 19 | - <?php echo ( ! empty( $payment_mode['logo'] ) ? ( (strstr( $payment_mode['logo'], 'http://' ) === false ) ? wp_get_attachment_image( $payment_mode['logo'], 'full' ) : '<img src="' . $payment_mode['logo'] . '" alt="" />' ) : '' ); ?> |
|
| 19 | + <?php echo (!empty($payment_mode['logo']) ? ((strstr($payment_mode['logo'], 'http://') === false) ? wp_get_attachment_image($payment_mode['logo'], 'full') : '<img src="' . $payment_mode['logo'] . '" alt="" />') : ''); ?> |
|
| 20 | 20 | </span> |
| 21 | - <span class="wps-shipping-method-name"><strong><?php _e( $payment_mode['name'], 'wpshop' ); ?></strong></span> |
|
| 21 | + <span class="wps-shipping-method-name"><strong><?php _e($payment_mode['name'], 'wpshop'); ?></strong></span> |
|
| 22 | 22 | </label> |
| 23 | 23 | <div class="wps-itemList-content"> |
| 24 | - <?php _e( $payment_mode['description'], 'wpshop' ); ?> |
|
| 24 | + <?php _e($payment_mode['description'], 'wpshop'); ?> |
|
| 25 | 25 | </div> |
| 26 | 26 | </li> |
| 27 | 27 | <?php endforeach; ?> |
| 28 | 28 | </ul> |
| 29 | 29 | <?php else : ?> |
| 30 | - <div class="wps-alert-info"><?php _e( 'No payment mode available', 'wpshop' ); ?> </div> |
|
| 30 | + <div class="wps-alert-info"><?php _e('No payment mode available', 'wpshop'); ?> </div> |
|
| 31 | 31 | <?php endif; ?> |
@@ -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,11 +410,11 @@ 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 | /** Check if a cart already exist. If there is already a cart that is not the same type (could be a cart or a quotation) */ |
| 416 | - if ( empty( $from_admin ) ){ |
|
| 417 | - if(isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type'] ) { |
|
| 416 | + if (empty($from_admin)) { |
|
| 417 | + if (isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type']) { |
|
| 418 | 418 | return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop'); |
| 419 | 419 | } |
| 420 | 420 | else { |
@@ -427,19 +427,19 @@ discard block |
||
| 427 | 427 | $order_items = array(); |
| 428 | 428 | |
| 429 | 429 | foreach ($product_list as $pid => $product_more_content) { |
| 430 | - if ( count($product_list) == 1 ) { |
|
| 431 | - if ( !isset( $quantity[$pid] ) ) $quantity[$pid] = 1; |
|
| 430 | + if (count($product_list) == 1) { |
|
| 431 | + if (!isset($quantity[$pid])) $quantity[$pid] = 1; |
|
| 432 | 432 | $product = wpshop_products::get_product_data($product_more_content['id'], false, '"publish", "free_product"'); |
| 433 | 433 | /** Check if the selected product exist */ |
| 434 | - if ( $product === false ) return __('This product does not exist', 'wpshop'); |
|
| 434 | + if ($product === false) return __('This product does not exist', 'wpshop'); |
|
| 435 | 435 | |
| 436 | 436 | /** Get information about the product price */ |
| 437 | 437 | $product_price_check = wpshop_prices::get_product_price($product, 'check_only'); |
| 438 | - if ( $product_price_check !== true ) return $product_price_check; |
|
| 438 | + if ($product_price_check !== true) return $product_price_check; |
|
| 439 | 439 | |
| 440 | 440 | $the_quantity = 1; |
| 441 | 441 | |
| 442 | - if ( !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) ) { |
|
| 442 | + if (!empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0])) { |
|
| 443 | 443 | /** Get the asked quantity for each product and check if there is enough stock */ |
| 444 | 444 | $the_quantity = $quantity[$pid]; |
| 445 | 445 | } |
@@ -451,127 +451,127 @@ discard block |
||
| 451 | 451 | //$quantity[$pid] = $the_quantity; |
| 452 | 452 | |
| 453 | 453 | $variation_id = 0; |
| 454 | - if ( !empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' ){ |
|
| 454 | + if (!empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined') { |
|
| 455 | 455 | $variation_id = $product_more_content['variations'][0]; |
| 456 | 456 | } |
| 457 | 457 | //$quantity_to_check = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($_SESSION['cart']['order_items'][$pid]) && !empty($_SESSION['cart']['order_items'][$pid]['item_qty']) ) ? $_SESSION['cart']['order_items'][$pid]['item_qty'] : $the_quantity; |
| 458 | 458 | |
| 459 | 459 | $wps_product_ctr = new wps_product_ctr(); |
| 460 | - $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id ); |
|
| 461 | - if ( $product_stock !== true ) { |
|
| 460 | + $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id); |
|
| 461 | + if ($product_stock !== true) { |
|
| 462 | 462 | return $product_stock; |
| 463 | 463 | } |
| 464 | - $count_items += (int) $product_more_content['product_qty']; |
|
| 464 | + $count_items += (int)$product_more_content['product_qty']; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | $order_items[$pid]['product_id'] = $product_more_content['id']; |
| 468 | 468 | $order_items[$pid]['product_qty'] = $the_quantity; |
| 469 | 469 | |
| 470 | 470 | /** For product with variation */ |
| 471 | - $order_items[$pid]['product_variation_type'] = !empty( $product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 471 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 472 | 472 | $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
| 473 | 473 | $order_items[$pid]['product_variation'] = ''; |
| 474 | - if ( !empty($product_more_content['variations']) ) { |
|
| 475 | - foreach ( $product_more_content['variations'] as $variation_id) { |
|
| 474 | + if (!empty($product_more_content['variations'])) { |
|
| 475 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 476 | 476 | $order_items[$pid]['product_variation'][] = $variation_id; |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - $current_cart = ( !empty( $order_meta )) ? $order_meta : array(); |
|
| 481 | + $current_cart = (!empty($order_meta)) ? $order_meta : array(); |
|
| 482 | 482 | |
| 483 | - foreach( $current_cart['order_items'] as $item_id => $item ) { |
|
| 484 | - if( !array_key_exists( $item_id, $order_items ) ) { |
|
| 483 | + foreach ($current_cart['order_items'] as $item_id => $item) { |
|
| 484 | + if (!array_key_exists($item_id, $order_items)) { |
|
| 485 | 485 | $count_items += $item['item_qty']; |
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
| 489 | - if( !empty( $wpshop_cart_option ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) && (int) $count_items > (int) $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) { |
|
| 488 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 489 | + if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed']) && (int)$count_items > (int)$wpshop_cart_option['total_nb_of_item_allowed'][0]) { |
|
| 490 | 490 | return __('No more products can be added to your cart.', 'wpshop'); |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart ); |
|
| 493 | + $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart); |
|
| 494 | 494 | |
| 495 | - if( empty($from_admin) ) { |
|
| 495 | + if (empty($from_admin)) { |
|
| 496 | 496 | self::store_cart_in_session($order); |
| 497 | 497 | /** Store the cart into database for connected user */ |
| 498 | - if ( get_current_user_id() ) { |
|
| 498 | + if (get_current_user_id()) { |
|
| 499 | 499 | $this->persistent_cart_update(); |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | else { |
| 503 | - update_post_meta($order_id, '_order_postmeta', $order ); |
|
| 503 | + update_post_meta($order_id, '_order_postmeta', $order); |
|
| 504 | 504 | |
| 505 | 505 | } |
| 506 | 506 | return 'success'; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - function prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected = array() ) { |
|
| 509 | + function prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected = array()) { |
|
| 510 | 510 | $product_price = ''; |
| 511 | 511 | $product_data = wpshop_products::get_product_data($product_id); |
| 512 | 512 | |
| 513 | 513 | // Free vars |
| 514 | - if ( !empty($wpshop_variation_selected['free']) ){ |
|
| 514 | + if (!empty($wpshop_variation_selected['free'])) { |
|
| 515 | 515 | $free_variations = $wpshop_variation_selected['free']; |
| 516 | 516 | unset($wpshop_variation_selected['free']); |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | // If product have many variations |
| 520 | - if ( count($wpshop_variation_selected ) > 1 ) { |
|
| 521 | - if ( !empty($wpshop_variation_selected) ) { |
|
| 522 | - $product_with_variation = wpshop_products::get_variation_by_priority( $wpshop_variation_selected, $product_id, true ); |
|
| 520 | + if (count($wpshop_variation_selected) > 1) { |
|
| 521 | + if (!empty($wpshop_variation_selected)) { |
|
| 522 | + $product_with_variation = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - if ( !empty($product_with_variation[$product_id]['variations']) ) { |
|
| 525 | + if (!empty($product_with_variation[$product_id]['variations'])) { |
|
| 526 | 526 | $product = $product_data; |
| 527 | 527 | $has_variation = true; |
| 528 | 528 | $head_product_id = $product_id; |
| 529 | 529 | |
| 530 | - if ( !empty($product_with_variation[$product_id]['variations']) && ( count($product_with_variation[$product_id]['variations']) == 1 ) && ($product_with_variation[$product_id]['variation_priority'] != 'single') ) { |
|
| 530 | + if (!empty($product_with_variation[$product_id]['variations']) && (count($product_with_variation[$product_id]['variations']) == 1) && ($product_with_variation[$product_id]['variation_priority'] != 'single')) { |
|
| 531 | 531 | $product_id = $product_with_variation[$product_id]['variations'][0]; |
| 532 | 532 | } |
| 533 | 533 | $product = wpshop_products::get_product_data($product_id, true); |
| 534 | 534 | |
| 535 | - $the_product = array_merge( array( |
|
| 535 | + $the_product = array_merge(array( |
|
| 536 | 536 | 'product_id' => $product_id, |
| 537 | 537 | 'product_qty' => $product_qty |
| 538 | 538 | ), $product); |
| 539 | 539 | |
| 540 | 540 | /* Add variation to product into cart for storage */ |
| 541 | - if ( !empty($product_with_variation[$head_product_id]['variations']) ) { |
|
| 542 | - $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']) ); |
|
| 541 | + if (!empty($product_with_variation[$head_product_id]['variations'])) { |
|
| 542 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority'])); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | $product_data = $the_product; |
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | - $product_to_add_to_cart = array( $product_id => array( 'id' => $product_id, 'product_qty' => $product_qty ) ); |
|
| 549 | + $product_to_add_to_cart = array($product_id => array('id' => $product_id, 'product_qty' => $product_qty)); |
|
| 550 | 550 | |
| 551 | - if ( !empty( $wpshop_variation_selected ) ) { |
|
| 552 | - $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true ); |
|
| 553 | - if ( !empty($variation_calculator[$product_id]) ) { |
|
| 551 | + if (!empty($wpshop_variation_selected)) { |
|
| 552 | + $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
| 553 | + if (!empty($variation_calculator[$product_id])) { |
|
| 554 | 554 | $product_to_add_to_cart[$product_id] = array_merge($product_to_add_to_cart[$product_id], $variation_calculator[$product_id]); |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | $new_pid = $product_id; |
| 559 | 559 | //Create custom ID on single variations Product |
| 560 | - 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' ) { |
|
| 560 | + 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') { |
|
| 561 | 561 | $tmp_obj = $product_to_add_to_cart[$product_id]; |
| 562 | - unset( $product_to_add_to_cart[$product_id] ); |
|
| 562 | + unset($product_to_add_to_cart[$product_id]); |
|
| 563 | 563 | $key = $product_id; |
| 564 | - foreach( $tmp_obj['variations'] as $variation_key) { |
|
| 565 | - $key.= '__'. $variation_key; |
|
| 564 | + foreach ($tmp_obj['variations'] as $variation_key) { |
|
| 565 | + $key .= '__' . $variation_key; |
|
| 566 | 566 | } |
| 567 | 567 | $product_to_add_to_cart[$key] = $tmp_obj; |
| 568 | 568 | $new_pid = $key; |
| 569 | 569 | } |
| 570 | 570 | // Add free variations |
| 571 | - if( !empty($free_variations) ) { |
|
| 571 | + if (!empty($free_variations)) { |
|
| 572 | 572 | $product_to_add_to_cart[$new_pid]['free_variation'] = $free_variations; |
| 573 | 573 | } |
| 574 | - return array( $product_to_add_to_cart, $new_pid ); |
|
| 574 | + return array($product_to_add_to_cart, $new_pid); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -582,67 +582,67 @@ discard block |
||
| 582 | 582 | * @param boolean $from_admin |
| 583 | 583 | * @return array |
| 584 | 584 | */ |
| 585 | - function calcul_cart_information( $product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false ) { |
|
| 585 | + function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) { |
|
| 586 | 586 | // Price piloting option |
| 587 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 587 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 588 | 588 | |
| 589 | 589 | // Init vars |
| 590 | - $cart_infos = ( !empty($current_cart) ) ? $current_cart : ( ( !empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ) ? $_SESSION['cart'] : array() ); |
|
| 591 | - $cart_items = ( !empty($current_cart) && !empty($current_cart['order_items']) ) ? $current_cart['order_items'] : array(); |
|
| 592 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
| 590 | + $cart_infos = (!empty($current_cart)) ? $current_cart : ((!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin) ? $_SESSION['cart'] : array()); |
|
| 591 | + $cart_items = (!empty($current_cart) && !empty($current_cart['order_items'])) ? $current_cart['order_items'] : array(); |
|
| 592 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
| 593 | 593 | $order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array(); |
| 594 | 594 | $total_weight = $nb_of_items = $order_shipping_cost_by_article = 0; |
| 595 | 595 | $order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0; |
| 596 | 596 | $cart_infos['order_amount_to_pay_now'] = 0; |
| 597 | 597 | |
| 598 | 598 | // If Product list is not empty, add products to order |
| 599 | - if( !empty($product_list) ) { |
|
| 600 | - foreach ( $product_list as $product_id => $d ) { |
|
| 599 | + if (!empty($product_list)) { |
|
| 600 | + foreach ($product_list as $product_id => $d) { |
|
| 601 | 601 | $product_key = $product_id; |
| 602 | - if( isset( $d['product_qty']) ) { |
|
| 602 | + if (isset($d['product_qty'])) { |
|
| 603 | 603 | // Formate datas |
| 604 | 604 | $product_id = $head_product_id = $d['product_id']; |
| 605 | 605 | $product_qty = $d['product_qty']; |
| 606 | 606 | $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
| 607 | 607 | |
| 608 | 608 | // If product is a single variation product |
| 609 | - if ( !empty($product_variation) && ( count($product_variation) == 1 ) ) { |
|
| 609 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 610 | 610 | $product_id = $product_variation[0]; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | // Construct final product |
| 614 | 614 | $product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"'); |
| 615 | - $the_product = array_merge( array('product_id' => $d['product_id'], 'product_qty' => $product_qty ), $product); |
|
| 615 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => $product_qty), $product); |
|
| 616 | 616 | |
| 617 | 617 | // Add variation to product into cart for storage |
| 618 | - if ( !empty($product_variation) ) { |
|
| 619 | - $the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']) ); |
|
| 618 | + if (!empty($product_variation)) { |
|
| 619 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | // Free Variations Checking |
| 623 | - if ( !empty( $d['free_variation'] ) ) { |
|
| 623 | + if (!empty($d['free_variation'])) { |
|
| 624 | 624 | $the_product['item_meta']['free_variation'] = $d['free_variation']; |
| 625 | 625 | $head_product_id = $the_product['product_id']; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | // If product is a variation, we check parent product general |
| 629 | - if( get_post_type( $the_product['product_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 630 | - $parent_def = wpshop_products::get_parent_variation( $the_product['product_id'] ); |
|
| 631 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 632 | - $variation_def = get_post_meta( $parent_def['parent_post']->ID, '_wpshop_variation_defining', true ); |
|
| 629 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 630 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 631 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 632 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 633 | 633 | $parent_meta = $parent_def['parent_post_meta']; |
| 634 | - 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 ) { |
|
| 635 | - $the_product['product_price'] += number_format( str_replace( ',', '.', $parent_meta['product_price'] ), 2, '.', '' ); |
|
| 636 | - $the_product['price_ht'] += number_format( str_replace( ',', '.',$parent_meta['price_ht']) , 2, '.', '' ); |
|
| 637 | - $the_product['tva'] += number_format( str_replace( ',', '.', $parent_meta['tva']) , 2, '.', '' ); |
|
| 634 | + 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) { |
|
| 635 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 636 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 637 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | // Delete product if its qty is equals to zero, else add this product to order |
| 643 | - if( empty( $d['product_qty'] ) ) { |
|
| 644 | - unset( $cart_items[$product_key] ); |
|
| 645 | - unset( $cart_infos['order_items'][$product_key] ); |
|
| 643 | + if (empty($d['product_qty'])) { |
|
| 644 | + unset($cart_items[$product_key]); |
|
| 645 | + unset($cart_infos['order_items'][$product_key]); |
|
| 646 | 646 | } |
| 647 | 647 | else { |
| 648 | 648 | $wps_orders = new wps_orders_ctr(); |
@@ -653,16 +653,16 @@ discard block |
||
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | // Add automaticaly Add-to-cart Products |
| 656 | - $cart_items = $this->add_automaticaly_product_to_cart( $cart_items ); |
|
| 656 | + $cart_items = $this->add_automaticaly_product_to_cart($cart_items); |
|
| 657 | 657 | |
| 658 | 658 | // Calcul Cart Informations |
| 659 | 659 | $cart_has_special_product = false; |
| 660 | - if( !empty($cart_items) && is_array($cart_items) ) { |
|
| 661 | - foreach( $cart_items as $item_id => $item ) { |
|
| 660 | + if (!empty($cart_items) && is_array($cart_items)) { |
|
| 661 | + foreach ($cart_items as $item_id => $item) { |
|
| 662 | 662 | |
| 663 | - if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) { |
|
| 663 | + if (!empty($item['item_amount_to_pay_now'])) { |
|
| 664 | 664 | $cart_has_special_product = true; |
| 665 | - $cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] ); |
|
| 665 | + $cart_infos['order_amount_to_pay_now'] += ($item['item_amount_to_pay_now'] * $item['item_qty']); |
|
| 666 | 666 | } |
| 667 | 667 | else { |
| 668 | 668 | $cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc']; |
@@ -671,11 +671,11 @@ discard block |
||
| 671 | 671 | $order_total_ht += $item['item_total_ht']; |
| 672 | 672 | $order_total_ttc += $item['item_total_ttc']; |
| 673 | 673 | // VAT |
| 674 | - if( !empty($order_tva[ $item['item_tva_rate'] ]) ) { |
|
| 675 | - $order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount']; |
|
| 674 | + if (!empty($order_tva[$item['item_tva_rate']])) { |
|
| 675 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 676 | 676 | } |
| 677 | 677 | else { |
| 678 | - $order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount']; |
|
| 678 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 679 | 679 | } |
| 680 | 680 | } |
| 681 | 681 | } |
@@ -689,13 +689,13 @@ discard block |
||
| 689 | 689 | $cart_infos['order_total_ttc'] = $order_total_ttc; |
| 690 | 690 | |
| 691 | 691 | // Calcul Shipping cost |
| 692 | - if( !$from_admin && empty( $cart_infos['order_shipping_cost_fixe'] ) && empty($_SESSION[ 'wps-pos-addon' ]) ) { |
|
| 692 | + if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe']) && empty($_SESSION['wps-pos-addon'])) { |
|
| 693 | 693 | $wps_shipping = new wps_shipping(); |
| 694 | - $total_cart_ht_or_ttc_regarding_config = ( !empty($price_piloting) && $price_piloting == 'HT' ) ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
| 695 | - $cart_weight = $wps_shipping->calcul_cart_weight( $cart_infos['order_items'] ); |
|
| 696 | - $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost( $cart_infos['order_items'] ); |
|
| 697 | - foreach( $cart_infos['order_items'] as $item ) { |
|
| 698 | - if( !empty($item['item_is_downloadable_']) && ( __( $item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
|
| 694 | + $total_cart_ht_or_ttc_regarding_config = (!empty($price_piloting) && $price_piloting == 'HT') ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
| 695 | + $cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']); |
|
| 696 | + $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']); |
|
| 697 | + foreach ($cart_infos['order_items'] as $item) { |
|
| 698 | + if (!empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) { |
|
| 699 | 699 | $is_downloadable_products = 'is_downloadable_'; |
| 700 | 700 | } else { |
| 701 | 701 | $is_downloadable_products = ''; |
@@ -707,39 +707,39 @@ discard block |
||
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | // If Price piloting is ET, calcul VAT on Shipping cost |
| 710 | - if ( !empty($price_piloting) && $price_piloting == 'HT') { |
|
| 711 | - $shipping_cost_vat = ( !empty($cart_infos['order_shipping_cost']) ) ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * number_format( $cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
| 710 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 711 | + $shipping_cost_vat = (!empty($cart_infos['order_shipping_cost'])) ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
| 712 | 712 | $order_tva['VAT_shipping_cost'] = $shipping_cost_vat; |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | // Calcul VAT Total |
| 716 | - if( !empty($order_tva) ) { |
|
| 717 | - foreach( $order_tva as $vat_rate => $vat_value ) { |
|
| 716 | + if (!empty($order_tva)) { |
|
| 717 | + foreach ($order_tva as $vat_rate => $vat_value) { |
|
| 718 | 718 | $total_vat += $vat_value; |
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | // Recap totals |
| 723 | - $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 ); |
|
| 723 | + $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); |
|
| 724 | 724 | $cart_infos['order_grand_total_before_discount'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc']; |
| 725 | 725 | |
| 726 | 726 | // Total to pay now |
| 727 | 727 | $total_received = 0; |
| 728 | - if( !empty( $cart_infos['order_payment']['received'] ) ) { |
|
| 729 | - foreach( $cart_infos['order_payment']['received'] as $received ) { |
|
| 730 | - $total_received += ( ( !empty($received['status']) && ( $received['status'] == 'payment_received') && !empty($received['received_amount']) ) ? $received['received_amount'] : 0 ); |
|
| 728 | + if (!empty($cart_infos['order_payment']['received'])) { |
|
| 729 | + foreach ($cart_infos['order_payment']['received'] as $received) { |
|
| 730 | + $total_received += ((!empty($received['status']) && ($received['status'] == 'payment_received') && !empty($received['received_amount'])) ? $received['received_amount'] : 0); |
|
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | $cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] - $total_received; |
| 734 | 734 | |
| 735 | 735 | // Apply cart rules |
| 736 | - $cart_rule = wpshop_cart_rules::get_cart_rule( $cart_infos['order_grand_total'] ); |
|
| 737 | - if( $cart_rule['cart_rule_exist'] ) { |
|
| 738 | - if ( !empty( $cart_rule['cart_rule_info']['discount_type'] ) ) { |
|
| 739 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount' ) { |
|
| 736 | + $cart_rule = wpshop_cart_rules::get_cart_rule($cart_infos['order_grand_total']); |
|
| 737 | + if ($cart_rule['cart_rule_exist']) { |
|
| 738 | + if (!empty($cart_rule['cart_rule_info']['discount_type'])) { |
|
| 739 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount') { |
|
| 740 | 740 | $cart_infos['order_discount_type'] = 'amount'; |
| 741 | 741 | } |
| 742 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'percent_discount' ) { |
|
| 742 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'percent_discount') { |
|
| 743 | 743 | $cart_infos['order_discount_type'] = 'percent'; |
| 744 | 744 | } |
| 745 | 745 | } |
@@ -747,15 +747,15 @@ discard block |
||
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // Apply coupons |
| 750 | - if( !empty( $_SESSION['cart']) && !$from_admin ) { |
|
| 751 | - if( !empty($_SESSION['cart']['coupon_id']) ) { |
|
| 750 | + if (!empty($_SESSION['cart']) && !$from_admin) { |
|
| 751 | + if (!empty($_SESSION['cart']['coupon_id'])) { |
|
| 752 | 752 | $wps_coupon_mdl = new wps_coupon_model(); |
| 753 | - $coupon = $wps_coupon_mdl->get_coupon_data( $_SESSION['cart']['coupon_id'] ); |
|
| 754 | - if( !empty($coupon) && !empty($coupon['wpshop_coupon_code']) ) { |
|
| 753 | + $coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']); |
|
| 754 | + if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) { |
|
| 755 | 755 | $wps_coupon = new wps_coupon_ctr(); |
| 756 | - $coupon_checking = $wps_coupon->applyCoupon( $coupon['wpshop_coupon_code'] ); |
|
| 756 | + $coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']); |
|
| 757 | 757 | // If Coupon conditions are Ok |
| 758 | - if( !empty($coupon_checking) && !empty( $coupon_checking['status'] ) && ( true == $coupon_checking['status'] ) ) { |
|
| 758 | + if (!empty($coupon_checking) && !empty($coupon_checking['status']) && (true == $coupon_checking['status'])) { |
|
| 759 | 759 | $cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type']; |
| 760 | 760 | $cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value']; |
| 761 | 761 | } |
@@ -764,51 +764,51 @@ discard block |
||
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | // Checking Discounts |
| 767 | - if( !empty($cart_infos['order_discount_type']) && isset( $cart_infos['order_discount_value'] ) ) { |
|
| 767 | + if (!empty($cart_infos['order_discount_type']) && isset($cart_infos['order_discount_value'])) { |
|
| 768 | 768 | // Calcul discount on Order |
| 769 | 769 | switch ($cart_infos['order_discount_type']) { |
| 770 | 770 | case 'amount': |
| 771 | - $cart_infos['order_discount_amount_total_cart'] = number_format( str_replace( ',', '.', $cart_infos['order_discount_value'] ), 2, '.', ''); |
|
| 771 | + $cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', ''); |
|
| 772 | 772 | break; |
| 773 | 773 | case 'percent': |
| 774 | - $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); |
|
| 774 | + $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); |
|
| 775 | 775 | break; |
| 776 | 776 | } |
| 777 | - if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) { |
|
| 777 | + if (number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format($cart_infos['order_grand_total'], 2, '.', '')) { |
|
| 778 | 778 | $cart_infos['order_grand_total'] = 0; |
| 779 | 779 | } |
| 780 | 780 | else { |
| 781 | - $cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
| 781 | + $cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
| 782 | 782 | } |
| 783 | - $cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
| 783 | + $cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | // Apply Partial Payments |
| 787 | 787 | $wpshop_payment = new wpshop_payment(); |
| 788 | - if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) { |
|
| 789 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' ); |
|
| 788 | + if (!empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation') { |
|
| 789 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total'], 'for_quotation'); |
|
| 790 | 790 | } |
| 791 | 791 | else { |
| 792 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] ); |
|
| 792 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']); |
|
| 793 | 793 | } |
| 794 | - if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) { |
|
| 794 | + if (!empty($partial_payment['amount_to_pay']) && (empty($cart_infos['order_status']) || $cart_infos['order_status'] == 'awaiting_payment') && (empty($product_partial_payment_amount))) { |
|
| 795 | 795 | unset($partial_payment['display']); |
| 796 | - $cart_infos['order_partial_payment'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
| 797 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
| 796 | + $cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
| 797 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
| 798 | 798 | } |
| 799 | 799 | // Apply Partial Payments : Subscription part. |
| 800 | - elseif ( ! empty( $cart_has_special_product ) ) { |
|
| 801 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $cart_infos['order_amount_to_pay_now'] ), 2, '.', ''); |
|
| 800 | + elseif (!empty($cart_has_special_product)) { |
|
| 801 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $cart_infos['order_amount_to_pay_now']), 2, '.', ''); |
|
| 802 | 802 | $cart_infos['order_product_partial_payment'] = 'subscription'; |
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | // Cart Type |
| 806 | - if ( isset( $_SESSION['cart']['cart_type'] ) ) { |
|
| 806 | + if (isset($_SESSION['cart']['cart_type'])) { |
|
| 807 | 807 | $cart_infos['cart_type'] = $_SESSION['cart']['cart_type']; |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | // Apply Extra actions on cart infos |
| 811 | - $cart_infos = apply_filters( 'wps_extra_calcul_in_cart', $cart_infos, $_SESSION ); |
|
| 811 | + $cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION); |
|
| 812 | 812 | |
| 813 | 813 | return $cart_infos; |
| 814 | 814 | } |
@@ -818,18 +818,18 @@ discard block |
||
| 818 | 818 | * @param array $cart_items |
| 819 | 819 | * @return array |
| 820 | 820 | */ |
| 821 | - function add_automaticaly_product_to_cart( $cart_items ) { |
|
| 821 | + function add_automaticaly_product_to_cart($cart_items) { |
|
| 822 | 822 | global $wpdb; |
| 823 | 823 | // Recovery all products with options |
| 824 | 824 | $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
| 825 | 825 | $post_list_with_options = $wpdb->get_results($query); |
| 826 | 826 | $wps_orders = new wps_orders_ctr(); |
| 827 | - if ( !empty($post_list_with_options) && !empty($cart_items) ) { |
|
| 828 | - foreach ( $post_list_with_options as $product_info) { |
|
| 827 | + if (!empty($post_list_with_options) && !empty($cart_items)) { |
|
| 828 | + foreach ($post_list_with_options as $product_info) { |
|
| 829 | 829 | $product_meta = unserialize($product_info->meta_value); |
| 830 | - if ( !empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id]) ) { |
|
| 830 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id])) { |
|
| 831 | 831 | $product = wpshop_products::get_product_data($product_info->post_id, true, '"draft", "publish"'); |
| 832 | - $the_product = array_merge( array( |
|
| 832 | + $the_product = array_merge(array( |
|
| 833 | 833 | 'product_id' => $product_info->post_id, |
| 834 | 834 | 'product_qty' => 1 |
| 835 | 835 | ), $product); |
@@ -843,28 +843,28 @@ discard block |
||
| 843 | 843 | |
| 844 | 844 | /** Ajax action to reload cart **/ |
| 845 | 845 | public static function wps_reload_cart() { |
| 846 | - check_ajax_referer( 'wps_reload_cart' ); |
|
| 846 | + check_ajax_referer('wps_reload_cart'); |
|
| 847 | 847 | |
| 848 | 848 | $wps_cart = new wps_cart(); |
| 849 | 849 | $result = $wps_cart->cart_content(); |
| 850 | 850 | |
| 851 | - wp_die( json_encode( array( 'response' => $result) ) ); |
|
| 851 | + wp_die(json_encode(array('response' => $result))); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | |
| 855 | 855 | /** Ajax action to reload mini cart */ |
| 856 | 856 | public function wps_reload_mini_cart() { |
| 857 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 857 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 858 | 858 | |
| 859 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) |
|
| 859 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_mini_cart')) |
|
| 860 | 860 | wp_die(); |
| 861 | 861 | |
| 862 | 862 | $wps_cart = new wps_cart(); |
| 863 | - $result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) ); |
|
| 864 | - $count_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $wps_cart->total_cart_items( $_SESSION['cart']['order_items'] ) : 0; |
|
| 863 | + $result = $wps_cart->mini_cart_content(sanitize_title($_POST['type'])); |
|
| 864 | + $count_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0; |
|
| 865 | 865 | $free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert'); |
| 866 | 866 | |
| 867 | - echo json_encode( array( 'response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert) ); |
|
| 867 | + echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert)); |
|
| 868 | 868 | die(); |
| 869 | 869 | } |
| 870 | 870 | |
@@ -874,35 +874,35 @@ discard block |
||
| 874 | 874 | * @return string |
| 875 | 875 | */ |
| 876 | 876 | function display_wps_numeration_cart() { |
| 877 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $_SESSION['cart']['order_items'] : array(); |
|
| 878 | - $total_cart_item = self::total_cart_items( $cart_items ); |
|
| 877 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $_SESSION['cart']['order_items'] : array(); |
|
| 878 | + $total_cart_item = self::total_cart_items($cart_items); |
|
| 879 | 879 | |
| 880 | 880 | ob_start(); |
| 881 | - require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart") ); |
|
| 881 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart")); |
|
| 882 | 882 | $output = ob_get_contents(); |
| 883 | 883 | ob_end_clean(); |
| 884 | 884 | return $output; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - public function display_button_add_to_cart( $args ) { |
|
| 888 | - $button_text = __( 'Add to cart', 'wpshop' ); |
|
| 887 | + public function display_button_add_to_cart($args) { |
|
| 888 | + $button_text = __('Add to cart', 'wpshop'); |
|
| 889 | 889 | $use_button = true; |
| 890 | - $output = __( 'No product has been found.', 'wpshop' ); |
|
| 890 | + $output = __('No product has been found.', 'wpshop'); |
|
| 891 | 891 | |
| 892 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
| 892 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 893 | 893 | |
| 894 | 894 | /** The user send the text in argument */ |
| 895 | - if ( !empty( $args['text' ] ) ) { |
|
| 895 | + if (!empty($args['text'])) { |
|
| 896 | 896 | $button_text = $args['text']; |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** The user send use input */ |
| 900 | - if ( !empty( $args['use_button'] ) && 'false' == $args['use_button'] ) { |
|
| 900 | + if (!empty($args['use_button']) && 'false' == $args['use_button']) { |
|
| 901 | 901 | $use_button = false; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | ob_start(); |
| 905 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart' ) ); |
|
| 905 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart')); |
|
| 906 | 906 | $output = ob_get_clean(); |
| 907 | 907 | } |
| 908 | 908 | |
@@ -911,21 +911,21 @@ discard block |
||
| 911 | 911 | |
| 912 | 912 | /** Ajax action to reload summary cart */ |
| 913 | 913 | public static function wps_reload_summary_cart() { |
| 914 | - check_ajax_referer( 'wps_reload_summary_cart' ); |
|
| 914 | + check_ajax_referer('wps_reload_summary_cart'); |
|
| 915 | 915 | |
| 916 | 916 | $wps_cart = new wps_cart(); |
| 917 | 917 | $result = $wps_cart->resume_cart_content(); |
| 918 | 918 | |
| 919 | - wp_die( json_encode( array( 'response' => $result, ) ) ); |
|
| 919 | + wp_die(json_encode(array('response' => $result,))); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | |
| 923 | 923 | /** Display Apply Coupon Interface **/ |
| 924 | 924 | function display_apply_coupon_interface() { |
| 925 | 925 | $output = ''; |
| 926 | - if ( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
| 926 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 927 | 927 | ob_start(); |
| 928 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon") ); |
|
| 928 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon")); |
|
| 929 | 929 | $output = ob_get_contents(); |
| 930 | 930 | ob_end_clean(); |
| 931 | 931 | } |
@@ -935,30 +935,30 @@ discard block |
||
| 935 | 935 | |
| 936 | 936 | /** AJAX - action to apply coupon **/ |
| 937 | 937 | function wps_apply_coupon() { |
| 938 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 938 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 939 | 939 | |
| 940 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) |
|
| 940 | + if (!wp_verify_nonce($_wpnonce, 'wps_apply_coupon')) |
|
| 941 | 941 | wp_die(); |
| 942 | 942 | |
| 943 | 943 | $status = false; $response = ''; |
| 944 | - $coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null; |
|
| 945 | - if( !empty($coupon) ) { |
|
| 944 | + $coupon = (!empty($_POST['coupon_code'])) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null; |
|
| 945 | + if (!empty($coupon)) { |
|
| 946 | 946 | $wps_coupon_ctr = new wps_coupon_ctr(); |
| 947 | 947 | $result = $wps_coupon_ctr->applyCoupon($coupon); |
| 948 | - if ($result['status']===true) { |
|
| 948 | + if ($result['status'] === true) { |
|
| 949 | 949 | $order = $this->calcul_cart_information(array()); |
| 950 | 950 | $this->store_cart_in_session($order); |
| 951 | 951 | $status = true; |
| 952 | - $response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>'; |
|
| 952 | + $response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>'; |
|
| 953 | 953 | } |
| 954 | 954 | else { |
| 955 | - $response = '<div class="wps-alert-error">' .$result['message']. '</div>'; |
|
| 955 | + $response = '<div class="wps-alert-error">' . $result['message'] . '</div>'; |
|
| 956 | 956 | } |
| 957 | 957 | } |
| 958 | 958 | else { |
| 959 | - $response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>'; |
|
| 959 | + $response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>'; |
|
| 960 | 960 | } |
| 961 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 961 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 962 | 962 | die(); |
| 963 | 963 | } |
| 964 | 964 | |
@@ -967,24 +967,24 @@ discard block |
||
| 967 | 967 | * AJAX - Pass to step two in the Checkout tunnel |
| 968 | 968 | */ |
| 969 | 969 | public static function wps_cart_pass_to_step_two() { |
| 970 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 970 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 971 | 971 | |
| 972 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) |
|
| 972 | + if (!wp_verify_nonce($_wpnonce, 'wps_cart_pass_to_step_two')) |
|
| 973 | 973 | wp_die(); |
| 974 | 974 | |
| 975 | 975 | $status = false; $response = ''; |
| 976 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 977 | - if( !empty($checkout_page_id) ) { |
|
| 978 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 979 | - $step = ( get_current_user_id() != 0 ) ? 3 : 2; |
|
| 980 | - $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
|
| 976 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 977 | + if (!empty($checkout_page_id)) { |
|
| 978 | + $permalink_option = get_option('permalink_structure'); |
|
| 979 | + $step = (get_current_user_id() != 0) ? 3 : 2; |
|
| 980 | + $response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step; |
|
| 981 | 981 | $response = apply_filters('wps_extra_signup_actions', $response); |
| 982 | 982 | $status = true; |
| 983 | 983 | } |
| 984 | 984 | else { |
| 985 | - $response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>'; |
|
| 985 | + $response = '<div class="wps-alert-error">' . __('An error was occured, please retry later or contact the website administrator', 'wpshop') . '</div>'; |
|
| 986 | 986 | } |
| 987 | - echo json_encode( array( 'status' => $status, 'response' => $response)); |
|
| 987 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 988 | 988 | die(); |
| 989 | 989 | } |
| 990 | 990 | |
@@ -993,14 +993,14 @@ discard block |
||
| 993 | 993 | * AJAX - Empty the cart |
| 994 | 994 | */ |
| 995 | 995 | function wps_empty_cart() { |
| 996 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 996 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 997 | 997 | |
| 998 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) |
|
| 998 | + if (!wp_verify_nonce($_wpnonce, 'wps_empty_cart')) |
|
| 999 | 999 | wp_die(); |
| 1000 | 1000 | |
| 1001 | 1001 | |
| 1002 | 1002 | $this->empty_cart(); |
| 1003 | - echo json_encode( array( 'status' => true) ); |
|
| 1003 | + echo json_encode(array('status' => true)); |
|
| 1004 | 1004 | die(); |
| 1005 | 1005 | } |
| 1006 | 1006 | } |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | ?> |
| 3 | -<!-- <span class="wps-mini-cart-body-title"><strong><?php echo $total_cart_item; ?></strong><?php _e( 'item(s)', 'wpshop'); ?><span><strong><?php echo number_format( $total_cart, 2, '.', ''); ?></strong> <?php echo $currency; ?></span></span>--> |
|
| 3 | +<!-- <span class="wps-mini-cart-body-title"><strong><?php echo $total_cart_item; ?></strong><?php _e('item(s)', 'wpshop'); ?><span><strong><?php echo number_format($total_cart, 2, '.', ''); ?></strong> <?php echo $currency; ?></span></span>--> |
|
| 4 | 4 | <div> |
| 5 | 5 | <ul> |
| 6 | - <?php foreach( $cart_items as $item_id => $item ) : ?> |
|
| 6 | + <?php foreach ($cart_items as $item_id => $item) : ?> |
|
| 7 | 7 | <?php |
| 8 | - $item_post_type = get_post_type( $item_id ); |
|
| 9 | - if ( $item_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 10 | - $parent_def = wpshop_products::get_parent_variation( $item_id ); |
|
| 8 | + $item_post_type = get_post_type($item_id); |
|
| 9 | + if ($item_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 10 | + $parent_def = wpshop_products::get_parent_variation($item_id); |
|
| 11 | 11 | $parent_post = $parent_def['parent_post']; |
| 12 | 12 | $item_id = $parent_post->ID; |
| 13 | - $item_title = $parent_post->post_title; |
|
| 13 | + $item_title = $parent_post->post_title; |
|
| 14 | 14 | } |
| 15 | 15 | else { |
| 16 | 16 | $item_title = $item['item_name']; |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | ?> |
| 19 | 19 | <li id="wps_product_<?php echo $item_id; ?>"> |
| 20 | 20 | <div class="wps-cart-item-img"> |
| 21 | - <a href="<?php echo get_permalink( $item_id ); ?>" title=""> |
|
| 22 | - <?php echo get_the_post_thumbnail( $item_id, 'thumbnail' ); ?> |
|
| 21 | + <a href="<?php echo get_permalink($item_id); ?>" title=""> |
|
| 22 | + <?php echo get_the_post_thumbnail($item_id, 'thumbnail'); ?> |
|
| 23 | 23 | </a> |
| 24 | 24 | </div> |
| 25 | 25 | <div class="wps-cart-item-content"> |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | </a> |
| 29 | 29 | <?php |
| 30 | 30 | $variations_indicator = ''; |
| 31 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails( get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true) ) ; |
|
| 31 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 32 | 32 | $output_order = array(); |
| 33 | - if ( count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail) ) { |
|
| 34 | - foreach ( $product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 35 | - foreach ( $product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 36 | - if ( !empty($attribute_def->code) ) |
|
| 33 | + if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 34 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 35 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 36 | + if (!empty($attribute_def->code)) |
|
| 37 | 37 | $output_order[$attribute_def->code] = $position; |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display( $item['item_meta'], $output_order, 'cart' ); |
|
| 41 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'cart'); |
|
| 42 | 42 | ksort($variation_attribute_ordered['attribute_list']); |
| 43 | - if( !empty($variation_attribute_ordered['attribute_list']) ) { |
|
| 43 | + if (!empty($variation_attribute_ordered['attribute_list'])) { |
|
| 44 | 44 | $variations_indicator .= '<ul class="wps-cart-item-variations" >'; |
| 45 | - foreach ( $variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output ) { |
|
| 46 | - if ( !empty($attribute_variation_to_output) ) { |
|
| 45 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 46 | + if (!empty($attribute_variation_to_output)) { |
|
| 47 | 47 | $variations_indicator .= $attribute_variation_to_output; |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - $variations_indicator = apply_filters( 'wps_cart_item_variation_list', $variations_indicator, $variation_attribute_ordered, $item, 0 ); |
|
| 50 | + $variations_indicator = apply_filters('wps_cart_item_variation_list', $variations_indicator, $variation_attribute_ordered, $item, 0); |
|
| 51 | 51 | $variations_indicator .= '</ul>'; |
| 52 | 52 | } |
| 53 | 53 | echo $variations_indicator; |
| 54 | 54 | ?> |
| 55 | 55 | </div> |
| 56 | 56 | <div class="wps-cart-item-price"> |
| 57 | - <span class="wps-price"><?php echo wpshop_tools::formate_number( $item['item_total_ttc'] ); ?><span> <?php echo $currency; ?></span></span> |
|
| 58 | - <span class="wps-tva"><?php _e( 'ATI', 'wpshop'); ?></span><br> |
|
| 57 | + <span class="wps-price"><?php echo wpshop_tools::formate_number($item['item_total_ttc']); ?><span> <?php echo $currency; ?></span></span> |
|
| 58 | + <span class="wps-tva"><?php _e('ATI', 'wpshop'); ?></span><br> |
|
| 59 | 59 | </div> |
| 60 | 60 | <div class="wps-cart-item-close"> |
| 61 | - <button type="button" class="wps-bton-icon wps_cart_delete_product" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_set_qty_for_product_into_cart' ); ?>"><i class="wps-icon-trash"></i></button> |
|
| 61 | + <button type="button" class="wps-bton-icon wps_cart_delete_product" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_set_qty_for_product_into_cart'); ?>"><i class="wps-icon-trash"></i></button> |
|
| 62 | 62 | </div> |
| 63 | 63 | </li> |
| 64 | 64 | <?php endforeach; ?> |
| 65 | 65 | </ul> |
| 66 | 66 | </div> |
| 67 | -<p><?php _e( 'Shipping cost', 'wpshop' ); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); ?></strong>€</span></p> |
|
| 67 | +<p><?php _e('Shipping cost', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number($shipping_cost_ati); ?></strong>€</span></p> |
|
| 68 | 68 | |
| 69 | -<?php if ( !empty( $cart_content['coupon_id']) ) : ?> |
|
| 70 | - <p><?php _e( 'Total ATI before discount', 'wpshop' ); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number( $order_total_before_discount ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 71 | - <p><?php _e( 'Discount', 'wpshop' ); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number( $coupon_value ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 69 | +<?php if (!empty($cart_content['coupon_id'])) : ?> |
|
| 70 | + <p><?php _e('Total ATI before discount', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number($order_total_before_discount); ?></strong> <?php echo $currency; ?></span></p> |
|
| 71 | + <p><?php _e('Discount', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number($coupon_value); ?></strong> <?php echo $currency; ?></span></p> |
|
| 72 | 72 | <?php endif; ?> |
| 73 | 73 | |
| 74 | -<p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number( $total_ati ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 75 | -<button class="wps-bton-second-halfwidth wpsjq-closeFixedCart"><i class="wps-icon-arrowleft"></i><?php _e( 'Return', 'wpshop'); ?></button> |
|
| 76 | -<a href="<?php echo get_permalink( wpshop_tools::get_page_id( get_option('wpshop_cart_page_id') ) ); ?>" class="wps-bton-first-halfwidth" role="button"><i class="wps-icon-paiement"></i><?php _e( 'Order', 'wpshop'); ?></a> |
|
| 74 | +<p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number($total_ati); ?></strong> <?php echo $currency; ?></span></p> |
|
| 75 | +<button class="wps-bton-second-halfwidth wpsjq-closeFixedCart"><i class="wps-icon-arrowleft"></i><?php _e('Return', 'wpshop'); ?></button> |
|
| 76 | +<a href="<?php echo get_permalink(wpshop_tools::get_page_id(get_option('wpshop_cart_page_id'))); ?>" class="wps-bton-first-halfwidth" role="button"><i class="wps-icon-paiement"></i><?php _e('Order', 'wpshop'); ?></a> |
|
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) { exit; |
|
| 2 | 2 | } |
| 3 | 3 | class wps_message_ctr { |
| 4 | 4 | |
@@ -18,19 +18,19 @@ discard block |
||
| 18 | 18 | function __construct() { |
| 19 | 19 | |
| 20 | 20 | /** Js */ |
| 21 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 21 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 22 | 22 | // End if(). |
| 23 | 23 | $this->template_dir = WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/'; |
| 24 | 24 | // WP General actions |
| 25 | - add_action( 'admin_init', array( $this, 'wps_messages_init_actions' ) ); |
|
| 26 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
| 27 | - add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array( $this, 'messages_custom_columns' ) ); |
|
| 28 | - add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array( $this, 'messages_edit_columns' ) ); |
|
| 25 | + add_action('admin_init', array($this, 'wps_messages_init_actions')); |
|
| 26 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
| 27 | + add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array($this, 'messages_custom_columns')); |
|
| 28 | + add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array($this, 'messages_edit_columns')); |
|
| 29 | 29 | // Shortcodes |
| 30 | - add_shortcode( 'wps_message_histo', array( $this, 'display_message_histo_per_customer' ) ); |
|
| 31 | - add_shortcode( 'order_customer_personnal_informations', array( $this, 'order_personnal_informations' ) ); |
|
| 30 | + add_shortcode('wps_message_histo', array($this, 'display_message_histo_per_customer')); |
|
| 31 | + add_shortcode('order_customer_personnal_informations', array($this, 'order_personnal_informations')); |
|
| 32 | 32 | /** Ajax */ |
| 33 | - add_action( 'wp_ajax_get_content_message', array( $this, 'get_content_message' ) ); |
|
| 33 | + add_action('wp_ajax_get_content_message', array($this, 'get_content_message')); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | /** Css */ |
| 42 | 42 | add_thickbox(); |
| 43 | - wp_register_style( 'wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION ); |
|
| 44 | - wp_enqueue_style( 'wpeo-message-css' ); |
|
| 43 | + wp_register_style('wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION); |
|
| 44 | + wp_enqueue_style('wpeo-message-css'); |
|
| 45 | 45 | /** My js */ |
| 46 | - wp_enqueue_script( 'wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array( 'jquery', 'thickbox' ), WPS_MESSAGE_VERSION ); |
|
| 46 | + wp_enqueue_script('wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array('jquery', 'thickbox'), WPS_MESSAGE_VERSION); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -59,23 +59,23 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function create_message_type() { |
| 61 | 61 | |
| 62 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, array( |
|
| 62 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, array( |
|
| 63 | 63 | 'labels' => array( |
| 64 | - 'name' => __( 'Message', 'wpshop' ), |
|
| 65 | - 'singular_name' => __( 'message', 'wpshop' ), |
|
| 66 | - 'add_new' => __( 'Add message', 'wpshop' ), |
|
| 67 | - 'add_new_item' => __( 'Add New message', 'wpshop' ), |
|
| 68 | - 'edit' => __( 'Edit', 'wpshop' ), |
|
| 69 | - 'edit_item' => __( 'Edit message', 'wpshop' ), |
|
| 70 | - 'new_item' => __( 'New message', 'wpshop' ), |
|
| 71 | - 'view' => __( 'View message', 'wpshop' ), |
|
| 72 | - 'view_item' => __( 'View message', 'wpshop' ), |
|
| 73 | - 'search_items' => __( 'Search messages', 'wpshop' ), |
|
| 74 | - 'not_found' => __( 'No message found', 'wpshop' ), |
|
| 75 | - 'not_found_in_trash' => __( 'No message found in trash', 'wpshop' ), |
|
| 64 | + 'name' => __('Message', 'wpshop'), |
|
| 65 | + 'singular_name' => __('message', 'wpshop'), |
|
| 66 | + 'add_new' => __('Add message', 'wpshop'), |
|
| 67 | + 'add_new_item' => __('Add New message', 'wpshop'), |
|
| 68 | + 'edit' => __('Edit', 'wpshop'), |
|
| 69 | + 'edit_item' => __('Edit message', 'wpshop'), |
|
| 70 | + 'new_item' => __('New message', 'wpshop'), |
|
| 71 | + 'view' => __('View message', 'wpshop'), |
|
| 72 | + 'view_item' => __('View message', 'wpshop'), |
|
| 73 | + 'search_items' => __('Search messages', 'wpshop'), |
|
| 74 | + 'not_found' => __('No message found', 'wpshop'), |
|
| 75 | + 'not_found_in_trash' => __('No message found in trash', 'wpshop'), |
|
| 76 | 76 | 'parent-item-colon' => '', |
| 77 | 77 | ), |
| 78 | - 'description' => __( 'This is where store messages are stored.', 'wpshop' ), |
|
| 78 | + 'description' => __('This is where store messages are stored.', 'wpshop'), |
|
| 79 | 79 | 'public' => true, |
| 80 | 80 | 'show_ui' => true, |
| 81 | 81 | 'capability_type' => 'post', |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | 'show_in_nav_menus' => false, |
| 87 | 87 | 'rewrite' => false, |
| 88 | 88 | 'query_var' => true, |
| 89 | - 'supports' => array( 'title', 'editor' ), |
|
| 89 | + 'supports' => array('title', 'editor'), |
|
| 90 | 90 | 'has_archive' => false, |
| 91 | - ) ); |
|
| 91 | + )); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | function add_meta_boxes() { |
| 98 | 98 | |
| 99 | 99 | // Add message sending historic meta box |
| 100 | - add_meta_box( 'wpshop_message_histo', |
|
| 101 | - __( 'Message historic', 'wpshop' ), |
|
| 102 | - array( $this, 'message_histo_box' ), |
|
| 103 | - WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high' ); |
|
| 100 | + add_meta_box('wpshop_message_histo', |
|
| 101 | + __('Message historic', 'wpshop'), |
|
| 102 | + array($this, 'message_histo_box'), |
|
| 103 | + WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high'); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | * @param unknown_type $post |
| 110 | 110 | * @param unknown_type $params |
| 111 | 111 | */ |
| 112 | - function message_histo_box( $post, $params ) { |
|
| 112 | + function message_histo_box($post, $params) { |
|
| 113 | 113 | |
| 114 | 114 | $output = '<div id="message_histo_container">'; |
| 115 | - $output .= $this->get_historic_message_by_type( $post->ID ); |
|
| 115 | + $output .= $this->get_historic_message_by_type($post->ID); |
|
| 116 | 116 | $output .= '</div>'; |
| 117 | 117 | echo $output; |
| 118 | 118 | } |
@@ -123,39 +123,39 @@ discard block |
||
| 123 | 123 | * @param integer $message_type_id : Message type ID |
| 124 | 124 | * @return string |
| 125 | 125 | */ |
| 126 | - function get_historic_message_by_type( $message_type_id ) { |
|
| 126 | + function get_historic_message_by_type($message_type_id) { |
|
| 127 | 127 | |
| 128 | 128 | global $wpdb; |
| 129 | 129 | $output = ''; |
| 130 | - if ( ! empty( $message_type_id ) ) { |
|
| 130 | + if (!empty($message_type_id)) { |
|
| 131 | 131 | // Recover all sended messages |
| 132 | 132 | $wps_message_mdl = new wps_message_mdl(); |
| 133 | - $messages = $wps_message_mdl->get_messages_histo( $message_type_id ); |
|
| 133 | + $messages = $wps_message_mdl->get_messages_histo($message_type_id); |
|
| 134 | 134 | ob_start(); |
| 135 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend', 'message_historic' ) ); |
|
| 135 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend', 'message_historic')); |
|
| 136 | 136 | $output .= ob_get_contents(); |
| 137 | 137 | ob_end_clean(); |
| 138 | 138 | } |
| 139 | 139 | return $output; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public static function get_xml_messages( $code = null ) { |
|
| 143 | - if ( is_null( self::$xml_messages ) ) { |
|
| 144 | - $xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' ); |
|
| 145 | - $default_emails = new SimpleXMLElement( $xml_default_emails ); |
|
| 142 | + public static function get_xml_messages($code = null) { |
|
| 143 | + if (is_null(self::$xml_messages)) { |
|
| 144 | + $xml_default_emails = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml'); |
|
| 145 | + $default_emails = new SimpleXMLElement($xml_default_emails); |
|
| 146 | 146 | self::$xml_messages = array(); |
| 147 | - foreach ( $default_emails->xpath( '//emails/email' ) as $email ) { |
|
| 148 | - self::$xml_messages[ (string) $email->attributes()->code ] = array( |
|
| 149 | - 'shop_type' => (string) $email->attributes()->shop_type, |
|
| 150 | - 'object' => (string) $email->subject, |
|
| 151 | - 'message' => (string) $email->content, |
|
| 147 | + foreach ($default_emails->xpath('//emails/email') as $email) { |
|
| 148 | + self::$xml_messages[(string)$email->attributes()->code] = array( |
|
| 149 | + 'shop_type' => (string)$email->attributes()->shop_type, |
|
| 150 | + 'object' => (string)$email->subject, |
|
| 151 | + 'message' => (string)$email->content, |
|
| 152 | 152 | ); |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | - if ( is_null( $code ) ) { |
|
| 155 | + if (is_null($code)) { |
|
| 156 | 156 | return self::$xml_messages; |
| 157 | - } elseif ( isset( self::$xml_messages[ $code ] ) ) { |
|
| 158 | - return self::$xml_messages[ $code ]; |
|
| 157 | + } elseif (isset(self::$xml_messages[$code])) { |
|
| 158 | + return self::$xml_messages[$code]; |
|
| 159 | 159 | } else { |
| 160 | 160 | return false; |
| 161 | 161 | } |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public static function create_default_message() { |
| 167 | 167 | // Read default emails for options creation |
| 168 | - foreach ( self::get_xml_messages() as $code => $email ) { |
|
| 169 | - if ( ( WPSHOP_DEFINED_SHOP_TYPE == $email['shop_type'] ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) { |
|
| 170 | - self::createMessage( $code, $email['object'], $email['message'] ); |
|
| 168 | + foreach (self::get_xml_messages() as $code => $email) { |
|
| 169 | + if ((WPSHOP_DEFINED_SHOP_TYPE == $email['shop_type']) || ('sale' == WPSHOP_DEFINED_SHOP_TYPE)) { |
|
| 170 | + self::createMessage($code, $email['object'], $email['message']); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -180,23 +180,23 @@ discard block |
||
| 180 | 180 | * @param string $message : Message content |
| 181 | 181 | * @return integer message ID |
| 182 | 182 | */ |
| 183 | - public static function createMessage( $code, $object = '', $message = '' ) { |
|
| 183 | + public static function createMessage($code, $object = '', $message = '') { |
|
| 184 | 184 | |
| 185 | 185 | $id = 0; |
| 186 | - $xml_message = self::get_xml_messages( $code ); |
|
| 187 | - $object = empty( $object ) ? $xml_message['object'] : $object; |
|
| 188 | - $message = empty( $message ) ? $xml_message['message'] : $message; |
|
| 189 | - $message_option = get_option( $code, null ); |
|
| 190 | - if ( empty( $message_option ) && ! empty( $object ) && ! empty( $message ) ) { |
|
| 186 | + $xml_message = self::get_xml_messages($code); |
|
| 187 | + $object = empty($object) ? $xml_message['object'] : $object; |
|
| 188 | + $message = empty($message) ? $xml_message['message'] : $message; |
|
| 189 | + $message_option = get_option($code, null); |
|
| 190 | + if (empty($message_option) && !empty($object) && !empty($message)) { |
|
| 191 | 191 | $new_message = array( |
| 192 | - 'post_title' => __( $object , 'wpshop' ), |
|
| 193 | - 'post_content' => self::customize_message( __( $message, 'wpshop' ) ), |
|
| 192 | + 'post_title' => __($object, 'wpshop'), |
|
| 193 | + 'post_content' => self::customize_message(__($message, 'wpshop')), |
|
| 194 | 194 | 'post_status' => 'publish', |
| 195 | 195 | 'post_author' => 1, |
| 196 | 196 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, |
| 197 | 197 | ); |
| 198 | - $id = wp_insert_post( $new_message ); |
|
| 199 | - update_option( $code, $id ); |
|
| 198 | + $id = wp_insert_post($new_message); |
|
| 199 | + update_option($code, $id); |
|
| 200 | 200 | } else { |
| 201 | 201 | $id = $message_option; |
| 202 | 202 | } |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | - function messages_custom_columns( $column ) { |
|
| 212 | + function messages_custom_columns($column) { |
|
| 213 | 213 | |
| 214 | 214 | global $post; |
| 215 | 215 | $metadata = get_post_custom(); |
| 216 | - switch ( $column ) { |
|
| 216 | + switch ($column) { |
|
| 217 | 217 | case 'extract': |
| 218 | - echo wp_trim_words( $post->post_content, 55 ); |
|
| 218 | + echo wp_trim_words($post->post_content, 55); |
|
| 219 | 219 | break; |
| 220 | 220 | case 'last_dispatch_date': |
| 221 | - if ( ! empty( $metadata['wpshop_message_last_dispatch_date'][0] ) ) { |
|
| 222 | - echo mysql2date( 'd F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true ); |
|
| 221 | + if (!empty($metadata['wpshop_message_last_dispatch_date'][0])) { |
|
| 222 | + echo mysql2date('d F Y, H:i:s', $metadata['wpshop_message_last_dispatch_date'][0], true); |
|
| 223 | 223 | } else { echo '-'; |
| 224 | 224 | } |
| 225 | 225 | break; |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return array |
| 233 | 233 | */ |
| 234 | - function messages_edit_columns( $columns ) { |
|
| 234 | + function messages_edit_columns($columns) { |
|
| 235 | 235 | |
| 236 | 236 | $columns = array( |
| 237 | 237 | 'cb' => '<input type="checkbox" />', |
| 238 | - 'title' => __( 'Name', 'wpshop' ), |
|
| 239 | - 'extract' => __( 'Extract from the message','wpshop' ), |
|
| 240 | - 'date' => __( 'Creation date','wpshop' ), |
|
| 241 | - 'last_dispatch_date' => __( 'Last dispatch date','wpshop' ), |
|
| 238 | + 'title' => __('Name', 'wpshop'), |
|
| 239 | + 'extract' => __('Extract from the message', 'wpshop'), |
|
| 240 | + 'date' => __('Creation date', 'wpshop'), |
|
| 241 | + 'last_dispatch_date' => __('Last dispatch date', 'wpshop'), |
|
| 242 | 242 | ); |
| 243 | 243 | return $columns; |
| 244 | 244 | } |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | * @param integer $current |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - function getMessageListOption( $current = 0 ) { |
|
| 252 | + function getMessageListOption($current = 0) { |
|
| 253 | 253 | |
| 254 | - $posts = query_posts( array( |
|
| 254 | + $posts = query_posts(array( |
|
| 255 | 255 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, |
| 256 | 256 | 'posts_per_page' => '-1', |
| 257 | - ) ); |
|
| 257 | + )); |
|
| 258 | 258 | $options = ''; |
| 259 | - if ( ! empty( $posts ) ) { |
|
| 260 | - $options = '<option value="0">' . __( 'Select values from list', 'wpshop' ) . '</option>'; |
|
| 261 | - foreach ( $posts as $p ) { |
|
| 262 | - $selected = $p->ID == $current ? ' selected="selected"': ''; |
|
| 259 | + if (!empty($posts)) { |
|
| 260 | + $options = '<option value="0">' . __('Select values from list', 'wpshop') . '</option>'; |
|
| 261 | + foreach ($posts as $p) { |
|
| 262 | + $selected = $p->ID == $current ? ' selected="selected"' : ''; |
|
| 263 | 263 | $options .= '<option value="' . $p->ID . '"' . $selected . '>' . $p->post_title . '</option>'; |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -274,13 +274,13 @@ discard block |
||
| 274 | 274 | * @param integer $customer_id : ID to identifiate the customer |
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | - function display_message_histo_per_customer( $args, $customer_id = '' ) { |
|
| 277 | + function display_message_histo_per_customer($args, $customer_id = '') { |
|
| 278 | 278 | |
| 279 | - $customer_id = ( ! empty( $customer_id ) ) ? $customer_id : get_current_user_id(); |
|
| 280 | - $message_id = ( ! empty( $args ) && ! empty( $args['message_id'] ) ) ? $args['message_id'] : ''; |
|
| 279 | + $customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
| 280 | + $message_id = (!empty($args) && !empty($args['message_id'])) ? $args['message_id'] : ''; |
|
| 281 | 281 | $message_elements = ''; |
| 282 | 282 | $wps_message_mdl = new wps_message_mdl(); |
| 283 | - $messages_data = $wps_message_mdl->get_messages_histo( $message_id, $customer_id ); |
|
| 283 | + $messages_data = $wps_message_mdl->get_messages_histo($message_id, $customer_id); |
|
| 284 | 284 | |
| 285 | 285 | // ob_start(); |
| 286 | 286 | // require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "frontend", "messages") ); |
@@ -288,22 +288,22 @@ discard block |
||
| 288 | 288 | // ob_end_clean(); |
| 289 | 289 | /** Order emails */ |
| 290 | 290 | $messages_histo = array(); |
| 291 | - foreach ( $messages_data as $meta_id => $messages ) : |
|
| 291 | + foreach ($messages_data as $meta_id => $messages) : |
|
| 292 | 292 | $i = 0; |
| 293 | - foreach ( $messages as $message ) : |
|
| 294 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['title'] = $message['mess_title']; |
|
| 295 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['message'] = $message['mess_message']; |
|
| 296 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['dates'] = $message['mess_dispatch_date']; |
|
| 297 | - if ( ! empty( $message['mess_object_id'] ) ) { |
|
| 298 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['object'] = $message['mess_object_id']; |
|
| 293 | + foreach ($messages as $message) : |
|
| 294 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['title'] = $message['mess_title']; |
|
| 295 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['message'] = $message['mess_message']; |
|
| 296 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['dates'] = $message['mess_dispatch_date']; |
|
| 297 | + if (!empty($message['mess_object_id'])) { |
|
| 298 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['object'] = $message['mess_object_id']; |
|
| 299 | 299 | } |
| 300 | 300 | $i++; |
| 301 | 301 | endforeach; |
| 302 | 302 | endforeach; |
| 303 | - ksort( $messages_histo ); |
|
| 304 | - $messages_histo = array_reverse( $messages_histo ); |
|
| 303 | + ksort($messages_histo); |
|
| 304 | + $messages_histo = array_reverse($messages_histo); |
|
| 305 | 305 | ob_start(); |
| 306 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'frontend', 'customer', 'messages' ) ); |
|
| 306 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'frontend', 'customer', 'messages')); |
|
| 307 | 307 | $output = ob_get_contents(); |
| 308 | 308 | ob_end_clean(); |
| 309 | 309 | return $output; |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | * @param string $message : message content |
| 316 | 316 | * @return string |
| 317 | 317 | */ |
| 318 | - public static function customize_message( $message ) { |
|
| 318 | + public static function customize_message($message) { |
|
| 319 | 319 | |
| 320 | - if ( ! empty( $message ) ) { |
|
| 320 | + if (!empty($message)) { |
|
| 321 | 321 | ob_start(); |
| 322 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', 'backend', 'message_html_structure' ) ); |
|
| 322 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', 'backend', 'message_html_structure')); |
|
| 323 | 323 | $message = ob_get_contents(); |
| 324 | 324 | ob_end_clean(); |
| 325 | 325 | } |
@@ -330,15 +330,15 @@ discard block |
||
| 330 | 330 | * |
| 331 | 331 | * @return boolean |
| 332 | 332 | */ |
| 333 | - function add_message( $recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null ) { |
|
| 333 | + function add_message($recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null) { |
|
| 334 | 334 | |
| 335 | - $date = empty( $date ) ? current_time( 'mysql', 0 ) : $date; |
|
| 335 | + $date = empty($date) ? current_time('mysql', 0) : $date; |
|
| 336 | 336 | $object_empty = array( |
| 337 | 337 | 'object_type' => '', |
| 338 | 338 | 'object_id' => 0, |
| 339 | 339 | ); |
| 340 | - $object = array_merge( $object_empty, $object ); |
|
| 341 | - $historic = get_post_meta( $recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr( $date, 0, 7 ), true ); |
|
| 340 | + $object = array_merge($object_empty, $object); |
|
| 341 | + $historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), true); |
|
| 342 | 342 | $data_to_insert = array( |
| 343 | 343 | 'mess_user_id' => $recipient_id, |
| 344 | 344 | 'mess_user_email' => $email, |
@@ -346,10 +346,10 @@ discard block |
||
| 346 | 346 | 'mess_object_id' => $object['object_id'], |
| 347 | 347 | 'mess_title' => $title, |
| 348 | 348 | 'mess_message' => $message, |
| 349 | - 'mess_dispatch_date' => array( $date ), |
|
| 349 | + 'mess_dispatch_date' => array($date), |
|
| 350 | 350 | ); |
| 351 | 351 | $historic[] = $data_to_insert; |
| 352 | - update_post_meta( $recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr( $date, 0, 7 ), $historic ); |
|
| 352 | + update_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), $historic); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -361,49 +361,49 @@ discard block |
||
| 361 | 361 | * @param boolean $duplicate_message : Duplicate a light message for historic storage |
| 362 | 362 | * @return string |
| 363 | 363 | */ |
| 364 | - function customMessage( $string, $data, $model_name = '', $duplicate_message = false ) { |
|
| 364 | + function customMessage($string, $data, $model_name = '', $duplicate_message = false) { |
|
| 365 | 365 | |
| 366 | 366 | $avant = array(); |
| 367 | 367 | $apres = array(); |
| 368 | - $logo_option = get_option( 'wpshop_logo' ); |
|
| 368 | + $logo_option = get_option('wpshop_logo'); |
|
| 369 | 369 | |
| 370 | - $data['your_shop_logo'] = ( ! empty( $logo_option ) ) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo( 'name' ) . '" />' : ''; |
|
| 370 | + $data['your_shop_logo'] = (!empty($logo_option)) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo('name') . '" />' : ''; |
|
| 371 | 371 | |
| 372 | - foreach ( $data as $key => $value ) { |
|
| 372 | + foreach ($data as $key => $value) { |
|
| 373 | 373 | $avant[] = '[' . $key . ']'; |
| 374 | - switch ( $key ) { |
|
| 374 | + switch ($key) { |
|
| 375 | 375 | case 'order_content' : |
| 376 | - $apres[] = ( $duplicate_message ) ? '[order_content]' : $this->order_content_template_for_mail( $data['order_id'] ); |
|
| 376 | + $apres[] = ($duplicate_message) ? '[order_content]' : $this->order_content_template_for_mail($data['order_id']); |
|
| 377 | 377 | break; |
| 378 | 378 | case 'order_addresses' : |
| 379 | - $apres[] = ( $duplicate_message ) ? '[order_addresses]' : $this->order_addresses_template_for_mail( $data['order_id'] ); |
|
| 379 | + $apres[] = ($duplicate_message) ? '[order_addresses]' : $this->order_addresses_template_for_mail($data['order_id']); |
|
| 380 | 380 | break; |
| 381 | 381 | |
| 382 | 382 | case 'order_billing_address' : |
| 383 | - $apres[] = ( $duplicate_message ) ? '[order_billing_address]' : $this->order_addresses_template_for_mail( $data['order_id'], 'billing' ); |
|
| 383 | + $apres[] = ($duplicate_message) ? '[order_billing_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'billing'); |
|
| 384 | 384 | break; |
| 385 | 385 | |
| 386 | 386 | case 'order_shipping_address' : |
| 387 | - $apres[] = ( $duplicate_message ) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail( $data['order_id'], 'shipping' ); |
|
| 387 | + $apres[] = ($duplicate_message) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'shipping'); |
|
| 388 | 388 | break; |
| 389 | 389 | |
| 390 | 390 | case 'order_customer_comments' : |
| 391 | - $apres[] = ( $duplicate_message ) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail( $data['order_id'] ); |
|
| 391 | + $apres[] = ($duplicate_message) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail($data['order_id']); |
|
| 392 | 392 | break; |
| 393 | 393 | case 'order_personnal_informations' : |
| 394 | - $apres[] = ( $duplicate_message ) ? '[order_personnal_informations]' : $this->order_personnal_informations(); |
|
| 394 | + $apres[] = ($duplicate_message) ? '[order_personnal_informations]' : $this->order_personnal_informations(); |
|
| 395 | 395 | break; |
| 396 | 396 | default : |
| 397 | 397 | $apres[] = $value; |
| 398 | 398 | break; |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | - $string = str_replace( $avant, $apres, $string ); |
|
| 401 | + $string = str_replace($avant, $apres, $string); |
|
| 402 | 402 | |
| 403 | - $string = apply_filters( 'wps_more_customized_message', $string, $data, $duplicate_message ); |
|
| 403 | + $string = apply_filters('wps_more_customized_message', $string, $data, $duplicate_message); |
|
| 404 | 404 | |
| 405 | - if ( ($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE') ) { |
|
| 406 | - $string = preg_replace( '/\[(.*)\]/Usi', '', $string ); |
|
| 405 | + if (($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE')) { |
|
| 406 | + $string = preg_replace('/\[(.*)\]/Usi', '', $string); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | return $string; |
@@ -418,22 +418,22 @@ discard block |
||
| 418 | 418 | * @param string $object : message object |
| 419 | 419 | * @param file $attached_file : File to attached to e-mail |
| 420 | 420 | */ |
| 421 | - function wpshop_prepared_email( $email, $model_name, $data = array(), $object = array(), $attached_file = '' ) { |
|
| 421 | + function wpshop_prepared_email($email, $model_name, $data = array(), $object = array(), $attached_file = '') { |
|
| 422 | 422 | global $wpdb; |
| 423 | - $data = apply_filters( 'wps_extra_data_to_send_in_email', $data ); |
|
| 424 | - $model_id = get_option( $model_name, 0 ); |
|
| 425 | - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id ); |
|
| 426 | - $post_message = $wpdb->get_row( $query ); |
|
| 423 | + $data = apply_filters('wps_extra_data_to_send_in_email', $data); |
|
| 424 | + $model_id = get_option($model_name, 0); |
|
| 425 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id); |
|
| 426 | + $post_message = $wpdb->get_row($query); |
|
| 427 | 427 | $duplicate_message = ''; |
| 428 | - if ( ! empty( $post_message ) ) { |
|
| 429 | - $title = $this->customMessage( $post_message->post_title, $data, $model_name ); |
|
| 430 | - $message = $this->customMessage( $post_message->post_content, $data, $model_name ); |
|
| 428 | + if (!empty($post_message)) { |
|
| 429 | + $title = $this->customMessage($post_message->post_title, $data, $model_name); |
|
| 430 | + $message = $this->customMessage($post_message->post_content, $data, $model_name); |
|
| 431 | 431 | // End if(). |
| 432 | - if ( array_key_exists( 'order_content', $data ) || array_key_exists( 'order_addresses', $data ) || array_key_exists( 'order_customer_comments', $data ) ) { |
|
| 433 | - $duplicate_message = $this->customMessage( $post_message->post_content, $data, $model_name, true ); |
|
| 432 | + if (array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data)) { |
|
| 433 | + $duplicate_message = $this->customMessage($post_message->post_content, $data, $model_name, true); |
|
| 434 | 434 | } |
| 435 | - if ( ! empty( $email ) ) { |
|
| 436 | - $this->wpshop_email( $email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message ); |
|
| 435 | + if (!empty($email)) { |
|
| 436 | + $this->wpshop_email($email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message); |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -450,37 +450,37 @@ discard block |
||
| 450 | 450 | * @param file $attachments : File to attached to e-mail |
| 451 | 451 | * @param string $duplicate_message : lighter message to store |
| 452 | 452 | */ |
| 453 | - function wpshop_email( $email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '' ) { |
|
| 453 | + function wpshop_email($email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '') { |
|
| 454 | 454 | global $wpdb; |
| 455 | 455 | // Sauvegarde |
| 456 | - if ( $save ) { |
|
| 457 | - $user = $wpdb->get_row( 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";' ); |
|
| 456 | + if ($save) { |
|
| 457 | + $user = $wpdb->get_row('SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";'); |
|
| 458 | 458 | $user_id = $user ? $user->ID : get_current_user_id(); |
| 459 | - $query = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 460 | - $user_post_id = $wpdb->get_var( $query ); |
|
| 459 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 460 | + $user_post_id = $wpdb->get_var($query); |
|
| 461 | 461 | |
| 462 | - if ( ! empty( $duplicate_message ) ) { |
|
| 463 | - $this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object ); |
|
| 462 | + if (!empty($duplicate_message)) { |
|
| 463 | + $this->add_message($user_post_id, $email, $title, $duplicate_message, $model_id, $object); |
|
| 464 | 464 | } else { |
| 465 | - $this->add_message( $user_post_id, $email, $title, $message, $model_id, $object ); |
|
| 465 | + $this->add_message($user_post_id, $email, $title, $message, $model_id, $object); |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - $emails = get_option( 'wpshop_emails', array() ); |
|
| 469 | + $emails = get_option('wpshop_emails', array()); |
|
| 470 | 470 | $noreply_email = $emails['noreply_email']; |
| 471 | 471 | // Split the email to get the name |
| 472 | - $vers_nom = substr( $email, 0, strpos( $email,'@' ) ); |
|
| 472 | + $vers_nom = substr($email, 0, strpos($email, '@')); |
|
| 473 | 473 | |
| 474 | 474 | // Headers du mail |
| 475 | 475 | $headers = "MIME-Version: 1.0\r\n"; |
| 476 | 476 | $headers .= "Content-type: text/html; charset=UTF-8\r\n"; |
| 477 | - $headers .= 'From: ' . get_bloginfo( 'name' ) . ' <' . $noreply_email . '>' . "\r\n"; |
|
| 477 | + $headers .= 'From: ' . get_bloginfo('name') . ' <' . $noreply_email . '>' . "\r\n"; |
|
| 478 | 478 | |
| 479 | 479 | // Mail en HTML |
| 480 | - @wp_mail( $email, $title, $message, $headers, $attachments ); |
|
| 480 | + @wp_mail($email, $title, $message, $headers, $attachments); |
|
| 481 | 481 | |
| 482 | - if ( ! empty( $attachments ) ) { |
|
| 483 | - unlink( $attachments ); |
|
| 482 | + if (!empty($attachments)) { |
|
| 483 | + unlink($attachments); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
@@ -490,13 +490,13 @@ discard block |
||
| 490 | 490 | * @param integer $order_id : Order ID |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - function order_content_template_for_mail( $order_id ) { |
|
| 493 | + function order_content_template_for_mail($order_id) { |
|
| 494 | 494 | $message = ''; |
| 495 | - if ( ! empty( $order_id ) ) { |
|
| 496 | - $currency_code = wpshop_tools::wpshop_get_currency( false ); |
|
| 497 | - $orders_infos = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 495 | + if (!empty($order_id)) { |
|
| 496 | + $currency_code = wpshop_tools::wpshop_get_currency(false); |
|
| 497 | + $orders_infos = get_post_meta($order_id, '_order_postmeta', true); |
|
| 498 | 498 | ob_start(); |
| 499 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_content_mail_template' ) ); |
|
| 499 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_content_mail_template')); |
|
| 500 | 500 | $message .= ob_get_contents(); |
| 501 | 501 | ob_end_clean(); |
| 502 | 502 | } |
@@ -510,44 +510,44 @@ discard block |
||
| 510 | 510 | * @param integer $address_type : Address type ID |
| 511 | 511 | * @return string |
| 512 | 512 | */ |
| 513 | - function order_addresses_template_for_mail( $order_id, $address_type = '' ) { |
|
| 513 | + function order_addresses_template_for_mail($order_id, $address_type = '') { |
|
| 514 | 514 | global $wpdb; |
| 515 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 516 | - $display_shipping = ( ! empty( $shipping_option ) && ! empty( $shipping_option['activate'] ) ) ? true : false; |
|
| 515 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 516 | + $display_shipping = (!empty($shipping_option) && !empty($shipping_option['activate'])) ? true : false; |
|
| 517 | 517 | $message = ''; |
| 518 | - if ( ! empty( $order_id ) ) { |
|
| 519 | - $order_addresses = get_post_meta( $order_id, '_order_info', true ); |
|
| 520 | - if ( ! empty( $order_addresses ) ) { |
|
| 521 | - foreach ( $order_addresses as $key => $order_address ) { |
|
| 522 | - if ( ! empty( $order_address ) && ( empty( $address_type ) || $address_type == $key ) ) { |
|
| 523 | - |
|
| 524 | - if ( $key != 'shipping' || ($key == 'shipping' && $display_shipping) ) { |
|
| 525 | - $address_type_title = ( ! empty( $key ) && $key == 'billing' ) ? __( 'Billing address', 'wpshop' ) : __( 'Shipping address', 'wpshop' ); |
|
| 518 | + if (!empty($order_id)) { |
|
| 519 | + $order_addresses = get_post_meta($order_id, '_order_info', true); |
|
| 520 | + if (!empty($order_addresses)) { |
|
| 521 | + foreach ($order_addresses as $key => $order_address) { |
|
| 522 | + if (!empty($order_address) && (empty($address_type) || $address_type == $key)) { |
|
| 523 | + |
|
| 524 | + if ($key != 'shipping' || ($key == 'shipping' && $display_shipping)) { |
|
| 525 | + $address_type_title = (!empty($key) && $key == 'billing') ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop'); |
|
| 526 | 526 | $civility = ''; |
| 527 | - if ( ! empty( $order_address['address']['civility'] ) ) { |
|
| 528 | - $query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility'] ); |
|
| 529 | - $civility = $wpdb->get_var( $query ); |
|
| 527 | + if (!empty($order_address['address']['civility'])) { |
|
| 528 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility']); |
|
| 529 | + $civility = $wpdb->get_var($query); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // Address informations |
| 533 | - $customer_last_name = ( ! empty( $order_address['address']['address_last_name'] ) ) ? $order_address['address']['address_last_name'] : ''; |
|
| 534 | - $customer_firtsname = ( ! empty( $order_address['address']['address_first_name'] ) ) ? $order_address['address']['address_first_name'] : ''; |
|
| 535 | - $customer_company = ( ! empty( $order_address['address']['company'] ) ) ? $order_address['address']['company'] : ''; |
|
| 536 | - $customer_address = ( ! empty( $order_address['address']['address'] ) ) ? $order_address['address']['address'] : ''; |
|
| 537 | - $customer_zip_code = ( ! empty( $order_address['address']['postcode'] ) ) ? $order_address['address']['postcode'] : ''; |
|
| 538 | - $customer_city = ( ! empty( $order_address['address']['city'] ) ) ? $order_address['address']['city'] : ''; |
|
| 539 | - $customer_state = ( ! empty( $order_address['address']['state'] ) ) ? $order_address['address']['state'] : ''; |
|
| 540 | - $customer_phone = ( ! empty( $order_address['address']['phone'] ) ) ? ' Tel. : ' . $order_address['address']['phone'] : ''; |
|
| 533 | + $customer_last_name = (!empty($order_address['address']['address_last_name'])) ? $order_address['address']['address_last_name'] : ''; |
|
| 534 | + $customer_firtsname = (!empty($order_address['address']['address_first_name'])) ? $order_address['address']['address_first_name'] : ''; |
|
| 535 | + $customer_company = (!empty($order_address['address']['company'])) ? $order_address['address']['company'] : ''; |
|
| 536 | + $customer_address = (!empty($order_address['address']['address'])) ? $order_address['address']['address'] : ''; |
|
| 537 | + $customer_zip_code = (!empty($order_address['address']['postcode'])) ? $order_address['address']['postcode'] : ''; |
|
| 538 | + $customer_city = (!empty($order_address['address']['city'])) ? $order_address['address']['city'] : ''; |
|
| 539 | + $customer_state = (!empty($order_address['address']['state'])) ? $order_address['address']['state'] : ''; |
|
| 540 | + $customer_phone = (!empty($order_address['address']['phone'])) ? ' Tel. : ' . $order_address['address']['phone'] : ''; |
|
| 541 | 541 | $country = ''; |
| 542 | - foreach ( unserialize( WPSHOP_COUNTRY_LIST ) as $key => $value ) { |
|
| 543 | - if ( ! empty( $order_address['address']['country'] ) && $key == $order_address['address']['country'] ) { |
|
| 542 | + foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) { |
|
| 543 | + if (!empty($order_address['address']['country']) && $key == $order_address['address']['country']) { |
|
| 544 | 544 | $country = $value; |
| 545 | 545 | } |
| 546 | 546 | } |
| 547 | 547 | $customer_country = $country; |
| 548 | 548 | |
| 549 | 549 | ob_start(); |
| 550 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_addresses_template_for_mail' ) ); |
|
| 550 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_addresses_template_for_mail')); |
|
| 551 | 551 | $message .= ob_get_contents(); |
| 552 | 552 | ob_end_clean(); |
| 553 | 553 | } |
@@ -564,20 +564,20 @@ discard block |
||
| 564 | 564 | * @param integer $order_id : Order ID |
| 565 | 565 | * @return string |
| 566 | 566 | */ |
| 567 | - function order_customer_comment_template_for_mail( $order_id ) { |
|
| 567 | + function order_customer_comment_template_for_mail($order_id) { |
|
| 568 | 568 | global $wpdb; |
| 569 | 569 | $message = ''; |
| 570 | - if ( ! empty( $order_id ) ) { |
|
| 571 | - $query = $wpdb->prepare( 'SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id ); |
|
| 572 | - $comment = $wpdb->get_var( $query ); |
|
| 573 | - $order_infos = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 574 | - if ( ! empty( $order_infos['order_key'] ) ) { |
|
| 575 | - $comment_title = __( 'Comments about the order', 'wpshop' ); |
|
| 570 | + if (!empty($order_id)) { |
|
| 571 | + $query = $wpdb->prepare('SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id); |
|
| 572 | + $comment = $wpdb->get_var($query); |
|
| 573 | + $order_infos = get_post_meta($order_id, '_order_postmeta', true); |
|
| 574 | + if (!empty($order_infos['order_key'])) { |
|
| 575 | + $comment_title = __('Comments about the order', 'wpshop'); |
|
| 576 | 576 | } else { |
| 577 | - $comment_title = __( 'Comments about the quotation', 'wpshop' ); |
|
| 577 | + $comment_title = __('Comments about the quotation', 'wpshop'); |
|
| 578 | 578 | } |
| 579 | 579 | ob_start(); |
| 580 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_email_customer_comments' ) ); |
|
| 580 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_email_customer_comments')); |
|
| 581 | 581 | $message .= ob_get_contents(); |
| 582 | 582 | ob_end_clean(); |
| 583 | 583 | } |
@@ -593,15 +593,15 @@ discard block |
||
| 593 | 593 | global $wpdb; |
| 594 | 594 | $user_id = get_current_user_id(); |
| 595 | 595 | $message = ''; |
| 596 | - $customer_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 597 | - if ( ! empty( $customer_entity ) ) { |
|
| 596 | + $customer_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 597 | + if (!empty($customer_entity)) { |
|
| 598 | 598 | |
| 599 | - $query = $wpdb->prepare( 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid' ); |
|
| 600 | - $attributes_sets = $wpdb->get_results( $query ); |
|
| 599 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid'); |
|
| 600 | + $attributes_sets = $wpdb->get_results($query); |
|
| 601 | 601 | |
| 602 | - if ( ! empty( $attributes_sets ) ) { |
|
| 602 | + if (!empty($attributes_sets)) { |
|
| 603 | 603 | ob_start(); |
| 604 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_personnal_informations_template_for_mail' ) ); |
|
| 604 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_personnal_informations_template_for_mail')); |
|
| 605 | 605 | $message .= ob_get_contents(); |
| 606 | 606 | ob_end_clean(); |
| 607 | 607 | } |
@@ -614,17 +614,17 @@ discard block |
||
| 614 | 614 | */ |
| 615 | 615 | function wpshop_messages_historic_correction() { |
| 616 | 616 | global $wpdb; |
| 617 | - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%' ); |
|
| 618 | - $messages_histo = $wpdb->get_results( $query ); |
|
| 617 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%'); |
|
| 618 | + $messages_histo = $wpdb->get_results($query); |
|
| 619 | 619 | |
| 620 | - foreach ( $messages_histo as $message ) { |
|
| 621 | - $query_user = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 622 | - $user_post_id = $wpdb->get_var( $query_user ); |
|
| 623 | - $wpdb->update( $wpdb->postmeta, array( |
|
| 620 | + foreach ($messages_histo as $message) { |
|
| 621 | + $query_user = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 622 | + $user_post_id = $wpdb->get_var($query_user); |
|
| 623 | + $wpdb->update($wpdb->postmeta, array( |
|
| 624 | 624 | 'post_id' => $user_post_id, |
| 625 | 625 | ), array( |
| 626 | 626 | 'meta_id' => $message->meta_id, |
| 627 | - ) ); |
|
| 627 | + )); |
|
| 628 | 628 | } |
| 629 | 629 | } |
| 630 | 630 | |
@@ -633,20 +633,20 @@ discard block |
||
| 633 | 633 | * Récupères le contenu du message |
| 634 | 634 | */ |
| 635 | 635 | public function get_content_message() { |
| 636 | - $_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 636 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 637 | 637 | |
| 638 | - if ( ! wp_verify_nonce( $_wpnonce, 'get_content_message' ) ) { |
|
| 638 | + if (!wp_verify_nonce($_wpnonce, 'get_content_message')) { |
|
| 639 | 639 | wp_die(); |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | global $wpdb; |
| 643 | - $meta_id = (int) $_GET['meta_id']; |
|
| 643 | + $meta_id = (int)$_GET['meta_id']; |
|
| 644 | 644 | |
| 645 | - $result = $wpdb->get_results( $wpdb->prepare( 'SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_id=%d', array( ($meta_id) ) ) ); |
|
| 646 | - $result = unserialize( $result[0]->meta_value ); |
|
| 645 | + $result = $wpdb->get_results($wpdb->prepare('SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_id=%d', array(($meta_id)))); |
|
| 646 | + $result = unserialize($result[0]->meta_value); |
|
| 647 | 647 | $result = $result[0]['mess_message']; |
| 648 | 648 | |
| 649 | - wp_die( $result ); |
|
| 649 | + wp_die($result); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | } |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | * Call hooks. |
| 14 | 14 | */ |
| 15 | 15 | public function __construct() { |
| 16 | - add_action( 'init', array( $this, 'init' ) ); |
|
| 17 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 11, 2 ); |
|
| 18 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); |
|
| 19 | - add_filter( 'wpshop_attribute_output_def', array( $this, 'wpshop_attribute_output_def' ), 10, 2 ); |
|
| 16 | + add_action('init', array($this, 'init')); |
|
| 17 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 11, 2); |
|
| 18 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 19 | + add_filter('wpshop_attribute_output_def', array($this, 'wpshop_attribute_output_def'), 10, 2); |
|
| 20 | 20 | } |
| 21 | 21 | /** |
| 22 | 22 | * Call private functions if class is activate. |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | * @param array $arguments Array of arguments to pass. |
| 26 | 26 | * @return mixed Return of real function called. |
| 27 | 27 | */ |
| 28 | - public function __call( $name, $arguments ) { |
|
| 29 | - if ( method_exists( $this, $name ) ) { |
|
| 30 | - if ( $this->is_activate() ) { |
|
| 31 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
| 28 | + public function __call($name, $arguments) { |
|
| 29 | + if (method_exists($this, $name)) { |
|
| 30 | + if ($this->is_activate()) { |
|
| 31 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | 41 | public function init() { |
| 42 | - $_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // Input var okay. |
|
| 43 | - $wps_variation_interface = ! empty( $_GET['wps_variation_interface'] ) ? filter_var( wp_unslash( $_GET['wps_variation_interface'] ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) : null; // Input var okay. |
|
| 44 | - if ( wp_verify_nonce( $_wpnonce, 'wps_remove_variation_interface' ) && null !== $wps_variation_interface ) { |
|
| 45 | - $this->is_activate( $wps_variation_interface ); |
|
| 42 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])) : ''; // Input var okay. |
|
| 43 | + $wps_variation_interface = !empty($_GET['wps_variation_interface']) ? filter_var(wp_unslash($_GET['wps_variation_interface']), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : null; // Input var okay. |
|
| 44 | + if (wp_verify_nonce($_wpnonce, 'wps_remove_variation_interface') && null !== $wps_variation_interface) { |
|
| 45 | + $this->is_activate($wps_variation_interface); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | /** |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | * @param boolean $new_val If set & db is different, save it. |
| 52 | 52 | * @return boolean Actual state of module. |
| 53 | 53 | */ |
| 54 | - public function is_activate( $new_val = null ) { |
|
| 55 | - if ( ! isset( $this->is_active ) ) { |
|
| 56 | - $option = get_option( 'wps_variation_interface_display', null ); |
|
| 57 | - if ( is_null( $option ) ) { |
|
| 54 | + public function is_activate($new_val = null) { |
|
| 55 | + if (!isset($this->is_active)) { |
|
| 56 | + $option = get_option('wps_variation_interface_display', null); |
|
| 57 | + if (is_null($option)) { |
|
| 58 | 58 | $new_val = true; |
| 59 | 59 | $option = false; |
| 60 | 60 | } |
| 61 | - $this->is_active = (bool) $option; |
|
| 61 | + $this->is_active = (bool)$option; |
|
| 62 | 62 | } |
| 63 | - if ( isset( $new_val ) && $this->is_active !== $new_val ) { |
|
| 64 | - update_option( 'wps_variation_interface_display', $new_val ); |
|
| 63 | + if (isset($new_val) && $this->is_active !== $new_val) { |
|
| 64 | + update_option('wps_variation_interface_display', $new_val); |
|
| 65 | 65 | $this->is_active = $new_val; |
| 66 | 66 | } |
| 67 | 67 | return $this->is_active; |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | * @param array $element Direct array attribute of db. |
| 73 | 73 | * @return void It set directly in variable class. |
| 74 | 74 | */ |
| 75 | - private function get_variations( $element ) { |
|
| 76 | - if ( ! isset( $this->variations ) ) { |
|
| 77 | - $variations = wpshop_attributes::get_variation_available_attribute( $element ); |
|
| 78 | - $this->variations = (array) array_merge( ( isset( $variations['available'] ) ? $variations['available'] : array()), ( isset( $variations['unavailable'] ) ? $variations['unavailable'] : array() ) ); |
|
| 79 | - unset( $variations ); |
|
| 75 | + private function get_variations($element) { |
|
| 76 | + if (!isset($this->variations)) { |
|
| 77 | + $variations = wpshop_attributes::get_variation_available_attribute($element); |
|
| 78 | + $this->variations = (array)array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array())); |
|
| 79 | + unset($variations); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | /** |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | * @param string $post_status Generated by WP. |
| 87 | 87 | * @param WP_Post $post Generated by WP. |
| 88 | 88 | */ |
| 89 | - public function add_meta_boxes( $post_status, $post ) { |
|
| 89 | + public function add_meta_boxes($post_status, $post) { |
|
| 90 | 90 | global $pagenow; |
| 91 | - if ( $this->is_activate() ) { |
|
| 92 | - $this->get_variations( $post->ID ); |
|
| 93 | - remove_meta_box( 'wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal' ); |
|
| 94 | - if ( 'post-new.php' !== $pagenow && ! empty( $this->variations ) ) { |
|
| 95 | - add_meta_box( 'wpshop_wpshop_variations', __( 'Product variation', 'wpshop' ), array( $this, 'meta_box_variation' ), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default' ); |
|
| 91 | + if ($this->is_activate()) { |
|
| 92 | + $this->get_variations($post->ID); |
|
| 93 | + remove_meta_box('wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal'); |
|
| 94 | + if ('post-new.php' !== $pagenow && !empty($this->variations)) { |
|
| 95 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array($this, 'meta_box_variation'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -102,49 +102,49 @@ discard block |
||
| 102 | 102 | * @param object $post Given by WordPress. |
| 103 | 103 | * @return void Display directly. |
| 104 | 104 | */ |
| 105 | - private function meta_box_variation( $post ) { |
|
| 106 | - $this->get_variations( $post->ID ); |
|
| 105 | + private function meta_box_variation($post) { |
|
| 106 | + $this->get_variations($post->ID); |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | $ids = array(); |
| 109 | - foreach ( $this->variations as $key => $variation ) { |
|
| 110 | - $available = wpshop_attributes::get_select_output( $variation['attribute_complete_def'] ); |
|
| 111 | - $this->variations[ $key ]['available'] = array_keys( $available['possible_value'] ); |
|
| 112 | - $ids = array_merge( $ids, array_keys( $available['possible_value'] ) ); |
|
| 109 | + foreach ($this->variations as $key => $variation) { |
|
| 110 | + $available = wpshop_attributes::get_select_output($variation['attribute_complete_def']); |
|
| 111 | + $this->variations[$key]['available'] = array_keys($available['possible_value']); |
|
| 112 | + $ids = array_merge($ids, array_keys($available['possible_value'])); |
|
| 113 | 113 | } |
| 114 | - $sql = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id IN (\'' . implode( '\', \'', $ids ) . '\') AND status = %s'; |
|
| 115 | - $query = call_user_func( array( $wpdb, 'prepare' ), $sql, 'valid' ); |
|
| 116 | - $product = wpshop_products::get_product_data( $post->ID, false, '"publish","draft","future"' ); |
|
| 117 | - $is_used_in_variation = wpshop_attributes::getElement( 'yes', "'valid', 'notused'", 'is_used_in_variation', true ); |
|
| 114 | + $sql = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id IN (\'' . implode('\', \'', $ids) . '\') AND status = %s'; |
|
| 115 | + $query = call_user_func(array($wpdb, 'prepare'), $sql, 'valid'); |
|
| 116 | + $product = wpshop_products::get_product_data($post->ID, false, '"publish","draft","future"'); |
|
| 117 | + $is_used_in_variation = wpshop_attributes::getElement('yes', "'valid', 'notused'", 'is_used_in_variation', true); |
|
| 118 | 118 | $attribute_list = array(); |
| 119 | - foreach ( $is_used_in_variation as $attribute ) { |
|
| 120 | - if ( in_array( $attribute->backend_input, array( 'multiple-select', 'select', 'radio', 'checkbox' ), true ) ) { |
|
| 121 | - $values = wpshop_attributes::get_select_output( $attribute ); |
|
| 122 | - if ( ! empty( $values['possible_value'] ) ) { |
|
| 119 | + foreach ($is_used_in_variation as $attribute) { |
|
| 120 | + if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'), true)) { |
|
| 121 | + $values = wpshop_attributes::get_select_output($attribute); |
|
| 122 | + if (!empty($values['possible_value'])) { |
|
| 123 | 123 | $attribute->possible_value = $values['possible_value']; |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | - $attribute_list[ $attribute->code ] = $attribute; |
|
| 126 | + $attribute_list[$attribute->code] = $attribute; |
|
| 127 | 127 | } |
| 128 | - $variation_defining = get_post_meta( $post->ID, '_wpshop_variation_defining', true ); |
|
| 129 | - $variations_saved = wpshop_products::get_variation( $post->ID ); |
|
| 130 | - if ( ! empty( $variations_saved ) ) { |
|
| 131 | - foreach ( $variations_saved as $variation_id => $variation ) { |
|
| 132 | - $downloadable = get_post_meta( $variation_id, 'attribute_option_is_downloadable_', true ); |
|
| 133 | - if ( ! empty( $downloadable['file_url'] ) ) { |
|
| 134 | - $variations_saved[ $variation_id ]['file']['path'] = $downloadable['file_url']; |
|
| 135 | - $variations_saved[ $variation_id ]['file']['name'] = basename( $downloadable['file_url'] ); |
|
| 128 | + $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true); |
|
| 129 | + $variations_saved = wpshop_products::get_variation($post->ID); |
|
| 130 | + if (!empty($variations_saved)) { |
|
| 131 | + foreach ($variations_saved as $variation_id => $variation) { |
|
| 132 | + $downloadable = get_post_meta($variation_id, 'attribute_option_is_downloadable_', true); |
|
| 133 | + if (!empty($downloadable['file_url'])) { |
|
| 134 | + $variations_saved[$variation_id]['file']['path'] = $downloadable['file_url']; |
|
| 135 | + $variations_saved[$variation_id]['file']['name'] = basename($downloadable['file_url']); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 139 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 140 | 140 | $product_currency = wpshop_tools::wpshop_get_currency(); |
| 141 | - wp_enqueue_style( 'wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css' ); |
|
| 142 | - wp_enqueue_script( 'wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js' ); |
|
| 143 | - wp_enqueue_script( 'wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js' ); |
|
| 144 | - wp_localize_script( 'wps-product-variation-interface-script', 'wps_product_variation_interface', apply_filters( 'wps_filters_product_variation_extra_columns_product_definition', array( |
|
| 141 | + wp_enqueue_style('wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css'); |
|
| 142 | + wp_enqueue_script('wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js'); |
|
| 143 | + wp_enqueue_script('wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js'); |
|
| 144 | + wp_localize_script('wps-product-variation-interface-script', 'wps_product_variation_interface', apply_filters('wps_filters_product_variation_extra_columns_product_definition', array( |
|
| 145 | 145 | 'variation' => $this->variations, |
| 146 | - 'nonce_delete' => wp_create_nonce( 'wpshop_variation_management' ), |
|
| 147 | - 'variation_value' => call_user_func( array( $wpdb, 'get_results' ), $query ), |
|
| 146 | + 'nonce_delete' => wp_create_nonce('wpshop_variation_management'), |
|
| 147 | + 'variation_value' => call_user_func(array($wpdb, 'get_results'), $query), |
|
| 148 | 148 | 'product_price' => $product['product_price'], |
| 149 | 149 | 'tx_tva' => $product['tx_tva'], |
| 150 | 150 | 'attribute_in_variation' => $attribute_list, |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | 'price_piloting' => $price_piloting, |
| 153 | 153 | 'currency' => $product_currency, |
| 154 | 154 | 'variation_defining' => $variation_defining, |
| 155 | - 'label_file' => __( 'Click to add file', 'wpshop' ), |
|
| 156 | - ) ) ); |
|
| 157 | - require_once wpshop_tools::get_template_part( WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation' ); |
|
| 155 | + 'label_file' => __('Click to add file', 'wpshop'), |
|
| 156 | + ))); |
|
| 157 | + require_once wpshop_tools::get_template_part(WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation'); |
|
| 158 | 158 | } |
| 159 | 159 | /** |
| 160 | 160 | * Save other values out of old variation interface. |
@@ -163,24 +163,24 @@ discard block |
||
| 163 | 163 | * @param object $post WP_Post of WordPress. |
| 164 | 164 | * @return void |
| 165 | 165 | */ |
| 166 | - private function save_post( $post_id, $post ) { |
|
| 167 | - if ( wp_is_post_revision( $post_id ) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || ! isset( $_REQUEST['wpshop_variation_defining']['options'] ) || ! isset( $_REQUEST['wps_pdt_variations'] ) ) { // Input var okay. |
|
| 166 | + private function save_post($post_id, $post) { |
|
| 167 | + if (wp_is_post_revision($post_id) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || !isset($_REQUEST['wpshop_variation_defining']['options']) || !isset($_REQUEST['wps_pdt_variations'])) { // Input var okay. |
|
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | - wpshop_products::variation_parameters_save( $post_id, $_REQUEST['wpshop_variation_defining']['options'] ); // Input var okay. |
|
| 171 | - remove_action( 'save_post', array( $this, 'save_post' ) ); |
|
| 172 | - foreach ( $_REQUEST['wps_pdt_variations'] as $variation_id => $data ) { // Input var okay. |
|
| 170 | + wpshop_products::variation_parameters_save($post_id, $_REQUEST['wpshop_variation_defining']['options']); // Input var okay. |
|
| 171 | + remove_action('save_post', array($this, 'save_post')); |
|
| 172 | + foreach ($_REQUEST['wps_pdt_variations'] as $variation_id => $data) { // Input var okay. |
|
| 173 | 173 | $variation = array( |
| 174 | 174 | 'ID' => $variation_id, |
| 175 | 175 | ); |
| 176 | - if ( isset( $data['status'] ) && 'on' === $data['status'] ) { |
|
| 176 | + if (isset($data['status']) && 'on' === $data['status']) { |
|
| 177 | 177 | $variation['post_status'] = 'publish'; |
| 178 | 178 | } else { |
| 179 | 179 | $variation['post_status'] = 'draft'; |
| 180 | 180 | } |
| 181 | - wp_update_post( $variation ); |
|
| 181 | + wp_update_post($variation); |
|
| 182 | 182 | } |
| 183 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); |
|
| 183 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 184 | 184 | } |
| 185 | 185 | /** |
| 186 | 186 | * Delete display in attributes products always in metabox. |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | * @param array $element Direct array attribute of db. |
| 190 | 190 | * @return array SAme array $output modified. |
| 191 | 191 | */ |
| 192 | - public function wpshop_attribute_output_def( $output, $element ) { |
|
| 193 | - if ( $this->is_activate() ) { |
|
| 194 | - $this->get_variations( $element ); |
|
| 195 | - if ( ! empty( $this->variations ) && in_array( $output['field_definition']['name'], array_keys( $this->variations ), true ) ) { |
|
| 192 | + public function wpshop_attribute_output_def($output, $element) { |
|
| 193 | + if ($this->is_activate()) { |
|
| 194 | + $this->get_variations($element); |
|
| 195 | + if (!empty($this->variations) && in_array($output['field_definition']['name'], array_keys($this->variations), true)) { |
|
| 196 | 196 | $output['field'] = ''; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @return void |
| 206 | 206 | */ |
| 207 | 207 | public function wpshop_download_file_dialog_active() { |
| 208 | - add_filter( 'wps_filters_product_variation_file', array( $this, 'wps_filters_product_variation_file' ), 0, 1 ); |
|
| 208 | + add_filter('wps_filters_product_variation_file', array($this, 'wps_filters_product_variation_file'), 0, 1); |
|
| 209 | 209 | } |
| 210 | 210 | /** |
| 211 | 211 | * Add old upload box for custom php dsiplay. |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param string $string Input filter. |
| 215 | 215 | * @return string The div for box. |
| 216 | 216 | */ |
| 217 | - public function wps_filters_product_variation_file( $string ) { |
|
| 218 | - return '<div style="display: none" onclick="open_dialog_box(this, %ID%, \'' . esc_html_e( 'Send the downloadable file', 'wpshop' ) . '\')"><div class="is_downloadable_statut_%ID%"></div></div>'; |
|
| 217 | + public function wps_filters_product_variation_file($string) { |
|
| 218 | + return '<div style="display: none" onclick="open_dialog_box(this, %ID%, \'' . esc_html_e('Send the downloadable file', 'wpshop') . '\')"><div class="is_downloadable_statut_%ID%"></div></div>'; |
|
| 219 | 219 | } |
| 220 | 220 | } |
@@ -2,18 +2,18 @@ discard block |
||
| 2 | 2 | <div data-view-model="wps_variations_options_summary" id="wps_variations_summary_display"> |
| 3 | 3 | <b>%summary%</b> |
| 4 | 4 | </div> |
| 5 | - <a id="wps_variations_parameters" title="<?php esc_html_e( 'Edit possibilities', 'wpshop' ); ?>" href="#"> |
|
| 5 | + <a id="wps_variations_parameters" title="<?php esc_html_e('Edit possibilities', 'wpshop'); ?>" href="#"> |
|
| 6 | 6 | <?php // href=">?php print wp_nonce_url( get_edit_post_link( $post->ID ) . '&wps_variation_interface=false', 'wps_remove_variation_interface' );?<">. ?> |
| 7 | 7 | <span class="dashicons dashicons-admin-generic"></span> |
| 8 | 8 | </a> |
| 9 | 9 | </div> |
| 10 | 10 | <div id="wps_variations_options"> |
| 11 | 11 | <ul id="wps_variations_options_title"> |
| 12 | - <li><?php esc_html_e( 'Generate option', 'wpshop' ); ?></li> |
|
| 13 | - <li><?php esc_html_e( 'Option', 'wpshop' ); ?></li> |
|
| 14 | - <li><?php esc_html_e( 'Requiered', 'wpshop' ); ?></li> |
|
| 15 | - <li><?php esc_html_e( 'Possibilities', 'wpshop' ); ?></li> |
|
| 16 | - <li><?php esc_html_e( 'Default', 'wpshop' ); ?></li> |
|
| 12 | + <li><?php esc_html_e('Generate option', 'wpshop'); ?></li> |
|
| 13 | + <li><?php esc_html_e('Option', 'wpshop'); ?></li> |
|
| 14 | + <li><?php esc_html_e('Requiered', 'wpshop'); ?></li> |
|
| 15 | + <li><?php esc_html_e('Possibilities', 'wpshop'); ?></li> |
|
| 16 | + <li><?php esc_html_e('Default', 'wpshop'); ?></li> |
|
| 17 | 17 | </ul> |
| 18 | 18 | <ul data-view-model="wps_variations_options_raw" class="wps_variations_options_raw"> |
| 19 | 19 | <li class="wps_variations_generate_col"> |
@@ -44,42 +44,42 @@ discard block |
||
| 44 | 44 | </div> |
| 45 | 45 | <div id="wps_variations_questions"> |
| 46 | 46 | <ul> |
| 47 | - <li class="wps_variations_questions_question_col"><?php esc_html_e( 'Do you want to manage each options singly or combine them ?', 'wpshop' ); ?></li> |
|
| 47 | + <li class="wps_variations_questions_question_col"><?php esc_html_e('Do you want to manage each options singly or combine them ?', 'wpshop'); ?></li> |
|
| 48 | 48 | <li class="wps_variations_questions_answers_col"> |
| 49 | 49 | <?php |
| 50 | 50 | $id = uniqid(); |
| 51 | 51 | ?> |
| 52 | - <input id="question_combine_options_<?php echo intval( $id ); ?>" name="question_combine_options" type="radio" value="combine"> |
|
| 53 | - <label for="question_combine_options_<?php echo intval( $id ); ?>"><?php esc_html_e( 'Combined options', 'wpshop' ); ?></label> |
|
| 52 | + <input id="question_combine_options_<?php echo intval($id); ?>" name="question_combine_options" type="radio" value="combine"> |
|
| 53 | + <label for="question_combine_options_<?php echo intval($id); ?>"><?php esc_html_e('Combined options', 'wpshop'); ?></label> |
|
| 54 | 54 | <?php |
| 55 | 55 | $id = uniqid(); |
| 56 | 56 | ?> |
| 57 | - <input id="question_combine_options_<?php echo intval( $id ); ?>" name="question_combine_options" type="radio" value="single"> |
|
| 58 | - <label for="question_combine_options_<?php echo intval( $id ); ?>"><?php esc_html_e( 'Distinct options', 'wpshop' ); ?></label> |
|
| 57 | + <input id="question_combine_options_<?php echo intval($id); ?>" name="question_combine_options" type="radio" value="single"> |
|
| 58 | + <label for="question_combine_options_<?php echo intval($id); ?>"><?php esc_html_e('Distinct options', 'wpshop'); ?></label> |
|
| 59 | 59 | </li> |
| 60 | 60 | </ul> |
| 61 | 61 | </div> |
| 62 | 62 | <div id="wps_variations_tabs"> |
| 63 | 63 | <ul> |
| 64 | - <li data-tab="wps_variations_price_option_tab" class="disabled"><?php esc_html_e( 'Options prices', 'wpshop' ); ?></li> |
|
| 65 | - <li id="wps_variations_apply_btn" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wpshop_variation_management' ) ); ?>"> |
|
| 66 | - <?php esc_html_e( 'Apply modifications', 'wpshop' ); ?> |
|
| 64 | + <li data-tab="wps_variations_price_option_tab" class="disabled"><?php esc_html_e('Options prices', 'wpshop'); ?></li> |
|
| 65 | + <li id="wps_variations_apply_btn" data-nonce="<?php echo esc_attr(wp_create_nonce('wpshop_variation_management')); ?>"> |
|
| 66 | + <?php esc_html_e('Apply modifications', 'wpshop'); ?> |
|
| 67 | 67 | </li> |
| 68 | 68 | </ul> |
| 69 | 69 | </div> |
| 70 | 70 | <div id="wps_variations_price_option_tab" class="wps_variations_tabs"> |
| 71 | 71 | <ul id="wps_variations_price_option_tab_title"> |
| 72 | - <li class="wps_variations_price_id_col"><?php esc_html_e( 'ID', 'wpshop' ); ?></li> |
|
| 73 | - <li class="wps_variations_price_name_col"><?php esc_html_e( 'Options', 'wpshop' ); ?></li> |
|
| 74 | - <li class="wps_variations_price_config_col"><?php esc_html_e( 'Prices', 'wpshop' ); ?></li> |
|
| 75 | - <li class="wps_variations_price_final_col"><?php esc_html_e( 'Final prices', 'wpshop' ); ?></li> |
|
| 76 | - <li class="wps_variations_price_vat_col"><?php esc_html_e( 'VAT', 'wpshop' ); ?></li> |
|
| 77 | - <li class="wps_variations_price_stock_col"><?php esc_html_e( 'Stock', 'wpshop' ); ?></li> |
|
| 78 | - <li class="wps_variations_price_weight_col"><?php esc_html_e( 'Weight', 'wpshop' ); ?></li> |
|
| 79 | - <li class="wps_variations_price_reference_col"><?php esc_html_e( 'Ref. product', 'wpshop' ); ?></li> |
|
| 80 | - <li class="wps_variations_price_file_col"><?php esc_html_e( 'Link download', 'wpshop' ); ?></li> |
|
| 81 | - <?php echo esc_html( apply_filters( 'wps_filters_product_variation_extra_columns_title', '' ) ); ?> |
|
| 82 | - <li class="wps_variations_price_active_col"><?php esc_html_e( 'Activate', 'wpshop' ); ?></li> |
|
| 72 | + <li class="wps_variations_price_id_col"><?php esc_html_e('ID', 'wpshop'); ?></li> |
|
| 73 | + <li class="wps_variations_price_name_col"><?php esc_html_e('Options', 'wpshop'); ?></li> |
|
| 74 | + <li class="wps_variations_price_config_col"><?php esc_html_e('Prices', 'wpshop'); ?></li> |
|
| 75 | + <li class="wps_variations_price_final_col"><?php esc_html_e('Final prices', 'wpshop'); ?></li> |
|
| 76 | + <li class="wps_variations_price_vat_col"><?php esc_html_e('VAT', 'wpshop'); ?></li> |
|
| 77 | + <li class="wps_variations_price_stock_col"><?php esc_html_e('Stock', 'wpshop'); ?></li> |
|
| 78 | + <li class="wps_variations_price_weight_col"><?php esc_html_e('Weight', 'wpshop'); ?></li> |
|
| 79 | + <li class="wps_variations_price_reference_col"><?php esc_html_e('Ref. product', 'wpshop'); ?></li> |
|
| 80 | + <li class="wps_variations_price_file_col"><?php esc_html_e('Link download', 'wpshop'); ?></li> |
|
| 81 | + <?php echo esc_html(apply_filters('wps_filters_product_variation_extra_columns_title', '')); ?> |
|
| 82 | + <li class="wps_variations_price_active_col"><?php esc_html_e('Activate', 'wpshop'); ?></li> |
|
| 83 | 83 | </ul> |
| 84 | 84 | <ul data-view-model="wps_variations_price_option_raw"> |
| 85 | 85 | <li class="wps_variations_price_id_col"> |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | </li> |
| 119 | 119 | <li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"> |
| 120 | 120 | <span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span> |
| 121 | - <?php echo esc_html( apply_filters( 'wps_filters_product_variation_file', '<input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)">' ) ); ?> |
|
| 122 | - <?php wp_nonce_field( 'ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce' );?> |
|
| 121 | + <?php echo esc_html(apply_filters('wps_filters_product_variation_file', '<input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)">')); ?> |
|
| 122 | + <?php wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce'); ?> |
|
| 123 | 123 | <a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"> |
| 124 | 124 | <span class="dashicons dashicons-download"></span> |
| 125 | 125 | </a> |
| 126 | 126 | </li> |
| 127 | - <?php echo esc_html( apply_filters( 'wps_filters_product_variation_extra_columns_content', '' ) ); ?> |
|
| 127 | + <?php echo esc_html(apply_filters('wps_filters_product_variation_extra_columns_content', '')); ?> |
|
| 128 | 128 | <li class="wps_variations_price_active_col"> |
| 129 | 129 | <input name="wps_pdt_variations[%ID%][status]" onclick="wps_variations_price_option_raw.control.activate(this)" type="checkbox" %price_option_activate%> |
| 130 | 130 | </li> |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * WP Shop Classic Checkout bootstrap file |
| 4 | 4 | * @author Jérôme ALLEGRE - Eoxia dev team <[email protected]> |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( !class_exists("wps_classic_checkout") ) { |
|
| 11 | +if (!class_exists("wps_classic_checkout")) { |
|
| 12 | 12 | |
| 13 | 13 | /** Template Global vars **/ |
| 14 | 14 | DEFINE('WPS_CLASSIC_CHECKOUT_DIR', basename(dirname(__FILE__))); |
| 15 | - DEFINE('WPS_CLASSIC_CHECKOUT_PATH', str_replace( "\\", "/", str_replace( WPS_CLASSIC_CHECKOUT_DIR, "", dirname( __FILE__ ) ) ) ); |
|
| 16 | - DEFINE('WPS_CLASSIC_CHECKOUT_URL', str_replace( str_replace( "\\", "/", ABSPATH), site_url() . '/', WPS_CLASSIC_CHECKOUT_PATH ) ); |
|
| 15 | + DEFINE('WPS_CLASSIC_CHECKOUT_PATH', str_replace("\\", "/", str_replace(WPS_CLASSIC_CHECKOUT_DIR, "", dirname(__FILE__)))); |
|
| 16 | + DEFINE('WPS_CLASSIC_CHECKOUT_URL', str_replace(str_replace("\\", "/", ABSPATH), site_url() . '/', WPS_CLASSIC_CHECKOUT_PATH)); |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | class wps_classic_checkout { |
@@ -35,21 +35,21 @@ discard block |
||
| 35 | 35 | $this->template_dir = WPS_CLASSIC_CHECKOUT_PATH . WPS_CLASSIC_CHECKOUT_DIR . "/templates/"; |
| 36 | 36 | |
| 37 | 37 | /** Classic Checkout Shortcode **/ |
| 38 | - add_shortcode( 'wps_checkout', array( &$this, 'show_classic_checkout') ); |
|
| 39 | - add_shortcode( 'wpshop_checkout', array( &$this, 'show_classic_checkout') ); |
|
| 38 | + add_shortcode('wps_checkout', array(&$this, 'show_classic_checkout')); |
|
| 39 | + add_shortcode('wpshop_checkout', array(&$this, 'show_classic_checkout')); |
|
| 40 | 40 | /** Checkout Step indicator **/ |
| 41 | - add_shortcode('wps_checkout_step_indicator', array(&$this, 'get_checkout_step_indicator') ); |
|
| 41 | + add_shortcode('wps_checkout_step_indicator', array(&$this, 'get_checkout_step_indicator')); |
|
| 42 | 42 | |
| 43 | 43 | // Add scripts |
| 44 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
| 44 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 45 | 45 | |
| 46 | 46 | /** Ajax Actions **/ |
| 47 | - add_action( 'wp_ajax_wps-checkout_valid_step_three', array( &$this, 'wps_checkout_valid_step_three') ); |
|
| 48 | - add_action( 'wp_ajax_wps-checkout_valid_step_four', array( &$this, 'wps_checkout_valid_step_four') ); |
|
| 49 | - add_action( 'wp_ajax_wps-checkout_valid_step_five', array( &$this, 'wps_checkout_valid_step_five') ); |
|
| 47 | + add_action('wp_ajax_wps-checkout_valid_step_three', array(&$this, 'wps_checkout_valid_step_three')); |
|
| 48 | + add_action('wp_ajax_wps-checkout_valid_step_four', array(&$this, 'wps_checkout_valid_step_four')); |
|
| 49 | + add_action('wp_ajax_wps-checkout_valid_step_five', array(&$this, 'wps_checkout_valid_step_five')); |
|
| 50 | 50 | |
| 51 | - add_action( 'admin_post_wps_direct_payment_link', array( 'wpshop_checkout', 'wps_direct_payment_link' ) ); |
|
| 52 | - add_action( 'admin_post_nopriv_wps_direct_payment_link', array( 'wpshop_checkout', 'wps_direct_payment_link_nopriv' ) ); |
|
| 51 | + add_action('admin_post_wps_direct_payment_link', array('wpshop_checkout', 'wps_direct_payment_link')); |
|
| 52 | + add_action('admin_post_nopriv_wps_direct_payment_link', array('wpshop_checkout', 'wps_direct_payment_link_nopriv')); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -57,145 +57,145 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | function add_scripts() { |
| 59 | 59 | wp_enqueue_script('jquery'); |
| 60 | - wp_enqueue_script( 'wps_classic_checkout', plugins_url('templates/frontend/js/wps_classic_checkout.js', __FILE__) ); |
|
| 60 | + wp_enqueue_script('wps_classic_checkout', plugins_url('templates/frontend/js/wps_classic_checkout.js', __FILE__)); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Display Classic Checkout |
| 65 | 65 | */ |
| 66 | 66 | function show_classic_checkout() { |
| 67 | - $order_id = !empty( $_GET['order_id'] ) ? (int) $_GET['order_id'] : ''; |
|
| 67 | + $order_id = !empty($_GET['order_id']) ? (int)$_GET['order_id'] : ''; |
|
| 68 | 68 | |
| 69 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
| 70 | - $current_step = !empty( $_GET[ 'order_step' ] ) && is_int( (int)$_GET[ 'order_step' ] ) ? (int)$_GET[ 'order_step' ] : null; |
|
| 69 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 70 | + $current_step = !empty($_GET['order_step']) && is_int((int)$_GET['order_step']) ? (int)$_GET['order_step'] : null; |
|
| 71 | 71 | |
| 72 | 72 | /** Cas spécial lorsqu'il n'y a qu'un seul produit autorisé dans le panier / Special case when there is only one product allowed into cart */ |
| 73 | - if ( ( empty( $current_step ) || ( 1 == $current_step ) ) && ( !empty( $wpshop_cart_option ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) && ( 1 == $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) ) ) { |
|
| 74 | - if( empty($_SESSION) || empty($_SESSION['cart']) || empty($_SESSION['cart']['order_items']) ) { |
|
| 75 | - $product_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_product_page_id' ) ); |
|
| 76 | - $url = get_permalink( $product_page_id ); |
|
| 77 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 73 | + if ((empty($current_step) || (1 == $current_step)) && (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed']) && (1 == $wpshop_cart_option['total_nb_of_item_allowed'][0]))) { |
|
| 74 | + if (empty($_SESSION) || empty($_SESSION['cart']) || empty($_SESSION['cart']['order_items'])) { |
|
| 75 | + $product_page_id = wpshop_tools::get_page_id(get_option('wpshop_product_page_id')); |
|
| 76 | + $url = get_permalink($product_page_id); |
|
| 77 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 78 | 78 | } |
| 79 | 79 | else { |
| 80 | 80 | $current_step = 2; |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $checkout_step_indicator = do_shortcode( '[wps_checkout_step_indicator]'); |
|
| 84 | + $checkout_step_indicator = do_shortcode('[wps_checkout_step_indicator]'); |
|
| 85 | 85 | $checkout_content = ''; |
| 86 | 86 | |
| 87 | - if ( !empty($current_step) ) { |
|
| 88 | - switch( $current_step) { |
|
| 87 | + if (!empty($current_step)) { |
|
| 88 | + switch ($current_step) { |
|
| 89 | 89 | case 1 : |
| 90 | 90 | ob_start(); |
| 91 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one") ); |
|
| 91 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one")); |
|
| 92 | 92 | $checkout_content .= ob_get_contents(); |
| 93 | 93 | ob_end_clean(); |
| 94 | 94 | break; |
| 95 | 95 | case 2 : |
| 96 | - if ( get_current_user_id() != 0 ) { |
|
| 97 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 98 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 99 | - $url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
| 100 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 96 | + if (get_current_user_id() != 0) { |
|
| 97 | + $permalink_option = get_option('permalink_structure'); |
|
| 98 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 99 | + $url = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
| 100 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 101 | 101 | } |
| 102 | 102 | else { |
| 103 | 103 | ob_start(); |
| 104 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-two") ); |
|
| 104 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-two")); |
|
| 105 | 105 | $checkout_content .= ob_get_contents(); |
| 106 | 106 | ob_end_clean(); |
| 107 | 107 | } |
| 108 | 108 | break; |
| 109 | 109 | case 3 : |
| 110 | - if ( get_current_user_id() == 0 ) { |
|
| 111 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 112 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 113 | - $url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=2'; |
|
| 114 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 110 | + if (get_current_user_id() == 0) { |
|
| 111 | + $permalink_option = get_option('permalink_structure'); |
|
| 112 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 113 | + $url = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=2'; |
|
| 114 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 115 | 115 | } |
| 116 | 116 | else { |
| 117 | - if( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
| 117 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 118 | 118 | ob_start(); |
| 119 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-three") ); |
|
| 119 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-three")); |
|
| 120 | 120 | $checkout_content .= ob_get_contents(); |
| 121 | 121 | ob_end_clean(); |
| 122 | - $url = apply_filters('wps_extra_signup_actions', ( isset( $url ) ? $url : '' ) ); |
|
| 123 | - if(!empty($url)) { |
|
| 124 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 122 | + $url = apply_filters('wps_extra_signup_actions', (isset($url) ? $url : '')); |
|
| 123 | + if (!empty($url)) { |
|
| 124 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | else { |
| 128 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 129 | - $url = get_permalink( $checkout_page_id ); |
|
| 130 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 128 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 129 | + $url = get_permalink($checkout_page_id); |
|
| 130 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | break; |
| 134 | 134 | case 4 : |
| 135 | - if ( get_current_user_id() == 0 ) { |
|
| 136 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 137 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 138 | - $url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=2'; |
|
| 139 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 135 | + if (get_current_user_id() == 0) { |
|
| 136 | + $permalink_option = get_option('permalink_structure'); |
|
| 137 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 138 | + $url = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=2'; |
|
| 139 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 140 | 140 | } |
| 141 | 141 | else { |
| 142 | - if( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
| 142 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 143 | 143 | ob_start(); |
| 144 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-four") ); |
|
| 144 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-four")); |
|
| 145 | 145 | $checkout_content .= ob_get_contents(); |
| 146 | 146 | ob_end_clean(); |
| 147 | 147 | } |
| 148 | 148 | else { |
| 149 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 150 | - $url = get_permalink( $checkout_page_id ); |
|
| 151 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 149 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 150 | + $url = get_permalink($checkout_page_id); |
|
| 151 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | break; |
| 155 | 155 | case 5 : |
| 156 | - if ( get_current_user_id() == 0 ) { |
|
| 157 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 158 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 159 | - $url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=2'; |
|
| 160 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 156 | + if (get_current_user_id() == 0) { |
|
| 157 | + $permalink_option = get_option('permalink_structure'); |
|
| 158 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 159 | + $url = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=2'; |
|
| 160 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 161 | 161 | } |
| 162 | 162 | else { |
| 163 | 163 | $wps_cart = new wps_cart(); |
| 164 | - $order = $wps_cart->calcul_cart_information( array() ); |
|
| 164 | + $order = $wps_cart->calcul_cart_information(array()); |
|
| 165 | 165 | $wps_cart->store_cart_in_session($order); |
| 166 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 167 | - if ( !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && ( ( !empty($shipping_option) && !empty($shipping_option['activate']) && !empty($_SESSION['shipping_method']) ) || ( !empty($shipping_option) && empty($shipping_option['activate']) ) ) ) { |
|
| 168 | - $order_id = ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
|
| 166 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 167 | + if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && ((!empty($shipping_option) && !empty($shipping_option['activate']) && !empty($_SESSION['shipping_method'])) || (!empty($shipping_option) && empty($shipping_option['activate'])))) { |
|
| 168 | + $order_id = (!empty($_SESSION['cart']['order_id'])) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
|
| 169 | 169 | ob_start(); |
| 170 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-five") ); |
|
| 170 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-five")); |
|
| 171 | 171 | $checkout_content .= ob_get_contents(); |
| 172 | 172 | ob_end_clean(); |
| 173 | - $checkout_content = apply_filters( 'classic_checkout_step_six_extra_content', $checkout_content ); |
|
| 173 | + $checkout_content = apply_filters('classic_checkout_step_six_extra_content', $checkout_content); |
|
| 174 | 174 | } |
| 175 | 175 | else { |
| 176 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 177 | - $url = get_permalink( $checkout_page_id ); |
|
| 178 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 176 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 177 | + $url = get_permalink($checkout_page_id); |
|
| 178 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | break; |
| 182 | 182 | case 6 : |
| 183 | 183 | |
| 184 | - if ( !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ){ |
|
| 184 | + if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 185 | 185 | $wps_marketing_tools_ctr = new wps_marketing_tools_ctr(); |
| 186 | - $checkout_content .= $wps_marketing_tools_ctr->display_ecommerce_ga_tracker( $_SESSION['order_id'] ); |
|
| 186 | + $checkout_content .= $wps_marketing_tools_ctr->display_ecommerce_ga_tracker($_SESSION['order_id']); |
|
| 187 | 187 | $checkout_content .= $this->wps_classic_confirmation_message(); |
| 188 | 188 | $checkout_content .= $this->wps_summary_order(); |
| 189 | 189 | } |
| 190 | 190 | else { |
| 191 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 192 | - $url = get_permalink( $checkout_page_id ); |
|
| 193 | - wpshop_tools::wpshop_safe_redirect( $url ); |
|
| 191 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 192 | + $url = get_permalink($checkout_page_id); |
|
| 193 | + wpshop_tools::wpshop_safe_redirect($url); |
|
| 194 | 194 | } |
| 195 | 195 | break; |
| 196 | 196 | default : |
| 197 | 197 | ob_start(); |
| 198 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one") ); |
|
| 198 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one")); |
|
| 199 | 199 | $checkout_content .= ob_get_contents(); |
| 200 | 200 | ob_end_clean(); |
| 201 | 201 | break; |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $checkout_content = do_shortcode('[wps_cart]'); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - require_once( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic_checkout") ); |
|
| 209 | + require_once(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic_checkout")); |
|
| 210 | 210 | |
| 211 | 211 | } |
| 212 | 212 | |
@@ -217,10 +217,10 @@ discard block |
||
| 217 | 217 | function wps_classic_confirmation_message() { |
| 218 | 218 | $output = ''; |
| 219 | 219 | $wps_cart = new wps_cart(); |
| 220 | - $available_templates = array( 'banktransfer', 'checks', 'free', 'paypal', 'cic', 'quotation', 'cash_on_delivery' ); |
|
| 221 | - $payment_method = ( !empty($_SESSION['payment_method']) && in_array($_SESSION['payment_method'], $available_templates) ) ? $_SESSION['payment_method'] : 'others'; |
|
| 220 | + $available_templates = array('banktransfer', 'checks', 'free', 'paypal', 'cic', 'quotation', 'cash_on_delivery'); |
|
| 221 | + $payment_method = (!empty($_SESSION['payment_method']) && in_array($_SESSION['payment_method'], $available_templates)) ? $_SESSION['payment_method'] : 'others'; |
|
| 222 | 222 | ob_start(); |
| 223 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir,"frontend", "confirmation/confirmation", $payment_method) ); |
|
| 223 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "confirmation/confirmation", $payment_method)); |
|
| 224 | 224 | $output .= ob_get_contents(); |
| 225 | 225 | ob_end_clean(); |
| 226 | 226 | return $output; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | function wps_summary_order() { |
| 230 | 230 | ob_start(); |
| 231 | - require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir,"frontend", "confirmation/confirmation-summary") ); |
|
| 231 | + require(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "confirmation/confirmation-summary")); |
|
| 232 | 232 | $output = ob_get_contents(); |
| 233 | 233 | ob_end_clean(); |
| 234 | 234 | return $output; |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | * @return String |
| 240 | 240 | */ |
| 241 | 241 | function get_checkout_step_indicator() { |
| 242 | - $default_step = ( !empty( $_GET['order_step'] ) ) ? wpshop_tools::varSanitizer( $_GET['order_step'] ) : 1; |
|
| 242 | + $default_step = (!empty($_GET['order_step'])) ? wpshop_tools::varSanitizer($_GET['order_step']) : 1; |
|
| 243 | 243 | $steps = array(); |
| 244 | 244 | |
| 245 | - $shipping_address_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 246 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
| 247 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 248 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 245 | + $shipping_address_option = get_option('wpshop_shipping_address_choice'); |
|
| 246 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 247 | + $permalink_option = get_option('permalink_structure'); |
|
| 248 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 249 | 249 | |
| 250 | 250 | |
| 251 | 251 | $no_cart = false; |
| 252 | - if ( empty( $wpshop_cart_option ) || empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) || ( 1 != (int) $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) ) { |
|
| 252 | + if (empty($wpshop_cart_option) || empty($wpshop_cart_option['total_nb_of_item_allowed']) || (1 != (int)$wpshop_cart_option['total_nb_of_item_allowed'][0])) { |
|
| 253 | 253 | $steps[] = __('Cart', 'wpshop'); |
| 254 | 254 | } |
| 255 | 255 | else { |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | $steps[] = __('Addresses', 'wpshop'); |
| 261 | 261 | |
| 262 | 262 | $no_shipping = false; |
| 263 | - if ( !empty( $shipping_address_option ) && !empty( $shipping_address_option[ 'activate' ] ) && !empty( $shipping_address_option[ 'choice' ] ) ) { |
|
| 263 | + if (!empty($shipping_address_option) && !empty($shipping_address_option['activate']) && !empty($shipping_address_option['choice'])) { |
|
| 264 | 264 | $steps[] = __('Shipping Mode', 'wpshop'); |
| 265 | 265 | } |
| 266 | 266 | else { |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | $no_payment = false; |
| 271 | 271 | $partial_payment_for_quotation = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
| 272 | - if( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && ( ( !empty($_SESSION['cart']['order_amount_to_pay_now']) && number_format( $_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '' ) == '0.00' ) || ( !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' && isset( $partial_payment_for_quotation['for_quotation']['activate'] ) ) ) ) { |
|
| 272 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && ((!empty($_SESSION['cart']['order_amount_to_pay_now']) && number_format($_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '') == '0.00') || (!empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' && isset($partial_payment_for_quotation['for_quotation']['activate'])))) { |
|
| 273 | 273 | $no_payment = true; |
| 274 | 274 | } |
| 275 | 275 | else { |
@@ -280,45 +280,45 @@ discard block |
||
| 280 | 280 | |
| 281 | 281 | $steps = apply_filters('wps_extra_action_checkout_indicator', $steps); |
| 282 | 282 | |
| 283 | - require_once( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir,"frontend", "checkout_step_indicator/checkout_step_indicator") ); |
|
| 283 | + require_once(wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "checkout_step_indicator/checkout_step_indicator")); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
| 287 | 287 | * AJAX - Valid Checkout Step three |
| 288 | 288 | */ |
| 289 | 289 | function wps_checkout_valid_step_three() { |
| 290 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 290 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 291 | 291 | |
| 292 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_valid_step_three' ) ) |
|
| 292 | + if (!wp_verify_nonce($_wpnonce, 'wps_checkout_valid_step_three')) |
|
| 293 | 293 | wp_die(); |
| 294 | 294 | |
| 295 | 295 | $response = ''; $status = true; |
| 296 | 296 | |
| 297 | - $shipping_address = ( !empty($_POST['shipping_address_id']) ) ? wpshop_tools::varSanitizer( $_POST['shipping_address_id'] ): null; |
|
| 298 | - $billing_address = ( !empty($_POST['billing_address_id']) ) ? wpshop_tools::varSanitizer( $_POST['billing_address_id'] ): null; |
|
| 297 | + $shipping_address = (!empty($_POST['shipping_address_id'])) ? wpshop_tools::varSanitizer($_POST['shipping_address_id']) : null; |
|
| 298 | + $billing_address = (!empty($_POST['billing_address_id'])) ? wpshop_tools::varSanitizer($_POST['billing_address_id']) : null; |
|
| 299 | 299 | |
| 300 | 300 | $user_id = get_current_user_id(); |
| 301 | 301 | |
| 302 | 302 | $response = '<div class="wps-alert-error"><ul>'; |
| 303 | 303 | |
| 304 | - if( $user_id != 0 ) { |
|
| 305 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 306 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 307 | - $user_addresses = wps_address::get_addresses_list( $user_id ); |
|
| 304 | + if ($user_id != 0) { |
|
| 305 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 306 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 307 | + $user_addresses = wps_address::get_addresses_list($user_id); |
|
| 308 | 308 | |
| 309 | 309 | // Check if is only downloadable else display address |
| 310 | 310 | $cart_is_downloadable = false; |
| 311 | - if ( !empty( $_SESSION['cart'] ) && !empty( $_SESSION['cart']['order_items'] ) ) { |
|
| 312 | - foreach( $_SESSION['cart']['order_items'] as $c ) { |
|
| 313 | - $product = wpshop_products::get_product_data( $c['item_id'] ); |
|
| 311 | + if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 312 | + foreach ($_SESSION['cart']['order_items'] as $c) { |
|
| 313 | + $product = wpshop_products::get_product_data($c['item_id']); |
|
| 314 | 314 | /** Check if it's a variation and check the parent product **/ |
| 315 | - if ( get_post_type( $c['item_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 316 | - $parent_def = wpshop_products::get_parent_variation( $c['item_id'] ); |
|
| 317 | - if ( !empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_']) ) { |
|
| 315 | + if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 316 | + $parent_def = wpshop_products::get_parent_variation($c['item_id']); |
|
| 317 | + if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) { |
|
| 318 | 318 | $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_']; |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | - if( !empty($product['is_downloadable_']) && ( __( $product['is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $product['is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
|
| 321 | + if (!empty($product['is_downloadable_']) && (__($product['is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($product['is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) { |
|
| 322 | 322 | $cart_is_downloadable = true; |
| 323 | 323 | } else { |
| 324 | 324 | $cart_is_downloadable = false; |
@@ -327,144 +327,144 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if( !empty($shipping_option) && !empty($shipping_option['activate']) && !$cart_is_downloadable ) { |
|
| 330 | + if (!empty($shipping_option) && !empty($shipping_option['activate']) && !$cart_is_downloadable) { |
|
| 331 | 331 | /** Check Shipping address **/ |
| 332 | - if ( empty($shipping_address) ) { |
|
| 332 | + if (empty($shipping_address)) { |
|
| 333 | 333 | $status = false; |
| 334 | 334 | /** Check if user have already create a shipping address **/ |
| 335 | - if ( !empty($shipping_option['choice']) && !empty($user_addresses) && !empty($user_addresses[ $shipping_option['choice'] ]) ){ |
|
| 336 | - $response .= '<li>'.__( 'You must select a shipping address', 'wpshop' ).'</li>'; |
|
| 335 | + if (!empty($shipping_option['choice']) && !empty($user_addresses) && !empty($user_addresses[$shipping_option['choice']])) { |
|
| 336 | + $response .= '<li>' . __('You must select a shipping address', 'wpshop') . '</li>'; |
|
| 337 | 337 | } |
| 338 | 338 | else { |
| 339 | - $response .= '<li>'.__( 'You must create a shipping address', 'wpshop' ).'</li>'; |
|
| 339 | + $response .= '<li>' . __('You must create a shipping address', 'wpshop') . '</li>'; |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | } |
| 344 | 344 | /** Check Billing address **/ |
| 345 | - if( empty($billing_address) ) { |
|
| 345 | + if (empty($billing_address)) { |
|
| 346 | 346 | $status = false; |
| 347 | - if ( !empty($billing_option['choice']) && !empty($user_addresses) && !empty($user_addresses[ $billing_option['choice'] ]) ){ |
|
| 348 | - $response .= '<li>'.__( 'You must select a billing address', 'wpshop' ).'</li>'; |
|
| 347 | + if (!empty($billing_option['choice']) && !empty($user_addresses) && !empty($user_addresses[$billing_option['choice']])) { |
|
| 348 | + $response .= '<li>' . __('You must select a billing address', 'wpshop') . '</li>'; |
|
| 349 | 349 | } |
| 350 | 350 | else { |
| 351 | - $response .= '<li>'.__( 'You must create a billing address', 'wpshop' ).'</li>'; |
|
| 351 | + $response .= '<li>' . __('You must create a billing address', 'wpshop') . '</li>'; |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | 355 | else { |
| 356 | 356 | $status = false; |
| 357 | - $response .= '<li>'.__( 'You must be logged to pass to next step', 'wpshop' ).'</li>'; |
|
| 357 | + $response .= '<li>' . __('You must be logged to pass to next step', 'wpshop') . '</li>'; |
|
| 358 | 358 | } |
| 359 | 359 | $response .= '</ul></div>'; |
| 360 | 360 | |
| 361 | 361 | /** If no error **/ |
| 362 | - if( $status ) { |
|
| 362 | + if ($status) { |
|
| 363 | 363 | $_SESSION['shipping_address'] = $shipping_address; |
| 364 | 364 | $_SESSION['billing_address'] = $billing_address; |
| 365 | 365 | |
| 366 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 367 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 366 | + $permalink_option = get_option('permalink_structure'); |
|
| 367 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 368 | 368 | /** Checking if no shipping method is required and it is a quotation or a free order **/ |
| 369 | - $shipping_option = get_option( 'wps_shipping_mode' ); |
|
| 369 | + $shipping_option = get_option('wps_shipping_mode'); |
|
| 370 | 370 | |
| 371 | 371 | /** Quotation, no shipping, no payment */ |
| 372 | - if ( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
|
| 372 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
|
| 373 | 373 | $status = true; |
| 374 | 374 | $_SESSION['shipping_method'] = 'No Shipping method required'; |
| 375 | 375 | $payment_method = $_SESSION['payment_method'] = 'quotation'; |
| 376 | - $order_id = wpshop_checkout::process_checkout( $payment_method, ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
| 377 | - $response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
|
| 376 | + $order_id = wpshop_checkout::process_checkout($payment_method, (!empty($_SESSION['cart']['order_id'])) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); |
|
| 377 | + $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=6'; |
|
| 378 | 378 | } else { |
| 379 | 379 | $available_shipping_method = false; |
| 380 | - if( !empty($shipping_option) && !empty($shipping_option['modes']) && !$cart_is_downloadable ) { |
|
| 381 | - foreach( $shipping_option['modes'] as $shipping_mode_id => $shipping_mode ) { |
|
| 382 | - if( !empty($shipping_mode['active']) && $shipping_mode['active'] == 'on' ) { |
|
| 380 | + if (!empty($shipping_option) && !empty($shipping_option['modes']) && !$cart_is_downloadable) { |
|
| 381 | + foreach ($shipping_option['modes'] as $shipping_mode_id => $shipping_mode) { |
|
| 382 | + if (!empty($shipping_mode['active']) && $shipping_mode['active'] == 'on') { |
|
| 383 | 383 | $available_shipping_method = true; |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if( !$available_shipping_method ) { |
|
| 388 | + if (!$available_shipping_method) { |
|
| 389 | 389 | $_SESSION['shipping_method'] = 'No Shipping method required'; |
| 390 | - $order_id = ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
|
| 390 | + $order_id = (!empty($_SESSION['cart']['order_id'])) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
|
| 391 | 391 | |
| 392 | - if( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && isset($_SESSION['cart']['order_amount_to_pay_now']) && number_format( $_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '' ) == '0.00' ) { |
|
| 392 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && isset($_SESSION['cart']['order_amount_to_pay_now']) && number_format($_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '') == '0.00') { |
|
| 393 | 393 | $status = true; |
| 394 | 394 | $payment_method = $_SESSION['payment_method'] = 'free'; |
| 395 | - $order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
| 396 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 397 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 398 | - $url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
|
| 395 | + $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); |
|
| 396 | + $permalink_option = get_option('permalink_structure'); |
|
| 397 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 398 | + $url = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=6'; |
|
| 399 | 399 | // wpshop_tools::wpshop_safe_redirect( $url ); |
| 400 | 400 | $response = $url; |
| 401 | 401 | } |
| 402 | 402 | else { |
| 403 | 403 | $status = true; |
| 404 | - $response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=5'; |
|
| 404 | + $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=5'; |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | else { |
| 408 | 408 | $status = true; |
| 409 | - $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=4'; |
|
| 409 | + $response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=4'; |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | //Stock checking verification |
| 414 | 414 | $this->checking_stock(); |
| 415 | 415 | |
| 416 | - wp_die( json_encode( array( 'status' => $status, 'response' => $response ) ) ); |
|
| 416 | + wp_die(json_encode(array('status' => $status, 'response' => $response))); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
| 420 | 420 | * AJAX - Valid Checkout step four |
| 421 | 421 | */ |
| 422 | 422 | function wps_checkout_valid_step_four() { |
| 423 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 423 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 424 | 424 | |
| 425 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_valid_step_four' ) ) |
|
| 425 | + if (!wp_verify_nonce($_wpnonce, 'wps_checkout_valid_step_four')) |
|
| 426 | 426 | wp_die(); |
| 427 | 427 | |
| 428 | - $shipping_method = ( !empty($_POST['shipping_mode']) ) ? wpshop_tools::varSanitizer($_POST['shipping_mode']) : null; |
|
| 428 | + $shipping_method = (!empty($_POST['shipping_mode'])) ? wpshop_tools::varSanitizer($_POST['shipping_mode']) : null; |
|
| 429 | 429 | $status = false; |
| 430 | 430 | $response = ''; |
| 431 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 432 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 433 | - if ( !empty($shipping_method) ) { |
|
| 431 | + $permalink_option = get_option('permalink_structure'); |
|
| 432 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 433 | + if (!empty($shipping_method)) { |
|
| 434 | 434 | $status = true; |
| 435 | 435 | $_SESSION['shipping_method'] = $shipping_method; |
| 436 | - $order_id = ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
|
| 437 | - if ( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
|
| 436 | + $order_id = (!empty($_SESSION['cart']['order_id'])) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
|
| 437 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
|
| 438 | 438 | $partial_payment_for_quotation = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
| 439 | - if( isset( $partial_payment_for_quotation['for_quotation']['activate'] ) ) { |
|
| 439 | + if (isset($partial_payment_for_quotation['for_quotation']['activate'])) { |
|
| 440 | 440 | $step = '5'; |
| 441 | 441 | } else { |
| 442 | 442 | $payment_method = $_SESSION['payment_method'] = 'quotation'; |
| 443 | - $order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
| 443 | + $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); |
|
| 444 | 444 | $step = '6'; |
| 445 | 445 | } |
| 446 | - $response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
|
| 446 | + $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step; |
|
| 447 | 447 | } |
| 448 | - elseif( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && !empty($_SESSION['cart']['order_amount_to_pay_now']) && number_format( $_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '' ) == '0.00' ) { |
|
| 448 | + elseif (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_amount_to_pay_now']) && number_format($_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '') == '0.00') { |
|
| 449 | 449 | $payment_method = $_SESSION['payment_method'] = 'free'; |
| 450 | - $order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
| 451 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 452 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 453 | - $url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
|
| 450 | + $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); |
|
| 451 | + $permalink_option = get_option('permalink_structure'); |
|
| 452 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 453 | + $url = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=6'; |
|
| 454 | 454 | $response = $url; |
| 455 | 455 | } |
| 456 | 456 | else { |
| 457 | - $response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=5'; |
|
| 457 | + $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=5'; |
|
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | else { |
| 461 | - $response .= '<div class="wps-alert-error">'.__( 'You must select a shipping method', 'wpshop' ).'</div>'; |
|
| 461 | + $response .= '<div class="wps-alert-error">' . __('You must select a shipping method', 'wpshop') . '</div>'; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | //Stock checking verification |
| 465 | 465 | $this->checking_stock(); |
| 466 | 466 | |
| 467 | - echo json_encode( array( 'status' => $status, 'response' => $response) ); |
|
| 467 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 468 | 468 | die(); |
| 469 | 469 | } |
| 470 | 470 | |
@@ -472,46 +472,46 @@ discard block |
||
| 472 | 472 | * AJAX - Valid Checkout step four |
| 473 | 473 | */ |
| 474 | 474 | function wps_checkout_valid_step_five() { |
| 475 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 476 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_valid_step_five' ) ) |
|
| 475 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 476 | + if (!wp_verify_nonce($_wpnonce, 'wps_checkout_valid_step_five')) |
|
| 477 | 477 | wp_die(); |
| 478 | 478 | |
| 479 | 479 | $status = false; |
| 480 | 480 | $response = ''; |
| 481 | - $payment_method = ( !empty($_POST['wps-payment-method']) ) ? wpshop_tools::varSanitizer( $_POST['wps-payment-method'] ): null; |
|
| 482 | - $order_id = ( !empty($_SESSION['cart']['order_id']) ) ? (int) $_SESSION['cart']['order_id'] : 0; |
|
| 483 | - $customer_comment = ( !empty($_POST['wps-customer-comment']) ) ? wpshop_tools::varSanitizer( $_POST['wps-customer-comment'] ) : null; |
|
| 481 | + $payment_method = (!empty($_POST['wps-payment-method'])) ? wpshop_tools::varSanitizer($_POST['wps-payment-method']) : null; |
|
| 482 | + $order_id = (!empty($_SESSION['cart']['order_id'])) ? (int)$_SESSION['cart']['order_id'] : 0; |
|
| 483 | + $customer_comment = (!empty($_POST['wps-customer-comment'])) ? wpshop_tools::varSanitizer($_POST['wps-customer-comment']) : null; |
|
| 484 | 484 | |
| 485 | - $terms_of_sale_required = isset( $_POST['terms_of_sale_indicator'] ) && !empty( $_POST['terms_of_sale_indicator'] ) ? (bool)$_POST['terms_of_sale_indicator'] : (bool)false; |
|
| 486 | - $terms_of_sale_checked = isset( $_POST['terms_of_sale'] ) && !empty( $_POST['terms_of_sale'] ) ? (bool)$_POST['terms_of_sale_indicator'] : (bool)false; |
|
| 485 | + $terms_of_sale_required = isset($_POST['terms_of_sale_indicator']) && !empty($_POST['terms_of_sale_indicator']) ? (bool)$_POST['terms_of_sale_indicator'] : (bool)false; |
|
| 486 | + $terms_of_sale_checked = isset($_POST['terms_of_sale']) && !empty($_POST['terms_of_sale']) ? (bool)$_POST['terms_of_sale_indicator'] : (bool)false; |
|
| 487 | 487 | |
| 488 | - if ( ( $terms_of_sale_required && $terms_of_sale_checked ) || !$terms_of_sale_required ) { |
|
| 489 | - if ( !empty($payment_method) ) { |
|
| 488 | + if (($terms_of_sale_required && $terms_of_sale_checked) || !$terms_of_sale_required) { |
|
| 489 | + if (!empty($payment_method)) { |
|
| 490 | 490 | /** Check if the payment method exist for the shop **/ |
| 491 | - $payment_option = get_option( 'wps_payment_mode' ); |
|
| 491 | + $payment_option = get_option('wps_payment_mode'); |
|
| 492 | 492 | |
| 493 | - if( !empty($payment_option) && !empty($payment_option['mode']) && array_key_exists( $payment_method, $payment_option['mode']) && !empty($payment_option['mode'][$payment_method]['active']) ) { |
|
| 494 | - if( !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' ) { |
|
| 493 | + if (!empty($payment_option) && !empty($payment_option['mode']) && array_key_exists($payment_method, $payment_option['mode']) && !empty($payment_option['mode'][$payment_method]['active'])) { |
|
| 494 | + if (!empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
|
| 495 | 495 | $new_payment_method = $payment_method; |
| 496 | 496 | $payment_method = 'quotation'; |
| 497 | 497 | $is_quotation = true; |
| 498 | 498 | } else { |
| 499 | 499 | $is_quotation = false; |
| 500 | 500 | } |
| 501 | - $order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
| 502 | - if( !empty($order_id) && !empty($customer_comment) ) { |
|
| 501 | + $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); |
|
| 502 | + if (!empty($order_id) && !empty($customer_comment)) { |
|
| 503 | 503 | $wps_back_office_orders_mdl = new wps_back_office_orders_mdl(); |
| 504 | 504 | $wps_back_office_orders_mdl->add_private_comment($order_id, $customer_comment); |
| 505 | 505 | //wp_update_post( array('ID' => $order_id, 'post_excerpt' => $customer_comment) ); |
| 506 | 506 | } |
| 507 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 508 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 509 | - $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
|
| 510 | - if( $is_quotation ) { |
|
| 511 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 512 | - $params = array( 'method' => $new_payment_method, 'waited_amount' => $order_meta['order_partial_payment'], 'status' => 'waiting_payment', 'author' => get_current_user_id() ); |
|
| 507 | + $permalink_option = get_option('permalink_structure'); |
|
| 508 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 509 | + $response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=6'; |
|
| 510 | + if ($is_quotation) { |
|
| 511 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 512 | + $params = array('method' => $new_payment_method, 'waited_amount' => $order_meta['order_partial_payment'], 'status' => 'waiting_payment', 'author' => get_current_user_id()); |
|
| 513 | 513 | $order_meta['order_payment']['received'][0] = $params; |
| 514 | - update_post_meta( $order_id, '_order_postmeta', $order_meta ); |
|
| 514 | + update_post_meta($order_id, '_order_postmeta', $order_meta); |
|
| 515 | 515 | $_SESSION['payment_method'] = $new_payment_method; |
| 516 | 516 | } else { |
| 517 | 517 | $_SESSION['payment_method'] = $payment_method; |
@@ -519,22 +519,22 @@ discard block |
||
| 519 | 519 | $status = true; |
| 520 | 520 | //Add an action to extra actions on order save |
| 521 | 521 | // @TODO : REQUEST |
| 522 | - $args = array( 'order_id' => $order_id, 'posted_data' => $_REQUEST); |
|
| 523 | - wpshop_tools::create_custom_hook( 'wps_order_extra_save_action', $args ); |
|
| 522 | + $args = array('order_id' => $order_id, 'posted_data' => $_REQUEST); |
|
| 523 | + wpshop_tools::create_custom_hook('wps_order_extra_save_action', $args); |
|
| 524 | 524 | } |
| 525 | 525 | else { |
| 526 | - $response = '<div class="wps-alert-error">' .__( 'This payment method is unavailable', 'wpshop' ).'</div>'; |
|
| 526 | + $response = '<div class="wps-alert-error">' . __('This payment method is unavailable', 'wpshop') . '</div>'; |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | else { |
| 530 | - $response = '<div class="wps-alert-error">' .__( 'You must choose a payment method', 'wpshop' ).'</div>'; |
|
| 530 | + $response = '<div class="wps-alert-error">' . __('You must choose a payment method', 'wpshop') . '</div>'; |
|
| 531 | 531 | } |
| 532 | 532 | } |
| 533 | 533 | else { |
| 534 | - $response = '<div class="wps-alert-error">' .__( 'You must accept the terms of sale to order', 'wpshop' ).'</div>'; |
|
| 534 | + $response = '<div class="wps-alert-error">' . __('You must accept the terms of sale to order', 'wpshop') . '</div>'; |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - echo json_encode( array('status' => $status, 'response' => $response) ); |
|
| 537 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 538 | 538 | die(); |
| 539 | 539 | } |
| 540 | 540 | |
@@ -542,15 +542,15 @@ discard block |
||
| 542 | 542 | * Checking stock in differents checkout steps |
| 543 | 543 | */ |
| 544 | 544 | function checking_stock() { |
| 545 | - if( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
| 546 | - foreach( $_SESSION['cart']['order_items'] as $item_id => $item ) { |
|
| 545 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 546 | + foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 547 | 547 | $wps_product = new wps_product_ctr(); |
| 548 | - $checking = $wps_product->check_stock( $item['item_id'], $item['item_qty'], $item_id ); |
|
| 549 | - if( $checking !== true ) { |
|
| 550 | - unset( $_SESSION['cart']['order_items'][$item_id] ); |
|
| 548 | + $checking = $wps_product->check_stock($item['item_id'], $item['item_qty'], $item_id); |
|
| 549 | + if ($checking !== true) { |
|
| 550 | + unset($_SESSION['cart']['order_items'][$item_id]); |
|
| 551 | 551 | $wps_cart_ctr = new wps_cart(); |
| 552 | - $order = $wps_cart_ctr->calcul_cart_information( array() ); |
|
| 553 | - $wps_cart_ctr->store_cart_in_session( $order ); |
|
| 552 | + $order = $wps_cart_ctr->calcul_cart_information(array()); |
|
| 553 | + $wps_cart_ctr->store_cart_in_session($order); |
|
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | } |
@@ -558,6 +558,6 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | -if ( class_exists("wps_classic_checkout") ) { |
|
| 561 | +if (class_exists("wps_classic_checkout")) { |
|
| 562 | 562 | $wps_classic_checkout = new wps_classic_checkout(); |
| 563 | 563 | } |