@@ -158,6 +158,7 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * Display pagination |
| 160 | 160 | * |
| 161 | + * @param integer $current_page |
|
| 161 | 162 | * @return string |
| 162 | 163 | */ |
| 163 | 164 | function get_products_pagination( $current_page, $attribute_set_id = 1 ) { |
@@ -201,6 +202,9 @@ discard block |
||
| 201 | 202 | return $output; |
| 202 | 203 | } |
| 203 | 204 | |
| 205 | + /** |
|
| 206 | + * @param integer $product_id |
|
| 207 | + */ |
|
| 204 | 208 | function wps_product_attached_files( $product_id ) { |
| 205 | 209 | global $wpdb; |
| 206 | 210 | $output = ''; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Main controller file for product mass modification module |
| 4 | 4 | * |
@@ -19,47 +19,47 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | function __construct() { |
| 21 | 21 | // Add submenu |
| 22 | - add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 ); |
|
| 22 | + add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350); |
|
| 23 | 23 | |
| 24 | 24 | // Declare Styles and JS Files |
| 25 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts') ); |
|
| 26 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_css' ) ); |
|
| 27 | - add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) ); |
|
| 25 | + add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts')); |
|
| 26 | + add_action('admin_enqueue_scripts', array($this, 'admin_css')); |
|
| 27 | + add_action('admin_print_scripts', array($this, 'admin_print_scripts')); |
|
| 28 | 28 | |
| 29 | 29 | // Trigger ajax action |
| 30 | - add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') ); |
|
| 31 | - add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') ); |
|
| 32 | - add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) ); |
|
| 33 | - add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) ); |
|
| 34 | - add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) ); |
|
| 30 | + add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page')); |
|
| 31 | + add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface')); |
|
| 32 | + add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation')); |
|
| 33 | + add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file')); |
|
| 34 | + add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list')); |
|
| 35 | 35 | // add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) ); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function register_mass_products_edit_submenu() { |
| 39 | - add_submenu_page( 'edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop' ), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface')); |
|
| 39 | + add_submenu_page('edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop'), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface')); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Define the aministration pat styles |
| 44 | 44 | */ |
| 45 | 45 | function admin_css() { |
| 46 | - wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL.'/assets/css/backend.css', '', WPS_PDCT_MASS_VERSION); |
|
| 46 | + wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css', '', WPS_PDCT_MASS_VERSION); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Add javascript to administration |
| 51 | 51 | */ |
| 52 | 52 | function add_admin_scripts() { |
| 53 | - wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL.'/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true); |
|
| 53 | + wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true); |
|
| 54 | 54 | wp_enqueue_media(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | function admin_print_scripts() { |
| 58 | 58 | $output = '<script type="text/javascript">'; |
| 59 | - $output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";'; |
|
| 60 | - $output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";'; |
|
| 61 | - $output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";'; |
|
| 62 | - $output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";'; |
|
| 59 | + $output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";'; |
|
| 60 | + $output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";'; |
|
| 61 | + $output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";'; |
|
| 62 | + $output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";'; |
|
| 63 | 63 | $output .= '</script>'; |
| 64 | 64 | echo $output; |
| 65 | 65 | } |
@@ -71,15 +71,15 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return array |
| 73 | 73 | */ |
| 74 | - function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) { |
|
| 75 | - |
|
| 76 | - if ( !empty( $attribute_list ) ) { |
|
| 77 | - foreach( $attribute_list as $attributes_group ) { |
|
| 78 | - foreach( $attributes_group as $attributes_sections ) { |
|
| 79 | - if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) { |
|
| 80 | - foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) { |
|
| 81 | - if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) { |
|
| 82 | - $quick_add_form_attributes[ $attribute_id ] = $att_def; |
|
| 74 | + function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) { |
|
| 75 | + |
|
| 76 | + if (!empty($attribute_list)) { |
|
| 77 | + foreach ($attribute_list as $attributes_group) { |
|
| 78 | + foreach ($attributes_group as $attributes_sections) { |
|
| 79 | + if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) { |
|
| 80 | + foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) { |
|
| 81 | + if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') { |
|
| 82 | + $quick_add_form_attributes[$attribute_id] = $att_def; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -96,29 +96,29 @@ discard block |
||
| 96 | 96 | * @param integer $page |
| 97 | 97 | * @return string |
| 98 | 98 | */ |
| 99 | - function display_products_list( $default = 1, $page = 0 ) { |
|
| 99 | + function display_products_list($default = 1, $page = 0) { |
|
| 100 | 100 | global $wpdb; |
| 101 | 101 | // Product entity |
| 102 | - $product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 102 | + $product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 103 | 103 | |
| 104 | 104 | $user_id = get_current_user_id(); |
| 105 | 105 | // Check product limit |
| 106 | - $product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 107 | - $product_limit = ( !empty($product_limit) ) ? $product_limit : 20; |
|
| 106 | + $product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 107 | + $product_limit = (!empty($product_limit)) ? $product_limit : 20; |
|
| 108 | 108 | |
| 109 | 109 | // Get products for the current page |
| 110 | 110 | $wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl(); |
| 111 | - $products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit ); |
|
| 111 | + $products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit); |
|
| 112 | 112 | |
| 113 | 113 | // Construct Table Head Data |
| 114 | 114 | $quick_add_form_attributes = array(); |
| 115 | 115 | $get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form(); |
| 116 | - foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) { |
|
| 116 | + foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) { |
|
| 117 | 117 | $quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | ob_start(); |
| 121 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) ); |
|
| 121 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list")); |
|
| 122 | 122 | $output = ob_get_contents(); |
| 123 | 123 | ob_end_clean(); |
| 124 | 124 | return $output; |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | $products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets(); |
| 135 | 135 | |
| 136 | 136 | $default = ''; |
| 137 | - if( !empty($products_attributes_groups) ) { |
|
| 138 | - foreach( $products_attributes_groups as $key => $products_attributes_group ) { |
|
| 139 | - if( $products_attributes_group->slug == 'free_product' ) { |
|
| 140 | - unset( $products_attributes_groups[$key] ); |
|
| 137 | + if (!empty($products_attributes_groups)) { |
|
| 138 | + foreach ($products_attributes_groups as $key => $products_attributes_group) { |
|
| 139 | + if ($products_attributes_group->slug == 'free_product') { |
|
| 140 | + unset($products_attributes_groups[$key]); |
|
| 141 | 141 | } |
| 142 | - if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) { |
|
| 142 | + if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') { |
|
| 143 | 143 | $default = $products_attributes_group->id; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | // Check page |
| 148 | - $page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0; |
|
| 148 | + $page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0; |
|
| 149 | 149 | // Display product tab |
| 150 | - $product_list_interface = $this->display_products_list( $default, $page ); |
|
| 150 | + $product_list_interface = $this->display_products_list($default, $page); |
|
| 151 | 151 | |
| 152 | 152 | // Get pagination |
| 153 | - $pagination = $this->get_products_pagination( $page, $default ); |
|
| 153 | + $pagination = $this->get_products_pagination($page, $default); |
|
| 154 | 154 | |
| 155 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) ); |
|
| 155 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface")); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return string |
| 162 | 162 | */ |
| 163 | - function get_products_pagination( $current_page, $attribute_set_id = 1 ) { |
|
| 163 | + function get_products_pagination($current_page, $attribute_set_id = 1) { |
|
| 164 | 164 | global $wpdb; |
| 165 | 165 | $user_id = get_current_user_id(); |
| 166 | 166 | $output = ''; |
| 167 | 167 | /** Define the element number per page. If the user change the default value, take this value */ |
| 168 | - $one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 169 | - $one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20; |
|
| 168 | + $one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 169 | + $one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20; |
|
| 170 | 170 | |
| 171 | 171 | /** Count the number of product existing in the shop */ |
| 172 | 172 | $query = $wpdb->prepare( |
@@ -178,37 +178,37 @@ discard block |
||
| 178 | 178 | AND meta_value = %s |
| 179 | 179 | AND post_status IN ( 'publish', 'draft' )", |
| 180 | 180 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id); |
| 181 | - $products = $wpdb->get_var( $query ); |
|
| 181 | + $products = $wpdb->get_var($query); |
|
| 182 | 182 | |
| 183 | - if( !empty($products) ) { |
|
| 183 | + if (!empty($products)) { |
|
| 184 | 184 | $args = array( |
| 185 | 185 | 'base' => '%_%', |
| 186 | - 'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ), |
|
| 187 | - 'current' => ( $current_page + 1 ), |
|
| 188 | - 'total' => ceil( $products / $one_page_limit ), |
|
| 186 | + 'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'), |
|
| 187 | + 'current' => ($current_page + 1), |
|
| 188 | + 'total' => ceil($products / $one_page_limit), |
|
| 189 | 189 | 'type' => 'array', |
| 190 | 190 | 'prev_next' => false, |
| 191 | 191 | 'show_all' => true, |
| 192 | 192 | ); |
| 193 | - $paginate = paginate_links( $args ); |
|
| 193 | + $paginate = paginate_links($args); |
|
| 194 | 194 | |
| 195 | 195 | $wps_product_ctr = new wps_product_ctr(); |
| 196 | 196 | ob_start(); |
| 197 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) ); |
|
| 197 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination")); |
|
| 198 | 198 | $output = ob_get_contents(); |
| 199 | 199 | ob_end_clean(); |
| 200 | 200 | } |
| 201 | 201 | return $output; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - function wps_product_attached_files( $product_id ) { |
|
| 204 | + function wps_product_attached_files($product_id) { |
|
| 205 | 205 | global $wpdb; |
| 206 | 206 | $output = ''; |
| 207 | - $query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%' ); |
|
| 208 | - $files = $wpdb->get_results( $query ); |
|
| 209 | - if( !empty($files) ) { |
|
| 207 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%'); |
|
| 208 | + $files = $wpdb->get_results($query); |
|
| 209 | + if (!empty($files)) { |
|
| 210 | 210 | ob_start(); |
| 211 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) ); |
|
| 211 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list")); |
|
| 212 | 212 | $output = ob_get_contents(); |
| 213 | 213 | ob_end_clean(); |
| 214 | 214 | } |
@@ -220,23 +220,23 @@ discard block |
||
| 220 | 220 | * AJAX - Change page action on mass edit product interface |
| 221 | 221 | */ |
| 222 | 222 | function wps_mass_edit_change_page() { |
| 223 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 223 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 224 | 224 | |
| 225 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) |
|
| 225 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page')) |
|
| 226 | 226 | wp_die(); |
| 227 | 227 | |
| 228 | 228 | $status = false; $response = ''; |
| 229 | - $page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0; |
|
| 230 | - $attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1; |
|
| 231 | - if( !empty($attribute_set_id) ) { |
|
| 229 | + $page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0; |
|
| 230 | + $attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1; |
|
| 231 | + if (!empty($attribute_set_id)) { |
|
| 232 | 232 | // Get tab |
| 233 | - $response = $this->display_products_list( $attribute_set_id, $page ); |
|
| 234 | - $pagination = $this->get_products_pagination( $page, $attribute_set_id ); |
|
| 235 | - if( !empty($response) ) { |
|
| 233 | + $response = $this->display_products_list($attribute_set_id, $page); |
|
| 234 | + $pagination = $this->get_products_pagination($page, $attribute_set_id); |
|
| 235 | + if (!empty($response)) { |
|
| 236 | 236 | $status = true; |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | - echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) ); |
|
| 239 | + echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination)); |
|
| 240 | 240 | wp_die(); |
| 241 | 241 | } |
| 242 | 242 | |
@@ -244,30 +244,30 @@ discard block |
||
| 244 | 244 | * AJAX - Create a draft product and display the line allowing to edit informations for this product |
| 245 | 245 | */ |
| 246 | 246 | function wps_mass_interface_new_product_creation() { |
| 247 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 247 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 248 | 248 | |
| 249 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) |
|
| 249 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation')) |
|
| 250 | 250 | wp_die(); |
| 251 | 251 | |
| 252 | 252 | global $wpdb; |
| 253 | 253 | $output = $pagination = ''; |
| 254 | 254 | $status = false; |
| 255 | 255 | |
| 256 | - $new_product_id = wp_insert_post( array( |
|
| 256 | + $new_product_id = wp_insert_post(array( |
|
| 257 | 257 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
| 258 | 258 | 'post_status' => 'publish', |
| 259 | - 'post_title' => __( 'New product', 'wpshop' ), |
|
| 260 | - ) ); |
|
| 259 | + 'post_title' => __('New product', 'wpshop'), |
|
| 260 | + )); |
|
| 261 | 261 | |
| 262 | - if( !is_object($new_product_id) ) { |
|
| 262 | + if (!is_object($new_product_id)) { |
|
| 263 | 263 | $status = true; |
| 264 | 264 | } |
| 265 | - if ( !empty( $new_product_id ) ) { |
|
| 266 | - $product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1; |
|
| 267 | - update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id ); |
|
| 265 | + if (!empty($new_product_id)) { |
|
| 266 | + $product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1; |
|
| 267 | + update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) ); |
|
| 270 | + echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination)); |
|
| 271 | 271 | wp_die(); |
| 272 | 272 | } |
| 273 | 273 | |
@@ -275,32 +275,32 @@ discard block |
||
| 275 | 275 | * AJAX - Save datas |
| 276 | 276 | */ |
| 277 | 277 | function wps_save_product_quick_interface() { |
| 278 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 278 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 279 | 279 | |
| 280 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) |
|
| 280 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface')) |
|
| 281 | 281 | wp_die(); |
| 282 | 282 | |
| 283 | 283 | global $wpdb; |
| 284 | 284 | $response = ''; $status = false; |
| 285 | 285 | $count_products_to_update = 0; $total_updated_products = 0; |
| 286 | 286 | |
| 287 | - $wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array(); |
|
| 288 | - $wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array(); |
|
| 289 | - $wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array(); |
|
| 287 | + $wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array(); |
|
| 288 | + $wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array(); |
|
| 289 | + $wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array(); |
|
| 290 | 290 | |
| 291 | 291 | // ------------------------------------------------------------------------------------------------------ |
| 292 | 292 | |
| 293 | - foreach( $_REQUEST['concur'] as $post_id => $columns ) { |
|
| 293 | + foreach ($_REQUEST['concur'] as $post_id => $columns) { |
|
| 294 | 294 | $concur = array(); |
| 295 | - for( $i = $count = 0; $i <= $count; $i++ ) { |
|
| 296 | - foreach( $columns as $key => $rows ) { |
|
| 297 | - $count = count( $rows )-1; |
|
| 295 | + for ($i = $count = 0; $i <= $count; $i++) { |
|
| 296 | + foreach ($columns as $key => $rows) { |
|
| 297 | + $count = count($rows) - 1; |
|
| 298 | 298 | $concur[$i][$key] = $rows[$i]; |
| 299 | 299 | } |
| 300 | - if( empty( $concur[$i]['is_row'] ) ) { |
|
| 301 | - unset( $concur[$i] ); |
|
| 300 | + if (empty($concur[$i]['is_row'])) { |
|
| 301 | + unset($concur[$i]); |
|
| 302 | 302 | } else { |
| 303 | - unset( $concur[$i]['is_row'] ); |
|
| 303 | + unset($concur[$i]['is_row']); |
|
| 304 | 304 | |
| 305 | 305 | $dotPos = strrpos($concur[$i]['price'], '.'); |
| 306 | 306 | $commaPos = strrpos($concur[$i]['price'], ','); |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | } else { |
| 311 | 311 | $concur[$i]['price'] = floatval( |
| 312 | 312 | preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], 0, $sep)) . '.' . |
| 313 | - preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep+1, strlen($concur[$i]['price']))) |
|
| 313 | + preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep + 1, strlen($concur[$i]['price']))) |
|
| 314 | 314 | ); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -318,51 +318,51 @@ discard block |
||
| 318 | 318 | $concur[$i]['price'] = $concur[$i]['price']; |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | - update_post_meta( $post_id, '_concur', $concur ); |
|
| 321 | + update_post_meta($post_id, '_concur', $concur); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // ------------------------------------------------------------------------------------------------------ |
| 325 | 325 | |
| 326 | - if( !empty($wps_product_quick_save) ) { |
|
| 327 | - $count_products_to_update = count( $wps_product_quick_save ); |
|
| 328 | - foreach( $wps_product_quick_save as $product_to_save ) { |
|
| 326 | + if (!empty($wps_product_quick_save)) { |
|
| 327 | + $count_products_to_update = count($wps_product_quick_save); |
|
| 328 | + foreach ($wps_product_quick_save as $product_to_save) { |
|
| 329 | 329 | $data_to_save = array(); |
| 330 | 330 | // Update post |
| 331 | - $updated_post = wp_update_post( array( 'ID' => $product_to_save, |
|
| 332 | - 'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ), |
|
| 333 | - 'post_content' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_content'] ), |
|
| 331 | + $updated_post = wp_update_post(array('ID' => $product_to_save, |
|
| 332 | + 'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']), |
|
| 333 | + 'post_content' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_content']), |
|
| 334 | 334 | ) |
| 335 | 335 | ); |
| 336 | 336 | // Update attributes |
| 337 | - if( !empty($updated_post) ) { |
|
| 337 | + if (!empty($updated_post)) { |
|
| 338 | 338 | // Update Featured picture |
| 339 | - if( !empty($wps_mass_interface[$product_to_save]['picture']) ) { |
|
| 340 | - $thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true ); |
|
| 341 | - if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 342 | - wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) ); |
|
| 343 | - update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] ); |
|
| 339 | + if (!empty($wps_mass_interface[$product_to_save]['picture'])) { |
|
| 340 | + $thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true); |
|
| 341 | + if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 342 | + wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post)); |
|
| 343 | + update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']); |
|
| 344 | 344 | } |
| 345 | - elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 346 | - delete_post_meta( $updated_post, '_thumbnail_id' ); |
|
| 345 | + elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 346 | + delete_post_meta($updated_post, '_thumbnail_id'); |
|
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | // Update files datas |
| 351 | - if( !empty($wps_mass_interface[$product_to_save]['files']) ) { |
|
| 352 | - $files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) ); |
|
| 353 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 354 | - foreach( $files_data as $file_id ) { |
|
| 355 | - if( !empty($file_id) ) { |
|
| 356 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) ); |
|
| 351 | + if (!empty($wps_mass_interface[$product_to_save]['files'])) { |
|
| 352 | + $files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files'])); |
|
| 353 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 354 | + foreach ($files_data as $file_id) { |
|
| 355 | + if (!empty($file_id)) { |
|
| 356 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post)); |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save ); |
|
| 363 | - $data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array(); |
|
| 362 | + $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save); |
|
| 363 | + $data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array(); |
|
| 364 | 364 | |
| 365 | - if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 365 | + if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 366 | 366 | // Get current barcode |
| 367 | 367 | $wps_product_mdl = new wps_product_mdl(); |
| 368 | 368 | $attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id; |
@@ -373,34 +373,34 @@ discard block |
||
| 373 | 373 | $data_to_save['user_ID'] = get_current_user_id(); |
| 374 | 374 | $data_to_save['action'] = 'editpost'; |
| 375 | 375 | |
| 376 | - if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) { |
|
| 377 | - wp_trash_post( $product_to_save ); |
|
| 376 | + if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") { |
|
| 377 | + wp_trash_post($product_to_save); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) { |
|
| 380 | + if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) { |
|
| 381 | 381 | $product_class = new wpshop_products(); |
| 382 | - $product_class->save_product_custom_informations( $product_to_save, $data_to_save ); |
|
| 382 | + $product_class->save_product_custom_informations($product_to_save, $data_to_save); |
|
| 383 | 383 | $total_updated_products++; |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | 388 | // Checking status |
| 389 | - $status = ( $total_updated_products == $count_products_to_update ) ? true : false; |
|
| 389 | + $status = ($total_updated_products == $count_products_to_update) ? true : false; |
|
| 390 | 390 | |
| 391 | - if( $status ) { |
|
| 392 | - $response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products ); |
|
| 391 | + if ($status) { |
|
| 392 | + $response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products); |
|
| 393 | 393 | } |
| 394 | 394 | else { |
| 395 | - if( !empty($total_updated_products) ) { |
|
| 396 | - $response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update ); |
|
| 395 | + if (!empty($total_updated_products)) { |
|
| 396 | + $response = sprintf(__('All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update); |
|
| 397 | 397 | } |
| 398 | 398 | else { |
| 399 | - $response = __( 'No product have been updated', 'wpshop'); |
|
| 399 | + $response = __('No product have been updated', 'wpshop'); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - echo json_encode( array('status' => $status, 'response' => $response ) ); |
|
| 403 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 404 | 404 | wp_die(); |
| 405 | 405 | } |
| 406 | 406 | |
@@ -408,18 +408,18 @@ discard block |
||
| 408 | 408 | * Delete product list |
| 409 | 409 | **/ |
| 410 | 410 | function wps_mass_delete_file() { |
| 411 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 411 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 412 | 412 | |
| 413 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) |
|
| 413 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file')) |
|
| 414 | 414 | wp_die(); |
| 415 | 415 | |
| 416 | 416 | $status = false; |
| 417 | - $file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null; |
|
| 418 | - if( !empty($file_id) ) { |
|
| 419 | - wp_update_post( array('ID' => $file_id, 'post_parent' => 0) ); |
|
| 417 | + $file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null; |
|
| 418 | + if (!empty($file_id)) { |
|
| 419 | + wp_update_post(array('ID' => $file_id, 'post_parent' => 0)); |
|
| 420 | 420 | $status = true; |
| 421 | 421 | } |
| 422 | - echo json_encode( array( 'status' => $status ) ); |
|
| 422 | + echo json_encode(array('status' => $status)); |
|
| 423 | 423 | wp_die(); |
| 424 | 424 | } |
| 425 | 425 | |
@@ -427,32 +427,32 @@ discard block |
||
| 427 | 427 | * Update product files list |
| 428 | 428 | */ |
| 429 | 429 | function wps_mass_edit_update_files_list() { |
| 430 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 430 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 431 | 431 | |
| 432 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) |
|
| 432 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list')) |
|
| 433 | 433 | wp_die(); |
| 434 | 434 | |
| 435 | 435 | $status = false; $response = ''; |
| 436 | - $product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null; |
|
| 437 | - $files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null; |
|
| 438 | - if( !empty($product_id ) ) { |
|
| 436 | + $product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null; |
|
| 437 | + $files = (!empty($_POST['files'])) ? intval($_POST['files']) : null; |
|
| 438 | + if (!empty($product_id)) { |
|
| 439 | 439 | // Update files datas |
| 440 | - if( !empty($files) ) { |
|
| 441 | - $files_data = explode( ',', $files ); |
|
| 442 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 443 | - foreach( $files_data as $file_id ) { |
|
| 444 | - if( !empty($file_id) ) { |
|
| 445 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) ); |
|
| 440 | + if (!empty($files)) { |
|
| 441 | + $files_data = explode(',', $files); |
|
| 442 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 443 | + foreach ($files_data as $file_id) { |
|
| 444 | + if (!empty($file_id)) { |
|
| 445 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id)); |
|
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
| 452 | - $response = $this->wps_product_attached_files( $product_id ); |
|
| 452 | + $response = $this->wps_product_attached_files($product_id); |
|
| 453 | 453 | $status = true; |
| 454 | 454 | } |
| 455 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 455 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 456 | 456 | wp_die(); |
| 457 | 457 | } |
| 458 | 458 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Billing module bootstrap file |
| 4 | 4 | * |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | /** Check if billing class does not exist before creating the class */ |
| 12 | -if ( !class_exists("wpshop_modules_billing") ) { |
|
| 12 | +if (!class_exists("wpshop_modules_billing")) { |
|
| 13 | 13 | /** |
| 14 | 14 | * Billing module utilities definition |
| 15 | 15 | * |
@@ -24,15 +24,15 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function __construct() { |
| 26 | 26 | /** Add custom template for current module */ |
| 27 | - add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) ); |
|
| 27 | + add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
| 28 | 28 | |
| 29 | 29 | /** In case wpshop is set on sale mode and not on view catalog only, Ad billign options */ |
| 30 | - if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) { |
|
| 31 | - $wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : ''; |
|
| 32 | - $old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : ''; |
|
| 30 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 31 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 32 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 33 | 33 | |
| 34 | - if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' ) |
|
| 35 | - && ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) { |
|
| 34 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 35 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 36 | 36 | /** Add module option to wpshop general options */ |
| 37 | 37 | add_filter('wpshop_options', array(&$this, 'add_options'), 9); |
| 38 | 38 | add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // Filter |
| 43 | - add_filter( 'wps_order_saving_admin_extra_action', array( $this, 'force_invoice_generation_on_order'), 50, 2 ); |
|
| 43 | + add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -50,17 +50,17 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return array The template with new elements |
| 52 | 52 | */ |
| 53 | - function custom_template_load( $templates ) { |
|
| 53 | + function custom_template_load($templates) { |
|
| 54 | 54 | include('templates/common/main_elements.tpl.php'); |
| 55 | 55 | $wpshop_template = $tpl_element; |
| 56 | 56 | /* Get custom frontend template */ |
| 57 | - if ( is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php') ) { |
|
| 57 | + if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) { |
|
| 58 | 58 | require_once(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php'); |
| 59 | 59 | if (!empty($tpl_element)) |
| 60 | - $wpshop_template['common']['custom'] = ($tpl_element);unset($tpl_element); |
|
| 60 | + $wpshop_template['common']['custom'] = ($tpl_element); unset($tpl_element); |
|
| 61 | 61 | } |
| 62 | 62 | $wpshop_display = new wpshop_display(); |
| 63 | - $templates = $wpshop_display->add_modules_template_to_internal( $wpshop_template, $templates ); |
|
| 63 | + $templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates); |
|
| 64 | 64 | |
| 65 | 65 | unset($tpl_element); |
| 66 | 66 | |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * Declare option groups for the module |
| 72 | 72 | */ |
| 73 | - function add_options( $option_group ) { |
|
| 73 | + function add_options($option_group) { |
|
| 74 | 74 | $option_group['wpshop_billing_info'] = |
| 75 | - array( 'label' => __('Billing', 'wpshop'), |
|
| 75 | + array('label' => __('Billing', 'wpshop'), |
|
| 76 | 76 | 'subgroups' => array( |
| 77 | 77 | 'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'), |
| 78 | 78 | ), |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * Declare the different options in groups for the module |
| 86 | 86 | */ |
| 87 | 87 | function declare_options() { |
| 88 | - add_settings_section('wpshop_billing_info','<span class="dashicons dashicons-admin-generic"></span>'. __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info'); |
|
| 88 | + add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info'); |
|
| 89 | 89 | |
| 90 | 90 | register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures')); |
| 91 | 91 | add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
@@ -94,30 +94,30 @@ discard block |
||
| 94 | 94 | add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
| 95 | 95 | add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
| 96 | 96 | |
| 97 | - $quotation_option = get_option( 'wpshop_addons' ); |
|
| 98 | - if ( !empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate']) ) { |
|
| 99 | - add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' .__('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info'); |
|
| 97 | + $quotation_option = get_option('wpshop_addons'); |
|
| 98 | + if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) { |
|
| 99 | + add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info'); |
|
| 100 | 100 | |
| 101 | 101 | register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time')); |
| 102 | 102 | add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
| 103 | 103 | $payment_option = get_option('wps_payment_mode'); |
| 104 | - if ( !empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active']) ) { |
|
| 104 | + if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) { |
|
| 105 | 105 | register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation')); |
| 106 | 106 | add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
| 107 | 107 | } |
| 108 | 108 | register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation')); |
| 109 | - add_settings_field('wpshop_payment_partial', __( 'Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 109 | + add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - function wpshop_options_validate_wpshop_bic_to_quotation ($input) { |
|
| 114 | + function wpshop_options_validate_wpshop_bic_to_quotation($input) { |
|
| 115 | 115 | return $input; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - function wpshop_bic_to_quotation_field () { |
|
| 118 | + function wpshop_bic_to_quotation_field() { |
|
| 119 | 119 | $add_quotation_option = get_option('wpshop_paymentMethod_options'); |
| 120 | - $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" ' .( ( !empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation']) ) ? 'checked="checked"' : ''). ' />'; |
|
| 120 | + $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />'; |
|
| 121 | 121 | echo $output; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -128,44 +128,44 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - function wpshop_options_validate_quotation_validate_time ($input) { |
|
| 131 | + function wpshop_options_validate_quotation_validate_time($input) { |
|
| 132 | 132 | return $input; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function wpshop_billing_number_figures_field() { |
| 136 | 136 | $wpshop_billing_number_figures = get_option('wpshop_billing_number_figures'); |
| 137 | - $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"': null; |
|
| 138 | - if(empty($wpshop_billing_number_figures)) $wpshop_billing_number_figures=5; |
|
| 137 | + $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null; |
|
| 138 | + if (empty($wpshop_billing_number_figures)) $wpshop_billing_number_figures = 5; |
|
| 139 | 139 | |
| 140 | - echo '<input name="wpshop_billing_number_figures" type="text" value="'.$wpshop_billing_number_figures.'" '.$readonly.' /> |
|
| 141 | - <a href="#" title="'.__('Number of figures to make appear on invoices','wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
|
| 140 | + echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' /> |
|
| 141 | + <a href="#" title="'.__('Number of figures to make appear on invoices', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>'; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - function wpshop_options_validate_billing_number_figures( $input ) { |
|
| 144 | + function wpshop_options_validate_billing_number_figures($input) { |
|
| 145 | 145 | return $input; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - function wpshop_billing_address_validator( $input ){ |
|
| 148 | + function wpshop_billing_address_validator($input) { |
|
| 149 | 149 | global $wpdb; |
| 150 | - $t = wps_address::get_addresss_form_fields_by_type ( $input['choice'] ); |
|
| 150 | + $t = wps_address::get_addresss_form_fields_by_type($input['choice']); |
|
| 151 | 151 | |
| 152 | 152 | $the_code = ''; |
| 153 | - foreach( $t[$input['choice']] as $group_id => $group_def ) { |
|
| 154 | - if ( !empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists( $input['integrate_into_register_form_matching_field']['user_email'], $group_def['content']) ) { |
|
| 153 | + foreach ($t[$input['choice']] as $group_id => $group_def) { |
|
| 154 | + if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) { |
|
| 155 | 155 | $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name']; |
| 156 | 156 | continue; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | $the_code; |
| 160 | 160 | |
| 161 | - if ( !empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes' ) { |
|
| 162 | - if ( !empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { |
|
| 161 | + if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') { |
|
| 162 | + if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { |
|
| 163 | 163 | $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code)); |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 168 | - if( !empty($billing_option) && !empty( $billing_option['display_model'] ) ) { |
|
| 167 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 168 | + if (!empty($billing_option) && !empty($billing_option['display_model'])) { |
|
| 169 | 169 | $input['display_model'] = $billing_option['display_model']; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $wpshop_billing_address = get_option('wpshop_billing_address'); |
| 180 | 180 | |
| 181 | - $query = $wpdb->prepare('SELECT ID FROM ' .$wpdb->posts. ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 181 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 182 | 182 | $entity_id = $wpdb->get_var($query); |
| 183 | 183 | |
| 184 | - $query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $entity_id); |
|
| 184 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 185 | 185 | $content = $wpdb->get_results($query); |
| 186 | 186 | |
| 187 | 187 | /* Field for billing address type choice */ |
@@ -190,21 +190,21 @@ discard block |
||
| 190 | 190 | $input_def['possible_value'] = $content; |
| 191 | 191 | $input_def['type'] = 'select'; |
| 192 | 192 | $input_def['value'] = $wpshop_billing_address['choice']; |
| 193 | - $output .= '<div>' .wpshop_form::check_input_type($input_def). '</div>'; |
|
| 193 | + $output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>'; |
|
| 194 | 194 | |
| 195 | 195 | /* Field for integrate billign form into register form */ |
| 196 | 196 | $input_def = array(); |
| 197 | 197 | $input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]'; |
| 198 | 198 | $input_def['id'] = 'wpshop_billing_address_integrate_into_register_form'; |
| 199 | - $input_def['possible_value'] = array( 'yes' => __('Integrate billing form into register form', 'wpshop') ); |
|
| 199 | + $input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop')); |
|
| 200 | 200 | $input_def['valueToPut'] = 'index'; |
| 201 | 201 | $input_def['options_label']['original'] = true; |
| 202 | 202 | $input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" '; |
| 203 | 203 | $input_def['type'] = 'checkbox'; |
| 204 | - $input_def['value'] = array( !empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : '' ); |
|
| 204 | + $input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : ''); |
|
| 205 | 205 | $output .= ' |
| 206 | 206 | <div class="wpshop_include_billing_form_into_register_container" > |
| 207 | - ' .wpshop_form::check_input_type($input_def). ' |
|
| 207 | + ' .wpshop_form::check_input_type($input_def) . ' |
|
| 208 | 208 | <input type="hidden" name="wpshop_ajax_integrate_billin_into_register" id="wpshop_ajax_integrate_billin_into_register" value="' . wp_create_nonce('wpshop_ajax_integrate_billin_into_register') . '" /> |
| 209 | 209 | <input type="hidden" name="wpshop_include_billing_form_into_register_where_value" id="wpshop_include_billing_form_into_register_where_value" value="' . (!empty($wpshop_billing_address['integrate_into_register_form_after_field']) ? $wpshop_billing_address['integrate_into_register_form_after_field'] : '') . '" /> |
| 210 | 210 | <div class="wpshop_include_billing_form_into_register_where" ></div> |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - function wpshop_quotation_validate_time_field () { |
|
| 220 | + function wpshop_quotation_validate_time_field() { |
|
| 221 | 221 | $quotation_option = get_option('wpshop_quotation_validate_time'); |
| 222 | - $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' .( ( !empty($quotation_option) && !empty($quotation_option['number']) ) ? $quotation_option['number'] : null ). '" />'; |
|
| 222 | + $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />'; |
|
| 223 | 223 | $output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">'; |
| 224 | - $output .= '<option value="day" ' .( ( !empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : ''). '>' .__('Days', 'wpshop'). '</option>'; |
|
| 225 | - $output .= '<option value="month" ' .( ( !empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : ''). '>' .__('Months', 'wpshop'). '</option>'; |
|
| 226 | - $output .= '<option value="year" ' .( ( !empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : ''). '>' .__('Years', 'wpshop'). '</option>'; |
|
| 224 | + $output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>'; |
|
| 225 | + $output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>'; |
|
| 226 | + $output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>'; |
|
| 227 | 227 | $output .= '</select>'; |
| 228 | 228 | |
| 229 | 229 | echo $output; |
@@ -236,19 +236,19 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return string The new invoice number |
| 238 | 238 | */ |
| 239 | - public static function generate_invoice_number( $order_id ) { |
|
| 239 | + public static function generate_invoice_number($order_id) { |
|
| 240 | 240 | /** Get configuration about the number of figure dor invoice number */ |
| 241 | 241 | |
| 242 | 242 | $number_figures = get_option('wpshop_billing_number_figures', false); |
| 243 | 243 | |
| 244 | 244 | /** If the number doesn't exist, we create a default one */ |
| 245 | - if(!$number_figures) { |
|
| 245 | + if (!$number_figures) { |
|
| 246 | 246 | update_option('wpshop_billing_number_figures', 5); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** sleep my script, SLEEP I SAY ! **/ |
| 250 | - $rand_time = rand( 1000, 200000 ); |
|
| 251 | - usleep( $rand_time ); |
|
| 250 | + $rand_time = rand(1000, 200000); |
|
| 251 | + usleep($rand_time); |
|
| 252 | 252 | /** GET UP !! **/ |
| 253 | 253 | |
| 254 | 254 | /** Get last invoice number */ |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | /** Check if number exists **/ |
| 266 | 266 | $billing_current_number_checking = get_option('wpshop_billing_current_number', false); |
| 267 | - if ( $billing_current_number_checking == $billing_current_number ) { |
|
| 267 | + if ($billing_current_number_checking == $billing_current_number) { |
|
| 268 | 268 | $billing_current_number++; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | update_option('wpshop_billing_current_number', $billing_current_number); |
| 272 | 272 | |
| 273 | 273 | /** Create the new invoice number with all parameters viewed above */ |
| 274 | - $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string)sprintf('%0'.$number_figures.'d', $billing_current_number)); |
|
| 274 | + $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string)sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 275 | 275 | |
| 276 | 276 | return $invoice_ref; |
| 277 | 277 | } |
@@ -285,67 +285,67 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return string The invoice output in case no error is found. The error in other case |
| 287 | 287 | */ |
| 288 | - public static function generate_html_invoice( $order_id, $invoice_ref ) { |
|
| 288 | + public static function generate_html_invoice($order_id, $invoice_ref) { |
|
| 289 | 289 | global $wpdb; |
| 290 | 290 | |
| 291 | - $date_output_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
|
| 291 | + $date_output_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 292 | 292 | $count_products = 0; |
| 293 | 293 | |
| 294 | - if ( !empty($order_id) ) { |
|
| 294 | + if (!empty($order_id)) { |
|
| 295 | 295 | $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
| 296 | 296 | |
| 297 | 297 | $discounts_exists = false; |
| 298 | 298 | |
| 299 | - $is_quotation = ( empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null ) ? true : false; |
|
| 299 | + $is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false; |
|
| 300 | 300 | /** Check if it's a partial payment bill **/ |
| 301 | 301 | $is_partial_payment = false; |
| 302 | - if( isset( $order_postmeta['order_payment']['received'] ) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid' ) { |
|
| 303 | - foreach( $order_postmeta['order_payment']['received'] as $key => $payment ) { |
|
| 304 | - if( isset( $payment['invoice_ref'] ) && $payment['invoice_ref'] == $invoice_ref ) { |
|
| 302 | + if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 303 | + foreach ($order_postmeta['order_payment']['received'] as $key => $payment) { |
|
| 304 | + if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) { |
|
| 305 | 305 | $is_partial_payment = true; |
| 306 | 306 | break; |
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | - } elseif( !empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref ) { |
|
| 309 | + } elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) { |
|
| 310 | 310 | $is_partial_payment = true; |
| 311 | - } elseif( empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid' ) { |
|
| 311 | + } elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 312 | 312 | $is_partial_payment = true; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** Check it is a shipping slip **/ |
| 316 | - $bon_colisage = !empty( $_GET['bon_colisage'] ) ? sanitize_key( $_GET['bon_colisage'] ) : false; |
|
| 317 | - if ( $bon_colisage ) $bon_colisage = true; |
|
| 316 | + $bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false; |
|
| 317 | + if ($bon_colisage) $bon_colisage = true; |
|
| 318 | 318 | |
| 319 | - if ( !empty($order_postmeta) ) { |
|
| 319 | + if (!empty($order_postmeta)) { |
|
| 320 | 320 | $tpl_component = array(); |
| 321 | 321 | |
| 322 | 322 | /** Billing Header **/ |
| 323 | 323 | //Logo |
| 324 | 324 | $logo_options = get_option('wpshop_logo'); |
| 325 | - $tpl_component['INVOICE_LOGO'] = ( !empty($logo_options) ) ? '<img src="' .str_replace( 'https', 'http', $logo_options ) .'" alt="" />' : ''; |
|
| 325 | + $tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : ''; |
|
| 326 | 326 | |
| 327 | 327 | // Title |
| 328 | - $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : ( ( $is_quotation ) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop') ); |
|
| 328 | + $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop')); |
|
| 329 | 329 | |
| 330 | 330 | // if ( empty($order_postmeta['order_invoice_ref']) ) { |
| 331 | 331 | // $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop'); |
| 332 | 332 | // $is_partial_payment = true; |
| 333 | 333 | // } |
| 334 | 334 | |
| 335 | - if ( $bon_colisage ) { |
|
| 336 | - $tpl_component['INVOICE_TITLE'] = __( 'Products List', 'wpshop' ); |
|
| 335 | + if ($bon_colisage) { |
|
| 336 | + $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop'); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - $tpl_component['INVOICE_ORDER_INVOICE_REF'] = ( !empty($invoice_ref) ) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null); |
|
| 340 | - if ( $bon_colisage ) { |
|
| 339 | + $tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null); |
|
| 340 | + if ($bon_colisage) { |
|
| 341 | 341 | $tpl_component['INVOICE_ORDER_INVOICE_REF'] = ''; |
| 342 | 342 | } |
| 343 | - $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ( $is_quotation ) ? sprintf( __('Ref. %s', 'wpshop'),$order_postmeta['order_temporary_key']) : sprintf( __('Order n. %s', 'wpshop'), $order_postmeta['order_key'] ); |
|
| 344 | - $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ( $is_quotation ) ? sprintf( __('Quotation date %s', 'wpshop'), mysql2date($date_output_format ,$order_postmeta['order_date'], true) ) : sprintf( __('Order date %s', 'wpshop'), mysql2date($date_output_format ,$order_postmeta['order_date'], true) ); |
|
| 343 | + $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']); |
|
| 344 | + $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)); |
|
| 345 | 345 | |
| 346 | 346 | /** Validate period for Quotation **/ |
| 347 | - if ( $is_quotation ) { |
|
| 348 | - $quotation_validate_period = self::quotation_validate_period( $order_postmeta['order_date'] ); |
|
| 347 | + if ($is_quotation) { |
|
| 348 | + $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']); |
|
| 349 | 349 | } |
| 350 | 350 | else { |
| 351 | 351 | $tpl_component['INVOICE_VALIDATE_TIME'] = ''; |
@@ -353,22 +353,22 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME']; |
| 355 | 355 | |
| 356 | - $tpl_component['AMOUNT_INFORMATION'] = ( !$bon_colisage ) ? sprintf( __('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency( true ) ) : ''; |
|
| 356 | + $tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : ''; |
|
| 357 | 357 | |
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | // Sender & receiver addresses |
| 361 | 361 | $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part( ); |
| 362 | - $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part( $order_id, $bon_colisage ); |
|
| 362 | + $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage); |
|
| 363 | 363 | |
| 364 | 364 | $tpl_component['INVOICE_TRACKING'] = ''; |
| 365 | 365 | $first = false; |
| 366 | - if( !empty($order_postmeta['order_trackingNumber']) ) { |
|
| 366 | + if (!empty($order_postmeta['order_trackingNumber'])) { |
|
| 367 | 367 | $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber']; |
| 368 | 368 | $first = true; |
| 369 | 369 | } |
| 370 | - if( !empty($order_postmeta['order_trackingLink']) ) { |
|
| 371 | - if( !$first ) { |
|
| 370 | + if (!empty($order_postmeta['order_trackingLink'])) { |
|
| 371 | + if (!$first) { |
|
| 372 | 372 | $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink']; |
| 373 | 373 | } else { |
| 374 | 374 | $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink']; |
@@ -378,22 +378,22 @@ discard block |
||
| 378 | 378 | |
| 379 | 379 | /** Items Tab **/ |
| 380 | 380 | $order_tva = array(); |
| 381 | - if ( $bon_colisage ) { |
|
| 381 | + if ($bon_colisage) { |
|
| 382 | 382 | $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common'); |
| 383 | 383 | } |
| 384 | 384 | else { |
| 385 | 385 | $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common'); |
| 386 | 386 | //if ( !$is_quotation ) { |
| 387 | 387 | /** Check if products have discounts **/ |
| 388 | - if ( !empty($order_postmeta['order_items']) && !$is_partial_payment ) { |
|
| 389 | - foreach( $order_postmeta['order_items'] as $item_id => $item ) { |
|
| 390 | - if ( !empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value']) ) { |
|
| 388 | + if (!empty($order_postmeta['order_items']) && !$is_partial_payment) { |
|
| 389 | + foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 390 | + if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) { |
|
| 391 | 391 | $discounts_exists = true; |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( $discounts_exists ) { |
|
| 396 | + if ($discounts_exists) { |
|
| 397 | 397 | $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common'); |
| 398 | 398 | } |
| 399 | 399 | |
@@ -403,119 +403,119 @@ discard block |
||
| 403 | 403 | $total_discounted = 0; |
| 404 | 404 | $tpl_component['INVOICE_ROWS'] = ''; |
| 405 | 405 | |
| 406 | - if( !$is_partial_payment ) { |
|
| 407 | - if ( !empty($order_postmeta['order_items']) ) { |
|
| 408 | - foreach( $order_postmeta['order_items'] as $item_id => $item ) { |
|
| 406 | + if (!$is_partial_payment) { |
|
| 407 | + if (!empty($order_postmeta['order_items'])) { |
|
| 408 | + foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 409 | 409 | $sub_tpl_component = array(); |
| 410 | 410 | $count_products += $item['item_qty']; |
| 411 | - $barcode = get_post_meta( $item['item_id'], '_barcode', true ); |
|
| 412 | - if ( empty($barcode) ) { |
|
| 413 | - $product_metadata = get_post_meta( $item['item_id'], '_wpshop_product_metadata', true ); |
|
| 414 | - $barcode = ( !empty($product_metadata) && !empty($product_metadata['barcode']) ) ? $product_metadata['barcode'] : ''; |
|
| 415 | - |
|
| 416 | - if( empty($barcode) ) { |
|
| 417 | - $product_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 418 | - $att_def = wpshop_attributes::getElement( 'barcode', '"valid"', 'code' ); |
|
| 419 | - $query = $wpdb->prepare( 'SELECT value FROM ' .$wpdb->prefix. 'wpshop__attribute_value_'.$att_def->data_type. ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id'] ); |
|
| 420 | - $barcode = $wpdb->get_var( $query ); |
|
| 411 | + $barcode = get_post_meta($item['item_id'], '_barcode', true); |
|
| 412 | + if (empty($barcode)) { |
|
| 413 | + $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true); |
|
| 414 | + $barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : ''; |
|
| 415 | + |
|
| 416 | + if (empty($barcode)) { |
|
| 417 | + $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 418 | + $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code'); |
|
| 419 | + $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']); |
|
| 420 | + $barcode = $wpdb->get_var($query); |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | - $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = ( !empty($barcode) ) ? $barcode : '-'; |
|
| 423 | + $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-'; |
|
| 424 | 424 | |
| 425 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = ( !empty($barcode) ) ? $barcode : $item['item_ref']; |
|
| 425 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref']; |
|
| 426 | 426 | |
| 427 | 427 | /** Item name **/ |
| 428 | 428 | $is_variation = false; |
| 429 | - if( get_post_type( $item['item_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 429 | + if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 430 | 430 | $is_variation = true; |
| 431 | - $parent_def = wpshop_products::get_parent_variation( $item['item_id'] ); |
|
| 432 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 431 | + $parent_def = wpshop_products::get_parent_variation($item['item_id']); |
|
| 432 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 433 | 433 | $parent_post = $parent_def['parent_post']; |
| 434 | 434 | $item_parent_id = $parent_post->ID; |
| 435 | - $item_title = $parent_post->post_title; |
|
| 435 | + $item_title = $parent_post->post_title; |
|
| 436 | 436 | } |
| 437 | 437 | } else { |
| 438 | 438 | $item_title = $item['item_name']; |
| 439 | 439 | } |
| 440 | 440 | $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title; |
| 441 | 441 | /** Get attribute order for current product */ |
| 442 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails( get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true) ) ; |
|
| 442 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 443 | 443 | $output_order = array(); |
| 444 | - if ( count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail) ) { |
|
| 445 | - foreach ( $product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 446 | - foreach ( $product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 447 | - if ( !empty($attribute_def->code) ) |
|
| 444 | + if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 445 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 446 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 447 | + if (!empty($attribute_def->code)) |
|
| 448 | 448 | $output_order[$attribute_def->code] = $position; |
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display( $item['item_meta'], $output_order, 'invoice_print', 'common'); |
|
| 452 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common'); |
|
| 453 | 453 | ksort($variation_attribute_ordered['attribute_list']); |
| 454 | 454 | $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = ''; |
| 455 | - foreach ( $variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output ) { |
|
| 455 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 456 | 456 | $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output; |
| 457 | 457 | } |
| 458 | - if( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/ ! empty( get_post_field( 'post_content', $item['item_id'] ) ) ) { |
|
| 459 | - if ( ! empty( $detail_tpl_component['CART_PRODUCT_MORE_INFO'] ) ) { |
|
| 458 | + if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/ !empty(get_post_field('post_content', $item['item_id'])) ) { |
|
| 459 | + if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) { |
|
| 460 | 460 | //$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>'; |
| 461 | 461 | } |
| 462 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br( get_post_field( 'post_content', $item['item_id'] ) ) . '</span>'; |
|
| 462 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>'; |
|
| 463 | 463 | } |
| 464 | 464 | $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : ''; |
| 465 | - unset( $detail_tpl_component ); |
|
| 465 | + unset($detail_tpl_component); |
|
| 466 | 466 | |
| 467 | 467 | $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty']; |
| 468 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ( ( !empty($item['item_pu_ttc_before_discount']) ) ? number_format( $item['item_pu_ttc_before_discount'], 2, '.', '' ) : number_format( $item['item_pu_ttc'], 2, '.', '' ) ); |
|
| 469 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ( ( !empty($item['item_pu_ht_before_discount']) ) ? number_format( $item['item_pu_ht_before_discount'], 2, '.', '' ) : number_format( $item['item_pu_ht'], 2, '.', '' ) ); |
|
| 470 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = ( !empty($item['item_discount_value']) ) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', '' ); |
|
| 471 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format( ($item['item_pu_ht'] * $item['item_qty']), 2, '.', '' ); |
|
| 468 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', '')); |
|
| 469 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', '')); |
|
| 470 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', ''); |
|
| 471 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', ''); |
|
| 472 | 472 | /** TVA **/ |
| 473 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', '' ); |
|
| 473 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', ''); |
|
| 474 | 474 | $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate']; |
| 475 | 475 | |
| 476 | 476 | |
| 477 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format( $item['item_total_ttc'], 2, '.', '' ); |
|
| 477 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', ''); |
|
| 478 | 478 | |
| 479 | 479 | |
| 480 | 480 | /** Checking Rate amount **/ |
| 481 | - if ( !$bon_colisage ) { |
|
| 482 | - $checking = self::check_product_price( $item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id ); |
|
| 483 | - if( !$checking ) { |
|
| 481 | + if (!$bon_colisage) { |
|
| 482 | + $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id); |
|
| 483 | + if (!$checking) { |
|
| 484 | 484 | return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop'); |
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if ( $bon_colisage ) { |
|
| 488 | + if ($bon_colisage) { |
|
| 489 | 489 | $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common'); |
| 490 | 490 | } |
| 491 | 491 | else { |
| 492 | - if ( $discounts_exists ) { |
|
| 492 | + if ($discounts_exists) { |
|
| 493 | 493 | $discounted_total_per_item = $item['item_total_ht']; |
| 494 | 494 | /** Unit Discount **/ |
| 495 | - if ( !empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value']) ) { |
|
| 496 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format( $item['item_unit_discount_amount'], 2, '.', ''); |
|
| 497 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format( $item['item_unit_discount_value'], 2, '.', ''); |
|
| 495 | + if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) { |
|
| 496 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', ''); |
|
| 497 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', ''); |
|
| 498 | 498 | $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount']; |
| 499 | 499 | } |
| 500 | 500 | else { |
| 501 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format( 0, 2, '.', ''); |
|
| 502 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format( 0, 2, '.', ''); |
|
| 501 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 502 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** Global Discount **/ |
| 506 | - if ( !empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value']) ) { |
|
| 507 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format( $item['item_global_discount_amount'], 2, '.', ''); |
|
| 508 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format( $item['item_global_discount_value'], 2, '.', ''); |
|
| 506 | + if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) { |
|
| 507 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', ''); |
|
| 508 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', ''); |
|
| 509 | 509 | $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount']; |
| 510 | 510 | } |
| 511 | 511 | else { |
| 512 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format( 0, 2, '.', ''); |
|
| 513 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format( 0, 2, '.', ''); |
|
| 512 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 513 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | $total_discounted += $discounted_total_per_item; |
| 517 | 517 | /** Total HT Discounted **/ |
| 518 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format( $discounted_total_per_item, 2, '.', ''); |
|
| 518 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', ''); |
|
| 519 | 519 | |
| 520 | 520 | $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
| 521 | 521 | } |
@@ -523,14 +523,14 @@ discard block |
||
| 523 | 523 | $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | - unset( $sub_tpl_component ); |
|
| 526 | + unset($sub_tpl_component); |
|
| 527 | 527 | |
| 528 | 528 | /** Check TVA **/ |
| 529 | - if ( empty($order_tva[ $item['item_tva_rate'] ]) ) { |
|
| 530 | - $order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount']; |
|
| 529 | + if (empty($order_tva[$item['item_tva_rate']])) { |
|
| 530 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 531 | 531 | } |
| 532 | 532 | else { |
| 533 | - $order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount']; |
|
| 533 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | } |
@@ -541,33 +541,33 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | /** Display Partials payments **/ |
| 543 | 543 | $total_partial_payment = 0; $last_payment = 0; |
| 544 | - $order_invoice_ref = ( !empty($order_postmeta['order_invoice_ref']) ) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 545 | - if ( !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage ) { |
|
| 546 | - foreach( $order_postmeta['order_payment']['received'] as $received_payment ) { |
|
| 547 | - if ( !empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref ) { |
|
| 548 | - if ( intval( substr($received_payment['invoice_ref'], 2) ) == intval( substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2) )) { |
|
| 544 | + $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 545 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 546 | + foreach ($order_postmeta['order_payment']['received'] as $received_payment) { |
|
| 547 | + if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) { |
|
| 548 | + if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) { |
|
| 549 | 549 | $sub_tpl_component = array(); |
| 550 | 550 | $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
| 551 | 551 | |
| 552 | 552 | /** Item name **/ |
| 553 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf( __('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __( $received_payment['method'], 'wpshop'), $received_payment['payment_reference']); |
|
| 553 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']); |
|
| 554 | 554 | $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
| 555 | 555 | $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
| 556 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format( $received_payment['received_amount'], 2, '.', '' ); |
|
| 557 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '' ); |
|
| 558 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format( $received_payment['received_amount'], 2, '.', '' ); |
|
| 556 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 557 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 558 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 559 | 559 | |
| 560 | 560 | /** TVA **/ |
| 561 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '' ); |
|
| 561 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 562 | 562 | $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
| 563 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format( $received_payment['received_amount'], 2, '.', '' ); |
|
| 563 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 564 | 564 | |
| 565 | - if ( $discounts_exists ) { |
|
| 566 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-'.number_format( $received_payment['received_amount'], 2, '.', ''); |
|
| 567 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format( 0, 2, '.', ''); |
|
| 568 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format( 0, 2, '.', ''); |
|
| 569 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format( 0, 2, '.', ''); |
|
| 570 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format( 0, 2, '.', ''); |
|
| 565 | + if ($discounts_exists) { |
|
| 566 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 567 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 568 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 569 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 570 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 571 | 571 | |
| 572 | 572 | $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
| 573 | 573 | } |
@@ -576,11 +576,11 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - unset( $sub_tpl_component ); |
|
| 580 | - $total_partial_payment += ( !empty($received_payment['received_amount']) ) ? $received_payment['received_amount'] : 0; |
|
| 579 | + unset($sub_tpl_component); |
|
| 580 | + $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 581 | 581 | } |
| 582 | - else if( 'payment_received' == $received_payment[ 'status' ] ) { |
|
| 583 | - $last_payment += ( !empty($received_payment['received_amount']) ) ? $received_payment['received_amount'] : 0; |
|
| 582 | + else if ('payment_received' == $received_payment['status']) { |
|
| 583 | + $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | } |
@@ -589,24 +589,24 @@ discard block |
||
| 589 | 589 | else { |
| 590 | 590 | /** Display Partials payments **/ |
| 591 | 591 | $total_partial_payment = 0; $last_payment = 0; |
| 592 | - if ( !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage ) { |
|
| 593 | - foreach( $order_postmeta['order_payment']['received'] as $key => $received_payment ) { |
|
| 594 | - if ( !empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref ) { |
|
| 592 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 593 | + foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) { |
|
| 594 | + if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) { |
|
| 595 | 595 | $sub_tpl_component = array(); |
| 596 | 596 | $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
| 597 | 597 | /** Item name **/ |
| 598 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf( __('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __( $received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key+1); |
|
| 598 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1); |
|
| 599 | 599 | $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
| 600 | 600 | $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
| 601 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format( $received_payment['received_amount'], 2, '.', '' ); |
|
| 602 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '' ); |
|
| 603 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format( $received_payment['received_amount'], 2, '.', '' ); |
|
| 601 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 602 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 603 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 604 | 604 | /** TVA **/ |
| 605 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '' ); |
|
| 605 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 606 | 606 | $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
| 607 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format( $received_payment['received_amount'], 2, '.', '' ); |
|
| 607 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 608 | 608 | $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
| 609 | - unset( $sub_tpl_component ); |
|
| 609 | + unset($sub_tpl_component); |
|
| 610 | 610 | $total_partial_payment += $received_payment['received_amount']; |
| 611 | 611 | } |
| 612 | 612 | } |
@@ -619,126 +619,126 @@ discard block |
||
| 619 | 619 | /** Summary of order **/ |
| 620 | 620 | $summary_tpl_component = array(); |
| 621 | 621 | $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = ''; |
| 622 | - if ( !$bon_colisage ) { |
|
| 623 | - if ( !empty( $order_tva ) ) { |
|
| 624 | - foreach( $order_tva as $tax_rate => $tax_amount ) { |
|
| 625 | - if ( $tax_amount > 0 ) { |
|
| 626 | - $tax_rate = ( !empty($tax_rate) && $tax_rate == 'VAT_shipping_cost' ) ? __('on Shipping cost', 'wpshop').' '.WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate; |
|
| 627 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf( __('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%' ); |
|
| 622 | + if (!$bon_colisage) { |
|
| 623 | + if (!empty($order_tva)) { |
|
| 624 | + foreach ($order_tva as $tax_rate => $tax_amount) { |
|
| 625 | + if ($tax_amount > 0) { |
|
| 626 | + $tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate; |
|
| 627 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 628 | 628 | $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
| 629 | 629 | $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
| 630 | - unset( $sub_tpl_component ); |
|
| 630 | + unset($sub_tpl_component); |
|
| 631 | 631 | } |
| 632 | - elseif( $is_partial_payment ) { |
|
| 632 | + elseif ($is_partial_payment) { |
|
| 633 | 633 | $tax_rate = 0; |
| 634 | - $tax_amount = number_format( 0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 635 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf( __('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%' ); |
|
| 634 | + $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 635 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 636 | 636 | $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
| 637 | 637 | $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
| 638 | - unset( $sub_tpl_component ); |
|
| 638 | + unset($sub_tpl_component); |
|
| 639 | 639 | } |
| 640 | 640 | } |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** If Discount Exist **/ |
| 644 | 644 | // Checking Discounts on order |
| 645 | - if( !empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value'] ) { |
|
| 645 | + if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) { |
|
| 646 | 646 | $discounts_exists = true; |
| 647 | 647 | // Calcul discount on Order |
| 648 | - switch( $order_postmeta['order_discount_type'] ) { |
|
| 648 | + switch ($order_postmeta['order_discount_type']) { |
|
| 649 | 649 | case 'amount': |
| 650 | - $total_discounted += number_format( str_replace( ',', '.', $order_postmeta['order_discount_value'] ), 2, '.', '' ); |
|
| 650 | + $total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', ''); |
|
| 651 | 651 | break; |
| 652 | 652 | case 'percent': |
| 653 | - $total_discounted += number_format( $order_postmeta['order_grand_total_before_discount'], 2, '.', '') * ( number_format( str_replace( ',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100 ); |
|
| 653 | + $total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100); |
|
| 654 | 654 | break; |
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | - if ( !empty($total_discounted) && $discounts_exists ) { |
|
| 657 | + if (!empty($total_discounted) && $discounts_exists) { |
|
| 658 | 658 | $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop'); |
| 659 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format( $total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 659 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 660 | 660 | $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
| 661 | - unset( $sub_tpl_component ); |
|
| 661 | + unset($sub_tpl_component); |
|
| 662 | 662 | } |
| 663 | 663 | else { |
| 664 | 664 | $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = ''; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | $shipping_cost = 0; |
| 668 | - if ( !$is_partial_payment ) { |
|
| 669 | - if( !empty($order_postmeta['order_shipping_cost']) ) { |
|
| 668 | + if (!$is_partial_payment) { |
|
| 669 | + if (!empty($order_postmeta['order_shipping_cost'])) { |
|
| 670 | 670 | $shipping_cost = $order_postmeta['order_shipping_cost']; |
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | - $price_piloting = get_option( 'wpshop_shop_price_piloting', 'TTC' ); |
|
| 674 | - $shipping_taxes = 'HT' == $price_piloting ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * $shipping_cost : $shipping_cost - ( $shipping_cost / ( 1 + WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ); |
|
| 675 | - $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format( $shipping_cost, 2, ',', '' ); |
|
| 676 | - $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format( $shipping_taxes, 2, ',', '' ); |
|
| 673 | + $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC'); |
|
| 674 | + $shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100)); |
|
| 675 | + $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', ''); |
|
| 676 | + $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', ''); |
|
| 677 | 677 | //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' ); |
| 678 | 678 | |
| 679 | - $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ( $is_partial_payment ) ? number_format(0, 2, ',', '' ) : number_format( $order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' ); |
|
| 680 | - $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ( $is_partial_payment ) ? number_format(0, 2, ',', '' ) : number_format( $order_postmeta['order_total_ht'], 2, ',', '' ); |
|
| 679 | + $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' ); |
|
| 680 | + $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', ''); |
|
| 681 | 681 | |
| 682 | 682 | $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
| 683 | 683 | |
| 684 | 684 | $total_payment = 0; |
| 685 | 685 | |
| 686 | 686 | /** Amount paid **/ |
| 687 | - if ( empty($order_postmeta['order_invoice_ref']) ) { |
|
| 687 | + if (empty($order_postmeta['order_invoice_ref'])) { |
|
| 688 | 688 | foreach ($order_postmeta['order_payment']['received'] as $key => $value) { |
| 689 | - if ( !empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF'] ) { |
|
| 689 | + if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) { |
|
| 690 | 690 | $total_payment = number_format($value['received_amount'], 2, ',', ''); |
| 691 | 691 | } |
| 692 | 692 | } |
| 693 | 693 | } |
| 694 | 694 | else { |
| 695 | - $total_payment = ( ($total_partial_payment+$last_payment) !== $order_postmeta['order_grand_total'] ) ? number_format($total_partial_payment+$last_payment, 2, ',', '') : $order_postmeta['order_grand_total']; |
|
| 695 | + $total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total']; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop'); |
| 699 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = ( !$is_partial_payment ) ? number_format( $last_payment, 2, ',', '') .' ' . wpshop_tools::wpshop_get_currency() : $total_payment .' ' . wpshop_tools::wpshop_get_currency(); |
|
| 699 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 700 | 700 | //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ? number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
| 701 | 701 | $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
| 702 | - unset( $sub_tpl_component ); |
|
| 702 | + unset($sub_tpl_component); |
|
| 703 | 703 | |
| 704 | 704 | $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop'); |
| 705 | 705 | $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products; |
| 706 | 706 | $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
| 707 | - unset( $sub_tpl_component ); |
|
| 707 | + unset($sub_tpl_component); |
|
| 708 | 708 | |
| 709 | 709 | |
| 710 | 710 | /** If Discount Exist **/ |
| 711 | - if ( !empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value']) ) { |
|
| 711 | + if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) { |
|
| 712 | 712 | $tpl_discount_component = array(); |
| 713 | 713 | $tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', ''); |
| 714 | 714 | |
| 715 | 715 | $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
| 716 | 716 | $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common'); |
| 717 | - unset( $tpl_discount_component ); |
|
| 717 | + unset($tpl_discount_component); |
|
| 718 | 718 | } |
| 719 | 719 | else { |
| 720 | 720 | $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = ''; |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | - $summary_tpl_component[ 'PRICE_PILOTING' ] = 'HT' == $price_piloting ? __( 'ET', 'wpshop' ) : __( 'ATI', 'wpshop' ); |
|
| 723 | + $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop'); |
|
| 724 | 724 | |
| 725 | 725 | $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common'); |
| 726 | - unset( $summary_tpl_component ); |
|
| 726 | + unset($summary_tpl_component); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | |
| 730 | 730 | /** IBAN Include on quotation **/ |
| 731 | - if ( $is_quotation ) { |
|
| 731 | + if ($is_quotation) { |
|
| 732 | 732 | /** If admin want to include his IBAN to quotation */ |
| 733 | 733 | $iban_options = get_option('wpshop_paymentMethod_options'); |
| 734 | 734 | $payment_options = get_option('wps_payment_mode'); |
| 735 | - if ( !empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on' ) { |
|
| 736 | - if ( !empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/ ) { |
|
| 737 | - $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop'). ' : <br/>'; |
|
| 738 | - $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop'). ' : '.( (!empty($iban_options['banktransfer']['bank_name']) ) ? $iban_options['banktransfer']['bank_name'] : ''). '<br/>'; |
|
| 739 | - $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop'). ' : '.( (!empty($iban_options['banktransfer']['iban']) ) ? $iban_options['banktransfer']['iban'] : ''). '<br/>'; |
|
| 740 | - $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop'). ' : '.( (!empty($iban_options['banktransfer']['bic']) ) ? $iban_options['banktransfer']['bic'] : ''). '<br/>'; |
|
| 741 | - $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop'). ' : '.( (!empty($iban_options['banktransfer']['accountowner']) ) ? $iban_options['banktransfer']['accountowner'] : ''). '<br/>'; |
|
| 735 | + if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') { |
|
| 736 | + if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) { |
|
| 737 | + $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>'; |
|
| 738 | + $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>'; |
|
| 739 | + $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>'; |
|
| 740 | + $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>'; |
|
| 741 | + $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>'; |
|
| 742 | 742 | } |
| 743 | 743 | } |
| 744 | 744 | else { |
@@ -751,8 +751,8 @@ discard block |
||
| 751 | 751 | |
| 752 | 752 | |
| 753 | 753 | /** Received payements **/ |
| 754 | - if ( !$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref']) ) { |
|
| 755 | - $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part( $order_id ); |
|
| 754 | + if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) { |
|
| 755 | + $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id); |
|
| 756 | 756 | } |
| 757 | 757 | else { |
| 758 | 758 | $tpl_component['RECEIVED_PAYMENT'] = ''; |
@@ -765,11 +765,11 @@ discard block |
||
| 765 | 765 | $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common'); |
| 766 | 766 | } |
| 767 | 767 | else { |
| 768 | - $output = __('No order information has been found', 'wpshop'); |
|
| 768 | + $output = __('No order information has been found', 'wpshop'); |
|
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | else { |
| 772 | - $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop'); |
|
| 772 | + $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop'); |
|
| 773 | 773 | } |
| 774 | 774 | return $output; |
| 775 | 775 | } |
@@ -780,61 +780,61 @@ discard block |
||
| 780 | 780 | * @param integer $order_id |
| 781 | 781 | * @return string |
| 782 | 782 | */ |
| 783 | - public static function generate_received_payment_part( $order_id ) { |
|
| 784 | - $date_ouput_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
|
| 783 | + public static function generate_received_payment_part($order_id) { |
|
| 784 | + $date_ouput_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 785 | 785 | $output = ''; |
| 786 | 786 | $tpl_component = array(); |
| 787 | 787 | $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = ''; |
| 788 | - if ( !empty($order_id) ) { |
|
| 788 | + if (!empty($order_id)) { |
|
| 789 | 789 | $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
| 790 | - if ( !empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) ) { |
|
| 791 | - $wps_payment_option = get_option( 'wps_payment_mode' ); |
|
| 792 | - foreach( $order_postmeta['order_payment']['received'] as $payment ) { |
|
| 793 | - if ( ! empty( $payment ) && ! in_array( $payment['method'], array( 'quotation' ), true ) && ! empty( $payment['received_amount'] ) ) { |
|
| 790 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) { |
|
| 791 | + $wps_payment_option = get_option('wps_payment_mode'); |
|
| 792 | + foreach ($order_postmeta['order_payment']['received'] as $payment) { |
|
| 793 | + if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) { |
|
| 794 | 794 | $sub_tpl_component = array(); |
| 795 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = ( !empty($payment['received_amount']) ) ? number_format( $payment['received_amount'], 2, ',', '' ).' '.wpshop_tools::wpshop_get_currency() : 0; |
|
| 796 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date']) ) ? mysql2date($date_ouput_format, $payment['date'], true) : ''; |
|
| 797 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ( ( !empty( $payment[ 'method' ] ) && is_array( $wps_payment_option ) && array_key_exists( strtolower( $payment['method'] ), $wps_payment_option[ 'mode' ] ) && !empty( $wps_payment_option[ 'mode' ][ strtolower( $payment['method'] ) ][ 'name' ] ) ) ? $wps_payment_option[ 'mode' ][ strtolower( $payment['method'] ) ][ 'name' ] : ( !empty( $payment[ 'method' ] ) ? __( $payment[ 'method' ], 'wpshop' ) : '' ) ); |
|
| 798 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = ( !empty($payment['payment_reference']) ) ? $payment['payment_reference'] : ''; |
|
| 799 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = ( !empty($payment['invoice_ref']) ) ? $payment['invoice_ref'] : ''; |
|
| 795 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0; |
|
| 796 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : ''; |
|
| 797 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : '')); |
|
| 798 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : ''; |
|
| 799 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : ''; |
|
| 800 | 800 | $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | 804 | $output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
| 805 | - unset( $tpl_component ); |
|
| 805 | + unset($tpl_component); |
|
| 806 | 806 | } |
| 807 | 807 | return $output; |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
| 811 | 811 | /** Return the validity period of a quotation **/ |
| 812 | - public static function quotation_validate_period( $quotation_date ) { |
|
| 812 | + public static function quotation_validate_period($quotation_date) { |
|
| 813 | 813 | $quotation_options = get_option('wpshop_quotation_validate_time'); |
| 814 | - if ( !empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type']) ) { |
|
| 814 | + if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) { |
|
| 815 | 815 | $timestamp_quotation = strtotime($quotation_date); |
| 816 | 816 | $timestamp_validity_date_quotation = 0; |
| 817 | 817 | $query = ''; |
| 818 | 818 | $date = ''; |
| 819 | 819 | global $wpdb; |
| 820 | - switch ( $quotation_options['time_type'] ) { |
|
| 820 | + switch ($quotation_options['time_type']) { |
|
| 821 | 821 | case 'day' : |
| 822 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " .$quotation_options['number']. " DAY) "); |
|
| 822 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " DAY) "); |
|
| 823 | 823 | break; |
| 824 | 824 | case 'month' : |
| 825 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " .$quotation_options['number']. " MONTH) "); |
|
| 825 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " MONTH) "); |
|
| 826 | 826 | break; |
| 827 | 827 | case 'year' : |
| 828 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " .$quotation_options['number']. " YEAR) "); |
|
| 828 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " YEAR) "); |
|
| 829 | 829 | break; |
| 830 | 830 | default : |
| 831 | 831 | $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL 15 DAY) "); |
| 832 | 832 | break; |
| 833 | 833 | } |
| 834 | - if ( $query != null) { |
|
| 834 | + if ($query != null) { |
|
| 835 | 835 | $date = mysql2date('d F Y', $wpdb->get_var($query), true); |
| 836 | 836 | } |
| 837 | - return sprintf( __('Quotation validity date %s', 'wpshop'), $date ) ; |
|
| 837 | + return sprintf(__('Quotation validity date %s', 'wpshop'), $date); |
|
| 838 | 838 | } |
| 839 | 839 | } |
| 840 | 840 | |
@@ -844,19 +844,19 @@ discard block |
||
| 844 | 844 | * @param string $invoice_ref |
| 845 | 845 | * @return string |
| 846 | 846 | */ |
| 847 | - public static function generate_invoice_for_email ( $order_id, $invoice_ref = '' ) { |
|
| 847 | + public static function generate_invoice_for_email($order_id, $invoice_ref = '') { |
|
| 848 | 848 | /** Generate the PDF file for the invoice **/ |
| 849 | 849 | $is_ok = false; |
| 850 | - if ( !empty($invoice_ref) ) { |
|
| 851 | - require_once(WPSHOP_LIBRAIRIES_DIR.'HTML2PDF/html2pdf.class.php'); |
|
| 850 | + if (!empty($invoice_ref)) { |
|
| 851 | + require_once(WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'); |
|
| 852 | 852 | try { |
| 853 | - $html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref ); |
|
| 853 | + $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref); |
|
| 854 | 854 | $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
| 855 | 855 | $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
| 856 | 856 | |
| 857 | 857 | $html2pdf->setDefaultFont('Arial'); |
| 858 | 858 | $html2pdf->writeHTML($html_content); |
| 859 | - $html2pdf->Output(WPSHOP_UPLOAD_DIR.$invoice_ref.'.pdf', 'F'); |
|
| 859 | + $html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F'); |
|
| 860 | 860 | $is_ok = true; |
| 861 | 861 | } |
| 862 | 862 | catch (HTML2PDF_exception $e) { |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | exit; |
| 865 | 865 | } |
| 866 | 866 | } |
| 867 | - return ( $is_ok ) ? WPSHOP_UPLOAD_DIR.$invoice_ref.'.pdf' : ''; |
|
| 867 | + return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : ''; |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
@@ -872,38 +872,38 @@ discard block |
||
| 872 | 872 | * @return Ambigous <string, string> |
| 873 | 873 | */ |
| 874 | 874 | public static function generate_invoice_sender_part() { |
| 875 | - $output =''; |
|
| 875 | + $output = ''; |
|
| 876 | 876 | $company = get_option('wpshop_company_info', array()); |
| 877 | 877 | $emails = get_option('wpshop_emails', array()); |
| 878 | - if ( !empty($company) ) { |
|
| 879 | - $tpl_component['COMPANY_EMAIL'] = ( !empty($emails) && !empty($emails['contact_email']) ) ? $emails['contact_email'] : ''; |
|
| 878 | + if (!empty($company)) { |
|
| 879 | + $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 880 | 880 | $tpl_component['COMPANY_WEBSITE'] = get_option('siteurl'); |
| 881 | - foreach ( $company as $company_info_key => $company_info_value ) { |
|
| 881 | + foreach ($company as $company_info_key => $company_info_value) { |
|
| 882 | 882 | switch ($company_info_key) { |
| 883 | 883 | case 'company_rcs' : |
| 884 | - $data = ( !empty($company_info_value) ) ? __('RCS', 'wpshop').' : '.$company_info_value : ''; |
|
| 884 | + $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 885 | 885 | break; |
| 886 | 886 | case 'company_capital' : |
| 887 | - $data = ( !empty($company_info_value) ) ? __('Capital', 'wpshop').' : '.$company_info_value : ''; |
|
| 887 | + $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 888 | 888 | break; |
| 889 | 889 | case 'company_siren' : |
| 890 | - $data = ( !empty($company_info_value) ) ? __('SIREN', 'wpshop').' : '.$company_info_value : ''; |
|
| 890 | + $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 891 | 891 | break; |
| 892 | 892 | case 'company_siret' : |
| 893 | - $data = ( !empty($company_info_value) ) ? __('SIRET', 'wpshop').' : '.$company_info_value : ''; |
|
| 893 | + $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 894 | 894 | break; |
| 895 | 895 | case 'company_tva_intra' : |
| 896 | - $data = ( !empty($company_info_value) ) ? __('TVA Intracommunautaire', 'wpshop').' : '.$company_info_value : ''; |
|
| 896 | + $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 897 | 897 | break; |
| 898 | 898 | case 'company_legal_statut' : |
| 899 | 899 | $array_state_compagny = wpshop_company_options::get_legal_status(); |
| 900 | - $data = ( !empty( $array_state_compagny ) && !empty( $array_state_compagny[$company_info_value] ) ) ? $array_state_compagny[$company_info_value] : __( 'Auto-Entrepreneur', 'wpshop' ) ; |
|
| 900 | + $data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop'); |
|
| 901 | 901 | break; |
| 902 | 902 | default : |
| 903 | 903 | $data = $company_info_value; |
| 904 | 904 | break; |
| 905 | 905 | } |
| 906 | - $tpl_component[ strtoupper( $company_info_key) ] = $data; |
|
| 906 | + $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 907 | 907 | } |
| 908 | 908 | $output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common'); |
| 909 | 909 | } |
@@ -916,57 +916,57 @@ discard block |
||
| 916 | 916 | * @param unknown_type $bon_colisage |
| 917 | 917 | * @return Ambigous <string, string> |
| 918 | 918 | */ |
| 919 | - public static function generate_receiver_part( $order_id, $bon_colisage = false ) { |
|
| 919 | + public static function generate_receiver_part($order_id, $bon_colisage = false) { |
|
| 920 | 920 | $output = ''; |
| 921 | 921 | $order_customer_postmeta = get_post_meta($order_id, '_order_info', true); |
| 922 | - $order_postmeta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
| 922 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 923 | 923 | |
| 924 | - if( $bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address']) ) { |
|
| 924 | + if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) { |
|
| 925 | 925 | $address_info = $order_customer_postmeta['shipping']['address']; |
| 926 | 926 | } else { |
| 927 | - if( !empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address']) ) { |
|
| 927 | + if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) { |
|
| 928 | 928 | $address_info = $order_customer_postmeta['billing']['address']; |
| 929 | 929 | } else { |
| 930 | 930 | $address_info = array(); |
| 931 | 931 | } |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | - if ( !empty($order_customer_postmeta) && !empty($address_info) ) { |
|
| 934 | + if (!empty($order_customer_postmeta) && !empty($address_info)) { |
|
| 935 | 935 | $default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY'); |
| 936 | - foreach ( $default_address_attributes as $default_address_attribute ) { |
|
| 936 | + foreach ($default_address_attributes as $default_address_attribute) { |
|
| 937 | 937 | $tpl_component[$default_address_attribute] = ''; |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | - foreach ( $address_info as $order_customer_info_key => $order_customer_info_value ) { |
|
| 940 | + foreach ($address_info as $order_customer_info_key => $order_customer_info_value) { |
|
| 941 | 941 | $tpl_component[strtoupper($order_customer_info_key)] = ''; |
| 942 | - if ( $order_customer_info_key == 'civility') { |
|
| 942 | + if ($order_customer_info_key == 'civility') { |
|
| 943 | 943 | global $wpdb; |
| 944 | - $query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id= %d', $order_customer_info_value); |
|
| 944 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value); |
|
| 945 | 945 | $civility = $wpdb->get_row($query); |
| 946 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility) ) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : ''; |
|
| 946 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : ''; |
|
| 947 | 947 | } |
| 948 | - else if( $order_customer_info_key == 'country') { |
|
| 948 | + else if ($order_customer_info_key == 'country') { |
|
| 949 | 949 | foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key=>$value) { |
| 950 | - if ( $order_customer_info_value == $key) { |
|
| 950 | + if ($order_customer_info_value == $key) { |
|
| 951 | 951 | $tpl_component[strtoupper($order_customer_info_key)] = $value; |
| 952 | 952 | } |
| 953 | 953 | } |
| 954 | 954 | } |
| 955 | - elseif( $order_customer_info_key == 'phone' ){ |
|
| 956 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value) ) ? __('Phone', 'wpshop').' : '.$order_customer_info_value : ''; |
|
| 955 | + elseif ($order_customer_info_key == 'phone') { |
|
| 956 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : ''; |
|
| 957 | 957 | } |
| 958 | 958 | else { |
| 959 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value) ) ? $order_customer_info_value : ''; |
|
| 959 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : ''; |
|
| 960 | 960 | } |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - if ( empty($tpl_component['PHONE']) ) { |
|
| 964 | - $tpl_component['PHONE'] = ( !empty( $order_customer_postmeta['billing']['address']['phone']) ) ? __('Phone', 'wpshop').' : '.$order_customer_postmeta['billing']['address']['phone'] : ''; |
|
| 963 | + if (empty($tpl_component['PHONE'])) { |
|
| 964 | + $tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : ''; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | - if ( empty($tpl_component['ADDRESS_USER_EMAIL']) || ( empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage ) ){ |
|
| 968 | - $user_info = get_userdata( $order_postmeta['customer_id'] ); |
|
| 969 | - $tpl_component['ADDRESS_USER_EMAIL'] = ( !empty($user_info) && !empty($user_info->user_email) ) ? $user_info->user_email : ''; |
|
| 967 | + if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) { |
|
| 968 | + $user_info = get_userdata($order_postmeta['customer_id']); |
|
| 969 | + $tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : ''; |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | |
@@ -980,36 +980,36 @@ discard block |
||
| 980 | 980 | * Genrate Footer invoice |
| 981 | 981 | * @return Ambigous <string, string> |
| 982 | 982 | */ |
| 983 | - public static function generate_footer_invoice(){ |
|
| 984 | - $output =''; |
|
| 983 | + public static function generate_footer_invoice() { |
|
| 984 | + $output = ''; |
|
| 985 | 985 | $company = get_option('wpshop_company_info', array()); |
| 986 | 986 | $emails = get_option('wpshop_emails', array()); |
| 987 | - if ( !empty($company) ) { |
|
| 988 | - $tpl_component['COMPANY_EMAIL'] = ( !empty($emails) && !empty($emails['contact_email']) ) ? $emails['contact_email'] : ''; |
|
| 987 | + if (!empty($company)) { |
|
| 988 | + $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 989 | 989 | $tpl_component['COMPANY_WEBSITE'] = site_url(); |
| 990 | - foreach ( $company as $company_info_key => $company_info_value ) { |
|
| 990 | + foreach ($company as $company_info_key => $company_info_value) { |
|
| 991 | 991 | |
| 992 | 992 | switch ($company_info_key) { |
| 993 | 993 | case 'company_rcs' : |
| 994 | - $data = ( !empty($company_info_value) ) ? __('RCS', 'wpshop').' : '.$company_info_value : ''; |
|
| 994 | + $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 995 | 995 | break; |
| 996 | 996 | case 'company_capital' : |
| 997 | - $data = ( !empty($company_info_value) ) ? __('Capital', 'wpshop').' : '.$company_info_value : ''; |
|
| 997 | + $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 998 | 998 | break; |
| 999 | 999 | case 'company_siren' : |
| 1000 | - $data = ( !empty($company_info_value) ) ? __('SIREN', 'wpshop').' : '.$company_info_value : ''; |
|
| 1000 | + $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1001 | 1001 | break; |
| 1002 | 1002 | case 'company_siret' : |
| 1003 | - $data = ( !empty($company_info_value) ) ? __('SIRET', 'wpshop').' : '.$company_info_value : ''; |
|
| 1003 | + $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1004 | 1004 | break; |
| 1005 | 1005 | case 'company_tva_intra' : |
| 1006 | - $data = ( !empty($company_info_value) ) ? __('TVA Intracommunautaire', 'wpshop').' : '.$company_info_value : ''; |
|
| 1006 | + $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1007 | 1007 | break; |
| 1008 | 1008 | default : |
| 1009 | 1009 | $data = $company_info_value; |
| 1010 | 1010 | break; |
| 1011 | 1011 | } |
| 1012 | - $tpl_component[ strtoupper( $company_info_key) ] = $data; |
|
| 1012 | + $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common'); |
| 1015 | 1015 | } |
@@ -1025,33 +1025,33 @@ discard block |
||
| 1025 | 1025 | * @param id $product_id |
| 1026 | 1026 | * @param string $invoice_ref |
| 1027 | 1027 | */ |
| 1028 | - public static function check_product_price( $price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id ) { |
|
| 1028 | + public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id) { |
|
| 1029 | 1029 | $checking = true; |
| 1030 | - $error_percent = 1; |
|
| 1030 | + $error_percent = 1; |
|
| 1031 | 1031 | |
| 1032 | 1032 | /** Check VAT Amount **/ |
| 1033 | - $formatted_tva_amount = number_format( $tva_amount, 2, '.', '' ); |
|
| 1034 | - $formatted_price_ht = number_format( $price_ht, 2, '.', '' ); |
|
| 1035 | - $formatted_price_ati = number_format( $price_ati, 2, '.', '' ); |
|
| 1036 | - $calculated_price_excluding_tax = $price_ati / ( 1 + ($tva_rate / 100) ); |
|
| 1033 | + $formatted_tva_amount = number_format($tva_amount, 2, '.', ''); |
|
| 1034 | + $formatted_price_ht = number_format($price_ht, 2, '.', ''); |
|
| 1035 | + $formatted_price_ati = number_format($price_ati, 2, '.', ''); |
|
| 1036 | + $calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100)); |
|
| 1037 | 1037 | $unformatted = $formatted_price_ati - $calculated_price_excluding_tax; |
| 1038 | - $checked_tva_amount = number_format( $unformatted, 2, '.', '' ); |
|
| 1038 | + $checked_tva_amount = number_format($unformatted, 2, '.', ''); |
|
| 1039 | 1039 | |
| 1040 | - if ( ( $checked_tva_amount < ($formatted_tva_amount / ( 1 + ($error_percent / 100) ) ) ) || ( $checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100) ) ) ) ) { |
|
| 1040 | + if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) { |
|
| 1041 | 1041 | $error_infos = array(); |
| 1042 | - $error_infos['real_datas']['price_ati'] = $formatted_price_ati; |
|
| 1043 | - $error_infos['real_datas']['price_ht'] = $formatted_price_ht; |
|
| 1044 | - $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount; |
|
| 1042 | + $error_infos['real_datas']['price_ati'] = $formatted_price_ati; |
|
| 1043 | + $error_infos['real_datas']['price_ht'] = $formatted_price_ht; |
|
| 1044 | + $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount; |
|
| 1045 | 1045 | |
| 1046 | 1046 | $error_infos['corrected_data'] = $checked_tva_amount; |
| 1047 | - self::invoice_error_check_administrator( $invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos ); |
|
| 1047 | + self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos); |
|
| 1048 | 1048 | $checking = false; |
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** Check price ati **/ |
| 1052 | - $checked_price_ati = $formatted_price_ht * ( 1 + ( $tva_rate / 100) ); |
|
| 1053 | - if ( ( $checked_price_ati < ($formatted_price_ati /( 1 + ($error_percent / 100) ) ) ) || ( $checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100)) ) ) ) { |
|
| 1054 | - self::invoice_error_check_administrator( $invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id ); |
|
| 1052 | + $checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100)); |
|
| 1053 | + if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) { |
|
| 1054 | + self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id); |
|
| 1055 | 1055 | $checking = false; |
| 1056 | 1056 | } |
| 1057 | 1057 | |
@@ -1064,29 +1064,29 @@ discard block |
||
| 1064 | 1064 | * @param string $object |
| 1065 | 1065 | * @param unknown_type $product_id |
| 1066 | 1066 | */ |
| 1067 | - function invoice_error_check_administrator( $invoice_ref, $object, $product_id, $order_id, $errors_infos = array() ) { |
|
| 1068 | - $wpshop_email_option = get_option( 'wpshop_emails'); |
|
| 1069 | - if ( !empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email']) ) { |
|
| 1067 | + function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array()) { |
|
| 1068 | + $wpshop_email_option = get_option('wpshop_emails'); |
|
| 1069 | + if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) { |
|
| 1070 | 1070 | $headers = "MIME-Version: 1.0\r\n"; |
| 1071 | 1071 | $headers .= "Content-type: text/html; charset=UTF-8\r\n"; |
| 1072 | - $headers .= 'From: '.get_bloginfo('name').' <'.$wpshop_email_option['noreply_email'].'>' . "\r\n"; |
|
| 1073 | - $message = '<b>'.__('Error type', 'wpshop').' : </b>'.$object.'<br/>'; |
|
| 1074 | - $message .= '<b>'.__( 'Product', 'wpshop').' : </b>'.get_the_title( $product_id ).'<br/>'; |
|
| 1075 | - $message .= '<b>'.__( 'Invoice ref', 'wpshop').' : </b>'.$invoice_ref.'<br/>'; |
|
| 1076 | - $message .= '<b>'.__( 'Order ID', 'wpshop').' : </b>'.$order_id.'<br/>'; |
|
| 1077 | - |
|
| 1078 | - if ( !empty($errors_infos) && !empty($errors_infos['real_datas']) ) { |
|
| 1079 | - $message .='<b>' .__( 'Bad datas', 'wpshop').' :</b> <ul>'; |
|
| 1080 | - foreach( $errors_infos['real_datas'] as $k => $errors_info ) { |
|
| 1081 | - $message .= '<li><b>'.$k.' : </b>'.$errors_info.'</li>'; |
|
| 1072 | + $headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n"; |
|
| 1073 | + $message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>'; |
|
| 1074 | + $message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>'; |
|
| 1075 | + $message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>'; |
|
| 1076 | + $message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>'; |
|
| 1077 | + |
|
| 1078 | + if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) { |
|
| 1079 | + $message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>'; |
|
| 1080 | + foreach ($errors_infos['real_datas'] as $k => $errors_info) { |
|
| 1081 | + $message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>'; |
|
| 1082 | 1082 | } |
| 1083 | 1083 | $message .= '</ul>'; |
| 1084 | - if ( !empty($errors_infos['corrected_data']) ) { |
|
| 1085 | - $message .= '<b>' . __( 'Good value', 'wpshop' ) . ' : </b>' . $errors_infos['corrected_data']; |
|
| 1084 | + if (!empty($errors_infos['corrected_data'])) { |
|
| 1085 | + $message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data']; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | - wp_mail( $wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop') , $message, $headers); |
|
| 1089 | + wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | } |
| 1092 | 1092 | |
@@ -1096,9 +1096,9 @@ discard block |
||
| 1096 | 1096 | * @param array $posted_datas |
| 1097 | 1097 | * @return string |
| 1098 | 1098 | */ |
| 1099 | - function force_invoice_generation_on_order( $order_metadata, $posted_datas ) { |
|
| 1100 | - if ( !empty ($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') { |
|
| 1101 | - $order_metadata['order_invoice_ref'] = $this->generate_invoice_number( $posted_datas['post_ID'] ); |
|
| 1099 | + function force_invoice_generation_on_order($order_metadata, $posted_datas) { |
|
| 1100 | + if (!empty ($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') { |
|
| 1101 | + $order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | return $order_metadata; |
| 1104 | 1104 | } |
@@ -1113,12 +1113,12 @@ discard block |
||
| 1113 | 1113 | $partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
| 1114 | 1114 | |
| 1115 | 1115 | $partial_for_quotation_is_activate = false; |
| 1116 | - if ( !empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate']) ) { |
|
| 1116 | + if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) { |
|
| 1117 | 1117 | $partial_for_quotation_is_activate = true; |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | $output .= ' |
| 1121 | - <input type="checkbox" name="wpshop_payment_partial[for_quotation][activate]"' . ($partial_for_quotation_is_activate ? ' checked="checked"' : '') . ' id="wpshop_payment_partial_on_quotation_activation_state" /> <label for="wpshop_payment_partial_on_quotation_activation_state" >' . __('Activate partial command for quotations', 'wpshop') . '</label><a href="#" title="'.__('If you want that customer pay a part o f total amount of there order, check this box then fill fields below','wpshop').'" class="wpshop_infobulle_marker">?</a> |
|
| 1121 | + <input type="checkbox" name="wpshop_payment_partial[for_quotation][activate]"' . ($partial_for_quotation_is_activate ? ' checked="checked"' : '') . ' id="wpshop_payment_partial_on_quotation_activation_state" /> <label for="wpshop_payment_partial_on_quotation_activation_state" >' . __('Activate partial command for quotations', 'wpshop') . '</label><a href="#" title="' . __('If you want that customer pay a part o f total amount of there order, check this box then fill fields below', 'wpshop') . '" class="wpshop_infobulle_marker">?</a> |
|
| 1122 | 1122 | <div class="wpshop_partial_payment_quotation_config_container' . ($partial_for_quotation_is_activate ? '' : ' wpshopHide') . '" id="wpshop_partial_payment_quotation_config_container" > |
| 1123 | 1123 | <div class="alignleft" > |
| 1124 | 1124 | ' . __('Value of partial payment', 'wpshop') . '<br/> |
@@ -1140,6 +1140,6 @@ discard block |
||
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | /** Instanciate the module utilities if not */ |
| 1143 | -if ( class_exists("wpshop_modules_billing") ) { |
|
| 1143 | +if (class_exists("wpshop_modules_billing")) { |
|
| 1144 | 1144 | $wpshop_modules_billing = new wpshop_modules_billing(); |
| 1145 | 1145 | } |
@@ -1,21 +1,21 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | ?> |
| 3 | 3 | <tr class="<?php echo $class; ?>" id="trPid_<?php echo $product['post_datas']->ID; ?>"> |
| 4 | 4 | <td class="wps-mass-interface-line-selector"><div class="wps-form-group"><div class="wps-form"><center><input type="checkbox" class="wps-save-product-checkbox" name="wps_product_quick_save[]" value="<?php echo $product['post_datas']->ID; ?>" /></center></div></div></td> |
| 5 | 5 | |
| 6 | 6 | <td class="wps_mass_interface_line"> |
| 7 | - <span class="wps_mass_interface_picture_container" id="wps_mass_interface_picture_container_<?php echo $product['post_datas']->ID; ?>"><?php echo get_the_post_thumbnail( $product['post_datas']->ID, 'thumbnail'); ?></span> |
|
| 7 | + <span class="wps_mass_interface_picture_container" id="wps_mass_interface_picture_container_<?php echo $product['post_datas']->ID; ?>"><?php echo get_the_post_thumbnail($product['post_datas']->ID, 'thumbnail'); ?></span> |
|
| 8 | 8 | <input type="hidden" value="" name="wps_mass_interface[<?php echo $product['post_datas']->ID; ?>][picture]" /> |
| 9 | 9 | <?php |
| 10 | - if( has_post_thumbnail($product['post_datas']->ID) ) { |
|
| 10 | + if (has_post_thumbnail($product['post_datas']->ID)) { |
|
| 11 | 11 | $has_thumb = true; |
| 12 | 12 | } else { |
| 13 | 13 | $has_thumb = false; |
| 14 | 14 | } |
| 15 | 15 | ?> |
| 16 | - <a href="#" style="display: <?php echo ( $has_thumb ) ? 'none' : 'inline-block'; ?>;" class="wps-bton-second-mini-rounded wps_add_picture_to_product_in_mass_interface" id="wps_add_picture_to_product_in_mass_interface_<?php echo $product['post_datas']->ID; ?>"><?php _e( 'Add a picture', 'wpshop'); ?></a> |
|
| 16 | + <a href="#" style="display: <?php echo ($has_thumb) ? 'none' : 'inline-block'; ?>;" class="wps-bton-second-mini-rounded wps_add_picture_to_product_in_mass_interface" id="wps_add_picture_to_product_in_mass_interface_<?php echo $product['post_datas']->ID; ?>"><?php _e('Add a picture', 'wpshop'); ?></a> |
|
| 17 | 17 | <div class="row-actions"> |
| 18 | - <center><a href="#" class="wps_del_picture_to_product_in_mass_interface" style="display: <?php echo ( !$has_thumb ) ? 'none' : 'inline-block'; ?>;" id="wps_del_picture_to_product_in_mass_interface_<?php echo $product['post_datas']->ID; ?>"><?php _e( 'Delete picture', 'wpshop'); ?></a></center> |
|
| 18 | + <center><a href="#" class="wps_del_picture_to_product_in_mass_interface" style="display: <?php echo (!$has_thumb) ? 'none' : 'inline-block'; ?>;" id="wps_del_picture_to_product_in_mass_interface_<?php echo $product['post_datas']->ID; ?>"><?php _e('Delete picture', 'wpshop'); ?></a></center> |
|
| 19 | 19 | </div> |
| 20 | 20 | </td> |
| 21 | 21 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | <input type="text" name="wps_mass_interface[<?php echo $product['post_datas']->ID; ?>][post_title]" value="<?php echo $product['post_datas']->post_title; ?>" /> |
| 27 | 27 | </div> |
| 28 | 28 | <div class="row-actions"> |
| 29 | - <a href="<?php echo get_edit_post_link( $product['post_datas']->ID ); ?>" target="_blank"><?php _e('Edit This')?></a> | |
|
| 29 | + <a href="<?php echo get_edit_post_link($product['post_datas']->ID); ?>" target="_blank"><?php _e('Edit This')?></a> | |
|
| 30 | 30 | <span class="trash"><a id="wps_mass_interface_post_delete_<?php echo $product['post_datas']->ID; ?>" class="submitdelete" href="#"><?php _e('Trash')?></a><input id="wps_mass_interface_post_delete_input_<?php echo $product['post_datas']->ID; ?>" type="hidden" name="wps_mass_interface[<?php echo $product['post_datas']->ID; ?>][post_delete]" value="false" /></span> | |
| 31 | 31 | <a href="<?php echo get_permalink($product['post_datas']->ID); ?>" target="_blank"><?php _e('View product', 'wpshop')?></a> |
| 32 | 32 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | <div class="wps-form-group"> |
| 39 | 39 | <?php /*<label><?php _e( 'Product description', 'wpshop'); ?> :</label>*/ ?> |
| 40 | 40 | <div class="wps-form"> |
| 41 | - <textarea id="wps_product_description_<?php echo $product['post_datas']->ID; ?>" name="wps_mass_interface[<?php echo $product['post_datas']->ID; ?>][post_content]"><?php echo nl2br( $product['post_datas']->post_content );?></textarea> |
|
| 41 | + <textarea id="wps_product_description_<?php echo $product['post_datas']->ID; ?>" name="wps_mass_interface[<?php echo $product['post_datas']->ID; ?>][post_content]"><?php echo nl2br($product['post_datas']->post_content); ?></textarea> |
|
| 42 | 42 | </div> |
| 43 | 43 | </div> |
| 44 | 44 | </td> |
@@ -49,43 +49,43 @@ discard block |
||
| 49 | 49 | <center><a class="wps-bton-first-mini-rounded wps_add_files_to_product_in_mass_interface" id="wps_add_files_to_product_in_mass_interface_<?php echo $product['post_datas']->ID; ?>"><?php _e( 'Add files', 'wpshop'); ?></a></center> |
| 50 | 50 | </td>*/ ?> |
| 51 | 51 | |
| 52 | - <?php if( !empty($quick_add_form_attributes) ) : |
|
| 52 | + <?php if (!empty($quick_add_form_attributes)) : |
|
| 53 | 53 | $i = 0; ?> |
| 54 | - <?php foreach( $quick_add_form_attributes as $attribute_id => $att_def ) : |
|
| 54 | + <?php foreach ($quick_add_form_attributes as $attribute_id => $att_def) : |
|
| 55 | 55 | |
| 56 | 56 | $att = null; |
| 57 | - $query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_id = %d AND status = %s', $default, $attribute_id, 'valid' ); |
|
| 58 | - $checking_display_att = $wpdb->get_results( $query ); |
|
| 57 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_id = %d AND status = %s', $default, $attribute_id, 'valid'); |
|
| 58 | + $checking_display_att = $wpdb->get_results($query); |
|
| 59 | 59 | |
| 60 | - if( !empty($checking_display_att) ) : |
|
| 61 | - $current_value = wpshop_attributes::getAttributeValueForEntityInSet( $att_def['data_type'], $attribute_id, $product_entity_id, $product['post_datas']->ID ); |
|
| 62 | - $output_specs = array( |
|
| 60 | + if (!empty($checking_display_att)) : |
|
| 61 | + $current_value = wpshop_attributes::getAttributeValueForEntityInSet($att_def['data_type'], $attribute_id, $product_entity_id, $product['post_datas']->ID); |
|
| 62 | + $output_specs = array( |
|
| 63 | 63 | 'page_code' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
| 64 | 64 | 'element_identifier' => $product['post_datas']->ID, |
| 65 | - 'field_id' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'_'.$product['post_datas']->ID. '_', |
|
| 66 | - 'current_value' => ( !empty($current_value->value) ? $current_value->value : '' ) |
|
| 65 | + 'field_id' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product['post_datas']->ID . '_', |
|
| 66 | + 'current_value' => (!empty($current_value->value) ? $current_value->value : '') |
|
| 67 | 67 | ); |
| 68 | - $att = wpshop_attributes::display_attribute( $att_def['code'], 'admin', $output_specs ); |
|
| 68 | + $att = wpshop_attributes::display_attribute($att_def['code'], 'admin', $output_specs); |
|
| 69 | 69 | endif; |
| 70 | 70 | ?> |
| 71 | 71 | <td class="wps_mass_interface_line"> |
| 72 | 72 | <div class="wps-form-group"> |
| 73 | 73 | <?php /*<label><?php _e( $att['field_definition']['label'], 'wpshop' ); ?></label>*/ ?> |
| 74 | - <div class="wps-form"><?php echo str_replace( 'name="wpshop_product_attribute', 'name="wpshop_product_attribute[' .$product['post_datas']->ID. ']', $att['field_definition']['output'] ); ?></div> |
|
| 74 | + <div class="wps-form"><?php echo str_replace('name="wpshop_product_attribute', 'name="wpshop_product_attribute[' . $product['post_datas']->ID . ']', $att['field_definition']['output']); ?></div> |
|
| 75 | 75 | </div> |
| 76 | 76 | </td> |
| 77 | 77 | <?php $i++; |
| 78 | 78 | endforeach; ?> |
| 79 | 79 | <?php endif; ?> |
| 80 | 80 | |
| 81 | - <td class="wps_mass_interface_line_deleted" colspan="<?php echo 3 + $i;?>" style="display: none;"> |
|
| 82 | - <?php printf( __( '%s will be deleted.', 'wpshop' ), $product['post_datas']->post_title); ?> <a class="wps_mass_interface_post_deleted_cancel" id="wps_mass_interface_post_delete_cancel_<?php echo $product['post_datas']->ID; ?>" href="#">Annuler</a> |
|
| 81 | + <td class="wps_mass_interface_line_deleted" colspan="<?php echo 3 + $i; ?>" style="display: none;"> |
|
| 82 | + <?php printf(__('%s will be deleted.', 'wpshop'), $product['post_datas']->post_title); ?> <a class="wps_mass_interface_post_deleted_cancel" id="wps_mass_interface_post_delete_cancel_<?php echo $product['post_datas']->ID; ?>" href="#">Annuler</a> |
|
| 83 | 83 | </td> |
| 84 | 84 | </tr> |
| 85 | 85 | <?php // ------------------------------------------------------------------------------------------------------ ?> |
| 86 | 86 | <?php |
| 87 | - $concurs = get_post_meta( $product['post_datas']->ID, '_concur', true ); |
|
| 88 | - if ( empty( $concurs ) ) { |
|
| 87 | + $concurs = get_post_meta($product['post_datas']->ID, '_concur', true); |
|
| 88 | + if (empty($concurs)) { |
|
| 89 | 89 | $concurs = array(); |
| 90 | 90 | } |
| 91 | 91 | foreach ($concurs as $key => $concur) { |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | </td> |
| 103 | 103 | <td><input type="text" placeholder="Prix" name="concur[<?php echo $product['post_datas']->ID; ?>][price][]" value="<?php echo $concur['price']; ?>"></td> |
| 104 | 104 | <td class="del_concur" style="color: red; cursor: pointer;">Supprimer</td> |
| 105 | - <?php for ($j=0; $j < $i-2; $j++) { |
|
| 105 | + <?php for ($j = 0; $j < $i - 2; $j++) { |
|
| 106 | 106 | echo '<td></td>'; |
| 107 | 107 | } ?> |
| 108 | 108 | </tr> |
| 109 | 109 | <?php |
| 110 | 110 | } |
| 111 | - $output_specs = array( 'page_code' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'element_identifier' => $product['post_datas']->ID, 'field_id' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'_'.$product['post_datas']->ID. '_%ID%' ); |
|
| 111 | + $output_specs = array('page_code' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'element_identifier' => $product['post_datas']->ID, 'field_id' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product['post_datas']->ID . '_%ID%'); |
|
| 112 | 112 | ?> |
| 113 | 113 | <tr class="<?php echo $class; ?> concurs cloner" style="display:none" data-id="<?php echo $product['post_datas']->ID; ?>"> |
| 114 | 114 | <td><input type="hidden" class="is_row" name="concur[<?php echo $product['post_datas']->ID; ?>][is_row][]" value="0"></td> |
| 115 | 115 | <td><input type="text" placeholder="Date" class="datepicker_concur" value="<?php echo current_time('Y-m-d'); ?>" name="concur[<?php echo $product['post_datas']->ID; ?>][date][]"></td> |
| 116 | 116 | <td><input type="text" placeholder="Lien" name="concur[<?php echo $product['post_datas']->ID; ?>][link][]"></td> |
| 117 | - <td><?php $att = wpshop_attributes::display_attribute( 'concurents_', 'backend', $output_specs ); echo preg_replace( '/name=".*?"/i', 'name="concur[' .$product['post_datas']->ID. '][name][]"', preg_replace( '/class=".*?"/i', 'class="wpshop_product_attribute_concurents_ chosen_select_concur"', $att['field_definition']['output'] ) ); ?></td> |
|
| 117 | + <td><?php $att = wpshop_attributes::display_attribute('concurents_', 'backend', $output_specs); echo preg_replace('/name=".*?"/i', 'name="concur[' . $product['post_datas']->ID . '][name][]"', preg_replace('/class=".*?"/i', 'class="wpshop_product_attribute_concurents_ chosen_select_concur"', $att['field_definition']['output'])); ?></td> |
|
| 118 | 118 | <td><input type="text" placeholder="Prix" name="concur[<?php echo $product['post_datas']->ID; ?>][price][]"></td> |
| 119 | 119 | <td class="del_concur" style="color: red; cursor: pointer;">Supprimer</td> |
| 120 | - <?php for ($j=0; $j < $i-2; $j++) { |
|
| 120 | + <?php for ($j = 0; $j < $i - 2; $j++) { |
|
| 121 | 121 | echo '<td></td>'; |
| 122 | 122 | } ?> |
| 123 | 123 | </tr> |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | <td></td> |
| 128 | 128 | <td></td> |
| 129 | 129 | <td class="add_concur" style="color: #0073aa; cursor: pointer;">Ajouter un concurrent</td> |
| 130 | - <?php for ($j=0; $j < $i-1; $j++) { |
|
| 130 | + <?php for ($j = 0; $j < $i - 1; $j++) { |
|
| 131 | 131 | echo '<td></td>'; |
| 132 | 132 | } ?> |
| 133 | 133 | </tr> |
@@ -4,37 +4,37 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | class wps_product_variation_interface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Array of variations. |
|
| 9 | - * |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - private $variations = null; |
|
| 13 | - /** |
|
| 14 | - * Call hooks. |
|
| 15 | - */ |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 7 | + /** |
|
| 8 | + * Array of variations. |
|
| 9 | + * |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + private $variations = null; |
|
| 13 | + /** |
|
| 14 | + * Call hooks. |
|
| 15 | + */ |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | 18 | add_action('init', array($this, 'init')); |
| 19 | - add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 11, 2); |
|
| 20 | - add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 21 | - add_filter('wpshop_attribute_output_def', array($this, 'wpshop_attribute_output_def'), 10, 2); |
|
| 22 | - } |
|
| 23 | - /** |
|
| 24 | - * Call private functions if class is activate. |
|
| 25 | - * |
|
| 26 | - * @param string $name Name of function to call. |
|
| 27 | - * @param array $arguments Array of arguments to pass. |
|
| 28 | - * @return mixed Return of real function called. |
|
| 29 | - */ |
|
| 30 | - public function __call($name, $arguments) |
|
| 31 | - { |
|
| 32 | - if (method_exists($this, $name)) { |
|
| 33 | - if ($this->is_activate()) { |
|
| 34 | - return call_user_func_array(array($this, $name), $arguments); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 19 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 11, 2); |
|
| 20 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 21 | + add_filter('wpshop_attribute_output_def', array($this, 'wpshop_attribute_output_def'), 10, 2); |
|
| 22 | + } |
|
| 23 | + /** |
|
| 24 | + * Call private functions if class is activate. |
|
| 25 | + * |
|
| 26 | + * @param string $name Name of function to call. |
|
| 27 | + * @param array $arguments Array of arguments to pass. |
|
| 28 | + * @return mixed Return of real function called. |
|
| 29 | + */ |
|
| 30 | + public function __call($name, $arguments) |
|
| 31 | + { |
|
| 32 | + if (method_exists($this, $name)) { |
|
| 33 | + if ($this->is_activate()) { |
|
| 34 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | public function init() { |
| 39 | 39 | $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])) : ''; // Input var okay. |
| 40 | 40 | $wps_variation_interface = !empty($_GET['wps_variation_interface']) ? filter_var(wp_unslash($_GET['wps_variation_interface']), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : null; // Input var okay. |
@@ -42,141 +42,141 @@ discard block |
||
| 42 | 42 | $this->is_activate($wps_variation_interface); |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - /** |
|
| 46 | - * Get if module is active. |
|
| 47 | - * |
|
| 48 | - * @param boolean $new_val If set & db is different, save it. |
|
| 49 | - * @return boolean Actual state of module. |
|
| 50 | - */ |
|
| 51 | - public function is_activate($new_val = null) |
|
| 52 | - { |
|
| 53 | - if (!isset($this->is_active)) { |
|
| 54 | - $option = get_option('wps_variation_interface_display', null); |
|
| 55 | - if (is_null($option)) { |
|
| 56 | - $new_val = true; |
|
| 57 | - $option = false; |
|
| 58 | - } |
|
| 59 | - $this->is_active = (bool) $option; |
|
| 60 | - } |
|
| 61 | - if (isset($new_val) && $this->is_active !== $new_val) { |
|
| 62 | - update_option('wps_variation_interface_display', $new_val); |
|
| 63 | - $this->is_active = $new_val; |
|
| 64 | - } |
|
| 65 | - return $this->is_active; |
|
| 66 | - } |
|
| 67 | - /** |
|
| 68 | - * Get variations of an element. |
|
| 69 | - * |
|
| 70 | - * @param array $element Direct array attribute of db. |
|
| 71 | - * @return void It set directly in variable class. |
|
| 72 | - */ |
|
| 73 | - private function get_variations($element) |
|
| 74 | - { |
|
| 75 | - if (!isset($this->variations)) { |
|
| 76 | - $variations = wpshop_attributes::get_variation_available_attribute($element); |
|
| 77 | - $this->variations = (array) array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array())); |
|
| 78 | - unset($variations); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - public function add_meta_boxes($post_status, $post) |
|
| 82 | - { |
|
| 83 | - global $pagenow; |
|
| 84 | - if ($this->is_activate()) { |
|
| 85 | - $this->get_variations($post->ID); |
|
| 86 | - remove_meta_box('wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal'); |
|
| 87 | - if ($pagenow !== 'post-new.php' && !empty($this->variations)) { |
|
| 88 | - add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array($this, 'meta_box_variation'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - /** |
|
| 93 | - * The metabox. |
|
| 94 | - * |
|
| 95 | - * @param object $post Given by WordPress. |
|
| 96 | - * @return void Display directly. |
|
| 97 | - */ |
|
| 98 | - private function meta_box_variation($post) |
|
| 99 | - { |
|
| 100 | - $this->get_variations($post->ID); |
|
| 101 | - global $wpdb; |
|
| 102 | - $ids = array(); |
|
| 103 | - foreach ($this->variations as $key => $variation) { |
|
| 104 | - $available = wpshop_attributes::get_select_output($variation['attribute_complete_def']); |
|
| 105 | - $this->variations[$key]['available'] = array_keys($available['possible_value']); |
|
| 106 | - $ids = array_merge($ids, array_keys($available['possible_value'])); |
|
| 107 | - } |
|
| 108 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE id IN ('" . implode("', '", $ids) . "') AND status = %s", 'valid'); |
|
| 109 | - $product = wpshop_products::get_product_data($post->ID, false, '"publish"'); |
|
| 110 | - $is_used_in_variation = wpshop_attributes::getElement('yes', "'valid', 'notused'", 'is_used_in_variation', true); |
|
| 111 | - $attribute_list = array(); |
|
| 112 | - foreach ($is_used_in_variation as $attribute) { |
|
| 113 | - if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'), true)) { |
|
| 114 | - $values = wpshop_attributes::get_select_output($attribute); |
|
| 115 | - if (!empty($values['possible_value'])) { |
|
| 116 | - $attribute->possible_value = $values['possible_value']; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - $attribute_list[$attribute->code] = $attribute; |
|
| 120 | - } |
|
| 121 | - $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true); |
|
| 122 | - $variations_saved = wpshop_products::get_variation($post->ID); |
|
| 123 | - if (!empty($variations_saved)) { |
|
| 124 | - foreach ($variations_saved as $variation_id => $variation) { |
|
| 125 | - $downloadable = get_post_meta($variation_id, 'attribute_option_is_downloadable_', true); |
|
| 126 | - if (!empty($downloadable['file_url'])) { |
|
| 127 | - $variations_saved[$variation_id]['file']['path'] = $downloadable['file_url']; |
|
| 128 | - $variations_saved[$variation_id]['file']['name'] = basename($downloadable['file_url']); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 133 | - $product_currency = wpshop_tools::wpshop_get_currency(); |
|
| 134 | - wp_enqueue_style('wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css'); |
|
| 135 | - wp_enqueue_script('wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js'); |
|
| 136 | - wp_enqueue_script('wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js'); |
|
| 137 | - wp_localize_script('wps-product-variation-interface-script', 'wps_product_variation_interface', array('variation' => $this->variations, 'nonce_delete' => wp_create_nonce('wpshop_variation_management'), 'variation_value' => $wpdb->get_results($query), 'product_price' => $product['product_price'], 'tx_tva' => $product['tx_tva'], 'attribute_in_variation' => $attribute_list, 'variations_saved' => $variations_saved, 'price_piloting' => $price_piloting, 'currency' => $product_currency, 'variation_defining' => $variation_defining, 'label_file' => __('Click to add file', 'wpshop'))); |
|
| 138 | - require_once wpshop_tools::get_template_part(WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation'); |
|
| 139 | - } |
|
| 140 | - /** |
|
| 141 | - * Save other values out of old variation interface. |
|
| 142 | - * |
|
| 143 | - * @param int $post_id Id of post. |
|
| 144 | - * @param object $post WP_Post of WordPress. |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - private function save_post($post_id, $post) |
|
| 148 | - { |
|
| 149 | - if (wp_is_post_revision($post_id) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || !isset($_REQUEST['wpshop_variation_defining']['options']) || !isset($_REQUEST['wps_pdt_variations'])) { |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - wpshop_products::variation_parameters_save($post_id, $_REQUEST['wpshop_variation_defining']['options']); |
|
| 153 | - remove_action('save_post', array($this, 'save_post')); |
|
| 154 | - foreach ($_REQUEST['wps_pdt_variations'] as $variation_id => $data) { |
|
| 155 | - $variation = array('ID' => $variation_id); |
|
| 156 | - if (isset($data['status']) && 'on' === $data['status']) { |
|
| 157 | - $variation['post_status'] = 'publish'; |
|
| 158 | - } else { |
|
| 159 | - $variation['post_status'] = 'draft'; |
|
| 160 | - } |
|
| 161 | - wp_update_post($variation); |
|
| 162 | - } |
|
| 163 | - add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 164 | - } |
|
| 165 | - /** |
|
| 166 | - * Delete display in attributes products always in metabox. |
|
| 167 | - * |
|
| 168 | - * @param array $output Result of wpshop_attributes::display_attribute() function. |
|
| 169 | - * @param array $element Direct array attribute of db. |
|
| 170 | - * @return array SAme array $output modified. |
|
| 171 | - */ |
|
| 172 | - public function wpshop_attribute_output_def($output, $element) |
|
| 173 | - { |
|
| 174 | - if ($this->is_activate()) { |
|
| 175 | - $this->get_variations($element); |
|
| 176 | - if (!empty($this->variations) && in_array($output['field_definition']['name'], array_keys($this->variations), true)) { |
|
| 177 | - $output['field'] = ''; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - return $output; |
|
| 181 | - } |
|
| 45 | + /** |
|
| 46 | + * Get if module is active. |
|
| 47 | + * |
|
| 48 | + * @param boolean $new_val If set & db is different, save it. |
|
| 49 | + * @return boolean Actual state of module. |
|
| 50 | + */ |
|
| 51 | + public function is_activate($new_val = null) |
|
| 52 | + { |
|
| 53 | + if (!isset($this->is_active)) { |
|
| 54 | + $option = get_option('wps_variation_interface_display', null); |
|
| 55 | + if (is_null($option)) { |
|
| 56 | + $new_val = true; |
|
| 57 | + $option = false; |
|
| 58 | + } |
|
| 59 | + $this->is_active = (bool) $option; |
|
| 60 | + } |
|
| 61 | + if (isset($new_val) && $this->is_active !== $new_val) { |
|
| 62 | + update_option('wps_variation_interface_display', $new_val); |
|
| 63 | + $this->is_active = $new_val; |
|
| 64 | + } |
|
| 65 | + return $this->is_active; |
|
| 66 | + } |
|
| 67 | + /** |
|
| 68 | + * Get variations of an element. |
|
| 69 | + * |
|
| 70 | + * @param array $element Direct array attribute of db. |
|
| 71 | + * @return void It set directly in variable class. |
|
| 72 | + */ |
|
| 73 | + private function get_variations($element) |
|
| 74 | + { |
|
| 75 | + if (!isset($this->variations)) { |
|
| 76 | + $variations = wpshop_attributes::get_variation_available_attribute($element); |
|
| 77 | + $this->variations = (array) array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array())); |
|
| 78 | + unset($variations); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + public function add_meta_boxes($post_status, $post) |
|
| 82 | + { |
|
| 83 | + global $pagenow; |
|
| 84 | + if ($this->is_activate()) { |
|
| 85 | + $this->get_variations($post->ID); |
|
| 86 | + remove_meta_box('wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal'); |
|
| 87 | + if ($pagenow !== 'post-new.php' && !empty($this->variations)) { |
|
| 88 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array($this, 'meta_box_variation'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + /** |
|
| 93 | + * The metabox. |
|
| 94 | + * |
|
| 95 | + * @param object $post Given by WordPress. |
|
| 96 | + * @return void Display directly. |
|
| 97 | + */ |
|
| 98 | + private function meta_box_variation($post) |
|
| 99 | + { |
|
| 100 | + $this->get_variations($post->ID); |
|
| 101 | + global $wpdb; |
|
| 102 | + $ids = array(); |
|
| 103 | + foreach ($this->variations as $key => $variation) { |
|
| 104 | + $available = wpshop_attributes::get_select_output($variation['attribute_complete_def']); |
|
| 105 | + $this->variations[$key]['available'] = array_keys($available['possible_value']); |
|
| 106 | + $ids = array_merge($ids, array_keys($available['possible_value'])); |
|
| 107 | + } |
|
| 108 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE id IN ('" . implode("', '", $ids) . "') AND status = %s", 'valid'); |
|
| 109 | + $product = wpshop_products::get_product_data($post->ID, false, '"publish"'); |
|
| 110 | + $is_used_in_variation = wpshop_attributes::getElement('yes', "'valid', 'notused'", 'is_used_in_variation', true); |
|
| 111 | + $attribute_list = array(); |
|
| 112 | + foreach ($is_used_in_variation as $attribute) { |
|
| 113 | + if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'), true)) { |
|
| 114 | + $values = wpshop_attributes::get_select_output($attribute); |
|
| 115 | + if (!empty($values['possible_value'])) { |
|
| 116 | + $attribute->possible_value = $values['possible_value']; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + $attribute_list[$attribute->code] = $attribute; |
|
| 120 | + } |
|
| 121 | + $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true); |
|
| 122 | + $variations_saved = wpshop_products::get_variation($post->ID); |
|
| 123 | + if (!empty($variations_saved)) { |
|
| 124 | + foreach ($variations_saved as $variation_id => $variation) { |
|
| 125 | + $downloadable = get_post_meta($variation_id, 'attribute_option_is_downloadable_', true); |
|
| 126 | + if (!empty($downloadable['file_url'])) { |
|
| 127 | + $variations_saved[$variation_id]['file']['path'] = $downloadable['file_url']; |
|
| 128 | + $variations_saved[$variation_id]['file']['name'] = basename($downloadable['file_url']); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 133 | + $product_currency = wpshop_tools::wpshop_get_currency(); |
|
| 134 | + wp_enqueue_style('wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css'); |
|
| 135 | + wp_enqueue_script('wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js'); |
|
| 136 | + wp_enqueue_script('wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js'); |
|
| 137 | + wp_localize_script('wps-product-variation-interface-script', 'wps_product_variation_interface', array('variation' => $this->variations, 'nonce_delete' => wp_create_nonce('wpshop_variation_management'), 'variation_value' => $wpdb->get_results($query), 'product_price' => $product['product_price'], 'tx_tva' => $product['tx_tva'], 'attribute_in_variation' => $attribute_list, 'variations_saved' => $variations_saved, 'price_piloting' => $price_piloting, 'currency' => $product_currency, 'variation_defining' => $variation_defining, 'label_file' => __('Click to add file', 'wpshop'))); |
|
| 138 | + require_once wpshop_tools::get_template_part(WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation'); |
|
| 139 | + } |
|
| 140 | + /** |
|
| 141 | + * Save other values out of old variation interface. |
|
| 142 | + * |
|
| 143 | + * @param int $post_id Id of post. |
|
| 144 | + * @param object $post WP_Post of WordPress. |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + private function save_post($post_id, $post) |
|
| 148 | + { |
|
| 149 | + if (wp_is_post_revision($post_id) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || !isset($_REQUEST['wpshop_variation_defining']['options']) || !isset($_REQUEST['wps_pdt_variations'])) { |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + wpshop_products::variation_parameters_save($post_id, $_REQUEST['wpshop_variation_defining']['options']); |
|
| 153 | + remove_action('save_post', array($this, 'save_post')); |
|
| 154 | + foreach ($_REQUEST['wps_pdt_variations'] as $variation_id => $data) { |
|
| 155 | + $variation = array('ID' => $variation_id); |
|
| 156 | + if (isset($data['status']) && 'on' === $data['status']) { |
|
| 157 | + $variation['post_status'] = 'publish'; |
|
| 158 | + } else { |
|
| 159 | + $variation['post_status'] = 'draft'; |
|
| 160 | + } |
|
| 161 | + wp_update_post($variation); |
|
| 162 | + } |
|
| 163 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 164 | + } |
|
| 165 | + /** |
|
| 166 | + * Delete display in attributes products always in metabox. |
|
| 167 | + * |
|
| 168 | + * @param array $output Result of wpshop_attributes::display_attribute() function. |
|
| 169 | + * @param array $element Direct array attribute of db. |
|
| 170 | + * @return array SAme array $output modified. |
|
| 171 | + */ |
|
| 172 | + public function wpshop_attribute_output_def($output, $element) |
|
| 173 | + { |
|
| 174 | + if ($this->is_activate()) { |
|
| 175 | + $this->get_variations($element); |
|
| 176 | + if (!empty($this->variations) && in_array($output['field_definition']['name'], array_keys($this->variations), true)) { |
|
| 177 | + $output['field'] = ''; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + return $output; |
|
| 181 | + } |
|
| 182 | 182 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <div id="wps_variations_summary"> |
| 2 | - <div data-view-model="wps_variations_options_summary" id="wps_variations_summary_display"><b>%summary%</b></div><a id="wps_variations_parameters" href="<?php print wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=false', 'wps_remove_variation_interface');?>" title="<?php _e('Back to old interface', 'wpshop'); ?>"><span class="dashicons dashicons-admin-generic"></span></a> |
|
| 2 | + <div data-view-model="wps_variations_options_summary" id="wps_variations_summary_display"><b>%summary%</b></div><a id="wps_variations_parameters" href="<?php print wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=false', 'wps_remove_variation_interface'); ?>" title="<?php _e('Back to old interface', 'wpshop'); ?>"><span class="dashicons dashicons-admin-generic"></span></a> |
|
| 3 | 3 | </div> |
| 4 | 4 | <div id="wps_variations_options"> |
| 5 | 5 | <ul id="wps_variations_options_title"> |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | <li class="wps_variations_price_vat_col">%vat%%currency%</li> |
| 55 | 55 | <li class="wps_variations_price_stock_col"><input type="text" pattern="[0-9]*" onchange="wps_variations_price_option_raw.control.stock(this)" name="wps_pdt_variations[%ID%][attribute][decimal][product_stock]" align="right" value="%stock%"></li> |
| 56 | 56 | <li class="wps_variations_price_weight_col"><input type="text" pattern="[0-9]+(\.[0-9][0-9]?)?" onchange="wps_variations_price_option_raw.control.weight(this)" name="wps_pdt_variations[%ID%][attribute][decimal][product_weight]" align="right" value="%weight%"></li> |
| 57 | - <li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"><?php echo apply_filters('wpshop_new_interface_variation_download_file_dialog', '<span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span><input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)">' . wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce') . '<a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"><span class="dashicons dashicons-download"></span></a>' ); ?></li> |
|
| 57 | + <li class="wps_variations_price_file_col" data-view-model="wps_variations_price_option_file_%ID%"><?php echo apply_filters('wpshop_new_interface_variation_download_file_dialog', '<span class="wps_variations_price_option_price_file" onclick="wps_variations_price_option_raw.control.file(this)">%link%</span><input style="display: none;" type="file" name="wpshop_file" id="wpshop_file" onchange="wps_variations_price_option_raw.control.link(event, this)">' . wp_nonce_field('ajax_wpshop_upload_downloadable_file_action', 'wpshop_file_nonce') . '<a class="wps_variations_price_option_price_download_file" href="%path%" target="_blank" download="" style="display: %download%"><span class="dashicons dashicons-download"></span></a>'); ?></li> |
|
| 58 | 58 | <li class="wps_variations_price_active_col"><input name="wps_pdt_variations[%ID%][status]" onclick="wps_variations_price_option_raw.control.activate(this)" type="checkbox" %price_option_activate%></li> |
| 59 | 59 | </ul> |
| 60 | 60 | </div> |
@@ -1,64 +1,64 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | ?> |
| 3 | -<!-- <h3 class="wps-h3"><?php _e( 'Cart summary', 'wpshop' ); ?></h3> --> |
|
| 3 | +<!-- <h3 class="wps-h3"><?php _e('Cart summary', 'wpshop'); ?></h3> --> |
|
| 4 | 4 | <ul class="wps-cart-resume-list"> |
| 5 | - <?php foreach( $cart_items as $item_id => $item ) : |
|
| 5 | + <?php foreach ($cart_items as $item_id => $item) : |
|
| 6 | 6 | $product_key = $item_id; |
| 7 | - $item_post_type = get_post_type( $item_id ); |
|
| 7 | + $item_post_type = get_post_type($item_id); |
|
| 8 | 8 | |
| 9 | 9 | $variations_indicator = ''; |
| 10 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails( get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true) ) ; |
|
| 10 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 11 | 11 | $output_order = array(); |
| 12 | - if ( count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail) ) { |
|
| 13 | - foreach ( $product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 14 | - foreach ( $product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 15 | - if ( !empty($attribute_def->code) ) |
|
| 12 | + if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 13 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 14 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 15 | + if (!empty($attribute_def->code)) |
|
| 16 | 16 | $output_order[$attribute_def->code] = $position; |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display( $item['item_meta'], $output_order, 'cart' ); |
|
| 20 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'cart'); |
|
| 21 | 21 | ksort($variation_attribute_ordered['attribute_list']); |
| 22 | - if( !empty($variation_attribute_ordered['attribute_list']) ) { |
|
| 22 | + if (!empty($variation_attribute_ordered['attribute_list'])) { |
|
| 23 | 23 | $variations_indicator .= '<ul class="wps-cart-item-variations" >'; |
| 24 | - foreach ( $variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output ) { |
|
| 25 | - if ( !empty($attribute_variation_to_output) ) { |
|
| 24 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 25 | + if (!empty($attribute_variation_to_output)) { |
|
| 26 | 26 | $variations_indicator .= $attribute_variation_to_output; |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | - $variations_indicator = apply_filters( 'wps_cart_item_variation_list', $variations_indicator, $variation_attribute_ordered, $item, 0 ); |
|
| 29 | + $variations_indicator = apply_filters('wps_cart_item_variation_list', $variations_indicator, $variation_attribute_ordered, $item, 0); |
|
| 30 | 30 | $variations_indicator .= '</ul>'; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( $item_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 34 | - $parent_def = wpshop_products::get_parent_variation( $item_id ); |
|
| 33 | + if ($item_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 34 | + $parent_def = wpshop_products::get_parent_variation($item_id); |
|
| 35 | 35 | $parent_post = $parent_def['parent_post']; |
| 36 | 36 | $item_id = $parent_post->ID; |
| 37 | - $item_title = $parent_post->post_title; |
|
| 37 | + $item_title = $parent_post->post_title; |
|
| 38 | 38 | } else { |
| 39 | 39 | $item_title = $item['item_name']; |
| 40 | 40 | } |
| 41 | 41 | ?> |
| 42 | 42 | <li data-id="<?php echo $product_key; ?>" > |
| 43 | 43 | <div class="wps-cart-item-img"> |
| 44 | - <a href="<?php echo get_permalink( $item_id ); ?>" title="<?php echo $item_title; ?>"> |
|
| 45 | - <?php echo get_the_post_thumbnail( $item_id, 'thumbnail' ); ?> |
|
| 44 | + <a href="<?php echo get_permalink($item_id); ?>" title="<?php echo $item_title; ?>"> |
|
| 45 | + <?php echo get_the_post_thumbnail($item_id, 'thumbnail'); ?> |
|
| 46 | 46 | </a> |
| 47 | 47 | </div> |
| 48 | 48 | <div class="wps-cart-item-content"> |
| 49 | - <a class="wps-cart-item-title" href="<?php echo get_permalink( $item_id ); ?>" title="<?php echo $item_title; ?>"> |
|
| 49 | + <a class="wps-cart-item-title" href="<?php echo get_permalink($item_id); ?>" title="<?php echo $item_title; ?>"> |
|
| 50 | 50 | <?php echo $item_title; ?> |
| 51 | 51 | </a> |
| 52 | 52 | <?php echo $variations_indicator; ?> |
| 53 | 53 | <div class="wps-productQtyForm "> |
| 54 | 54 | <a href="" class="wps-cart-reduce-product-qty"><i class="wps-icon-minus"></i></a> |
| 55 | - <input type="text" name="french-hens" id="wps-cart-product-qty-<?php echo $product_key; ?>" data-nonce="<?php echo wp_create_nonce( 'ajax_wpshop_set_qty_for_product_into_cart' ); ?>" value="<?php echo $item['item_qty']; ?>" class="wps-circlerounded wps-cart-product-qty"> |
|
| 55 | + <input type="text" name="french-hens" id="wps-cart-product-qty-<?php echo $product_key; ?>" data-nonce="<?php echo wp_create_nonce('ajax_wpshop_set_qty_for_product_into_cart'); ?>" value="<?php echo $item['item_qty']; ?>" class="wps-circlerounded wps-cart-product-qty"> |
|
| 56 | 56 | <a href="" class="wps-cart-add-product-qty"><i class="wps-icon-plus"></i></a> |
| 57 | 57 | </div> |
| 58 | 58 | </div> |
| 59 | 59 | <div class="wps-cart-item-price"> |
| 60 | - <span class="wps-price"><?php echo wpshop_tools::formate_number( $item['item_total_ttc'] ); ?> <span><?php echo $currency; ?></span></span> |
|
| 61 | - <span class="wps-tva"><?php _e( 'ATI', 'wpshop'); ?></span><br> |
|
| 60 | + <span class="wps-price"><?php echo wpshop_tools::formate_number($item['item_total_ttc']); ?> <span><?php echo $currency; ?></span></span> |
|
| 61 | + <span class="wps-tva"><?php _e('ATI', 'wpshop'); ?></span><br> |
|
| 62 | 62 | </div> |
| 63 | 63 | </li> |
| 64 | 64 | <?php endforeach; ?> |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | <?php echo do_shortcode('[wps_apply_coupon]'); ?> |
| 69 | 69 | </div> |
| 70 | 70 | <div class="wps-cart-total"> |
| 71 | - <p><?php _e( 'Shipping cost ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $shipping_cost_ati ); ?></strong><?php echo $currency; ?></span></p> |
|
| 72 | - <?php if ( !empty( $cart_content['coupon_id']) ) : ?> |
|
| 73 | - <p><?php _e( 'Total ATI before discount', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number( $order_total_before_discount ); ?></strong><?php echo $currency; ?></span></p> |
|
| 74 | - <p><?php _e( 'Discount', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number( $coupon_value ); ?></strong><?php echo $currency; ?></span></p> |
|
| 71 | + <p><?php _e('Shipping cost ATI', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($shipping_cost_ati); ?></strong><?php echo $currency; ?></span></p> |
|
| 72 | + <?php if (!empty($cart_content['coupon_id'])) : ?> |
|
| 73 | + <p><?php _e('Total ATI before discount', 'wpshop'); ?><span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($order_total_before_discount); ?></strong><?php echo $currency; ?></span></p> |
|
| 74 | + <p><?php _e('Discount', 'wpshop'); ?><span class="wps-inline-alignRight"><strong><?php echo wpshop_tools::formate_number($coupon_value); ?></strong><?php echo $currency; ?></span></p> |
|
| 75 | 75 | <?php endif; ?> |
| 76 | 76 | <p class="wps-hightlight"> |
| 77 | - <?php _e( 'Total ATI', 'wpshop'); ?> |
|
| 77 | + <?php _e('Total ATI', 'wpshop'); ?> |
|
| 78 | 78 | <span class="wps-inline-alignRight"> |
| 79 | - <strong><?php echo wpshop_tools::formate_number( $total_ati ); ?></strong> |
|
| 79 | + <strong><?php echo wpshop_tools::formate_number($total_ati); ?></strong> |
|
| 80 | 80 | <?php echo $currency; ?> |
| 81 | 81 | </span> |
| 82 | 82 | </p> |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | </div><!-- wps-cart-cartouche --> |
| 85 | 85 | |
| 86 | 86 | <?php $wps_payment_mode = get_option('wps_payment_mode'); ?> |
| 87 | -<?php if( isset( $wps_payment_mode['mode']['paypal']['active'] ) ): ?> |
|
| 87 | +<?php if (isset($wps_payment_mode['mode']['paypal']['active'])): ?> |
|
| 88 | 88 | <div class="wps-secured-logos"> |
| 89 | 89 | <span class="wps-logo-paypal"></span> |
| 90 | 90 | <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 | <!-- <h3 class="wps-h3"><?php _e( 'Cart summary', 'wpshop' ); ?></h3> --> |
| 4 | 6 | <ul class="wps-cart-resume-list"> |
@@ -12,8 +14,9 @@ discard block |
||
| 12 | 14 | if ( count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail) ) { |
| 13 | 15 | foreach ( $product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
| 14 | 16 | foreach ( $product_attr_group_detail['attribut'] as $position => $attribute_def) { |
| 15 | - if ( !empty($attribute_def->code) ) |
|
| 16 | - $output_order[$attribute_def->code] = $position; |
|
| 17 | + if ( !empty($attribute_def->code) ) { |
|
| 18 | + $output_order[$attribute_def->code] = $position; |
|
| 19 | + } |
|
| 17 | 20 | } |
| 18 | 21 | } |
| 19 | 22 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit;
|
|
| 2 | 2 | /** |
| 3 | 3 | * Manage Customer general and front-end functions |
| 4 | 4 | * @author ALLEGRE Jérôme - EOXIA |
@@ -8,29 +8,29 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | function __construct() {
|
| 10 | 10 | /** Create customer entity type on wordpress initilisation*/ |
| 11 | - add_action( 'init', array( $this, 'create_customer_entity' ) ); |
|
| 11 | + add_action('init', array($this, 'create_customer_entity'));
|
|
| 12 | 12 | |
| 13 | 13 | /** Call style for administration */ |
| 14 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_css' ) ); |
|
| 14 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_css'));
|
|
| 15 | 15 | |
| 16 | - add_action( 'admin_init', array( $this, 'customer_action_on_plugin_init' ) ); |
|
| 17 | - add_action( 'admin_init', array( $this, 'redirect_new_user' ) ); |
|
| 18 | - add_action( 'admin_menu', array( $this, 'customer_action_on_menu' ) ); |
|
| 16 | + add_action('admin_init', array($this, 'customer_action_on_plugin_init'));
|
|
| 17 | + add_action('admin_init', array($this, 'redirect_new_user'));
|
|
| 18 | + add_action('admin_menu', array($this, 'customer_action_on_menu'));
|
|
| 19 | 19 | |
| 20 | 20 | /** When a wordpress user is created, create a customer (post type) */ |
| 21 | - add_action( 'user_register', array( $this, 'create_entity_customer_when_user_is_created') ); |
|
| 22 | - add_action( 'edit_user_profile_update', array( $this, 'update_entity_customer_when_profile_user_is_update' ) ); |
|
| 21 | + add_action('user_register', array($this, 'create_entity_customer_when_user_is_created'));
|
|
| 22 | + add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update'));
|
|
| 23 | 23 | |
| 24 | 24 | /** When save customer update */ |
| 25 | - add_action( 'save_post', array( $this, 'save_entity_customer' ), 10, 2 ); |
|
| 25 | + add_action('save_post', array($this, 'save_entity_customer'), 10, 2);
|
|
| 26 | 26 | //add_action( 'admin_notices', array( $this, 'notice_save_post_customer_informations' ) ); |
| 27 | 27 | |
| 28 | 28 | /** Add filters for customer list */ |
| 29 | - add_filter( 'bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array( $this, 'customer_list_table_bulk_actions' ) ); |
|
| 30 | - add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array( $this, 'list_table_header' ) ); |
|
| 31 | - add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column' , array( $this, 'list_table_column_content' ), 10, 2 ); |
|
| 32 | - add_action( 'restrict_manage_posts', array(&$this, 'list_table_filters') ); |
|
| 33 | - add_filter( 'parse_query', array(&$this, 'list_table_filter_parse_query') ); |
|
| 29 | + add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions'));
|
|
| 30 | + add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header'));
|
|
| 31 | + add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2);
|
|
| 32 | + add_action('restrict_manage_posts', array(&$this, 'list_table_filters'));
|
|
| 33 | + add_filter('parse_query', array(&$this, 'list_table_filter_parse_query'));
|
|
| 34 | 34 | |
| 35 | 35 | /** Filter search for customers */ |
| 36 | 36 | //add_filter( 'pre_get_posts', array( $this, 'customer_search' ) ); |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * Customer options for the shop |
| 44 | 44 | */ |
| 45 | 45 | public static function declare_options() {
|
| 46 | - if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) {
|
|
| 47 | - $wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : ''; |
|
| 48 | - $old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : ''; |
|
| 46 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
|
|
| 47 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 48 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 49 | 49 | |
| 50 | - if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' ) |
|
| 51 | - && ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) {
|
|
| 50 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 51 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
|
|
| 52 | 52 | /** Add module option to wpshop general options */ |
| 53 | 53 | register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters'));
|
| 54 | 54 | add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info');
|
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param unknown_type $input |
| 63 | 63 | * @return unknown |
| 64 | 64 | */ |
| 65 | - public static function wpshop_options_validate_customers_newsleters( $input ) {
|
|
| 65 | + public static function wpshop_options_validate_customers_newsleters($input) {
|
|
| 66 | 66 | return $input; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $input_def['valueToPut'] = 'index'; |
| 78 | 78 | $input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no'; |
| 79 | 79 | $input_def['possible_value'] = 'yes'; |
| 80 | - $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __( 'Newsletters of the site', 'wpshop' ) . '</label>' . '<a href="#" title="'.__('Check this box if you want display newsletter site subscription','wpshop').'" class="wpshop_infobulle_marker">?</a>' . '<br>';
|
|
| 80 | + $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
|
|
| 81 | 81 | |
| 82 | 82 | $input_def = array(); |
| 83 | 83 | $input_def['name'] = ''; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $input_def['valueToPut'] = 'index'; |
| 87 | 87 | $input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no'; |
| 88 | 88 | $input_def['possible_value'] = 'yes'; |
| 89 | - $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __( 'Newsletters of the partners', 'wpshop' ) . '</label>' . '<a href="#" title="'.__('Check this box if you want display newsletter partners subscription','wpshop').'" class="wpshop_infobulle_marker">?</a>' . '<br>';
|
|
| 89 | + $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
|
|
| 90 | 90 | |
| 91 | 91 | echo $output; |
| 92 | 92 | } |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * Include stylesheets |
| 96 | 96 | */ |
| 97 | 97 | function admin_css() {
|
| 98 | - wp_register_style( 'wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION ); |
|
| 99 | - wp_enqueue_style( 'wpshop-modules-customer-backend-styles' ); |
|
| 98 | + wp_register_style('wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION);
|
|
| 99 | + wp_enqueue_style('wpshop-modules-customer-backend-styles');
|
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -115,27 +115,27 @@ discard block |
||
| 115 | 115 | $wps_customer_mdl = new wps_customer_mdl(); |
| 116 | 116 | $users = $wps_customer_mdl->getUserList(); |
| 117 | 117 | $select_users = ''; |
| 118 | - if( !empty($users) ) {
|
|
| 119 | - foreach($users as $user) {
|
|
| 118 | + if (!empty($users)) {
|
|
| 119 | + foreach ($users as $user) {
|
|
| 120 | 120 | if ($user->ID != 1) {
|
| 121 | - $lastname = get_user_meta( $user->ID, 'last_name', true ); |
|
| 122 | - $firstname = get_user_meta( $user->ID, 'first_name', true ); |
|
| 123 | - if ( ! empty( $customer_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) ) && ! empty( $company_attr = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE entity_id = %s AND code = %s AND status = %s', $customer_entity_id, 'company_customer', 'valid' ) ) ) ) {
|
|
| 124 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.strtolower($company_attr->data_type). ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $company_attr->id, wps_customer_ctr::get_customer_id_by_author_id( $user->ID ) ); |
|
| 125 | - $company_value = $wpdb->get_var( $query ); |
|
| 121 | + $lastname = get_user_meta($user->ID, 'last_name', true); |
|
| 122 | + $firstname = get_user_meta($user->ID, 'first_name', true); |
|
| 123 | + if (!empty($customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) && !empty($company_attr = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %s AND code = %s AND status = %s', $customer_entity_id, 'company_customer', 'valid')))) {
|
|
| 124 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($company_attr->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $company_attr->id, wps_customer_ctr::get_customer_id_by_author_id($user->ID));
|
|
| 125 | + $company_value = $wpdb->get_var($query); |
|
| 126 | 126 | } |
| 127 | 127 | ob_start(); ?> |
| 128 | - <option value="<?php echo $user->ID; ?>" <?php echo ( ( !$multiple ) && ( $selected_user == $user->ID ) ) ? ' selected="selected"' : ''; ?>> |
|
| 129 | - <?php echo $lastname; ?> <?php echo $firstname; ?> (<?php echo $user->user_email; ?>)<?php echo isset( $company_value ) ? ' : ' . $company_value : ''; ?> |
|
| 128 | + <option value="<?php echo $user->ID; ?>" <?php echo ((!$multiple) && ($selected_user == $user->ID)) ? ' selected="selected"' : ''; ?>> |
|
| 129 | + <?php echo $lastname; ?> <?php echo $firstname; ?> (<?php echo $user->user_email; ?>)<?php echo isset($company_value) ? ' : ' . $company_value : ''; ?> |
|
| 130 | 130 | </option> |
| 131 | 131 | <?php |
| 132 | 132 | $select_users .= ob_get_clean(); |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | $content_output = ' |
| 136 | - <select name="' . $customer_list_params['name'] . '" id="' . $customer_list_params['id'] . '" data-placeholder="' . __('Choose a customer', 'wpshop') . '" class="chosen_select"' . ( $multiple ? ' multiple="multiple" ' : '') . '' . ( $disabled ? ' disabled="disabled" ' : '') . '>
|
|
| 136 | + <select name="' . $customer_list_params['name'] . '" id="' . $customer_list_params['id'] . '" data-placeholder="' . __('Choose a customer', 'wpshop') . '" class="chosen_select"' . ($multiple ? ' multiple="multiple" ' : '') . '' . ($disabled ? ' disabled="disabled" ' : '') . '>
|
|
| 137 | 137 | <option value="0" ></option> |
| 138 | - '.$select_users.' |
|
| 138 | + '.$select_users . ' |
|
| 139 | 139 | </select>'; |
| 140 | 140 | } |
| 141 | 141 | return $content_output; |
@@ -153,26 +153,26 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | function create_customer_entity() {
|
| 155 | 155 | global $wpdb; |
| 156 | - $query = $wpdb->prepare( "SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params' );
|
|
| 157 | - $customer_entity_definition = $wpdb->get_row( $query ); |
|
| 158 | - $current_entity_params = !empty( $customer_entity_definition ) && !empty( $customer_entity_definition->meta_value ) ? unserialize( $customer_entity_definition->meta_value ) : null; |
|
| 156 | + $query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params');
|
|
| 157 | + $customer_entity_definition = $wpdb->get_row($query); |
|
| 158 | + $current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null; |
|
| 159 | 159 | |
| 160 | 160 | $post_type_params = array( |
| 161 | 161 | 'labels' => array( |
| 162 | - 'name' => __( 'Customers' , 'wpshop' ), |
|
| 163 | - 'singular_name' => __( 'Customer', 'wpshop' ), |
|
| 164 | - 'add_new_item' => __( 'New customer', 'wpshop' ), |
|
| 165 | - 'add_new' => __( 'New customer', 'wpshop' ), |
|
| 166 | - 'edit_item' => __( 'Edit customer', 'wpshop' ), |
|
| 167 | - 'new_item' => __( 'New customer', 'wpshop' ), |
|
| 168 | - 'view_item' => __( 'View customer', 'wpshop' ), |
|
| 169 | - 'search_items' => __( 'Search in customers', 'wpshop' ), |
|
| 170 | - 'not_found' => __( 'No customer found', 'wpshop' ), |
|
| 171 | - 'not_found_in_trash' => __( 'No customer founded in trash', 'wpshop' ), |
|
| 162 | + 'name' => __('Customers', 'wpshop'),
|
|
| 163 | + 'singular_name' => __('Customer', 'wpshop'),
|
|
| 164 | + 'add_new_item' => __('New customer', 'wpshop'),
|
|
| 165 | + 'add_new' => __('New customer', 'wpshop'),
|
|
| 166 | + 'edit_item' => __('Edit customer', 'wpshop'),
|
|
| 167 | + 'new_item' => __('New customer', 'wpshop'),
|
|
| 168 | + 'view_item' => __('View customer', 'wpshop'),
|
|
| 169 | + 'search_items' => __('Search in customers', 'wpshop'),
|
|
| 170 | + 'not_found' => __('No customer found', 'wpshop'),
|
|
| 171 | + 'not_found_in_trash' => __('No customer founded in trash', 'wpshop'),
|
|
| 172 | 172 | 'parent_item_colon' => '', |
| 173 | 173 | ), |
| 174 | 174 | 'description' => '', |
| 175 | - 'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array( 'title' ), |
|
| 175 | + 'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'),
|
|
| 176 | 176 | 'hierarchical' => false, |
| 177 | 177 | 'public' => false, |
| 178 | 178 | 'show_ui' => true, |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | 'delete_posts' => 'delete_product' |
| 197 | 197 | ) |
| 198 | 198 | ); |
| 199 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params ); |
|
| 199 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -210,30 +210,30 @@ discard block |
||
| 210 | 210 | /** |
| 211 | 211 | * Redirect when create new customer in admin |
| 212 | 212 | */ |
| 213 | - public function redirect_new_user(){
|
|
| 213 | + public function redirect_new_user() {
|
|
| 214 | 214 | global $pagenow; |
| 215 | 215 | |
| 216 | 216 | /* Check current admin page. */ |
| 217 | - if( $pagenow != 'user-new.php' && isset( $_SESSION['redirect_to_customer'] ) ) {
|
|
| 217 | + if ($pagenow != 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
|
|
| 218 | 218 | $redirect = $_SESSION['redirect_to_customer']; |
| 219 | - unset( $_SESSION['redirect_to_customer'] ); |
|
| 220 | - if( $pagenow == 'users.php' ) {
|
|
| 221 | - wp_redirect( admin_url( $redirect, 'http' ) ); |
|
| 219 | + unset($_SESSION['redirect_to_customer']); |
|
| 220 | + if ($pagenow == 'users.php') {
|
|
| 221 | + wp_redirect(admin_url($redirect, 'http')); |
|
| 222 | 222 | exit; |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /* Redirect to new user */ |
| 227 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 228 | - if( $pagenow == 'post-new.php' && isset( $post_type ) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) {
|
|
| 227 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 228 | + if ($pagenow == 'post-new.php' && isset($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
|
|
| 229 | 229 | $_SESSION['redirect_to_customer'] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS; |
| 230 | - wp_redirect( admin_url('user-new.php', 'http' ), 301 );
|
|
| 230 | + wp_redirect(admin_url('user-new.php', 'http'), 301);
|
|
| 231 | 231 | exit; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /* Include JS on new user customer */ |
| 235 | - if( $pagenow == 'user-new.php' && isset( $_SESSION['redirect_to_customer'] ) ) {
|
|
| 236 | - add_action( 'admin_print_scripts', array( $this, 'admin_user_customer_js' ), 20 ); |
|
| 235 | + if ($pagenow == 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
|
|
| 236 | + add_action('admin_print_scripts', array($this, 'admin_user_customer_js'), 20);
|
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | /* JS to select customer in place of suscriber */ |
@@ -249,23 +249,23 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @param integer $user_id |
| 251 | 251 | */ |
| 252 | - public static function create_entity_customer_when_user_is_created( $user_id ) {
|
|
| 253 | - $user_data = get_userdata( $user_id ); |
|
| 254 | - $user_info = array_merge( get_object_vars( $user_data->data ), array_map( 'self::array_map_create_entity_customer_when_user_is_created', get_user_meta( $user_id ) ) ); |
|
| 255 | - $customer_post_ID = wp_insert_post( array( 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename ) ); |
|
| 256 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 252 | + public static function create_entity_customer_when_user_is_created($user_id) {
|
|
| 253 | + $user_data = get_userdata($user_id); |
|
| 254 | + $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
|
|
| 255 | + $customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename));
|
|
| 256 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 257 | 257 | |
| 258 | 258 | /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ |
| 259 | - $usermeta = get_post_meta( $user_id, 'metaboxhidden_nav-menus', true); |
|
| 260 | - if ( !empty($usermeta) && is_array($usermeta) ) {
|
|
| 259 | + $usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true); |
|
| 260 | + if (!empty($usermeta) && is_array($usermeta)) {
|
|
| 261 | 261 | $data_to_delete = array_search('add-wpshop_product_category', $usermeta);
|
| 262 | - if ( $data_to_delete !== false ) {
|
|
| 263 | - unset( $usermeta[$data_to_delete] ); |
|
| 262 | + if ($data_to_delete !== false) {
|
|
| 263 | + unset($usermeta[$data_to_delete]); |
|
| 264 | 264 | update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta); |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | - private static function array_map_create_entity_customer_when_user_is_created( $a ) {
|
|
| 268 | + private static function array_map_create_entity_customer_when_user_is_created($a) {
|
|
| 269 | 269 | return $a[0]; |
| 270 | 270 | } |
| 271 | 271 | |
@@ -274,13 +274,13 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @param integer $user_id |
| 276 | 276 | */ |
| 277 | - public static function update_entity_customer_when_profile_user_is_update( $user_id ) {
|
|
| 278 | - $user_data = get_userdata( $user_id ); |
|
| 279 | - $user_info = array_merge( get_object_vars( $user_data->data ), array_map( 'self::array_map_create_entity_customer_when_user_is_created', get_user_meta( $user_id ) ) ); |
|
| 280 | - $customer_post_ID = self::get_customer_id_by_author_id( $user_id ); |
|
| 281 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 277 | + public static function update_entity_customer_when_profile_user_is_update($user_id) {
|
|
| 278 | + $user_data = get_userdata($user_id); |
|
| 279 | + $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
|
|
| 280 | + $customer_post_ID = self::get_customer_id_by_author_id($user_id); |
|
| 281 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 282 | 282 | } |
| 283 | - private static function array_map_update_entity_customer_when_profile_user_is_update( $a ) {
|
|
| 283 | + private static function array_map_update_entity_customer_when_profile_user_is_update($a) {
|
|
| 284 | 284 | return $a[0]; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -290,53 +290,53 @@ discard block |
||
| 290 | 290 | * @param integer $post_id |
| 291 | 291 | * @param WP_Post $post |
| 292 | 292 | */ |
| 293 | - public static function save_entity_customer( $customer_post_ID, $post ) {
|
|
| 294 | - if( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision( $customer_post_ID ) ) {
|
|
| 293 | + public static function save_entity_customer($customer_post_ID, $post) {
|
|
| 294 | + if (WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision($customer_post_ID)) {
|
|
| 295 | 295 | return; |
| 296 | 296 | } |
| 297 | 297 | $user_id = $post->post_author; |
| 298 | 298 | $user_info = array(); |
| 299 | - $attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : array(); |
|
| 300 | - if( !empty( $attribute ) ) {
|
|
| 301 | - foreach( $attribute as $type => $attributes ) {
|
|
| 302 | - foreach( $attributes as $meta => $attribute ) {
|
|
| 303 | - $user_info[$meta] = sanitize_text_field( $attribute ); |
|
| 299 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
| 300 | + if (!empty($attribute)) {
|
|
| 301 | + foreach ($attribute as $type => $attributes) {
|
|
| 302 | + foreach ($attributes as $meta => $attribute) {
|
|
| 303 | + $user_info[$meta] = sanitize_text_field($attribute); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 307 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 308 | 308 | /** Update newsletter user preferences **/ |
| 309 | 309 | $newsletter_preferences = array(); |
| 310 | - $newsletter_site = !empty( $_POST['newsletters_site'] ) ? sanitize_text_field( $_POST['newsletters_site'] ) : ''; |
|
| 311 | - if( !empty($newsletter_site) ) {
|
|
| 310 | + $newsletter_site = !empty($_POST['newsletters_site']) ? sanitize_text_field($_POST['newsletters_site']) : ''; |
|
| 311 | + if (!empty($newsletter_site)) {
|
|
| 312 | 312 | $newsletter_preferences['newsletters_site'] = 1; |
| 313 | 313 | } |
| 314 | - $newsletters_site_partners = !empty( $_POST['newsletters_site_partners'] ) ? sanitize_text_field( $_POST['newsletters_site_partners'] ) : ''; |
|
| 315 | - if( !empty($newsletters_site_partners) ) {
|
|
| 314 | + $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? sanitize_text_field($_POST['newsletters_site_partners']) : ''; |
|
| 315 | + if (!empty($newsletters_site_partners)) {
|
|
| 316 | 316 | $newsletter_preferences['newsletters_site_partners'] = 1; |
| 317 | 317 | } |
| 318 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
| 318 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
| 319 | 319 | return; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - public static function save_customer_synchronize( $customer_post_ID, $user_id, $user_info ) {
|
|
| 322 | + public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info) {
|
|
| 323 | 323 | global $wpdb; |
| 324 | 324 | global $wpshop; |
| 325 | - $exclude_user_meta = array( 'user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name' ); |
|
| 325 | + $exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name');
|
|
| 326 | 326 | $wps_entities = new wpshop_entities(); |
| 327 | - $element_id = $wps_entities->get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 328 | - $query = $wpdb->prepare( 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id ); |
|
| 329 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
| 327 | + $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 328 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
|
|
| 329 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 330 | 330 | $attributes_default = array(); |
| 331 | - if ( !empty( $attribute_set_id ) ) {
|
|
| 332 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
| 333 | - foreach ( $group as $attribute_sets ) {
|
|
| 334 | - foreach ( $attribute_sets as $attribute_set_field ) {
|
|
| 335 | - foreach( $attribute_set_field['content'] as $attribute ) {
|
|
| 336 | - if( isset( $attribute['value'] ) ) {
|
|
| 337 | - if( is_serialized( $attribute['value'] ) ) {
|
|
| 338 | - $unserialized_value = unserialize( $attribute['value'] ); |
|
| 339 | - if( isset( $unserialized_value['default_value'] ) ) {
|
|
| 331 | + if (!empty($attribute_set_id)) {
|
|
| 332 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
| 333 | + foreach ($group as $attribute_sets) {
|
|
| 334 | + foreach ($attribute_sets as $attribute_set_field) {
|
|
| 335 | + foreach ($attribute_set_field['content'] as $attribute) {
|
|
| 336 | + if (isset($attribute['value'])) {
|
|
| 337 | + if (is_serialized($attribute['value'])) {
|
|
| 338 | + $unserialized_value = unserialize($attribute['value']); |
|
| 339 | + if (isset($unserialized_value['default_value'])) {
|
|
| 340 | 340 | $attributes_default[$attribute['name']] = $unserialized_value['default_value']; |
| 341 | 341 | } |
| 342 | 342 | } else {
|
@@ -347,30 +347,30 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | - $user_info = array_merge( $attributes_default, $user_info ); |
|
| 351 | - foreach( $user_info as $user_meta => $user_meta_value ) {
|
|
| 352 | - $attribute_def = wpshop_attributes::getElement( $user_meta, "'valid'", 'code' ); |
|
| 353 | - if( !empty( $attribute_def ) ){
|
|
| 350 | + $user_info = array_merge($attributes_default, $user_info); |
|
| 351 | + foreach ($user_info as $user_meta => $user_meta_value) {
|
|
| 352 | + $attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code'); |
|
| 353 | + if (!empty($attribute_def)) {
|
|
| 354 | 354 | //Save data in user meta |
| 355 | - if( in_array( $user_meta, $exclude_user_meta ) ) {
|
|
| 356 | - if( $user_meta == 'user_pass' ) {
|
|
| 357 | - $new_password = wpshop_tools::varSanitizer( $user_meta_value ); |
|
| 358 | - if( wp_hash_password( $new_password ) == get_user_meta( $user_id, $user_meta, true ) ) {
|
|
| 355 | + if (in_array($user_meta, $exclude_user_meta)) {
|
|
| 356 | + if ($user_meta == 'user_pass') {
|
|
| 357 | + $new_password = wpshop_tools::varSanitizer($user_meta_value); |
|
| 358 | + if (wp_hash_password($new_password) == get_user_meta($user_id, $user_meta, true)) {
|
|
| 359 | 359 | continue; |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | - wp_update_user( array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer( $user_meta_value ) ) );
|
|
| 362 | + wp_update_user(array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer($user_meta_value)));
|
|
| 363 | 363 | } else {
|
| 364 | - update_user_meta( $user_id, $user_meta, wpshop_tools::varSanitizer( $user_meta_value ) ); |
|
| 364 | + update_user_meta($user_id, $user_meta, wpshop_tools::varSanitizer($user_meta_value)); |
|
| 365 | 365 | } |
| 366 | 366 | //Save data in attribute tables, ckeck first if exist to know if Insert or Update |
| 367 | - $query = $wpdb->prepare( 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id ); |
|
| 368 | - $checking_attribute_exist = $wpdb->get_results( $query ); |
|
| 369 | - if( !empty( $checking_attribute_exist ) ) {
|
|
| 367 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id);
|
|
| 368 | + $checking_attribute_exist = $wpdb->get_results($query); |
|
| 369 | + if (!empty($checking_attribute_exist)) {
|
|
| 370 | 370 | $wpdb->update( |
| 371 | - WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ), |
|
| 371 | + WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type), |
|
| 372 | 372 | array( |
| 373 | - 'value' => wpshop_tools::varSanitizer( $user_meta_value ) ), |
|
| 373 | + 'value' => wpshop_tools::varSanitizer($user_meta_value) ), |
|
| 374 | 374 | array( |
| 375 | 375 | 'entity_type_id' => $element_id, |
| 376 | 376 | 'entity_id' => $customer_post_ID, |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | } |
| 381 | 381 | else {
|
| 382 | 382 | $wpdb->insert( |
| 383 | - WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ), |
|
| 383 | + WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type), |
|
| 384 | 384 | array( |
| 385 | 385 | 'entity_type_id' => $element_id, |
| 386 | 386 | 'attribute_id' => $attribute_def->id, |
| 387 | 387 | 'entity_id' => $customer_post_ID, |
| 388 | 388 | 'user_id' => $user_id, |
| 389 | - 'creation_date_value' => current_time( 'mysql', 0 ), |
|
| 389 | + 'creation_date_value' => current_time('mysql', 0),
|
|
| 390 | 390 | 'language' => 'fr_FR', |
| 391 | - 'value' => wpshop_tools::varSanitizer( $user_meta_value ) |
|
| 391 | + 'value' => wpshop_tools::varSanitizer($user_meta_value) |
|
| 392 | 392 | ) |
| 393 | 393 | ); |
| 394 | 394 | } |
@@ -400,14 +400,14 @@ discard block |
||
| 400 | 400 | * Notice for errors on admin |
| 401 | 401 | */ |
| 402 | 402 | function notice_save_post_customer_informations() {
|
| 403 | - $errors = isset( $_SESSION['save_post_customer_informations_errors'] ) ? $_SESSION['save_post_customer_informations_errors'] : ''; |
|
| 404 | - if( !empty( $errors ) ) {
|
|
| 405 | - foreach( $errors as $error ) {
|
|
| 403 | + $errors = isset($_SESSION['save_post_customer_informations_errors']) ? $_SESSION['save_post_customer_informations_errors'] : ''; |
|
| 404 | + if (!empty($errors)) {
|
|
| 405 | + foreach ($errors as $error) {
|
|
| 406 | 406 | $class = "error"; |
| 407 | 407 | $message = $error; |
| 408 | 408 | echo"<div class=\"$class\"> <p>$message</p></div>"; |
| 409 | 409 | } |
| 410 | - unset( $_SESSION['save_post_customer_informations_errors'] ); |
|
| 410 | + unset($_SESSION['save_post_customer_informations_errors']); |
|
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | |
@@ -418,16 +418,16 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * @return array The new header to display |
| 420 | 420 | */ |
| 421 | - function list_table_header( $current_header ) {
|
|
| 422 | - unset( $current_header['title'] ); |
|
| 423 | - unset( $current_header['date'] ); |
|
| 421 | + function list_table_header($current_header) {
|
|
| 422 | + unset($current_header['title']); |
|
| 423 | + unset($current_header['date']); |
|
| 424 | 424 | |
| 425 | - $current_header['customer_identifier'] = __( 'Customer ID', 'wpshop' ); |
|
| 426 | - $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __( 'Last-name', 'wpshop' ) . '</span><span class="wps-customer-first_name" >' . __( 'First-name', 'wpshop' ) . '</span>'; |
|
| 427 | - $current_header['customer_email'] = __( 'E-mail', 'wpshop' ); |
|
| 428 | - $current_header['customer_orders'] = __( 'Customer\'s orders', 'wpshop' ); |
|
| 429 | - $current_header['customer_date_subscription'] = __( 'Subscription', 'wpshop' ); |
|
| 430 | - $current_header['customer_date_lastlogin'] = __( 'Last login date', 'wpshop' ); |
|
| 425 | + $current_header['customer_identifier'] = __('Customer ID', 'wpshop');
|
|
| 426 | + $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>';
|
|
| 427 | + $current_header['customer_email'] = __('E-mail', 'wpshop');
|
|
| 428 | + $current_header['customer_orders'] = __('Customer\'s orders', 'wpshop');
|
|
| 429 | + $current_header['customer_date_subscription'] = __('Subscription', 'wpshop');
|
|
| 430 | + $current_header['customer_date_lastlogin'] = __('Last login date', 'wpshop');
|
|
| 431 | 431 | |
| 432 | 432 | return $current_header; |
| 433 | 433 | } |
@@ -438,44 +438,44 @@ discard block |
||
| 438 | 438 | * @param string $column THe column identifier to modify output for |
| 439 | 439 | * @param integer $post_id The current post identifier |
| 440 | 440 | */ |
| 441 | - function list_table_column_content( $column, $post_id ) {
|
|
| 441 | + function list_table_column_content($column, $post_id) {
|
|
| 442 | 442 | global $wpdb; |
| 443 | 443 | /** Get wp_users idenfifier from customer id */ |
| 444 | - $current_user_id_in_list = self::get_author_id_by_customer_id( $post_id ); |
|
| 444 | + $current_user_id_in_list = self::get_author_id_by_customer_id($post_id); |
|
| 445 | 445 | |
| 446 | 446 | /** Get current post informations */ |
| 447 | - $customer_post = get_post( $post_id ); |
|
| 447 | + $customer_post = get_post($post_id); |
|
| 448 | 448 | |
| 449 | 449 | /** Get user data */ |
| 450 | - $current_user_datas = get_userdata( $current_user_id_in_list ); |
|
| 450 | + $current_user_datas = get_userdata($current_user_id_in_list); |
|
| 451 | 451 | |
| 452 | 452 | /** Switch current column for custom case */ |
| 453 | 453 | $use_template = true; |
| 454 | - switch ( $column ) {
|
|
| 454 | + switch ($column) {
|
|
| 455 | 455 | case 'customer_identifier': |
| 456 | 456 | echo $post_id; |
| 457 | 457 | $use_template = false; |
| 458 | 458 | break; |
| 459 | 459 | case 'customer_date_subscription': |
| 460 | - echo mysql2date( get_option( 'date_format' ), $current_user_datas->user_registered, true ); |
|
| 460 | + echo mysql2date(get_option('date_format'), $current_user_datas->user_registered, true);
|
|
| 461 | 461 | $use_template = false; |
| 462 | 462 | break; |
| 463 | 463 | case 'customer_date_lastlogin': |
| 464 | - $last_login = get_user_meta( $current_user_id_in_list, 'last_login_time', true ); |
|
| 465 | - if ( !empty( $last_login ) ) : |
|
| 466 | - echo mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) , $last_login, true ); |
|
| 464 | + $last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true); |
|
| 465 | + if (!empty($last_login)) : |
|
| 466 | + echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
|
|
| 467 | 467 | else: |
| 468 | - _e( 'Never logged in', 'wpshop' ); |
|
| 468 | + _e('Never logged in', 'wpshop');
|
|
| 469 | 469 | endif; |
| 470 | 470 | $use_template = false; |
| 471 | 471 | break; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** Require the template for displaying the current column */ |
| 475 | - if ( $use_template ) {
|
|
| 476 | - $template = wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column ); |
|
| 477 | - if ( is_file( $template ) ) {
|
|
| 478 | - require( $template ); |
|
| 475 | + if ($use_template) {
|
|
| 476 | + $template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column); |
|
| 477 | + if (is_file($template)) {
|
|
| 478 | + require($template); |
|
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | 481 | } |
@@ -487,33 +487,33 @@ discard block |
||
| 487 | 487 | * |
| 488 | 488 | * @return array The new action list to use into customer list table |
| 489 | 489 | */ |
| 490 | - function customer_list_table_bulk_actions( $actions ){
|
|
| 491 | - unset( $actions[ 'edit' ] ); |
|
| 492 | - unset( $actions[ 'trash' ] ); |
|
| 490 | + function customer_list_table_bulk_actions($actions) {
|
|
| 491 | + unset($actions['edit']); |
|
| 492 | + unset($actions['trash']); |
|
| 493 | 493 | |
| 494 | 494 | return $actions; |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | function list_table_filters() {
|
| 498 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 498 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 499 | 499 | if (isset($post_type)) {
|
| 500 | 500 | if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) {
|
| 501 | 501 | $filter_possibilities = array(); |
| 502 | 502 | $filter_possibilities[''] = __('-- Select Filter --', 'wpshop');
|
| 503 | 503 | $filter_possibilities['orders'] = __('List customers with orders', 'wpshop');
|
| 504 | 504 | $filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop');
|
| 505 | - echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field( $_GET['entity_filter'] ) : ''), '', 'index');
|
|
| 505 | + echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
|
|
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | function list_table_filter_parse_query($query) {
|
| 511 | 511 | global $pagenow, $wpdb; |
| 512 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 513 | - $entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
| 514 | - if ( is_admin() && ($pagenow == 'edit.php') && !empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) && !empty( $entity_filter ) ) {
|
|
| 512 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 513 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
| 514 | + if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) {
|
|
| 515 | 515 | $check = null; |
| 516 | - switch ( $entity_filter ) {
|
|
| 516 | + switch ($entity_filter) {
|
|
| 517 | 517 | case 'orders': |
| 518 | 518 | $sql_query = $wpdb->prepare( |
| 519 | 519 | "SELECT ID |
@@ -550,13 +550,13 @@ discard block |
||
| 550 | 550 | break; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - if ( !empty( $check ) ) {
|
|
| 553 | + if (!empty($check)) {
|
|
| 554 | 554 | $results = $wpdb->get_results($sql_query); |
| 555 | 555 | $user_id_list = array(); |
| 556 | - foreach($results as $item){
|
|
| 556 | + foreach ($results as $item) {
|
|
| 557 | 557 | $user_id_list[] = $item->ID; |
| 558 | 558 | } |
| 559 | - if( empty($post_id_list) ) {
|
|
| 559 | + if (empty($post_id_list)) {
|
|
| 560 | 560 | $post_id_list[] = 'no_result'; |
| 561 | 561 | } |
| 562 | 562 | $query->query_vars[$check] = $user_id_list; |
@@ -571,11 +571,11 @@ discard block |
||
| 571 | 571 | * |
| 572 | 572 | * @return array |
| 573 | 573 | */ |
| 574 | - public static function get_all_customer( $post_status = 'publish' ) {
|
|
| 574 | + public static function get_all_customer($post_status = 'publish') {
|
|
| 575 | 575 | global $wpdb; |
| 576 | 576 | |
| 577 | - $query = $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status );
|
|
| 578 | - $list_customer = $wpdb->get_results( $query ); |
|
| 577 | + $query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status);
|
|
| 578 | + $list_customer = $wpdb->get_results($query); |
|
| 579 | 579 | |
| 580 | 580 | return $list_customer; |
| 581 | 581 | } |
@@ -586,11 +586,11 @@ discard block |
||
| 586 | 586 | * @param int $author_id |
| 587 | 587 | * @return int $customer_id |
| 588 | 588 | */ |
| 589 | - public static function get_customer_id_by_author_id( $author_id ) {
|
|
| 589 | + public static function get_customer_id_by_author_id($author_id) {
|
|
| 590 | 590 | global $wpdb; |
| 591 | 591 | |
| 592 | - $query = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
|
|
| 593 | - $customer_id = $wpdb->get_var( $query ); |
|
| 592 | + $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
|
|
| 593 | + $customer_id = $wpdb->get_var($query); |
|
| 594 | 594 | |
| 595 | 595 | return $customer_id; |
| 596 | 596 | } |
@@ -602,10 +602,10 @@ discard block |
||
| 602 | 602 | * @param int $customer_id ID in wpshop_customers type. |
| 603 | 603 | * @return int |
| 604 | 604 | */ |
| 605 | - public static function get_author_id_by_customer_id( $customer_id ) {
|
|
| 605 | + public static function get_author_id_by_customer_id($customer_id) {
|
|
| 606 | 606 | global $wpdb; |
| 607 | 607 | |
| 608 | - $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $customer_id ) );
|
|
| 608 | + $author_id = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $customer_id));
|
|
| 609 | 609 | |
| 610 | 610 | return $author_id; |
| 611 | 611 | } |
@@ -616,30 +616,30 @@ discard block |
||
| 616 | 616 | * @param array $form Passer directement le $_POST pour créer un client. |
| 617 | 617 | * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà |
| 618 | 618 | */ |
| 619 | - public static function quick_add_customer( $form ) {
|
|
| 619 | + public static function quick_add_customer($form) {
|
|
| 620 | 620 | $return = 1; |
| 621 | - if ( !empty( $form ) ) {
|
|
| 621 | + if (!empty($form)) {
|
|
| 622 | 622 | global $wpdb; |
| 623 | - $customer_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 624 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $customer_type_id);
|
|
| 625 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 623 | + $customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 624 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id);
|
|
| 625 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 626 | 626 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 627 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 627 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 628 | 628 | |
| 629 | 629 | $customer_attributes_to_save = $customer_attributes_to_save_temp = array(); |
| 630 | 630 | |
| 631 | - foreach ( $form[ 'attribute' ] as $attribute_type => $attributes ) {
|
|
| 632 | - foreach ( $attributes as $attribute_code => $attribute_value ) {
|
|
| 631 | + foreach ($form['attribute'] as $attribute_type => $attributes) {
|
|
| 632 | + foreach ($attributes as $attribute_code => $attribute_value) {
|
|
| 633 | 633 | $customer_attributes_compare[$attribute_code] = $attribute_type; |
| 634 | 634 | } |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - foreach( $account_attributes as $account_attribute_group ) {
|
|
| 638 | - foreach ( $account_attribute_group[ 'attribut' ] as $attribute ) {
|
|
| 639 | - foreach( preg_grep ( '/' . $attribute->code . '/' , array_keys( $customer_attributes_compare ) ) as $codeForm ) {
|
|
| 640 | - if( $customer_attributes_compare[$codeForm] == $attribute->data_type ) {
|
|
| 641 | - $user[ $attribute->code ] = array( 'attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field( $_POST[ 'attribute' ][ $attribute->data_type ][ $codeForm ] ) ); |
|
| 642 | - if( $attribute->code == 'user_email' ) {
|
|
| 637 | + foreach ($account_attributes as $account_attribute_group) {
|
|
| 638 | + foreach ($account_attribute_group['attribut'] as $attribute) {
|
|
| 639 | + foreach (preg_grep('/' . $attribute->code . '/', array_keys($customer_attributes_compare)) as $codeForm) {
|
|
| 640 | + if ($customer_attributes_compare[$codeForm] == $attribute->data_type) {
|
|
| 641 | + $user[$attribute->code] = array('attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field($_POST['attribute'][$attribute->data_type][$codeForm]));
|
|
| 642 | + if ($attribute->code == 'user_email') {
|
|
| 643 | 643 | $email_founded = true; |
| 644 | 644 | } |
| 645 | 645 | } |
@@ -647,22 +647,22 @@ discard block |
||
| 647 | 647 | } |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - if ( $email_founded && is_email( $user['user_email']['value'] ) ) {
|
|
| 651 | - $user_id = username_exists( $user['user_email']['value'] ); |
|
| 652 | - if ( empty( $user_id ) ) {
|
|
| 653 | - $user_name = isset( $user['user_login']['value'] ) ? $user['user_login']['value'] : $user['user_email']['value']; |
|
| 654 | - $user_pass = isset( $user['user_pass']['value'] ) ? $user['user_pass']['value'] : wp_generate_password( 12, false ); |
|
| 655 | - $user_id = wp_create_user( $user_name, $user_pass, $user['user_email']['value'] ); |
|
| 650 | + if ($email_founded && is_email($user['user_email']['value'])) {
|
|
| 651 | + $user_id = username_exists($user['user_email']['value']); |
|
| 652 | + if (empty($user_id)) {
|
|
| 653 | + $user_name = isset($user['user_login']['value']) ? $user['user_login']['value'] : $user['user_email']['value']; |
|
| 654 | + $user_pass = isset($user['user_pass']['value']) ? $user['user_pass']['value'] : wp_generate_password(12, false); |
|
| 655 | + $user_id = wp_create_user($user_name, $user_pass, $user['user_email']['value']); |
|
| 656 | 656 | |
| 657 | - if ( !is_wp_error( $user_id ) ) {
|
|
| 658 | - $customer_entity_request = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 659 | - $customer_entity_id = $wpdb->get_var( $customer_entity_request ); |
|
| 657 | + if (!is_wp_error($user_id)) {
|
|
| 658 | + $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
|
|
| 659 | + $customer_entity_id = $wpdb->get_var($customer_entity_request); |
|
| 660 | 660 | $return = array(); |
| 661 | 661 | $return['integer']['ID'] = $user_id; |
| 662 | 662 | |
| 663 | - foreach( $user as $meta_key => $meta_values ) {
|
|
| 664 | - update_user_meta( $user_id, $meta_key, $meta_values['value'] ); |
|
| 665 | - $wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.strtolower( $meta_values['data_type'] ), array( 'entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time( 'mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value'] ) ); |
|
| 663 | + foreach ($user as $meta_key => $meta_values) {
|
|
| 664 | + update_user_meta($user_id, $meta_key, $meta_values['value']); |
|
| 665 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($meta_values['data_type']), array('entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value']));
|
|
| 666 | 666 | $return[$meta_values['data_type']][$meta_key] = $meta_values['value']; |
| 667 | 667 | } |
| 668 | 668 | } |
@@ -680,13 +680,13 @@ discard block |
||
| 680 | 680 | * |
| 681 | 681 | * @param string $term The term we have to search into database for getting existing users / Le terme qu'il faut rechercher pour retrouver les utilisateurs dans la base de données |
| 682 | 682 | */ |
| 683 | - public function search_customer( $term ) {
|
|
| 683 | + public function search_customer($term) {
|
|
| 684 | 684 | global $wpdb; |
| 685 | 685 | |
| 686 | 686 | /** Build the customer search */ |
| 687 | 687 | $args = array( |
| 688 | 688 | 'search' => "*" . $term . "*", |
| 689 | - 'search_columns' => array( 'user_login', 'user_email', 'user_nicename', ), |
|
| 689 | + 'search_columns' => array('user_login', 'user_email', 'user_nicename',),
|
|
| 690 | 690 | 'meta_query' => array( |
| 691 | 691 | 'relation' => 'OR', |
| 692 | 692 | array( |
@@ -701,21 +701,21 @@ discard block |
||
| 701 | 701 | ), |
| 702 | 702 | ), |
| 703 | 703 | ); |
| 704 | - $customer_search = new WP_User_Query( $args ); |
|
| 704 | + $customer_search = new WP_User_Query($args); |
|
| 705 | 705 | |
| 706 | 706 | $customer_list = array(); |
| 707 | - if ( !empty($customer_search->results) ) {
|
|
| 708 | - foreach ( $customer_search->results as $customer ) {
|
|
| 707 | + if (!empty($customer_search->results)) {
|
|
| 708 | + foreach ($customer_search->results as $customer) {
|
|
| 709 | 709 | /** Check the username, if last name and first name are empty we select email **/ |
| 710 | - $last_name_meta = get_user_meta( $customer->ID, 'last_name', true); |
|
| 711 | - $first_name_meta = get_user_meta( $customer->ID, 'first_name', true); |
|
| 710 | + $last_name_meta = get_user_meta($customer->ID, 'last_name', true); |
|
| 711 | + $first_name_meta = get_user_meta($customer->ID, 'first_name', true); |
|
| 712 | 712 | $user_data = $customer->data; |
| 713 | 713 | $email_data = $user_data->user_email; |
| 714 | 714 | |
| 715 | - if ( !empty($last_name_meta) ) {
|
|
| 715 | + if (!empty($last_name_meta)) {
|
|
| 716 | 716 | $user_name = $last_name_meta; |
| 717 | 717 | } |
| 718 | - elseif( !empty( $first_name_meta)) {
|
|
| 718 | + elseif (!empty($first_name_meta)) {
|
|
| 719 | 719 | $user_name = $first_name_meta; |
| 720 | 720 | } |
| 721 | 721 | else {
|
@@ -1,62 +1,62 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_shipping_mode_ajax_actions { |
| 3 | 3 | |
| 4 | 4 | function __construct() { |
| 5 | 5 | /** Ajax Actions **/ |
| 6 | - add_action('wp_ajax_save_shipping_rule',array( $this, 'wpshop_ajax_save_shipping_rule')); |
|
| 7 | - add_action('wp_ajax_display_shipping_rules',array( $this, 'wpshop_ajax_display_shipping_rules')); |
|
| 8 | - add_action('wp_ajax_delete_shipping_rule',array( $this, 'wpshop_ajax_delete_shipping_rule')); |
|
| 9 | - add_action('wp_ajax_wps_add_new_shipping_mode',array( $this, 'wps_add_new_shipping_mode')); |
|
| 10 | - add_action('wp_ajax_wps_delete_shipping_mode',array( $this, 'wps_delete_shipping_mode')); |
|
| 11 | - add_action('wp_ajax_wps_reload_shipping_mode',array( $this, 'wps_reload_shipping_mode')); |
|
| 12 | - add_action('wp_ajax_wps_calculate_shipping_cost',array( $this, 'wps_calculate_shipping_cost')); |
|
| 13 | - add_action( 'wp_ajax_wps_load_shipping_methods', array(&$this, 'wps_load_shipping_methods') ); |
|
| 6 | + add_action('wp_ajax_save_shipping_rule', array($this, 'wpshop_ajax_save_shipping_rule')); |
|
| 7 | + add_action('wp_ajax_display_shipping_rules', array($this, 'wpshop_ajax_display_shipping_rules')); |
|
| 8 | + add_action('wp_ajax_delete_shipping_rule', array($this, 'wpshop_ajax_delete_shipping_rule')); |
|
| 9 | + add_action('wp_ajax_wps_add_new_shipping_mode', array($this, 'wps_add_new_shipping_mode')); |
|
| 10 | + add_action('wp_ajax_wps_delete_shipping_mode', array($this, 'wps_delete_shipping_mode')); |
|
| 11 | + add_action('wp_ajax_wps_reload_shipping_mode', array($this, 'wps_reload_shipping_mode')); |
|
| 12 | + add_action('wp_ajax_wps_calculate_shipping_cost', array($this, 'wps_calculate_shipping_cost')); |
|
| 13 | + add_action('wp_ajax_wps_load_shipping_methods', array(&$this, 'wps_load_shipping_methods')); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * AJAX - Save custom Rules |
| 18 | 18 | **/ |
| 19 | - function wpshop_ajax_save_shipping_rule(){ |
|
| 20 | - check_ajax_referer( 'wpshop_ajax_save_shipping_rule' ); |
|
| 19 | + function wpshop_ajax_save_shipping_rule() { |
|
| 20 | + check_ajax_referer('wpshop_ajax_save_shipping_rule'); |
|
| 21 | 21 | |
| 22 | 22 | global $wpdb; |
| 23 | 23 | $wps_shipping = new wps_shipping(); |
| 24 | 24 | $status = false; |
| 25 | 25 | $reponse = array(); |
| 26 | - $fees_data = ( !empty($_POST['fees_data']) ) ? ( $_POST['fees_data'] ) : null; |
|
| 27 | - $weight_rule = ( !empty($_POST['weight_rule']) ) ? wpshop_tools::varSanitizer( $_POST['weight_rule'] ) : null; |
|
| 28 | - $shipping_price = ( !empty($_POST['shipping_price']) ) ? wpshop_tools::varSanitizer( $_POST['shipping_price'] ) : 0; |
|
| 29 | - $selected_country = ( !empty($_POST['selected_country']) ) ? wpshop_tools::varSanitizer( $_POST['selected_country'] ) : null; |
|
| 30 | - $shipping_rules = $wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 26 | + $fees_data = (!empty($_POST['fees_data'])) ? ($_POST['fees_data']) : null; |
|
| 27 | + $weight_rule = (!empty($_POST['weight_rule'])) ? wpshop_tools::varSanitizer($_POST['weight_rule']) : null; |
|
| 28 | + $shipping_price = (!empty($_POST['shipping_price'])) ? wpshop_tools::varSanitizer($_POST['shipping_price']) : 0; |
|
| 29 | + $selected_country = (!empty($_POST['selected_country'])) ? wpshop_tools::varSanitizer($_POST['selected_country']) : null; |
|
| 30 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 31 | 31 | |
| 32 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 33 | - $query = $wpdb->prepare('SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 34 | - $unity = $wpdb->get_var( $query ); |
|
| 32 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 33 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 34 | + $unity = $wpdb->get_var($query); |
|
| 35 | 35 | |
| 36 | - $weight_rule = ( !empty($unity) && $unity == 'kg' ) ? $weight_rule * 1000 : $weight_rule; |
|
| 36 | + $weight_rule = (!empty($unity) && $unity == 'kg') ? $weight_rule * 1000 : $weight_rule; |
|
| 37 | 37 | //Check if this shipping rule (same country and same weight) already exist in the shipping rules definition |
| 38 | - if( !empty($shipping_rules) ) { |
|
| 38 | + if (!empty($shipping_rules)) { |
|
| 39 | 39 | $existing_country = false; |
| 40 | 40 | $tab_key = -1; |
| 41 | - foreach ( $shipping_rules as $key=>$shipping_rule) { |
|
| 42 | - if ( $shipping_rule['destination'] == $selected_country) { |
|
| 41 | + foreach ($shipping_rules as $key=>$shipping_rule) { |
|
| 42 | + if ($shipping_rule['destination'] == $selected_country) { |
|
| 43 | 43 | $existing_country = true; |
| 44 | 44 | $tab_key = $key; |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - if ( $existing_country && $tab_key > -1) { |
|
| 47 | + if ($existing_country && $tab_key > -1) { |
|
| 48 | 48 | $shipping_rules[$tab_key]['fees'][$weight_rule] = $shipping_price; |
| 49 | 49 | } |
| 50 | 50 | else { |
| 51 | - $shipping_rules[] = array( 'destination' => $selected_country, 'rule' => 'weight', 'fees' => array($weight_rule => $shipping_price) ); |
|
| 51 | + $shipping_rules[] = array('destination' => $selected_country, 'rule' => 'weight', 'fees' => array($weight_rule => $shipping_price)); |
|
| 52 | 52 | } |
| 53 | 53 | $status = true; |
| 54 | 54 | } |
| 55 | 55 | else { |
| 56 | - $shipping_rules = array( '0' => array('destination' => $selected_country, 'rule' => 'weight', 'fees' => array( $weight_rule => $shipping_price)) ); |
|
| 56 | + $shipping_rules = array('0' => array('destination' => $selected_country, 'rule' => 'weight', 'fees' => array($weight_rule => $shipping_price))); |
|
| 57 | 57 | $status = true; |
| 58 | 58 | } |
| 59 | - $reponse = array('status' => $status, 'reponse' => $wps_shipping->shipping_fees_array_2_string( $shipping_rules ) ); |
|
| 59 | + $reponse = array('status' => $status, 'reponse' => $wps_shipping->shipping_fees_array_2_string($shipping_rules)); |
|
| 60 | 60 | echo json_encode($reponse); |
| 61 | 61 | die(); |
| 62 | 62 | } |
@@ -65,18 +65,18 @@ discard block |
||
| 65 | 65 | * AJAX - Delete Custom shipping Rule |
| 66 | 66 | */ |
| 67 | 67 | function wpshop_ajax_delete_shipping_rule() { |
| 68 | - check_ajax_referer( 'wpshop_ajax_delete_shipping_rule' ); |
|
| 68 | + check_ajax_referer('wpshop_ajax_delete_shipping_rule'); |
|
| 69 | 69 | |
| 70 | 70 | global $wpdb; |
| 71 | 71 | $wps_shipping = new wps_shipping(); |
| 72 | - $fees_data = ( !empty($_POST['fees_data']) ) ? ( $_POST['fees_data'] ) : null; |
|
| 73 | - $country_and_weight = ( !empty($_POST['country_and_weight']) ) ? sanitize_text_field( $_POST['country_and_weight'] ) : null; |
|
| 72 | + $fees_data = (!empty($_POST['fees_data'])) ? ($_POST['fees_data']) : null; |
|
| 73 | + $country_and_weight = (!empty($_POST['country_and_weight'])) ? sanitize_text_field($_POST['country_and_weight']) : null; |
|
| 74 | 74 | $datas = explode("|", $country_and_weight); |
| 75 | 75 | $country = $datas[0]; |
| 76 | 76 | $weight = $datas[1]; |
| 77 | 77 | $shipping_mode_id = $datas[2]; |
| 78 | 78 | |
| 79 | - $shipping_rules = $wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 79 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 80 | 80 | |
| 81 | 81 | /** Check the default weight unity **/ |
| 82 | 82 | // $weight_unity_id = get_option('wpshop_shop_default_weight_unity'); |
@@ -89,46 +89,46 @@ discard block |
||
| 89 | 89 | // } |
| 90 | 90 | // } |
| 91 | 91 | |
| 92 | - if ( array_key_exists($country, $shipping_rules) ) { |
|
| 93 | - if ( array_key_exists((string)$weight, $shipping_rules[$country]['fees']) ) { |
|
| 92 | + if (array_key_exists($country, $shipping_rules)) { |
|
| 93 | + if (array_key_exists((string)$weight, $shipping_rules[$country]['fees'])) { |
|
| 94 | 94 | unset($shipping_rules[$country]['fees'][$weight]); |
| 95 | 95 | } |
| 96 | - if ( empty($shipping_rules[$country]['fees']) ) { |
|
| 96 | + if (empty($shipping_rules[$country]['fees'])) { |
|
| 97 | 97 | unset($shipping_rules[$country]); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | } |
| 101 | - foreach ( $shipping_rules as $k=>$shipping_rule ) { |
|
| 102 | - if ( !isset($shipping_rule['fees']) ) { |
|
| 101 | + foreach ($shipping_rules as $k=>$shipping_rule) { |
|
| 102 | + if (!isset($shipping_rule['fees'])) { |
|
| 103 | 103 | unset($shipping_rules[$k]); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $status = true; |
| 108 | 108 | |
| 109 | - if ( !empty( $shipping_rules ) ) { |
|
| 110 | - $rules = $wps_shipping->shipping_fees_array_2_string( $shipping_rules ); |
|
| 109 | + if (!empty($shipping_rules)) { |
|
| 110 | + $rules = $wps_shipping->shipping_fees_array_2_string($shipping_rules); |
|
| 111 | 111 | } |
| 112 | 112 | else { |
| 113 | 113 | $rules = ''; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - wp_die( json_encode( array( 'status' => $status, 'reponse' => $rules, ) ) ); |
|
| 116 | + wp_die(json_encode(array('status' => $status, 'reponse' => $rules,))); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * AJAX - Display Created custom shipping rules |
| 121 | 121 | */ |
| 122 | - function wpshop_ajax_display_shipping_rules () { |
|
| 123 | - check_ajax_referer( 'wpshop_ajax_display_shipping_rules' ); |
|
| 122 | + function wpshop_ajax_display_shipping_rules() { |
|
| 123 | + check_ajax_referer('wpshop_ajax_display_shipping_rules'); |
|
| 124 | 124 | |
| 125 | 125 | $status = false; |
| 126 | - $fees_data = ( !empty($_POST['fees_data']) ) ? ( $_POST['fees_data'] ) : null; |
|
| 127 | - $shipping_mode_id = ( !empty($_POST['shipping_mode_id']) ) ? (int) $_POST['shipping_mode_id'] : null; |
|
| 126 | + $fees_data = (!empty($_POST['fees_data'])) ? ($_POST['fees_data']) : null; |
|
| 127 | + $shipping_mode_id = (!empty($_POST['shipping_mode_id'])) ? (int)$_POST['shipping_mode_id'] : null; |
|
| 128 | 128 | $result = ''; |
| 129 | - if( !empty($fees_data) ) { |
|
| 129 | + if (!empty($fees_data)) { |
|
| 130 | 130 | $wps_shipping_mode_ctr = new wps_shipping_mode_ctr(); |
| 131 | - $result = $wps_shipping_mode_ctr->generate_shipping_rules_table( $fees_data, $shipping_mode_id ); |
|
| 131 | + $result = $wps_shipping_mode_ctr->generate_shipping_rules_table($fees_data, $shipping_mode_id); |
|
| 132 | 132 | $status = true; |
| 133 | 133 | } |
| 134 | 134 | else { |
@@ -146,38 +146,38 @@ discard block |
||
| 146 | 146 | * AJAX - Reload shippig mode interface |
| 147 | 147 | */ |
| 148 | 148 | function wps_reload_shipping_mode() { |
| 149 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 149 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 150 | 150 | |
| 151 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_shipping_mode' ) ) |
|
| 151 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_shipping_mode')) |
|
| 152 | 152 | wp_die(); |
| 153 | 153 | |
| 154 | 154 | $status = false; $allow_order = true; |
| 155 | 155 | $result = ''; |
| 156 | - $address_id = !empty( $_POST['address_id'] ) ? (int) $_POST['address_id'] : 0; |
|
| 157 | - if ( !empty($address_id) ) { |
|
| 156 | + $address_id = !empty($_POST['address_id']) ? (int)$_POST['address_id'] : 0; |
|
| 157 | + if (!empty($address_id)) { |
|
| 158 | 158 | $_SESSION['shipping_address'] = $address_id; |
| 159 | 159 | } |
| 160 | - $shipping_address_id = ( !empty($_SESSION['shipping_address']) ) ? $_SESSION['shipping_address'] : ''; |
|
| 161 | - if ( !empty($shipping_address_id) ) { |
|
| 160 | + $shipping_address_id = (!empty($_SESSION['shipping_address'])) ? $_SESSION['shipping_address'] : ''; |
|
| 161 | + if (!empty($shipping_address_id)) { |
|
| 162 | 162 | //$result = self::generate_shipping_mode_for_an_address(); |
| 163 | 163 | $wps_shipping_mode_ctr = new wps_shipping_mode_ctr(); |
| 164 | 164 | // $shipping_modes = $wps_shipping_mode_ctr->generate_shipping_mode_for_an_address( intval($_POST['address_id']) ); |
| 165 | 165 | |
| 166 | 166 | $status = $allow_order = $shipping_modes[0]; |
| 167 | - if( empty( $shipping_modes[0]) || $shipping_modes[0] == false ) { |
|
| 167 | + if (empty($shipping_modes[0]) || $shipping_modes[0] == false) { |
|
| 168 | 168 | $status = false; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $result = $shipping_modes[1]; |
| 172 | 172 | |
| 173 | - if ( $status == false ) { |
|
| 173 | + if ($status == false) { |
|
| 174 | 174 | $allow_order = false; |
| 175 | - $result = '<div class="error_bloc">' .__('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop' ). '</div>'; |
|
| 175 | + $result = '<div class="error_bloc">' . __('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop') . '</div>'; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | } |
| 179 | - $response = array('status' => $status, 'response' => $result, 'allow_order' => $allow_order ); |
|
| 180 | - echo json_encode( $response ); |
|
| 179 | + $response = array('status' => $status, 'response' => $result, 'allow_order' => $allow_order); |
|
| 180 | + echo json_encode($response); |
|
| 181 | 181 | die(); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -185,26 +185,26 @@ discard block |
||
| 185 | 185 | * AJAX - Calculate Shipping cost |
| 186 | 186 | */ |
| 187 | 187 | function wps_calculate_shipping_cost() { |
| 188 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 188 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 189 | 189 | |
| 190 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_calculate_shipping_cost' ) ) |
|
| 190 | + if (!wp_verify_nonce($_wpnonce, 'wps_calculate_shipping_cost')) |
|
| 191 | 191 | wp_die(); |
| 192 | 192 | |
| 193 | 193 | $status = false; |
| 194 | 194 | $result = ''; |
| 195 | 195 | $chosen_method = !empty($_POST['chosen_method']) ? wpshop_tools::varSanitizer($_POST['chosen_method']) : null; |
| 196 | 196 | |
| 197 | - if( !empty($chosen_method) ) { |
|
| 197 | + if (!empty($chosen_method)) { |
|
| 198 | 198 | $_SESSION['shipping_method'] = $chosen_method; |
| 199 | 199 | $wps_cart = new wps_cart(); |
| 200 | - $order = $wps_cart->calcul_cart_information( array() ); |
|
| 200 | + $order = $wps_cart->calcul_cart_information(array()); |
|
| 201 | 201 | $wps_cart->store_cart_in_session($order); |
| 202 | 202 | |
| 203 | 203 | $status = true; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $response = array('status' => $status ); |
|
| 207 | - echo json_encode( $response ); |
|
| 206 | + $response = array('status' => $status); |
|
| 207 | + echo json_encode($response); |
|
| 208 | 208 | die(); |
| 209 | 209 | } |
| 210 | 210 | |
@@ -212,68 +212,68 @@ discard block |
||
| 212 | 212 | * AJAX - (New checkout Tunnel ) Load available shipping modes |
| 213 | 213 | */ |
| 214 | 214 | function wps_load_shipping_methods() { |
| 215 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 215 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 216 | 216 | |
| 217 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_load_shipping_methods' ) ) |
|
| 217 | + if (!wp_verify_nonce($_wpnonce, 'wps_load_shipping_methods')) |
|
| 218 | 218 | wp_die(); |
| 219 | 219 | |
| 220 | 220 | $status = true; $response = ''; |
| 221 | - $shipping_address_id = ( !empty($_POST['shipping_address']) ) ? intval( $_POST['shipping_address'] ) : null; |
|
| 222 | - if ( !empty($shipping_address_id) ) { |
|
| 221 | + $shipping_address_id = (!empty($_POST['shipping_address'])) ? intval($_POST['shipping_address']) : null; |
|
| 222 | + if (!empty($shipping_address_id)) { |
|
| 223 | 223 | // Check if element is an address |
| 224 | 224 | $check_address_type = get_post($shipping_address_id); |
| 225 | - if ( !empty($check_address_type) && $check_address_type->post_author == get_current_user_id() && $check_address_type->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ) { |
|
| 225 | + if (!empty($check_address_type) && $check_address_type->post_author == get_current_user_id() && $check_address_type->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) { |
|
| 226 | 226 | // Get address metadatas |
| 227 | - $address_metadata = get_post_meta( $shipping_address_id, '_wpshop_address_metadata', true ); |
|
| 228 | - if( !empty($address_metadata) && !empty($address_metadata['country']) ) { |
|
| 227 | + $address_metadata = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true); |
|
| 228 | + if (!empty($address_metadata) && !empty($address_metadata['country'])) { |
|
| 229 | 229 | $country = $address_metadata['country']; |
| 230 | 230 | $postcode = $address_metadata['postcode']; |
| 231 | - $shipping_methods = get_option( 'wps_shipping_mode' ); |
|
| 231 | + $shipping_methods = get_option('wps_shipping_mode'); |
|
| 232 | 232 | $available_shipping_methods = array(); |
| 233 | - if( !empty($shipping_methods) && !empty($shipping_methods['modes']) ) { |
|
| 233 | + if (!empty($shipping_methods) && !empty($shipping_methods['modes'])) { |
|
| 234 | 234 | // Check all shipping methods |
| 235 | - foreach( $shipping_methods['modes'] as $shipping_method_id => $shipping_method ){ |
|
| 236 | - if ( empty($shipping_method['limit_destination']) || ( empty($shipping_method['limit_destination']['country']) || ( !empty($shipping_method['limit_destination']['country']) && in_array($country, $shipping_method['limit_destination']['country']) ) ) ) { |
|
| 237 | - $available_shipping_methods[ $shipping_method_id ] = $shipping_method; |
|
| 235 | + foreach ($shipping_methods['modes'] as $shipping_method_id => $shipping_method) { |
|
| 236 | + if (empty($shipping_method['limit_destination']) || (empty($shipping_method['limit_destination']['country']) || (!empty($shipping_method['limit_destination']['country']) && in_array($country, $shipping_method['limit_destination']['country'])))) { |
|
| 237 | + $available_shipping_methods[$shipping_method_id] = $shipping_method; |
|
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | - if( !empty($available_shipping_methods) ) { |
|
| 241 | - foreach( $available_shipping_methods as $shipping_mode_id => $shipping_mode ) { |
|
| 240 | + if (!empty($available_shipping_methods)) { |
|
| 241 | + foreach ($available_shipping_methods as $shipping_mode_id => $shipping_mode) { |
|
| 242 | 242 | ob_start(); |
| 243 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/","frontend", "shipping-mode", "element") ); |
|
| 243 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/", "frontend", "shipping-mode", "element")); |
|
| 244 | 244 | $response .= ob_get_contents(); |
| 245 | 245 | ob_end_clean(); |
| 246 | 246 | |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | else { |
| 250 | - $response = '<div class="wps-alert-error">' .__( 'No shipping method available for your shipping address', 'wpshop' ). '</div>'; |
|
| 250 | + $response = '<div class="wps-alert-error">' . __('No shipping method available for your shipping address', 'wpshop') . '</div>'; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | } |
| 254 | 254 | else { |
| 255 | - $response = '<div class="wps-alert-info">' .__( 'No shipping method available', 'wpshop' ). '</div>'; |
|
| 255 | + $response = '<div class="wps-alert-info">' . __('No shipping method available', 'wpshop') . '</div>'; |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | else { |
| 261 | - $response = '<div class="wps-alert-info">' .__( 'Please select a shipping address to choose a shipping method', 'wpshop' ). '</div>'; |
|
| 261 | + $response = '<div class="wps-alert-info">' . __('Please select a shipping address to choose a shipping method', 'wpshop') . '</div>'; |
|
| 262 | 262 | } |
| 263 | - echo json_encode( array( 'status' => $status, 'response' => $response) ); |
|
| 263 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 264 | 264 | die(); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | function wps_add_new_shipping_mode() { |
| 269 | - check_ajax_referer( 'wps_add_new_shipping_mode' ); |
|
| 269 | + check_ajax_referer('wps_add_new_shipping_mode'); |
|
| 270 | 270 | |
| 271 | 271 | $status = false; $reponse = ''; |
| 272 | 272 | |
| 273 | - $k = 'wps_custom_shipping_mode_'.time(); |
|
| 273 | + $k = 'wps_custom_shipping_mode_' . time(); |
|
| 274 | 274 | $shipping_mode = array(); |
| 275 | 275 | ob_start(); |
| 276 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/", "backend", "shipping-mode") ); |
|
| 276 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/", "backend", "shipping-mode")); |
|
| 277 | 277 | $response .= ob_get_contents(); |
| 278 | 278 | ob_end_clean(); |
| 279 | 279 | |
@@ -281,23 +281,23 @@ discard block |
||
| 281 | 281 | jQuery("select.chosen_select").chosen( WPSHOP_CHOSEN_ATTRS ); |
| 282 | 282 | } );</script>'; |
| 283 | 283 | |
| 284 | - $status = ( !empty($response) ) ? true : false; |
|
| 284 | + $status = (!empty($response)) ? true : false; |
|
| 285 | 285 | |
| 286 | - echo json_encode( array( 'status' => $status, 'response' => $response) ); |
|
| 286 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 287 | 287 | wp_die(); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | function wps_delete_shipping_mode() { |
| 291 | - check_ajax_referer( 'wps_delete_shipping_mode' ); |
|
| 292 | - $shipping_mode = ! empty( $_POST['shipping_mode'] ) ? sanitize_text_field( $_POST['shipping_mode'] ) : null; |
|
| 293 | - $wps_shipping_mode = get_option( 'wps_shipping_mode' ); |
|
| 294 | - if ( ! empty( $wps_shipping_mode['modes'] ) && array_key_exists( $shipping_mode, $wps_shipping_mode['modes'] ) ) { |
|
| 295 | - unset( $wps_shipping_mode['modes'][ $shipping_mode ] ); |
|
| 296 | - if ( ! empty( $wps_shipping_mode['default_choice'] ) && $wps_shipping_mode['default_choice'] === $shipping_mode ) { |
|
| 291 | + check_ajax_referer('wps_delete_shipping_mode'); |
|
| 292 | + $shipping_mode = !empty($_POST['shipping_mode']) ? sanitize_text_field($_POST['shipping_mode']) : null; |
|
| 293 | + $wps_shipping_mode = get_option('wps_shipping_mode'); |
|
| 294 | + if (!empty($wps_shipping_mode['modes']) && array_key_exists($shipping_mode, $wps_shipping_mode['modes'])) { |
|
| 295 | + unset($wps_shipping_mode['modes'][$shipping_mode]); |
|
| 296 | + if (!empty($wps_shipping_mode['default_choice']) && $wps_shipping_mode['default_choice'] === $shipping_mode) { |
|
| 297 | 297 | $wps_shipping_mode['default_choice'] = 'default_shipping_mode'; |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | - update_option( 'wps_shipping_mode', $wps_shipping_mode ); |
|
| 300 | + update_option('wps_shipping_mode', $wps_shipping_mode); |
|
| 301 | 301 | wp_send_json_success(); |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_shipping_mode_ctr { |
| 3 | 3 | |
| 4 | 4 | /** |
@@ -18,34 +18,34 @@ discard block |
||
| 18 | 18 | /** Template Load **/ |
| 19 | 19 | // add_filter( 'wpshop_custom_template', array( $this, 'custom_template_load' ) ); |
| 20 | 20 | |
| 21 | - add_action( 'admin_init', array( $this, 'migrate_default_shipping_mode' ) ); |
|
| 21 | + add_action('admin_init', array($this, 'migrate_default_shipping_mode')); |
|
| 22 | 22 | |
| 23 | 23 | /** Add module option to wpshop general options */ |
| 24 | - add_filter('wpshop_options', array( $this, 'add_options'), 9); |
|
| 25 | - add_action('wsphop_options', array( $this, 'create_options'), 8); |
|
| 24 | + add_filter('wpshop_options', array($this, 'add_options'), 9); |
|
| 25 | + add_action('wsphop_options', array($this, 'create_options'), 8); |
|
| 26 | 26 | |
| 27 | 27 | // Add files in back-office |
| 28 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_in_admin' ) ); |
|
| 28 | + add_action('admin_enqueue_scripts', array($this, 'add_scripts_in_admin')); |
|
| 29 | 29 | // Add files in front-office |
| 30 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
| 30 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 31 | 31 | |
| 32 | 32 | // Available Shortcodes |
| 33 | - add_shortcode( 'wps_shipping_mode', array( &$this, 'display_shipping_mode') ); |
|
| 34 | - add_shortcode( 'wps_shipping_method', array( &$this, 'display_shipping_methods') ); |
|
| 35 | - add_shortcode( 'wps_shipping_summary', array( &$this, 'display_shipping_summary') ); |
|
| 33 | + add_shortcode('wps_shipping_mode', array(&$this, 'display_shipping_mode')); |
|
| 34 | + add_shortcode('wps_shipping_method', array(&$this, 'display_shipping_methods')); |
|
| 35 | + add_shortcode('wps_shipping_summary', array(&$this, 'display_shipping_summary')); |
|
| 36 | 36 | |
| 37 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box') ); |
|
| 37 | + add_action('add_meta_boxes', array($this, 'add_meta_box')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | function add_meta_box() { |
| 41 | 41 | global $post; |
| 42 | 42 | /** Box for shipping information */ |
| 43 | 43 | $shipping_option = get_option('wpshop_shipping_address_choice'); |
| 44 | - $order_meta = get_post_meta( $post->ID, '_order_postmeta', true ); |
|
| 45 | - if (!in_array( $post->post_status, array( 'auto-draft' ) ) && ( !empty($shipping_option['activate']) && $shipping_option['activate'] && empty($order_meta['order_payment']['shipping_method'] ) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos' )) { |
|
| 44 | + $order_meta = get_post_meta($post->ID, '_order_postmeta', true); |
|
| 45 | + if (!in_array($post->post_status, array('auto-draft')) && (!empty($shipping_option['activate']) && $shipping_option['activate'] && empty($order_meta['order_payment']['shipping_method']) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos')) { |
|
| 46 | 46 | add_meta_box( |
| 47 | 47 | 'wpshop_order_shipping', |
| 48 | - '<span class="dashicons dashicons-palmtree"></span> '.__('Shipping', 'wpshop'), |
|
| 48 | + '<span class="dashicons dashicons-palmtree"></span> ' . __('Shipping', 'wpshop'), |
|
| 49 | 49 | array($this, 'order_shipping_box'), |
| 50 | 50 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low' |
| 51 | 51 | ); |
@@ -58,29 +58,29 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | function add_scripts() { |
| 60 | 60 | //CSS files |
| 61 | - wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/css/wps_shipping_mode.css', false ); |
|
| 62 | - wp_enqueue_style( 'wps_shipping_mode_css' ); |
|
| 61 | + wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/css/wps_shipping_mode.css', false); |
|
| 62 | + wp_enqueue_style('wps_shipping_mode_css'); |
|
| 63 | 63 | // Javascript Files |
| 64 | - wp_enqueue_script( 'jquery' ); |
|
| 65 | - wp_enqueue_script( 'wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/js/shipping_method.js', false ); |
|
| 64 | + wp_enqueue_script('jquery'); |
|
| 65 | + wp_enqueue_script('wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/js/shipping_method.js', false); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Add JS and CSS files in back-office |
| 70 | 70 | */ |
| 71 | - function add_scripts_in_admin( $hook ) { |
|
| 71 | + function add_scripts_in_admin($hook) { |
|
| 72 | 72 | global $current_screen; |
| 73 | - if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) && $hook !== 'settings_page_wpshop_option' ) |
|
| 73 | + if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER), true) && $hook !== 'settings_page_wpshop_option') |
|
| 74 | 74 | return; |
| 75 | 75 | |
| 76 | 76 | add_thickbox(); |
| 77 | 77 | wp_enqueue_script('jquery'); |
| 78 | 78 | wp_enqueue_script('jquery-ui-sortable'); |
| 79 | 79 | // Javascript files |
| 80 | - wp_enqueue_script( 'wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/js/wps_shipping_mode.js', false ); |
|
| 80 | + wp_enqueue_script('wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/js/wps_shipping_mode.js', false); |
|
| 81 | 81 | //CSS files |
| 82 | - wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/css/wps_shipping_mode.css', false ); |
|
| 83 | - wp_enqueue_style( 'wps_shipping_mode_css' ); |
|
| 82 | + wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/css/wps_shipping_mode.css', false); |
|
| 83 | + wp_enqueue_style('wps_shipping_mode_css'); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * Declare option groups for the module |
| 104 | 104 | */ |
| 105 | - function add_options( $option_group ) { |
|
| 105 | + function add_options($option_group) { |
|
| 106 | 106 | $option_group['wpshop_shipping_option']['subgroups']['wps_shipping_mode']['class'] = ' wpshop_admin_box_options_shipping_mode'; |
| 107 | 107 | return $option_group; |
| 108 | 108 | } |
@@ -111,38 +111,38 @@ discard block |
||
| 111 | 111 | * Create Options |
| 112 | 112 | **/ |
| 113 | 113 | function create_options() { |
| 114 | - add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>'.__('Shipping method', 'wpshop'), '', 'wps_shipping_mode'); |
|
| 115 | - register_setting('wpshop_options', 'wps_shipping_mode', array( $this, 'wpshop_options_validate_wps_shipping_mode')); |
|
| 116 | - add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array( $this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode'); |
|
| 114 | + add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>' . __('Shipping method', 'wpshop'), '', 'wps_shipping_mode'); |
|
| 115 | + register_setting('wpshop_options', 'wps_shipping_mode', array($this, 'wpshop_options_validate_wps_shipping_mode')); |
|
| 116 | + add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array($this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode'); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * WPS Shipping mode Option Validator |
| 121 | 121 | **/ |
| 122 | - function wpshop_options_validate_wps_shipping_mode( $input ) { |
|
| 122 | + function wpshop_options_validate_wps_shipping_mode($input) { |
|
| 123 | 123 | $wps_shipping = new wps_shipping(); |
| 124 | - if ( !empty($input['modes']) ) { |
|
| 125 | - foreach( $input['modes'] as $mode => $mode_det ) { |
|
| 124 | + if (!empty($input['modes'])) { |
|
| 125 | + foreach ($input['modes'] as $mode => $mode_det) { |
|
| 126 | 126 | /** Custom Shipping rules **/ |
| 127 | - $input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array( $input['modes'][$mode]['custom_shipping_rules']['fees'] ); |
|
| 127 | + $input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array($input['modes'][$mode]['custom_shipping_rules']['fees']); |
|
| 128 | 128 | |
| 129 | 129 | /** Shipping Modes Logo Treatment **/ |
| 130 | - if ( !empty($_FILES[$mode.'_logo']['name']) && empty($_FILES[$mode.'_logo']['error']) ) { |
|
| 131 | - $filename = $_FILES[$mode.'_logo']; |
|
| 132 | - $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 133 | - $wp_filetype = wp_check_filetype(basename($filename['name']), null ); |
|
| 130 | + if (!empty($_FILES[$mode . '_logo']['name']) && empty($_FILES[$mode . '_logo']['error'])) { |
|
| 131 | + $filename = $_FILES[$mode . '_logo']; |
|
| 132 | + $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 133 | + $wp_filetype = wp_check_filetype(basename($filename['name']), null); |
|
| 134 | 134 | $wp_upload_dir = wp_upload_dir(); |
| 135 | 135 | $attachment = array( |
| 136 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename['name'] ), |
|
| 136 | + 'guid' => $wp_upload_dir['url'] . '/' . basename($filename['name']), |
|
| 137 | 137 | 'post_mime_type' => $wp_filetype['type'], |
| 138 | 138 | 'post_title' => preg_replace(' /\.[^.]+$/', '', basename($filename['name'])), |
| 139 | 139 | 'post_content' => '', |
| 140 | 140 | 'post_status' => 'inherit' |
| 141 | 141 | ); |
| 142 | - $attach_id = wp_insert_attachment( $attachment, $upload['file']); |
|
| 142 | + $attach_id = wp_insert_attachment($attachment, $upload['file']); |
|
| 143 | 143 | require_once(ABSPATH . 'wp-admin/includes/image.php'); |
| 144 | - $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); |
|
| 145 | - wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 144 | + $attach_data = wp_generate_attachment_metadata($attach_id, $upload['file']); |
|
| 145 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 146 | 146 | |
| 147 | 147 | $input['modes'][$mode]['logo'] = $attach_id; |
| 148 | 148 | } |
@@ -156,38 +156,38 @@ discard block |
||
| 156 | 156 | **/ |
| 157 | 157 | function migrate_default_shipping_mode() { |
| 158 | 158 | $data = array(); |
| 159 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 160 | - if ( empty($shipping_mode_option) ) { |
|
| 159 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 160 | + if (empty($shipping_mode_option)) { |
|
| 161 | 161 | $data['modes']['default_shipping_mode']['active'] = 'on'; |
| 162 | 162 | $data['modes']['default_shipping_mode']['name'] = __('Home Delivery', 'wpshop'); |
| 163 | 163 | $data['modes']['default_shipping_mode']['explanation'] = __('Your purchase will be delivered directly to you at home', 'wpshop'); |
| 164 | 164 | /** Check CUstom Shipping **/ |
| 165 | - $custom_shipping_option = get_option( 'wpshop_custom_shipping' ); |
|
| 166 | - if ( !empty($custom_shipping_option) ) { |
|
| 165 | + $custom_shipping_option = get_option('wpshop_custom_shipping'); |
|
| 166 | + if (!empty($custom_shipping_option)) { |
|
| 167 | 167 | $data['modes']['default_shipping_mode']['custom_shipping_rules'] = $custom_shipping_option; |
| 168 | 168 | } |
| 169 | 169 | /** Check Country Limit **/ |
| 170 | - $limit_destination = get_option( 'wpshop_limit_shipping_destination' ); |
|
| 171 | - if ( !empty($custom_shipping_option) ) { |
|
| 170 | + $limit_destination = get_option('wpshop_limit_shipping_destination'); |
|
| 171 | + if (!empty($custom_shipping_option)) { |
|
| 172 | 172 | $data['modes']['default_shipping_mode']['limit_destination'] = $limit_destination; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** Check Others shipping configurations **/ |
| 176 | 176 | $wpshop_shipping_rules_option = get_option('wpshop_shipping_rules'); |
| 177 | - if ( !empty($wpshop_shipping_rules_option) ){ |
|
| 178 | - if ( !empty($wpshop_shipping_rules_option['min_max']) ) { |
|
| 177 | + if (!empty($wpshop_shipping_rules_option)) { |
|
| 178 | + if (!empty($wpshop_shipping_rules_option['min_max'])) { |
|
| 179 | 179 | $data['modes']['default_shipping_mode']['min_max'] = $wpshop_shipping_rules_option['min_max']; |
| 180 | 180 | } |
| 181 | - if ( !empty($wpshop_shipping_rules_option['free_from']) ) { |
|
| 181 | + if (!empty($wpshop_shipping_rules_option['free_from'])) { |
|
| 182 | 182 | $data['modes']['default_shipping_mode']['free_from'] = $wpshop_shipping_rules_option['free_from']; |
| 183 | 183 | } |
| 184 | - if ( !empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']) ) { |
|
| 184 | + if (!empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping'])) { |
|
| 185 | 185 | $data['modes']['default_shipping_mode']['free_shipping'] = $wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']; |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | $data['default_choice'] = 'default_shipping_mode'; |
| 189 | 189 | |
| 190 | - update_option( 'wps_shipping_mode', $data ); |
|
| 190 | + update_option('wps_shipping_mode', $data); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * Display the Admin Interface for Shipping Mode |
| 196 | 196 | **/ |
| 197 | 197 | function display_shipping_mode_in_admin() { |
| 198 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 199 | - require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes") ); |
|
| 198 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 199 | + require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes")); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | * @param array $shipping_mode |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - function generate_shipping_mode_interface( $k, $shipping_mode ) { |
|
| 208 | + function generate_shipping_mode_interface($k, $shipping_mode) { |
|
| 209 | 209 | global $wpdb; |
| 210 | 210 | $tpl_component = array(); |
| 211 | 211 | |
| 212 | - $shipping_mode_option = get_option( 'wps_shipping_mode'); |
|
| 213 | - $default_shipping_mode = !empty( $shipping_mode_option['default_choice'] ) ? $shipping_mode_option['default_choice'] : ''; |
|
| 212 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 213 | + $default_shipping_mode = !empty($shipping_mode_option['default_choice']) ? $shipping_mode_option['default_choice'] : ''; |
|
| 214 | 214 | |
| 215 | 215 | $countries = unserialize(WPSHOP_COUNTRY_LIST); |
| 216 | 216 | |
| 217 | 217 | /** Default Weight Unity **/ |
| 218 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 219 | - $query = $wpdb->prepare('SELECT name FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 220 | - $unity = $wpdb->get_var( $query ); |
|
| 218 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 219 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 220 | + $unity = $wpdb->get_var($query); |
|
| 221 | 221 | |
| 222 | 222 | |
| 223 | - $fees_data = ( !empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees']) ) ? $shipping_mode['custom_shipping_rules']['fees'] : array(); |
|
| 224 | - if(is_array($fees_data)) { |
|
| 223 | + $fees_data = (!empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees'])) ? $shipping_mode['custom_shipping_rules']['fees'] : array(); |
|
| 224 | + if (is_array($fees_data)) { |
|
| 225 | 225 | $wps_shipping = new wps_shipping(); |
| 226 | 226 | $fees_data = $wps_shipping->shipping_fees_array_2_string($fees_data); |
| 227 | 227 | } |
| 228 | 228 | ob_start(); |
| 229 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface") ); |
|
| 229 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface")); |
|
| 230 | 230 | $output = ob_get_contents(); |
| 231 | 231 | ob_end_clean(); |
| 232 | 232 | |
@@ -239,22 +239,22 @@ discard block |
||
| 239 | 239 | * @param array $fees_data |
| 240 | 240 | * @param string $key |
| 241 | 241 | */ |
| 242 | - function generate_shipping_rules_table( $fees_data, $shipping_mode_id ){ |
|
| 242 | + function generate_shipping_rules_table($fees_data, $shipping_mode_id) { |
|
| 243 | 243 | global $wpdb; |
| 244 | 244 | $result = ''; |
| 245 | - if ( !empty( $fees_data) ) { |
|
| 245 | + if (!empty($fees_data)) { |
|
| 246 | 246 | $wps_shipping = new wps_shipping(); |
| 247 | - $shipping_rules =$wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 247 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 248 | 248 | $result = ''; |
| 249 | - $tpl_component =''; |
|
| 249 | + $tpl_component = ''; |
|
| 250 | 250 | $tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = ''; |
| 251 | 251 | $tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id; |
| 252 | 252 | $country_list = unserialize(WPSHOP_COUNTRY_LIST); |
| 253 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 254 | - $query = $wpdb->prepare('SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 255 | - $unity = $wpdb->get_var( $query ); |
|
| 253 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 254 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 255 | + $unity = $wpdb->get_var($query); |
|
| 256 | 256 | ob_start(); |
| 257 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table") ); |
|
| 257 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table")); |
|
| 258 | 258 | $result = ob_get_contents(); |
| 259 | 259 | ob_end_clean(); |
| 260 | 260 | } |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | function display_shipping_methods() { |
| 276 | 276 | $output = $shipping_methods = ''; $no_shipping_mode_for_area = false; |
| 277 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 278 | - if( !empty($_SESSION['shipping_address']) ) { |
|
| 279 | - $shipping_modes = $this->get_shipping_mode_for_address( $_SESSION['shipping_address'] ); |
|
| 280 | - if( empty($shipping_modes) ) { |
|
| 277 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
| 278 | + if (!empty($_SESSION['shipping_address'])) { |
|
| 279 | + $shipping_modes = $this->get_shipping_mode_for_address($_SESSION['shipping_address']); |
|
| 280 | + if (empty($shipping_modes)) { |
|
| 281 | 281 | $no_shipping_mode_for_area = true; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $shipping_modes = apply_filters( 'wps_filter_shipping_methods', $shipping_modes ); |
|
| 284 | + $shipping_modes = apply_filters('wps_filter_shipping_methods', $shipping_modes); |
|
| 285 | 285 | ob_start(); |
| 286 | - require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container") ); |
|
| 286 | + require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container")); |
|
| 287 | 287 | $output = ob_get_contents(); |
| 288 | 288 | ob_end_clean(); |
| 289 | 289 | |
@@ -296,24 +296,24 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | function display_shipping_summary() { |
| 298 | 298 | $output = ''; |
| 299 | - $billing_address_id = ( !empty($_SESSION['billing_address']) ) ? $_SESSION['billing_address'] : null; |
|
| 300 | - $shipping_address_id = ( !empty($_SESSION['shipping_address']) ) ? $_SESSION['shipping_address'] : null; |
|
| 301 | - $shipping_mode = ( !empty($_SESSION['shipping_method']) ) ? $_SESSION['shipping_method'] : null; |
|
| 299 | + $billing_address_id = (!empty($_SESSION['billing_address'])) ? $_SESSION['billing_address'] : null; |
|
| 300 | + $shipping_address_id = (!empty($_SESSION['shipping_address'])) ? $_SESSION['shipping_address'] : null; |
|
| 301 | + $shipping_mode = (!empty($_SESSION['shipping_method'])) ? $_SESSION['shipping_method'] : null; |
|
| 302 | 302 | |
| 303 | - if( !empty($billing_address_id) ) { |
|
| 303 | + if (!empty($billing_address_id)) { |
|
| 304 | 304 | $billing_infos = get_post_meta($billing_address_id, '_wpshop_address_metadata', true); |
| 305 | - $billing_content = wps_address::display_an_address( $billing_infos, $billing_address_id); |
|
| 305 | + $billing_content = wps_address::display_an_address($billing_infos, $billing_address_id); |
|
| 306 | 306 | |
| 307 | - if ( !empty($shipping_address_id) && !empty($shipping_mode) ) { |
|
| 307 | + if (!empty($shipping_address_id) && !empty($shipping_mode)) { |
|
| 308 | 308 | $shipping_infos = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true); |
| 309 | - $shipping_content = wps_address::display_an_address( $shipping_infos, $shipping_address_id); |
|
| 309 | + $shipping_content = wps_address::display_an_address($shipping_infos, $shipping_address_id); |
|
| 310 | 310 | |
| 311 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 312 | - $shipping_mode = ( !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name']) ) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; |
|
| 311 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 312 | + $shipping_mode = (!empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name'])) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | ob_start(); |
| 316 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary") ); |
|
| 316 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary")); |
|
| 317 | 317 | $output = ob_get_contents(); |
| 318 | 318 | ob_end_clean(); |
| 319 | 319 | } |
@@ -327,42 +327,42 @@ discard block |
||
| 327 | 327 | * @param integer $address_id |
| 328 | 328 | * @return string |
| 329 | 329 | */ |
| 330 | - function get_shipping_mode_for_address( $address_id ) { |
|
| 330 | + function get_shipping_mode_for_address($address_id) { |
|
| 331 | 331 | $shipping_modes_to_display = array(); |
| 332 | - if( !empty($address_id) ) { |
|
| 333 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 334 | - $address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta( $address_id, '_wpshop_address_metadata', true); |
|
| 335 | - if( !empty( $shipping_modes ) && !empty($shipping_modes['modes']) ){ |
|
| 336 | - foreach( $shipping_modes['modes'] as $k => $shipping_mode ) { |
|
| 337 | - if ( !empty($shipping_mode) && !empty($shipping_mode['active']) ) { |
|
| 332 | + if (!empty($address_id)) { |
|
| 333 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
| 334 | + $address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta($address_id, '_wpshop_address_metadata', true); |
|
| 335 | + if (!empty($shipping_modes) && !empty($shipping_modes['modes'])) { |
|
| 336 | + foreach ($shipping_modes['modes'] as $k => $shipping_mode) { |
|
| 337 | + if (!empty($shipping_mode) && !empty($shipping_mode['active'])) { |
|
| 338 | 338 | /** Check Country Shipping Limitation **/ |
| 339 | - if ( empty($shipping_mode['limit_destination']) || ( !empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country']) ) || ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']) ) ) { |
|
| 339 | + if (empty($shipping_mode['limit_destination']) || (!empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country'])) || (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']))) { |
|
| 340 | 340 | /** Check Limit Destination By Postcode **/ |
| 341 | 341 | $visible = true; |
| 342 | 342 | /** Check Postcode limitation **/ |
| 343 | - if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode']) ) { |
|
| 344 | - $postcodes = explode(',', $shipping_mode['limit_destination']['postcode'] ); |
|
| 345 | - foreach( $postcodes as $postcode_id => $postcode ) { |
|
| 346 | - $postcodes[ $postcode_id ] = trim( str_replace( ' ', '', $postcode) ); |
|
| 343 | + if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode'])) { |
|
| 344 | + $postcodes = explode(',', $shipping_mode['limit_destination']['postcode']); |
|
| 345 | + foreach ($postcodes as $postcode_id => $postcode) { |
|
| 346 | + $postcodes[$postcode_id] = trim(str_replace(' ', '', $postcode)); |
|
| 347 | 347 | } |
| 348 | - if ( !in_array($address_metadata['postcode'], $postcodes) ) { |
|
| 348 | + if (!in_array($address_metadata['postcode'], $postcodes)) { |
|
| 349 | 349 | $visible = false; |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | /** Check Department limitation **/ |
| 353 | - $department = isset( $address_metadata['postcode'] ) ? substr( $address_metadata['postcode'], 0, 2 ) : ''; |
|
| 354 | - if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department']) ) { |
|
| 355 | - $departments = explode(',', $shipping_mode['limit_destination']['department'] ); |
|
| 356 | - foreach( $departments as $department_id => $d ) { |
|
| 357 | - $departments[ $department_id ] = trim( str_replace( ' ', '', $d) ); |
|
| 353 | + $department = isset($address_metadata['postcode']) ? substr($address_metadata['postcode'], 0, 2) : ''; |
|
| 354 | + if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department'])) { |
|
| 355 | + $departments = explode(',', $shipping_mode['limit_destination']['department']); |
|
| 356 | + foreach ($departments as $department_id => $d) { |
|
| 357 | + $departments[$department_id] = trim(str_replace(' ', '', $d)); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( !in_array($department, $departments) ) { |
|
| 360 | + if (!in_array($department, $departments)) { |
|
| 361 | 361 | $visible = false; |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - if ( $visible ) { |
|
| 365 | + if ($visible) { |
|
| 366 | 366 | $shipping_modes_to_display['modes'][$k] = $shipping_mode; |
| 367 | 367 | } |
| 368 | 368 | } |
@@ -378,12 +378,12 @@ discard block |
||
| 378 | 378 | * Display shipping informations in order administration panel |
| 379 | 379 | * @param object $order : Order post infos |
| 380 | 380 | */ |
| 381 | - function order_shipping_box( $order ) { |
|
| 382 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 381 | + function order_shipping_box($order) { |
|
| 382 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 383 | 383 | $order_postmeta = get_post_meta($order->ID, '_order_postmeta', true); |
| 384 | - $shipping_method_name = ( !empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ( (!empty($order_postmeta['order_payment']['shipping_method']) ) ? $order_postmeta['order_payment']['shipping_method'] : '' ); |
|
| 384 | + $shipping_method_name = (!empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ((!empty($order_postmeta['order_payment']['shipping_method'])) ? $order_postmeta['order_payment']['shipping_method'] : ''); |
|
| 385 | 385 | ob_start(); |
| 386 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos") ); |
|
| 386 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos")); |
|
| 387 | 387 | $output = ob_get_contents(); |
| 388 | 388 | ob_end_clean(); |
| 389 | 389 | echo $output; |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_shipping_mode_ctr { |
| 3 | 5 | |
| 4 | 6 | /** |
@@ -70,8 +72,9 @@ discard block |
||
| 70 | 72 | */ |
| 71 | 73 | function add_scripts_in_admin( $hook ) { |
| 72 | 74 | global $current_screen; |
| 73 | - if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) && $hook !== 'settings_page_wpshop_option' ) |
|
| 74 | - return; |
|
| 75 | + if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) && $hook !== 'settings_page_wpshop_option' ) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 75 | 78 | |
| 76 | 79 | add_thickbox(); |
| 77 | 80 | wp_enqueue_script('jquery'); |