@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | |
| 263 | 263 | /** Renvoi une nouvelle r�f�rence unique pour une commande |
| 264 | - * @return int |
|
| 264 | + * @return string |
|
| 265 | 265 | */ |
| 266 | 266 | public static function get_new_order_reference(){ |
| 267 | 267 | $number_figures = get_option('wpshop_order_number_figures', false); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** Renvoi une nouvelle r�f�rence unique pour un devis |
| 285 | - * @return int |
|
| 285 | + * @return string |
|
| 286 | 286 | */ |
| 287 | 287 | public static function get_new_pre_order_reference($save = true){ |
| 288 | 288 | $number_figures = get_option('wpshop_order_number_figures', false); |
@@ -662,6 +662,10 @@ discard block |
||
| 662 | 662 | |
| 663 | 663 | return $output; |
| 664 | 664 | } |
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * @param boolean $state |
|
| 668 | + */ |
|
| 665 | 669 | static function display_customer_pay_quotation( $state, $oid ) { |
| 666 | 670 | $btn = '<p><a role="button" data-nonce="' . wp_create_nonce( 'wps_quotation_is_payable_by_customer' ) . '" class="wps-bton-' . ( ( $state ) ? 'third' : 'second' ) . '-mini-rounded quotation_is_payable_by_customer" href="#" >'.__('Valid quotation', 'wpshop').'</a></p>'; |
| 667 | 671 | if( $state ) { |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Products management method file |
| 4 | 4 | * |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | /* Check if file is include. No direct access possible with file url */ |
| 13 | -if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
| 14 | - die( __('Access is not allowed by this way', 'wpshop') ); |
|
| 13 | +if (!defined('WPSHOP_VERSION')) { |
|
| 14 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | /** Add action button */ |
| 71 | 71 | add_meta_box( |
| 72 | 72 | 'wpshop_order_actions', |
| 73 | - '<span class="dashicons dashicons-info"></span> '.__('Actions on order', 'wpshop'), |
|
| 73 | + '<span class="dashicons dashicons-info"></span> ' . __('Actions on order', 'wpshop'), |
|
| 74 | 74 | array('wpshop_orders', 'order_actions'), |
| 75 | 75 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'high' |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | - if ( !in_array( $post->post_status, array( 'auto-draft' ) ) ) { |
|
| 78 | + if (!in_array($post->post_status, array('auto-draft'))) { |
|
| 79 | 79 | add_meta_box('wpshop_credit_actions', __('Credit on order', 'wpshop'), array('wps_credit', 'wps_credit_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @param object $order The current order being edited |
| 102 | 102 | */ |
| 103 | - public static function order_actions( $order ) { |
|
| 103 | + public static function order_actions($order) { |
|
| 104 | 104 | $output = ''; |
| 105 | 105 | |
| 106 | 106 | $order_status = unserialize(WPSHOP_ORDER_STATUS); |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | $tpl_component = array(); |
| 110 | 110 | |
| 111 | - $delete_button = wpshop_display::display_template_element('wpshop_admin_order_action_del_button', array('ADMIN_ORDER_DELETE_LINK' => esc_url( get_delete_post_link($order->ID) ) , 'ADMIN_ORDER_DELETE_TEXT' => (!EMPTY_TRASH_DAYS ? __('Delete Permanently', 'wpshop') : __('Move to Trash', 'wpshop'))), array(), 'admin'); |
|
| 112 | - $tpl_component['ADMIN_ORDER_DELETE_ORDER'] = current_user_can( "delete_post", $order->ID ) ? $delete_button : ''; |
|
| 111 | + $delete_button = wpshop_display::display_template_element('wpshop_admin_order_action_del_button', array('ADMIN_ORDER_DELETE_LINK' => esc_url(get_delete_post_link($order->ID)), 'ADMIN_ORDER_DELETE_TEXT' => (!EMPTY_TRASH_DAYS ? __('Delete Permanently', 'wpshop') : __('Move to Trash', 'wpshop'))), array(), 'admin'); |
|
| 112 | + $tpl_component['ADMIN_ORDER_DELETE_ORDER'] = current_user_can("delete_post", $order->ID) ? $delete_button : ''; |
|
| 113 | 113 | |
| 114 | 114 | /** Add an action list */ |
| 115 | 115 | $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = ''; |
| 116 | 116 | |
| 117 | 117 | /** Display main information about the order */ |
| 118 | 118 | $order_main_info = ''; |
| 119 | - if(!empty($order_postmeta['order_date'])){ |
|
| 120 | - $order_main_info .= '<div class="wps-product-section"><span class="dashicons dashicons-calendar-alt"></span> <strong>'.__('Order date','wpshop').' : </strong><br/>'.mysql2date('d F Y H:i:s', $order_postmeta['order_date'], true).'</div>'; |
|
| 119 | + if (!empty($order_postmeta['order_date'])) { |
|
| 120 | + $order_main_info .= '<div class="wps-product-section"><span class="dashicons dashicons-calendar-alt"></span> <strong>' . __('Order date', 'wpshop') . ' : </strong><br/>' . mysql2date('d F Y H:i:s', $order_postmeta['order_date'], true) . '</div>'; |
|
| 121 | 121 | } |
| 122 | 122 | $order_main_info .= '<div class="wps-product-section">'; |
| 123 | - if(empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))){ |
|
| 124 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Temporary quotation reference','wpshop').': </strong>'.self::get_new_pre_order_reference(false).'<br/>'; |
|
| 123 | + if (empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))) { |
|
| 124 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Temporary quotation reference', 'wpshop') . ': </strong>' . self::get_new_pre_order_reference(false) . '<br/>'; |
|
| 125 | 125 | } |
| 126 | - else{ |
|
| 127 | - if(!empty($order_postmeta['order_key'])){ |
|
| 128 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Order reference','wpshop').' : </strong>'.$order_postmeta['order_key'].'<br/>'; |
|
| 126 | + else { |
|
| 127 | + if (!empty($order_postmeta['order_key'])) { |
|
| 128 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Order reference', 'wpshop') . ' : </strong>' . $order_postmeta['order_key'] . '<br/>'; |
|
| 129 | 129 | } |
| 130 | - if(!empty($order_postmeta['order_temporary_key'])){ |
|
| 131 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Pre-order reference','wpshop').': </strong>'.$order_postmeta['order_temporary_key'].'<br/>'; |
|
| 132 | - $post_ID = !empty( $_GET['post'] ) ? (int) $_GET['post'] : 0; |
|
| 133 | - $order_main_info .= '<a href="' .admin_url( 'admin-post.php?action=wps_invoice&order_id=' . $post_ID . '&mode=pdf' ) . '">' .__('Download the quotation', 'wpshop'). '</a><br />'; |
|
| 130 | + if (!empty($order_postmeta['order_temporary_key'])) { |
|
| 131 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Pre-order reference', 'wpshop') . ': </strong>' . $order_postmeta['order_temporary_key'] . '<br/>'; |
|
| 132 | + $post_ID = !empty($_GET['post']) ? (int)$_GET['post'] : 0; |
|
| 133 | + $order_main_info .= '<a href="' . admin_url('admin-post.php?action=wps_invoice&order_id=' . $post_ID . '&mode=pdf') . '">' . __('Download the quotation', 'wpshop') . '</a><br />'; |
|
| 134 | 134 | } |
| 135 | - if(!empty($order_postmeta['order_invoice_ref'])){ |
|
| 135 | + if (!empty($order_postmeta['order_invoice_ref'])) { |
|
| 136 | 136 | $sub_tpl_component = array(); |
| 137 | - $order_invoice_download = '<a href="' . admin_url( 'admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&invoice_ref=' . $order_postmeta['order_invoice_ref'] . '&mode=pdf' ) . '">' . __('Download invoice', 'wpshop') . '</a><br />'; |
|
| 138 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'. __('Invoice number','wpshop').': </strong>'.$order_postmeta['order_invoice_ref'].'<br/>' . $order_invoice_download . ''; |
|
| 137 | + $order_invoice_download = '<a href="' . admin_url('admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&invoice_ref=' . $order_postmeta['order_invoice_ref'] . '&mode=pdf') . '">' . __('Download invoice', 'wpshop') . '</a><br />'; |
|
| 138 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Invoice number', 'wpshop') . ': </strong>' . $order_postmeta['order_invoice_ref'] . '<br/>' . $order_invoice_download . ''; |
|
| 139 | 139 | } |
| 140 | 140 | else { |
| 141 | 141 | $order_main_info .= wpshop_display::display_template_element('wpshop_admin_order_generate_invoice_button', array(), array(), 'admin'); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | |
| 147 | 147 | /*Add the current order status in display**/ |
| 148 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= ( !empty($order_postmeta['order_status']) ) ? (sprintf('<span class="order_status_' . $order->ID . ' wpshop_order_status_container wpshop_order_status_%1$s ">%2$s</span>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) ) : ''; |
|
| 148 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= (!empty($order_postmeta['order_status'])) ? (sprintf('<span class="order_status_' . $order->ID . ' wpshop_order_status_container wpshop_order_status_%1$s ">%2$s</span>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop'))) : ''; |
|
| 149 | 149 | |
| 150 | 150 | $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= $order_main_info; |
| 151 | 151 | |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | </div>'; |
| 164 | 164 | }*/ |
| 165 | 165 | |
| 166 | - if( ( ( !empty($order_postmeta['cart_type']) && $order_postmeta['cart_type'] == 'quotation' ) || !empty( $order_postmeta['order_temporary_key'] ) ) && in_array( $order_postmeta['order_status'], array( 'awaiting_payment', 'partially_paid' ) ) && (float) $order_postmeta['order_amount_to_pay_now'] != (float) 0 ) { |
|
| 167 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section">' . self::display_customer_pay_quotation( isset( $order_postmeta['pay_quotation'] ), $order->ID ) . '</div>'; |
|
| 166 | + if (((!empty($order_postmeta['cart_type']) && $order_postmeta['cart_type'] == 'quotation') || !empty($order_postmeta['order_temporary_key'])) && in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid')) && (float)$order_postmeta['order_amount_to_pay_now'] != (float)0) { |
|
| 167 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section">' . self::display_customer_pay_quotation(isset($order_postmeta['pay_quotation']), $order->ID) . '</div>'; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -175,30 +175,30 @@ discard block |
||
| 175 | 175 | }*/ |
| 176 | 176 | |
| 177 | 177 | /*Add the button regarding the order status**/ |
| 178 | - if ( !empty($order_postmeta['order_status']) ) { |
|
| 179 | - if( $order_postmeta['order_status'] == 'awaiting_payment' ) { |
|
| 180 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section"><button class="wps-bton-second-mini-rounded markAsCanceled order_'.$order->ID.'" >'.__('Cancel this order', 'wpshop').'</button><input type="hidden" id="markascanceled_order_hidden_indicator" name="markascanceled_order_hidden_indicator" /></div>'; |
|
| 178 | + if (!empty($order_postmeta['order_status'])) { |
|
| 179 | + if ($order_postmeta['order_status'] == 'awaiting_payment') { |
|
| 180 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section"><button class="wps-bton-second-mini-rounded markAsCanceled order_' . $order->ID . '" >' . __('Cancel this order', 'wpshop') . '</button><input type="hidden" id="markascanceled_order_hidden_indicator" name="markascanceled_order_hidden_indicator" /></div>'; |
|
| 181 | 181 | } |
| 182 | - $credit_meta = get_post_meta( $order->ID, '_wps_order_credit', true ); |
|
| 182 | + $credit_meta = get_post_meta($order->ID, '_wps_order_credit', true); |
|
| 183 | 183 | |
| 184 | - $total_received = (float) 0; |
|
| 185 | - if ( ! empty( $order_postmeta['order_payment'] ) && ! empty( $order_postmeta['order_payment']['received'] ) ) { |
|
| 186 | - foreach( $order_postmeta['order_payment']['received'] as $received ) { |
|
| 187 | - $total_received += (float) isset( $received['received_amount'] ) ? $received['received_amount'] : 0; |
|
| 184 | + $total_received = (float)0; |
|
| 185 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) { |
|
| 186 | + foreach ($order_postmeta['order_payment']['received'] as $received) { |
|
| 187 | + $total_received += (float)isset($received['received_amount']) ? $received['received_amount'] : 0; |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( empty($credit_meta) && (float) 0 !== $total_received ) { |
|
| 192 | - if( $order_postmeta['order_status'] == 'refunded') { |
|
| 193 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container">' .__('Credit Slip number', 'wpshop'). ' : <strong>'. ( (!empty($order_postmeta) && !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['refunded_action']) && !empty($order_postmeta['order_payment']['refunded_action']['credit_slip_ref']) ) ? '<a href="' .admin_url( 'admin-post.php?action=wps_invoice&order_id=' .$order->ID. '&invoice_ref=' .$order_postmeta['order_payment']['refunded_action']['credit_slip_ref'].'&credit_slip=ok' ). '" target="_blank">'.$order_postmeta['order_payment']['refunded_action']['credit_slip_ref'].'</a>' : '') .'</strong></div>'; |
|
| 191 | + if (empty($credit_meta) && (float)0 !== $total_received) { |
|
| 192 | + if ($order_postmeta['order_status'] == 'refunded') { |
|
| 193 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container">' . __('Credit Slip number', 'wpshop') . ' : <strong>' . ((!empty($order_postmeta) && !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['refunded_action']) && !empty($order_postmeta['order_payment']['refunded_action']['credit_slip_ref'])) ? '<a href="' . admin_url('admin-post.php?action=wps_invoice&order_id=' . $order->ID . '&invoice_ref=' . $order_postmeta['order_payment']['refunded_action']['credit_slip_ref'] . '&credit_slip=ok') . '" target="_blank">' . $order_postmeta['order_payment']['refunded_action']['credit_slip_ref'] . '</a>' : '') . '</strong></div>'; |
|
| 194 | 194 | } |
| 195 | 195 | else { |
| 196 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container" ><button class="wps-bton-second-mini-rounded markAsRefunded order_' .$order->ID. '">' .__('Refund this order', 'wpshop'). '</button><input type="hidden" id="markasrefunded_order_hidden_indicator" name="markasrefunded_order_hidden_indicator" /></div>'; |
|
| 196 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section wps_markAsRefunded_container" ><button class="wps-bton-second-mini-rounded markAsRefunded order_' . $order->ID . '">' . __('Refund this order', 'wpshop') . '</button><input type="hidden" id="markasrefunded_order_hidden_indicator" name="markasrefunded_order_hidden_indicator" /></div>'; |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = strrev( preg_replace( strrev( '/wps-product-section/' ), '', strrev( $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] ), 1 ) ); |
|
| 201 | - echo wpshop_display::display_template_element( 'wpshop_admin_order_action_box', $tpl_component, array( 'type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'id' => $order->ID ), 'admin' ); |
|
| 200 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = strrev(preg_replace(strrev('/wps-product-section/'), '', strrev($tpl_component['ADMIN_ORDER_ACTIONS_LIST']), 1)); |
|
| 201 | + echo wpshop_display::display_template_element('wpshop_admin_order_action_box', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'id' => $order->ID), 'admin'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | function order_container_in_admin() { |
| 207 | 207 | global $post; |
| 208 | 208 | $output = '<div id="wps_order_content_container">'; |
| 209 | - $output .= self::order_content( $post ); |
|
| 209 | + $output .= self::order_content($post); |
|
| 210 | 210 | $output .= '</div>'; |
| 211 | 211 | echo $output; |
| 212 | 212 | } |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @param order $post The complete order content |
| 219 | 219 | */ |
| 220 | - function order_content( $post ) { |
|
| 220 | + function order_content($post) { |
|
| 221 | 221 | $order_content = ''; |
| 222 | 222 | |
| 223 | 223 | $order = get_post_meta($post->ID, '_order_postmeta', true); |
| 224 | 224 | |
| 225 | 225 | $order_content .= '<div id="order_product_container" class="order_product_container wpshop_cls" >'; |
| 226 | - if($order){/* Read the order content if the order has product */ |
|
| 226 | + if ($order) {/* Read the order content if the order has product */ |
|
| 227 | 227 | $order_content .= '<input type="hidden" value="" name="order_products_to_delete" id="order_products_to_delete" />' . wpshop_cart::display_cart(true, $order, 'admin'); |
| 228 | 228 | if (empty($order['order_invoice_ref'])) { |
| 229 | 229 | $order_content .= '<div id="order_refresh_button_container" class="wpshop_clear_block" ><input type="button" class="button-primary alignright wpshopHide" id="wpshop_admin_order_recalculate" value="' . __('Refresh order informations', 'wpshop') . '" /></div>'; |
@@ -241,18 +241,18 @@ discard block |
||
| 241 | 241 | /** Generate the billing reference regarding the order $order_id |
| 242 | 242 | * @return void |
| 243 | 243 | */ |
| 244 | - function order_generate_billing_number($order_id, $force_invoicing = false){ |
|
| 244 | + function order_generate_billing_number($order_id, $force_invoicing = false) { |
|
| 245 | 245 | global $wpdb, $wpshop_modules_billing; |
| 246 | 246 | |
| 247 | 247 | // Get the order from the db |
| 248 | 248 | $order = get_post_meta($order_id, '_order_postmeta', true); |
| 249 | 249 | |
| 250 | 250 | // If the payment is completed |
| 251 | - if(($order['order_status']=='completed') || $force_invoicing) { |
|
| 251 | + if (($order['order_status'] == 'completed') || $force_invoicing) { |
|
| 252 | 252 | |
| 253 | 253 | // If the reference hasn't been generated yet |
| 254 | - if(empty($order['order_invoice_ref'])) { |
|
| 255 | - $order['order_invoice_ref'] = $wpshop_modules_billing->generate_invoice_number( $order_id ); |
|
| 254 | + if (empty($order['order_invoice_ref'])) { |
|
| 255 | + $order['order_invoice_ref'] = $wpshop_modules_billing->generate_invoice_number($order_id); |
|
| 256 | 256 | |
| 257 | 257 | update_post_meta($order_id, '_order_postmeta', $order); |
| 258 | 258 | } |
@@ -263,45 +263,45 @@ discard block |
||
| 263 | 263 | /** Renvoi une nouvelle r�f�rence unique pour une commande |
| 264 | 264 | * @return int |
| 265 | 265 | */ |
| 266 | - public static function get_new_order_reference(){ |
|
| 266 | + public static function get_new_order_reference() { |
|
| 267 | 267 | $number_figures = get_option('wpshop_order_number_figures', false); |
| 268 | 268 | /* If the number doesn't exist, we create a default one */ |
| 269 | - if(!$number_figures){ |
|
| 269 | + if (!$number_figures) { |
|
| 270 | 270 | $number_figures = 5; |
| 271 | 271 | update_option('wpshop_order_number_figures', $number_figures); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | $order_current_number = get_option('wpshop_order_current_number', false); |
| 275 | 275 | /* If the counter doesn't exist, we initiate it */ |
| 276 | - if(!$order_current_number) { $order_current_number = 1; } |
|
| 276 | + if (!$order_current_number) { $order_current_number = 1; } |
|
| 277 | 277 | else { $order_current_number++; } |
| 278 | 278 | update_option('wpshop_order_current_number', $order_current_number); |
| 279 | 279 | |
| 280 | - $order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number); |
|
| 281 | - return WPSHOP_ORDER_REFERENCE_PREFIX.$order_ref; |
|
| 280 | + $order_ref = (string)sprintf('%0' . $number_figures . 'd', $order_current_number); |
|
| 281 | + return WPSHOP_ORDER_REFERENCE_PREFIX . $order_ref; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** Renvoi une nouvelle r�f�rence unique pour un devis |
| 285 | 285 | * @return int |
| 286 | 286 | */ |
| 287 | - public static function get_new_pre_order_reference($save = true){ |
|
| 287 | + public static function get_new_pre_order_reference($save = true) { |
|
| 288 | 288 | $number_figures = get_option('wpshop_order_number_figures', false); |
| 289 | 289 | /* If the number doesn't exist, we create a default one */ |
| 290 | - if(!$number_figures){ |
|
| 290 | + if (!$number_figures) { |
|
| 291 | 291 | $number_figures = 5; |
| 292 | 292 | update_option('wpshop_order_number_figures', $number_figures); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | $order_current_number = get_option('wpshop_preorder_current_number', false); |
| 296 | 296 | /* If the counter doesn't exist, we initiate it */ |
| 297 | - if(!$order_current_number) { $order_current_number = 1; } |
|
| 297 | + if (!$order_current_number) { $order_current_number = 1; } |
|
| 298 | 298 | else { $order_current_number++; } |
| 299 | - if($save){ |
|
| 299 | + if ($save) { |
|
| 300 | 300 | update_option('wpshop_preorder_current_number', $order_current_number); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number); |
|
| 304 | - return WPSHOP_PREORDER_REFERENCE_PREFIX.$order_ref; |
|
| 303 | + $order_ref = (string)sprintf('%0' . $number_figures . 'd', $order_current_number); |
|
| 304 | + return WPSHOP_PREORDER_REFERENCE_PREFIX . $order_ref; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -316,24 +316,24 @@ discard block |
||
| 316 | 316 | * |
| 317 | 317 | * @return void |
| 318 | 318 | */ |
| 319 | - public static function set_order_customer_addresses($user_id, $order_id, $shipping_address_id='', $billing_address_id=''){ |
|
| 319 | + public static function set_order_customer_addresses($user_id, $order_id, $shipping_address_id = '', $billing_address_id = '') { |
|
| 320 | 320 | /** Get order informations */ |
| 321 | 321 | $billing_info['id'] = get_post_meta($billing_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true); |
| 322 | - $billing_info['address'] = get_post_meta($billing_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 323 | - $billing_info['address_id'] = ( !empty($_SESSION['billing_address']) ) ? intval( $_SESSION['billing_address'] ) : ''; |
|
| 324 | - if ( !empty($_SESSION['shipping_partner_id']) ) { |
|
| 325 | - $partner_address_id = get_post_meta( $_SESSION['shipping_partner_id'], '_wpshop_attached_address', true); |
|
| 322 | + $billing_info['address'] = get_post_meta($billing_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 323 | + $billing_info['address_id'] = (!empty($_SESSION['billing_address'])) ? intval($_SESSION['billing_address']) : ''; |
|
| 324 | + if (!empty($_SESSION['shipping_partner_id'])) { |
|
| 325 | + $partner_address_id = get_post_meta($_SESSION['shipping_partner_id'], '_wpshop_attached_address', true); |
|
| 326 | 326 | if (!empty($partner_address_id)) { |
| 327 | - foreach( $partner_address_id as $address_id ) { |
|
| 327 | + foreach ($partner_address_id as $address_id) { |
|
| 328 | 328 | $shipping_info['id'] = get_post_meta($address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true); |
| 329 | - $shipping_info['address'] = get_post_meta( $address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 329 | + $shipping_info['address'] = get_post_meta($address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | else { |
| 334 | 334 | $shipping_info['id'] = get_post_meta($shipping_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true); |
| 335 | - $shipping_info['address'] = get_post_meta($shipping_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 336 | - $shipping_info['address_id'] = ( !empty($_SESSION['shipping_address']) ) ? intval( $_SESSION['shipping_address'] ) : ''; |
|
| 335 | + $shipping_info['address'] = get_post_meta($shipping_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 336 | + $shipping_info['address_id'] = (!empty($_SESSION['shipping_address'])) ? intval($_SESSION['shipping_address']) : ''; |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | $order_info = array('billing' => $billing_info, 'shipping' => $shipping_info); |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | /** Set the custom colums |
| 347 | 347 | * @return array |
| 348 | 348 | */ |
| 349 | - static function orders_edit_columns($columns){ |
|
| 349 | + static function orders_edit_columns($columns) { |
|
| 350 | 350 | $columns = array( |
| 351 | 351 | 'cb' => '<input type="checkbox" />', |
| 352 | 352 | 'order_identifier' => __('Identifiers', 'wpshop'), |
@@ -366,40 +366,40 @@ discard block |
||
| 366 | 366 | * @return array |
| 367 | 367 | */ |
| 368 | 368 | public static function orders_custom_columns($column, $post_id) { |
| 369 | - if ( get_post_type( $post_id ) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) { |
|
| 369 | + if (get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
|
| 370 | 370 | global $civility, $order_status; |
| 371 | 371 | |
| 372 | 372 | $metadata = get_post_custom(); |
| 373 | 373 | |
| 374 | - $order_postmeta = isset($metadata['_order_postmeta'][0])?unserialize($metadata['_order_postmeta'][0]):''; |
|
| 375 | - $addresses = get_post_meta($post_id,'_order_info', true); |
|
| 374 | + $order_postmeta = isset($metadata['_order_postmeta'][0]) ? unserialize($metadata['_order_postmeta'][0]) : ''; |
|
| 375 | + $addresses = get_post_meta($post_id, '_order_info', true); |
|
| 376 | 376 | |
| 377 | - switch($column){ |
|
| 377 | + switch ($column) { |
|
| 378 | 378 | case "order_identifier": |
| 379 | - if( !empty( $order_postmeta['order_key'] ) ) { |
|
| 379 | + if (!empty($order_postmeta['order_key'])) { |
|
| 380 | 380 | echo '<b>' . $order_postmeta['order_key'] . '</b><br>'; |
| 381 | 381 | } |
| 382 | - if( !empty( $order_postmeta['order_invoice_ref'] ) ) { |
|
| 382 | + if (!empty($order_postmeta['order_invoice_ref'])) { |
|
| 383 | 383 | echo '<i>' . $order_postmeta['order_invoice_ref'] . '</i>'; |
| 384 | - } elseif( !empty($order_postmeta['order_temporary_key'] ) ) { |
|
| 384 | + } elseif (!empty($order_postmeta['order_temporary_key'])) { |
|
| 385 | 385 | echo '<b>' . $order_postmeta['order_temporary_key'] . '</b>'; |
| 386 | 386 | } |
| 387 | 387 | break; |
| 388 | 388 | |
| 389 | 389 | case "order_status": |
| 390 | - echo !empty($order_postmeta['order_status']) ? sprintf('<mark class="%s" id="order_status_'.$post_id.'">%s</mark>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) : __('Unknown Status', 'wpshop'); |
|
| 390 | + echo !empty($order_postmeta['order_status']) ? sprintf('<mark class="%s" id="order_status_' . $post_id . '">%s</mark>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) : __('Unknown Status', 'wpshop'); |
|
| 391 | 391 | break; |
| 392 | 392 | |
| 393 | 393 | case "order_billing": |
| 394 | - if ( !empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address']) ) { |
|
| 394 | + if (!empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address'])) { |
|
| 395 | 395 | $billing = $addresses['billing']['address']; |
| 396 | 396 | } |
| 397 | - else if ( !empty($addresses['billing']) ) { |
|
| 397 | + else if (!empty($addresses['billing'])) { |
|
| 398 | 398 | $billing = $addresses['billing']; |
| 399 | 399 | } |
| 400 | - if ( !empty($billing) ) { |
|
| 401 | - echo (!empty($billing['civility']) ? __(wpshop_attributes::get_attribute_type_select_option_info($billing['civility'], 'label', 'custom'), 'wpshop') : null).' <strong>'.(!empty($billing['address_first_name']) ? $billing['address_first_name'] : null).' '.(!empty($billing['address_last_name']) ? $billing['address_last_name'] : null).'</strong>'; |
|
| 402 | - echo empty($billing['company']) ?'<br />' : ', <i>'.$billing['company'].'</i><br />'; |
|
| 400 | + if (!empty($billing)) { |
|
| 401 | + echo (!empty($billing['civility']) ? __(wpshop_attributes::get_attribute_type_select_option_info($billing['civility'], 'label', 'custom'), 'wpshop') : null) . ' <strong>' . (!empty($billing['address_first_name']) ? $billing['address_first_name'] : null) . ' ' . (!empty($billing['address_last_name']) ? $billing['address_last_name'] : null) . '</strong>'; |
|
| 402 | + echo empty($billing['company']) ? '<br />' : ', <i>' . $billing['company'] . '</i><br />'; |
|
| 403 | 403 | echo !empty($billing['address']) ? $billing['address'] : null; |
| 404 | 404 | echo !empty($billing['postcode']) ? '<br />' . $billing['postcode'] . ' ' : null; |
| 405 | 405 | echo !empty($billing['city']) ? $billing['city'] . ', ' : null; |
@@ -412,35 +412,35 @@ discard block |
||
| 412 | 412 | break; |
| 413 | 413 | |
| 414 | 414 | case "order_shipping": |
| 415 | - if ( !empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address']) ) { |
|
| 415 | + if (!empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address'])) { |
|
| 416 | 416 | $shipping = $addresses['shipping']['address']; |
| 417 | 417 | } |
| 418 | - else if ( !empty($addresses['shipping']) ) { |
|
| 418 | + else if (!empty($addresses['shipping'])) { |
|
| 419 | 419 | $shipping = $addresses['shipping']; |
| 420 | 420 | } |
| 421 | - if ( !empty($shipping) ) { |
|
| 422 | - echo '<strong>'.(!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null).' '.(!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null).'</strong>'; |
|
| 423 | - echo empty($shipping['company'])?'<br />':', <i>'.$shipping['company'].'</i><br />'; |
|
| 421 | + if (!empty($shipping)) { |
|
| 422 | + echo '<strong>' . (!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null) . ' ' . (!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null) . '</strong>'; |
|
| 423 | + echo empty($shipping['company']) ? '<br />' : ', <i>' . $shipping['company'] . '</i><br />'; |
|
| 424 | 424 | echo (!empty($shipping['address']) ? $shipping['address'] : null); |
| 425 | 425 | echo !empty($billing['postcode']) ? '<br />' . $billing['postcode'] . ' ' : null; |
| 426 | 426 | echo !empty($billing['city']) ? $billing['city'] . ', ' : null; |
| 427 | 427 | echo !empty($billing['country']) ? $billing['country'] : null; |
| 428 | 428 | } |
| 429 | - else{ |
|
| 429 | + else { |
|
| 430 | 430 | echo __('No information available for user shipping', 'wpshop'); |
| 431 | 431 | } |
| 432 | 432 | break; |
| 433 | 433 | |
| 434 | 434 | case "order_type": |
| 435 | - echo '<a href="'.admin_url('post.php?post='.$post_id.'&action=edit').'">'.(!empty($order_postmeta['order_temporary_key']) ? __('Quotation','wpshop') : __('Basic order','wpshop')).'</a>'; |
|
| 435 | + echo '<a href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . (!empty($order_postmeta['order_temporary_key']) ? __('Quotation', 'wpshop') : __('Basic order', 'wpshop')) . '</a>'; |
|
| 436 | 436 | $buttons = '<p class="row-actions">'; |
| 437 | 437 | // Voir la commande |
| 438 | - $buttons .= '<a class="button button-small" href="'.admin_url('post.php?post='.$post_id.'&action=edit').'">'.__('View', 'wpshop').'</a>'; |
|
| 438 | + $buttons .= '<a class="button button-small" href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . __('View', 'wpshop') . '</a>'; |
|
| 439 | 439 | // Marquer comme envoy� |
| 440 | 440 | if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'completed')) { |
| 441 | - $buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_'.$post_id.' wps-bton-loader">'.__('Mark as shipped', 'wpshop').'</a> '; |
|
| 441 | + $buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_' . $post_id . ' wps-bton-loader">' . __('Mark as shipped', 'wpshop') . '</a> '; |
|
| 442 | 442 | } |
| 443 | - else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment' )) { |
|
| 443 | + else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment')) { |
|
| 444 | 444 | // $buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' '; |
| 445 | 445 | } |
| 446 | 446 | $buttons .= '</p>'; |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | |
| 454 | 454 | case "order_total": |
| 455 | 455 | $currency = !empty($order_postmeta['order_currency']) ? $order_postmeta['order_currency'] : get_option('wpshop_shop_default_currency'); |
| 456 | - echo isset( $order_postmeta['order_grand_total'] ) ? number_format( $order_postmeta['order_grand_total'], 2, '.', '' ).' '. wpshop_tools::wpshop_get_sigle($currency) : 'NaN'; |
|
| 456 | + echo isset($order_postmeta['order_grand_total']) ? number_format($order_postmeta['order_grand_total'], 2, '.', '') . ' ' . wpshop_tools::wpshop_get_sigle($currency) : 'NaN'; |
|
| 457 | 457 | break; |
| 458 | 458 | |
| 459 | 459 | /*case "order_actions": |
@@ -481,10 +481,10 @@ discard block |
||
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | public static function list_table_filters() { |
| 484 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 485 | - $entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
| 486 | - $entity_filter_btpf = !empty( $_GET['entity_filter_btpf'] ) ? sanitize_text_field( $_GET['entity_filter_btpf'] ) : ''; |
|
| 487 | - $entity_filter_btps = !empty( $_GET['entity_filter_btps'] ) ? sanitize_text_field( $_GET['entity_filter_btps'] ) : ''; |
|
| 484 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 485 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
| 486 | + $entity_filter_btpf = !empty($_GET['entity_filter_btpf']) ? sanitize_text_field($_GET['entity_filter_btpf']) : ''; |
|
| 487 | + $entity_filter_btps = !empty($_GET['entity_filter_btps']) ? sanitize_text_field($_GET['entity_filter_btps']) : ''; |
|
| 488 | 488 | |
| 489 | 489 | if (isset($post_type)) { |
| 490 | 490 | if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER)) { |
@@ -496,23 +496,23 @@ discard block |
||
| 496 | 496 | echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, $entity_filter, '', 'index'); |
| 497 | 497 | $min = $entity_filter_btpf; |
| 498 | 498 | $max = $entity_filter_btps; |
| 499 | - echo ' <label for="entity_filter_btpf">'.__('Between two prices', 'wpshop').'</label> '; |
|
| 500 | - echo wpshop_form::form_input('entity_filter_btpf', 'entity_filter_btpf', $min, 'text', 'placeholder="'.__('Minimum price', 'wpshop').'"', null); |
|
| 501 | - echo wpshop_form::form_input('entity_filter_btps', 'entity_filter_btps', $max, 'text', 'placeholder="'.__('Maximum price', 'wpshop').'"', null); |
|
| 499 | + echo ' <label for="entity_filter_btpf">' . __('Between two prices', 'wpshop') . '</label> '; |
|
| 500 | + echo wpshop_form::form_input('entity_filter_btpf', 'entity_filter_btpf', $min, 'text', 'placeholder="' . __('Minimum price', 'wpshop') . '"', null); |
|
| 501 | + echo wpshop_form::form_input('entity_filter_btps', 'entity_filter_btps', $max, 'text', 'placeholder="' . __('Maximum price', 'wpshop') . '"', null); |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | public static function list_table_filter_parse_query($query) { |
| 507 | 507 | global $pagenow, $wpdb; |
| 508 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 509 | - $entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
| 510 | - $entity_filter_btpf = !empty( $_GET['entity_filter_btpf'] ) ? sanitize_text_field( $_GET['entity_filter_btpf'] ) : ''; |
|
| 511 | - $entity_filter_btps = !empty( $_GET['entity_filter_btps'] ) ? sanitize_text_field( $_GET['entity_filter_btps'] ) : ''; |
|
| 508 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 509 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
| 510 | + $entity_filter_btpf = !empty($_GET['entity_filter_btpf']) ? sanitize_text_field($_GET['entity_filter_btpf']) : ''; |
|
| 511 | + $entity_filter_btps = !empty($_GET['entity_filter_btps']) ? sanitize_text_field($_GET['entity_filter_btps']) : ''; |
|
| 512 | 512 | |
| 513 | - if ( is_admin() && ($pagenow == 'edit.php') && !empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) && !empty( $entity_filter ) ) { |
|
| 513 | + if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) && !empty($entity_filter)) { |
|
| 514 | 514 | $check = null; |
| 515 | - switch ( $entity_filter ) { |
|
| 515 | + switch ($entity_filter) { |
|
| 516 | 516 | case 'all': |
| 517 | 517 | $sql_query = $wpdb->prepare( |
| 518 | 518 | "SELECT ID |
@@ -576,27 +576,27 @@ discard block |
||
| 576 | 576 | break; |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if ( !empty( $check ) ) { |
|
| 580 | - if( !empty($no_btp) && $no_btp == 'yes' ) { |
|
| 579 | + if (!empty($check)) { |
|
| 580 | + if (!empty($no_btp) && $no_btp == 'yes') { |
|
| 581 | 581 | $min = 'minimum'; |
| 582 | 582 | $max = 'maximum'; |
| 583 | 583 | } else { |
| 584 | - $min = ( !empty($_GET['entity_filter_btpf']) && is_numeric($_GET['entity_filter_btpf']) ) ? sanitize_text_field( $_GET['entity_filter_btpf'] ) : 'minimum'; |
|
| 585 | - $max = ( !empty($_GET['entity_filter_btps']) && is_numeric($_GET['entity_filter_btps']) ) ? sanitize_text_field( $_GET['entity_filter_btps'] ) : 'maximum'; |
|
| 584 | + $min = (!empty($_GET['entity_filter_btpf']) && is_numeric($_GET['entity_filter_btpf'])) ? sanitize_text_field($_GET['entity_filter_btpf']) : 'minimum'; |
|
| 585 | + $max = (!empty($_GET['entity_filter_btps']) && is_numeric($_GET['entity_filter_btps'])) ? sanitize_text_field($_GET['entity_filter_btps']) : 'maximum'; |
|
| 586 | 586 | } |
| 587 | 587 | $results = $wpdb->get_results($sql_query); |
| 588 | 588 | $post_id_list = array(); |
| 589 | 589 | $i = 0; |
| 590 | - foreach($results as $item){ |
|
| 590 | + foreach ($results as $item) { |
|
| 591 | 591 | $meta_value = get_post_meta($item->ID, '_order_postmeta'); |
| 592 | - $price = ( !empty( $meta_value[0]['order_grand_total'] ) ) ? $meta_value[0]['order_grand_total'] : ''; |
|
| 593 | - if( $price >= $min || $min == 'minimum' ) { |
|
| 594 | - if( $price <= $max || $max == 'maximum' ) { |
|
| 592 | + $price = (!empty($meta_value[0]['order_grand_total'])) ? $meta_value[0]['order_grand_total'] : ''; |
|
| 593 | + if ($price >= $min || $min == 'minimum') { |
|
| 594 | + if ($price <= $max || $max == 'maximum') { |
|
| 595 | 595 | $post_id_list[] = $item->ID; |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | - if( empty($post_id_list) ) { |
|
| 599 | + if (empty($post_id_list)) { |
|
| 600 | 600 | $post_id_list[] = 'no_result'; |
| 601 | 601 | } |
| 602 | 602 | $query->query_vars[$check] = $post_id_list; |
@@ -607,66 +607,66 @@ discard block |
||
| 607 | 607 | |
| 608 | 608 | |
| 609 | 609 | |
| 610 | - function latest_products_ordered ( $orders ) { |
|
| 610 | + function latest_products_ordered($orders) { |
|
| 611 | 611 | global $wpdb; |
| 612 | 612 | $product_id = $output = ''; |
| 613 | 613 | $products = array(); |
| 614 | 614 | $display_option = get_option('wpshop_display_option'); |
| 615 | - if ( !empty($orders) && !empty($display_option) && !empty($display_option['latest_products_ordered']) ) { |
|
| 616 | - foreach( $orders as $order ) { |
|
| 617 | - $order_content = get_post_meta( $order->ID, '_order_postmeta', true ); |
|
| 618 | - if ( !empty($order_content) && !empty( $order_content['order_items']) ) { |
|
| 615 | + if (!empty($orders) && !empty($display_option) && !empty($display_option['latest_products_ordered'])) { |
|
| 616 | + foreach ($orders as $order) { |
|
| 617 | + $order_content = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 618 | + if (!empty($order_content) && !empty($order_content['order_items'])) { |
|
| 619 | 619 | |
| 620 | - foreach( $order_content['order_items'] as $item ) { |
|
| 621 | - if ( count( $products) >= $display_option['latest_products_ordered'] ) { |
|
| 620 | + foreach ($order_content['order_items'] as $item) { |
|
| 621 | + if (count($products) >= $display_option['latest_products_ordered']) { |
|
| 622 | 622 | continue; |
| 623 | 623 | } |
| 624 | 624 | $product_id = $item['item_id']; |
| 625 | - if ( !empty( $item) && !empty($item['item_meta']) && !empty($item['item_meta']['variation_definition']) ) { |
|
| 626 | - $parent_def = wpshop_products::get_parent_variation( $item['item_id'] ); |
|
| 627 | - if ( !empty( $parent_def ) ) { |
|
| 625 | + if (!empty($item) && !empty($item['item_meta']) && !empty($item['item_meta']['variation_definition'])) { |
|
| 626 | + $parent_def = wpshop_products::get_parent_variation($item['item_id']); |
|
| 627 | + if (!empty($parent_def)) { |
|
| 628 | 628 | $parent_post = $parent_def['parent_post']; |
| 629 | 629 | $product_id = $parent_post->ID; |
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - if ( !in_array($product_id, $products) ) { |
|
| 633 | + if (!in_array($product_id, $products)) { |
|
| 634 | 634 | $products[] = $product_id; |
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | - if ( !empty($products) ) { |
|
| 639 | + if (!empty($products)) { |
|
| 640 | 640 | $products_id = implode(",", $products); |
| 641 | - $output = wpshop_display::display_template_element('latest_products_ordered', array('LATEST_PRODUCTS_ORDERED' => do_shortcode('[wpshop_products pid="' .$products_id. '"]')) ); |
|
| 641 | + $output = wpshop_display::display_template_element('latest_products_ordered', array('LATEST_PRODUCTS_ORDERED' => do_shortcode('[wpshop_products pid="' . $products_id . '"]'))); |
|
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | return $output; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - function get_order_list_for_customer( $customer_id ) { |
|
| 647 | + function get_order_list_for_customer($customer_id) { |
|
| 648 | 648 | global $wpdb; |
| 649 | 649 | $output = ''; |
| 650 | 650 | |
| 651 | - if( !empty($customer_id) ) { |
|
| 652 | - $query = $wpdb->prepare( 'SELECT * |
|
| 653 | - FROM ' .$wpdb->posts. ' |
|
| 651 | + if (!empty($customer_id)) { |
|
| 652 | + $query = $wpdb->prepare('SELECT * |
|
| 653 | + FROM ' .$wpdb->posts . ' |
|
| 654 | 654 | WHERE post_author = %d |
| 655 | - AND post_type = %s', $customer_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 656 | - $orders = $wpdb->get_results( $query ); |
|
| 655 | + AND post_type = %s', $customer_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 656 | + $orders = $wpdb->get_results($query); |
|
| 657 | 657 | |
| 658 | - foreach( $orders as $order ) { |
|
| 658 | + foreach ($orders as $order) { |
|
| 659 | 659 | |
| 660 | 660 | } |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | return $output; |
| 664 | 664 | } |
| 665 | - static function display_customer_pay_quotation( $state, $oid ) { |
|
| 666 | - $btn = '<p><a role="button" data-nonce="' . wp_create_nonce( 'wps_quotation_is_payable_by_customer' ) . '" class="wps-bton-' . ( ( $state ) ? 'third' : 'second' ) . '-mini-rounded quotation_is_payable_by_customer" href="#" >'.__('Valid quotation', 'wpshop').'</a></p>'; |
|
| 667 | - if( $state ) { |
|
| 665 | + static function display_customer_pay_quotation($state, $oid) { |
|
| 666 | + $btn = '<p><a role="button" data-nonce="' . wp_create_nonce('wps_quotation_is_payable_by_customer') . '" class="wps-bton-' . (($state) ? 'third' : 'second') . '-mini-rounded quotation_is_payable_by_customer" href="#" >' . __('Valid quotation', 'wpshop') . '</a></p>'; |
|
| 667 | + if ($state) { |
|
| 668 | 668 | //$btn .= '<a target="_blank" href="' . admin_url( 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $oid . '&is_link=link' ) . '">' . __( 'Pay link', 'wpshop' ) . '</a>'; |
| 669 | - $btn .= '<span><input id="wps_direct_link_url" type="text" value="' . wpshop_checkout::wps_direct_payment_link_url( $oid ) . '"/><a class="button" data-copy-target="#wps_direct_link_url" title="' . __( 'Copy', 'wpshop' ) . '"><span class="dashicons dashicons-clipboard"></span></a><a data-nonce="' . wp_create_nonce( 'wps_send_direct_payment_link' ) . '" role="button" class="button" href="#" title="' . __( 'Send by mail', 'wpshop' ) . '"><span class="dashicons dashicons-email"></span></a></span><span>' . sprintf( __( 'Link is valid until %s', 'wpshop' ), mysql2date( get_option( 'date_format' ), date_format( date_create( date('Y-m') . ' + 2month - 1day' ), 'Y-m-d H:i:s' ), true ) ) . '</span>'; |
|
| 669 | + $btn .= '<span><input id="wps_direct_link_url" type="text" value="' . wpshop_checkout::wps_direct_payment_link_url($oid) . '"/><a class="button" data-copy-target="#wps_direct_link_url" title="' . __('Copy', 'wpshop') . '"><span class="dashicons dashicons-clipboard"></span></a><a data-nonce="' . wp_create_nonce('wps_send_direct_payment_link') . '" role="button" class="button" href="#" title="' . __('Send by mail', 'wpshop') . '"><span class="dashicons dashicons-email"></span></a></span><span>' . sprintf(__('Link is valid until %s', 'wpshop'), mysql2date(get_option('date_format'), date_format(date_create(date('Y-m') . ' + 2month - 1day'), 'Y-m-d H:i:s'), true)) . '</span>'; |
|
| 670 | 670 | } |
| 671 | 671 | return $btn; |
| 672 | 672 | } |
@@ -1,26 +1,26 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_orders_in_back_office { |
| 3 | 3 | |
| 4 | 4 | function __construct() { |
| 5 | 5 | // Template loading |
| 6 | 6 | $this->template_dir = WPS_ORDERS_PATH . WPS_ORDERS_DIR . "/templates/"; |
| 7 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes') ); |
|
| 7 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
| 8 | 8 | |
| 9 | 9 | // Ajax actions |
| 10 | - add_action('wp_ajax_wpshop_add_private_comment_to_order', array( $this, 'wpshop_add_private_comment_to_order' ) ); |
|
| 11 | - add_action('wp_ajax_wps_order_refresh_product_listing', array( $this, 'refresh_product_list' ) ); |
|
| 12 | - add_action('wp_ajax_wps_add_product_to_order_admin', array( $this, 'wps_add_product_to_order_admin' ) ); |
|
| 13 | - add_action('wp_ajax_wps_refresh_cart_order', array( $this, 'refresh_cart_order' ) ); |
|
| 14 | - add_action('wp_ajax_wps_refresh_payments_order', array( $this, 'refresh_payments_order' ) ); |
|
| 15 | - add_action('wp_ajax_wps_update_product_qty_in_admin', array( $this, 'wps_update_product_qty_in_admin' ) ); |
|
| 16 | - add_action('wp_ajax_wps_order_load_product_variations', array( $this, 'wps_order_load_product_variations' ) ); |
|
| 17 | - add_action('wp_ajax_wps-orders-update-cart-informations', array( $this, 'wps_orders_update_cart_informations' ) ); |
|
| 18 | - add_action('wp_ajax_wps_reverify_payment_invoice_ref', array( $this, 'wps_reverify_payment_invoice_ref' ) ); |
|
| 10 | + add_action('wp_ajax_wpshop_add_private_comment_to_order', array($this, 'wpshop_add_private_comment_to_order')); |
|
| 11 | + add_action('wp_ajax_wps_order_refresh_product_listing', array($this, 'refresh_product_list')); |
|
| 12 | + add_action('wp_ajax_wps_add_product_to_order_admin', array($this, 'wps_add_product_to_order_admin')); |
|
| 13 | + add_action('wp_ajax_wps_refresh_cart_order', array($this, 'refresh_cart_order')); |
|
| 14 | + add_action('wp_ajax_wps_refresh_payments_order', array($this, 'refresh_payments_order')); |
|
| 15 | + add_action('wp_ajax_wps_update_product_qty_in_admin', array($this, 'wps_update_product_qty_in_admin')); |
|
| 16 | + add_action('wp_ajax_wps_order_load_product_variations', array($this, 'wps_order_load_product_variations')); |
|
| 17 | + add_action('wp_ajax_wps-orders-update-cart-informations', array($this, 'wps_orders_update_cart_informations')); |
|
| 18 | + add_action('wp_ajax_wps_reverify_payment_invoice_ref', array($this, 'wps_reverify_payment_invoice_ref')); |
|
| 19 | 19 | |
| 20 | 20 | // WP General actions |
| 21 | - add_action( 'admin_enqueue_scripts', array( $this, 'wps_orders_scripts') ); |
|
| 22 | - add_action( 'admin_enqueue_scripts', array( $this, 'wps_orders_scripts_texts' ), 20 ); |
|
| 23 | - add_action('save_post', array( $this, 'save_order_custom_informations')); |
|
| 21 | + add_action('admin_enqueue_scripts', array($this, 'wps_orders_scripts')); |
|
| 22 | + add_action('admin_enqueue_scripts', array($this, 'wps_orders_scripts_texts'), 20); |
|
| 23 | + add_action('save_post', array($this, 'save_order_custom_informations')); |
|
| 24 | 24 | |
| 25 | 25 | // WP Filters |
| 26 | 26 | //add_filter( 'wps_order_saving_admin_extra_action', array( $this, 'wps_notif_user_on_order_saving'), 100, 2 ); |
@@ -31,51 +31,51 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function wps_orders_scripts() { |
| 33 | 33 | global $current_screen; |
| 34 | - if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) ) |
|
| 34 | + if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER), true)) |
|
| 35 | 35 | return; |
| 36 | 36 | |
| 37 | - wp_enqueue_script( 'wps_orders_backend', WPS_ORDERS_URL.WPS_ORDERS_DIR.'/assets/backend/js/wps_orders.js' ); |
|
| 37 | + wp_enqueue_script('wps_orders_backend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/backend/js/wps_orders.js'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | function wps_orders_scripts_texts() { |
| 41 | - wp_localize_script( 'wps_orders_backend', 'message_confirm_reload', __( 'Are you sure you want to refresh your browser?', 'wpshop' ) ); |
|
| 42 | - wp_localize_script( 'wps_orders_backend', 'message_error_reverify_payment_invoice_ref', __( 'Error detected.', 'wpshop' ) ); |
|
| 41 | + wp_localize_script('wps_orders_backend', 'message_confirm_reload', __('Are you sure you want to refresh your browser?', 'wpshop')); |
|
| 42 | + wp_localize_script('wps_orders_backend', 'message_error_reverify_payment_invoice_ref', __('Error detected.', 'wpshop')); |
|
| 43 | 43 | } |
| 44 | 44 | /** |
| 45 | 45 | * Add meta boxes |
| 46 | 46 | */ |
| 47 | 47 | function add_meta_boxes() { |
| 48 | 48 | global $post; |
| 49 | - $order_meta = get_post_meta( $post->ID, '_order_postmeta', true ); |
|
| 49 | + $order_meta = get_post_meta($post->ID, '_order_postmeta', true); |
|
| 50 | 50 | /** Box Order Payments **/ |
| 51 | - if( !in_array( $post->post_status, array( 'auto-draft' ) ) ) { |
|
| 52 | - add_meta_box('wpshop_order_payment', '<span class="dashicons dashicons-money"></span> '.__('Order payment', 'wpshop'),array($this, 'display_order_payments_box'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
| 51 | + if (!in_array($post->post_status, array('auto-draft'))) { |
|
| 52 | + add_meta_box('wpshop_order_payment', '<span class="dashicons dashicons-money"></span> ' . __('Order payment', 'wpshop'), array($this, 'display_order_payments_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
| 53 | 53 | } |
| 54 | 54 | /** Box for customer order comment */ |
| 55 | - if ( ! empty( $post->post_excerpt ) ) { |
|
| 56 | - add_meta_box('wpshop_order_customer_comment', '<span class="dashicons dashicons-format-status"></span> '.__('Order customer comment', 'wpshop'),array( $this, 'order_customer_comment_box'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
| 55 | + if (!empty($post->post_excerpt)) { |
|
| 56 | + add_meta_box('wpshop_order_customer_comment', '<span class="dashicons dashicons-format-status"></span> ' . __('Order customer comment', 'wpshop'), array($this, 'order_customer_comment_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
| 57 | 57 | } |
| 58 | 58 | /** Historic sales **/ |
| 59 | - add_meta_box('wpshop_product_order_historic', __('Sales informations', 'wpshop'), array( $this, 'meta_box_product_sale_informations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low'); |
|
| 59 | + add_meta_box('wpshop_product_order_historic', __('Sales informations', 'wpshop'), array($this, 'meta_box_product_sale_informations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low'); |
|
| 60 | 60 | /** Box with the complete order content */ |
| 61 | 61 | $payment_started = false; |
| 62 | - if ( ! empty( $order_meta['order_payment'] ) && ! empty( $order_meta['order_payment']['received'] ) ) { |
|
| 63 | - foreach ( $order_meta['order_payment']['received'] as $received ) { |
|
| 64 | - if ( empty( $received['received_amount'] ) ) { |
|
| 62 | + if (!empty($order_meta['order_payment']) && !empty($order_meta['order_payment']['received'])) { |
|
| 63 | + foreach ($order_meta['order_payment']['received'] as $received) { |
|
| 64 | + if (empty($received['received_amount'])) { |
|
| 65 | 65 | continue; |
| 66 | 66 | } |
| 67 | 67 | $payment_started = true; |
| 68 | 68 | break; |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | - if ( ! $payment_started ) { |
|
| 72 | - add_meta_box( 'wpshop_product_list', '<span class="dashicons dashicons-archive"></span> ' . __( 'Product List', 'wpshop' ), array( $this, 'wps_products_listing_for_quotation' ), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low' ); |
|
| 71 | + if (!$payment_started) { |
|
| 72 | + add_meta_box('wpshop_product_list', '<span class="dashicons dashicons-archive"></span> ' . __('Product List', 'wpshop'), array($this, 'wps_products_listing_for_quotation'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
| 73 | 73 | } |
| 74 | 74 | /** Box with the complete order content */ |
| 75 | - add_meta_box( 'wpshop_order_content', '<span class="dashicons dashicons-cart"></span> '.__('Order content', 'wpshop'), array( $this, 'meta_box_order_content'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
| 75 | + add_meta_box('wpshop_order_content', '<span class="dashicons dashicons-cart"></span> ' . __('Order content', 'wpshop'), array($this, 'meta_box_order_content'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
| 76 | 76 | /** Box Private order comments **/ |
| 77 | - if( !in_array( $post->post_status, array( 'auto-draft' ) ) ) { |
|
| 78 | - add_meta_box('wpshop_order_private_comments', '<span class="dashicons dashicons-format-chat"></span> '.__('Comments', 'wpshop'), array( $this, 'meta_box_private_comment'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
| 77 | + if (!in_array($post->post_status, array('auto-draft'))) { |
|
| 78 | + add_meta_box('wpshop_order_private_comments', '<span class="dashicons dashicons-format-chat"></span> ' . __('Comments', 'wpshop'), array($this, 'meta_box_private_comment'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -83,65 +83,65 @@ discard block |
||
| 83 | 83 | * METABOX CONTENT - Display Customer comments on order in administration panel |
| 84 | 84 | * @param object $order |
| 85 | 85 | */ |
| 86 | - function order_customer_comment_box( $order ) { |
|
| 87 | - if ( !empty($order) && !empty($order->ID) ) { |
|
| 88 | - require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "customer_comment_on_order_box") ); |
|
| 86 | + function order_customer_comment_box($order) { |
|
| 87 | + if (!empty($order) && !empty($order->ID)) { |
|
| 88 | + require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "customer_comment_on_order_box")); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * METABOX CONTENT - Display an order historic of product in administration product panel |
| 94 | 94 | */ |
| 95 | - function meta_box_product_sale_informations () { |
|
| 95 | + function meta_box_product_sale_informations() { |
|
| 96 | 96 | global $post; |
| 97 | 97 | $product_id = $post->ID; |
| 98 | - $variations = wpshop_products::get_variation( $product_id ); |
|
| 99 | - $order_status = unserialize( WPSHOP_ORDER_STATUS ); |
|
| 100 | - $color_label = array( 'awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge', 'pos' => 'bleu'); |
|
| 98 | + $variations = wpshop_products::get_variation($product_id); |
|
| 99 | + $order_status = unserialize(WPSHOP_ORDER_STATUS); |
|
| 100 | + $color_label = array('awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge', 'pos' => 'bleu'); |
|
| 101 | 101 | // Get datas |
| 102 | 102 | $sales_informations = array(); |
| 103 | 103 | /** Query **/ |
| 104 | - $data_to_compare = '"item_id";s:' .strlen($product_id). ':"' .$product_id. '";'; |
|
| 105 | - $query_args = array( 'posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array( array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE') ) ); |
|
| 106 | - $orders = new WP_Query( $query_args ); |
|
| 107 | - if ( !empty($orders) && !empty($orders->posts) ) { |
|
| 108 | - foreach( $orders->posts as $order ) { |
|
| 109 | - $order_meta = get_post_meta( $order->ID, '_order_postmeta', true ); |
|
| 110 | - $order_info = get_post_meta( $order->ID, '_order_info', true ); |
|
| 104 | + $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 105 | + $query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE'))); |
|
| 106 | + $orders = new WP_Query($query_args); |
|
| 107 | + if (!empty($orders) && !empty($orders->posts)) { |
|
| 108 | + foreach ($orders->posts as $order) { |
|
| 109 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 110 | + $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 111 | 111 | $sales_informations[] = array( |
| 112 | - 'order_key' => ( !empty($order_meta) && !empty($order_meta['order_key']) ) ? $order_meta['order_key'] : '', |
|
| 113 | - 'order_date' => ( !empty($order_meta) && !empty($order_meta['order_date']) ) ? $order_meta['order_date'] : '', |
|
| 114 | - 'customer_firstname' => ( !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name']) ) ? $order_info['billing']['address']['address_first_name'] : '', |
|
| 115 | - 'customer_name' => ( !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name']) ) ? $order_info['billing']['address']['address_last_name'] : '', |
|
| 116 | - 'customer_email' => ( !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email']) ) ? $order_info['billing']['address']['address_user_email'] : '', |
|
| 112 | + 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 113 | + 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 114 | + 'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '', |
|
| 115 | + 'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '', |
|
| 116 | + 'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '', |
|
| 117 | 117 | 'order_id' => $order->ID, |
| 118 | 118 | 'order_status' => $order_meta['order_status'] |
| 119 | 119 | ); |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | // Display results |
| 123 | - require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product_order_historic") ); |
|
| 123 | + require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product_order_historic")); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * METABOX CONTENT - Payments Box in Orders panel |
| 128 | 128 | * @param string $order |
| 129 | 129 | */ |
| 130 | - function display_order_payments_box( $order ) { |
|
| 130 | + function display_order_payments_box($order) { |
|
| 131 | 131 | $order_status = unserialize(WPSHOP_ORDER_STATUS); |
| 132 | 132 | $order_postmeta = get_post_meta($order->ID, '_order_postmeta', true); |
| 133 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "wps_order_payment_box") ); |
|
| 133 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "wps_order_payment_box")); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * METABOX CONTENT - Display an lsiting of products to make quotation in backend |
| 138 | 138 | */ |
| 139 | 139 | function wps_products_listing_for_quotation($post) { |
| 140 | - $letters = array( 'ALL', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); |
|
| 141 | - $current_letter = sanitize_title( $letters[1] ); |
|
| 140 | + $letters = array('ALL', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); |
|
| 141 | + $current_letter = sanitize_title($letters[1]); |
|
| 142 | 142 | $wps_product_mdl = new wps_product_mdl(); |
| 143 | - $products = $wps_product_mdl->get_products_by_letter( $current_letter ); |
|
| 144 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing") ); |
|
| 143 | + $products = $wps_product_mdl->get_products_by_letter($current_letter); |
|
| 144 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing")); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | function meta_box_private_comment() { |
| 151 | 151 | global $post; |
| 152 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_private_comments") ); |
|
| 152 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_private_comments")); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function meta_box_order_content() { |
| 159 | 159 | global $post_id; |
| 160 | - unset( $_SESSION['cart'] ); |
|
| 161 | - echo do_shortcode( '[wps_cart oid="' .$post_id. '" cart_type="admin-panel"]'); |
|
| 160 | + unset($_SESSION['cart']); |
|
| 161 | + echo do_shortcode('[wps_cart oid="' . $post_id . '" cart_type="admin-panel"]'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -168,68 +168,68 @@ discard block |
||
| 168 | 168 | function save_order_custom_informations() { |
| 169 | 169 | global $wpdb; |
| 170 | 170 | |
| 171 | - $post_ID = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0; |
|
| 171 | + $post_ID = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0; |
|
| 172 | 172 | // Check if it is an order save action |
| 173 | - if ( !empty($post_ID) && ( get_post_type($post_ID) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) ) { |
|
| 173 | + if (!empty($post_ID) && (get_post_type($post_ID) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER)) { |
|
| 174 | 174 | //Define Customer ID |
| 175 | - $user_id = ( !empty( $_REQUEST['wps_customer_id'] ) ) ? (int) $_REQUEST['wps_customer_id'] : get_current_user_id(); |
|
| 175 | + $user_id = (!empty($_REQUEST['wps_customer_id'])) ? (int)$_REQUEST['wps_customer_id'] : get_current_user_id(); |
|
| 176 | 176 | |
| 177 | 177 | // Order MetaData |
| 178 | - $order_meta = get_post_meta( $post_ID, '_order_postmeta', true); |
|
| 178 | + $order_meta = get_post_meta($post_ID, '_order_postmeta', true); |
|
| 179 | 179 | |
| 180 | 180 | // Save General information of order's attached customer |
| 181 | - $wpdb->update( $wpdb->posts, array('post_author' => $user_id, 'post_parent' => $user_id, 'post_status' => 'publish'), array('ID' => $post_ID) ); |
|
| 182 | - update_post_meta( $post_ID, '_wpshop_order_customer_id', $user_id ); |
|
| 181 | + $wpdb->update($wpdb->posts, array('post_author' => $user_id, 'post_parent' => $user_id, 'post_status' => 'publish'), array('ID' => $post_ID)); |
|
| 182 | + update_post_meta($post_ID, '_wpshop_order_customer_id', $user_id); |
|
| 183 | 183 | $order_meta['customer_id'] = $user_id; |
| 184 | - if ( empty($order_meta['order_key']) ) { |
|
| 185 | - $order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && ($order_meta['order_status']!='awaiting_payment') ? wpshop_orders::get_new_order_reference() : ''); |
|
| 184 | + if (empty($order_meta['order_key'])) { |
|
| 185 | + $order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && ($order_meta['order_status'] != 'awaiting_payment') ? wpshop_orders::get_new_order_reference() : ''); |
|
| 186 | 186 | $order_meta['order_temporary_key'] = (isset($order_meta['order_temporary_key']) && ($order_meta['order_temporary_key'] != '')) ? $order_meta['order_temporary_key'] : wpshop_orders::get_new_pre_order_reference(); |
| 187 | 187 | } |
| 188 | 188 | $order_meta['order_status'] = (isset($order_meta['order_status']) && ($order_meta['order_status'] != '')) ? $order_meta['order_status'] : 'awaiting_payment'; |
| 189 | 189 | $order_meta['order_date'] = (isset($order_meta['order_date']) && ($order_meta['order_date'] != '')) ? $order_meta['order_date'] : current_time('mysql', 0); |
| 190 | 190 | $order_meta['order_currency'] = wpshop_tools::wpshop_get_currency(true); |
| 191 | 191 | |
| 192 | - $billing_adress_id = ( !empty( $_REQUEST['wps_order_selected_address'] ) && !empty( $_REQUEST['wps_order_selected_address']['billing'] ) ) ? (int) $_REQUEST['wps_order_selected_address']['billing'] : 0; |
|
| 192 | + $billing_adress_id = (!empty($_REQUEST['wps_order_selected_address']) && !empty($_REQUEST['wps_order_selected_address']['billing'])) ? (int)$_REQUEST['wps_order_selected_address']['billing'] : 0; |
|
| 193 | 193 | |
| 194 | 194 | // Order Attached Addresses save |
| 195 | - if( !empty( $billing_adress_id ) ) { |
|
| 195 | + if (!empty($billing_adress_id)) { |
|
| 196 | 196 | // Informations |
| 197 | - $order_informations = get_post_meta( $post_ID, '_order_info', true ); |
|
| 198 | - $order_informations = ( !empty($order_informations) ) ? $order_informations : array(); |
|
| 199 | - $billing_address_option = get_option( 'wpshop_billing_address' ); |
|
| 200 | - $billing_address_option = ( !empty($billing_address_option) && !empty( $billing_address_option['choice'] ) ) ? $billing_address_option['choice'] : ''; |
|
| 197 | + $order_informations = get_post_meta($post_ID, '_order_info', true); |
|
| 198 | + $order_informations = (!empty($order_informations)) ? $order_informations : array(); |
|
| 199 | + $billing_address_option = get_option('wpshop_billing_address'); |
|
| 200 | + $billing_address_option = (!empty($billing_address_option) && !empty($billing_address_option['choice'])) ? $billing_address_option['choice'] : ''; |
|
| 201 | 201 | |
| 202 | 202 | // Billing datas |
| 203 | - $order_informations['billing'] = array( 'id' => $billing_address_option, |
|
| 203 | + $order_informations['billing'] = array('id' => $billing_address_option, |
|
| 204 | 204 | 'address_id' => $billing_adress_id, |
| 205 | - 'address' => get_post_meta( $billing_adress_id, '_wpshop_address_metadata', true ) |
|
| 205 | + 'address' => get_post_meta($billing_adress_id, '_wpshop_address_metadata', true) |
|
| 206 | 206 | ); |
| 207 | 207 | // Shipping datas |
| 208 | - $shipping_adress_id = ( !empty( $_REQUEST['wps_order_selected_address'] ) && !empty( $_REQUEST['wps_order_selected_address']['shipping'] ) ) ? (int) $_REQUEST['wps_order_selected_address']['shipping'] : 0; |
|
| 208 | + $shipping_adress_id = (!empty($_REQUEST['wps_order_selected_address']) && !empty($_REQUEST['wps_order_selected_address']['shipping'])) ? (int)$_REQUEST['wps_order_selected_address']['shipping'] : 0; |
|
| 209 | 209 | |
| 210 | - if( !empty( $shipping_adress_id ) ) { |
|
| 211 | - $shipping_address_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 212 | - $shipping_address_option = ( !empty($shipping_address_option) && !empty($shipping_address_option['choice']) ) ? $shipping_address_option['choice'] : ''; |
|
| 213 | - $order_informations['shipping'] = array( 'id' => $shipping_address_option, |
|
| 210 | + if (!empty($shipping_adress_id)) { |
|
| 211 | + $shipping_address_option = get_option('wpshop_shipping_address_choice'); |
|
| 212 | + $shipping_address_option = (!empty($shipping_address_option) && !empty($shipping_address_option['choice'])) ? $shipping_address_option['choice'] : ''; |
|
| 213 | + $order_informations['shipping'] = array('id' => $shipping_address_option, |
|
| 214 | 214 | 'address_id' => $shipping_adress_id, |
| 215 | - 'address' => get_post_meta( $shipping_adress_id, '_wpshop_address_metadata', true ) |
|
| 215 | + 'address' => get_post_meta($shipping_adress_id, '_wpshop_address_metadata', true) |
|
| 216 | 216 | ); |
| 217 | 217 | } |
| 218 | - update_post_meta( $post_ID, '_order_info', $order_informations ); |
|
| 218 | + update_post_meta($post_ID, '_order_info', $order_informations); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $wpshop_admin_order_payment_received = !empty( $_REQUEST['wpshop_admin_order_payment_received'] ) ? (array)$_REQUEST['wpshop_admin_order_payment_received'] : array(); |
|
| 222 | - $wpshop_admin_order_payment_received['method'] = !empty( $wpshop_admin_order_payment_received['method'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['method'] ) : ''; |
|
| 223 | - $wpshop_admin_order_payment_received['payment_reference'] = !empty( $wpshop_admin_order_payment_received['payment_reference'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['payment_reference'] ) : ''; |
|
| 224 | - $wpshop_admin_order_payment_received['date'] = !empty( $wpshop_admin_order_payment_received['date'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['date'] ) : ''; |
|
| 225 | - $wpshop_admin_order_payment_received['received_amount'] = !empty( $wpshop_admin_order_payment_received['received_amount'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['received_amount'] ) : ''; |
|
| 226 | - $action_triggered_from = !empty( $_REQUEST['action_triggered_from'] ) ? sanitize_text_field( $_REQUEST['action_triggered_from'] ) : ''; |
|
| 227 | - $wshop_admin_order_payment_reference = !empty( $_REQUEST['wpshop_admin_order_payment_reference'] ) ? sanitize_text_field( $_REQUEST['wpshop_admin_order_payment_reference'] ) : ''; |
|
| 221 | + $wpshop_admin_order_payment_received = !empty($_REQUEST['wpshop_admin_order_payment_received']) ? (array)$_REQUEST['wpshop_admin_order_payment_received'] : array(); |
|
| 222 | + $wpshop_admin_order_payment_received['method'] = !empty($wpshop_admin_order_payment_received['method']) ? sanitize_text_field($wpshop_admin_order_payment_received['method']) : ''; |
|
| 223 | + $wpshop_admin_order_payment_received['payment_reference'] = !empty($wpshop_admin_order_payment_received['payment_reference']) ? sanitize_text_field($wpshop_admin_order_payment_received['payment_reference']) : ''; |
|
| 224 | + $wpshop_admin_order_payment_received['date'] = !empty($wpshop_admin_order_payment_received['date']) ? sanitize_text_field($wpshop_admin_order_payment_received['date']) : ''; |
|
| 225 | + $wpshop_admin_order_payment_received['received_amount'] = !empty($wpshop_admin_order_payment_received['received_amount']) ? sanitize_text_field($wpshop_admin_order_payment_received['received_amount']) : ''; |
|
| 226 | + $action_triggered_from = !empty($_REQUEST['action_triggered_from']) ? sanitize_text_field($_REQUEST['action_triggered_from']) : ''; |
|
| 227 | + $wshop_admin_order_payment_reference = !empty($_REQUEST['wpshop_admin_order_payment_reference']) ? sanitize_text_field($_REQUEST['wpshop_admin_order_payment_reference']) : ''; |
|
| 228 | 228 | |
| 229 | 229 | // Add a Payment to Order MetaData |
| 230 | - if ( !empty($wpshop_admin_order_payment_received) && !empty($wpshop_admin_order_payment_received['method']) |
|
| 230 | + if (!empty($wpshop_admin_order_payment_received) && !empty($wpshop_admin_order_payment_received['method']) |
|
| 231 | 231 | && !empty($wpshop_admin_order_payment_received['date']) && !empty($wpshop_admin_order_payment_received['received_amount']) && |
| 232 | - ( $action_triggered_from == 'add_payment' || !empty($wshop_admin_order_payment_reference) ) ) { |
|
| 232 | + ($action_triggered_from == 'add_payment' || !empty($wshop_admin_order_payment_reference))) { |
|
| 233 | 233 | |
| 234 | 234 | $received_payment_amount = $wpshop_admin_order_payment_received['received_amount']; |
| 235 | 235 | // Payment Params |
@@ -242,36 +242,36 @@ discard block |
||
| 242 | 242 | 'date' => current_time('mysql', 0), |
| 243 | 243 | 'received_amount' => $received_payment_amount |
| 244 | 244 | ); |
| 245 | - $order_meta = wpshop_payment::check_order_payment_total_amount($post_ID, $params_array, 'completed', $order_meta, false ); |
|
| 245 | + $order_meta = wpshop_payment::check_order_payment_total_amount($post_ID, $params_array, 'completed', $order_meta, false); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | //Round final amount |
| 249 | - $order_meta['order_grand_total'] = number_format( round($order_meta['order_grand_total'], 2), 2, '.', ''); |
|
| 250 | - $order_meta['order_total_ttc'] = number_format( round($order_meta['order_total_ttc'], 2), 2, '.', ''); |
|
| 251 | - $order_meta['order_amount_to_pay_now'] = number_format( round($order_meta['order_amount_to_pay_now'], 2), 2, '.', ''); |
|
| 249 | + $order_meta['order_grand_total'] = number_format(round($order_meta['order_grand_total'], 2), 2, '.', ''); |
|
| 250 | + $order_meta['order_total_ttc'] = number_format(round($order_meta['order_total_ttc'], 2), 2, '.', ''); |
|
| 251 | + $order_meta['order_amount_to_pay_now'] = number_format(round($order_meta['order_amount_to_pay_now'], 2), 2, '.', ''); |
|
| 252 | 252 | |
| 253 | 253 | // Payment Pre-Fill |
| 254 | - if ( empty( $order_meta['order_payment'] ) ) { |
|
| 254 | + if (empty($order_meta['order_payment'])) { |
|
| 255 | 255 | $order_meta['order_payment']['customer_choice']['method'] = ''; |
| 256 | - $order_meta['order_payment']['received'][] = array('waited_amount' => ( !empty($order_meta) && !empty($order_meta['order_grand_total']) ) ? number_format($order_meta['order_grand_total'],2,'.', '') : 0 ); |
|
| 256 | + $order_meta['order_payment']['received'][] = array('waited_amount' => (!empty($order_meta) && !empty($order_meta['order_grand_total'])) ? number_format($order_meta['order_grand_total'], 2, '.', '') : 0); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $data['post_ID'] = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0; |
|
| 260 | - $data['markascanceled_order_hidden_indicator'] = !empty( $_REQUEST['markascanceled_order_hidden_indicator' ] ) ? sanitize_text_field( $_REQUEST['markascanceled_order_hidden_indicator'] ) : ''; |
|
| 261 | - $data['resendordertocustomer_order_hidden_indicator'] = !empty( $_REQUEST['resendordertocustomer_order_hidden_indicator' ] ) ? sanitize_text_field( $_REQUEST['resendordertocustomer_order_hidden_indicator'] ) : ''; |
|
| 262 | - $data['action_triggered_from'] = !empty( $_REQUEST['action_triggered_from' ] ) ? sanitize_text_field( $_REQUEST['action_triggered_from'] ) : ''; |
|
| 263 | - $data['notif_the_customer'] = !empty( $_REQUEST['notif_the_customer' ] ) ? sanitize_text_field( $_REQUEST['notif_the_customer'] ) : ''; |
|
| 259 | + $data['post_ID'] = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0; |
|
| 260 | + $data['markascanceled_order_hidden_indicator'] = !empty($_REQUEST['markascanceled_order_hidden_indicator']) ? sanitize_text_field($_REQUEST['markascanceled_order_hidden_indicator']) : ''; |
|
| 261 | + $data['resendordertocustomer_order_hidden_indicator'] = !empty($_REQUEST['resendordertocustomer_order_hidden_indicator']) ? sanitize_text_field($_REQUEST['resendordertocustomer_order_hidden_indicator']) : ''; |
|
| 262 | + $data['action_triggered_from'] = !empty($_REQUEST['action_triggered_from']) ? sanitize_text_field($_REQUEST['action_triggered_from']) : ''; |
|
| 263 | + $data['notif_the_customer'] = !empty($_REQUEST['notif_the_customer']) ? sanitize_text_field($_REQUEST['notif_the_customer']) : ''; |
|
| 264 | 264 | // Apply a filter to make credit, notificate the customer and generate billing actions |
| 265 | - $order_meta = apply_filters( 'wps_order_saving_admin_extra_action', $order_meta, $data ); |
|
| 265 | + $order_meta = apply_filters('wps_order_saving_admin_extra_action', $order_meta, $data); |
|
| 266 | 266 | |
| 267 | 267 | // Save Shipping informations & Order status |
| 268 | - if ( isset( $order_meta['order_shipping_date'] ) ) { |
|
| 269 | - update_post_meta( $post_ID, '_wpshop_order_shipping_date', $order_meta['order_shipping_date']); |
|
| 268 | + if (isset($order_meta['order_shipping_date'])) { |
|
| 269 | + update_post_meta($post_ID, '_wpshop_order_shipping_date', $order_meta['order_shipping_date']); |
|
| 270 | 270 | } |
| 271 | - update_post_meta( $post_ID, '_wpshop_order_status', $order_meta['order_status']); |
|
| 271 | + update_post_meta($post_ID, '_wpshop_order_status', $order_meta['order_status']); |
|
| 272 | 272 | |
| 273 | 273 | // Save Metadata |
| 274 | - update_post_meta( $post_ID, '_order_postmeta', $order_meta); |
|
| 274 | + update_post_meta($post_ID, '_order_postmeta', $order_meta); |
|
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | * @param array $posted_datas |
| 283 | 283 | * @return array |
| 284 | 284 | */ |
| 285 | - function wps_notif_user_on_order_saving( $order_metadata, $posted_datas ) { |
|
| 286 | - if( !empty($posted_datas['notif_the_customer']) && $posted_datas['notif_the_customer']=='on' ) { |
|
| 285 | + function wps_notif_user_on_order_saving($order_metadata, $posted_datas) { |
|
| 286 | + if (!empty($posted_datas['notif_the_customer']) && $posted_datas['notif_the_customer'] == 'on') { |
|
| 287 | 287 | $wps_message = new wps_message_ctr(); |
| 288 | 288 | /* Get order current content */ |
| 289 | 289 | $user = get_post_meta($posted_datas['post_ID'], '_order_info', true); |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | $first_name = $user['billing']['address']['address_first_name']; |
| 293 | 293 | $last_name = $user['billing']['address']['address_last_name']; |
| 294 | 294 | |
| 295 | - $object = array('object_type'=>'order','object_id'=>(int)$_REQUEST['post_ID']); |
|
| 295 | + $object = array('object_type'=>'order', 'object_id'=>(int)$_REQUEST['post_ID']); |
|
| 296 | 296 | /* Envoie du message de confirmation de commande au client */ |
| 297 | - if ( empty( $order_metadata['order_key'] ) ) { |
|
| 297 | + if (empty($order_metadata['order_key'])) { |
|
| 298 | 298 | $wps_message->wpshop_prepared_email($email, |
| 299 | 299 | 'WPSHOP_QUOTATION_UPDATE_MESSAGE', |
| 300 | - array( 'order_id' => $object['object_id'], |
|
| 300 | + array('order_id' => $object['object_id'], |
|
| 301 | 301 | 'customer_first_name' => $first_name, |
| 302 | 302 | 'customer_last_name' => $last_name, |
| 303 | 303 | 'order_date' => current_time('mysql', 0), |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | $wps_message->wpshop_prepared_email( |
| 313 | 313 | $email, |
| 314 | 314 | 'WPSHOP_ORDER_UPDATE_MESSAGE', |
| 315 | - array( 'customer_first_name' => $first_name, |
|
| 315 | + array('customer_first_name' => $first_name, |
|
| 316 | 316 | 'customer_last_name' => $last_name, |
| 317 | 317 | 'order_key' => $order_metadata['order_key'], |
| 318 | 318 | 'order_billing_address' => '', |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | 'order_addresses' => '', |
| 321 | 321 | 'order_addresses' => '', |
| 322 | 322 | 'order_billing_address' => '', |
| 323 | - 'order_shipping_address' => '' ), |
|
| 323 | + 'order_shipping_address' => ''), |
|
| 324 | 324 | $object); |
| 325 | 325 | } |
| 326 | 326 | } |
@@ -331,25 +331,25 @@ discard block |
||
| 331 | 331 | * AJAX - Add a private comment to order |
| 332 | 332 | */ |
| 333 | 333 | function wpshop_add_private_comment_to_order() { |
| 334 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 334 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 335 | 335 | |
| 336 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_add_private_comment_to_order' ) ) |
|
| 336 | + if (!wp_verify_nonce($_wpnonce, 'wpshop_add_private_comment_to_order')) |
|
| 337 | 337 | wp_die(); |
| 338 | 338 | |
| 339 | 339 | $status = false; $result = ''; |
| 340 | - $order_id = ( !empty($_POST['oid']) ) ? intval($_POST['oid']) : null; |
|
| 341 | - $comment = ( !empty($_POST['comment']) ) ? wpshop_tools::varSanitizer($_POST['comment']) : null; |
|
| 342 | - $send_email = ( !empty($_POST['send_email']) ) ? wpshop_tools::varSanitizer($_POST['send_email']) : null; |
|
| 343 | - $copy_to_administrator = ( !empty($_POST['copy_to_administrator']) ) ? wpshop_tools::varSanitizer($_POST['copy_to_administrator']) : null; |
|
| 340 | + $order_id = (!empty($_POST['oid'])) ? intval($_POST['oid']) : null; |
|
| 341 | + $comment = (!empty($_POST['comment'])) ? wpshop_tools::varSanitizer($_POST['comment']) : null; |
|
| 342 | + $send_email = (!empty($_POST['send_email'])) ? wpshop_tools::varSanitizer($_POST['send_email']) : null; |
|
| 343 | + $copy_to_administrator = (!empty($_POST['copy_to_administrator'])) ? wpshop_tools::varSanitizer($_POST['copy_to_administrator']) : null; |
|
| 344 | 344 | |
| 345 | - if ( !empty($comment) && !empty($order_id) ) { |
|
| 345 | + if (!empty($comment) && !empty($order_id)) { |
|
| 346 | 346 | $wps_back_office_orders_mdl = new wps_back_office_orders_mdl(); |
| 347 | - $new_comment = $wps_back_office_orders_mdl->add_private_comment($order_id, $comment, $send_email, false, $copy_to_administrator ); |
|
| 348 | - if($new_comment) { |
|
| 349 | - $order_private_comment = get_post_meta( $order_id, '_order_private_comments', true ); |
|
| 347 | + $new_comment = $wps_back_office_orders_mdl->add_private_comment($order_id, $comment, $send_email, false, $copy_to_administrator); |
|
| 348 | + if ($new_comment) { |
|
| 349 | + $order_private_comment = get_post_meta($order_id, '_order_private_comments', true); |
|
| 350 | 350 | $oid = $order_id; |
| 351 | 351 | ob_start(); |
| 352 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_sended_private_comments") ); |
|
| 352 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_sended_private_comments")); |
|
| 353 | 353 | $result = ob_get_contents(); |
| 354 | 354 | ob_end_clean(); |
| 355 | 355 | $status = true; |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | $result = __('An error was occured', 'wpshop'); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $response = array( 'status' => $status, 'response' => $result ); |
|
| 363 | - echo json_encode( $response ); |
|
| 362 | + $response = array('status' => $status, 'response' => $result); |
|
| 363 | + echo json_encode($response); |
|
| 364 | 364 | wp_die(); |
| 365 | 365 | } |
| 366 | 366 | |
@@ -368,29 +368,29 @@ discard block |
||
| 368 | 368 | * AJAX - Refresh product listing in order back-office |
| 369 | 369 | */ |
| 370 | 370 | function refresh_product_list() { |
| 371 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 372 | - $letter = ( !empty($_POST['letter']) ) ? sanitize_title( $_POST['letter'] ) : ''; |
|
| 371 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 372 | + $letter = (!empty($_POST['letter'])) ? sanitize_title($_POST['letter']) : ''; |
|
| 373 | 373 | |
| 374 | - if ( !wp_verify_nonce( $_wpnonce, 'refresh_product_list_'.strtolower($letter) ) ) |
|
| 374 | + if (!wp_verify_nonce($_wpnonce, 'refresh_product_list_' . strtolower($letter))) |
|
| 375 | 375 | wp_die(); |
| 376 | 376 | |
| 377 | 377 | $status = false; $response = ''; |
| 378 | - $oid = !empty( $_POST['oid'] ) ? (int) $_POST['oid'] : 0; |
|
| 378 | + $oid = !empty($_POST['oid']) ? (int)$_POST['oid'] : 0; |
|
| 379 | 379 | |
| 380 | - if( !empty($oid) ) { |
|
| 381 | - $post = get_post( $oid ); |
|
| 380 | + if (!empty($oid)) { |
|
| 381 | + $post = get_post($oid); |
|
| 382 | 382 | } |
| 383 | - if( !empty($letter) ) { |
|
| 383 | + if (!empty($letter)) { |
|
| 384 | 384 | $current_letter = $letter; |
| 385 | 385 | $wps_product_mdl = new wps_product_mdl(); |
| 386 | - $products = $wps_product_mdl->get_products_by_letter( $letter ); |
|
| 386 | + $products = $wps_product_mdl->get_products_by_letter($letter); |
|
| 387 | 387 | ob_start(); |
| 388 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing_table") ); |
|
| 388 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing_table")); |
|
| 389 | 389 | $response = ob_get_contents(); |
| 390 | 390 | ob_end_clean(); |
| 391 | 391 | $status = true; |
| 392 | 392 | } |
| 393 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 393 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 394 | 394 | wp_die(); |
| 395 | 395 | } |
| 396 | 396 | |
@@ -398,38 +398,38 @@ discard block |
||
| 398 | 398 | * AJAX - Add product to order in back-office panel |
| 399 | 399 | */ |
| 400 | 400 | function wps_add_product_to_order_admin() { |
| 401 | - check_ajax_referer( 'wps_add_product_to_order_admin' ); |
|
| 401 | + check_ajax_referer('wps_add_product_to_order_admin'); |
|
| 402 | 402 | |
| 403 | 403 | $status = false; $response = ''; $product_have_variations = false; |
| 404 | 404 | // Sended vars |
| 405 | - $product_id = ( !empty($_POST['pid']) ) ? intval( $_POST['pid']) : null; |
|
| 406 | - $order_id = ( !empty($_POST['oid']) ) ? intval( $_POST['oid']) : null; |
|
| 407 | - $product_qty = ( !empty($_POST['qty']) ) ? intval( $_POST['qty']) : 1; |
|
| 405 | + $product_id = (!empty($_POST['pid'])) ? intval($_POST['pid']) : null; |
|
| 406 | + $order_id = (!empty($_POST['oid'])) ? intval($_POST['oid']) : null; |
|
| 407 | + $product_qty = (!empty($_POST['qty'])) ? intval($_POST['qty']) : 1; |
|
| 408 | 408 | |
| 409 | - if( !empty($order_id) && !empty($product_id) ) { |
|
| 409 | + if (!empty($order_id) && !empty($product_id)) { |
|
| 410 | 410 | $wps_orders = new wps_orders_ctr(); |
| 411 | 411 | $product_datas = wpshop_products::get_product_data($product_id, false, '"publish", "free_product"'); |
| 412 | 412 | // Check if product have variations |
| 413 | - $have_variations_checking = wpshop_products::get_variation( $product_id ); |
|
| 414 | - if( !empty($have_variations_checking) ) { |
|
| 413 | + $have_variations_checking = wpshop_products::get_variation($product_id); |
|
| 414 | + if (!empty($have_variations_checking)) { |
|
| 415 | 415 | $product_have_variations = true; |
| 416 | 416 | } |
| 417 | 417 | else { |
| 418 | 418 | // Get Metadatas |
| 419 | - $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 419 | + $order_metadata = get_post_meta($order_id, '_order_postmeta', true); |
|
| 420 | 420 | // Calcul cart informations |
| 421 | 421 | $wps_cart = new wps_cart(); |
| 422 | - $order_metadata = $wps_cart->calcul_cart_information( array( $product_id => array( 'product_id' => $product_id, 'product_qty' => $product_qty ) ), '', $order_metadata, true, false ); |
|
| 422 | + $order_metadata = $wps_cart->calcul_cart_information(array($product_id => array('product_id' => $product_id, 'product_qty' => $product_qty)), '', $order_metadata, true, false); |
|
| 423 | 423 | // Update Metadatas |
| 424 | - update_post_meta( $order_id, '_order_postmeta', $order_metadata ); |
|
| 424 | + update_post_meta($order_id, '_order_postmeta', $order_metadata); |
|
| 425 | 425 | $status = true; |
| 426 | 426 | } |
| 427 | 427 | $status = true; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - $_wpnonce = wp_create_nonce( 'wps_order_load_product_variations' ); |
|
| 430 | + $_wpnonce = wp_create_nonce('wps_order_load_product_variations'); |
|
| 431 | 431 | |
| 432 | - echo json_encode( array( '_wpnonce' => $_wpnonce, 'status' => $status, 'response' => $response, 'variations_exist' => $product_have_variations ) ); |
|
| 432 | + echo json_encode(array('_wpnonce' => $_wpnonce, 'status' => $status, 'response' => $response, 'variations_exist' => $product_have_variations)); |
|
| 433 | 433 | wp_die(); |
| 434 | 434 | } |
| 435 | 435 | |
@@ -437,15 +437,15 @@ discard block |
||
| 437 | 437 | * AJAX - Refresh cart in administration |
| 438 | 438 | */ |
| 439 | 439 | function refresh_cart_order() { |
| 440 | - check_ajax_referer( 'wps_reload_cart' ); |
|
| 440 | + check_ajax_referer('wps_reload_cart'); |
|
| 441 | 441 | |
| 442 | 442 | $status = false; $response = ''; |
| 443 | - $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null; |
|
| 444 | - if( !empty($order_id) ) { |
|
| 445 | - $response = do_shortcode( '[wps_cart oid="' .$order_id. '" cart_type="admin-panel"]'); |
|
| 443 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null; |
|
| 444 | + if (!empty($order_id)) { |
|
| 445 | + $response = do_shortcode('[wps_cart oid="' . $order_id . '" cart_type="admin-panel"]'); |
|
| 446 | 446 | $status = true; |
| 447 | 447 | } |
| 448 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 448 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 449 | 449 | wp_die(); |
| 450 | 450 | } |
| 451 | 451 | |
@@ -453,17 +453,17 @@ discard block |
||
| 453 | 453 | * AJAX - Refresh cart in administration |
| 454 | 454 | */ |
| 455 | 455 | function refresh_payments_order() { |
| 456 | - check_ajax_referer( 'wps_reload_cart' ); |
|
| 456 | + check_ajax_referer('wps_reload_cart'); |
|
| 457 | 457 | $status = false; $response = ''; |
| 458 | - $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null; |
|
| 459 | - if( !empty($order_id) ) { |
|
| 458 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null; |
|
| 459 | + if (!empty($order_id)) { |
|
| 460 | 460 | ob_start(); |
| 461 | - echo $this->display_order_payments_box( get_post( $order_id ) ); |
|
| 461 | + echo $this->display_order_payments_box(get_post($order_id)); |
|
| 462 | 462 | $response = ob_get_contents(); |
| 463 | 463 | ob_end_clean(); |
| 464 | 464 | $status = true; |
| 465 | 465 | } |
| 466 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 466 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 467 | 467 | wp_die(); |
| 468 | 468 | } |
| 469 | 469 | |
@@ -471,25 +471,25 @@ discard block |
||
| 471 | 471 | * AJAX - Update product Quantity in Back-office Panel |
| 472 | 472 | */ |
| 473 | 473 | function wps_update_product_qty_in_admin() { |
| 474 | - check_ajax_referer( 'wps_reload_cart' ); |
|
| 474 | + check_ajax_referer('wps_reload_cart'); |
|
| 475 | 475 | |
| 476 | 476 | $status = false; $response = ''; |
| 477 | - $product_id = ( !empty($_POST['product_id']) ) ? wpshop_tools::varSanitizer( $_POST['product_id'] ) : null; |
|
| 478 | - $order_id = ( !empty($_POST['order_id']) ) ? intval( $_POST['order_id'] ) : null; |
|
| 479 | - $product_qty = ( !empty($_POST['qty']) ) ? intval( $_POST['qty'] ) : 0; |
|
| 477 | + $product_id = (!empty($_POST['product_id'])) ? wpshop_tools::varSanitizer($_POST['product_id']) : null; |
|
| 478 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null; |
|
| 479 | + $product_qty = (!empty($_POST['qty'])) ? intval($_POST['qty']) : 0; |
|
| 480 | 480 | |
| 481 | - if( !empty($product_id) && !empty($order_id) ) { |
|
| 481 | + if (!empty($product_id) && !empty($order_id)) { |
|
| 482 | 482 | // Get Metadatas |
| 483 | - $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 483 | + $order_metadata = get_post_meta($order_id, '_order_postmeta', true); |
|
| 484 | 484 | // Calcul cart informations |
| 485 | 485 | $wps_cart = new wps_cart(); |
| 486 | - $order_metadata = $wps_cart->calcul_cart_information( array( $product_id => array( 'product_id' => $product_id, 'product_qty' => $product_qty ) ), '', $order_metadata, true, false ); |
|
| 486 | + $order_metadata = $wps_cart->calcul_cart_information(array($product_id => array('product_id' => $product_id, 'product_qty' => $product_qty)), '', $order_metadata, true, false); |
|
| 487 | 487 | // Update Metadatas |
| 488 | - update_post_meta( $order_id, '_order_postmeta', $order_metadata ); |
|
| 488 | + update_post_meta($order_id, '_order_postmeta', $order_metadata); |
|
| 489 | 489 | $status = true; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - echo json_encode( array( 'status' => $status ) ); |
|
| 492 | + echo json_encode(array('status' => $status)); |
|
| 493 | 493 | wp_die(); |
| 494 | 494 | } |
| 495 | 495 | |
@@ -497,15 +497,15 @@ discard block |
||
| 497 | 497 | * AJAX - Load Product Variations in ThickBox on Add product to order action |
| 498 | 498 | */ |
| 499 | 499 | function wps_order_load_product_variations() { |
| 500 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 500 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 501 | 501 | |
| 502 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_order_load_product_variations' ) ) |
|
| 502 | + if (!wp_verify_nonce($_wpnonce, 'wps_order_load_product_variations')) |
|
| 503 | 503 | wp_die(); |
| 504 | 504 | |
| 505 | - $product_id = ( !empty($_GET['pid']) ) ? intval( $_GET['pid']) : null; |
|
| 506 | - $order_id = ( !empty($_GET['oid']) ) ? intval( $_GET['oid']) : null; |
|
| 507 | - $qty = ( !empty($_GET['qty']) ) ? intval( $_GET['qty']) : 1; |
|
| 508 | - echo '<div class="wps-boxed"><span class="wps-h5">'.__( 'Select your variations', 'wpshop' ).'</span>'.wpshop_products::wpshop_variation($product_id, true, $order_id, $qty ).'<a href="#" class="wps-bton-first-mini-rounded alignRight wps-orders-add_variation_product"><i class="wps-icon-basket"></i> ' .__( 'Add to cart', 'wpshop' ). '</a>'.'</div>'; |
|
| 505 | + $product_id = (!empty($_GET['pid'])) ? intval($_GET['pid']) : null; |
|
| 506 | + $order_id = (!empty($_GET['oid'])) ? intval($_GET['oid']) : null; |
|
| 507 | + $qty = (!empty($_GET['qty'])) ? intval($_GET['qty']) : 1; |
|
| 508 | + echo '<div class="wps-boxed"><span class="wps-h5">' . __('Select your variations', 'wpshop') . '</span>' . wpshop_products::wpshop_variation($product_id, true, $order_id, $qty) . '<a href="#" class="wps-bton-first-mini-rounded alignRight wps-orders-add_variation_product"><i class="wps-icon-basket"></i> ' . __('Add to cart', 'wpshop') . '</a>' . '</div>'; |
|
| 509 | 509 | wp_die(); |
| 510 | 510 | } |
| 511 | 511 | |
@@ -513,67 +513,67 @@ discard block |
||
| 513 | 513 | * AJAX - Update cart informations |
| 514 | 514 | */ |
| 515 | 515 | function wps_orders_update_cart_informations() { |
| 516 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 516 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 517 | 517 | |
| 518 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_update_cart_informations' ) ) |
|
| 518 | + if (!wp_verify_nonce($_wpnonce, 'wps_orders_update_cart_informations')) |
|
| 519 | 519 | wp_die(); |
| 520 | 520 | |
| 521 | 521 | $status = false; |
| 522 | - $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : ''; |
|
| 522 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : ''; |
|
| 523 | 523 | $shipping_cost = isset($_POST['shipping_cost']) ? wpshop_tools::varSanitizer($_POST['shipping_cost']) : ''; |
| 524 | 524 | $discount_value = isset($_POST['discount_amount']) ? wpshop_tools::varSanitizer($_POST['discount_amount']) : ''; |
| 525 | 525 | $discount_type = isset($_POST['discount_type']) ? wpshop_tools::varSanitizer($_POST['discount_type']) : ''; |
| 526 | 526 | |
| 527 | 527 | |
| 528 | - if( !empty($order_id) ) { |
|
| 529 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 528 | + if (!empty($order_id)) { |
|
| 529 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 530 | 530 | $order_meta['order_shipping_cost'] = $shipping_cost; |
| 531 | 531 | |
| 532 | 532 | //Add discounts if exists |
| 533 | - if( isset($discount_value) && !empty($discount_type) ) { |
|
| 533 | + if (isset($discount_value) && !empty($discount_type)) { |
|
| 534 | 534 | $order_meta['order_discount_type'] = $discount_type; |
| 535 | 535 | $order_meta['order_discount_value'] = $discount_value; |
| 536 | 536 | } |
| 537 | 537 | $wps_cart = new wps_cart(); |
| 538 | - $order_meta = $wps_cart->calcul_cart_information( array(), '', $order_meta, true ); |
|
| 539 | - update_post_meta( $order_id, '_order_postmeta', $order_meta ); |
|
| 538 | + $order_meta = $wps_cart->calcul_cart_information(array(), '', $order_meta, true); |
|
| 539 | + update_post_meta($order_id, '_order_postmeta', $order_meta); |
|
| 540 | 540 | $status = true; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - echo json_encode( array( 'status' => $status) ); |
|
| 543 | + echo json_encode(array('status' => $status)); |
|
| 544 | 544 | wp_die(); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | function wps_reverify_payment_invoice_ref() { |
| 548 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 548 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 549 | 549 | |
| 550 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reverify_payment_invoice_ref' ) ) |
|
| 550 | + if (!wp_verify_nonce($_wpnonce, 'wps_reverify_payment_invoice_ref')) |
|
| 551 | 551 | wp_die(); |
| 552 | 552 | |
| 553 | 553 | $status = true; |
| 554 | - $inputs = !empty( $_POST['inputs'] ) ? (array) $_POST['inputs'] : false; |
|
| 554 | + $inputs = !empty($_POST['inputs']) ? (array)$_POST['inputs'] : false; |
|
| 555 | 555 | |
| 556 | 556 | if (!$inputs) |
| 557 | 557 | $status = false; |
| 558 | 558 | |
| 559 | - if( $status ) { |
|
| 559 | + if ($status) { |
|
| 560 | 560 | $inputs_clone = $inputs; |
| 561 | 561 | $inputs = array(); |
| 562 | - foreach( $inputs_clone as $var ) { |
|
| 563 | - if( isset( $var['key'] ) && isset( $var['value'] ) ) { |
|
| 562 | + foreach ($inputs_clone as $var) { |
|
| 563 | + if (isset($var['key']) && isset($var['value'])) { |
|
| 564 | 564 | $inputs[$var['key']] = $var['value']; |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - ( isset( $inputs['order_id'] ) ) ? $order_id = $inputs['order_id'] : $status = $order_id = false; |
|
| 569 | - ( isset( $inputs['index_payment'] ) ) ? $index_payment = $inputs['index_payment'] : $status = $index_payment = false; |
|
| 568 | + (isset($inputs['order_id'])) ? $order_id = $inputs['order_id'] : $status = $order_id = false; |
|
| 569 | + (isset($inputs['index_payment'])) ? $index_payment = $inputs['index_payment'] : $status = $index_payment = false; |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | - if( $status ) { |
|
| 573 | - $status = wpshop_payment::reverify_payment_invoice_ref( $order_id, $index_payment ); |
|
| 572 | + if ($status) { |
|
| 573 | + $status = wpshop_payment::reverify_payment_invoice_ref($order_id, $index_payment); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - echo json_encode( array( 'status' => $status ) ); |
|
| 576 | + echo json_encode(array('status' => $status)); |
|
| 577 | 577 | wp_die(); |
| 578 | 578 | } |
| 579 | 579 | |
@@ -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 | - $mini_cart_body = __( 'Your cart is empty', 'wpshop' ); |
|
| 179 | + $mini_cart_body = __('Your cart is empty', 'wpshop'); |
|
| 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,14 +451,14 @@ 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 | 464 | } |
@@ -467,99 +467,99 @@ discard block |
||
| 467 | 467 | $order_items[$pid]['product_qty'] = $the_quantity; |
| 468 | 468 | |
| 469 | 469 | /** For product with variation */ |
| 470 | - $order_items[$pid]['product_variation_type'] = !empty( $product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 470 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 471 | 471 | $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
| 472 | 472 | $order_items[$pid]['product_variation'] = ''; |
| 473 | - if ( !empty($product_more_content['variations']) ) { |
|
| 474 | - foreach ( $product_more_content['variations'] as $variation_id) { |
|
| 473 | + if (!empty($product_more_content['variations'])) { |
|
| 474 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 475 | 475 | $order_items[$pid]['product_variation'][] = $variation_id; |
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - $current_cart = ( !empty( $order_meta )) ? $order_meta : array(); |
|
| 481 | - $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart ); |
|
| 480 | + $current_cart = (!empty($order_meta)) ? $order_meta : array(); |
|
| 481 | + $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart); |
|
| 482 | 482 | |
| 483 | - if( empty($from_admin) ) { |
|
| 483 | + if (empty($from_admin)) { |
|
| 484 | 484 | self::store_cart_in_session($order); |
| 485 | 485 | /** Store the cart into database for connected user */ |
| 486 | - if ( get_current_user_id() ) { |
|
| 486 | + if (get_current_user_id()) { |
|
| 487 | 487 | $this->persistent_cart_update(); |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | else { |
| 491 | - update_post_meta($order_id, '_order_postmeta', $order ); |
|
| 491 | + update_post_meta($order_id, '_order_postmeta', $order); |
|
| 492 | 492 | |
| 493 | 493 | } |
| 494 | 494 | return 'success'; |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - function prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected = array() ) { |
|
| 497 | + function prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected = array()) { |
|
| 498 | 498 | $product_price = ''; |
| 499 | 499 | $product_data = wpshop_products::get_product_data($product_id); |
| 500 | 500 | |
| 501 | 501 | // Free vars |
| 502 | - if ( !empty($wpshop_variation_selected['free']) ){ |
|
| 502 | + if (!empty($wpshop_variation_selected['free'])) { |
|
| 503 | 503 | $free_variations = $wpshop_variation_selected['free']; |
| 504 | 504 | unset($wpshop_variation_selected['free']); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // If product have many variations |
| 508 | - if ( count($wpshop_variation_selected ) > 1 ) { |
|
| 509 | - if ( !empty($wpshop_variation_selected) ) { |
|
| 510 | - $product_with_variation = wpshop_products::get_variation_by_priority( $wpshop_variation_selected, $product_id, true ); |
|
| 508 | + if (count($wpshop_variation_selected) > 1) { |
|
| 509 | + if (!empty($wpshop_variation_selected)) { |
|
| 510 | + $product_with_variation = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - if ( !empty($product_with_variation[$product_id]['variations']) ) { |
|
| 513 | + if (!empty($product_with_variation[$product_id]['variations'])) { |
|
| 514 | 514 | $product = $product_data; |
| 515 | 515 | $has_variation = true; |
| 516 | 516 | $head_product_id = $product_id; |
| 517 | 517 | |
| 518 | - if ( !empty($product_with_variation[$product_id]['variations']) && ( count($product_with_variation[$product_id]['variations']) == 1 ) && ($product_with_variation[$product_id]['variation_priority'] != 'single') ) { |
|
| 518 | + if (!empty($product_with_variation[$product_id]['variations']) && (count($product_with_variation[$product_id]['variations']) == 1) && ($product_with_variation[$product_id]['variation_priority'] != 'single')) { |
|
| 519 | 519 | $product_id = $product_with_variation[$product_id]['variations'][0]; |
| 520 | 520 | } |
| 521 | 521 | $product = wpshop_products::get_product_data($product_id, true); |
| 522 | 522 | |
| 523 | - $the_product = array_merge( array( |
|
| 523 | + $the_product = array_merge(array( |
|
| 524 | 524 | 'product_id' => $product_id, |
| 525 | 525 | 'product_qty' => $product_qty |
| 526 | 526 | ), $product); |
| 527 | 527 | |
| 528 | 528 | /* Add variation to product into cart for storage */ |
| 529 | - if ( !empty($product_with_variation[$head_product_id]['variations']) ) { |
|
| 530 | - $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']) ); |
|
| 529 | + if (!empty($product_with_variation[$head_product_id]['variations'])) { |
|
| 530 | + $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'])); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | $product_data = $the_product; |
| 534 | 534 | } |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - $product_to_add_to_cart = array( $product_id => array( 'id' => $product_id, 'product_qty' => $product_qty ) ); |
|
| 537 | + $product_to_add_to_cart = array($product_id => array('id' => $product_id, 'product_qty' => $product_qty)); |
|
| 538 | 538 | |
| 539 | - if ( !empty( $wpshop_variation_selected ) ) { |
|
| 540 | - $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true ); |
|
| 541 | - if ( !empty($variation_calculator[$product_id]) ) { |
|
| 539 | + if (!empty($wpshop_variation_selected)) { |
|
| 540 | + $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
| 541 | + if (!empty($variation_calculator[$product_id])) { |
|
| 542 | 542 | $product_to_add_to_cart[$product_id] = array_merge($product_to_add_to_cart[$product_id], $variation_calculator[$product_id]); |
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | $new_pid = $product_id; |
| 547 | 547 | //Create custom ID on single variations Product |
| 548 | - 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' ) { |
|
| 548 | + 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') { |
|
| 549 | 549 | $tmp_obj = $product_to_add_to_cart[$product_id]; |
| 550 | - unset( $product_to_add_to_cart[$product_id] ); |
|
| 550 | + unset($product_to_add_to_cart[$product_id]); |
|
| 551 | 551 | $key = $product_id; |
| 552 | - foreach( $tmp_obj['variations'] as $variation_key) { |
|
| 553 | - $key.= '__'. $variation_key; |
|
| 552 | + foreach ($tmp_obj['variations'] as $variation_key) { |
|
| 553 | + $key .= '__' . $variation_key; |
|
| 554 | 554 | } |
| 555 | 555 | $product_to_add_to_cart[$key] = $tmp_obj; |
| 556 | 556 | $new_pid = $key; |
| 557 | 557 | } |
| 558 | 558 | // Add free variations |
| 559 | - if( !empty($free_variations) ) { |
|
| 559 | + if (!empty($free_variations)) { |
|
| 560 | 560 | $product_to_add_to_cart[$new_pid]['free_variation'] = $free_variations; |
| 561 | 561 | } |
| 562 | - return array( $product_to_add_to_cart, $new_pid ); |
|
| 562 | + return array($product_to_add_to_cart, $new_pid); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -570,67 +570,67 @@ discard block |
||
| 570 | 570 | * @param boolean $from_admin |
| 571 | 571 | * @return array |
| 572 | 572 | */ |
| 573 | - function calcul_cart_information( $product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false ) { |
|
| 573 | + function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) { |
|
| 574 | 574 | // Price piloting option |
| 575 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 575 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 576 | 576 | |
| 577 | 577 | // Init vars |
| 578 | - $cart_infos = ( !empty($current_cart) ) ? $current_cart : ( ( !empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ) ? $_SESSION['cart'] : array() ); |
|
| 579 | - $cart_items = ( !empty($current_cart) && !empty($current_cart['order_items']) ) ? $current_cart['order_items'] : array(); |
|
| 580 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
| 578 | + $cart_infos = (!empty($current_cart)) ? $current_cart : ((!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin) ? $_SESSION['cart'] : array()); |
|
| 579 | + $cart_items = (!empty($current_cart) && !empty($current_cart['order_items'])) ? $current_cart['order_items'] : array(); |
|
| 580 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
| 581 | 581 | $order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array(); |
| 582 | 582 | $total_weight = $nb_of_items = $order_shipping_cost_by_article = 0; |
| 583 | 583 | $order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0; |
| 584 | 584 | $cart_infos['order_amount_to_pay_now'] = 0; |
| 585 | 585 | |
| 586 | 586 | // If Product list is not empty, add products to order |
| 587 | - if( !empty($product_list) ) { |
|
| 588 | - foreach ( $product_list as $product_id => $d ) { |
|
| 587 | + if (!empty($product_list)) { |
|
| 588 | + foreach ($product_list as $product_id => $d) { |
|
| 589 | 589 | $product_key = $product_id; |
| 590 | - if( isset( $d['product_qty']) ) { |
|
| 590 | + if (isset($d['product_qty'])) { |
|
| 591 | 591 | // Formate datas |
| 592 | 592 | $product_id = $head_product_id = $d['product_id']; |
| 593 | 593 | $product_qty = $d['product_qty']; |
| 594 | 594 | $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
| 595 | 595 | |
| 596 | 596 | // If product is a single variation product |
| 597 | - if ( !empty($product_variation) && ( count($product_variation) == 1 ) ) { |
|
| 597 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 598 | 598 | $product_id = $product_variation[0]; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | // Construct final product |
| 602 | 602 | $product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"'); |
| 603 | - $the_product = array_merge( array('product_id' => $d['product_id'], 'product_qty' => $product_qty ), $product); |
|
| 603 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => $product_qty), $product); |
|
| 604 | 604 | |
| 605 | 605 | // Add variation to product into cart for storage |
| 606 | - if ( !empty($product_variation) ) { |
|
| 607 | - $the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']) ); |
|
| 606 | + if (!empty($product_variation)) { |
|
| 607 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | // Free Variations Checking |
| 611 | - if ( !empty( $d['free_variation'] ) ) { |
|
| 611 | + if (!empty($d['free_variation'])) { |
|
| 612 | 612 | $the_product['item_meta']['free_variation'] = $d['free_variation']; |
| 613 | 613 | $head_product_id = $the_product['product_id']; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | // If product is a variation, we check parent product general |
| 617 | - if( get_post_type( $the_product['product_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 618 | - $parent_def = wpshop_products::get_parent_variation( $the_product['product_id'] ); |
|
| 619 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 620 | - $variation_def = get_post_meta( $parent_def['parent_post']->ID, '_wpshop_variation_defining', true ); |
|
| 617 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 618 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 619 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 620 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 621 | 621 | $parent_meta = $parent_def['parent_post_meta']; |
| 622 | - 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 ) { |
|
| 623 | - $the_product['product_price'] += number_format( str_replace( ',', '.', $parent_meta['product_price'] ), 2, '.', '' ); |
|
| 624 | - $the_product['price_ht'] += number_format( str_replace( ',', '.',$parent_meta['price_ht']) , 2, '.', '' ); |
|
| 625 | - $the_product['tva'] += number_format( str_replace( ',', '.', $parent_meta['tva']) , 2, '.', '' ); |
|
| 622 | + 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) { |
|
| 623 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 624 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 625 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | // Delete product if its qty is equals to zero, else add this product to order |
| 631 | - if( empty( $d['product_qty'] ) ) { |
|
| 632 | - unset( $cart_items[$product_key] ); |
|
| 633 | - unset( $cart_infos['order_items'][$product_key] ); |
|
| 631 | + if (empty($d['product_qty'])) { |
|
| 632 | + unset($cart_items[$product_key]); |
|
| 633 | + unset($cart_infos['order_items'][$product_key]); |
|
| 634 | 634 | } |
| 635 | 635 | else { |
| 636 | 636 | $wps_orders = new wps_orders_ctr(); |
@@ -641,16 +641,16 @@ discard block |
||
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // Add automaticaly Add-to-cart Products |
| 644 | - $cart_items = $this->add_automaticaly_product_to_cart( $cart_items ); |
|
| 644 | + $cart_items = $this->add_automaticaly_product_to_cart($cart_items); |
|
| 645 | 645 | |
| 646 | 646 | // Calcul Cart Informations |
| 647 | 647 | $cart_has_special_product = false; |
| 648 | - if( !empty($cart_items) && is_array($cart_items) ) { |
|
| 649 | - foreach( $cart_items as $item_id => $item ) { |
|
| 648 | + if (!empty($cart_items) && is_array($cart_items)) { |
|
| 649 | + foreach ($cart_items as $item_id => $item) { |
|
| 650 | 650 | |
| 651 | - if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) { |
|
| 651 | + if (!empty($item['item_amount_to_pay_now'])) { |
|
| 652 | 652 | $cart_has_special_product = true; |
| 653 | - $cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] ); |
|
| 653 | + $cart_infos['order_amount_to_pay_now'] += ($item['item_amount_to_pay_now'] * $item['item_qty']); |
|
| 654 | 654 | } |
| 655 | 655 | else { |
| 656 | 656 | $cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc']; |
@@ -659,11 +659,11 @@ discard block |
||
| 659 | 659 | $order_total_ht += $item['item_total_ht']; |
| 660 | 660 | $order_total_ttc += $item['item_total_ttc']; |
| 661 | 661 | // VAT |
| 662 | - if( !empty($order_tva[ $item['item_tva_rate'] ]) ) { |
|
| 663 | - $order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount']; |
|
| 662 | + if (!empty($order_tva[$item['item_tva_rate']])) { |
|
| 663 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 664 | 664 | } |
| 665 | 665 | else { |
| 666 | - $order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount']; |
|
| 666 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | } |
@@ -677,13 +677,13 @@ discard block |
||
| 677 | 677 | $cart_infos['order_total_ttc'] = $order_total_ttc; |
| 678 | 678 | |
| 679 | 679 | // Calcul Shipping cost |
| 680 | - if( !$from_admin && empty( $cart_infos['order_shipping_cost_fixe'] ) && empty($_SESSION[ 'wps-pos-addon' ]) ) { |
|
| 680 | + if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe']) && empty($_SESSION['wps-pos-addon'])) { |
|
| 681 | 681 | $wps_shipping = new wps_shipping(); |
| 682 | - $total_cart_ht_or_ttc_regarding_config = ( !empty($price_piloting) && $price_piloting == 'HT' ) ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
| 683 | - $cart_weight = $wps_shipping->calcul_cart_weight( $cart_infos['order_items'] ); |
|
| 684 | - $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost( $cart_infos['order_items'] ); |
|
| 685 | - foreach( $cart_infos['order_items'] as $item ) { |
|
| 686 | - if( !empty($item['item_is_downloadable_']) && ( __( $item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
|
| 682 | + $total_cart_ht_or_ttc_regarding_config = (!empty($price_piloting) && $price_piloting == 'HT') ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
| 683 | + $cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']); |
|
| 684 | + $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']); |
|
| 685 | + foreach ($cart_infos['order_items'] as $item) { |
|
| 686 | + if (!empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) { |
|
| 687 | 687 | $is_downloadable_products = 'is_downloadable_'; |
| 688 | 688 | } else { |
| 689 | 689 | $is_downloadable_products = ''; |
@@ -695,39 +695,39 @@ discard block |
||
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | // If Price piloting is ET, calcul VAT on Shipping cost |
| 698 | - if ( !empty($price_piloting) && $price_piloting == 'HT') { |
|
| 699 | - $shipping_cost_vat = ( !empty($cart_infos['order_shipping_cost']) ) ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * number_format( $cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
| 698 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 699 | + $shipping_cost_vat = (!empty($cart_infos['order_shipping_cost'])) ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
| 700 | 700 | $order_tva['VAT_shipping_cost'] = $shipping_cost_vat; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | // Calcul VAT Total |
| 704 | - if( !empty($order_tva) ) { |
|
| 705 | - foreach( $order_tva as $vat_rate => $vat_value ) { |
|
| 704 | + if (!empty($order_tva)) { |
|
| 705 | + foreach ($order_tva as $vat_rate => $vat_value) { |
|
| 706 | 706 | $total_vat += $vat_value; |
| 707 | 707 | } |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | // Recap totals |
| 711 | - $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 ); |
|
| 711 | + $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); |
|
| 712 | 712 | $cart_infos['order_grand_total_before_discount'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc']; |
| 713 | 713 | |
| 714 | 714 | // Total to pay now |
| 715 | 715 | $total_received = 0; |
| 716 | - if( !empty( $cart_infos['order_payment']['received'] ) ) { |
|
| 717 | - foreach( $cart_infos['order_payment']['received'] as $received ) { |
|
| 718 | - $total_received += ( ( !empty($received['status']) && ( $received['status'] == 'payment_received') && !empty($received['received_amount']) ) ? $received['received_amount'] : 0 ); |
|
| 716 | + if (!empty($cart_infos['order_payment']['received'])) { |
|
| 717 | + foreach ($cart_infos['order_payment']['received'] as $received) { |
|
| 718 | + $total_received += ((!empty($received['status']) && ($received['status'] == 'payment_received') && !empty($received['received_amount'])) ? $received['received_amount'] : 0); |
|
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | 721 | $cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] - $total_received; |
| 722 | 722 | |
| 723 | 723 | // Apply cart rules |
| 724 | - $cart_rule = wpshop_cart_rules::get_cart_rule( $cart_infos['order_grand_total'] ); |
|
| 725 | - if( $cart_rule['cart_rule_exist'] ) { |
|
| 726 | - if ( !empty( $cart_rule['cart_rule_info']['discount_type'] ) ) { |
|
| 727 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount' ) { |
|
| 724 | + $cart_rule = wpshop_cart_rules::get_cart_rule($cart_infos['order_grand_total']); |
|
| 725 | + if ($cart_rule['cart_rule_exist']) { |
|
| 726 | + if (!empty($cart_rule['cart_rule_info']['discount_type'])) { |
|
| 727 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount') { |
|
| 728 | 728 | $cart_infos['order_discount_type'] = 'amount'; |
| 729 | 729 | } |
| 730 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'percent_discount' ) { |
|
| 730 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'percent_discount') { |
|
| 731 | 731 | $cart_infos['order_discount_type'] = 'percent'; |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -735,15 +735,15 @@ discard block |
||
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // Apply coupons |
| 738 | - if( !empty( $_SESSION['cart']) && !$from_admin ) { |
|
| 739 | - if( !empty($_SESSION['cart']['coupon_id']) ) { |
|
| 738 | + if (!empty($_SESSION['cart']) && !$from_admin) { |
|
| 739 | + if (!empty($_SESSION['cart']['coupon_id'])) { |
|
| 740 | 740 | $wps_coupon_mdl = new wps_coupon_model(); |
| 741 | - $coupon = $wps_coupon_mdl->get_coupon_data( $_SESSION['cart']['coupon_id'] ); |
|
| 742 | - if( !empty($coupon) && !empty($coupon['wpshop_coupon_code']) ) { |
|
| 741 | + $coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']); |
|
| 742 | + if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) { |
|
| 743 | 743 | $wps_coupon = new wps_coupon_ctr(); |
| 744 | - $coupon_checking = $wps_coupon->applyCoupon( $coupon['wpshop_coupon_code'] ); |
|
| 744 | + $coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']); |
|
| 745 | 745 | // If Coupon conditions are Ok |
| 746 | - if( !empty($coupon_checking) && !empty( $coupon_checking['status'] ) && ( true == $coupon_checking['status'] ) ) { |
|
| 746 | + if (!empty($coupon_checking) && !empty($coupon_checking['status']) && (true == $coupon_checking['status'])) { |
|
| 747 | 747 | $cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type']; |
| 748 | 748 | $cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value']; |
| 749 | 749 | } |
@@ -752,51 +752,51 @@ discard block |
||
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | // Checking Discounts |
| 755 | - if( !empty($cart_infos['order_discount_type']) && isset( $cart_infos['order_discount_value'] ) ) { |
|
| 755 | + if (!empty($cart_infos['order_discount_type']) && isset($cart_infos['order_discount_value'])) { |
|
| 756 | 756 | // Calcul discount on Order |
| 757 | 757 | switch ($cart_infos['order_discount_type']) { |
| 758 | 758 | case 'amount': |
| 759 | - $cart_infos['order_discount_amount_total_cart'] = number_format( str_replace( ',', '.', $cart_infos['order_discount_value'] ), 2, '.', ''); |
|
| 759 | + $cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', ''); |
|
| 760 | 760 | break; |
| 761 | 761 | case 'percent': |
| 762 | - $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); |
|
| 762 | + $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); |
|
| 763 | 763 | break; |
| 764 | 764 | } |
| 765 | - if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) { |
|
| 765 | + if (number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format($cart_infos['order_grand_total'], 2, '.', '')) { |
|
| 766 | 766 | $cart_infos['order_grand_total'] = 0; |
| 767 | 767 | } |
| 768 | 768 | else { |
| 769 | - $cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
| 769 | + $cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
| 770 | 770 | } |
| 771 | - $cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
| 771 | + $cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | // Apply Partial Payments |
| 775 | 775 | $wpshop_payment = new wpshop_payment(); |
| 776 | - if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) { |
|
| 777 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' ); |
|
| 776 | + if (!empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation') { |
|
| 777 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total'], 'for_quotation'); |
|
| 778 | 778 | } |
| 779 | 779 | else { |
| 780 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] ); |
|
| 780 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']); |
|
| 781 | 781 | } |
| 782 | - if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) { |
|
| 782 | + if (!empty($partial_payment['amount_to_pay']) && (empty($cart_infos['order_status']) || $cart_infos['order_status'] == 'awaiting_payment') && (empty($product_partial_payment_amount))) { |
|
| 783 | 783 | unset($partial_payment['display']); |
| 784 | - $cart_infos['order_partial_payment'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
| 785 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
| 784 | + $cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
| 785 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
| 786 | 786 | } |
| 787 | 787 | // Apply Partial Payments : Subscription part. |
| 788 | - elseif ( ! empty( $cart_has_special_product ) ) { |
|
| 789 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $cart_infos['order_amount_to_pay_now'] ), 2, '.', ''); |
|
| 788 | + elseif (!empty($cart_has_special_product)) { |
|
| 789 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $cart_infos['order_amount_to_pay_now']), 2, '.', ''); |
|
| 790 | 790 | $cart_infos['order_product_partial_payment'] = 'subscription'; |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // Cart Type |
| 794 | - if ( isset( $_SESSION['cart']['cart_type'] ) ) { |
|
| 794 | + if (isset($_SESSION['cart']['cart_type'])) { |
|
| 795 | 795 | $cart_infos['cart_type'] = $_SESSION['cart']['cart_type']; |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | // Apply Extra actions on cart infos |
| 799 | - $cart_infos = apply_filters( 'wps_extra_calcul_in_cart', $cart_infos, $_SESSION ); |
|
| 799 | + $cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION); |
|
| 800 | 800 | |
| 801 | 801 | return $cart_infos; |
| 802 | 802 | } |
@@ -806,18 +806,18 @@ discard block |
||
| 806 | 806 | * @param array $cart_items |
| 807 | 807 | * @return array |
| 808 | 808 | */ |
| 809 | - function add_automaticaly_product_to_cart( $cart_items ) { |
|
| 809 | + function add_automaticaly_product_to_cart($cart_items) { |
|
| 810 | 810 | global $wpdb; |
| 811 | 811 | // Recovery all products with options |
| 812 | 812 | $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
| 813 | 813 | $post_list_with_options = $wpdb->get_results($query); |
| 814 | 814 | $wps_orders = new wps_orders_ctr(); |
| 815 | - if ( !empty($post_list_with_options) && !empty($cart_items) ) { |
|
| 816 | - foreach ( $post_list_with_options as $product_info) { |
|
| 815 | + if (!empty($post_list_with_options) && !empty($cart_items)) { |
|
| 816 | + foreach ($post_list_with_options as $product_info) { |
|
| 817 | 817 | $product_meta = unserialize($product_info->meta_value); |
| 818 | - if ( !empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id]) ) { |
|
| 818 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id])) { |
|
| 819 | 819 | $product = wpshop_products::get_product_data($product_info->post_id, true, '"draft", "publish"'); |
| 820 | - $the_product = array_merge( array( |
|
| 820 | + $the_product = array_merge(array( |
|
| 821 | 821 | 'product_id' => $product_info->post_id, |
| 822 | 822 | 'product_qty' => 1 |
| 823 | 823 | ), $product); |
@@ -831,28 +831,28 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | /** Ajax action to reload cart **/ |
| 833 | 833 | public static function wps_reload_cart() { |
| 834 | - check_ajax_referer( 'wps_reload_cart' ); |
|
| 834 | + check_ajax_referer('wps_reload_cart'); |
|
| 835 | 835 | |
| 836 | 836 | $wps_cart = new wps_cart(); |
| 837 | 837 | $result = $wps_cart->cart_content(); |
| 838 | 838 | |
| 839 | - wp_die( json_encode( array( 'response' => $result) ) ); |
|
| 839 | + wp_die(json_encode(array('response' => $result))); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | |
| 843 | 843 | /** Ajax action to reload mini cart */ |
| 844 | 844 | public function wps_reload_mini_cart() { |
| 845 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 845 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 846 | 846 | |
| 847 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) |
|
| 847 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_mini_cart')) |
|
| 848 | 848 | wp_die(); |
| 849 | 849 | |
| 850 | 850 | $wps_cart = new wps_cart(); |
| 851 | - $result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) ); |
|
| 852 | - $count_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $wps_cart->total_cart_items( $_SESSION['cart']['order_items'] ) : 0; |
|
| 851 | + $result = $wps_cart->mini_cart_content(sanitize_title($_POST['type'])); |
|
| 852 | + $count_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0; |
|
| 853 | 853 | $free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert'); |
| 854 | 854 | |
| 855 | - echo json_encode( array( 'response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert) ); |
|
| 855 | + echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert)); |
|
| 856 | 856 | die(); |
| 857 | 857 | } |
| 858 | 858 | |
@@ -862,35 +862,35 @@ discard block |
||
| 862 | 862 | * @return string |
| 863 | 863 | */ |
| 864 | 864 | function display_wps_numeration_cart() { |
| 865 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $_SESSION['cart']['order_items'] : array(); |
|
| 866 | - $total_cart_item = self::total_cart_items( $cart_items ); |
|
| 865 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $_SESSION['cart']['order_items'] : array(); |
|
| 866 | + $total_cart_item = self::total_cart_items($cart_items); |
|
| 867 | 867 | |
| 868 | 868 | ob_start(); |
| 869 | - require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart") ); |
|
| 869 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart")); |
|
| 870 | 870 | $output = ob_get_contents(); |
| 871 | 871 | ob_end_clean(); |
| 872 | 872 | return $output; |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - public function display_button_add_to_cart( $args ) { |
|
| 876 | - $button_text = __( 'Add to cart', 'wpshop' ); |
|
| 875 | + public function display_button_add_to_cart($args) { |
|
| 876 | + $button_text = __('Add to cart', 'wpshop'); |
|
| 877 | 877 | $use_button = true; |
| 878 | - $output = __( 'No product has been found.', 'wpshop' ); |
|
| 878 | + $output = __('No product has been found.', 'wpshop'); |
|
| 879 | 879 | |
| 880 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
| 880 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 881 | 881 | |
| 882 | 882 | /** The user send the text in argument */ |
| 883 | - if ( !empty( $args['text' ] ) ) { |
|
| 883 | + if (!empty($args['text'])) { |
|
| 884 | 884 | $button_text = $args['text']; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** The user send use input */ |
| 888 | - if ( !empty( $args['use_button'] ) && 'false' == $args['use_button'] ) { |
|
| 888 | + if (!empty($args['use_button']) && 'false' == $args['use_button']) { |
|
| 889 | 889 | $use_button = false; |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | ob_start(); |
| 893 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart' ) ); |
|
| 893 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart')); |
|
| 894 | 894 | $output = ob_get_clean(); |
| 895 | 895 | } |
| 896 | 896 | |
@@ -899,21 +899,21 @@ discard block |
||
| 899 | 899 | |
| 900 | 900 | /** Ajax action to reload summary cart */ |
| 901 | 901 | public static function wps_reload_summary_cart() { |
| 902 | - check_ajax_referer( 'wps_reload_summary_cart' ); |
|
| 902 | + check_ajax_referer('wps_reload_summary_cart'); |
|
| 903 | 903 | |
| 904 | 904 | $wps_cart = new wps_cart(); |
| 905 | 905 | $result = $wps_cart->resume_cart_content(); |
| 906 | 906 | |
| 907 | - wp_die( json_encode( array( 'response' => $result, ) ) ); |
|
| 907 | + wp_die(json_encode(array('response' => $result,))); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
| 911 | 911 | /** Display Apply Coupon Interface **/ |
| 912 | 912 | function display_apply_coupon_interface() { |
| 913 | 913 | $output = ''; |
| 914 | - if ( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
| 914 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 915 | 915 | ob_start(); |
| 916 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon") ); |
|
| 916 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon")); |
|
| 917 | 917 | $output = ob_get_contents(); |
| 918 | 918 | ob_end_clean(); |
| 919 | 919 | } |
@@ -923,30 +923,30 @@ discard block |
||
| 923 | 923 | |
| 924 | 924 | /** AJAX - action to apply coupon **/ |
| 925 | 925 | function wps_apply_coupon() { |
| 926 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 926 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 927 | 927 | |
| 928 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) |
|
| 928 | + if (!wp_verify_nonce($_wpnonce, 'wps_apply_coupon')) |
|
| 929 | 929 | wp_die(); |
| 930 | 930 | |
| 931 | 931 | $status = false; $response = ''; |
| 932 | - $coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null; |
|
| 933 | - if( !empty($coupon) ) { |
|
| 932 | + $coupon = (!empty($_POST['coupon_code'])) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null; |
|
| 933 | + if (!empty($coupon)) { |
|
| 934 | 934 | $wps_coupon_ctr = new wps_coupon_ctr(); |
| 935 | 935 | $result = $wps_coupon_ctr->applyCoupon($coupon); |
| 936 | - if ($result['status']===true) { |
|
| 936 | + if ($result['status'] === true) { |
|
| 937 | 937 | $order = $this->calcul_cart_information(array()); |
| 938 | 938 | $this->store_cart_in_session($order); |
| 939 | 939 | $status = true; |
| 940 | - $response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>'; |
|
| 940 | + $response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>'; |
|
| 941 | 941 | } |
| 942 | 942 | else { |
| 943 | - $response = '<div class="wps-alert-error">' .$result['message']. '</div>'; |
|
| 943 | + $response = '<div class="wps-alert-error">' . $result['message'] . '</div>'; |
|
| 944 | 944 | } |
| 945 | 945 | } |
| 946 | 946 | else { |
| 947 | - $response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>'; |
|
| 947 | + $response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>'; |
|
| 948 | 948 | } |
| 949 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 949 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 950 | 950 | die(); |
| 951 | 951 | } |
| 952 | 952 | |
@@ -955,24 +955,24 @@ discard block |
||
| 955 | 955 | * AJAX - Pass to step two in the Checkout tunnel |
| 956 | 956 | */ |
| 957 | 957 | public static function wps_cart_pass_to_step_two() { |
| 958 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 958 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 959 | 959 | |
| 960 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) |
|
| 960 | + if (!wp_verify_nonce($_wpnonce, 'wps_cart_pass_to_step_two')) |
|
| 961 | 961 | wp_die(); |
| 962 | 962 | |
| 963 | 963 | $status = false; $response = ''; |
| 964 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 965 | - if( !empty($checkout_page_id) ) { |
|
| 966 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 967 | - $step = ( get_current_user_id() != 0 ) ? 3 : 2; |
|
| 968 | - $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
|
| 964 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 965 | + if (!empty($checkout_page_id)) { |
|
| 966 | + $permalink_option = get_option('permalink_structure'); |
|
| 967 | + $step = (get_current_user_id() != 0) ? 3 : 2; |
|
| 968 | + $response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step; |
|
| 969 | 969 | $response = apply_filters('wps_extra_signup_actions', $response); |
| 970 | 970 | $status = true; |
| 971 | 971 | } |
| 972 | 972 | else { |
| 973 | - $response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>'; |
|
| 973 | + $response = '<div class="wps-alert-error">' . __('An error was occured, please retry later or contact the website administrator', 'wpshop') . '</div>'; |
|
| 974 | 974 | } |
| 975 | - echo json_encode( array( 'status' => $status, 'response' => $response)); |
|
| 975 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 976 | 976 | die(); |
| 977 | 977 | } |
| 978 | 978 | |
@@ -981,14 +981,14 @@ discard block |
||
| 981 | 981 | * AJAX - Empty the cart |
| 982 | 982 | */ |
| 983 | 983 | function wps_empty_cart() { |
| 984 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 984 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 985 | 985 | |
| 986 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) |
|
| 986 | + if (!wp_verify_nonce($_wpnonce, 'wps_empty_cart')) |
|
| 987 | 987 | wp_die(); |
| 988 | 988 | |
| 989 | 989 | |
| 990 | 990 | $this->empty_cart(); |
| 991 | - echo json_encode( array( 'status' => true) ); |
|
| 991 | + echo json_encode(array('status' => true)); |
|
| 992 | 992 | die(); |
| 993 | 993 | } |
| 994 | 994 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_shipping_mode_ctr { |
| 3 | 3 | |
| 4 | 4 | /** |
@@ -18,34 +18,34 @@ discard block |
||
| 18 | 18 | /** Template Load **/ |
| 19 | 19 | // add_filter( 'wpshop_custom_template', array( $this, 'custom_template_load' ) ); |
| 20 | 20 | |
| 21 | - add_action( 'admin_init', array( $this, 'migrate_default_shipping_mode' ) ); |
|
| 21 | + add_action('admin_init', array($this, 'migrate_default_shipping_mode')); |
|
| 22 | 22 | |
| 23 | 23 | /** Add module option to wpshop general options */ |
| 24 | - add_filter('wpshop_options', array( $this, 'add_options'), 9); |
|
| 25 | - add_action('wsphop_options', array( $this, 'create_options'), 8); |
|
| 24 | + add_filter('wpshop_options', array($this, 'add_options'), 9); |
|
| 25 | + add_action('wsphop_options', array($this, 'create_options'), 8); |
|
| 26 | 26 | |
| 27 | 27 | // Add files in back-office |
| 28 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_in_admin' ) ); |
|
| 28 | + add_action('admin_enqueue_scripts', array($this, 'add_scripts_in_admin')); |
|
| 29 | 29 | // Add files in front-office |
| 30 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
| 30 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 31 | 31 | |
| 32 | 32 | // Available Shortcodes |
| 33 | - add_shortcode( 'wps_shipping_mode', array( &$this, 'display_shipping_mode') ); |
|
| 34 | - add_shortcode( 'wps_shipping_method', array( &$this, 'display_shipping_methods') ); |
|
| 35 | - add_shortcode( 'wps_shipping_summary', array( &$this, 'display_shipping_summary') ); |
|
| 33 | + add_shortcode('wps_shipping_mode', array(&$this, 'display_shipping_mode')); |
|
| 34 | + add_shortcode('wps_shipping_method', array(&$this, 'display_shipping_methods')); |
|
| 35 | + add_shortcode('wps_shipping_summary', array(&$this, 'display_shipping_summary')); |
|
| 36 | 36 | |
| 37 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box') ); |
|
| 37 | + add_action('add_meta_boxes', array($this, 'add_meta_box')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | function add_meta_box() { |
| 41 | 41 | global $post; |
| 42 | 42 | /** Box for shipping information */ |
| 43 | 43 | $shipping_option = get_option('wpshop_shipping_address_choice'); |
| 44 | - $order_meta = get_post_meta( $post->ID, '_order_postmeta', true ); |
|
| 45 | - if (!in_array( $post->post_status, array( 'auto-draft' ) ) && ( !empty($shipping_option['activate']) && $shipping_option['activate'] && empty($order_meta['order_payment']['shipping_method'] ) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos' )) { |
|
| 44 | + $order_meta = get_post_meta($post->ID, '_order_postmeta', true); |
|
| 45 | + if (!in_array($post->post_status, array('auto-draft')) && (!empty($shipping_option['activate']) && $shipping_option['activate'] && empty($order_meta['order_payment']['shipping_method']) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos')) { |
|
| 46 | 46 | add_meta_box( |
| 47 | 47 | 'wpshop_order_shipping', |
| 48 | - '<span class="dashicons dashicons-palmtree"></span> '.__('Shipping', 'wpshop'), |
|
| 48 | + '<span class="dashicons dashicons-palmtree"></span> ' . __('Shipping', 'wpshop'), |
|
| 49 | 49 | array($this, 'order_shipping_box'), |
| 50 | 50 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low' |
| 51 | 51 | ); |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | function add_scripts() { |
| 60 | 60 | //CSS files |
| 61 | - wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/css/wps_shipping_mode.css', false ); |
|
| 62 | - wp_enqueue_style( 'wps_shipping_mode_css' ); |
|
| 61 | + wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/css/wps_shipping_mode.css', false); |
|
| 62 | + wp_enqueue_style('wps_shipping_mode_css'); |
|
| 63 | 63 | // Javascript Files |
| 64 | - wp_enqueue_script( 'jquery' ); |
|
| 65 | - wp_enqueue_script( 'wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/js/shipping_method.js', false ); |
|
| 64 | + wp_enqueue_script('jquery'); |
|
| 65 | + wp_enqueue_script('wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/js/shipping_method.js', false); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | function add_scripts_in_admin() { |
| 72 | 72 | global $current_screen; |
| 73 | - if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) ) |
|
| 73 | + if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER), true)) |
|
| 74 | 74 | return; |
| 75 | 75 | |
| 76 | 76 | add_thickbox(); |
| 77 | 77 | wp_enqueue_script('jquery'); |
| 78 | 78 | wp_enqueue_script('jquery-ui-sortable'); |
| 79 | 79 | // Javascript files |
| 80 | - wp_enqueue_script( 'wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/js/wps_shipping_mode.js', false ); |
|
| 80 | + wp_enqueue_script('wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/js/wps_shipping_mode.js', false); |
|
| 81 | 81 | //CSS files |
| 82 | - wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/css/wps_shipping_mode.css', false ); |
|
| 83 | - wp_enqueue_style( 'wps_shipping_mode_css' ); |
|
| 82 | + wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/css/wps_shipping_mode.css', false); |
|
| 83 | + wp_enqueue_style('wps_shipping_mode_css'); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * Declare option groups for the module |
| 104 | 104 | */ |
| 105 | - function add_options( $option_group ) { |
|
| 105 | + function add_options($option_group) { |
|
| 106 | 106 | $option_group['wpshop_shipping_option']['subgroups']['wps_shipping_mode']['class'] = ' wpshop_admin_box_options_shipping_mode'; |
| 107 | 107 | return $option_group; |
| 108 | 108 | } |
@@ -111,38 +111,38 @@ discard block |
||
| 111 | 111 | * Create Options |
| 112 | 112 | **/ |
| 113 | 113 | function create_options() { |
| 114 | - add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>'.__('Shipping method', 'wpshop'), '', 'wps_shipping_mode'); |
|
| 115 | - register_setting('wpshop_options', 'wps_shipping_mode', array( $this, 'wpshop_options_validate_wps_shipping_mode')); |
|
| 116 | - add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array( $this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode'); |
|
| 114 | + add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>' . __('Shipping method', 'wpshop'), '', 'wps_shipping_mode'); |
|
| 115 | + register_setting('wpshop_options', 'wps_shipping_mode', array($this, 'wpshop_options_validate_wps_shipping_mode')); |
|
| 116 | + add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array($this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode'); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * WPS Shipping mode Option Validator |
| 121 | 121 | **/ |
| 122 | - function wpshop_options_validate_wps_shipping_mode( $input ) { |
|
| 122 | + function wpshop_options_validate_wps_shipping_mode($input) { |
|
| 123 | 123 | $wps_shipping = new wps_shipping(); |
| 124 | - if ( !empty($input['modes']) ) { |
|
| 125 | - foreach( $input['modes'] as $mode => $mode_det ) { |
|
| 124 | + if (!empty($input['modes'])) { |
|
| 125 | + foreach ($input['modes'] as $mode => $mode_det) { |
|
| 126 | 126 | /** Custom Shipping rules **/ |
| 127 | - $input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array( $input['modes'][$mode]['custom_shipping_rules']['fees'] ); |
|
| 127 | + $input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array($input['modes'][$mode]['custom_shipping_rules']['fees']); |
|
| 128 | 128 | |
| 129 | 129 | /** Shipping Modes Logo Treatment **/ |
| 130 | - if ( !empty($_FILES[$mode.'_logo']['name']) && empty($_FILES[$mode.'_logo']['error']) ) { |
|
| 131 | - $filename = $_FILES[$mode.'_logo']; |
|
| 132 | - $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 133 | - $wp_filetype = wp_check_filetype(basename($filename['name']), null ); |
|
| 130 | + if (!empty($_FILES[$mode . '_logo']['name']) && empty($_FILES[$mode . '_logo']['error'])) { |
|
| 131 | + $filename = $_FILES[$mode . '_logo']; |
|
| 132 | + $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 133 | + $wp_filetype = wp_check_filetype(basename($filename['name']), null); |
|
| 134 | 134 | $wp_upload_dir = wp_upload_dir(); |
| 135 | 135 | $attachment = array( |
| 136 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename['name'] ), |
|
| 136 | + 'guid' => $wp_upload_dir['url'] . '/' . basename($filename['name']), |
|
| 137 | 137 | 'post_mime_type' => $wp_filetype['type'], |
| 138 | 138 | 'post_title' => preg_replace(' /\.[^.]+$/', '', basename($filename['name'])), |
| 139 | 139 | 'post_content' => '', |
| 140 | 140 | 'post_status' => 'inherit' |
| 141 | 141 | ); |
| 142 | - $attach_id = wp_insert_attachment( $attachment, $upload['file']); |
|
| 142 | + $attach_id = wp_insert_attachment($attachment, $upload['file']); |
|
| 143 | 143 | require_once(ABSPATH . 'wp-admin/includes/image.php'); |
| 144 | - $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); |
|
| 145 | - wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 144 | + $attach_data = wp_generate_attachment_metadata($attach_id, $upload['file']); |
|
| 145 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 146 | 146 | |
| 147 | 147 | $input['modes'][$mode]['logo'] = $attach_id; |
| 148 | 148 | } |
@@ -156,38 +156,38 @@ discard block |
||
| 156 | 156 | **/ |
| 157 | 157 | function migrate_default_shipping_mode() { |
| 158 | 158 | $data = array(); |
| 159 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 160 | - if ( empty($shipping_mode_option) ) { |
|
| 159 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 160 | + if (empty($shipping_mode_option)) { |
|
| 161 | 161 | $data['modes']['default_shipping_mode']['active'] = 'on'; |
| 162 | 162 | $data['modes']['default_shipping_mode']['name'] = __('Home Delivery', 'wpshop'); |
| 163 | 163 | $data['modes']['default_shipping_mode']['explanation'] = __('Your purchase will be delivered directly to you at home', 'wpshop'); |
| 164 | 164 | /** Check CUstom Shipping **/ |
| 165 | - $custom_shipping_option = get_option( 'wpshop_custom_shipping' ); |
|
| 166 | - if ( !empty($custom_shipping_option) ) { |
|
| 165 | + $custom_shipping_option = get_option('wpshop_custom_shipping'); |
|
| 166 | + if (!empty($custom_shipping_option)) { |
|
| 167 | 167 | $data['modes']['default_shipping_mode']['custom_shipping_rules'] = $custom_shipping_option; |
| 168 | 168 | } |
| 169 | 169 | /** Check Country Limit **/ |
| 170 | - $limit_destination = get_option( 'wpshop_limit_shipping_destination' ); |
|
| 171 | - if ( !empty($custom_shipping_option) ) { |
|
| 170 | + $limit_destination = get_option('wpshop_limit_shipping_destination'); |
|
| 171 | + if (!empty($custom_shipping_option)) { |
|
| 172 | 172 | $data['modes']['default_shipping_mode']['limit_destination'] = $limit_destination; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** Check Others shipping configurations **/ |
| 176 | 176 | $wpshop_shipping_rules_option = get_option('wpshop_shipping_rules'); |
| 177 | - if ( !empty($wpshop_shipping_rules_option) ){ |
|
| 178 | - if ( !empty($wpshop_shipping_rules_option['min_max']) ) { |
|
| 177 | + if (!empty($wpshop_shipping_rules_option)) { |
|
| 178 | + if (!empty($wpshop_shipping_rules_option['min_max'])) { |
|
| 179 | 179 | $data['modes']['default_shipping_mode']['min_max'] = $wpshop_shipping_rules_option['min_max']; |
| 180 | 180 | } |
| 181 | - if ( !empty($wpshop_shipping_rules_option['free_from']) ) { |
|
| 181 | + if (!empty($wpshop_shipping_rules_option['free_from'])) { |
|
| 182 | 182 | $data['modes']['default_shipping_mode']['free_from'] = $wpshop_shipping_rules_option['free_from']; |
| 183 | 183 | } |
| 184 | - if ( !empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']) ) { |
|
| 184 | + if (!empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping'])) { |
|
| 185 | 185 | $data['modes']['default_shipping_mode']['free_shipping'] = $wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']; |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | $data['default_choice'] = 'default_shipping_mode'; |
| 189 | 189 | |
| 190 | - update_option( 'wps_shipping_mode', $data ); |
|
| 190 | + update_option('wps_shipping_mode', $data); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * Display the Admin Interface for Shipping Mode |
| 196 | 196 | **/ |
| 197 | 197 | function display_shipping_mode_in_admin() { |
| 198 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 199 | - require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes") ); |
|
| 198 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 199 | + require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes")); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | * @param array $shipping_mode |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - function generate_shipping_mode_interface( $k, $shipping_mode ) { |
|
| 208 | + function generate_shipping_mode_interface($k, $shipping_mode) { |
|
| 209 | 209 | global $wpdb; |
| 210 | 210 | $tpl_component = array(); |
| 211 | 211 | |
| 212 | - $shipping_mode_option = get_option( 'wps_shipping_mode'); |
|
| 213 | - $default_shipping_mode = !empty( $shipping_mode_option['default_choice'] ) ? $shipping_mode_option['default_choice'] : ''; |
|
| 212 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 213 | + $default_shipping_mode = !empty($shipping_mode_option['default_choice']) ? $shipping_mode_option['default_choice'] : ''; |
|
| 214 | 214 | |
| 215 | 215 | $countries = unserialize(WPSHOP_COUNTRY_LIST); |
| 216 | 216 | |
| 217 | 217 | /** Default Weight Unity **/ |
| 218 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 219 | - $query = $wpdb->prepare('SELECT name FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 220 | - $unity = $wpdb->get_var( $query ); |
|
| 218 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 219 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 220 | + $unity = $wpdb->get_var($query); |
|
| 221 | 221 | |
| 222 | 222 | |
| 223 | - $fees_data = ( !empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees']) ) ? $shipping_mode['custom_shipping_rules']['fees'] : array(); |
|
| 224 | - if(is_array($fees_data)) { |
|
| 223 | + $fees_data = (!empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees'])) ? $shipping_mode['custom_shipping_rules']['fees'] : array(); |
|
| 224 | + if (is_array($fees_data)) { |
|
| 225 | 225 | $wps_shipping = new wps_shipping(); |
| 226 | 226 | $fees_data = $wps_shipping->shipping_fees_array_2_string($fees_data); |
| 227 | 227 | } |
| 228 | 228 | ob_start(); |
| 229 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface") ); |
|
| 229 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface")); |
|
| 230 | 230 | $output = ob_get_contents(); |
| 231 | 231 | ob_end_clean(); |
| 232 | 232 | |
@@ -239,22 +239,22 @@ discard block |
||
| 239 | 239 | * @param array $fees_data |
| 240 | 240 | * @param string $key |
| 241 | 241 | */ |
| 242 | - function generate_shipping_rules_table( $fees_data, $shipping_mode_id ){ |
|
| 242 | + function generate_shipping_rules_table($fees_data, $shipping_mode_id) { |
|
| 243 | 243 | global $wpdb; |
| 244 | 244 | $result = ''; |
| 245 | - if ( !empty( $fees_data) ) { |
|
| 245 | + if (!empty($fees_data)) { |
|
| 246 | 246 | $wps_shipping = new wps_shipping(); |
| 247 | - $shipping_rules =$wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 247 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 248 | 248 | $result = ''; |
| 249 | - $tpl_component =''; |
|
| 249 | + $tpl_component = ''; |
|
| 250 | 250 | $tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = ''; |
| 251 | 251 | $tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id; |
| 252 | 252 | $country_list = unserialize(WPSHOP_COUNTRY_LIST); |
| 253 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 254 | - $query = $wpdb->prepare('SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 255 | - $unity = $wpdb->get_var( $query ); |
|
| 253 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 254 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 255 | + $unity = $wpdb->get_var($query); |
|
| 256 | 256 | ob_start(); |
| 257 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table") ); |
|
| 257 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table")); |
|
| 258 | 258 | $result = ob_get_contents(); |
| 259 | 259 | ob_end_clean(); |
| 260 | 260 | } |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | function display_shipping_methods() { |
| 276 | 276 | $output = $shipping_methods = ''; $no_shipping_mode_for_area = false; |
| 277 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 278 | - if( !empty($_SESSION['shipping_address']) ) { |
|
| 279 | - $shipping_modes = $this->get_shipping_mode_for_address( $_SESSION['shipping_address'] ); |
|
| 280 | - if( empty($shipping_modes) ) { |
|
| 277 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
| 278 | + if (!empty($_SESSION['shipping_address'])) { |
|
| 279 | + $shipping_modes = $this->get_shipping_mode_for_address($_SESSION['shipping_address']); |
|
| 280 | + if (empty($shipping_modes)) { |
|
| 281 | 281 | $no_shipping_mode_for_area = true; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $shipping_modes = apply_filters( 'wps_filter_shipping_methods', $shipping_modes ); |
|
| 284 | + $shipping_modes = apply_filters('wps_filter_shipping_methods', $shipping_modes); |
|
| 285 | 285 | ob_start(); |
| 286 | - require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container") ); |
|
| 286 | + require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container")); |
|
| 287 | 287 | $output = ob_get_contents(); |
| 288 | 288 | ob_end_clean(); |
| 289 | 289 | |
@@ -296,24 +296,24 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | function display_shipping_summary() { |
| 298 | 298 | $output = ''; |
| 299 | - $billing_address_id = ( !empty($_SESSION['billing_address']) ) ? $_SESSION['billing_address'] : null; |
|
| 300 | - $shipping_address_id = ( !empty($_SESSION['shipping_address']) ) ? $_SESSION['shipping_address'] : null; |
|
| 301 | - $shipping_mode = ( !empty($_SESSION['shipping_method']) ) ? $_SESSION['shipping_method'] : null; |
|
| 299 | + $billing_address_id = (!empty($_SESSION['billing_address'])) ? $_SESSION['billing_address'] : null; |
|
| 300 | + $shipping_address_id = (!empty($_SESSION['shipping_address'])) ? $_SESSION['shipping_address'] : null; |
|
| 301 | + $shipping_mode = (!empty($_SESSION['shipping_method'])) ? $_SESSION['shipping_method'] : null; |
|
| 302 | 302 | |
| 303 | - if( !empty($billing_address_id) ) { |
|
| 303 | + if (!empty($billing_address_id)) { |
|
| 304 | 304 | $billing_infos = get_post_meta($billing_address_id, '_wpshop_address_metadata', true); |
| 305 | - $billing_content = wps_address::display_an_address( $billing_infos, $billing_address_id); |
|
| 305 | + $billing_content = wps_address::display_an_address($billing_infos, $billing_address_id); |
|
| 306 | 306 | |
| 307 | - if ( !empty($shipping_address_id) && !empty($shipping_mode) ) { |
|
| 307 | + if (!empty($shipping_address_id) && !empty($shipping_mode)) { |
|
| 308 | 308 | $shipping_infos = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true); |
| 309 | - $shipping_content = wps_address::display_an_address( $shipping_infos, $shipping_address_id); |
|
| 309 | + $shipping_content = wps_address::display_an_address($shipping_infos, $shipping_address_id); |
|
| 310 | 310 | |
| 311 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 312 | - $shipping_mode = ( !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name']) ) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; |
|
| 311 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 312 | + $shipping_mode = (!empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name'])) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | ob_start(); |
| 316 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary") ); |
|
| 316 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary")); |
|
| 317 | 317 | $output = ob_get_contents(); |
| 318 | 318 | ob_end_clean(); |
| 319 | 319 | } |
@@ -327,42 +327,42 @@ discard block |
||
| 327 | 327 | * @param integer $address_id |
| 328 | 328 | * @return string |
| 329 | 329 | */ |
| 330 | - function get_shipping_mode_for_address( $address_id ) { |
|
| 330 | + function get_shipping_mode_for_address($address_id) { |
|
| 331 | 331 | $shipping_modes_to_display = array(); |
| 332 | - if( !empty($address_id) ) { |
|
| 333 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 334 | - $address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta( $address_id, '_wpshop_address_metadata', true); |
|
| 335 | - if( !empty( $shipping_modes ) && !empty($shipping_modes['modes']) ){ |
|
| 336 | - foreach( $shipping_modes['modes'] as $k => $shipping_mode ) { |
|
| 337 | - if ( !empty($shipping_mode) && !empty($shipping_mode['active']) ) { |
|
| 332 | + if (!empty($address_id)) { |
|
| 333 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
| 334 | + $address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta($address_id, '_wpshop_address_metadata', true); |
|
| 335 | + if (!empty($shipping_modes) && !empty($shipping_modes['modes'])) { |
|
| 336 | + foreach ($shipping_modes['modes'] as $k => $shipping_mode) { |
|
| 337 | + if (!empty($shipping_mode) && !empty($shipping_mode['active'])) { |
|
| 338 | 338 | /** Check Country Shipping Limitation **/ |
| 339 | - if ( empty($shipping_mode['limit_destination']) || ( !empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country']) ) || ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']) ) ) { |
|
| 339 | + if (empty($shipping_mode['limit_destination']) || (!empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country'])) || (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']))) { |
|
| 340 | 340 | /** Check Limit Destination By Postcode **/ |
| 341 | 341 | $visible = true; |
| 342 | 342 | /** Check Postcode limitation **/ |
| 343 | - if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode']) ) { |
|
| 344 | - $postcodes = explode(',', $shipping_mode['limit_destination']['postcode'] ); |
|
| 345 | - foreach( $postcodes as $postcode_id => $postcode ) { |
|
| 346 | - $postcodes[ $postcode_id ] = trim( str_replace( ' ', '', $postcode) ); |
|
| 343 | + if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode'])) { |
|
| 344 | + $postcodes = explode(',', $shipping_mode['limit_destination']['postcode']); |
|
| 345 | + foreach ($postcodes as $postcode_id => $postcode) { |
|
| 346 | + $postcodes[$postcode_id] = trim(str_replace(' ', '', $postcode)); |
|
| 347 | 347 | } |
| 348 | - if ( !in_array($address_metadata['postcode'], $postcodes) ) { |
|
| 348 | + if (!in_array($address_metadata['postcode'], $postcodes)) { |
|
| 349 | 349 | $visible = false; |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | /** Check Department limitation **/ |
| 353 | - $department = isset( $address_metadata['postcode'] ) ? substr( $address_metadata['postcode'], 0, 2 ) : ''; |
|
| 354 | - if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department']) ) { |
|
| 355 | - $departments = explode(',', $shipping_mode['limit_destination']['department'] ); |
|
| 356 | - foreach( $departments as $department_id => $d ) { |
|
| 357 | - $departments[ $department_id ] = trim( str_replace( ' ', '', $d) ); |
|
| 353 | + $department = isset($address_metadata['postcode']) ? substr($address_metadata['postcode'], 0, 2) : ''; |
|
| 354 | + if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department'])) { |
|
| 355 | + $departments = explode(',', $shipping_mode['limit_destination']['department']); |
|
| 356 | + foreach ($departments as $department_id => $d) { |
|
| 357 | + $departments[$department_id] = trim(str_replace(' ', '', $d)); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( !in_array($department, $departments) ) { |
|
| 360 | + if (!in_array($department, $departments)) { |
|
| 361 | 361 | $visible = false; |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - if ( $visible ) { |
|
| 365 | + if ($visible) { |
|
| 366 | 366 | $shipping_modes_to_display['modes'][$k] = $shipping_mode; |
| 367 | 367 | } |
| 368 | 368 | } |
@@ -378,12 +378,12 @@ discard block |
||
| 378 | 378 | * Display shipping informations in order administration panel |
| 379 | 379 | * @param object $order : Order post infos |
| 380 | 380 | */ |
| 381 | - function order_shipping_box( $order ) { |
|
| 382 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 381 | + function order_shipping_box($order) { |
|
| 382 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 383 | 383 | $order_postmeta = get_post_meta($order->ID, '_order_postmeta', true); |
| 384 | - $shipping_method_name = ( !empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ( (!empty($order_postmeta['order_payment']['shipping_method']) ) ? $order_postmeta['order_payment']['shipping_method'] : '' ); |
|
| 384 | + $shipping_method_name = (!empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ((!empty($order_postmeta['order_payment']['shipping_method'])) ? $order_postmeta['order_payment']['shipping_method'] : ''); |
|
| 385 | 385 | ob_start(); |
| 386 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos") ); |
|
| 386 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos")); |
|
| 387 | 387 | $output = ob_get_contents(); |
| 388 | 388 | ob_end_clean(); |
| 389 | 389 | echo $output; |