@@ -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 | * |
@@ -21,29 +21,29 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | function __construct() { |
| 23 | 23 | // Add submenu |
| 24 | - add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 ); |
|
| 24 | + add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350); |
|
| 25 | 25 | |
| 26 | 26 | // Trigger ajax action |
| 27 | - add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') ); |
|
| 28 | - add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') ); |
|
| 29 | - add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) ); |
|
| 30 | - add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) ); |
|
| 31 | - add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) ); |
|
| 27 | + add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page')); |
|
| 28 | + add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface')); |
|
| 29 | + add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation')); |
|
| 30 | + add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file')); |
|
| 31 | + add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list')); |
|
| 32 | 32 | // add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) ); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | function register_mass_products_edit_submenu() { |
| 36 | - $this->submenu = 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' ) ); |
|
| 36 | + $this->submenu = 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')); |
|
| 37 | 37 | // Declare Styles and JS Files. |
| 38 | - add_action( 'admin_print_styles-' . $this->submenu, array( $this, 'admin_print_styles' ) ); |
|
| 39 | - add_action( 'admin_print_scripts-' . $this->submenu, array( $this, 'admin_print_scripts' ) ); |
|
| 38 | + add_action('admin_print_styles-' . $this->submenu, array($this, 'admin_print_styles')); |
|
| 39 | + add_action('admin_print_scripts-' . $this->submenu, array($this, 'admin_print_scripts')); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Add css to administration |
| 44 | 44 | */ |
| 45 | 45 | function admin_print_styles() { |
| 46 | - wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css' ); |
|
| 46 | + wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function admin_print_scripts() { |
| 53 | 53 | wp_enqueue_media(); |
| 54 | - wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true ); |
|
| 54 | + wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true); |
|
| 55 | 55 | $output = '<script type="text/javascript">'; |
| 56 | - $output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";'; |
|
| 57 | - $output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";'; |
|
| 58 | - $output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";'; |
|
| 59 | - $output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";'; |
|
| 56 | + $output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";'; |
|
| 57 | + $output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";'; |
|
| 58 | + $output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";'; |
|
| 59 | + $output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";'; |
|
| 60 | 60 | $output .= '</script>'; |
| 61 | 61 | echo $output; |
| 62 | 62 | } |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | - function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) { |
|
| 72 | - |
|
| 73 | - if ( !empty( $attribute_list ) ) { |
|
| 74 | - foreach( $attribute_list as $attributes_group ) { |
|
| 75 | - foreach( $attributes_group as $attributes_sections ) { |
|
| 76 | - if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) { |
|
| 77 | - foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) { |
|
| 78 | - if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) { |
|
| 79 | - $quick_add_form_attributes[ $attribute_id ] = $att_def; |
|
| 71 | + function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) { |
|
| 72 | + |
|
| 73 | + if (!empty($attribute_list)) { |
|
| 74 | + foreach ($attribute_list as $attributes_group) { |
|
| 75 | + foreach ($attributes_group as $attributes_sections) { |
|
| 76 | + if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) { |
|
| 77 | + foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) { |
|
| 78 | + if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') { |
|
| 79 | + $quick_add_form_attributes[$attribute_id] = $att_def; |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -93,29 +93,29 @@ discard block |
||
| 93 | 93 | * @param integer $page |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - function display_products_list( $default = 1, $page = 0, $order_by = 'date', $order = 'ASC' ) { |
|
| 96 | + function display_products_list($default = 1, $page = 0, $order_by = 'date', $order = 'ASC') { |
|
| 97 | 97 | global $wpdb; |
| 98 | 98 | // Product entity |
| 99 | - $product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 99 | + $product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 100 | 100 | |
| 101 | 101 | $user_id = get_current_user_id(); |
| 102 | 102 | // Check product limit |
| 103 | - $product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 104 | - $product_limit = ( !empty($product_limit) ) ? $product_limit : 20; |
|
| 103 | + $product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 104 | + $product_limit = (!empty($product_limit)) ? $product_limit : 20; |
|
| 105 | 105 | |
| 106 | 106 | // Get products for the current page |
| 107 | 107 | $wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl(); |
| 108 | - $products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit ); |
|
| 108 | + $products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit); |
|
| 109 | 109 | |
| 110 | 110 | // Construct Table Head Data |
| 111 | 111 | $quick_add_form_attributes = array(); |
| 112 | 112 | $get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form(); |
| 113 | - foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) { |
|
| 113 | + foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) { |
|
| 114 | 114 | $quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | ob_start(); |
| 118 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) ); |
|
| 118 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list")); |
|
| 119 | 119 | $output = ob_get_contents(); |
| 120 | 120 | ob_end_clean(); |
| 121 | 121 | return $output; |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | $products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets(); |
| 132 | 132 | |
| 133 | 133 | $default = ''; |
| 134 | - if( !empty($products_attributes_groups) ) { |
|
| 135 | - foreach( $products_attributes_groups as $key => $products_attributes_group ) { |
|
| 136 | - if( $products_attributes_group->slug == 'free_product' ) { |
|
| 137 | - unset( $products_attributes_groups[$key] ); |
|
| 134 | + if (!empty($products_attributes_groups)) { |
|
| 135 | + foreach ($products_attributes_groups as $key => $products_attributes_group) { |
|
| 136 | + if ($products_attributes_group->slug == 'free_product') { |
|
| 137 | + unset($products_attributes_groups[$key]); |
|
| 138 | 138 | } |
| 139 | - if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) { |
|
| 139 | + if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') { |
|
| 140 | 140 | $default = $products_attributes_group->id; |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | // Check page |
| 145 | - $page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0; |
|
| 145 | + $page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0; |
|
| 146 | 146 | // Display product tab |
| 147 | - $order_by = !empty( $_GET[ 'order_by' ] ) ? sanitize_title( $_GET[ 'order_by' ] ) : 'date'; |
|
| 148 | - $order = !empty( $_GET[ 'order' ] ) ? sanitize_title( $_GET[ 'order' ] ) : 'ASC'; |
|
| 149 | - $product_list_interface = $this->display_products_list( $default, $page, $order_by, $order ); |
|
| 147 | + $order_by = !empty($_GET['order_by']) ? sanitize_title($_GET['order_by']) : 'date'; |
|
| 148 | + $order = !empty($_GET['order']) ? sanitize_title($_GET['order']) : 'ASC'; |
|
| 149 | + $product_list_interface = $this->display_products_list($default, $page, $order_by, $order); |
|
| 150 | 150 | |
| 151 | 151 | // Get pagination |
| 152 | - $pagination = $this->get_products_pagination( $page, $default ); |
|
| 152 | + $pagination = $this->get_products_pagination($page, $default); |
|
| 153 | 153 | |
| 154 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) ); |
|
| 154 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface")); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - function get_products_pagination( $current_page, $attribute_set_id = 1 ) { |
|
| 162 | + function get_products_pagination($current_page, $attribute_set_id = 1) { |
|
| 163 | 163 | global $wpdb; |
| 164 | 164 | $user_id = get_current_user_id(); |
| 165 | 165 | $output = ''; |
| 166 | 166 | /** Define the element number per page. If the user change the default value, take this value */ |
| 167 | - $one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 168 | - $one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20; |
|
| 167 | + $one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 168 | + $one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20; |
|
| 169 | 169 | |
| 170 | 170 | /** Count the number of product existing in the shop */ |
| 171 | 171 | $query = $wpdb->prepare( |
@@ -177,37 +177,37 @@ discard block |
||
| 177 | 177 | AND meta_value = %s |
| 178 | 178 | AND post_status IN ( 'publish', 'draft' )", |
| 179 | 179 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id); |
| 180 | - $products = $wpdb->get_var( $query ); |
|
| 180 | + $products = $wpdb->get_var($query); |
|
| 181 | 181 | |
| 182 | - if( !empty($products) ) { |
|
| 182 | + if (!empty($products)) { |
|
| 183 | 183 | $args = array( |
| 184 | 184 | 'base' => '%_%', |
| 185 | - 'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ), |
|
| 186 | - 'current' => ( $current_page + 1 ), |
|
| 187 | - 'total' => ceil( $products / $one_page_limit ), |
|
| 185 | + 'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'), |
|
| 186 | + 'current' => ($current_page + 1), |
|
| 187 | + 'total' => ceil($products / $one_page_limit), |
|
| 188 | 188 | 'type' => 'array', |
| 189 | 189 | 'prev_next' => false, |
| 190 | 190 | 'show_all' => true, |
| 191 | 191 | ); |
| 192 | - $paginate = paginate_links( $args ); |
|
| 192 | + $paginate = paginate_links($args); |
|
| 193 | 193 | |
| 194 | 194 | $wps_product_ctr = new wps_product_ctr(); |
| 195 | 195 | ob_start(); |
| 196 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) ); |
|
| 196 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination")); |
|
| 197 | 197 | $output = ob_get_contents(); |
| 198 | 198 | ob_end_clean(); |
| 199 | 199 | } |
| 200 | 200 | return $output; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - function wps_product_attached_files( $product_id ) { |
|
| 203 | + function wps_product_attached_files($product_id) { |
|
| 204 | 204 | global $wpdb; |
| 205 | 205 | $output = ''; |
| 206 | - $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%' ); |
|
| 207 | - $files = $wpdb->get_results( $query ); |
|
| 208 | - if( !empty($files) ) { |
|
| 206 | + $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%'); |
|
| 207 | + $files = $wpdb->get_results($query); |
|
| 208 | + if (!empty($files)) { |
|
| 209 | 209 | ob_start(); |
| 210 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) ); |
|
| 210 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list")); |
|
| 211 | 211 | $output = ob_get_contents(); |
| 212 | 212 | ob_end_clean(); |
| 213 | 213 | } |
@@ -219,23 +219,23 @@ discard block |
||
| 219 | 219 | * AJAX - Change page action on mass edit product interface |
| 220 | 220 | */ |
| 221 | 221 | function wps_mass_edit_change_page() { |
| 222 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 222 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 223 | 223 | |
| 224 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) |
|
| 224 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page')) |
|
| 225 | 225 | wp_die(); |
| 226 | 226 | |
| 227 | 227 | $status = false; $response = ''; |
| 228 | - $page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0; |
|
| 229 | - $attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1; |
|
| 230 | - if( !empty($attribute_set_id) ) { |
|
| 228 | + $page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0; |
|
| 229 | + $attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1; |
|
| 230 | + if (!empty($attribute_set_id)) { |
|
| 231 | 231 | // Get tab |
| 232 | - $response = $this->display_products_list( $attribute_set_id, $page ); |
|
| 233 | - $pagination = $this->get_products_pagination( $page, $attribute_set_id ); |
|
| 234 | - if( !empty($response) ) { |
|
| 232 | + $response = $this->display_products_list($attribute_set_id, $page); |
|
| 233 | + $pagination = $this->get_products_pagination($page, $attribute_set_id); |
|
| 234 | + if (!empty($response)) { |
|
| 235 | 235 | $status = true; |
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | - echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) ); |
|
| 238 | + echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination)); |
|
| 239 | 239 | wp_die(); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -243,30 +243,30 @@ discard block |
||
| 243 | 243 | * AJAX - Create a draft product and display the line allowing to edit informations for this product |
| 244 | 244 | */ |
| 245 | 245 | function wps_mass_interface_new_product_creation() { |
| 246 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 246 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 247 | 247 | |
| 248 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) |
|
| 248 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation')) |
|
| 249 | 249 | wp_die(); |
| 250 | 250 | |
| 251 | 251 | global $wpdb; |
| 252 | 252 | $output = $pagination = ''; |
| 253 | 253 | $status = false; |
| 254 | 254 | |
| 255 | - $new_product_id = wp_insert_post( array( |
|
| 255 | + $new_product_id = wp_insert_post(array( |
|
| 256 | 256 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
| 257 | 257 | 'post_status' => 'publish', |
| 258 | - 'post_title' => __( 'New product', 'wpshop' ), |
|
| 259 | - ) ); |
|
| 258 | + 'post_title' => __('New product', 'wpshop'), |
|
| 259 | + )); |
|
| 260 | 260 | |
| 261 | - if( !is_object($new_product_id) ) { |
|
| 261 | + if (!is_object($new_product_id)) { |
|
| 262 | 262 | $status = true; |
| 263 | 263 | } |
| 264 | - if ( !empty( $new_product_id ) ) { |
|
| 265 | - $product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1; |
|
| 266 | - update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id ); |
|
| 264 | + if (!empty($new_product_id)) { |
|
| 265 | + $product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1; |
|
| 266 | + update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) ); |
|
| 269 | + echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination)); |
|
| 270 | 270 | wp_die(); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -274,32 +274,32 @@ discard block |
||
| 274 | 274 | * AJAX - Save datas |
| 275 | 275 | */ |
| 276 | 276 | function wps_save_product_quick_interface() { |
| 277 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 277 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 278 | 278 | |
| 279 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) |
|
| 279 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface')) |
|
| 280 | 280 | wp_die(); |
| 281 | 281 | |
| 282 | 282 | global $wpdb; |
| 283 | 283 | $response = ''; $status = false; |
| 284 | 284 | $count_products_to_update = 0; $total_updated_products = 0; |
| 285 | 285 | |
| 286 | - $wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array(); |
|
| 287 | - $wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array(); |
|
| 288 | - $wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array(); |
|
| 286 | + $wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array(); |
|
| 287 | + $wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array(); |
|
| 288 | + $wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array(); |
|
| 289 | 289 | |
| 290 | 290 | // ------------------------------------------------------------------------------------------------------ |
| 291 | 291 | |
| 292 | - foreach( $_REQUEST['concur'] as $post_id => $columns ) { |
|
| 292 | + foreach ($_REQUEST['concur'] as $post_id => $columns) { |
|
| 293 | 293 | $concur = array(); |
| 294 | - for( $i = $count = 0; $i <= $count; $i++ ) { |
|
| 295 | - foreach( $columns as $key => $rows ) { |
|
| 296 | - $count = count( $rows )-1; |
|
| 294 | + for ($i = $count = 0; $i <= $count; $i++) { |
|
| 295 | + foreach ($columns as $key => $rows) { |
|
| 296 | + $count = count($rows) - 1; |
|
| 297 | 297 | $concur[$i][$key] = $rows[$i]; |
| 298 | 298 | } |
| 299 | - if( empty( $concur[$i]['is_row'] ) ) { |
|
| 300 | - unset( $concur[$i] ); |
|
| 299 | + if (empty($concur[$i]['is_row'])) { |
|
| 300 | + unset($concur[$i]); |
|
| 301 | 301 | } else { |
| 302 | - unset( $concur[$i]['is_row'] ); |
|
| 302 | + unset($concur[$i]['is_row']); |
|
| 303 | 303 | |
| 304 | 304 | $dotPos = strrpos($concur[$i]['price'], '.'); |
| 305 | 305 | $commaPos = strrpos($concur[$i]['price'], ','); |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | } else { |
| 310 | 310 | $concur[$i]['price'] = floatval( |
| 311 | 311 | preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], 0, $sep)) . '.' . |
| 312 | - preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep+1, strlen($concur[$i]['price']))) |
|
| 312 | + preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep + 1, strlen($concur[$i]['price']))) |
|
| 313 | 313 | ); |
| 314 | 314 | } |
| 315 | 315 | |
@@ -317,51 +317,51 @@ discard block |
||
| 317 | 317 | $concur[$i]['price'] = $concur[$i]['price']; |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | - update_post_meta( $post_id, '_concur', $concur ); |
|
| 320 | + update_post_meta($post_id, '_concur', $concur); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // ------------------------------------------------------------------------------------------------------ |
| 324 | 324 | |
| 325 | - if( !empty($wps_product_quick_save) ) { |
|
| 326 | - $count_products_to_update = count( $wps_product_quick_save ); |
|
| 327 | - foreach( $wps_product_quick_save as $product_to_save ) { |
|
| 325 | + if (!empty($wps_product_quick_save)) { |
|
| 326 | + $count_products_to_update = count($wps_product_quick_save); |
|
| 327 | + foreach ($wps_product_quick_save as $product_to_save) { |
|
| 328 | 328 | $data_to_save = array(); |
| 329 | 329 | // Update post |
| 330 | - $updated_post = wp_update_post( array( 'ID' => $product_to_save, |
|
| 331 | - 'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ), |
|
| 332 | - 'post_content' => wp_kses_post( $wps_mass_interface[$product_to_save]['post_content'] ), |
|
| 330 | + $updated_post = wp_update_post(array('ID' => $product_to_save, |
|
| 331 | + 'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']), |
|
| 332 | + 'post_content' => wp_kses_post($wps_mass_interface[$product_to_save]['post_content']), |
|
| 333 | 333 | ) |
| 334 | 334 | ); |
| 335 | 335 | // Update attributes |
| 336 | - if( !empty($updated_post) ) { |
|
| 336 | + if (!empty($updated_post)) { |
|
| 337 | 337 | // Update Featured picture |
| 338 | - if( !empty($wps_mass_interface[$product_to_save]['picture']) ) { |
|
| 339 | - $thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true ); |
|
| 340 | - if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 341 | - wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) ); |
|
| 342 | - update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] ); |
|
| 338 | + if (!empty($wps_mass_interface[$product_to_save]['picture'])) { |
|
| 339 | + $thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true); |
|
| 340 | + if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 341 | + wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post)); |
|
| 342 | + update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']); |
|
| 343 | 343 | } |
| 344 | - elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 345 | - delete_post_meta( $updated_post, '_thumbnail_id' ); |
|
| 344 | + elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 345 | + delete_post_meta($updated_post, '_thumbnail_id'); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Update files datas |
| 350 | - if( !empty($wps_mass_interface[$product_to_save]['files']) ) { |
|
| 351 | - $files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) ); |
|
| 352 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 353 | - foreach( $files_data as $file_id ) { |
|
| 354 | - if( !empty($file_id) ) { |
|
| 355 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) ); |
|
| 350 | + if (!empty($wps_mass_interface[$product_to_save]['files'])) { |
|
| 351 | + $files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files'])); |
|
| 352 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 353 | + foreach ($files_data as $file_id) { |
|
| 354 | + if (!empty($file_id)) { |
|
| 355 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post)); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - $data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save ); |
|
| 362 | - $data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array(); |
|
| 361 | + $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save); |
|
| 362 | + $data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array(); |
|
| 363 | 363 | |
| 364 | - if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 364 | + if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 365 | 365 | // Get current barcode |
| 366 | 366 | $wps_product_mdl = new wps_product_mdl(); |
| 367 | 367 | $attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id; |
@@ -372,34 +372,34 @@ discard block |
||
| 372 | 372 | $data_to_save['user_ID'] = get_current_user_id(); |
| 373 | 373 | $data_to_save['action'] = 'editpost'; |
| 374 | 374 | |
| 375 | - if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) { |
|
| 376 | - wp_trash_post( $product_to_save ); |
|
| 375 | + if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") { |
|
| 376 | + wp_trash_post($product_to_save); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) { |
|
| 379 | + if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) { |
|
| 380 | 380 | $product_class = new wpshop_products(); |
| 381 | - $product_class->save_product_custom_informations( $product_to_save, $data_to_save ); |
|
| 381 | + $product_class->save_product_custom_informations($product_to_save, $data_to_save); |
|
| 382 | 382 | $total_updated_products++; |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | // Checking status |
| 388 | - $status = ( $total_updated_products == $count_products_to_update ) ? true : false; |
|
| 388 | + $status = ($total_updated_products == $count_products_to_update) ? true : false; |
|
| 389 | 389 | |
| 390 | - if( $status ) { |
|
| 391 | - $response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products ); |
|
| 390 | + if ($status) { |
|
| 391 | + $response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products); |
|
| 392 | 392 | } |
| 393 | 393 | else { |
| 394 | - if( !empty($total_updated_products) ) { |
|
| 395 | - $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 ); |
|
| 394 | + if (!empty($total_updated_products)) { |
|
| 395 | + $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); |
|
| 396 | 396 | } |
| 397 | 397 | else { |
| 398 | - $response = __( 'No product have been updated', 'wpshop'); |
|
| 398 | + $response = __('No product have been updated', 'wpshop'); |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - echo json_encode( array('status' => $status, 'response' => $response ) ); |
|
| 402 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 403 | 403 | wp_die(); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -407,18 +407,18 @@ discard block |
||
| 407 | 407 | * Delete product list |
| 408 | 408 | **/ |
| 409 | 409 | function wps_mass_delete_file() { |
| 410 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 410 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 411 | 411 | |
| 412 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) |
|
| 412 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file')) |
|
| 413 | 413 | wp_die(); |
| 414 | 414 | |
| 415 | 415 | $status = false; |
| 416 | - $file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null; |
|
| 417 | - if( !empty($file_id) ) { |
|
| 418 | - wp_update_post( array('ID' => $file_id, 'post_parent' => 0) ); |
|
| 416 | + $file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null; |
|
| 417 | + if (!empty($file_id)) { |
|
| 418 | + wp_update_post(array('ID' => $file_id, 'post_parent' => 0)); |
|
| 419 | 419 | $status = true; |
| 420 | 420 | } |
| 421 | - echo json_encode( array( 'status' => $status ) ); |
|
| 421 | + echo json_encode(array('status' => $status)); |
|
| 422 | 422 | wp_die(); |
| 423 | 423 | } |
| 424 | 424 | |
@@ -426,32 +426,32 @@ discard block |
||
| 426 | 426 | * Update product files list |
| 427 | 427 | */ |
| 428 | 428 | function wps_mass_edit_update_files_list() { |
| 429 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 429 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 430 | 430 | |
| 431 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) |
|
| 431 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list')) |
|
| 432 | 432 | wp_die(); |
| 433 | 433 | |
| 434 | 434 | $status = false; $response = ''; |
| 435 | - $product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null; |
|
| 436 | - $files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null; |
|
| 437 | - if( !empty($product_id ) ) { |
|
| 435 | + $product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null; |
|
| 436 | + $files = (!empty($_POST['files'])) ? intval($_POST['files']) : null; |
|
| 437 | + if (!empty($product_id)) { |
|
| 438 | 438 | // Update files datas |
| 439 | - if( !empty($files) ) { |
|
| 440 | - $files_data = explode( ',', $files ); |
|
| 441 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 442 | - foreach( $files_data as $file_id ) { |
|
| 443 | - if( !empty($file_id) ) { |
|
| 444 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) ); |
|
| 439 | + if (!empty($files)) { |
|
| 440 | + $files_data = explode(',', $files); |
|
| 441 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 442 | + foreach ($files_data as $file_id) { |
|
| 443 | + if (!empty($file_id)) { |
|
| 444 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id)); |
|
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
| 451 | - $response = $this->wps_product_attached_files( $product_id ); |
|
| 451 | + $response = $this->wps_product_attached_files($product_id); |
|
| 452 | 452 | $status = true; |
| 453 | 453 | } |
| 454 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 454 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 455 | 455 | wp_die(); |
| 456 | 456 | } |
| 457 | 457 | |
@@ -1,14 +1,14 @@ |
||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) { exit; |
|
| 2 | 2 | } |
| 3 | 3 | |
| 4 | -if ( false ) { |
|
| 5 | - DEFINE( 'WPS_PDCT_MASS_VERSION', '2.0' ); |
|
| 6 | - DEFINE( 'WPS_PDCT_MASS_DIR', basename( dirname( __FILE__ ) ) ); |
|
| 7 | - DEFINE( 'WPS_PDCT_MASS_PATH', dirname( __FILE__ ) ); |
|
| 8 | - DEFINE( 'WPS_PDCT_MASS_URL', str_replace( str_replace( '\\', '/', ABSPATH ), site_url() . '/', str_replace( '\\', '/', WPS_PDCT_MASS_PATH ) ) ); |
|
| 4 | +if (false) { |
|
| 5 | + DEFINE('WPS_PDCT_MASS_VERSION', '2.0'); |
|
| 6 | + DEFINE('WPS_PDCT_MASS_DIR', basename(dirname(__FILE__))); |
|
| 7 | + DEFINE('WPS_PDCT_MASS_PATH', dirname(__FILE__)); |
|
| 8 | + DEFINE('WPS_PDCT_MASS_URL', str_replace(str_replace('\\', '/', ABSPATH), site_url() . '/', str_replace('\\', '/', WPS_PDCT_MASS_PATH))); |
|
| 9 | 9 | /** Define the templates directories */ |
| 10 | - DEFINE( 'WPS_PDCT_MASS_TEMPLATES_MAIN_DIR', WPS_PDCT_MASS_PATH . '/templates/' ); |
|
| 11 | - include( plugin_dir_path( __FILE__ ) . '/controller/wps_product_mass_interface_ctr.php' ); |
|
| 12 | - include( plugin_dir_path( __FILE__ ) . '/model/wps_product_mass_interface_mdl.php' ); |
|
| 10 | + DEFINE('WPS_PDCT_MASS_TEMPLATES_MAIN_DIR', WPS_PDCT_MASS_PATH . '/templates/'); |
|
| 11 | + include(plugin_dir_path(__FILE__) . '/controller/wps_product_mass_interface_ctr.php'); |
|
| 12 | + include(plugin_dir_path(__FILE__) . '/model/wps_product_mass_interface_mdl.php'); |
|
| 13 | 13 | // $wps_product_mass_interface_ctr = new wps_product_mass_interface_ctr(); |
| 14 | 14 | } |
@@ -5,14 +5,14 @@ discard block |
||
| 5 | 5 | * @package wps-mass-interface3 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | +if (!defined('ABSPATH')) { |
|
| 9 | 9 | exit; |
| 10 | 10 | } |
| 11 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 11 | +if (!class_exists('WP_List_Table')) { |
|
| 12 | 12 | include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 13 | 13 | } |
| 14 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 15 | - exit( 'class-wp-list-table.php not found.' ); |
|
| 14 | +if (!class_exists('WP_List_Table')) { |
|
| 15 | + exit('class-wp-list-table.php not found.'); |
|
| 16 | 16 | } |
| 17 | 17 | /** |
| 18 | 18 | * Custom WP_List_Table to edit attributes from WPShop EAV. |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | * @method __construct |
| 79 | 79 | * @param array $args New key : exclude_attribute_codes. |
| 80 | 80 | */ |
| 81 | - public function __construct( $args ) { |
|
| 82 | - if ( isset( $args['exclude_attribute_codes'] ) ) { |
|
| 81 | + public function __construct($args) { |
|
| 82 | + if (isset($args['exclude_attribute_codes'])) { |
|
| 83 | 83 | $this->exclude_attribute_codes = $args['exclude_attribute_codes']; |
| 84 | 84 | } |
| 85 | 85 | parent::__construct( |
| 86 | 86 | array( |
| 87 | 87 | 'plural' => 'posts', |
| 88 | 88 | 'ajax' => true, |
| 89 | - 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
| 89 | + 'screen' => isset($args['screen']) ? $args['screen'] : null, |
|
| 90 | 90 | ) |
| 91 | 91 | ); |
| 92 | - $this->current_view = (int) substr( $this->screen->id, strpos( $this->screen->id, '_att_set_' ) + 9 ); |
|
| 93 | - $this->entity_id = (int) wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 94 | - $this->_post_types = array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ); |
|
| 92 | + $this->current_view = (int)substr($this->screen->id, strpos($this->screen->id, '_att_set_') + 9); |
|
| 93 | + $this->entity_id = (int)wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 94 | + $this->_post_types = array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION); |
|
| 95 | 95 | } |
| 96 | 96 | /** |
| 97 | 97 | * List columns. |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | public function get_columns() { |
| 103 | 103 | $columns = array( |
| 104 | 104 | 'cb' => '<input type="checkbox" />', |
| 105 | - 'title' => __( 'Title' ), |
|
| 106 | - 'thumbnail' => __( 'Thumbnail' ), |
|
| 105 | + 'title' => __('Title'), |
|
| 106 | + 'thumbnail' => __('Thumbnail'), |
|
| 107 | 107 | ); |
| 108 | - foreach ( $this->request_items_columns() as $column => $data_column ) { |
|
| 109 | - if ( ! empty( $column ) && ! empty( $data_column ) ) { |
|
| 110 | - $columns[ $column ] = $data_column['name']; |
|
| 108 | + foreach ($this->request_items_columns() as $column => $data_column) { |
|
| 109 | + if (!empty($column) && !empty($data_column)) { |
|
| 110 | + $columns[$column] = $data_column['name']; |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | return $columns; |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | protected function get_sortable_columns() { |
| 122 | 122 | $sortable_columns = array( |
| 123 | - 'title' => array( 'title', false ), |
|
| 123 | + 'title' => array('title', false), |
|
| 124 | 124 | ); |
| 125 | - foreach ( $this->request_items_columns() as $column => $data_column ) { |
|
| 126 | - $sortable_columns[ $column ] = array( $data_column['code'], false ); |
|
| 125 | + foreach ($this->request_items_columns() as $column => $data_column) { |
|
| 126 | + $sortable_columns[$column] = array($data_column['code'], false); |
|
| 127 | 127 | } |
| 128 | 128 | return $sortable_columns; |
| 129 | 129 | } |
@@ -135,22 +135,22 @@ discard block |
||
| 135 | 135 | * @param string $column_name Current column. |
| 136 | 136 | * @return string |
| 137 | 137 | */ |
| 138 | - public function column_default( $item, $column_name ) { |
|
| 139 | - if ( isset( $this->columns_items[ $column_name ] ) && is_callable( array( $this, "column_data_{$this->columns_items[ $column_name ]['type']}" ) ) ) { |
|
| 140 | - $callable_ext = str_replace( '-', '_', $this->columns_items[ $column_name ]['type'] ); |
|
| 141 | - $callable = array( $this, "column_data_{$callable_ext}" ); |
|
| 142 | - if ( ! is_callable( $callable ) ) { |
|
| 143 | - $callable = array( $this, 'column_data_text' ); |
|
| 138 | + public function column_default($item, $column_name) { |
|
| 139 | + if (isset($this->columns_items[$column_name]) && is_callable(array($this, "column_data_{$this->columns_items[$column_name]['type']}"))) { |
|
| 140 | + $callable_ext = str_replace('-', '_', $this->columns_items[$column_name]['type']); |
|
| 141 | + $callable = array($this, "column_data_{$callable_ext}"); |
|
| 142 | + if (!is_callable($callable)) { |
|
| 143 | + $callable = array($this, 'column_data_text'); |
|
| 144 | 144 | } |
| 145 | 145 | return call_user_func( |
| 146 | 146 | $callable, |
| 147 | - (int) $this->columns_items[ $column_name ]['id'], |
|
| 148 | - $this->columns_items[ $column_name ]['code'], |
|
| 149 | - $this->columns_items[ $column_name ]['data'], |
|
| 147 | + (int)$this->columns_items[$column_name]['id'], |
|
| 148 | + $this->columns_items[$column_name]['code'], |
|
| 149 | + $this->columns_items[$column_name]['data'], |
|
| 150 | 150 | $item |
| 151 | 151 | ); |
| 152 | 152 | } |
| 153 | - return print_r( $item[ $column_name ], true ); |
|
| 153 | + return print_r($item[$column_name], true); |
|
| 154 | 154 | } |
| 155 | 155 | /** |
| 156 | 156 | * Column content for checkbox. |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param array $item Result of sql query. |
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - public function column_cb( $item ) { |
|
| 162 | + public function column_cb($item) { |
|
| 163 | 163 | return sprintf( |
| 164 | 164 | '<input type="checkbox" name="cb[]" value="%d" />', |
| 165 | 165 | $item['ID'] |
@@ -172,20 +172,20 @@ discard block |
||
| 172 | 172 | * @param array $item Result of sql query. |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function column_thumbnail( $item ) { |
|
| 175 | + public function column_thumbnail($item) { |
|
| 176 | 176 | $thumbnail_id = ''; |
| 177 | - $link_content = get_the_post_thumbnail( $item['ID'], array( 25, 25 ) ); |
|
| 178 | - if ( empty( $link_content ) ) { |
|
| 179 | - $link_content = __( 'Choose Image' ); |
|
| 177 | + $link_content = get_the_post_thumbnail($item['ID'], array(25, 25)); |
|
| 178 | + if (empty($link_content)) { |
|
| 179 | + $link_content = __('Choose Image'); |
|
| 180 | 180 | } else { |
| 181 | - $thumbnail_id = get_post_thumbnail_id( $item['ID'] ); |
|
| 181 | + $thumbnail_id = get_post_thumbnail_id($item['ID']); |
|
| 182 | 182 | } |
| 183 | - $popup_title = __( 'Choose Image' ); |
|
| 183 | + $popup_title = __('Choose Image'); |
|
| 184 | 184 | return sprintf( |
| 185 | 185 | '<input type="hidden" name="row_%1$s[thumbnail]" value="%2$s"><a href="#thumbnail" data-media-title="%3$s">%4$s</a>', |
| 186 | 186 | $item['ID'], |
| 187 | 187 | $thumbnail_id, |
| 188 | - __( 'Choose Image' ), |
|
| 188 | + __('Choose Image'), |
|
| 189 | 189 | $link_content |
| 190 | 190 | ); |
| 191 | 191 | } |
@@ -196,39 +196,39 @@ discard block |
||
| 196 | 196 | * @param array $item Result of sql query. |
| 197 | 197 | * @return string |
| 198 | 198 | */ |
| 199 | - public function column_title( $item ) { |
|
| 200 | - if ( 'private' === $item['status'] ) { |
|
| 201 | - $post_states['private'] = __( 'Private' ); |
|
| 199 | + public function column_title($item) { |
|
| 200 | + if ('private' === $item['status']) { |
|
| 201 | + $post_states['private'] = __('Private'); |
|
| 202 | 202 | } |
| 203 | - if ( 'draft' === $item['status'] ) { |
|
| 204 | - $post_states['draft'] = __( 'Draft' ); |
|
| 203 | + if ('draft' === $item['status']) { |
|
| 204 | + $post_states['draft'] = __('Draft'); |
|
| 205 | 205 | } |
| 206 | - if ( 'pending' === $item['status'] ) { |
|
| 207 | - $post_states['pending'] = _x( 'Pending', 'post status' ); |
|
| 206 | + if ('pending' === $item['status']) { |
|
| 207 | + $post_states['pending'] = _x('Pending', 'post status'); |
|
| 208 | 208 | } |
| 209 | - if ( 'future' === $item['status'] ) { |
|
| 210 | - $post_states['scheduled'] = __( 'Scheduled' ); |
|
| 209 | + if ('future' === $item['status']) { |
|
| 210 | + $post_states['scheduled'] = __('Scheduled'); |
|
| 211 | 211 | } |
| 212 | - if ( current_user_can( 'edit_post', $item['ID'] ) && 'trash' !== $item['status'] ) { |
|
| 212 | + if (current_user_can('edit_post', $item['ID']) && 'trash' !== $item['status']) { |
|
| 213 | 213 | $result = sprintf( |
| 214 | 214 | '<a class="row-title" href="%s" aria-label="%s">%s</a>', |
| 215 | - get_edit_post_link( $item['ID'] ), |
|
| 215 | + get_edit_post_link($item['ID']), |
|
| 216 | 216 | // translators: WordPress translate. |
| 217 | - esc_attr( sprintf( __( '“%s” (Edit)' ), $item['title'] ) ), |
|
| 217 | + esc_attr(sprintf(__('“%s” (Edit)'), $item['title'])), |
|
| 218 | 218 | $item['title'] |
| 219 | 219 | ); |
| 220 | 220 | } else { |
| 221 | 221 | $result = $item['title']; |
| 222 | 222 | } |
| 223 | - if ( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item['type'] ) { |
|
| 224 | - $attr_def = get_post_meta( $item['ID'], '_wpshop_variations_attribute_def', true ); |
|
| 223 | + if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item['type']) { |
|
| 224 | + $attr_def = get_post_meta($item['ID'], '_wpshop_variations_attribute_def', true); |
|
| 225 | 225 | $columns_items = $this->request_items_columns(); |
| 226 | 226 | $first_variation = true; |
| 227 | - $parent = $this->items[ $item['parent'] ]; |
|
| 228 | - foreach ( $attr_def as $key => $value ) { |
|
| 229 | - foreach ( $this->get_select_items_option( $columns_items[ $key ]['id'] ) as $all_value ) { |
|
| 230 | - if ( $all_value['id'] === $value ) { |
|
| 231 | - if ( $first_variation ) { |
|
| 227 | + $parent = $this->items[$item['parent']]; |
|
| 228 | + foreach ($attr_def as $key => $value) { |
|
| 229 | + foreach ($this->get_select_items_option($columns_items[$key]['id']) as $all_value) { |
|
| 230 | + if ($all_value['id'] === $value) { |
|
| 231 | + if ($first_variation) { |
|
| 232 | 232 | $result = $parent['title'] . ' : '; |
| 233 | 233 | $first_variation = false; |
| 234 | 234 | } else { |
@@ -240,19 +240,19 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | - if ( ! empty( $post_states ) ) { |
|
| 244 | - $state_count = count( $post_states ); |
|
| 243 | + if (!empty($post_states)) { |
|
| 244 | + $state_count = count($post_states); |
|
| 245 | 245 | $i = 0; |
| 246 | 246 | $result .= ' — '; |
| 247 | - foreach ( $post_states as $state ) { |
|
| 247 | + foreach ($post_states as $state) { |
|
| 248 | 248 | ++$i; |
| 249 | - ( $i === $state_count ) ? $sep = '' : $sep = ', '; |
|
| 249 | + ($i === $state_count) ? $sep = '' : $sep = ', '; |
|
| 250 | 250 | $result .= "<span class='post-state'>$state$sep</span>"; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | return sprintf( |
| 254 | 254 | '<strong>%s</strong>', |
| 255 | - isset( $item['lvl'] ) ? $item['lvl'] . $result : $result |
|
| 255 | + isset($item['lvl']) ? $item['lvl'] . $result : $result |
|
| 256 | 256 | ); |
| 257 | 257 | } |
| 258 | 258 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param array $item Result of sql query. |
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | - public function column_data_default( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
| 268 | + public function column_data_default($attribute_id, $attribute_code, $attribute_data, $item) { |
|
| 269 | 269 | return 'default'; |
| 270 | 270 | } |
| 271 | 271 | /** |
@@ -278,13 +278,13 @@ discard block |
||
| 278 | 278 | * @param array $item Result of sql query. |
| 279 | 279 | * @return string |
| 280 | 280 | */ |
| 281 | - public function column_data_text( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
| 281 | + public function column_data_text($attribute_id, $attribute_code, $attribute_data, $item) { |
|
| 282 | 282 | $unit = ''; |
| 283 | - if ( is_array( $item[ $attribute_code ] ) ) { |
|
| 284 | - $unit = ' ' . $item[ $attribute_code ]['unit']; |
|
| 285 | - $value = $item[ $attribute_code ]['value']; |
|
| 283 | + if (is_array($item[$attribute_code])) { |
|
| 284 | + $unit = ' ' . $item[$attribute_code]['unit']; |
|
| 285 | + $value = $item[$attribute_code]['value']; |
|
| 286 | 286 | } else { |
| 287 | - $value = $item[ $attribute_code ]; |
|
| 287 | + $value = $item[$attribute_code]; |
|
| 288 | 288 | } |
| 289 | 289 | return sprintf( |
| 290 | 290 | '<input type="text" name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]" value="%4$s">', |
@@ -305,34 +305,34 @@ discard block |
||
| 305 | 305 | * @param array $item Result of sql query. |
| 306 | 306 | * @return string |
| 307 | 307 | */ |
| 308 | - public function column_data_select( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
| 308 | + public function column_data_select($attribute_id, $attribute_code, $attribute_data, $item) { |
|
| 309 | 309 | $unit = ''; |
| 310 | - if ( is_array( $item[ $attribute_code ] ) && isset( $item[ $attribute_code ]['unit'] ) ) { |
|
| 311 | - $unit = ' ' . $item[ $attribute_code ]['unit']; |
|
| 312 | - $value = $item[ $attribute_code ]['value']; |
|
| 310 | + if (is_array($item[$attribute_code]) && isset($item[$attribute_code]['unit'])) { |
|
| 311 | + $unit = ' ' . $item[$attribute_code]['unit']; |
|
| 312 | + $value = $item[$attribute_code]['value']; |
|
| 313 | 313 | } else { |
| 314 | - $value = $item[ $attribute_code ]; |
|
| 314 | + $value = $item[$attribute_code]; |
|
| 315 | 315 | } |
| 316 | 316 | $has_selected = false; |
| 317 | 317 | $select_items = array(); |
| 318 | - foreach ( $this->get_select_items_option( $attribute_id ) as $option_item ) { |
|
| 319 | - if ( is_array( $value ) ) { |
|
| 320 | - foreach ( $value as $val ) { |
|
| 321 | - $selected = selected( $val, $option_item['id'], false ); |
|
| 322 | - if ( ! empty( $selected ) ) { |
|
| 318 | + foreach ($this->get_select_items_option($attribute_id) as $option_item) { |
|
| 319 | + if (is_array($value)) { |
|
| 320 | + foreach ($value as $val) { |
|
| 321 | + $selected = selected($val, $option_item['id'], false); |
|
| 322 | + if (!empty($selected)) { |
|
| 323 | 323 | break; |
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | } else { |
| 327 | - $selected = selected( $value, $option_item['id'], false ); |
|
| 327 | + $selected = selected($value, $option_item['id'], false); |
|
| 328 | 328 | } |
| 329 | - $has_selected = empty( $selected ) ? $has_selected : true; |
|
| 329 | + $has_selected = empty($selected) ? $has_selected : true; |
|
| 330 | 330 | $select_items[] = "<option value=\"{$option_item['id']}\"{$selected}>{$option_item['label']}</option>"; |
| 331 | 331 | } |
| 332 | - if ( ! $has_selected ) { |
|
| 333 | - array_unshift( $select_items, '<option selected disabled>' . __( 'None' ) . '</option>' ); |
|
| 332 | + if (!$has_selected) { |
|
| 333 | + array_unshift($select_items, '<option selected disabled>' . __('None') . '</option>'); |
|
| 334 | 334 | } |
| 335 | - $select_items = implode( '', $select_items ); |
|
| 335 | + $select_items = implode('', $select_items); |
|
| 336 | 336 | return sprintf( |
| 337 | 337 | '<select name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]">%4$s</select>', |
| 338 | 338 | $attribute_code, |
@@ -352,13 +352,13 @@ discard block |
||
| 352 | 352 | * @param array $item Result of sql query. |
| 353 | 353 | * @return string |
| 354 | 354 | */ |
| 355 | - public function column_data_textarea( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
| 355 | + public function column_data_textarea($attribute_id, $attribute_code, $attribute_data, $item) { |
|
| 356 | 356 | $unit = ''; |
| 357 | - if ( is_array( $item[ $attribute_code ] ) ) { |
|
| 358 | - $unit = ' ' . $item[ $attribute_code ]['unit']; |
|
| 359 | - $value = $item[ $attribute_code ]['value']; |
|
| 357 | + if (is_array($item[$attribute_code])) { |
|
| 358 | + $unit = ' ' . $item[$attribute_code]['unit']; |
|
| 359 | + $value = $item[$attribute_code]['value']; |
|
| 360 | 360 | } else { |
| 361 | - $value = $item[ $attribute_code ]; |
|
| 361 | + $value = $item[$attribute_code]; |
|
| 362 | 362 | } |
| 363 | 363 | return sprintf( |
| 364 | 364 | '<textarea name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]">%4$s</textarea>', |
@@ -379,29 +379,29 @@ discard block |
||
| 379 | 379 | * @param array $item Result of sql query. |
| 380 | 380 | * @return string |
| 381 | 381 | */ |
| 382 | - public function column_data_multiple_select( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
| 382 | + public function column_data_multiple_select($attribute_id, $attribute_code, $attribute_data, $item) { |
|
| 383 | 383 | $unit = ''; |
| 384 | - if ( is_array( $item[ $attribute_code ] ) && isset( $item[ $attribute_code ]['unit'] ) ) { |
|
| 385 | - $unit = ' ' . $item[ $attribute_code ]['unit']; |
|
| 386 | - $value = $item[ $attribute_code ]['value']; |
|
| 384 | + if (is_array($item[$attribute_code]) && isset($item[$attribute_code]['unit'])) { |
|
| 385 | + $unit = ' ' . $item[$attribute_code]['unit']; |
|
| 386 | + $value = $item[$attribute_code]['value']; |
|
| 387 | 387 | } else { |
| 388 | - $value = $item[ $attribute_code ]; |
|
| 388 | + $value = $item[$attribute_code]; |
|
| 389 | 389 | } |
| 390 | 390 | $select_items = array(); |
| 391 | - foreach ( $this->get_select_items_option( $attribute_id ) as $option_item ) { |
|
| 392 | - if ( is_array( $value ) ) { |
|
| 393 | - foreach ( $value as $val ) { |
|
| 394 | - $selected = selected( $val, $option_item['id'], false ); |
|
| 395 | - if ( ! empty( $selected ) ) { |
|
| 391 | + foreach ($this->get_select_items_option($attribute_id) as $option_item) { |
|
| 392 | + if (is_array($value)) { |
|
| 393 | + foreach ($value as $val) { |
|
| 394 | + $selected = selected($val, $option_item['id'], false); |
|
| 395 | + if (!empty($selected)) { |
|
| 396 | 396 | break; |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | } else { |
| 400 | - $selected = selected( $value, $option_item['id'], false ); |
|
| 400 | + $selected = selected($value, $option_item['id'], false); |
|
| 401 | 401 | } |
| 402 | 402 | $select_items[] = "<option value=\"{$option_item['id']}\"{$selected}>{$option_item['label']}</option>"; |
| 403 | 403 | } |
| 404 | - $select_items = implode( '', $select_items ); |
|
| 404 | + $select_items = implode('', $select_items); |
|
| 405 | 405 | return sprintf( |
| 406 | 406 | '<select class="chosen-select" multiple data-placeholder="%6$s" name="row_%2$s[wpshop_product_attribute][%3$s][%1$s][]">%4$s</select>', |
| 407 | 407 | $attribute_code, |
@@ -419,9 +419,9 @@ discard block |
||
| 419 | 419 | * @param Mixed $id_post Null = all / Int = single. |
| 420 | 420 | * @return array Return all values with ARRAY_A. |
| 421 | 421 | */ |
| 422 | - public function request( $id_post = null ) { |
|
| 422 | + public function request($id_post = null) { |
|
| 423 | 423 | global $wpdb; |
| 424 | - $per_page = $this->get_items_per_page( $this->screen->get_option( 'per_page', 'option' ) ); |
|
| 424 | + $per_page = $this->get_items_per_page($this->screen->get_option('per_page', 'option')); |
|
| 425 | 425 | $include_states = array( |
| 426 | 426 | 'publish', |
| 427 | 427 | 'future', |
@@ -431,24 +431,24 @@ discard block |
||
| 431 | 431 | 'trash', |
| 432 | 432 | 'scheduled', |
| 433 | 433 | ); |
| 434 | - $include_states = implode( "','", $include_states ); |
|
| 435 | - $post_types = implode( "','", $this->_post_types ); |
|
| 436 | - $orderby = isset( $_REQUEST['orderby'] ) ? esc_sql( $_REQUEST['orderby'] ) : 'p.post_date'; // WPCS: CSRF ok. |
|
| 437 | - $order = isset( $_REQUEST['order'] ) ? esc_sql( $_REQUEST['order'] ) : 'DESC'; // WPCS: CSRF ok. |
|
| 438 | - $cast = isset( $_REQUEST['cast'] ) ? esc_sql( $_REQUEST['cast'] ) : ''; // WPCS: CSRF ok. |
|
| 439 | - $cast = strtoupper( $cast ); |
|
| 440 | - $s = isset( $_REQUEST['s'] ) ? esc_sql( $_REQUEST['s'] ) : ''; // WPCS: CSRF ok. |
|
| 441 | - $exclude_attribute_codes = implode( "','", $this->exclude_attribute_codes ); |
|
| 434 | + $include_states = implode("','", $include_states); |
|
| 435 | + $post_types = implode("','", $this->_post_types); |
|
| 436 | + $orderby = isset($_REQUEST['orderby']) ? esc_sql($_REQUEST['orderby']) : 'p.post_date'; // WPCS: CSRF ok. |
|
| 437 | + $order = isset($_REQUEST['order']) ? esc_sql($_REQUEST['order']) : 'DESC'; // WPCS: CSRF ok. |
|
| 438 | + $cast = isset($_REQUEST['cast']) ? esc_sql($_REQUEST['cast']) : ''; // WPCS: CSRF ok. |
|
| 439 | + $cast = strtoupper($cast); |
|
| 440 | + $s = isset($_REQUEST['s']) ? esc_sql($_REQUEST['s']) : ''; // WPCS: CSRF ok. |
|
| 441 | + $exclude_attribute_codes = implode("','", $this->exclude_attribute_codes); |
|
| 442 | 442 | $extra = ''; |
| 443 | - $items_count = $wpdb->prepare( "SELECT FOUND_ROWS() FROM {$wpdb->posts} WHERE 1 = %d", 1 ); |
|
| 444 | - if ( ! is_null( $id_post ) ) { |
|
| 445 | - $id_post = intval( $id_post ); |
|
| 443 | + $items_count = $wpdb->prepare("SELECT FOUND_ROWS() FROM {$wpdb->posts} WHERE 1 = %d", 1); |
|
| 444 | + if (!is_null($id_post)) { |
|
| 445 | + $id_post = intval($id_post); |
|
| 446 | 446 | $extra = " |
| 447 | 447 | AND p.ID = {$id_post}"; |
| 448 | 448 | $s = ''; |
| 449 | 449 | } |
| 450 | 450 | $true = true; |
| 451 | - if ( $true ) { // FOUND_ROWS incompatibilities ? |
|
| 451 | + if ($true) { // FOUND_ROWS incompatibilities ? |
|
| 452 | 452 | $items_count = $wpdb->prepare( |
| 453 | 453 | "SELECT COUNT(*) |
| 454 | 454 | FROM {$wpdb->posts} p |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | $wpsdb_values_text = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; |
| 471 | 471 | $wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; |
| 472 | 472 | $extra_select = ''; |
| 473 | - if ( ! in_array( $orderby, array( 'p.post_date', 'title', 'ID' ), true ) ) { |
|
| 473 | + if (!in_array($orderby, array('p.post_date', 'title', 'ID'), true)) { |
|
| 474 | 474 | $extra_select = "GROUP_CONCAT( ( SELECT IFNULL( val_dec1.value, |
| 475 | 475 | IFNULL( val_dat1.value, |
| 476 | 476 | IFNULL( val_tex1.value, |
@@ -491,15 +491,15 @@ discard block |
||
| 491 | 491 | LEFT JOIN {$wpsdb_values_varchar} val_var1 ON val_var1.attribute_id = attr1.id AND val_var1.entity_id = p1.ID |
| 492 | 492 | LEFT JOIN {$wpsdb_values_options} val_opt1 ON val_opt1.attribute_id = attr1.id AND val_opt1.id = val_int1.value |
| 493 | 493 | WHERE p1.ID = p.ID ) SEPARATOR ' ' )"; |
| 494 | - print_r( $extra_select ); |
|
| 495 | - if ( ! empty( $cast ) ) { |
|
| 494 | + print_r($extra_select); |
|
| 495 | + if (!empty($cast)) { |
|
| 496 | 496 | $extra_select = "CAST( {$extra_select} AS {$cast} )"; |
| 497 | 497 | } |
| 498 | 498 | $extra_select = ", |
| 499 | 499 | {$extra_select} AS {$orderby}"; |
| 500 | 500 | } |
| 501 | 501 | $wpdb->query( |
| 502 | - $wpdb->prepare( 'SET SESSION group_concat_max_len = %d', 1000000 ) |
|
| 502 | + $wpdb->prepare('SET SESSION group_concat_max_len = %d', 1000000) |
|
| 503 | 503 | ); |
| 504 | 504 | $datas = $wpdb->get_results( |
| 505 | 505 | $wpdb->prepare( |
@@ -555,23 +555,23 @@ discard block |
||
| 555 | 555 | $this->request_current_view(), |
| 556 | 556 | $this->entity_id, |
| 557 | 557 | '%' . $s . '%', |
| 558 | - ( $this->get_pagenum() -1 ) * $per_page, |
|
| 558 | + ($this->get_pagenum() - 1) * $per_page, |
|
| 559 | 559 | $per_page |
| 560 | 560 | ), |
| 561 | 561 | ARRAY_A |
| 562 | 562 | ); |
| 563 | - if ( ! is_array( $datas ) ) { |
|
| 563 | + if (!is_array($datas)) { |
|
| 564 | 564 | $datas = array(); |
| 565 | 565 | } |
| 566 | - if ( ! isset( $this->_pagination_args['total_items'] ) && ! isset( $this->_pagination_args['per_page'] ) ) { |
|
| 566 | + if (!isset($this->_pagination_args['total_items']) && !isset($this->_pagination_args['per_page'])) { |
|
| 567 | 567 | $this->set_pagination_args( |
| 568 | 568 | array( |
| 569 | - 'total_items' => (int) $wpdb->get_var( $items_count ), |
|
| 570 | - 'per_page' => $this->get_items_per_page( $this->screen->get_option( 'per_page', 'option' ) ), |
|
| 569 | + 'total_items' => (int)$wpdb->get_var($items_count), |
|
| 570 | + 'per_page' => $this->get_items_per_page($this->screen->get_option('per_page', 'option')), |
|
| 571 | 571 | ) |
| 572 | 572 | ); |
| 573 | 573 | } |
| 574 | - return array_map( array( $this, 'data_reorganize' ), $datas ); |
|
| 574 | + return array_map(array($this, 'data_reorganize'), $datas); |
|
| 575 | 575 | } |
| 576 | 576 | /** |
| 577 | 577 | * Main function to call before display WP_List_Table. See parent class. |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @return void Same results as request() but id as key. |
| 581 | 581 | */ |
| 582 | 582 | public function prepare_items() { |
| 583 | - foreach ( $this->request() as $item ) { |
|
| 584 | - $this->items[ $item['ID'] ] = $item; |
|
| 583 | + foreach ($this->request() as $item) { |
|
| 584 | + $this->items[$item['ID']] = $item; |
|
| 585 | 585 | } |
| 586 | 586 | } |
| 587 | 587 | /** |
@@ -591,20 +591,20 @@ discard block |
||
| 591 | 591 | * @param string $column_key Current column. |
| 592 | 592 | * @return string |
| 593 | 593 | */ |
| 594 | - public function cast_column( $column_key ) { |
|
| 594 | + public function cast_column($column_key) { |
|
| 595 | 595 | $columns_items = $this->request_items_columns(); |
| 596 | - if ( isset( $columns_items[ $column_key ] ) ) { |
|
| 597 | - $cast = $columns_items[ $column_key ]['data']; |
|
| 598 | - if ( in_array( $cast, array( 'varchar', 'text' ), true ) ) { |
|
| 596 | + if (isset($columns_items[$column_key])) { |
|
| 597 | + $cast = $columns_items[$column_key]['data']; |
|
| 598 | + if (in_array($cast, array('varchar', 'text'), true)) { |
|
| 599 | 599 | $cast = 'char'; |
| 600 | 600 | } |
| 601 | - if ( 'tx_tva' === $column_key ) { |
|
| 601 | + if ('tx_tva' === $column_key) { |
|
| 602 | 602 | return 'decimal'; |
| 603 | 603 | } |
| 604 | - if ( 'integer' === $cast && 'select' === $columns_items[ $column_key ]['type'] ) { |
|
| 604 | + if ('integer' === $cast && 'select' === $columns_items[$column_key]['type']) { |
|
| 605 | 605 | return null; |
| 606 | 606 | } |
| 607 | - if ( 'integer' === $cast && 'multiple-select' === $columns_items[ $column_key ]['type'] ) { |
|
| 607 | + if ('integer' === $cast && 'multiple-select' === $columns_items[$column_key]['type']) { |
|
| 608 | 608 | return null; |
| 609 | 609 | } |
| 610 | 610 | return $cast; |
@@ -618,12 +618,12 @@ discard block |
||
| 618 | 618 | * @param array $item Result of sql query. |
| 619 | 619 | * @return array Item reorganized. |
| 620 | 620 | */ |
| 621 | - public function data_reorganize( $item ) { |
|
| 622 | - $values = explode( ';', $item['data'] ); |
|
| 623 | - foreach ( $values as $value ) { |
|
| 624 | - $value = explode( ':', $value ); |
|
| 625 | - if ( ! isset( $this->columns_items[ $value[1] ] ) ) { |
|
| 626 | - $this->columns_items[ $value[1] ] = array( |
|
| 621 | + public function data_reorganize($item) { |
|
| 622 | + $values = explode(';', $item['data']); |
|
| 623 | + foreach ($values as $value) { |
|
| 624 | + $value = explode(':', $value); |
|
| 625 | + if (!isset($this->columns_items[$value[1]])) { |
|
| 626 | + $this->columns_items[$value[1]] = array( |
|
| 627 | 627 | 'id' => $value[0], |
| 628 | 628 | 'code' => $value[1], |
| 629 | 629 | 'name' => $value[2], |
@@ -631,32 +631,32 @@ discard block |
||
| 631 | 631 | 'data' => $value[7], |
| 632 | 632 | ); |
| 633 | 633 | } |
| 634 | - if ( 'yes' === $value[4] ) { |
|
| 635 | - if ( isset( $item[ $value[1] ]['value'] ) ) { |
|
| 636 | - if ( is_array( $item[ $value[1] ]['value'] ) ) { |
|
| 637 | - $item[ $value[1] ]['value'][] = $value[3]; |
|
| 634 | + if ('yes' === $value[4]) { |
|
| 635 | + if (isset($item[$value[1]]['value'])) { |
|
| 636 | + if (is_array($item[$value[1]]['value'])) { |
|
| 637 | + $item[$value[1]]['value'][] = $value[3]; |
|
| 638 | 638 | } else { |
| 639 | - $item[ $value[1] ]['value'] = array( $item[ $value[1] ]['value'], $value[3] ); |
|
| 639 | + $item[$value[1]]['value'] = array($item[$value[1]]['value'], $value[3]); |
|
| 640 | 640 | } |
| 641 | 641 | } else { |
| 642 | - $item[ $value[1] ] = array( |
|
| 642 | + $item[$value[1]] = array( |
|
| 643 | 643 | 'value' => $value[3], |
| 644 | 644 | 'unit' => $value[5], |
| 645 | 645 | ); |
| 646 | 646 | } |
| 647 | 647 | } else { |
| 648 | - if ( isset( $item[ $value[1] ] ) ) { |
|
| 649 | - if ( is_array( $item[ $value[1] ] ) ) { |
|
| 650 | - $item[ $value[1] ][] = $value[3]; |
|
| 651 | - } elseif ( $item[ $value[1] ] !== $value[3] ) { |
|
| 652 | - $item[ $value[1] ] = array( $item[ $value[1] ], $value[3] ); |
|
| 648 | + if (isset($item[$value[1]])) { |
|
| 649 | + if (is_array($item[$value[1]])) { |
|
| 650 | + $item[$value[1]][] = $value[3]; |
|
| 651 | + } elseif ($item[$value[1]] !== $value[3]) { |
|
| 652 | + $item[$value[1]] = array($item[$value[1]], $value[3]); |
|
| 653 | 653 | } |
| 654 | 654 | } else { |
| 655 | - $item[ $value[1] ] = $value[3]; |
|
| 655 | + $item[$value[1]] = $value[3]; |
|
| 656 | 656 | } |
| 657 | 657 | } |
| 658 | 658 | }// End foreach(). |
| 659 | - unset( $item['data'] ); |
|
| 659 | + unset($item['data']); |
|
| 660 | 660 | return $item; |
| 661 | 661 | } |
| 662 | 662 | /** |
@@ -666,11 +666,11 @@ discard block |
||
| 666 | 666 | * @param int $attribute_id Attribute ID. |
| 667 | 667 | * @return array |
| 668 | 668 | */ |
| 669 | - public function get_select_items_option( $attribute_id ) { |
|
| 670 | - if ( ! isset( self::$wpsdb_values_options[ $attribute_id ] ) ) { |
|
| 669 | + public function get_select_items_option($attribute_id) { |
|
| 670 | + if (!isset(self::$wpsdb_values_options[$attribute_id])) { |
|
| 671 | 671 | global $wpdb; |
| 672 | 672 | $wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; |
| 673 | - self::$wpsdb_values_options[ $attribute_id ] = $wpdb->get_results( |
|
| 673 | + self::$wpsdb_values_options[$attribute_id] = $wpdb->get_results( |
|
| 674 | 674 | $wpdb->prepare( |
| 675 | 675 | "SELECT * |
| 676 | 676 | FROM {$wpsdb_values_options} |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | ARRAY_A |
| 682 | 682 | ); |
| 683 | 683 | } |
| 684 | - return self::$wpsdb_values_options[ $attribute_id ]; |
|
| 684 | + return self::$wpsdb_values_options[$attribute_id]; |
|
| 685 | 685 | } |
| 686 | 686 | /** |
| 687 | 687 | * Get all views available. |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | public function request_views() { |
| 693 | 693 | global $wpdb; |
| 694 | - if ( is_null( $this->_views ) ) { |
|
| 694 | + if (is_null($this->_views)) { |
|
| 695 | 695 | $wpsdb_sets = WPSHOP_DBT_ATTRIBUTE_SET; |
| 696 | 696 | $include_states = array( |
| 697 | 697 | 'publish', |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | 'trash', |
| 703 | 703 | 'scheduled', |
| 704 | 704 | ); |
| 705 | - $include_states = implode( "','", $include_states ); |
|
| 706 | - $post_types = implode( "','", $this->_post_types ); |
|
| 705 | + $include_states = implode("','", $include_states); |
|
| 706 | + $post_types = implode("','", $this->_post_types); |
|
| 707 | 707 | $this->_views = $wpdb->get_results( |
| 708 | 708 | $wpdb->prepare( |
| 709 | 709 | "SELECT s.id, name, slug, default_set, COUNT(p.ID) AS count |
@@ -729,9 +729,9 @@ discard block |
||
| 729 | 729 | * @return [type] [description] |
| 730 | 730 | */ |
| 731 | 731 | public function request_current_view() { |
| 732 | - if ( is_null( $this->current_view ) ) { |
|
| 733 | - foreach ( $this->request_views() as $view ) { |
|
| 734 | - if ( filter_var( $view['default_set'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 732 | + if (is_null($this->current_view)) { |
|
| 733 | + foreach ($this->request_views() as $view) { |
|
| 734 | + if (filter_var($view['default_set'], FILTER_VALIDATE_BOOLEAN)) { |
|
| 735 | 735 | $this->current_view = $view['id']; |
| 736 | 736 | } |
| 737 | 737 | } |
@@ -745,12 +745,12 @@ discard block |
||
| 745 | 745 | * @return array See :754 order columns. |
| 746 | 746 | */ |
| 747 | 747 | public function request_items_columns() { |
| 748 | - if ( empty( $this->columns_items ) ) { |
|
| 748 | + if (empty($this->columns_items)) { |
|
| 749 | 749 | global $wpdb; |
| 750 | 750 | $wpsdb_attribute = WPSHOP_DBT_ATTRIBUTE; |
| 751 | 751 | $wpsdb_attribute_set = WPSHOP_DBT_ATTRIBUTE_DETAILS; |
| 752 | - $exclude_attribute_codes = implode( "','", $this->exclude_attribute_codes ); |
|
| 753 | - foreach ( $wpdb->get_results( |
|
| 752 | + $exclude_attribute_codes = implode("','", $this->exclude_attribute_codes); |
|
| 753 | + foreach ($wpdb->get_results( |
|
| 754 | 754 | $wpdb->prepare( |
| 755 | 755 | "SELECT attr.id, attr.code, attr.frontend_label AS name, attr.backend_input AS type, attr.data_type AS data |
| 756 | 756 | FROM {$wpsdb_attribute} attr |
@@ -764,11 +764,11 @@ discard block |
||
| 764 | 764 | $this->entity_id |
| 765 | 765 | ), |
| 766 | 766 | ARRAY_A |
| 767 | - ) as $column ) { |
|
| 768 | - $this->columns_items[ $column['code'] ] = $column; |
|
| 767 | + ) as $column) { |
|
| 768 | + $this->columns_items[$column['code']] = $column; |
|
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | - ksort( $this->columns_items ); |
|
| 771 | + ksort($this->columns_items); |
|
| 772 | 772 | return $this->columns_items; |
| 773 | 773 | } |
| 774 | 774 | /** |
@@ -779,9 +779,9 @@ discard block |
||
| 779 | 779 | */ |
| 780 | 780 | public function get_views() { |
| 781 | 781 | $result = array(); |
| 782 | - foreach ( $this->request_views() as $view ) { |
|
| 782 | + foreach ($this->request_views() as $view) { |
|
| 783 | 783 | $class = ''; |
| 784 | - if ( (int) $view['id'] === (int) $this->request_current_view() ) { |
|
| 784 | + if ((int)$view['id'] === (int)$this->request_current_view()) { |
|
| 785 | 785 | $class = ' class="current"'; |
| 786 | 786 | } |
| 787 | 787 | $link = add_query_arg( |
@@ -790,17 +790,17 @@ discard block |
||
| 790 | 790 | str_replace( |
| 791 | 791 | "{$this->screen->post_type}_page_", |
| 792 | 792 | '', |
| 793 | - substr( $this->screen->id, 0, strpos( $this->screen->id, '_att_set_' ) ) . '_att_set_' . $view['id'] |
|
| 793 | + substr($this->screen->id, 0, strpos($this->screen->id, '_att_set_')) . '_att_set_' . $view['id'] |
|
| 794 | 794 | ), |
| 795 | 795 | ) |
| 796 | 796 | ); |
| 797 | - $link = remove_query_arg( 'paged', $link ); |
|
| 798 | - $result[ $view['id'] ] = sprintf( |
|
| 797 | + $link = remove_query_arg('paged', $link); |
|
| 798 | + $result[$view['id']] = sprintf( |
|
| 799 | 799 | '<a href="%s"%s>%s <span class="count">(%s)</span></a>', |
| 800 | - esc_url( $link ), |
|
| 800 | + esc_url($link), |
|
| 801 | 801 | $class, |
| 802 | 802 | $view['name'], |
| 803 | - number_format_i18n( $view['count'] ) |
|
| 803 | + number_format_i18n($view['count']) |
|
| 804 | 804 | ); |
| 805 | 805 | } |
| 806 | 806 | return $result; |
@@ -812,10 +812,10 @@ discard block |
||
| 812 | 812 | * @param string $which Can be top or bottom. |
| 813 | 813 | * @return void Direct display. |
| 814 | 814 | */ |
| 815 | - public function bulk_actions( $which = '' ) { |
|
| 816 | - submit_button( __( 'Save changes', 'wpshop' ), 'bulk-save', 'bulk-save', false, array( |
|
| 817 | - 'data-nonce' => wp_create_nonce( 'bulk-save-' . $this->hook ), |
|
| 818 | - ) ); |
|
| 815 | + public function bulk_actions($which = '') { |
|
| 816 | + submit_button(__('Save changes', 'wpshop'), 'bulk-save', 'bulk-save', false, array( |
|
| 817 | + 'data-nonce' => wp_create_nonce('bulk-save-' . $this->hook), |
|
| 818 | + )); |
|
| 819 | 819 | ?><span class="spinner"></span><?php |
| 820 | 820 | } |
| 821 | 821 | /** |
@@ -829,30 +829,30 @@ discard block |
||
| 829 | 829 | * @param array $rows List of rows always traited. |
| 830 | 830 | * @return void |
| 831 | 831 | */ |
| 832 | - private function _display_row( &$lvl, $item_id, $item, &$rows ) { |
|
| 833 | - if ( array_key_exists( $item_id, $rows ) ) { |
|
| 832 | + private function _display_row(&$lvl, $item_id, $item, &$rows) { |
|
| 833 | + if (array_key_exists($item_id, $rows)) { |
|
| 834 | 834 | return; |
| 835 | 835 | } |
| 836 | - if ( ! array_key_exists( $item['parent'], $this->items ) && 0 !== (int) $item['parent'] ) { |
|
| 837 | - $parent_item = $this->request( $item['parent'] ); |
|
| 838 | - $this->items[ $item['parent'] ] = $parent_item[0]; |
|
| 836 | + if (!array_key_exists($item['parent'], $this->items) && 0 !== (int)$item['parent']) { |
|
| 837 | + $parent_item = $this->request($item['parent']); |
|
| 838 | + $this->items[$item['parent']] = $parent_item[0]; |
|
| 839 | 839 | } |
| 840 | - if ( array_key_exists( $item['parent'], $rows ) ) { |
|
| 841 | - $offset = array_search( $item['parent'], array_keys( $rows ), true ); |
|
| 842 | - $rows_a = array_slice( $rows, $offset, null, true ); |
|
| 843 | - $rows_a[ $item_id ] = $item; |
|
| 844 | - $rows_b = array_slice( $rows, 0, $offset, true ); |
|
| 845 | - $rows = array_replace( $rows_a, $rows_b ); |
|
| 840 | + if (array_key_exists($item['parent'], $rows)) { |
|
| 841 | + $offset = array_search($item['parent'], array_keys($rows), true); |
|
| 842 | + $rows_a = array_slice($rows, $offset, null, true); |
|
| 843 | + $rows_a[$item_id] = $item; |
|
| 844 | + $rows_b = array_slice($rows, 0, $offset, true); |
|
| 845 | + $rows = array_replace($rows_a, $rows_b); |
|
| 846 | 846 | // $rows = $rows_a + $rows_b; FASTER ? |
| 847 | 847 | $lvl++; |
| 848 | - } elseif ( 0 !== (int) $item['parent'] ) { |
|
| 849 | - $this->_display_row( $lvl, $item['parent'], $this->items[ $item['parent'] ], $rows ); |
|
| 848 | + } elseif (0 !== (int)$item['parent']) { |
|
| 849 | + $this->_display_row($lvl, $item['parent'], $this->items[$item['parent']], $rows); |
|
| 850 | 850 | $lvl++; |
| 851 | 851 | } |
| 852 | - if ( ! empty( $item ) ) { |
|
| 853 | - $item['lvl'] = str_repeat( '— ', $lvl ); |
|
| 852 | + if (!empty($item)) { |
|
| 853 | + $item['lvl'] = str_repeat('— ', $lvl); |
|
| 854 | 854 | } |
| 855 | - $rows[ $item_id ] = $item; |
|
| 855 | + $rows[$item_id] = $item; |
|
| 856 | 856 | } |
| 857 | 857 | /** |
| 858 | 858 | * See WP_List_Table. |
@@ -862,13 +862,13 @@ discard block |
||
| 862 | 862 | */ |
| 863 | 863 | public function display_rows() { |
| 864 | 864 | $rows = array(); |
| 865 | - foreach ( $this->items as $item_id => $item ) { |
|
| 865 | + foreach ($this->items as $item_id => $item) { |
|
| 866 | 866 | $lvl = 0; |
| 867 | - $this->_display_row( $lvl, $item_id, $item, $rows ); |
|
| 867 | + $this->_display_row($lvl, $item_id, $item, $rows); |
|
| 868 | 868 | } |
| 869 | - foreach ( $rows as $item ) { |
|
| 870 | - if ( ! empty( $item ) ) { |
|
| 871 | - $this->single_row( $item ); |
|
| 869 | + foreach ($rows as $item) { |
|
| 870 | + if (!empty($item)) { |
|
| 871 | + $this->single_row($item); |
|
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | } |
@@ -889,52 +889,52 @@ discard block |
||
| 889 | 889 | * @param boolean $with_id See wp_list_table::print_column_headers. |
| 890 | 890 | * @return void Direct display. |
| 891 | 891 | */ |
| 892 | - public function print_column_headers( $with_id = true ) { |
|
| 893 | - list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
|
| 892 | + public function print_column_headers($with_id = true) { |
|
| 893 | + list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
| 894 | 894 | |
| 895 | - $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
| 896 | - $current_url = remove_query_arg( 'paged', $current_url ); |
|
| 895 | + $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
|
| 896 | + $current_url = remove_query_arg('paged', $current_url); |
|
| 897 | 897 | |
| 898 | - if ( isset( $_GET['orderby'] ) ) { // WPCS: CSRF ok. |
|
| 898 | + if (isset($_GET['orderby'])) { // WPCS: CSRF ok. |
|
| 899 | 899 | $current_orderby = $_GET['orderby']; // WPCS: CSRF ok. |
| 900 | 900 | } else { |
| 901 | 901 | $current_orderby = ''; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) { // WPCS: CSRF ok. |
|
| 904 | + if (isset($_GET['order']) && 'desc' === $_GET['order']) { // WPCS: CSRF ok. |
|
| 905 | 905 | $current_order = 'desc'; |
| 906 | 906 | } else { |
| 907 | 907 | $current_order = 'asc'; |
| 908 | 908 | } |
| 909 | 909 | |
| 910 | - if ( ! empty( $columns['cb'] ) ) { |
|
| 910 | + if (!empty($columns['cb'])) { |
|
| 911 | 911 | static $cb_counter = 1; |
| 912 | - $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>' |
|
| 912 | + $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>' |
|
| 913 | 913 | . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />'; |
| 914 | 914 | $cb_counter++; |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - foreach ( $columns as $column_key => $column_display_name ) { |
|
| 918 | - $class = array( 'manage-column', "column-$column_key" ); |
|
| 917 | + foreach ($columns as $column_key => $column_display_name) { |
|
| 918 | + $class = array('manage-column', "column-$column_key"); |
|
| 919 | 919 | |
| 920 | - if ( in_array( $column_key, $hidden, true ) ) { |
|
| 920 | + if (in_array($column_key, $hidden, true)) { |
|
| 921 | 921 | $class[] = 'hidden'; |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | - if ( 'cb' === $column_key ) { |
|
| 924 | + if ('cb' === $column_key) { |
|
| 925 | 925 | $class[] = 'check-column'; |
| 926 | - } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) { |
|
| 926 | + } elseif (in_array($column_key, array('posts', 'comments', 'links'), true)) { |
|
| 927 | 927 | $class[] = 'num'; |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | - if ( $column_key === $primary ) { |
|
| 930 | + if ($column_key === $primary) { |
|
| 931 | 931 | $class[] = 'column-primary'; |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | - if ( isset( $sortable[ $column_key ] ) ) { |
|
| 935 | - list( $orderby, $desc_first ) = $sortable[ $column_key ]; |
|
| 934 | + if (isset($sortable[$column_key])) { |
|
| 935 | + list($orderby, $desc_first) = $sortable[$column_key]; |
|
| 936 | 936 | |
| 937 | - if ( $current_orderby === $orderby ) { |
|
| 937 | + if ($current_orderby === $orderby) { |
|
| 938 | 938 | $order = 'asc' === $current_order ? 'desc' : 'asc'; |
| 939 | 939 | $class[] = 'sorted'; |
| 940 | 940 | $class[] = $current_order; |
@@ -944,17 +944,17 @@ discard block |
||
| 944 | 944 | $class[] = $desc_first ? 'asc' : 'desc'; |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | - $cast = $this->cast_column( $column_key ); |
|
| 947 | + $cast = $this->cast_column($column_key); |
|
| 948 | 948 | |
| 949 | - $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order', 'cast' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>'; |
|
| 949 | + $column_display_name = '<a href="' . esc_url(add_query_arg(compact('orderby', 'order', 'cast'), $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>'; |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; |
|
| 953 | - $scope = ( 'th' === $tag ) ? 'scope="col"' : ''; |
|
| 952 | + $tag = ('cb' === $column_key) ? 'td' : 'th'; |
|
| 953 | + $scope = ('th' === $tag) ? 'scope="col"' : ''; |
|
| 954 | 954 | $id = $with_id ? "id='$column_key'" : ''; |
| 955 | 955 | |
| 956 | - if ( ! empty( $class ) ) { |
|
| 957 | - $class = "class='" . join( ' ', $class ) . "'"; |
|
| 956 | + if (!empty($class)) { |
|
| 957 | + $class = "class='" . join(' ', $class) . "'"; |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | echo "<$tag $scope $id $class>$column_display_name</$tag>"; // WPCS: XSS ok. |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * @package wps-mass-interface3 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | +if (!defined('ABSPATH')) { |
|
| 9 | 9 | exit; |
| 10 | 10 | } |
| 11 | 11 | /** |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | * @method __construct |
| 63 | 63 | */ |
| 64 | 64 | public function __construct() { |
| 65 | - add_action( 'admin_menu', array( $this, 'mass_init' ), 350 ); |
|
| 66 | - add_action( 'wp_ajax_wps_mass_3_new', array( $this, 'ajax_new' ) ); |
|
| 67 | - add_action( 'wp_ajax_wps_mass_3_save', array( $this, 'ajax_save' ) ); |
|
| 68 | - add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 ); |
|
| 65 | + add_action('admin_menu', array($this, 'mass_init'), 350); |
|
| 66 | + add_action('wp_ajax_wps_mass_3_new', array($this, 'ajax_new')); |
|
| 67 | + add_action('wp_ajax_wps_mass_3_save', array($this, 'ajax_save')); |
|
| 68 | + add_filter('set-screen-option', array($this, 'set_screen_option'), 10, 3); |
|
| 69 | 69 | } |
| 70 | 70 | /** |
| 71 | 71 | * Page Initialisation |
@@ -74,18 +74,18 @@ discard block |
||
| 74 | 74 | * @return void |
| 75 | 75 | */ |
| 76 | 76 | public function mass_init() { |
| 77 | - $page = ( isset( $_GET['page'] ) && strpos( $_GET['page'] , 'mass_edit_interface3_att_set_' ) !== false ) ? $_GET['page'] : 'mass_edit_interface3_att_set_1'; |
|
| 77 | + $page = (isset($_GET['page']) && strpos($_GET['page'], 'mass_edit_interface3_att_set_') !== false) ? $_GET['page'] : 'mass_edit_interface3_att_set_1'; |
|
| 78 | 78 | $this->hook = add_submenu_page( |
| 79 | 79 | 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
| 80 | - __( 'Mass product edit', 'wpshop' ), |
|
| 81 | - __( 'Mass product edit', 'wpshop' ), |
|
| 80 | + __('Mass product edit', 'wpshop'), |
|
| 81 | + __('Mass product edit', 'wpshop'), |
|
| 82 | 82 | 'manage_options', |
| 83 | 83 | $page, |
| 84 | - array( $this, 'mass_interface' ) |
|
| 84 | + array($this, 'mass_interface') |
|
| 85 | 85 | ); |
| 86 | - add_action( "load-{$this->hook}", array( $this, 'mass_interface_screen_option' ) ); |
|
| 87 | - add_action( "admin_print_scripts-{$this->hook}", array( $this, 'scripts' ) ); |
|
| 88 | - add_action( "admin_print_styles-{$this->hook}", array( $this, 'styles' ) ); |
|
| 86 | + add_action("load-{$this->hook}", array($this, 'mass_interface_screen_option')); |
|
| 87 | + add_action("admin_print_scripts-{$this->hook}", array($this, 'scripts')); |
|
| 88 | + add_action("admin_print_styles-{$this->hook}", array($this, 'styles')); |
|
| 89 | 89 | } |
| 90 | 90 | /** |
| 91 | 91 | * Page content. |
@@ -94,47 +94,47 @@ discard block |
||
| 94 | 94 | * @return void Direct display. |
| 95 | 95 | */ |
| 96 | 96 | public function mass_interface() { |
| 97 | - $wp_list_table = $this->wp_list_table( $this->hook ); |
|
| 97 | + $wp_list_table = $this->wp_list_table($this->hook); |
|
| 98 | 98 | $wp_list_table->prepare_items(); ?> |
| 99 | 99 | <div class="wrap"> |
| 100 | 100 | <h1 class="wp-heading-inline"><?php |
| 101 | - echo esc_html( $this->post_type_object->labels->name ); |
|
| 101 | + echo esc_html($this->post_type_object->labels->name); |
|
| 102 | 102 | ?></h1> |
| 103 | 103 | <?php |
| 104 | - if ( current_user_can( $this->post_type_object->cap->create_posts ) ) { |
|
| 105 | - echo ' <a href="#addPost" class="page-title-action" data-nonce="' . esc_attr( wp_create_nonce( 'add_post-' . $this->hook ) ) . '">'; |
|
| 106 | - echo esc_html( $this->post_type_object->labels->add_new ) . '</a>'; |
|
| 104 | + if (current_user_can($this->post_type_object->cap->create_posts)) { |
|
| 105 | + echo ' <a href="#addPost" class="page-title-action" data-nonce="' . esc_attr(wp_create_nonce('add_post-' . $this->hook)) . '">'; |
|
| 106 | + echo esc_html($this->post_type_object->labels->add_new) . '</a>'; |
|
| 107 | 107 | } |
| 108 | 108 | ?> |
| 109 | 109 | <hr class="wp-header-end"> |
| 110 | 110 | <form id="posts-filter" method="get"> |
| 111 | 111 | <?php $wp_list_table->views(); ?> |
| 112 | - <?php $wp_list_table->search_box( $this->post_type_object->labels->search_items, 'post' ); ?> |
|
| 112 | + <?php $wp_list_table->search_box($this->post_type_object->labels->search_items, 'post'); ?> |
|
| 113 | 113 | <input type="hidden" name="page" value="<?php |
| 114 | - echo esc_attr( str_replace( |
|
| 114 | + echo esc_attr(str_replace( |
|
| 115 | 115 | "{$wp_list_table->screen->post_type}_page_", |
| 116 | 116 | '', |
| 117 | 117 | $wp_list_table->screen->id |
| 118 | - ) ); ?>"> |
|
| 119 | - <input type="hidden" name="post_type" value="<?php echo esc_attr( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); ?>"> |
|
| 118 | + )); ?>"> |
|
| 119 | + <input type="hidden" name="post_type" value="<?php echo esc_attr(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); ?>"> |
|
| 120 | 120 | </form> |
| 121 | 121 | <?php $wp_list_table->display(); ?> |
| 122 | 122 | <table style="display:none;"> |
| 123 | 123 | <tbody id="posts-add"> |
| 124 | - <tr id="inline-edit" class="inline-edit-row inline-edit-row-post <?php echo esc_attr( "inline-edit-{$this->post_type_object->name} quick-edit-row quick-edit-row-post inline-edit-{$this->post_type_object->name}" ); ?>" style="display: none"> |
|
| 125 | - <td colspan="<?php echo esc_attr( $wp_list_table->get_column_count() ); ?>" class="colspanchange"> |
|
| 124 | + <tr id="inline-edit" class="inline-edit-row inline-edit-row-post <?php echo esc_attr("inline-edit-{$this->post_type_object->name} quick-edit-row quick-edit-row-post inline-edit-{$this->post_type_object->name}"); ?>" style="display: none"> |
|
| 125 | + <td colspan="<?php echo esc_attr($wp_list_table->get_column_count()); ?>" class="colspanchange"> |
|
| 126 | 126 | <fieldset class="inline-edit-col"> |
| 127 | - <legend class="inline-edit-legend"><?php echo esc_html( $this->post_type_object->labels->add_new ) ?></legend> |
|
| 127 | + <legend class="inline-edit-legend"><?php echo esc_html($this->post_type_object->labels->add_new) ?></legend> |
|
| 128 | 128 | <div class="inline-edit-col"> |
| 129 | 129 | <label> |
| 130 | - <span class="title"><?php esc_html_e( 'Title' ); ?></span> |
|
| 130 | + <span class="title"><?php esc_html_e('Title'); ?></span> |
|
| 131 | 131 | <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span> |
| 132 | 132 | </label> |
| 133 | 133 | </div> |
| 134 | 134 | </fieldset> |
| 135 | 135 | <p class="submit inline-edit-save"> |
| 136 | - <button type="button" class="button cancel alignleft"><?php esc_html_e( 'Cancel' ); ?></button> |
|
| 137 | - <button type="button" class="button button-primary save alignright"><?php echo esc_html( $this->post_type_object->labels->add_new ); ?></button> |
|
| 136 | + <button type="button" class="button cancel alignleft"><?php esc_html_e('Cancel'); ?></button> |
|
| 137 | + <button type="button" class="button button-primary save alignright"><?php echo esc_html($this->post_type_object->labels->add_new); ?></button> |
|
| 138 | 138 | <span class="spinner"></span> |
| 139 | 139 | <span class="error" style="display:none"></span> |
| 140 | 140 | <br class="clear" /> |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | * @return void |
| 154 | 154 | */ |
| 155 | 155 | public function mass_interface_screen_option() { |
| 156 | - add_action( 'admin_notices', array( $this, 'ajax_admin_notice' ) ); |
|
| 157 | - add_filter( 'default_hidden_columns', array( $this, 'hidden_columns' ), 10, 2 ); |
|
| 158 | - $this->wp_list_table( $this->hook ); |
|
| 156 | + add_action('admin_notices', array($this, 'ajax_admin_notice')); |
|
| 157 | + add_filter('default_hidden_columns', array($this, 'hidden_columns'), 10, 2); |
|
| 158 | + $this->wp_list_table($this->hook); |
|
| 159 | 159 | } |
| 160 | 160 | /** |
| 161 | 161 | * Instance WPS_Mass_List_Table. |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @param string $screen Current screen. |
| 165 | 165 | * @return WPS_Mass_List_Table Table class. |
| 166 | 166 | */ |
| 167 | - public function wp_list_table( $screen ) { |
|
| 168 | - if ( is_null( $this->wp_list_table ) ) { |
|
| 169 | - $this->post_type_object = get_post_type_object( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 170 | - include_once( WPS_PDCT_MASS_INCLUDE_PATH . 'class-wps-mass-list-table.php' ); |
|
| 167 | + public function wp_list_table($screen) { |
|
| 168 | + if (is_null($this->wp_list_table)) { |
|
| 169 | + $this->post_type_object = get_post_type_object(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 170 | + include_once(WPS_PDCT_MASS_INCLUDE_PATH . 'class-wps-mass-list-table.php'); |
|
| 171 | 171 | $this->wp_list_table = new WPS_Mass_List_Table( |
| 172 | 172 | array( |
| 173 | 173 | 'screen' => $screen, |
@@ -199,10 +199,10 @@ discard block |
||
| 199 | 199 | * @param WP_Screen $screen Current screen. |
| 200 | 200 | * @return array Return of filter. |
| 201 | 201 | */ |
| 202 | - public function hidden_columns( $hidden, $screen ) { |
|
| 203 | - $wp_list_table = $this->wp_list_table( $this->hook ); |
|
| 204 | - if ( $screen === $wp_list_table->screen ) { |
|
| 205 | - $hidden = array_diff( array_flip( $wp_list_table->get_columns() ), $this->default_show_columns ); |
|
| 202 | + public function hidden_columns($hidden, $screen) { |
|
| 203 | + $wp_list_table = $this->wp_list_table($this->hook); |
|
| 204 | + if ($screen === $wp_list_table->screen) { |
|
| 205 | + $hidden = array_diff(array_flip($wp_list_table->get_columns()), $this->default_show_columns); |
|
| 206 | 206 | $hidden[] = 'thumbnail'; |
| 207 | 207 | } |
| 208 | 208 | return $hidden; |
@@ -215,11 +215,11 @@ discard block |
||
| 215 | 215 | * @param string $option Actual option to save. |
| 216 | 216 | * @param mixed $value Actual value to save. |
| 217 | 217 | */ |
| 218 | - public function set_screen_option( $string, $option, $value ) { |
|
| 218 | + public function set_screen_option($string, $option, $value) { |
|
| 219 | 219 | $class = get_class(); |
| 220 | - if ( "{$class}_per_page" === $option ) { |
|
| 221 | - $value = (int) $value; |
|
| 222 | - if ( $value < 1 || $value > 999 ) { |
|
| 220 | + if ("{$class}_per_page" === $option) { |
|
| 221 | + $value = (int)$value; |
|
| 222 | + if ($value < 1 || $value > 999) { |
|
| 223 | 223 | $string = false; |
| 224 | 224 | } |
| 225 | 225 | return $value; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @return void Direct display. |
| 234 | 234 | */ |
| 235 | 235 | public function ajax_admin_notice() { |
| 236 | - printf( '<div class="%1$s"><p></p></div>', esc_attr( 'hidden is-dismissible notice' ) ); |
|
| 236 | + printf('<div class="%1$s"><p></p></div>', esc_attr('hidden is-dismissible notice')); |
|
| 237 | 237 | } |
| 238 | 238 | /** |
| 239 | 239 | * Enqueue scripts. |
@@ -245,13 +245,13 @@ discard block |
||
| 245 | 245 | wp_enqueue_script( |
| 246 | 246 | 'jquery_chosen_js', |
| 247 | 247 | WPS_PDCT_MASS_CHOSEN_JS . 'chosen.jquery.min.js', |
| 248 | - array( 'jquery' ), |
|
| 248 | + array('jquery'), |
|
| 249 | 249 | true |
| 250 | 250 | ); |
| 251 | 251 | wp_enqueue_script( |
| 252 | 252 | 'mass_interface3-ajax', |
| 253 | 253 | WPS_PDCT_MASS_JS . 'wps-mass-interface3.js', |
| 254 | - array( 'jquery', 'jquery-form' ), |
|
| 254 | + array('jquery', 'jquery-form'), |
|
| 255 | 255 | true |
| 256 | 256 | ); |
| 257 | 257 | wp_enqueue_media(); |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | * @return void |
| 264 | 264 | */ |
| 265 | 265 | public function styles() { |
| 266 | - wp_register_style( 'jquery_chosen_css', WPS_PDCT_MASS_CHOSEN_CSS . 'chosen.min.css' ); |
|
| 267 | - wp_register_style( 'mass_interface3_css', WPS_PDCT_MASS_CSS . 'wps-mass-interface3.css' ); |
|
| 268 | - wp_enqueue_style( 'jquery_chosen_css' ); |
|
| 269 | - wp_enqueue_style( 'mass_interface3_css' ); |
|
| 270 | - wp_deregister_style( 'wpshop_main_css' ); |
|
| 266 | + wp_register_style('jquery_chosen_css', WPS_PDCT_MASS_CHOSEN_CSS . 'chosen.min.css'); |
|
| 267 | + wp_register_style('mass_interface3_css', WPS_PDCT_MASS_CSS . 'wps-mass-interface3.css'); |
|
| 268 | + wp_enqueue_style('jquery_chosen_css'); |
|
| 269 | + wp_enqueue_style('mass_interface3_css'); |
|
| 270 | + wp_deregister_style('wpshop_main_css'); |
|
| 271 | 271 | } |
| 272 | 272 | /** |
| 273 | 273 | * Ajax callback for new element. |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | * @return void JSON with all elements to update. |
| 277 | 277 | */ |
| 278 | 278 | public function ajax_new() { |
| 279 | - add_filter( 'default_hidden_columns', array( $this, 'hidden_columns' ), 10, 2 ); |
|
| 280 | - $wp_list_table = $this->wp_list_table( $_POST['screen'] ); |
|
| 279 | + add_filter('default_hidden_columns', array($this, 'hidden_columns'), 10, 2); |
|
| 280 | + $wp_list_table = $this->wp_list_table($_POST['screen']); |
|
| 281 | 281 | $wpshop_product_attribute = array(); |
| 282 | - foreach ( $wp_list_table->request_items_columns() as $key_var => $var ) { |
|
| 283 | - $wpshop_product_attribute[ $var['data'] ][ $key_var ] = null; |
|
| 282 | + foreach ($wp_list_table->request_items_columns() as $key_var => $var) { |
|
| 283 | + $wpshop_product_attribute[$var['data']][$key_var] = null; |
|
| 284 | 284 | } |
| 285 | 285 | $new_product_id = wp_insert_post( |
| 286 | 286 | array( |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | 'post_title' => $_POST['title'], |
| 290 | 290 | ) |
| 291 | 291 | ); |
| 292 | - if ( ! empty( $new_product_id ) ) { |
|
| 293 | - update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $wp_list_table->current_view ); |
|
| 292 | + if (!empty($new_product_id)) { |
|
| 293 | + update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $wp_list_table->current_view); |
|
| 294 | 294 | $product_class = new wpshop_products(); |
| 295 | 295 | $product_class->save_product_custom_informations( |
| 296 | 296 | $new_product_id, array( |
@@ -302,31 +302,31 @@ discard block |
||
| 302 | 302 | ) |
| 303 | 303 | ); |
| 304 | 304 | } else { |
| 305 | - wp_die( 1 ); |
|
| 305 | + wp_die(1); |
|
| 306 | 306 | } |
| 307 | 307 | $class = get_class(); |
| 308 | - $data = $wp_list_table->request( $new_product_id ); |
|
| 309 | - $per_page = $wp_list_table->screen->get_option( 'per_page', 'option' ); |
|
| 308 | + $data = $wp_list_table->request($new_product_id); |
|
| 309 | + $per_page = $wp_list_table->screen->get_option('per_page', 'option'); |
|
| 310 | 310 | $wp_list_table->column_headers(); |
| 311 | 311 | $wp_list_table->items = true; |
| 312 | 312 | ob_start(); |
| 313 | 313 | $wp_list_table->views(); |
| 314 | 314 | $subsubsub = ob_get_clean(); |
| 315 | 315 | ob_start(); |
| 316 | - $wp_list_table->display_tablenav( 'top' ); |
|
| 316 | + $wp_list_table->display_tablenav('top'); |
|
| 317 | 317 | $tablenav_top = ob_get_clean(); |
| 318 | 318 | ob_start(); |
| 319 | - $wp_list_table->display_tablenav( 'bottom' ); |
|
| 319 | + $wp_list_table->display_tablenav('bottom'); |
|
| 320 | 320 | $tablenav_bottom = ob_get_clean(); |
| 321 | 321 | ob_start(); |
| 322 | - $wp_list_table->single_row( $data[0] ); |
|
| 323 | - wp_send_json_success( array( |
|
| 322 | + $wp_list_table->single_row($data[0]); |
|
| 323 | + wp_send_json_success(array( |
|
| 324 | 324 | 'row' => ob_get_clean(), |
| 325 | 325 | 'per_page' => $per_page, |
| 326 | 326 | 'tablenav_top' => $tablenav_top, |
| 327 | 327 | 'tablenav_bottom' => $tablenav_bottom, |
| 328 | 328 | 'subsubsub' => $subsubsub, |
| 329 | - ) ); |
|
| 329 | + )); |
|
| 330 | 330 | } |
| 331 | 331 | /** |
| 332 | 332 | * Ajax callback for save selected elements. |
@@ -337,19 +337,19 @@ discard block |
||
| 337 | 337 | public function ajax_save() { |
| 338 | 338 | $i = 0; |
| 339 | 339 | $product_class = new wpshop_products(); |
| 340 | - if ( ! empty( $_REQUEST['cb'] ) ) { |
|
| 341 | - foreach ( $_REQUEST['cb'] as $id ) { |
|
| 342 | - $id = intval( $id ); |
|
| 343 | - if ( isset( $_REQUEST[ 'row_' . $id ]['thumbnail'] ) ) { |
|
| 344 | - intval( $_REQUEST[ 'row_' . $id ]['thumbnail'] ); |
|
| 345 | - update_post_meta( $id, '_thumbnail_id', intval( $_REQUEST[ 'row_' . $id ]['thumbnail'] ) ); |
|
| 346 | - unset( $_REQUEST[ 'row_' . $id ]['thumbnail'] ); |
|
| 340 | + if (!empty($_REQUEST['cb'])) { |
|
| 341 | + foreach ($_REQUEST['cb'] as $id) { |
|
| 342 | + $id = intval($id); |
|
| 343 | + if (isset($_REQUEST['row_' . $id]['thumbnail'])) { |
|
| 344 | + intval($_REQUEST['row_' . $id]['thumbnail']); |
|
| 345 | + update_post_meta($id, '_thumbnail_id', intval($_REQUEST['row_' . $id]['thumbnail'])); |
|
| 346 | + unset($_REQUEST['row_' . $id]['thumbnail']); |
|
| 347 | 347 | } |
| 348 | - if ( ! empty( $_REQUEST[ 'row_' . $id ] ) ) { |
|
| 348 | + if (!empty($_REQUEST['row_' . $id])) { |
|
| 349 | 349 | $product_class->save_product_custom_informations( |
| 350 | 350 | $id, |
| 351 | 351 | array_merge( |
| 352 | - $_REQUEST[ 'row_' . $id ], |
|
| 352 | + $_REQUEST['row_' . $id], |
|
| 353 | 353 | array( |
| 354 | 354 | 'post_ID' => $id, |
| 355 | 355 | 'product_id' => $id, |
@@ -5,14 +5,14 @@ |
||
| 5 | 5 | * @package wps-mass-interface3 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -DEFINE( 'WPS_PDCT_MASS_VERSION', '3.0' ); |
|
| 9 | -DEFINE( 'WPS_PDCT_MASS_URL', plugin_dir_url( __FILE__ ) ); |
|
| 10 | -DEFINE( 'WPS_PDCT_MASS_INCLUDE_PATH', dirname( __FILE__ ) . '\include\\' ); |
|
| 11 | -DEFINE( 'WPS_PDCT_MASS_INCLUDE_URL', WPS_PDCT_MASS_URL . 'include/' ); |
|
| 12 | -DEFINE( 'WPS_PDCT_MASS_JS', WPS_PDCT_MASS_INCLUDE_URL . 'js/' ); |
|
| 13 | -DEFINE( 'WPS_PDCT_MASS_CSS', WPS_PDCT_MASS_INCLUDE_URL . 'css/' ); |
|
| 14 | -DEFINE( 'WPS_PDCT_MASS_CHOSEN_JS', WPS_PDCT_MASS_JS . 'chosen-v1.7.0/' ); |
|
| 15 | -DEFINE( 'WPS_PDCT_MASS_CHOSEN_CSS', WPS_PDCT_MASS_CSS . 'chosen-v1.7.0/' ); |
|
| 8 | +DEFINE('WPS_PDCT_MASS_VERSION', '3.0'); |
|
| 9 | +DEFINE('WPS_PDCT_MASS_URL', plugin_dir_url(__FILE__)); |
|
| 10 | +DEFINE('WPS_PDCT_MASS_INCLUDE_PATH', dirname(__FILE__) . '\include\\'); |
|
| 11 | +DEFINE('WPS_PDCT_MASS_INCLUDE_URL', WPS_PDCT_MASS_URL . 'include/'); |
|
| 12 | +DEFINE('WPS_PDCT_MASS_JS', WPS_PDCT_MASS_INCLUDE_URL . 'js/'); |
|
| 13 | +DEFINE('WPS_PDCT_MASS_CSS', WPS_PDCT_MASS_INCLUDE_URL . 'css/'); |
|
| 14 | +DEFINE('WPS_PDCT_MASS_CHOSEN_JS', WPS_PDCT_MASS_JS . 'chosen-v1.7.0/'); |
|
| 15 | +DEFINE('WPS_PDCT_MASS_CHOSEN_CSS', WPS_PDCT_MASS_CSS . 'chosen-v1.7.0/'); |
|
| 16 | 16 | |
| 17 | -include_once( WPS_PDCT_MASS_INCLUDE_PATH . 'class-mass-interface3.php' ); |
|
| 17 | +include_once(WPS_PDCT_MASS_INCLUDE_PATH . 'class-mass-interface3.php'); |
|
| 18 | 18 | new mass_interface3(); |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | * Call hooks. |
| 14 | 14 | */ |
| 15 | 15 | public function __construct() { |
| 16 | - add_action( 'init', array( $this, 'init' ) ); |
|
| 17 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 11, 2 ); |
|
| 18 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); |
|
| 19 | - add_filter( 'wpshop_attribute_output_def', array( $this, 'wpshop_attribute_output_def' ), 10, 2 ); |
|
| 16 | + add_action('init', array($this, 'init')); |
|
| 17 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 11, 2); |
|
| 18 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 19 | + add_filter('wpshop_attribute_output_def', array($this, 'wpshop_attribute_output_def'), 10, 2); |
|
| 20 | 20 | } |
| 21 | 21 | /** |
| 22 | 22 | * Call private functions if class is activate. |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | * @param array $arguments Array of arguments to pass. |
| 26 | 26 | * @return mixed Return of real function called. |
| 27 | 27 | */ |
| 28 | - public function __call( $name, $arguments ) { |
|
| 29 | - if ( method_exists( $this, $name ) ) { |
|
| 30 | - if ( $this->is_activate() ) { |
|
| 31 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
| 28 | + public function __call($name, $arguments) { |
|
| 29 | + if (method_exists($this, $name)) { |
|
| 30 | + if ($this->is_activate()) { |
|
| 31 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | 41 | public function init() { |
| 42 | - $_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // Input var okay. |
|
| 43 | - $wps_variation_interface = ! empty( $_GET['wps_variation_interface'] ) ? filter_var( wp_unslash( $_GET['wps_variation_interface'] ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) : null; // Input var okay. |
|
| 44 | - if ( wp_verify_nonce( $_wpnonce, 'wps_remove_variation_interface' ) && null !== $wps_variation_interface ) { |
|
| 45 | - $this->is_activate( $wps_variation_interface ); |
|
| 42 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])) : ''; // Input var okay. |
|
| 43 | + $wps_variation_interface = !empty($_GET['wps_variation_interface']) ? filter_var(wp_unslash($_GET['wps_variation_interface']), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : null; // Input var okay. |
|
| 44 | + if (wp_verify_nonce($_wpnonce, 'wps_remove_variation_interface') && null !== $wps_variation_interface) { |
|
| 45 | + $this->is_activate($wps_variation_interface); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | /** |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | * @param boolean $new_val If set & db is different, save it. |
| 52 | 52 | * @return boolean Actual state of module. |
| 53 | 53 | */ |
| 54 | - public function is_activate( $new_val = null ) { |
|
| 55 | - if ( ! isset( $this->is_active ) ) { |
|
| 56 | - $option = get_option( 'wps_variation_interface_display', null ); |
|
| 57 | - if ( is_null( $option ) ) { |
|
| 54 | + public function is_activate($new_val = null) { |
|
| 55 | + if (!isset($this->is_active)) { |
|
| 56 | + $option = get_option('wps_variation_interface_display', null); |
|
| 57 | + if (is_null($option)) { |
|
| 58 | 58 | $new_val = true; |
| 59 | 59 | $option = false; |
| 60 | 60 | } |
| 61 | - $this->is_active = (bool) $option; |
|
| 61 | + $this->is_active = (bool)$option; |
|
| 62 | 62 | } |
| 63 | - if ( isset( $new_val ) && $this->is_active !== $new_val ) { |
|
| 64 | - update_option( 'wps_variation_interface_display', $new_val ); |
|
| 63 | + if (isset($new_val) && $this->is_active !== $new_val) { |
|
| 64 | + update_option('wps_variation_interface_display', $new_val); |
|
| 65 | 65 | $this->is_active = $new_val; |
| 66 | 66 | } |
| 67 | 67 | return $this->is_active; |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | * @param array $element Direct array attribute of db. |
| 73 | 73 | * @return void It set directly in variable class. |
| 74 | 74 | */ |
| 75 | - private function get_variations( $element ) { |
|
| 76 | - if ( ! isset( $this->variations ) ) { |
|
| 77 | - $variations = wpshop_attributes::get_variation_available_attribute( $element ); |
|
| 78 | - $this->variations = (array) array_merge( ( isset( $variations['available'] ) ? $variations['available'] : array()), ( isset( $variations['unavailable'] ) ? $variations['unavailable'] : array() ) ); |
|
| 79 | - unset( $variations ); |
|
| 75 | + private function get_variations($element) { |
|
| 76 | + if (!isset($this->variations)) { |
|
| 77 | + $variations = wpshop_attributes::get_variation_available_attribute($element); |
|
| 78 | + $this->variations = (array)array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array())); |
|
| 79 | + unset($variations); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | /** |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | * @param string $post_status Generated by WP. |
| 87 | 87 | * @param WP_Post $post Generated by WP. |
| 88 | 88 | */ |
| 89 | - public function add_meta_boxes( $post_status, $post ) { |
|
| 89 | + public function add_meta_boxes($post_status, $post) { |
|
| 90 | 90 | global $pagenow; |
| 91 | - if ( $this->is_activate() ) { |
|
| 92 | - $this->get_variations( $post->ID ); |
|
| 93 | - remove_meta_box( 'wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal' ); |
|
| 94 | - if ( 'post-new.php' !== $pagenow && ! empty( $this->variations ) ) { |
|
| 95 | - add_meta_box( 'wpshop_wpshop_variations', __( 'Product variation', 'wpshop' ), array( $this, 'meta_box_variation' ), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default' ); |
|
| 91 | + if ($this->is_activate()) { |
|
| 92 | + $this->get_variations($post->ID); |
|
| 93 | + remove_meta_box('wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal'); |
|
| 94 | + if ('post-new.php' !== $pagenow && !empty($this->variations)) { |
|
| 95 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array($this, 'meta_box_variation'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -102,59 +102,59 @@ discard block |
||
| 102 | 102 | * @param object $post Given by WordPress. |
| 103 | 103 | * @return void Display directly. |
| 104 | 104 | */ |
| 105 | - private function meta_box_variation( $post ) { |
|
| 106 | - $this->get_variations( $post->ID ); |
|
| 105 | + private function meta_box_variation($post) { |
|
| 106 | + $this->get_variations($post->ID); |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | $ids = array(); |
| 109 | - foreach ( $this->variations as $key => $variation ) { |
|
| 110 | - $available = wpshop_attributes::get_select_output( $variation['attribute_complete_def'] ); |
|
| 111 | - $this->variations[ $key ]['available'] = array_keys( $available['possible_value'] ); |
|
| 112 | - $ids = array_merge( $ids, array_keys( $available['possible_value'] ) ); |
|
| 109 | + foreach ($this->variations as $key => $variation) { |
|
| 110 | + $available = wpshop_attributes::get_select_output($variation['attribute_complete_def']); |
|
| 111 | + $this->variations[$key]['available'] = array_keys($available['possible_value']); |
|
| 112 | + $ids = array_merge($ids, array_keys($available['possible_value'])); |
|
| 113 | 113 | } |
| 114 | - $sql = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id IN (\'' . implode( '\', \'', $ids ) . '\') AND status = %s'; |
|
| 115 | - $query = call_user_func( array( $wpdb, 'prepare' ), $sql, 'valid' ); |
|
| 116 | - $product = wpshop_products::get_product_data( $post->ID, false, '"publish","draft","future","pending"' ); |
|
| 117 | - $is_used_in_variation = wpshop_attributes::getElement( 'yes', "'valid', 'notused'", 'is_used_in_variation', true ); |
|
| 114 | + $sql = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id IN (\'' . implode('\', \'', $ids) . '\') AND status = %s'; |
|
| 115 | + $query = call_user_func(array($wpdb, 'prepare'), $sql, 'valid'); |
|
| 116 | + $product = wpshop_products::get_product_data($post->ID, false, '"publish","draft","future","pending"'); |
|
| 117 | + $is_used_in_variation = wpshop_attributes::getElement('yes', "'valid', 'notused'", 'is_used_in_variation', true); |
|
| 118 | 118 | $attribute_list = array(); |
| 119 | - foreach ( $is_used_in_variation as $attribute ) { |
|
| 120 | - if ( in_array( $attribute->backend_input, array( 'multiple-select', 'select', 'radio', 'checkbox' ), true ) ) { |
|
| 121 | - $values = wpshop_attributes::get_select_output( $attribute ); |
|
| 122 | - if ( ! empty( $values['possible_value'] ) ) { |
|
| 119 | + foreach ($is_used_in_variation as $attribute) { |
|
| 120 | + if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'), true)) { |
|
| 121 | + $values = wpshop_attributes::get_select_output($attribute); |
|
| 122 | + if (!empty($values['possible_value'])) { |
|
| 123 | 123 | $attribute->possible_value = $values['possible_value']; |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | - $attribute_list[ $attribute->code ] = $attribute; |
|
| 126 | + $attribute_list[$attribute->code] = $attribute; |
|
| 127 | 127 | } |
| 128 | - $variation_defining = get_post_meta( $post->ID, '_wpshop_variation_defining', true ); |
|
| 129 | - $variations_saved = wpshop_products::get_variation( $post->ID ); |
|
| 130 | - if ( ! empty( $variations_saved ) ) { |
|
| 131 | - foreach ( $variations_saved as $variation_id => $variation ) { |
|
| 132 | - $downloadable = get_post_meta( $variation_id, 'attribute_option_is_downloadable_', true ); |
|
| 133 | - if ( ! empty( $downloadable['file_url'] ) ) { |
|
| 134 | - $variations_saved[ $variation_id ]['file']['path'] = $downloadable['file_url']; |
|
| 135 | - $variations_saved[ $variation_id ]['file']['name'] = basename( $downloadable['file_url'] ); |
|
| 128 | + $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true); |
|
| 129 | + $variations_saved = wpshop_products::get_variation($post->ID); |
|
| 130 | + if (!empty($variations_saved)) { |
|
| 131 | + foreach ($variations_saved as $variation_id => $variation) { |
|
| 132 | + $downloadable = get_post_meta($variation_id, 'attribute_option_is_downloadable_', true); |
|
| 133 | + if (!empty($downloadable['file_url'])) { |
|
| 134 | + $variations_saved[$variation_id]['file']['path'] = $downloadable['file_url']; |
|
| 135 | + $variations_saved[$variation_id]['file']['name'] = basename($downloadable['file_url']); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 139 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 140 | 140 | $product_currency = wpshop_tools::wpshop_get_currency(); |
| 141 | - wp_enqueue_style( 'wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css' ); |
|
| 142 | - wp_enqueue_script( 'wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js' ); |
|
| 143 | - wp_enqueue_script( 'wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js' ); |
|
| 144 | - wp_localize_script( 'wps-product-variation-interface-script', 'wps_product_variation_interface', apply_filters( 'wps_filters_product_variation_extra_columns_product_definition', array( |
|
| 141 | + wp_enqueue_style('wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css'); |
|
| 142 | + wp_enqueue_script('wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js'); |
|
| 143 | + wp_enqueue_script('wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js'); |
|
| 144 | + wp_localize_script('wps-product-variation-interface-script', 'wps_product_variation_interface', apply_filters('wps_filters_product_variation_extra_columns_product_definition', array( |
|
| 145 | 145 | 'variation' => $this->variations, |
| 146 | - 'nonce_delete' => wp_create_nonce( 'wpshop_variation_management' ), |
|
| 147 | - 'variation_value' => call_user_func( array( $wpdb, 'get_results' ), $query ), |
|
| 148 | - 'product_price' => ( ! empty( $price_piloting ) && 'HT' !== $price_piloting ) ? $product['product_price'] : $product['price_ht'], |
|
| 146 | + 'nonce_delete' => wp_create_nonce('wpshop_variation_management'), |
|
| 147 | + 'variation_value' => call_user_func(array($wpdb, 'get_results'), $query), |
|
| 148 | + 'product_price' => (!empty($price_piloting) && 'HT' !== $price_piloting) ? $product['product_price'] : $product['price_ht'], |
|
| 149 | 149 | 'tx_tva' => $product['tx_tva'], |
| 150 | 150 | 'attribute_in_variation' => $attribute_list, |
| 151 | 151 | 'variations_saved' => $variations_saved, |
| 152 | 152 | 'price_piloting' => $price_piloting, |
| 153 | 153 | 'currency' => $product_currency, |
| 154 | 154 | 'variation_defining' => $variation_defining, |
| 155 | - 'label_file' => __( 'Click to add file', 'wpshop' ), |
|
| 156 | - ) ) ); |
|
| 157 | - require_once wpshop_tools::get_template_part( WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation' ); |
|
| 155 | + 'label_file' => __('Click to add file', 'wpshop'), |
|
| 156 | + ))); |
|
| 157 | + require_once wpshop_tools::get_template_part(WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation'); |
|
| 158 | 158 | } |
| 159 | 159 | /** |
| 160 | 160 | * Save other values out of old variation interface. |
@@ -163,24 +163,24 @@ discard block |
||
| 163 | 163 | * @param object $post WP_Post of WordPress. |
| 164 | 164 | * @return void |
| 165 | 165 | */ |
| 166 | - private function save_post( $post_id, $post ) { |
|
| 167 | - if ( wp_is_post_revision( $post_id ) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || ! isset( $_REQUEST['wpshop_variation_defining']['options'] ) || ! isset( $_REQUEST['wps_pdt_variations'] ) ) { // Input var okay. |
|
| 166 | + private function save_post($post_id, $post) { |
|
| 167 | + if (wp_is_post_revision($post_id) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || !isset($_REQUEST['wpshop_variation_defining']['options']) || !isset($_REQUEST['wps_pdt_variations'])) { // Input var okay. |
|
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | - wpshop_products::variation_parameters_save( $post_id, $_REQUEST['wpshop_variation_defining']['options'] ); // Input var okay. |
|
| 171 | - remove_action( 'save_post', array( $this, 'save_post' ) ); |
|
| 172 | - foreach ( $_REQUEST['wps_pdt_variations'] as $variation_id => $data ) { // Input var okay. |
|
| 170 | + wpshop_products::variation_parameters_save($post_id, $_REQUEST['wpshop_variation_defining']['options']); // Input var okay. |
|
| 171 | + remove_action('save_post', array($this, 'save_post')); |
|
| 172 | + foreach ($_REQUEST['wps_pdt_variations'] as $variation_id => $data) { // Input var okay. |
|
| 173 | 173 | $variation = array( |
| 174 | 174 | 'ID' => $variation_id, |
| 175 | 175 | ); |
| 176 | - if ( isset( $data['status'] ) && 'on' === $data['status'] ) { |
|
| 176 | + if (isset($data['status']) && 'on' === $data['status']) { |
|
| 177 | 177 | $variation['post_status'] = 'publish'; |
| 178 | 178 | } else { |
| 179 | 179 | $variation['post_status'] = 'draft'; |
| 180 | 180 | } |
| 181 | - wp_update_post( $variation ); |
|
| 181 | + wp_update_post($variation); |
|
| 182 | 182 | } |
| 183 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); |
|
| 183 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 184 | 184 | } |
| 185 | 185 | /** |
| 186 | 186 | * Delete display in attributes products always in metabox. |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | * @param array $element Direct array attribute of db. |
| 190 | 190 | * @return array SAme array $output modified. |
| 191 | 191 | */ |
| 192 | - public function wpshop_attribute_output_def( $output, $element ) { |
|
| 193 | - if ( $this->is_activate() ) { |
|
| 194 | - $this->get_variations( $element ); |
|
| 195 | - if ( ! empty( $this->variations ) && in_array( $output['field_definition']['name'], array_keys( $this->variations ), true ) ) { |
|
| 192 | + public function wpshop_attribute_output_def($output, $element) { |
|
| 193 | + if ($this->is_activate()) { |
|
| 194 | + $this->get_variations($element); |
|
| 195 | + if (!empty($this->variations) && in_array($output['field_definition']['name'], array_keys($this->variations), true)) { |
|
| 196 | 196 | $output['field'] = ''; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @return void |
| 206 | 206 | */ |
| 207 | 207 | public static function wpshop_download_file_dialog_active() { |
| 208 | - add_filter( 'wps_filters_product_variation_file', array( 'wps_product_variation_interface', 'wps_filters_product_variation_file' ), 0, 1 ); |
|
| 208 | + add_filter('wps_filters_product_variation_file', array('wps_product_variation_interface', 'wps_filters_product_variation_file'), 0, 1); |
|
| 209 | 209 | } |
| 210 | 210 | /** |
| 211 | 211 | * Add old upload box for custom php dsiplay. |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | * @param string $string Input filter. |
| 215 | 215 | * @return string The div for box. |
| 216 | 216 | */ |
| 217 | - public static function wps_filters_product_variation_file( $string ) { |
|
| 217 | + public static function wps_filters_product_variation_file($string) { |
|
| 218 | 218 | ob_start(); |
| 219 | 219 | ?> |
| 220 | - <div style="display: none;" onclick="open_dialog_box(this, %ID%, '<?php esc_html_e( 'Send the downloadable file', 'wpshop' ); ?>')"> |
|
| 220 | + <div style="display: none;" onclick="open_dialog_box(this, %ID%, '<?php esc_html_e('Send the downloadable file', 'wpshop'); ?>')"> |
|
| 221 | 221 | <div class="is_downloadable_statut_%ID%"></div> |
| 222 | 222 | </div> |
| 223 | 223 | <?php |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) { exit; |
|
| 2 | 2 | } |
| 3 | 3 | |
| 4 | 4 | // End if(). |
| 5 | -if ( ! defined( 'WPSHOP_VERSION' ) ) { |
|
| 6 | - die( __( 'Access is not allowed by this way', 'wpshop' ) ); |
|
| 5 | +if (!defined('WPSHOP_VERSION')) { |
|
| 6 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | /** |
@@ -18,58 +18,58 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | // End if(). |
| 21 | -include_once( WPSHOP_DIR . '/core/module_management/module_management.php' ); |
|
| 22 | -include_once( WPSHOP_INCLUDES_DIR . 'wpshop_ajax.php' ); |
|
| 23 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'install.class.php' ); |
|
| 24 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'permissions.class.php' ); |
|
| 25 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'options/options.class.php' ); |
|
| 26 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'notices.class.php' ); |
|
| 21 | +include_once(WPSHOP_DIR . '/core/module_management/module_management.php'); |
|
| 22 | +include_once(WPSHOP_INCLUDES_DIR . 'wpshop_ajax.php'); |
|
| 23 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'install.class.php'); |
|
| 24 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'permissions.class.php'); |
|
| 25 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'options/options.class.php'); |
|
| 26 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'notices.class.php'); |
|
| 27 | 27 | /* Purchase management */ |
| 28 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'purchase/checkout.class.php' ); |
|
| 29 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'purchase/orders.class.php' ); |
|
| 28 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'purchase/checkout.class.php'); |
|
| 29 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'purchase/orders.class.php'); |
|
| 30 | 30 | /* Database management */ |
| 31 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'db/db_structure_definition.php' ); |
|
| 32 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'db/db_data_definition.php' ); |
|
| 33 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'db/database.class.php' ); |
|
| 31 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'db/db_structure_definition.php'); |
|
| 32 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'db/db_data_definition.php'); |
|
| 33 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'db/database.class.php'); |
|
| 34 | 34 | /* Payments management */ |
| 35 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'payments/payment.class.php' ); |
|
| 36 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'payments/paypal.class.php' ); |
|
| 35 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'payments/payment.class.php'); |
|
| 36 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'payments/paypal.class.php'); |
|
| 37 | 37 | // If the CIC payment method is active |
| 38 | -$wpshop_paymentMethod = get_option( 'wps_payment_mode' ); |
|
| 39 | -if ( WPSHOP_PAYMENT_METHOD_CIC && ! empty( $wpshop_paymentMethod ) && ! empty( $wpshop_paymentMethod['mode'] ) && ! empty( $wpshop_paymentMethod['mode']['cic'] ) ) { |
|
| 40 | - include_once( WPSHOP_LIBRAIRIES_DIR . 'payments/cic.class.php' ); |
|
| 38 | +$wpshop_paymentMethod = get_option('wps_payment_mode'); |
|
| 39 | +if (WPSHOP_PAYMENT_METHOD_CIC && !empty($wpshop_paymentMethod) && !empty($wpshop_paymentMethod['mode']) && !empty($wpshop_paymentMethod['mode']['cic'])) { |
|
| 40 | + include_once(WPSHOP_LIBRAIRIES_DIR . 'payments/cic.class.php'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // End if(). |
| 44 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 45 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
|
| 44 | +if (!class_exists('WP_List_Table')) { |
|
| 45 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); |
|
| 46 | 46 | } |
| 47 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'display/display.class.php' ); |
|
| 48 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'display/form.class.php' ); |
|
| 49 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'display/form_management.class.php' ); |
|
| 50 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'display/widgets/categories.widget.php' ); |
|
| 51 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'display/widgets/products.widget.php' ); |
|
| 47 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'display/display.class.php'); |
|
| 48 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'display/form.class.php'); |
|
| 49 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'display/form_management.class.php'); |
|
| 50 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'display/widgets/categories.widget.php'); |
|
| 51 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'display/widgets/products.widget.php'); |
|
| 52 | 52 | // End if(). |
| 53 | -add_action( 'admin_init', array( 'wpshop_display', 'check_template_file' ) ); |
|
| 53 | +add_action('admin_init', array('wpshop_display', 'check_template_file')); |
|
| 54 | 54 | /* Files management */ |
| 55 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'documents/documents.class.php' ); |
|
| 56 | -add_action( 'admin_head', array( 'wpshop_documents', 'galery_manager_css' ) ); |
|
| 57 | -add_filter( 'attachment_fields_to_edit', array( 'wpshop_documents', 'attachment_fields' ), 11, 2 ); |
|
| 58 | -add_filter( 'gettext', array( 'wpshop_documents', 'change_picture_translation' ), 11, 2 ); |
|
| 55 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'documents/documents.class.php'); |
|
| 56 | +add_action('admin_head', array('wpshop_documents', 'galery_manager_css')); |
|
| 57 | +add_filter('attachment_fields_to_edit', array('wpshop_documents', 'attachment_fields'), 11, 2); |
|
| 58 | +add_filter('gettext', array('wpshop_documents', 'change_picture_translation'), 11, 2); |
|
| 59 | 59 | /* Catalog management */ |
| 60 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'catalog/products.class.php' ); |
|
| 61 | -include_once( WPSHOP_LIBRAIRIES_DIR . 'catalog/categories.class.php' ); |
|
| 62 | -add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_columns', array( 'wpshop_categories', 'category_manage_columns' ) ); |
|
| 63 | -add_filter( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_custom_column', array( 'wpshop_categories', 'category_manage_columns_content' ), 10, 3 ); |
|
| 64 | -add_action( WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_edit_form_fields', array( 'wpshop_categories', 'category_edit_fields' ) ); |
|
| 65 | -add_action( 'created_' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, array( 'wpshop_categories', 'category_fields_saver' ), 10, 2 ); |
|
| 66 | -add_action( 'edited_' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, array( 'wpshop_categories', 'category_fields_saver' ), 10, 2 ); |
|
| 60 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'catalog/products.class.php'); |
|
| 61 | +include_once(WPSHOP_LIBRAIRIES_DIR . 'catalog/categories.class.php'); |
|
| 62 | +add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_columns', array('wpshop_categories', 'category_manage_columns')); |
|
| 63 | +add_filter('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_custom_column', array('wpshop_categories', 'category_manage_columns_content'), 10, 3); |
|
| 64 | +add_action(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_edit_form_fields', array('wpshop_categories', 'category_edit_fields')); |
|
| 65 | +add_action('created_' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, array('wpshop_categories', 'category_fields_saver'), 10, 2); |
|
| 66 | +add_action('edited_' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, array('wpshop_categories', 'category_fields_saver'), 10, 2); |
|
| 67 | 67 | /* EAV management */ |
| 68 | -include( WPSHOP_LIBRAIRIES_DIR . 'eav/wp_list_custom_attributes.class.php' ); |
|
| 69 | -include( WPSHOP_LIBRAIRIES_DIR . 'eav/attributes.class.php' ); |
|
| 70 | -include( WPSHOP_LIBRAIRIES_DIR . 'eav/attributes_unit.class.php' ); |
|
| 71 | -include( WPSHOP_LIBRAIRIES_DIR . 'eav/wp_list_custom_attributes_set.class.php' ); |
|
| 72 | -include( WPSHOP_LIBRAIRIES_DIR . 'eav/attributes_set.class.php' ); |
|
| 73 | -include( WPSHOP_LIBRAIRIES_DIR . 'eav/entities.class.php' ); |
|
| 68 | +include(WPSHOP_LIBRAIRIES_DIR . 'eav/wp_list_custom_attributes.class.php'); |
|
| 69 | +include(WPSHOP_LIBRAIRIES_DIR . 'eav/attributes.class.php'); |
|
| 70 | +include(WPSHOP_LIBRAIRIES_DIR . 'eav/attributes_unit.class.php'); |
|
| 71 | +include(WPSHOP_LIBRAIRIES_DIR . 'eav/wp_list_custom_attributes_set.class.php'); |
|
| 72 | +include(WPSHOP_LIBRAIRIES_DIR . 'eav/attributes_set.class.php'); |
|
| 73 | +include(WPSHOP_LIBRAIRIES_DIR . 'eav/entities.class.php'); |
|
| 74 | 74 | /* Modules management */ |
| 75 | 75 | eo_module_management::extra_modules(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | /* Check if file is include. No direct access possible with file url */ |
| 16 | 16 | if (!defined('WPSHOP_VERSION')) { |
| 17 | - die(__('Access is not allowed by this way', 'wpshop')); |
|
| 17 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -26,160 +26,160 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class wpshop_products |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * Définition du code de la classe courante |
|
| 31 | - */ |
|
| 32 | - const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 33 | - const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION; |
|
| 34 | - |
|
| 35 | - public function add_product_to_current_order_interface() |
|
| 36 | - { |
|
| 37 | - $output = ''; |
|
| 38 | - $output .= self::products_list_js(); |
|
| 39 | - $output .= '<input type="text" id="wps_order_search_product" />'; |
|
| 40 | - echo $output; |
|
| 41 | - die(); |
|
| 42 | - } |
|
| 29 | + /** |
|
| 30 | + * Définition du code de la classe courante |
|
| 31 | + */ |
|
| 32 | + const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 33 | + const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION; |
|
| 34 | + |
|
| 35 | + public function add_product_to_current_order_interface() |
|
| 36 | + { |
|
| 37 | + $output = ''; |
|
| 38 | + $output .= self::products_list_js(); |
|
| 39 | + $output .= '<input type="text" id="wps_order_search_product" />'; |
|
| 40 | + echo $output; |
|
| 41 | + die(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function products_list_js() |
|
| 45 | - { |
|
| 46 | - global $wpdb; |
|
| 47 | - /** Create a JS Array of products **/ |
|
| 44 | + public function products_list_js() |
|
| 45 | + { |
|
| 46 | + global $wpdb; |
|
| 47 | + /** Create a JS Array of products **/ |
|
| 48 | 48 | // $query = $wpdb->prepare('SELECT ID, post_title FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_status = %s', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
| 49 | - // $products_post = $wpdb->get_results( $query ); |
|
| 50 | - |
|
| 51 | - $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1)); |
|
| 52 | - |
|
| 53 | - if (!empty($products_post)) { |
|
| 54 | - $products_js_array = 'var products = ['; |
|
| 55 | - foreach ($products_post as $product) { |
|
| 56 | - $barcode = get_post_meta($product->ID, '_barcode', true); |
|
| 57 | - $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", '; |
|
| 58 | - $products_js_array .= 'value:"' . $product->ID . '", '; |
|
| 59 | - $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},'; |
|
| 60 | - } |
|
| 61 | - $products_js_array .= '];'; |
|
| 62 | - } |
|
| 63 | - $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin'); |
|
| 64 | - return $output; |
|
| 65 | - } |
|
| 49 | + // $products_post = $wpdb->get_results( $query ); |
|
| 50 | + |
|
| 51 | + $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1)); |
|
| 52 | + |
|
| 53 | + if (!empty($products_post)) { |
|
| 54 | + $products_js_array = 'var products = ['; |
|
| 55 | + foreach ($products_post as $product) { |
|
| 56 | + $barcode = get_post_meta($product->ID, '_barcode', true); |
|
| 57 | + $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", '; |
|
| 58 | + $products_js_array .= 'value:"' . $product->ID . '", '; |
|
| 59 | + $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},'; |
|
| 60 | + } |
|
| 61 | + $products_js_array .= '];'; |
|
| 62 | + } |
|
| 63 | + $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin'); |
|
| 64 | + return $output; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Déclaration des produits et variations en tant que "post" de wordpress |
|
| 69 | - * |
|
| 70 | - * @see register_post_type() |
|
| 71 | - */ |
|
| 72 | - public static function create_wpshop_products_type() |
|
| 73 | - { |
|
| 74 | - |
|
| 75 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 76 | - //$options2 = get_option('wpshop_catalog_categories_option', array()); |
|
| 77 | - /*echo '<pre>'; print_r( $options ); echo '</pre>'; |
|
| 67 | + /** |
|
| 68 | + * Déclaration des produits et variations en tant que "post" de wordpress |
|
| 69 | + * |
|
| 70 | + * @see register_post_type() |
|
| 71 | + */ |
|
| 72 | + public static function create_wpshop_products_type() |
|
| 73 | + { |
|
| 74 | + |
|
| 75 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 76 | + //$options2 = get_option('wpshop_catalog_categories_option', array()); |
|
| 77 | + /*echo '<pre>'; print_r( $options ); echo '</pre>'; |
|
| 78 | 78 | echo '<pre>'; print_r( $options2 ); echo '</pre>'; exit();*/ |
| 79 | 79 | |
| 80 | - $slug = array( |
|
| 81 | - 'slug' => '', |
|
| 82 | - 'with_front' => false, |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') { |
|
| 86 | - $slug = false; |
|
| 87 | - } else { |
|
| 88 | - $slug['slug'] = $options['wpshop_catalog_product_slug']; |
|
| 89 | - if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 90 | - $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%'; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/ |
|
| 94 | - |
|
| 95 | - /* Définition des produits */ |
|
| 96 | - register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array( |
|
| 97 | - 'labels' => array( |
|
| 98 | - 'name' => __('Products', 'wpshop'), |
|
| 99 | - 'singular_name' => __('Catalog', 'wpshop'), |
|
| 100 | - 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 101 | - 'add_new' => __('Add new product', 'wpshop'), |
|
| 102 | - 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 103 | - 'edit_item' => __('Edit product', 'wpshop'), |
|
| 104 | - 'new_item' => __('New product', 'wpshop'), |
|
| 105 | - 'view_item' => __('View product', 'wpshop'), |
|
| 106 | - 'search_items' => __('Search products', 'wpshop'), |
|
| 107 | - 'not_found' => __('No products found', 'wpshop'), |
|
| 108 | - 'not_found_in_trash' => __('No products found in Trash', 'wpshop'), |
|
| 109 | - 'parent_item_colon' => '', |
|
| 110 | - ), |
|
| 111 | - 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 112 | - 'public' => true, |
|
| 113 | - 'has_archive' => false, |
|
| 114 | - 'show_in_nav_menus' => true, |
|
| 115 | - //'rewrite' => false, // For information see below |
|
| 116 | - 'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES), |
|
| 117 | - 'menu_icon' => 'dashicons-archive', |
|
| 118 | - 'rewrite' => $slug, |
|
| 119 | - ))); |
|
| 120 | - |
|
| 121 | - /* Définition des variations de produit (Déclinaisons) */ |
|
| 122 | - register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array( |
|
| 123 | - 'labels' => array( |
|
| 124 | - 'name' => __('Variations', 'wpshop'), |
|
| 125 | - 'singular_name' => __('Variation', 'wpshop'), |
|
| 126 | - 'add_new' => __('Add Variation', 'wpshop'), |
|
| 127 | - 'add_new_item' => __('Add New Variation', 'wpshop'), |
|
| 128 | - 'edit' => __('Edit', 'wpshop'), |
|
| 129 | - 'edit_item' => __('Edit Variation', 'wpshop'), |
|
| 130 | - 'new_item' => __('New Variation', 'wpshop'), |
|
| 131 | - 'view' => __('View Variation', 'wpshop'), |
|
| 132 | - 'view_item' => __('View Variation', 'wpshop'), |
|
| 133 | - 'search_items' => __('Search Variations', 'wpshop'), |
|
| 134 | - 'not_found' => __('No Variations found', 'wpshop'), |
|
| 135 | - 'not_found_in_trash' => __('No Variations found in trash', 'wpshop'), |
|
| 136 | - 'parent_item_colon' => '', |
|
| 137 | - ), |
|
| 138 | - 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 139 | - 'public' => true, |
|
| 140 | - 'has_archive' => true, |
|
| 141 | - 'show_in_nav_menus' => false, |
|
| 142 | - 'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 143 | - |
|
| 144 | - 'publicly_queryable' => false, |
|
| 145 | - 'exclude_from_search' => true, |
|
| 146 | - 'hierarchical' => false, |
|
| 147 | - |
|
| 148 | - // 'public' => true, |
|
| 149 | - // 'show_ui' => false, |
|
| 150 | - // 'rewrite' => false, |
|
| 151 | - // 'query_var' => true, |
|
| 152 | - // 'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ), |
|
| 153 | - // 'show_in_nav_menus' => false |
|
| 154 | - ) |
|
| 155 | - )); |
|
| 156 | - |
|
| 157 | - // add to our plugin init function |
|
| 158 | - //global $wp_rewrite; |
|
| 159 | - /* Slug url is set into option */ |
|
| 160 | - /*$options = get_option('wpshop_catalog_product_option', array()); |
|
| 80 | + $slug = array( |
|
| 81 | + 'slug' => '', |
|
| 82 | + 'with_front' => false, |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') { |
|
| 86 | + $slug = false; |
|
| 87 | + } else { |
|
| 88 | + $slug['slug'] = $options['wpshop_catalog_product_slug']; |
|
| 89 | + if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 90 | + $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%'; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/ |
|
| 94 | + |
|
| 95 | + /* Définition des produits */ |
|
| 96 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array( |
|
| 97 | + 'labels' => array( |
|
| 98 | + 'name' => __('Products', 'wpshop'), |
|
| 99 | + 'singular_name' => __('Catalog', 'wpshop'), |
|
| 100 | + 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 101 | + 'add_new' => __('Add new product', 'wpshop'), |
|
| 102 | + 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 103 | + 'edit_item' => __('Edit product', 'wpshop'), |
|
| 104 | + 'new_item' => __('New product', 'wpshop'), |
|
| 105 | + 'view_item' => __('View product', 'wpshop'), |
|
| 106 | + 'search_items' => __('Search products', 'wpshop'), |
|
| 107 | + 'not_found' => __('No products found', 'wpshop'), |
|
| 108 | + 'not_found_in_trash' => __('No products found in Trash', 'wpshop'), |
|
| 109 | + 'parent_item_colon' => '', |
|
| 110 | + ), |
|
| 111 | + 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 112 | + 'public' => true, |
|
| 113 | + 'has_archive' => false, |
|
| 114 | + 'show_in_nav_menus' => true, |
|
| 115 | + //'rewrite' => false, // For information see below |
|
| 116 | + 'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES), |
|
| 117 | + 'menu_icon' => 'dashicons-archive', |
|
| 118 | + 'rewrite' => $slug, |
|
| 119 | + ))); |
|
| 120 | + |
|
| 121 | + /* Définition des variations de produit (Déclinaisons) */ |
|
| 122 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array( |
|
| 123 | + 'labels' => array( |
|
| 124 | + 'name' => __('Variations', 'wpshop'), |
|
| 125 | + 'singular_name' => __('Variation', 'wpshop'), |
|
| 126 | + 'add_new' => __('Add Variation', 'wpshop'), |
|
| 127 | + 'add_new_item' => __('Add New Variation', 'wpshop'), |
|
| 128 | + 'edit' => __('Edit', 'wpshop'), |
|
| 129 | + 'edit_item' => __('Edit Variation', 'wpshop'), |
|
| 130 | + 'new_item' => __('New Variation', 'wpshop'), |
|
| 131 | + 'view' => __('View Variation', 'wpshop'), |
|
| 132 | + 'view_item' => __('View Variation', 'wpshop'), |
|
| 133 | + 'search_items' => __('Search Variations', 'wpshop'), |
|
| 134 | + 'not_found' => __('No Variations found', 'wpshop'), |
|
| 135 | + 'not_found_in_trash' => __('No Variations found in trash', 'wpshop'), |
|
| 136 | + 'parent_item_colon' => '', |
|
| 137 | + ), |
|
| 138 | + 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 139 | + 'public' => true, |
|
| 140 | + 'has_archive' => true, |
|
| 141 | + 'show_in_nav_menus' => false, |
|
| 142 | + 'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 143 | + |
|
| 144 | + 'publicly_queryable' => false, |
|
| 145 | + 'exclude_from_search' => true, |
|
| 146 | + 'hierarchical' => false, |
|
| 147 | + |
|
| 148 | + // 'public' => true, |
|
| 149 | + // 'show_ui' => false, |
|
| 150 | + // 'rewrite' => false, |
|
| 151 | + // 'query_var' => true, |
|
| 152 | + // 'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ), |
|
| 153 | + // 'show_in_nav_menus' => false |
|
| 154 | + ) |
|
| 155 | + )); |
|
| 156 | + |
|
| 157 | + // add to our plugin init function |
|
| 158 | + //global $wp_rewrite; |
|
| 159 | + /* Slug url is set into option */ |
|
| 160 | + /*$options = get_option('wpshop_catalog_product_option', array()); |
|
| 161 | 161 | $gallery_structure = (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : 'catalog'); |
| 162 | 162 | $gallery_structure .= !empty($options['wpshop_catalog_product_slug_with_category']) ? '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%' : ''; |
| 163 | 163 | $gallery_structure .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%'; |
| 164 | 164 | $wp_rewrite->add_permastruct(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $gallery_structure, false); |
| 165 | 165 | $wp_rewrite->add_rewrite_tag('%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%', '([^/]+)', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "=");*/ |
| 166 | - // flush_rewrite_rules(); |
|
| 167 | - } |
|
| 166 | + // flush_rewrite_rules(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - public static function hidden_meta_boxes($hidden, $screen, $use_defaults) |
|
| 170 | - { |
|
| 171 | - global $wpdb; |
|
| 172 | - if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) { |
|
| 173 | - $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 174 | - foreach ($user_meta_for_wpshop as $meta_to_check) { |
|
| 175 | - $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true); |
|
| 176 | - if (empty($metas_hidden) && !is_array($metas_hidden)) { |
|
| 177 | - $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - return $hidden; |
|
| 182 | - } |
|
| 169 | + public static function hidden_meta_boxes($hidden, $screen, $use_defaults) |
|
| 170 | + { |
|
| 171 | + global $wpdb; |
|
| 172 | + if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) { |
|
| 173 | + $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 174 | + foreach ($user_meta_for_wpshop as $meta_to_check) { |
|
| 175 | + $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true); |
|
| 176 | + if (empty($metas_hidden) && !is_array($metas_hidden)) { |
|
| 177 | + $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + return $hidden; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | public static function admin_menu() { |
| 185 | 185 | global $submenu; |
@@ -206,35 +206,35 @@ discard block |
||
| 206 | 206 | $submenu['edit.php?post_type=wpshop_product'] = $submenu_reorder; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Create the different bow for the product management page looking for the attribute set to create the different boxes |
|
| 211 | - */ |
|
| 212 | - public static function add_meta_boxes() |
|
| 213 | - { |
|
| 214 | - global $post, $currentTabContent; |
|
| 215 | - |
|
| 216 | - if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) { |
|
| 217 | - /* Get the attribute set list for the current entity */ |
|
| 218 | - $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
|
| 219 | - /* Check if the meta information of the current product already exists */ |
|
| 220 | - $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 221 | - /* Check if the product has been saved without meta information set */ |
|
| 222 | - $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); |
|
| 223 | - /* Unset 'free_product' from list of attributes set */ |
|
| 224 | - foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
|
| 225 | - if ($attribute_set->slug == 'free_product') { |
|
| 226 | - unset($attributeEntitySetList[$key_attribute_set]); |
|
| 227 | - break; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ |
|
| 232 | - if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) { |
|
| 233 | - if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) { |
|
| 234 | - $post_attribute_set_id = $attributeEntitySetList[0]->id; |
|
| 235 | - } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) { |
|
| 236 | - $post_attribute_set_id = $attribute_set_id->value; |
|
| 237 | - } |
|
| 209 | + /** |
|
| 210 | + * Create the different bow for the product management page looking for the attribute set to create the different boxes |
|
| 211 | + */ |
|
| 212 | + public static function add_meta_boxes() |
|
| 213 | + { |
|
| 214 | + global $post, $currentTabContent; |
|
| 215 | + |
|
| 216 | + if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) { |
|
| 217 | + /* Get the attribute set list for the current entity */ |
|
| 218 | + $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
|
| 219 | + /* Check if the meta information of the current product already exists */ |
|
| 220 | + $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 221 | + /* Check if the product has been saved without meta information set */ |
|
| 222 | + $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); |
|
| 223 | + /* Unset 'free_product' from list of attributes set */ |
|
| 224 | + foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
|
| 225 | + if ($attribute_set->slug == 'free_product') { |
|
| 226 | + unset($attributeEntitySetList[$key_attribute_set]); |
|
| 227 | + break; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ |
|
| 232 | + if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) { |
|
| 233 | + if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) { |
|
| 234 | + $post_attribute_set_id = $attributeEntitySetList[0]->id; |
|
| 235 | + } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) { |
|
| 236 | + $post_attribute_set_id = $attribute_set_id->value; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | /*$post_attribute_set_id = (int) get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
| 240 | 240 | |
@@ -252,32 +252,32 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | }*/ |
| 254 | 254 | |
| 255 | - $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); |
|
| 256 | - |
|
| 257 | - $fixed_box_exist = false; |
|
| 258 | - /* Get all the other attribute set for hte current entity */ |
|
| 259 | - if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { |
|
| 260 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 261 | - if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) { |
|
| 262 | - add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); |
|
| 263 | - } else { |
|
| 264 | - $fixed_box_exist = true; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - if ($fixed_box_exist) { |
|
| 270 | - add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 271 | - add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 275 | - // Actions |
|
| 276 | - // @since 1.4.3.7 Deleted |
|
| 277 | - //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 278 | - |
|
| 279 | - /** Product option */ |
|
| 280 | - add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 255 | + $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); |
|
| 256 | + |
|
| 257 | + $fixed_box_exist = false; |
|
| 258 | + /* Get all the other attribute set for hte current entity */ |
|
| 259 | + if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { |
|
| 260 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 261 | + if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) { |
|
| 262 | + add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); |
|
| 263 | + } else { |
|
| 264 | + $fixed_box_exist = true; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + if ($fixed_box_exist) { |
|
| 270 | + add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 271 | + add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 275 | + // Actions |
|
| 276 | + // @since 1.4.3.7 Deleted |
|
| 277 | + //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 278 | + |
|
| 279 | + /** Product option */ |
|
| 280 | + add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 281 | 281 | /*add_meta_box('wpshop_histo_attrs', __('Historic attributes', 'wpshop'), function($post) { |
| 282 | 282 | global $wpdb; |
| 283 | 283 | $limit = 40; |
@@ -310,21 +310,21 @@ discard block |
||
| 310 | 310 | 'total' => $max_page |
| 311 | 311 | ) ); |
| 312 | 312 | }, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');*/ |
| 313 | - } else if (count($attributeEntitySetList) > 1) { |
|
| 314 | - $input_def['id'] = 'product_attribute_set_id'; |
|
| 315 | - $input_def['name'] = 'product_attribute_set_id'; |
|
| 316 | - $input_def['value'] = ''; |
|
| 317 | - $input_def['type'] = 'select'; |
|
| 318 | - $input_def['possible_value'] = $attributeEntitySetList; |
|
| 319 | - |
|
| 320 | - $input_def['value'] = ''; |
|
| 321 | - foreach ($attributeEntitySetList as $set) { |
|
| 322 | - if ($set->default_set == 'yes') { |
|
| 323 | - $input_def['value'] = $set->id; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 313 | + } else if (count($attributeEntitySetList) > 1) { |
|
| 314 | + $input_def['id'] = 'product_attribute_set_id'; |
|
| 315 | + $input_def['name'] = 'product_attribute_set_id'; |
|
| 316 | + $input_def['value'] = ''; |
|
| 317 | + $input_def['type'] = 'select'; |
|
| 318 | + $input_def['possible_value'] = $attributeEntitySetList; |
|
| 319 | + |
|
| 320 | + $input_def['value'] = ''; |
|
| 321 | + foreach ($attributeEntitySetList as $set) { |
|
| 322 | + if ($set->default_set == 'yes') { |
|
| 323 | + $input_def['value'] = $set->id; |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 328 | 328 | <ul class="attribute_set_selector" > |
| 329 | 329 | <li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li> |
| 330 | 330 | <li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . __('Choose an attribute group for this product', 'wpshop') . '</label> ' . wpshop_form::check_input_type($input_def, self::currentPageCode . '_attribute[integer]') . '</li> |
@@ -332,792 +332,792 @@ discard block |
||
| 332 | 332 | <li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li> |
| 333 | 333 | </ul>'; |
| 334 | 334 | |
| 335 | - add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector')); |
|
| 336 | - } |
|
| 337 | - } |
|
| 335 | + add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector')); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - } |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Add a box into product edition page for options on the product |
|
| 343 | - * |
|
| 344 | - * @param object $post |
|
| 345 | - */ |
|
| 346 | - public static function product_options_meta_box_content($post) |
|
| 347 | - { |
|
| 348 | - $output = ''; |
|
| 341 | + /** |
|
| 342 | + * Add a box into product edition page for options on the product |
|
| 343 | + * |
|
| 344 | + * @param object $post |
|
| 345 | + */ |
|
| 346 | + public static function product_options_meta_box_content($post) |
|
| 347 | + { |
|
| 348 | + $output = ''; |
|
| 349 | 349 | |
| 350 | - $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 350 | + $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 351 | 351 | |
| 352 | - $tpl_component = array(); |
|
| 353 | - $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 354 | - $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 352 | + $tpl_component = array(); |
|
| 353 | + $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 354 | + $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 355 | 355 | |
| 356 | - echo $output; |
|
| 357 | - } |
|
| 356 | + echo $output; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * Display the fixed box |
|
| 361 | - */ |
|
| 362 | - public static function product_data_meta_box($post, $metaboxArgs) |
|
| 363 | - { |
|
| 364 | - $output = ''; |
|
| 359 | + /** |
|
| 360 | + * Display the fixed box |
|
| 361 | + */ |
|
| 362 | + public static function product_data_meta_box($post, $metaboxArgs) |
|
| 363 | + { |
|
| 364 | + $output = ''; |
|
| 365 | 365 | |
| 366 | - $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 366 | + $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 367 | 367 | |
| 368 | - echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 368 | + echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 369 | 369 | <ul>'; |
| 370 | - if (!empty($currentTabContent['box'])) { |
|
| 371 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 372 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 373 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 374 | - echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 380 | - echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 381 | - echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 382 | - echo '</ul>'; |
|
| 383 | - |
|
| 384 | - if (!empty($currentTabContent['box'])) { |
|
| 385 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 386 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 387 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 388 | - echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 370 | + if (!empty($currentTabContent['box'])) { |
|
| 371 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 372 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 373 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 374 | + echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 380 | + echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 381 | + echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 382 | + echo '</ul>'; |
|
| 383 | + |
|
| 384 | + if (!empty($currentTabContent['box'])) { |
|
| 385 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 386 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 387 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 388 | + echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 395 | - echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>'; |
|
| 396 | - echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 397 | - if (!empty($currentTabContent['boxMore'])) { |
|
| 398 | - echo $currentTabContent['boxMore']; |
|
| 399 | - } |
|
| 400 | - echo '</div>'; |
|
| 394 | + echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 395 | + echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>'; |
|
| 396 | + echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 397 | + if (!empty($currentTabContent['boxMore'])) { |
|
| 398 | + echo $currentTabContent['boxMore']; |
|
| 399 | + } |
|
| 400 | + echo '</div>'; |
|
| 401 | 401 | |
| 402 | - echo $output; |
|
| 403 | - } |
|
| 402 | + echo $output; |
|
| 403 | + } |
|
| 404 | 404 | |
| 405 | - /** |
|
| 406 | - * Output the content for related product metabox |
|
| 407 | - * @param object $post The current edited post |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public static function related_products_meta_box_content($post) |
|
| 411 | - { |
|
| 412 | - $content = $existing_selection = ''; |
|
| 413 | - |
|
| 414 | - if (!empty($post->ID)) { |
|
| 415 | - $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 416 | - if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 417 | - foreach ($related_products_id as $related_product_id) { |
|
| 418 | - $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 405 | + /** |
|
| 406 | + * Output the content for related product metabox |
|
| 407 | + * @param object $post The current edited post |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public static function related_products_meta_box_content($post) |
|
| 411 | + { |
|
| 412 | + $content = $existing_selection = ''; |
|
| 413 | + |
|
| 414 | + if (!empty($post->ID)) { |
|
| 415 | + $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 416 | + if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 417 | + foreach ($related_products_id as $related_product_id) { |
|
| 418 | + $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - $content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p> |
|
| 423 | + $content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p> |
|
| 424 | 424 | <select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select> |
| 425 | 425 | <input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" /> |
| 426 | 426 | <input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 427 | 427 | |
| 428 | - return $content; |
|
| 429 | - } |
|
| 428 | + return $content; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - /** |
|
| 432 | - * Output the content for related product metabox |
|
| 433 | - * @param object $post The current edited post |
|
| 434 | - * @return string |
|
| 435 | - */ |
|
| 436 | - public static function provider_products_meta_box_content($post) |
|
| 437 | - { |
|
| 438 | - $content = $existing_selection = ''; |
|
| 439 | - |
|
| 440 | - if (!empty($post->ID)) { |
|
| 441 | - $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true); |
|
| 442 | - if (!empty($providers_id) && !empty($providers_id[0])) { |
|
| 443 | - foreach ($providers_id as $provider_id) { |
|
| 444 | - $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>'; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 431 | + /** |
|
| 432 | + * Output the content for related product metabox |
|
| 433 | + * @param object $post The current edited post |
|
| 434 | + * @return string |
|
| 435 | + */ |
|
| 436 | + public static function provider_products_meta_box_content($post) |
|
| 437 | + { |
|
| 438 | + $content = $existing_selection = ''; |
|
| 439 | + |
|
| 440 | + if (!empty($post->ID)) { |
|
| 441 | + $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true); |
|
| 442 | + if (!empty($providers_id) && !empty($providers_id[0])) { |
|
| 443 | + foreach ($providers_id as $provider_id) { |
|
| 444 | + $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>'; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p> |
|
| 449 | + $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p> |
|
| 450 | 450 | <select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select> |
| 451 | 451 | <input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" /> |
| 452 | 452 | <input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 453 | 453 | |
| 454 | - return $content; |
|
| 455 | - } |
|
| 454 | + return $content; |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * Define the metabox content for the action box |
|
| 459 | - * @param obejct $post The current element being edited |
|
| 460 | - */ |
|
| 461 | - public static function product_actions_meta_box_content($post) |
|
| 462 | - { |
|
| 463 | - $output = ''; |
|
| 464 | - /* |
|
| 457 | + /** |
|
| 458 | + * Define the metabox content for the action box |
|
| 459 | + * @param obejct $post The current element being edited |
|
| 460 | + */ |
|
| 461 | + public static function product_actions_meta_box_content($post) |
|
| 462 | + { |
|
| 463 | + $output = ''; |
|
| 464 | + /* |
|
| 465 | 465 | * Template parameters |
| 466 | 466 | */ |
| 467 | - $template_part = 'wpshop_duplicate_product'; |
|
| 468 | - $tpl_component = array(); |
|
| 469 | - $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 470 | - $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 471 | - /* |
|
| 467 | + $template_part = 'wpshop_duplicate_product'; |
|
| 468 | + $tpl_component = array(); |
|
| 469 | + $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 470 | + $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 471 | + /* |
|
| 472 | 472 | * Build template |
| 473 | 473 | */ |
| 474 | - $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 475 | - unset($tpl_component); |
|
| 474 | + $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 475 | + unset($tpl_component); |
|
| 476 | 476 | |
| 477 | - echo $output; |
|
| 478 | - } |
|
| 477 | + echo $output; |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - /** |
|
| 481 | - * Define the content of the product main information box |
|
| 482 | - */ |
|
| 483 | - public static function meta_box_content($post, $metaboxArgs) |
|
| 484 | - { |
|
| 485 | - global $currentTabContent; |
|
| 480 | + /** |
|
| 481 | + * Define the content of the product main information box |
|
| 482 | + */ |
|
| 483 | + public static function meta_box_content($post, $metaboxArgs) |
|
| 484 | + { |
|
| 485 | + global $currentTabContent; |
|
| 486 | 486 | |
| 487 | - /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 488 | - echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 489 | - } |
|
| 487 | + /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 488 | + echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - /** |
|
| 492 | - * Define the metabox content for product custom display in product |
|
| 493 | - * @param object $post The current element being edited |
|
| 494 | - * @return string The metabox content |
|
| 495 | - */ |
|
| 496 | - public static function product_frontend_display_config_meta_box($post) |
|
| 497 | - { |
|
| 498 | - $content = ''; |
|
| 499 | - |
|
| 500 | - $product_attribute_frontend_display_config = null; |
|
| 501 | - if (!empty($post->ID)) { |
|
| 502 | - $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 503 | - |
|
| 504 | - $extra_options = get_option('wpshop_extra_options', array()); |
|
| 505 | - $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 506 | - $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 507 | - $column = 1; |
|
| 508 | - |
|
| 509 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 510 | - $sub_tpl_component = array(); |
|
| 511 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 512 | - |
|
| 513 | - $tpl_component = array(); |
|
| 514 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 515 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 516 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 517 | - $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 518 | - |
|
| 519 | - $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 520 | - $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : ''; |
|
| 521 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 522 | - unset($tpl_component); |
|
| 523 | - |
|
| 524 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 525 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 526 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 527 | - $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 531 | - foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 532 | - if (!isset($sub_content[$column])) { |
|
| 533 | - $sub_content[$column] = ''; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - $attribute_sub_output = ''; |
|
| 537 | - foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 538 | - if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 539 | - $tpl_component = array(); |
|
| 540 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 541 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 542 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 543 | - $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 544 | - $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : ''; |
|
| 545 | - $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 546 | - unset($tpl_component); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $tpl_component = array(); |
|
| 551 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 552 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 553 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 554 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 555 | - $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 556 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>'; |
|
| 557 | - $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 558 | - $column++; |
|
| 559 | - if ($column > $column_count) { |
|
| 560 | - $column = 1; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - $tpl_component = array(); |
|
| 565 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 566 | - for ($i = 1; $i <= $column_count; $i++) { |
|
| 567 | - if (!empty($sub_content[$i])) { |
|
| 568 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - } |
|
| 572 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 573 | - $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 574 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 575 | - |
|
| 576 | - $content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>'; |
|
| 577 | - } |
|
| 491 | + /** |
|
| 492 | + * Define the metabox content for product custom display in product |
|
| 493 | + * @param object $post The current element being edited |
|
| 494 | + * @return string The metabox content |
|
| 495 | + */ |
|
| 496 | + public static function product_frontend_display_config_meta_box($post) |
|
| 497 | + { |
|
| 498 | + $content = ''; |
|
| 499 | + |
|
| 500 | + $product_attribute_frontend_display_config = null; |
|
| 501 | + if (!empty($post->ID)) { |
|
| 502 | + $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 503 | + |
|
| 504 | + $extra_options = get_option('wpshop_extra_options', array()); |
|
| 505 | + $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 506 | + $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 507 | + $column = 1; |
|
| 508 | + |
|
| 509 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 510 | + $sub_tpl_component = array(); |
|
| 511 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 512 | + |
|
| 513 | + $tpl_component = array(); |
|
| 514 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 515 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 516 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 517 | + $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 518 | + |
|
| 519 | + $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 520 | + $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : ''; |
|
| 521 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 522 | + unset($tpl_component); |
|
| 523 | + |
|
| 524 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 525 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 526 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 527 | + $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 528 | + } |
|
| 578 | 529 | |
| 579 | - return $content; |
|
| 580 | - } |
|
| 530 | + if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 531 | + foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 532 | + if (!isset($sub_content[$column])) { |
|
| 533 | + $sub_content[$column] = ''; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + $attribute_sub_output = ''; |
|
| 537 | + foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 538 | + if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 539 | + $tpl_component = array(); |
|
| 540 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 541 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 542 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 543 | + $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 544 | + $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : ''; |
|
| 545 | + $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 546 | + unset($tpl_component); |
|
| 547 | + } |
|
| 548 | + } |
|
| 581 | 549 | |
| 582 | - /** |
|
| 583 | - * Retrieve the attribute list used for sorting product into frontend listing |
|
| 584 | - * @return array The attribute list to use for listing sorting |
|
| 585 | - */ |
|
| 586 | - public static function get_sorting_criteria() |
|
| 587 | - { |
|
| 588 | - global $wpdb; |
|
| 550 | + $tpl_component = array(); |
|
| 551 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 552 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 553 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 554 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 555 | + $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 556 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>'; |
|
| 557 | + $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 558 | + $column++; |
|
| 559 | + if ($column > $column_count) { |
|
| 560 | + $column = 1; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + $tpl_component = array(); |
|
| 565 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 566 | + for ($i = 1; $i <= $column_count; $i++) { |
|
| 567 | + if (!empty($sub_content[$i])) { |
|
| 568 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 569 | + } |
|
| 589 | 570 | |
| 590 | - $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop'))); |
|
| 571 | + } |
|
| 572 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 573 | + $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 574 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 591 | 575 | |
| 592 | - $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 593 | - $results = $wpdb->get_results($query, ARRAY_A); |
|
| 594 | - if (!empty($results)) { |
|
| 595 | - $data = array_merge($data, $results); |
|
| 596 | - } |
|
| 576 | + $content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>'; |
|
| 577 | + } |
|
| 597 | 578 | |
| 598 | - return $data; |
|
| 599 | - } |
|
| 579 | + return $content; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Retrieve the attribute list used for sorting product into frontend listing |
|
| 584 | + * @return array The attribute list to use for listing sorting |
|
| 585 | + */ |
|
| 586 | + public static function get_sorting_criteria() |
|
| 587 | + { |
|
| 588 | + global $wpdb; |
|
| 589 | + |
|
| 590 | + $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop'))); |
|
| 591 | + |
|
| 592 | + $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 593 | + $results = $wpdb->get_results($query, ARRAY_A); |
|
| 594 | + if (!empty($results)) { |
|
| 595 | + $data = array_merge($data, $results); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return $data; |
|
| 599 | + } |
|
| 600 | 600 | |
| 601 | - public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 602 | - { |
|
| 603 | - global $wpdb; |
|
| 601 | + public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 602 | + { |
|
| 603 | + global $wpdb; |
|
| 604 | 604 | |
| 605 | - $products = array(); |
|
| 606 | - $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 607 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 605 | + $products = array(); |
|
| 606 | + $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 607 | + $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 608 | 608 | |
| 609 | - if (!empty($data)) { |
|
| 610 | - if ($data['data_type_to_use'] == 'custom') { |
|
| 611 | - // Find which table to take |
|
| 612 | - if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;} |
|
| 609 | + if (!empty($data)) { |
|
| 610 | + if ($data['data_type_to_use'] == 'custom') { |
|
| 611 | + // Find which table to take |
|
| 612 | + if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;} |
|
| 613 | 613 | |
| 614 | - if (isset($table_name)) { |
|
| 615 | - // If the value is an id of a select, radio or checkbox |
|
| 616 | - if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 614 | + if (isset($table_name)) { |
|
| 615 | + // If the value is an id of a select, radio or checkbox |
|
| 616 | + if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 617 | 617 | |
| 618 | - $query = $wpdb->prepare(" |
|
| 618 | + $query = $wpdb->prepare(" |
|
| 619 | 619 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 620 | 620 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 621 | 621 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 622 | 622 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id |
| 623 | 623 | WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value |
| 624 | - ); |
|
| 625 | - $data = $wpdb->get_results($query); |
|
| 626 | - } else { |
|
| 624 | + ); |
|
| 625 | + $data = $wpdb->get_results($query); |
|
| 626 | + } else { |
|
| 627 | 627 | |
| 628 | - $query = $wpdb->prepare(" |
|
| 628 | + $query = $wpdb->prepare(" |
|
| 629 | 629 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 630 | 630 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 631 | 631 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 632 | 632 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 633 | 633 | WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000 |
| 634 | - ); |
|
| 635 | - $data = $wpdb->get_results($query); |
|
| 636 | - |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 643 | - /** Check the ID of manufacturer **/ |
|
| 644 | - $default_value = unserialize($data['default_value']); |
|
| 645 | - if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 646 | - $query = get_post($attr_value); |
|
| 647 | - $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 648 | - if (!empty($pid)) { |
|
| 649 | - $query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid); |
|
| 650 | - $data = $wpdb->get_results($query); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } else { |
|
| 654 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - } else { |
|
| 658 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 659 | - } |
|
| 634 | + ); |
|
| 635 | + $data = $wpdb->get_results($query); |
|
| 660 | 636 | |
| 661 | - if (!empty($data)) { |
|
| 662 | - foreach ($data as $p) { |
|
| 663 | - if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 664 | - $products[] = $p->entity_id; |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - return $products; |
|
| 669 | - } |
|
| 637 | + } |
|
| 638 | + } else { |
|
| 639 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 640 | + } |
|
| 670 | 641 | |
| 671 | - /** |
|
| 672 | - * Related product shortcode reader |
|
| 673 | - * |
|
| 674 | - * @param array $atts { |
|
| 675 | - * pid : Product idenfifier to get related element for |
|
| 676 | - * display_mode : The output mode if defined (grid || list) |
|
| 677 | - * } |
|
| 678 | - * |
|
| 679 | - * @return string |
|
| 680 | - * |
|
| 681 | - */ |
|
| 682 | - public static function wpshop_related_products_func($atts) |
|
| 683 | - { |
|
| 684 | - global $wp_query; |
|
| 642 | + } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 643 | + /** Check the ID of manufacturer **/ |
|
| 644 | + $default_value = unserialize($data['default_value']); |
|
| 645 | + if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 646 | + $query = get_post($attr_value); |
|
| 647 | + $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 648 | + if (!empty($pid)) { |
|
| 649 | + $query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid); |
|
| 650 | + $data = $wpdb->get_results($query); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } else { |
|
| 654 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 655 | + } |
|
| 685 | 656 | |
| 686 | - $atts['product_type'] = 'related'; |
|
| 687 | - if (empty($atts['pid'])) { |
|
| 688 | - $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 689 | - } |
|
| 657 | + } else { |
|
| 658 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + if (!empty($data)) { |
|
| 662 | + foreach ($data as $p) { |
|
| 663 | + if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 664 | + $products[] = $p->entity_id; |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + return $products; |
|
| 669 | + } |
|
| 690 | 670 | |
| 691 | - $related_product_output = self::wpshop_products_func($atts); |
|
| 671 | + /** |
|
| 672 | + * Related product shortcode reader |
|
| 673 | + * |
|
| 674 | + * @param array $atts { |
|
| 675 | + * pid : Product idenfifier to get related element for |
|
| 676 | + * display_mode : The output mode if defined (grid || list) |
|
| 677 | + * } |
|
| 678 | + * |
|
| 679 | + * @return string |
|
| 680 | + * |
|
| 681 | + */ |
|
| 682 | + public static function wpshop_related_products_func($atts) |
|
| 683 | + { |
|
| 684 | + global $wp_query; |
|
| 685 | + |
|
| 686 | + $atts['product_type'] = 'related'; |
|
| 687 | + if (empty($atts['pid'])) { |
|
| 688 | + $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 689 | + } |
|
| 692 | 690 | |
| 693 | - $output = ''; |
|
| 694 | - if (!empty($related_product_output)) { |
|
| 695 | - ob_start(); |
|
| 696 | - require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 697 | - $output = ob_get_contents(); |
|
| 698 | - ob_end_clean(); |
|
| 699 | - } |
|
| 691 | + $related_product_output = self::wpshop_products_func($atts); |
|
| 700 | 692 | |
| 701 | - return $output; |
|
| 702 | - } |
|
| 693 | + $output = ''; |
|
| 694 | + if (!empty($related_product_output)) { |
|
| 695 | + ob_start(); |
|
| 696 | + require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 697 | + $output = ob_get_contents(); |
|
| 698 | + ob_end_clean(); |
|
| 699 | + } |
|
| 703 | 700 | |
| 704 | - /** |
|
| 705 | - * Display a list of product from a shortcode |
|
| 706 | - * |
|
| 707 | - * @param array $atts { |
|
| 708 | - * limit : The number of element to display |
|
| 709 | - * order : The information to order list by |
|
| 710 | - * sorting : List order (ASC | DESC) |
|
| 711 | - * display : Display size (normal | mini) |
|
| 712 | - * type : Display tyep (grid | list) only work with display=normal |
|
| 713 | - * pagination : The number of element per page |
|
| 714 | - * display_pagination : Display the pagination or not |
|
| 715 | - * } |
|
| 716 | - * |
|
| 717 | - * @return string |
|
| 718 | - * |
|
| 719 | - **/ |
|
| 720 | - public static function wpshop_products_func($atts) |
|
| 721 | - { |
|
| 722 | - global $wpdb, $wp_query; |
|
| 723 | - |
|
| 724 | - $string = ''; |
|
| 725 | - $have_results = false; |
|
| 726 | - $output_results = true; |
|
| 727 | - $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 728 | - $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 729 | - $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 730 | - $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 731 | - $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 732 | - $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 733 | - $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 734 | - $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 735 | - $attr = ''; |
|
| 736 | - |
|
| 737 | - $sorting_criteria = self::get_sorting_criteria(); |
|
| 738 | - |
|
| 739 | - /** Get products which have att_name equal to att_value */ |
|
| 740 | - if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 741 | - $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 742 | - |
|
| 743 | - $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 744 | - |
|
| 745 | - // Foreach on the found products |
|
| 746 | - if (!empty($products)) { |
|
| 747 | - $pid = implode(',', $products); |
|
| 748 | - if (empty($pid)) { |
|
| 749 | - $output_results = false; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - } else { |
|
| 753 | - $output_results = false; |
|
| 754 | - } |
|
| 701 | + return $output; |
|
| 702 | + } |
|
| 755 | 703 | |
| 756 | - } |
|
| 704 | + /** |
|
| 705 | + * Display a list of product from a shortcode |
|
| 706 | + * |
|
| 707 | + * @param array $atts { |
|
| 708 | + * limit : The number of element to display |
|
| 709 | + * order : The information to order list by |
|
| 710 | + * sorting : List order (ASC | DESC) |
|
| 711 | + * display : Display size (normal | mini) |
|
| 712 | + * type : Display tyep (grid | list) only work with display=normal |
|
| 713 | + * pagination : The number of element per page |
|
| 714 | + * display_pagination : Display the pagination or not |
|
| 715 | + * } |
|
| 716 | + * |
|
| 717 | + * @return string |
|
| 718 | + * |
|
| 719 | + **/ |
|
| 720 | + public static function wpshop_products_func($atts) |
|
| 721 | + { |
|
| 722 | + global $wpdb, $wp_query; |
|
| 723 | + |
|
| 724 | + $string = ''; |
|
| 725 | + $have_results = false; |
|
| 726 | + $output_results = true; |
|
| 727 | + $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 728 | + $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 729 | + $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 730 | + $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 731 | + $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 732 | + $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 733 | + $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 734 | + $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 735 | + $attr = ''; |
|
| 736 | + |
|
| 737 | + $sorting_criteria = self::get_sorting_criteria(); |
|
| 738 | + |
|
| 739 | + /** Get products which have att_name equal to att_value */ |
|
| 740 | + if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 741 | + $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 742 | + |
|
| 743 | + $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 744 | + |
|
| 745 | + // Foreach on the found products |
|
| 746 | + if (!empty($products)) { |
|
| 747 | + $pid = implode(',', $products); |
|
| 748 | + if (empty($pid)) { |
|
| 749 | + $output_results = false; |
|
| 750 | + } |
|
| 757 | 751 | |
| 758 | - /** Get related products */ |
|
| 759 | - if (!empty($atts['product_type'])) { |
|
| 760 | - switch ($atts['product_type']) { |
|
| 761 | - case 'related': |
|
| 762 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 763 | - $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 764 | - $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 765 | - |
|
| 766 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 767 | - if (!empty($pids) && !empty($pids[0])) { |
|
| 768 | - $pid = implode(',', $pids); |
|
| 769 | - } |
|
| 770 | - if (empty($pid) || $pid == $product_id) { |
|
| 771 | - $output_results = false; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - break; |
|
| 775 | - } |
|
| 776 | - } |
|
| 752 | + } else { |
|
| 753 | + $output_results = false; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + } |
|
| 777 | 757 | |
| 778 | - /** Output all the products */ |
|
| 779 | - if ($output_results) { |
|
| 780 | - $data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination); |
|
| 758 | + /** Get related products */ |
|
| 759 | + if (!empty($atts['product_type'])) { |
|
| 760 | + switch ($atts['product_type']) { |
|
| 761 | + case 'related': |
|
| 762 | + $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 763 | + $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 764 | + $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 765 | + |
|
| 766 | + $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 767 | + if (!empty($pids) && !empty($pids[0])) { |
|
| 768 | + $pid = implode(',', $pids); |
|
| 769 | + } |
|
| 770 | + if (empty($pid) || $pid == $product_id) { |
|
| 771 | + $output_results = false; |
|
| 772 | + } |
|
| 781 | 773 | |
| 782 | - if ($data[0]) { |
|
| 783 | - $have_results = true; |
|
| 784 | - $string = $data[1]; |
|
| 785 | - } |
|
| 786 | - } |
|
| 774 | + break; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + /** Output all the products */ |
|
| 779 | + if ($output_results) { |
|
| 780 | + $data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination); |
|
| 781 | + |
|
| 782 | + if ($data[0]) { |
|
| 783 | + $have_results = true; |
|
| 784 | + $string = $data[1]; |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + /** If there are result to display */ |
|
| 789 | + if ($have_results) { |
|
| 790 | + $sorting = ''; |
|
| 791 | + if (!empty($pid)) { |
|
| 792 | + $product_list = explode(',', $pid); |
|
| 793 | + if (count($product_list) == 1) { |
|
| 794 | + $atts['sorting'] = 'no'; |
|
| 795 | + } |
|
| 796 | + } |
|
| 787 | 797 | |
| 788 | - /** If there are result to display */ |
|
| 789 | - if ($have_results) { |
|
| 790 | - $sorting = ''; |
|
| 791 | - if (!empty($pid)) { |
|
| 792 | - $product_list = explode(',', $pid); |
|
| 793 | - if (count($product_list) == 1) { |
|
| 794 | - $atts['sorting'] = 'no'; |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - /* |
|
| 798 | + /* |
|
| 799 | 799 | * Template parameters |
| 800 | 800 | */ |
| 801 | - $template_part = 'product_listing_sorting'; |
|
| 802 | - $tpl_component = array(); |
|
| 801 | + $template_part = 'product_listing_sorting'; |
|
| 802 | + $tpl_component = array(); |
|
| 803 | 803 | |
| 804 | - /* |
|
| 804 | + /* |
|
| 805 | 805 | * Build template |
| 806 | 806 | */ |
| 807 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 808 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 809 | - /* Include the old way template part */ |
|
| 810 | - ob_start(); |
|
| 811 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 812 | - $sorting = ob_get_contents(); |
|
| 813 | - ob_end_clean(); |
|
| 814 | - } else { |
|
| 815 | - /* |
|
| 807 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 808 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 809 | + /* Include the old way template part */ |
|
| 810 | + ob_start(); |
|
| 811 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 812 | + $sorting = ob_get_contents(); |
|
| 813 | + ob_end_clean(); |
|
| 814 | + } else { |
|
| 815 | + /* |
|
| 816 | 816 | * Display hidden field every times |
| 817 | 817 | */ |
| 818 | - $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 819 | - $sub_tpl_component = array(); |
|
| 820 | - $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 821 | - $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 822 | - $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 823 | - $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 824 | - $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 825 | - $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 826 | - $sub_tpl_component['ATTR'] = $attr; |
|
| 827 | - $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 828 | - unset($sub_tpl_component); |
|
| 829 | - |
|
| 830 | - if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 831 | - $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 832 | - $sub_tpl_component = array(); |
|
| 833 | - $criteria = ''; |
|
| 834 | - foreach ($sorting_criteria as $c): |
|
| 818 | + $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 819 | + $sub_tpl_component = array(); |
|
| 820 | + $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 821 | + $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 822 | + $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 823 | + $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 824 | + $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 825 | + $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 826 | + $sub_tpl_component['ATTR'] = $attr; |
|
| 827 | + $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 828 | + unset($sub_tpl_component); |
|
| 829 | + |
|
| 830 | + if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 831 | + $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 832 | + $sub_tpl_component = array(); |
|
| 833 | + $criteria = ''; |
|
| 834 | + foreach ($sorting_criteria as $c): |
|
| 835 | 835 | $selected = isset( $atts['order'] ) ? $atts['order'] : null; |
| 836 | - $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 837 | - endforeach; |
|
| 838 | - $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 839 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 840 | - unset($sub_tpl_component); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 844 | - $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 845 | - $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 846 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 847 | - } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 848 | - $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 849 | - $sub_tpl_component = array(); |
|
| 850 | - $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 851 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 852 | - unset($sub_tpl_component); |
|
| 853 | - |
|
| 854 | - $template_part = 'product_listing_sorting_hidden'; |
|
| 855 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - unset($tpl_component); |
|
| 859 | - |
|
| 860 | - if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 861 | - $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 862 | - } else { |
|
| 863 | - $string = '<div class="wpshop_products_block">' . $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div></div>'; |
|
| 864 | - } |
|
| 865 | - } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 866 | - $string = __('There is nothing to output here', 'wpshop'); |
|
| 867 | - } |
|
| 836 | + $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 837 | + endforeach; |
|
| 838 | + $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 839 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 840 | + unset($sub_tpl_component); |
|
| 841 | + } |
|
| 868 | 842 | |
| 869 | - return do_shortcode($string); |
|
| 870 | - } |
|
| 843 | + if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 844 | + $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 845 | + $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 846 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 847 | + } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 848 | + $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 849 | + $sub_tpl_component = array(); |
|
| 850 | + $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 851 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 852 | + unset($sub_tpl_component); |
|
| 853 | + |
|
| 854 | + $template_part = 'product_listing_sorting_hidden'; |
|
| 855 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + unset($tpl_component); |
|
| 871 | 859 | |
| 872 | - public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true) |
|
| 873 | - { |
|
| 874 | - global $wpdb; |
|
| 860 | + if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 861 | + $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 862 | + } else { |
|
| 863 | + $string = '<div class="wpshop_products_block">' . $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div></div>'; |
|
| 864 | + } |
|
| 865 | + } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 866 | + $string = __('There is nothing to output here', 'wpshop'); |
|
| 867 | + } |
|
| 875 | 868 | |
| 876 | - $string = '<span id="wpshop_loading"> </span>'; |
|
| 877 | - $have_results = false; |
|
| 878 | - $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 869 | + return do_shortcode($string); |
|
| 870 | + } |
|
| 879 | 871 | |
| 880 | - /** Check if Discount are activated */ |
|
| 881 | - $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 872 | + public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true) |
|
| 873 | + { |
|
| 874 | + global $wpdb; |
|
| 882 | 875 | |
| 883 | - if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 884 | - $criteria = 'wpshop_displayed_price'; |
|
| 885 | - } |
|
| 876 | + $string = '<span id="wpshop_loading"> </span>'; |
|
| 877 | + $have_results = false; |
|
| 878 | + $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 886 | 879 | |
| 887 | - $query = array( |
|
| 888 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 889 | - 'order' => $order, |
|
| 890 | - 'posts_per_page' => $products_per_page, |
|
| 891 | - 'paged' => $page_number, |
|
| 892 | - 'post_status' => 'publish', |
|
| 893 | - ); |
|
| 894 | - |
|
| 895 | - // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 896 | - if ($nb_of_product_limit > 0) { |
|
| 897 | - $query['posts_per_page'] = $nb_of_product_limit; |
|
| 898 | - unset($query['paged']); |
|
| 899 | - } |
|
| 900 | - if (!empty($pid)) { |
|
| 901 | - if (!is_array($pid)) { |
|
| 902 | - $pid = explode(',', $pid); |
|
| 903 | - } |
|
| 880 | + /** Check if Discount are activated */ |
|
| 881 | + $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 904 | 882 | |
| 905 | - $query['post__in'] = $pid; |
|
| 906 | - } |
|
| 907 | - if (!empty($cid)) { |
|
| 908 | - $cid = explode(',', $cid); |
|
| 909 | - $query['tax_query'] = array(array( |
|
| 910 | - 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 911 | - 'field' => 'id', |
|
| 912 | - 'terms' => $cid, |
|
| 913 | - 'operator' => 'IN', |
|
| 914 | - )); |
|
| 915 | - } |
|
| 916 | - if ($criteria != null) { |
|
| 917 | - switch ($criteria) { |
|
| 918 | - case 'creator': |
|
| 919 | - case 'author': |
|
| 920 | - $query['author'] = get_current_user_id(); |
|
| 921 | - break; |
|
| 922 | - case 'none': |
|
| 923 | - case 'ID': |
|
| 924 | - case 'title': |
|
| 925 | - case 'date': |
|
| 926 | - case 'modified': |
|
| 927 | - case 'relevance': |
|
| 928 | - case 'post__in': |
|
| 929 | - case 'rand': |
|
| 930 | - $query['orderby'] = $criteria; |
|
| 931 | - break; |
|
| 932 | - default: |
|
| 933 | - if (!empty($pid)) { |
|
| 934 | - $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 935 | - } else { |
|
| 936 | - $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 937 | - $post_meta = $wpdb->get_var($check_meta); |
|
| 938 | - } |
|
| 939 | - if (!empty($post_meta)) { |
|
| 940 | - if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 941 | - $query['orderby'] = 'meta_value_num'; |
|
| 942 | - } else { |
|
| 943 | - $query['orderby'] = 'meta_value'; |
|
| 944 | - } |
|
| 945 | - $query['meta_key'] = '_' . $criteria; |
|
| 946 | - } |
|
| 947 | - break; |
|
| 948 | - } |
|
| 949 | - } else { |
|
| 950 | - $query['orderby'] = 'menu_order ID'; |
|
| 951 | - } |
|
| 952 | - $post_per_page = $query['posts_per_page']; |
|
| 953 | - $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 954 | - if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 955 | - $tmp_array = array(); |
|
| 956 | - |
|
| 957 | - if (empty($page_number) || $page_number == 1) { |
|
| 958 | - for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 959 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 960 | - } |
|
| 961 | - } else { |
|
| 962 | - $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 963 | - for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 964 | - if (!empty($query['post__in'][$i])) { |
|
| 965 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - unset($query['post__in']); |
|
| 970 | - $query['post__in'] = $tmp_array; |
|
| 971 | - $query['posts_per_page'] = -1; |
|
| 972 | - } |
|
| 883 | + if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 884 | + $criteria = 'wpshop_displayed_price'; |
|
| 885 | + } |
|
| 973 | 886 | |
| 974 | - $query['post_status'] = 'publish'; |
|
| 975 | - |
|
| 976 | - $custom_query = new WP_Query($query); |
|
| 977 | - |
|
| 978 | - if ($custom_query->have_posts()) { |
|
| 979 | - $have_results = true; |
|
| 980 | - |
|
| 981 | - // ---------------- // |
|
| 982 | - // Products listing // |
|
| 983 | - // ---------------- // |
|
| 984 | - $current_position = 1; |
|
| 985 | - $product_list = ''; |
|
| 986 | - while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 987 | - $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 988 | - $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 989 | - $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 990 | - $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 991 | - $current_position++; |
|
| 992 | - endwhile; |
|
| 993 | - $tpl_component = array(); |
|
| 994 | - $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 995 | - $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 996 | - $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 997 | - $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 998 | - $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 999 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1000 | - $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 1001 | - |
|
| 1002 | - // --------------------- // |
|
| 1003 | - // Pagination management // |
|
| 1004 | - // --------------------- // |
|
| 1005 | - if ( $display_pagination ) { |
|
| 1006 | - if ($nb_of_product_limit == 0) { |
|
| 1007 | - |
|
| 1008 | - $paginate = paginate_links(array( |
|
| 1009 | - 'base' => '%_%', |
|
| 1010 | - 'format' => '/?page_product=%#%', |
|
| 1011 | - 'current' => $page_number, |
|
| 1012 | - 'total' => $custom_query->max_num_pages, |
|
| 1013 | - 'type' => 'array', |
|
| 1014 | - 'prev_next' => false, |
|
| 1015 | - )); |
|
| 1016 | - if (!empty($paginate)) { |
|
| 1017 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 1018 | - foreach ($paginate as $p) { |
|
| 1019 | - $string .= '<li>' . $p . '</li>'; |
|
| 1020 | - } |
|
| 1021 | - $string .= '</ul>'; |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 1026 | - $paginate = paginate_links(array( |
|
| 1027 | - 'base' => '%_%', |
|
| 1028 | - 'format' => '/?page_product=%#%', |
|
| 1029 | - 'current' => $page_number, |
|
| 1030 | - 'total' => ceil(count($total_products) / $post_per_page), |
|
| 1031 | - 'type' => 'array', |
|
| 1032 | - 'prev_next' => false, |
|
| 1033 | - )); |
|
| 1034 | - if (!empty($paginate)) { |
|
| 1035 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 1036 | - foreach ($paginate as $p) { |
|
| 1037 | - $string .= '<li>' . $p . '</li>'; |
|
| 1038 | - } |
|
| 1039 | - $string .= '</ul>'; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 887 | + $query = array( |
|
| 888 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 889 | + 'order' => $order, |
|
| 890 | + 'posts_per_page' => $products_per_page, |
|
| 891 | + 'paged' => $page_number, |
|
| 892 | + 'post_status' => 'publish', |
|
| 893 | + ); |
|
| 894 | + |
|
| 895 | + // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 896 | + if ($nb_of_product_limit > 0) { |
|
| 897 | + $query['posts_per_page'] = $nb_of_product_limit; |
|
| 898 | + unset($query['paged']); |
|
| 899 | + } |
|
| 900 | + if (!empty($pid)) { |
|
| 901 | + if (!is_array($pid)) { |
|
| 902 | + $pid = explode(',', $pid); |
|
| 903 | + } |
|
| 1043 | 904 | |
| 1044 | - } |
|
| 1045 | - wp_reset_query(); // important |
|
| 905 | + $query['post__in'] = $pid; |
|
| 906 | + } |
|
| 907 | + if (!empty($cid)) { |
|
| 908 | + $cid = explode(',', $cid); |
|
| 909 | + $query['tax_query'] = array(array( |
|
| 910 | + 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 911 | + 'field' => 'id', |
|
| 912 | + 'terms' => $cid, |
|
| 913 | + 'operator' => 'IN', |
|
| 914 | + )); |
|
| 915 | + } |
|
| 916 | + if ($criteria != null) { |
|
| 917 | + switch ($criteria) { |
|
| 918 | + case 'creator': |
|
| 919 | + case 'author': |
|
| 920 | + $query['author'] = get_current_user_id(); |
|
| 921 | + break; |
|
| 922 | + case 'none': |
|
| 923 | + case 'ID': |
|
| 924 | + case 'title': |
|
| 925 | + case 'date': |
|
| 926 | + case 'modified': |
|
| 927 | + case 'relevance': |
|
| 928 | + case 'post__in': |
|
| 929 | + case 'rand': |
|
| 930 | + $query['orderby'] = $criteria; |
|
| 931 | + break; |
|
| 932 | + default: |
|
| 933 | + if (!empty($pid)) { |
|
| 934 | + $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 935 | + } else { |
|
| 936 | + $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 937 | + $post_meta = $wpdb->get_var($check_meta); |
|
| 938 | + } |
|
| 939 | + if (!empty($post_meta)) { |
|
| 940 | + if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 941 | + $query['orderby'] = 'meta_value_num'; |
|
| 942 | + } else { |
|
| 943 | + $query['orderby'] = 'meta_value'; |
|
| 944 | + } |
|
| 945 | + $query['meta_key'] = '_' . $criteria; |
|
| 946 | + } |
|
| 947 | + break; |
|
| 948 | + } |
|
| 949 | + } else { |
|
| 950 | + $query['orderby'] = 'menu_order ID'; |
|
| 951 | + } |
|
| 952 | + $post_per_page = $query['posts_per_page']; |
|
| 953 | + $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 954 | + if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 955 | + $tmp_array = array(); |
|
| 956 | + |
|
| 957 | + if (empty($page_number) || $page_number == 1) { |
|
| 958 | + for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 959 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 960 | + } |
|
| 961 | + } else { |
|
| 962 | + $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 963 | + for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 964 | + if (!empty($query['post__in'][$i])) { |
|
| 965 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + unset($query['post__in']); |
|
| 970 | + $query['post__in'] = $tmp_array; |
|
| 971 | + $query['posts_per_page'] = -1; |
|
| 972 | + } |
|
| 1046 | 973 | |
| 1047 | - return array($have_results, $string); |
|
| 1048 | - } |
|
| 974 | + $query['post_status'] = 'publish'; |
|
| 975 | + |
|
| 976 | + $custom_query = new WP_Query($query); |
|
| 977 | + |
|
| 978 | + if ($custom_query->have_posts()) { |
|
| 979 | + $have_results = true; |
|
| 980 | + |
|
| 981 | + // ---------------- // |
|
| 982 | + // Products listing // |
|
| 983 | + // ---------------- // |
|
| 984 | + $current_position = 1; |
|
| 985 | + $product_list = ''; |
|
| 986 | + while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 987 | + $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 988 | + $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 989 | + $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 990 | + $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 991 | + $current_position++; |
|
| 992 | + endwhile; |
|
| 993 | + $tpl_component = array(); |
|
| 994 | + $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 995 | + $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 996 | + $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 997 | + $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 998 | + $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 999 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1000 | + $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 1001 | + |
|
| 1002 | + // --------------------- // |
|
| 1003 | + // Pagination management // |
|
| 1004 | + // --------------------- // |
|
| 1005 | + if ( $display_pagination ) { |
|
| 1006 | + if ($nb_of_product_limit == 0) { |
|
| 1007 | + |
|
| 1008 | + $paginate = paginate_links(array( |
|
| 1009 | + 'base' => '%_%', |
|
| 1010 | + 'format' => '/?page_product=%#%', |
|
| 1011 | + 'current' => $page_number, |
|
| 1012 | + 'total' => $custom_query->max_num_pages, |
|
| 1013 | + 'type' => 'array', |
|
| 1014 | + 'prev_next' => false, |
|
| 1015 | + )); |
|
| 1016 | + if (!empty($paginate)) { |
|
| 1017 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 1018 | + foreach ($paginate as $p) { |
|
| 1019 | + $string .= '<li>' . $p . '</li>'; |
|
| 1020 | + } |
|
| 1021 | + $string .= '</ul>'; |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1049 | 1024 | |
| 1050 | - /** |
|
| 1051 | - * Update quantity for a product |
|
| 1052 | - * @param integer $product_id The product we want to update quantity for |
|
| 1053 | - * @param decimal $qty The new quantity |
|
| 1054 | - */ |
|
| 1055 | - public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') |
|
| 1056 | - { |
|
| 1057 | - global $wpdb; |
|
| 1058 | - |
|
| 1059 | - $product = self::get_product_data($product_id); |
|
| 1060 | - /** Check if there is variation ***/ |
|
| 1061 | - if (!empty($variation_id) && $variation_id != $product_id) { |
|
| 1062 | - $variation_post_type = get_post_type($variation_id); |
|
| 1063 | - if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1064 | - /** Check if variation def is combined **/ |
|
| 1065 | - $variations = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1066 | - if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) { |
|
| 1067 | - /** Get post meta of variation */ |
|
| 1068 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1069 | - if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) { |
|
| 1070 | - $product = self::get_product_data($variation_id); |
|
| 1071 | - $product_id = $variation_id; |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - } |
|
| 1025 | + if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 1026 | + $paginate = paginate_links(array( |
|
| 1027 | + 'base' => '%_%', |
|
| 1028 | + 'format' => '/?page_product=%#%', |
|
| 1029 | + 'current' => $page_number, |
|
| 1030 | + 'total' => ceil(count($total_products) / $post_per_page), |
|
| 1031 | + 'type' => 'array', |
|
| 1032 | + 'prev_next' => false, |
|
| 1033 | + )); |
|
| 1034 | + if (!empty($paginate)) { |
|
| 1035 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 1036 | + foreach ($paginate as $p) { |
|
| 1037 | + $string .= '<li>' . $p . '</li>'; |
|
| 1038 | + } |
|
| 1039 | + $string .= '</ul>'; |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + } |
|
| 1045 | + wp_reset_query(); // important |
|
| 1076 | 1046 | |
| 1077 | - if (!empty($product)) { |
|
| 1078 | - $newQty = $product['product_stock'] - $qty; |
|
| 1079 | - $value_id = 0; |
|
| 1080 | - if ($newQty >= 0) { |
|
| 1081 | - $query = ' |
|
| 1047 | + return array($have_results, $string); |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + /** |
|
| 1051 | + * Update quantity for a product |
|
| 1052 | + * @param integer $product_id The product we want to update quantity for |
|
| 1053 | + * @param decimal $qty The new quantity |
|
| 1054 | + */ |
|
| 1055 | + public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') |
|
| 1056 | + { |
|
| 1057 | + global $wpdb; |
|
| 1058 | + |
|
| 1059 | + $product = self::get_product_data($product_id); |
|
| 1060 | + /** Check if there is variation ***/ |
|
| 1061 | + if (!empty($variation_id) && $variation_id != $product_id) { |
|
| 1062 | + $variation_post_type = get_post_type($variation_id); |
|
| 1063 | + if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1064 | + /** Check if variation def is combined **/ |
|
| 1065 | + $variations = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1066 | + if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) { |
|
| 1067 | + /** Get post meta of variation */ |
|
| 1068 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1069 | + if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) { |
|
| 1070 | + $product = self::get_product_data($variation_id); |
|
| 1071 | + $product_id = $variation_id; |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + if (!empty($product)) { |
|
| 1078 | + $newQty = $product['product_stock'] - $qty; |
|
| 1079 | + $value_id = 0; |
|
| 1080 | + if ($newQty >= 0) { |
|
| 1081 | + $query = ' |
|
| 1082 | 1082 | SELECT wp_wpshop__attribute_value_decimal.value_id |
| 1083 | 1083 | FROM wp_wpshop__attribute_value_decimal |
| 1084 | 1084 | LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id |
| 1085 | 1085 | WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock" |
| 1086 | 1086 | LIMIT 1 |
| 1087 | 1087 | '; |
| 1088 | - $value_id = $wpdb->get_var($query); |
|
| 1089 | - $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id)); |
|
| 1090 | - } |
|
| 1091 | - // Historic |
|
| 1092 | - $attribute_histo_content = array(); |
|
| 1093 | - $attribute_histo_content['status'] = 'valid'; |
|
| 1094 | - $attribute_histo_content['creation_date'] = current_time('mysql', 0); |
|
| 1095 | - $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0); |
|
| 1096 | - $attribute_histo_content['original_value_id'] = $value_id; |
|
| 1097 | - $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1098 | - $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code'); |
|
| 1099 | - $attribute_histo_content['attribute_id'] = $stock_atribute->id; |
|
| 1100 | - $attribute_histo_content['entity_id'] = $product_id; |
|
| 1101 | - $attribute_histo_content['value'] = $product['product_stock']; |
|
| 1102 | - $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal'; |
|
| 1103 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content); |
|
| 1104 | - |
|
| 1105 | - $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 1106 | - $product_meta['product_stock'] = $newQty; |
|
| 1107 | - update_post_meta($product_id, '_wpshop_product_metadata', $product_meta); |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1088 | + $value_id = $wpdb->get_var($query); |
|
| 1089 | + $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id)); |
|
| 1090 | + } |
|
| 1091 | + // Historic |
|
| 1092 | + $attribute_histo_content = array(); |
|
| 1093 | + $attribute_histo_content['status'] = 'valid'; |
|
| 1094 | + $attribute_histo_content['creation_date'] = current_time('mysql', 0); |
|
| 1095 | + $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0); |
|
| 1096 | + $attribute_histo_content['original_value_id'] = $value_id; |
|
| 1097 | + $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1098 | + $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code'); |
|
| 1099 | + $attribute_histo_content['attribute_id'] = $stock_atribute->id; |
|
| 1100 | + $attribute_histo_content['entity_id'] = $product_id; |
|
| 1101 | + $attribute_histo_content['value'] = $product['product_stock']; |
|
| 1102 | + $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal'; |
|
| 1103 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content); |
|
| 1104 | + |
|
| 1105 | + $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 1106 | + $product_meta['product_stock'] = $newQty; |
|
| 1107 | + update_post_meta($product_id, '_wpshop_product_metadata', $product_meta); |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | 1110 | |
| 1111 | - /** |
|
| 1112 | - * Retrieve an array with complete information about a given product |
|
| 1113 | - * @param integer $product_id |
|
| 1114 | - * @param boolean $for_cart_storage |
|
| 1115 | - * @return array Information about the product defined by first parameter |
|
| 1116 | - */ |
|
| 1117 | - public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1118 | - { |
|
| 1119 | - global $wpdb; |
|
| 1120 | - $query = $wpdb->prepare(' |
|
| 1111 | + /** |
|
| 1112 | + * Retrieve an array with complete information about a given product |
|
| 1113 | + * @param integer $product_id |
|
| 1114 | + * @param boolean $for_cart_storage |
|
| 1115 | + * @return array Information about the product defined by first parameter |
|
| 1116 | + */ |
|
| 1117 | + public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1118 | + { |
|
| 1119 | + global $wpdb; |
|
| 1120 | + $query = $wpdb->prepare(' |
|
| 1121 | 1121 | SELECT P.*, PM.meta_value AS attribute_set_id |
| 1122 | 1122 | FROM ' . $wpdb->posts . ' AS P |
| 1123 | 1123 | INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID) |
@@ -1129,398 +1129,398 @@ discard block |
||
| 1129 | 1129 | LIMIT 1 |
| 1130 | 1130 | ', $product_id); |
| 1131 | 1131 | |
| 1132 | - $product = $wpdb->get_row($query); |
|
| 1133 | - |
|
| 1134 | - $product_data = array(); |
|
| 1135 | - $product_meta = array(); |
|
| 1136 | - |
|
| 1137 | - if (!empty($product)) { |
|
| 1138 | - $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1139 | - $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1140 | - $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1141 | - $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1142 | - |
|
| 1143 | - $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1144 | - $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1145 | - $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1146 | - $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1147 | - |
|
| 1148 | - $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1149 | - |
|
| 1150 | - $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $product->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1151 | - if (!empty($data)) { |
|
| 1152 | - foreach ($data as $attribute) { |
|
| 1153 | - $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1154 | - $value = $attribute->$data_type; |
|
| 1155 | - if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1156 | - $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - /** Special traitment regarding attribute_code */ |
|
| 1160 | - switch ($attribute->attribute_code) { |
|
| 1161 | - case 'product_weight': |
|
| 1162 | - $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1163 | - if (!empty($default_weight_unity)) { |
|
| 1164 | - $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1165 | - $unity = $wpdb->get_var($query); |
|
| 1166 | - if ($unity == 'kg') { |
|
| 1167 | - $value *= 1000; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - } |
|
| 1171 | - break; |
|
| 1172 | - default: |
|
| 1173 | - $value = !empty($value) ? $value : 0; |
|
| 1174 | - break; |
|
| 1175 | - } |
|
| 1176 | - $product_data[$attribute->attribute_code] = $value; |
|
| 1177 | - |
|
| 1178 | - if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1179 | - $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1180 | - if (!empty($meta)) { |
|
| 1181 | - $product_meta[$attribute->attribute_code] = $meta; |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1186 | - $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1187 | - } |
|
| 1188 | - if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1189 | - $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - } else { |
|
| 1193 | - |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - /** Get datas about product options */ |
|
| 1197 | - if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1198 | - $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1199 | - |
|
| 1200 | - foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1201 | - $variation_id = $attribute_value; |
|
| 1202 | - $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1203 | - |
|
| 1204 | - $product_meta['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true)); |
|
| 1205 | - $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1206 | - switch ($attribute_definition->backend_input) { |
|
| 1207 | - case 'select': |
|
| 1208 | - case 'multiple-select': |
|
| 1209 | - case 'radio': |
|
| 1210 | - case 'checkbox': |
|
| 1211 | - $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1212 | - break; |
|
| 1213 | - } |
|
| 1214 | - $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1215 | - $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1216 | - } |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1220 | - |
|
| 1221 | - /** Get the display definition for the current product for checking custom display */ |
|
| 1222 | - $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1223 | - } |
|
| 1132 | + $product = $wpdb->get_row($query); |
|
| 1224 | 1133 | |
| 1225 | - return $product_data; |
|
| 1226 | - } |
|
| 1134 | + $product_data = array(); |
|
| 1135 | + $product_meta = array(); |
|
| 1227 | 1136 | |
| 1228 | - /** |
|
| 1229 | - * Add a product into the db. This function is used for the EDI |
|
| 1230 | - * @param $name Name of the product |
|
| 1231 | - * @param $description Description of the product |
|
| 1232 | - * @param $attrs List of the attributes and values of the product |
|
| 1233 | - * @return boolean |
|
| 1234 | - */ |
|
| 1235 | - public function addProduct($name, $description, $attrs = array()) |
|
| 1236 | - { |
|
| 1237 | - $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1238 | - return $new_product[0]; |
|
| 1239 | - } |
|
| 1137 | + if (!empty($product)) { |
|
| 1138 | + $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1139 | + $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1140 | + $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1141 | + $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1240 | 1142 | |
| 1241 | - /** |
|
| 1242 | - * Retrieve a product listing |
|
| 1243 | - * @param boolean $formated If the output have to be formated or not |
|
| 1244 | - * @param string $product_search Optionnal Define a search term for request |
|
| 1245 | - * @return object|string If $formated is set to true will display an html output with all product. Else return a wordpress database object with the product list |
|
| 1246 | - */ |
|
| 1247 | - public static function product_list($formated = false, $product_search = null) |
|
| 1248 | - { |
|
| 1249 | - global $wpdb; |
|
| 1250 | - |
|
| 1251 | - $query_extra_params = $query_extra_params_value = ''; |
|
| 1252 | - if (!empty($product_search)) { |
|
| 1253 | - $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1254 | - if (is_array($product_search)) { |
|
| 1255 | - $query_extra_params = " AND ID IN (%s)"; |
|
| 1256 | - $query_extra_params_value = implode(",", $product_search); |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1143 | + $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1144 | + $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1145 | + $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1146 | + $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1147 | + |
|
| 1148 | + $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1149 | + |
|
| 1150 | + $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $product->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1151 | + if (!empty($data)) { |
|
| 1152 | + foreach ($data as $attribute) { |
|
| 1153 | + $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1154 | + $value = $attribute->$data_type; |
|
| 1155 | + if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1156 | + $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + /** Special traitment regarding attribute_code */ |
|
| 1160 | + switch ($attribute->attribute_code) { |
|
| 1161 | + case 'product_weight': |
|
| 1162 | + $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1163 | + if (!empty($default_weight_unity)) { |
|
| 1164 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1165 | + $unity = $wpdb->get_var($query); |
|
| 1166 | + if ($unity == 'kg') { |
|
| 1167 | + $value *= 1000; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + } |
|
| 1171 | + break; |
|
| 1172 | + default: |
|
| 1173 | + $value = !empty($value) ? $value : 0; |
|
| 1174 | + break; |
|
| 1175 | + } |
|
| 1176 | + $product_data[$attribute->attribute_code] = $value; |
|
| 1177 | + |
|
| 1178 | + if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1179 | + $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1180 | + if (!empty($meta)) { |
|
| 1181 | + $product_meta[$attribute->attribute_code] = $meta; |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1186 | + $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1187 | + } |
|
| 1188 | + if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1189 | + $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + } else { |
|
| 1193 | + |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + /** Get datas about product options */ |
|
| 1197 | + if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1198 | + $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1199 | + |
|
| 1200 | + foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1201 | + $variation_id = $attribute_value; |
|
| 1202 | + $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1203 | + |
|
| 1204 | + $product_meta['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true)); |
|
| 1205 | + $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1206 | + switch ($attribute_definition->backend_input) { |
|
| 1207 | + case 'select': |
|
| 1208 | + case 'multiple-select': |
|
| 1209 | + case 'radio': |
|
| 1210 | + case 'checkbox': |
|
| 1211 | + $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1212 | + break; |
|
| 1213 | + } |
|
| 1214 | + $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1215 | + $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1216 | + } |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1220 | + |
|
| 1221 | + /** Get the display definition for the current product for checking custom display */ |
|
| 1222 | + $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $product_data; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + /** |
|
| 1229 | + * Add a product into the db. This function is used for the EDI |
|
| 1230 | + * @param $name Name of the product |
|
| 1231 | + * @param $description Description of the product |
|
| 1232 | + * @param $attrs List of the attributes and values of the product |
|
| 1233 | + * @return boolean |
|
| 1234 | + */ |
|
| 1235 | + public function addProduct($name, $description, $attrs = array()) |
|
| 1236 | + { |
|
| 1237 | + $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1238 | + return $new_product[0]; |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * Retrieve a product listing |
|
| 1243 | + * @param boolean $formated If the output have to be formated or not |
|
| 1244 | + * @param string $product_search Optionnal Define a search term for request |
|
| 1245 | + * @return object|string If $formated is set to true will display an html output with all product. Else return a wordpress database object with the product list |
|
| 1246 | + */ |
|
| 1247 | + public static function product_list($formated = false, $product_search = null) |
|
| 1248 | + { |
|
| 1249 | + global $wpdb; |
|
| 1250 | + |
|
| 1251 | + $query_extra_params = $query_extra_params_value = ''; |
|
| 1252 | + if (!empty($product_search)) { |
|
| 1253 | + $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1254 | + if (is_array($product_search)) { |
|
| 1255 | + $query_extra_params = " AND ID IN (%s)"; |
|
| 1256 | + $query_extra_params_value = implode(",", $product_search); |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | 1259 | |
| 1260 | - $query = $wpdb->prepare("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s" . $query_extra_params, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish', $query_extra_params_value); |
|
| 1261 | - $data = $wpdb->get_results($query); |
|
| 1260 | + $query = $wpdb->prepare("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s" . $query_extra_params, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish', $query_extra_params_value); |
|
| 1261 | + $data = $wpdb->get_results($query); |
|
| 1262 | 1262 | |
| 1263 | - /* |
|
| 1263 | + /* |
|
| 1264 | 1264 | * Make some arangement on output if parameter is given |
| 1265 | 1265 | */ |
| 1266 | - if ($formated) { |
|
| 1267 | - $product_string = ''; |
|
| 1268 | - foreach ($data as $d) { |
|
| 1269 | - $product_string .= ' |
|
| 1266 | + if ($formated) { |
|
| 1267 | + $product_string = ''; |
|
| 1268 | + foreach ($data as $d) { |
|
| 1269 | + $product_string .= ' |
|
| 1270 | 1270 | <li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" > |
| 1271 | 1271 | <input type="checkbox" class="wpshop_shortcode_element wpshop_shortcode_element_product" value="' . $d->ID . '" id="' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '-' . $d->ID . '" name="products[]" /><label for="' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '-' . $d->ID . '" > ' . $d->post_title . '</label> |
| 1272 | 1272 | </li>'; |
| 1273 | - } |
|
| 1274 | - } |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | 1275 | |
| 1276 | - return $formated ? $product_string : $data; |
|
| 1277 | - } |
|
| 1276 | + return $formated ? $product_string : $data; |
|
| 1277 | + } |
|
| 1278 | 1278 | |
| 1279 | - /** |
|
| 1280 | - * Enregistrement des données pour le produit |
|
| 1281 | - */ |
|
| 1282 | - public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1283 | - { |
|
| 1284 | - global $wpdb; |
|
| 1285 | - |
|
| 1286 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1287 | - // Apply a filter to extra actions |
|
| 1288 | - $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1289 | - |
|
| 1290 | - if (!empty($data_to_save['post_ID']) && ((get_post_type($data_to_save['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || (get_post_type($data_to_save['post_ID']) == "free_product"))) { |
|
| 1291 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1292 | - /* Fill the product reference automatically if nothing is sent */ |
|
| 1293 | - if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1294 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1295 | - $last_ref = $wpdb->get_var($query); |
|
| 1296 | - $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref; |
|
| 1297 | - } else { |
|
| 1298 | - /* Check if the product reference existing in the database */ |
|
| 1299 | - $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1300 | - $query = $wpdb->prepare( |
|
| 1301 | - "SELECT value_id |
|
| 1279 | + /** |
|
| 1280 | + * Enregistrement des données pour le produit |
|
| 1281 | + */ |
|
| 1282 | + public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1283 | + { |
|
| 1284 | + global $wpdb; |
|
| 1285 | + |
|
| 1286 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1287 | + // Apply a filter to extra actions |
|
| 1288 | + $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1289 | + |
|
| 1290 | + if (!empty($data_to_save['post_ID']) && ((get_post_type($data_to_save['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || (get_post_type($data_to_save['post_ID']) == "free_product"))) { |
|
| 1291 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1292 | + /* Fill the product reference automatically if nothing is sent */ |
|
| 1293 | + if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1294 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1295 | + $last_ref = $wpdb->get_var($query); |
|
| 1296 | + $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref; |
|
| 1297 | + } else { |
|
| 1298 | + /* Check if the product reference existing in the database */ |
|
| 1299 | + $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1300 | + $query = $wpdb->prepare( |
|
| 1301 | + "SELECT value_id |
|
| 1302 | 1302 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
| 1303 | 1303 | INNER JOIN {$wpdb->posts} ON ( ID = entity_id ) |
| 1304 | 1304 | WHERE value = %s |
| 1305 | 1305 | AND entity_id != %d |
| 1306 | 1306 | AND entity_type_id = %d" |
| 1307 | - , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1308 | - $existing_reference = $wpdb->get_var($query); |
|
| 1309 | - |
|
| 1310 | - /* If this product reference exist -> Create a new product reference */ |
|
| 1311 | - if ($wpdb->num_rows > 0) { |
|
| 1312 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1313 | - $last_ref = $wpdb->get_var($query); |
|
| 1314 | - $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref; |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - /* Save the attributes values into wpshop eav database */ |
|
| 1319 | - $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1320 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1321 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1322 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1323 | - $lang = $wpdb->get_var($query); |
|
| 1324 | - } |
|
| 1325 | - wpshop_attributes::saveAttributeForEntity($data_to_save[wpshop_products::currentPageCode . '_attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $data_to_save['post_ID'], $lang, $update_from); |
|
| 1326 | - |
|
| 1327 | - /* Update product price looking for shop parameters */ |
|
| 1328 | - wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1329 | - |
|
| 1330 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1331 | - $productMetaDatas = array(); |
|
| 1332 | - foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1333 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1334 | - if ($attributeCode == 'product_attribute_set_id') { |
|
| 1335 | - /* Update the attribute set id for the current product */ |
|
| 1336 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1337 | - } |
|
| 1338 | - if ($attributeType == 'decimal') { |
|
| 1339 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1340 | - } |
|
| 1341 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1342 | - $attributeValue = (int) $attributeValue; |
|
| 1343 | - } |
|
| 1344 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1351 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1352 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1353 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1357 | - if (empty($product['product_id'])) { |
|
| 1358 | - $product['product_id'] = $data_to_save['post_ID']; |
|
| 1359 | - } |
|
| 1360 | - $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1361 | - update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1362 | - |
|
| 1363 | - /** Save product variation */ |
|
| 1364 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1365 | - foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1366 | - |
|
| 1367 | - foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1368 | - $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1369 | - if (!empty($variation_definition) && !empty($variation_definition['attribute']) && is_object($price_attr_def) && !empty($variation_definition['attribute'][$price_attr_def->data_type]) && is_array($variation_definition['attribute'][$price_attr_def->data_type]) && !array_key_exists($price_attribute_code, $variation_definition['attribute'][$price_attr_def->data_type])) { |
|
| 1370 | - $variation_definition['attribute'][$price_attr_def->data_type][$price_attribute_code] = !empty($data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code]) ? $data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code] : 0; |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1374 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1375 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1376 | - $lang = $wpdb->get_var($query); |
|
| 1377 | - } |
|
| 1378 | - wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1379 | - |
|
| 1380 | - /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1381 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1382 | - if (!empty($variation_metadata)) { |
|
| 1383 | - $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1384 | - if (!empty($attributes_list)) { |
|
| 1385 | - foreach ($attributes_list as $attribute) { |
|
| 1386 | - $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1387 | - $attributeValue = $attribute->$value_key; |
|
| 1388 | - if ($attribute->data_type == 'decimal') { |
|
| 1389 | - $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1390 | - } |
|
| 1391 | - if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1392 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1393 | - } |
|
| 1394 | - $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1400 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1401 | - if ($attributeType == 'decimal') { |
|
| 1402 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1403 | - } |
|
| 1404 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1405 | - $attributeValue = (int) $attributeValue; |
|
| 1406 | - } |
|
| 1407 | - $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1411 | - |
|
| 1412 | - /** Save attached picture id **/ |
|
| 1413 | - $attached_picture_id = (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id'])) ? intval($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id']) : ''; |
|
| 1414 | - $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1415 | - |
|
| 1416 | - /* Update product price looking for shop parameters */ |
|
| 1417 | - wpshop_products::calculate_price($variation_id); |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - /* Update the related products list*/ |
|
| 1422 | - if (!empty($data_to_save['related_products_list'])) { |
|
| 1423 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1424 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1425 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1426 | - } |
|
| 1427 | - /* Update the provider list*/ |
|
| 1428 | - if (!empty($data_to_save['provider_list'])) { |
|
| 1429 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1430 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1431 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - /* Update product options */ |
|
| 1435 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1436 | - update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1437 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1438 | - delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - /** Add flag on variations to check which type of variation **/ |
|
| 1442 | - $check_product_have_variations = self::get_variation($post_id); |
|
| 1443 | - if (!empty($check_product_have_variations)) { |
|
| 1444 | - $variation_flag = self::check_variation_type($post_id); |
|
| 1445 | - $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1446 | - $variation_defining['variation_type'] = $variation_flag; |
|
| 1447 | - update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1448 | - } |
|
| 1449 | - add_post_meta($post_id, '_wpshop_variation_defining', array('follow_general_config' => true, 'options' => array('priority' => array('combined'), 'price_behaviour' => array('replacement'), 'price_display' => (!empty($catalog_product_option) && !empty($catalog_product_option['price_display'])) ? $catalog_product_option['price_display'] : array('text_from' => 'on', 'lower_price' => 'on'))), true); |
|
| 1450 | - } |
|
| 1307 | + , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1308 | + $existing_reference = $wpdb->get_var($query); |
|
| 1309 | + |
|
| 1310 | + /* If this product reference exist -> Create a new product reference */ |
|
| 1311 | + if ($wpdb->num_rows > 0) { |
|
| 1312 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1313 | + $last_ref = $wpdb->get_var($query); |
|
| 1314 | + $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1451 | 1317 | |
| 1452 | - flush_rewrite_rules(); |
|
| 1453 | - } |
|
| 1318 | + /* Save the attributes values into wpshop eav database */ |
|
| 1319 | + $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1320 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1321 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1322 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1323 | + $lang = $wpdb->get_var($query); |
|
| 1324 | + } |
|
| 1325 | + wpshop_attributes::saveAttributeForEntity($data_to_save[wpshop_products::currentPageCode . '_attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $data_to_save['post_ID'], $lang, $update_from); |
|
| 1326 | + |
|
| 1327 | + /* Update product price looking for shop parameters */ |
|
| 1328 | + wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1329 | + |
|
| 1330 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1331 | + $productMetaDatas = array(); |
|
| 1332 | + foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1333 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1334 | + if ($attributeCode == 'product_attribute_set_id') { |
|
| 1335 | + /* Update the attribute set id for the current product */ |
|
| 1336 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1337 | + } |
|
| 1338 | + if ($attributeType == 'decimal') { |
|
| 1339 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1340 | + } |
|
| 1341 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1342 | + $attributeValue = (int) $attributeValue; |
|
| 1343 | + } |
|
| 1344 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1348 | + } |
|
| 1454 | 1349 | |
| 1455 | - /** |
|
| 1456 | - * Return the variation type |
|
| 1457 | - * @param integer $post_id |
|
| 1458 | - * @return string |
|
| 1459 | - */ |
|
| 1460 | - public function check_variation_type($post_id) |
|
| 1461 | - { |
|
| 1462 | - $variation_type = 'single'; |
|
| 1463 | - if (!empty($variation_type)) { |
|
| 1464 | - $variations = self::get_variation($post_id); |
|
| 1465 | - if (!empty($variations)) { |
|
| 1466 | - foreach ($variations as $variation_id => $variation_data) { |
|
| 1467 | - if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1468 | - return 'single'; |
|
| 1469 | - } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1470 | - $variation_type = 'combined'; |
|
| 1471 | - } |
|
| 1472 | - } |
|
| 1473 | - } |
|
| 1474 | - } |
|
| 1475 | - return $variation_type; |
|
| 1476 | - } |
|
| 1350 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1351 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1352 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1353 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1354 | + } |
|
| 1477 | 1355 | |
| 1478 | - /** |
|
| 1479 | - * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1480 | - * |
|
| 1481 | - * @param mixed $permalink The actual permalink of the element |
|
| 1482 | - * @param object $post The post we want to set the permalink for |
|
| 1483 | - * @param void |
|
| 1484 | - * |
|
| 1485 | - * @return mixed The new permalink for the current element |
|
| 1486 | - */ |
|
| 1487 | - public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1488 | - { |
|
| 1489 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1490 | - |
|
| 1491 | - if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1492 | - if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1493 | - return $permalink; |
|
| 1494 | - } else { |
|
| 1495 | - $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1496 | - $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1497 | - if (empty($product_categories)) { |
|
| 1498 | - $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1499 | - } else { |
|
| 1500 | - $product_category_slug = $product_categories[0]->slug; |
|
| 1501 | - } |
|
| 1502 | - $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1503 | - } |
|
| 1504 | - } |
|
| 1356 | + $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1357 | + if (empty($product['product_id'])) { |
|
| 1358 | + $product['product_id'] = $data_to_save['post_ID']; |
|
| 1359 | + } |
|
| 1360 | + $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1361 | + update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1362 | + |
|
| 1363 | + /** Save product variation */ |
|
| 1364 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1365 | + foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1366 | + |
|
| 1367 | + foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1368 | + $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1369 | + if (!empty($variation_definition) && !empty($variation_definition['attribute']) && is_object($price_attr_def) && !empty($variation_definition['attribute'][$price_attr_def->data_type]) && is_array($variation_definition['attribute'][$price_attr_def->data_type]) && !array_key_exists($price_attribute_code, $variation_definition['attribute'][$price_attr_def->data_type])) { |
|
| 1370 | + $variation_definition['attribute'][$price_attr_def->data_type][$price_attribute_code] = !empty($data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code]) ? $data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code] : 0; |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1374 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1375 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1376 | + $lang = $wpdb->get_var($query); |
|
| 1377 | + } |
|
| 1378 | + wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1379 | + |
|
| 1380 | + /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1381 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1382 | + if (!empty($variation_metadata)) { |
|
| 1383 | + $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1384 | + if (!empty($attributes_list)) { |
|
| 1385 | + foreach ($attributes_list as $attribute) { |
|
| 1386 | + $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1387 | + $attributeValue = $attribute->$value_key; |
|
| 1388 | + if ($attribute->data_type == 'decimal') { |
|
| 1389 | + $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1390 | + } |
|
| 1391 | + if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1392 | + $attributeValue = (int) $attribute->$value_key; |
|
| 1393 | + } |
|
| 1394 | + $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + } |
|
| 1505 | 1398 | |
| 1506 | - return $permalink; |
|
| 1399 | + foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1400 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1401 | + if ($attributeType == 'decimal') { |
|
| 1402 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1403 | + } |
|
| 1404 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1405 | + $attributeValue = (int) $attributeValue; |
|
| 1406 | + } |
|
| 1407 | + $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1507 | 1411 | |
| 1508 | - //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1412 | + /** Save attached picture id **/ |
|
| 1413 | + $attached_picture_id = (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id'])) ? intval($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id']) : ''; |
|
| 1414 | + $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1509 | 1415 | |
| 1510 | - //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1416 | + /* Update product price looking for shop parameters */ |
|
| 1417 | + wpshop_products::calculate_price($variation_id); |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1511 | 1420 | |
| 1512 | - /*if(false) { |
|
| 1513 | - global $wp_query; |
|
| 1514 | - $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES ); |
|
| 1421 | + /* Update the related products list*/ |
|
| 1422 | + if (!empty($data_to_save['related_products_list'])) { |
|
| 1423 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1424 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1425 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1426 | + } |
|
| 1427 | + /* Update the provider list*/ |
|
| 1428 | + if (!empty($data_to_save['provider_list'])) { |
|
| 1429 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1430 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1431 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + /* Update product options */ |
|
| 1435 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1436 | + update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1437 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1438 | + delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + /** Add flag on variations to check which type of variation **/ |
|
| 1442 | + $check_product_have_variations = self::get_variation($post_id); |
|
| 1443 | + if (!empty($check_product_have_variations)) { |
|
| 1444 | + $variation_flag = self::check_variation_type($post_id); |
|
| 1445 | + $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1446 | + $variation_defining['variation_type'] = $variation_flag; |
|
| 1447 | + update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1448 | + } |
|
| 1449 | + add_post_meta($post_id, '_wpshop_variation_defining', array('follow_general_config' => true, 'options' => array('priority' => array('combined'), 'price_behaviour' => array('replacement'), 'price_display' => (!empty($catalog_product_option) && !empty($catalog_product_option['price_display'])) ? $catalog_product_option['price_display'] : array('text_from' => 'on', 'lower_price' => 'on'))), true); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + flush_rewrite_rules(); |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + /** |
|
| 1456 | + * Return the variation type |
|
| 1457 | + * @param integer $post_id |
|
| 1458 | + * @return string |
|
| 1459 | + */ |
|
| 1460 | + public function check_variation_type($post_id) |
|
| 1461 | + { |
|
| 1462 | + $variation_type = 'single'; |
|
| 1463 | + if (!empty($variation_type)) { |
|
| 1464 | + $variations = self::get_variation($post_id); |
|
| 1465 | + if (!empty($variations)) { |
|
| 1466 | + foreach ($variations as $variation_id => $variation_data) { |
|
| 1467 | + if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1468 | + return 'single'; |
|
| 1469 | + } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1470 | + $variation_type = 'combined'; |
|
| 1471 | + } |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + } |
|
| 1475 | + return $variation_type; |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + /** |
|
| 1479 | + * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1480 | + * |
|
| 1481 | + * @param mixed $permalink The actual permalink of the element |
|
| 1482 | + * @param object $post The post we want to set the permalink for |
|
| 1483 | + * @param void |
|
| 1484 | + * |
|
| 1485 | + * @return mixed The new permalink for the current element |
|
| 1486 | + */ |
|
| 1487 | + public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1488 | + { |
|
| 1489 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1490 | + |
|
| 1491 | + if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1492 | + if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1493 | + return $permalink; |
|
| 1494 | + } else { |
|
| 1495 | + $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1496 | + $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1497 | + if (empty($product_categories)) { |
|
| 1498 | + $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1499 | + } else { |
|
| 1500 | + $product_category_slug = $product_categories[0]->slug; |
|
| 1501 | + } |
|
| 1502 | + $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1503 | + } |
|
| 1504 | + } |
|
| 1505 | + |
|
| 1506 | + return $permalink; |
|
| 1507 | + |
|
| 1508 | + //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1509 | + |
|
| 1510 | + //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1511 | + |
|
| 1512 | + /*if(false) { |
|
| 1513 | + global $wp_query; |
|
| 1514 | + $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES ); |
|
| 1515 | 1515 | |
| 1516 | 1516 | if(count($product_categories) == 0){ /* Product has only one category we get the only available slug */ |
| 1517 | - /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1517 | + /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1518 | 1518 | } |
| 1519 | 1519 | elseif(count($product_categories) == 1){ /* Product has only one category we get the only available slug */ |
| 1520 | - /* $product_category_slug = $product_categories[0]->slug; |
|
| 1520 | + /* $product_category_slug = $product_categories[0]->slug; |
|
| 1521 | 1521 | } |
| 1522 | 1522 | else{ /* Product has several categories choose the slug of the we want */ |
| 1523 | - /* $product_category_slugs = array(); |
|
| 1523 | + /* $product_category_slugs = array(); |
|
| 1524 | 1524 | foreach($product_categories as $product_category){ |
| 1525 | 1525 | $product_category_slugs[] = $product_category->slug; |
| 1526 | 1526 | } |
@@ -1530,457 +1530,457 @@ discard block |
||
| 1530 | 1530 | $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
| 1531 | 1531 | return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID ); |
| 1532 | 1532 | }*/ |
| 1533 | - } |
|
| 1533 | + } |
|
| 1534 | 1534 | |
| 1535 | - public static function set_product_request_by_name($query) |
|
| 1536 | - { |
|
| 1537 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1535 | + public static function set_product_request_by_name($query) |
|
| 1536 | + { |
|
| 1537 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1538 | 1538 | |
| 1539 | - if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1540 | - // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1541 | - } |
|
| 1539 | + if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1540 | + // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1541 | + } |
|
| 1542 | 1542 | |
| 1543 | - /** |
|
| 1544 | - * Define output for product |
|
| 1545 | - * |
|
| 1546 | - * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1547 | - * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1548 | - * |
|
| 1549 | - * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1550 | - */ |
|
| 1551 | - public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1552 | - { |
|
| 1553 | - $content = $attributeContentOutput = ''; |
|
| 1554 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1555 | - /** Log number of view for the current product */ |
|
| 1556 | - $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1557 | - $product_view_number++; |
|
| 1558 | - update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1559 | - |
|
| 1560 | - /** Get product definition */ |
|
| 1561 | - |
|
| 1562 | - $product = self::get_product_data($product_id); |
|
| 1563 | - wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1564 | - |
|
| 1565 | - /** Get the product thumbnail */ |
|
| 1566 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1567 | - if (has_post_thumbnail($product_id)) { |
|
| 1568 | - $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1569 | - $tpl_component = array(); |
|
| 1570 | - $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1571 | - $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1572 | - $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1573 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1574 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1575 | - foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1576 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1577 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE; |
|
| 1578 | - } |
|
| 1579 | - } |
|
| 1580 | - $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = (!empty($tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'])) ? $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] : WPSHOP_DEFAULT_PRODUCT_PICTURE; |
|
| 1581 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1582 | - unset($tpl_component); |
|
| 1583 | - } |
|
| 1543 | + /** |
|
| 1544 | + * Define output for product |
|
| 1545 | + * |
|
| 1546 | + * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1547 | + * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1548 | + * |
|
| 1549 | + * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1550 | + */ |
|
| 1551 | + public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1552 | + { |
|
| 1553 | + $content = $attributeContentOutput = ''; |
|
| 1554 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1555 | + /** Log number of view for the current product */ |
|
| 1556 | + $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1557 | + $product_view_number++; |
|
| 1558 | + update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1559 | + |
|
| 1560 | + /** Get product definition */ |
|
| 1561 | + |
|
| 1562 | + $product = self::get_product_data($product_id); |
|
| 1563 | + wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1564 | + |
|
| 1565 | + /** Get the product thumbnail */ |
|
| 1566 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1567 | + if (has_post_thumbnail($product_id)) { |
|
| 1568 | + $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1569 | + $tpl_component = array(); |
|
| 1570 | + $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1571 | + $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1572 | + $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1573 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1574 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1575 | + foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1576 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1577 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE; |
|
| 1578 | + } |
|
| 1579 | + } |
|
| 1580 | + $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = (!empty($tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'])) ? $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] : WPSHOP_DEFAULT_PRODUCT_PICTURE; |
|
| 1581 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1582 | + unset($tpl_component); |
|
| 1583 | + } |
|
| 1584 | 1584 | |
| 1585 | - $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1586 | - |
|
| 1587 | - /** Retrieve product attributes for output */ |
|
| 1588 | - $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1589 | - |
|
| 1590 | - /** Retrieve product price */ |
|
| 1591 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1592 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1593 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1594 | - $productPrice = ''; |
|
| 1595 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1596 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1597 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1598 | - if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) { |
|
| 1599 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1600 | - } |
|
| 1585 | + $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1586 | + |
|
| 1587 | + /** Retrieve product attributes for output */ |
|
| 1588 | + $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1589 | + |
|
| 1590 | + /** Retrieve product price */ |
|
| 1591 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1592 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1593 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1594 | + $productPrice = ''; |
|
| 1595 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1596 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1597 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1598 | + if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) { |
|
| 1599 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1600 | + } |
|
| 1601 | 1601 | |
| 1602 | - /** Check if there is at less 1 product in stock */ |
|
| 1603 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1604 | - $productStock = ($productStock === true) ? 1 : null; |
|
| 1602 | + /** Check if there is at less 1 product in stock */ |
|
| 1603 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1604 | + $productStock = ($productStock === true) ? 1 : null; |
|
| 1605 | 1605 | |
| 1606 | - /** if !product stock check product have variation with stock **/ |
|
| 1606 | + /** if !product stock check product have variation with stock **/ |
|
| 1607 | 1607 | // if ( empty($productStock) ) { |
| 1608 | - $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1609 | - if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1610 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1611 | - if (!empty($variations)) { |
|
| 1612 | - foreach ($variations as $variation) { |
|
| 1613 | - if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1614 | - $productStock = 1; |
|
| 1615 | - } |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1618 | - } |
|
| 1608 | + $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1609 | + if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1610 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1611 | + if (!empty($variations)) { |
|
| 1612 | + foreach ($variations as $variation) { |
|
| 1613 | + if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1614 | + $productStock = 1; |
|
| 1615 | + } |
|
| 1616 | + } |
|
| 1617 | + } |
|
| 1618 | + } |
|
| 1619 | 1619 | // } |
| 1620 | 1620 | |
| 1621 | - /** Define "Add to cart" button */ |
|
| 1622 | - $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'complete_sheet'); |
|
| 1623 | - $display_price_state_when_price_is_empty = true; |
|
| 1624 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1625 | - $display_price_state_when_price_is_empty = false; |
|
| 1626 | - } else if (!empty($productPrice)) { |
|
| 1627 | - $display_price_state_when_price_is_empty = true; |
|
| 1628 | - } |
|
| 1629 | - $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'complete') : ''; |
|
| 1630 | - $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : ''; |
|
| 1631 | - |
|
| 1632 | - /** Define "Ask a quotation" button */ |
|
| 1633 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1634 | - |
|
| 1635 | - /** Template parameters */ |
|
| 1636 | - $template_part = 'product_complete_tpl'; |
|
| 1637 | - $tpl_component = array(); |
|
| 1638 | - |
|
| 1639 | - $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1640 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1641 | - $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1642 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1643 | - $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1644 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1645 | - $modules_option = get_option('wpshop_modules'); |
|
| 1646 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1647 | - if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1648 | - $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1649 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1650 | - } |
|
| 1621 | + /** Define "Add to cart" button */ |
|
| 1622 | + $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'complete_sheet'); |
|
| 1623 | + $display_price_state_when_price_is_empty = true; |
|
| 1624 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1625 | + $display_price_state_when_price_is_empty = false; |
|
| 1626 | + } else if (!empty($productPrice)) { |
|
| 1627 | + $display_price_state_when_price_is_empty = true; |
|
| 1628 | + } |
|
| 1629 | + $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'complete') : ''; |
|
| 1630 | + $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : ''; |
|
| 1631 | + |
|
| 1632 | + /** Define "Ask a quotation" button */ |
|
| 1633 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1634 | + |
|
| 1635 | + /** Template parameters */ |
|
| 1636 | + $template_part = 'product_complete_tpl'; |
|
| 1637 | + $tpl_component = array(); |
|
| 1638 | + |
|
| 1639 | + $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1640 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1641 | + $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1642 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1643 | + $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1644 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1645 | + $modules_option = get_option('wpshop_modules'); |
|
| 1646 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1647 | + if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1648 | + $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1649 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1650 | + } |
|
| 1651 | 1651 | |
| 1652 | - /** Gallery **/ |
|
| 1653 | - $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1654 | - |
|
| 1655 | - $product_new_def = self::display_product_special_state('declare_new', 'complete', (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : '')); |
|
| 1656 | - |
|
| 1657 | - $product_new = $product_new_def['output']; |
|
| 1658 | - $product_class = $product_new_def['class']; |
|
| 1659 | - |
|
| 1660 | - $product_featured_def = self::display_product_special_state('highlight_product', 'complete', (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : '')); |
|
| 1661 | - $product_featured = $product_featured_def['output']; |
|
| 1662 | - $product_class .= $product_featured_def['class']; |
|
| 1663 | - |
|
| 1664 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1665 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1666 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1667 | - |
|
| 1668 | - $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1669 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1670 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1671 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1672 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1673 | - $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1674 | - $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1675 | - $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1676 | - |
|
| 1677 | - /** Build template */ |
|
| 1678 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1679 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1680 | - /* Include the old way template part */ |
|
| 1681 | - ob_start(); |
|
| 1682 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1683 | - $content = ob_get_contents(); |
|
| 1684 | - ob_end_clean(); |
|
| 1685 | - } else { |
|
| 1686 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1687 | - } |
|
| 1688 | - unset($tpl_component); |
|
| 1689 | - return $content; |
|
| 1690 | - } |
|
| 1652 | + /** Gallery **/ |
|
| 1653 | + $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1654 | + |
|
| 1655 | + $product_new_def = self::display_product_special_state('declare_new', 'complete', (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : '')); |
|
| 1656 | + |
|
| 1657 | + $product_new = $product_new_def['output']; |
|
| 1658 | + $product_class = $product_new_def['class']; |
|
| 1659 | + |
|
| 1660 | + $product_featured_def = self::display_product_special_state('highlight_product', 'complete', (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : '')); |
|
| 1661 | + $product_featured = $product_featured_def['output']; |
|
| 1662 | + $product_class .= $product_featured_def['class']; |
|
| 1663 | + |
|
| 1664 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1665 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1666 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1667 | + |
|
| 1668 | + $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1669 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1670 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1671 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1672 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1673 | + $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1674 | + $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1675 | + $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1676 | + |
|
| 1677 | + /** Build template */ |
|
| 1678 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1679 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1680 | + /* Include the old way template part */ |
|
| 1681 | + ob_start(); |
|
| 1682 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1683 | + $content = ob_get_contents(); |
|
| 1684 | + ob_end_clean(); |
|
| 1685 | + } else { |
|
| 1686 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1687 | + } |
|
| 1688 | + unset($tpl_component); |
|
| 1689 | + return $content; |
|
| 1690 | + } |
|
| 1691 | 1691 | |
| 1692 | - public static function product_mini_output($product_id, $category_id, $output_type = 'list', $current_item_position = 1, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE) |
|
| 1693 | - { |
|
| 1694 | - $content = ''; |
|
| 1695 | - $product_information = $product_class = ''; |
|
| 1692 | + public static function product_mini_output($product_id, $category_id, $output_type = 'list', $current_item_position = 1, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE) |
|
| 1693 | + { |
|
| 1694 | + $content = ''; |
|
| 1695 | + $product_information = $product_class = ''; |
|
| 1696 | 1696 | |
| 1697 | - /** Get the product thumbnail */ |
|
| 1698 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1699 | - if (has_post_thumbnail($product_id)) { |
|
| 1700 | - $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1701 | - } |
|
| 1697 | + /** Get the product thumbnail */ |
|
| 1698 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1699 | + if (has_post_thumbnail($product_id)) { |
|
| 1700 | + $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1701 | + } |
|
| 1702 | 1702 | |
| 1703 | - $product = self::get_product_data($product_id); |
|
| 1703 | + $product = self::get_product_data($product_id); |
|
| 1704 | 1704 | |
| 1705 | - /** Get the product information for output */ |
|
| 1706 | - if (!empty($product)) { |
|
| 1705 | + /** Get the product information for output */ |
|
| 1706 | + if (!empty($product)) { |
|
| 1707 | 1707 | |
| 1708 | - $product_title = $product['post_title']; |
|
| 1709 | - $product_name = $product['post_name']; |
|
| 1710 | - $product_link = get_permalink($product_id); |
|
| 1711 | - $product_more_informations = $product['product_content']; |
|
| 1712 | - $product_excerpt = $product['product_excerpt']; |
|
| 1708 | + $product_title = $product['post_title']; |
|
| 1709 | + $product_name = $product['post_name']; |
|
| 1710 | + $product_link = get_permalink($product_id); |
|
| 1711 | + $product_more_informations = $product['product_content']; |
|
| 1712 | + $product_excerpt = $product['product_excerpt']; |
|
| 1713 | 1713 | |
| 1714 | - if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1715 | - $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1716 | - $product_more_informations = $post_content[0]; |
|
| 1717 | - } |
|
| 1714 | + if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1715 | + $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1716 | + $product_more_informations = $post_content[0]; |
|
| 1717 | + } |
|
| 1718 | 1718 | |
| 1719 | - } else { |
|
| 1720 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1721 | - $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1722 | - $product_link = ''; |
|
| 1723 | - $product_more_informations = ''; |
|
| 1724 | - $product_excerpt = ''; |
|
| 1725 | - } |
|
| 1719 | + } else { |
|
| 1720 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1721 | + $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1722 | + $product_link = ''; |
|
| 1723 | + $product_more_informations = ''; |
|
| 1724 | + $product_excerpt = ''; |
|
| 1725 | + } |
|
| 1726 | 1726 | |
| 1727 | - /** Retrieve product price */ |
|
| 1728 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1729 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1730 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1731 | - $productPrice = ''; |
|
| 1732 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1733 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1734 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1735 | - if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) { |
|
| 1736 | - $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1737 | - |
|
| 1738 | - if (!empty($product_price_infos)) { |
|
| 1739 | - $tpl_component_price = array(); |
|
| 1740 | - /** Price piloting **/ |
|
| 1727 | + /** Retrieve product price */ |
|
| 1728 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1729 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1730 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1731 | + $productPrice = ''; |
|
| 1732 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1733 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1734 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1735 | + if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) { |
|
| 1736 | + $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1737 | + |
|
| 1738 | + if (!empty($product_price_infos)) { |
|
| 1739 | + $tpl_component_price = array(); |
|
| 1740 | + /** Price piloting **/ |
|
| 1741 | 1741 | $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
| 1742 | 1742 | $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
| 1743 | - $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1744 | - $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : ''; |
|
| 1745 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1743 | + $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1744 | + $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : ''; |
|
| 1745 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1746 | 1746 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1747 | 1747 | if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
| 1748 | 1748 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1749 | 1749 | } |
| 1750 | - $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1751 | - $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1752 | - $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1753 | - $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1754 | - } else { |
|
| 1755 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1756 | - } |
|
| 1757 | - } |
|
| 1750 | + $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1751 | + $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1752 | + $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1753 | + $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1754 | + } else { |
|
| 1755 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1756 | + } |
|
| 1757 | + } |
|
| 1758 | 1758 | |
| 1759 | - /** Check if there is at less 1 product in stock */ |
|
| 1760 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1761 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1762 | - $productStock = $productStock === true ? 1 : null; |
|
| 1763 | - |
|
| 1764 | - /** Define "Add to cart" button */ |
|
| 1765 | - $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'mini_output'); |
|
| 1766 | - $display_price_state_when_price_is_empty = false; |
|
| 1767 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1768 | - $display_price_state_when_price_is_empty = false; |
|
| 1769 | - } else if (!empty($productPrice)) { |
|
| 1770 | - $display_price_state_when_price_is_empty = true; |
|
| 1771 | - } |
|
| 1772 | - $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'mini') : ''; |
|
| 1773 | - $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : ''; |
|
| 1759 | + /** Check if there is at less 1 product in stock */ |
|
| 1760 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1761 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1762 | + $productStock = $productStock === true ? 1 : null; |
|
| 1763 | + |
|
| 1764 | + /** Define "Add to cart" button */ |
|
| 1765 | + $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'mini_output'); |
|
| 1766 | + $display_price_state_when_price_is_empty = false; |
|
| 1767 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1768 | + $display_price_state_when_price_is_empty = false; |
|
| 1769 | + } else if (!empty($productPrice)) { |
|
| 1770 | + $display_price_state_when_price_is_empty = true; |
|
| 1771 | + } |
|
| 1772 | + $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'mini') : ''; |
|
| 1773 | + $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : ''; |
|
| 1774 | 1774 | |
| 1775 | - /** Define "Ask a quotation" button */ |
|
| 1776 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1777 | - $product_new_def = self::display_product_special_state('declare_new', $output_type, (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : '')); |
|
| 1775 | + /** Define "Ask a quotation" button */ |
|
| 1776 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1777 | + $product_new_def = self::display_product_special_state('declare_new', $output_type, (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : '')); |
|
| 1778 | 1778 | |
| 1779 | - $product_new = $product_new_def['output']; |
|
| 1780 | - $product_class .= $product_new_def['class']; |
|
| 1779 | + $product_new = $product_new_def['output']; |
|
| 1780 | + $product_class .= $product_new_def['class']; |
|
| 1781 | 1781 | |
| 1782 | - $product_featured_def = self::display_product_special_state('highlight_product', $output_type, (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : '')); |
|
| 1783 | - $product_featured = $product_featured_def['output']; |
|
| 1784 | - $product_class .= $product_featured_def['class']; |
|
| 1782 | + $product_featured_def = self::display_product_special_state('highlight_product', $output_type, (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : '')); |
|
| 1783 | + $product_featured = $product_featured_def['output']; |
|
| 1784 | + $product_class .= $product_featured_def['class']; |
|
| 1785 | 1785 | |
| 1786 | - if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1787 | - $product_class .= ' wpshop_last_product_of_line'; |
|
| 1788 | - } |
|
| 1786 | + if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1787 | + $product_class .= ' wpshop_last_product_of_line'; |
|
| 1788 | + } |
|
| 1789 | 1789 | |
| 1790 | - if (!empty($product['product_id'])) { |
|
| 1791 | - /** Template parameters */ |
|
| 1792 | - $template_part = 'product_mini_' . $output_type; |
|
| 1793 | - $tpl_component = array(); |
|
| 1794 | - $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1795 | - $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1796 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1797 | - $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1798 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1799 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1800 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1801 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1802 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1803 | - $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1804 | - $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1805 | - $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1806 | - $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1807 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1808 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1809 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1810 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1811 | - |
|
| 1812 | - if (has_post_thumbnail($product_id)) { |
|
| 1813 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1814 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1815 | - $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1816 | - foreach ($existing_image_sizes as $size_name) { |
|
| 1817 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1818 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE; |
|
| 1819 | - } |
|
| 1820 | - } |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1824 | - $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1825 | - $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1826 | - |
|
| 1827 | - /** Build template */ |
|
| 1828 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1829 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1830 | - /** Include the old way template part */ |
|
| 1831 | - ob_start(); |
|
| 1832 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1833 | - $content = ob_get_contents(); |
|
| 1834 | - ob_end_clean(); |
|
| 1835 | - } else { |
|
| 1836 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1837 | - } |
|
| 1838 | - unset($tpl_component); |
|
| 1790 | + if (!empty($product['product_id'])) { |
|
| 1791 | + /** Template parameters */ |
|
| 1792 | + $template_part = 'product_mini_' . $output_type; |
|
| 1793 | + $tpl_component = array(); |
|
| 1794 | + $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1795 | + $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1796 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1797 | + $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1798 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1799 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1800 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1801 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1802 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1803 | + $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1804 | + $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1805 | + $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1806 | + $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1807 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1808 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1809 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1810 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1811 | + |
|
| 1812 | + if (has_post_thumbnail($product_id)) { |
|
| 1813 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1814 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1815 | + $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1816 | + foreach ($existing_image_sizes as $size_name) { |
|
| 1817 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1818 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE; |
|
| 1819 | + } |
|
| 1820 | + } |
|
| 1821 | + } |
|
| 1839 | 1822 | |
| 1840 | - } |
|
| 1823 | + $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1824 | + $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1825 | + $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1826 | + |
|
| 1827 | + /** Build template */ |
|
| 1828 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1829 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1830 | + /** Include the old way template part */ |
|
| 1831 | + ob_start(); |
|
| 1832 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1833 | + $content = ob_get_contents(); |
|
| 1834 | + ob_end_clean(); |
|
| 1835 | + } else { |
|
| 1836 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1837 | + } |
|
| 1838 | + unset($tpl_component); |
|
| 1841 | 1839 | |
| 1842 | - return $content; |
|
| 1843 | - } |
|
| 1840 | + } |
|
| 1844 | 1841 | |
| 1845 | - /** |
|
| 1846 | - * Get the products (post) of a given category |
|
| 1847 | - * |
|
| 1848 | - * @param string $category_slug The category slug we want to get the product list for |
|
| 1849 | - * |
|
| 1850 | - * @return mixed $widget_content The output for the product list |
|
| 1851 | - */ |
|
| 1852 | - public static function get_product_of_category($category_slug, $category_id) |
|
| 1853 | - { |
|
| 1854 | - global $top_categories; |
|
| 1855 | - $widget_content = ''; |
|
| 1856 | - $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1857 | - if (false == $products) { |
|
| 1858 | - $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1859 | - $products = get_posts($args); |
|
| 1860 | - wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1861 | - } |
|
| 1862 | - if (is_array($products) && (count($products) > 0)) { |
|
| 1863 | - foreach ($products as $product) { |
|
| 1864 | - if ($product->post_status == "publish") { |
|
| 1865 | - ob_start(); |
|
| 1866 | - require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1867 | - $widget_content .= ob_get_contents(); |
|
| 1868 | - ob_end_clean(); |
|
| 1869 | - } |
|
| 1870 | - } |
|
| 1871 | - } |
|
| 1842 | + return $content; |
|
| 1843 | + } |
|
| 1872 | 1844 | |
| 1873 | - echo $widget_content; |
|
| 1874 | - } |
|
| 1845 | + /** |
|
| 1846 | + * Get the products (post) of a given category |
|
| 1847 | + * |
|
| 1848 | + * @param string $category_slug The category slug we want to get the product list for |
|
| 1849 | + * |
|
| 1850 | + * @return mixed $widget_content The output for the product list |
|
| 1851 | + */ |
|
| 1852 | + public static function get_product_of_category($category_slug, $category_id) |
|
| 1853 | + { |
|
| 1854 | + global $top_categories; |
|
| 1855 | + $widget_content = ''; |
|
| 1856 | + $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1857 | + if (false == $products) { |
|
| 1858 | + $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1859 | + $products = get_posts($args); |
|
| 1860 | + wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1861 | + } |
|
| 1862 | + if (is_array($products) && (count($products) > 0)) { |
|
| 1863 | + foreach ($products as $product) { |
|
| 1864 | + if ($product->post_status == "publish") { |
|
| 1865 | + ob_start(); |
|
| 1866 | + require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1867 | + $widget_content .= ob_get_contents(); |
|
| 1868 | + ob_end_clean(); |
|
| 1869 | + } |
|
| 1870 | + } |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + echo $widget_content; |
|
| 1874 | + } |
|
| 1875 | 1875 | |
| 1876 | - /** |
|
| 1877 | - * |
|
| 1878 | - * @param unknown_type $selected_product |
|
| 1879 | - * @return string |
|
| 1880 | - */ |
|
| 1881 | - public function custom_product_list($selected_product = array()) |
|
| 1882 | - { |
|
| 1883 | - global $wpdb; |
|
| 1884 | - |
|
| 1885 | - /* Start the table definition */ |
|
| 1886 | - $tableId = 'wpshop_product_list'; |
|
| 1887 | - $tableTitles = array(); |
|
| 1888 | - $tableTitles[] = ''; |
|
| 1889 | - $tableTitles[] = __('Id', 'wpshop'); |
|
| 1890 | - $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1891 | - $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1892 | - $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1893 | - $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1894 | - $tableTitles[] = __('Price', 'wpshop'); |
|
| 1895 | - $tableClasses = array(); |
|
| 1896 | - $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1897 | - $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1898 | - $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1899 | - $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1900 | - $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1901 | - $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1902 | - $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1903 | - |
|
| 1904 | - /* Get post list */ |
|
| 1905 | - $has_result = false; |
|
| 1906 | - $current_line_index = 0; |
|
| 1907 | - $posts = query_posts(array( |
|
| 1908 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1909 | - )); |
|
| 1910 | - if (!empty($posts)) { |
|
| 1911 | - $has_result = true; |
|
| 1912 | - foreach ($posts as $post) { |
|
| 1913 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1914 | - |
|
| 1915 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1916 | - |
|
| 1917 | - unset($tableRowValue); |
|
| 1918 | - $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />'); |
|
| 1919 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1920 | - $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>'); |
|
| 1921 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1922 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1923 | - $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/> |
|
| 1876 | + /** |
|
| 1877 | + * |
|
| 1878 | + * @param unknown_type $selected_product |
|
| 1879 | + * @return string |
|
| 1880 | + */ |
|
| 1881 | + public function custom_product_list($selected_product = array()) |
|
| 1882 | + { |
|
| 1883 | + global $wpdb; |
|
| 1884 | + |
|
| 1885 | + /* Start the table definition */ |
|
| 1886 | + $tableId = 'wpshop_product_list'; |
|
| 1887 | + $tableTitles = array(); |
|
| 1888 | + $tableTitles[] = ''; |
|
| 1889 | + $tableTitles[] = __('Id', 'wpshop'); |
|
| 1890 | + $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1891 | + $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1892 | + $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1893 | + $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1894 | + $tableTitles[] = __('Price', 'wpshop'); |
|
| 1895 | + $tableClasses = array(); |
|
| 1896 | + $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1897 | + $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1898 | + $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1899 | + $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1900 | + $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1901 | + $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1902 | + $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1903 | + |
|
| 1904 | + /* Get post list */ |
|
| 1905 | + $has_result = false; |
|
| 1906 | + $current_line_index = 0; |
|
| 1907 | + $posts = query_posts(array( |
|
| 1908 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1909 | + )); |
|
| 1910 | + if (!empty($posts)) { |
|
| 1911 | + $has_result = true; |
|
| 1912 | + foreach ($posts as $post) { |
|
| 1913 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1914 | + |
|
| 1915 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1916 | + |
|
| 1917 | + unset($tableRowValue); |
|
| 1918 | + $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />'); |
|
| 1919 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1920 | + $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>'); |
|
| 1921 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1922 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1923 | + $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/> |
|
| 1924 | 1924 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1925 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1926 | - $tableRows[] = $tableRowValue; |
|
| 1925 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1926 | + $tableRows[] = $tableRowValue; |
|
| 1927 | 1927 | |
| 1928 | - $current_line_index++; |
|
| 1929 | - } |
|
| 1930 | - wp_reset_query(); |
|
| 1931 | - } |
|
| 1932 | - $posts = query_posts(array( |
|
| 1933 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1934 | - )); |
|
| 1935 | - if (!empty($posts)) { |
|
| 1936 | - $has_result = true; |
|
| 1937 | - foreach ($posts as $post) { |
|
| 1938 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1939 | - |
|
| 1940 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1941 | - |
|
| 1942 | - unset($tableRowValue); |
|
| 1943 | - $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />'); |
|
| 1944 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1945 | - $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>'); |
|
| 1946 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1947 | - $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1948 | - if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1949 | - $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1950 | - $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1951 | - $option_name = $wpdb->get_var($query); |
|
| 1952 | - $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1953 | - $option_value = $wpdb->get_var($query); |
|
| 1954 | - $parent_post = $parent_product['parent_post']; |
|
| 1955 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1956 | - } else { |
|
| 1957 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1958 | - } |
|
| 1959 | - |
|
| 1960 | - $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/> |
|
| 1928 | + $current_line_index++; |
|
| 1929 | + } |
|
| 1930 | + wp_reset_query(); |
|
| 1931 | + } |
|
| 1932 | + $posts = query_posts(array( |
|
| 1933 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1934 | + )); |
|
| 1935 | + if (!empty($posts)) { |
|
| 1936 | + $has_result = true; |
|
| 1937 | + foreach ($posts as $post) { |
|
| 1938 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1939 | + |
|
| 1940 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1941 | + |
|
| 1942 | + unset($tableRowValue); |
|
| 1943 | + $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />'); |
|
| 1944 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1945 | + $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>'); |
|
| 1946 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1947 | + $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1948 | + if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1949 | + $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1950 | + $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1951 | + $option_name = $wpdb->get_var($query); |
|
| 1952 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1953 | + $option_value = $wpdb->get_var($query); |
|
| 1954 | + $parent_post = $parent_product['parent_post']; |
|
| 1955 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1956 | + } else { |
|
| 1957 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/> |
|
| 1961 | 1961 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1962 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1963 | - $tableRows[] = $tableRowValue; |
|
| 1962 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1963 | + $tableRows[] = $tableRowValue; |
|
| 1964 | 1964 | |
| 1965 | - $current_line_index++; |
|
| 1966 | - } |
|
| 1967 | - wp_reset_query(); |
|
| 1968 | - } |
|
| 1965 | + $current_line_index++; |
|
| 1966 | + } |
|
| 1967 | + wp_reset_query(); |
|
| 1968 | + } |
|
| 1969 | 1969 | |
| 1970 | - if (!$has_result) { |
|
| 1971 | - $tableRowsId[] = 'no_product_found'; |
|
| 1972 | - unset($tableRowValue); |
|
| 1973 | - $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1974 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1975 | - $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1976 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1977 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1978 | - $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1979 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1980 | - $tableRows[] = $tableRowValue; |
|
| 1981 | - } |
|
| 1970 | + if (!$has_result) { |
|
| 1971 | + $tableRowsId[] = 'no_product_found'; |
|
| 1972 | + unset($tableRowValue); |
|
| 1973 | + $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1974 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1975 | + $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1976 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1977 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1978 | + $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1979 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1980 | + $tableRows[] = $tableRowValue; |
|
| 1981 | + } |
|
| 1982 | 1982 | |
| 1983 | - return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1983 | + return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1984 | 1984 | <script type="text/javascript" > |
| 1985 | 1985 | wpshop(document).ready(function(){ |
| 1986 | 1986 | jQuery("#' . $tableId . '").dataTable( { |
@@ -1989,1534 +1989,1534 @@ discard block |
||
| 1989 | 1989 | }); |
| 1990 | 1990 | }); |
| 1991 | 1991 | </script>'; |
| 1992 | - } |
|
| 1992 | + } |
|
| 1993 | 1993 | |
| 1994 | - /** |
|
| 1995 | - * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1996 | - * |
|
| 1997 | - * @param string $special The type of special type we want to output |
|
| 1998 | - * @param string $output_type The current display type (used for product listing) |
|
| 1999 | - * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 2000 | - * @param datetime $special_state_start The start date if applicable for the special state |
|
| 2001 | - * @param datetime $special_state_end The end date if applicable for the special state |
|
| 2002 | - * |
|
| 2003 | - * @return array $product_special_state The product special state |
|
| 2004 | - */ |
|
| 2005 | - public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 2006 | - { |
|
| 2007 | - $product_special_state = array(); |
|
| 2008 | - $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 2009 | - |
|
| 2010 | - /** Get product special state definition */ |
|
| 2011 | - $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 2012 | - $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 2013 | - $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 2014 | - |
|
| 2015 | - /** Get current time */ |
|
| 2016 | - $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 2017 | - |
|
| 2018 | - /** PRODUCT MARK AS NEW */ |
|
| 2019 | - $show_product_special_state = false; |
|
| 2020 | - if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 2021 | - (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 2022 | - (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 2023 | - $show_product_special_state = true; |
|
| 2024 | - } |
|
| 1994 | + /** |
|
| 1995 | + * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1996 | + * |
|
| 1997 | + * @param string $special The type of special type we want to output |
|
| 1998 | + * @param string $output_type The current display type (used for product listing) |
|
| 1999 | + * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 2000 | + * @param datetime $special_state_start The start date if applicable for the special state |
|
| 2001 | + * @param datetime $special_state_end The end date if applicable for the special state |
|
| 2002 | + * |
|
| 2003 | + * @return array $product_special_state The product special state |
|
| 2004 | + */ |
|
| 2005 | + public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 2006 | + { |
|
| 2007 | + $product_special_state = array(); |
|
| 2008 | + $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 2009 | + |
|
| 2010 | + /** Get product special state definition */ |
|
| 2011 | + $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 2012 | + $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 2013 | + $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 2014 | + |
|
| 2015 | + /** Get current time */ |
|
| 2016 | + $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 2017 | + |
|
| 2018 | + /** PRODUCT MARK AS NEW */ |
|
| 2019 | + $show_product_special_state = false; |
|
| 2020 | + if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 2021 | + (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 2022 | + (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 2023 | + $show_product_special_state = true; |
|
| 2024 | + } |
|
| 2025 | 2025 | |
| 2026 | - if ($show_product_special_state) { |
|
| 2027 | - /** Check the type of special output needed */ |
|
| 2028 | - switch ($special) { |
|
| 2029 | - case 'declare_new': |
|
| 2030 | - $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 2031 | - $template_part = 'product_is_new_sticker'; |
|
| 2032 | - break; |
|
| 2033 | - |
|
| 2034 | - case 'highlight_product': |
|
| 2035 | - $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 2036 | - $template_part = 'product_is_featured_sticker'; |
|
| 2037 | - break; |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - /** Template parameters */ |
|
| 2041 | - $tpl_component = array(); |
|
| 2042 | - |
|
| 2043 | - /** Build template */ |
|
| 2044 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2045 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2046 | - /** Include the old way template part */ |
|
| 2047 | - ob_start(); |
|
| 2048 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2049 | - $product_special_state['output'] = ob_get_contents(); |
|
| 2050 | - ob_end_clean(); |
|
| 2051 | - } else { |
|
| 2052 | - $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2053 | - } |
|
| 2054 | - unset($tpl_component); |
|
| 2055 | - } |
|
| 2026 | + if ($show_product_special_state) { |
|
| 2027 | + /** Check the type of special output needed */ |
|
| 2028 | + switch ($special) { |
|
| 2029 | + case 'declare_new': |
|
| 2030 | + $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 2031 | + $template_part = 'product_is_new_sticker'; |
|
| 2032 | + break; |
|
| 2056 | 2033 | |
| 2057 | - return $product_special_state; |
|
| 2058 | - } |
|
| 2034 | + case 'highlight_product': |
|
| 2035 | + $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 2036 | + $template_part = 'product_is_featured_sticker'; |
|
| 2037 | + break; |
|
| 2038 | + } |
|
| 2059 | 2039 | |
| 2060 | - /** |
|
| 2061 | - * Prepare product price for saving and easier read later |
|
| 2062 | - * |
|
| 2063 | - * @param integer $element_id Identifier of current product |
|
| 2064 | - */ |
|
| 2065 | - public static function calculate_price($element_id) |
|
| 2066 | - { |
|
| 2067 | - global $wpdb; |
|
| 2068 | - |
|
| 2069 | - /** |
|
| 2070 | - * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2071 | - * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2072 | - * price_ht and tva |
|
| 2073 | - */ |
|
| 2074 | - $query = $wpdb->prepare( |
|
| 2075 | - "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2040 | + /** Template parameters */ |
|
| 2041 | + $tpl_component = array(); |
|
| 2042 | + |
|
| 2043 | + /** Build template */ |
|
| 2044 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2045 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2046 | + /** Include the old way template part */ |
|
| 2047 | + ob_start(); |
|
| 2048 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2049 | + $product_special_state['output'] = ob_get_contents(); |
|
| 2050 | + ob_end_clean(); |
|
| 2051 | + } else { |
|
| 2052 | + $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2053 | + } |
|
| 2054 | + unset($tpl_component); |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + return $product_special_state; |
|
| 2058 | + } |
|
| 2059 | + |
|
| 2060 | + /** |
|
| 2061 | + * Prepare product price for saving and easier read later |
|
| 2062 | + * |
|
| 2063 | + * @param integer $element_id Identifier of current product |
|
| 2064 | + */ |
|
| 2065 | + public static function calculate_price($element_id) |
|
| 2066 | + { |
|
| 2067 | + global $wpdb; |
|
| 2068 | + |
|
| 2069 | + /** |
|
| 2070 | + * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2071 | + * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2072 | + * price_ht and tva |
|
| 2073 | + */ |
|
| 2074 | + $query = $wpdb->prepare( |
|
| 2075 | + "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2076 | 2076 | FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR |
| 2077 | 2077 | RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d)) |
| 2078 | 2078 | WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')", |
| 2079 | - $element_id |
|
| 2080 | - ); |
|
| 2081 | - $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2082 | - |
|
| 2083 | - /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2084 | - if (empty($prices_attribute)) { |
|
| 2085 | - return false; |
|
| 2086 | - } else { |
|
| 2087 | - /** |
|
| 2088 | - * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2089 | - * the base amount according on the shop price control |
|
| 2090 | - */ |
|
| 2091 | - $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2092 | - $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2093 | - $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2094 | - |
|
| 2095 | - /** |
|
| 2096 | - * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2097 | - * create an attribute |
|
| 2098 | - */ |
|
| 2099 | - $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2100 | - $language = WPSHOP_CURRENT_LOCALE; |
|
| 2101 | - $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2102 | - |
|
| 2103 | - if (!empty($icl_post_language)) { |
|
| 2104 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2105 | - $language = $wpdb->get_var($query); |
|
| 2106 | - } |
|
| 2107 | - |
|
| 2108 | - /** |
|
| 2109 | - * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2110 | - * Check configuration to know how to make the calcul for the product |
|
| 2111 | - */ |
|
| 2112 | - if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2113 | - $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2114 | - $price_no_vat = $base_price; |
|
| 2115 | - } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2116 | - $price_with_vat = $base_price; |
|
| 2117 | - $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2118 | - } |
|
| 2119 | - |
|
| 2120 | - /** |
|
| 2121 | - * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2122 | - * type que celui-ci / The last parameter allows not to delete the |
|
| 2123 | - * attributes of the same type as this one |
|
| 2124 | - */ |
|
| 2125 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2126 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2127 | - |
|
| 2128 | - /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2129 | - $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2130 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2131 | - |
|
| 2132 | - /** Update the product meta information with the calculated prices */ |
|
| 2133 | - $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2134 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2135 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2136 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2137 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2138 | - |
|
| 2139 | - update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2079 | + $element_id |
|
| 2080 | + ); |
|
| 2081 | + $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2082 | + |
|
| 2083 | + /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2084 | + if (empty($prices_attribute)) { |
|
| 2085 | + return false; |
|
| 2086 | + } else { |
|
| 2087 | + /** |
|
| 2088 | + * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2089 | + * the base amount according on the shop price control |
|
| 2090 | + */ |
|
| 2091 | + $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2092 | + $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2093 | + $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2094 | + |
|
| 2095 | + /** |
|
| 2096 | + * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2097 | + * create an attribute |
|
| 2098 | + */ |
|
| 2099 | + $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2100 | + $language = WPSHOP_CURRENT_LOCALE; |
|
| 2101 | + $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2102 | + |
|
| 2103 | + if (!empty($icl_post_language)) { |
|
| 2104 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2105 | + $language = $wpdb->get_var($query); |
|
| 2106 | + } |
|
| 2140 | 2107 | |
| 2141 | - /** Met à jour la meta _wps_price_infos */ |
|
| 2142 | - $p = wpshop_products::get_product_data($element_id); |
|
| 2143 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2144 | - update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2108 | + /** |
|
| 2109 | + * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2110 | + * Check configuration to know how to make the calcul for the product |
|
| 2111 | + */ |
|
| 2112 | + if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2113 | + $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2114 | + $price_no_vat = $base_price; |
|
| 2115 | + } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2116 | + $price_with_vat = $base_price; |
|
| 2117 | + $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2118 | + } |
|
| 2145 | 2119 | |
| 2146 | - /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2147 | - wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2148 | - } |
|
| 2120 | + /** |
|
| 2121 | + * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2122 | + * type que celui-ci / The last parameter allows not to delete the |
|
| 2123 | + * attributes of the same type as this one |
|
| 2124 | + */ |
|
| 2125 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2126 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2127 | + |
|
| 2128 | + /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2129 | + $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2130 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2131 | + |
|
| 2132 | + /** Update the product meta information with the calculated prices */ |
|
| 2133 | + $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2134 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2135 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2136 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2137 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2138 | + |
|
| 2139 | + update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2140 | + |
|
| 2141 | + /** Met à jour la meta _wps_price_infos */ |
|
| 2142 | + $p = wpshop_products::get_product_data($element_id); |
|
| 2143 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2144 | + update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2145 | + |
|
| 2146 | + /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2147 | + wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2148 | + } |
|
| 2149 | 2149 | |
| 2150 | - return true; |
|
| 2151 | - } |
|
| 2150 | + return true; |
|
| 2151 | + } |
|
| 2152 | 2152 | |
| 2153 | - /** |
|
| 2154 | - * Allows to get the good button for adding product to cart |
|
| 2155 | - * |
|
| 2156 | - * @param integer $product_id The product identifier |
|
| 2157 | - * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2158 | - * |
|
| 2159 | - * @return string $button The html output for the button |
|
| 2160 | - */ |
|
| 2161 | - public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2162 | - { |
|
| 2163 | - $button = ''; |
|
| 2153 | + /** |
|
| 2154 | + * Allows to get the good button for adding product to cart |
|
| 2155 | + * |
|
| 2156 | + * @param integer $product_id The product identifier |
|
| 2157 | + * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2158 | + * |
|
| 2159 | + * @return string $button The html output for the button |
|
| 2160 | + */ |
|
| 2161 | + public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2162 | + { |
|
| 2163 | + $button = ''; |
|
| 2164 | 2164 | // $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true ); |
| 2165 | 2165 | |
| 2166 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale' /*&& ( empty($attributes_frontend_display) || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['mini_output']) && $output_type == 'mini') || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['complete_sheet']) && $output_type == 'complete') ) */) { |
|
| 2167 | - /* |
|
| 2166 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale' /*&& ( empty($attributes_frontend_display) || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['mini_output']) && $output_type == 'mini') || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['complete_sheet']) && $output_type == 'complete') ) */) { |
|
| 2167 | + /* |
|
| 2168 | 2168 | * Check if current product has variation for button display |
| 2169 | 2169 | */ |
| 2170 | - $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2171 | - $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2170 | + $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2171 | + $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2172 | 2172 | |
| 2173 | - /* |
|
| 2173 | + /* |
|
| 2174 | 2174 | * Template parameters |
| 2175 | 2175 | */ |
| 2176 | 2176 | |
| 2177 | - if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2178 | - /** Check variation stock **/ |
|
| 2179 | - $variations = self::get_variation($product_id); |
|
| 2180 | - if (!empty($variations)) { |
|
| 2181 | - foreach ($variations as $variation) { |
|
| 2182 | - if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2183 | - $productStock += $variation['variation_dif']['product_stock']; |
|
| 2184 | - } |
|
| 2185 | - } |
|
| 2186 | - } |
|
| 2187 | - } |
|
| 2188 | - |
|
| 2189 | - $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2177 | + if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2178 | + /** Check variation stock **/ |
|
| 2179 | + $variations = self::get_variation($product_id); |
|
| 2180 | + if (!empty($variations)) { |
|
| 2181 | + foreach ($variations as $variation) { |
|
| 2182 | + if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2183 | + $productStock += $variation['variation_dif']['product_stock']; |
|
| 2184 | + } |
|
| 2185 | + } |
|
| 2186 | + } |
|
| 2187 | + } |
|
| 2188 | + |
|
| 2189 | + $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2190 | 2190 | $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
| 2191 | 2191 | |
| 2192 | - $tpl_component = array(); |
|
| 2193 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2194 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2195 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2192 | + $tpl_component = array(); |
|
| 2193 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2194 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2195 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2196 | 2196 | |
| 2197 | - /* |
|
| 2197 | + /* |
|
| 2198 | 2198 | * Build template |
| 2199 | 2199 | */ |
| 2200 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2201 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2202 | - /* Include the old way template part */ |
|
| 2203 | - ob_start(); |
|
| 2204 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2205 | - $button = ob_get_contents(); |
|
| 2206 | - ob_end_clean(); |
|
| 2207 | - } else { |
|
| 2208 | - $button = wpshop_display::display_template_element($template_part, $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $product_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . 'output_type' => $output_type)); |
|
| 2209 | - } |
|
| 2210 | - unset($tpl_component); |
|
| 2211 | - } |
|
| 2212 | - return $button; |
|
| 2213 | - } |
|
| 2214 | - |
|
| 2215 | - /** |
|
| 2216 | - * Allows to get the good button for adding product to a quotation |
|
| 2217 | - * |
|
| 2218 | - * @param integer $product_id The product identifier |
|
| 2219 | - * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2220 | - * |
|
| 2221 | - * @return string $button The html output for the button |
|
| 2222 | - */ |
|
| 2223 | - public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2224 | - { |
|
| 2225 | - $quotation_button = ''; |
|
| 2226 | - |
|
| 2227 | - if (WPSHOP_ADDONS_QUOTATION && (!empty($product_quotation_state) && strtolower(__($product_quotation_state, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) && (empty($_SESSION['cart']['cart_type']) || ($_SESSION['cart']['cart_type'] == 'quotation'))) { |
|
| 2228 | - $variations_list = (is_array(wpshop_products::get_variation($product_id)) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? array_merge(wpshop_products::get_variation($product_id), wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode))) : array(); |
|
| 2229 | - /** |
|
| 2230 | - * Template parameters |
|
| 2231 | - */ |
|
| 2232 | - $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2233 | - $tpl_component = array(); |
|
| 2234 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2235 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2236 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2200 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2201 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2202 | + /* Include the old way template part */ |
|
| 2203 | + ob_start(); |
|
| 2204 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2205 | + $button = ob_get_contents(); |
|
| 2206 | + ob_end_clean(); |
|
| 2207 | + } else { |
|
| 2208 | + $button = wpshop_display::display_template_element($template_part, $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $product_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . 'output_type' => $output_type)); |
|
| 2209 | + } |
|
| 2210 | + unset($tpl_component); |
|
| 2211 | + } |
|
| 2212 | + return $button; |
|
| 2213 | + } |
|
| 2237 | 2214 | |
| 2238 | - /** |
|
| 2239 | - * Build template |
|
| 2240 | - */ |
|
| 2241 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2242 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2243 | - /* Include the old way template part */ |
|
| 2244 | - ob_start(); |
|
| 2245 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2246 | - $quotation_button = ob_get_contents(); |
|
| 2247 | - ob_end_clean(); |
|
| 2248 | - } else { |
|
| 2249 | - $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2250 | - } |
|
| 2251 | - unset($tpl_component); |
|
| 2252 | - } |
|
| 2215 | + /** |
|
| 2216 | + * Allows to get the good button for adding product to a quotation |
|
| 2217 | + * |
|
| 2218 | + * @param integer $product_id The product identifier |
|
| 2219 | + * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2220 | + * |
|
| 2221 | + * @return string $button The html output for the button |
|
| 2222 | + */ |
|
| 2223 | + public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2224 | + { |
|
| 2225 | + $quotation_button = ''; |
|
| 2226 | + |
|
| 2227 | + if (WPSHOP_ADDONS_QUOTATION && (!empty($product_quotation_state) && strtolower(__($product_quotation_state, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) && (empty($_SESSION['cart']['cart_type']) || ($_SESSION['cart']['cart_type'] == 'quotation'))) { |
|
| 2228 | + $variations_list = (is_array(wpshop_products::get_variation($product_id)) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? array_merge(wpshop_products::get_variation($product_id), wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode))) : array(); |
|
| 2229 | + /** |
|
| 2230 | + * Template parameters |
|
| 2231 | + */ |
|
| 2232 | + $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2233 | + $tpl_component = array(); |
|
| 2234 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2235 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2236 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2237 | + |
|
| 2238 | + /** |
|
| 2239 | + * Build template |
|
| 2240 | + */ |
|
| 2241 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2242 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2243 | + /* Include the old way template part */ |
|
| 2244 | + ob_start(); |
|
| 2245 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2246 | + $quotation_button = ob_get_contents(); |
|
| 2247 | + ob_end_clean(); |
|
| 2248 | + } else { |
|
| 2249 | + $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2250 | + } |
|
| 2251 | + unset($tpl_component); |
|
| 2252 | + } |
|
| 2253 | 2253 | |
| 2254 | - return $quotation_button; |
|
| 2255 | - } |
|
| 2254 | + return $quotation_button; |
|
| 2255 | + } |
|
| 2256 | 2256 | |
| 2257 | - /** |
|
| 2258 | - * Return the output for a product attachement gallery (picture or document) |
|
| 2259 | - * |
|
| 2260 | - * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2261 | - * @param string $content The gallery content build previously |
|
| 2262 | - * |
|
| 2263 | - * @return string The attachement gallery output |
|
| 2264 | - */ |
|
| 2265 | - public static function display_attachment_gallery($attachement_type, $content) |
|
| 2266 | - { |
|
| 2267 | - $galery_output = ''; |
|
| 2268 | - |
|
| 2269 | - /* |
|
| 2257 | + /** |
|
| 2258 | + * Return the output for a product attachement gallery (picture or document) |
|
| 2259 | + * |
|
| 2260 | + * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2261 | + * @param string $content The gallery content build previously |
|
| 2262 | + * |
|
| 2263 | + * @return string The attachement gallery output |
|
| 2264 | + */ |
|
| 2265 | + public static function display_attachment_gallery($attachement_type, $content) |
|
| 2266 | + { |
|
| 2267 | + $galery_output = ''; |
|
| 2268 | + |
|
| 2269 | + /* |
|
| 2270 | 2270 | * Get the template part for given galery type |
| 2271 | 2271 | */ |
| 2272 | - switch ($attachement_type) { |
|
| 2273 | - case 'picture': |
|
| 2274 | - $template_part = 'product_attachment_picture_galery'; |
|
| 2275 | - break; |
|
| 2276 | - case 'document': |
|
| 2277 | - $template_part = 'product_attachment_galery'; |
|
| 2278 | - break; |
|
| 2279 | - } |
|
| 2272 | + switch ($attachement_type) { |
|
| 2273 | + case 'picture': |
|
| 2274 | + $template_part = 'product_attachment_picture_galery'; |
|
| 2275 | + break; |
|
| 2276 | + case 'document': |
|
| 2277 | + $template_part = 'product_attachment_galery'; |
|
| 2278 | + break; |
|
| 2279 | + } |
|
| 2280 | 2280 | |
| 2281 | - /* |
|
| 2281 | + /* |
|
| 2282 | 2282 | * Template parameters |
| 2283 | 2283 | */ |
| 2284 | - $tpl_component = array(); |
|
| 2285 | - $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2286 | - $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2284 | + $tpl_component = array(); |
|
| 2285 | + $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2286 | + $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2287 | 2287 | |
| 2288 | - /* |
|
| 2288 | + /* |
|
| 2289 | 2289 | * Build template |
| 2290 | 2290 | */ |
| 2291 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2292 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2293 | - /* Include the old way template part */ |
|
| 2294 | - ob_start(); |
|
| 2295 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2296 | - $galery_output = ob_get_contents(); |
|
| 2297 | - ob_end_clean(); |
|
| 2298 | - } else { |
|
| 2299 | - $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2300 | - } |
|
| 2301 | - unset($tpl_component); |
|
| 2291 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2292 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2293 | + /* Include the old way template part */ |
|
| 2294 | + ob_start(); |
|
| 2295 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2296 | + $galery_output = ob_get_contents(); |
|
| 2297 | + ob_end_clean(); |
|
| 2298 | + } else { |
|
| 2299 | + $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2300 | + } |
|
| 2301 | + unset($tpl_component); |
|
| 2302 | 2302 | |
| 2303 | - return $galery_output; |
|
| 2304 | - } |
|
| 2303 | + return $galery_output; |
|
| 2304 | + } |
|
| 2305 | 2305 | |
| 2306 | - /** |
|
| 2307 | - * Define the metabox to display in product edition page in backend |
|
| 2308 | - * @param object $post The current element displayed for edition |
|
| 2309 | - */ |
|
| 2310 | - public static function meta_box_variations($post) |
|
| 2311 | - { |
|
| 2312 | - $output = ''; |
|
| 2313 | - /* Variations container */ |
|
| 2314 | - $tpl_component = array(); |
|
| 2315 | - $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2316 | - $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2317 | - $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2318 | - echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2319 | - } |
|
| 2306 | + /** |
|
| 2307 | + * Define the metabox to display in product edition page in backend |
|
| 2308 | + * @param object $post The current element displayed for edition |
|
| 2309 | + */ |
|
| 2310 | + public static function meta_box_variations($post) |
|
| 2311 | + { |
|
| 2312 | + $output = ''; |
|
| 2313 | + /* Variations container */ |
|
| 2314 | + $tpl_component = array(); |
|
| 2315 | + $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2316 | + $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2317 | + $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2318 | + echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2319 | + } |
|
| 2320 | 2320 | |
| 2321 | - /** |
|
| 2322 | - * Call variation creation function with a list of defined variation |
|
| 2323 | - * |
|
| 2324 | - * @param array $possible_variations A list of variation to create for the current element |
|
| 2325 | - * @param integer $element_id The product we want to create variation for |
|
| 2326 | - * |
|
| 2327 | - * @return mixed The last created variation identifier |
|
| 2328 | - */ |
|
| 2329 | - public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2330 | - { |
|
| 2331 | - /** Get existing variation */ |
|
| 2332 | - $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2333 | - $existing_variations = array(); |
|
| 2334 | - if (!empty($existing_variations_in_db)) { |
|
| 2335 | - foreach ($existing_variations_in_db as $variations_def) { |
|
| 2336 | - $existing_variations[] = $variations_def['variation_def']; |
|
| 2337 | - } |
|
| 2338 | - } |
|
| 2339 | - /** New variation definition */ |
|
| 2340 | - $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2341 | - |
|
| 2342 | - /** Read possible values */ |
|
| 2343 | - foreach ($possible_variations as $variation_definition) { |
|
| 2344 | - if (in_array($variation_definition, $existing_variations)) { |
|
| 2345 | - continue; |
|
| 2346 | - } |
|
| 2347 | - |
|
| 2348 | - $attribute_to_set = array(); |
|
| 2349 | - foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2350 | - $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2351 | - $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2352 | - if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2353 | - $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2354 | - } |
|
| 2355 | - } |
|
| 2356 | - $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2357 | - } |
|
| 2358 | - update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2321 | + /** |
|
| 2322 | + * Call variation creation function with a list of defined variation |
|
| 2323 | + * |
|
| 2324 | + * @param array $possible_variations A list of variation to create for the current element |
|
| 2325 | + * @param integer $element_id The product we want to create variation for |
|
| 2326 | + * |
|
| 2327 | + * @return mixed The last created variation identifier |
|
| 2328 | + */ |
|
| 2329 | + public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2330 | + { |
|
| 2331 | + /** Get existing variation */ |
|
| 2332 | + $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2333 | + $existing_variations = array(); |
|
| 2334 | + if (!empty($existing_variations_in_db)) { |
|
| 2335 | + foreach ($existing_variations_in_db as $variations_def) { |
|
| 2336 | + $existing_variations[] = $variations_def['variation_def']; |
|
| 2337 | + } |
|
| 2338 | + } |
|
| 2339 | + /** New variation definition */ |
|
| 2340 | + $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2359 | 2341 | |
| 2360 | - return !empty($variation_id) ? $variation_id : 0; |
|
| 2361 | - } |
|
| 2342 | + /** Read possible values */ |
|
| 2343 | + foreach ($possible_variations as $variation_definition) { |
|
| 2344 | + if (in_array($variation_definition, $existing_variations)) { |
|
| 2345 | + continue; |
|
| 2346 | + } |
|
| 2362 | 2347 | |
| 2363 | - /** |
|
| 2364 | - * Create a new variation for product |
|
| 2365 | - * |
|
| 2366 | - * @param integer $head_product The product identifier to create the new variation for |
|
| 2367 | - * @param array $variation_attributes Attribute list for the variation |
|
| 2368 | - * |
|
| 2369 | - * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2370 | - */ |
|
| 2371 | - public static function create_variation($head_product, $variation_attributes) |
|
| 2372 | - { |
|
| 2373 | - /** Create custom title */ |
|
| 2374 | - $title_variation = ""; |
|
| 2375 | - if (!empty($variation_attributes)) { |
|
| 2376 | - foreach ($variation_attributes as $type => $array) { |
|
| 2377 | - if (!empty($array)) { |
|
| 2378 | - foreach ($array as $code => $value) { |
|
| 2379 | - $title_variation .= " " . $code . " " . $value; |
|
| 2380 | - } |
|
| 2381 | - } |
|
| 2382 | - } |
|
| 2383 | - } |
|
| 2348 | + $attribute_to_set = array(); |
|
| 2349 | + foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2350 | + $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2351 | + $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2352 | + if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2353 | + $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2354 | + } |
|
| 2355 | + } |
|
| 2356 | + $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2357 | + } |
|
| 2358 | + update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2384 | 2359 | |
| 2385 | - $variation = array( |
|
| 2386 | - 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2387 | - 'post_content' => '', |
|
| 2388 | - 'post_status' => 'publish', |
|
| 2389 | - 'post_author' => get_current_user_id(), |
|
| 2390 | - 'post_parent' => $head_product, |
|
| 2391 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2392 | - ); |
|
| 2393 | - $variation_id = wp_insert_post($variation); |
|
| 2394 | - |
|
| 2395 | - wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2396 | - |
|
| 2397 | - /* Update product price looking for shop parameters */ |
|
| 2398 | - wpshop_products::calculate_price($variation_id); |
|
| 2399 | - |
|
| 2400 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2401 | - $productMetaDatas = array(); |
|
| 2402 | - foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2403 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2404 | - if (!empty($attributeValue)) { |
|
| 2405 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2406 | - } |
|
| 2407 | - } |
|
| 2408 | - } |
|
| 2409 | - update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2410 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2411 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, get_post_meta($head_product, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2360 | + return !empty($variation_id) ? $variation_id : 0; |
|
| 2361 | + } |
|
| 2412 | 2362 | |
| 2413 | - return $variation_id; |
|
| 2414 | - } |
|
| 2363 | + /** |
|
| 2364 | + * Create a new variation for product |
|
| 2365 | + * |
|
| 2366 | + * @param integer $head_product The product identifier to create the new variation for |
|
| 2367 | + * @param array $variation_attributes Attribute list for the variation |
|
| 2368 | + * |
|
| 2369 | + * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2370 | + */ |
|
| 2371 | + public static function create_variation($head_product, $variation_attributes) |
|
| 2372 | + { |
|
| 2373 | + /** Create custom title */ |
|
| 2374 | + $title_variation = ""; |
|
| 2375 | + if (!empty($variation_attributes)) { |
|
| 2376 | + foreach ($variation_attributes as $type => $array) { |
|
| 2377 | + if (!empty($array)) { |
|
| 2378 | + foreach ($array as $code => $value) { |
|
| 2379 | + $title_variation .= " " . $code . " " . $value; |
|
| 2380 | + } |
|
| 2381 | + } |
|
| 2382 | + } |
|
| 2383 | + } |
|
| 2415 | 2384 | |
| 2416 | - /** |
|
| 2417 | - * Get variation list for a given product |
|
| 2418 | - * |
|
| 2419 | - * @param integer $head_product The product identifier to get the variation for |
|
| 2420 | - * @return object The variation list |
|
| 2421 | - */ |
|
| 2422 | - public static function get_variation($head_product, $type = 'any') |
|
| 2423 | - { |
|
| 2424 | - global $wpdb; |
|
| 2425 | - $variations_output = null; |
|
| 2426 | - $args = array( |
|
| 2427 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2428 | - 'post_parent' => $head_product, |
|
| 2429 | - 'orderby' => 'ID', |
|
| 2430 | - 'order' => 'ASC', |
|
| 2431 | - 'posts_per_page' => -1, |
|
| 2432 | - 'post_status' => $type, |
|
| 2433 | - ); |
|
| 2434 | - $variations = get_posts($args); |
|
| 2435 | - |
|
| 2436 | - if (!empty($variations)) { |
|
| 2437 | - $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2438 | - |
|
| 2439 | - foreach ($variations as $post_def) { |
|
| 2440 | - $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post_def->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, "'valid', 'deleted'"); |
|
| 2441 | - foreach ($data as $content) { |
|
| 2442 | - $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2443 | - if (!empty($content->$attribute_value)) { |
|
| 2444 | - if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2445 | - $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2446 | - } else { |
|
| 2447 | - $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2448 | - } |
|
| 2449 | - } |
|
| 2450 | - } |
|
| 2451 | - $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2452 | - } |
|
| 2453 | - } |
|
| 2454 | - wp_reset_query(); |
|
| 2455 | - return $variations_output; |
|
| 2456 | - } |
|
| 2385 | + $variation = array( |
|
| 2386 | + 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2387 | + 'post_content' => '', |
|
| 2388 | + 'post_status' => 'publish', |
|
| 2389 | + 'post_author' => get_current_user_id(), |
|
| 2390 | + 'post_parent' => $head_product, |
|
| 2391 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2392 | + ); |
|
| 2393 | + $variation_id = wp_insert_post($variation); |
|
| 2394 | + |
|
| 2395 | + wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2396 | + |
|
| 2397 | + /* Update product price looking for shop parameters */ |
|
| 2398 | + wpshop_products::calculate_price($variation_id); |
|
| 2399 | + |
|
| 2400 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2401 | + $productMetaDatas = array(); |
|
| 2402 | + foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2403 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2404 | + if (!empty($attributeValue)) { |
|
| 2405 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2406 | + } |
|
| 2407 | + } |
|
| 2408 | + } |
|
| 2409 | + update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2410 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2411 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, get_post_meta($head_product, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2457 | 2412 | |
| 2458 | - /** |
|
| 2459 | - * Affichage des variations d'un produit dans l'administration |
|
| 2460 | - * |
|
| 2461 | - * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2462 | - * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2463 | - */ |
|
| 2464 | - public static function display_variation_admin($head_product) |
|
| 2465 | - { |
|
| 2466 | - $output = ''; |
|
| 2467 | - $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2468 | - /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2469 | - $variations = self::get_variation($head_product); |
|
| 2470 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2471 | - |
|
| 2472 | - /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2473 | - if (!empty($variations) && is_array($variations)) { |
|
| 2474 | - $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2475 | - |
|
| 2476 | - foreach ($variations as $variation) { |
|
| 2477 | - $tpl_component = array(); |
|
| 2478 | - |
|
| 2479 | - $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2480 | - $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2481 | - $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2482 | - $p = (!empty($variation['variation_dif']['product_price']) || !empty($variation['variation_dif']['price_ht'])) ? ((!empty($price_piloting) && $price_piloting == 'HT' && !empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) : 0; |
|
| 2483 | - $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2484 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2485 | - |
|
| 2486 | - } else { |
|
| 2487 | - |
|
| 2488 | - } |
|
| 2489 | - $post_obj = $variation['post']; |
|
| 2490 | - |
|
| 2491 | - $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2492 | - if (!empty($parent_product_infos)) { |
|
| 2493 | - $parent_post = $parent_product_infos['parent_post']; |
|
| 2494 | - $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2495 | - if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2496 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2497 | - $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2498 | - } else { |
|
| 2499 | - $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2500 | - } |
|
| 2501 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2502 | - } else { |
|
| 2503 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2504 | - $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2505 | - } else { |
|
| 2506 | - $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2507 | - } |
|
| 2508 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2509 | - } |
|
| 2510 | - $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2511 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2512 | - } |
|
| 2513 | - |
|
| 2514 | - if (!empty($variation['variation_def'])) { |
|
| 2515 | - foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2516 | - if (!empty($variation_value)) { |
|
| 2517 | - $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2518 | - $tpl_component['VARIATION_DETAIL'] .= '<input type="hidden" name="' . self::current_page_variation_code . '[' . $variation['post']->ID . '][attribute][' . $attribute_def_for_variation->data_type . '][' . $variation_key . ']" value="' . $variation_value . '" />' . wpshop_display::display_template_element('wpshop_admin_variation_item_def_header', array('VARIATION_ATTRIBUTE_CODE' => $attribute_def_for_variation->frontend_label, 'VARIATION_ATTRIBUTE_CODE_VALUE' => stripslashes(wpshop_attributes::get_attribute_type_select_option_info($variation_value, 'label', $attribute_def_for_variation->data_type_to_use, true))), array(), 'admin'); |
|
| 2519 | - $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2520 | - |
|
| 2521 | - /** Define Link image to variation interface **/ |
|
| 2522 | - if (!empty($product_option_postmeta) && !empty($product_option_postmeta['attributes']) && !empty($product_option_postmeta['variation_type']) && ((count($product_option_postmeta['attributes']) == 1 && $product_option_postmeta['variation_type'] == 'single') || ($product_option_postmeta['variation_type'] == 'combined'))) { |
|
| 2523 | - $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2524 | - |
|
| 2525 | - $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2526 | - if (!empty($media_id_data)) { |
|
| 2527 | - $medias_ids = explode(',', $media_id_data); |
|
| 2528 | - |
|
| 2529 | - if (!empty($medias_ids)) { |
|
| 2530 | - foreach ($medias_ids as $media_id) { |
|
| 2531 | - if (!empty($media_id)) { |
|
| 2532 | - $pictures[] = get_post($media_id); |
|
| 2533 | - } |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - $pictures_data = ''; |
|
| 2539 | - if (!empty($pictures)) { |
|
| 2540 | - $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2541 | - |
|
| 2542 | - $done_picture = array(); |
|
| 2543 | - foreach ($pictures as $picture) { |
|
| 2544 | - if (!in_array($picture->ID, $done_picture)) { |
|
| 2545 | - if (wp_attachment_is_image($picture->ID)) { |
|
| 2546 | - $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2547 | - $pictures_data .= wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_element', array('PICTURE_CHOICE_VARIATION_ID' => $picture->ID, 'PRODUCT_VARIATION_ID' => $variation['post']->ID, 'PICTURE_CHOICE_SELECTED' => $checked, 'PICTURE_CHOICE_VARIATION_IMG' => wp_get_attachment_image($picture->ID, 'thumbnail')), array(), 'admin'); |
|
| 2548 | - |
|
| 2549 | - $done_picture[] = $picture->ID; |
|
| 2550 | - } |
|
| 2551 | - } |
|
| 2552 | - } |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - $tpl_component['VARIATION_IMAGE_CHOICE'] = wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_container', array('PICTURE_CHOICE_CONTAINER_CONTENT' => $pictures_data), array(), 'admin'); |
|
| 2556 | - } |
|
| 2557 | - |
|
| 2558 | - } |
|
| 2559 | - } |
|
| 2560 | - } |
|
| 2561 | - |
|
| 2562 | - $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2563 | - |
|
| 2564 | - $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2565 | - $tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('post_id' => $variation['post']->ID, 'input_class' => ' ', 'field_name' => wpshop_products::current_page_variation_code . '[' . $variation['post']->ID . ']', 'page_code' => self::current_page_variation_code, 'field_id' => self::current_page_variation_code . '_' . $variation['post']->ID, 'variation_dif_values' => (!empty($variation['variation_dif']) ? $variation['variation_dif'] : array()))); |
|
| 2566 | - $tpl_component['VARIATION_DEFINITION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin'); |
|
| 2567 | - |
|
| 2568 | - /* Add the variation definition to output */ |
|
| 2569 | - $existing_variation_list .= wpshop_display::display_template_element('wpshop_admin_variation_item_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin'); |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - $output .= wpshop_display::display_template_element('wpshop_admin_existing_variation_list', array('ADMIN_EXISTING_VARIATIONS_CONTAINER_CLASS' => '', 'ADMIN_EXISTING_VARIATIONS_CONTAINER' => $existing_variation_list), array(), 'admin'); |
|
| 2573 | - /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2574 | - wp_reset_query(); |
|
| 2575 | - } else { |
|
| 2576 | - $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2577 | - } |
|
| 2413 | + return $variation_id; |
|
| 2414 | + } |
|
| 2578 | 2415 | |
| 2579 | - return $output; |
|
| 2580 | - } |
|
| 2416 | + /** |
|
| 2417 | + * Get variation list for a given product |
|
| 2418 | + * |
|
| 2419 | + * @param integer $head_product The product identifier to get the variation for |
|
| 2420 | + * @return object The variation list |
|
| 2421 | + */ |
|
| 2422 | + public static function get_variation($head_product, $type = 'any') |
|
| 2423 | + { |
|
| 2424 | + global $wpdb; |
|
| 2425 | + $variations_output = null; |
|
| 2426 | + $args = array( |
|
| 2427 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2428 | + 'post_parent' => $head_product, |
|
| 2429 | + 'orderby' => 'ID', |
|
| 2430 | + 'order' => 'ASC', |
|
| 2431 | + 'posts_per_page' => -1, |
|
| 2432 | + 'post_status' => $type, |
|
| 2433 | + ); |
|
| 2434 | + $variations = get_posts($args); |
|
| 2435 | + |
|
| 2436 | + if (!empty($variations)) { |
|
| 2437 | + $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2438 | + |
|
| 2439 | + foreach ($variations as $post_def) { |
|
| 2440 | + $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post_def->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, "'valid', 'deleted'"); |
|
| 2441 | + foreach ($data as $content) { |
|
| 2442 | + $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2443 | + if (!empty($content->$attribute_value)) { |
|
| 2444 | + if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2445 | + $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2446 | + } else { |
|
| 2447 | + $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2448 | + } |
|
| 2449 | + } |
|
| 2450 | + } |
|
| 2451 | + $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2452 | + } |
|
| 2453 | + } |
|
| 2454 | + wp_reset_query(); |
|
| 2455 | + return $variations_output; |
|
| 2456 | + } |
|
| 2581 | 2457 | |
| 2582 | - /** |
|
| 2583 | - * Retrieve and display the variation for a given product |
|
| 2584 | - * @param integer $product_id The product identifier to get variation for |
|
| 2585 | - */ |
|
| 2586 | - public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2587 | - { |
|
| 2588 | - global $wp_query; |
|
| 2589 | - $output = ''; |
|
| 2590 | - |
|
| 2591 | - $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2592 | - $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2593 | - $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2594 | - |
|
| 2595 | - /** Get attribute order for current product */ |
|
| 2596 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2597 | - $output_order = array(); |
|
| 2598 | - if (count($product_attribute_order_detail) > 0) { |
|
| 2599 | - if (!empty($product_attribute_order_detail)) { |
|
| 2600 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2601 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2602 | - if (!empty($attribute_def->code)) { |
|
| 2603 | - $output_order[$attribute_def->code] = $position; |
|
| 2604 | - } |
|
| 2605 | - |
|
| 2606 | - } |
|
| 2607 | - } |
|
| 2608 | - } |
|
| 2609 | - } |
|
| 2458 | + /** |
|
| 2459 | + * Affichage des variations d'un produit dans l'administration |
|
| 2460 | + * |
|
| 2461 | + * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2462 | + * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2463 | + */ |
|
| 2464 | + public static function display_variation_admin($head_product) |
|
| 2465 | + { |
|
| 2466 | + $output = ''; |
|
| 2467 | + $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2468 | + /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2469 | + $variations = self::get_variation($head_product); |
|
| 2470 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2471 | + |
|
| 2472 | + /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2473 | + if (!empty($variations) && is_array($variations)) { |
|
| 2474 | + $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2475 | + |
|
| 2476 | + foreach ($variations as $variation) { |
|
| 2477 | + $tpl_component = array(); |
|
| 2478 | + |
|
| 2479 | + $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2480 | + $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2481 | + $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2482 | + $p = (!empty($variation['variation_dif']['product_price']) || !empty($variation['variation_dif']['price_ht'])) ? ((!empty($price_piloting) && $price_piloting == 'HT' && !empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) : 0; |
|
| 2483 | + $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2484 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2485 | + |
|
| 2486 | + } else { |
|
| 2610 | 2487 | |
| 2611 | - $variations_params = array(); |
|
| 2612 | - $variation_attribute = array(); |
|
| 2613 | - $variation_attribute_ordered = array(); |
|
| 2614 | - $possible_values = array(); |
|
| 2615 | - $possible_values_for_selection_calculation = array(); |
|
| 2616 | - |
|
| 2617 | - /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2618 | - $wpshop_variation_list = self::get_variation($product_id); |
|
| 2619 | - if (!empty($wpshop_variation_list)) { |
|
| 2620 | - foreach ($wpshop_variation_list as $variation) { |
|
| 2621 | - if (!empty($variation['variation_def'])) { |
|
| 2622 | - $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2623 | - foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2624 | - if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2625 | - $tpl_component = array(); |
|
| 2626 | - |
|
| 2627 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2628 | - $default_value_is_serial = false; |
|
| 2629 | - $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2630 | - if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2631 | - $default_value_is_serial = true; |
|
| 2632 | - $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2633 | - $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2637 | - $possible_values[$attribute_code][0][0] = ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) ? stripslashes(sprintf($attribute_list_first_element, strtolower($attribute_db_definition->frontend_label))) : __('Choose a value', 'wpshop'); |
|
| 2638 | - } |
|
| 2639 | - |
|
| 2640 | - if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2641 | - $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2642 | - $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2643 | - } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2644 | - $post_def = get_post($attribute_value); |
|
| 2645 | - $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2646 | - $position = $post_def->menu_order; |
|
| 2647 | - } |
|
| 2648 | - |
|
| 2649 | - if (!empty($variation['variation_dif'])) { |
|
| 2650 | - foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2651 | - $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2652 | - $the_value = $attribute_dif_value; |
|
| 2653 | - if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2654 | - $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2655 | - } |
|
| 2656 | - $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2657 | - } |
|
| 2658 | - } |
|
| 2659 | - if (!empty($attribute_value)) { |
|
| 2660 | - $possible_values[$attribute_code][$position][$attribute_value] = wpshop_display::display_template_element('product_variation_item_possible_values', $tpl_component, array('type' => 'attribute_for_variation', 'id' => $attribute_code)); |
|
| 2661 | - $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2662 | - } |
|
| 2663 | - unset($tpl_component); |
|
| 2664 | - } |
|
| 2665 | - } |
|
| 2666 | - } |
|
| 2667 | - } |
|
| 2668 | - |
|
| 2669 | - $variation_tpl = array(); |
|
| 2670 | - if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2671 | - foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2672 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2673 | - |
|
| 2674 | - if (!empty($attribute_db_definition)) { |
|
| 2675 | - $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_db_definition->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_code, 'complete_sheet'); |
|
| 2676 | - |
|
| 2677 | - $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? true : false; |
|
| 2678 | - if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2679 | - $is_required = true; |
|
| 2680 | - } |
|
| 2681 | - |
|
| 2682 | - $input_def = array(); |
|
| 2683 | - $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2684 | - $value = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : (!empty($attribute_db_definition->default_value) ? $attribute_db_definition->default_value : null); |
|
| 2685 | - if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2686 | - unset($possible_values[$attribute_code][0]); |
|
| 2687 | - $value = array($value); |
|
| 2688 | - } |
|
| 2689 | - $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2690 | - $input_def['name'] = $attribute_code; |
|
| 2691 | - $real_possible_values = array(); |
|
| 2692 | - if (!empty($possible_values[$attribute_code])) { |
|
| 2693 | - ksort($possible_values[$attribute_code]); |
|
| 2694 | - foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2695 | - foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2696 | - $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2697 | - if (!empty($attribute_value)) { |
|
| 2698 | - global $wpdb; |
|
| 2699 | - $query = $wpdb->prepare("SELECT post_status FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value LIKE '%%" . serialize($attribute_code) . serialize($attribute_value) . "%%'", $product_id); |
|
| 2700 | - if ('draft' == $wpdb->get_var($query)) { |
|
| 2701 | - unset($real_possible_values[$attribute_value]); |
|
| 2702 | - } |
|
| 2703 | - } |
|
| 2704 | - } |
|
| 2705 | - } |
|
| 2706 | - } |
|
| 2707 | - $input_def['possible_value'] = $real_possible_values; |
|
| 2708 | - $input_def['valueToPut'] = 'index'; |
|
| 2709 | - $input_def['value'] = $value; |
|
| 2710 | - |
|
| 2711 | - $input_def['options']['more_input'] = ''; |
|
| 2712 | - if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2713 | - foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2714 | - $input_def['options']['more_input'] .= '<input type="hidden" disabled="disabled" value="' . str_replace("\\", "", $value) . '" name="' . $input_def['id'] . '_current_value" id="' . $input_def['id'] . '_current_value_' . $value_id . '" />'; |
|
| 2715 | - } |
|
| 2716 | - } |
|
| 2717 | - |
|
| 2718 | - $input_def['options_label']['original'] = true; |
|
| 2719 | - $input_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_code . ' ' : '') . ($attribute_db_definition->_display_informations_about_value == 'yes' ? ' wpshop_display_information_about_value' : '') . ' ' . ((is_admin()) ? $attribute_db_definition->backend_css_class : $attribute_db_definition->frontend_css_class) . '" '; |
|
| 2720 | - |
|
| 2721 | - if (!empty($real_possible_values)) { |
|
| 2722 | - $tpl_component = array(); |
|
| 2723 | - $attribute_output_def['value'] = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : $input_def['value']; |
|
| 2724 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2725 | - $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_code . '" >' . stripslashes($attribute_db_definition->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_db_definition->frontend_label)); |
|
| 2726 | - $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2727 | - $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2728 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2729 | - $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2730 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2731 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2732 | - $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_code : '') . ' wpshop_variation_' . $attribute_code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id; |
|
| 2733 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2734 | - $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2735 | - $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2736 | - } |
|
| 2737 | - |
|
| 2738 | - $variation_attribute[] = $attribute_code; |
|
| 2739 | - } |
|
| 2740 | - } |
|
| 2741 | - } |
|
| 2488 | + } |
|
| 2489 | + $post_obj = $variation['post']; |
|
| 2490 | + |
|
| 2491 | + $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2492 | + if (!empty($parent_product_infos)) { |
|
| 2493 | + $parent_post = $parent_product_infos['parent_post']; |
|
| 2494 | + $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2495 | + if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2496 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2497 | + $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2498 | + } else { |
|
| 2499 | + $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2500 | + } |
|
| 2501 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2502 | + } else { |
|
| 2503 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2504 | + $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2505 | + } else { |
|
| 2506 | + $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2507 | + } |
|
| 2508 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2509 | + } |
|
| 2510 | + $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2511 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2512 | + } |
|
| 2742 | 2513 | |
| 2743 | - } |
|
| 2744 | - $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2745 | - wp_reset_query(); |
|
| 2746 | - |
|
| 2747 | - $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2748 | - if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2749 | - foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2750 | - $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_not_in_variation_but_user_defined->code, $head_wpshop_variation_definition['options']['required_attributes']))) || $attribute_not_in_variation_but_user_defined->is_required == 'yes') ? true : false; |
|
| 2751 | - |
|
| 2752 | - $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_not_in_variation_but_user_defined->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_not_in_variation_but_user_defined->code, 'complete_sheet'); |
|
| 2753 | - if ($attribute_display_state && array_key_exists($attribute_not_in_variation_but_user_defined->code, $output_order) && !in_array($attribute_not_in_variation_but_user_defined->code, $variation_attribute) && ($attribute_not_in_variation_but_user_defined->is_used_for_variation == 'no')) { |
|
| 2754 | - $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_not_in_variation_but_user_defined, (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code] : '')); |
|
| 2755 | - |
|
| 2756 | - $tpl_component = array(); |
|
| 2757 | - $attribute_output_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_not_in_variation_but_user_defined->code : '') . ' ' . (str_replace('"', '', str_replace('class="', '', $attribute_output_def['option']))) . ' ' . ((is_admin()) ? $attribute_not_in_variation_but_user_defined->backend_css_class : $attribute_not_in_variation_but_user_defined->frontend_css_class) . '" '; |
|
| 2758 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2759 | - $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_not_in_variation_but_user_defined->code . '" >' . stripslashes($attribute_not_in_variation_but_user_defined->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_not_in_variation_but_user_defined->frontend_label)); |
|
| 2760 | - $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2761 | - $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' title="' . $attribute_not_in_variation_but_user_defined->frontend_help_message . '" ' : ''; |
|
| 2762 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2763 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2764 | - $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2765 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2766 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2767 | - $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_not_in_variation_but_user_defined->code : '') . ' wpshop_variation_' . $attribute_not_in_variation_but_user_defined->code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id; |
|
| 2768 | - $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)] = ($attribute_output_def['type'] != 'hidden') ? wpshop_display::display_template_element('product_variation_item', $tpl_component) : wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2769 | - $variation_attribute_ordered[$output_order[$attribute_not_in_variation_but_user_defined->code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)]; |
|
| 2770 | - } |
|
| 2771 | - } |
|
| 2772 | - } |
|
| 2773 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2774 | - if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2775 | - ksort($variation_attribute_ordered); |
|
| 2776 | - foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2777 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2778 | - } |
|
| 2779 | - } |
|
| 2780 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2781 | - $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2782 | - if ($from_admin && !empty($order_id)) { |
|
| 2783 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2784 | - $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2785 | - } |
|
| 2786 | - $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2514 | + if (!empty($variation['variation_def'])) { |
|
| 2515 | + foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2516 | + if (!empty($variation_value)) { |
|
| 2517 | + $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2518 | + $tpl_component['VARIATION_DETAIL'] .= '<input type="hidden" name="' . self::current_page_variation_code . '[' . $variation['post']->ID . '][attribute][' . $attribute_def_for_variation->data_type . '][' . $variation_key . ']" value="' . $variation_value . '" />' . wpshop_display::display_template_element('wpshop_admin_variation_item_def_header', array('VARIATION_ATTRIBUTE_CODE' => $attribute_def_for_variation->frontend_label, 'VARIATION_ATTRIBUTE_CODE_VALUE' => stripslashes(wpshop_attributes::get_attribute_type_select_option_info($variation_value, 'label', $attribute_def_for_variation->data_type_to_use, true))), array(), 'admin'); |
|
| 2519 | + $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2520 | + |
|
| 2521 | + /** Define Link image to variation interface **/ |
|
| 2522 | + if (!empty($product_option_postmeta) && !empty($product_option_postmeta['attributes']) && !empty($product_option_postmeta['variation_type']) && ((count($product_option_postmeta['attributes']) == 1 && $product_option_postmeta['variation_type'] == 'single') || ($product_option_postmeta['variation_type'] == 'combined'))) { |
|
| 2523 | + $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2524 | + |
|
| 2525 | + $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2526 | + if (!empty($media_id_data)) { |
|
| 2527 | + $medias_ids = explode(',', $media_id_data); |
|
| 2528 | + |
|
| 2529 | + if (!empty($medias_ids)) { |
|
| 2530 | + foreach ($medias_ids as $media_id) { |
|
| 2531 | + if (!empty($media_id)) { |
|
| 2532 | + $pictures[] = get_post($media_id); |
|
| 2533 | + } |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + $pictures_data = ''; |
|
| 2539 | + if (!empty($pictures)) { |
|
| 2540 | + $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2541 | + |
|
| 2542 | + $done_picture = array(); |
|
| 2543 | + foreach ($pictures as $picture) { |
|
| 2544 | + if (!in_array($picture->ID, $done_picture)) { |
|
| 2545 | + if (wp_attachment_is_image($picture->ID)) { |
|
| 2546 | + $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2547 | + $pictures_data .= wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_element', array('PICTURE_CHOICE_VARIATION_ID' => $picture->ID, 'PRODUCT_VARIATION_ID' => $variation['post']->ID, 'PICTURE_CHOICE_SELECTED' => $checked, 'PICTURE_CHOICE_VARIATION_IMG' => wp_get_attachment_image($picture->ID, 'thumbnail')), array(), 'admin'); |
|
| 2548 | + |
|
| 2549 | + $done_picture[] = $picture->ID; |
|
| 2550 | + } |
|
| 2551 | + } |
|
| 2552 | + } |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + $tpl_component['VARIATION_IMAGE_CHOICE'] = wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_container', array('PICTURE_CHOICE_CONTAINER_CONTENT' => $pictures_data), array(), 'admin'); |
|
| 2556 | + } |
|
| 2557 | + |
|
| 2558 | + } |
|
| 2559 | + } |
|
| 2560 | + } |
|
| 2787 | 2561 | |
| 2788 | - return $output; |
|
| 2789 | - } |
|
| 2562 | + $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2790 | 2563 | |
| 2791 | - public static function get_parent_variation($variation_id) |
|
| 2792 | - { |
|
| 2793 | - $result = array(); |
|
| 2794 | - if (!empty($variation_id)) { |
|
| 2795 | - $variation_post = get_post($variation_id); |
|
| 2796 | - if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2797 | - $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2798 | - $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2799 | - } |
|
| 2800 | - } |
|
| 2801 | - return $result; |
|
| 2802 | - } |
|
| 2564 | + $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2565 | + $tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('post_id' => $variation['post']->ID, 'input_class' => ' ', 'field_name' => wpshop_products::current_page_variation_code . '[' . $variation['post']->ID . ']', 'page_code' => self::current_page_variation_code, 'field_id' => self::current_page_variation_code . '_' . $variation['post']->ID, 'variation_dif_values' => (!empty($variation['variation_dif']) ? $variation['variation_dif'] : array()))); |
|
| 2566 | + $tpl_component['VARIATION_DEFINITION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin'); |
|
| 2803 | 2567 | |
| 2804 | - /** |
|
| 2805 | - * Display the current configuration for a given product |
|
| 2806 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2807 | - */ |
|
| 2808 | - public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2809 | - { |
|
| 2810 | - $output = ''; |
|
| 2811 | - |
|
| 2812 | - $product_variations_selection_args = array( |
|
| 2813 | - 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2814 | - 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2815 | - ); |
|
| 2816 | - |
|
| 2817 | - $current_user_id = get_current_user_id(); |
|
| 2818 | - |
|
| 2819 | - if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2820 | - foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2821 | - if (!empty($item) && !empty($item['item_id'])) { |
|
| 2822 | - |
|
| 2823 | - $free_variations = array(); |
|
| 2824 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2825 | - foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2826 | - $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2827 | - } |
|
| 2828 | - } |
|
| 2829 | - |
|
| 2830 | - $variations = array(); |
|
| 2831 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2832 | - foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2833 | - |
|
| 2834 | - if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2835 | - foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2836 | - $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2837 | - } |
|
| 2838 | - } |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2842 | - |
|
| 2843 | - $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2844 | - } |
|
| 2845 | - } |
|
| 2846 | - } |
|
| 2568 | + /* Add the variation definition to output */ |
|
| 2569 | + $existing_variation_list .= wpshop_display::display_template_element('wpshop_admin_variation_item_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin'); |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + $output .= wpshop_display::display_template_element('wpshop_admin_existing_variation_list', array('ADMIN_EXISTING_VARIATIONS_CONTAINER_CLASS' => '', 'ADMIN_EXISTING_VARIATIONS_CONTAINER' => $existing_variation_list), array(), 'admin'); |
|
| 2573 | + /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2574 | + wp_reset_query(); |
|
| 2575 | + } else { |
|
| 2576 | + $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2577 | + } |
|
| 2847 | 2578 | |
| 2848 | - $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2579 | + return $output; |
|
| 2580 | + } |
|
| 2849 | 2581 | |
| 2850 | - echo $output; |
|
| 2851 | - } |
|
| 2582 | + /** |
|
| 2583 | + * Retrieve and display the variation for a given product |
|
| 2584 | + * @param integer $product_id The product identifier to get variation for |
|
| 2585 | + */ |
|
| 2586 | + public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2587 | + { |
|
| 2588 | + global $wp_query; |
|
| 2589 | + $output = ''; |
|
| 2590 | + |
|
| 2591 | + $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2592 | + $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2593 | + $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2594 | + |
|
| 2595 | + /** Get attribute order for current product */ |
|
| 2596 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2597 | + $output_order = array(); |
|
| 2598 | + if (count($product_attribute_order_detail) > 0) { |
|
| 2599 | + if (!empty($product_attribute_order_detail)) { |
|
| 2600 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2601 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2602 | + if (!empty($attribute_def->code)) { |
|
| 2603 | + $output_order[$attribute_def->code] = $position; |
|
| 2604 | + } |
|
| 2605 | + |
|
| 2606 | + } |
|
| 2607 | + } |
|
| 2608 | + } |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + $variations_params = array(); |
|
| 2612 | + $variation_attribute = array(); |
|
| 2613 | + $variation_attribute_ordered = array(); |
|
| 2614 | + $possible_values = array(); |
|
| 2615 | + $possible_values_for_selection_calculation = array(); |
|
| 2616 | + |
|
| 2617 | + /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2618 | + $wpshop_variation_list = self::get_variation($product_id); |
|
| 2619 | + if (!empty($wpshop_variation_list)) { |
|
| 2620 | + foreach ($wpshop_variation_list as $variation) { |
|
| 2621 | + if (!empty($variation['variation_def'])) { |
|
| 2622 | + $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2623 | + foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2624 | + if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2625 | + $tpl_component = array(); |
|
| 2626 | + |
|
| 2627 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2628 | + $default_value_is_serial = false; |
|
| 2629 | + $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2630 | + if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2631 | + $default_value_is_serial = true; |
|
| 2632 | + $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2633 | + $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2637 | + $possible_values[$attribute_code][0][0] = ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) ? stripslashes(sprintf($attribute_list_first_element, strtolower($attribute_db_definition->frontend_label))) : __('Choose a value', 'wpshop'); |
|
| 2638 | + } |
|
| 2639 | + |
|
| 2640 | + if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2641 | + $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2642 | + $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2643 | + } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2644 | + $post_def = get_post($attribute_value); |
|
| 2645 | + $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2646 | + $position = $post_def->menu_order; |
|
| 2647 | + } |
|
| 2648 | + |
|
| 2649 | + if (!empty($variation['variation_dif'])) { |
|
| 2650 | + foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2651 | + $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2652 | + $the_value = $attribute_dif_value; |
|
| 2653 | + if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2654 | + $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2655 | + } |
|
| 2656 | + $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2657 | + } |
|
| 2658 | + } |
|
| 2659 | + if (!empty($attribute_value)) { |
|
| 2660 | + $possible_values[$attribute_code][$position][$attribute_value] = wpshop_display::display_template_element('product_variation_item_possible_values', $tpl_component, array('type' => 'attribute_for_variation', 'id' => $attribute_code)); |
|
| 2661 | + $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2662 | + } |
|
| 2663 | + unset($tpl_component); |
|
| 2664 | + } |
|
| 2665 | + } |
|
| 2666 | + } |
|
| 2667 | + } |
|
| 2668 | + |
|
| 2669 | + $variation_tpl = array(); |
|
| 2670 | + if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2671 | + foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2672 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2673 | + |
|
| 2674 | + if (!empty($attribute_db_definition)) { |
|
| 2675 | + $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_db_definition->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_code, 'complete_sheet'); |
|
| 2676 | + |
|
| 2677 | + $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? true : false; |
|
| 2678 | + if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2679 | + $is_required = true; |
|
| 2680 | + } |
|
| 2681 | + |
|
| 2682 | + $input_def = array(); |
|
| 2683 | + $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2684 | + $value = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : (!empty($attribute_db_definition->default_value) ? $attribute_db_definition->default_value : null); |
|
| 2685 | + if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2686 | + unset($possible_values[$attribute_code][0]); |
|
| 2687 | + $value = array($value); |
|
| 2688 | + } |
|
| 2689 | + $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2690 | + $input_def['name'] = $attribute_code; |
|
| 2691 | + $real_possible_values = array(); |
|
| 2692 | + if (!empty($possible_values[$attribute_code])) { |
|
| 2693 | + ksort($possible_values[$attribute_code]); |
|
| 2694 | + foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2695 | + foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2696 | + $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2697 | + if (!empty($attribute_value)) { |
|
| 2698 | + global $wpdb; |
|
| 2699 | + $query = $wpdb->prepare("SELECT post_status FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value LIKE '%%" . serialize($attribute_code) . serialize($attribute_value) . "%%'", $product_id); |
|
| 2700 | + if ('draft' == $wpdb->get_var($query)) { |
|
| 2701 | + unset($real_possible_values[$attribute_value]); |
|
| 2702 | + } |
|
| 2703 | + } |
|
| 2704 | + } |
|
| 2705 | + } |
|
| 2706 | + } |
|
| 2707 | + $input_def['possible_value'] = $real_possible_values; |
|
| 2708 | + $input_def['valueToPut'] = 'index'; |
|
| 2709 | + $input_def['value'] = $value; |
|
| 2710 | + |
|
| 2711 | + $input_def['options']['more_input'] = ''; |
|
| 2712 | + if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2713 | + foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2714 | + $input_def['options']['more_input'] .= '<input type="hidden" disabled="disabled" value="' . str_replace("\\", "", $value) . '" name="' . $input_def['id'] . '_current_value" id="' . $input_def['id'] . '_current_value_' . $value_id . '" />'; |
|
| 2715 | + } |
|
| 2716 | + } |
|
| 2717 | + |
|
| 2718 | + $input_def['options_label']['original'] = true; |
|
| 2719 | + $input_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_code . ' ' : '') . ($attribute_db_definition->_display_informations_about_value == 'yes' ? ' wpshop_display_information_about_value' : '') . ' ' . ((is_admin()) ? $attribute_db_definition->backend_css_class : $attribute_db_definition->frontend_css_class) . '" '; |
|
| 2720 | + |
|
| 2721 | + if (!empty($real_possible_values)) { |
|
| 2722 | + $tpl_component = array(); |
|
| 2723 | + $attribute_output_def['value'] = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : $input_def['value']; |
|
| 2724 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2725 | + $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_code . '" >' . stripslashes($attribute_db_definition->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_db_definition->frontend_label)); |
|
| 2726 | + $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2727 | + $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2728 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2729 | + $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2730 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2731 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2732 | + $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_code : '') . ' wpshop_variation_' . $attribute_code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id; |
|
| 2733 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2734 | + $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2735 | + $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2736 | + } |
|
| 2737 | + |
|
| 2738 | + $variation_attribute[] = $attribute_code; |
|
| 2739 | + } |
|
| 2740 | + } |
|
| 2741 | + } |
|
| 2742 | + |
|
| 2743 | + } |
|
| 2744 | + $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2745 | + wp_reset_query(); |
|
| 2746 | + |
|
| 2747 | + $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2748 | + if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2749 | + foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2750 | + $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_not_in_variation_but_user_defined->code, $head_wpshop_variation_definition['options']['required_attributes']))) || $attribute_not_in_variation_but_user_defined->is_required == 'yes') ? true : false; |
|
| 2751 | + |
|
| 2752 | + $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_not_in_variation_but_user_defined->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_not_in_variation_but_user_defined->code, 'complete_sheet'); |
|
| 2753 | + if ($attribute_display_state && array_key_exists($attribute_not_in_variation_but_user_defined->code, $output_order) && !in_array($attribute_not_in_variation_but_user_defined->code, $variation_attribute) && ($attribute_not_in_variation_but_user_defined->is_used_for_variation == 'no')) { |
|
| 2754 | + $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_not_in_variation_but_user_defined, (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code] : '')); |
|
| 2755 | + |
|
| 2756 | + $tpl_component = array(); |
|
| 2757 | + $attribute_output_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_not_in_variation_but_user_defined->code : '') . ' ' . (str_replace('"', '', str_replace('class="', '', $attribute_output_def['option']))) . ' ' . ((is_admin()) ? $attribute_not_in_variation_but_user_defined->backend_css_class : $attribute_not_in_variation_but_user_defined->frontend_css_class) . '" '; |
|
| 2758 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2759 | + $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_not_in_variation_but_user_defined->code . '" >' . stripslashes($attribute_not_in_variation_but_user_defined->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_not_in_variation_but_user_defined->frontend_label)); |
|
| 2760 | + $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2761 | + $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' title="' . $attribute_not_in_variation_but_user_defined->frontend_help_message . '" ' : ''; |
|
| 2762 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2763 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2764 | + $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2765 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2766 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2767 | + $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_not_in_variation_but_user_defined->code : '') . ' wpshop_variation_' . $attribute_not_in_variation_but_user_defined->code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id; |
|
| 2768 | + $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)] = ($attribute_output_def['type'] != 'hidden') ? wpshop_display::display_template_element('product_variation_item', $tpl_component) : wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2769 | + $variation_attribute_ordered[$output_order[$attribute_not_in_variation_but_user_defined->code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)]; |
|
| 2770 | + } |
|
| 2771 | + } |
|
| 2772 | + } |
|
| 2773 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2774 | + if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2775 | + ksort($variation_attribute_ordered); |
|
| 2776 | + foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2777 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2778 | + } |
|
| 2779 | + } |
|
| 2780 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2781 | + $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2782 | + if ($from_admin && !empty($order_id)) { |
|
| 2783 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2784 | + $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2785 | + } |
|
| 2786 | + $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2787 | + |
|
| 2788 | + return $output; |
|
| 2789 | + } |
|
| 2790 | + |
|
| 2791 | + public static function get_parent_variation($variation_id) |
|
| 2792 | + { |
|
| 2793 | + $result = array(); |
|
| 2794 | + if (!empty($variation_id)) { |
|
| 2795 | + $variation_post = get_post($variation_id); |
|
| 2796 | + if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2797 | + $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2798 | + $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2799 | + } |
|
| 2800 | + } |
|
| 2801 | + return $result; |
|
| 2802 | + } |
|
| 2803 | + |
|
| 2804 | + /** |
|
| 2805 | + * Display the current configuration for a given product |
|
| 2806 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2807 | + */ |
|
| 2808 | + public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2809 | + { |
|
| 2810 | + $output = ''; |
|
| 2811 | + |
|
| 2812 | + $product_variations_selection_args = array( |
|
| 2813 | + 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2814 | + 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2815 | + ); |
|
| 2816 | + |
|
| 2817 | + $current_user_id = get_current_user_id(); |
|
| 2818 | + |
|
| 2819 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2820 | + foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2821 | + if (!empty($item) && !empty($item['item_id'])) { |
|
| 2822 | + |
|
| 2823 | + $free_variations = array(); |
|
| 2824 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2825 | + foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2826 | + $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2827 | + } |
|
| 2828 | + } |
|
| 2829 | + |
|
| 2830 | + $variations = array(); |
|
| 2831 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2832 | + foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2833 | + |
|
| 2834 | + if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2835 | + foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2836 | + $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2837 | + } |
|
| 2838 | + } |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2842 | + |
|
| 2843 | + $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2844 | + } |
|
| 2845 | + } |
|
| 2846 | + } |
|
| 2847 | + |
|
| 2848 | + $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2849 | + |
|
| 2850 | + echo $output; |
|
| 2851 | + } |
|
| 2852 | + |
|
| 2853 | + /** |
|
| 2854 | + * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2855 | + * |
|
| 2856 | + * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2857 | + * @param array $wpshop_variation_selected La liste des options ayant un prix sélectionnées par le client / Options list with price selected by the customer |
|
| 2858 | + * @param array $wpshop_free_variation La liste des options n'entrainant pas de modification du prix final sélectionnées par le client / Options list without price selected by the customer |
|
| 2859 | + * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2860 | + * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2861 | + * |
|
| 2862 | + * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2863 | + */ |
|
| 2864 | + public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2865 | + { |
|
| 2866 | + global $wpdb; |
|
| 2867 | + |
|
| 2868 | + $wpshop_cart = new wps_cart(); |
|
| 2869 | + $wpshop_products = new wpshop_products(); |
|
| 2870 | + |
|
| 2871 | + $response = ''; |
|
| 2872 | + $response_status = $has_variation = false; |
|
| 2873 | + $tpl_component = array(); |
|
| 2874 | + |
|
| 2875 | + // Check if variations exists |
|
| 2876 | + if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2877 | + |
|
| 2878 | + //Recover all selected variations |
|
| 2879 | + $variations_selected = array(); |
|
| 2880 | + if (!empty($wpshop_variation_selected)) { |
|
| 2881 | + foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2882 | + $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2883 | + $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2884 | + } |
|
| 2885 | + } |
|
| 2852 | 2886 | |
| 2853 | - /** |
|
| 2854 | - * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2855 | - * |
|
| 2856 | - * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2857 | - * @param array $wpshop_variation_selected La liste des options ayant un prix sélectionnées par le client / Options list with price selected by the customer |
|
| 2858 | - * @param array $wpshop_free_variation La liste des options n'entrainant pas de modification du prix final sélectionnées par le client / Options list without price selected by the customer |
|
| 2859 | - * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2860 | - * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2861 | - * |
|
| 2862 | - * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2863 | - */ |
|
| 2864 | - public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2865 | - { |
|
| 2866 | - global $wpdb; |
|
| 2867 | - |
|
| 2868 | - $wpshop_cart = new wps_cart(); |
|
| 2869 | - $wpshop_products = new wpshop_products(); |
|
| 2870 | - |
|
| 2871 | - $response = ''; |
|
| 2872 | - $response_status = $has_variation = false; |
|
| 2873 | - $tpl_component = array(); |
|
| 2874 | - |
|
| 2875 | - // Check if variations exists |
|
| 2876 | - if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2877 | - |
|
| 2878 | - //Recover all selected variations |
|
| 2879 | - $variations_selected = array(); |
|
| 2880 | - if (!empty($wpshop_variation_selected)) { |
|
| 2881 | - foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2882 | - $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2883 | - $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2884 | - } |
|
| 2885 | - } |
|
| 2886 | - |
|
| 2887 | - // Check variations priority |
|
| 2888 | - $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2889 | - |
|
| 2890 | - // Check if $product_with_variation have variations |
|
| 2891 | - if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2892 | - |
|
| 2893 | - $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2894 | - $product_to_add_to_cart = $formatted_product[0]; |
|
| 2895 | - foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2896 | - $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2897 | - |
|
| 2898 | - /** For product with variation */ |
|
| 2899 | - $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2900 | - $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2901 | - $order_items[$pid]['product_variation'] = ''; |
|
| 2902 | - if (!empty($product_more_content['variations'])) { |
|
| 2903 | - foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2904 | - $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2905 | - } |
|
| 2906 | - } |
|
| 2907 | - } |
|
| 2908 | - |
|
| 2909 | - // If Product list is not empty, add products to order |
|
| 2910 | - if (!empty($order_items)) { |
|
| 2911 | - foreach ($order_items as $product_id => $d) { |
|
| 2912 | - $product_key = $product_id; |
|
| 2913 | - |
|
| 2914 | - // Formate datas |
|
| 2915 | - $product_id = $head_product_id = $d['product_id']; |
|
| 2916 | - $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2917 | - |
|
| 2918 | - // If product is a single variation product |
|
| 2919 | - if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2920 | - $product_id = $product_variation[0]; |
|
| 2921 | - } |
|
| 2922 | - |
|
| 2923 | - // Construct final product |
|
| 2924 | - $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2925 | - $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2887 | + // Check variations priority |
|
| 2888 | + $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2889 | + |
|
| 2890 | + // Check if $product_with_variation have variations |
|
| 2891 | + if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2892 | + |
|
| 2893 | + $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2894 | + $product_to_add_to_cart = $formatted_product[0]; |
|
| 2895 | + foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2896 | + $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2897 | + |
|
| 2898 | + /** For product with variation */ |
|
| 2899 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2900 | + $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2901 | + $order_items[$pid]['product_variation'] = ''; |
|
| 2902 | + if (!empty($product_more_content['variations'])) { |
|
| 2903 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2904 | + $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2905 | + } |
|
| 2906 | + } |
|
| 2907 | + } |
|
| 2908 | + |
|
| 2909 | + // If Product list is not empty, add products to order |
|
| 2910 | + if (!empty($order_items)) { |
|
| 2911 | + foreach ($order_items as $product_id => $d) { |
|
| 2912 | + $product_key = $product_id; |
|
| 2913 | + |
|
| 2914 | + // Formate datas |
|
| 2915 | + $product_id = $head_product_id = $d['product_id']; |
|
| 2916 | + $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2917 | + |
|
| 2918 | + // If product is a single variation product |
|
| 2919 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2920 | + $product_id = $product_variation[0]; |
|
| 2921 | + } |
|
| 2922 | + |
|
| 2923 | + // Construct final product |
|
| 2924 | + $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2925 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2926 | 2926 | $the_product['text_from'] = $product_with_variation['text_from']; |
| 2927 | 2927 | |
| 2928 | - // Add variation to product into cart for storage |
|
| 2929 | - if (!empty($product_variation)) { |
|
| 2930 | - $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2931 | - } |
|
| 2932 | - |
|
| 2933 | - // Free Variations Checking |
|
| 2934 | - if (!empty($d['free_variation'])) { |
|
| 2935 | - $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2936 | - $head_product_id = $the_product['product_id']; |
|
| 2937 | - } |
|
| 2938 | - |
|
| 2939 | - // If product is a variation, we check parent product general |
|
| 2940 | - if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2941 | - $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2942 | - if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2943 | - $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2944 | - $parent_meta = $parent_def['parent_post_meta']; |
|
| 2945 | - if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) { |
|
| 2946 | - $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2947 | - $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2948 | - $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2949 | - } |
|
| 2950 | - } |
|
| 2951 | - } |
|
| 2952 | - } |
|
| 2953 | - } |
|
| 2954 | - |
|
| 2955 | - if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2956 | - $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2957 | - if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2958 | - $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2959 | - $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2960 | - } |
|
| 2961 | - $the_product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et']; |
|
| 2962 | - $the_product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati']; |
|
| 2963 | - $the_product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva']; |
|
| 2964 | - } |
|
| 2965 | - |
|
| 2966 | - $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2967 | - // Add free variations to product |
|
| 2968 | - if (!empty($wpshop_free_variation)) { |
|
| 2969 | - $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2970 | - } |
|
| 2971 | - // Change picture if have a selected variation |
|
| 2972 | - $the_selected_variation = !empty($product_with_variation) && !empty($product_with_variation[$head_product_id]) && !empty($product_with_variation[$head_product_id]['variations']) ? $product_with_variation[$head_product_id]['variations'] : null; |
|
| 2973 | - $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2974 | - |
|
| 2975 | - // Price Display |
|
| 2976 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2977 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2978 | - $productPrice = ''; |
|
| 2979 | - if ($price_display) { |
|
| 2980 | - $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2981 | - } |
|
| 2982 | - |
|
| 2983 | - //Get Summary cart |
|
| 2984 | - $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2985 | - $response_status = true; |
|
| 2986 | - } else { |
|
| 2987 | - //Product without variations |
|
| 2988 | - $product_data = wpshop_products::get_product_data($product_id); |
|
| 2989 | - $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2928 | + // Add variation to product into cart for storage |
|
| 2929 | + if (!empty($product_variation)) { |
|
| 2930 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2931 | + } |
|
| 2932 | + |
|
| 2933 | + // Free Variations Checking |
|
| 2934 | + if (!empty($d['free_variation'])) { |
|
| 2935 | + $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2936 | + $head_product_id = $the_product['product_id']; |
|
| 2937 | + } |
|
| 2938 | + |
|
| 2939 | + // If product is a variation, we check parent product general |
|
| 2940 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2941 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2942 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2943 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2944 | + $parent_meta = $parent_def['parent_post_meta']; |
|
| 2945 | + if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) { |
|
| 2946 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2947 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2948 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2949 | + } |
|
| 2950 | + } |
|
| 2951 | + } |
|
| 2952 | + } |
|
| 2953 | + } |
|
| 2954 | + |
|
| 2955 | + if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2956 | + $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2957 | + if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2958 | + $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2959 | + $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2960 | + } |
|
| 2961 | + $the_product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et']; |
|
| 2962 | + $the_product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati']; |
|
| 2963 | + $the_product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva']; |
|
| 2964 | + } |
|
| 2965 | + |
|
| 2966 | + $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2967 | + // Add free variations to product |
|
| 2968 | + if (!empty($wpshop_free_variation)) { |
|
| 2969 | + $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2970 | + } |
|
| 2971 | + // Change picture if have a selected variation |
|
| 2972 | + $the_selected_variation = !empty($product_with_variation) && !empty($product_with_variation[$head_product_id]) && !empty($product_with_variation[$head_product_id]['variations']) ? $product_with_variation[$head_product_id]['variations'] : null; |
|
| 2973 | + $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2974 | + |
|
| 2975 | + // Price Display |
|
| 2976 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2977 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2978 | + $productPrice = ''; |
|
| 2979 | + if ($price_display) { |
|
| 2980 | + $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2981 | + } |
|
| 2982 | + |
|
| 2983 | + //Get Summary cart |
|
| 2984 | + $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2990 | 2985 | $response_status = true; |
| 2991 | - } |
|
| 2992 | - } |
|
| 2986 | + } else { |
|
| 2987 | + //Product without variations |
|
| 2988 | + $product_data = wpshop_products::get_product_data($product_id); |
|
| 2989 | + $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2990 | + $response_status = true; |
|
| 2991 | + } |
|
| 2992 | + } |
|
| 2993 | 2993 | |
| 2994 | - return array($response_status, $response); |
|
| 2995 | - } |
|
| 2994 | + return array($response_status, $response); |
|
| 2995 | + } |
|
| 2996 | 2996 | |
| 2997 | - /** |
|
| 2998 | - * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2999 | - * |
|
| 3000 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 3001 | - */ |
|
| 3002 | - public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 3003 | - { |
|
| 3004 | - echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 3005 | - } |
|
| 2997 | + /** |
|
| 2998 | + * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2999 | + * |
|
| 3000 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 3001 | + */ |
|
| 3002 | + public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 3003 | + { |
|
| 3004 | + echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 3005 | + } |
|
| 3006 | 3006 | |
| 3007 | - /** |
|
| 3008 | - * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 3009 | - * |
|
| 3010 | - * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 3011 | - * @param integer $product_id The basic product choose by the user in frontend |
|
| 3012 | - * |
|
| 3013 | - * @return array The product list for adding to the cart build by variation priority |
|
| 3014 | - */ |
|
| 3015 | - public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 3016 | - { |
|
| 3017 | - global $wpdb; |
|
| 3018 | - $all_required_variations_selected = $no_selected_variation = true; |
|
| 3019 | - $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 3020 | - |
|
| 3021 | - // Check if all required variations are selected |
|
| 3022 | - $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 3023 | - foreach ($selected_variation as $k => $value) { |
|
| 3024 | - if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 3025 | - $all_required_variations_selected = false; |
|
| 3026 | - } |
|
| 3027 | - if ($value != 0) { |
|
| 3028 | - $no_selected_variation = false; |
|
| 3029 | - } |
|
| 3030 | - } |
|
| 3031 | - if (!empty($selected_variation)) { |
|
| 3032 | - //Check variations configuration |
|
| 3033 | - $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 3034 | - // Check variations type |
|
| 3035 | - $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 3036 | - $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 3037 | - |
|
| 3038 | - //Check defined variation priority |
|
| 3039 | - $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 3040 | - $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 3041 | - |
|
| 3042 | - // Recover all product variations |
|
| 3043 | - $query_variation = $selected_variation; |
|
| 3044 | - // Delete free variations |
|
| 3045 | - unset($query_variation['free']); |
|
| 3046 | - |
|
| 3047 | - if ($product_variation_type == 'single') { |
|
| 3048 | - // Get single variations |
|
| 3049 | - $single_variations = array(); |
|
| 3050 | - foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 3051 | - if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 3052 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id); |
|
| 3053 | - $single_variation_id = $wpdb->get_var($query); |
|
| 3054 | - if (!empty($single_variation_id)) { |
|
| 3055 | - $single_variations[] = $single_variation_id; |
|
| 3056 | - unset($query_variation[$attribute_code]); |
|
| 3057 | - } |
|
| 3058 | - } |
|
| 3059 | - } |
|
| 3060 | - } else { |
|
| 3061 | - // Get combined variations |
|
| 3062 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_key = '_wpshop_variations_attribute_def' AND P_META.meta_value = '" . serialize($query_variation) . "'", $product_id); |
|
| 3063 | - $combined_variation_id = $wpdb->get_var($query); |
|
| 3064 | - if (!empty($combined_variation_id)) { |
|
| 3065 | - $combined_variations[] = $combined_variation_id; |
|
| 3066 | - } |
|
| 3067 | - |
|
| 3068 | - } |
|
| 3069 | - |
|
| 3070 | - //If all required variations are not selected |
|
| 3071 | - if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3072 | - $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3073 | - // If we choose to display lower price variation combinaison |
|
| 3074 | - if (empty($product_variation_configuration) || (!empty($product_variation_configuration) && empty($product_variation_configuration['options'])) || (!empty($product_variation_configuration) && !empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['price_display']) && !empty($product_variation_configuration['options']['price_display']['lower_price']))) { |
|
| 3075 | - //Get lower price variation combinaison |
|
| 3076 | - $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3077 | - if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3078 | - foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3079 | - $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3080 | - } |
|
| 3081 | - } |
|
| 3082 | - $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3083 | - } else { |
|
| 3084 | - $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3085 | - } |
|
| 3086 | - } else { |
|
| 3087 | - $product_to_add_to_cart['text_from'] = ''; |
|
| 3088 | - $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3089 | - } |
|
| 3090 | - } |
|
| 3007 | + /** |
|
| 3008 | + * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 3009 | + * |
|
| 3010 | + * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 3011 | + * @param integer $product_id The basic product choose by the user in frontend |
|
| 3012 | + * |
|
| 3013 | + * @return array The product list for adding to the cart build by variation priority |
|
| 3014 | + */ |
|
| 3015 | + public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 3016 | + { |
|
| 3017 | + global $wpdb; |
|
| 3018 | + $all_required_variations_selected = $no_selected_variation = true; |
|
| 3019 | + $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 3020 | + |
|
| 3021 | + // Check if all required variations are selected |
|
| 3022 | + $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 3023 | + foreach ($selected_variation as $k => $value) { |
|
| 3024 | + if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 3025 | + $all_required_variations_selected = false; |
|
| 3026 | + } |
|
| 3027 | + if ($value != 0) { |
|
| 3028 | + $no_selected_variation = false; |
|
| 3029 | + } |
|
| 3030 | + } |
|
| 3031 | + if (!empty($selected_variation)) { |
|
| 3032 | + //Check variations configuration |
|
| 3033 | + $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 3034 | + // Check variations type |
|
| 3035 | + $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 3036 | + $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 3037 | + |
|
| 3038 | + //Check defined variation priority |
|
| 3039 | + $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 3040 | + $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 3041 | + |
|
| 3042 | + // Recover all product variations |
|
| 3043 | + $query_variation = $selected_variation; |
|
| 3044 | + // Delete free variations |
|
| 3045 | + unset($query_variation['free']); |
|
| 3046 | + |
|
| 3047 | + if ($product_variation_type == 'single') { |
|
| 3048 | + // Get single variations |
|
| 3049 | + $single_variations = array(); |
|
| 3050 | + foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 3051 | + if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 3052 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id); |
|
| 3053 | + $single_variation_id = $wpdb->get_var($query); |
|
| 3054 | + if (!empty($single_variation_id)) { |
|
| 3055 | + $single_variations[] = $single_variation_id; |
|
| 3056 | + unset($query_variation[$attribute_code]); |
|
| 3057 | + } |
|
| 3058 | + } |
|
| 3059 | + } |
|
| 3060 | + } else { |
|
| 3061 | + // Get combined variations |
|
| 3062 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_key = '_wpshop_variations_attribute_def' AND P_META.meta_value = '" . serialize($query_variation) . "'", $product_id); |
|
| 3063 | + $combined_variation_id = $wpdb->get_var($query); |
|
| 3064 | + if (!empty($combined_variation_id)) { |
|
| 3065 | + $combined_variations[] = $combined_variation_id; |
|
| 3066 | + } |
|
| 3091 | 3067 | |
| 3092 | - return $product_to_add_to_cart; |
|
| 3093 | - } |
|
| 3068 | + } |
|
| 3094 | 3069 | |
| 3095 | - public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3096 | - { |
|
| 3097 | - global $wpdb; |
|
| 3098 | - |
|
| 3099 | - if (!empty($product_variations)) { |
|
| 3100 | - // Initialize variations total price datas |
|
| 3101 | - $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3102 | - $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3103 | - $vat_rate = 0; |
|
| 3104 | - $discount_amount = $discount_rate = $special_price = 0; |
|
| 3105 | - // Recover Head product metadata |
|
| 3106 | - $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3107 | - $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3108 | - if (!empty($tva_rate_id)) { |
|
| 3109 | - // Recover VAT Rate of product |
|
| 3110 | - $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3111 | - $vat_rate = $wpdb->get_var($query); |
|
| 3112 | - } |
|
| 3113 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3114 | - foreach ($product_variations as $product_variation) { |
|
| 3115 | - $variation_metadata['product_price'] = 0; |
|
| 3116 | - $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3117 | - if (!empty($variation_metadata)) { |
|
| 3118 | - $p_et = ((empty($price_piloting) || $price_piloting == 'TTC') ? ((!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + ($vat_rate / 100))) : $variation_metadata['price_ht']); |
|
| 3119 | - $p_ati = ((empty($price_piloting) || $price_piloting == 'TTC') ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) : ($variation_metadata['price_ht'] * (1 + ($vat_rate / 100)))); |
|
| 3120 | - |
|
| 3121 | - $variations_total_price['price_et'] += $p_et; |
|
| 3122 | - $variations_total_price['price_ati'] += $p_ati; |
|
| 3123 | - $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3124 | - |
|
| 3125 | - $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3126 | - |
|
| 3127 | - // Check discount |
|
| 3128 | - $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3129 | - if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3130 | - $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3131 | - $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3132 | - $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3133 | - $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3134 | - |
|
| 3135 | - if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3136 | - $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3137 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3138 | - $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3139 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3140 | - $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3141 | - } |
|
| 3142 | - } |
|
| 3143 | - |
|
| 3144 | - $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3145 | - $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3146 | - } |
|
| 3147 | - } |
|
| 3148 | - |
|
| 3149 | - // Check if add or replace variation price to head product |
|
| 3150 | - /** |
|
| 3151 | - * Since 1.4.3.7 |
|
| 3152 | - * L'option du produit remplace le prix du produit de tête. |
|
| 3153 | - */ |
|
| 3070 | + //If all required variations are not selected |
|
| 3071 | + if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3072 | + $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3073 | + // If we choose to display lower price variation combinaison |
|
| 3074 | + if (empty($product_variation_configuration) || (!empty($product_variation_configuration) && empty($product_variation_configuration['options'])) || (!empty($product_variation_configuration) && !empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['price_display']) && !empty($product_variation_configuration['options']['price_display']['lower_price']))) { |
|
| 3075 | + //Get lower price variation combinaison |
|
| 3076 | + $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3077 | + if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3078 | + foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3079 | + $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3080 | + } |
|
| 3081 | + } |
|
| 3082 | + $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3083 | + } else { |
|
| 3084 | + $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3085 | + } |
|
| 3086 | + } else { |
|
| 3087 | + $product_to_add_to_cart['text_from'] = ''; |
|
| 3088 | + $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3089 | + } |
|
| 3090 | + } |
|
| 3091 | + |
|
| 3092 | + return $product_to_add_to_cart; |
|
| 3093 | + } |
|
| 3094 | + |
|
| 3095 | + public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3096 | + { |
|
| 3097 | + global $wpdb; |
|
| 3098 | + |
|
| 3099 | + if (!empty($product_variations)) { |
|
| 3100 | + // Initialize variations total price datas |
|
| 3101 | + $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3102 | + $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3103 | + $vat_rate = 0; |
|
| 3104 | + $discount_amount = $discount_rate = $special_price = 0; |
|
| 3105 | + // Recover Head product metadata |
|
| 3106 | + $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3107 | + $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3108 | + if (!empty($tva_rate_id)) { |
|
| 3109 | + // Recover VAT Rate of product |
|
| 3110 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3111 | + $vat_rate = $wpdb->get_var($query); |
|
| 3112 | + } |
|
| 3113 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3114 | + foreach ($product_variations as $product_variation) { |
|
| 3115 | + $variation_metadata['product_price'] = 0; |
|
| 3116 | + $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3117 | + if (!empty($variation_metadata)) { |
|
| 3118 | + $p_et = ((empty($price_piloting) || $price_piloting == 'TTC') ? ((!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + ($vat_rate / 100))) : $variation_metadata['price_ht']); |
|
| 3119 | + $p_ati = ((empty($price_piloting) || $price_piloting == 'TTC') ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) : ($variation_metadata['price_ht'] * (1 + ($vat_rate / 100)))); |
|
| 3120 | + |
|
| 3121 | + $variations_total_price['price_et'] += $p_et; |
|
| 3122 | + $variations_total_price['price_ati'] += $p_ati; |
|
| 3123 | + $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3124 | + |
|
| 3125 | + $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3126 | + |
|
| 3127 | + // Check discount |
|
| 3128 | + $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3129 | + if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3130 | + $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3131 | + $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3132 | + $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3133 | + $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3134 | + |
|
| 3135 | + if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3136 | + $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3137 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3138 | + $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3139 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3140 | + $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3141 | + } |
|
| 3142 | + } |
|
| 3143 | + |
|
| 3144 | + $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3145 | + $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3146 | + } |
|
| 3147 | + } |
|
| 3148 | + |
|
| 3149 | + // Check if add or replace variation price to head product |
|
| 3150 | + /** |
|
| 3151 | + * Since 1.4.3.7 |
|
| 3152 | + * L'option du produit remplace le prix du produit de tête. |
|
| 3153 | + */ |
|
| 3154 | 3154 | if( true ) { |
| 3155 | - //Replace the product price |
|
| 3156 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3157 | - $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3158 | - $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3159 | - |
|
| 3160 | - $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3161 | - $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3162 | - $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3163 | - } else { |
|
| 3164 | - $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3165 | - $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3166 | - $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3167 | - } |
|
| 3168 | - } else { |
|
| 3169 | - // Add variations price to product price |
|
| 3170 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3171 | - $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3172 | - $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3173 | - |
|
| 3174 | - $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3175 | - $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3176 | - $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3177 | - } else { |
|
| 3178 | - $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3179 | - $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3180 | - $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3181 | - } |
|
| 3182 | - // Check parent discount |
|
| 3183 | - $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3184 | - if (!empty($parent_discount_config)) { |
|
| 3185 | - $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price']; |
|
| 3186 | - $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht']; |
|
| 3187 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3188 | - |
|
| 3189 | - if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3190 | - $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3191 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3192 | - $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3193 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3194 | - $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3195 | - } |
|
| 3196 | - } |
|
| 3197 | - } |
|
| 3198 | - } else { |
|
| 3199 | - // If product have just Free variations |
|
| 3200 | - $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3201 | - if (!empty($discount_config)) { |
|
| 3202 | - $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price']; |
|
| 3203 | - $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht']; |
|
| 3204 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3205 | - } |
|
| 3206 | - } |
|
| 3155 | + //Replace the product price |
|
| 3156 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3157 | + $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3158 | + $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3159 | + |
|
| 3160 | + $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3161 | + $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3162 | + $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3163 | + } else { |
|
| 3164 | + $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3165 | + $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3166 | + $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3167 | + } |
|
| 3168 | + } else { |
|
| 3169 | + // Add variations price to product price |
|
| 3170 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3171 | + $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3172 | + $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3173 | + |
|
| 3174 | + $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3175 | + $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3176 | + $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3177 | + } else { |
|
| 3178 | + $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3179 | + $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3180 | + $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3181 | + } |
|
| 3182 | + // Check parent discount |
|
| 3183 | + $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3184 | + if (!empty($parent_discount_config)) { |
|
| 3185 | + $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price']; |
|
| 3186 | + $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht']; |
|
| 3187 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3188 | + |
|
| 3189 | + if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3190 | + $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3191 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3192 | + $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3193 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3194 | + $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3195 | + } |
|
| 3196 | + } |
|
| 3197 | + } |
|
| 3198 | + } else { |
|
| 3199 | + // If product have just Free variations |
|
| 3200 | + $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3201 | + if (!empty($discount_config)) { |
|
| 3202 | + $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price']; |
|
| 3203 | + $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht']; |
|
| 3204 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3205 | + } |
|
| 3206 | + } |
|
| 3207 | 3207 | |
| 3208 | - // Text From indicator |
|
| 3209 | - if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3210 | - $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3211 | - } |
|
| 3212 | - return $product_into_cart; |
|
| 3213 | - } |
|
| 3208 | + // Text From indicator |
|
| 3209 | + if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3210 | + $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3211 | + } |
|
| 3212 | + return $product_into_cart; |
|
| 3213 | + } |
|
| 3214 | 3214 | |
| 3215 | - /** |
|
| 3216 | - * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3217 | - * |
|
| 3218 | - * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3219 | - * @param array $output_order The good order for attribute defined by administrator |
|
| 3220 | - * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3221 | - * |
|
| 3222 | - * @return array The array containing all product options ordered as the admin configure it |
|
| 3223 | - */ |
|
| 3224 | - public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3225 | - { |
|
| 3226 | - $variation_attribute_ordered = array(); |
|
| 3227 | - $variation_attribute_ordered['prices'] = array(); |
|
| 3228 | - $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3229 | - |
|
| 3230 | - if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3231 | - foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3232 | - $variation_tpl_component = array(); |
|
| 3233 | - foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3234 | - $variation_tpl_component['VARIATION_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value); |
|
| 3235 | - } |
|
| 3236 | - $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3237 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3238 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3239 | - $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part); |
|
| 3240 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3241 | - $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3242 | - } |
|
| 3243 | - } else { |
|
| 3244 | - $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part); |
|
| 3245 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3246 | - $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3247 | - } |
|
| 3248 | - } |
|
| 3249 | - unset($variation_tpl_component); |
|
| 3250 | - } |
|
| 3251 | - } |
|
| 3215 | + /** |
|
| 3216 | + * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3217 | + * |
|
| 3218 | + * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3219 | + * @param array $output_order The good order for attribute defined by administrator |
|
| 3220 | + * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3221 | + * |
|
| 3222 | + * @return array The array containing all product options ordered as the admin configure it |
|
| 3223 | + */ |
|
| 3224 | + public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3225 | + { |
|
| 3226 | + $variation_attribute_ordered = array(); |
|
| 3227 | + $variation_attribute_ordered['prices'] = array(); |
|
| 3228 | + $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3229 | + |
|
| 3230 | + if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3231 | + foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3232 | + $variation_tpl_component = array(); |
|
| 3233 | + foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3234 | + $variation_tpl_component['VARIATION_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value); |
|
| 3235 | + } |
|
| 3236 | + $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3237 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3238 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3239 | + $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part); |
|
| 3240 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3241 | + $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3242 | + } |
|
| 3243 | + } else { |
|
| 3244 | + $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part); |
|
| 3245 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3246 | + $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3247 | + } |
|
| 3248 | + } |
|
| 3249 | + unset($variation_tpl_component); |
|
| 3250 | + } |
|
| 3251 | + } |
|
| 3252 | 3252 | |
| 3253 | - if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3254 | - foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3255 | - $variation_tpl_component = array(); |
|
| 3256 | - foreach ($variation_details as $info_name => $info_value) { |
|
| 3257 | - if ($info_name != 'item_meta') { |
|
| 3258 | - $variation_tpl_component['VARIATION_DETAIL_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value); |
|
| 3259 | - } |
|
| 3260 | - } |
|
| 3261 | - foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3262 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3263 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3264 | - $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3265 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3266 | - |
|
| 3267 | - $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3268 | - } |
|
| 3269 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3270 | - $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part); |
|
| 3271 | - } |
|
| 3272 | - unset($variation_tpl_component); |
|
| 3273 | - } |
|
| 3274 | - } |
|
| 3253 | + if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3254 | + foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3255 | + $variation_tpl_component = array(); |
|
| 3256 | + foreach ($variation_details as $info_name => $info_value) { |
|
| 3257 | + if ($info_name != 'item_meta') { |
|
| 3258 | + $variation_tpl_component['VARIATION_DETAIL_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value); |
|
| 3259 | + } |
|
| 3260 | + } |
|
| 3261 | + foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3262 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3263 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3264 | + $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3265 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3275 | 3266 | |
| 3276 | - /** Free Variation part */ |
|
| 3277 | - if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3278 | - foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3279 | - if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3280 | - $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3281 | - $attribute_code = $variation_definition[0]; |
|
| 3282 | - $attribute_selected_value = $variation_definition[1]; |
|
| 3283 | - } else { |
|
| 3284 | - $attribute_code = $build_variation_key; |
|
| 3285 | - $attribute_selected_value = $build_variation; |
|
| 3286 | - } |
|
| 3287 | - |
|
| 3288 | - $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3289 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3290 | - $value_to_outut = $attribute_selected_value; |
|
| 3291 | - switch ($free_variation_attribute_def->data_type) { |
|
| 3292 | - case 'datetime': |
|
| 3293 | - $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3294 | - break; |
|
| 3295 | - } |
|
| 3296 | - |
|
| 3297 | - if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3298 | - switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3299 | - case 'custom': |
|
| 3300 | - case 'internal': |
|
| 3301 | - $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3302 | - $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3303 | - break; |
|
| 3304 | - } |
|
| 3305 | - } |
|
| 3306 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3307 | - $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3308 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3309 | - if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3310 | - $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_code), $template_part); |
|
| 3311 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3312 | - $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3313 | - } |
|
| 3314 | - } |
|
| 3315 | - unset($variation_tpl_component); |
|
| 3316 | - } |
|
| 3317 | - } |
|
| 3318 | - return $variation_attribute_ordered; |
|
| 3319 | - } |
|
| 3267 | + $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3268 | + } |
|
| 3269 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3270 | + $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part); |
|
| 3271 | + } |
|
| 3272 | + unset($variation_tpl_component); |
|
| 3273 | + } |
|
| 3274 | + } |
|
| 3320 | 3275 | |
| 3321 | - public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3322 | - { |
|
| 3323 | - $response = array(); |
|
| 3324 | - /** Selected Product image **/ |
|
| 3325 | - $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3326 | - if (!empty($post_thumbnail_id)) { |
|
| 3327 | - $response['img_id'] = $post_thumbnail_id; |
|
| 3328 | - $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3329 | - $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3330 | - } |
|
| 3276 | + /** Free Variation part */ |
|
| 3277 | + if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3278 | + foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3279 | + if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3280 | + $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3281 | + $attribute_code = $variation_definition[0]; |
|
| 3282 | + $attribute_selected_value = $variation_definition[1]; |
|
| 3283 | + } else { |
|
| 3284 | + $attribute_code = $build_variation_key; |
|
| 3285 | + $attribute_selected_value = $build_variation; |
|
| 3286 | + } |
|
| 3331 | 3287 | |
| 3332 | - /** check if have one variation **/ |
|
| 3333 | - if (!empty($variations) && count($variations) == 1) { |
|
| 3334 | - $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3335 | - if (!empty($variation_attached_image_id)) { |
|
| 3336 | - $response['img_id'] = $variation_attached_image_id; |
|
| 3337 | - $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3338 | - $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3339 | - } |
|
| 3340 | - } |
|
| 3341 | - return $response; |
|
| 3342 | - } |
|
| 3288 | + $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3289 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3290 | + $value_to_outut = $attribute_selected_value; |
|
| 3291 | + switch ($free_variation_attribute_def->data_type) { |
|
| 3292 | + case 'datetime': |
|
| 3293 | + $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3294 | + break; |
|
| 3295 | + } |
|
| 3343 | 3296 | |
| 3344 | - /** Add a meta box of product sales history in product administration panel **/ |
|
| 3345 | - public function meta_box_product_sale_informations() |
|
| 3346 | - { |
|
| 3347 | - global $post; |
|
| 3348 | - $product_id = $post->ID; |
|
| 3349 | - |
|
| 3350 | - $variations = self::get_variation($product_id); |
|
| 3351 | - |
|
| 3352 | - $sales_informations = array(); |
|
| 3353 | - /** Query **/ |
|
| 3354 | - $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3355 | - $query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE'))); |
|
| 3356 | - $orders = new WP_Query($query_args); |
|
| 3357 | - if (!empty($orders) && !empty($orders->posts)) { |
|
| 3358 | - foreach ($orders->posts as $order) { |
|
| 3359 | - $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3360 | - $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3361 | - $sales_informations[] = array( |
|
| 3362 | - 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3363 | - 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3364 | - 'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '', |
|
| 3365 | - 'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '', |
|
| 3366 | - 'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '', |
|
| 3367 | - ); |
|
| 3368 | - } |
|
| 3369 | - } |
|
| 3297 | + if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3298 | + switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3299 | + case 'custom': |
|
| 3300 | + case 'internal': |
|
| 3301 | + $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3302 | + $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3303 | + break; |
|
| 3304 | + } |
|
| 3305 | + } |
|
| 3306 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3307 | + $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3308 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3309 | + if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3310 | + $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_code), $template_part); |
|
| 3311 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3312 | + $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3313 | + } |
|
| 3314 | + } |
|
| 3315 | + unset($variation_tpl_component); |
|
| 3316 | + } |
|
| 3317 | + } |
|
| 3318 | + return $variation_attribute_ordered; |
|
| 3319 | + } |
|
| 3370 | 3320 | |
| 3371 | - /** If product has been ordered **/ |
|
| 3372 | - $output = ''; |
|
| 3373 | - if (!empty($sales_informations)) { |
|
| 3374 | - $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3375 | - $output .= '<ul>'; |
|
| 3376 | - foreach ($sales_informations as $sales_information) { |
|
| 3377 | - $output .= '<li>' . sprintf(__('Ordered by %s %s (%s) on %s (Order ref. : %s)', 'wpshop'), $sales_information['customer_name'], $sales_information['customer_firstname'], $sales_information['customer_email'], $sales_information['order_date'], $sales_information['order_key']) . '</li>'; |
|
| 3378 | - } |
|
| 3379 | - $output .= '</ul>'; |
|
| 3380 | - } else { |
|
| 3381 | - $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3382 | - } |
|
| 3321 | + public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3322 | + { |
|
| 3323 | + $response = array(); |
|
| 3324 | + /** Selected Product image **/ |
|
| 3325 | + $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3326 | + if (!empty($post_thumbnail_id)) { |
|
| 3327 | + $response['img_id'] = $post_thumbnail_id; |
|
| 3328 | + $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3329 | + $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3330 | + } |
|
| 3383 | 3331 | |
| 3384 | - echo $output; |
|
| 3385 | - } |
|
| 3332 | + /** check if have one variation **/ |
|
| 3333 | + if (!empty($variations) && count($variations) == 1) { |
|
| 3334 | + $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3335 | + if (!empty($variation_attached_image_id)) { |
|
| 3336 | + $response['img_id'] = $variation_attached_image_id; |
|
| 3337 | + $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3338 | + $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3339 | + } |
|
| 3340 | + } |
|
| 3341 | + return $response; |
|
| 3342 | + } |
|
| 3386 | 3343 | |
| 3387 | - public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3388 | - { |
|
| 3389 | - global $wpdb, $wpshop_payment; |
|
| 3390 | - $output = ''; |
|
| 3391 | - $tpl_component = array(); |
|
| 3392 | - /** Get attribute order for current product */ |
|
| 3393 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3394 | - $output_order = array(); |
|
| 3395 | - if (count($product_attribute_order_detail) > 0) { |
|
| 3396 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3397 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3398 | - if (!empty($attribute_def->code)) { |
|
| 3399 | - $output_order[$attribute_def->code] = $position; |
|
| 3400 | - } |
|
| 3401 | - |
|
| 3402 | - } |
|
| 3403 | - } |
|
| 3404 | - } |
|
| 3405 | - $variation_attribute_ordered = array(); |
|
| 3406 | - |
|
| 3407 | - /** Check if product is a variation and change his name **/ |
|
| 3408 | - $product_post_type = get_post_type($the_product['product_id']); |
|
| 3409 | - if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3410 | - $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3411 | - $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3412 | - $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3413 | - } |
|
| 3344 | + /** Add a meta box of product sales history in product administration panel **/ |
|
| 3345 | + public function meta_box_product_sale_informations() |
|
| 3346 | + { |
|
| 3347 | + global $post; |
|
| 3348 | + $product_id = $post->ID; |
|
| 3349 | + |
|
| 3350 | + $variations = self::get_variation($product_id); |
|
| 3351 | + |
|
| 3352 | + $sales_informations = array(); |
|
| 3353 | + /** Query **/ |
|
| 3354 | + $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3355 | + $query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE'))); |
|
| 3356 | + $orders = new WP_Query($query_args); |
|
| 3357 | + if (!empty($orders) && !empty($orders->posts)) { |
|
| 3358 | + foreach ($orders->posts as $order) { |
|
| 3359 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3360 | + $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3361 | + $sales_informations[] = array( |
|
| 3362 | + 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3363 | + 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3364 | + 'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '', |
|
| 3365 | + 'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '', |
|
| 3366 | + 'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '', |
|
| 3367 | + ); |
|
| 3368 | + } |
|
| 3369 | + } |
|
| 3414 | 3370 | |
| 3415 | - foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3416 | - if ($product_definition_key != 'item_meta') { |
|
| 3417 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3418 | - if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3419 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3420 | - } |
|
| 3421 | - } else { |
|
| 3422 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3423 | - } |
|
| 3424 | - } |
|
| 3371 | + /** If product has been ordered **/ |
|
| 3372 | + $output = ''; |
|
| 3373 | + if (!empty($sales_informations)) { |
|
| 3374 | + $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3375 | + $output .= '<ul>'; |
|
| 3376 | + foreach ($sales_informations as $sales_information) { |
|
| 3377 | + $output .= '<li>' . sprintf(__('Ordered by %s %s (%s) on %s (Order ref. : %s)', 'wpshop'), $sales_information['customer_name'], $sales_information['customer_firstname'], $sales_information['customer_email'], $sales_information['order_date'], $sales_information['order_key']) . '</li>'; |
|
| 3378 | + } |
|
| 3379 | + $output .= '</ul>'; |
|
| 3380 | + } else { |
|
| 3381 | + $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3382 | + } |
|
| 3425 | 3383 | |
| 3426 | - ksort($variation_attribute_ordered['attribute_list']); |
|
| 3427 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3428 | - foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3429 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3430 | - } |
|
| 3384 | + echo $output; |
|
| 3385 | + } |
|
| 3431 | 3386 | |
| 3432 | - /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3433 | - $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3434 | - if (!empty($attribute_list)) { |
|
| 3435 | - foreach ($attribute_list as $attribute_def) { |
|
| 3436 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3437 | - } |
|
| 3438 | - } |
|
| 3387 | + public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3388 | + { |
|
| 3389 | + global $wpdb, $wpshop_payment; |
|
| 3390 | + $output = ''; |
|
| 3391 | + $tpl_component = array(); |
|
| 3392 | + /** Get attribute order for current product */ |
|
| 3393 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3394 | + $output_order = array(); |
|
| 3395 | + if (count($product_attribute_order_detail) > 0) { |
|
| 3396 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3397 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3398 | + if (!empty($attribute_def->code)) { |
|
| 3399 | + $output_order[$attribute_def->code] = $position; |
|
| 3400 | + } |
|
| 3439 | 3401 | |
| 3440 | - /** Fill the array with all prices for different variations */ |
|
| 3441 | - foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3442 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3443 | - } |
|
| 3402 | + } |
|
| 3403 | + } |
|
| 3404 | + } |
|
| 3405 | + $variation_attribute_ordered = array(); |
|
| 3406 | + |
|
| 3407 | + /** Check if product is a variation and change his name **/ |
|
| 3408 | + $product_post_type = get_post_type($the_product['product_id']); |
|
| 3409 | + if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3410 | + $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3411 | + $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3412 | + $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3413 | + } |
|
| 3444 | 3414 | |
| 3445 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3446 | - $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3447 | - $post_list_with_options = $wpdb->get_results($query); |
|
| 3448 | - if (!empty($post_list_with_options)) { |
|
| 3449 | - $additionnal_price = 0; |
|
| 3450 | - foreach ($post_list_with_options as $product_info) { |
|
| 3451 | - $product_meta = unserialize($product_info->meta_value); |
|
| 3452 | - if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3453 | - $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3454 | - |
|
| 3455 | - $the_product = array_merge(array( |
|
| 3456 | - 'product_id' => $product_info->post_id, |
|
| 3457 | - 'product_qty' => 1, |
|
| 3458 | - ), $product); |
|
| 3459 | - |
|
| 3460 | - $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3461 | - $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3462 | - |
|
| 3463 | - $tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate)); |
|
| 3464 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3465 | - } |
|
| 3466 | - } |
|
| 3467 | - } |
|
| 3415 | + foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3416 | + if ($product_definition_key != 'item_meta') { |
|
| 3417 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3418 | + if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3419 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3420 | + } |
|
| 3421 | + } else { |
|
| 3422 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3423 | + } |
|
| 3424 | + } |
|
| 3468 | 3425 | |
| 3469 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3470 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3471 | - if (!empty($additionnal_price)) { |
|
| 3472 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3473 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3474 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3475 | - } |
|
| 3426 | + ksort($variation_attribute_ordered['attribute_list']); |
|
| 3427 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3428 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3429 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3430 | + } |
|
| 3431 | + |
|
| 3432 | + /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3433 | + $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3434 | + if (!empty($attribute_list)) { |
|
| 3435 | + foreach ($attribute_list as $attribute_def) { |
|
| 3436 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3437 | + } |
|
| 3438 | + } |
|
| 3439 | + |
|
| 3440 | + /** Fill the array with all prices for different variations */ |
|
| 3441 | + foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3442 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3443 | + } |
|
| 3444 | + |
|
| 3445 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3446 | + $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3447 | + $post_list_with_options = $wpdb->get_results($query); |
|
| 3448 | + if (!empty($post_list_with_options)) { |
|
| 3449 | + $additionnal_price = 0; |
|
| 3450 | + foreach ($post_list_with_options as $product_info) { |
|
| 3451 | + $product_meta = unserialize($product_info->meta_value); |
|
| 3452 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3453 | + $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3454 | + |
|
| 3455 | + $the_product = array_merge(array( |
|
| 3456 | + 'product_id' => $product_info->post_id, |
|
| 3457 | + 'product_qty' => 1, |
|
| 3458 | + ), $product); |
|
| 3459 | + |
|
| 3460 | + $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3461 | + $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3462 | + |
|
| 3463 | + $tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate)); |
|
| 3464 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3465 | + } |
|
| 3466 | + } |
|
| 3467 | + } |
|
| 3476 | 3468 | |
| 3477 | - /** Call informtion for partial payment */ |
|
| 3478 | - $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3479 | - $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3469 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3470 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3471 | + if (!empty($additionnal_price)) { |
|
| 3472 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3473 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3474 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3475 | + } |
|
| 3480 | 3476 | |
| 3481 | - /** Define the current selected currency for the order summary */ |
|
| 3477 | + /** Call informtion for partial payment */ |
|
| 3478 | + $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3479 | + $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3480 | + |
|
| 3481 | + /** Define the current selected currency for the order summary */ |
|
| 3482 | 3482 | // $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
| 3483 | - $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3484 | - return $output; |
|
| 3485 | - } |
|
| 3483 | + $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3484 | + return $output; |
|
| 3485 | + } |
|
| 3486 | 3486 | |
| 3487 | - /** |
|
| 3488 | - * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3489 | - * @param string $ID ID product variations or not |
|
| 3490 | - * @return string Return ID |
|
| 3491 | - */ |
|
| 3492 | - public static function get_id_variation($ID) |
|
| 3493 | - { |
|
| 3494 | - $result = explode('__', $ID); |
|
| 3495 | - return end($result); |
|
| 3496 | - } |
|
| 3487 | + /** |
|
| 3488 | + * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3489 | + * @param string $ID ID product variations or not |
|
| 3490 | + * @return string Return ID |
|
| 3491 | + */ |
|
| 3492 | + public static function get_id_variation($ID) |
|
| 3493 | + { |
|
| 3494 | + $result = explode('__', $ID); |
|
| 3495 | + return end($result); |
|
| 3496 | + } |
|
| 3497 | 3497 | |
| 3498 | - /** |
|
| 3499 | - * Update all variations definitions who not modified |
|
| 3500 | - * @param array $new_value |
|
| 3501 | - * @param array $old_value |
|
| 3502 | - * @return array $new_value |
|
| 3503 | - */ |
|
| 3504 | - public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3505 | - { |
|
| 3506 | - global $wpdb; |
|
| 3507 | - $query = $wpdb->prepare('SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND meta_value LIKE %s', '_wpshop_variation_defining', '%' . serialize('follow_general_config') . '%'); |
|
| 3508 | - foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3509 | - $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3510 | - $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3511 | - update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3512 | - } |
|
| 3513 | - return $new_value; |
|
| 3514 | - } |
|
| 3498 | + /** |
|
| 3499 | + * Update all variations definitions who not modified |
|
| 3500 | + * @param array $new_value |
|
| 3501 | + * @param array $old_value |
|
| 3502 | + * @return array $new_value |
|
| 3503 | + */ |
|
| 3504 | + public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3505 | + { |
|
| 3506 | + global $wpdb; |
|
| 3507 | + $query = $wpdb->prepare('SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND meta_value LIKE %s', '_wpshop_variation_defining', '%' . serialize('follow_general_config') . '%'); |
|
| 3508 | + foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3509 | + $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3510 | + $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3511 | + update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3512 | + } |
|
| 3513 | + return $new_value; |
|
| 3514 | + } |
|
| 3515 | 3515 | |
| 3516 | - public static function variation_parameters_save($current_post_id, $options) |
|
| 3517 | - { |
|
| 3516 | + public static function variation_parameters_save($current_post_id, $options) |
|
| 3517 | + { |
|
| 3518 | 3518 | $variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true); |
| 3519 | - $variation_post_meta['options'] = $options; |
|
| 3519 | + $variation_post_meta['options'] = $options; |
|
| 3520 | 3520 | $variation_post_meta['follow_general_config'] = true; |
| 3521 | 3521 | if( $variation_post_meta['follow_general_config'] ) { |
| 3522 | 3522 | $shop_option = get_option('wpshop_catalog_product_option', array()); |
@@ -3532,6 +3532,6 @@ discard block |
||
| 3532 | 3532 | } |
| 3533 | 3533 | } |
| 3534 | 3534 | } |
| 3535 | - update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3536 | - } |
|
| 3535 | + update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3536 | + } |
|
| 3537 | 3537 | } |
@@ -184,20 +184,20 @@ discard block |
||
| 184 | 184 | public static function admin_menu() { |
| 185 | 185 | global $submenu; |
| 186 | 186 | $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
| 187 | - $entities_to_unset = array( 'free_product', 'default' ); |
|
| 187 | + $entities_to_unset = array('free_product', 'default'); |
|
| 188 | 188 | $submenu_before = $submenu['edit.php?post_type=wpshop_product']; |
| 189 | 189 | foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
| 190 | - if ( !( in_array( $attribute_set->slug, $entities_to_unset ) || in_array( $attribute_set->name, $entities_to_unset ) ) ) { |
|
| 191 | - add_submenu_page( 'edit.php?post_type=wpshop_product', sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product'); |
|
| 190 | + if (!(in_array($attribute_set->slug, $entities_to_unset) || in_array($attribute_set->name, $entities_to_unset))) { |
|
| 191 | + add_submenu_page('edit.php?post_type=wpshop_product', sprintf(__('Add %s', 'wpshop'), $attribute_set->name), sprintf(__('Add %s', 'wpshop'), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product'); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | - $submenu_new_elements = array_diff_key ( $submenu['edit.php?post_type=wpshop_product'], $submenu_before ); |
|
| 194 | + $submenu_new_elements = array_diff_key($submenu['edit.php?post_type=wpshop_product'], $submenu_before); |
|
| 195 | 195 | $submenu_reorder = array(); |
| 196 | - foreach( $submenu_before as $key => $element ) { |
|
| 197 | - if( empty( $submenu_reorder[$key] ) ) { |
|
| 196 | + foreach ($submenu_before as $key => $element) { |
|
| 197 | + if (empty($submenu_reorder[$key])) { |
|
| 198 | 198 | $submenu_reorder[$key] = $element; |
| 199 | - if( in_array( 'post-new.php?post_type=wpshop_product', $element ) ) { |
|
| 200 | - $submenu_reorder = array_merge( $submenu_reorder, array_values( $submenu_new_elements ) ); |
|
| 199 | + if (in_array('post-new.php?post_type=wpshop_product', $element)) { |
|
| 200 | + $submenu_reorder = array_merge($submenu_reorder, array_values($submenu_new_elements)); |
|
| 201 | 201 | } |
| 202 | 202 | } else { |
| 203 | 203 | $submenu_reorder[] = $element; |
@@ -604,12 +604,12 @@ discard block |
||
| 604 | 604 | |
| 605 | 605 | $products = array(); |
| 606 | 606 | $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
| 607 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 607 | + $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 608 | 608 | |
| 609 | 609 | if (!empty($data)) { |
| 610 | 610 | if ($data['data_type_to_use'] == 'custom') { |
| 611 | 611 | // Find which table to take |
| 612 | - if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;} |
|
| 612 | + if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME; } elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL; } elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER; } elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; } elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; } elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR; } |
|
| 613 | 613 | |
| 614 | 614 | if (isset($table_name)) { |
| 615 | 615 | // If the value is an id of a select, radio or checkbox |
@@ -759,11 +759,11 @@ discard block |
||
| 759 | 759 | if (!empty($atts['product_type'])) { |
| 760 | 760 | switch ($atts['product_type']) { |
| 761 | 761 | case 'related': |
| 762 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 762 | + $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID(); |
|
| 763 | 763 | $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
| 764 | 764 | $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
| 765 | 765 | |
| 766 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 766 | + $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 767 | 767 | if (!empty($pids) && !empty($pids[0])) { |
| 768 | 768 | $pid = implode(',', $pids); |
| 769 | 769 | } |
@@ -832,8 +832,8 @@ discard block |
||
| 832 | 832 | $sub_tpl_component = array(); |
| 833 | 833 | $criteria = ''; |
| 834 | 834 | foreach ($sorting_criteria as $c): |
| 835 | - $selected = isset( $atts['order'] ) ? $atts['order'] : null; |
|
| 836 | - $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 835 | + $selected = isset($atts['order']) ? $atts['order'] : null; |
|
| 836 | + $criteria .= '<option value="' . $c['code'] . '" ' . selected($selected, $c['code'], false) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 837 | 837 | endforeach; |
| 838 | 838 | $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
| 839 | 839 | $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
@@ -1002,7 +1002,7 @@ discard block |
||
| 1002 | 1002 | // --------------------- // |
| 1003 | 1003 | // Pagination management // |
| 1004 | 1004 | // --------------------- // |
| 1005 | - if ( $display_pagination ) { |
|
| 1005 | + if ($display_pagination) { |
|
| 1006 | 1006 | if ($nb_of_product_limit == 0) { |
| 1007 | 1007 | |
| 1008 | 1008 | $paginate = paginate_links(array( |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | { |
| 1284 | 1284 | global $wpdb; |
| 1285 | 1285 | |
| 1286 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1286 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST; |
|
| 1287 | 1287 | // Apply a filter to extra actions |
| 1288 | 1288 | $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
| 1289 | 1289 | |
@@ -1339,7 +1339,7 @@ discard block |
||
| 1339 | 1339 | $attributeValue = str_replace(',', '.', $attributeValue); |
| 1340 | 1340 | } |
| 1341 | 1341 | if (($attributeType == 'integer') && !is_array($attributeValue)) { |
| 1342 | - $attributeValue = (int) $attributeValue; |
|
| 1342 | + $attributeValue = (int)$attributeValue; |
|
| 1343 | 1343 | } |
| 1344 | 1344 | $productMetaDatas[$attributeCode] = $attributeValue; |
| 1345 | 1345 | } |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | $attributeValue = str_replace(',', '.', $attribute->$value_key); |
| 1390 | 1390 | } |
| 1391 | 1391 | if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
| 1392 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1392 | + $attributeValue = (int)$attribute->$value_key; |
|
| 1393 | 1393 | } |
| 1394 | 1394 | $variation_metadata[$attribute->code] = $attribute->$value_key; |
| 1395 | 1395 | } |
@@ -1402,7 +1402,7 @@ discard block |
||
| 1402 | 1402 | $attributeValue = str_replace(',', '.', $attributeValue); |
| 1403 | 1403 | } |
| 1404 | 1404 | if (($attributeType == 'integer') && !is_array($attributeValue)) { |
| 1405 | - $attributeValue = (int) $attributeValue; |
|
| 1405 | + $attributeValue = (int)$attributeValue; |
|
| 1406 | 1406 | } |
| 1407 | 1407 | $variation_metadata[$attributeCode] = $attributeValue; |
| 1408 | 1408 | } |
@@ -1738,13 +1738,13 @@ discard block |
||
| 1738 | 1738 | if (!empty($product_price_infos)) { |
| 1739 | 1739 | $tpl_component_price = array(); |
| 1740 | 1740 | /** Price piloting **/ |
| 1741 | - $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
|
| 1742 | - $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
|
| 1741 | + $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1742 | + $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : ''; |
|
| 1743 | 1743 | $price_ploting = get_option('wpshop_shop_price_piloting'); |
| 1744 | 1744 | $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : ''; |
| 1745 | 1745 | $variations = wpshop_products::get_variation($product_id); |
| 1746 | 1746 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1747 | - if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
|
| 1747 | + if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) { |
|
| 1748 | 1748 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1749 | 1749 | } |
| 1750 | 1750 | $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
@@ -2187,7 +2187,7 @@ discard block |
||
| 2187 | 2187 | } |
| 2188 | 2188 | |
| 2189 | 2189 | $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
| 2190 | - $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
|
| 2190 | + $template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id); |
|
| 2191 | 2191 | |
| 2192 | 2192 | $tpl_component = array(); |
| 2193 | 2193 | $tpl_component['PRODUCT_ID'] = $product_id; |
@@ -3049,7 +3049,7 @@ discard block |
||
| 3049 | 3049 | $single_variations = array(); |
| 3050 | 3050 | foreach ($selected_variation as $attribute_code => $attribute_value) { |
| 3051 | 3051 | if (isset($attribute_value) && $attribute_code != 'free') { |
| 3052 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id); |
|
| 3052 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int)$attribute_value)) . "'", $product_id); |
|
| 3053 | 3053 | $single_variation_id = $wpdb->get_var($query); |
| 3054 | 3054 | if (!empty($single_variation_id)) { |
| 3055 | 3055 | $single_variations[] = $single_variation_id; |
@@ -3151,7 +3151,7 @@ discard block |
||
| 3151 | 3151 | * Since 1.4.3.7 |
| 3152 | 3152 | * L'option du produit remplace le prix du produit de tête. |
| 3153 | 3153 | */ |
| 3154 | - if( true ) { |
|
| 3154 | + if (true) { |
|
| 3155 | 3155 | //Replace the product price |
| 3156 | 3156 | if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
| 3157 | 3157 | $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
@@ -3518,16 +3518,16 @@ discard block |
||
| 3518 | 3518 | $variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true); |
| 3519 | 3519 | $variation_post_meta['options'] = $options; |
| 3520 | 3520 | $variation_post_meta['follow_general_config'] = true; |
| 3521 | - if( $variation_post_meta['follow_general_config'] ) { |
|
| 3521 | + if ($variation_post_meta['follow_general_config']) { |
|
| 3522 | 3522 | $shop_option = get_option('wpshop_catalog_product_option', array()); |
| 3523 | - if( isset( $shop_option ) ) { |
|
| 3523 | + if (isset($shop_option)) { |
|
| 3524 | 3524 | $variation_post_meta['options']['price_display'] = $shop_option['price_display']; |
| 3525 | 3525 | } |
| 3526 | 3526 | } |
| 3527 | 3527 | $variations = wpshop_attributes::get_variation_available_attribute($current_post_id); |
| 3528 | - if( !empty( $variations['available'] ) ) { |
|
| 3529 | - foreach( $variations['available'] as $key => $value ) { |
|
| 3530 | - if( !in_array( $value['attribute_complete_def']->code, $variation_post_meta['attributes'] ) ) { |
|
| 3528 | + if (!empty($variations['available'])) { |
|
| 3529 | + foreach ($variations['available'] as $key => $value) { |
|
| 3530 | + if (!in_array($value['attribute_complete_def']->code, $variation_post_meta['attributes'])) { |
|
| 3531 | 3531 | $variation_post_meta['attributes'][] = $value['attribute_complete_def']->code; |
| 3532 | 3532 | } |
| 3533 | 3533 | } |