@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | |
| 267 | 267 | /** Renvoi une nouvelle r�f�rence unique pour une commande |
| 268 | - * @return int |
|
| 268 | + * @return string |
|
| 269 | 269 | */ |
| 270 | 270 | public static function get_new_order_reference(){ |
| 271 | 271 | $number_figures = get_option('wpshop_order_number_figures', false); |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** Renvoi une nouvelle r�f�rence unique pour un devis |
| 289 | - * @return int |
|
| 289 | + * @return string |
|
| 290 | 290 | */ |
| 291 | 291 | public static function get_new_pre_order_reference($save = true){ |
| 292 | 292 | $number_figures = get_option('wpshop_order_number_figures', false); |
@@ -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,7 +70,7 @@ 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 | ); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @param object $order The current order being edited |
| 112 | 112 | */ |
| 113 | - public static function order_actions( $order ) { |
|
| 113 | + public static function order_actions($order) { |
|
| 114 | 114 | $output = ''; |
| 115 | 115 | |
| 116 | 116 | $order_status = unserialize(WPSHOP_ORDER_STATUS); |
@@ -118,37 +118,37 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $tpl_component = array(); |
| 120 | 120 | |
| 121 | - $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'); |
|
| 122 | - $tpl_component['ADMIN_ORDER_DELETE_ORDER'] = current_user_can( "delete_post", $order->ID ) ? $delete_button : ''; |
|
| 121 | + $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'); |
|
| 122 | + $tpl_component['ADMIN_ORDER_DELETE_ORDER'] = current_user_can("delete_post", $order->ID) ? $delete_button : ''; |
|
| 123 | 123 | |
| 124 | 124 | /** Add an action list */ |
| 125 | 125 | $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] = ''; |
| 126 | 126 | |
| 127 | 127 | /** Display main information about the order */ |
| 128 | 128 | $order_main_info = ''; |
| 129 | - if(!empty($order_postmeta['order_date'])){ |
|
| 130 | - $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>'; |
|
| 129 | + if (!empty($order_postmeta['order_date'])) { |
|
| 130 | + $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>'; |
|
| 131 | 131 | } |
| 132 | 132 | $order_main_info .= '<div class="wps-product-section">'; |
| 133 | - if(empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))){ |
|
| 134 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Temporary quotation reference','wpshop').': </strong>'.self::get_new_pre_order_reference(false).'<br/>'; |
|
| 133 | + if (empty($order_postmeta['order_date']) || (empty($order_postmeta['order_key']) && empty($order_postmeta['order_temporary_key']) && empty($order_postmeta['order_invoice_ref']))) { |
|
| 134 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Temporary quotation reference', 'wpshop') . ': </strong>' . self::get_new_pre_order_reference(false) . '<br/>'; |
|
| 135 | 135 | } |
| 136 | - else{ |
|
| 137 | - if(!empty($order_postmeta['order_key'])){ |
|
| 138 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Order reference','wpshop').' : </strong>'.$order_postmeta['order_key'].'<br/>'; |
|
| 136 | + else { |
|
| 137 | + if (!empty($order_postmeta['order_key'])) { |
|
| 138 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Order reference', 'wpshop') . ' : </strong>' . $order_postmeta['order_key'] . '<br/>'; |
|
| 139 | 139 | } |
| 140 | - if(!empty($order_postmeta['order_temporary_key'])){ |
|
| 141 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'.__('Pre-order reference','wpshop').': </strong>'.$order_postmeta['order_temporary_key'].'<br/>'; |
|
| 142 | - $post_ID = !empty( $_GET['post'] ) ? (int) $_GET['post'] : 0; |
|
| 143 | - $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 />'; |
|
| 140 | + if (!empty($order_postmeta['order_temporary_key'])) { |
|
| 141 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Pre-order reference', 'wpshop') . ': </strong>' . $order_postmeta['order_temporary_key'] . '<br/>'; |
|
| 142 | + $post_ID = !empty($_GET['post']) ? (int)$_GET['post'] : 0; |
|
| 143 | + $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 />'; |
|
| 144 | 144 | } |
| 145 | - if(!empty($order_postmeta['order_invoice_ref'])){ |
|
| 145 | + if (!empty($order_postmeta['order_invoice_ref'])) { |
|
| 146 | 146 | $sub_tpl_component = array(); |
| 147 | 147 | $sub_tpl_component['ADMIN_ORDER_RECEIVED_PAYMENT_INVOICE_REF'] = $order_postmeta['order_invoice_ref']; |
| 148 | 148 | $sub_tpl_component['ADMIN_ORDER_PAYMENT_RECEIVED_LINE_CLASSES'] = ''; |
| 149 | - $sub_tpl_component['ADMIN_ORDER_INVOICE_DOWNLOAD_LINK'] = admin_url( 'admin-post.php?action=wps_invoice&order_id=' . $order->ID ); |
|
| 149 | + $sub_tpl_component['ADMIN_ORDER_INVOICE_DOWNLOAD_LINK'] = admin_url('admin-post.php?action=wps_invoice&order_id=' . $order->ID); |
|
| 150 | 150 | $order_invoice_download = wpshop_display::display_template_element('wpshop_admin_order_payment_received_invoice_download_links', $sub_tpl_component, array(), 'admin'); |
| 151 | - $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>'. __('Invoice number','wpshop').': </strong>'.$order_postmeta['order_invoice_ref'].'<br/>' . $order_invoice_download . ''; |
|
| 151 | + $order_main_info .= '<span class="dashicons dashicons-arrow-right"></span> <strong>' . __('Invoice number', 'wpshop') . ': </strong>' . $order_postmeta['order_invoice_ref'] . '<br/>' . $order_invoice_download . ''; |
|
| 152 | 152 | } |
| 153 | 153 | else { |
| 154 | 154 | $order_main_info .= wpshop_display::display_template_element('wpshop_admin_order_generate_invoice_button', array(), array(), 'admin'); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | /*Add the current order status in display**/ |
| 161 | - $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')) ) : ''; |
|
| 161 | + $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'))) : ''; |
|
| 162 | 162 | |
| 163 | 163 | $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= $order_main_info; |
| 164 | 164 | |
@@ -184,21 +184,21 @@ discard block |
||
| 184 | 184 | }*/ |
| 185 | 185 | |
| 186 | 186 | /*Add the button regarding the order status**/ |
| 187 | - if ( !empty($order_postmeta['order_status']) ) { |
|
| 188 | - if( in_array( $order_postmeta['order_status'], array( 'awaiting_payment', 'partially_paid' ) ) ) { |
|
| 189 | - $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section"><input id="wps_direct_link_url" type="text" value="' . wpshop_checkout::wps_direct_payment_link_url( $order->ID ) . '"/><a class="wps-bton-second-mini-rounded" data-copy-target="#wps_direct_link_url" title="Copier"><span class="dashicons dashicons-editor-paste-text"></span></a><a data-nonce="' . wp_create_nonce( 'wps_send_direct_payment_link' ) . '" role="button" class="wps-bton-second-mini-rounded send_direct_payment_link" href="#" title="Envoyer par mail"><span class="dashicons dashicons-email"></span></a></div>'; |
|
| 187 | + if (!empty($order_postmeta['order_status'])) { |
|
| 188 | + if (in_array($order_postmeta['order_status'], array('awaiting_payment', 'partially_paid'))) { |
|
| 189 | + $tpl_component['ADMIN_ORDER_ACTIONS_LIST'] .= '<div class="wps-product-section"><input id="wps_direct_link_url" type="text" value="' . wpshop_checkout::wps_direct_payment_link_url($order->ID) . '"/><a class="wps-bton-second-mini-rounded" data-copy-target="#wps_direct_link_url" title="Copier"><span class="dashicons dashicons-editor-paste-text"></span></a><a data-nonce="' . wp_create_nonce('wps_send_direct_payment_link') . '" role="button" class="wps-bton-second-mini-rounded send_direct_payment_link" href="#" title="Envoyer par mail"><span class="dashicons dashicons-email"></span></a></div>'; |
|
| 190 | 190 | } |
| 191 | - if( $order_postmeta['order_status'] == 'awaiting_payment' ) { |
|
| 192 | - $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>'; |
|
| 191 | + if ($order_postmeta['order_status'] == 'awaiting_payment') { |
|
| 192 | + $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>'; |
|
| 193 | 193 | } |
| 194 | - $credit_meta = get_post_meta( $order->ID, '_wps_order_credit', true ); |
|
| 194 | + $credit_meta = get_post_meta($order->ID, '_wps_order_credit', true); |
|
| 195 | 195 | |
| 196 | - if ( empty($credit_meta) ) { |
|
| 197 | - if( $order_postmeta['order_status'] == 'refunded') { |
|
| 198 | - $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>'; |
|
| 196 | + if (empty($credit_meta)) { |
|
| 197 | + if ($order_postmeta['order_status'] == 'refunded') { |
|
| 198 | + $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>'; |
|
| 199 | 199 | } |
| 200 | 200 | else { |
| 201 | - $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>'; |
|
| 201 | + $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>'; |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | function order_container_in_admin() { |
| 211 | 211 | global $post; |
| 212 | 212 | $output = '<div id="wps_order_content_container">'; |
| 213 | - $output .= self::order_content( $post ); |
|
| 213 | + $output .= self::order_content($post); |
|
| 214 | 214 | $output .= '</div>'; |
| 215 | 215 | echo $output; |
| 216 | 216 | } |
@@ -221,13 +221,13 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @param order $post The complete order content |
| 223 | 223 | */ |
| 224 | - function order_content( $post ) { |
|
| 224 | + function order_content($post) { |
|
| 225 | 225 | $order_content = ''; |
| 226 | 226 | |
| 227 | 227 | $order = get_post_meta($post->ID, '_order_postmeta', true); |
| 228 | 228 | |
| 229 | 229 | $order_content .= '<div id="order_product_container" class="order_product_container wpshop_cls" >'; |
| 230 | - if($order){/* Read the order content if the order has product */ |
|
| 230 | + if ($order) {/* Read the order content if the order has product */ |
|
| 231 | 231 | $order_content .= '<input type="hidden" value="" name="order_products_to_delete" id="order_products_to_delete" />' . wpshop_cart::display_cart(true, $order, 'admin'); |
| 232 | 232 | if (empty($order['order_invoice_ref'])) { |
| 233 | 233 | $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>'; |
@@ -245,18 +245,18 @@ discard block |
||
| 245 | 245 | /** Generate the billing reference regarding the order $order_id |
| 246 | 246 | * @return void |
| 247 | 247 | */ |
| 248 | - function order_generate_billing_number($order_id, $force_invoicing = false){ |
|
| 248 | + function order_generate_billing_number($order_id, $force_invoicing = false) { |
|
| 249 | 249 | global $wpdb, $wpshop_modules_billing; |
| 250 | 250 | |
| 251 | 251 | // Get the order from the db |
| 252 | 252 | $order = get_post_meta($order_id, '_order_postmeta', true); |
| 253 | 253 | |
| 254 | 254 | // If the payment is completed |
| 255 | - if(($order['order_status']=='completed') || $force_invoicing) { |
|
| 255 | + if (($order['order_status'] == 'completed') || $force_invoicing) { |
|
| 256 | 256 | |
| 257 | 257 | // If the reference hasn't been generated yet |
| 258 | - if(empty($order['order_invoice_ref'])) { |
|
| 259 | - $order['order_invoice_ref'] = $wpshop_modules_billing->generate_invoice_number( $order_id ); |
|
| 258 | + if (empty($order['order_invoice_ref'])) { |
|
| 259 | + $order['order_invoice_ref'] = $wpshop_modules_billing->generate_invoice_number($order_id); |
|
| 260 | 260 | |
| 261 | 261 | update_post_meta($order_id, '_order_postmeta', $order); |
| 262 | 262 | } |
@@ -267,45 +267,45 @@ discard block |
||
| 267 | 267 | /** Renvoi une nouvelle r�f�rence unique pour une commande |
| 268 | 268 | * @return int |
| 269 | 269 | */ |
| 270 | - public static function get_new_order_reference(){ |
|
| 270 | + public static function get_new_order_reference() { |
|
| 271 | 271 | $number_figures = get_option('wpshop_order_number_figures', false); |
| 272 | 272 | /* If the number doesn't exist, we create a default one */ |
| 273 | - if(!$number_figures){ |
|
| 273 | + if (!$number_figures) { |
|
| 274 | 274 | $number_figures = 5; |
| 275 | 275 | update_option('wpshop_order_number_figures', $number_figures); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $order_current_number = get_option('wpshop_order_current_number', false); |
| 279 | 279 | /* If the counter doesn't exist, we initiate it */ |
| 280 | - if(!$order_current_number) { $order_current_number = 1; } |
|
| 280 | + if (!$order_current_number) { $order_current_number = 1; } |
|
| 281 | 281 | else { $order_current_number++; } |
| 282 | 282 | update_option('wpshop_order_current_number', $order_current_number); |
| 283 | 283 | |
| 284 | - $order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number); |
|
| 285 | - return WPSHOP_ORDER_REFERENCE_PREFIX.$order_ref; |
|
| 284 | + $order_ref = (string)sprintf('%0' . $number_figures . 'd', $order_current_number); |
|
| 285 | + return WPSHOP_ORDER_REFERENCE_PREFIX . $order_ref; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** Renvoi une nouvelle r�f�rence unique pour un devis |
| 289 | 289 | * @return int |
| 290 | 290 | */ |
| 291 | - public static function get_new_pre_order_reference($save = true){ |
|
| 291 | + public static function get_new_pre_order_reference($save = true) { |
|
| 292 | 292 | $number_figures = get_option('wpshop_order_number_figures', false); |
| 293 | 293 | /* If the number doesn't exist, we create a default one */ |
| 294 | - if(!$number_figures){ |
|
| 294 | + if (!$number_figures) { |
|
| 295 | 295 | $number_figures = 5; |
| 296 | 296 | update_option('wpshop_order_number_figures', $number_figures); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | $order_current_number = get_option('wpshop_preorder_current_number', false); |
| 300 | 300 | /* If the counter doesn't exist, we initiate it */ |
| 301 | - if(!$order_current_number) { $order_current_number = 1; } |
|
| 301 | + if (!$order_current_number) { $order_current_number = 1; } |
|
| 302 | 302 | else { $order_current_number++; } |
| 303 | - if($save){ |
|
| 303 | + if ($save) { |
|
| 304 | 304 | update_option('wpshop_preorder_current_number', $order_current_number); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - $order_ref = (string)sprintf('%0'.$number_figures.'d', $order_current_number); |
|
| 308 | - return WPSHOP_PREORDER_REFERENCE_PREFIX.$order_ref; |
|
| 307 | + $order_ref = (string)sprintf('%0' . $number_figures . 'd', $order_current_number); |
|
| 308 | + return WPSHOP_PREORDER_REFERENCE_PREFIX . $order_ref; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -320,24 +320,24 @@ discard block |
||
| 320 | 320 | * |
| 321 | 321 | * @return void |
| 322 | 322 | */ |
| 323 | - public static function set_order_customer_addresses($user_id, $order_id, $shipping_address_id='', $billing_address_id=''){ |
|
| 323 | + public static function set_order_customer_addresses($user_id, $order_id, $shipping_address_id = '', $billing_address_id = '') { |
|
| 324 | 324 | /** Get order informations */ |
| 325 | 325 | $billing_info['id'] = get_post_meta($billing_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true); |
| 326 | - $billing_info['address'] = get_post_meta($billing_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 327 | - $billing_info['address_id'] = ( !empty($_SESSION['billing_address']) ) ? intval( $_SESSION['billing_address'] ) : ''; |
|
| 328 | - if ( !empty($_SESSION['shipping_partner_id']) ) { |
|
| 329 | - $partner_address_id = get_post_meta( $_SESSION['shipping_partner_id'], '_wpshop_attached_address', true); |
|
| 326 | + $billing_info['address'] = get_post_meta($billing_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 327 | + $billing_info['address_id'] = (!empty($_SESSION['billing_address'])) ? intval($_SESSION['billing_address']) : ''; |
|
| 328 | + if (!empty($_SESSION['shipping_partner_id'])) { |
|
| 329 | + $partner_address_id = get_post_meta($_SESSION['shipping_partner_id'], '_wpshop_attached_address', true); |
|
| 330 | 330 | if (!empty($partner_address_id)) { |
| 331 | - foreach( $partner_address_id as $address_id ) { |
|
| 331 | + foreach ($partner_address_id as $address_id) { |
|
| 332 | 332 | $shipping_info['id'] = get_post_meta($address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true); |
| 333 | - $shipping_info['address'] = get_post_meta( $address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 333 | + $shipping_info['address'] = get_post_meta($address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | else { |
| 338 | 338 | $shipping_info['id'] = get_post_meta($shipping_address_id, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, true); |
| 339 | - $shipping_info['address'] = get_post_meta($shipping_address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 340 | - $shipping_info['address_id'] = ( !empty($_SESSION['shipping_address']) ) ? intval( $_SESSION['shipping_address'] ) : ''; |
|
| 339 | + $shipping_info['address'] = get_post_meta($shipping_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 340 | + $shipping_info['address_id'] = (!empty($_SESSION['shipping_address'])) ? intval($_SESSION['shipping_address']) : ''; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $order_info = array('billing' => $billing_info, 'shipping' => $shipping_info); |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | /** Set the custom colums |
| 351 | 351 | * @return array |
| 352 | 352 | */ |
| 353 | - static function orders_edit_columns($columns){ |
|
| 353 | + static function orders_edit_columns($columns) { |
|
| 354 | 354 | $columns = array( |
| 355 | 355 | 'cb' => '<input type="checkbox" />', |
| 356 | 356 | 'order_identifier' => __('Identifiers', 'wpshop'), |
@@ -370,42 +370,42 @@ discard block |
||
| 370 | 370 | * @return array |
| 371 | 371 | */ |
| 372 | 372 | public static function orders_custom_columns($column, $post_id) { |
| 373 | - if ( get_post_type( $post_id ) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER ) { |
|
| 373 | + if (get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
|
| 374 | 374 | global $civility, $order_status; |
| 375 | 375 | |
| 376 | 376 | $metadata = get_post_custom(); |
| 377 | 377 | |
| 378 | - $order_postmeta = isset($metadata['_order_postmeta'][0])?unserialize($metadata['_order_postmeta'][0]):''; |
|
| 379 | - $addresses = get_post_meta($post_id,'_order_info', true); |
|
| 378 | + $order_postmeta = isset($metadata['_order_postmeta'][0]) ? unserialize($metadata['_order_postmeta'][0]) : ''; |
|
| 379 | + $addresses = get_post_meta($post_id, '_order_info', true); |
|
| 380 | 380 | |
| 381 | - switch($column){ |
|
| 381 | + switch ($column) { |
|
| 382 | 382 | case "order_identifier": |
| 383 | - if( !empty( $order_postmeta['order_key'] ) ) { |
|
| 383 | + if (!empty($order_postmeta['order_key'])) { |
|
| 384 | 384 | echo '<b>' . $order_postmeta['order_key'] . '</b><br>'; |
| 385 | 385 | } |
| 386 | - if( !empty( $order_postmeta['order_invoice_ref'] ) ) { |
|
| 386 | + if (!empty($order_postmeta['order_invoice_ref'])) { |
|
| 387 | 387 | echo '<i>' . $order_postmeta['order_invoice_ref'] . '</i>'; |
| 388 | - } elseif( !empty($order_postmeta['order_temporary_key'] ) ) { |
|
| 388 | + } elseif (!empty($order_postmeta['order_temporary_key'])) { |
|
| 389 | 389 | echo '<b>' . $order_postmeta['order_temporary_key'] . '</b>'; |
| 390 | 390 | } |
| 391 | 391 | break; |
| 392 | 392 | |
| 393 | 393 | case "order_status": |
| 394 | - 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'); |
|
| 394 | + 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'); |
|
| 395 | 395 | break; |
| 396 | 396 | |
| 397 | 397 | case "order_billing": |
| 398 | - if ( !empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address']) ) { |
|
| 398 | + if (!empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address'])) { |
|
| 399 | 399 | $billing = $addresses['billing']['address']; |
| 400 | 400 | } |
| 401 | - else if ( !empty($addresses['billing']) ) { |
|
| 401 | + else if (!empty($addresses['billing'])) { |
|
| 402 | 402 | $billing = $addresses['billing']; |
| 403 | 403 | } |
| 404 | - if ( !empty($billing) ) { |
|
| 405 | - 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>'; |
|
| 406 | - echo empty($billing['company'])?'<br />':', <i>'.$billing['company'].'</i><br />'; |
|
| 407 | - echo (!empty($billing['address']) ? $billing['address'] : null).'<br />'; |
|
| 408 | - echo (!empty($billing['postcode']) ? $billing['postcode'] : null).' '.(!empty($billing['city']) ? $billing['city'] : null).', '.(!empty($billing['country']) ? $billing['country'] : null); |
|
| 404 | + if (!empty($billing)) { |
|
| 405 | + 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>'; |
|
| 406 | + echo empty($billing['company']) ? '<br />' : ', <i>' . $billing['company'] . '</i><br />'; |
|
| 407 | + echo (!empty($billing['address']) ? $billing['address'] : null) . '<br />'; |
|
| 408 | + echo (!empty($billing['postcode']) ? $billing['postcode'] : null) . ' ' . (!empty($billing['city']) ? $billing['city'] : null) . ', ' . (!empty($billing['country']) ? $billing['country'] : null); |
|
| 409 | 409 | echo (!empty($billing['phone']) ? '<br />' . $billing['phone'] : ''); |
| 410 | 410 | } |
| 411 | 411 | else { |
@@ -414,33 +414,33 @@ discard block |
||
| 414 | 414 | break; |
| 415 | 415 | |
| 416 | 416 | case "order_shipping": |
| 417 | - if ( !empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address']) ) { |
|
| 417 | + if (!empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address'])) { |
|
| 418 | 418 | $shipping = $addresses['shipping']['address']; |
| 419 | 419 | } |
| 420 | - else if ( !empty($addresses['shipping']) ) { |
|
| 420 | + else if (!empty($addresses['shipping'])) { |
|
| 421 | 421 | $shipping = $addresses['shipping']; |
| 422 | 422 | } |
| 423 | - if ( !empty($shipping) ) { |
|
| 424 | - echo '<strong>'.(!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null).' '.(!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null).'</strong>'; |
|
| 425 | - echo empty($shipping['company'])?'<br />':', <i>'.$shipping['company'].'</i><br />'; |
|
| 426 | - echo (!empty($shipping['address']) ? $shipping['address'] : null).'<br />'; |
|
| 427 | - echo (!empty($shipping['postcode']) ? $shipping['postcode'] : null).' '.(!empty($shipping['city']) ? $shipping['city'] : null).', '.(!empty($shipping['country']) ? $shipping['country'] : null); |
|
| 423 | + if (!empty($shipping)) { |
|
| 424 | + echo '<strong>' . (!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null) . ' ' . (!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null) . '</strong>'; |
|
| 425 | + echo empty($shipping['company']) ? '<br />' : ', <i>' . $shipping['company'] . '</i><br />'; |
|
| 426 | + echo (!empty($shipping['address']) ? $shipping['address'] : null) . '<br />'; |
|
| 427 | + echo (!empty($shipping['postcode']) ? $shipping['postcode'] : null) . ' ' . (!empty($shipping['city']) ? $shipping['city'] : null) . ', ' . (!empty($shipping['country']) ? $shipping['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,55 +607,55 @@ 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 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | /** |
| 125 | 125 | * Build an array with the different items to add to an order |
| 126 | 126 | * |
| 127 | - * @param array $products The item list to add to the order |
|
| 127 | + * @param array $product The item list to add to the order |
|
| 128 | 128 | * |
| 129 | 129 | * @return array $item_list The item to add to order |
| 130 | 130 | */ |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * @method wps_token_order_customer |
| 420 | 420 | * @param int $order_id OrderID. |
| 421 | - * @return mixed sha1 or false. |
|
| 421 | + * @return false|string sha1 or false. |
|
| 422 | 422 | */ |
| 423 | 423 | public static function wps_token_order_customer( $order_id ) { |
| 424 | 424 | $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
@@ -346,7 +346,7 @@ |
||
| 346 | 346 | $_SESSION['billing_address'] = $order_info['billing']['address_id']; |
| 347 | 347 | $_SESSION['cart'] = $order_meta; |
| 348 | 348 | $_SESSION['cart']['order_id'] = $order_id; |
| 349 | - $_SESSION['cart']['cart_type'] = 'cart'; |
|
| 349 | + $_SESSION['cart']['cart_type'] = 'cart'; |
|
| 350 | 350 | $_SESSION['cart']['order_shipping_cost_fixe'] = 'on'; |
| 351 | 351 | $permalink = get_permalink( get_option( 'wpshop_cart_page_id' ) ) . '?order_step=5'; |
| 352 | 352 | } else { |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) { exit; |
|
| 2 | 2 | } |
| 3 | 3 | class wps_orders_ctr { |
| 4 | 4 | |
@@ -20,24 +20,24 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | /** Template Load */ |
| 22 | 22 | // add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) ); |
| 23 | - add_shortcode( 'order_customer_informations', array( &$this, 'display_order_customer_informations' ) ); |
|
| 24 | - add_shortcode( 'wps_orders_in_customer_account', array( $this, 'display_orders_in_account' ) ); |
|
| 25 | - add_action( 'wp_enqueue_scripts', array( $this, 'wps_orders_scripts' ) ); |
|
| 23 | + add_shortcode('order_customer_informations', array(&$this, 'display_order_customer_informations')); |
|
| 24 | + add_shortcode('wps_orders_in_customer_account', array($this, 'display_orders_in_account')); |
|
| 25 | + add_action('wp_enqueue_scripts', array($this, 'wps_orders_scripts')); |
|
| 26 | 26 | /** Include the different javascript */ |
| 27 | - add_action( 'admin_init', array( &$this, 'admin_js' ) ); |
|
| 27 | + add_action('admin_init', array(&$this, 'admin_js')); |
|
| 28 | 28 | |
| 29 | 29 | /** Ajax Actions */ |
| 30 | 30 | // add_action( 'wp_ajax_wps_add_product_to_quotation', array( &$this, 'wps_add_product_to_quotation') ); |
| 31 | 31 | // add_action( 'wap_ajax_wps_change_product_list', array( &$this, 'wps_change_product_list') ); |
| 32 | 32 | // add_action( 'wap_ajax_wps_orders_load_variations_container', array( &$this, 'wps_orders_load_variations_container') ); |
| 33 | 33 | // add_action( 'wap_ajax_wps_order_refresh_in_admin', array( &$this, 'wps_order_refresh_in_admin') ); |
| 34 | - add_action( 'wp_ajax_wps_orders_load_details', array( $this, 'wps_orders_load_details' ) ); |
|
| 34 | + add_action('wp_ajax_wps_orders_load_details', array($this, 'wps_orders_load_details')); |
|
| 35 | 35 | // Add a product sale historic in administration product panel |
| 36 | - add_action( 'wp_ajax_wps_order_choose_customer', array( $this, 'wps_order_choose_customer' ) ); |
|
| 36 | + add_action('wp_ajax_wps_order_choose_customer', array($this, 'wps_order_choose_customer')); |
|
| 37 | 37 | /** For delete order */ |
| 38 | - add_action( 'wp_ajax_wps_delete_order', array( $this, 'wps_delete_order' ) ); |
|
| 38 | + add_action('wp_ajax_wps_delete_order', array($this, 'wps_delete_order')); |
|
| 39 | 39 | /** Invoice Page */ |
| 40 | - add_action( 'admin_post_wps_invoice', array( $this, 'wps_invoice_output' ) ); |
|
| 40 | + add_action('admin_post_wps_invoice', array($this, 'wps_invoice_output')); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function wps_orders_scripts() { |
| 56 | 56 | |
| 57 | - wp_enqueue_script( 'wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js' ); |
|
| 57 | + wp_enqueue_script('wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | function display_order_customer_informations() { |
@@ -62,23 +62,23 @@ discard block |
||
| 62 | 62 | global $post_id; |
| 63 | 63 | global $wpdb; |
| 64 | 64 | $output = ''; |
| 65 | - if ( ! empty( $post_id ) ) { |
|
| 66 | - $order_postmeta = get_post_meta( $post_id, '_order_postmeta', true ); |
|
| 67 | - $order_info = get_post_meta( $post_id, '_order_info', true ); |
|
| 65 | + if (!empty($post_id)) { |
|
| 66 | + $order_postmeta = get_post_meta($post_id, '_order_postmeta', true); |
|
| 67 | + $order_info = get_post_meta($post_id, '_order_info', true); |
|
| 68 | 68 | /** Check the order status */ |
| 69 | - if ( ! empty( $order_postmeta ) ) { |
|
| 70 | - if ( ! empty( $order_postmeta['order_status'] ) && $order_postmeta['order_status'] != 'awaiting_payment' ) { |
|
| 71 | - $output = wps_address::display_an_address( $order_info['billing']['address'] ); |
|
| 72 | - $output .= wps_address::display_an_address( $order_info['shipping']['address'] ); |
|
| 69 | + if (!empty($order_postmeta)) { |
|
| 70 | + if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] != 'awaiting_payment') { |
|
| 71 | + $output = wps_address::display_an_address($order_info['billing']['address']); |
|
| 72 | + $output .= wps_address::display_an_address($order_info['shipping']['address']); |
|
| 73 | 73 | } else { |
| 74 | - $output = wps_address::display_an_address( $order_info['billing']['address'] ); |
|
| 74 | + $output = wps_address::display_an_address($order_info['billing']['address']); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } else { |
| 78 | 78 | /** Display "Choose customer or create one" Interface */ |
| 79 | 79 | $tpl_component = array(); |
| 80 | 80 | $args = array( |
| 81 | - 'show_option_all' => __( 'Choose a customer', 'wpshop' ), |
|
| 81 | + 'show_option_all' => __('Choose a customer', 'wpshop'), |
|
| 82 | 82 | 'orderby' => 'display_name', |
| 83 | 83 | 'order' => 'ASC', |
| 84 | 84 | 'include' => null, // string |
@@ -92,10 +92,10 @@ discard block |
||
| 92 | 92 | 'id' => null, // integer |
| 93 | 93 | 'class' => 'chosen_select', // string |
| 94 | 94 | 'blog_id' => $GLOBALS['blog_id'], |
| 95 | - 'who' => null,// string |
|
| 95 | + 'who' => null, // string |
|
| 96 | 96 | ); |
| 97 | - $tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users( $args ); |
|
| 98 | - $output = wpshop_display::display_template_element( 'wps_orders_choose_customer_interface', $tpl_component, array(), 'admin' ); |
|
| 97 | + $tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users($args); |
|
| 98 | + $output = wpshop_display::display_template_element('wps_orders_choose_customer_interface', $tpl_component, array(), 'admin'); |
|
| 99 | 99 | } |
| 100 | 100 | return $output; |
| 101 | 101 | } |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @param integer $customer_id |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - function display_orders_in_account( $customer_id = '' ) { |
|
| 109 | + function display_orders_in_account($customer_id = '') { |
|
| 110 | 110 | |
| 111 | 111 | $output = ''; |
| 112 | - $customer_id = ( ! empty( $customer_id ) ) ? $customer_id : get_current_user_id(); |
|
| 113 | - $from_admin = ( ! empty( $customer_id ) ) ? true : false; |
|
| 112 | + $customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
| 113 | + $from_admin = (!empty($customer_id)) ? true : false; |
|
| 114 | 114 | $wps_orders_mdl = new wps_orders_mdl(); |
| 115 | - $orders = $wps_orders_mdl->get_customer_orders( $customer_id ); |
|
| 115 | + $orders = $wps_orders_mdl->get_customer_orders($customer_id); |
|
| 116 | 116 | // Display orders |
| 117 | 117 | ob_start(); |
| 118 | - require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'orders_list_in_account' ) ); |
|
| 118 | + require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'orders_list_in_account')); |
|
| 119 | 119 | $output = ob_get_contents(); |
| 120 | 120 | ob_end_clean(); |
| 121 | 121 | return $output; |
@@ -128,102 +128,102 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return array $item_list The item to add to order |
| 130 | 130 | */ |
| 131 | - function add_product_to_order( $product ) { |
|
| 131 | + function add_product_to_order($product) { |
|
| 132 | 132 | |
| 133 | 133 | global $wpdb; |
| 134 | - if ( ! empty( $product ) && empty( $product['price_ttc_before_discount'] ) && empty( $product['price_ht_before_discount'] ) ) { |
|
| 135 | - $price_infos = wpshop_prices::check_product_price( $product, true ); |
|
| 136 | - $product['price_ht'] = ( ! empty( $price_infos['discount'] ) && ! empty( $price_infos['discount']['discount_exist'] ) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et']; |
|
| 137 | - $product['product_price'] = ( ! empty( $price_infos['discount'] ) && ! empty( $price_infos['discount']['discount_exist'] ) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati']; |
|
| 138 | - $product['tva'] = ( ! empty( $price_infos['discount'] ) && ! empty( $price_infos['discount']['discount_exist'] ) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva']; |
|
| 134 | + if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) { |
|
| 135 | + $price_infos = wpshop_prices::check_product_price($product, true); |
|
| 136 | + $product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et']; |
|
| 137 | + $product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati']; |
|
| 138 | + $product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva']; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 142 | - if ( ! empty( $price_piloting ) && $price_piloting == 'HT' ) { |
|
| 141 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 142 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 143 | 143 | $total_ht = $product['price_ht'] * $product['product_qty']; |
| 144 | - $tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 ); |
|
| 144 | + $tva_total_amount = $total_ht * ($product['tx_tva'] / 100); |
|
| 145 | 145 | $total_ttc = $total_ht + $tva_total_amount; |
| 146 | 146 | } else { |
| 147 | 147 | $total_ttc = $product['product_price'] * $product['product_qty']; |
| 148 | - $total_ht = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) ); |
|
| 148 | + $total_ht = $total_ttc / (1 + ($product['tx_tva'] / 100)); |
|
| 149 | 149 | $tva_total_amount = $total_ttc - $total_ht; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $tva = ! empty( $product[ WPSHOP_PRODUCT_PRICE_TAX ] ) ? $product[ WPSHOP_PRODUCT_PRICE_TAX ] : null; |
|
| 152 | + $tva = !empty($product[WPSHOP_PRODUCT_PRICE_TAX]) ? $product[WPSHOP_PRODUCT_PRICE_TAX] : null; |
|
| 153 | 153 | $item_discount_type = $item_discount_value = $item_discount_amount = 0; |
| 154 | - $d_amount = ! empty( $product ) && ! empty( $product['discount_amount'] ) ? wpshop_tools::formate_number( $product['discount_amount'] ) : null; |
|
| 155 | - $d_rate = ! empty( $product ) && ! empty( $product['discount_rate'] ) ? wpshop_tools::formate_number( $product['discount_rate'] ) : null; |
|
| 156 | - $d_special = ! empty( $product ) && ! empty( $product['special_price'] ) ? wpshop_tools::formate_number( $product['special_price'] ) : null; |
|
| 157 | - if ( ! empty( $d_amount ) ) { |
|
| 154 | + $d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null; |
|
| 155 | + $d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null; |
|
| 156 | + $d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null; |
|
| 157 | + if (!empty($d_amount)) { |
|
| 158 | 158 | $item_discount_type = 'discount_amount'; |
| 159 | 159 | $item_discount_amount = $product['discount_amount']; |
| 160 | 160 | $item_discount_value = $product['discount_amount']; |
| 161 | - } elseif ( ! empty( $d_rate ) ) { |
|
| 161 | + } elseif (!empty($d_rate)) { |
|
| 162 | 162 | $item_discount_type = 'discount_rate'; |
| 163 | 163 | $item_discount_amount = $product['discount_rate']; |
| 164 | 164 | $item_discount_value = $product['discount_rate']; |
| 165 | - } elseif ( ! empty( $d_special ) ) { |
|
| 165 | + } elseif (!empty($d_special)) { |
|
| 166 | 166 | $item_discount_type = 'special_price'; |
| 167 | 167 | $item_discount_amount = $product['special_price']; |
| 168 | 168 | $item_discount_value = $product['special_price']; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $item = array( 'item_id' => $product['product_id'], 'item_ref' => ! empty( $product['product_reference'] ) ? $product['product_reference'] : null, 'item_name' => ! empty( $product['product_name'] ) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => ! empty( $product['item_meta'] ) ? $product['item_meta'] : array() ); |
|
| 172 | - $array_not_to_do = array( WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations' ); |
|
| 173 | - if ( ! empty( $product['item_meta'] ) ) { |
|
| 174 | - foreach ( $product['item_meta'] as $key => $value ) { |
|
| 175 | - if ( ! isset( $item[ 'item_' . $key ] ) && ! in_array( $key, $array_not_to_do ) && ! empty( $product[ $key ] ) ) { |
|
| 176 | - $item[ 'item_' . $key ] = $product[ $key ]; |
|
| 171 | + $item = array('item_id' => $product['product_id'], 'item_ref' => !empty($product['product_reference']) ? $product['product_reference'] : null, 'item_name' => !empty($product['product_name']) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array()); |
|
| 172 | + $array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations'); |
|
| 173 | + if (!empty($product['item_meta'])) { |
|
| 174 | + foreach ($product['item_meta'] as $key => $value) { |
|
| 175 | + if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) { |
|
| 176 | + $item['item_' . $key] = $product[$key]; |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** Check if it's a variation product */ |
| 182 | - if ( ! empty( $product ) && ! empty( $product['item_meta'] ) && ! empty( $product['item_meta']['variations'] ) ) { |
|
| 183 | - foreach ( $product['item_meta']['variations'] as $k => $variation ) { |
|
| 184 | - $product_variation_def = get_post_meta( $k, '_wpshop_variations_attribute_def', true ); |
|
| 185 | - if ( ! empty( $product_variation_def ) ) { |
|
| 186 | - foreach ( $product_variation_def as $attribute_code => $variation_id ) { |
|
| 187 | - $variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' ); |
|
| 188 | - if ( ! empty( $variation_attribute_def ) ) { |
|
| 189 | - $item['item_meta']['variation_definition'][ $attribute_code ]['NAME'] = $variation_attribute_def->frontend_label; |
|
| 190 | - if ( $variation_attribute_def->data_type_to_use == 'custom' ) { |
|
| 191 | - $query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id ); |
|
| 192 | - $variation_name = $wpdb->get_var( $query ); |
|
| 182 | + if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) { |
|
| 183 | + foreach ($product['item_meta']['variations'] as $k => $variation) { |
|
| 184 | + $product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true); |
|
| 185 | + if (!empty($product_variation_def)) { |
|
| 186 | + foreach ($product_variation_def as $attribute_code => $variation_id) { |
|
| 187 | + $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code'); |
|
| 188 | + if (!empty($variation_attribute_def)) { |
|
| 189 | + $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label; |
|
| 190 | + if ($variation_attribute_def->data_type_to_use == 'custom') { |
|
| 191 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id); |
|
| 192 | + $variation_name = $wpdb->get_var($query); |
|
| 193 | 193 | } else { |
| 194 | - $variation_post = get_post( $variation_id ); |
|
| 194 | + $variation_post = get_post($variation_id); |
|
| 195 | 195 | $variation_name = $variation_post->post_title; |
| 196 | 196 | } |
| 197 | - $item['item_meta']['variation_definition'][ $attribute_code ]['UNSTYLED_VALUE'] = $variation_name; |
|
| 198 | - $item['item_meta']['variation_definition'][ $attribute_code ]['VALUE'] = $variation_name; |
|
| 197 | + $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name; |
|
| 198 | + $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name; |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | } else { |
| 204 | 204 | /** Check if it's product with one variation */ |
| 205 | - $product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true ); |
|
| 206 | - if ( ! empty( $product_variation_def ) ) { |
|
| 207 | - foreach ( $product_variation_def as $attribute_code => $variation_id ) { |
|
| 208 | - $variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' ); |
|
| 209 | - if ( ! empty( $variation_attribute_def ) ) { |
|
| 210 | - $item['item_meta']['variation_definition'][ $attribute_code ]['NAME'] = $variation_attribute_def->frontend_label; |
|
| 211 | - if ( $variation_attribute_def->data_type_to_use == 'custom' ) { |
|
| 212 | - $query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id ); |
|
| 213 | - $variation_name = $wpdb->get_var( $query ); |
|
| 205 | + $product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true); |
|
| 206 | + if (!empty($product_variation_def)) { |
|
| 207 | + foreach ($product_variation_def as $attribute_code => $variation_id) { |
|
| 208 | + $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code'); |
|
| 209 | + if (!empty($variation_attribute_def)) { |
|
| 210 | + $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label; |
|
| 211 | + if ($variation_attribute_def->data_type_to_use == 'custom') { |
|
| 212 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id); |
|
| 213 | + $variation_name = $wpdb->get_var($query); |
|
| 214 | 214 | } else { |
| 215 | - $variation_post = get_post( $variation_id ); |
|
| 215 | + $variation_post = get_post($variation_id); |
|
| 216 | 216 | $variation_name = $variation_post->post_title; |
| 217 | 217 | } |
| 218 | - $item['item_meta']['variation_definition'][ $attribute_code ]['UNSTYLED_VALUE'] = $variation_name; |
|
| 219 | - $item['item_meta']['variation_definition'][ $attribute_code ]['VALUE'] = $variation_name; |
|
| 218 | + $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name; |
|
| 219 | + $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name; |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** On ajoute la possibilité d'étendre les données produits ajoutées dans le panier / Add possibility to extends product data saved into cart */ |
| 226 | - $item = apply_filters( 'wpshop-add-product-to-order', $item, $product ); |
|
| 226 | + $item = apply_filters('wpshop-add-product-to-order', $item, $product); |
|
| 227 | 227 | return $item; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -232,40 +232,40 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | function wps_invoice_output() { |
| 234 | 234 | |
| 235 | - $order_id = ( ! empty( $_GET['order_id'] )) ? (int) $_GET['order_id'] : null; |
|
| 236 | - $invoice_ref = ( ! empty( $_GET['invoice_ref'] )) ? sanitize_text_field( $_GET['invoice_ref'] ) : null; |
|
| 237 | - $mode = ( ! empty( $_GET['mode'] )) ? sanitize_text_field( $_GET['mode'] ) : 'html'; |
|
| 238 | - $is_credit_slip = ( ! empty( $_GET['credit_slip'] )) ? sanitize_text_field( $_GET['credit_slip'] ) : null; |
|
| 235 | + $order_id = (!empty($_GET['order_id'])) ? (int)$_GET['order_id'] : null; |
|
| 236 | + $invoice_ref = (!empty($_GET['invoice_ref'])) ? sanitize_text_field($_GET['invoice_ref']) : null; |
|
| 237 | + $mode = (!empty($_GET['mode'])) ? sanitize_text_field($_GET['mode']) : 'html'; |
|
| 238 | + $is_credit_slip = (!empty($_GET['credit_slip'])) ? sanitize_text_field($_GET['credit_slip']) : null; |
|
| 239 | 239 | $user_id = get_current_user_id(); |
| 240 | - if ( ! empty( $order_id ) && $user_id != 0 ) { |
|
| 240 | + if (!empty($order_id) && $user_id != 0) { |
|
| 241 | 241 | /** Order reading */ |
| 242 | - $order_postmeta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 242 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 243 | 243 | /** Start invoice display */ |
| 244 | - if ( ! empty( $is_credit_slip ) ) { |
|
| 245 | - $html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref, 'credit_slip' ); |
|
| 244 | + if (!empty($is_credit_slip)) { |
|
| 245 | + $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref, 'credit_slip'); |
|
| 246 | 246 | } else { |
| 247 | - $html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref ); |
|
| 247 | + $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - if ( $mode == 'pdf' ) { |
|
| 251 | - require_once( WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php' ); |
|
| 250 | + if ($mode == 'pdf') { |
|
| 251 | + require_once(WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'); |
|
| 252 | 252 | try { |
| 253 | 253 | // $html_content = wpshop_display::display_template_element('invoice_print_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
| 254 | - $html_content = wpshop_display::display_template_element( 'invoice_page_content_css', array(), array(), 'common' ) . '<page>' . $html_content . '</page>'; |
|
| 255 | - $html2pdf = new HTML2PDF( 'P', 'A4', 'fr' ); |
|
| 256 | - $html2pdf->setDefaultFont( 'Arial' ); |
|
| 257 | - $html2pdf->writeHTML( $html_content ); |
|
| 258 | - $html2pdf->Output( 'order_' . $order_id . '.pdf', 'D' ); |
|
| 254 | + $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
|
| 255 | + $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
|
| 256 | + $html2pdf->setDefaultFont('Arial'); |
|
| 257 | + $html2pdf->writeHTML($html_content); |
|
| 258 | + $html2pdf->Output('order_' . $order_id . '.pdf', 'D'); |
|
| 259 | 259 | } catch (HTML2PDF_exception $e) { |
| 260 | 260 | echo $e; |
| 261 | 261 | exit; |
| 262 | 262 | } |
| 263 | 263 | } else { |
| 264 | - $order_invoice_ref = ( ! empty( $order_postmeta['order_invoice_ref'] ) ) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 265 | - $tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element( 'invoice_page_content_css', array(), array(), 'common' ); |
|
| 264 | + $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 265 | + $tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common'); |
|
| 266 | 266 | $tpl_component['INVOICE_MAIN_PAGE'] = $html_content; |
| 267 | - $tpl_component['INVOICE_TITLE_PAGE'] = sprintf( __( 'Invoice %1$s for order %3$s (#%2$s)', 'wpshop' ), $order_invoice_ref, $order_id, $order_postmeta['order_key'] ); |
|
| 268 | - echo wpshop_display::display_template_element( 'invoice_page', $tpl_component, array(), 'common' ); |
|
| 267 | + $tpl_component['INVOICE_TITLE_PAGE'] = sprintf(__('Invoice %1$s for order %3$s (#%2$s)', 'wpshop'), $order_invoice_ref, $order_id, $order_postmeta['order_key']); |
|
| 268 | + echo wpshop_display::display_template_element('invoice_page', $tpl_component, array(), 'common'); |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | die(); |
@@ -277,21 +277,21 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function wps_orders_load_details() { |
| 279 | 279 | |
| 280 | - check_ajax_referer( 'wps_orders_load_details' ); |
|
| 281 | - $order_id = ( ! empty( $_POST['order_id'] ) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : ''; |
|
| 280 | + check_ajax_referer('wps_orders_load_details'); |
|
| 281 | + $order_id = (!empty($_POST['order_id'])) ? wpshop_tools::varSanitizer($_POST['order_id']) : ''; |
|
| 282 | 282 | $user_id = get_current_user_id(); |
| 283 | 283 | $status = false; |
| 284 | 284 | $result = ''; |
| 285 | - if ( ! empty( $order_id ) ) { |
|
| 286 | - $order = get_post( $order_id ); |
|
| 287 | - $order_infos = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 288 | - $order_key = ( ! empty( $order_infos['order_key'] ) ) ? $order_infos['order_key'] : '-'; |
|
| 289 | - if ( ! empty( $order ) && ! empty( $user_id ) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id ) { |
|
| 290 | - $result = do_shortcode( '[wps_cart cart_type="summary" oid="' . $order_id . '"]' ); |
|
| 285 | + if (!empty($order_id)) { |
|
| 286 | + $order = get_post($order_id); |
|
| 287 | + $order_infos = get_post_meta($order_id, '_order_postmeta', true); |
|
| 288 | + $order_key = (!empty($order_infos['order_key'])) ? $order_infos['order_key'] : '-'; |
|
| 289 | + if (!empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id) { |
|
| 290 | + $result = do_shortcode('[wps_cart cart_type="summary" oid="' . $order_id . '"]'); |
|
| 291 | 291 | $status = true; |
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | - echo json_encode( array( 'status' => $status, 'title' => sprintf( __( 'Order n° %s details', 'wpshop' ), $order_key ), 'content' => $result ) ); |
|
| 294 | + echo json_encode(array('status' => $status, 'title' => sprintf(__('Order n° %s details', 'wpshop'), $order_key), 'content' => $result)); |
|
| 295 | 295 | wp_die(); |
| 296 | 296 | } |
| 297 | 297 | |
@@ -300,60 +300,60 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | function wps_order_choose_customer() { |
| 302 | 302 | |
| 303 | - $_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 304 | - if ( ! wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) ) { |
|
| 303 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 304 | + if (!wp_verify_nonce($_wpnonce, 'wps_order_choose_customer')) { |
|
| 305 | 305 | wp_die(); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | $status = false; |
| 309 | 309 | $billing_data = $shipping_data = ''; |
| 310 | - $customer_id = ( ! empty( $_POST['customer_id'] ) ) ? intval( $_POST['customer_id'] ): null; |
|
| 311 | - if ( ! empty( $customer_id ) ) { |
|
| 310 | + $customer_id = (!empty($_POST['customer_id'])) ? intval($_POST['customer_id']) : null; |
|
| 311 | + if (!empty($customer_id)) { |
|
| 312 | 312 | $wps_address = new wps_address(); |
| 313 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 314 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 313 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 314 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 315 | 315 | $billing_option = $billing_option['choice']; |
| 316 | - $customer_addresses_list = wps_address::get_addresses_list( $customer_id ); |
|
| 316 | + $customer_addresses_list = wps_address::get_addresses_list($customer_id); |
|
| 317 | 317 | $status = true; |
| 318 | - $billing_data = '<div class="wps-alert-info">' . sprintf( __( 'No Billing address created, <a href="%s" title="' . __( 'Create a new billing address', 'wpshop' ) . '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ) . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600' ) . '</div>'; |
|
| 319 | - if ( ! empty( $shipping_option ) && ! empty( $shipping_option['activate'] ) ) { |
|
| 318 | + $billing_data = '<div class="wps-alert-info">' . sprintf(__('No Billing address created, <a href="%s" title="' . __('Create a new billing address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600') . '</div>'; |
|
| 319 | + if (!empty($shipping_option) && !empty($shipping_option['activate'])) { |
|
| 320 | 320 | $shipping_option = $shipping_option['choice']; |
| 321 | - $shipping_data = '<div class="wps-alert-info">' . sprintf( __( 'No shipping address created, <a href="%s" title="' . __( 'Create a new shipping address', 'wpshop' ) . '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ) . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600' ) . '</div>'; |
|
| 321 | + $shipping_data = '<div class="wps-alert-info">' . sprintf(__('No shipping address created, <a href="%s" title="' . __('Create a new shipping address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600') . '</div>'; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if ( ! empty( $customer_addresses_list ) ) { |
|
| 325 | - foreach ( $customer_addresses_list as $address_type => $customer_addresses ) { |
|
| 326 | - if ( $billing_option == $address_type ) { |
|
| 327 | - $billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type ); |
|
| 324 | + if (!empty($customer_addresses_list)) { |
|
| 325 | + foreach ($customer_addresses_list as $address_type => $customer_addresses) { |
|
| 326 | + if ($billing_option == $address_type) { |
|
| 327 | + $billing_data = $wps_address->display_address_in_administration($customer_addresses, $address_type); |
|
| 328 | 328 | } else { |
| 329 | - $shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type ); |
|
| 329 | + $shipping_data = $wps_address->display_address_in_administration($customer_addresses, $address_type); |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | - echo json_encode( array( 'status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data ) ); |
|
| 334 | + echo json_encode(array('status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data)); |
|
| 335 | 335 | wp_die(); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - static function pay_quotation( $order_id ) { |
|
| 338 | + static function pay_quotation($order_id) { |
|
| 339 | 339 | |
| 340 | 340 | $status = true; |
| 341 | - $order_id = (int) $order_id; |
|
| 342 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 343 | - $order_info = get_post_meta( $order_id, '_order_info', true ); |
|
| 344 | - $_SESSION['shipping_method'] = isset( $order_meta['order_payment']['shipping_method'] ) ? $order_meta['order_payment']['shipping_method'] : 'No Shipping method required'; |
|
| 345 | - if ( isset( $order_info['billing']['address_id'] ) ) { |
|
| 341 | + $order_id = (int)$order_id; |
|
| 342 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 343 | + $order_info = get_post_meta($order_id, '_order_info', true); |
|
| 344 | + $_SESSION['shipping_method'] = isset($order_meta['order_payment']['shipping_method']) ? $order_meta['order_payment']['shipping_method'] : 'No Shipping method required'; |
|
| 345 | + if (isset($order_info['billing']['address_id'])) { |
|
| 346 | 346 | $_SESSION['billing_address'] = $order_info['billing']['address_id']; |
| 347 | 347 | $_SESSION['cart'] = $order_meta; |
| 348 | 348 | $_SESSION['cart']['order_id'] = $order_id; |
| 349 | 349 | $_SESSION['cart']['cart_type'] = 'cart'; |
| 350 | 350 | $_SESSION['cart']['order_shipping_cost_fixe'] = 'on'; |
| 351 | - $permalink = get_permalink( get_option( 'wpshop_cart_page_id' ) ) . '?order_step=5'; |
|
| 351 | + $permalink = get_permalink(get_option('wpshop_cart_page_id')) . '?order_step=5'; |
|
| 352 | 352 | } else { |
| 353 | - $status = self::add_order_to_session( $order_id ); |
|
| 354 | - $permalink = get_permalink( wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ) ); |
|
| 353 | + $status = self::add_order_to_session($order_id); |
|
| 354 | + $permalink = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))); |
|
| 355 | 355 | } |
| 356 | - return array( 'status' => $status, 'permalink' => $permalink ); |
|
| 356 | + return array('status' => $status, 'permalink' => $permalink); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -362,54 +362,54 @@ discard block |
||
| 362 | 362 | * @method add_order_to_session |
| 363 | 363 | * @param int $order_id Id of order. |
| 364 | 364 | */ |
| 365 | - public static function add_order_to_session( $order_id ) { |
|
| 365 | + public static function add_order_to_session($order_id) { |
|
| 366 | 366 | |
| 367 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 368 | - if ( $order_meta != false ) { |
|
| 367 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 368 | + if ($order_meta != false) { |
|
| 369 | 369 | $_SESSION['cart'] = array(); |
| 370 | 370 | $_SESSION['cart']['order_amount_to_pay_now'] = $order_meta['order_amount_to_pay_now']; |
| 371 | 371 | $_SESSION['cart']['order_items'] = array(); |
| 372 | - if ( ! empty( $order_meta ) && ! empty( $order_meta['order_items'] ) ) { |
|
| 372 | + if (!empty($order_meta) && !empty($order_meta['order_items'])) { |
|
| 373 | 373 | $wpshop_cart_type = 'cart'; |
| 374 | - foreach ( $order_meta['order_items'] as $item ) { |
|
| 375 | - $_SESSION['cart']['order_items'][ $item['item_id'] ] = $item; |
|
| 374 | + foreach ($order_meta['order_items'] as $item) { |
|
| 375 | + $_SESSION['cart']['order_items'][$item['item_id']] = $item; |
|
| 376 | 376 | } |
| 377 | 377 | $wps_cart_ctr = new wps_cart(); |
| 378 | - $order = $wps_cart_ctr->calcul_cart_information( array() ); |
|
| 379 | - $wps_cart_ctr->store_cart_in_session( $order ); |
|
| 378 | + $order = $wps_cart_ctr->calcul_cart_information(array()); |
|
| 379 | + $wps_cart_ctr->store_cart_in_session($order); |
|
| 380 | 380 | } |
| 381 | 381 | $_SESSION['order_id'] = $order_id; |
| 382 | 382 | } |
| 383 | - return (bool) ($order_meta != false); |
|
| 383 | + return (bool)($order_meta != false); |
|
| 384 | 384 | } |
| 385 | 385 | /** |
| 386 | 386 | * AJAX - Delete order by order_id |
| 387 | 387 | */ |
| 388 | 388 | public function wps_delete_order() { |
| 389 | 389 | |
| 390 | - $_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 391 | - if ( ! wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) ) { |
|
| 390 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 391 | + if (!wp_verify_nonce($_wpnonce, 'wps_delete_order')) { |
|
| 392 | 392 | wp_die(); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | $status = false; |
| 396 | 396 | $output = ''; |
| 397 | - $order_id = ! empty( $_POST['order_id'] ) ? (int) $_POST['order_id'] : 0; |
|
| 398 | - if ( $order_id ) { |
|
| 399 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 397 | + $order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : 0; |
|
| 398 | + if ($order_id) { |
|
| 399 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 400 | 400 | $wps_credit = new wps_credit(); |
| 401 | - $wps_credit->create_an_credit( $order_id ); |
|
| 401 | + $wps_credit->create_an_credit($order_id); |
|
| 402 | 402 | $order_meta['order_status'] = 'canceled'; |
| 403 | - $order_meta['order_payment']['refunded_action']['refunded_date'] = current_time( 'mysql', 0 ); |
|
| 403 | + $order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0); |
|
| 404 | 404 | $order_meta['order_payment']['refunded_action']['author'] = get_current_user_id(); |
| 405 | - update_post_meta( $order_id, '_order_postmeta', $order_meta ); |
|
| 405 | + update_post_meta($order_id, '_order_postmeta', $order_meta); |
|
| 406 | 406 | ob_start(); |
| 407 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'order_row_in_account' ) ); |
|
| 407 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'order_row_in_account')); |
|
| 408 | 408 | $output = ob_get_contents(); |
| 409 | 409 | ob_end_clean(); |
| 410 | 410 | $status = true; |
| 411 | 411 | } |
| 412 | - echo json_encode( array( 'status' => $status, 'row' => $output ) ); |
|
| 412 | + echo json_encode(array('status' => $status, 'row' => $output)); |
|
| 413 | 413 | wp_die(); |
| 414 | 414 | } |
| 415 | 415 | |
@@ -420,11 +420,11 @@ discard block |
||
| 420 | 420 | * @param int $order_id OrderID. |
| 421 | 421 | * @return mixed sha1 or false. |
| 422 | 422 | */ |
| 423 | - public static function wps_token_order_customer( $order_id ) { |
|
| 424 | - $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 425 | - if ( ! isset( $order_metadata['customer_id'] ) ) { |
|
| 423 | + public static function wps_token_order_customer($order_id) { |
|
| 424 | + $order_metadata = get_post_meta($order_id, '_order_postmeta', true); |
|
| 425 | + if (!isset($order_metadata['customer_id'])) { |
|
| 426 | 426 | return false; |
| 427 | 427 | } |
| 428 | - return sha1( site_url() . '_' . $order_id . '_' . $order_metadata['customer_id'] . '_' . date( 'ym' ) ); |
|
| 428 | + return sha1(site_url() . '_' . $order_id . '_' . $order_metadata['customer_id'] . '_' . date('ym')); |
|
| 429 | 429 | } |
| 430 | 430 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | /* Check if file is include. No direct access possible with file url */ |
| 4 | -if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
| 5 | - die( __('Access is not allowed by this way', 'wpshop') ); |
|
| 4 | +if (!defined('WPSHOP_VERSION')) { |
|
| 5 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | /** Constructor of the class |
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | - function __construct () { |
|
| 28 | + function __construct() { |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - public static function process_checkout($paymentMethod='paypal', $order_id = 0, $customer_id = 0, $customer_billing_address_id = 0, $customer_shipping_address_id = 0) { |
|
| 32 | + public static function process_checkout($paymentMethod = 'paypal', $order_id = 0, $customer_id = 0, $customer_billing_address_id = 0, $customer_shipping_address_id = 0) { |
|
| 33 | 33 | |
| 34 | 34 | global $wpdb, $wpshop, $wpshop_cart; |
| 35 | 35 | $wps_message = new wps_message_ctr(); |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | if (is_user_logged_in()) : |
| 39 | 39 | $user_id = get_current_user_id(); |
| 40 | 40 | |
| 41 | - if ( $customer_id != 0 ) { |
|
| 41 | + if ($customer_id != 0) { |
|
| 42 | 42 | $user_id = $customer_id; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // If the order is already created in the db |
| 46 | - if(!empty($order_id) && is_numeric($order_id)) { |
|
| 46 | + if (!empty($order_id) && is_numeric($order_id)) { |
|
| 47 | 47 | $order = get_post_meta($order_id, '_order_postmeta', true); |
| 48 | 48 | |
| 49 | - if(!empty($order)) { |
|
| 50 | - if($order['customer_id'] == $user_id) { |
|
| 49 | + if (!empty($order)) { |
|
| 50 | + if ($order['customer_id'] == $user_id) { |
|
| 51 | 51 | $order['payment_method'] = $paymentMethod; |
| 52 | - $_SESSION['order_id'] = (int) $order_id; |
|
| 52 | + $_SESSION['order_id'] = (int)$order_id; |
|
| 53 | 53 | // Store cart in session |
| 54 | 54 | //wpshop_cart::store_cart_in_session($order); |
| 55 | 55 | // Add a payment |
| 56 | - $order['order_payment']['received'][] = array( 'method' => $paymentMethod, 'waited_amount' => $order['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => get_current_user_id() ); |
|
| 56 | + $order['order_payment']['received'][] = array('method' => $paymentMethod, 'waited_amount' => $order['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => get_current_user_id()); |
|
| 57 | 57 | |
| 58 | 58 | // On enregistre la commande |
| 59 | 59 | update_post_meta($order_id, '_order_postmeta', $order); |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | else $wpshop->add_error(__('The order doesn\'t exist.', 'wpshop')); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | $order_data = array( |
| 68 | 68 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
| 69 | - 'post_title' => sprintf(__('Order - %s','wpshop'), mysql2date('d M Y\, H:i:s', current_time('mysql', 0), true)), |
|
| 69 | + 'post_title' => sprintf(__('Order - %s', 'wpshop'), mysql2date('d M Y\, H:i:s', current_time('mysql', 0), true)), |
|
| 70 | 70 | 'post_status' => 'publish', |
| 71 | - 'post_excerpt' => !empty($_POST['wps-customer-comment']) ? sanitize_text_field( $_POST['wps-customer-comment'] ) : '', |
|
| 71 | + 'post_excerpt' => !empty($_POST['wps-customer-comment']) ? sanitize_text_field($_POST['wps-customer-comment']) : '', |
|
| 72 | 72 | 'post_author' => $user_id, |
| 73 | 73 | 'comment_status' => 'closed' |
| 74 | 74 | ); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $order_tva = array(); |
| 79 | 79 | |
| 80 | 80 | //$cart = (array)$wpshop_cart->cart; |
| 81 | - if ( !empty($_SESSION['cart']) && !empty( $_SESSION['cart']['shipping_method']) ) { |
|
| 81 | + if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['shipping_method'])) { |
|
| 82 | 82 | $_SESSION['cart']['shipping_method'] = __('Standard shipping method', 'wpshop'); |
| 83 | 83 | } |
| 84 | 84 | $cart = (array)$_SESSION['cart']; |
@@ -90,35 +90,35 @@ discard block |
||
| 90 | 90 | $_SESSION['order_id'] = $order_id; |
| 91 | 91 | |
| 92 | 92 | // Cr�ation des codes de t�l�chargement si il y a des produits t�l�chargeable dans le panier |
| 93 | - if ( !empty( $cart['order_items'] ) ) { |
|
| 94 | - foreach($cart['order_items'] as $c) { |
|
| 93 | + if (!empty($cart['order_items'])) { |
|
| 94 | + foreach ($cart['order_items'] as $c) { |
|
| 95 | 95 | $product_id = $c['item_id']; |
| 96 | 96 | $product = null; |
| 97 | - if( isset( $c['item_meta']['variations'] ) ) { |
|
| 98 | - foreach ( $c['item_meta']['variations'] as $variation_id => $variation ) { |
|
| 99 | - if( isset( $variation['item_meta']['is_downloadable_'] ) ) { |
|
| 97 | + if (isset($c['item_meta']['variations'])) { |
|
| 98 | + foreach ($c['item_meta']['variations'] as $variation_id => $variation) { |
|
| 99 | + if (isset($variation['item_meta']['is_downloadable_'])) { |
|
| 100 | 100 | $product_id = $c['item_id'] . '__' . $variation_id; |
| 101 | - $product = wpshop_products::get_product_data( $product_id ); |
|
| 101 | + $product = wpshop_products::get_product_data($product_id); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | - if( !isset( $product ) ) { |
|
| 106 | - $product = wpshop_products::get_product_data( $c['item_id'] ); |
|
| 105 | + if (!isset($product)) { |
|
| 106 | + $product = wpshop_products::get_product_data($c['item_id']); |
|
| 107 | 107 | $product_id = $c['item_id']; |
| 108 | 108 | /** Check if it's a variation and check the parent product **/ |
| 109 | - if ( get_post_type( $c['item_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 110 | - $parent_def = wpshop_products::get_parent_variation( $c['item_id'] ); |
|
| 111 | - if ( !empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_']) ) { |
|
| 109 | + if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 110 | + $parent_def = wpshop_products::get_parent_variation($c['item_id']); |
|
| 111 | + if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) { |
|
| 112 | 112 | $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_']; |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - if(!empty($product['is_downloadable_'])) { |
|
| 116 | + if (!empty($product['is_downloadable_'])) { |
|
| 117 | 117 | $download_codes[$product_id] = array('item_id' => $product_id, 'download_code' => uniqid('', true)); |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | - if(!empty($download_codes)) update_user_meta($user_id, '_order_download_codes_'.$order_id, $download_codes); |
|
| 121 | + if (!empty($download_codes)) update_user_meta($user_id, '_order_download_codes_' . $order_id, $download_codes); |
|
| 122 | 122 | |
| 123 | 123 | // Informations de commande � stocker |
| 124 | 124 | $currency = wpshop_tools::wpshop_get_currency(true); |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | 'order_payment' => array( |
| 134 | 134 | 'customer_choice' => array('method' => $paymentMethod), |
| 135 | 135 | 'received' => array('0' => array('method' => $paymentMethod, 'waited_amount' => $cart['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => $user_id)), |
| 136 | - 'shipping_method' => ( ( !empty( $_SESSION['shipping_method']) ) ? wpshop_tools::varSanitizer( $_SESSION['shipping_method']) : __('Standard shipping method', 'wpshop') ) |
|
| 136 | + 'shipping_method' => ((!empty($_SESSION['shipping_method'])) ? wpshop_tools::varSanitizer($_SESSION['shipping_method']) : __('Standard shipping method', 'wpshop')) |
|
| 137 | 137 | ), |
| 138 | 138 | ), $cart); |
| 139 | 139 | |
| 140 | 140 | // Si c'est un devis |
| 141 | - if ( $paymentMethod == 'quotation' ) { |
|
| 141 | + if ($paymentMethod == 'quotation') { |
|
| 142 | 142 | $order['order_temporary_key'] = wpshop_orders::get_new_pre_order_reference(); |
| 143 | 143 | } |
| 144 | 144 | else { |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | //Round final amount |
| 149 | - $order['order_grand_total'] = number_format( round($order['order_grand_total'], 2), 2, '.', ''); |
|
| 150 | - $order['order_total_ttc'] = number_format( round($order['order_total_ttc'], 2), 2, '.', ''); |
|
| 151 | - $order['order_amount_to_pay_now'] = number_format( round($order['order_amount_to_pay_now'], 2), 2, '.', ''); |
|
| 149 | + $order['order_grand_total'] = number_format(round($order['order_grand_total'], 2), 2, '.', ''); |
|
| 150 | + $order['order_total_ttc'] = number_format(round($order['order_total_ttc'], 2), 2, '.', ''); |
|
| 151 | + $order['order_amount_to_pay_now'] = number_format(round($order['order_amount_to_pay_now'], 2), 2, '.', ''); |
|
| 152 | 152 | |
| 153 | 153 | /** On enregistre la commande */ |
| 154 | 154 | update_post_meta($order_id, '_order_postmeta', $order); |
@@ -157,75 +157,75 @@ discard block |
||
| 157 | 157 | update_post_meta($order_id, '_wpshop_order_status', $order['order_status']); |
| 158 | 158 | |
| 159 | 159 | |
| 160 | - do_action( 'wps_order_extra_save', $order_id ); |
|
| 160 | + do_action('wps_order_extra_save', $order_id); |
|
| 161 | 161 | |
| 162 | 162 | //Add an action to extra actions on order save |
| 163 | 163 | // @TODO : REQUEST |
| 164 | - $args = array( 'order_id' => $order_id, 'posted_data' => $_REQUEST ); |
|
| 165 | - wpshop_tools::create_custom_hook( 'wps_order_extra_save_action', $args ); |
|
| 164 | + $args = array('order_id' => $order_id, 'posted_data' => $_REQUEST); |
|
| 165 | + wpshop_tools::create_custom_hook('wps_order_extra_save_action', $args); |
|
| 166 | 166 | |
| 167 | 167 | /** Set custmer information for the order */ |
| 168 | - $shipping_address = ( !empty($shipping_address_option) && !empty($shipping_address_option['activate']) ) ? ( ( !empty($_SESSION['shipping_address']) ) ? wpshop_tools::varSanitizer($_SESSION['shipping_address']) : $customer_shipping_address_id ) : ''; |
|
| 169 | - $billing_address = ( !empty($_SESSION['billing_address']) ) ? wpshop_tools::varSanitizer($_SESSION['billing_address']) : $customer_billing_address_id; |
|
| 168 | + $shipping_address = (!empty($shipping_address_option) && !empty($shipping_address_option['activate'])) ? ((!empty($_SESSION['shipping_address'])) ? wpshop_tools::varSanitizer($_SESSION['shipping_address']) : $customer_shipping_address_id) : ''; |
|
| 169 | + $billing_address = (!empty($_SESSION['billing_address'])) ? wpshop_tools::varSanitizer($_SESSION['billing_address']) : $customer_billing_address_id; |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - if ( !empty( $billing_address) ) { |
|
| 172 | + if (!empty($billing_address)) { |
|
| 173 | 173 | wpshop_orders::set_order_customer_addresses($user_id, $order_id, $shipping_address, $billing_address); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( !empty($_SESSION['shipping_address_to_save']) ) { |
|
| 176 | + if (!empty($_SESSION['shipping_address_to_save'])) { |
|
| 177 | 177 | $order_infos_postmeta = get_post_meta($order_id, '_order_info', true); |
| 178 | 178 | $order_infos_postmeta['shipping']['address'] = $_SESSION['shipping_address_to_save']; |
| 179 | 179 | $order_infos_postmeta['shipping']['address_id'] = ''; |
| 180 | 180 | update_post_meta($order_id, '_order_info', $order_infos_postmeta); |
| 181 | - unset( $_SESSION['shipping_address_to_save'] ); |
|
| 181 | + unset($_SESSION['shipping_address_to_save']); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | |
| 185 | 185 | /** Save Coupon use **/ |
| 186 | - if ( !empty($_SESSION['cart']['coupon_id']) ) { |
|
| 186 | + if (!empty($_SESSION['cart']['coupon_id'])) { |
|
| 187 | 187 | $wps_coupon_mdl = new wps_coupon_model(); |
| 188 | - $wps_coupon_mdl->save_coupon_use( $_SESSION['cart']['coupon_id'] ); |
|
| 188 | + $wps_coupon_mdl->save_coupon_use($_SESSION['cart']['coupon_id']); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** Notify the customer as the case */ |
| 192 | 192 | $user_info = get_userdata($user_id); |
| 193 | 193 | $email = $user_info->user_email; |
| 194 | - $first_name = $user_info->user_firstname ; |
|
| 194 | + $first_name = $user_info->user_firstname; |
|
| 195 | 195 | $last_name = $user_info->user_lastname; |
| 196 | 196 | |
| 197 | 197 | // Envoie du message de confirmation de commande au client |
| 198 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true); |
|
| 198 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 199 | 199 | |
| 200 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 201 | - $shipping_method = ( !empty($order_meta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_meta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_meta['order_payment']['shipping_method']]['name'] : ( (!empty($order_meta['order_payment']['shipping_method']) ) ? $order_meta['order_payment']['shipping_method'] : '' ); |
|
| 200 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 201 | + $shipping_method = (!empty($order_meta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_meta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_meta['order_payment']['shipping_method']]['name'] : ((!empty($order_meta['order_payment']['shipping_method'])) ? $order_meta['order_payment']['shipping_method'] : ''); |
|
| 202 | 202 | |
| 203 | - if ( !empty($order_meta) && !empty($order_meta['cart_type']) && $order_meta['cart_type'] == 'quotation' && empty($order_meta['order_key']) ) { |
|
| 204 | - $wps_message->wpshop_prepared_email($email, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE', array('order_id' => $order_id,'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_date' => current_time('mysql', 0), 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => '') ); |
|
| 203 | + if (!empty($order_meta) && !empty($order_meta['cart_type']) && $order_meta['cart_type'] == 'quotation' && empty($order_meta['order_key'])) { |
|
| 204 | + $wps_message->wpshop_prepared_email($email, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_date' => current_time('mysql', 0), 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => '')); |
|
| 205 | 205 | } |
| 206 | 206 | else { |
| 207 | - $email_option = get_option( 'wpshop_emails' ); |
|
| 208 | - if ( empty($email_option['send_confirmation_order_message']) ) { |
|
| 209 | - $payment_method_option = get_option( 'wps_payment_mode' ); |
|
| 210 | - $order_payment_method = ( !empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_meta['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]) ) ? $payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]['name'] : $order_meta['order_payment']['customer_choice']['method']; |
|
| 207 | + $email_option = get_option('wpshop_emails'); |
|
| 208 | + if (empty($email_option['send_confirmation_order_message'])) { |
|
| 209 | + $payment_method_option = get_option('wps_payment_mode'); |
|
| 210 | + $order_payment_method = (!empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_meta['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']])) ? $payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]['name'] : $order_meta['order_payment']['customer_choice']['method']; |
|
| 211 | 211 | |
| 212 | - $wps_message->wpshop_prepared_email($email, 'WPSHOP_ORDER_CONFIRMATION_MESSAGE', array('order_id' => $order_id,'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_key' => ( ( !empty($order_meta['order_key']) ) ? $order_meta['order_key'] : ''),'order_date' => current_time('mysql', 0), 'order_payment_method' => $order_payment_method, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => '' ) ); |
|
| 212 | + $wps_message->wpshop_prepared_email($email, 'WPSHOP_ORDER_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_key' => ((!empty($order_meta['order_key'])) ? $order_meta['order_key'] : ''), 'order_date' => current_time('mysql', 0), 'order_payment_method' => $order_payment_method, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => '')); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if ( empty($_SESSION['wps-pos-addon']) ) { |
|
| 216 | + if (empty($_SESSION['wps-pos-addon'])) { |
|
| 217 | 217 | $email_option = get_option('wpshop_emails'); |
| 218 | - if( empty($email_option) || ( !empty($email_option) && empty($email_option['send_confirmation_order_message']) ) ){ |
|
| 219 | - self::send_order_email_to_administrator( $order_id, $user_info ); |
|
| 218 | + if (empty($email_option) || (!empty($email_option) && empty($email_option['send_confirmation_order_message']))) { |
|
| 219 | + self::send_order_email_to_administrator($order_id, $user_info); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
| 224 | 224 | /** IF Order amount is 0, Finish the Order **/ |
| 225 | - if ( $cart['order_amount_to_pay_now'] == 0 ) { |
|
| 225 | + if ($cart['order_amount_to_pay_now'] == 0) { |
|
| 226 | 226 | $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
| 227 | 227 | $payment_status = 'completed'; |
| 228 | - $params_array = array ( |
|
| 228 | + $params_array = array( |
|
| 229 | 229 | 'method' =>'free', |
| 230 | 230 | 'waited_amount' => $order_meta['order_amount_to_pay_now'], |
| 231 | 231 | 'status' => 'payment_received', |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | ); |
| 237 | 237 | wpshop_payment::check_order_payment_total_amount($order_id, $params_array, $payment_status); |
| 238 | 238 | } |
| 239 | - apply_filters( 'wpshop_finish_order_extra_actions', $order_id); |
|
| 239 | + apply_filters('wpshop_finish_order_extra_actions', $order_id); |
|
| 240 | 240 | } |
| 241 | 241 | endif; |
| 242 | 242 | return $order_id; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - public static function send_order_email_to_administrator ( $order_id, $customer_infos = '' ) { |
|
| 246 | - if ( !empty($order_id) ) { |
|
| 245 | + public static function send_order_email_to_administrator($order_id, $customer_infos = '') { |
|
| 246 | + if (!empty($order_id)) { |
|
| 247 | 247 | $wps_message = new wps_message_ctr(); |
| 248 | 248 | $order_infos = get_post_meta($order_id, '_order_postmeta', true); |
| 249 | 249 | //Send email to administrator(s) |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | $shop_admin_email = $shop_admin_email_option['contact_email']; |
| 252 | 252 | $order_tmp_key = ''; |
| 253 | 253 | |
| 254 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 255 | - $shipping_method = ( !empty($order_infos['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_infos['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_infos['order_payment']['shipping_method']]['name'] : ( (!empty($order_infos['order_payment']['shipping_method']) ) ? $order_infos['order_payment']['shipping_method'] : '' ); |
|
| 254 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 255 | + $shipping_method = (!empty($order_infos['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_infos['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_infos['order_payment']['shipping_method']]['name'] : ((!empty($order_infos['order_payment']['shipping_method'])) ? $order_infos['order_payment']['shipping_method'] : ''); |
|
| 256 | 256 | |
| 257 | 257 | |
| 258 | - if( !empty( $order_infos ) && !empty($order_infos['cart_type']) && $order_infos['cart_type'] == 'normal' && !empty($order_infos['order_key']) ){ |
|
| 258 | + if (!empty($order_infos) && !empty($order_infos['cart_type']) && $order_infos['cart_type'] == 'normal' && !empty($order_infos['order_key'])) { |
|
| 259 | 259 | $message_type = 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE'; |
| 260 | 260 | } |
| 261 | 261 | else { |
@@ -263,12 +263,12 @@ discard block |
||
| 263 | 263 | $order_tmp_key = $order_infos['order_temporary_key']; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - $payment_method_option = get_option( 'wps_payment_mode' ); |
|
| 267 | - $order_payment_method = ( !empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_infos['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_infos['order_payment']['customer_choice']['method']]) ) ? $payment_method_option['mode'][$order_infos['order_payment']['customer_choice']['method']]['name'] : $order_infos['order_payment']['customer_choice']['method']; |
|
| 266 | + $payment_method_option = get_option('wps_payment_mode'); |
|
| 267 | + $order_payment_method = (!empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_infos['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_infos['order_payment']['customer_choice']['method']])) ? $payment_method_option['mode'][$order_infos['order_payment']['customer_choice']['method']]['name'] : $order_infos['order_payment']['customer_choice']['method']; |
|
| 268 | 268 | |
| 269 | - $data_to_send = array('order_id' => $order_id, 'order_key' => $order_infos['order_key'], 'customer_email' => ( !empty($customer_infos) && !empty($customer_infos->user_email) ) ? $customer_infos->user_email : '' , 'customer_last_name' => ( !empty($customer_infos) && !empty($customer_infos->user_lastname) ) ? $customer_infos->user_lastname : '', 'customer_first_name' => ( !empty($customer_infos) && !empty($customer_infos->user_firstname) ) ? $customer_infos->user_firstname : '', 'order_date' => $order_infos['order_date'], 'order_payment_method' => $order_payment_method, 'order_temporary_key' => $order_tmp_key, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '','order_shipping_method' => $shipping_method, 'order_personnal_informations' => '' ); |
|
| 269 | + $data_to_send = array('order_id' => $order_id, 'order_key' => $order_infos['order_key'], 'customer_email' => (!empty($customer_infos) && !empty($customer_infos->user_email)) ? $customer_infos->user_email : '', 'customer_last_name' => (!empty($customer_infos) && !empty($customer_infos->user_lastname)) ? $customer_infos->user_lastname : '', 'customer_first_name' => (!empty($customer_infos) && !empty($customer_infos->user_firstname)) ? $customer_infos->user_firstname : '', 'order_date' => $order_infos['order_date'], 'order_payment_method' => $order_payment_method, 'order_temporary_key' => $order_tmp_key, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => ''); |
|
| 270 | 270 | |
| 271 | - $wps_message->wpshop_prepared_email( $shop_admin_email, $message_type, $data_to_send, array('object_type' => 'order', 'object_id' => $order_id)); |
|
| 271 | + $wps_message->wpshop_prepared_email($shop_admin_email, $message_type, $data_to_send, array('object_type' => 'order', 'object_id' => $order_id)); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
@@ -279,13 +279,13 @@ discard block |
||
| 279 | 279 | * @param mixed $data Array or false. |
| 280 | 280 | * @return void |
| 281 | 281 | */ |
| 282 | - public static function wps_direct_payment_link( $data = false ) { |
|
| 283 | - $data = empty( $data ) ? self::wps_direct_payment_link_verify_token() : $data; |
|
| 284 | - if ( (bool) $data ) { |
|
| 285 | - wps_orders_ctr::pay_quotation( $data['oid'] ); |
|
| 286 | - wpshop_tools::wpshop_safe_redirect( get_permalink( wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ) ) . '?order_step=5' ); |
|
| 282 | + public static function wps_direct_payment_link($data = false) { |
|
| 283 | + $data = empty($data) ? self::wps_direct_payment_link_verify_token() : $data; |
|
| 284 | + if ((bool)$data) { |
|
| 285 | + wps_orders_ctr::pay_quotation($data['oid']); |
|
| 286 | + wpshop_tools::wpshop_safe_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . '?order_step=5'); |
|
| 287 | 287 | } else { |
| 288 | - wpshop_tools::wpshop_safe_redirect( get_permalink( wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' ) ) ) ); |
|
| 288 | + wpshop_tools::wpshop_safe_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')))); |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | /** |
@@ -295,12 +295,12 @@ discard block |
||
| 295 | 295 | * @param mixed $data Array or false. |
| 296 | 296 | * @return void |
| 297 | 297 | */ |
| 298 | - public static function wps_direct_payment_link_nopriv( $data = false ) { |
|
| 299 | - $data = empty( $data ) ? self::wps_direct_payment_link_verify_token() : $data; |
|
| 300 | - if ( (bool) $data ) { |
|
| 301 | - wp_set_auth_cookie( $data['cid'], true, is_ssl() ); |
|
| 298 | + public static function wps_direct_payment_link_nopriv($data = false) { |
|
| 299 | + $data = empty($data) ? self::wps_direct_payment_link_verify_token() : $data; |
|
| 300 | + if ((bool)$data) { |
|
| 301 | + wp_set_auth_cookie($data['cid'], true, is_ssl()); |
|
| 302 | 302 | } |
| 303 | - self::wps_direct_payment_link( $data ); |
|
| 303 | + self::wps_direct_payment_link($data); |
|
| 304 | 304 | } |
| 305 | 305 | /** |
| 306 | 306 | * Verify token in request. |
@@ -309,11 +309,11 @@ discard block |
||
| 309 | 309 | * @return mixed Customer id or false. |
| 310 | 310 | */ |
| 311 | 311 | public static function wps_direct_payment_link_verify_token() { |
| 312 | - $token = ! empty( $_GET['token'] ) ? sanitize_text_field( $_GET['token'] ) : ''; |
|
| 313 | - $order_id = ! empty( $_GET['order_id'] ) ? (int) $_GET['order_id'] : ''; |
|
| 314 | - $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 315 | - $customer_id = ! empty( $order_metadata['customer_id'] ) ? (int) $order_metadata['customer_id'] : false; |
|
| 316 | - return ( (bool) $customer_id && wps_orders_ctr::wps_token_order_customer( $order_id ) === $token ) ? array( 'oid' => $order_id, 'cid' => $customer_id ) : false; |
|
| 312 | + $token = !empty($_GET['token']) ? sanitize_text_field($_GET['token']) : ''; |
|
| 313 | + $order_id = !empty($_GET['order_id']) ? (int)$_GET['order_id'] : ''; |
|
| 314 | + $order_metadata = get_post_meta($order_id, '_order_postmeta', true); |
|
| 315 | + $customer_id = !empty($order_metadata['customer_id']) ? (int)$order_metadata['customer_id'] : false; |
|
| 316 | + return ((bool)$customer_id && wps_orders_ctr::wps_token_order_customer($order_id) === $token) ? array('oid' => $order_id, 'cid' => $customer_id) : false; |
|
| 317 | 317 | } |
| 318 | 318 | /** |
| 319 | 319 | * Get URL for wps_direct_link. |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @param int $order_id OrderID. |
| 323 | 323 | * @return string Url or empty string. |
| 324 | 324 | */ |
| 325 | - public static function wps_direct_payment_link_url( $order_id ) { |
|
| 326 | - return ( (bool) ( $token = wps_orders_ctr::wps_token_order_customer( (int) $order_id ) ) ) ? admin_url( 'admin-post.php?action=wps_direct_payment_link&token=' . $token . '&order_id=' . (int) $order_id ) : ''; |
|
| 325 | + public static function wps_direct_payment_link_url($order_id) { |
|
| 326 | + return ((bool)($token = wps_orders_ctr::wps_token_order_customer((int)$order_id))) ? admin_url('admin-post.php?action=wps_direct_payment_link&token=' . $token . '&order_id=' . (int)$order_id) : ''; |
|
| 327 | 327 | } |
| 328 | 328 | } |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | /* Check if file is include. No direct access possible with file url */ |
| 4 | 6 | if ( !defined( 'WPSHOP_VERSION' ) ) { |
@@ -58,12 +60,13 @@ discard block |
||
| 58 | 60 | // On enregistre la commande |
| 59 | 61 | update_post_meta($order_id, '_order_postmeta', $order); |
| 60 | 62 | update_post_meta($order_id, '_wpshop_order_customer_id', $user_id); |
| 63 | + } else { |
|
| 64 | + $wpshop->add_error(__('You don\'t own the order', 'wpshop')); |
|
| 61 | 65 | } |
| 62 | - else $wpshop->add_error(__('You don\'t own the order', 'wpshop')); |
|
| 66 | + } else { |
|
| 67 | + $wpshop->add_error(__('The order doesn\'t exist.', 'wpshop')); |
|
| 63 | 68 | } |
| 64 | - else $wpshop->add_error(__('The order doesn\'t exist.', 'wpshop')); |
|
| 65 | - } |
|
| 66 | - else{ |
|
| 69 | + } else{ |
|
| 67 | 70 | $order_data = array( |
| 68 | 71 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
| 69 | 72 | 'post_title' => sprintf(__('Order - %s','wpshop'), mysql2date('d M Y\, H:i:s', current_time('mysql', 0), true)), |
@@ -118,7 +121,9 @@ discard block |
||
| 118 | 121 | } |
| 119 | 122 | } |
| 120 | 123 | } |
| 121 | - if(!empty($download_codes)) update_user_meta($user_id, '_order_download_codes_'.$order_id, $download_codes); |
|
| 124 | + if(!empty($download_codes)) { |
|
| 125 | + update_user_meta($user_id, '_order_download_codes_'.$order_id, $download_codes); |
|
| 126 | + } |
|
| 122 | 127 | |
| 123 | 128 | // Informations de commande � stocker |
| 124 | 129 | $currency = wpshop_tools::wpshop_get_currency(true); |
@@ -140,8 +145,7 @@ discard block |
||
| 140 | 145 | // Si c'est un devis |
| 141 | 146 | if ( $paymentMethod == 'quotation' ) { |
| 142 | 147 | $order['order_temporary_key'] = wpshop_orders::get_new_pre_order_reference(); |
| 143 | - } |
|
| 144 | - else { |
|
| 148 | + } else { |
|
| 145 | 149 | $order['order_key'] = wpshop_orders::get_new_order_reference(); |
| 146 | 150 | } |
| 147 | 151 | |
@@ -202,8 +206,7 @@ discard block |
||
| 202 | 206 | |
| 203 | 207 | if ( !empty($order_meta) && !empty($order_meta['cart_type']) && $order_meta['cart_type'] == 'quotation' && empty($order_meta['order_key']) ) { |
| 204 | 208 | $wps_message->wpshop_prepared_email($email, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE', array('order_id' => $order_id,'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_date' => current_time('mysql', 0), 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => '') ); |
| 205 | - } |
|
| 206 | - else { |
|
| 209 | + } else { |
|
| 207 | 210 | $email_option = get_option( 'wpshop_emails' ); |
| 208 | 211 | if ( empty($email_option['send_confirmation_order_message']) ) { |
| 209 | 212 | $payment_method_option = get_option( 'wps_payment_mode' ); |
@@ -257,8 +260,7 @@ discard block |
||
| 257 | 260 | |
| 258 | 261 | if( !empty( $order_infos ) && !empty($order_infos['cart_type']) && $order_infos['cart_type'] == 'normal' && !empty($order_infos['order_key']) ){ |
| 259 | 262 | $message_type = 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE'; |
| 260 | - } |
|
| 261 | - else { |
|
| 263 | + } else { |
|
| 262 | 264 | $message_type = 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'; |
| 263 | 265 | $order_tmp_key = $order_infos['order_temporary_key']; |
| 264 | 266 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /* Check if file is include. No direct access possible with file url */ |
| 3 | -if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
| 4 | - die( __('Access is not allowed by this way', 'wpshop') ); |
|
| 3 | +if (!defined('WPSHOP_VERSION')) { |
|
| 4 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -19,36 +19,36 @@ discard block |
||
| 19 | 19 | * @package wpshop |
| 20 | 20 | * @subpackage librairies |
| 21 | 21 | */ |
| 22 | -class wpshop_notices{ |
|
| 22 | +class wpshop_notices { |
|
| 23 | 23 | |
| 24 | 24 | /** Notice the user to install the plugin */ |
| 25 | 25 | public static function sale_shop_notice() { |
| 26 | - $plug_version = substr( WPSHOP_VERSION, 0, 5 ); |
|
| 26 | + $plug_version = substr(WPSHOP_VERSION, 0, 5); |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - $notice_display_user_option = get_user_meta( get_current_user_id(), '_wps_hide_notice_messages_indicator', true); |
|
| 29 | + $notice_display_user_option = get_user_meta(get_current_user_id(), '_wps_hide_notice_messages_indicator', true); |
|
| 30 | 30 | |
| 31 | 31 | $notice = ''; |
| 32 | 32 | $messages_to_hide = ''; |
| 33 | 33 | /* Check that the user has already choose a payment method */ |
| 34 | - $paymentMethod = get_option( 'wps_payment_mode' ); |
|
| 34 | + $paymentMethod = get_option('wps_payment_mode'); |
|
| 35 | 35 | $no_payment_mode_configurated = true; |
| 36 | - if ( !empty($paymentMethod ) && !empty($paymentMethod['mode']) ) { |
|
| 37 | - foreach( $paymentMethod['mode'] as $k => $pm ) { |
|
| 38 | - if ( !empty($pm['active'] ) ) { |
|
| 36 | + if (!empty($paymentMethod) && !empty($paymentMethod['mode'])) { |
|
| 37 | + foreach ($paymentMethod['mode'] as $k => $pm) { |
|
| 38 | + if (!empty($pm['active'])) { |
|
| 39 | 39 | $no_payment_mode_configurated = false; |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if( $no_payment_mode_configurated ) { |
|
| 45 | - $notice .= '<li>' . __('Payment method are missing', 'wpshop') . ' <a href="' . admin_url('options-general.php?page='.WPSHOP_URL_SLUG_OPTION.'#wpshop_payments_option') . '" class="button-primary wpshop_missing_parameters_button" >' . __('Choose a payment method', 'wpshop') . '</a></li>'; |
|
| 44 | + if ($no_payment_mode_configurated) { |
|
| 45 | + $notice .= '<li>' . __('Payment method are missing', 'wpshop') . ' <a href="' . admin_url('options-general.php?page=' . WPSHOP_URL_SLUG_OPTION . '#wpshop_payments_option') . '" class="button-primary wpshop_missing_parameters_button" >' . __('Choose a payment method', 'wpshop') . '</a></li>'; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /* Check that the user has already choose a payment method */ |
| 49 | 49 | $emails = get_option('wpshop_emails', array()); |
| 50 | - if(empty($emails)) { |
|
| 51 | - $notice .= '<li>' . __('Shop emails are misssing', 'wpshop') . ' <a href="' . admin_url('options-general.php?page='.WPSHOP_URL_SLUG_OPTION.'#wpshop_emails_option') . '" class="button-primary wpshop_missing_parameters_button" >' . __('Configure shop emails', 'wpshop') . '</a></li>'; |
|
| 50 | + if (empty($emails)) { |
|
| 51 | + $notice .= '<li>' . __('Shop emails are misssing', 'wpshop') . ' <a href="' . admin_url('options-general.php?page=' . WPSHOP_URL_SLUG_OPTION . '#wpshop_emails_option') . '" class="button-primary wpshop_missing_parameters_button" >' . __('Configure shop emails', 'wpshop') . '</a></li>'; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -58,20 +58,20 @@ discard block |
||
| 58 | 58 | $messages_to_hide .= 'SLICKSHOP,'; |
| 59 | 59 | }*/ |
| 60 | 60 | |
| 61 | - $install = !empty( $_GET[ 'install' ] ) ? sanitize_text_field( $_GET[ 'install' ] ) : ''; |
|
| 61 | + $install = !empty($_GET['install']) ? sanitize_text_field($_GET['install']) : ''; |
|
| 62 | 62 | |
| 63 | - if(!empty($notice) && ( empty( $install ) ) ) { |
|
| 64 | - $notice='<p>'.__('You configure your shop to be a sale shop. But some configuration are missing for this type of shop using', 'wpshop').'</p><ul>'.$notice.'</ul>'; |
|
| 65 | - if ( !empty($messages_to_hide) ) { |
|
| 66 | - $notice .= '<button data-nonce="' . wp_create_nonce( 'wps_hide_notice_messages' ) . '" class="wps_hide_notice_message button-secondary" id="wps_hide_notice_message">' .__('Hide this message', 'wpshop'). '</button>'; |
|
| 67 | - $notice .= '<input type="hidden" id="hide_messages_indicator" value="' .$messages_to_hide. '"/>'; |
|
| 63 | + if (!empty($notice) && (empty($install))) { |
|
| 64 | + $notice = '<p>' . __('You configure your shop to be a sale shop. But some configuration are missing for this type of shop using', 'wpshop') . '</p><ul>' . $notice . '</ul>'; |
|
| 65 | + if (!empty($messages_to_hide)) { |
|
| 66 | + $notice .= '<button data-nonce="' . wp_create_nonce('wps_hide_notice_messages') . '" class="wps_hide_notice_message button-secondary" id="wps_hide_notice_message">' . __('Hide this message', 'wpshop') . '</button>'; |
|
| 67 | + $notice .= '<input type="hidden" id="hide_messages_indicator" value="' . $messages_to_hide . '"/>'; |
|
| 68 | 68 | } |
| 69 | 69 | self::admin_notice_container($notice, 'wpshop_shop_sale_type_notice'); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** */ |
| 74 | - public static function admin_notice_container($message, $container_class = ''){ |
|
| 74 | + public static function admin_notice_container($message, $container_class = '') { |
|
| 75 | 75 | ?> |
| 76 | 76 | <div class="updated wpshop_admin_notice <?php echo $container_class; ?>" id="<?php echo $container_class; ?>" > |
| 77 | 77 | <h3><?php _e('Configure my shop', 'wpshop') ?></h3> |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /* Check if file is include. No direct access possible with file url */ |
| 6 | 6 | if (!defined('WPSHOP_VERSION')) { |
| 7 | - die(__('Access is not allowed by this way', 'wpshop')); |
|
| 7 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | /** |
@@ -25,2409 +25,2409 @@ discard block |
||
| 25 | 25 | class wpshop_install |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Define the action launch when plugin is activate |
|
| 30 | - * |
|
| 31 | - * @return void |
|
| 32 | - */ |
|
| 33 | - public static function install_on_activation() |
|
| 34 | - { |
|
| 35 | - /* Create the different option needed for the plugin work properly */ |
|
| 36 | - add_option('wpshop_db_options', array('db_version' => 0)); |
|
| 37 | - add_option('wpshop_shop_default_currency', WPSHOP_SHOP_DEFAULT_CURRENCY); |
|
| 38 | - add_option('wpshop_emails', array('noreply_email' => get_bloginfo('admin_email'), 'contact_email' => get_bloginfo('admin_email'))); |
|
| 39 | - add_option('wpshop_catalog_product_option', array('wpshop_catalog_product_slug' => WPSHOP_CATALOG_PRODUCT_SLUG)); |
|
| 40 | - add_option('wpshop_catalog_categories_option', array('wpshop_catalog_categories_slug' => WPSHOP_CATALOG_CATEGORIES_SLUG)); |
|
| 41 | - add_option('wpshop_display_option', array('wpshop_display_list_type' => 'grid', 'wpshop_display_grid_element_number' => '3', 'wpshop_display_cat_sheet_output' => array('category_description', 'category_subcategory', 'category_subproduct'))); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Create the default pages |
|
| 46 | - */ |
|
| 47 | - public static function wpshop_insert_default_pages($pages_type = '') |
|
| 48 | - { |
|
| 49 | - global $wpdb, $wp_rewrite; |
|
| 50 | - |
|
| 51 | - /** if we will create any new pages we need to flush page cache */ |
|
| 52 | - $page_creation = false; |
|
| 53 | - $created_pages = array(); |
|
| 54 | - |
|
| 55 | - /** Default data array for add page */ |
|
| 56 | - $page_default_args = array( |
|
| 57 | - 'post_type' => 'page', |
|
| 58 | - 'comment_status' => 'closed', |
|
| 59 | - 'ping_status' => 'closed', |
|
| 60 | - 'post_status' => 'publish', |
|
| 61 | - 'post_author' => get_current_user_id(), |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - /** Get defined shop type */ |
|
| 65 | - $wpshop_shop_type = !empty($pages_type) ? $pages_type : get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 66 | - |
|
| 67 | - /** Get the default datas for installation - Pages */ |
|
| 68 | - $xml_default_pages = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_pages.xml'); |
|
| 69 | - $defined_default_pages = new SimpleXMLElement($xml_default_pages); |
|
| 70 | - foreach ($defined_default_pages->xpath('//pages/page') as $page) { |
|
| 71 | - if (($wpshop_shop_type == $page->attributes()->shop_type) || ('sale' == $wpshop_shop_type)) { |
|
| 72 | - $page_id = null; |
|
| 73 | - |
|
| 74 | - /** Do a specific check for cart page, for old wpshop installation */ |
|
| 75 | - if ('wpshop_cart_page_id' == (string) $page->attributes()->code) { |
|
| 76 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s AND post_type != %s", '%[wpshop_basket]%', 'revision'); |
|
| 77 | - $page_id = $wpdb->get_var($query); |
|
| 78 | - |
|
| 79 | - wp_update_post(array( |
|
| 80 | - 'ID' => $page_id, |
|
| 81 | - 'post_content' => (string) $page->content, |
|
| 82 | - )); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** Check if a page exists with the current content readed form xml file */ |
|
| 86 | - if (empty($page_id)) { |
|
| 87 | - $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string) $page->content . '%', 'revision'); |
|
| 88 | - $page_id = $wpdb->get_var($query); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** If the page does not exists create it */ |
|
| 92 | - if (empty($page_id)) { |
|
| 93 | - $default_page_args = wp_parse_args(array( |
|
| 94 | - 'post_title' => __((string) $page->title, 'wpshop'), |
|
| 95 | - 'post_name' => __((string) $page->slug, 'wpshop'), |
|
| 96 | - 'post_content' => __((string) $page->content, 'wpshop'), |
|
| 97 | - 'menu_order' => (string) $page->attributes()->position, |
|
| 98 | - ), $page_default_args); |
|
| 99 | - |
|
| 100 | - $page_id = wp_insert_post($default_page_args); |
|
| 101 | - $created_pages[] = (string) $page->attributes()->code; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** If the page is created or already exists associated the page to the good service */ |
|
| 105 | - if (!empty($page_id)) { |
|
| 106 | - add_option((string) $page->attributes()->code, $page_id); |
|
| 107 | - |
|
| 108 | - $page_creation = true; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** Check if page have been created in order to do specific action */ |
|
| 115 | - if (!empty($created_pages)) { |
|
| 116 | - /** If cart page and checkout page have just been created, change cart page id into checkout page id */ |
|
| 117 | - if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) { |
|
| 118 | - update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id')); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - wp_cache_flush(); |
|
| 124 | - /** If new page => empty cache */ |
|
| 125 | - if ($page_creation) { |
|
| 126 | - wp_cache_delete('all_page_ids', 'pages'); |
|
| 127 | - // $wp_rewrite->flush_rules(); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Insert sample datas when installing wpshop the first time if the admin choose |
|
| 133 | - */ |
|
| 134 | - public static function import_sample_datas() |
|
| 135 | - { |
|
| 136 | - global $wpdb, $wp_rewrite; |
|
| 137 | - |
|
| 138 | - /** Default data array for add product */ |
|
| 139 | - $product_default_args = array( |
|
| 140 | - 'comment_status' => 'closed', |
|
| 141 | - 'ping_status' => 'closed', |
|
| 142 | - 'post_status' => 'publish', |
|
| 143 | - 'post_author' => get_current_user_id(), |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - /** Get the default datas for installation - sample products */ |
|
| 147 | - $sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml'); |
|
| 148 | - $defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA); |
|
| 149 | - |
|
| 150 | - $namespaces = $defined_sample_datas->getDocNamespaces(); |
|
| 151 | - if (!isset($namespaces['wp'])) { |
|
| 152 | - $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if (!isset($namespaces['excerpt'])) { |
|
| 156 | - $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) { |
|
| 160 | - $dc = $product->children('http://purl.org/dc/elements/1.1/'); |
|
| 161 | - $content = $product->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 162 | - $excerpt = $product->children($namespaces['excerpt']); |
|
| 163 | - $wp = $product->children($namespaces['wp']); |
|
| 164 | - |
|
| 165 | - $product_args = wp_parse_args(array( |
|
| 166 | - 'post_title' => (string) $product->title, |
|
| 167 | - 'post_name' => (string) $wp->post_name, |
|
| 168 | - 'post_content' => (string) $content->encoded, |
|
| 169 | - 'post_excerpt' => (string) $excerpt->encoded, |
|
| 170 | - 'post_type' => (string) $wp->post_type, |
|
| 171 | - ), $product_default_args); |
|
| 172 | - |
|
| 173 | - $product_id = wp_insert_post($product_args); |
|
| 174 | - |
|
| 175 | - foreach ($wp->postmeta as $meta) { |
|
| 176 | - update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) { |
|
| 180 | - $wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/'); |
|
| 181 | - $wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 182 | - $wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']); |
|
| 183 | - $wps_pdt_var_wp = $product_variation->children($namespaces['wp']); |
|
| 184 | - |
|
| 185 | - $product_args = wp_parse_args(array( |
|
| 186 | - 'post_title' => (string) $product_variation->title, |
|
| 187 | - 'post_name' => (string) $wps_pdt_var_wp->post_name, |
|
| 188 | - 'post_content' => (string) $wps_pdt_var_content->encoded, |
|
| 189 | - 'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded, |
|
| 190 | - 'post_type' => (string) $wps_pdt_var_wp->post_type, |
|
| 191 | - 'post_parent' => $product_id, |
|
| 192 | - ), $product_default_args); |
|
| 193 | - |
|
| 194 | - $product_variation_id = wp_insert_post($product_args); |
|
| 195 | - |
|
| 196 | - foreach ($wps_pdt_var_wp->postmeta as $meta) { |
|
| 197 | - update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 205 | - */ |
|
| 206 | - public static function update_wpshop_dev() |
|
| 207 | - { |
|
| 208 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 209 | - |
|
| 210 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 211 | - |
|
| 212 | - self::execute_operation_on_db_for_update('dev'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 217 | - */ |
|
| 218 | - public static function update_wpshop() |
|
| 219 | - { |
|
| 220 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 221 | - $do_changes = false; |
|
| 222 | - |
|
| 223 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 224 | - |
|
| 225 | - $current_db_version = get_option('wpshop_db_options', 0); |
|
| 226 | - $current_db_version = $current_db_version['db_version']; |
|
| 227 | - |
|
| 228 | - $current_def_max_version = max(array_keys($wpshop_update_way)); |
|
| 229 | - $new_version = $current_def_max_version + 1; |
|
| 230 | - $version_nb_delta = $current_def_max_version - $current_db_version; |
|
| 231 | - |
|
| 232 | - /* Check if there are modification to do */ |
|
| 233 | - if ($current_def_max_version >= $current_db_version) { |
|
| 234 | - /* Check the lowest version of db to execute */ |
|
| 235 | - $lowest_version_to_execute = $current_def_max_version - $version_nb_delta; |
|
| 236 | - |
|
| 237 | - for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) { |
|
| 238 | - $do_changes = self::execute_operation_on_db_for_update($i); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /* Update the db version option value */ |
|
| 243 | - if ($do_changes) { |
|
| 244 | - $db_version = get_option('wpshop_db_options', 0); |
|
| 245 | - $db_version['db_version'] = $new_version; |
|
| 246 | - update_option('wpshop_db_options', $db_version); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Update db structure on each plugin update |
|
| 252 | - * |
|
| 253 | - * @param integer $i The current plugin db version |
|
| 254 | - * @return boolean If the changes are done correctly or not |
|
| 255 | - */ |
|
| 256 | - public static function alter_db_structure_on_update($i) |
|
| 257 | - { |
|
| 258 | - $do_changes = false; |
|
| 259 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete; |
|
| 260 | - |
|
| 261 | - /* Check if there are modification to do */ |
|
| 262 | - if (isset($wpshop_update_way[$i])) { |
|
| 263 | - /* Check if there are modification to make on table */ |
|
| 264 | - if (isset($wpshop_db_table_list[$i])) { |
|
| 265 | - foreach ($wpshop_db_table_list[$i] as $table_name) { |
|
| 266 | - dbDelta($wpshop_db_table[$table_name]); |
|
| 267 | - } |
|
| 268 | - $do_changes = true; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /* Request maker */ |
|
| 272 | - if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) { |
|
| 273 | - foreach ($wpshop_db_request[$i] as $request) { |
|
| 274 | - $wpdb->query($request); |
|
| 275 | - $do_changes = true; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /* Delete datas */ |
|
| 280 | - if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) { |
|
| 281 | - foreach ($wpshop_db_delete[$i] as $request) { |
|
| 282 | - $wpdb->query($request); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return $do_changes; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Do changes on database for wpshop plugin for a given version |
|
| 292 | - * |
|
| 293 | - * @param integer $i The wpshop db version to execute operation for |
|
| 294 | - * |
|
| 295 | - * @return boolean |
|
| 296 | - */ |
|
| 297 | - public static function execute_operation_on_db_for_update($i) |
|
| 298 | - { |
|
| 299 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete; |
|
| 300 | - $do_changes = false; |
|
| 301 | - |
|
| 302 | - /* Check if there are modification to do */ |
|
| 303 | - if (isset($wpshop_update_way[$i])) { |
|
| 304 | - $do_changes = self::alter_db_structure_on_update($i); |
|
| 305 | - |
|
| 306 | - /********************/ |
|
| 307 | - /* Insert data */ |
|
| 308 | - /********************/ |
|
| 309 | - /* Options content */ |
|
| 310 | - if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) { |
|
| 311 | - foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) { |
|
| 312 | - add_option($option_name, $option_content, '', 'yes'); |
|
| 313 | - } |
|
| 314 | - $do_changes = true; |
|
| 315 | - } |
|
| 316 | - if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) { |
|
| 317 | - foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) { |
|
| 318 | - $option_current_content = get_option($option_name); |
|
| 319 | - foreach ($option_content as $option_key => $option_value) { |
|
| 320 | - $option_current_content[$option_key] = $option_value; |
|
| 321 | - } |
|
| 322 | - update_option($option_name, $option_current_content); |
|
| 323 | - } |
|
| 324 | - $do_changes = true; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /* Eav content */ |
|
| 328 | - if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) { |
|
| 329 | - $do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes); |
|
| 330 | - } |
|
| 331 | - /* Eav content update */ |
|
| 332 | - if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) { |
|
| 333 | - $do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /* Add datas */ |
|
| 337 | - if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) { |
|
| 338 | - foreach ($wpshop_db_content_add[$i] as $table_name => $def) { |
|
| 339 | - foreach ($def as $information_index => $table_information) { |
|
| 340 | - $wpdb->insert($table_name, $table_information, '%s'); |
|
| 341 | - $do_changes = true; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /* Update datas */ |
|
| 347 | - if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) { |
|
| 348 | - foreach ($wpshop_db_content_update[$i] as $table_name => $def) { |
|
| 349 | - foreach ($def as $information_index => $table_information) { |
|
| 350 | - $wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s'); |
|
| 351 | - $do_changes = true; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $do_changes = self::make_specific_operation_on_update($i); |
|
| 358 | - |
|
| 359 | - return $do_changes; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Create specific data in eav db model |
|
| 364 | - * |
|
| 365 | - * @param array $eav_content The complete array with all element to create into database |
|
| 366 | - * @param boolean $do_changes The current state of changes to do |
|
| 367 | - * |
|
| 368 | - * @return boolean If there are changes to do or not |
|
| 369 | - */ |
|
| 370 | - public static function add_content_to_eav($eav_content, $do_changes) |
|
| 371 | - { |
|
| 372 | - global $wpdb; |
|
| 373 | - /* Create entities if entites are set to be created for the current version */ |
|
| 374 | - if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) { |
|
| 375 | - foreach ($eav_content['entities'] as $entity) { |
|
| 376 | - /* Creation de l'entité produit dans la table des posts */ |
|
| 377 | - wpshop_entities::create_cpt_from_csv_file($entity); |
|
| 378 | - } |
|
| 379 | - $do_changes = true; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /* Create attributes for a given entity if attributes are set to be created for current version */ |
|
| 383 | - if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 384 | - foreach ($eav_content['attributes'] as $entity_code) { |
|
| 385 | - wpshop_entities::create_cpt_attributes_from_csv_file($entity_code); |
|
| 386 | - } |
|
| 387 | - $do_changes = true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /* Create attribute groups for a given entity if attributes groups are set to be created for current version */ |
|
| 391 | - if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 392 | - foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 393 | - $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 394 | - |
|
| 395 | - if ($entity_id > 0) { |
|
| 396 | - foreach ($attribute_set as $set_name => $set_groups) { |
|
| 397 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 398 | - $attribute_set_id = $wpdb->get_var($query); |
|
| 399 | - if ($attribute_set_id <= 0) { |
|
| 400 | - $attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name); |
|
| 401 | - if ($set_name == 'default') { |
|
| 402 | - $attribute_set_content['default_set'] = 'yes'; |
|
| 403 | - } |
|
| 404 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content); |
|
| 405 | - $attribute_set_id = $wpdb->insert_id; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - if ($attribute_set_id > 0) { |
|
| 409 | - foreach ($set_groups as $set_group_infos) { |
|
| 410 | - $set_group_infos_details = $set_group_infos['details']; |
|
| 411 | - unset($set_group_infos['details']); |
|
| 412 | - /* Change an attribute set status if definition specify this param */ |
|
| 413 | - if (isset($set_group_infos['status'])) { |
|
| 414 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 415 | - } |
|
| 416 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 417 | - $attribute_set_section_id = $wpdb->get_var($query); |
|
| 418 | - if ($attribute_set_section_id <= 0) { |
|
| 419 | - $new_set_section_infos = $set_group_infos; |
|
| 420 | - $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 421 | - $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 422 | - $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 423 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 424 | - $attribute_set_section_id = $wpdb->insert_id; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) { |
|
| 428 | - $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 429 | - $last_position = $wpdb->get_var($query); |
|
| 430 | - $position = (int) $last_position + 1; |
|
| 431 | - foreach ($set_group_infos_details as $attribute_code) { |
|
| 432 | - $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 433 | - $attribute_id = $wpdb->get_row($query); |
|
| 434 | - |
|
| 435 | - if ($attribute_id->id > 0) { |
|
| 436 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position)); |
|
| 437 | - $position++; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - $do_changes = true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return $do_changes; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Update specific data in eav db model |
|
| 455 | - * |
|
| 456 | - * @param array $eav_content The complete array with all element to create into database |
|
| 457 | - * @param boolean $do_changes The current state of changes to do |
|
| 458 | - * |
|
| 459 | - * @return boolean If there are changes to do or not |
|
| 460 | - */ |
|
| 461 | - public static function update_eav_content($eav_content, $do_changes) |
|
| 462 | - { |
|
| 463 | - /* Update attributes fo a given entity if attributes are set to be updated for current version */ |
|
| 464 | - if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 465 | - foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) { |
|
| 466 | - foreach ($attribute_definition as $attribute_def) { |
|
| 467 | - $option_list_for_attribute = ''; |
|
| 468 | - if (isset($attribute_def['backend_input_values'])) { |
|
| 469 | - $option_list_for_attribute = $attribute_def['backend_input_values']; |
|
| 470 | - unset($attribute_def['backend_input_values']); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /* Get entity identifier from code */ |
|
| 474 | - $attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 475 | - $attribute_def['status'] = $attribute_def['attribute_status']; |
|
| 476 | - unset($attribute_def['attribute_status']); |
|
| 477 | - $attribute_def['last_update_date'] = current_time('mysql', 0); |
|
| 478 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code'])); |
|
| 479 | - $attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code'])); |
|
| 480 | - |
|
| 481 | - /* Insert option values if there are some to add for the current attribute */ |
|
| 482 | - if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) { |
|
| 483 | - foreach ($option_list_for_attribute as $option_code => $option_value) { |
|
| 484 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value)); |
|
| 485 | - if ($option_code == $attribute_def['default_value']) { |
|
| 486 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code)); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - $do_changes = true; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /* Update attribute groups fo a given entity if attributes groups are set to be updated for current version */ |
|
| 496 | - if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 497 | - foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 498 | - $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 499 | - |
|
| 500 | - if ($entity_id > 0) { |
|
| 501 | - foreach ($attribute_set as $set_name => $set_groups) { |
|
| 502 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 503 | - $attribute_set_id = $wpdb->get_var($query); |
|
| 504 | - if ($attribute_set_id <= 0) { |
|
| 505 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name)); |
|
| 506 | - $attribute_set_id = $wpdb->insert_id; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - if ($attribute_set_id > 0) { |
|
| 510 | - foreach ($set_groups as $set_group_infos) { |
|
| 511 | - $set_group_infos_details = $set_group_infos['details']; |
|
| 512 | - unset($set_group_infos['details']); |
|
| 513 | - /* Change an attribute set status if definition specify this param */ |
|
| 514 | - if (isset($set_group_infos['status'])) { |
|
| 515 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 516 | - } |
|
| 517 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 518 | - $attribute_set_section_id = $wpdb->get_var($query); |
|
| 519 | - if ($attribute_set_section_id <= 0) { |
|
| 520 | - $new_set_section_infos = $set_group_infos; |
|
| 521 | - $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 522 | - $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 523 | - $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 524 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 525 | - $attribute_set_section_id = $wpdb->insert_id; |
|
| 526 | - } else { |
|
| 527 | - $new_set_section_infos = $set_group_infos; |
|
| 528 | - $new_set_section_infos['last_update_date'] = current_time('mysql', 0); |
|
| 529 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id)); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) { |
|
| 533 | - if (count($set_group_infos_details) <= 0) { |
|
| 534 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id)); |
|
| 535 | - } else { |
|
| 536 | - $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 537 | - $last_position = $wpdb->get_var($query); |
|
| 538 | - $position = (int) $last_position + 1; |
|
| 539 | - foreach ($set_group_infos_details as $attribute_code) { |
|
| 540 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 541 | - $attribute_id = $wpdb->get_var($query); |
|
| 542 | - if ($attribute_id > 0) { |
|
| 543 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position)); |
|
| 544 | - $position++; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - $do_changes = true; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return $do_changes; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Manage special operation on wpshop plugin update |
|
| 562 | - */ |
|
| 563 | - public static function make_specific_operation_on_update($version) |
|
| 564 | - { |
|
| 565 | - global $wpdb, $wp_rewrite; |
|
| 566 | - $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 567 | - |
|
| 568 | - switch ($version) { |
|
| 569 | - case 3: |
|
| 570 | - case 6: |
|
| 571 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 572 | - wp_cache_flush(); |
|
| 573 | - return true; |
|
| 574 | - break; |
|
| 575 | - case 8: |
|
| 576 | - /** Change metaboxes order for product in case it already exists */ |
|
| 577 | - $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product'); |
|
| 578 | - $customer_metaboxes_order = $wpdb->get_results($query); |
|
| 579 | - if (!empty($customer_metaboxes_order)) { |
|
| 580 | - foreach ($customer_metaboxes_order as $customer_metabox_order) { |
|
| 581 | - $do_changes = false; |
|
| 582 | - $current_order = unserialize($customer_metabox_order->meta_value); |
|
| 583 | - if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) { |
|
| 584 | - str_replace('wpshop_product_important_datas,', '', $current_order['normal']); |
|
| 585 | - $do_changes = true; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - if (array_key_exists('side', $current_order)) { |
|
| 589 | - str_replace('wpshop_product_important_datas,', '', $current_order['side']); |
|
| 590 | - str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']); |
|
| 591 | - $do_changes = true; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if (true === $do_changes) { |
|
| 595 | - $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id)); |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - } else { |
|
| 599 | - $users = get_users(array('role' => 'administrator')); |
|
| 600 | - if (!empty($users)) { |
|
| 601 | - foreach ($users as $user) { |
|
| 602 | - $user_meta = array( |
|
| 603 | - 'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', |
|
| 604 | - 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', |
|
| 605 | - 'advanced' => '', |
|
| 606 | - ); |
|
| 607 | - update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /* Update the product prices into database */ |
|
| 613 | - $query = $wpdb->prepare(" |
|
| 28 | + /** |
|
| 29 | + * Define the action launch when plugin is activate |
|
| 30 | + * |
|
| 31 | + * @return void |
|
| 32 | + */ |
|
| 33 | + public static function install_on_activation() |
|
| 34 | + { |
|
| 35 | + /* Create the different option needed for the plugin work properly */ |
|
| 36 | + add_option('wpshop_db_options', array('db_version' => 0)); |
|
| 37 | + add_option('wpshop_shop_default_currency', WPSHOP_SHOP_DEFAULT_CURRENCY); |
|
| 38 | + add_option('wpshop_emails', array('noreply_email' => get_bloginfo('admin_email'), 'contact_email' => get_bloginfo('admin_email'))); |
|
| 39 | + add_option('wpshop_catalog_product_option', array('wpshop_catalog_product_slug' => WPSHOP_CATALOG_PRODUCT_SLUG)); |
|
| 40 | + add_option('wpshop_catalog_categories_option', array('wpshop_catalog_categories_slug' => WPSHOP_CATALOG_CATEGORIES_SLUG)); |
|
| 41 | + add_option('wpshop_display_option', array('wpshop_display_list_type' => 'grid', 'wpshop_display_grid_element_number' => '3', 'wpshop_display_cat_sheet_output' => array('category_description', 'category_subcategory', 'category_subproduct'))); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Create the default pages |
|
| 46 | + */ |
|
| 47 | + public static function wpshop_insert_default_pages($pages_type = '') |
|
| 48 | + { |
|
| 49 | + global $wpdb, $wp_rewrite; |
|
| 50 | + |
|
| 51 | + /** if we will create any new pages we need to flush page cache */ |
|
| 52 | + $page_creation = false; |
|
| 53 | + $created_pages = array(); |
|
| 54 | + |
|
| 55 | + /** Default data array for add page */ |
|
| 56 | + $page_default_args = array( |
|
| 57 | + 'post_type' => 'page', |
|
| 58 | + 'comment_status' => 'closed', |
|
| 59 | + 'ping_status' => 'closed', |
|
| 60 | + 'post_status' => 'publish', |
|
| 61 | + 'post_author' => get_current_user_id(), |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + /** Get defined shop type */ |
|
| 65 | + $wpshop_shop_type = !empty($pages_type) ? $pages_type : get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 66 | + |
|
| 67 | + /** Get the default datas for installation - Pages */ |
|
| 68 | + $xml_default_pages = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_pages.xml'); |
|
| 69 | + $defined_default_pages = new SimpleXMLElement($xml_default_pages); |
|
| 70 | + foreach ($defined_default_pages->xpath('//pages/page') as $page) { |
|
| 71 | + if (($wpshop_shop_type == $page->attributes()->shop_type) || ('sale' == $wpshop_shop_type)) { |
|
| 72 | + $page_id = null; |
|
| 73 | + |
|
| 74 | + /** Do a specific check for cart page, for old wpshop installation */ |
|
| 75 | + if ('wpshop_cart_page_id' == (string) $page->attributes()->code) { |
|
| 76 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s AND post_type != %s", '%[wpshop_basket]%', 'revision'); |
|
| 77 | + $page_id = $wpdb->get_var($query); |
|
| 78 | + |
|
| 79 | + wp_update_post(array( |
|
| 80 | + 'ID' => $page_id, |
|
| 81 | + 'post_content' => (string) $page->content, |
|
| 82 | + )); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** Check if a page exists with the current content readed form xml file */ |
|
| 86 | + if (empty($page_id)) { |
|
| 87 | + $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string) $page->content . '%', 'revision'); |
|
| 88 | + $page_id = $wpdb->get_var($query); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** If the page does not exists create it */ |
|
| 92 | + if (empty($page_id)) { |
|
| 93 | + $default_page_args = wp_parse_args(array( |
|
| 94 | + 'post_title' => __((string) $page->title, 'wpshop'), |
|
| 95 | + 'post_name' => __((string) $page->slug, 'wpshop'), |
|
| 96 | + 'post_content' => __((string) $page->content, 'wpshop'), |
|
| 97 | + 'menu_order' => (string) $page->attributes()->position, |
|
| 98 | + ), $page_default_args); |
|
| 99 | + |
|
| 100 | + $page_id = wp_insert_post($default_page_args); |
|
| 101 | + $created_pages[] = (string) $page->attributes()->code; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** If the page is created or already exists associated the page to the good service */ |
|
| 105 | + if (!empty($page_id)) { |
|
| 106 | + add_option((string) $page->attributes()->code, $page_id); |
|
| 107 | + |
|
| 108 | + $page_creation = true; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** Check if page have been created in order to do specific action */ |
|
| 115 | + if (!empty($created_pages)) { |
|
| 116 | + /** If cart page and checkout page have just been created, change cart page id into checkout page id */ |
|
| 117 | + if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) { |
|
| 118 | + update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id')); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + wp_cache_flush(); |
|
| 124 | + /** If new page => empty cache */ |
|
| 125 | + if ($page_creation) { |
|
| 126 | + wp_cache_delete('all_page_ids', 'pages'); |
|
| 127 | + // $wp_rewrite->flush_rules(); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Insert sample datas when installing wpshop the first time if the admin choose |
|
| 133 | + */ |
|
| 134 | + public static function import_sample_datas() |
|
| 135 | + { |
|
| 136 | + global $wpdb, $wp_rewrite; |
|
| 137 | + |
|
| 138 | + /** Default data array for add product */ |
|
| 139 | + $product_default_args = array( |
|
| 140 | + 'comment_status' => 'closed', |
|
| 141 | + 'ping_status' => 'closed', |
|
| 142 | + 'post_status' => 'publish', |
|
| 143 | + 'post_author' => get_current_user_id(), |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + /** Get the default datas for installation - sample products */ |
|
| 147 | + $sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml'); |
|
| 148 | + $defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA); |
|
| 149 | + |
|
| 150 | + $namespaces = $defined_sample_datas->getDocNamespaces(); |
|
| 151 | + if (!isset($namespaces['wp'])) { |
|
| 152 | + $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if (!isset($namespaces['excerpt'])) { |
|
| 156 | + $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) { |
|
| 160 | + $dc = $product->children('http://purl.org/dc/elements/1.1/'); |
|
| 161 | + $content = $product->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 162 | + $excerpt = $product->children($namespaces['excerpt']); |
|
| 163 | + $wp = $product->children($namespaces['wp']); |
|
| 164 | + |
|
| 165 | + $product_args = wp_parse_args(array( |
|
| 166 | + 'post_title' => (string) $product->title, |
|
| 167 | + 'post_name' => (string) $wp->post_name, |
|
| 168 | + 'post_content' => (string) $content->encoded, |
|
| 169 | + 'post_excerpt' => (string) $excerpt->encoded, |
|
| 170 | + 'post_type' => (string) $wp->post_type, |
|
| 171 | + ), $product_default_args); |
|
| 172 | + |
|
| 173 | + $product_id = wp_insert_post($product_args); |
|
| 174 | + |
|
| 175 | + foreach ($wp->postmeta as $meta) { |
|
| 176 | + update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) { |
|
| 180 | + $wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/'); |
|
| 181 | + $wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 182 | + $wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']); |
|
| 183 | + $wps_pdt_var_wp = $product_variation->children($namespaces['wp']); |
|
| 184 | + |
|
| 185 | + $product_args = wp_parse_args(array( |
|
| 186 | + 'post_title' => (string) $product_variation->title, |
|
| 187 | + 'post_name' => (string) $wps_pdt_var_wp->post_name, |
|
| 188 | + 'post_content' => (string) $wps_pdt_var_content->encoded, |
|
| 189 | + 'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded, |
|
| 190 | + 'post_type' => (string) $wps_pdt_var_wp->post_type, |
|
| 191 | + 'post_parent' => $product_id, |
|
| 192 | + ), $product_default_args); |
|
| 193 | + |
|
| 194 | + $product_variation_id = wp_insert_post($product_args); |
|
| 195 | + |
|
| 196 | + foreach ($wps_pdt_var_wp->postmeta as $meta) { |
|
| 197 | + update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 205 | + */ |
|
| 206 | + public static function update_wpshop_dev() |
|
| 207 | + { |
|
| 208 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 209 | + |
|
| 210 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 211 | + |
|
| 212 | + self::execute_operation_on_db_for_update('dev'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 217 | + */ |
|
| 218 | + public static function update_wpshop() |
|
| 219 | + { |
|
| 220 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 221 | + $do_changes = false; |
|
| 222 | + |
|
| 223 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 224 | + |
|
| 225 | + $current_db_version = get_option('wpshop_db_options', 0); |
|
| 226 | + $current_db_version = $current_db_version['db_version']; |
|
| 227 | + |
|
| 228 | + $current_def_max_version = max(array_keys($wpshop_update_way)); |
|
| 229 | + $new_version = $current_def_max_version + 1; |
|
| 230 | + $version_nb_delta = $current_def_max_version - $current_db_version; |
|
| 231 | + |
|
| 232 | + /* Check if there are modification to do */ |
|
| 233 | + if ($current_def_max_version >= $current_db_version) { |
|
| 234 | + /* Check the lowest version of db to execute */ |
|
| 235 | + $lowest_version_to_execute = $current_def_max_version - $version_nb_delta; |
|
| 236 | + |
|
| 237 | + for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) { |
|
| 238 | + $do_changes = self::execute_operation_on_db_for_update($i); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /* Update the db version option value */ |
|
| 243 | + if ($do_changes) { |
|
| 244 | + $db_version = get_option('wpshop_db_options', 0); |
|
| 245 | + $db_version['db_version'] = $new_version; |
|
| 246 | + update_option('wpshop_db_options', $db_version); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Update db structure on each plugin update |
|
| 252 | + * |
|
| 253 | + * @param integer $i The current plugin db version |
|
| 254 | + * @return boolean If the changes are done correctly or not |
|
| 255 | + */ |
|
| 256 | + public static function alter_db_structure_on_update($i) |
|
| 257 | + { |
|
| 258 | + $do_changes = false; |
|
| 259 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete; |
|
| 260 | + |
|
| 261 | + /* Check if there are modification to do */ |
|
| 262 | + if (isset($wpshop_update_way[$i])) { |
|
| 263 | + /* Check if there are modification to make on table */ |
|
| 264 | + if (isset($wpshop_db_table_list[$i])) { |
|
| 265 | + foreach ($wpshop_db_table_list[$i] as $table_name) { |
|
| 266 | + dbDelta($wpshop_db_table[$table_name]); |
|
| 267 | + } |
|
| 268 | + $do_changes = true; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /* Request maker */ |
|
| 272 | + if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) { |
|
| 273 | + foreach ($wpshop_db_request[$i] as $request) { |
|
| 274 | + $wpdb->query($request); |
|
| 275 | + $do_changes = true; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /* Delete datas */ |
|
| 280 | + if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) { |
|
| 281 | + foreach ($wpshop_db_delete[$i] as $request) { |
|
| 282 | + $wpdb->query($request); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return $do_changes; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Do changes on database for wpshop plugin for a given version |
|
| 292 | + * |
|
| 293 | + * @param integer $i The wpshop db version to execute operation for |
|
| 294 | + * |
|
| 295 | + * @return boolean |
|
| 296 | + */ |
|
| 297 | + public static function execute_operation_on_db_for_update($i) |
|
| 298 | + { |
|
| 299 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete; |
|
| 300 | + $do_changes = false; |
|
| 301 | + |
|
| 302 | + /* Check if there are modification to do */ |
|
| 303 | + if (isset($wpshop_update_way[$i])) { |
|
| 304 | + $do_changes = self::alter_db_structure_on_update($i); |
|
| 305 | + |
|
| 306 | + /********************/ |
|
| 307 | + /* Insert data */ |
|
| 308 | + /********************/ |
|
| 309 | + /* Options content */ |
|
| 310 | + if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) { |
|
| 311 | + foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) { |
|
| 312 | + add_option($option_name, $option_content, '', 'yes'); |
|
| 313 | + } |
|
| 314 | + $do_changes = true; |
|
| 315 | + } |
|
| 316 | + if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) { |
|
| 317 | + foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) { |
|
| 318 | + $option_current_content = get_option($option_name); |
|
| 319 | + foreach ($option_content as $option_key => $option_value) { |
|
| 320 | + $option_current_content[$option_key] = $option_value; |
|
| 321 | + } |
|
| 322 | + update_option($option_name, $option_current_content); |
|
| 323 | + } |
|
| 324 | + $do_changes = true; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /* Eav content */ |
|
| 328 | + if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) { |
|
| 329 | + $do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes); |
|
| 330 | + } |
|
| 331 | + /* Eav content update */ |
|
| 332 | + if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) { |
|
| 333 | + $do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /* Add datas */ |
|
| 337 | + if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) { |
|
| 338 | + foreach ($wpshop_db_content_add[$i] as $table_name => $def) { |
|
| 339 | + foreach ($def as $information_index => $table_information) { |
|
| 340 | + $wpdb->insert($table_name, $table_information, '%s'); |
|
| 341 | + $do_changes = true; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /* Update datas */ |
|
| 347 | + if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) { |
|
| 348 | + foreach ($wpshop_db_content_update[$i] as $table_name => $def) { |
|
| 349 | + foreach ($def as $information_index => $table_information) { |
|
| 350 | + $wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s'); |
|
| 351 | + $do_changes = true; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $do_changes = self::make_specific_operation_on_update($i); |
|
| 358 | + |
|
| 359 | + return $do_changes; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Create specific data in eav db model |
|
| 364 | + * |
|
| 365 | + * @param array $eav_content The complete array with all element to create into database |
|
| 366 | + * @param boolean $do_changes The current state of changes to do |
|
| 367 | + * |
|
| 368 | + * @return boolean If there are changes to do or not |
|
| 369 | + */ |
|
| 370 | + public static function add_content_to_eav($eav_content, $do_changes) |
|
| 371 | + { |
|
| 372 | + global $wpdb; |
|
| 373 | + /* Create entities if entites are set to be created for the current version */ |
|
| 374 | + if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) { |
|
| 375 | + foreach ($eav_content['entities'] as $entity) { |
|
| 376 | + /* Creation de l'entité produit dans la table des posts */ |
|
| 377 | + wpshop_entities::create_cpt_from_csv_file($entity); |
|
| 378 | + } |
|
| 379 | + $do_changes = true; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /* Create attributes for a given entity if attributes are set to be created for current version */ |
|
| 383 | + if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 384 | + foreach ($eav_content['attributes'] as $entity_code) { |
|
| 385 | + wpshop_entities::create_cpt_attributes_from_csv_file($entity_code); |
|
| 386 | + } |
|
| 387 | + $do_changes = true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /* Create attribute groups for a given entity if attributes groups are set to be created for current version */ |
|
| 391 | + if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 392 | + foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 393 | + $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 394 | + |
|
| 395 | + if ($entity_id > 0) { |
|
| 396 | + foreach ($attribute_set as $set_name => $set_groups) { |
|
| 397 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 398 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 399 | + if ($attribute_set_id <= 0) { |
|
| 400 | + $attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name); |
|
| 401 | + if ($set_name == 'default') { |
|
| 402 | + $attribute_set_content['default_set'] = 'yes'; |
|
| 403 | + } |
|
| 404 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content); |
|
| 405 | + $attribute_set_id = $wpdb->insert_id; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if ($attribute_set_id > 0) { |
|
| 409 | + foreach ($set_groups as $set_group_infos) { |
|
| 410 | + $set_group_infos_details = $set_group_infos['details']; |
|
| 411 | + unset($set_group_infos['details']); |
|
| 412 | + /* Change an attribute set status if definition specify this param */ |
|
| 413 | + if (isset($set_group_infos['status'])) { |
|
| 414 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 415 | + } |
|
| 416 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 417 | + $attribute_set_section_id = $wpdb->get_var($query); |
|
| 418 | + if ($attribute_set_section_id <= 0) { |
|
| 419 | + $new_set_section_infos = $set_group_infos; |
|
| 420 | + $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 421 | + $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 422 | + $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 423 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 424 | + $attribute_set_section_id = $wpdb->insert_id; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) { |
|
| 428 | + $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 429 | + $last_position = $wpdb->get_var($query); |
|
| 430 | + $position = (int) $last_position + 1; |
|
| 431 | + foreach ($set_group_infos_details as $attribute_code) { |
|
| 432 | + $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 433 | + $attribute_id = $wpdb->get_row($query); |
|
| 434 | + |
|
| 435 | + if ($attribute_id->id > 0) { |
|
| 436 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position)); |
|
| 437 | + $position++; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + $do_changes = true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return $do_changes; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Update specific data in eav db model |
|
| 455 | + * |
|
| 456 | + * @param array $eav_content The complete array with all element to create into database |
|
| 457 | + * @param boolean $do_changes The current state of changes to do |
|
| 458 | + * |
|
| 459 | + * @return boolean If there are changes to do or not |
|
| 460 | + */ |
|
| 461 | + public static function update_eav_content($eav_content, $do_changes) |
|
| 462 | + { |
|
| 463 | + /* Update attributes fo a given entity if attributes are set to be updated for current version */ |
|
| 464 | + if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 465 | + foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) { |
|
| 466 | + foreach ($attribute_definition as $attribute_def) { |
|
| 467 | + $option_list_for_attribute = ''; |
|
| 468 | + if (isset($attribute_def['backend_input_values'])) { |
|
| 469 | + $option_list_for_attribute = $attribute_def['backend_input_values']; |
|
| 470 | + unset($attribute_def['backend_input_values']); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /* Get entity identifier from code */ |
|
| 474 | + $attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 475 | + $attribute_def['status'] = $attribute_def['attribute_status']; |
|
| 476 | + unset($attribute_def['attribute_status']); |
|
| 477 | + $attribute_def['last_update_date'] = current_time('mysql', 0); |
|
| 478 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code'])); |
|
| 479 | + $attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code'])); |
|
| 480 | + |
|
| 481 | + /* Insert option values if there are some to add for the current attribute */ |
|
| 482 | + if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) { |
|
| 483 | + foreach ($option_list_for_attribute as $option_code => $option_value) { |
|
| 484 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value)); |
|
| 485 | + if ($option_code == $attribute_def['default_value']) { |
|
| 486 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code)); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + $do_changes = true; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /* Update attribute groups fo a given entity if attributes groups are set to be updated for current version */ |
|
| 496 | + if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 497 | + foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 498 | + $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 499 | + |
|
| 500 | + if ($entity_id > 0) { |
|
| 501 | + foreach ($attribute_set as $set_name => $set_groups) { |
|
| 502 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 503 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 504 | + if ($attribute_set_id <= 0) { |
|
| 505 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name)); |
|
| 506 | + $attribute_set_id = $wpdb->insert_id; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ($attribute_set_id > 0) { |
|
| 510 | + foreach ($set_groups as $set_group_infos) { |
|
| 511 | + $set_group_infos_details = $set_group_infos['details']; |
|
| 512 | + unset($set_group_infos['details']); |
|
| 513 | + /* Change an attribute set status if definition specify this param */ |
|
| 514 | + if (isset($set_group_infos['status'])) { |
|
| 515 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 516 | + } |
|
| 517 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 518 | + $attribute_set_section_id = $wpdb->get_var($query); |
|
| 519 | + if ($attribute_set_section_id <= 0) { |
|
| 520 | + $new_set_section_infos = $set_group_infos; |
|
| 521 | + $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 522 | + $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 523 | + $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 524 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 525 | + $attribute_set_section_id = $wpdb->insert_id; |
|
| 526 | + } else { |
|
| 527 | + $new_set_section_infos = $set_group_infos; |
|
| 528 | + $new_set_section_infos['last_update_date'] = current_time('mysql', 0); |
|
| 529 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id)); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) { |
|
| 533 | + if (count($set_group_infos_details) <= 0) { |
|
| 534 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id)); |
|
| 535 | + } else { |
|
| 536 | + $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 537 | + $last_position = $wpdb->get_var($query); |
|
| 538 | + $position = (int) $last_position + 1; |
|
| 539 | + foreach ($set_group_infos_details as $attribute_code) { |
|
| 540 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 541 | + $attribute_id = $wpdb->get_var($query); |
|
| 542 | + if ($attribute_id > 0) { |
|
| 543 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position)); |
|
| 544 | + $position++; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + $do_changes = true; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return $do_changes; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Manage special operation on wpshop plugin update |
|
| 562 | + */ |
|
| 563 | + public static function make_specific_operation_on_update($version) |
|
| 564 | + { |
|
| 565 | + global $wpdb, $wp_rewrite; |
|
| 566 | + $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 567 | + |
|
| 568 | + switch ($version) { |
|
| 569 | + case 3: |
|
| 570 | + case 6: |
|
| 571 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 572 | + wp_cache_flush(); |
|
| 573 | + return true; |
|
| 574 | + break; |
|
| 575 | + case 8: |
|
| 576 | + /** Change metaboxes order for product in case it already exists */ |
|
| 577 | + $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product'); |
|
| 578 | + $customer_metaboxes_order = $wpdb->get_results($query); |
|
| 579 | + if (!empty($customer_metaboxes_order)) { |
|
| 580 | + foreach ($customer_metaboxes_order as $customer_metabox_order) { |
|
| 581 | + $do_changes = false; |
|
| 582 | + $current_order = unserialize($customer_metabox_order->meta_value); |
|
| 583 | + if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) { |
|
| 584 | + str_replace('wpshop_product_important_datas,', '', $current_order['normal']); |
|
| 585 | + $do_changes = true; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + if (array_key_exists('side', $current_order)) { |
|
| 589 | + str_replace('wpshop_product_important_datas,', '', $current_order['side']); |
|
| 590 | + str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']); |
|
| 591 | + $do_changes = true; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if (true === $do_changes) { |
|
| 595 | + $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id)); |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + } else { |
|
| 599 | + $users = get_users(array('role' => 'administrator')); |
|
| 600 | + if (!empty($users)) { |
|
| 601 | + foreach ($users as $user) { |
|
| 602 | + $user_meta = array( |
|
| 603 | + 'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', |
|
| 604 | + 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', |
|
| 605 | + 'advanced' => '', |
|
| 606 | + ); |
|
| 607 | + update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /* Update the product prices into database */ |
|
| 613 | + $query = $wpdb->prepare(" |
|
| 614 | 614 | SELECT |
| 615 | 615 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price, |
| 616 | 616 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht, |
| 617 | 617 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva, |
| 618 | 618 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva'); |
| 619 | - $product_prices = $wpdb->get_row($query); |
|
| 620 | - $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva)); |
|
| 621 | - $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price); |
|
| 622 | - $price_list = $wpdb->get_results($query); |
|
| 623 | - foreach ($price_list as $existing_ttc_price) { |
|
| 624 | - $tax_rate = 1.20; |
|
| 625 | - $price_ht = $existing_ttc_price->value / $tax_rate; |
|
| 626 | - $tax_amount = $existing_ttc_price->value - $price_ht; |
|
| 627 | - |
|
| 628 | - $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0))); |
|
| 629 | - $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0))); |
|
| 630 | - $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0))); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /* Update orders structure into database */ |
|
| 634 | - $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 635 | - foreach ($orders_id as $o) { |
|
| 636 | - $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 637 | - $neworder = array(); |
|
| 638 | - $items = array(); |
|
| 639 | - |
|
| 640 | - if (!isset($myorder['order_tva'])) { |
|
| 641 | - $order_total_ht = 0; |
|
| 642 | - $order_total_ttc = 0; |
|
| 643 | - $order_tva = array('20' => 0); |
|
| 644 | - |
|
| 645 | - foreach ($myorder['order_items'] as $item) { |
|
| 646 | - /* item */ |
|
| 647 | - $pu_ht = $item['cost'] / 1.20; |
|
| 648 | - $pu_tva = $item['cost'] - $pu_ht; |
|
| 649 | - $total_ht = $pu_ht * $item['qty']; |
|
| 650 | - $tva_total_amount = $pu_tva * $item['qty']; |
|
| 651 | - $total_ttc = $item['cost'] * $item['qty']; |
|
| 652 | - /* item */ |
|
| 653 | - $order_total_ht += $total_ht; |
|
| 654 | - $order_total_ttc += $total_ttc; |
|
| 655 | - $order_tva['20'] += $tva_total_amount; |
|
| 656 | - |
|
| 657 | - $items[] = array( |
|
| 658 | - 'item_id' => $item['id'], |
|
| 659 | - 'item_ref' => 'Nc', |
|
| 660 | - 'item_name' => $item['name'], |
|
| 661 | - 'item_qty' => $item['qty'], |
|
| 662 | - |
|
| 663 | - 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), |
|
| 664 | - 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), |
|
| 665 | - |
|
| 666 | - 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), |
|
| 667 | - 'item_ecotaxe_tva' => 20, |
|
| 668 | - 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), |
|
| 669 | - |
|
| 670 | - 'item_discount_type' => 0, |
|
| 671 | - 'item_discount_value' => 0, |
|
| 672 | - 'item_discount_amount' => number_format(0, 2, '.', ''), |
|
| 673 | - |
|
| 674 | - 'item_tva_rate' => 20, |
|
| 675 | - 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), |
|
| 676 | - |
|
| 677 | - 'item_total_ht' => number_format($total_ht, 2, '.', ''), |
|
| 678 | - 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), |
|
| 679 | - 'item_total_ttc' => number_format($total_ttc, 2, '.', ''), |
|
| 680 | - /*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/ |
|
| 681 | - ); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - $neworder = array( |
|
| 685 | - 'order_key' => $myorder['order_key'], |
|
| 686 | - 'customer_id' => $myorder['customer_id'], |
|
| 687 | - 'order_status' => $myorder['order_status'], |
|
| 688 | - 'order_date' => $myorder['order_date'], |
|
| 689 | - 'order_payment_date' => $myorder['order_payment_date'], |
|
| 690 | - 'order_shipping_date' => $myorder['order_shipping_date'], |
|
| 691 | - 'payment_method' => $myorder['payment_method'], |
|
| 692 | - 'order_invoice_ref' => '', |
|
| 693 | - 'order_currency' => $myorder['order_currency'], |
|
| 694 | - 'order_total_ht' => $order_total_ht, |
|
| 695 | - 'order_total_ttc' => $order_total_ttc, |
|
| 696 | - 'order_grand_total' => $order_total_ttc, |
|
| 697 | - 'order_shipping_cost' => number_format(0, 2, '.', ''), |
|
| 698 | - 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), |
|
| 699 | - 'order_items' => $items, |
|
| 700 | - ); |
|
| 701 | - /* Update the order postmeta */ |
|
| 702 | - update_post_meta($o->ID, '_order_postmeta', $neworder); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 707 | - wp_cache_flush(); |
|
| 708 | - return true; |
|
| 709 | - break; |
|
| 710 | - case 12: |
|
| 711 | - $query = "SELECT ID FROM " . $wpdb->users; |
|
| 712 | - $user_list = $wpdb->get_results($query); |
|
| 713 | - foreach ($user_list as $user) { |
|
| 714 | - $user_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 715 | - $user_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 716 | - $shipping_info = get_user_meta($user->ID, 'shipping_info', true); |
|
| 717 | - |
|
| 718 | - if (($user_first_name == '') && !empty($shipping_info['first_name'])) { |
|
| 719 | - update_user_meta($user->ID, 'first_name', $shipping_info['first_name']); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (($user_last_name == '') && !empty($shipping_info['last_name'])) { |
|
| 723 | - update_user_meta($user->ID, 'last_name', $shipping_info['last_name']); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /* Update orders structure into database */ |
|
| 728 | - $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 729 | - foreach ($orders_id as $o) { |
|
| 730 | - $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 731 | - if (!empty($myorder)) { |
|
| 732 | - $new_items = array(); |
|
| 733 | - foreach ($myorder['order_items'] as $item) { |
|
| 734 | - $new_items = $item; |
|
| 735 | - $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount'; |
|
| 736 | - // unset($new_items['item_discount_rate']); |
|
| 737 | - $new_items['item_discount_value'] = 0; |
|
| 738 | - } |
|
| 739 | - $myorder['order_items'] = $new_items; |
|
| 740 | - |
|
| 741 | - /* Update the order postmeta */ |
|
| 742 | - update_post_meta($o->ID, '_order_postmeta', $myorder); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - /* Delete useless database table */ |
|
| 747 | - $query = "DROP TABLE " . WPSHOP_DBT_CART; |
|
| 748 | - $wpdb->query($query); |
|
| 749 | - $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS; |
|
| 750 | - $wpdb->query($query); |
|
| 751 | - return true; |
|
| 752 | - break; |
|
| 753 | - case 13: |
|
| 754 | - $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true); |
|
| 755 | - foreach ($attribute_used_for_sort_by as $attribute) { |
|
| 756 | - $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 757 | - foreach ($data as $post) { |
|
| 758 | - $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 759 | - if (!empty($postmeta[$attribute->code])) { |
|
| 760 | - update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - wp_reset_query(); |
|
| 764 | - } |
|
| 765 | - return true; |
|
| 766 | - break; |
|
| 767 | - case 17: |
|
| 768 | - $products = query_posts(array( |
|
| 769 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) |
|
| 770 | - ); |
|
| 771 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes'); |
|
| 772 | - $default_attribute_set = $wpdb->get_var($query); |
|
| 773 | - foreach ($products as $product) { |
|
| 774 | - $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 775 | - if (empty($p_att_set_id)) { |
|
| 776 | - /* Update the attribute set id for the current product */ |
|
| 777 | - update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set); |
|
| 778 | - } |
|
| 779 | - wp_reset_query(); |
|
| 780 | - } |
|
| 781 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 782 | - wp_cache_flush(); |
|
| 783 | - return true; |
|
| 784 | - break; |
|
| 785 | - case 18: |
|
| 786 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 787 | - wp_cache_flush(); |
|
| 788 | - return true; |
|
| 789 | - break; |
|
| 790 | - case 19: |
|
| 791 | - $wp_rewrite->flush_rules(); |
|
| 792 | - return true; |
|
| 793 | - break; |
|
| 794 | - |
|
| 795 | - case 21: |
|
| 796 | - /** |
|
| 797 | - * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement |
|
| 798 | - */ |
|
| 799 | - $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock'); |
|
| 800 | - $manage_stock_option = $wpdb->get_results($query); |
|
| 801 | - if (!empty($manage_stock_option)) { |
|
| 802 | - $no_is_present = false; |
|
| 803 | - $attribute_id = $manage_stock_option[0]->attribute_id; |
|
| 804 | - foreach ($manage_stock_option as $manage_definition) { |
|
| 805 | - if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) { |
|
| 806 | - $no_is_present = true; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - if (!$no_is_present) { |
|
| 810 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop'))); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** Change price attribute set section order for default set */ |
|
| 815 | - $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 816 | - unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); |
|
| 817 | - $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')"; |
|
| 818 | - $attribute_ids = $wpdb->get_var($query); |
|
| 819 | - |
|
| 820 | - $query = $wpdb->prepare(" |
|
| 619 | + $product_prices = $wpdb->get_row($query); |
|
| 620 | + $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva)); |
|
| 621 | + $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price); |
|
| 622 | + $price_list = $wpdb->get_results($query); |
|
| 623 | + foreach ($price_list as $existing_ttc_price) { |
|
| 624 | + $tax_rate = 1.20; |
|
| 625 | + $price_ht = $existing_ttc_price->value / $tax_rate; |
|
| 626 | + $tax_amount = $existing_ttc_price->value - $price_ht; |
|
| 627 | + |
|
| 628 | + $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0))); |
|
| 629 | + $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0))); |
|
| 630 | + $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0))); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /* Update orders structure into database */ |
|
| 634 | + $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 635 | + foreach ($orders_id as $o) { |
|
| 636 | + $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 637 | + $neworder = array(); |
|
| 638 | + $items = array(); |
|
| 639 | + |
|
| 640 | + if (!isset($myorder['order_tva'])) { |
|
| 641 | + $order_total_ht = 0; |
|
| 642 | + $order_total_ttc = 0; |
|
| 643 | + $order_tva = array('20' => 0); |
|
| 644 | + |
|
| 645 | + foreach ($myorder['order_items'] as $item) { |
|
| 646 | + /* item */ |
|
| 647 | + $pu_ht = $item['cost'] / 1.20; |
|
| 648 | + $pu_tva = $item['cost'] - $pu_ht; |
|
| 649 | + $total_ht = $pu_ht * $item['qty']; |
|
| 650 | + $tva_total_amount = $pu_tva * $item['qty']; |
|
| 651 | + $total_ttc = $item['cost'] * $item['qty']; |
|
| 652 | + /* item */ |
|
| 653 | + $order_total_ht += $total_ht; |
|
| 654 | + $order_total_ttc += $total_ttc; |
|
| 655 | + $order_tva['20'] += $tva_total_amount; |
|
| 656 | + |
|
| 657 | + $items[] = array( |
|
| 658 | + 'item_id' => $item['id'], |
|
| 659 | + 'item_ref' => 'Nc', |
|
| 660 | + 'item_name' => $item['name'], |
|
| 661 | + 'item_qty' => $item['qty'], |
|
| 662 | + |
|
| 663 | + 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), |
|
| 664 | + 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), |
|
| 665 | + |
|
| 666 | + 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), |
|
| 667 | + 'item_ecotaxe_tva' => 20, |
|
| 668 | + 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), |
|
| 669 | + |
|
| 670 | + 'item_discount_type' => 0, |
|
| 671 | + 'item_discount_value' => 0, |
|
| 672 | + 'item_discount_amount' => number_format(0, 2, '.', ''), |
|
| 673 | + |
|
| 674 | + 'item_tva_rate' => 20, |
|
| 675 | + 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), |
|
| 676 | + |
|
| 677 | + 'item_total_ht' => number_format($total_ht, 2, '.', ''), |
|
| 678 | + 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), |
|
| 679 | + 'item_total_ttc' => number_format($total_ttc, 2, '.', ''), |
|
| 680 | + /*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/ |
|
| 681 | + ); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + $neworder = array( |
|
| 685 | + 'order_key' => $myorder['order_key'], |
|
| 686 | + 'customer_id' => $myorder['customer_id'], |
|
| 687 | + 'order_status' => $myorder['order_status'], |
|
| 688 | + 'order_date' => $myorder['order_date'], |
|
| 689 | + 'order_payment_date' => $myorder['order_payment_date'], |
|
| 690 | + 'order_shipping_date' => $myorder['order_shipping_date'], |
|
| 691 | + 'payment_method' => $myorder['payment_method'], |
|
| 692 | + 'order_invoice_ref' => '', |
|
| 693 | + 'order_currency' => $myorder['order_currency'], |
|
| 694 | + 'order_total_ht' => $order_total_ht, |
|
| 695 | + 'order_total_ttc' => $order_total_ttc, |
|
| 696 | + 'order_grand_total' => $order_total_ttc, |
|
| 697 | + 'order_shipping_cost' => number_format(0, 2, '.', ''), |
|
| 698 | + 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), |
|
| 699 | + 'order_items' => $items, |
|
| 700 | + ); |
|
| 701 | + /* Update the order postmeta */ |
|
| 702 | + update_post_meta($o->ID, '_order_postmeta', $neworder); |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 707 | + wp_cache_flush(); |
|
| 708 | + return true; |
|
| 709 | + break; |
|
| 710 | + case 12: |
|
| 711 | + $query = "SELECT ID FROM " . $wpdb->users; |
|
| 712 | + $user_list = $wpdb->get_results($query); |
|
| 713 | + foreach ($user_list as $user) { |
|
| 714 | + $user_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 715 | + $user_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 716 | + $shipping_info = get_user_meta($user->ID, 'shipping_info', true); |
|
| 717 | + |
|
| 718 | + if (($user_first_name == '') && !empty($shipping_info['first_name'])) { |
|
| 719 | + update_user_meta($user->ID, 'first_name', $shipping_info['first_name']); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (($user_last_name == '') && !empty($shipping_info['last_name'])) { |
|
| 723 | + update_user_meta($user->ID, 'last_name', $shipping_info['last_name']); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /* Update orders structure into database */ |
|
| 728 | + $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 729 | + foreach ($orders_id as $o) { |
|
| 730 | + $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 731 | + if (!empty($myorder)) { |
|
| 732 | + $new_items = array(); |
|
| 733 | + foreach ($myorder['order_items'] as $item) { |
|
| 734 | + $new_items = $item; |
|
| 735 | + $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount'; |
|
| 736 | + // unset($new_items['item_discount_rate']); |
|
| 737 | + $new_items['item_discount_value'] = 0; |
|
| 738 | + } |
|
| 739 | + $myorder['order_items'] = $new_items; |
|
| 740 | + |
|
| 741 | + /* Update the order postmeta */ |
|
| 742 | + update_post_meta($o->ID, '_order_postmeta', $myorder); |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + /* Delete useless database table */ |
|
| 747 | + $query = "DROP TABLE " . WPSHOP_DBT_CART; |
|
| 748 | + $wpdb->query($query); |
|
| 749 | + $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS; |
|
| 750 | + $wpdb->query($query); |
|
| 751 | + return true; |
|
| 752 | + break; |
|
| 753 | + case 13: |
|
| 754 | + $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true); |
|
| 755 | + foreach ($attribute_used_for_sort_by as $attribute) { |
|
| 756 | + $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 757 | + foreach ($data as $post) { |
|
| 758 | + $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 759 | + if (!empty($postmeta[$attribute->code])) { |
|
| 760 | + update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + wp_reset_query(); |
|
| 764 | + } |
|
| 765 | + return true; |
|
| 766 | + break; |
|
| 767 | + case 17: |
|
| 768 | + $products = query_posts(array( |
|
| 769 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) |
|
| 770 | + ); |
|
| 771 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes'); |
|
| 772 | + $default_attribute_set = $wpdb->get_var($query); |
|
| 773 | + foreach ($products as $product) { |
|
| 774 | + $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 775 | + if (empty($p_att_set_id)) { |
|
| 776 | + /* Update the attribute set id for the current product */ |
|
| 777 | + update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set); |
|
| 778 | + } |
|
| 779 | + wp_reset_query(); |
|
| 780 | + } |
|
| 781 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 782 | + wp_cache_flush(); |
|
| 783 | + return true; |
|
| 784 | + break; |
|
| 785 | + case 18: |
|
| 786 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 787 | + wp_cache_flush(); |
|
| 788 | + return true; |
|
| 789 | + break; |
|
| 790 | + case 19: |
|
| 791 | + $wp_rewrite->flush_rules(); |
|
| 792 | + return true; |
|
| 793 | + break; |
|
| 794 | + |
|
| 795 | + case 21: |
|
| 796 | + /** |
|
| 797 | + * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement |
|
| 798 | + */ |
|
| 799 | + $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock'); |
|
| 800 | + $manage_stock_option = $wpdb->get_results($query); |
|
| 801 | + if (!empty($manage_stock_option)) { |
|
| 802 | + $no_is_present = false; |
|
| 803 | + $attribute_id = $manage_stock_option[0]->attribute_id; |
|
| 804 | + foreach ($manage_stock_option as $manage_definition) { |
|
| 805 | + if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) { |
|
| 806 | + $no_is_present = true; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + if (!$no_is_present) { |
|
| 810 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop'))); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** Change price attribute set section order for default set */ |
|
| 815 | + $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 816 | + unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); |
|
| 817 | + $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')"; |
|
| 818 | + $attribute_ids = $wpdb->get_var($query); |
|
| 819 | + |
|
| 820 | + $query = $wpdb->prepare(" |
|
| 821 | 821 | SELECT ATTR_DET.attribute_group_id |
| 822 | 822 | FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET |
| 823 | 823 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTR_GROUP ON ((ATTR_GROUP.id = ATTR_DET.attribute_group_id) AND (ATTR_GROUP.code = %s)) |
| 824 | 824 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTR_SET ON ((ATTR_SET.id = ATTR_GROUP.attribute_set_id) AND (ATTR_SET.name = %s)) |
| 825 | 825 | WHERE ATTR_DET.attribute_id IN (" . $attribute_ids . ")" |
| 826 | - , 'prices', __('default', 'wpshop')); |
|
| 827 | - $list = $wpdb->get_results($query); |
|
| 828 | - if (!empty($list)) { |
|
| 829 | - $change_order = true; |
|
| 830 | - $old_value = $list[0]->attribute_group_id; |
|
| 831 | - unset($list[0]); |
|
| 832 | - if (!empty($list)) { |
|
| 833 | - foreach ($list as $data) { |
|
| 834 | - if ($old_value != $data->attribute_group_id) { |
|
| 835 | - $change_order = false; |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - if ($change_order) { |
|
| 839 | - foreach ($price_tab as $price_code) { |
|
| 840 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code); |
|
| 841 | - $attribute_id = $wpdb->get_var($query); |
|
| 842 | - switch ($price_code) { |
|
| 843 | - case WPSHOP_PRODUCT_PRICE_HT: |
|
| 844 | - $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 1 : 3; |
|
| 845 | - break; |
|
| 846 | - case WPSHOP_PRODUCT_PRICE_TAX: |
|
| 847 | - $position = 2; |
|
| 848 | - break; |
|
| 849 | - case WPSHOP_PRODUCT_PRICE_TTC: |
|
| 850 | - $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 3 : 1; |
|
| 851 | - break; |
|
| 852 | - case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT: |
|
| 853 | - $position = 4; |
|
| 854 | - break; |
|
| 855 | - } |
|
| 856 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id)); |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - return true; |
|
| 862 | - break; |
|
| 863 | - case 22: |
|
| 864 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 865 | - $product_entity_id = $wpdb->get_var($query); |
|
| 866 | - if (empty($product_entityd_id) || ($product_entity_id <= 0) || !$product_entity_id) { |
|
| 867 | - /* Create the product entity into post table */ |
|
| 868 | - $product_entity = array( |
|
| 869 | - 'post_title' => __('Products', 'wpshop'), |
|
| 870 | - 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 871 | - 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), |
|
| 872 | - 'post_status' => 'publish', |
|
| 873 | - 'post_author' => 1, |
|
| 874 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, |
|
| 875 | - ); |
|
| 876 | - $product_entity_id = wp_insert_post($product_entity); |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /* Update eav table with the new entity id for product */ |
|
| 880 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 881 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 882 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 883 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 884 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 885 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 886 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 887 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 888 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 889 | - |
|
| 890 | - /* Create an element of customer entity for each existing user */ |
|
| 891 | - $user_list = get_users(); |
|
| 892 | - foreach ($user_list as $user) { |
|
| 893 | - wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - return true; |
|
| 897 | - break; |
|
| 898 | - case 23: |
|
| 899 | - /* Delete duplicate entities */ |
|
| 900 | - $query = ("SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' "); |
|
| 901 | - $product_entity_list = $wpdb->get_results($query); |
|
| 902 | - if (count($product_entity_list) > 1) { |
|
| 903 | - $i = 0; |
|
| 904 | - foreach ($product_entity_list as $product_entity) { |
|
| 905 | - if ($i > 0) { |
|
| 906 | - wp_delete_post($product_entity->ID); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - return true; |
|
| 911 | - break; |
|
| 912 | - case 24: |
|
| 913 | - /* Update the link status for disabled attribute set */ |
|
| 914 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted'); |
|
| 915 | - $deleted_attribute_group = $wpdb->get_results($query); |
|
| 916 | - if (!empty($deleted_attribute_group)) { |
|
| 917 | - foreach ($deleted_attribute_group as $group) { |
|
| 918 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id)); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - /* Update entities meta management */ |
|
| 923 | - $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES)); |
|
| 924 | - if (!empty($entities)) { |
|
| 925 | - foreach ($entities as $entity) { |
|
| 926 | - $support = get_post_meta($entity->ID, '_wpshop_entity_support', true); |
|
| 927 | - $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true); |
|
| 928 | - update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite))); |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - wp_reset_query(); |
|
| 932 | - return true; |
|
| 933 | - break; |
|
| 934 | - case 25: |
|
| 935 | - /* Get the first entities of product and customer */ |
|
| 936 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 937 | - $product_entity_id = $wpdb->get_var($query); |
|
| 938 | - |
|
| 939 | - /* Update attributes that are not linked with entities */ |
|
| 940 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0)); |
|
| 941 | - |
|
| 942 | - /* Get entities that have been created a lot of time and delete them */ |
|
| 943 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 944 | - $entities_to_delete = $wpdb->get_results($query); |
|
| 945 | - if (!empty($entities_to_delete) && is_array($entities_to_delete)) { |
|
| 946 | - foreach ($entities_to_delete as $entity) { |
|
| 947 | - wp_delete_post($entity->ID, true); |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - /* Get post list that are children of entities created a lot of time */ |
|
| 952 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%"); |
|
| 953 | - $entities_to_update = $wpdb->get_results($query); |
|
| 954 | - if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 955 | - foreach ($entities_to_update as $entity) { |
|
| 956 | - wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)); |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%"); |
|
| 960 | - $entities_to_update = $wpdb->get_results($query); |
|
| 961 | - if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 962 | - foreach ($entities_to_update as $entity) { |
|
| 963 | - wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - /* Change addons managament */ |
|
| 968 | - $wpshop_addons_options = get_option('wpshop_addons_state', array()); |
|
| 969 | - if (!empty($wpshop_addons_options)) { |
|
| 970 | - foreach ($wpshop_addons_options as $addon_name => $addon_state) { |
|
| 971 | - $options_args = array(); |
|
| 972 | - $options_args[$addon_name]['activate'] = $addon_state; |
|
| 973 | - $options_args[$addon_name]['activation_date'] = current_time('mysql', 0); |
|
| 974 | - if (!$addon_state) { |
|
| 975 | - $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args); |
|
| 979 | - } |
|
| 980 | - delete_option('wpshop_addons_state'); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - /* Update the different entities id into attribute set details table */ |
|
| 984 | - $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 985 | - $wpdb->query($query); |
|
| 986 | - |
|
| 987 | - return true; |
|
| 988 | - break; |
|
| 989 | - case 26: |
|
| 990 | - $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' "; |
|
| 991 | - $results = $wpdb->get_results($query); |
|
| 992 | - foreach ($results as $result) { |
|
| 993 | - $order_info = unserialize($result->meta_value); |
|
| 994 | - update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']); |
|
| 995 | - update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']); |
|
| 996 | - update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - /* Update the different entities id into attribute set details table */ |
|
| 1000 | - $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 1001 | - $wpdb->query($query); |
|
| 1002 | - |
|
| 1003 | - return true; |
|
| 1004 | - break; |
|
| 1005 | - |
|
| 1006 | - case 29: |
|
| 1007 | - $billing_title = __('Billing address', 'wpshop'); |
|
| 1008 | - $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1009 | - |
|
| 1010 | - //UPDATE USERS ADDRESSES |
|
| 1011 | - $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"'; |
|
| 1012 | - $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"'; |
|
| 1013 | - |
|
| 1014 | - $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query); |
|
| 1015 | - $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query); |
|
| 1016 | - |
|
| 1017 | - //Add Address & Google Map API KEY options |
|
| 1018 | - add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes'); |
|
| 1019 | - add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes'); |
|
| 1020 | - add_option('wpshop_google_map_api_key', '', '', 'yes'); |
|
| 1021 | - |
|
| 1022 | - $query = 'SELECT * FROM ' . $wpdb->users . ''; |
|
| 1023 | - $results = $wpdb->get_results($query); |
|
| 1024 | - foreach ($results as $result) { |
|
| 1025 | - $billing_infos = get_user_meta($result->ID, 'billing_info', true); |
|
| 1026 | - $shipping_infos = get_user_meta($result->ID, 'shipping_info', true); |
|
| 1027 | - if (!empty($billing_infos)) { |
|
| 1028 | - //Save Billing Infos |
|
| 1029 | - $billing_address = array(); |
|
| 1030 | - if (!empty($billing_infos['civility'])) { |
|
| 1031 | - switch ($billing_infos['civility']) { |
|
| 1032 | - case 1: |
|
| 1033 | - $civility = $mister_id; |
|
| 1034 | - break; |
|
| 1035 | - case 2: |
|
| 1036 | - $civility = $madam_id; |
|
| 1037 | - break; |
|
| 1038 | - case 3: |
|
| 1039 | - $civility = $miss_id; |
|
| 1040 | - break; |
|
| 1041 | - } |
|
| 1042 | - } else { |
|
| 1043 | - $civility = $mister_id; |
|
| 1044 | - } |
|
| 1045 | - $billing_address = array('address_title' => $billing_title, |
|
| 1046 | - 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', |
|
| 1047 | - 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', |
|
| 1048 | - 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', |
|
| 1049 | - 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', |
|
| 1050 | - 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', |
|
| 1051 | - 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', |
|
| 1052 | - 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', |
|
| 1053 | - 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', |
|
| 1054 | - 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', |
|
| 1055 | - 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', |
|
| 1056 | - 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', |
|
| 1057 | - 'civility' => $civility, |
|
| 1058 | - ); |
|
| 1059 | - //Create the post and post_meta for the billing address |
|
| 1060 | - $post_address = array( |
|
| 1061 | - 'post_author' => $result->ID, |
|
| 1062 | - 'post_title' => $billing_title, |
|
| 1063 | - 'post_status' => 'publish', |
|
| 1064 | - 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1065 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1066 | - 'post_parent' => $result->ID, |
|
| 1067 | - ); |
|
| 1068 | - $post_address_id = wp_insert_post($post_address); |
|
| 1069 | - |
|
| 1070 | - //Create the post_meta with the address infos |
|
| 1071 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address); |
|
| 1072 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - if (!empty($shipping_infos)) { |
|
| 1076 | - //Save Shipping Infos |
|
| 1077 | - if (!empty($shipping_infos['civility'])) { |
|
| 1078 | - switch ($shipping_infos['civility']) { |
|
| 1079 | - case 1: |
|
| 1080 | - $civility = $mister_id; |
|
| 1081 | - break; |
|
| 1082 | - case 2: |
|
| 1083 | - $civility = $madam_id; |
|
| 1084 | - break; |
|
| 1085 | - case 3: |
|
| 1086 | - $civility = $miss_id; |
|
| 1087 | - break; |
|
| 1088 | - } |
|
| 1089 | - } else { |
|
| 1090 | - $civility = $mister_id; |
|
| 1091 | - } |
|
| 1092 | - $shipping_address = array(); |
|
| 1093 | - $shipping_address = array('address_title' => $shipping_title, |
|
| 1094 | - 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', |
|
| 1095 | - 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', |
|
| 1096 | - 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', |
|
| 1097 | - 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', |
|
| 1098 | - 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', |
|
| 1099 | - 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', |
|
| 1100 | - 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', |
|
| 1101 | - 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', |
|
| 1102 | - 'civility' => $civility, |
|
| 1103 | - ); |
|
| 1104 | - //Create the post and post_meta for the billing address |
|
| 1105 | - $post_address = array( |
|
| 1106 | - 'post_author' => $result->ID, |
|
| 1107 | - 'post_title' => $shipping_title, |
|
| 1108 | - 'post_status' => 'publish', |
|
| 1109 | - 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1110 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1111 | - 'post_parent' => $result->ID, |
|
| 1112 | - ); |
|
| 1113 | - $post_address_id = wp_insert_post($post_address); |
|
| 1114 | - //Create the post_meta with the address infos |
|
| 1115 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address); |
|
| 1116 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id); |
|
| 1117 | - } |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - // FORMATE THE ORDER ADDRESSES INFOS |
|
| 1121 | - $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1122 | - foreach ($results as $result) { |
|
| 1123 | - $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1124 | - |
|
| 1125 | - $billing_address = array(); |
|
| 1126 | - if (!empty($address['billing'])) { |
|
| 1127 | - if (!empty($address['billing']['civility'])) { |
|
| 1128 | - switch ($address['billing']['civility']) { |
|
| 1129 | - case 1: |
|
| 1130 | - $civility = $mister_id; |
|
| 1131 | - break; |
|
| 1132 | - case 2: |
|
| 1133 | - $civility = $madam_id; |
|
| 1134 | - break; |
|
| 1135 | - case 3: |
|
| 1136 | - $civility = $miss_id; |
|
| 1137 | - break; |
|
| 1138 | - default: |
|
| 1139 | - $civility = $mister_id; |
|
| 1140 | - break; |
|
| 1141 | - } |
|
| 1142 | - } else { |
|
| 1143 | - $civility = $mister_id; |
|
| 1144 | - } |
|
| 1145 | - $billing_address = array('address_title' => $billing_title, |
|
| 1146 | - 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1147 | - 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1148 | - 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1149 | - 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1150 | - 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1151 | - 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1152 | - 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1153 | - 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1154 | - 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1155 | - 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1156 | - 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1157 | - 'civility' => $civility, |
|
| 1158 | - ); |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - $shipping_address = array(); |
|
| 1162 | - if (!empty($address['shipping'])) { |
|
| 1163 | - if (!empty($address['shipping']['civility'])) { |
|
| 1164 | - switch ($address['shipping']['civility']) { |
|
| 1165 | - case 1: |
|
| 1166 | - $civility = $mister_id; |
|
| 1167 | - break; |
|
| 1168 | - case 2: |
|
| 1169 | - $civility = $madam_id; |
|
| 1170 | - break; |
|
| 1171 | - case 3: |
|
| 1172 | - $civility = $miss_id; |
|
| 1173 | - break; |
|
| 1174 | - } |
|
| 1175 | - } else { |
|
| 1176 | - $civility = $mister_id; |
|
| 1177 | - } |
|
| 1178 | - $shipping_address = array('address_title' => $shipping_title, |
|
| 1179 | - 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1180 | - 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1181 | - 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1182 | - 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1183 | - 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1184 | - 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1185 | - 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1186 | - 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1187 | - 'civility' => $civility, |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address); |
|
| 1192 | - $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address); |
|
| 1193 | - $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content); |
|
| 1194 | - |
|
| 1195 | - //Update the post meta |
|
| 1196 | - update_post_meta($result->ID, '_order_info', $array_new_format); |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - /* Update entities meta management */ |
|
| 1200 | - $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1)); |
|
| 1201 | - if (!empty($entities)) { |
|
| 1202 | - foreach ($entities as $entity) { |
|
| 1203 | - $params = get_post_meta($entity->ID, '_wpshop_entity_params', true); |
|
| 1204 | - $support = (!empty($params['support'])) ? $params['support'] : ''; |
|
| 1205 | - $rewrite = (!empty($params['rewrite'])) ? $params['rewrite'] : ''; |
|
| 1206 | - |
|
| 1207 | - $display_admin_menu = 'on'; |
|
| 1208 | - |
|
| 1209 | - update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu)); |
|
| 1210 | - } |
|
| 1211 | - } |
|
| 1212 | - wp_reset_query(); |
|
| 1213 | - |
|
| 1214 | - // Default Weight unity and Currency Options |
|
| 1215 | - add_option('wpshop_shop_weight_group', 3, '', 'yes'); |
|
| 1216 | - add_option('wpshop_shop_default_weight_unity', 6, '', 'yes'); |
|
| 1217 | - add_option('wpshop_shop_currency_group', 4, '', 'yes'); |
|
| 1218 | - |
|
| 1219 | - $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1220 | - foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1221 | - if ($default_currency == $k) { |
|
| 1222 | - $symbol = $v; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - if (!empty($symbol)) { |
|
| 1226 | - $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"'; |
|
| 1227 | - $currency = $wpdb->get_row($query); |
|
| 1228 | - if (!empty($currency)) { |
|
| 1229 | - update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1230 | - // Update the change rate of the default currency |
|
| 1231 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - // Update the field for variation and user definition field |
|
| 1236 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes')); |
|
| 1237 | - // Update field type for frontend output selection |
|
| 1238 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array()); |
|
| 1239 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea')); |
|
| 1240 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select')); |
|
| 1241 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select')); |
|
| 1242 | - |
|
| 1243 | - add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page'))); |
|
| 1244 | - |
|
| 1245 | - return true; |
|
| 1246 | - break; |
|
| 1247 | - |
|
| 1248 | - case '30': |
|
| 1249 | - /** Update the current price piloting field for using it into variation specific attributes */ |
|
| 1250 | - $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT); |
|
| 1251 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute)); |
|
| 1252 | - |
|
| 1253 | - /** Update the product reference field for using it into variation specific attributes */ |
|
| 1254 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference')); |
|
| 1255 | - |
|
| 1256 | - /** Insert new message for admin when a customer make an order */ |
|
| 1257 | - $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1258 | - if (empty($admin_new_order_message)) { |
|
| 1259 | - wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1260 | - } |
|
| 1261 | - /** Update all amount for paypal orders */ |
|
| 1262 | - $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal'); |
|
| 1263 | - $paypal_payment_list = $wpdb->get_results($query); |
|
| 1264 | - if (!empty($paypal_payment_list)) { |
|
| 1265 | - foreach ($paypal_payment_list as $post) { |
|
| 1266 | - $order_meta = get_post_meta($post->post_id, '_order_postmeta', true); |
|
| 1267 | - $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true); |
|
| 1268 | - if (!empty($order_meta['order_status']) && ($order_meta['order_status'] == 'incorrect_amount')) { |
|
| 1269 | - if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) { |
|
| 1270 | - $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5); |
|
| 1271 | - $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5); |
|
| 1272 | - if ($order_amount_payed == $order_amount_to_pay) { |
|
| 1273 | - wpshop_payment::setOrderPaymentStatus($order_id, 'completed'); |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /** Save existing orders address information */ |
|
| 1281 | - $billing_title = __('Billing address', 'wpshop'); |
|
| 1282 | - $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1283 | - $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1284 | - foreach ($results as $result) { |
|
| 1285 | - $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1286 | - $address_format = array(); |
|
| 1287 | - |
|
| 1288 | - $billing_address = array(); |
|
| 1289 | - if (!empty($address['billing']) && empty($address['billing']['id'])) { |
|
| 1290 | - if (!empty($address['billing']['civility'])) { |
|
| 1291 | - switch ($address['billing']['civility']) { |
|
| 1292 | - case 1: |
|
| 1293 | - $civility = $mister_id; |
|
| 1294 | - break; |
|
| 1295 | - case 2: |
|
| 1296 | - $civility = $madam_id; |
|
| 1297 | - break; |
|
| 1298 | - case 3: |
|
| 1299 | - $civility = $miss_id; |
|
| 1300 | - break; |
|
| 1301 | - default: |
|
| 1302 | - $civility = $mister_id; |
|
| 1303 | - break; |
|
| 1304 | - } |
|
| 1305 | - } else { |
|
| 1306 | - $civility = $mister_id; |
|
| 1307 | - } |
|
| 1308 | - $billing_address = array('address_title' => $billing_title, |
|
| 1309 | - 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1310 | - 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1311 | - 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1312 | - 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1313 | - 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1314 | - 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1315 | - 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1316 | - 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1317 | - 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1318 | - 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1319 | - 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1320 | - 'civility' => $civility, |
|
| 1321 | - ); |
|
| 1322 | - $billing_address_option = get_option('wpshop_billing_address'); |
|
| 1323 | - $address_format['billing']['id'] = $billing_address_option['choice']; |
|
| 1324 | - $address_format['billing']['address'] = $shipping_address; |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - $shipping_address = array(); |
|
| 1328 | - if (!empty($address['shipping']) && empty($address['shipping']['id'])) { |
|
| 1329 | - if (!empty($address['shipping']['civility'])) { |
|
| 1330 | - switch ($address['shipping']['civility']) { |
|
| 1331 | - case 1: |
|
| 1332 | - $civility = $mister_id; |
|
| 1333 | - break; |
|
| 1334 | - case 2: |
|
| 1335 | - $civility = $madam_id; |
|
| 1336 | - break; |
|
| 1337 | - case 3: |
|
| 1338 | - $civility = $miss_id; |
|
| 1339 | - break; |
|
| 1340 | - } |
|
| 1341 | - } else { |
|
| 1342 | - $civility = $mister_id; |
|
| 1343 | - } |
|
| 1344 | - $shipping_address = array('address_title' => $shipping_title, |
|
| 1345 | - 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1346 | - 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1347 | - 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1348 | - 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1349 | - 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1350 | - 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1351 | - 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1352 | - 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1353 | - 'civility' => $civility, |
|
| 1354 | - ); |
|
| 1355 | - $shipping_address_options = get_option('wpshop_shipping_address_choice'); |
|
| 1356 | - $address_format['shipping']['id'] = $shipping_address_options['choice']; |
|
| 1357 | - $address_format['shipping']['address'] = $shipping_address; |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - if (!empty($address_format)) { |
|
| 1361 | - update_post_meta($result->ID, '_order_info', $address_format); |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - /** Delete username from frontend form */ |
|
| 1366 | - $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code'); |
|
| 1367 | - if (!empty($attribute_login)) { |
|
| 1368 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id)); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted')); |
|
| 1372 | - |
|
| 1373 | - return true; |
|
| 1374 | - break; |
|
| 1375 | - |
|
| 1376 | - case '31': |
|
| 1377 | - /** Change order structure in order to support several payment */ |
|
| 1378 | - $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish'))); |
|
| 1379 | - if (!empty($existing_orders)) { |
|
| 1380 | - foreach ($existing_orders as $order_main_informations) { |
|
| 1381 | - /** Transfer payment return data form old meta to new */ |
|
| 1382 | - $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true); |
|
| 1383 | - update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data); |
|
| 1384 | - delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data'); |
|
| 1385 | - |
|
| 1386 | - /** Transfer old payment storage method to new storage method */ |
|
| 1387 | - $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true); |
|
| 1388 | - if (!empty($order_meta['order_status'])) { |
|
| 1389 | - $order_meta['order_payment']['customer_choice'] = array('method' => (!empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : ''))); |
|
| 1390 | - unset($order_meta['payment_method']); |
|
| 1391 | - $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0; |
|
| 1392 | - $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method']; |
|
| 1393 | - $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date']; |
|
| 1394 | - $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment'; |
|
| 1395 | - $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1396 | - $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1397 | - if (in_array($order_meta['order_status'], array('completed', 'shipped'))) { |
|
| 1398 | - $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total']; |
|
| 1399 | - $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID); |
|
| 1400 | - $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date']; |
|
| 1401 | - $order_meta['order_payment']['received'][0]['status'] = 'payment_received'; |
|
| 1402 | - $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1403 | - $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1404 | - $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref']; |
|
| 1405 | - } |
|
| 1406 | - update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta); |
|
| 1407 | - |
|
| 1408 | - if (!empty($order_meta['order_payment']['customer_choice'])) { |
|
| 1409 | - switch ($order_meta['order_payment']['customer_choice']) { |
|
| 1410 | - case 'check': |
|
| 1411 | - delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true)); |
|
| 1412 | - break; |
|
| 1413 | - case 'paypal': |
|
| 1414 | - delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true)); |
|
| 1415 | - break; |
|
| 1416 | - case 'cic': |
|
| 1417 | - delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true)); |
|
| 1418 | - break; |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1424 | - $wps_messages = new wps_message_ctr(); |
|
| 1425 | - $wps_messages->wpshop_messages_historic_correction(); |
|
| 1426 | - wp_reset_query(); |
|
| 1427 | - |
|
| 1428 | - $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1429 | - foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1430 | - if ($default_currency == $k) { |
|
| 1431 | - $symbol = $v; |
|
| 1432 | - } |
|
| 1433 | - } |
|
| 1434 | - if (!empty($symbol)) { |
|
| 1435 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', ''); |
|
| 1436 | - $currency = $wpdb->get_row($query); |
|
| 1437 | - if (!empty($currency)) { |
|
| 1438 | - update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1439 | - // Update the change rate of the default currency |
|
| 1440 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE'); |
|
| 1445 | - if (!empty($shipping_confirmation_message)) { |
|
| 1446 | - $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop'); |
|
| 1447 | - $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message); |
|
| 1448 | - wp_update_post($post); |
|
| 1449 | - } |
|
| 1450 | - return true; |
|
| 1451 | - break; |
|
| 1452 | - case '32': |
|
| 1453 | - /** Update product set id that are null */ |
|
| 1454 | - $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id'); |
|
| 1455 | - $wpdb->query($query); |
|
| 1456 | - |
|
| 1457 | - $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME); |
|
| 1458 | - if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) { |
|
| 1459 | - $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1460 | - if (empty($admin_new_quotation_message)) { |
|
| 1461 | - wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1462 | - } |
|
| 1463 | - $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1464 | - if (empty($admin_new_quotation_confirm_message)) { |
|
| 1465 | - wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1466 | - } |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - /** Allows the administrator to manage a little bit more the catalog rewrite parameters */ |
|
| 1470 | - $options = get_option('wpshop_catalog_product_option'); |
|
| 1471 | - $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category']; |
|
| 1472 | - update_option('wpshop_catalog_product_option', $options); |
|
| 1473 | - |
|
| 1474 | - /** Create a new page for unsuccessfull payment return */ |
|
| 1475 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 1476 | - wp_cache_flush(); |
|
| 1477 | - |
|
| 1478 | - /** Update the iso code of currencies */ |
|
| 1479 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro')); |
|
| 1480 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar')); |
|
| 1481 | - |
|
| 1482 | - /** Update VAT Rate*/ |
|
| 1483 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva'); |
|
| 1484 | - $attribute_ids = $wpdb->get_results($query); |
|
| 1485 | - foreach ($attribute_ids as $attribute_id) { |
|
| 1486 | - $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id); |
|
| 1487 | - $wpdb->query($query); |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - return true; |
|
| 1491 | - break; |
|
| 1492 | - |
|
| 1493 | - case '33': |
|
| 1494 | - /** Update the user_mail for the new system of log in/register */ |
|
| 1495 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"'); |
|
| 1496 | - |
|
| 1497 | - /** Put discount attributes in price attribute set section*/ |
|
| 1498 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1499 | - $prices_section_id = $wpdb->get_var($query); |
|
| 1500 | - |
|
| 1501 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount'); |
|
| 1502 | - $attributes = $wpdb->get_results($query); |
|
| 1503 | - if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1504 | - foreach ($attributes as $attribute) { |
|
| 1505 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id); |
|
| 1506 | - } |
|
| 1507 | - } |
|
| 1508 | - return true; |
|
| 1509 | - break; |
|
| 1510 | - |
|
| 1511 | - case '34': |
|
| 1512 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1513 | - $prices_section_id = $wpdb->get_var($query); |
|
| 1514 | - |
|
| 1515 | - $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id); |
|
| 1516 | - $last_position_id = $wpdb->get_var($query); |
|
| 1517 | - |
|
| 1518 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id); |
|
| 1519 | - $attribute_example = $wpdb->get_row($query); |
|
| 1520 | - |
|
| 1521 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to'); |
|
| 1522 | - $attributes = $wpdb->get_results($query); |
|
| 1523 | - $i = 1; |
|
| 1524 | - if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1525 | - |
|
| 1526 | - foreach ($attributes as $attribute) { |
|
| 1527 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id)); |
|
| 1528 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i)); |
|
| 1529 | - $i++; |
|
| 1530 | - } |
|
| 1531 | - } |
|
| 1532 | - $discount_options = get_option('wpshop_catalog_product_option'); |
|
| 1533 | - $status = (!empty($discount_options) && !empty($discount_options['discount'])) ? 'valid' : 'notused'; |
|
| 1534 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from')); |
|
| 1535 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to')); |
|
| 1536 | - return true; |
|
| 1537 | - break; |
|
| 1538 | - |
|
| 1539 | - case '35': |
|
| 1540 | - $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)); |
|
| 1541 | - return true; |
|
| 1542 | - break; |
|
| 1543 | - |
|
| 1544 | - case '36': |
|
| 1545 | - wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
| 1546 | - @set_time_limit(900); |
|
| 1547 | - /** Change the path for old categories pictures */ |
|
| 1548 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755); |
|
| 1549 | - |
|
| 1550 | - $query = 'SELECT * FROM ' . $wpdb->terms; |
|
| 1551 | - $terms = $wpdb->get_results($query); |
|
| 1552 | - if (!empty($terms)) { |
|
| 1553 | - foreach ($terms as $term) { |
|
| 1554 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755); |
|
| 1555 | - /** Check if a picture exists **/ |
|
| 1556 | - $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id); |
|
| 1557 | - if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) { |
|
| 1558 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1559 | - $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture']; |
|
| 1560 | - $img_basename = basename($img_path); |
|
| 1561 | - $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1562 | - /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1563 | - $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1564 | - $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1565 | - if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1566 | - $attachment = array( |
|
| 1567 | - 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1568 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1569 | - 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1570 | - 'post_content' => '', |
|
| 1571 | - 'post_status' => 'inherit', |
|
| 1572 | - ); |
|
| 1573 | - $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1574 | - /** Generate differnts sizes for this image **/ |
|
| 1575 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1576 | - $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1577 | - wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1578 | - /** Update option picture **/ |
|
| 1579 | - $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1580 | - update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option); |
|
| 1581 | - } |
|
| 1582 | - } |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ |
|
| 1587 | - $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus'); |
|
| 1588 | - $meta_keys = $wpdb->get_results($query); |
|
| 1589 | - if (!empty($meta_keys) && is_array($meta_keys)) { |
|
| 1590 | - foreach ($meta_keys as $meta_key) { |
|
| 1591 | - $user_id = $meta_key->user_id; |
|
| 1592 | - $meta_value = unserialize($meta_key->meta_value); |
|
| 1593 | - if (!empty($meta_value) && is_array($meta_value)) { |
|
| 1594 | - $data_to_delete = array_search('add-wpshop_product_category', $meta_value); |
|
| 1595 | - if ($data_to_delete !== false) { |
|
| 1596 | - unset($meta_value[$data_to_delete]); |
|
| 1597 | - } |
|
| 1598 | - } |
|
| 1599 | - update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value); |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - return true; |
|
| 1603 | - break; |
|
| 1604 | - |
|
| 1605 | - case '37': |
|
| 1606 | - @set_time_limit(900); |
|
| 1607 | - /** Change the path for old categories pictures */ |
|
| 1608 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755); |
|
| 1609 | - /** Read all categories folders **/ |
|
| 1610 | - $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category'; |
|
| 1611 | - if (file_exists($categories_main_dir)) { |
|
| 1612 | - $main_folder_content = scandir($categories_main_dir); |
|
| 1613 | - /** For each category folder **/ |
|
| 1614 | - foreach ($main_folder_content as $category_folder) { |
|
| 1615 | - if ($category_folder && substr($category_folder, 0, 1) != '.') { |
|
| 1616 | - $category_id = $category_folder; |
|
| 1617 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755); |
|
| 1618 | - $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder); |
|
| 1619 | - /** For each Picture of category **/ |
|
| 1620 | - $file_time = 0; |
|
| 1621 | - $save_this_picture = false; |
|
| 1622 | - while (false !== ($fichier = readdir($scan_category_folder))) { |
|
| 1623 | - if ($fichier && substr($fichier, 0, 1) != '.') { |
|
| 1624 | - if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) { |
|
| 1625 | - $save_this_picture = true; |
|
| 1626 | - $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier); |
|
| 1627 | - } |
|
| 1628 | - /** Select category option **/ |
|
| 1629 | - $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id); |
|
| 1630 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1631 | - $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier; |
|
| 1632 | - $img_basename = basename($img_path); |
|
| 1633 | - $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1634 | - /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1635 | - $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1636 | - $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1637 | - |
|
| 1638 | - if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1639 | - $attachment = array( |
|
| 1640 | - 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1641 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1642 | - 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1643 | - 'post_content' => '', |
|
| 1644 | - 'post_status' => 'inherit', |
|
| 1645 | - ); |
|
| 1646 | - $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1647 | - /** Generate differnts sizes for this image **/ |
|
| 1648 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1649 | - $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1650 | - wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1651 | - /** Update option picture **/ |
|
| 1652 | - $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1653 | - if ($save_this_picture) { |
|
| 1654 | - update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option); |
|
| 1655 | - } |
|
| 1656 | - $save_this_picture = false; |
|
| 1657 | - } |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - } |
|
| 1661 | - } |
|
| 1662 | - } |
|
| 1663 | - return true; |
|
| 1664 | - break; |
|
| 1665 | - |
|
| 1666 | - case '38': |
|
| 1667 | - wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE'); |
|
| 1668 | - return true; |
|
| 1669 | - break; |
|
| 1670 | - |
|
| 1671 | - case '39': |
|
| 1672 | - $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1673 | - /** Check if the 7% VAT Rate is not already created **/ |
|
| 1674 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7'); |
|
| 1675 | - $exist_vat_rate = $wpdb->get_results($query); |
|
| 1676 | - |
|
| 1677 | - if (empty($exist_vat_rate)) { |
|
| 1678 | - /** Get Max Position **/ |
|
| 1679 | - $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 1680 | - $max_position = $wpdb->get_var($query); |
|
| 1681 | - |
|
| 1682 | - if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 1683 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7')); |
|
| 1684 | - } |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** Filter Search optimization **/ |
|
| 1688 | - @set_time_limit(900); |
|
| 1689 | - $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1690 | - $categories = $wpdb->get_results($query); |
|
| 1691 | - $cats = array(); |
|
| 1692 | - if (!empty($categories)) { |
|
| 1693 | - foreach ($categories as $category) { |
|
| 1694 | - $cats[] = $category->term_id; |
|
| 1695 | - } |
|
| 1696 | - $wpshop_filter_search = new wps_filter_search(); |
|
| 1697 | - $wpshop_filter_search->stock_values_for_attribute($cats); |
|
| 1698 | - } |
|
| 1699 | - return true; |
|
| 1700 | - break; |
|
| 1701 | - |
|
| 1702 | - case '40': |
|
| 1703 | - /** Store watt in puissance unit group */ |
|
| 1704 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop')); |
|
| 1705 | - $puissance_unit_group_id = $wpdb->get_var($query); |
|
| 1706 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt')); |
|
| 1707 | - |
|
| 1708 | - /** Store day/week/year in duration unit group */ |
|
| 1709 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop')); |
|
| 1710 | - $duration_unit_group_id = $wpdb->get_var($query); |
|
| 1711 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day')); |
|
| 1712 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week')); |
|
| 1713 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year')); |
|
| 1714 | - |
|
| 1715 | - /** Store day/week/year in duration unit group */ |
|
| 1716 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop')); |
|
| 1717 | - $length_unit_group_id = $wpdb->get_var($query); |
|
| 1718 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm')); |
|
| 1719 | - return true; |
|
| 1720 | - break; |
|
| 1721 | - |
|
| 1722 | - case '41': |
|
| 1723 | - /** Get distinct attribute set and delete doublons */ |
|
| 1724 | - $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1725 | - $list_of_set = $wpdb->get_results($query); |
|
| 1726 | - foreach ($list_of_set as $set_infos) { |
|
| 1727 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1728 | - $wpdb->query($query); |
|
| 1729 | - } |
|
| 1730 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET); |
|
| 1731 | - |
|
| 1732 | - /** Get and delete attribute set section */ |
|
| 1733 | - $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )"; |
|
| 1734 | - $wpdb->query($query); |
|
| 1735 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP); |
|
| 1736 | - |
|
| 1737 | - /** Get and delete attribute set details */ |
|
| 1738 | - $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1739 | - $wpdb->query($query); |
|
| 1740 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1741 | - |
|
| 1742 | - $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1743 | - $affectation_list = $wpdb->get_results($query); |
|
| 1744 | - foreach ($affectation_list as $affectation_to_treat) { |
|
| 1745 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id); |
|
| 1746 | - $wpdb->query($query); |
|
| 1747 | - } |
|
| 1748 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1749 | - |
|
| 1750 | - /** Get and delete double unit */ |
|
| 1751 | - $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1"; |
|
| 1752 | - $list_of_set = $wpdb->get_results($query); |
|
| 1753 | - foreach ($list_of_set as $set_infos) { |
|
| 1754 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id); |
|
| 1755 | - $wpdb->query($query); |
|
| 1756 | - } |
|
| 1757 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT); |
|
| 1758 | - |
|
| 1759 | - $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1760 | - $list_of_set = $wpdb->get_results($query); |
|
| 1761 | - foreach ($list_of_set as $set_infos) { |
|
| 1762 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1763 | - $wpdb->query($query); |
|
| 1764 | - } |
|
| 1765 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP); |
|
| 1766 | - |
|
| 1767 | - /** Get and delete attribute set details */ |
|
| 1768 | - $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1769 | - $wpdb->query($query); |
|
| 1770 | - $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1771 | - $affectation_list = $wpdb->get_results($query); |
|
| 1772 | - foreach ($affectation_list as $list) { |
|
| 1773 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, ''); |
|
| 1774 | - $wpdb->query($query); |
|
| 1775 | - } |
|
| 1776 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1777 | - |
|
| 1778 | - return true; |
|
| 1779 | - break; |
|
| 1780 | - |
|
| 1781 | - case '42': |
|
| 1782 | - $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1783 | - if (empty($available_downloadable_product)) { |
|
| 1784 | - wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1785 | - } |
|
| 1786 | - return true; |
|
| 1787 | - break; |
|
| 1788 | - |
|
| 1789 | - case '43': |
|
| 1790 | - $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1791 | - if (empty($available_downloadable_product)) { |
|
| 1792 | - wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1793 | - } |
|
| 1794 | - return true; |
|
| 1795 | - break; |
|
| 1796 | - |
|
| 1797 | - case '44': |
|
| 1798 | - $display_option = get_option('wpshop_display_option'); |
|
| 1799 | - if (!empty($display_option) && empty($display_option['latest_products_ordered'])) { |
|
| 1800 | - $display_option['latest_products_ordered'] = 3; |
|
| 1801 | - update_option('wpshop_display_option', $display_option); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - /** Check messages for customization **/ |
|
| 1805 | - $messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED); |
|
| 1806 | - if (!empty($messages)) { |
|
| 1807 | - foreach ($messages as $key => $message) { |
|
| 1808 | - $message_option = get_option($key); |
|
| 1809 | - if (!empty($message_option)) { |
|
| 1810 | - $post_message = get_post($message_option); |
|
| 1811 | - $original_message = (!empty($post_message) && !empty($post_message->post_content)) ? $post_message->post_content : ''; |
|
| 1812 | - $tags = array('<p>', '</p>'); |
|
| 1813 | - if (str_replace($tags, '', $original_message) == str_replace($tags, '', __($message, 'wpshop'))) { |
|
| 1814 | - wp_update_post(array('ID' => $message_option, 'post_content' => wps_message_ctr::customize_message($original_message))); |
|
| 1815 | - } |
|
| 1816 | - } |
|
| 1817 | - } |
|
| 1818 | - } |
|
| 1819 | - |
|
| 1820 | - return true; |
|
| 1821 | - break; |
|
| 1822 | - |
|
| 1823 | - case '45': |
|
| 1824 | - $shipping_mode_ctr = new wps_shipping_mode_ctr(); |
|
| 1825 | - $shipping_mode_ctr->migrate_default_shipping_mode(); |
|
| 1826 | - return true; |
|
| 1827 | - break; |
|
| 1828 | - |
|
| 1829 | - case '46': |
|
| 1830 | - wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE'); |
|
| 1831 | - wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE); |
|
| 1832 | - return true; |
|
| 1833 | - break; |
|
| 1834 | - |
|
| 1835 | - case '47': |
|
| 1836 | - wps_payment_mode::migrate_payment_modes(); |
|
| 1837 | - return true; |
|
| 1838 | - break; |
|
| 1839 | - |
|
| 1840 | - case '48': |
|
| 1841 | - @ini_set('max_execution_time', '500'); |
|
| 1842 | - |
|
| 1843 | - $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1844 | - $output_type_option = get_option('wpshop_display_option'); |
|
| 1845 | - $output_type = $output_type_option['wpshop_display_list_type']; |
|
| 1846 | - |
|
| 1847 | - for ($i = 0; $i <= $count_products->publish; $i += 20) { |
|
| 1848 | - $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
|
| 1849 | - $products = $wpdb->get_results($query); |
|
| 1850 | - if (!empty($products)) { |
|
| 1851 | - foreach ($products as $product) { |
|
| 1852 | - $p = wpshop_products::get_product_data($product->ID); |
|
| 1853 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); |
|
| 1854 | - update_post_meta($product->ID, '_wps_price_infos', $price); |
|
| 1855 | - } |
|
| 1856 | - } |
|
| 1857 | - } |
|
| 1858 | - |
|
| 1859 | - return true; |
|
| 1860 | - break; |
|
| 1861 | - |
|
| 1862 | - case '49': |
|
| 1863 | - update_option('wpshop_send_invoice', true); |
|
| 1864 | - return true; |
|
| 1865 | - break; |
|
| 1866 | - |
|
| 1867 | - case '50': |
|
| 1868 | - $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1869 | - $price_display_option['price_display']['text_from'] = 'on'; |
|
| 1870 | - $price_display_option['price_display']['lower_price'] = 'on'; |
|
| 1871 | - update_option('wpshop_catalog_product_option', $price_display_option); |
|
| 1872 | - |
|
| 1873 | - self::wpshop_insert_default_pages(); |
|
| 1874 | - |
|
| 1875 | - return true; |
|
| 1876 | - break; |
|
| 1877 | - |
|
| 1878 | - case '51': |
|
| 1879 | - /** Insert new message for direct payment link */ |
|
| 1880 | - $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1881 | - if (empty($direct_payment_link_message)) { |
|
| 1882 | - wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1883 | - } |
|
| 1884 | - return true; |
|
| 1885 | - break; |
|
| 1886 | - |
|
| 1887 | - case '52': |
|
| 1888 | - $account_page_option = get_option('wpshop_myaccount_page_id'); |
|
| 1889 | - if (!empty($account_page_option)) { |
|
| 1890 | - $page_account = get_post($account_page_option); |
|
| 1891 | - $page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]'; |
|
| 1892 | - wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content)); |
|
| 1893 | - } |
|
| 1894 | - return true; |
|
| 1895 | - break; |
|
| 1896 | - |
|
| 1897 | - case '53': |
|
| 1898 | - $payment_modes_option = get_option('wps_payment_mode'); |
|
| 1899 | - if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) { |
|
| 1900 | - $payment_modes_option['mode']['cash_on_delivery'] = array( |
|
| 1901 | - 'name' => __('Cash on delivery', 'wpshop'), |
|
| 1902 | - 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', |
|
| 1903 | - 'description' => __('Pay your order on delivery', 'wpshop')); |
|
| 1904 | - |
|
| 1905 | - update_option('wps_payment_mode', $payment_modes_option); |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - // Mass action on products to add a flag on variation definition |
|
| 1909 | - $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1910 | - if (!empty($products)) { |
|
| 1911 | - foreach ($products as $p) { |
|
| 1912 | - $post_id = $p->ID; |
|
| 1913 | - $check_product_have_variations = wpshop_products::get_variation($post_id); |
|
| 1914 | - if (!empty($check_product_have_variations)) { |
|
| 1915 | - $variation_flag = wpshop_products::check_variation_type($post_id); |
|
| 1916 | - $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1917 | - $variation_defining['variation_type'] = $variation_flag; |
|
| 1918 | - update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1919 | - } |
|
| 1920 | - } |
|
| 1921 | - } |
|
| 1922 | - return true; |
|
| 1923 | - break; |
|
| 1924 | - |
|
| 1925 | - case '54': |
|
| 1926 | - // Change shortcode of sign up page |
|
| 1927 | - $signup_page_id = get_option('wpshop_signup_page_id'); |
|
| 1928 | - if (!empty($signup_page_id)) { |
|
| 1929 | - $signup_page = get_post($signup_page_id); |
|
| 1930 | - $signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]'; |
|
| 1931 | - wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content)); |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - // Change Terms of sale default content |
|
| 1935 | - $terms_page_id = get_option('wpshop_terms_of_sale_page_id'); |
|
| 1936 | - if (!empty($terms_page_id)) { |
|
| 1937 | - $terms_sale_page = get_post($terms_page_id); |
|
| 1938 | - if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') { |
|
| 1939 | - $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>'; |
|
| 1940 | - $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>'; |
|
| 1941 | - $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1942 | - $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>'; |
|
| 1943 | - $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1944 | - $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>'; |
|
| 1945 | - $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1946 | - $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>'; |
|
| 1947 | - $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name')); |
|
| 1948 | - wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data)); |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - return true; |
|
| 1953 | - break; |
|
| 1954 | - |
|
| 1955 | - case '55': |
|
| 1956 | - $checkout_page_id = get_option('wpshop_checkout_page_id'); |
|
| 1957 | - $checkout_page = get_post($checkout_page_id); |
|
| 1958 | - $checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]'; |
|
| 1959 | - wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content)); |
|
| 1960 | - |
|
| 1961 | - // Update cart page id |
|
| 1962 | - update_option('wpshop_cart_page_id', $checkout_page_id); |
|
| 1963 | - return true; |
|
| 1964 | - break; |
|
| 1965 | - |
|
| 1966 | - case '56': |
|
| 1967 | - $wps_entities = new wpshop_entities(); |
|
| 1968 | - $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1969 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id); |
|
| 1970 | - $set = $wpdb->get_row($query); |
|
| 1971 | - if (!empty($set)) { |
|
| 1972 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, |
|
| 1973 | - array('default_set' => 'yes'), |
|
| 1974 | - array('id' => $set->id)); |
|
| 1975 | - } |
|
| 1976 | - // Update Opinions activation option |
|
| 1977 | - update_option('wps_opinion', array('active' => 'on')); |
|
| 1978 | - return true; |
|
| 1979 | - break; |
|
| 1980 | - |
|
| 1981 | - case '57': |
|
| 1982 | - $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 1983 | - $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes'; |
|
| 1984 | - $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes'; |
|
| 1985 | - |
|
| 1986 | - update_option('wpshop_cart_option', $wpshop_cart_option); |
|
| 1987 | - return true; |
|
| 1988 | - break; |
|
| 1989 | - |
|
| 1990 | - case '58': |
|
| 1991 | - /** Turn customers publish into draft **/ |
|
| 1992 | - $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1993 | - $wpdb->query($query); |
|
| 1994 | - |
|
| 1995 | - $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1996 | - /** Check if the 0% VAT Rate is not already created **/ |
|
| 1997 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0'); |
|
| 1998 | - $exist_vat_rate = $wpdb->get_results($query); |
|
| 1999 | - |
|
| 2000 | - if (empty($exist_vat_rate)) { |
|
| 2001 | - /** Get Max Position **/ |
|
| 2002 | - $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 2003 | - $max_position = $wpdb->get_var($query); |
|
| 2004 | - |
|
| 2005 | - if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 2006 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0')); |
|
| 2007 | - } |
|
| 2008 | - } |
|
| 2009 | - return true; |
|
| 2010 | - break; |
|
| 2011 | - |
|
| 2012 | - case '59': |
|
| 2013 | - /** Move old images gallery to the new gallery, and remove old links **/ |
|
| 2014 | - $allowed = get_allowed_mime_types(); |
|
| 2015 | - $args = array( |
|
| 2016 | - 'posts_per_page' => -1, |
|
| 2017 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 2018 | - 'post_status' => array('publish', 'draft', 'trash'), |
|
| 2019 | - ); |
|
| 2020 | - $posts = get_posts($args); |
|
| 2021 | - $result = array(); |
|
| 2022 | - foreach ($posts as $post) { |
|
| 2023 | - $array = array(); |
|
| 2024 | - $array['Post'] = $post; |
|
| 2025 | - $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true); |
|
| 2026 | - $array['Attachments'] = get_attached_media($allowed, $post->ID); |
|
| 2027 | - $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true); |
|
| 2028 | - if (!empty($array['TrueAttachmentsString'])) { |
|
| 2029 | - $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']); |
|
| 2030 | - } |
|
| 2031 | - $array['OldAttachmentsString'] = ''; |
|
| 2032 | - foreach ($array['Attachments'] as $attachment) { |
|
| 2033 | - $filename = basename(get_attached_file($attachment->ID)); |
|
| 2034 | - $pos_ext = strrpos($filename, '.'); |
|
| 2035 | - $filename_no_ext = substr($filename, 0, $pos_ext); |
|
| 2036 | - if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) { |
|
| 2037 | - $array['OldAttachmentsString'] .= $attachment->ID . ','; |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2040 | - unset($TrueAttachments_id); |
|
| 2041 | - $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString']; |
|
| 2042 | - update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]); |
|
| 2043 | - } |
|
| 2044 | - return true; |
|
| 2045 | - break; |
|
| 2046 | - |
|
| 2047 | - case '60': |
|
| 2048 | - /* Create default emails */ |
|
| 2049 | - wps_message_ctr::create_default_message(); |
|
| 2050 | - |
|
| 2051 | - /** Update entries for quick add */ |
|
| 2052 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"'); |
|
| 2053 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"'); |
|
| 2054 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"'); |
|
| 2055 | - switch (WPSHOP_PRODUCT_PRICE_PILOT) { |
|
| 2056 | - case 'HT': |
|
| 2057 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"'); |
|
| 2058 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"'); |
|
| 2059 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"'); |
|
| 2060 | - break; |
|
| 2061 | - default: |
|
| 2062 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"'); |
|
| 2063 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"'); |
|
| 2064 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"'); |
|
| 2065 | - break; |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - /* Default country with WP language */ |
|
| 2069 | - $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice'); |
|
| 2070 | - if (empty($wpshop_country_default_choice_option)) { |
|
| 2071 | - update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3)); |
|
| 2072 | - } |
|
| 2073 | - return true; |
|
| 2074 | - break; |
|
| 2075 | - |
|
| 2076 | - case '61': |
|
| 2077 | - /** Import the xml for guided tour */ |
|
| 2078 | - wpsBubble_ctr::import_xml(); |
|
| 2079 | - |
|
| 2080 | - /* Hide admin bar */ |
|
| 2081 | - $wpshop_display_option = get_option('wpshop_display_option'); |
|
| 2082 | - if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) { |
|
| 2083 | - $wpshop_display_option['wpshop_hide_admin_bar'] = 'on'; |
|
| 2084 | - update_option('wpshop_display_option', $wpshop_display_option); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - return true; |
|
| 2088 | - break; |
|
| 2089 | - |
|
| 2090 | - case '62': |
|
| 2091 | - /** Install user default for POS */ |
|
| 2092 | - wps_pos_addon::action_to_do_on_activation(); |
|
| 2093 | - |
|
| 2094 | - return true; |
|
| 2095 | - break; |
|
| 2096 | - |
|
| 2097 | - case '63': |
|
| 2098 | - $data = get_option('wps_shipping_mode'); |
|
| 2099 | - if (empty($data['modes']['default_shipping_mode_for_pos'])) { |
|
| 2100 | - $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop'); |
|
| 2101 | - $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop'); |
|
| 2102 | - update_option('wps_shipping_mode', $data); |
|
| 2103 | - } |
|
| 2104 | - return true; |
|
| 2105 | - break; |
|
| 2106 | - |
|
| 2107 | - case '64': |
|
| 2108 | - $options = get_option('wpshop_catalog_product_option'); |
|
| 2109 | - if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 2110 | - unset($options['wpshop_catalog_product_slug_with_category']); |
|
| 2111 | - update_option('wpshop_catalog_product_option', $options); |
|
| 2112 | - } |
|
| 2113 | - return true; |
|
| 2114 | - break; |
|
| 2115 | - |
|
| 2116 | - case '65': |
|
| 2117 | - $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 2118 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id); |
|
| 2119 | - $company_id = $wpdb->get_var($query); |
|
| 2120 | - if (!isset($company_id)) { |
|
| 2121 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2122 | - 'is_visible_in_front' => 'no', |
|
| 2123 | - 'is_visible_in_front_listing' => 'yes', |
|
| 2124 | - 'is_global' => 'no', |
|
| 2125 | - 'is_user_defined' => 'no', |
|
| 2126 | - 'is_required' => 'no', |
|
| 2127 | - 'is_visible_in_advanced_search' => 'no', |
|
| 2128 | - 'is_searchable' => 'no', |
|
| 2129 | - 'is_filterable' => 'no', |
|
| 2130 | - 'is_comparable' => 'no', |
|
| 2131 | - 'is_html_allowed_on_front' => 'no', |
|
| 2132 | - 'is_unique' => 'no', |
|
| 2133 | - 'is_filterable_in_search' => 'no', |
|
| 2134 | - 'is_used_for_sort_by' => 'no', |
|
| 2135 | - 'is_configurable' => 'no', |
|
| 2136 | - 'is_requiring_unit' => 'no', |
|
| 2137 | - 'is_recordable_in_cart_meta' => 'no', |
|
| 2138 | - 'is_used_in_admin_listing_column' => 'no', |
|
| 2139 | - 'is_used_in_quick_add_form' => 'no', |
|
| 2140 | - 'is_used_for_variation' => 'no', |
|
| 2141 | - 'is_used_in_variation' => 'no', |
|
| 2142 | - '_display_informations_about_value' => 'no', |
|
| 2143 | - '_need_verification' => 'no', |
|
| 2144 | - '_unit_group_id' => null, |
|
| 2145 | - '_default_unit' => null, |
|
| 2146 | - 'is_historisable' => 'yes', |
|
| 2147 | - 'is_intrinsic' => 'no', |
|
| 2148 | - 'data_type_to_use' => 'custom', |
|
| 2149 | - 'use_ajax_for_filling_field' => 'no', |
|
| 2150 | - 'data_type' => 'varchar', |
|
| 2151 | - 'backend_table' => null, |
|
| 2152 | - 'backend_label' => 'Company', |
|
| 2153 | - 'backend_input' => 'text', |
|
| 2154 | - 'frontend_label' => 'Company', |
|
| 2155 | - 'frontend_input' => 'text', |
|
| 2156 | - 'frontend_verification' => null, |
|
| 2157 | - 'code' => 'company_customer', |
|
| 2158 | - 'note' => '', |
|
| 2159 | - 'default_value' => '', |
|
| 2160 | - 'frontend_css_class' => 'company_customer', |
|
| 2161 | - 'backend_css_class' => null, |
|
| 2162 | - 'frontend_help_message' => null, |
|
| 2163 | - 'entity_id' => $entity_id, |
|
| 2164 | - )); |
|
| 2165 | - $company_id = $wpdb->insert_id; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id); |
|
| 2169 | - $is_provider_id = $wpdb->get_var($query); |
|
| 2170 | - if (!isset($is_provider_id)) { |
|
| 2171 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2172 | - 'is_visible_in_front' => 'no', |
|
| 2173 | - 'is_visible_in_front_listing' => 'yes', |
|
| 2174 | - 'is_global' => 'no', |
|
| 2175 | - 'is_user_defined' => 'no', |
|
| 2176 | - 'is_required' => 'yes', |
|
| 2177 | - 'is_visible_in_advanced_search' => 'no', |
|
| 2178 | - 'is_searchable' => 'no', |
|
| 2179 | - 'is_filterable' => 'no', |
|
| 2180 | - 'is_comparable' => 'no', |
|
| 2181 | - 'is_html_allowed_on_front' => 'no', |
|
| 2182 | - 'is_unique' => 'no', |
|
| 2183 | - 'is_filterable_in_search' => 'no', |
|
| 2184 | - 'is_used_for_sort_by' => 'no', |
|
| 2185 | - 'is_configurable' => 'no', |
|
| 2186 | - 'is_requiring_unit' => 'no', |
|
| 2187 | - 'is_recordable_in_cart_meta' => 'no', |
|
| 2188 | - 'is_used_in_admin_listing_column' => 'no', |
|
| 2189 | - 'is_used_in_quick_add_form' => 'no', |
|
| 2190 | - 'is_used_for_variation' => 'no', |
|
| 2191 | - 'is_used_in_variation' => 'no', |
|
| 2192 | - '_display_informations_about_value' => 'no', |
|
| 2193 | - '_need_verification' => 'no', |
|
| 2194 | - '_unit_group_id' => null, |
|
| 2195 | - '_default_unit' => null, |
|
| 2196 | - 'is_historisable' => 'yes', |
|
| 2197 | - 'is_intrinsic' => 'no', |
|
| 2198 | - 'data_type_to_use' => 'custom', |
|
| 2199 | - 'use_ajax_for_filling_field' => 'no', |
|
| 2200 | - 'data_type' => 'integer', |
|
| 2201 | - 'backend_table' => null, |
|
| 2202 | - 'backend_label' => 'Provider', |
|
| 2203 | - 'backend_input' => 'select', |
|
| 2204 | - 'frontend_label' => 'Provider', |
|
| 2205 | - 'frontend_input' => 'select', |
|
| 2206 | - 'frontend_verification' => null, |
|
| 2207 | - 'code' => 'is_provider', |
|
| 2208 | - 'note' => '', |
|
| 2209 | - 'default_value' => 'no', |
|
| 2210 | - 'frontend_css_class' => 'is_provider', |
|
| 2211 | - 'backend_css_class' => null, |
|
| 2212 | - 'frontend_help_message' => null, |
|
| 2213 | - 'entity_id' => $entity_id, |
|
| 2214 | - )); |
|
| 2215 | - $is_provider_id = $wpdb->insert_id; |
|
| 2216 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2217 | - 'status' => 'valid', |
|
| 2218 | - 'attribute_id' => $is_provider_id, |
|
| 2219 | - 'creation_date_value' => current_time('mysql'), |
|
| 2220 | - 'value' => 'yes', |
|
| 2221 | - 'label' => 'Yes', |
|
| 2222 | - )); |
|
| 2223 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2224 | - 'status' => 'valid', |
|
| 2225 | - 'attribute_id' => $is_provider_id, |
|
| 2226 | - 'creation_date_value' => current_time('mysql'), |
|
| 2227 | - 'value' => 'no', |
|
| 2228 | - 'label' => 'No', |
|
| 2229 | - )); |
|
| 2230 | - $default_value = $wpdb->insert_id; |
|
| 2231 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id)); |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id); |
|
| 2235 | - $company_section_detail_id = $wpdb->get_var($query); |
|
| 2236 | - |
|
| 2237 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id); |
|
| 2238 | - $is_provider_section_detail_id = $wpdb->get_var($query); |
|
| 2239 | - |
|
| 2240 | - if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) { |
|
| 2241 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 2242 | - $attribute_set_id = $wpdb->get_var($query); |
|
| 2243 | - |
|
| 2244 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account'); |
|
| 2245 | - $attribute_set_section_id = $wpdb->get_var($query); |
|
| 2246 | - |
|
| 2247 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 2248 | - $attributes_set_details = $wpdb->get_results($query); |
|
| 2249 | - $set_details_id_postion_order = array(); |
|
| 2250 | - foreach ($attributes_set_details as $attribute_set_detail) { |
|
| 2251 | - $query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id); |
|
| 2252 | - $attribute_set_detail_code = $wpdb->get_var($query); |
|
| 2253 | - if ($attribute_set_detail_code == 'last_name') { |
|
| 2254 | - $set_details_id_postion_order[1] = $attribute_set_detail->attribute_id; |
|
| 2255 | - } |
|
| 2256 | - if ($attribute_set_detail_code == 'first_name') { |
|
| 2257 | - $set_details_id_postion_order[2] = $attribute_set_detail->attribute_id; |
|
| 2258 | - } |
|
| 2259 | - if ($attribute_set_detail_code == 'user_email') { |
|
| 2260 | - $set_details_id_postion_order[3] = $attribute_set_detail->attribute_id; |
|
| 2261 | - } |
|
| 2262 | - if ($attribute_set_detail_code == 'user_pass') { |
|
| 2263 | - $set_details_id_postion_order[4] = $attribute_set_detail->attribute_id; |
|
| 2264 | - } |
|
| 2265 | - } |
|
| 2266 | - $max_position = count($set_details_id_postion_order); |
|
| 2267 | - |
|
| 2268 | - if (!isset($company_section_detail_id)) { |
|
| 2269 | - $max_position = $max_position + 1; |
|
| 2270 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position)); |
|
| 2271 | - $set_details_id_postion_order[$max_position] = $company_id; |
|
| 2272 | - $company_section_detail_id = $wpdb->insert_id; |
|
| 2273 | - } |
|
| 2274 | - |
|
| 2275 | - if (!isset($is_provider_section_detail_id)) { |
|
| 2276 | - $max_position = $max_position + 1; |
|
| 2277 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position)); |
|
| 2278 | - $set_details_id_postion_order[$max_position] = $is_provider_id; |
|
| 2279 | - $is_provider_section_detail_id = $wpdb->insert_id; |
|
| 2280 | - } |
|
| 2281 | - |
|
| 2282 | - foreach ($set_details_id_postion_order as $pos => $attr_id) { |
|
| 2283 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d')); |
|
| 2284 | - } |
|
| 2285 | - } |
|
| 2286 | - |
|
| 2287 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s')); |
|
| 2288 | - |
|
| 2289 | - return true; |
|
| 2290 | - break; |
|
| 2291 | - |
|
| 2292 | - case 66: |
|
| 2293 | - $price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2294 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2295 | - 'is_visible_in_front' => 'no', |
|
| 2296 | - 'is_visible_in_front_listing' => 'yes', |
|
| 2297 | - 'is_global' => 'no', |
|
| 2298 | - 'is_user_defined' => 'no', |
|
| 2299 | - 'is_required' => 'no', |
|
| 2300 | - 'is_visible_in_advanced_search' => 'no', |
|
| 2301 | - 'is_searchable' => 'no', |
|
| 2302 | - 'is_filterable' => 'no', |
|
| 2303 | - 'is_comparable' => 'no', |
|
| 2304 | - 'is_html_allowed_on_front' => 'no', |
|
| 2305 | - 'is_unique' => 'no', |
|
| 2306 | - 'is_filterable_in_search' => 'no', |
|
| 2307 | - 'is_used_for_sort_by' => 'no', |
|
| 2308 | - 'is_configurable' => 'no', |
|
| 2309 | - 'is_requiring_unit' => 'no', |
|
| 2310 | - 'is_recordable_in_cart_meta' => 'no', |
|
| 2311 | - 'is_used_in_admin_listing_column' => 'no', |
|
| 2312 | - 'is_used_in_quick_add_form' => 'no', |
|
| 2313 | - 'is_used_for_variation' => 'no', |
|
| 2314 | - 'is_used_in_variation' => 'yes', |
|
| 2315 | - '_display_informations_about_value' => 'no', |
|
| 2316 | - '_need_verification' => 'no', |
|
| 2317 | - '_unit_group_id' => null, |
|
| 2318 | - '_default_unit' => null, |
|
| 2319 | - 'is_historisable' => 'yes', |
|
| 2320 | - 'is_intrinsic' => 'no', |
|
| 2321 | - 'data_type_to_use' => 'custom', |
|
| 2322 | - 'use_ajax_for_filling_field' => 'no', |
|
| 2323 | - 'data_type' => 'integer', |
|
| 2324 | - 'backend_table' => null, |
|
| 2325 | - 'backend_label' => null, |
|
| 2326 | - 'backend_input' => 'select', |
|
| 2327 | - 'frontend_label' => 'price_behaviour', |
|
| 2328 | - 'frontend_input' => 'select', |
|
| 2329 | - 'frontend_verification' => null, |
|
| 2330 | - 'code' => 'price_behaviour', |
|
| 2331 | - 'note' => '', |
|
| 2332 | - 'default_value' => '', |
|
| 2333 | - 'frontend_css_class' => 'price_behaviour', |
|
| 2334 | - 'backend_css_class' => null, |
|
| 2335 | - 'frontend_help_message' => null, |
|
| 2336 | - 'entity_id' => $price_behaviour_entity_id, |
|
| 2337 | - )); |
|
| 2338 | - $price_behaviour = $wpdb->insert_id; |
|
| 2339 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2340 | - 'status' => 'valid', |
|
| 2341 | - 'attribute_id' => $price_behaviour, |
|
| 2342 | - 'creation_date' => current_time('mysql'), |
|
| 2343 | - 'value' => '+', |
|
| 2344 | - 'label' => '+', |
|
| 2345 | - )); |
|
| 2346 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2347 | - 'status' => 'valid', |
|
| 2348 | - 'attribute_id' => $price_behaviour, |
|
| 2349 | - 'creation_date' => current_time('mysql'), |
|
| 2350 | - 'value' => '=', |
|
| 2351 | - 'label' => '=', |
|
| 2352 | - )); |
|
| 2353 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default'); |
|
| 2354 | - $price_behaviour_section_id = $wpdb->get_var($query); |
|
| 2355 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices'); |
|
| 2356 | - $price_behaviour_section_detail_id = $wpdb->get_var($query); |
|
| 2357 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array( |
|
| 2358 | - 'status' => 'deleted', |
|
| 2359 | - 'creation_date' => current_time('mysql', 0), |
|
| 2360 | - 'entity_type_id' => $price_behaviour_entity_id, |
|
| 2361 | - 'attribute_set_id' => $price_behaviour_section_id, |
|
| 2362 | - 'attribute_group_id' => $price_behaviour_section_detail_id, |
|
| 2363 | - 'attribute_id' => $price_behaviour, |
|
| 2364 | - 'position' => 0, |
|
| 2365 | - )); |
|
| 2366 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_')); |
|
| 2367 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva')); |
|
| 2368 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht')); |
|
| 2369 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock')); |
|
| 2370 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight')); |
|
| 2371 | - return true; |
|
| 2372 | - break; |
|
| 2373 | - |
|
| 2374 | - /* Always add specific case before this bloc */ |
|
| 2375 | - case 'dev': |
|
| 2376 | - |
|
| 2377 | - //wp_cache_flush(); |
|
| 2378 | - // Newsletters options |
|
| 2379 | - //$wp_rewrite->flush_rules(); |
|
| 2380 | - return true; |
|
| 2381 | - break; |
|
| 2382 | - |
|
| 2383 | - default: |
|
| 2384 | - return true; |
|
| 2385 | - break; |
|
| 2386 | - } |
|
| 2387 | - } |
|
| 2388 | - |
|
| 2389 | - /** |
|
| 2390 | - * Method called when deactivating the plugin |
|
| 2391 | - * @see register_deactivation_hook() |
|
| 2392 | - */ |
|
| 2393 | - public function uninstall_wpshop() |
|
| 2394 | - { |
|
| 2395 | - global $wpdb; |
|
| 2396 | - |
|
| 2397 | - if (WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION && in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) { |
|
| 2398 | - $query = $wpdb->query("DROP TABLE `wp_wpshop__attribute`, `wp_wpshop__attributes_unit`, `wp_wpshop__attributes_unit_groups`, `wp_wpshop__attribute_set`, `wp_wpshop__attribute_set_section`, `wp_wpshop__attribute_set_section_details`, `wp_wpshop__attribute_value_datetime`, `wp_wpshop__attribute_value_decimal`, `wp_wpshop__attribute_value_integer`, `wp_wpshop__attribute_value_text`, `wp_wpshop__attribute_value_varchar`, `wp_wpshop__attribute_value__histo`, `wp_wpshop__cart`, `wp_wpshop__cart_contents`, `wp_wpshop__documentation`, `wp_wpshop__entity`, `wp_wpshop__historique`, `wp_wpshop__message`, `wp_wpshop__attribute_value_options`;"); |
|
| 2399 | - $query = $wpdb->query("DELETE FROM " . $wpdb->options . " WHERE `option_name` LIKE '%wpshop%';"); |
|
| 2400 | - |
|
| 2401 | - $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE 'wpshop_%';"); |
|
| 2402 | - $list = ' '; |
|
| 2403 | - foreach ($wpshop_products_posts as $post) { |
|
| 2404 | - $list .= "'" . $post->ID . "', "; |
|
| 2405 | - } |
|
| 2406 | - $list = substr($list, 0, -2); |
|
| 2407 | - |
|
| 2408 | - $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_parent IN (" . $list . ");"); |
|
| 2409 | - $list_attachment = ' '; |
|
| 2410 | - foreach ($wpshop_products_posts as $post) { |
|
| 2411 | - $list_attachment .= "'" . $post->ID . "', "; |
|
| 2412 | - } |
|
| 2413 | - $list_attachment = substr($list_attachment, 0, -2); |
|
| 2414 | - |
|
| 2415 | - $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list . ");"); |
|
| 2416 | - $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list_attachment . ");"); |
|
| 2417 | - $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list . ");"); |
|
| 2418 | - $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list_attachment . ");"); |
|
| 2419 | - $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE post_content LIKE '%wpshop%';"); |
|
| 2420 | - } |
|
| 2421 | - |
|
| 2422 | - /* Unset administrator permission */ |
|
| 2423 | - $adminRole = get_role('administrator'); |
|
| 2424 | - foreach ($adminRole->capabilities as $capabilityName => $capability) { |
|
| 2425 | - if (substr($capabilityName, 0, 7) == 'wpshop_') { |
|
| 2426 | - if ($adminRole->has_cap($capabilityName)) { |
|
| 2427 | - $adminRole->remove_cap($capabilityName); |
|
| 2428 | - } |
|
| 2429 | - } |
|
| 2430 | - } |
|
| 2431 | - } |
|
| 826 | + , 'prices', __('default', 'wpshop')); |
|
| 827 | + $list = $wpdb->get_results($query); |
|
| 828 | + if (!empty($list)) { |
|
| 829 | + $change_order = true; |
|
| 830 | + $old_value = $list[0]->attribute_group_id; |
|
| 831 | + unset($list[0]); |
|
| 832 | + if (!empty($list)) { |
|
| 833 | + foreach ($list as $data) { |
|
| 834 | + if ($old_value != $data->attribute_group_id) { |
|
| 835 | + $change_order = false; |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + if ($change_order) { |
|
| 839 | + foreach ($price_tab as $price_code) { |
|
| 840 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code); |
|
| 841 | + $attribute_id = $wpdb->get_var($query); |
|
| 842 | + switch ($price_code) { |
|
| 843 | + case WPSHOP_PRODUCT_PRICE_HT: |
|
| 844 | + $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 1 : 3; |
|
| 845 | + break; |
|
| 846 | + case WPSHOP_PRODUCT_PRICE_TAX: |
|
| 847 | + $position = 2; |
|
| 848 | + break; |
|
| 849 | + case WPSHOP_PRODUCT_PRICE_TTC: |
|
| 850 | + $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 3 : 1; |
|
| 851 | + break; |
|
| 852 | + case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT: |
|
| 853 | + $position = 4; |
|
| 854 | + break; |
|
| 855 | + } |
|
| 856 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id)); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + return true; |
|
| 862 | + break; |
|
| 863 | + case 22: |
|
| 864 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 865 | + $product_entity_id = $wpdb->get_var($query); |
|
| 866 | + if (empty($product_entityd_id) || ($product_entity_id <= 0) || !$product_entity_id) { |
|
| 867 | + /* Create the product entity into post table */ |
|
| 868 | + $product_entity = array( |
|
| 869 | + 'post_title' => __('Products', 'wpshop'), |
|
| 870 | + 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 871 | + 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), |
|
| 872 | + 'post_status' => 'publish', |
|
| 873 | + 'post_author' => 1, |
|
| 874 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, |
|
| 875 | + ); |
|
| 876 | + $product_entity_id = wp_insert_post($product_entity); |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /* Update eav table with the new entity id for product */ |
|
| 880 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 881 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 882 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 883 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 884 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 885 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 886 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 887 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 888 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 889 | + |
|
| 890 | + /* Create an element of customer entity for each existing user */ |
|
| 891 | + $user_list = get_users(); |
|
| 892 | + foreach ($user_list as $user) { |
|
| 893 | + wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + return true; |
|
| 897 | + break; |
|
| 898 | + case 23: |
|
| 899 | + /* Delete duplicate entities */ |
|
| 900 | + $query = ("SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' "); |
|
| 901 | + $product_entity_list = $wpdb->get_results($query); |
|
| 902 | + if (count($product_entity_list) > 1) { |
|
| 903 | + $i = 0; |
|
| 904 | + foreach ($product_entity_list as $product_entity) { |
|
| 905 | + if ($i > 0) { |
|
| 906 | + wp_delete_post($product_entity->ID); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + return true; |
|
| 911 | + break; |
|
| 912 | + case 24: |
|
| 913 | + /* Update the link status for disabled attribute set */ |
|
| 914 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted'); |
|
| 915 | + $deleted_attribute_group = $wpdb->get_results($query); |
|
| 916 | + if (!empty($deleted_attribute_group)) { |
|
| 917 | + foreach ($deleted_attribute_group as $group) { |
|
| 918 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id)); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + /* Update entities meta management */ |
|
| 923 | + $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES)); |
|
| 924 | + if (!empty($entities)) { |
|
| 925 | + foreach ($entities as $entity) { |
|
| 926 | + $support = get_post_meta($entity->ID, '_wpshop_entity_support', true); |
|
| 927 | + $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true); |
|
| 928 | + update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite))); |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + wp_reset_query(); |
|
| 932 | + return true; |
|
| 933 | + break; |
|
| 934 | + case 25: |
|
| 935 | + /* Get the first entities of product and customer */ |
|
| 936 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 937 | + $product_entity_id = $wpdb->get_var($query); |
|
| 938 | + |
|
| 939 | + /* Update attributes that are not linked with entities */ |
|
| 940 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0)); |
|
| 941 | + |
|
| 942 | + /* Get entities that have been created a lot of time and delete them */ |
|
| 943 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 944 | + $entities_to_delete = $wpdb->get_results($query); |
|
| 945 | + if (!empty($entities_to_delete) && is_array($entities_to_delete)) { |
|
| 946 | + foreach ($entities_to_delete as $entity) { |
|
| 947 | + wp_delete_post($entity->ID, true); |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + /* Get post list that are children of entities created a lot of time */ |
|
| 952 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%"); |
|
| 953 | + $entities_to_update = $wpdb->get_results($query); |
|
| 954 | + if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 955 | + foreach ($entities_to_update as $entity) { |
|
| 956 | + wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)); |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%"); |
|
| 960 | + $entities_to_update = $wpdb->get_results($query); |
|
| 961 | + if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 962 | + foreach ($entities_to_update as $entity) { |
|
| 963 | + wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + /* Change addons managament */ |
|
| 968 | + $wpshop_addons_options = get_option('wpshop_addons_state', array()); |
|
| 969 | + if (!empty($wpshop_addons_options)) { |
|
| 970 | + foreach ($wpshop_addons_options as $addon_name => $addon_state) { |
|
| 971 | + $options_args = array(); |
|
| 972 | + $options_args[$addon_name]['activate'] = $addon_state; |
|
| 973 | + $options_args[$addon_name]['activation_date'] = current_time('mysql', 0); |
|
| 974 | + if (!$addon_state) { |
|
| 975 | + $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args); |
|
| 979 | + } |
|
| 980 | + delete_option('wpshop_addons_state'); |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + /* Update the different entities id into attribute set details table */ |
|
| 984 | + $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 985 | + $wpdb->query($query); |
|
| 986 | + |
|
| 987 | + return true; |
|
| 988 | + break; |
|
| 989 | + case 26: |
|
| 990 | + $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' "; |
|
| 991 | + $results = $wpdb->get_results($query); |
|
| 992 | + foreach ($results as $result) { |
|
| 993 | + $order_info = unserialize($result->meta_value); |
|
| 994 | + update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']); |
|
| 995 | + update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']); |
|
| 996 | + update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + /* Update the different entities id into attribute set details table */ |
|
| 1000 | + $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 1001 | + $wpdb->query($query); |
|
| 1002 | + |
|
| 1003 | + return true; |
|
| 1004 | + break; |
|
| 1005 | + |
|
| 1006 | + case 29: |
|
| 1007 | + $billing_title = __('Billing address', 'wpshop'); |
|
| 1008 | + $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1009 | + |
|
| 1010 | + //UPDATE USERS ADDRESSES |
|
| 1011 | + $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"'; |
|
| 1012 | + $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"'; |
|
| 1013 | + |
|
| 1014 | + $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query); |
|
| 1015 | + $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query); |
|
| 1016 | + |
|
| 1017 | + //Add Address & Google Map API KEY options |
|
| 1018 | + add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes'); |
|
| 1019 | + add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes'); |
|
| 1020 | + add_option('wpshop_google_map_api_key', '', '', 'yes'); |
|
| 1021 | + |
|
| 1022 | + $query = 'SELECT * FROM ' . $wpdb->users . ''; |
|
| 1023 | + $results = $wpdb->get_results($query); |
|
| 1024 | + foreach ($results as $result) { |
|
| 1025 | + $billing_infos = get_user_meta($result->ID, 'billing_info', true); |
|
| 1026 | + $shipping_infos = get_user_meta($result->ID, 'shipping_info', true); |
|
| 1027 | + if (!empty($billing_infos)) { |
|
| 1028 | + //Save Billing Infos |
|
| 1029 | + $billing_address = array(); |
|
| 1030 | + if (!empty($billing_infos['civility'])) { |
|
| 1031 | + switch ($billing_infos['civility']) { |
|
| 1032 | + case 1: |
|
| 1033 | + $civility = $mister_id; |
|
| 1034 | + break; |
|
| 1035 | + case 2: |
|
| 1036 | + $civility = $madam_id; |
|
| 1037 | + break; |
|
| 1038 | + case 3: |
|
| 1039 | + $civility = $miss_id; |
|
| 1040 | + break; |
|
| 1041 | + } |
|
| 1042 | + } else { |
|
| 1043 | + $civility = $mister_id; |
|
| 1044 | + } |
|
| 1045 | + $billing_address = array('address_title' => $billing_title, |
|
| 1046 | + 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', |
|
| 1047 | + 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', |
|
| 1048 | + 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', |
|
| 1049 | + 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', |
|
| 1050 | + 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', |
|
| 1051 | + 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', |
|
| 1052 | + 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', |
|
| 1053 | + 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', |
|
| 1054 | + 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', |
|
| 1055 | + 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', |
|
| 1056 | + 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', |
|
| 1057 | + 'civility' => $civility, |
|
| 1058 | + ); |
|
| 1059 | + //Create the post and post_meta for the billing address |
|
| 1060 | + $post_address = array( |
|
| 1061 | + 'post_author' => $result->ID, |
|
| 1062 | + 'post_title' => $billing_title, |
|
| 1063 | + 'post_status' => 'publish', |
|
| 1064 | + 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1065 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1066 | + 'post_parent' => $result->ID, |
|
| 1067 | + ); |
|
| 1068 | + $post_address_id = wp_insert_post($post_address); |
|
| 1069 | + |
|
| 1070 | + //Create the post_meta with the address infos |
|
| 1071 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address); |
|
| 1072 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + if (!empty($shipping_infos)) { |
|
| 1076 | + //Save Shipping Infos |
|
| 1077 | + if (!empty($shipping_infos['civility'])) { |
|
| 1078 | + switch ($shipping_infos['civility']) { |
|
| 1079 | + case 1: |
|
| 1080 | + $civility = $mister_id; |
|
| 1081 | + break; |
|
| 1082 | + case 2: |
|
| 1083 | + $civility = $madam_id; |
|
| 1084 | + break; |
|
| 1085 | + case 3: |
|
| 1086 | + $civility = $miss_id; |
|
| 1087 | + break; |
|
| 1088 | + } |
|
| 1089 | + } else { |
|
| 1090 | + $civility = $mister_id; |
|
| 1091 | + } |
|
| 1092 | + $shipping_address = array(); |
|
| 1093 | + $shipping_address = array('address_title' => $shipping_title, |
|
| 1094 | + 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', |
|
| 1095 | + 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', |
|
| 1096 | + 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', |
|
| 1097 | + 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', |
|
| 1098 | + 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', |
|
| 1099 | + 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', |
|
| 1100 | + 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', |
|
| 1101 | + 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', |
|
| 1102 | + 'civility' => $civility, |
|
| 1103 | + ); |
|
| 1104 | + //Create the post and post_meta for the billing address |
|
| 1105 | + $post_address = array( |
|
| 1106 | + 'post_author' => $result->ID, |
|
| 1107 | + 'post_title' => $shipping_title, |
|
| 1108 | + 'post_status' => 'publish', |
|
| 1109 | + 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1110 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1111 | + 'post_parent' => $result->ID, |
|
| 1112 | + ); |
|
| 1113 | + $post_address_id = wp_insert_post($post_address); |
|
| 1114 | + //Create the post_meta with the address infos |
|
| 1115 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address); |
|
| 1116 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id); |
|
| 1117 | + } |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + // FORMATE THE ORDER ADDRESSES INFOS |
|
| 1121 | + $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1122 | + foreach ($results as $result) { |
|
| 1123 | + $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1124 | + |
|
| 1125 | + $billing_address = array(); |
|
| 1126 | + if (!empty($address['billing'])) { |
|
| 1127 | + if (!empty($address['billing']['civility'])) { |
|
| 1128 | + switch ($address['billing']['civility']) { |
|
| 1129 | + case 1: |
|
| 1130 | + $civility = $mister_id; |
|
| 1131 | + break; |
|
| 1132 | + case 2: |
|
| 1133 | + $civility = $madam_id; |
|
| 1134 | + break; |
|
| 1135 | + case 3: |
|
| 1136 | + $civility = $miss_id; |
|
| 1137 | + break; |
|
| 1138 | + default: |
|
| 1139 | + $civility = $mister_id; |
|
| 1140 | + break; |
|
| 1141 | + } |
|
| 1142 | + } else { |
|
| 1143 | + $civility = $mister_id; |
|
| 1144 | + } |
|
| 1145 | + $billing_address = array('address_title' => $billing_title, |
|
| 1146 | + 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1147 | + 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1148 | + 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1149 | + 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1150 | + 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1151 | + 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1152 | + 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1153 | + 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1154 | + 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1155 | + 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1156 | + 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1157 | + 'civility' => $civility, |
|
| 1158 | + ); |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + $shipping_address = array(); |
|
| 1162 | + if (!empty($address['shipping'])) { |
|
| 1163 | + if (!empty($address['shipping']['civility'])) { |
|
| 1164 | + switch ($address['shipping']['civility']) { |
|
| 1165 | + case 1: |
|
| 1166 | + $civility = $mister_id; |
|
| 1167 | + break; |
|
| 1168 | + case 2: |
|
| 1169 | + $civility = $madam_id; |
|
| 1170 | + break; |
|
| 1171 | + case 3: |
|
| 1172 | + $civility = $miss_id; |
|
| 1173 | + break; |
|
| 1174 | + } |
|
| 1175 | + } else { |
|
| 1176 | + $civility = $mister_id; |
|
| 1177 | + } |
|
| 1178 | + $shipping_address = array('address_title' => $shipping_title, |
|
| 1179 | + 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1180 | + 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1181 | + 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1182 | + 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1183 | + 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1184 | + 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1185 | + 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1186 | + 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1187 | + 'civility' => $civility, |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address); |
|
| 1192 | + $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address); |
|
| 1193 | + $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content); |
|
| 1194 | + |
|
| 1195 | + //Update the post meta |
|
| 1196 | + update_post_meta($result->ID, '_order_info', $array_new_format); |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + /* Update entities meta management */ |
|
| 1200 | + $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1)); |
|
| 1201 | + if (!empty($entities)) { |
|
| 1202 | + foreach ($entities as $entity) { |
|
| 1203 | + $params = get_post_meta($entity->ID, '_wpshop_entity_params', true); |
|
| 1204 | + $support = (!empty($params['support'])) ? $params['support'] : ''; |
|
| 1205 | + $rewrite = (!empty($params['rewrite'])) ? $params['rewrite'] : ''; |
|
| 1206 | + |
|
| 1207 | + $display_admin_menu = 'on'; |
|
| 1208 | + |
|
| 1209 | + update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu)); |
|
| 1210 | + } |
|
| 1211 | + } |
|
| 1212 | + wp_reset_query(); |
|
| 1213 | + |
|
| 1214 | + // Default Weight unity and Currency Options |
|
| 1215 | + add_option('wpshop_shop_weight_group', 3, '', 'yes'); |
|
| 1216 | + add_option('wpshop_shop_default_weight_unity', 6, '', 'yes'); |
|
| 1217 | + add_option('wpshop_shop_currency_group', 4, '', 'yes'); |
|
| 1218 | + |
|
| 1219 | + $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1220 | + foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1221 | + if ($default_currency == $k) { |
|
| 1222 | + $symbol = $v; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + if (!empty($symbol)) { |
|
| 1226 | + $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"'; |
|
| 1227 | + $currency = $wpdb->get_row($query); |
|
| 1228 | + if (!empty($currency)) { |
|
| 1229 | + update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1230 | + // Update the change rate of the default currency |
|
| 1231 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + // Update the field for variation and user definition field |
|
| 1236 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes')); |
|
| 1237 | + // Update field type for frontend output selection |
|
| 1238 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array()); |
|
| 1239 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea')); |
|
| 1240 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select')); |
|
| 1241 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select')); |
|
| 1242 | + |
|
| 1243 | + add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page'))); |
|
| 1244 | + |
|
| 1245 | + return true; |
|
| 1246 | + break; |
|
| 1247 | + |
|
| 1248 | + case '30': |
|
| 1249 | + /** Update the current price piloting field for using it into variation specific attributes */ |
|
| 1250 | + $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT); |
|
| 1251 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute)); |
|
| 1252 | + |
|
| 1253 | + /** Update the product reference field for using it into variation specific attributes */ |
|
| 1254 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference')); |
|
| 1255 | + |
|
| 1256 | + /** Insert new message for admin when a customer make an order */ |
|
| 1257 | + $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1258 | + if (empty($admin_new_order_message)) { |
|
| 1259 | + wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1260 | + } |
|
| 1261 | + /** Update all amount for paypal orders */ |
|
| 1262 | + $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal'); |
|
| 1263 | + $paypal_payment_list = $wpdb->get_results($query); |
|
| 1264 | + if (!empty($paypal_payment_list)) { |
|
| 1265 | + foreach ($paypal_payment_list as $post) { |
|
| 1266 | + $order_meta = get_post_meta($post->post_id, '_order_postmeta', true); |
|
| 1267 | + $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true); |
|
| 1268 | + if (!empty($order_meta['order_status']) && ($order_meta['order_status'] == 'incorrect_amount')) { |
|
| 1269 | + if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) { |
|
| 1270 | + $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5); |
|
| 1271 | + $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5); |
|
| 1272 | + if ($order_amount_payed == $order_amount_to_pay) { |
|
| 1273 | + wpshop_payment::setOrderPaymentStatus($order_id, 'completed'); |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /** Save existing orders address information */ |
|
| 1281 | + $billing_title = __('Billing address', 'wpshop'); |
|
| 1282 | + $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1283 | + $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1284 | + foreach ($results as $result) { |
|
| 1285 | + $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1286 | + $address_format = array(); |
|
| 1287 | + |
|
| 1288 | + $billing_address = array(); |
|
| 1289 | + if (!empty($address['billing']) && empty($address['billing']['id'])) { |
|
| 1290 | + if (!empty($address['billing']['civility'])) { |
|
| 1291 | + switch ($address['billing']['civility']) { |
|
| 1292 | + case 1: |
|
| 1293 | + $civility = $mister_id; |
|
| 1294 | + break; |
|
| 1295 | + case 2: |
|
| 1296 | + $civility = $madam_id; |
|
| 1297 | + break; |
|
| 1298 | + case 3: |
|
| 1299 | + $civility = $miss_id; |
|
| 1300 | + break; |
|
| 1301 | + default: |
|
| 1302 | + $civility = $mister_id; |
|
| 1303 | + break; |
|
| 1304 | + } |
|
| 1305 | + } else { |
|
| 1306 | + $civility = $mister_id; |
|
| 1307 | + } |
|
| 1308 | + $billing_address = array('address_title' => $billing_title, |
|
| 1309 | + 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1310 | + 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1311 | + 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1312 | + 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1313 | + 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1314 | + 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1315 | + 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1316 | + 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1317 | + 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1318 | + 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1319 | + 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1320 | + 'civility' => $civility, |
|
| 1321 | + ); |
|
| 1322 | + $billing_address_option = get_option('wpshop_billing_address'); |
|
| 1323 | + $address_format['billing']['id'] = $billing_address_option['choice']; |
|
| 1324 | + $address_format['billing']['address'] = $shipping_address; |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + $shipping_address = array(); |
|
| 1328 | + if (!empty($address['shipping']) && empty($address['shipping']['id'])) { |
|
| 1329 | + if (!empty($address['shipping']['civility'])) { |
|
| 1330 | + switch ($address['shipping']['civility']) { |
|
| 1331 | + case 1: |
|
| 1332 | + $civility = $mister_id; |
|
| 1333 | + break; |
|
| 1334 | + case 2: |
|
| 1335 | + $civility = $madam_id; |
|
| 1336 | + break; |
|
| 1337 | + case 3: |
|
| 1338 | + $civility = $miss_id; |
|
| 1339 | + break; |
|
| 1340 | + } |
|
| 1341 | + } else { |
|
| 1342 | + $civility = $mister_id; |
|
| 1343 | + } |
|
| 1344 | + $shipping_address = array('address_title' => $shipping_title, |
|
| 1345 | + 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1346 | + 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1347 | + 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1348 | + 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1349 | + 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1350 | + 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1351 | + 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1352 | + 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1353 | + 'civility' => $civility, |
|
| 1354 | + ); |
|
| 1355 | + $shipping_address_options = get_option('wpshop_shipping_address_choice'); |
|
| 1356 | + $address_format['shipping']['id'] = $shipping_address_options['choice']; |
|
| 1357 | + $address_format['shipping']['address'] = $shipping_address; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + if (!empty($address_format)) { |
|
| 1361 | + update_post_meta($result->ID, '_order_info', $address_format); |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + /** Delete username from frontend form */ |
|
| 1366 | + $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code'); |
|
| 1367 | + if (!empty($attribute_login)) { |
|
| 1368 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id)); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted')); |
|
| 1372 | + |
|
| 1373 | + return true; |
|
| 1374 | + break; |
|
| 1375 | + |
|
| 1376 | + case '31': |
|
| 1377 | + /** Change order structure in order to support several payment */ |
|
| 1378 | + $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish'))); |
|
| 1379 | + if (!empty($existing_orders)) { |
|
| 1380 | + foreach ($existing_orders as $order_main_informations) { |
|
| 1381 | + /** Transfer payment return data form old meta to new */ |
|
| 1382 | + $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true); |
|
| 1383 | + update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data); |
|
| 1384 | + delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data'); |
|
| 1385 | + |
|
| 1386 | + /** Transfer old payment storage method to new storage method */ |
|
| 1387 | + $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true); |
|
| 1388 | + if (!empty($order_meta['order_status'])) { |
|
| 1389 | + $order_meta['order_payment']['customer_choice'] = array('method' => (!empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : ''))); |
|
| 1390 | + unset($order_meta['payment_method']); |
|
| 1391 | + $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0; |
|
| 1392 | + $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method']; |
|
| 1393 | + $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date']; |
|
| 1394 | + $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment'; |
|
| 1395 | + $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1396 | + $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1397 | + if (in_array($order_meta['order_status'], array('completed', 'shipped'))) { |
|
| 1398 | + $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total']; |
|
| 1399 | + $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID); |
|
| 1400 | + $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date']; |
|
| 1401 | + $order_meta['order_payment']['received'][0]['status'] = 'payment_received'; |
|
| 1402 | + $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1403 | + $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1404 | + $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref']; |
|
| 1405 | + } |
|
| 1406 | + update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta); |
|
| 1407 | + |
|
| 1408 | + if (!empty($order_meta['order_payment']['customer_choice'])) { |
|
| 1409 | + switch ($order_meta['order_payment']['customer_choice']) { |
|
| 1410 | + case 'check': |
|
| 1411 | + delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true)); |
|
| 1412 | + break; |
|
| 1413 | + case 'paypal': |
|
| 1414 | + delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true)); |
|
| 1415 | + break; |
|
| 1416 | + case 'cic': |
|
| 1417 | + delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true)); |
|
| 1418 | + break; |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | + $wps_messages = new wps_message_ctr(); |
|
| 1425 | + $wps_messages->wpshop_messages_historic_correction(); |
|
| 1426 | + wp_reset_query(); |
|
| 1427 | + |
|
| 1428 | + $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1429 | + foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1430 | + if ($default_currency == $k) { |
|
| 1431 | + $symbol = $v; |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1434 | + if (!empty($symbol)) { |
|
| 1435 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', ''); |
|
| 1436 | + $currency = $wpdb->get_row($query); |
|
| 1437 | + if (!empty($currency)) { |
|
| 1438 | + update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1439 | + // Update the change rate of the default currency |
|
| 1440 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE'); |
|
| 1445 | + if (!empty($shipping_confirmation_message)) { |
|
| 1446 | + $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop'); |
|
| 1447 | + $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message); |
|
| 1448 | + wp_update_post($post); |
|
| 1449 | + } |
|
| 1450 | + return true; |
|
| 1451 | + break; |
|
| 1452 | + case '32': |
|
| 1453 | + /** Update product set id that are null */ |
|
| 1454 | + $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id'); |
|
| 1455 | + $wpdb->query($query); |
|
| 1456 | + |
|
| 1457 | + $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME); |
|
| 1458 | + if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) { |
|
| 1459 | + $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1460 | + if (empty($admin_new_quotation_message)) { |
|
| 1461 | + wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1462 | + } |
|
| 1463 | + $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1464 | + if (empty($admin_new_quotation_confirm_message)) { |
|
| 1465 | + wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1466 | + } |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + /** Allows the administrator to manage a little bit more the catalog rewrite parameters */ |
|
| 1470 | + $options = get_option('wpshop_catalog_product_option'); |
|
| 1471 | + $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category']; |
|
| 1472 | + update_option('wpshop_catalog_product_option', $options); |
|
| 1473 | + |
|
| 1474 | + /** Create a new page for unsuccessfull payment return */ |
|
| 1475 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 1476 | + wp_cache_flush(); |
|
| 1477 | + |
|
| 1478 | + /** Update the iso code of currencies */ |
|
| 1479 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro')); |
|
| 1480 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar')); |
|
| 1481 | + |
|
| 1482 | + /** Update VAT Rate*/ |
|
| 1483 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva'); |
|
| 1484 | + $attribute_ids = $wpdb->get_results($query); |
|
| 1485 | + foreach ($attribute_ids as $attribute_id) { |
|
| 1486 | + $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id); |
|
| 1487 | + $wpdb->query($query); |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + return true; |
|
| 1491 | + break; |
|
| 1492 | + |
|
| 1493 | + case '33': |
|
| 1494 | + /** Update the user_mail for the new system of log in/register */ |
|
| 1495 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"'); |
|
| 1496 | + |
|
| 1497 | + /** Put discount attributes in price attribute set section*/ |
|
| 1498 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1499 | + $prices_section_id = $wpdb->get_var($query); |
|
| 1500 | + |
|
| 1501 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount'); |
|
| 1502 | + $attributes = $wpdb->get_results($query); |
|
| 1503 | + if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1504 | + foreach ($attributes as $attribute) { |
|
| 1505 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id); |
|
| 1506 | + } |
|
| 1507 | + } |
|
| 1508 | + return true; |
|
| 1509 | + break; |
|
| 1510 | + |
|
| 1511 | + case '34': |
|
| 1512 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1513 | + $prices_section_id = $wpdb->get_var($query); |
|
| 1514 | + |
|
| 1515 | + $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id); |
|
| 1516 | + $last_position_id = $wpdb->get_var($query); |
|
| 1517 | + |
|
| 1518 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id); |
|
| 1519 | + $attribute_example = $wpdb->get_row($query); |
|
| 1520 | + |
|
| 1521 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to'); |
|
| 1522 | + $attributes = $wpdb->get_results($query); |
|
| 1523 | + $i = 1; |
|
| 1524 | + if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1525 | + |
|
| 1526 | + foreach ($attributes as $attribute) { |
|
| 1527 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id)); |
|
| 1528 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i)); |
|
| 1529 | + $i++; |
|
| 1530 | + } |
|
| 1531 | + } |
|
| 1532 | + $discount_options = get_option('wpshop_catalog_product_option'); |
|
| 1533 | + $status = (!empty($discount_options) && !empty($discount_options['discount'])) ? 'valid' : 'notused'; |
|
| 1534 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from')); |
|
| 1535 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to')); |
|
| 1536 | + return true; |
|
| 1537 | + break; |
|
| 1538 | + |
|
| 1539 | + case '35': |
|
| 1540 | + $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)); |
|
| 1541 | + return true; |
|
| 1542 | + break; |
|
| 1543 | + |
|
| 1544 | + case '36': |
|
| 1545 | + wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
| 1546 | + @set_time_limit(900); |
|
| 1547 | + /** Change the path for old categories pictures */ |
|
| 1548 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755); |
|
| 1549 | + |
|
| 1550 | + $query = 'SELECT * FROM ' . $wpdb->terms; |
|
| 1551 | + $terms = $wpdb->get_results($query); |
|
| 1552 | + if (!empty($terms)) { |
|
| 1553 | + foreach ($terms as $term) { |
|
| 1554 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755); |
|
| 1555 | + /** Check if a picture exists **/ |
|
| 1556 | + $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id); |
|
| 1557 | + if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) { |
|
| 1558 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1559 | + $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture']; |
|
| 1560 | + $img_basename = basename($img_path); |
|
| 1561 | + $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1562 | + /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1563 | + $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1564 | + $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1565 | + if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1566 | + $attachment = array( |
|
| 1567 | + 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1568 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1569 | + 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1570 | + 'post_content' => '', |
|
| 1571 | + 'post_status' => 'inherit', |
|
| 1572 | + ); |
|
| 1573 | + $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1574 | + /** Generate differnts sizes for this image **/ |
|
| 1575 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1576 | + $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1577 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1578 | + /** Update option picture **/ |
|
| 1579 | + $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1580 | + update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option); |
|
| 1581 | + } |
|
| 1582 | + } |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ |
|
| 1587 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus'); |
|
| 1588 | + $meta_keys = $wpdb->get_results($query); |
|
| 1589 | + if (!empty($meta_keys) && is_array($meta_keys)) { |
|
| 1590 | + foreach ($meta_keys as $meta_key) { |
|
| 1591 | + $user_id = $meta_key->user_id; |
|
| 1592 | + $meta_value = unserialize($meta_key->meta_value); |
|
| 1593 | + if (!empty($meta_value) && is_array($meta_value)) { |
|
| 1594 | + $data_to_delete = array_search('add-wpshop_product_category', $meta_value); |
|
| 1595 | + if ($data_to_delete !== false) { |
|
| 1596 | + unset($meta_value[$data_to_delete]); |
|
| 1597 | + } |
|
| 1598 | + } |
|
| 1599 | + update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value); |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + return true; |
|
| 1603 | + break; |
|
| 1604 | + |
|
| 1605 | + case '37': |
|
| 1606 | + @set_time_limit(900); |
|
| 1607 | + /** Change the path for old categories pictures */ |
|
| 1608 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755); |
|
| 1609 | + /** Read all categories folders **/ |
|
| 1610 | + $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category'; |
|
| 1611 | + if (file_exists($categories_main_dir)) { |
|
| 1612 | + $main_folder_content = scandir($categories_main_dir); |
|
| 1613 | + /** For each category folder **/ |
|
| 1614 | + foreach ($main_folder_content as $category_folder) { |
|
| 1615 | + if ($category_folder && substr($category_folder, 0, 1) != '.') { |
|
| 1616 | + $category_id = $category_folder; |
|
| 1617 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755); |
|
| 1618 | + $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder); |
|
| 1619 | + /** For each Picture of category **/ |
|
| 1620 | + $file_time = 0; |
|
| 1621 | + $save_this_picture = false; |
|
| 1622 | + while (false !== ($fichier = readdir($scan_category_folder))) { |
|
| 1623 | + if ($fichier && substr($fichier, 0, 1) != '.') { |
|
| 1624 | + if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) { |
|
| 1625 | + $save_this_picture = true; |
|
| 1626 | + $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier); |
|
| 1627 | + } |
|
| 1628 | + /** Select category option **/ |
|
| 1629 | + $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id); |
|
| 1630 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1631 | + $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier; |
|
| 1632 | + $img_basename = basename($img_path); |
|
| 1633 | + $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1634 | + /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1635 | + $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1636 | + $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1637 | + |
|
| 1638 | + if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1639 | + $attachment = array( |
|
| 1640 | + 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1641 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1642 | + 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1643 | + 'post_content' => '', |
|
| 1644 | + 'post_status' => 'inherit', |
|
| 1645 | + ); |
|
| 1646 | + $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1647 | + /** Generate differnts sizes for this image **/ |
|
| 1648 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1649 | + $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1650 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1651 | + /** Update option picture **/ |
|
| 1652 | + $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1653 | + if ($save_this_picture) { |
|
| 1654 | + update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option); |
|
| 1655 | + } |
|
| 1656 | + $save_this_picture = false; |
|
| 1657 | + } |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + } |
|
| 1661 | + } |
|
| 1662 | + } |
|
| 1663 | + return true; |
|
| 1664 | + break; |
|
| 1665 | + |
|
| 1666 | + case '38': |
|
| 1667 | + wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE'); |
|
| 1668 | + return true; |
|
| 1669 | + break; |
|
| 1670 | + |
|
| 1671 | + case '39': |
|
| 1672 | + $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1673 | + /** Check if the 7% VAT Rate is not already created **/ |
|
| 1674 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7'); |
|
| 1675 | + $exist_vat_rate = $wpdb->get_results($query); |
|
| 1676 | + |
|
| 1677 | + if (empty($exist_vat_rate)) { |
|
| 1678 | + /** Get Max Position **/ |
|
| 1679 | + $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 1680 | + $max_position = $wpdb->get_var($query); |
|
| 1681 | + |
|
| 1682 | + if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 1683 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7')); |
|
| 1684 | + } |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** Filter Search optimization **/ |
|
| 1688 | + @set_time_limit(900); |
|
| 1689 | + $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1690 | + $categories = $wpdb->get_results($query); |
|
| 1691 | + $cats = array(); |
|
| 1692 | + if (!empty($categories)) { |
|
| 1693 | + foreach ($categories as $category) { |
|
| 1694 | + $cats[] = $category->term_id; |
|
| 1695 | + } |
|
| 1696 | + $wpshop_filter_search = new wps_filter_search(); |
|
| 1697 | + $wpshop_filter_search->stock_values_for_attribute($cats); |
|
| 1698 | + } |
|
| 1699 | + return true; |
|
| 1700 | + break; |
|
| 1701 | + |
|
| 1702 | + case '40': |
|
| 1703 | + /** Store watt in puissance unit group */ |
|
| 1704 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop')); |
|
| 1705 | + $puissance_unit_group_id = $wpdb->get_var($query); |
|
| 1706 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt')); |
|
| 1707 | + |
|
| 1708 | + /** Store day/week/year in duration unit group */ |
|
| 1709 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop')); |
|
| 1710 | + $duration_unit_group_id = $wpdb->get_var($query); |
|
| 1711 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day')); |
|
| 1712 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week')); |
|
| 1713 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year')); |
|
| 1714 | + |
|
| 1715 | + /** Store day/week/year in duration unit group */ |
|
| 1716 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop')); |
|
| 1717 | + $length_unit_group_id = $wpdb->get_var($query); |
|
| 1718 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm')); |
|
| 1719 | + return true; |
|
| 1720 | + break; |
|
| 1721 | + |
|
| 1722 | + case '41': |
|
| 1723 | + /** Get distinct attribute set and delete doublons */ |
|
| 1724 | + $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1725 | + $list_of_set = $wpdb->get_results($query); |
|
| 1726 | + foreach ($list_of_set as $set_infos) { |
|
| 1727 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1728 | + $wpdb->query($query); |
|
| 1729 | + } |
|
| 1730 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET); |
|
| 1731 | + |
|
| 1732 | + /** Get and delete attribute set section */ |
|
| 1733 | + $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )"; |
|
| 1734 | + $wpdb->query($query); |
|
| 1735 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP); |
|
| 1736 | + |
|
| 1737 | + /** Get and delete attribute set details */ |
|
| 1738 | + $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1739 | + $wpdb->query($query); |
|
| 1740 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1741 | + |
|
| 1742 | + $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1743 | + $affectation_list = $wpdb->get_results($query); |
|
| 1744 | + foreach ($affectation_list as $affectation_to_treat) { |
|
| 1745 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id); |
|
| 1746 | + $wpdb->query($query); |
|
| 1747 | + } |
|
| 1748 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1749 | + |
|
| 1750 | + /** Get and delete double unit */ |
|
| 1751 | + $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1"; |
|
| 1752 | + $list_of_set = $wpdb->get_results($query); |
|
| 1753 | + foreach ($list_of_set as $set_infos) { |
|
| 1754 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id); |
|
| 1755 | + $wpdb->query($query); |
|
| 1756 | + } |
|
| 1757 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT); |
|
| 1758 | + |
|
| 1759 | + $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1760 | + $list_of_set = $wpdb->get_results($query); |
|
| 1761 | + foreach ($list_of_set as $set_infos) { |
|
| 1762 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1763 | + $wpdb->query($query); |
|
| 1764 | + } |
|
| 1765 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP); |
|
| 1766 | + |
|
| 1767 | + /** Get and delete attribute set details */ |
|
| 1768 | + $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1769 | + $wpdb->query($query); |
|
| 1770 | + $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1771 | + $affectation_list = $wpdb->get_results($query); |
|
| 1772 | + foreach ($affectation_list as $list) { |
|
| 1773 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, ''); |
|
| 1774 | + $wpdb->query($query); |
|
| 1775 | + } |
|
| 1776 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1777 | + |
|
| 1778 | + return true; |
|
| 1779 | + break; |
|
| 1780 | + |
|
| 1781 | + case '42': |
|
| 1782 | + $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1783 | + if (empty($available_downloadable_product)) { |
|
| 1784 | + wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1785 | + } |
|
| 1786 | + return true; |
|
| 1787 | + break; |
|
| 1788 | + |
|
| 1789 | + case '43': |
|
| 1790 | + $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1791 | + if (empty($available_downloadable_product)) { |
|
| 1792 | + wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1793 | + } |
|
| 1794 | + return true; |
|
| 1795 | + break; |
|
| 1796 | + |
|
| 1797 | + case '44': |
|
| 1798 | + $display_option = get_option('wpshop_display_option'); |
|
| 1799 | + if (!empty($display_option) && empty($display_option['latest_products_ordered'])) { |
|
| 1800 | + $display_option['latest_products_ordered'] = 3; |
|
| 1801 | + update_option('wpshop_display_option', $display_option); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + /** Check messages for customization **/ |
|
| 1805 | + $messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED); |
|
| 1806 | + if (!empty($messages)) { |
|
| 1807 | + foreach ($messages as $key => $message) { |
|
| 1808 | + $message_option = get_option($key); |
|
| 1809 | + if (!empty($message_option)) { |
|
| 1810 | + $post_message = get_post($message_option); |
|
| 1811 | + $original_message = (!empty($post_message) && !empty($post_message->post_content)) ? $post_message->post_content : ''; |
|
| 1812 | + $tags = array('<p>', '</p>'); |
|
| 1813 | + if (str_replace($tags, '', $original_message) == str_replace($tags, '', __($message, 'wpshop'))) { |
|
| 1814 | + wp_update_post(array('ID' => $message_option, 'post_content' => wps_message_ctr::customize_message($original_message))); |
|
| 1815 | + } |
|
| 1816 | + } |
|
| 1817 | + } |
|
| 1818 | + } |
|
| 1819 | + |
|
| 1820 | + return true; |
|
| 1821 | + break; |
|
| 1822 | + |
|
| 1823 | + case '45': |
|
| 1824 | + $shipping_mode_ctr = new wps_shipping_mode_ctr(); |
|
| 1825 | + $shipping_mode_ctr->migrate_default_shipping_mode(); |
|
| 1826 | + return true; |
|
| 1827 | + break; |
|
| 1828 | + |
|
| 1829 | + case '46': |
|
| 1830 | + wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE'); |
|
| 1831 | + wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE); |
|
| 1832 | + return true; |
|
| 1833 | + break; |
|
| 1834 | + |
|
| 1835 | + case '47': |
|
| 1836 | + wps_payment_mode::migrate_payment_modes(); |
|
| 1837 | + return true; |
|
| 1838 | + break; |
|
| 1839 | + |
|
| 1840 | + case '48': |
|
| 1841 | + @ini_set('max_execution_time', '500'); |
|
| 1842 | + |
|
| 1843 | + $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1844 | + $output_type_option = get_option('wpshop_display_option'); |
|
| 1845 | + $output_type = $output_type_option['wpshop_display_list_type']; |
|
| 1846 | + |
|
| 1847 | + for ($i = 0; $i <= $count_products->publish; $i += 20) { |
|
| 1848 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
|
| 1849 | + $products = $wpdb->get_results($query); |
|
| 1850 | + if (!empty($products)) { |
|
| 1851 | + foreach ($products as $product) { |
|
| 1852 | + $p = wpshop_products::get_product_data($product->ID); |
|
| 1853 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); |
|
| 1854 | + update_post_meta($product->ID, '_wps_price_infos', $price); |
|
| 1855 | + } |
|
| 1856 | + } |
|
| 1857 | + } |
|
| 1858 | + |
|
| 1859 | + return true; |
|
| 1860 | + break; |
|
| 1861 | + |
|
| 1862 | + case '49': |
|
| 1863 | + update_option('wpshop_send_invoice', true); |
|
| 1864 | + return true; |
|
| 1865 | + break; |
|
| 1866 | + |
|
| 1867 | + case '50': |
|
| 1868 | + $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1869 | + $price_display_option['price_display']['text_from'] = 'on'; |
|
| 1870 | + $price_display_option['price_display']['lower_price'] = 'on'; |
|
| 1871 | + update_option('wpshop_catalog_product_option', $price_display_option); |
|
| 1872 | + |
|
| 1873 | + self::wpshop_insert_default_pages(); |
|
| 1874 | + |
|
| 1875 | + return true; |
|
| 1876 | + break; |
|
| 1877 | + |
|
| 1878 | + case '51': |
|
| 1879 | + /** Insert new message for direct payment link */ |
|
| 1880 | + $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1881 | + if (empty($direct_payment_link_message)) { |
|
| 1882 | + wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1883 | + } |
|
| 1884 | + return true; |
|
| 1885 | + break; |
|
| 1886 | + |
|
| 1887 | + case '52': |
|
| 1888 | + $account_page_option = get_option('wpshop_myaccount_page_id'); |
|
| 1889 | + if (!empty($account_page_option)) { |
|
| 1890 | + $page_account = get_post($account_page_option); |
|
| 1891 | + $page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]'; |
|
| 1892 | + wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content)); |
|
| 1893 | + } |
|
| 1894 | + return true; |
|
| 1895 | + break; |
|
| 1896 | + |
|
| 1897 | + case '53': |
|
| 1898 | + $payment_modes_option = get_option('wps_payment_mode'); |
|
| 1899 | + if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) { |
|
| 1900 | + $payment_modes_option['mode']['cash_on_delivery'] = array( |
|
| 1901 | + 'name' => __('Cash on delivery', 'wpshop'), |
|
| 1902 | + 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', |
|
| 1903 | + 'description' => __('Pay your order on delivery', 'wpshop')); |
|
| 1904 | + |
|
| 1905 | + update_option('wps_payment_mode', $payment_modes_option); |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + // Mass action on products to add a flag on variation definition |
|
| 1909 | + $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1910 | + if (!empty($products)) { |
|
| 1911 | + foreach ($products as $p) { |
|
| 1912 | + $post_id = $p->ID; |
|
| 1913 | + $check_product_have_variations = wpshop_products::get_variation($post_id); |
|
| 1914 | + if (!empty($check_product_have_variations)) { |
|
| 1915 | + $variation_flag = wpshop_products::check_variation_type($post_id); |
|
| 1916 | + $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1917 | + $variation_defining['variation_type'] = $variation_flag; |
|
| 1918 | + update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1919 | + } |
|
| 1920 | + } |
|
| 1921 | + } |
|
| 1922 | + return true; |
|
| 1923 | + break; |
|
| 1924 | + |
|
| 1925 | + case '54': |
|
| 1926 | + // Change shortcode of sign up page |
|
| 1927 | + $signup_page_id = get_option('wpshop_signup_page_id'); |
|
| 1928 | + if (!empty($signup_page_id)) { |
|
| 1929 | + $signup_page = get_post($signup_page_id); |
|
| 1930 | + $signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]'; |
|
| 1931 | + wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content)); |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + // Change Terms of sale default content |
|
| 1935 | + $terms_page_id = get_option('wpshop_terms_of_sale_page_id'); |
|
| 1936 | + if (!empty($terms_page_id)) { |
|
| 1937 | + $terms_sale_page = get_post($terms_page_id); |
|
| 1938 | + if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') { |
|
| 1939 | + $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>'; |
|
| 1940 | + $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>'; |
|
| 1941 | + $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1942 | + $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>'; |
|
| 1943 | + $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1944 | + $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>'; |
|
| 1945 | + $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1946 | + $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>'; |
|
| 1947 | + $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name')); |
|
| 1948 | + wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data)); |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + return true; |
|
| 1953 | + break; |
|
| 1954 | + |
|
| 1955 | + case '55': |
|
| 1956 | + $checkout_page_id = get_option('wpshop_checkout_page_id'); |
|
| 1957 | + $checkout_page = get_post($checkout_page_id); |
|
| 1958 | + $checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]'; |
|
| 1959 | + wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content)); |
|
| 1960 | + |
|
| 1961 | + // Update cart page id |
|
| 1962 | + update_option('wpshop_cart_page_id', $checkout_page_id); |
|
| 1963 | + return true; |
|
| 1964 | + break; |
|
| 1965 | + |
|
| 1966 | + case '56': |
|
| 1967 | + $wps_entities = new wpshop_entities(); |
|
| 1968 | + $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1969 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id); |
|
| 1970 | + $set = $wpdb->get_row($query); |
|
| 1971 | + if (!empty($set)) { |
|
| 1972 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, |
|
| 1973 | + array('default_set' => 'yes'), |
|
| 1974 | + array('id' => $set->id)); |
|
| 1975 | + } |
|
| 1976 | + // Update Opinions activation option |
|
| 1977 | + update_option('wps_opinion', array('active' => 'on')); |
|
| 1978 | + return true; |
|
| 1979 | + break; |
|
| 1980 | + |
|
| 1981 | + case '57': |
|
| 1982 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 1983 | + $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes'; |
|
| 1984 | + $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes'; |
|
| 1985 | + |
|
| 1986 | + update_option('wpshop_cart_option', $wpshop_cart_option); |
|
| 1987 | + return true; |
|
| 1988 | + break; |
|
| 1989 | + |
|
| 1990 | + case '58': |
|
| 1991 | + /** Turn customers publish into draft **/ |
|
| 1992 | + $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1993 | + $wpdb->query($query); |
|
| 1994 | + |
|
| 1995 | + $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1996 | + /** Check if the 0% VAT Rate is not already created **/ |
|
| 1997 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0'); |
|
| 1998 | + $exist_vat_rate = $wpdb->get_results($query); |
|
| 1999 | + |
|
| 2000 | + if (empty($exist_vat_rate)) { |
|
| 2001 | + /** Get Max Position **/ |
|
| 2002 | + $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 2003 | + $max_position = $wpdb->get_var($query); |
|
| 2004 | + |
|
| 2005 | + if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 2006 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0')); |
|
| 2007 | + } |
|
| 2008 | + } |
|
| 2009 | + return true; |
|
| 2010 | + break; |
|
| 2011 | + |
|
| 2012 | + case '59': |
|
| 2013 | + /** Move old images gallery to the new gallery, and remove old links **/ |
|
| 2014 | + $allowed = get_allowed_mime_types(); |
|
| 2015 | + $args = array( |
|
| 2016 | + 'posts_per_page' => -1, |
|
| 2017 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 2018 | + 'post_status' => array('publish', 'draft', 'trash'), |
|
| 2019 | + ); |
|
| 2020 | + $posts = get_posts($args); |
|
| 2021 | + $result = array(); |
|
| 2022 | + foreach ($posts as $post) { |
|
| 2023 | + $array = array(); |
|
| 2024 | + $array['Post'] = $post; |
|
| 2025 | + $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true); |
|
| 2026 | + $array['Attachments'] = get_attached_media($allowed, $post->ID); |
|
| 2027 | + $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true); |
|
| 2028 | + if (!empty($array['TrueAttachmentsString'])) { |
|
| 2029 | + $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']); |
|
| 2030 | + } |
|
| 2031 | + $array['OldAttachmentsString'] = ''; |
|
| 2032 | + foreach ($array['Attachments'] as $attachment) { |
|
| 2033 | + $filename = basename(get_attached_file($attachment->ID)); |
|
| 2034 | + $pos_ext = strrpos($filename, '.'); |
|
| 2035 | + $filename_no_ext = substr($filename, 0, $pos_ext); |
|
| 2036 | + if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) { |
|
| 2037 | + $array['OldAttachmentsString'] .= $attachment->ID . ','; |
|
| 2038 | + } |
|
| 2039 | + } |
|
| 2040 | + unset($TrueAttachments_id); |
|
| 2041 | + $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString']; |
|
| 2042 | + update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]); |
|
| 2043 | + } |
|
| 2044 | + return true; |
|
| 2045 | + break; |
|
| 2046 | + |
|
| 2047 | + case '60': |
|
| 2048 | + /* Create default emails */ |
|
| 2049 | + wps_message_ctr::create_default_message(); |
|
| 2050 | + |
|
| 2051 | + /** Update entries for quick add */ |
|
| 2052 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"'); |
|
| 2053 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"'); |
|
| 2054 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"'); |
|
| 2055 | + switch (WPSHOP_PRODUCT_PRICE_PILOT) { |
|
| 2056 | + case 'HT': |
|
| 2057 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"'); |
|
| 2058 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"'); |
|
| 2059 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"'); |
|
| 2060 | + break; |
|
| 2061 | + default: |
|
| 2062 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"'); |
|
| 2063 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"'); |
|
| 2064 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"'); |
|
| 2065 | + break; |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + /* Default country with WP language */ |
|
| 2069 | + $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice'); |
|
| 2070 | + if (empty($wpshop_country_default_choice_option)) { |
|
| 2071 | + update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3)); |
|
| 2072 | + } |
|
| 2073 | + return true; |
|
| 2074 | + break; |
|
| 2075 | + |
|
| 2076 | + case '61': |
|
| 2077 | + /** Import the xml for guided tour */ |
|
| 2078 | + wpsBubble_ctr::import_xml(); |
|
| 2079 | + |
|
| 2080 | + /* Hide admin bar */ |
|
| 2081 | + $wpshop_display_option = get_option('wpshop_display_option'); |
|
| 2082 | + if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) { |
|
| 2083 | + $wpshop_display_option['wpshop_hide_admin_bar'] = 'on'; |
|
| 2084 | + update_option('wpshop_display_option', $wpshop_display_option); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + return true; |
|
| 2088 | + break; |
|
| 2089 | + |
|
| 2090 | + case '62': |
|
| 2091 | + /** Install user default for POS */ |
|
| 2092 | + wps_pos_addon::action_to_do_on_activation(); |
|
| 2093 | + |
|
| 2094 | + return true; |
|
| 2095 | + break; |
|
| 2096 | + |
|
| 2097 | + case '63': |
|
| 2098 | + $data = get_option('wps_shipping_mode'); |
|
| 2099 | + if (empty($data['modes']['default_shipping_mode_for_pos'])) { |
|
| 2100 | + $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop'); |
|
| 2101 | + $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop'); |
|
| 2102 | + update_option('wps_shipping_mode', $data); |
|
| 2103 | + } |
|
| 2104 | + return true; |
|
| 2105 | + break; |
|
| 2106 | + |
|
| 2107 | + case '64': |
|
| 2108 | + $options = get_option('wpshop_catalog_product_option'); |
|
| 2109 | + if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 2110 | + unset($options['wpshop_catalog_product_slug_with_category']); |
|
| 2111 | + update_option('wpshop_catalog_product_option', $options); |
|
| 2112 | + } |
|
| 2113 | + return true; |
|
| 2114 | + break; |
|
| 2115 | + |
|
| 2116 | + case '65': |
|
| 2117 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 2118 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id); |
|
| 2119 | + $company_id = $wpdb->get_var($query); |
|
| 2120 | + if (!isset($company_id)) { |
|
| 2121 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2122 | + 'is_visible_in_front' => 'no', |
|
| 2123 | + 'is_visible_in_front_listing' => 'yes', |
|
| 2124 | + 'is_global' => 'no', |
|
| 2125 | + 'is_user_defined' => 'no', |
|
| 2126 | + 'is_required' => 'no', |
|
| 2127 | + 'is_visible_in_advanced_search' => 'no', |
|
| 2128 | + 'is_searchable' => 'no', |
|
| 2129 | + 'is_filterable' => 'no', |
|
| 2130 | + 'is_comparable' => 'no', |
|
| 2131 | + 'is_html_allowed_on_front' => 'no', |
|
| 2132 | + 'is_unique' => 'no', |
|
| 2133 | + 'is_filterable_in_search' => 'no', |
|
| 2134 | + 'is_used_for_sort_by' => 'no', |
|
| 2135 | + 'is_configurable' => 'no', |
|
| 2136 | + 'is_requiring_unit' => 'no', |
|
| 2137 | + 'is_recordable_in_cart_meta' => 'no', |
|
| 2138 | + 'is_used_in_admin_listing_column' => 'no', |
|
| 2139 | + 'is_used_in_quick_add_form' => 'no', |
|
| 2140 | + 'is_used_for_variation' => 'no', |
|
| 2141 | + 'is_used_in_variation' => 'no', |
|
| 2142 | + '_display_informations_about_value' => 'no', |
|
| 2143 | + '_need_verification' => 'no', |
|
| 2144 | + '_unit_group_id' => null, |
|
| 2145 | + '_default_unit' => null, |
|
| 2146 | + 'is_historisable' => 'yes', |
|
| 2147 | + 'is_intrinsic' => 'no', |
|
| 2148 | + 'data_type_to_use' => 'custom', |
|
| 2149 | + 'use_ajax_for_filling_field' => 'no', |
|
| 2150 | + 'data_type' => 'varchar', |
|
| 2151 | + 'backend_table' => null, |
|
| 2152 | + 'backend_label' => 'Company', |
|
| 2153 | + 'backend_input' => 'text', |
|
| 2154 | + 'frontend_label' => 'Company', |
|
| 2155 | + 'frontend_input' => 'text', |
|
| 2156 | + 'frontend_verification' => null, |
|
| 2157 | + 'code' => 'company_customer', |
|
| 2158 | + 'note' => '', |
|
| 2159 | + 'default_value' => '', |
|
| 2160 | + 'frontend_css_class' => 'company_customer', |
|
| 2161 | + 'backend_css_class' => null, |
|
| 2162 | + 'frontend_help_message' => null, |
|
| 2163 | + 'entity_id' => $entity_id, |
|
| 2164 | + )); |
|
| 2165 | + $company_id = $wpdb->insert_id; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id); |
|
| 2169 | + $is_provider_id = $wpdb->get_var($query); |
|
| 2170 | + if (!isset($is_provider_id)) { |
|
| 2171 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2172 | + 'is_visible_in_front' => 'no', |
|
| 2173 | + 'is_visible_in_front_listing' => 'yes', |
|
| 2174 | + 'is_global' => 'no', |
|
| 2175 | + 'is_user_defined' => 'no', |
|
| 2176 | + 'is_required' => 'yes', |
|
| 2177 | + 'is_visible_in_advanced_search' => 'no', |
|
| 2178 | + 'is_searchable' => 'no', |
|
| 2179 | + 'is_filterable' => 'no', |
|
| 2180 | + 'is_comparable' => 'no', |
|
| 2181 | + 'is_html_allowed_on_front' => 'no', |
|
| 2182 | + 'is_unique' => 'no', |
|
| 2183 | + 'is_filterable_in_search' => 'no', |
|
| 2184 | + 'is_used_for_sort_by' => 'no', |
|
| 2185 | + 'is_configurable' => 'no', |
|
| 2186 | + 'is_requiring_unit' => 'no', |
|
| 2187 | + 'is_recordable_in_cart_meta' => 'no', |
|
| 2188 | + 'is_used_in_admin_listing_column' => 'no', |
|
| 2189 | + 'is_used_in_quick_add_form' => 'no', |
|
| 2190 | + 'is_used_for_variation' => 'no', |
|
| 2191 | + 'is_used_in_variation' => 'no', |
|
| 2192 | + '_display_informations_about_value' => 'no', |
|
| 2193 | + '_need_verification' => 'no', |
|
| 2194 | + '_unit_group_id' => null, |
|
| 2195 | + '_default_unit' => null, |
|
| 2196 | + 'is_historisable' => 'yes', |
|
| 2197 | + 'is_intrinsic' => 'no', |
|
| 2198 | + 'data_type_to_use' => 'custom', |
|
| 2199 | + 'use_ajax_for_filling_field' => 'no', |
|
| 2200 | + 'data_type' => 'integer', |
|
| 2201 | + 'backend_table' => null, |
|
| 2202 | + 'backend_label' => 'Provider', |
|
| 2203 | + 'backend_input' => 'select', |
|
| 2204 | + 'frontend_label' => 'Provider', |
|
| 2205 | + 'frontend_input' => 'select', |
|
| 2206 | + 'frontend_verification' => null, |
|
| 2207 | + 'code' => 'is_provider', |
|
| 2208 | + 'note' => '', |
|
| 2209 | + 'default_value' => 'no', |
|
| 2210 | + 'frontend_css_class' => 'is_provider', |
|
| 2211 | + 'backend_css_class' => null, |
|
| 2212 | + 'frontend_help_message' => null, |
|
| 2213 | + 'entity_id' => $entity_id, |
|
| 2214 | + )); |
|
| 2215 | + $is_provider_id = $wpdb->insert_id; |
|
| 2216 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2217 | + 'status' => 'valid', |
|
| 2218 | + 'attribute_id' => $is_provider_id, |
|
| 2219 | + 'creation_date_value' => current_time('mysql'), |
|
| 2220 | + 'value' => 'yes', |
|
| 2221 | + 'label' => 'Yes', |
|
| 2222 | + )); |
|
| 2223 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2224 | + 'status' => 'valid', |
|
| 2225 | + 'attribute_id' => $is_provider_id, |
|
| 2226 | + 'creation_date_value' => current_time('mysql'), |
|
| 2227 | + 'value' => 'no', |
|
| 2228 | + 'label' => 'No', |
|
| 2229 | + )); |
|
| 2230 | + $default_value = $wpdb->insert_id; |
|
| 2231 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id)); |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id); |
|
| 2235 | + $company_section_detail_id = $wpdb->get_var($query); |
|
| 2236 | + |
|
| 2237 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id); |
|
| 2238 | + $is_provider_section_detail_id = $wpdb->get_var($query); |
|
| 2239 | + |
|
| 2240 | + if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) { |
|
| 2241 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 2242 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 2243 | + |
|
| 2244 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account'); |
|
| 2245 | + $attribute_set_section_id = $wpdb->get_var($query); |
|
| 2246 | + |
|
| 2247 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 2248 | + $attributes_set_details = $wpdb->get_results($query); |
|
| 2249 | + $set_details_id_postion_order = array(); |
|
| 2250 | + foreach ($attributes_set_details as $attribute_set_detail) { |
|
| 2251 | + $query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id); |
|
| 2252 | + $attribute_set_detail_code = $wpdb->get_var($query); |
|
| 2253 | + if ($attribute_set_detail_code == 'last_name') { |
|
| 2254 | + $set_details_id_postion_order[1] = $attribute_set_detail->attribute_id; |
|
| 2255 | + } |
|
| 2256 | + if ($attribute_set_detail_code == 'first_name') { |
|
| 2257 | + $set_details_id_postion_order[2] = $attribute_set_detail->attribute_id; |
|
| 2258 | + } |
|
| 2259 | + if ($attribute_set_detail_code == 'user_email') { |
|
| 2260 | + $set_details_id_postion_order[3] = $attribute_set_detail->attribute_id; |
|
| 2261 | + } |
|
| 2262 | + if ($attribute_set_detail_code == 'user_pass') { |
|
| 2263 | + $set_details_id_postion_order[4] = $attribute_set_detail->attribute_id; |
|
| 2264 | + } |
|
| 2265 | + } |
|
| 2266 | + $max_position = count($set_details_id_postion_order); |
|
| 2267 | + |
|
| 2268 | + if (!isset($company_section_detail_id)) { |
|
| 2269 | + $max_position = $max_position + 1; |
|
| 2270 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position)); |
|
| 2271 | + $set_details_id_postion_order[$max_position] = $company_id; |
|
| 2272 | + $company_section_detail_id = $wpdb->insert_id; |
|
| 2273 | + } |
|
| 2274 | + |
|
| 2275 | + if (!isset($is_provider_section_detail_id)) { |
|
| 2276 | + $max_position = $max_position + 1; |
|
| 2277 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position)); |
|
| 2278 | + $set_details_id_postion_order[$max_position] = $is_provider_id; |
|
| 2279 | + $is_provider_section_detail_id = $wpdb->insert_id; |
|
| 2280 | + } |
|
| 2281 | + |
|
| 2282 | + foreach ($set_details_id_postion_order as $pos => $attr_id) { |
|
| 2283 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d')); |
|
| 2284 | + } |
|
| 2285 | + } |
|
| 2286 | + |
|
| 2287 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s')); |
|
| 2288 | + |
|
| 2289 | + return true; |
|
| 2290 | + break; |
|
| 2291 | + |
|
| 2292 | + case 66: |
|
| 2293 | + $price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2294 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2295 | + 'is_visible_in_front' => 'no', |
|
| 2296 | + 'is_visible_in_front_listing' => 'yes', |
|
| 2297 | + 'is_global' => 'no', |
|
| 2298 | + 'is_user_defined' => 'no', |
|
| 2299 | + 'is_required' => 'no', |
|
| 2300 | + 'is_visible_in_advanced_search' => 'no', |
|
| 2301 | + 'is_searchable' => 'no', |
|
| 2302 | + 'is_filterable' => 'no', |
|
| 2303 | + 'is_comparable' => 'no', |
|
| 2304 | + 'is_html_allowed_on_front' => 'no', |
|
| 2305 | + 'is_unique' => 'no', |
|
| 2306 | + 'is_filterable_in_search' => 'no', |
|
| 2307 | + 'is_used_for_sort_by' => 'no', |
|
| 2308 | + 'is_configurable' => 'no', |
|
| 2309 | + 'is_requiring_unit' => 'no', |
|
| 2310 | + 'is_recordable_in_cart_meta' => 'no', |
|
| 2311 | + 'is_used_in_admin_listing_column' => 'no', |
|
| 2312 | + 'is_used_in_quick_add_form' => 'no', |
|
| 2313 | + 'is_used_for_variation' => 'no', |
|
| 2314 | + 'is_used_in_variation' => 'yes', |
|
| 2315 | + '_display_informations_about_value' => 'no', |
|
| 2316 | + '_need_verification' => 'no', |
|
| 2317 | + '_unit_group_id' => null, |
|
| 2318 | + '_default_unit' => null, |
|
| 2319 | + 'is_historisable' => 'yes', |
|
| 2320 | + 'is_intrinsic' => 'no', |
|
| 2321 | + 'data_type_to_use' => 'custom', |
|
| 2322 | + 'use_ajax_for_filling_field' => 'no', |
|
| 2323 | + 'data_type' => 'integer', |
|
| 2324 | + 'backend_table' => null, |
|
| 2325 | + 'backend_label' => null, |
|
| 2326 | + 'backend_input' => 'select', |
|
| 2327 | + 'frontend_label' => 'price_behaviour', |
|
| 2328 | + 'frontend_input' => 'select', |
|
| 2329 | + 'frontend_verification' => null, |
|
| 2330 | + 'code' => 'price_behaviour', |
|
| 2331 | + 'note' => '', |
|
| 2332 | + 'default_value' => '', |
|
| 2333 | + 'frontend_css_class' => 'price_behaviour', |
|
| 2334 | + 'backend_css_class' => null, |
|
| 2335 | + 'frontend_help_message' => null, |
|
| 2336 | + 'entity_id' => $price_behaviour_entity_id, |
|
| 2337 | + )); |
|
| 2338 | + $price_behaviour = $wpdb->insert_id; |
|
| 2339 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2340 | + 'status' => 'valid', |
|
| 2341 | + 'attribute_id' => $price_behaviour, |
|
| 2342 | + 'creation_date' => current_time('mysql'), |
|
| 2343 | + 'value' => '+', |
|
| 2344 | + 'label' => '+', |
|
| 2345 | + )); |
|
| 2346 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2347 | + 'status' => 'valid', |
|
| 2348 | + 'attribute_id' => $price_behaviour, |
|
| 2349 | + 'creation_date' => current_time('mysql'), |
|
| 2350 | + 'value' => '=', |
|
| 2351 | + 'label' => '=', |
|
| 2352 | + )); |
|
| 2353 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default'); |
|
| 2354 | + $price_behaviour_section_id = $wpdb->get_var($query); |
|
| 2355 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices'); |
|
| 2356 | + $price_behaviour_section_detail_id = $wpdb->get_var($query); |
|
| 2357 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array( |
|
| 2358 | + 'status' => 'deleted', |
|
| 2359 | + 'creation_date' => current_time('mysql', 0), |
|
| 2360 | + 'entity_type_id' => $price_behaviour_entity_id, |
|
| 2361 | + 'attribute_set_id' => $price_behaviour_section_id, |
|
| 2362 | + 'attribute_group_id' => $price_behaviour_section_detail_id, |
|
| 2363 | + 'attribute_id' => $price_behaviour, |
|
| 2364 | + 'position' => 0, |
|
| 2365 | + )); |
|
| 2366 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_')); |
|
| 2367 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva')); |
|
| 2368 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht')); |
|
| 2369 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock')); |
|
| 2370 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight')); |
|
| 2371 | + return true; |
|
| 2372 | + break; |
|
| 2373 | + |
|
| 2374 | + /* Always add specific case before this bloc */ |
|
| 2375 | + case 'dev': |
|
| 2376 | + |
|
| 2377 | + //wp_cache_flush(); |
|
| 2378 | + // Newsletters options |
|
| 2379 | + //$wp_rewrite->flush_rules(); |
|
| 2380 | + return true; |
|
| 2381 | + break; |
|
| 2382 | + |
|
| 2383 | + default: |
|
| 2384 | + return true; |
|
| 2385 | + break; |
|
| 2386 | + } |
|
| 2387 | + } |
|
| 2388 | + |
|
| 2389 | + /** |
|
| 2390 | + * Method called when deactivating the plugin |
|
| 2391 | + * @see register_deactivation_hook() |
|
| 2392 | + */ |
|
| 2393 | + public function uninstall_wpshop() |
|
| 2394 | + { |
|
| 2395 | + global $wpdb; |
|
| 2396 | + |
|
| 2397 | + if (WPSHOP_DEBUG_MODE_ALLOW_DATA_DELETION && in_array(long2ip(ip2long($_SERVER['REMOTE_ADDR'])), unserialize(WPSHOP_DEBUG_MODE_ALLOWED_IP))) { |
|
| 2398 | + $query = $wpdb->query("DROP TABLE `wp_wpshop__attribute`, `wp_wpshop__attributes_unit`, `wp_wpshop__attributes_unit_groups`, `wp_wpshop__attribute_set`, `wp_wpshop__attribute_set_section`, `wp_wpshop__attribute_set_section_details`, `wp_wpshop__attribute_value_datetime`, `wp_wpshop__attribute_value_decimal`, `wp_wpshop__attribute_value_integer`, `wp_wpshop__attribute_value_text`, `wp_wpshop__attribute_value_varchar`, `wp_wpshop__attribute_value__histo`, `wp_wpshop__cart`, `wp_wpshop__cart_contents`, `wp_wpshop__documentation`, `wp_wpshop__entity`, `wp_wpshop__historique`, `wp_wpshop__message`, `wp_wpshop__attribute_value_options`;"); |
|
| 2399 | + $query = $wpdb->query("DELETE FROM " . $wpdb->options . " WHERE `option_name` LIKE '%wpshop%';"); |
|
| 2400 | + |
|
| 2401 | + $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE 'wpshop_%';"); |
|
| 2402 | + $list = ' '; |
|
| 2403 | + foreach ($wpshop_products_posts as $post) { |
|
| 2404 | + $list .= "'" . $post->ID . "', "; |
|
| 2405 | + } |
|
| 2406 | + $list = substr($list, 0, -2); |
|
| 2407 | + |
|
| 2408 | + $wpshop_products_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_parent IN (" . $list . ");"); |
|
| 2409 | + $list_attachment = ' '; |
|
| 2410 | + foreach ($wpshop_products_posts as $post) { |
|
| 2411 | + $list_attachment .= "'" . $post->ID . "', "; |
|
| 2412 | + } |
|
| 2413 | + $list_attachment = substr($list_attachment, 0, -2); |
|
| 2414 | + |
|
| 2415 | + $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list . ");"); |
|
| 2416 | + $query = $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE post_id IN (" . $list_attachment . ");"); |
|
| 2417 | + $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list . ");"); |
|
| 2418 | + $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . $list_attachment . ");"); |
|
| 2419 | + $query = $wpdb->query("DELETE FROM " . $wpdb->posts . " WHERE post_content LIKE '%wpshop%';"); |
|
| 2420 | + } |
|
| 2421 | + |
|
| 2422 | + /* Unset administrator permission */ |
|
| 2423 | + $adminRole = get_role('administrator'); |
|
| 2424 | + foreach ($adminRole->capabilities as $capabilityName => $capability) { |
|
| 2425 | + if (substr($capabilityName, 0, 7) == 'wpshop_') { |
|
| 2426 | + if ($adminRole->has_cap($capabilityName)) { |
|
| 2427 | + $adminRole->remove_cap($capabilityName); |
|
| 2428 | + } |
|
| 2429 | + } |
|
| 2430 | + } |
|
| 2431 | + } |
|
| 2432 | 2432 | |
| 2433 | 2433 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_media_manager_backend_ctr { |
| 3 | 3 | /** Define the main directory containing the template for the current plugin |
| 4 | 4 | * @var string |
@@ -9,14 +9,14 @@ discard block |
||
| 9 | 9 | $this->template_dir = WPS_MEDIA_MANAGER_PATH . WPS_MEDIA_MANAGER_DIR . "/templates/"; |
| 10 | 10 | |
| 11 | 11 | // Add action to create custom type and custom taxonomy |
| 12 | - add_action( 'add_meta_boxes', array($this, 'add_meta_box') ); |
|
| 13 | - add_action( 'save_post', array($this, 'save_post_actions') ); |
|
| 12 | + add_action('add_meta_boxes', array($this, 'add_meta_box')); |
|
| 13 | + add_action('save_post', array($this, 'save_post_actions')); |
|
| 14 | 14 | |
| 15 | 15 | // Add Scripts |
| 16 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_backend' ) ); |
|
| 16 | + add_action('admin_enqueue_scripts', array($this, 'add_scripts_backend')); |
|
| 17 | 17 | |
| 18 | 18 | // Ajax Actions |
| 19 | - add_action( 'wp_ajax_display_pictures_in_backend', array( $this, 'wp_ajax_display_pictures_in_backend' ) ); |
|
| 19 | + add_action('wp_ajax_display_pictures_in_backend', array($this, 'wp_ajax_display_pictures_in_backend')); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,16 +24,16 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function add_scripts_backend() { |
| 26 | 26 | global $current_screen; |
| 27 | - if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ), true ) ) |
|
| 27 | + if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), true)) |
|
| 28 | 28 | return; |
| 29 | 29 | |
| 30 | - wp_enqueue_script( 'jquery'); |
|
| 31 | - wp_enqueue_script( 'jquery-ui'); |
|
| 32 | - wp_enqueue_script( 'jquery-ui-sortable'); |
|
| 33 | - wp_enqueue_script( 'wps_media_manager_backend', WPS_MEDIA_MANAGER_URL . WPS_MEDIA_MANAGER_DIR .'/assets/js/wps_media_manager_backend.js'); |
|
| 30 | + wp_enqueue_script('jquery'); |
|
| 31 | + wp_enqueue_script('jquery-ui'); |
|
| 32 | + wp_enqueue_script('jquery-ui-sortable'); |
|
| 33 | + wp_enqueue_script('wps_media_manager_backend', WPS_MEDIA_MANAGER_URL . WPS_MEDIA_MANAGER_DIR . '/assets/js/wps_media_manager_backend.js'); |
|
| 34 | 34 | |
| 35 | - wp_register_style( 'wps_media_manager_css_backend', WPS_MEDIA_MANAGER_URL . WPS_MEDIA_MANAGER_DIR .'/assets/css/wps_media_manager_backend.css' ); |
|
| 36 | - wp_enqueue_style( 'wps_media_manager_css_backend' ); |
|
| 35 | + wp_register_style('wps_media_manager_css_backend', WPS_MEDIA_MANAGER_URL . WPS_MEDIA_MANAGER_DIR . '/assets/css/wps_media_manager_backend.css'); |
|
| 36 | + wp_enqueue_style('wps_media_manager_css_backend'); |
|
| 37 | 37 | |
| 38 | 38 | } |
| 39 | 39 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Display meta Box in Project Custom Type |
| 42 | 42 | */ |
| 43 | 43 | function add_meta_box() { |
| 44 | - add_meta_box('wps_media_manager', __('Media Manager', 'wpshop' ),array( $this, 'meta_box' ), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal','low'); |
|
| 44 | + add_meta_box('wps_media_manager', __('Media Manager', 'wpshop'), array($this, 'meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -50,51 +50,51 @@ discard block |
||
| 50 | 50 | function meta_box() { |
| 51 | 51 | global $post; |
| 52 | 52 | $media = ''; |
| 53 | - $media_id_data = get_post_meta( $post->ID, '_wps_product_media', true ); |
|
| 54 | - if( !empty($media_id_data) ) { |
|
| 55 | - $media_id = explode( ',', $media_id_data ); |
|
| 53 | + $media_id_data = get_post_meta($post->ID, '_wps_product_media', true); |
|
| 54 | + if (!empty($media_id_data)) { |
|
| 55 | + $media_id = explode(',', $media_id_data); |
|
| 56 | 56 | ob_start(); |
| 57 | - require_once( wpshop_tools::get_template_part( WPS_MEDIA_MANAGER_DIR, $this->template_dir, "backend", "media_list") ); |
|
| 57 | + require_once(wpshop_tools::get_template_part(WPS_MEDIA_MANAGER_DIR, $this->template_dir, "backend", "media_list")); |
|
| 58 | 58 | $media = ob_get_contents(); |
| 59 | 59 | ob_end_clean(); |
| 60 | 60 | } |
| 61 | - require_once( wpshop_tools::get_template_part( WPS_MEDIA_MANAGER_DIR, $this->template_dir, "backend", "meta_box") ); |
|
| 61 | + require_once(wpshop_tools::get_template_part(WPS_MEDIA_MANAGER_DIR, $this->template_dir, "backend", "meta_box")); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * AJAX - Display pictures in backend panel |
| 66 | 66 | */ |
| 67 | 67 | function wp_ajax_display_pictures_in_backend() { |
| 68 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 68 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 69 | 69 | |
| 70 | - if ( !wp_verify_nonce( $_wpnonce, 'wp_ajax_display_pictures_in_backend' ) ) |
|
| 70 | + if (!wp_verify_nonce($_wpnonce, 'wp_ajax_display_pictures_in_backend')) |
|
| 71 | 71 | wp_die(); |
| 72 | 72 | |
| 73 | 73 | $status = true; $response = ''; |
| 74 | 74 | $media_indicator = !empty($_POST['media_id']) ? (int)$_POST['media_id'] : null; |
| 75 | - if( !empty($media_indicator) ) { |
|
| 76 | - $media_id = explode( ',', $media_indicator ); |
|
| 77 | - if( !empty($media_id) ) { |
|
| 75 | + if (!empty($media_indicator)) { |
|
| 76 | + $media_id = explode(',', $media_indicator); |
|
| 77 | + if (!empty($media_id)) { |
|
| 78 | 78 | ob_start(); |
| 79 | - require( wpshop_tools::get_template_part( WPS_MEDIA_MANAGER_DIR, $this->template_dir, "backend", "media_list") ); |
|
| 79 | + require(wpshop_tools::get_template_part(WPS_MEDIA_MANAGER_DIR, $this->template_dir, "backend", "media_list")); |
|
| 80 | 80 | $response = ob_get_contents(); |
| 81 | 81 | ob_end_clean(); |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 84 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 85 | 85 | wp_die(); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // @TODO: NONCE et vérifier product_media |
| 89 | 89 | function save_post_actions() { |
| 90 | - $post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : ''; |
|
| 91 | - $product_media_form = !empty( $_POST['product_media_form'] ) ? sanitize_text_field( $_POST['product_media_form'] ) : ''; |
|
| 92 | - $action = !empty( $_POST['action'] ) ? sanitize_text_field( $_POST['action'] ) : ''; |
|
| 93 | - $product_media = !empty( $_POST['product_media'] ) ? sanitize_text_field( $_POST['product_media'] ) : ''; |
|
| 94 | - $post_ID = !empty( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; |
|
| 95 | - |
|
| 96 | - if ( !empty($post_type) && !empty($product_media_form) && $product_media_form == 'post' && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT && !empty( $action ) && $action != 'autosave' ) { |
|
| 97 | - update_post_meta( $post_ID, '_wps_product_media', $product_media ); |
|
| 90 | + $post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : ''; |
|
| 91 | + $product_media_form = !empty($_POST['product_media_form']) ? sanitize_text_field($_POST['product_media_form']) : ''; |
|
| 92 | + $action = !empty($_POST['action']) ? sanitize_text_field($_POST['action']) : ''; |
|
| 93 | + $product_media = !empty($_POST['product_media']) ? sanitize_text_field($_POST['product_media']) : ''; |
|
| 94 | + $post_ID = !empty($_POST['post_ID']) ? (int)$_POST['post_ID'] : 0; |
|
| 95 | + |
|
| 96 | + if (!empty($post_type) && !empty($product_media_form) && $product_media_form == 'post' && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT && !empty($action) && $action != 'autosave') { |
|
| 97 | + update_post_meta($post_ID, '_wps_product_media', $product_media); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_media_manager_backend_ctr { |
| 3 | 5 | /** Define the main directory containing the template for the current plugin |
| 4 | 6 | * @var string |
@@ -24,8 +26,9 @@ discard block |
||
| 24 | 26 | */ |
| 25 | 27 | function add_scripts_backend() { |
| 26 | 28 | global $current_screen; |
| 27 | - if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ), true ) ) |
|
| 28 | - return; |
|
| 29 | + if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ), true ) ) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 29 | 32 | |
| 30 | 33 | wp_enqueue_script( 'jquery'); |
| 31 | 34 | wp_enqueue_script( 'jquery-ui'); |
@@ -67,8 +70,9 @@ discard block |
||
| 67 | 70 | function wp_ajax_display_pictures_in_backend() { |
| 68 | 71 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 69 | 72 | |
| 70 | - if ( !wp_verify_nonce( $_wpnonce, 'wp_ajax_display_pictures_in_backend' ) ) |
|
| 71 | - wp_die(); |
|
| 73 | + if ( !wp_verify_nonce( $_wpnonce, 'wp_ajax_display_pictures_in_backend' ) ) { |
|
| 74 | + wp_die(); |
|
| 75 | + } |
|
| 72 | 76 | |
| 73 | 77 | $status = true; $response = ''; |
| 74 | 78 | $media_indicator = !empty($_POST['media_id']) ? (int)$_POST['media_id'] : null; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * WPShop Payment Mode bootstrap file |
| 4 | 4 | * @author Jérôme ALLEGRE - Eoxia dev team <[email protected]> |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( !class_exists("wps_payment_mode") ) { |
|
| 11 | +if (!class_exists("wps_payment_mode")) { |
|
| 12 | 12 | |
| 13 | 13 | /** Template Global vars **/ |
| 14 | 14 | DEFINE('WPS_PAYMENT_MODE_DIR', basename(dirname(__FILE__))); |
| 15 | - DEFINE('WPS_PAYMENT_MODE_PATH', str_replace( "\\", "/", str_replace( WPS_PAYMENT_MODE_DIR, "", dirname( __FILE__ ) ) ) ); |
|
| 16 | - DEFINE('WPS_PAYMENT_MODE_URL', str_replace( str_replace( "\\", "/", ABSPATH), site_url() . '/', WPS_PAYMENT_MODE_PATH ) ); |
|
| 15 | + DEFINE('WPS_PAYMENT_MODE_PATH', str_replace("\\", "/", str_replace(WPS_PAYMENT_MODE_DIR, "", dirname(__FILE__)))); |
|
| 16 | + DEFINE('WPS_PAYMENT_MODE_URL', str_replace(str_replace("\\", "/", ABSPATH), site_url() . '/', WPS_PAYMENT_MODE_PATH)); |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | class wps_payment_mode { |
@@ -32,55 +32,55 @@ discard block |
||
| 32 | 32 | $this->template_dir = WPS_PAYMENT_MODE_PATH . WPS_PAYMENT_MODE_DIR . "/templates/"; |
| 33 | 33 | |
| 34 | 34 | /** Checking Payment Mode Option **/ |
| 35 | - $payment_option = get_option( 'wps_payment_mode' ); |
|
| 36 | - if ( empty($payment_option) ) { |
|
| 35 | + $payment_option = get_option('wps_payment_mode'); |
|
| 36 | + if (empty($payment_option)) { |
|
| 37 | 37 | self::migrate_payment_modes(); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** Check if SystemPay is registred in Payment Main Option **/ |
| 41 | - $payment_option = get_option( 'wps_payment_mode' ); |
|
| 42 | - if ( !empty($payment_option) && !empty($payment_option['mode']) && !array_key_exists('checks', $payment_option['mode']) ) { |
|
| 41 | + $payment_option = get_option('wps_payment_mode'); |
|
| 42 | + if (!empty($payment_option) && !empty($payment_option['mode']) && !array_key_exists('checks', $payment_option['mode'])) { |
|
| 43 | 43 | $payment_option['mode']['checks']['name'] = __('Checks', 'wpshop'); |
| 44 | - $payment_option['mode']['checks']['logo'] = WPSHOP_TEMPLATES_URL.'wpshop/medias/cheque.png'; |
|
| 44 | + $payment_option['mode']['checks']['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/cheque.png'; |
|
| 45 | 45 | $payment_option['mode']['checks']['description'] = __('Reservation of products upon receipt of the check.', 'wpshop'); |
| 46 | - update_option( 'wps_payment_mode', $payment_option ); |
|
| 46 | + update_option('wps_payment_mode', $payment_option); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ( !empty($payment_option) && !empty($payment_option['mode']) && !array_key_exists('banktransfer', $payment_option['mode']) ) { |
|
| 49 | + if (!empty($payment_option) && !empty($payment_option['mode']) && !array_key_exists('banktransfer', $payment_option['mode'])) { |
|
| 50 | 50 | $payment_modes['mode']['banktransfer']['name'] = __('Banktransfer', 'wpshop'); |
| 51 | - $payment_modes['mode']['banktransfer']['logo'] = WPSHOP_TEMPLATES_URL.'wpshop/medias/cheque.png'; |
|
| 51 | + $payment_modes['mode']['banktransfer']['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/cheque.png'; |
|
| 52 | 52 | $payment_modes['mode']['banktransfer']['description'] = __('Reservation of products upon confirmation of payment.', 'wpshop'); |
| 53 | - update_option( 'wps_payment_mode', $payment_option ); |
|
| 53 | + update_option('wps_payment_mode', $payment_option); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_script') ); |
|
| 57 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts') ); |
|
| 56 | + add_action('wp_enqueue_scripts', array($this, 'add_script')); |
|
| 57 | + add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts')); |
|
| 58 | 58 | |
| 59 | 59 | /** Create Options **/ |
| 60 | - add_action('wsphop_options', array(&$this, 'create_options') ); |
|
| 60 | + add_action('wsphop_options', array(&$this, 'create_options')); |
|
| 61 | 61 | |
| 62 | - add_filter( 'wps_payment_mode_interface_checks', array( &$this, 'display_interface_check') ); |
|
| 63 | - add_filter( 'wps_payment_mode_interface_banktransfer', array( &$this, 'display_admin_interface_banktransfer') ); |
|
| 64 | - add_filter( 'wps_payment_mode_interface_cic', array( 'wpshop_CIC', 'display_admin_part') ); |
|
| 62 | + add_filter('wps_payment_mode_interface_checks', array(&$this, 'display_interface_check')); |
|
| 63 | + add_filter('wps_payment_mode_interface_banktransfer', array(&$this, 'display_admin_interface_banktransfer')); |
|
| 64 | + add_filter('wps_payment_mode_interface_cic', array('wpshop_CIC', 'display_admin_part')); |
|
| 65 | 65 | |
| 66 | - add_shortcode( 'wps_payment', array( &$this, 'display_payment_modes' )); |
|
| 66 | + add_shortcode('wps_payment', array(&$this, 'display_payment_modes')); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | function add_script() { |
| 71 | - wp_enqueue_script( 'jquery'); |
|
| 72 | - wp_enqueue_script( 'wps_payment_mode', plugins_url('assets/frontend/js/wps_payment_mode.js', __FILE__) ); |
|
| 71 | + wp_enqueue_script('jquery'); |
|
| 72 | + wp_enqueue_script('wps_payment_mode', plugins_url('assets/frontend/js/wps_payment_mode.js', __FILE__)); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | function add_admin_scripts($hook) { |
| 76 | - if( $hook != 'settings_page_wpshop_option' ) |
|
| 76 | + if ($hook != 'settings_page_wpshop_option') |
|
| 77 | 77 | return; |
| 78 | 78 | |
| 79 | 79 | add_thickbox(); |
| 80 | - wp_enqueue_script( 'jquery'); |
|
| 80 | + wp_enqueue_script('jquery'); |
|
| 81 | 81 | wp_enqueue_script('jquery-ui'); |
| 82 | 82 | wp_enqueue_script('jquery-ui-sortable'); |
| 83 | - wp_enqueue_script( 'wps_payment_mode_js', plugins_url('assets/backend/js/wps_payment_mode.js', __FILE__) ); |
|
| 83 | + wp_enqueue_script('wps_payment_mode_js', plugins_url('assets/backend/js/wps_payment_mode.js', __FILE__)); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -98,25 +98,25 @@ discard block |
||
| 98 | 98 | * @param array $input |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - function wps_validate_payment_option( $input ) { |
|
| 102 | - if( is_array($input) ) { |
|
| 103 | - foreach( $input['mode'] as $mode_key => $mode_config ) { |
|
| 104 | - if ( !empty($_FILES[$mode_key.'_logo']['name']) && empty($_FILES[$mode_key.'_logo']['error']) ) { |
|
| 105 | - $filename = $_FILES[$mode_key.'_logo']; |
|
| 106 | - $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 107 | - $wp_filetype = wp_check_filetype(basename($filename['name']), null ); |
|
| 101 | + function wps_validate_payment_option($input) { |
|
| 102 | + if (is_array($input)) { |
|
| 103 | + foreach ($input['mode'] as $mode_key => $mode_config) { |
|
| 104 | + if (!empty($_FILES[$mode_key . '_logo']['name']) && empty($_FILES[$mode_key . '_logo']['error'])) { |
|
| 105 | + $filename = $_FILES[$mode_key . '_logo']; |
|
| 106 | + $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 107 | + $wp_filetype = wp_check_filetype(basename($filename['name']), null); |
|
| 108 | 108 | $wp_upload_dir = wp_upload_dir(); |
| 109 | 109 | $attachment = array( |
| 110 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename['name'] ), |
|
| 110 | + 'guid' => $wp_upload_dir['url'] . '/' . basename($filename['name']), |
|
| 111 | 111 | 'post_mime_type' => $wp_filetype['type'], |
| 112 | 112 | 'post_title' => preg_replace(' /\.[^.]+$/', '', basename($filename['name'])), |
| 113 | 113 | 'post_content' => '', |
| 114 | 114 | 'post_status' => 'inherit' |
| 115 | 115 | ); |
| 116 | - $attach_id = wp_insert_attachment( $attachment, $upload['file']); |
|
| 116 | + $attach_id = wp_insert_attachment($attachment, $upload['file']); |
|
| 117 | 117 | require_once(ABSPATH . 'wp-admin/includes/image.php'); |
| 118 | - $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); |
|
| 119 | - wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 118 | + $attach_data = wp_generate_attachment_metadata($attach_id, $upload['file']); |
|
| 119 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 120 | 120 | |
| 121 | 121 | $input['mode'][$mode_key]['logo'] = $attach_id; |
| 122 | 122 | } |
@@ -130,68 +130,68 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | function display_payment_modes_in_admin() { |
| 132 | 132 | $output = ''; |
| 133 | - $payment_option = get_option( 'wps_payment_mode' ); |
|
| 133 | + $payment_option = get_option('wps_payment_mode'); |
|
| 134 | 134 | |
| 135 | - require_once( wpshop_tools::get_template_part( WPS_PAYMENT_MODE_DIR, $this->template_dir, "backend", "payment-modes") ); |
|
| 135 | + require_once(wpshop_tools::get_template_part(WPS_PAYMENT_MODE_DIR, $this->template_dir, "backend", "payment-modes")); |
|
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | |
| 140 | 140 | public static function migrate_payment_modes() { |
| 141 | 141 | $payment_modes = array(); |
| 142 | - $payment_option = get_option( 'wpshop_paymentMethod' ); |
|
| 142 | + $payment_option = get_option('wpshop_paymentMethod'); |
|
| 143 | 143 | $methods = array(); |
| 144 | - $methods['display_position']['paypal'] = ( !empty($payment_option) && !empty($payment_option['paypal']) ) ? 'on' : ''; |
|
| 145 | - $methods['display_position']['checks'] = ( !empty($payment_option) && !empty($payment_option['checks']) ) ? 'on' : ''; |
|
| 146 | - $methods['display_position']['banktransfer'] = ( !empty($payment_option) && !empty($payment_option['banktransfer']) ) ? 'on' : ''; |
|
| 147 | - $methods['default_method'] = ( !empty($payment_option['default_method']) ) ? $payment_option['default_method'] : 'checks'; |
|
| 148 | - |
|
| 149 | - if ( !empty($payment_option['display_position']) ) { |
|
| 150 | - $methods['display_position'] = array_merge( $methods['display_position'], $payment_option['display_position'] ); |
|
| 151 | - foreach( $methods['display_position'] as $k => $v ) { |
|
| 152 | - if ( !empty($payment_option[$k]) ) { |
|
| 144 | + $methods['display_position']['paypal'] = (!empty($payment_option) && !empty($payment_option['paypal'])) ? 'on' : ''; |
|
| 145 | + $methods['display_position']['checks'] = (!empty($payment_option) && !empty($payment_option['checks'])) ? 'on' : ''; |
|
| 146 | + $methods['display_position']['banktransfer'] = (!empty($payment_option) && !empty($payment_option['banktransfer'])) ? 'on' : ''; |
|
| 147 | + $methods['default_method'] = (!empty($payment_option['default_method'])) ? $payment_option['default_method'] : 'checks'; |
|
| 148 | + |
|
| 149 | + if (!empty($payment_option['display_position'])) { |
|
| 150 | + $methods['display_position'] = array_merge($methods['display_position'], $payment_option['display_position']); |
|
| 151 | + foreach ($methods['display_position'] as $k => $v) { |
|
| 152 | + if (!empty($payment_option[$k])) { |
|
| 153 | 153 | $methods['display_position'][$k] = $payment_option[$k]; |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( !empty($methods) && !empty($methods['display_position']) ) { |
|
| 159 | - foreach( $methods['display_position'] as $key => $value ) { |
|
| 160 | - $payment_modes['mode'][$key]['active'] = ( !empty($methods['display_position'][ $key ]) && $methods['display_position'][ $key ] == 'on' ) ? $methods['display_position'][ $key ] : ''; |
|
| 161 | - switch( $key ) { |
|
| 158 | + if (!empty($methods) && !empty($methods['display_position'])) { |
|
| 159 | + foreach ($methods['display_position'] as $key => $value) { |
|
| 160 | + $payment_modes['mode'][$key]['active'] = (!empty($methods['display_position'][$key]) && $methods['display_position'][$key] == 'on') ? $methods['display_position'][$key] : ''; |
|
| 161 | + switch ($key) { |
|
| 162 | 162 | case 'paypal' : |
| 163 | 163 | $payment_modes['mode'][$key]['name'] = __('Paypal', 'wpshop'); |
| 164 | - $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL.'wpshop/medias/paypal.png'; |
|
| 164 | + $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/paypal.png'; |
|
| 165 | 165 | $payment_modes['mode'][$key]['description'] = __('Tips : If you have a Paypal account, by choosing this payment method, you will be redirected to the secure payment site Paypal to make your payment. Debit your PayPal account, immediate booking products.', 'wpshop'); |
| 166 | 166 | break; |
| 167 | 167 | case 'banktransfer' : |
| 168 | 168 | $payment_modes['mode'][$key]['name'] = __('Banktransfer', 'wpshop'); |
| 169 | - $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL.'wpshop/medias/cheque.png'; |
|
| 169 | + $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/cheque.png'; |
|
| 170 | 170 | $payment_modes['mode'][$key]['description'] = __('Reservation of products upon confirmation of payment.', 'wpshop'); |
| 171 | 171 | break; |
| 172 | 172 | case 'checks' : |
| 173 | 173 | $payment_modes['mode'][$key]['name'] = __('Checks', 'wpshop'); |
| 174 | - $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL.'wpshop/medias/cheque.png'; |
|
| 174 | + $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/cheque.png'; |
|
| 175 | 175 | $payment_modes['mode'][$key]['description'] = __('Reservation of products upon receipt of the check.', 'wpshop'); |
| 176 | 176 | $payment_modes['mode'][$key]['active'] = 'on'; |
| 177 | 177 | break; |
| 178 | 178 | case 'systempay' : |
| 179 | 179 | $payment_modes['mode'][$key]['name'] = __('Systempay', 'wpshop'); |
| 180 | - $payment_modes['mode'][$key]['logo'] = plugins_url().'/wpshop_systemPay/img/systemPay.png'; |
|
| 180 | + $payment_modes['mode'][$key]['logo'] = plugins_url() . '/wpshop_systemPay/img/systemPay.png'; |
|
| 181 | 181 | $payment_modes['mode'][$key]['description'] = __('SystemPay - Banque Populaire', 'wpshop_systemPay'); |
| 182 | 182 | break; |
| 183 | 183 | case 'cic' : |
| 184 | 184 | $payment_modes['mode'][$key]['name'] = __('CIC', 'wpshop'); |
| 185 | - $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL.'wpshop/medias/cic_payment_logo.jpg'; |
|
| 185 | + $payment_modes['mode'][$key]['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/cic_payment_logo.jpg'; |
|
| 186 | 186 | $payment_modes['mode'][$key]['description'] = __('Reservation of products upon confirmation of payment.', 'wpshop'); |
| 187 | 187 | break; |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( $methods['default_method'] ) { |
|
| 191 | + if ($methods['default_method']) { |
|
| 192 | 192 | $payment_modes['default_choice'] = $methods['default_method']; |
| 193 | 193 | } |
| 194 | - update_option( 'wps_payment_mode', $payment_modes); |
|
| 194 | + update_option('wps_payment_mode', $payment_modes); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | } |
@@ -212,31 +212,31 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $wpshop_paymentMethod_options = get_option('wpshop_paymentMethod_options'); |
| 214 | 214 | $output = '<div class="wps-boxed">'; |
| 215 | - $output .= '<div class="wps-form-group"><label>'.__('Bank name', 'wpshop').'</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][bank_name]" type="text" value="'.(!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['bank_name'])?$wpshop_paymentMethod_options['banktransfer']['bank_name']:'').'" /></div></div>'; |
|
| 216 | - $output .= '<div class="wps-form-group"><label>'.__('IBAN', 'wpshop').'</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][iban]" type="text" value="'.(!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['iban'])?$wpshop_paymentMethod_options['banktransfer']['iban']:'').'" /></div></div>'; |
|
| 217 | - $output .= '<div class="wps-form-group"><label>'.__('BIC/SWIFT', 'wpshop').'</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][bic]" type="text" value="'.(!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['bic'])?$wpshop_paymentMethod_options['banktransfer']['bic']:'').'" /></div></div>'; |
|
| 218 | - $output .= '<div class="wps-form-group"><label>'.__('Account owner name', 'wpshop').'</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][accountowner]" type="text" value="'.(!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['accountowner'])?$wpshop_paymentMethod_options['banktransfer']['accountowner']:'').'" /></div></div>'; |
|
| 215 | + $output .= '<div class="wps-form-group"><label>' . __('Bank name', 'wpshop') . '</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][bank_name]" type="text" value="' . (!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['bank_name']) ? $wpshop_paymentMethod_options['banktransfer']['bank_name'] : '') . '" /></div></div>'; |
|
| 216 | + $output .= '<div class="wps-form-group"><label>' . __('IBAN', 'wpshop') . '</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][iban]" type="text" value="' . (!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['iban']) ? $wpshop_paymentMethod_options['banktransfer']['iban'] : '') . '" /></div></div>'; |
|
| 217 | + $output .= '<div class="wps-form-group"><label>' . __('BIC/SWIFT', 'wpshop') . '</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][bic]" type="text" value="' . (!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['bic']) ? $wpshop_paymentMethod_options['banktransfer']['bic'] : '') . '" /></div></div>'; |
|
| 218 | + $output .= '<div class="wps-form-group"><label>' . __('Account owner name', 'wpshop') . '</label><div class="wps-form"><input name="wpshop_paymentMethod_options[banktransfer][accountowner]" type="text" value="' . (!empty($wpshop_paymentMethod_options) && !empty($wpshop_paymentMethod_options['banktransfer']) && !empty($wpshop_paymentMethod_options['banktransfer']['accountowner']) ? $wpshop_paymentMethod_options['banktransfer']['accountowner'] : '') . '" /></div></div>'; |
|
| 219 | 219 | $output .= '</div>'; |
| 220 | 220 | return $output; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | function display_payment_modes() { |
| 224 | 224 | $output = ''; |
| 225 | - $payment_modes = get_option( 'wps_payment_mode' ); |
|
| 225 | + $payment_modes = get_option('wps_payment_mode'); |
|
| 226 | 226 | |
| 227 | - if ( !empty($payment_modes) && !empty($payment_modes['mode']) ) { |
|
| 228 | - $default_choice = ( !empty($payment_modes['default_choice']) ) ? $payment_modes['default_choice'] : ''; |
|
| 227 | + if (!empty($payment_modes) && !empty($payment_modes['mode'])) { |
|
| 228 | + $default_choice = (!empty($payment_modes['default_choice'])) ? $payment_modes['default_choice'] : ''; |
|
| 229 | 229 | $payment_modes = $payment_modes['mode']; |
| 230 | 230 | $tmp_array = array(); |
| 231 | - foreach( $payment_modes as $payment_mode_id => $payment_mode ) { |
|
| 232 | - if( !empty($payment_mode['active']) ) { |
|
| 233 | - $tmp_array[ $payment_mode_id ] = $payment_mode; |
|
| 231 | + foreach ($payment_modes as $payment_mode_id => $payment_mode) { |
|
| 232 | + if (!empty($payment_mode['active'])) { |
|
| 233 | + $tmp_array[$payment_mode_id] = $payment_mode; |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | - $payment_modes = apply_filters( 'wps-paymentmode-filter', $tmp_array ); |
|
| 236 | + $payment_modes = apply_filters('wps-paymentmode-filter', $tmp_array); |
|
| 237 | 237 | |
| 238 | 238 | ob_start(); |
| 239 | - require_once( wpshop_tools::get_template_part( WPS_PAYMENT_MODE_DIR, $this->template_dir, "frontend", "payment-modes") ); |
|
| 239 | + require_once(wpshop_tools::get_template_part(WPS_PAYMENT_MODE_DIR, $this->template_dir, "frontend", "payment-modes")); |
|
| 240 | 240 | $output = ob_get_contents(); |
| 241 | 241 | ob_end_clean(); |
| 242 | 242 | } |
@@ -249,6 +249,6 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** Instanciate the module utilities if not */ |
| 252 | -if ( class_exists("wps_payment_mode") ) { |
|
| 252 | +if (class_exists("wps_payment_mode")) { |
|
| 253 | 253 | $wps_shipping_mode = new wps_payment_mode(); |
| 254 | 254 | } |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * WPShop Payment Mode bootstrap file |
| 4 | 6 | * @author Jérôme ALLEGRE - Eoxia dev team <[email protected]> |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | function add_admin_scripts($hook) { |
| 76 | - if( $hook != 'settings_page_wpshop_option' ) |
|
| 77 | - return; |
|
| 78 | + if( $hook != 'settings_page_wpshop_option' ) { |
|
| 79 | + return; |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | add_thickbox(); |
| 80 | 83 | wp_enqueue_script( 'jquery'); |
@@ -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'] ) ) { |
|
| 680 | + if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe'])) { |
|
| 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,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_cart { |
| 3 | 5 | |
| 4 | 6 | function __construct() { |
@@ -151,12 +153,10 @@ discard block |
||
| 151 | 153 | require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart") ); |
| 152 | 154 | $output = ob_get_contents(); |
| 153 | 155 | ob_end_clean(); |
| 154 | - } |
|
| 155 | - else { |
|
| 156 | + } else { |
|
| 156 | 157 | return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';; |
| 157 | 158 | } |
| 158 | - } |
|
| 159 | - else { |
|
| 159 | + } else { |
|
| 160 | 160 | return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';; |
| 161 | 161 | } |
| 162 | 162 | return $output; |
@@ -174,15 +174,13 @@ discard block |
||
| 174 | 174 | /** Count items **/ |
| 175 | 175 | $total_cart_item = self::total_cart_items( $cart_items ); |
| 176 | 176 | $mini_cart_body = self::mini_cart_content( $type ); |
| 177 | - } |
|
| 178 | - else { |
|
| 177 | + } else { |
|
| 179 | 178 | $mini_cart_body = __( 'Your cart is empty', 'wpshop' ); |
| 180 | 179 | } |
| 181 | 180 | ob_start(); |
| 182 | 181 | if( !empty($type) && $type == 'fixed' ) { |
| 183 | 182 | require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart") ); |
| 184 | - } |
|
| 185 | - else { |
|
| 183 | + } else { |
|
| 186 | 184 | require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart") ); |
| 187 | 185 | } |
| 188 | 186 | |
@@ -210,18 +208,15 @@ discard block |
||
| 210 | 208 | ob_start(); |
| 211 | 209 | if( !empty($type) && $type == 'fixed' ) { |
| 212 | 210 | require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content") ); |
| 213 | - } |
|
| 214 | - else { |
|
| 211 | + } else { |
|
| 215 | 212 | require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content") ); |
| 216 | 213 | } |
| 217 | 214 | $output = ob_get_contents(); |
| 218 | 215 | ob_end_clean(); |
| 219 | - } |
|
| 220 | - else { |
|
| 216 | + } else { |
|
| 221 | 217 | $output = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
| 222 | 218 | } |
| 223 | - } |
|
| 224 | - else { |
|
| 219 | + } else { |
|
| 225 | 220 | $output = '<div class="wps-alert-info">' . __( 'Your cart is empty', 'wpshop' ).'</div>'; |
| 226 | 221 | } |
| 227 | 222 | return $output; |
@@ -256,12 +251,10 @@ discard block |
||
| 256 | 251 | require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content") ); |
| 257 | 252 | $output = ob_get_contents(); |
| 258 | 253 | ob_end_clean(); |
| 259 | - } |
|
| 260 | - else { |
|
| 254 | + } else { |
|
| 261 | 255 | $resume_cart_body = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
| 262 | 256 | } |
| 263 | - } |
|
| 264 | - else { |
|
| 257 | + } else { |
|
| 265 | 258 | $resume_cart_body ='<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
| 266 | 259 | } |
| 267 | 260 | return $output; |
@@ -298,8 +291,9 @@ discard block |
||
| 298 | 291 | * @return array() |
| 299 | 292 | */ |
| 300 | 293 | function get_persistent_cart() { |
| 301 | - if(get_current_user_id()) |
|
| 302 | - $cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true); |
|
| 294 | + if(get_current_user_id()) { |
|
| 295 | + $cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true); |
|
| 296 | + } |
|
| 303 | 297 | return empty($cart) ? array() : $cart; |
| 304 | 298 | } |
| 305 | 299 | |
@@ -314,10 +308,11 @@ discard block |
||
| 314 | 308 | * Save the persistent cart when updated |
| 315 | 309 | */ |
| 316 | 310 | function persistent_cart_update() { |
| 317 | - if(get_current_user_id()) |
|
| 318 | - update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array( |
|
| 311 | + if(get_current_user_id()) { |
|
| 312 | + update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array( |
|
| 319 | 313 | 'cart' => $_SESSION['cart'], |
| 320 | 314 | )); |
| 315 | + } |
|
| 321 | 316 | } |
| 322 | 317 | |
| 323 | 318 | /** |
@@ -372,8 +367,7 @@ discard block |
||
| 372 | 367 | // Check Parent ID |
| 373 | 368 | if( get_post_type($cart['order_items'][ $product_id ]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) { |
| 374 | 369 | $parent_product_id = $cart['order_items'][ $product_id ]['item_id']; |
| 375 | - } |
|
| 376 | - else { |
|
| 370 | + } else { |
|
| 377 | 371 | $parent_data = wpshop_products::get_parent_variation( $cart['order_items'][ $product_id ]['item_id'] ); |
| 378 | 372 | $parent_post = $parent_data['parent_post']; |
| 379 | 373 | $parent_product_id = $parent_post->ID; |
@@ -388,8 +382,7 @@ discard block |
||
| 388 | 382 | } |
| 389 | 383 | } |
| 390 | 384 | } |
| 391 | - } |
|
| 392 | - else { |
|
| 385 | + } else { |
|
| 393 | 386 | $selected_variations = get_post_meta( $product_id, '_wpshop_variations_attribute_def', true ); |
| 394 | 387 | } |
| 395 | 388 | } |
@@ -399,8 +392,7 @@ discard block |
||
| 399 | 392 | $new_pid = $product_id; |
| 400 | 393 | $return = $this->add_to_cart( $product_to_add_to_cart, array( $new_pid => $quantity ), $wpshop_cart_type, array(), $from_admin, $cart, $order_id ); |
| 401 | 394 | return $return; |
| 402 | - } |
|
| 403 | - else { |
|
| 395 | + } else { |
|
| 404 | 396 | return __('This product does not exist in the cart.', 'wpshop'); |
| 405 | 397 | } |
| 406 | 398 | } |
@@ -416,8 +408,7 @@ discard block |
||
| 416 | 408 | if ( empty( $from_admin ) ){ |
| 417 | 409 | if(isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type'] ) { |
| 418 | 410 | return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop'); |
| 419 | - } |
|
| 420 | - else { |
|
| 411 | + } else { |
|
| 421 | 412 | $_SESSION['cart']['cart_type'] = $type; |
| 422 | 413 | } |
| 423 | 414 | $order_meta = $_SESSION['cart']; |
@@ -428,22 +419,27 @@ discard block |
||
| 428 | 419 | |
| 429 | 420 | foreach ($product_list as $pid => $product_more_content) { |
| 430 | 421 | if ( count($product_list) == 1 ) { |
| 431 | - if ( !isset( $quantity[$pid] ) ) $quantity[$pid] = 1; |
|
| 422 | + if ( !isset( $quantity[$pid] ) ) { |
|
| 423 | + $quantity[$pid] = 1; |
|
| 424 | + } |
|
| 432 | 425 | $product = wpshop_products::get_product_data($product_more_content['id'], false, '"publish", "free_product"'); |
| 433 | 426 | /** Check if the selected product exist */ |
| 434 | - if ( $product === false ) return __('This product does not exist', 'wpshop'); |
|
| 427 | + if ( $product === false ) { |
|
| 428 | + return __('This product does not exist', 'wpshop'); |
|
| 429 | + } |
|
| 435 | 430 | |
| 436 | 431 | /** Get information about the product price */ |
| 437 | 432 | $product_price_check = wpshop_prices::get_product_price($product, 'check_only'); |
| 438 | - if ( $product_price_check !== true ) return $product_price_check; |
|
| 433 | + if ( $product_price_check !== true ) { |
|
| 434 | + return $product_price_check; |
|
| 435 | + } |
|
| 439 | 436 | |
| 440 | 437 | $the_quantity = 1; |
| 441 | 438 | |
| 442 | 439 | 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 | 440 | /** Get the asked quantity for each product and check if there is enough stock */ |
| 444 | 441 | $the_quantity = $quantity[$pid]; |
| 445 | - } |
|
| 446 | - else { |
|
| 442 | + } else { |
|
| 447 | 443 | /** Get the asked quantity for each product and check if there is enough stock */ |
| 448 | 444 | $the_quantity = $quantity[$pid]; |
| 449 | 445 | } |
@@ -486,8 +482,7 @@ discard block |
||
| 486 | 482 | if ( get_current_user_id() ) { |
| 487 | 483 | $this->persistent_cart_update(); |
| 488 | 484 | } |
| 489 | - } |
|
| 490 | - else { |
|
| 485 | + } else { |
|
| 491 | 486 | update_post_meta($order_id, '_order_postmeta', $order ); |
| 492 | 487 | |
| 493 | 488 | } |
@@ -631,8 +626,7 @@ discard block |
||
| 631 | 626 | if( empty( $d['product_qty'] ) ) { |
| 632 | 627 | unset( $cart_items[$product_key] ); |
| 633 | 628 | unset( $cart_infos['order_items'][$product_key] ); |
| 634 | - } |
|
| 635 | - else { |
|
| 629 | + } else { |
|
| 636 | 630 | $wps_orders = new wps_orders_ctr(); |
| 637 | 631 | $cart_items[$product_key] = $wps_orders->add_product_to_order($the_product); |
| 638 | 632 | } |
@@ -651,8 +645,7 @@ discard block |
||
| 651 | 645 | if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) { |
| 652 | 646 | $cart_has_special_product = true; |
| 653 | 647 | $cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] ); |
| 654 | - } |
|
| 655 | - else { |
|
| 648 | + } else { |
|
| 656 | 649 | $cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc']; |
| 657 | 650 | } |
| 658 | 651 | |
@@ -661,13 +654,11 @@ discard block |
||
| 661 | 654 | // VAT |
| 662 | 655 | if( !empty($order_tva[ $item['item_tva_rate'] ]) ) { |
| 663 | 656 | $order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount']; |
| 664 | - } |
|
| 665 | - else { |
|
| 657 | + } else { |
|
| 666 | 658 | $order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount']; |
| 667 | 659 | } |
| 668 | 660 | } |
| 669 | - } |
|
| 670 | - else { |
|
| 661 | + } else { |
|
| 671 | 662 | return array(); |
| 672 | 663 | } |
| 673 | 664 | |
@@ -764,8 +755,7 @@ discard block |
||
| 764 | 755 | } |
| 765 | 756 | if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) { |
| 766 | 757 | $cart_infos['order_grand_total'] = 0; |
| 767 | - } |
|
| 768 | - else { |
|
| 758 | + } else { |
|
| 769 | 759 | $cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
| 770 | 760 | } |
| 771 | 761 | $cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
@@ -775,8 +765,7 @@ discard block |
||
| 775 | 765 | $wpshop_payment = new wpshop_payment(); |
| 776 | 766 | if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) { |
| 777 | 767 | $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' ); |
| 778 | - } |
|
| 779 | - else { |
|
| 768 | + } else { |
|
| 780 | 769 | $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] ); |
| 781 | 770 | } |
| 782 | 771 | if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) { |
@@ -844,8 +833,9 @@ discard block |
||
| 844 | 833 | public function wps_reload_mini_cart() { |
| 845 | 834 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 846 | 835 | |
| 847 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) |
|
| 848 | - wp_die(); |
|
| 836 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) { |
|
| 837 | + wp_die(); |
|
| 838 | + } |
|
| 849 | 839 | |
| 850 | 840 | $wps_cart = new wps_cart(); |
| 851 | 841 | $result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) ); |
@@ -925,8 +915,9 @@ discard block |
||
| 925 | 915 | function wps_apply_coupon() { |
| 926 | 916 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 927 | 917 | |
| 928 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) |
|
| 929 | - wp_die(); |
|
| 918 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) { |
|
| 919 | + wp_die(); |
|
| 920 | + } |
|
| 930 | 921 | |
| 931 | 922 | $status = false; $response = ''; |
| 932 | 923 | $coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null; |
@@ -938,12 +929,10 @@ discard block |
||
| 938 | 929 | $this->store_cart_in_session($order); |
| 939 | 930 | $status = true; |
| 940 | 931 | $response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>'; |
| 941 | - } |
|
| 942 | - else { |
|
| 932 | + } else { |
|
| 943 | 933 | $response = '<div class="wps-alert-error">' .$result['message']. '</div>'; |
| 944 | 934 | } |
| 945 | - } |
|
| 946 | - else { |
|
| 935 | + } else { |
|
| 947 | 936 | $response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>'; |
| 948 | 937 | } |
| 949 | 938 | echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
@@ -957,8 +946,9 @@ discard block |
||
| 957 | 946 | public static function wps_cart_pass_to_step_two() { |
| 958 | 947 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 959 | 948 | |
| 960 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) |
|
| 961 | - wp_die(); |
|
| 949 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) { |
|
| 950 | + wp_die(); |
|
| 951 | + } |
|
| 962 | 952 | |
| 963 | 953 | $status = false; $response = ''; |
| 964 | 954 | $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
@@ -968,8 +958,7 @@ discard block |
||
| 968 | 958 | $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
| 969 | 959 | $response = apply_filters('wps_extra_signup_actions', $response); |
| 970 | 960 | $status = true; |
| 971 | - } |
|
| 972 | - else { |
|
| 961 | + } else { |
|
| 973 | 962 | $response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>'; |
| 974 | 963 | } |
| 975 | 964 | echo json_encode( array( 'status' => $status, 'response' => $response)); |
@@ -983,8 +972,9 @@ discard block |
||
| 983 | 972 | function wps_empty_cart() { |
| 984 | 973 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 985 | 974 | |
| 986 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) |
|
| 987 | - wp_die(); |
|
| 975 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) { |
|
| 976 | + wp_die(); |
|
| 977 | + } |
|
| 988 | 978 | |
| 989 | 979 | |
| 990 | 980 | $this->empty_cart(); |
@@ -1,29 +1,29 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | ?> |
| 3 | 3 | <div class="wps-cart-cartouche"> |
| 4 | 4 | <div class="wps-cart-message"> |
| 5 | - <?php if( $cart_type != 'admin-panel' ) : ?> |
|
| 6 | - <?php if ( !empty($cart_type) && $cart_type == 'summary' && !$account_origin ) : ?> |
|
| 7 | - <?php $url_step_one = get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ); ?> |
|
| 8 | - <?php printf( __( 'You have forget an item ? <a href="%s">Modify your cart !</a>', 'wpshop'), $url_step_one ); ?> |
|
| 5 | + <?php if ($cart_type != 'admin-panel') : ?> |
|
| 6 | + <?php if (!empty($cart_type) && $cart_type == 'summary' && !$account_origin) : ?> |
|
| 7 | + <?php $url_step_one = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))); ?> |
|
| 8 | + <?php printf(__('You have forget an item ? <a href="%s">Modify your cart !</a>', 'wpshop'), $url_step_one); ?> |
|
| 9 | 9 | <?php else : ?> |
| 10 | - <?php if( !$account_origin ) : |
|
| 10 | + <?php if (!$account_origin) : |
|
| 11 | 11 | echo do_shortcode('[wps_apply_coupon]'); |
| 12 | 12 | else : ?> |
| 13 | - <button id="<?php echo $oid; ?>" class="wps-bton-first-mini-rounded make_order_again" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_restart_the_order' ); ?>"><?php _e( 'Make this order again', 'wpshop'); ?></button> |
|
| 13 | + <button id="<?php echo $oid; ?>" class="wps-bton-first-mini-rounded make_order_again" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_restart_the_order'); ?>"><?php _e('Make this order again', 'wpshop'); ?></button> |
|
| 14 | 14 | <?php endif; ?> |
| 15 | - <?php if( !empty($tracking) ) : ?> |
|
| 15 | + <?php if (!empty($tracking)) : ?> |
|
| 16 | 16 | <p><br /> |
| 17 | - <?php if( !empty($tracking['number']) ) : ?> |
|
| 18 | - <strong><?php _e('Tracking number','wpshop'); ?> :</strong> <?php _e($tracking['number']); ?><br /> |
|
| 17 | + <?php if (!empty($tracking['number'])) : ?> |
|
| 18 | + <strong><?php _e('Tracking number', 'wpshop'); ?> :</strong> <?php _e($tracking['number']); ?><br /> |
|
| 19 | 19 | <?php endif; ?> |
| 20 | - <?php if( !empty($tracking['link']) ) : ?> |
|
| 20 | + <?php if (!empty($tracking['link'])) : ?> |
|
| 21 | 21 | <?php /** Check if http:// it's found in the link */ |
| 22 | 22 | $url = $tracking['link']; |
| 23 | - if('http://' != substr($url, 0, 7)) |
|
| 23 | + if ('http://' != substr($url, 0, 7)) |
|
| 24 | 24 | $url = 'http://' . $url; |
| 25 | 25 | ?> |
| 26 | - <a class="wps-bton-fourth-mini-rounded" href="<?php echo $url; ?>" target="_blank"><?php _e('Tracking link','wpshop'); ?></a> |
|
| 26 | + <a class="wps-bton-fourth-mini-rounded" href="<?php echo $url; ?>" target="_blank"><?php _e('Tracking link', 'wpshop'); ?></a> |
|
| 27 | 27 | <?php endif; ?> |
| 28 | 28 | </p> |
| 29 | 29 | <?php endif; ?> |
@@ -31,141 +31,141 @@ discard block |
||
| 31 | 31 | <?php endif; ?> |
| 32 | 32 | </div><!-- wps-cart-message --> |
| 33 | 33 | <div class="wps-cart-total"> |
| 34 | - <?php $shipping_price_from = get_option( 'wpshop_shipping_cost_from' ); ?> |
|
| 34 | + <?php $shipping_price_from = get_option('wpshop_shipping_cost_from'); ?> |
|
| 35 | 35 | |
| 36 | 36 | <!-- Recap shipping --> |
| 37 | 37 | |
| 38 | - <?php if( $cart_option == 'full_cart' || $cart_option == 'simplified_et' || $price_piloting == 'HT' ) : ?> |
|
| 38 | + <?php if ($cart_option == 'full_cart' || $cart_option == 'simplified_et' || $price_piloting == 'HT') : ?> |
|
| 39 | 39 | <p> |
| 40 | - <?php _e( 'Shipping cost ET', 'wpshop'); ?> <?php echo ( ( !empty($shipping_price_from) && empty( $_SESSION['shipping_address'] ) ) ? '<br/><i>('.__( 'From', 'wpshop').')</i>' : '' ); ?> |
|
| 40 | + <?php _e('Shipping cost ET', 'wpshop'); ?> <?php echo ((!empty($shipping_price_from) && empty($_SESSION['shipping_address'])) ? '<br/><i>(' . __('From', 'wpshop') . ')</i>' : ''); ?> |
|
| 41 | 41 | <span class="wps-alignRight"> |
| 42 | - <?php if( $cart_type != 'admin-panel' ) : ?> |
|
| 43 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_et ); ?></strong> <?php echo $currency; ?> |
|
| 42 | + <?php if ($cart_type != 'admin-panel') : ?> |
|
| 43 | + <strong><?php echo wpshop_tools::formate_number($shipping_cost_et); ?></strong> <?php echo $currency; ?> |
|
| 44 | 44 | <?php else : ?> |
| 45 | - <?php if( ( empty( $cart_content['order_status'] ) || ( $cart_content['order_status'] == 'awaiting_payment' ) || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) && $price_piloting == 'HT' ) : ?> |
|
| 46 | - <input type="text" size="5" value="<?php echo number_format( $shipping_cost_et, 2 ); ?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 45 | + <?php if ((empty($cart_content['order_status']) || ($cart_content['order_status'] == 'awaiting_payment') || ((!empty($cart_content['cart_type']) && $cart_content['cart_type'] == 'quotation') && $cart_content['order_status'] != 'completed')) && $price_piloting == 'HT') : ?> |
|
| 46 | + <input type="text" size="5" value="<?php echo number_format($shipping_cost_et, 2); ?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 47 | 47 | <?php else : ?> |
| 48 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_et ); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 48 | + <strong><?php echo wpshop_tools::formate_number($shipping_cost_et); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 49 | 49 | <?php endif; ?> |
| 50 | 50 | <?php endif; ?> |
| 51 | 51 | </span> |
| 52 | 52 | </p> |
| 53 | 53 | <?php endif; ?> |
| 54 | 54 | |
| 55 | - <?php if( $cart_option == 'full_cart' ) : ?> |
|
| 55 | + <?php if ($cart_option == 'full_cart') : ?> |
|
| 56 | 56 | <p> |
| 57 | - <?php _e( 'VAT on Shipping cost', 'wpshop'); ?> |
|
| 57 | + <?php _e('VAT on Shipping cost', 'wpshop'); ?> |
|
| 58 | 58 | <span class="wps-alignRight"> |
| 59 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_vat ); ?></strong> <?php echo $currency; ?> |
|
| 59 | + <strong><?php echo wpshop_tools::formate_number($shipping_cost_vat); ?></strong> <?php echo $currency; ?> |
|
| 60 | 60 | </span> |
| 61 | 61 | </p> |
| 62 | 62 | <?php endif; ?> |
| 63 | 63 | |
| 64 | - <?php if( $cart_option == 'full_cart' || $cart_option == 'simplified_ati' || $price_piloting == 'TTC' ) : ?> |
|
| 64 | + <?php if ($cart_option == 'full_cart' || $cart_option == 'simplified_ati' || $price_piloting == 'TTC') : ?> |
|
| 65 | 65 | <p> |
| 66 | - <?php _e( 'Shipping cost', 'wpshop'); ?> <?php echo ( ( !empty($shipping_price_from) && empty( $_SESSION['shipping_address'] ) ) ? '<br/><i>('.__( 'From', 'wpshop').')</i>' : '' ); ?> |
|
| 66 | + <?php _e('Shipping cost', 'wpshop'); ?> <?php echo ((!empty($shipping_price_from) && empty($_SESSION['shipping_address'])) ? '<br/><i>(' . __('From', 'wpshop') . ')</i>' : ''); ?> |
|
| 67 | 67 | <span class="wps-alignRight"> |
| 68 | - <?php if( $cart_type != 'admin-panel' ) : ?> |
|
| 69 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); ?></strong> <?php echo $currency; ?> |
|
| 68 | + <?php if ($cart_type != 'admin-panel') : ?> |
|
| 69 | + <strong><?php echo wpshop_tools::formate_number($shipping_cost_ati); ?></strong> <?php echo $currency; ?> |
|
| 70 | 70 | <?php else : ?> |
| 71 | - <?php if( ( empty( $cart_content['order_status'] ) || ( $cart_content['order_status'] == 'awaiting_payment' ) || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) && $price_piloting == 'TTC' ) : ?> |
|
| 72 | - <input type="text" size="5" value="<?php echo number_format( $shipping_cost_ati, 2 ); ?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 71 | + <?php if ((empty($cart_content['order_status']) || ($cart_content['order_status'] == 'awaiting_payment') || ((!empty($cart_content['cart_type']) && $cart_content['cart_type'] == 'quotation') && $cart_content['order_status'] != 'completed')) && $price_piloting == 'TTC') : ?> |
|
| 72 | + <input type="text" size="5" value="<?php echo number_format($shipping_cost_ati, 2); ?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 73 | 73 | <?php else : ?> |
| 74 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 74 | + <strong><?php echo wpshop_tools::formate_number($shipping_cost_ati); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 75 | 75 | <?php endif; ?> |
| 76 | 76 | <?php endif; ?> |
| 77 | 77 | </span> |
| 78 | 78 | </p> |
| 79 | 79 | <?php endif; ?> |
| 80 | 80 | |
| 81 | - <?php if( $cart_option == 'full_cart' && !empty($cart_content['order_tva']) ) : ?> |
|
| 82 | - <?php foreach( $cart_content['order_tva'] as $order_vat_rate => $order_vat_value ) : |
|
| 83 | - if( $order_vat_rate != 'VAT_shipping_cost') : |
|
| 81 | + <?php if ($cart_option == 'full_cart' && !empty($cart_content['order_tva'])) : ?> |
|
| 82 | + <?php foreach ($cart_content['order_tva'] as $order_vat_rate => $order_vat_value) : |
|
| 83 | + if ($order_vat_rate != 'VAT_shipping_cost') : |
|
| 84 | 84 | ?> |
| 85 | 85 | <p> |
| 86 | - <?php printf( __( 'VAT (%s %%)', 'wpshop'), $order_vat_rate); ?> |
|
| 86 | + <?php printf(__('VAT (%s %%)', 'wpshop'), $order_vat_rate); ?> |
|
| 87 | 87 | <span class="wps-alignRight"> |
| 88 | - <strong><?php echo wpshop_tools::formate_number( $order_vat_value ); ?></strong> <?php echo $currency; ?> |
|
| 88 | + <strong><?php echo wpshop_tools::formate_number($order_vat_value); ?></strong> <?php echo $currency; ?> |
|
| 89 | 89 | </span> |
| 90 | 90 | </p> |
| 91 | 91 | <?php |
| 92 | 92 | endif; |
| 93 | 93 | endforeach; ?> |
| 94 | 94 | <?php endif; ?> |
| 95 | - <?php if( !empty($cart_content['order_discount_value']) || ( $cart_type == 'admin-panel' ) ) : ?> |
|
| 95 | + <?php if (!empty($cart_content['order_discount_value']) || ($cart_type == 'admin-panel')) : ?> |
|
| 96 | 96 | <p> |
| 97 | - <?php _e( 'Discount', 'wpshop'); ?> |
|
| 97 | + <?php _e('Discount', 'wpshop'); ?> |
|
| 98 | 98 | <span class="wps-alignRight"> |
| 99 | - <?php if( ( $cart_type == 'admin-panel' ) && ( empty( $cart_content['order_status'] ) || $cart_content['order_status'] == 'awaiting_payment' || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) ) : ?> |
|
| 100 | - <input type="text" id="wps-orders-discount-value" size="5" style="text-align : right" value="<?php echo ( !empty($cart_content['order_discount_value']) ) ? $cart_content['order_discount_value'] : number_format( 0, 2 ); ?>"/> |
|
| 99 | + <?php if (($cart_type == 'admin-panel') && (empty($cart_content['order_status']) || $cart_content['order_status'] == 'awaiting_payment' || ((!empty($cart_content['cart_type']) && $cart_content['cart_type'] == 'quotation') && $cart_content['order_status'] != 'completed'))) : ?> |
|
| 100 | + <input type="text" id="wps-orders-discount-value" size="5" style="text-align : right" value="<?php echo (!empty($cart_content['order_discount_value'])) ? $cart_content['order_discount_value'] : number_format(0, 2); ?>"/> |
|
| 101 | 101 | <?php else : ?> |
| 102 | - <?php if( !empty($cart_content['order_discount_value']) ) : ?> |
|
| 103 | - <strong><?php echo $cart_content['order_discount_value']; ?> <?php echo ( !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'percent' ) ? '%' : wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 102 | + <?php if (!empty($cart_content['order_discount_value'])) : ?> |
|
| 103 | + <strong><?php echo $cart_content['order_discount_value']; ?> <?php echo (!empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'percent') ? '%' : wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 104 | 104 | <?php else : ?> |
| 105 | 105 | 0 <?php echo wpshop_tools::wpshop_get_currency(); ?> |
| 106 | 106 | <?php endif; ?> |
| 107 | 107 | <?php endif; ?> |
| 108 | 108 | </span> |
| 109 | 109 | </p> |
| 110 | - <?php if( ( $cart_type == 'admin-panel' ) && ( empty( $cart_content['order_status'] ) || $cart_content['order_status'] == 'awaiting_payment' || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) ) : ?> |
|
| 110 | + <?php if (($cart_type == 'admin-panel') && (empty($cart_content['order_status']) || $cart_content['order_status'] == 'awaiting_payment' || ((!empty($cart_content['cart_type']) && $cart_content['cart_type'] == 'quotation') && $cart_content['order_status'] != 'completed'))) : ?> |
|
| 111 | 111 | <p> |
| 112 | - <?php _e( 'Discount type', 'wpshop'); ?> |
|
| 112 | + <?php _e('Discount type', 'wpshop'); ?> |
|
| 113 | 113 | <span class="wps-alignRight"> |
| 114 | 114 | <select id="wps-orders-discount-type"> |
| 115 | - <option value="percent" <?php echo ( !empty($cart_content) && !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'percent' ) ? 'selected="selected"' : ''; ?>>%</option> |
|
| 116 | - <option value="amount" <?php echo ( !empty($cart_content) && !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'amount' ) ? 'selected="selected"' : ''; ?>><?php echo wpshop_tools::wpshop_get_currency(); ?></option> |
|
| 115 | + <option value="percent" <?php echo (!empty($cart_content) && !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'percent') ? 'selected="selected"' : ''; ?>>%</option> |
|
| 116 | + <option value="amount" <?php echo (!empty($cart_content) && !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'amount') ? 'selected="selected"' : ''; ?>><?php echo wpshop_tools::wpshop_get_currency(); ?></option> |
|
| 117 | 117 | </select> |
| 118 | 118 | </span> |
| 119 | 119 | </p> |
| 120 | 120 | <?php endif; ?> |
| 121 | 121 | <?php endif; ?> |
| 122 | 122 | |
| 123 | - <?php if ( !empty( $cart_content['coupon_id']) ) : ?> |
|
| 124 | - <p><?php _e( 'Total ATI before discount', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $order_totla_before_discount ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 125 | - <p><?php _e( 'Discount', 'wpshop'); ?> (<?php echo $coupon_title; ?>) <span class="wps-alignRight"><strong><?php echo $coupon_value; ?></strong><?php echo $currency; ?></span></p> |
|
| 123 | + <?php if (!empty($cart_content['coupon_id'])) : ?> |
|
| 124 | + <p><?php _e('Total ATI before discount', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($order_totla_before_discount); ?></strong> <?php echo $currency; ?></span></p> |
|
| 125 | + <p><?php _e('Discount', 'wpshop'); ?> (<?php echo $coupon_title; ?>) <span class="wps-alignRight"><strong><?php echo $coupon_value; ?></strong><?php echo $currency; ?></span></p> |
|
| 126 | 126 | <?php endif; ?> |
| 127 | 127 | |
| 128 | - <?php if( !empty($_SESSION['cart']['order_partial_payment']) ) : |
|
| 129 | - $wps_partial_payment_data = get_option( 'wpshop_payment_partial' ); |
|
| 130 | - if( !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' ) { |
|
| 128 | + <?php if (!empty($_SESSION['cart']['order_partial_payment'])) : |
|
| 129 | + $wps_partial_payment_data = get_option('wpshop_payment_partial'); |
|
| 130 | + if (!empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
|
| 131 | 131 | $partial_payment_informations = $wps_partial_payment_data['for_quotation']; |
| 132 | 132 | } else { |
| 133 | 133 | $partial_payment_informations = $wps_partial_payment_data['for_all']; |
| 134 | 134 | } |
| 135 | - $partial_payment_amount = $_SESSION['cart']['order_partial_payment']; |
|
| 135 | + $partial_payment_amount = $_SESSION['cart']['order_partial_payment']; |
|
| 136 | 136 | ?> |
| 137 | - <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $cart_content['order_grand_total'] ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 137 | + <p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($cart_content['order_grand_total']); ?></strong> <?php echo $currency; ?></span></p> |
|
| 138 | 138 | <p class="wps-hightlight"> |
| 139 | - <?php printf(__('Payable now %s','wpshop'), '(' . $partial_payment_informations['value'] . ( ( !empty($partial_payment_informations['type']) && $partial_payment_informations['type'] == 'percentage' ) ? '%': wpshop_tools::wpshop_get_currency( false ) ) . ')'); ?> |
|
| 140 | - <span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $partial_payment_amount ); ?></strong> <?php echo $currency; ?> |
|
| 139 | + <?php printf(__('Payable now %s', 'wpshop'), '(' . $partial_payment_informations['value'] . ((!empty($partial_payment_informations['type']) && $partial_payment_informations['type'] == 'percentage') ? '%' : wpshop_tools::wpshop_get_currency(false)) . ')'); ?> |
|
| 140 | + <span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($partial_payment_amount); ?></strong> <?php echo $currency; ?> |
|
| 141 | 141 | </span></p> |
| 142 | - <?php elseif ( !empty( $cart_content ) && !empty( $cart_content[ 'order_status'] ) && ( 'partially_paid' == $cart_content[ 'order_status' ] ) && !empty( $cart_content[ 'order_payment' ] ) && !empty( $cart_content[ 'order_payment' ][ 'received' ] ) ) : ?> |
|
| 143 | - <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $cart_content['order_grand_total'] ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 142 | + <?php elseif (!empty($cart_content) && !empty($cart_content['order_status']) && ('partially_paid' == $cart_content['order_status']) && !empty($cart_content['order_payment']) && !empty($cart_content['order_payment']['received'])) : ?> |
|
| 143 | + <p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($cart_content['order_grand_total']); ?></strong> <?php echo $currency; ?></span></p> |
|
| 144 | 144 | <?php $allready_received_amount = 0; ?> |
| 145 | - <?php foreach ( $cart_content[ 'order_payment' ][ 'received' ] as $payment ) : ?> |
|
| 146 | - <?php if ( ! empty( $payment[ 'status' ] ) && 'payment_received' == $payment[ 'status' ] ) : ?> |
|
| 147 | - <?php $allready_received_amount += $payment[ 'received_amount' ]; ?> |
|
| 145 | + <?php foreach ($cart_content['order_payment']['received'] as $payment) : ?> |
|
| 146 | + <?php if (!empty($payment['status']) && 'payment_received' == $payment['status']) : ?> |
|
| 147 | + <?php $allready_received_amount += $payment['received_amount']; ?> |
|
| 148 | 148 | <?php endif; ?> |
| 149 | 149 | <?php endforeach; ?> |
| 150 | - <p><?php _e( 'Already paid', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $allready_received_amount ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 151 | - <p class="wps-hightlight"><?php _e( 'Due amount for this order', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $cart_content['order_grand_total'] - $allready_received_amount ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 150 | + <p><?php _e('Already paid', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($allready_received_amount); ?></strong> <?php echo $currency; ?></span></p> |
|
| 151 | + <p class="wps-hightlight"><?php _e('Due amount for this order', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($cart_content['order_grand_total'] - $allready_received_amount); ?></strong> <?php echo $currency; ?></span></p> |
|
| 152 | 152 | <?php else : ?> |
| 153 | - <?php if ( isset( $_SESSION[ 'cart' ][ 'order_product_partial_payment' ]) ) : ?> |
|
| 154 | - <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $_SESSION['cart']['order_amount_to_pay_now'] ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 153 | + <?php if (isset($_SESSION['cart']['order_product_partial_payment'])) : ?> |
|
| 154 | + <p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($_SESSION['cart']['order_amount_to_pay_now']); ?></strong> <?php echo $currency; ?></span></p> |
|
| 155 | 155 | <?php else: ?> |
| 156 | - <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $total_ati ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 156 | + <p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($total_ati); ?></strong> <?php echo $currency; ?></span></p> |
|
| 157 | 157 | <?php endif; ?> |
| 158 | 158 | <?php endif; ?> |
| 159 | 159 | </div><!-- wps-cart-total --> |
| 160 | 160 | </div><!-- wps-cart-cartouche --> |
| 161 | 161 | |
| 162 | -<?php if ( empty($cart_type) || ( !empty($cart_type) && $cart_type != 'summary' && $cart_type != 'admin-panel') ) : ?> |
|
| 162 | +<?php if (empty($cart_type) || (!empty($cart_type) && $cart_type != 'summary' && $cart_type != 'admin-panel')) : ?> |
|
| 163 | 163 | <div class="wps-checkout-actions"> |
| 164 | - <button data-nonce="<?php echo wp_create_nonce( 'wps_empty_cart' ); ?>" class="wps-bton-second emptyCart"><?php _e( 'Empty the cart', 'wpshop' ); ?></button> |
|
| 165 | - <?php if( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' ) : ?> |
|
| 166 | - <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce( 'wps_cart_pass_to_step_two' ); ?>" id="wps-cart-order-action"><?php _e( 'Validate my quotation', 'wpshop' ); ?></button> |
|
| 164 | + <button data-nonce="<?php echo wp_create_nonce('wps_empty_cart'); ?>" class="wps-bton-second emptyCart"><?php _e('Empty the cart', 'wpshop'); ?></button> |
|
| 165 | + <?php if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') : ?> |
|
| 166 | + <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce('wps_cart_pass_to_step_two'); ?>" id="wps-cart-order-action"><?php _e('Validate my quotation', 'wpshop'); ?></button> |
|
| 167 | 167 | <?php else : ?> |
| 168 | - <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce( 'wps_cart_pass_to_step_two' ); ?>" id="wps-cart-order-action"><?php _e( 'Order', 'wpshop' ); ?></button> |
|
| 168 | + <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce('wps_cart_pass_to_step_two'); ?>" id="wps-cart-order-action"><?php _e('Order', 'wpshop'); ?></button> |
|
| 169 | 169 | <?php endif; ?> |
| 170 | 170 | </div> |
| 171 | 171 | <div class="wps-cart-notices"> |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | </div> |
| 176 | 176 | <?php endif; ?> |
| 177 | 177 | |
| 178 | -<?php if( !empty($cart_type) && $cart_type == 'admin-panel' && ( empty( $cart_content['order_status'] ) || $cart_content['order_status'] == 'awaiting_payment' || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) ) : ?> |
|
| 179 | - <button class="wps-bton-second-rounded alignRight" data-nonce="<?php echo wp_create_nonce( 'wps_orders_update_cart_informations' ); ?>" id="wps-orders-update-cart-informations"><i class="dashicons dashicons-update"></i><?php _e( 'Update order informations', 'wpshop'); ?></button> |
|
| 178 | +<?php if (!empty($cart_type) && $cart_type == 'admin-panel' && (empty($cart_content['order_status']) || $cart_content['order_status'] == 'awaiting_payment' || ((!empty($cart_content['cart_type']) && $cart_content['cart_type'] == 'quotation') && $cart_content['order_status'] != 'completed'))) : ?> |
|
| 179 | + <button class="wps-bton-second-rounded alignRight" data-nonce="<?php echo wp_create_nonce('wps_orders_update_cart_informations'); ?>" id="wps-orders-update-cart-informations"><i class="dashicons dashicons-update"></i><?php _e('Update order informations', 'wpshop'); ?></button> |
|
| 180 | 180 | <?php endif; ?> |
| 181 | 181 | <?php $wps_payment_mode = get_option('wps_payment_mode'); ?> |
| 182 | -<?php if( isset( $wps_payment_mode['mode']['paypal']['active'] ) ): ?> |
|
| 182 | +<?php if (isset($wps_payment_mode['mode']['paypal']['active'])): ?> |
|
| 183 | 183 | <div class="wps-secured-logos"> |
| 184 | 184 | <span class="wps-logo-paypal"></span> |
| 185 | 185 | <span class="wps-logo-visa"></span> |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | ?> |
| 3 | 5 | <div class="wps-cart-cartouche"> |
| 4 | 6 | <div class="wps-cart-message"> |
@@ -6,11 +8,16 @@ discard block |
||
| 6 | 8 | <?php if ( !empty($cart_type) && $cart_type == 'summary' && !$account_origin ) : ?> |
| 7 | 9 | <?php $url_step_one = get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ); ?> |
| 8 | 10 | <?php printf( __( 'You have forget an item ? <a href="%s">Modify your cart !</a>', 'wpshop'), $url_step_one ); ?> |
| 9 | - <?php else : ?> |
|
| 11 | + <?php else { |
|
| 12 | + : ?> |
|
| 10 | 13 | <?php if( !$account_origin ) : |
| 11 | 14 | echo do_shortcode('[wps_apply_coupon]'); |
| 12 | - else : ?> |
|
| 13 | - <button id="<?php echo $oid; ?>" class="wps-bton-first-mini-rounded make_order_again" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_restart_the_order' ); ?>"><?php _e( 'Make this order again', 'wpshop'); ?></button> |
|
| 15 | +} |
|
| 16 | + else { |
|
| 17 | + : ?> |
|
| 18 | + <button id="<?php echo $oid; |
|
| 19 | + } |
|
| 20 | + ?>" class="wps-bton-first-mini-rounded make_order_again" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_restart_the_order' ); ?>"><?php _e( 'Make this order again', 'wpshop'); ?></button> |
|
| 14 | 21 | <?php endif; ?> |
| 15 | 22 | <?php if( !empty($tracking) ) : ?> |
| 16 | 23 | <p><br /> |
@@ -20,8 +27,9 @@ discard block |
||
| 20 | 27 | <?php if( !empty($tracking['link']) ) : ?> |
| 21 | 28 | <?php /** Check if http:// it's found in the link */ |
| 22 | 29 | $url = $tracking['link']; |
| 23 | - if('http://' != substr($url, 0, 7)) |
|
| 24 | - $url = 'http://' . $url; |
|
| 30 | + if('http://' != substr($url, 0, 7)) { |
|
| 31 | + $url = 'http://' . $url; |
|
| 32 | + } |
|
| 25 | 33 | ?> |
| 26 | 34 | <a class="wps-bton-fourth-mini-rounded" href="<?php echo $url; ?>" target="_blank"><?php _e('Tracking link','wpshop'); ?></a> |
| 27 | 35 | <?php endif; ?> |
@@ -41,11 +49,17 @@ discard block |
||
| 41 | 49 | <span class="wps-alignRight"> |
| 42 | 50 | <?php if( $cart_type != 'admin-panel' ) : ?> |
| 43 | 51 | <strong><?php echo wpshop_tools::formate_number( $shipping_cost_et ); ?></strong> <?php echo $currency; ?> |
| 44 | - <?php else : ?> |
|
| 52 | + <?php else { |
|
| 53 | + : ?> |
|
| 45 | 54 | <?php if( ( empty( $cart_content['order_status'] ) || ( $cart_content['order_status'] == 'awaiting_payment' ) || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) && $price_piloting == 'HT' ) : ?> |
| 46 | - <input type="text" size="5" value="<?php echo number_format( $shipping_cost_et, 2 ); ?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 47 | - <?php else : ?> |
|
| 48 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_et ); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 55 | + <input type="text" size="5" value="<?php echo number_format( $shipping_cost_et, 2 ); |
|
| 56 | +} |
|
| 57 | +?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 58 | + <?php else { |
|
| 59 | + : ?> |
|
| 60 | + <strong><?php echo wpshop_tools::formate_number( $shipping_cost_et ); |
|
| 61 | +} |
|
| 62 | +?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 49 | 63 | <?php endif; ?> |
| 50 | 64 | <?php endif; ?> |
| 51 | 65 | </span> |
@@ -67,11 +81,17 @@ discard block |
||
| 67 | 81 | <span class="wps-alignRight"> |
| 68 | 82 | <?php if( $cart_type != 'admin-panel' ) : ?> |
| 69 | 83 | <strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); ?></strong> <?php echo $currency; ?> |
| 70 | - <?php else : ?> |
|
| 84 | + <?php else { |
|
| 85 | + : ?> |
|
| 71 | 86 | <?php if( ( empty( $cart_content['order_status'] ) || ( $cart_content['order_status'] == 'awaiting_payment' ) || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) && $price_piloting == 'TTC' ) : ?> |
| 72 | - <input type="text" size="5" value="<?php echo number_format( $shipping_cost_ati, 2 ); ?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 73 | - <?php else : ?> |
|
| 74 | - <strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 87 | + <input type="text" size="5" value="<?php echo number_format( $shipping_cost_ati, 2 ); |
|
| 88 | +} |
|
| 89 | +?>" id="wps-orders-shipping-cost" class="wps-error" style="text-align : right" /> |
|
| 90 | + <?php else { |
|
| 91 | + : ?> |
|
| 92 | + <strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); |
|
| 93 | +} |
|
| 94 | +?> <?php echo wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 75 | 95 | <?php endif; ?> |
| 76 | 96 | <?php endif; ?> |
| 77 | 97 | </span> |
@@ -98,11 +118,17 @@ discard block |
||
| 98 | 118 | <span class="wps-alignRight"> |
| 99 | 119 | <?php if( ( $cart_type == 'admin-panel' ) && ( empty( $cart_content['order_status'] ) || $cart_content['order_status'] == 'awaiting_payment' || ( ( !empty( $cart_content['cart_type'] ) && $cart_content['cart_type'] == 'quotation' ) && $cart_content['order_status'] != 'completed' ) ) ) : ?> |
| 100 | 120 | <input type="text" id="wps-orders-discount-value" size="5" style="text-align : right" value="<?php echo ( !empty($cart_content['order_discount_value']) ) ? $cart_content['order_discount_value'] : number_format( 0, 2 ); ?>"/> |
| 101 | - <?php else : ?> |
|
| 121 | + <?php else { |
|
| 122 | + : ?> |
|
| 102 | 123 | <?php if( !empty($cart_content['order_discount_value']) ) : ?> |
| 103 | - <strong><?php echo $cart_content['order_discount_value']; ?> <?php echo ( !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'percent' ) ? '%' : wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 104 | - <?php else : ?> |
|
| 105 | - 0 <?php echo wpshop_tools::wpshop_get_currency(); ?> |
|
| 124 | + <strong><?php echo $cart_content['order_discount_value']; |
|
| 125 | +} |
|
| 126 | +?> <?php echo ( !empty($cart_content['order_discount_type']) && $cart_content['order_discount_type'] == 'percent' ) ? '%' : wpshop_tools::wpshop_get_currency(); ?></strong> |
|
| 127 | + <?php else { |
|
| 128 | + : ?> |
|
| 129 | + 0 <?php echo wpshop_tools::wpshop_get_currency(); |
|
| 130 | +} |
|
| 131 | +?> |
|
| 106 | 132 | <?php endif; ?> |
| 107 | 133 | <?php endif; ?> |
| 108 | 134 | </span> |
@@ -149,11 +175,17 @@ discard block |
||
| 149 | 175 | <?php endforeach; ?> |
| 150 | 176 | <p><?php _e( 'Already paid', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $allready_received_amount ); ?></strong> <?php echo $currency; ?></span></p> |
| 151 | 177 | <p class="wps-hightlight"><?php _e( 'Due amount for this order', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $cart_content['order_grand_total'] - $allready_received_amount ); ?></strong> <?php echo $currency; ?></span></p> |
| 152 | - <?php else : ?> |
|
| 178 | + <?php else { |
|
| 179 | + : ?> |
|
| 153 | 180 | <?php if ( isset( $_SESSION[ 'cart' ][ 'order_product_partial_payment' ]) ) : ?> |
| 154 | - <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $_SESSION['cart']['order_amount_to_pay_now'] ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 155 | - <?php else: ?> |
|
| 156 | - <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $total_ati ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 181 | + <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); |
|
| 182 | +} |
|
| 183 | +?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $_SESSION['cart']['order_amount_to_pay_now'] ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 184 | + <?php else { |
|
| 185 | + : ?> |
|
| 186 | + <p class="wps-hightlight"><?php _e( 'Total ATI', 'wpshop'); |
|
| 187 | +} |
|
| 188 | +?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $total_ati ); ?></strong> <?php echo $currency; ?></span></p> |
|
| 157 | 189 | <?php endif; ?> |
| 158 | 190 | <?php endif; ?> |
| 159 | 191 | </div><!-- wps-cart-total --> |
@@ -164,8 +196,11 @@ discard block |
||
| 164 | 196 | <button data-nonce="<?php echo wp_create_nonce( 'wps_empty_cart' ); ?>" class="wps-bton-second emptyCart"><?php _e( 'Empty the cart', 'wpshop' ); ?></button> |
| 165 | 197 | <?php if( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' ) : ?> |
| 166 | 198 | <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce( 'wps_cart_pass_to_step_two' ); ?>" id="wps-cart-order-action"><?php _e( 'Validate my quotation', 'wpshop' ); ?></button> |
| 167 | - <?php else : ?> |
|
| 168 | - <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce( 'wps_cart_pass_to_step_two' ); ?>" id="wps-cart-order-action"><?php _e( 'Order', 'wpshop' ); ?></button> |
|
| 199 | + <?php else { |
|
| 200 | + : ?> |
|
| 201 | + <button class="wps-bton-first" data-nonce="<?php echo wp_create_nonce( 'wps_cart_pass_to_step_two' ); |
|
| 202 | +} |
|
| 203 | +?>" id="wps-cart-order-action"><?php _e( 'Order', 'wpshop' ); ?></button> |
|
| 169 | 204 | <?php endif; ?> |
| 170 | 205 | </div> |
| 171 | 206 | <div class="wps-cart-notices"> |