@@ -1,8 +1,8 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | /* Check if file is include. No direct access possible with file url */ |
| 4 | -if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
| 5 | - die( __('Access is not allowed by this way', 'wpshop') ); |
|
| 4 | +if (!defined('WPSHOP_VERSION')) { |
|
| 5 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string Html code composing the page header |
| 32 | 32 | */ |
| 33 | - public static function displayPageHeader($pageTitle, $pageIcon, $iconTitle, $iconAlt, $hasAddButton = true, $addButtonLink = '', $actionInformationMessage = '', $current_page_slug = ''){ |
|
| 34 | - include(WPSHOP_TEMPLATES_DIR.'admin/admin_page_header.tpl.php'); |
|
| 33 | + public static function displayPageHeader($pageTitle, $pageIcon, $iconTitle, $iconAlt, $hasAddButton = true, $addButtonLink = '', $actionInformationMessage = '', $current_page_slug = '') { |
|
| 34 | + include(WPSHOP_TEMPLATES_DIR . 'admin/admin_page_header.tpl.php'); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return string Html code composing the page footer |
| 43 | 43 | */ |
| 44 | - public static function displayPageFooter($formActionButton){ |
|
| 45 | - include(WPSHOP_TEMPLATES_DIR.'admin/admin_page_footer.tpl.php'); |
|
| 44 | + public static function displayPageFooter($formActionButton) { |
|
| 45 | + include(WPSHOP_TEMPLATES_DIR . 'admin/admin_page_footer.tpl.php'); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string The complete html page output |
| 52 | 52 | */ |
| 53 | - public static function display_page(){ |
|
| 53 | + public static function display_page() { |
|
| 54 | 54 | |
| 55 | 55 | $pageAddButton = false; |
| 56 | 56 | $pageMessage = $addButtonLink = $pageFormButton = $pageIcon = $pageIconTitle = $pageIconAlt = $objectType = ''; |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : ''; |
| 61 | 61 | |
| 62 | 62 | /* Select the content to add to the page looking for the parameter */ |
| 63 | - switch($pageSlug){ |
|
| 63 | + switch ($pageSlug) { |
|
| 64 | 64 | case WPSHOP_URL_SLUG_ATTRIBUTE_LISTING: |
| 65 | 65 | $objectType = new wpshop_attributes(); |
| 66 | 66 | $current_user_can_edit = current_user_can('wpshop_edit_attributes'); |
| 67 | 67 | $current_user_can_add = current_user_can('wpshop_add_attributes'); |
| 68 | 68 | $current_user_can_delete = current_user_can('wpshop_delete_attributes'); |
| 69 | - if(current_user_can('wpshop_add_attributes')){ |
|
| 69 | + if (current_user_can('wpshop_add_attributes')) { |
|
| 70 | 70 | $pageAddButton = true; |
| 71 | 71 | } |
| 72 | 72 | break; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $current_user_can_edit = current_user_can('wpshop_edit_attribute_set'); |
| 76 | 76 | $current_user_can_add = current_user_can('wpshop_add_attribute_set'); |
| 77 | 77 | $current_user_can_delete = current_user_can('wpshop_delete_attribute_set'); |
| 78 | - if(current_user_can('wpshop_add_attribute_set')){ |
|
| 78 | + if (current_user_can('wpshop_add_attribute_set')) { |
|
| 79 | 79 | $pageAddButton = true; |
| 80 | 80 | } |
| 81 | 81 | break; |
@@ -88,20 +88,20 @@ discard block |
||
| 88 | 88 | $pageAddButton = false; |
| 89 | 89 | $objectType = new wpshop_messages(); |
| 90 | 90 | $current_user_can_edit = true; |
| 91 | - $mid = !empty( $_GET['mid'] ) ? sanitize_text_field( $_GET['mid'] ) : ''; |
|
| 92 | - if(!empty($mid)){ |
|
| 91 | + $mid = !empty($_GET['mid']) ? sanitize_text_field($_GET['mid']) : ''; |
|
| 92 | + if (!empty($mid)) { |
|
| 93 | 93 | $action = 'edit'; |
| 94 | 94 | } |
| 95 | 95 | break; |
| 96 | 96 | default:{ |
| 97 | - $pageTitle = sprintf(__('You have to add this page into %s at line %s', 'wpshop'), __FILE__, (__LINE__ - 4)); |
|
| 97 | + $pageTitle = sprintf(__('You have to add this page into %s at line %s', 'wpshop'), __FILE__, (__LINE__ -4)); |
|
| 98 | 98 | $pageAddButton = false; |
| 99 | 99 | } |
| 100 | 100 | break; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if($objectType != ''){ |
|
| 104 | - if(($action != '') && ((($action == 'edit') && $current_user_can_edit) || (($action == 'add') && $current_user_can_add) || (($action == 'delete') && $current_user_can_delete))){ |
|
| 103 | + if ($objectType != '') { |
|
| 104 | + if (($action != '') && ((($action == 'edit') && $current_user_can_edit) || (($action == 'add') && $current_user_can_add) || (($action == 'delete') && $current_user_can_delete))) { |
|
| 105 | 105 | $outputType = 'adding'; |
| 106 | 106 | } |
| 107 | 107 | $objectType->elementAction(); |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | $pageIconTitle = self::getPageIconInformation('title', $objectType); |
| 111 | 111 | $pageIconAlt = self::getPageIconInformation('alt', $objectType); |
| 112 | 112 | |
| 113 | - if($outputType == 'listing'){ |
|
| 113 | + if ($outputType == 'listing') { |
|
| 114 | 114 | $pageContent = $objectType->elementList(); |
| 115 | 115 | } |
| 116 | - elseif($outputType == 'adding'){ |
|
| 116 | + elseif ($outputType == 'adding') { |
|
| 117 | 117 | $pageAddButton = false; |
| 118 | 118 | |
| 119 | 119 | $pageFormButton = $objectType->getPageFormButton($objectToEdit); |
@@ -123,11 +123,11 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $pageTitle = $objectType->pageTitle(); |
| 125 | 125 | $pageMessage = $objectType->pageMessage; |
| 126 | - if ( in_array( $objectType->getEditionSlug(), array(WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING) ) ) { |
|
| 126 | + if (in_array($objectType->getEditionSlug(), array(WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING))) { |
|
| 127 | 127 | $addButtonLink = admin_url('admin.php?page=' . $objectType->getEditionSlug() . '&action=add'); |
| 128 | 128 | } |
| 129 | 129 | else { |
| 130 | - $addButtonLink = admin_url('edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES.'&page=' . $objectType->getEditionSlug() . '&action=add'); |
|
| 130 | + $addButtonLink = admin_url('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES . '&page=' . $objectType->getEditionSlug() . '&action=add'); |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
@@ -149,37 +149,37 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @return string The output builded from selected type |
| 151 | 151 | */ |
| 152 | - public static function custom_page_output_builder($content, $output_type='tab') { |
|
| 152 | + public static function custom_page_output_builder($content, $output_type = 'tab') { |
|
| 153 | 153 | $output_custom_layout = ''; |
| 154 | 154 | |
| 155 | - switch ( $output_type ) { |
|
| 155 | + switch ($output_type) { |
|
| 156 | 156 | case 'separated_bloc': |
| 157 | - foreach ( $content as $element_type => $element_type_details ) { |
|
| 158 | - $output_custom_layout.=' |
|
| 159 | - <div class="wpshop_separated_bloc wpshop_separated_bloc_'.$element_type.'" >'; |
|
| 160 | - foreach ( $element_type_details as $element_type_key => $element_type_content ) { |
|
| 161 | - $output_custom_layout.=' |
|
| 162 | - <div class="wpshop_admin_box wpshop_admin_box_'.$element_type.' wpshop_admin_box_'.$element_type.'_'.$element_type_key.'" > |
|
| 157 | + foreach ($content as $element_type => $element_type_details) { |
|
| 158 | + $output_custom_layout .= ' |
|
| 159 | + <div class="wpshop_separated_bloc wpshop_separated_bloc_'.$element_type . '" >'; |
|
| 160 | + foreach ($element_type_details as $element_type_key => $element_type_content) { |
|
| 161 | + $output_custom_layout .= ' |
|
| 162 | + <div class="wpshop_admin_box wpshop_admin_box_'.$element_type . ' wpshop_admin_box_' . $element_type . '_' . $element_type_key . '" > |
|
| 163 | 163 | <h3>' . $element_type_content['title'] . '</h3>' . $element_type_content['content'] . ' |
| 164 | 164 | </div>'; |
| 165 | 165 | } |
| 166 | - $output_custom_layout.=' |
|
| 166 | + $output_custom_layout .= ' |
|
| 167 | 167 | </div>'; |
| 168 | 168 | } |
| 169 | 169 | break; |
| 170 | 170 | case 'tab': |
| 171 | - $tab_list=$tab_content_list=''; |
|
| 172 | - foreach ( $content as $element_type => $element_type_details ) { |
|
| 173 | - foreach ( $element_type_details as $element_type_key => $element_type_content ) { |
|
| 174 | - $tab_list.=' |
|
| 175 | - <li><a href="#wpshop_'.$element_type.'_'.$element_type_key.'" >'.$element_type_content['title'].'</a></li>'; |
|
| 176 | - $tab_content_list.=' |
|
| 177 | - <div id="wpshop_'.$element_type.'_'.$element_type_key.'" class="wpshop_admin_box wpshop_admin_box_'.$element_type.' wpshop_admin_box_'.$element_type.'_'.$element_type_key.'" >'.$element_type_content['content'].' |
|
| 171 | + $tab_list = $tab_content_list = ''; |
|
| 172 | + foreach ($content as $element_type => $element_type_details) { |
|
| 173 | + foreach ($element_type_details as $element_type_key => $element_type_content) { |
|
| 174 | + $tab_list .= ' |
|
| 175 | + <li><a href="#wpshop_'.$element_type . '_' . $element_type_key . '" >' . $element_type_content['title'] . '</a></li>'; |
|
| 176 | + $tab_content_list .= ' |
|
| 177 | + <div id="wpshop_'.$element_type . '_' . $element_type_key . '" class="wpshop_admin_box wpshop_admin_box_' . $element_type . ' wpshop_admin_box_' . $element_type . '_' . $element_type_key . '" >' . $element_type_content['content'] . ' |
|
| 178 | 178 | </div>'; |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | - $output_custom_layout.=' |
|
| 182 | - <div id="wpshopFormManagementContainer" class="wpshop_tabs wpshop_full_page_tabs wpshop_'.$element_type.'_tabs" > |
|
| 181 | + $output_custom_layout .= ' |
|
| 182 | + <div id="wpshopFormManagementContainer" class="wpshop_tabs wpshop_full_page_tabs wpshop_'.$element_type . '_tabs" > |
|
| 183 | 183 | <ul>' . $tab_list . '</ul>' . $tab_content_list . ' |
| 184 | 184 | </div>'; |
| 185 | 185 | break; |
@@ -201,21 +201,21 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @return string $table The html code of the table to output |
| 203 | 203 | */ |
| 204 | - public static function getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, $tableSummary = '', $withFooter = true){ |
|
| 204 | + public static function getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, $tableSummary = '', $withFooter = true) { |
|
| 205 | 205 | $tableTitleBar = $tableBody = ''; |
| 206 | 206 | |
| 207 | 207 | /* Create the header and footer row */ |
| 208 | - for($i=0; $i<count($tableTitles); $i++){ |
|
| 208 | + for ($i = 0; $i < count($tableTitles); $i++) { |
|
| 209 | 209 | $tableTitleBar .= ' |
| 210 | 210 | <th class="' . $tableClasses[$i] . '" scope="col" >' . $tableTitles[$i] . '</th>'; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /* Create each table row */ |
| 214 | - for($lineNumber=0; $lineNumber<count($tableRows); $lineNumber++){ |
|
| 214 | + for ($lineNumber = 0; $lineNumber < count($tableRows); $lineNumber++) { |
|
| 215 | 215 | $tableRow = $tableRows[$lineNumber]; |
| 216 | 216 | $tableBody .= ' |
| 217 | 217 | <tr id="' . $tableRowsId[$lineNumber] . '" class="tableRow" >'; |
| 218 | - for($i=0; $i<count($tableRow); $i++){ |
|
| 218 | + for ($i = 0; $i < count($tableRow); $i++) { |
|
| 219 | 219 | $tableBody .= ' |
| 220 | 220 | <td class="' . $tableClasses[$i] . ' ' . $tableRow[$i]['class'] . '" >' . $tableRow[$i]['value'] . '</td>'; |
| 221 | 221 | } |
@@ -226,13 +226,13 @@ discard block |
||
| 226 | 226 | /* Create the table output */ |
| 227 | 227 | $table = ' |
| 228 | 228 | <table id="' . $tableId . '" cellspacing="0" cellpadding="0" class="widefat post fixed" >'; |
| 229 | - if($tableTitleBar != ''){ |
|
| 229 | + if ($tableTitleBar != '') { |
|
| 230 | 230 | $table .= ' |
| 231 | 231 | <thead> |
| 232 | 232 | <tr class="tableTitleHeader" >' . $tableTitleBar . ' |
| 233 | 233 | </tr> |
| 234 | 234 | </thead>'; |
| 235 | - if($withFooter){ |
|
| 235 | + if ($withFooter) { |
|
| 236 | 236 | $table .= ' |
| 237 | 237 | <tfoot> |
| 238 | 238 | <tr class="tableTitleFooter" >' . $tableTitleBar . ' |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @return string $pageIconInformation The information to output in the page |
| 257 | 257 | */ |
| 258 | - public static function getPageIconInformation($infoType, $object){ |
|
| 259 | - switch($infoType){ |
|
| 258 | + public static function getPageIconInformation($infoType, $object) { |
|
| 259 | + switch ($infoType) { |
|
| 260 | 260 | case 'path': |
| 261 | 261 | $pageIconInformation = $object->pageIcon; |
| 262 | 262 | break; |
@@ -278,18 +278,18 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return string $file_path The good filepath to include |
| 280 | 280 | */ |
| 281 | - public static function get_template_file($file_name, $default_dir = WPSHOP_TEMPLATES_DIR, $dir_name = 'wpshop', $usage_type = 'include', $check_only_custom = false){ |
|
| 281 | + public static function get_template_file($file_name, $default_dir = WPSHOP_TEMPLATES_DIR, $dir_name = 'wpshop', $usage_type = 'include', $check_only_custom = false) { |
|
| 282 | 282 | $file_path = ''; |
| 283 | 283 | $the_file = $dir_name . '/' . $file_name; |
| 284 | 284 | |
| 285 | 285 | if (is_file(get_stylesheet_directory() . '/' . $the_file)) { |
| 286 | 286 | $default_dir = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, get_stylesheet_directory()); |
| 287 | - if($usage_type == 'include'){ |
|
| 287 | + if ($usage_type == 'include') { |
|
| 288 | 288 | $default_dir = get_stylesheet_directory(); |
| 289 | 289 | } |
| 290 | 290 | $file_path = $default_dir . '/' . $the_file; |
| 291 | 291 | } |
| 292 | - else if ( !$check_only_custom ) { |
|
| 292 | + else if (!$check_only_custom) { |
|
| 293 | 293 | $file_path = $default_dir . $the_file; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -312,124 +312,124 @@ discard block |
||
| 312 | 312 | $custom_template_part = get_stylesheet_directory() . '/' . $default_template_dir . '/'; |
| 313 | 313 | |
| 314 | 314 | /** Let support the old way of template managing */ |
| 315 | - switch ( $template_part ) { |
|
| 315 | + switch ($template_part) { |
|
| 316 | 316 | case 'category_mini_list': |
| 317 | 317 | $old_file_to_take_care_url = 'category-mini-list.tpl.php'; |
| 318 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 318 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 319 | 319 | $old_file_to_take_care = true; |
| 320 | 320 | endif; |
| 321 | 321 | break; |
| 322 | 322 | case 'category_mini_grid': |
| 323 | 323 | $old_file_to_take_care_url = 'category-mini-grid.tpl.php'; |
| 324 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 324 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 325 | 325 | $old_file_to_take_care = true; |
| 326 | 326 | endif; |
| 327 | 327 | break; |
| 328 | 328 | case 'product_complete_tpl': |
| 329 | 329 | $old_file_to_take_care_url = 'product.tpl.php'; |
| 330 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 330 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 331 | 331 | $old_file_to_take_care = true; |
| 332 | 332 | endif; |
| 333 | 333 | break; |
| 334 | 334 | case 'product_mini_list': |
| 335 | 335 | $old_file_to_take_care_url = 'product-mini-list.tpl.php'; |
| 336 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 336 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 337 | 337 | $old_file_to_take_care = true; |
| 338 | 338 | endif; |
| 339 | 339 | break; |
| 340 | 340 | case 'product_mini_grid': |
| 341 | 341 | $old_file_to_take_care_url = 'product-mini-grid.tpl.php'; |
| 342 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 342 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 343 | 343 | $old_file_to_take_care = true; |
| 344 | 344 | endif; |
| 345 | 345 | break; |
| 346 | 346 | case 'product_listing_sorting': |
| 347 | 347 | $old_file_to_take_care_url = 'product_listing_sorting.tpl.php'; |
| 348 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 348 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 349 | 349 | $old_file_to_take_care = true; |
| 350 | 350 | endif; |
| 351 | 351 | break; |
| 352 | 352 | case 'unavailable_product_button': |
| 353 | 353 | $old_file_to_take_care_url = 'not_available_product_button.tpl.php'; |
| 354 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 354 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 355 | 355 | $old_file_to_take_care = true; |
| 356 | 356 | endif; |
| 357 | 357 | break; |
| 358 | 358 | case 'add_to_cart_button': |
| 359 | 359 | $old_file_to_take_care_url = 'available_product_button.tpl.php'; |
| 360 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 360 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 361 | 361 | $old_file_to_take_care = true; |
| 362 | 362 | endif; |
| 363 | 363 | break; |
| 364 | 364 | case 'ask_quotation_button': |
| 365 | 365 | $old_file_to_take_care_url = 'quotation_button.tpl.php'; |
| 366 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 366 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 367 | 367 | $old_file_to_take_care = true; |
| 368 | 368 | endif; |
| 369 | 369 | break; |
| 370 | 370 | case 'mini_cart_content': |
| 371 | 371 | $old_file_to_take_care_url = 'wpshop_mini_cart.tpl.php'; |
| 372 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 372 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 373 | 373 | $old_file_to_take_care = true; |
| 374 | 374 | endif; |
| 375 | 375 | break; |
| 376 | 376 | case 'product_is_new_sticker': |
| 377 | 377 | $old_file_to_take_care_url = 'product-is-new.tpl.php'; |
| 378 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 378 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 379 | 379 | $old_file_to_take_care = true; |
| 380 | 380 | endif; |
| 381 | 381 | break; |
| 382 | 382 | case 'product_is_featured_sticker': |
| 383 | 383 | $old_file_to_take_care_url = 'product-is-featured.tpl.php'; |
| 384 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 384 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 385 | 385 | $old_file_to_take_care = true; |
| 386 | 386 | endif; |
| 387 | 387 | break; |
| 388 | 388 | case 'product_attribute_container': |
| 389 | 389 | $old_file_to_take_care_url = 'product-attribute-front-display-main-container.tpl.php'; |
| 390 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 390 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 391 | 391 | $old_file_to_take_care = true; |
| 392 | 392 | endif; |
| 393 | 393 | break; |
| 394 | 394 | case 'product_attribute_tabs': |
| 395 | 395 | $old_file_to_take_care_url = 'product-attribute-front-display-tabs.tpl.php'; |
| 396 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 396 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 397 | 397 | $old_file_to_take_care = true; |
| 398 | 398 | endif; |
| 399 | 399 | break; |
| 400 | 400 | case 'product_attribute_tabs_detail': |
| 401 | 401 | $old_file_to_take_care_url = 'product-attribute-front-display-tabs-content.tpl.php'; |
| 402 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 402 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 403 | 403 | $old_file_to_take_care = true; |
| 404 | 404 | endif; |
| 405 | 405 | break; |
| 406 | 406 | case 'product_attachment_picture_galery': |
| 407 | 407 | $old_file_to_take_care_url = 'product_picture_galery.tpl.php'; |
| 408 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 408 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 409 | 409 | $old_file_to_take_care = true; |
| 410 | 410 | endif; |
| 411 | 411 | break; |
| 412 | 412 | case 'product_attachment_galery': |
| 413 | 413 | $old_file_to_take_care_url = 'product_document_library.tpl.php'; |
| 414 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 414 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 415 | 415 | $old_file_to_take_care = true; |
| 416 | 416 | endif; |
| 417 | 417 | break; |
| 418 | 418 | case 'product_attachment_item_picture': |
| 419 | 419 | $old_file_to_take_care_url = 'product_attachment_picture_line.tpl.php'; |
| 420 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 420 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 421 | 421 | $old_file_to_take_care = true; |
| 422 | 422 | endif; |
| 423 | 423 | break; |
| 424 | 424 | case 'product_attachment_item_document': |
| 425 | 425 | $old_file_to_take_care_url = 'product_attachment_document_line.tpl.php'; |
| 426 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 426 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 427 | 427 | $old_file_to_take_care = true; |
| 428 | 428 | endif; |
| 429 | 429 | break; |
| 430 | 430 | case 'product_added_to_cart_message': |
| 431 | 431 | $old_file_to_take_care_url = 'product_added_to_cart_message.tpl.php'; |
| 432 | - if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
| 432 | + if (is_file($custom_template_part . $old_file_to_take_care_url)) : |
|
| 433 | 433 | $old_file_to_take_care = true; |
| 434 | 434 | endif; |
| 435 | 435 | break; |
@@ -459,13 +459,13 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | public static function display_template_element($template_part, $template_part_component, $extras_args = array(), $default_template_dir = 'wpshop') { |
| 461 | 461 | /** Set the template element to return by default before checking if custom exists in order to be sure to return something */ |
| 462 | - $default_template_element = wpshop_display::check_template_to_display( 'default', $template_part, $extras_args, $default_template_dir ); |
|
| 462 | + $default_template_element = wpshop_display::check_template_to_display('default', $template_part, $extras_args, $default_template_dir); |
|
| 463 | 463 | |
| 464 | 464 | /** Check in custom template if there is not a custom element to display for current */ |
| 465 | - $custom_template_element = wpshop_display::check_template_to_display( 'custom', $template_part, $extras_args, $default_template_dir ); |
|
| 465 | + $custom_template_element = wpshop_display::check_template_to_display('custom', $template_part, $extras_args, $default_template_dir); |
|
| 466 | 466 | $tpl_element_to_return = !empty($custom_template_element) ? $custom_template_element : $default_template_element; |
| 467 | 467 | |
| 468 | - $template_part_component = apply_filters( 'wps_filter_display_' . $template_part, $template_part_component, $extras_args, $default_template_dir ); |
|
| 468 | + $template_part_component = apply_filters('wps_filter_display_' . $template_part, $template_part_component, $extras_args, $default_template_dir); |
|
| 469 | 469 | |
| 470 | 470 | return self::feed_template($tpl_element_to_return, $template_part_component); |
| 471 | 471 | } |
@@ -477,44 +477,44 @@ discard block |
||
| 477 | 477 | /* Load template component */ |
| 478 | 478 | /* Get default admin template */ |
| 479 | 479 | require_once(WPSHOP_TEMPLATES_DIR . 'admin/main_elements.tpl.php'); |
| 480 | - $wpshop_template['admin']['default'] = ($tpl_element);unset($tpl_element); |
|
| 480 | + $wpshop_template['admin']['default'] = ($tpl_element); unset($tpl_element); |
|
| 481 | 481 | /* Get custom admin template */ |
| 482 | - if ( is_file(get_stylesheet_directory() . '/admin/main_elements.tpl.php') ) { |
|
| 482 | + if (is_file(get_stylesheet_directory() . '/admin/main_elements.tpl.php')) { |
|
| 483 | 483 | require_once(get_stylesheet_directory() . '/admin/main_elements.tpl.php'); |
| 484 | 484 | if (!empty($tpl_element)) |
| 485 | - $wpshop_template['admin']['custom'] = ($tpl_element);unset($tpl_element); |
|
| 485 | + $wpshop_template['admin']['custom'] = ($tpl_element); unset($tpl_element); |
|
| 486 | 486 | } |
| 487 | - if ( is_file(get_stylesheet_directory() . '/admin/wpshop_elements_template.tpl.php') ) { |
|
| 487 | + if (is_file(get_stylesheet_directory() . '/admin/wpshop_elements_template.tpl.php')) { |
|
| 488 | 488 | require_once(get_stylesheet_directory() . '/admin/wpshop_elements_template.tpl.php'); |
| 489 | 489 | if (!empty($tpl_element)) |
| 490 | - $wpshop_template['admin']['custom'] = ($tpl_element);unset($tpl_element); |
|
| 490 | + $wpshop_template['admin']['custom'] = ($tpl_element); unset($tpl_element); |
|
| 491 | 491 | } |
| 492 | 492 | /* Get default frontend template */ |
| 493 | 493 | require_once(WPSHOP_TEMPLATES_DIR . 'wpshop/main_elements.tpl.php'); |
| 494 | - $wpshop_template['wpshop']['default'] = ($tpl_element);unset($tpl_element); |
|
| 494 | + $wpshop_template['wpshop']['default'] = ($tpl_element); unset($tpl_element); |
|
| 495 | 495 | /* Get custom frontend template */ |
| 496 | - if ( is_file(get_stylesheet_directory() . '/wpshop/main_elements.tpl.php') ) { |
|
| 496 | + if (is_file(get_stylesheet_directory() . '/wpshop/main_elements.tpl.php')) { |
|
| 497 | 497 | require_once(get_stylesheet_directory() . '/wpshop/main_elements.tpl.php'); |
| 498 | 498 | if (!empty($tpl_element)) |
| 499 | - $wpshop_template['wpshop']['custom'] = ($tpl_element);unset($tpl_element); |
|
| 499 | + $wpshop_template['wpshop']['custom'] = ($tpl_element); unset($tpl_element); |
|
| 500 | 500 | } |
| 501 | - if ( is_file(get_stylesheet_directory() . '/wpshop/wpshop_elements_template.tpl.php') ) { |
|
| 501 | + if (is_file(get_stylesheet_directory() . '/wpshop/wpshop_elements_template.tpl.php')) { |
|
| 502 | 502 | require_once(get_stylesheet_directory() . '/wpshop/wpshop_elements_template.tpl.php'); |
| 503 | 503 | if (!empty($tpl_element)) |
| 504 | - $wpshop_template['wpshop']['custom'] = ($tpl_element);unset($tpl_element); |
|
| 504 | + $wpshop_template['wpshop']['custom'] = ($tpl_element); unset($tpl_element); |
|
| 505 | 505 | } |
| 506 | - foreach ( $wpshop_template as $site_side => $types ) { |
|
| 507 | - foreach ( $types as $type => $tpl_component ) { |
|
| 508 | - foreach ( $tpl_component as $tpl_key => $tpl_content ) { |
|
| 506 | + foreach ($wpshop_template as $site_side => $types) { |
|
| 507 | + foreach ($types as $type => $tpl_component) { |
|
| 508 | + foreach ($tpl_component as $tpl_key => $tpl_content) { |
|
| 509 | 509 | $wpshop_template[$site_side][$type][$tpl_key] = str_replace(" |
| 510 | 510 | ", '', $tpl_content); |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - $wpshop_template = apply_filters( 'wpshop_custom_template', $wpshop_template); |
|
| 515 | + $wpshop_template = apply_filters('wpshop_custom_template', $wpshop_template); |
|
| 516 | 516 | |
| 517 | - DEFINE( 'WPSHOP_TEMPLATE', serialize($wpshop_template) ); |
|
| 517 | + DEFINE('WPSHOP_TEMPLATE', serialize($wpshop_template)); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -525,12 +525,12 @@ discard block |
||
| 525 | 525 | * |
| 526 | 526 | * @return array The new array with all elment, internal and module templates |
| 527 | 527 | */ |
| 528 | - public static function add_modules_template_to_internal( $tpl_element, $templates ) { |
|
| 529 | - if ( !empty($tpl_element) ) { |
|
| 530 | - foreach ( $tpl_element as $template_part => $template_part_content) { |
|
| 531 | - if ( !empty($template_part_content) && is_array($template_part_content) ) { |
|
| 532 | - foreach ( $template_part_content as $template_type => $template_type_content) { |
|
| 533 | - foreach ( $template_type_content as $template_key => $template) { |
|
| 528 | + public static function add_modules_template_to_internal($tpl_element, $templates) { |
|
| 529 | + if (!empty($tpl_element)) { |
|
| 530 | + foreach ($tpl_element as $template_part => $template_part_content) { |
|
| 531 | + if (!empty($template_part_content) && is_array($template_part_content)) { |
|
| 532 | + foreach ($template_part_content as $template_type => $template_type_content) { |
|
| 533 | + foreach ($template_type_content as $template_key => $template) { |
|
| 534 | 534 | $templates[$template_part][$template_type][$template_key] = $template; |
| 535 | 535 | } |
| 536 | 536 | } |
@@ -550,20 +550,20 @@ discard block |
||
| 550 | 550 | * |
| 551 | 551 | * @return string The good template to take in care, regarding on the given parameters |
| 552 | 552 | */ |
| 553 | - public static function check_template_to_display( $part, $template_part, $extras_args, $default_template_dir ) { |
|
| 553 | + public static function check_template_to_display($part, $template_part, $extras_args, $default_template_dir) { |
|
| 554 | 554 | $tpl_element_to_return = ''; |
| 555 | 555 | |
| 556 | 556 | /** Get the defined template */ |
| 557 | 557 | $template = defined("WPSHOP_TEMPLATE") ? unserialize(WPSHOP_TEMPLATE) : array(); |
| 558 | 558 | |
| 559 | - if ( !empty($extras_args['type']) && !empty($extras_args['id']) && !empty( $template[$default_template_dir][$part]) && !empty($extras_args['page']) && !empty( $template[$default_template_dir][$part][$extras_args['page']] ) && !empty( $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']]) && !empty( $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']] ) && !empty( $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']][$template_part] ) ) { |
|
| 559 | + if (!empty($extras_args['type']) && !empty($extras_args['id']) && !empty($template[$default_template_dir][$part]) && !empty($extras_args['page']) && !empty($template[$default_template_dir][$part][$extras_args['page']]) && !empty($template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']]) && !empty($template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']]) && !empty($template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']][$template_part])) { |
|
| 560 | 560 | $tpl_element_to_return = $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']][$template_part]; |
| 561 | 561 | } |
| 562 | - elseif ( !empty($extras_args['type']) && !empty($extras_args['id']) && !empty( $template[$default_template_dir][$part][$extras_args['type']]) && !empty( $template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']] ) && !empty( $template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']][$template_part] ) ) { |
|
| 562 | + elseif (!empty($extras_args['type']) && !empty($extras_args['id']) && !empty($template[$default_template_dir][$part][$extras_args['type']]) && !empty($template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']]) && !empty($template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']][$template_part])) { |
|
| 563 | 563 | $tpl_element_to_return = $template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']][$template_part]; |
| 564 | 564 | } |
| 565 | 565 | /** Check if the file have been duplicated into theme directory for customization */ |
| 566 | - elseif ( !empty( $template[$default_template_dir][$part] ) && !empty( $template[$default_template_dir][$part][$template_part] ) ) { |
|
| 566 | + elseif (!empty($template[$default_template_dir][$part]) && !empty($template[$default_template_dir][$part][$template_part])) { |
|
| 567 | 567 | $tpl_element_to_return = $template[$default_template_dir][$part][$template_part]; |
| 568 | 568 | } |
| 569 | 569 | |
@@ -583,13 +583,13 @@ discard block |
||
| 583 | 583 | $feed['CURRENCY'] = wpshop_tools::wpshop_get_currency(); |
| 584 | 584 | $feed['CURRENCY_CHOOSEN'] = wpshop_tools::wpshop_get_currency(); |
| 585 | 585 | $feed['CURRENCY_SELECTOR'] = wpshop_attributes_unit::wpshop_shop_currency_list_field(); |
| 586 | - $feed['CART_LINK'] = get_permalink( wpshop_tools::get_page_id( get_option('wpshop_cart_page_id') ) ); |
|
| 586 | + $feed['CART_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_cart_page_id'))); |
|
| 587 | 587 | |
| 588 | 588 | $available_key = array(); |
| 589 | 589 | foreach ($feed as $element => $value) { |
| 590 | - $available_key[] = '{WPSHOP_'.$element.'}'; |
|
| 591 | - if ( !is_array($value) ) { |
|
| 592 | - $template_to_fill = str_replace('{WPSHOP_'.$element.'}', $value, $template_to_fill); |
|
| 590 | + $available_key[] = '{WPSHOP_' . $element . '}'; |
|
| 591 | + if (!is_array($value)) { |
|
| 592 | + $template_to_fill = str_replace('{WPSHOP_' . $element . '}', $value, $template_to_fill); |
|
| 593 | 593 | } |
| 594 | 594 | } |
| 595 | 595 | if (WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE) $template_to_fill = '<!-- Available keys : ' . implode(' / ', $available_key) . ' -->' . $template_to_fill; |
@@ -602,11 +602,11 @@ discard block |
||
| 602 | 602 | * |
| 603 | 603 | * @param boolean $force_replacement Define if we overwrite in all case or just if it not exist |
| 604 | 604 | */ |
| 605 | - public static function check_template_file( $force_replacement = false ) { |
|
| 605 | + public static function check_template_file($force_replacement = false) { |
|
| 606 | 606 | $wpshop_directory = get_stylesheet_directory() . '/wpshop'; |
| 607 | 607 | |
| 608 | 608 | /* Add different file template */ |
| 609 | - if(!is_dir($wpshop_directory)){ |
|
| 609 | + if (!is_dir($wpshop_directory)) { |
|
| 610 | 610 | @mkdir($wpshop_directory, 0755, true); |
| 611 | 611 | } |
| 612 | 612 | /* On s'assure que le dossier principal est bien en 0755 */ |
@@ -614,12 +614,12 @@ discard block |
||
| 614 | 614 | $upload_dir = wp_upload_dir(); |
| 615 | 615 | |
| 616 | 616 | /* Add the category template */ |
| 617 | - if(!is_file(get_stylesheet_directory() . '/taxonomy-wpshop_product_category.php') || ($force_replacement)){ |
|
| 617 | + if (!is_file(get_stylesheet_directory() . '/taxonomy-wpshop_product_category.php') || ($force_replacement)) { |
|
| 618 | 618 | @copy(WPSHOP_TEMPLATES_DIR . 'taxonomy-wpshop_product_category.php', get_stylesheet_directory() . '/taxonomy-wpshop_product_category.php'); |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /* Add the product template */ |
| 622 | - if(!is_file(get_stylesheet_directory() . '/single-wpshop_product.php') || ($force_replacement)){ |
|
| 622 | + if (!is_file(get_stylesheet_directory() . '/single-wpshop_product.php') || ($force_replacement)) { |
|
| 623 | 623 | @copy(WPSHOP_TEMPLATES_DIR . 'single-wpshop_product.php', get_stylesheet_directory() . '/single-wpshop_product.php'); |
| 624 | 624 | } |
| 625 | 625 | } |
@@ -637,31 +637,31 @@ discard block |
||
| 637 | 637 | /* Check if user is on taxonomy edition page */ |
| 638 | 638 | if ($pagenow == 'edit-tags.php') { |
| 639 | 639 | |
| 640 | - if(!user_can_richedit()) { return; } |
|
| 640 | + if (!user_can_richedit()) { return; } |
|
| 641 | 641 | |
| 642 | 642 | $taxonomies = get_taxonomies(); |
| 643 | 643 | |
| 644 | 644 | foreach ($taxonomies as $tax) { |
| 645 | - if ( in_array($tax, array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES)) ) { |
|
| 646 | - add_action($tax . '_edit_form_fields', array('wpshop_display','wpshop_add_form')); |
|
| 647 | - add_action($tax . '_add_form_fields', array('wpshop_display','wpshop_add_form')); |
|
| 645 | + if (in_array($tax, array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES))) { |
|
| 646 | + add_action($tax . '_edit_form_fields', array('wpshop_display', 'wpshop_add_form')); |
|
| 647 | + add_action($tax . '_add_form_fields', array('wpshop_display', 'wpshop_add_form')); |
|
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | - $action = !empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : ''; |
|
| 651 | - $taxonomy = !empty( $_REQUEST['taxonomy'] ) ? sanitize_text_field( $_REQUEST['taxonomy'] ) : ''; |
|
| 650 | + $action = !empty($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : ''; |
|
| 651 | + $taxonomy = !empty($_REQUEST['taxonomy']) ? sanitize_text_field($_REQUEST['taxonomy']) : ''; |
|
| 652 | 652 | |
| 653 | 653 | if ($pagenow == 'edit-tags.php' && isset($action) && $action == 'edit' && empty($taxonomy)) { |
| 654 | - add_action('edit_term',array('wpshop_display','wpshop_rt_taxonomy_save')); |
|
| 654 | + add_action('edit_term', array('wpshop_display', 'wpshop_rt_taxonomy_save')); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | - foreach ( array( 'pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description' ) as $filter ) { |
|
| 658 | - remove_filter( $filter, 'wp_filter_kses' ); |
|
| 657 | + foreach (array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description') as $filter) { |
|
| 658 | + remove_filter($filter, 'wp_filter_kses'); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /* Enable shortcodes in category, taxonomy, tag descriptions */ |
| 664 | - if(function_exists('term_description')) { |
|
| 664 | + if (function_exists('term_description')) { |
|
| 665 | 665 | add_filter('term_description', 'do_shortcode'); |
| 666 | 666 | } |
| 667 | 667 | else { |
@@ -677,8 +677,8 @@ discard block |
||
| 677 | 677 | |
| 678 | 678 | $a = array('description'); |
| 679 | 679 | foreach ($a as $v) { |
| 680 | - $term = (array) $_POST[$v]; |
|
| 681 | - wp_update_term($tag_ID,$v,$term); |
|
| 680 | + $term = (array)$_POST[$v]; |
|
| 681 | + wp_update_term($tag_ID, $v, $term); |
|
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
@@ -690,9 +690,9 @@ discard block |
||
| 690 | 690 | public static function wpshop_add_form($object = '') { |
| 691 | 691 | global $pagenow; |
| 692 | 692 | |
| 693 | - $content = is_object($object) && isset($object->description) ? ( html_entity_decode( $object->description, ENT_COMPAT | ENT_HTML401, 'UTF-8' ) ) : ''; |
|
| 693 | + $content = is_object($object) && isset($object->description) ? (html_entity_decode($object->description, ENT_COMPAT | ENT_HTML401, 'UTF-8')) : ''; |
|
| 694 | 694 | |
| 695 | - if( in_array($pagenow, array('edit-tags.php')) ) { |
|
| 695 | + if (in_array($pagenow, array('edit-tags.php'))) { |
|
| 696 | 696 | $editor_id = 'tag_description'; |
| 697 | 697 | $editor_selector = 'description'; |
| 698 | 698 | } |
@@ -722,8 +722,8 @@ discard block |
||
| 722 | 722 | |
| 723 | 723 | public static function wps_hide_admin_bar_for_customers() { |
| 724 | 724 | $wpshop_hide_admin_bar_option = get_option('wpshop_display_option'); |
| 725 | - if ( !empty($wpshop_hide_admin_bar_option) && !empty($wpshop_hide_admin_bar_option['wpshop_hide_admin_bar']) && ! current_user_can( 'manage_options' ) ) { |
|
| 726 | - show_admin_bar( false ); |
|
| 725 | + if (!empty($wpshop_hide_admin_bar_option) && !empty($wpshop_hide_admin_bar_option['wpshop_hide_admin_bar']) && !current_user_can('manage_options')) { |
|
| 726 | + show_admin_bar(false); |
|
| 727 | 727 | } |
| 728 | 728 | } |
| 729 | 729 | |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | * @param string $content The content of a post |
| 738 | 738 | * @return Ambigous <mixed, string>|unknown |
| 739 | 739 | */ |
| 740 | - public static function products_page( $content = '' ) { |
|
| 740 | + public static function products_page($content = '') { |
|
| 741 | 741 | global $wp_query; |
| 742 | 742 | |
| 743 | 743 | if (!empty($wp_query->queried_object) && !empty($wp_query->queried_object->post_type) && ($wp_query->queried_object->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)) { |
@@ -756,15 +756,15 @@ discard block |
||
| 756 | 756 | * |
| 757 | 757 | * @return string The formated value |
| 758 | 758 | */ |
| 759 | - public static function format_field_output( $output_type, $value ) { |
|
| 759 | + public static function format_field_output($output_type, $value) { |
|
| 760 | 760 | $formated_value = $value; |
| 761 | 761 | |
| 762 | - if ( !empty($value) ) { |
|
| 763 | - switch ( $output_type ) { |
|
| 762 | + if (!empty($value)) { |
|
| 763 | + switch ($output_type) { |
|
| 764 | 764 | case 'wpshop_product_price': |
| 765 | - $formated_value = (is_numeric($value) ) ? number_format($value, 2, ',', '') : $value; |
|
| 765 | + $formated_value = (is_numeric($value)) ? number_format($value, 2, ',', '') : $value; |
|
| 766 | 766 | $formated_value_content = explode(',', $formated_value); |
| 767 | - if ( !empty($formated_value_content) && !empty($formated_value_content[1]) && $formated_value_content[1] <= 0 ) { |
|
| 767 | + if (!empty($formated_value_content) && !empty($formated_value_content[1]) && $formated_value_content[1] <= 0) { |
|
| 768 | 768 | $formated_value = $formated_value_content[0]; |
| 769 | 769 | } |
| 770 | 770 | break; |
@@ -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,47 +252,47 @@ 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'); |
|
| 281 | - } else if (count($attributeEntitySetList) > 1) { |
|
| 282 | - $input_def['id'] = 'product_attribute_set_id'; |
|
| 283 | - $input_def['name'] = 'product_attribute_set_id'; |
|
| 284 | - $input_def['value'] = ''; |
|
| 285 | - $input_def['type'] = 'select'; |
|
| 286 | - $input_def['possible_value'] = $attributeEntitySetList; |
|
| 287 | - |
|
| 288 | - $input_def['value'] = ''; |
|
| 289 | - foreach ($attributeEntitySetList as $set) { |
|
| 290 | - if ($set->default_set == 'yes') { |
|
| 291 | - $input_def['value'] = $set->id; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 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 | + } else if (count($attributeEntitySetList) > 1) { |
|
| 282 | + $input_def['id'] = 'product_attribute_set_id'; |
|
| 283 | + $input_def['name'] = 'product_attribute_set_id'; |
|
| 284 | + $input_def['value'] = ''; |
|
| 285 | + $input_def['type'] = 'select'; |
|
| 286 | + $input_def['possible_value'] = $attributeEntitySetList; |
|
| 287 | + |
|
| 288 | + $input_def['value'] = ''; |
|
| 289 | + foreach ($attributeEntitySetList as $set) { |
|
| 290 | + if ($set->default_set == 'yes') { |
|
| 291 | + $input_def['value'] = $set->id; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 296 | 296 | <ul class="attribute_set_selector" > |
| 297 | 297 | <li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li> |
| 298 | 298 | <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> |
@@ -300,791 +300,791 @@ discard block |
||
| 300 | 300 | <li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li> |
| 301 | 301 | </ul>'; |
| 302 | 302 | |
| 303 | - 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')); |
|
| 304 | - } |
|
| 305 | - } |
|
| 303 | + 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')); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - } |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Add a box into product edition page for options on the product |
|
| 311 | - * |
|
| 312 | - * @param object $post |
|
| 313 | - */ |
|
| 314 | - public static function product_options_meta_box_content($post) |
|
| 315 | - { |
|
| 316 | - $output = ''; |
|
| 309 | + /** |
|
| 310 | + * Add a box into product edition page for options on the product |
|
| 311 | + * |
|
| 312 | + * @param object $post |
|
| 313 | + */ |
|
| 314 | + public static function product_options_meta_box_content($post) |
|
| 315 | + { |
|
| 316 | + $output = ''; |
|
| 317 | 317 | |
| 318 | - $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 318 | + $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 319 | 319 | |
| 320 | - $tpl_component = array(); |
|
| 321 | - $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 322 | - $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 320 | + $tpl_component = array(); |
|
| 321 | + $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 322 | + $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 323 | 323 | |
| 324 | - echo $output; |
|
| 325 | - } |
|
| 324 | + echo $output; |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * Display the fixed box |
|
| 329 | - */ |
|
| 330 | - public static function product_data_meta_box($post, $metaboxArgs) |
|
| 331 | - { |
|
| 332 | - $output = ''; |
|
| 327 | + /** |
|
| 328 | + * Display the fixed box |
|
| 329 | + */ |
|
| 330 | + public static function product_data_meta_box($post, $metaboxArgs) |
|
| 331 | + { |
|
| 332 | + $output = ''; |
|
| 333 | 333 | |
| 334 | - $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 334 | + $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 335 | 335 | |
| 336 | - echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 336 | + echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 337 | 337 | <ul>'; |
| 338 | - if (!empty($currentTabContent['box'])) { |
|
| 339 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 340 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 341 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 342 | - echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 348 | - echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 349 | - echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 350 | - echo '</ul>'; |
|
| 351 | - |
|
| 352 | - if (!empty($currentTabContent['box'])) { |
|
| 353 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 354 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 355 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 356 | - echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - } |
|
| 338 | + if (!empty($currentTabContent['box'])) { |
|
| 339 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 340 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 341 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 342 | + echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 348 | + echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 349 | + echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 350 | + echo '</ul>'; |
|
| 351 | + |
|
| 352 | + if (!empty($currentTabContent['box'])) { |
|
| 353 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 354 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 355 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 356 | + echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 363 | - echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>'; |
|
| 364 | - echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 365 | - if (!empty($currentTabContent['boxMore'])) { |
|
| 366 | - echo $currentTabContent['boxMore']; |
|
| 367 | - } |
|
| 368 | - echo '</div>'; |
|
| 362 | + echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 363 | + echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>'; |
|
| 364 | + echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 365 | + if (!empty($currentTabContent['boxMore'])) { |
|
| 366 | + echo $currentTabContent['boxMore']; |
|
| 367 | + } |
|
| 368 | + echo '</div>'; |
|
| 369 | 369 | |
| 370 | - echo $output; |
|
| 371 | - } |
|
| 370 | + echo $output; |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * Output the content for related product metabox |
|
| 375 | - * @param object $post The current edited post |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public static function related_products_meta_box_content($post) |
|
| 379 | - { |
|
| 380 | - $content = $existing_selection = ''; |
|
| 381 | - |
|
| 382 | - if (!empty($post->ID)) { |
|
| 383 | - $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 384 | - if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 385 | - foreach ($related_products_id as $related_product_id) { |
|
| 386 | - $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - } |
|
| 373 | + /** |
|
| 374 | + * Output the content for related product metabox |
|
| 375 | + * @param object $post The current edited post |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public static function related_products_meta_box_content($post) |
|
| 379 | + { |
|
| 380 | + $content = $existing_selection = ''; |
|
| 381 | + |
|
| 382 | + if (!empty($post->ID)) { |
|
| 383 | + $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 384 | + if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 385 | + foreach ($related_products_id as $related_product_id) { |
|
| 386 | + $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - $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> |
|
| 391 | + $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> |
|
| 392 | 392 | <select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select> |
| 393 | 393 | <input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" /> |
| 394 | 394 | <input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 395 | 395 | |
| 396 | - return $content; |
|
| 397 | - } |
|
| 396 | + return $content; |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Output the content for related product metabox |
|
| 401 | - * @param object $post The current edited post |
|
| 402 | - * @return string |
|
| 403 | - */ |
|
| 404 | - public static function provider_products_meta_box_content($post) |
|
| 405 | - { |
|
| 406 | - $content = $existing_selection = ''; |
|
| 407 | - |
|
| 408 | - if (!empty($post->ID)) { |
|
| 409 | - $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true); |
|
| 410 | - if (!empty($providers_id) && !empty($providers_id[0])) { |
|
| 411 | - foreach ($providers_id as $provider_id) { |
|
| 412 | - $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>'; |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 399 | + /** |
|
| 400 | + * Output the content for related product metabox |
|
| 401 | + * @param object $post The current edited post |
|
| 402 | + * @return string |
|
| 403 | + */ |
|
| 404 | + public static function provider_products_meta_box_content($post) |
|
| 405 | + { |
|
| 406 | + $content = $existing_selection = ''; |
|
| 407 | + |
|
| 408 | + if (!empty($post->ID)) { |
|
| 409 | + $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true); |
|
| 410 | + if (!empty($providers_id) && !empty($providers_id[0])) { |
|
| 411 | + foreach ($providers_id as $provider_id) { |
|
| 412 | + $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>'; |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p> |
|
| 417 | + $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p> |
|
| 418 | 418 | <select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select> |
| 419 | 419 | <input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" /> |
| 420 | 420 | <input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 421 | 421 | |
| 422 | - return $content; |
|
| 423 | - } |
|
| 422 | + return $content; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - /** |
|
| 426 | - * Define the metabox content for the action box |
|
| 427 | - * @param obejct $post The current element being edited |
|
| 428 | - */ |
|
| 429 | - public static function product_actions_meta_box_content($post) |
|
| 430 | - { |
|
| 431 | - $output = ''; |
|
| 432 | - /* |
|
| 425 | + /** |
|
| 426 | + * Define the metabox content for the action box |
|
| 427 | + * @param obejct $post The current element being edited |
|
| 428 | + */ |
|
| 429 | + public static function product_actions_meta_box_content($post) |
|
| 430 | + { |
|
| 431 | + $output = ''; |
|
| 432 | + /* |
|
| 433 | 433 | * Template parameters |
| 434 | 434 | */ |
| 435 | - $template_part = 'wpshop_duplicate_product'; |
|
| 436 | - $tpl_component = array(); |
|
| 437 | - $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 438 | - $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 439 | - /* |
|
| 435 | + $template_part = 'wpshop_duplicate_product'; |
|
| 436 | + $tpl_component = array(); |
|
| 437 | + $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 438 | + $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 439 | + /* |
|
| 440 | 440 | * Build template |
| 441 | 441 | */ |
| 442 | - $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 443 | - unset($tpl_component); |
|
| 442 | + $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 443 | + unset($tpl_component); |
|
| 444 | 444 | |
| 445 | - echo $output; |
|
| 446 | - } |
|
| 445 | + echo $output; |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - /** |
|
| 449 | - * Define the content of the product main information box |
|
| 450 | - */ |
|
| 451 | - public static function meta_box_content($post, $metaboxArgs) |
|
| 452 | - { |
|
| 453 | - global $currentTabContent; |
|
| 448 | + /** |
|
| 449 | + * Define the content of the product main information box |
|
| 450 | + */ |
|
| 451 | + public static function meta_box_content($post, $metaboxArgs) |
|
| 452 | + { |
|
| 453 | + global $currentTabContent; |
|
| 454 | 454 | |
| 455 | - /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 456 | - echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 457 | - } |
|
| 455 | + /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 456 | + echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - /** |
|
| 460 | - * Define the metabox content for product custom display in product |
|
| 461 | - * @param object $post The current element being edited |
|
| 462 | - * @return string The metabox content |
|
| 463 | - */ |
|
| 464 | - public static function product_frontend_display_config_meta_box($post) |
|
| 465 | - { |
|
| 466 | - $content = ''; |
|
| 467 | - |
|
| 468 | - $product_attribute_frontend_display_config = null; |
|
| 469 | - if (!empty($post->ID)) { |
|
| 470 | - $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 471 | - |
|
| 472 | - $extra_options = get_option('wpshop_extra_options', array()); |
|
| 473 | - $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 474 | - $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 475 | - $column = 1; |
|
| 476 | - |
|
| 477 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 478 | - $sub_tpl_component = array(); |
|
| 479 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 480 | - |
|
| 481 | - $tpl_component = array(); |
|
| 482 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 483 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 484 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 485 | - $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 486 | - |
|
| 487 | - $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"' : ''; |
|
| 488 | - $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"' : ''; |
|
| 489 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 490 | - unset($tpl_component); |
|
| 491 | - |
|
| 492 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 493 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 494 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 495 | - $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 499 | - foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 500 | - if (!isset($sub_content[$column])) { |
|
| 501 | - $sub_content[$column] = ''; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $attribute_sub_output = ''; |
|
| 505 | - foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 506 | - if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 507 | - $tpl_component = array(); |
|
| 508 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 509 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 510 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 511 | - $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"' : ''; |
|
| 512 | - $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"' : ''; |
|
| 513 | - $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 514 | - unset($tpl_component); |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - $tpl_component = array(); |
|
| 519 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 520 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 521 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 522 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 523 | - $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"' : ''; |
|
| 524 | - $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>'; |
|
| 525 | - $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 526 | - $column++; |
|
| 527 | - if ($column > $column_count) { |
|
| 528 | - $column = 1; |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - $tpl_component = array(); |
|
| 533 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 534 | - for ($i = 1; $i <= $column_count; $i++) { |
|
| 535 | - if (!empty($sub_content[$i])) { |
|
| 536 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - } |
|
| 540 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 541 | - $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 542 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 543 | - |
|
| 544 | - $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>'; |
|
| 545 | - } |
|
| 459 | + /** |
|
| 460 | + * Define the metabox content for product custom display in product |
|
| 461 | + * @param object $post The current element being edited |
|
| 462 | + * @return string The metabox content |
|
| 463 | + */ |
|
| 464 | + public static function product_frontend_display_config_meta_box($post) |
|
| 465 | + { |
|
| 466 | + $content = ''; |
|
| 467 | + |
|
| 468 | + $product_attribute_frontend_display_config = null; |
|
| 469 | + if (!empty($post->ID)) { |
|
| 470 | + $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 471 | + |
|
| 472 | + $extra_options = get_option('wpshop_extra_options', array()); |
|
| 473 | + $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 474 | + $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 475 | + $column = 1; |
|
| 476 | + |
|
| 477 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 478 | + $sub_tpl_component = array(); |
|
| 479 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 480 | + |
|
| 481 | + $tpl_component = array(); |
|
| 482 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 483 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 484 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 485 | + $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 486 | + |
|
| 487 | + $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"' : ''; |
|
| 488 | + $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"' : ''; |
|
| 489 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 490 | + unset($tpl_component); |
|
| 491 | + |
|
| 492 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 493 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 494 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 495 | + $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 496 | + } |
|
| 546 | 497 | |
| 547 | - return $content; |
|
| 548 | - } |
|
| 498 | + if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 499 | + foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 500 | + if (!isset($sub_content[$column])) { |
|
| 501 | + $sub_content[$column] = ''; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $attribute_sub_output = ''; |
|
| 505 | + foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 506 | + if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 507 | + $tpl_component = array(); |
|
| 508 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 509 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 510 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 511 | + $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"' : ''; |
|
| 512 | + $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"' : ''; |
|
| 513 | + $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 514 | + unset($tpl_component); |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + $tpl_component = array(); |
|
| 519 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 520 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 521 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 522 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 523 | + $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"' : ''; |
|
| 524 | + $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>'; |
|
| 525 | + $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 526 | + $column++; |
|
| 527 | + if ($column > $column_count) { |
|
| 528 | + $column = 1; |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + $tpl_component = array(); |
|
| 533 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 534 | + for ($i = 1; $i <= $column_count; $i++) { |
|
| 535 | + if (!empty($sub_content[$i])) { |
|
| 536 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 537 | + } |
|
| 549 | 538 | |
| 550 | - /** |
|
| 551 | - * Retrieve the attribute list used for sorting product into frontend listing |
|
| 552 | - * @return array The attribute list to use for listing sorting |
|
| 553 | - */ |
|
| 554 | - public static function get_sorting_criteria() |
|
| 555 | - { |
|
| 556 | - global $wpdb; |
|
| 539 | + } |
|
| 540 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 541 | + $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 542 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 557 | 543 | |
| 558 | - $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'))); |
|
| 544 | + $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>'; |
|
| 545 | + } |
|
| 559 | 546 | |
| 560 | - $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 561 | - $results = $wpdb->get_results($query, ARRAY_A); |
|
| 562 | - if (!empty($results)) { |
|
| 563 | - $data = array_merge($data, $results); |
|
| 564 | - } |
|
| 547 | + return $content; |
|
| 548 | + } |
|
| 565 | 549 | |
| 566 | - return $data; |
|
| 567 | - } |
|
| 550 | + /** |
|
| 551 | + * Retrieve the attribute list used for sorting product into frontend listing |
|
| 552 | + * @return array The attribute list to use for listing sorting |
|
| 553 | + */ |
|
| 554 | + public static function get_sorting_criteria() |
|
| 555 | + { |
|
| 556 | + global $wpdb; |
|
| 557 | + |
|
| 558 | + $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'))); |
|
| 559 | + |
|
| 560 | + $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 561 | + $results = $wpdb->get_results($query, ARRAY_A); |
|
| 562 | + if (!empty($results)) { |
|
| 563 | + $data = array_merge($data, $results); |
|
| 564 | + } |
|
| 568 | 565 | |
| 569 | - public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 570 | - { |
|
| 571 | - global $wpdb; |
|
| 566 | + return $data; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 570 | + { |
|
| 571 | + global $wpdb; |
|
| 572 | 572 | |
| 573 | - $products = array(); |
|
| 574 | - $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 575 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 573 | + $products = array(); |
|
| 574 | + $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 575 | + $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 576 | 576 | |
| 577 | - if (!empty($data)) { |
|
| 578 | - if ($data['data_type_to_use'] == 'custom') { |
|
| 579 | - // Find which table to take |
|
| 580 | - 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;} |
|
| 577 | + if (!empty($data)) { |
|
| 578 | + if ($data['data_type_to_use'] == 'custom') { |
|
| 579 | + // Find which table to take |
|
| 580 | + 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;} |
|
| 581 | 581 | |
| 582 | - if (isset($table_name)) { |
|
| 583 | - // If the value is an id of a select, radio or checkbox |
|
| 584 | - if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 582 | + if (isset($table_name)) { |
|
| 583 | + // If the value is an id of a select, radio or checkbox |
|
| 584 | + if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 585 | 585 | |
| 586 | - $query = $wpdb->prepare(" |
|
| 586 | + $query = $wpdb->prepare(" |
|
| 587 | 587 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 588 | 588 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 589 | 589 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 590 | 590 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id |
| 591 | 591 | WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value |
| 592 | - ); |
|
| 593 | - $data = $wpdb->get_results($query); |
|
| 594 | - } else { |
|
| 592 | + ); |
|
| 593 | + $data = $wpdb->get_results($query); |
|
| 594 | + } else { |
|
| 595 | 595 | |
| 596 | - $query = $wpdb->prepare(" |
|
| 596 | + $query = $wpdb->prepare(" |
|
| 597 | 597 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 598 | 598 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 599 | 599 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 600 | 600 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 601 | 601 | WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000 |
| 602 | - ); |
|
| 603 | - $data = $wpdb->get_results($query); |
|
| 604 | - |
|
| 605 | - } |
|
| 606 | - } else { |
|
| 607 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 611 | - /** Check the ID of manufacturer **/ |
|
| 612 | - $default_value = unserialize($data['default_value']); |
|
| 613 | - if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 614 | - $query = get_post($attr_value); |
|
| 615 | - $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 616 | - if (!empty($pid)) { |
|
| 617 | - $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); |
|
| 618 | - $data = $wpdb->get_results($query); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - } else { |
|
| 622 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - } else { |
|
| 626 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 627 | - } |
|
| 602 | + ); |
|
| 603 | + $data = $wpdb->get_results($query); |
|
| 628 | 604 | |
| 629 | - if (!empty($data)) { |
|
| 630 | - foreach ($data as $p) { |
|
| 631 | - if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 632 | - $products[] = $p->entity_id; |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - return $products; |
|
| 637 | - } |
|
| 605 | + } |
|
| 606 | + } else { |
|
| 607 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 608 | + } |
|
| 638 | 609 | |
| 639 | - /** |
|
| 640 | - * Related product shortcode reader |
|
| 641 | - * |
|
| 642 | - * @param array $atts { |
|
| 643 | - * pid : Product idenfifier to get related element for |
|
| 644 | - * display_mode : The output mode if defined (grid || list) |
|
| 645 | - * } |
|
| 646 | - * |
|
| 647 | - * @return string |
|
| 648 | - * |
|
| 649 | - */ |
|
| 650 | - public static function wpshop_related_products_func($atts) |
|
| 651 | - { |
|
| 652 | - global $wp_query; |
|
| 610 | + } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 611 | + /** Check the ID of manufacturer **/ |
|
| 612 | + $default_value = unserialize($data['default_value']); |
|
| 613 | + if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 614 | + $query = get_post($attr_value); |
|
| 615 | + $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 616 | + if (!empty($pid)) { |
|
| 617 | + $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); |
|
| 618 | + $data = $wpdb->get_results($query); |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + } else { |
|
| 622 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 623 | + } |
|
| 653 | 624 | |
| 654 | - $atts['product_type'] = 'related'; |
|
| 655 | - if (empty($atts['pid'])) { |
|
| 656 | - $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 657 | - } |
|
| 625 | + } else { |
|
| 626 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 627 | + } |
|
| 658 | 628 | |
| 659 | - $related_product_output = self::wpshop_products_func($atts); |
|
| 629 | + if (!empty($data)) { |
|
| 630 | + foreach ($data as $p) { |
|
| 631 | + if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 632 | + $products[] = $p->entity_id; |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + return $products; |
|
| 637 | + } |
|
| 660 | 638 | |
| 661 | - $output = ''; |
|
| 662 | - if (!empty($related_product_output)) { |
|
| 663 | - ob_start(); |
|
| 664 | - require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 665 | - $output = ob_get_contents(); |
|
| 666 | - ob_end_clean(); |
|
| 667 | - } |
|
| 639 | + /** |
|
| 640 | + * Related product shortcode reader |
|
| 641 | + * |
|
| 642 | + * @param array $atts { |
|
| 643 | + * pid : Product idenfifier to get related element for |
|
| 644 | + * display_mode : The output mode if defined (grid || list) |
|
| 645 | + * } |
|
| 646 | + * |
|
| 647 | + * @return string |
|
| 648 | + * |
|
| 649 | + */ |
|
| 650 | + public static function wpshop_related_products_func($atts) |
|
| 651 | + { |
|
| 652 | + global $wp_query; |
|
| 653 | + |
|
| 654 | + $atts['product_type'] = 'related'; |
|
| 655 | + if (empty($atts['pid'])) { |
|
| 656 | + $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 657 | + } |
|
| 668 | 658 | |
| 669 | - return $output; |
|
| 670 | - } |
|
| 659 | + $related_product_output = self::wpshop_products_func($atts); |
|
| 671 | 660 | |
| 672 | - /** |
|
| 673 | - * Display a list of product from a shortcode |
|
| 674 | - * |
|
| 675 | - * @param array $atts { |
|
| 676 | - * limit : The number of element to display |
|
| 677 | - * order : The information to order list by |
|
| 678 | - * sorting : List order (ASC | DESC) |
|
| 679 | - * display : Display size (normal | mini) |
|
| 680 | - * type : Display tyep (grid | list) only work with display=normal |
|
| 681 | - * pagination : The number of element per page |
|
| 682 | - * display_pagination : Display the pagination or not |
|
| 683 | - * } |
|
| 684 | - * |
|
| 685 | - * @return string |
|
| 686 | - * |
|
| 687 | - **/ |
|
| 688 | - public static function wpshop_products_func($atts) |
|
| 689 | - { |
|
| 690 | - global $wpdb, $wp_query; |
|
| 691 | - |
|
| 692 | - $string = ''; |
|
| 693 | - $have_results = false; |
|
| 694 | - $output_results = true; |
|
| 695 | - $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 696 | - $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 697 | - $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 698 | - $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 699 | - $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 700 | - $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 701 | - $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; |
|
| 702 | - $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 703 | - $attr = ''; |
|
| 704 | - |
|
| 705 | - $sorting_criteria = self::get_sorting_criteria(); |
|
| 706 | - |
|
| 707 | - /** Get products which have att_name equal to att_value */ |
|
| 708 | - if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 709 | - $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 710 | - |
|
| 711 | - $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 712 | - |
|
| 713 | - // Foreach on the found products |
|
| 714 | - if (!empty($products)) { |
|
| 715 | - $pid = implode(',', $products); |
|
| 716 | - if (empty($pid)) { |
|
| 717 | - $output_results = false; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - } else { |
|
| 721 | - $output_results = false; |
|
| 722 | - } |
|
| 661 | + $output = ''; |
|
| 662 | + if (!empty($related_product_output)) { |
|
| 663 | + ob_start(); |
|
| 664 | + require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 665 | + $output = ob_get_contents(); |
|
| 666 | + ob_end_clean(); |
|
| 667 | + } |
|
| 723 | 668 | |
| 724 | - } |
|
| 669 | + return $output; |
|
| 670 | + } |
|
| 725 | 671 | |
| 726 | - /** Get related products */ |
|
| 727 | - if (!empty($atts['product_type'])) { |
|
| 728 | - switch ($atts['product_type']) { |
|
| 729 | - case 'related': |
|
| 730 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 731 | - $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 732 | - $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; |
|
| 733 | - |
|
| 734 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 735 | - if (!empty($pids) && !empty($pids[0])) { |
|
| 736 | - $pid = implode(',', $pids); |
|
| 737 | - } |
|
| 738 | - if (empty($pid) || $pid == $product_id) { |
|
| 739 | - $output_results = false; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - break; |
|
| 743 | - } |
|
| 744 | - } |
|
| 672 | + /** |
|
| 673 | + * Display a list of product from a shortcode |
|
| 674 | + * |
|
| 675 | + * @param array $atts { |
|
| 676 | + * limit : The number of element to display |
|
| 677 | + * order : The information to order list by |
|
| 678 | + * sorting : List order (ASC | DESC) |
|
| 679 | + * display : Display size (normal | mini) |
|
| 680 | + * type : Display tyep (grid | list) only work with display=normal |
|
| 681 | + * pagination : The number of element per page |
|
| 682 | + * display_pagination : Display the pagination or not |
|
| 683 | + * } |
|
| 684 | + * |
|
| 685 | + * @return string |
|
| 686 | + * |
|
| 687 | + **/ |
|
| 688 | + public static function wpshop_products_func($atts) |
|
| 689 | + { |
|
| 690 | + global $wpdb, $wp_query; |
|
| 691 | + |
|
| 692 | + $string = ''; |
|
| 693 | + $have_results = false; |
|
| 694 | + $output_results = true; |
|
| 695 | + $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 696 | + $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 697 | + $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 698 | + $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 699 | + $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 700 | + $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 701 | + $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; |
|
| 702 | + $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 703 | + $attr = ''; |
|
| 704 | + |
|
| 705 | + $sorting_criteria = self::get_sorting_criteria(); |
|
| 706 | + |
|
| 707 | + /** Get products which have att_name equal to att_value */ |
|
| 708 | + if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 709 | + $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 710 | + |
|
| 711 | + $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 712 | + |
|
| 713 | + // Foreach on the found products |
|
| 714 | + if (!empty($products)) { |
|
| 715 | + $pid = implode(',', $products); |
|
| 716 | + if (empty($pid)) { |
|
| 717 | + $output_results = false; |
|
| 718 | + } |
|
| 745 | 719 | |
| 746 | - /** Output all the products */ |
|
| 747 | - if ($output_results) { |
|
| 748 | - $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); |
|
| 720 | + } else { |
|
| 721 | + $output_results = false; |
|
| 722 | + } |
|
| 749 | 723 | |
| 750 | - if ($data[0]) { |
|
| 751 | - $have_results = true; |
|
| 752 | - $string = $data[1]; |
|
| 753 | - } |
|
| 754 | - } |
|
| 724 | + } |
|
| 755 | 725 | |
| 756 | - /** If there are result to display */ |
|
| 757 | - if ($have_results) { |
|
| 758 | - $sorting = ''; |
|
| 759 | - if (!empty($pid)) { |
|
| 760 | - $product_list = explode(',', $pid); |
|
| 761 | - if (count($product_list) == 1) { |
|
| 762 | - $atts['sorting'] = 'no'; |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - /* |
|
| 726 | + /** Get related products */ |
|
| 727 | + if (!empty($atts['product_type'])) { |
|
| 728 | + switch ($atts['product_type']) { |
|
| 729 | + case 'related': |
|
| 730 | + $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 731 | + $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 732 | + $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; |
|
| 733 | + |
|
| 734 | + $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 735 | + if (!empty($pids) && !empty($pids[0])) { |
|
| 736 | + $pid = implode(',', $pids); |
|
| 737 | + } |
|
| 738 | + if (empty($pid) || $pid == $product_id) { |
|
| 739 | + $output_results = false; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + break; |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + /** Output all the products */ |
|
| 747 | + if ($output_results) { |
|
| 748 | + $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); |
|
| 749 | + |
|
| 750 | + if ($data[0]) { |
|
| 751 | + $have_results = true; |
|
| 752 | + $string = $data[1]; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** If there are result to display */ |
|
| 757 | + if ($have_results) { |
|
| 758 | + $sorting = ''; |
|
| 759 | + if (!empty($pid)) { |
|
| 760 | + $product_list = explode(',', $pid); |
|
| 761 | + if (count($product_list) == 1) { |
|
| 762 | + $atts['sorting'] = 'no'; |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + /* |
|
| 767 | 767 | * Template parameters |
| 768 | 768 | */ |
| 769 | - $template_part = 'product_listing_sorting'; |
|
| 770 | - $tpl_component = array(); |
|
| 769 | + $template_part = 'product_listing_sorting'; |
|
| 770 | + $tpl_component = array(); |
|
| 771 | 771 | |
| 772 | - /* |
|
| 772 | + /* |
|
| 773 | 773 | * Build template |
| 774 | 774 | */ |
| 775 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 776 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 777 | - /* Include the old way template part */ |
|
| 778 | - ob_start(); |
|
| 779 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 780 | - $sorting = ob_get_contents(); |
|
| 781 | - ob_end_clean(); |
|
| 782 | - } else { |
|
| 783 | - /* |
|
| 775 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 776 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 777 | + /* Include the old way template part */ |
|
| 778 | + ob_start(); |
|
| 779 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 780 | + $sorting = ob_get_contents(); |
|
| 781 | + ob_end_clean(); |
|
| 782 | + } else { |
|
| 783 | + /* |
|
| 784 | 784 | * Display hidden field every times |
| 785 | 785 | */ |
| 786 | - $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 787 | - $sub_tpl_component = array(); |
|
| 788 | - $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 789 | - $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 790 | - $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 791 | - $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 792 | - $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 793 | - $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 794 | - $sub_tpl_component['ATTR'] = $attr; |
|
| 795 | - $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 796 | - unset($sub_tpl_component); |
|
| 797 | - |
|
| 798 | - if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 799 | - $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 800 | - $sub_tpl_component = array(); |
|
| 801 | - $criteria = ''; |
|
| 802 | - foreach ($sorting_criteria as $c): |
|
| 803 | - $criteria .= '<option value="' . $c['code'] . '">' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 804 | - endforeach; |
|
| 805 | - $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 806 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 807 | - unset($sub_tpl_component); |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 811 | - $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 812 | - $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 813 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 814 | - } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 815 | - $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 816 | - $sub_tpl_component = array(); |
|
| 817 | - $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 818 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 819 | - unset($sub_tpl_component); |
|
| 820 | - |
|
| 821 | - $template_part = 'product_listing_sorting_hidden'; |
|
| 822 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - unset($tpl_component); |
|
| 826 | - |
|
| 827 | - if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 828 | - $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 829 | - } else { |
|
| 830 | - $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>'; |
|
| 831 | - } |
|
| 832 | - } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 833 | - $string = __('There is nothing to output here', 'wpshop'); |
|
| 834 | - } |
|
| 786 | + $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 787 | + $sub_tpl_component = array(); |
|
| 788 | + $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 789 | + $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 790 | + $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 791 | + $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 792 | + $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 793 | + $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 794 | + $sub_tpl_component['ATTR'] = $attr; |
|
| 795 | + $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 796 | + unset($sub_tpl_component); |
|
| 797 | + |
|
| 798 | + if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 799 | + $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 800 | + $sub_tpl_component = array(); |
|
| 801 | + $criteria = ''; |
|
| 802 | + foreach ($sorting_criteria as $c): |
|
| 803 | + $criteria .= '<option value="' . $c['code'] . '">' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 804 | + endforeach; |
|
| 805 | + $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 806 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 807 | + unset($sub_tpl_component); |
|
| 808 | + } |
|
| 835 | 809 | |
| 836 | - return do_shortcode($string); |
|
| 837 | - } |
|
| 810 | + if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 811 | + $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 812 | + $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 813 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 814 | + } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 815 | + $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 816 | + $sub_tpl_component = array(); |
|
| 817 | + $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 818 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 819 | + unset($sub_tpl_component); |
|
| 820 | + |
|
| 821 | + $template_part = 'product_listing_sorting_hidden'; |
|
| 822 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + unset($tpl_component); |
|
| 838 | 826 | |
| 839 | - 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) |
|
| 840 | - { |
|
| 841 | - global $wpdb; |
|
| 827 | + if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 828 | + $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 829 | + } else { |
|
| 830 | + $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>'; |
|
| 831 | + } |
|
| 832 | + } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 833 | + $string = __('There is nothing to output here', 'wpshop'); |
|
| 834 | + } |
|
| 842 | 835 | |
| 843 | - $string = '<span id="wpshop_loading"> </span>'; |
|
| 844 | - $have_results = false; |
|
| 845 | - $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 836 | + return do_shortcode($string); |
|
| 837 | + } |
|
| 846 | 838 | |
| 847 | - /** Check if Discount are activated */ |
|
| 848 | - $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 839 | + 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) |
|
| 840 | + { |
|
| 841 | + global $wpdb; |
|
| 849 | 842 | |
| 850 | - if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 851 | - $criteria = 'wpshop_displayed_price'; |
|
| 852 | - } |
|
| 843 | + $string = '<span id="wpshop_loading"> </span>'; |
|
| 844 | + $have_results = false; |
|
| 845 | + $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 853 | 846 | |
| 854 | - $query = array( |
|
| 855 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 856 | - 'order' => $order, |
|
| 857 | - 'posts_per_page' => $products_per_page, |
|
| 858 | - 'paged' => $page_number, |
|
| 859 | - 'post_status' => 'publish', |
|
| 860 | - ); |
|
| 861 | - |
|
| 862 | - // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 863 | - if ($nb_of_product_limit > 0) { |
|
| 864 | - $query['posts_per_page'] = $nb_of_product_limit; |
|
| 865 | - unset($query['paged']); |
|
| 866 | - } |
|
| 867 | - if (!empty($pid)) { |
|
| 868 | - if (!is_array($pid)) { |
|
| 869 | - $pid = explode(',', $pid); |
|
| 870 | - } |
|
| 847 | + /** Check if Discount are activated */ |
|
| 848 | + $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 871 | 849 | |
| 872 | - $query['post__in'] = $pid; |
|
| 873 | - } |
|
| 874 | - if (!empty($cid)) { |
|
| 875 | - $cid = explode(',', $cid); |
|
| 876 | - $query['tax_query'] = array(array( |
|
| 877 | - 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 878 | - 'field' => 'id', |
|
| 879 | - 'terms' => $cid, |
|
| 880 | - 'operator' => 'IN', |
|
| 881 | - )); |
|
| 882 | - } |
|
| 883 | - if ($criteria != null) { |
|
| 884 | - switch ($criteria) { |
|
| 885 | - case 'creator': |
|
| 886 | - case 'author': |
|
| 887 | - $query['author'] = get_current_user_id(); |
|
| 888 | - break; |
|
| 889 | - case 'none': |
|
| 890 | - case 'ID': |
|
| 891 | - case 'title': |
|
| 892 | - case 'date': |
|
| 893 | - case 'modified': |
|
| 894 | - case 'relevance': |
|
| 895 | - case 'post__in': |
|
| 896 | - case 'rand': |
|
| 897 | - $query['orderby'] = $criteria; |
|
| 898 | - break; |
|
| 899 | - default: |
|
| 900 | - if (!empty($pid)) { |
|
| 901 | - $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 902 | - } else { |
|
| 903 | - $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 904 | - $post_meta = $wpdb->get_var($check_meta); |
|
| 905 | - } |
|
| 906 | - if (!empty($post_meta)) { |
|
| 907 | - if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 908 | - $query['orderby'] = 'meta_value_num'; |
|
| 909 | - } else { |
|
| 910 | - $query['orderby'] = 'meta_value'; |
|
| 911 | - } |
|
| 912 | - $query['meta_key'] = '_' . $criteria; |
|
| 913 | - } |
|
| 914 | - break; |
|
| 915 | - } |
|
| 916 | - } else { |
|
| 917 | - $query['orderby'] = 'menu_order ID'; |
|
| 918 | - } |
|
| 919 | - $post_per_page = $query['posts_per_page']; |
|
| 920 | - $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 921 | - if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 922 | - $tmp_array = array(); |
|
| 923 | - |
|
| 924 | - if (empty($page_number) || $page_number == 1) { |
|
| 925 | - for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 926 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 927 | - } |
|
| 928 | - } else { |
|
| 929 | - $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 930 | - for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 931 | - if (!empty($query['post__in'][$i])) { |
|
| 932 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - unset($query['post__in']); |
|
| 937 | - $query['post__in'] = $tmp_array; |
|
| 938 | - $query['posts_per_page'] = -1; |
|
| 939 | - } |
|
| 850 | + if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 851 | + $criteria = 'wpshop_displayed_price'; |
|
| 852 | + } |
|
| 940 | 853 | |
| 941 | - $query['post_status'] = 'publish'; |
|
| 942 | - |
|
| 943 | - $custom_query = new WP_Query($query); |
|
| 944 | - |
|
| 945 | - if ($custom_query->have_posts()) { |
|
| 946 | - $have_results = true; |
|
| 947 | - |
|
| 948 | - // ---------------- // |
|
| 949 | - // Products listing // |
|
| 950 | - // ---------------- // |
|
| 951 | - $current_position = 1; |
|
| 952 | - $product_list = ''; |
|
| 953 | - while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 954 | - $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 955 | - $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 956 | - $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 957 | - $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 958 | - $current_position++; |
|
| 959 | - endwhile; |
|
| 960 | - $tpl_component = array(); |
|
| 961 | - $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 962 | - $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 963 | - $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 964 | - $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 965 | - $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 966 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 967 | - $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 968 | - |
|
| 969 | - // --------------------- // |
|
| 970 | - // Pagination management // |
|
| 971 | - // --------------------- // |
|
| 972 | - if ($display_pagination) { |
|
| 973 | - if ($nb_of_product_limit == 0) { |
|
| 974 | - |
|
| 975 | - $paginate = paginate_links(array( |
|
| 976 | - 'base' => '%_%', |
|
| 977 | - 'format' => '/?page_product=%#%', |
|
| 978 | - 'current' => $page_number, |
|
| 979 | - 'total' => $custom_query->max_num_pages, |
|
| 980 | - 'type' => 'array', |
|
| 981 | - 'prev_next' => false, |
|
| 982 | - )); |
|
| 983 | - if (!empty($paginate)) { |
|
| 984 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 985 | - foreach ($paginate as $p) { |
|
| 986 | - $string .= '<li>' . $p . '</li>'; |
|
| 987 | - } |
|
| 988 | - $string .= '</ul>'; |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 993 | - $paginate = paginate_links(array( |
|
| 994 | - 'base' => '%_%', |
|
| 995 | - 'format' => '/?page_product=%#%', |
|
| 996 | - 'current' => $page_number, |
|
| 997 | - 'total' => ceil(count($total_products) / $post_per_page), |
|
| 998 | - 'type' => 'array', |
|
| 999 | - 'prev_next' => false, |
|
| 1000 | - )); |
|
| 1001 | - if (!empty($paginate)) { |
|
| 1002 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 1003 | - foreach ($paginate as $p) { |
|
| 1004 | - $string .= '<li>' . $p . '</li>'; |
|
| 1005 | - } |
|
| 1006 | - $string .= '</ul>'; |
|
| 1007 | - } |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 854 | + $query = array( |
|
| 855 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 856 | + 'order' => $order, |
|
| 857 | + 'posts_per_page' => $products_per_page, |
|
| 858 | + 'paged' => $page_number, |
|
| 859 | + 'post_status' => 'publish', |
|
| 860 | + ); |
|
| 861 | + |
|
| 862 | + // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 863 | + if ($nb_of_product_limit > 0) { |
|
| 864 | + $query['posts_per_page'] = $nb_of_product_limit; |
|
| 865 | + unset($query['paged']); |
|
| 866 | + } |
|
| 867 | + if (!empty($pid)) { |
|
| 868 | + if (!is_array($pid)) { |
|
| 869 | + $pid = explode(',', $pid); |
|
| 870 | + } |
|
| 1010 | 871 | |
| 1011 | - } |
|
| 1012 | - wp_reset_query(); // important |
|
| 872 | + $query['post__in'] = $pid; |
|
| 873 | + } |
|
| 874 | + if (!empty($cid)) { |
|
| 875 | + $cid = explode(',', $cid); |
|
| 876 | + $query['tax_query'] = array(array( |
|
| 877 | + 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 878 | + 'field' => 'id', |
|
| 879 | + 'terms' => $cid, |
|
| 880 | + 'operator' => 'IN', |
|
| 881 | + )); |
|
| 882 | + } |
|
| 883 | + if ($criteria != null) { |
|
| 884 | + switch ($criteria) { |
|
| 885 | + case 'creator': |
|
| 886 | + case 'author': |
|
| 887 | + $query['author'] = get_current_user_id(); |
|
| 888 | + break; |
|
| 889 | + case 'none': |
|
| 890 | + case 'ID': |
|
| 891 | + case 'title': |
|
| 892 | + case 'date': |
|
| 893 | + case 'modified': |
|
| 894 | + case 'relevance': |
|
| 895 | + case 'post__in': |
|
| 896 | + case 'rand': |
|
| 897 | + $query['orderby'] = $criteria; |
|
| 898 | + break; |
|
| 899 | + default: |
|
| 900 | + if (!empty($pid)) { |
|
| 901 | + $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 902 | + } else { |
|
| 903 | + $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 904 | + $post_meta = $wpdb->get_var($check_meta); |
|
| 905 | + } |
|
| 906 | + if (!empty($post_meta)) { |
|
| 907 | + if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 908 | + $query['orderby'] = 'meta_value_num'; |
|
| 909 | + } else { |
|
| 910 | + $query['orderby'] = 'meta_value'; |
|
| 911 | + } |
|
| 912 | + $query['meta_key'] = '_' . $criteria; |
|
| 913 | + } |
|
| 914 | + break; |
|
| 915 | + } |
|
| 916 | + } else { |
|
| 917 | + $query['orderby'] = 'menu_order ID'; |
|
| 918 | + } |
|
| 919 | + $post_per_page = $query['posts_per_page']; |
|
| 920 | + $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 921 | + if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 922 | + $tmp_array = array(); |
|
| 923 | + |
|
| 924 | + if (empty($page_number) || $page_number == 1) { |
|
| 925 | + for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 926 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 927 | + } |
|
| 928 | + } else { |
|
| 929 | + $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 930 | + for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 931 | + if (!empty($query['post__in'][$i])) { |
|
| 932 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + unset($query['post__in']); |
|
| 937 | + $query['post__in'] = $tmp_array; |
|
| 938 | + $query['posts_per_page'] = -1; |
|
| 939 | + } |
|
| 1013 | 940 | |
| 1014 | - return array($have_results, $string); |
|
| 1015 | - } |
|
| 941 | + $query['post_status'] = 'publish'; |
|
| 942 | + |
|
| 943 | + $custom_query = new WP_Query($query); |
|
| 944 | + |
|
| 945 | + if ($custom_query->have_posts()) { |
|
| 946 | + $have_results = true; |
|
| 947 | + |
|
| 948 | + // ---------------- // |
|
| 949 | + // Products listing // |
|
| 950 | + // ---------------- // |
|
| 951 | + $current_position = 1; |
|
| 952 | + $product_list = ''; |
|
| 953 | + while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 954 | + $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 955 | + $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 956 | + $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 957 | + $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 958 | + $current_position++; |
|
| 959 | + endwhile; |
|
| 960 | + $tpl_component = array(); |
|
| 961 | + $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 962 | + $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 963 | + $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 964 | + $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 965 | + $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 966 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 967 | + $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 968 | + |
|
| 969 | + // --------------------- // |
|
| 970 | + // Pagination management // |
|
| 971 | + // --------------------- // |
|
| 972 | + if ($display_pagination) { |
|
| 973 | + if ($nb_of_product_limit == 0) { |
|
| 974 | + |
|
| 975 | + $paginate = paginate_links(array( |
|
| 976 | + 'base' => '%_%', |
|
| 977 | + 'format' => '/?page_product=%#%', |
|
| 978 | + 'current' => $page_number, |
|
| 979 | + 'total' => $custom_query->max_num_pages, |
|
| 980 | + 'type' => 'array', |
|
| 981 | + 'prev_next' => false, |
|
| 982 | + )); |
|
| 983 | + if (!empty($paginate)) { |
|
| 984 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 985 | + foreach ($paginate as $p) { |
|
| 986 | + $string .= '<li>' . $p . '</li>'; |
|
| 987 | + } |
|
| 988 | + $string .= '</ul>'; |
|
| 989 | + } |
|
| 990 | + } |
|
| 1016 | 991 | |
| 1017 | - /** |
|
| 1018 | - * Update quantity for a product |
|
| 1019 | - * @param integer $product_id The product we want to update quantity for |
|
| 1020 | - * @param decimal $qty The new quantity |
|
| 1021 | - */ |
|
| 1022 | - public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') |
|
| 1023 | - { |
|
| 1024 | - global $wpdb; |
|
| 1025 | - |
|
| 1026 | - $product = self::get_product_data($product_id); |
|
| 1027 | - /** Check if there is variation ***/ |
|
| 1028 | - if (!empty($variation_id) && $variation_id != $product_id) { |
|
| 1029 | - $variation_post_type = get_post_type($variation_id); |
|
| 1030 | - if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1031 | - /** Check if variation def is combined **/ |
|
| 1032 | - $variations = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1033 | - if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) { |
|
| 1034 | - /** Get post meta of variation */ |
|
| 1035 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1036 | - if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) { |
|
| 1037 | - $product = self::get_product_data($variation_id); |
|
| 1038 | - $product_id = $variation_id; |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 992 | + if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 993 | + $paginate = paginate_links(array( |
|
| 994 | + 'base' => '%_%', |
|
| 995 | + 'format' => '/?page_product=%#%', |
|
| 996 | + 'current' => $page_number, |
|
| 997 | + 'total' => ceil(count($total_products) / $post_per_page), |
|
| 998 | + 'type' => 'array', |
|
| 999 | + 'prev_next' => false, |
|
| 1000 | + )); |
|
| 1001 | + if (!empty($paginate)) { |
|
| 1002 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 1003 | + foreach ($paginate as $p) { |
|
| 1004 | + $string .= '<li>' . $p . '</li>'; |
|
| 1005 | + } |
|
| 1006 | + $string .= '</ul>'; |
|
| 1007 | + } |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + } |
|
| 1012 | + wp_reset_query(); // important |
|
| 1013 | + |
|
| 1014 | + return array($have_results, $string); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * Update quantity for a product |
|
| 1019 | + * @param integer $product_id The product we want to update quantity for |
|
| 1020 | + * @param decimal $qty The new quantity |
|
| 1021 | + */ |
|
| 1022 | + public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') |
|
| 1023 | + { |
|
| 1024 | + global $wpdb; |
|
| 1025 | + |
|
| 1026 | + $product = self::get_product_data($product_id); |
|
| 1027 | + /** Check if there is variation ***/ |
|
| 1028 | + if (!empty($variation_id) && $variation_id != $product_id) { |
|
| 1029 | + $variation_post_type = get_post_type($variation_id); |
|
| 1030 | + if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1031 | + /** Check if variation def is combined **/ |
|
| 1032 | + $variations = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1033 | + if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) { |
|
| 1034 | + /** Get post meta of variation */ |
|
| 1035 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1036 | + if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) { |
|
| 1037 | + $product = self::get_product_data($variation_id); |
|
| 1038 | + $product_id = $variation_id; |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - if (!empty($product)) { |
|
| 1045 | - $newQty = $product['product_stock'] - $qty; |
|
| 1046 | - $value_id = 0; |
|
| 1047 | - if ($newQty >= 0) { |
|
| 1048 | - $query = ' |
|
| 1044 | + if (!empty($product)) { |
|
| 1045 | + $newQty = $product['product_stock'] - $qty; |
|
| 1046 | + $value_id = 0; |
|
| 1047 | + if ($newQty >= 0) { |
|
| 1048 | + $query = ' |
|
| 1049 | 1049 | SELECT wp_wpshop__attribute_value_decimal.value_id |
| 1050 | 1050 | FROM wp_wpshop__attribute_value_decimal |
| 1051 | 1051 | LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id |
| 1052 | 1052 | WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock" |
| 1053 | 1053 | LIMIT 1 |
| 1054 | 1054 | '; |
| 1055 | - $value_id = $wpdb->get_var($query); |
|
| 1056 | - $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id)); |
|
| 1057 | - } |
|
| 1058 | - // Historic |
|
| 1059 | - $attribute_histo_content = array(); |
|
| 1060 | - $attribute_histo_content['status'] = 'valid'; |
|
| 1061 | - $attribute_histo_content['creation_date'] = current_time('mysql', 0); |
|
| 1062 | - $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0); |
|
| 1063 | - $attribute_histo_content['original_value_id'] = $value_id; |
|
| 1064 | - $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1065 | - $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code'); |
|
| 1066 | - $attribute_histo_content['attribute_id'] = $stock_atribute->id; |
|
| 1067 | - $attribute_histo_content['entity_id'] = $product_id; |
|
| 1068 | - $attribute_histo_content['value'] = $product['product_stock']; |
|
| 1069 | - $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal'; |
|
| 1070 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content); |
|
| 1071 | - |
|
| 1072 | - $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 1073 | - $product_meta['product_stock'] = $newQty; |
|
| 1074 | - update_post_meta($product_id, '_wpshop_product_metadata', $product_meta); |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1055 | + $value_id = $wpdb->get_var($query); |
|
| 1056 | + $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id)); |
|
| 1057 | + } |
|
| 1058 | + // Historic |
|
| 1059 | + $attribute_histo_content = array(); |
|
| 1060 | + $attribute_histo_content['status'] = 'valid'; |
|
| 1061 | + $attribute_histo_content['creation_date'] = current_time('mysql', 0); |
|
| 1062 | + $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0); |
|
| 1063 | + $attribute_histo_content['original_value_id'] = $value_id; |
|
| 1064 | + $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1065 | + $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code'); |
|
| 1066 | + $attribute_histo_content['attribute_id'] = $stock_atribute->id; |
|
| 1067 | + $attribute_histo_content['entity_id'] = $product_id; |
|
| 1068 | + $attribute_histo_content['value'] = $product['product_stock']; |
|
| 1069 | + $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal'; |
|
| 1070 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content); |
|
| 1071 | + |
|
| 1072 | + $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 1073 | + $product_meta['product_stock'] = $newQty; |
|
| 1074 | + update_post_meta($product_id, '_wpshop_product_metadata', $product_meta); |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | 1077 | |
| 1078 | - /** |
|
| 1079 | - * Retrieve an array with complete information about a given product |
|
| 1080 | - * @param integer $product_id |
|
| 1081 | - * @param boolean $for_cart_storage |
|
| 1082 | - * @return array Information about the product defined by first parameter |
|
| 1083 | - */ |
|
| 1084 | - public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1085 | - { |
|
| 1086 | - global $wpdb; |
|
| 1087 | - $query = $wpdb->prepare(' |
|
| 1078 | + /** |
|
| 1079 | + * Retrieve an array with complete information about a given product |
|
| 1080 | + * @param integer $product_id |
|
| 1081 | + * @param boolean $for_cart_storage |
|
| 1082 | + * @return array Information about the product defined by first parameter |
|
| 1083 | + */ |
|
| 1084 | + public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1085 | + { |
|
| 1086 | + global $wpdb; |
|
| 1087 | + $query = $wpdb->prepare(' |
|
| 1088 | 1088 | SELECT P.*, PM.meta_value AS attribute_set_id |
| 1089 | 1089 | FROM ' . $wpdb->posts . ' AS P |
| 1090 | 1090 | INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID) |
@@ -1096,398 +1096,398 @@ discard block |
||
| 1096 | 1096 | LIMIT 1 |
| 1097 | 1097 | ', $product_id); |
| 1098 | 1098 | |
| 1099 | - $product = $wpdb->get_row($query); |
|
| 1100 | - |
|
| 1101 | - $product_data = array(); |
|
| 1102 | - $product_meta = array(); |
|
| 1103 | - |
|
| 1104 | - if (!empty($product)) { |
|
| 1105 | - $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1106 | - $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1107 | - $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1108 | - $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1109 | - |
|
| 1110 | - $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1111 | - $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1112 | - $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1113 | - $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1114 | - |
|
| 1115 | - $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1116 | - |
|
| 1117 | - $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); |
|
| 1118 | - if (!empty($data)) { |
|
| 1119 | - foreach ($data as $attribute) { |
|
| 1120 | - $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1121 | - $value = $attribute->$data_type; |
|
| 1122 | - if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1123 | - $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - /** Special traitment regarding attribute_code */ |
|
| 1127 | - switch ($attribute->attribute_code) { |
|
| 1128 | - case 'product_weight': |
|
| 1129 | - $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1130 | - if (!empty($default_weight_unity)) { |
|
| 1131 | - $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1132 | - $unity = $wpdb->get_var($query); |
|
| 1133 | - if ($unity == 'kg') { |
|
| 1134 | - $value *= 1000; |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - } |
|
| 1138 | - break; |
|
| 1139 | - default: |
|
| 1140 | - $value = !empty($value) ? $value : 0; |
|
| 1141 | - break; |
|
| 1142 | - } |
|
| 1143 | - $product_data[$attribute->attribute_code] = $value; |
|
| 1144 | - |
|
| 1145 | - if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1146 | - $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1147 | - if (!empty($meta)) { |
|
| 1148 | - $product_meta[$attribute->attribute_code] = $meta; |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1153 | - $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1154 | - } |
|
| 1155 | - if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1156 | - $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - } else { |
|
| 1160 | - |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - /** Get datas about product options */ |
|
| 1164 | - if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1165 | - $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1166 | - |
|
| 1167 | - foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1168 | - $variation_id = $attribute_value; |
|
| 1169 | - $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1170 | - |
|
| 1171 | - $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)); |
|
| 1172 | - $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1173 | - switch ($attribute_definition->backend_input) { |
|
| 1174 | - case 'select': |
|
| 1175 | - case 'multiple-select': |
|
| 1176 | - case 'radio': |
|
| 1177 | - case 'checkbox': |
|
| 1178 | - $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1179 | - break; |
|
| 1180 | - } |
|
| 1181 | - $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1182 | - $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1187 | - |
|
| 1188 | - /** Get the display definition for the current product for checking custom display */ |
|
| 1189 | - $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1190 | - } |
|
| 1099 | + $product = $wpdb->get_row($query); |
|
| 1100 | + |
|
| 1101 | + $product_data = array(); |
|
| 1102 | + $product_meta = array(); |
|
| 1103 | + |
|
| 1104 | + if (!empty($product)) { |
|
| 1105 | + $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1106 | + $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1107 | + $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1108 | + $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1109 | + |
|
| 1110 | + $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1111 | + $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1112 | + $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1113 | + $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1114 | + |
|
| 1115 | + $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1116 | + |
|
| 1117 | + $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); |
|
| 1118 | + if (!empty($data)) { |
|
| 1119 | + foreach ($data as $attribute) { |
|
| 1120 | + $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1121 | + $value = $attribute->$data_type; |
|
| 1122 | + if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1123 | + $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + /** Special traitment regarding attribute_code */ |
|
| 1127 | + switch ($attribute->attribute_code) { |
|
| 1128 | + case 'product_weight': |
|
| 1129 | + $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1130 | + if (!empty($default_weight_unity)) { |
|
| 1131 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1132 | + $unity = $wpdb->get_var($query); |
|
| 1133 | + if ($unity == 'kg') { |
|
| 1134 | + $value *= 1000; |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + } |
|
| 1138 | + break; |
|
| 1139 | + default: |
|
| 1140 | + $value = !empty($value) ? $value : 0; |
|
| 1141 | + break; |
|
| 1142 | + } |
|
| 1143 | + $product_data[$attribute->attribute_code] = $value; |
|
| 1144 | + |
|
| 1145 | + if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1146 | + $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1147 | + if (!empty($meta)) { |
|
| 1148 | + $product_meta[$attribute->attribute_code] = $meta; |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1153 | + $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1154 | + } |
|
| 1155 | + if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1156 | + $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + } else { |
|
| 1191 | 1160 | |
| 1192 | - return $product_data; |
|
| 1193 | - } |
|
| 1161 | + } |
|
| 1194 | 1162 | |
| 1195 | - /** |
|
| 1196 | - * Add a product into the db. This function is used for the EDI |
|
| 1197 | - * @param $name Name of the product |
|
| 1198 | - * @param $description Description of the product |
|
| 1199 | - * @param $attrs List of the attributes and values of the product |
|
| 1200 | - * @return boolean |
|
| 1201 | - */ |
|
| 1202 | - public function addProduct($name, $description, $attrs = array()) |
|
| 1203 | - { |
|
| 1204 | - $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1205 | - return $new_product[0]; |
|
| 1206 | - } |
|
| 1163 | + /** Get datas about product options */ |
|
| 1164 | + if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1165 | + $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1166 | + |
|
| 1167 | + foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1168 | + $variation_id = $attribute_value; |
|
| 1169 | + $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1170 | + |
|
| 1171 | + $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)); |
|
| 1172 | + $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1173 | + switch ($attribute_definition->backend_input) { |
|
| 1174 | + case 'select': |
|
| 1175 | + case 'multiple-select': |
|
| 1176 | + case 'radio': |
|
| 1177 | + case 'checkbox': |
|
| 1178 | + $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1179 | + break; |
|
| 1180 | + } |
|
| 1181 | + $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1182 | + $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1207 | 1185 | |
| 1208 | - /** |
|
| 1209 | - * Retrieve a product listing |
|
| 1210 | - * @param boolean $formated If the output have to be formated or not |
|
| 1211 | - * @param string $product_search Optionnal Define a search term for request |
|
| 1212 | - * @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 |
|
| 1213 | - */ |
|
| 1214 | - public static function product_list($formated = false, $product_search = null) |
|
| 1215 | - { |
|
| 1216 | - global $wpdb; |
|
| 1217 | - |
|
| 1218 | - $query_extra_params = $query_extra_params_value = ''; |
|
| 1219 | - if (!empty($product_search)) { |
|
| 1220 | - $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1221 | - if (is_array($product_search)) { |
|
| 1222 | - $query_extra_params = " AND ID IN (%s)"; |
|
| 1223 | - $query_extra_params_value = implode(",", $product_search); |
|
| 1224 | - } |
|
| 1225 | - } |
|
| 1186 | + $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1187 | + |
|
| 1188 | + /** Get the display definition for the current product for checking custom display */ |
|
| 1189 | + $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return $product_data; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + /** |
|
| 1196 | + * Add a product into the db. This function is used for the EDI |
|
| 1197 | + * @param $name Name of the product |
|
| 1198 | + * @param $description Description of the product |
|
| 1199 | + * @param $attrs List of the attributes and values of the product |
|
| 1200 | + * @return boolean |
|
| 1201 | + */ |
|
| 1202 | + public function addProduct($name, $description, $attrs = array()) |
|
| 1203 | + { |
|
| 1204 | + $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1205 | + return $new_product[0]; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * Retrieve a product listing |
|
| 1210 | + * @param boolean $formated If the output have to be formated or not |
|
| 1211 | + * @param string $product_search Optionnal Define a search term for request |
|
| 1212 | + * @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 |
|
| 1213 | + */ |
|
| 1214 | + public static function product_list($formated = false, $product_search = null) |
|
| 1215 | + { |
|
| 1216 | + global $wpdb; |
|
| 1217 | + |
|
| 1218 | + $query_extra_params = $query_extra_params_value = ''; |
|
| 1219 | + if (!empty($product_search)) { |
|
| 1220 | + $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1221 | + if (is_array($product_search)) { |
|
| 1222 | + $query_extra_params = " AND ID IN (%s)"; |
|
| 1223 | + $query_extra_params_value = implode(",", $product_search); |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1226 | 1226 | |
| 1227 | - $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); |
|
| 1228 | - $data = $wpdb->get_results($query); |
|
| 1227 | + $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); |
|
| 1228 | + $data = $wpdb->get_results($query); |
|
| 1229 | 1229 | |
| 1230 | - /* |
|
| 1230 | + /* |
|
| 1231 | 1231 | * Make some arangement on output if parameter is given |
| 1232 | 1232 | */ |
| 1233 | - if ($formated) { |
|
| 1234 | - $product_string = ''; |
|
| 1235 | - foreach ($data as $d) { |
|
| 1236 | - $product_string .= ' |
|
| 1233 | + if ($formated) { |
|
| 1234 | + $product_string = ''; |
|
| 1235 | + foreach ($data as $d) { |
|
| 1236 | + $product_string .= ' |
|
| 1237 | 1237 | <li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" > |
| 1238 | 1238 | <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> |
| 1239 | 1239 | </li>'; |
| 1240 | - } |
|
| 1241 | - } |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - return $formated ? $product_string : $data; |
|
| 1244 | - } |
|
| 1243 | + return $formated ? $product_string : $data; |
|
| 1244 | + } |
|
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * Enregistrement des données pour le produit |
|
| 1248 | - */ |
|
| 1249 | - public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1250 | - { |
|
| 1251 | - global $wpdb; |
|
| 1252 | - |
|
| 1253 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1254 | - // Apply a filter to extra actions |
|
| 1255 | - $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1256 | - |
|
| 1257 | - 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"))) { |
|
| 1258 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1259 | - /* Fill the product reference automatically if nothing is sent */ |
|
| 1260 | - if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1261 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1262 | - $last_ref = $wpdb->get_var($query); |
|
| 1263 | - $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; |
|
| 1264 | - } else { |
|
| 1265 | - /* Check if the product reference existing in the database */ |
|
| 1266 | - $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1267 | - $query = $wpdb->prepare( |
|
| 1268 | - "SELECT value_id |
|
| 1246 | + /** |
|
| 1247 | + * Enregistrement des données pour le produit |
|
| 1248 | + */ |
|
| 1249 | + public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1250 | + { |
|
| 1251 | + global $wpdb; |
|
| 1252 | + |
|
| 1253 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1254 | + // Apply a filter to extra actions |
|
| 1255 | + $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1256 | + |
|
| 1257 | + 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"))) { |
|
| 1258 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1259 | + /* Fill the product reference automatically if nothing is sent */ |
|
| 1260 | + if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1261 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1262 | + $last_ref = $wpdb->get_var($query); |
|
| 1263 | + $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; |
|
| 1264 | + } else { |
|
| 1265 | + /* Check if the product reference existing in the database */ |
|
| 1266 | + $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1267 | + $query = $wpdb->prepare( |
|
| 1268 | + "SELECT value_id |
|
| 1269 | 1269 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
| 1270 | 1270 | INNER JOIN {$wpdb->posts} ON ( ID = entity_id ) |
| 1271 | 1271 | WHERE value = %s |
| 1272 | 1272 | AND entity_id != %d |
| 1273 | 1273 | AND entity_type_id = %d" |
| 1274 | - , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1275 | - $existing_reference = $wpdb->get_var($query); |
|
| 1276 | - |
|
| 1277 | - /* If this product reference exist -> Create a new product reference */ |
|
| 1278 | - if ($wpdb->num_rows > 0) { |
|
| 1279 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1280 | - $last_ref = $wpdb->get_var($query); |
|
| 1281 | - $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; |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - /* Save the attributes values into wpshop eav database */ |
|
| 1286 | - $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1287 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1288 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1289 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1290 | - $lang = $wpdb->get_var($query); |
|
| 1291 | - } |
|
| 1292 | - 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); |
|
| 1293 | - |
|
| 1294 | - /* Update product price looking for shop parameters */ |
|
| 1295 | - wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1296 | - |
|
| 1297 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1298 | - $productMetaDatas = array(); |
|
| 1299 | - foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1300 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1301 | - if ($attributeCode == 'product_attribute_set_id') { |
|
| 1302 | - /* Update the attribute set id for the current product */ |
|
| 1303 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1304 | - } |
|
| 1305 | - if ($attributeType == 'decimal') { |
|
| 1306 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1307 | - } |
|
| 1308 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1309 | - $attributeValue = (int) $attributeValue; |
|
| 1310 | - } |
|
| 1311 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1318 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1319 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1320 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1324 | - if (empty($product['product_id'])) { |
|
| 1325 | - $product['product_id'] = $data_to_save['post_ID']; |
|
| 1326 | - } |
|
| 1327 | - $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1328 | - update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1329 | - |
|
| 1330 | - /** Save product variation */ |
|
| 1331 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1332 | - foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1333 | - |
|
| 1334 | - foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1335 | - $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1336 | - 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])) { |
|
| 1337 | - $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; |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1341 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1342 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1343 | - $lang = $wpdb->get_var($query); |
|
| 1344 | - } |
|
| 1345 | - wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1346 | - |
|
| 1347 | - /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1348 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1349 | - if (!empty($variation_metadata)) { |
|
| 1350 | - $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1351 | - if (!empty($attributes_list)) { |
|
| 1352 | - foreach ($attributes_list as $attribute) { |
|
| 1353 | - $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1354 | - $attributeValue = $attribute->$value_key; |
|
| 1355 | - if ($attribute->data_type == 'decimal') { |
|
| 1356 | - $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1357 | - } |
|
| 1358 | - if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1359 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1360 | - } |
|
| 1361 | - $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1367 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1368 | - if ($attributeType == 'decimal') { |
|
| 1369 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1370 | - } |
|
| 1371 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1372 | - $attributeValue = (int) $attributeValue; |
|
| 1373 | - } |
|
| 1374 | - $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1375 | - } |
|
| 1376 | - } |
|
| 1377 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1378 | - |
|
| 1379 | - /** Save attached picture id **/ |
|
| 1380 | - $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']) : ''; |
|
| 1381 | - $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1382 | - |
|
| 1383 | - /* Update product price looking for shop parameters */ |
|
| 1384 | - wpshop_products::calculate_price($variation_id); |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /* Update the related products list*/ |
|
| 1389 | - if (!empty($data_to_save['related_products_list'])) { |
|
| 1390 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1391 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1392 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1393 | - } |
|
| 1394 | - /* Update the provider list*/ |
|
| 1395 | - if (!empty($data_to_save['provider_list'])) { |
|
| 1396 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1397 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1398 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - /* Update product options */ |
|
| 1402 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1403 | - update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1404 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1405 | - delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - /** Add flag on variations to check which type of variation **/ |
|
| 1409 | - $check_product_have_variations = self::get_variation($post_id); |
|
| 1410 | - if (!empty($check_product_have_variations)) { |
|
| 1411 | - $variation_flag = self::check_variation_type($post_id); |
|
| 1412 | - $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1413 | - $variation_defining['variation_type'] = $variation_flag; |
|
| 1414 | - update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1415 | - } |
|
| 1416 | - 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); |
|
| 1417 | - } |
|
| 1274 | + , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1275 | + $existing_reference = $wpdb->get_var($query); |
|
| 1276 | + |
|
| 1277 | + /* If this product reference exist -> Create a new product reference */ |
|
| 1278 | + if ($wpdb->num_rows > 0) { |
|
| 1279 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1280 | + $last_ref = $wpdb->get_var($query); |
|
| 1281 | + $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; |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1418 | 1284 | |
| 1419 | - flush_rewrite_rules(); |
|
| 1420 | - } |
|
| 1285 | + /* Save the attributes values into wpshop eav database */ |
|
| 1286 | + $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1287 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1288 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1289 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1290 | + $lang = $wpdb->get_var($query); |
|
| 1291 | + } |
|
| 1292 | + 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); |
|
| 1293 | + |
|
| 1294 | + /* Update product price looking for shop parameters */ |
|
| 1295 | + wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1296 | + |
|
| 1297 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1298 | + $productMetaDatas = array(); |
|
| 1299 | + foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1300 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1301 | + if ($attributeCode == 'product_attribute_set_id') { |
|
| 1302 | + /* Update the attribute set id for the current product */ |
|
| 1303 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1304 | + } |
|
| 1305 | + if ($attributeType == 'decimal') { |
|
| 1306 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1307 | + } |
|
| 1308 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1309 | + $attributeValue = (int) $attributeValue; |
|
| 1310 | + } |
|
| 1311 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1315 | + } |
|
| 1421 | 1316 | |
| 1422 | - /** |
|
| 1423 | - * Return the variation type |
|
| 1424 | - * @param integer $post_id |
|
| 1425 | - * @return string |
|
| 1426 | - */ |
|
| 1427 | - public function check_variation_type($post_id) |
|
| 1428 | - { |
|
| 1429 | - $variation_type = 'single'; |
|
| 1430 | - if (!empty($variation_type)) { |
|
| 1431 | - $variations = self::get_variation($post_id); |
|
| 1432 | - if (!empty($variations)) { |
|
| 1433 | - foreach ($variations as $variation_id => $variation_data) { |
|
| 1434 | - if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1435 | - return 'single'; |
|
| 1436 | - } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1437 | - $variation_type = 'combined'; |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - return $variation_type; |
|
| 1443 | - } |
|
| 1317 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1318 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1319 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1320 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1321 | + } |
|
| 1444 | 1322 | |
| 1445 | - /** |
|
| 1446 | - * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1447 | - * |
|
| 1448 | - * @param mixed $permalink The actual permalink of the element |
|
| 1449 | - * @param object $post The post we want to set the permalink for |
|
| 1450 | - * @param void |
|
| 1451 | - * |
|
| 1452 | - * @return mixed The new permalink for the current element |
|
| 1453 | - */ |
|
| 1454 | - public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1455 | - { |
|
| 1456 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1457 | - |
|
| 1458 | - if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1459 | - if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1460 | - return $permalink; |
|
| 1461 | - } else { |
|
| 1462 | - $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1463 | - $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1464 | - if (empty($product_categories)) { |
|
| 1465 | - $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1466 | - } else { |
|
| 1467 | - $product_category_slug = $product_categories[0]->slug; |
|
| 1468 | - } |
|
| 1469 | - $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1470 | - } |
|
| 1471 | - } |
|
| 1323 | + $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1324 | + if (empty($product['product_id'])) { |
|
| 1325 | + $product['product_id'] = $data_to_save['post_ID']; |
|
| 1326 | + } |
|
| 1327 | + $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1328 | + update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1329 | + |
|
| 1330 | + /** Save product variation */ |
|
| 1331 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1332 | + foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1333 | + |
|
| 1334 | + foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1335 | + $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1336 | + 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])) { |
|
| 1337 | + $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; |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1341 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1342 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1343 | + $lang = $wpdb->get_var($query); |
|
| 1344 | + } |
|
| 1345 | + wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1346 | + |
|
| 1347 | + /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1348 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1349 | + if (!empty($variation_metadata)) { |
|
| 1350 | + $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1351 | + if (!empty($attributes_list)) { |
|
| 1352 | + foreach ($attributes_list as $attribute) { |
|
| 1353 | + $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1354 | + $attributeValue = $attribute->$value_key; |
|
| 1355 | + if ($attribute->data_type == 'decimal') { |
|
| 1356 | + $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1357 | + } |
|
| 1358 | + if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1359 | + $attributeValue = (int) $attribute->$value_key; |
|
| 1360 | + } |
|
| 1361 | + $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1367 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1368 | + if ($attributeType == 'decimal') { |
|
| 1369 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1370 | + } |
|
| 1371 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1372 | + $attributeValue = (int) $attributeValue; |
|
| 1373 | + } |
|
| 1374 | + $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1375 | + } |
|
| 1376 | + } |
|
| 1377 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1378 | + |
|
| 1379 | + /** Save attached picture id **/ |
|
| 1380 | + $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']) : ''; |
|
| 1381 | + $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1382 | + |
|
| 1383 | + /* Update product price looking for shop parameters */ |
|
| 1384 | + wpshop_products::calculate_price($variation_id); |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /* Update the related products list*/ |
|
| 1389 | + if (!empty($data_to_save['related_products_list'])) { |
|
| 1390 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1391 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1392 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1393 | + } |
|
| 1394 | + /* Update the provider list*/ |
|
| 1395 | + if (!empty($data_to_save['provider_list'])) { |
|
| 1396 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1397 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1398 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + /* Update product options */ |
|
| 1402 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1403 | + update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1404 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1405 | + delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + /** Add flag on variations to check which type of variation **/ |
|
| 1409 | + $check_product_have_variations = self::get_variation($post_id); |
|
| 1410 | + if (!empty($check_product_have_variations)) { |
|
| 1411 | + $variation_flag = self::check_variation_type($post_id); |
|
| 1412 | + $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1413 | + $variation_defining['variation_type'] = $variation_flag; |
|
| 1414 | + update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1415 | + } |
|
| 1416 | + 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); |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + flush_rewrite_rules(); |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + /** |
|
| 1423 | + * Return the variation type |
|
| 1424 | + * @param integer $post_id |
|
| 1425 | + * @return string |
|
| 1426 | + */ |
|
| 1427 | + public function check_variation_type($post_id) |
|
| 1428 | + { |
|
| 1429 | + $variation_type = 'single'; |
|
| 1430 | + if (!empty($variation_type)) { |
|
| 1431 | + $variations = self::get_variation($post_id); |
|
| 1432 | + if (!empty($variations)) { |
|
| 1433 | + foreach ($variations as $variation_id => $variation_data) { |
|
| 1434 | + if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1435 | + return 'single'; |
|
| 1436 | + } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1437 | + $variation_type = 'combined'; |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + return $variation_type; |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + /** |
|
| 1446 | + * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1447 | + * |
|
| 1448 | + * @param mixed $permalink The actual permalink of the element |
|
| 1449 | + * @param object $post The post we want to set the permalink for |
|
| 1450 | + * @param void |
|
| 1451 | + * |
|
| 1452 | + * @return mixed The new permalink for the current element |
|
| 1453 | + */ |
|
| 1454 | + public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1455 | + { |
|
| 1456 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1457 | + |
|
| 1458 | + if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1459 | + if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1460 | + return $permalink; |
|
| 1461 | + } else { |
|
| 1462 | + $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1463 | + $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1464 | + if (empty($product_categories)) { |
|
| 1465 | + $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1466 | + } else { |
|
| 1467 | + $product_category_slug = $product_categories[0]->slug; |
|
| 1468 | + } |
|
| 1469 | + $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1470 | + } |
|
| 1471 | + } |
|
| 1472 | 1472 | |
| 1473 | - return $permalink; |
|
| 1473 | + return $permalink; |
|
| 1474 | 1474 | |
| 1475 | - //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1475 | + //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1476 | 1476 | |
| 1477 | - //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1477 | + //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1478 | 1478 | |
| 1479 | - /*if(false) { |
|
| 1479 | + /*if(false) { |
|
| 1480 | 1480 | global $wp_query; |
| 1481 | 1481 | $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES ); |
| 1482 | 1482 | |
| 1483 | 1483 | if(count($product_categories) == 0){ /* Product has only one category we get the only available slug */ |
| 1484 | - /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1484 | + /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1485 | 1485 | } |
| 1486 | 1486 | elseif(count($product_categories) == 1){ /* Product has only one category we get the only available slug */ |
| 1487 | - /* $product_category_slug = $product_categories[0]->slug; |
|
| 1487 | + /* $product_category_slug = $product_categories[0]->slug; |
|
| 1488 | 1488 | } |
| 1489 | 1489 | else{ /* Product has several categories choose the slug of the we want */ |
| 1490 | - /* $product_category_slugs = array(); |
|
| 1490 | + /* $product_category_slugs = array(); |
|
| 1491 | 1491 | foreach($product_categories as $product_category){ |
| 1492 | 1492 | $product_category_slugs[] = $product_category->slug; |
| 1493 | 1493 | } |
@@ -1497,457 +1497,457 @@ discard block |
||
| 1497 | 1497 | $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
| 1498 | 1498 | return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID ); |
| 1499 | 1499 | }*/ |
| 1500 | - } |
|
| 1500 | + } |
|
| 1501 | 1501 | |
| 1502 | - public static function set_product_request_by_name($query) |
|
| 1503 | - { |
|
| 1504 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1502 | + public static function set_product_request_by_name($query) |
|
| 1503 | + { |
|
| 1504 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1505 | 1505 | |
| 1506 | - if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1507 | - // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1508 | - } |
|
| 1506 | + if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1507 | + // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1508 | + } |
|
| 1509 | 1509 | |
| 1510 | - /** |
|
| 1511 | - * Define output for product |
|
| 1512 | - * |
|
| 1513 | - * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1514 | - * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1515 | - * |
|
| 1516 | - * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1517 | - */ |
|
| 1518 | - public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1519 | - { |
|
| 1520 | - $content = $attributeContentOutput = ''; |
|
| 1521 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1522 | - /** Log number of view for the current product */ |
|
| 1523 | - $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1524 | - $product_view_number++; |
|
| 1525 | - update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1526 | - |
|
| 1527 | - /** Get product definition */ |
|
| 1528 | - |
|
| 1529 | - $product = self::get_product_data($product_id); |
|
| 1530 | - wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1531 | - |
|
| 1532 | - /** Get the product thumbnail */ |
|
| 1533 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1534 | - if (has_post_thumbnail($product_id)) { |
|
| 1535 | - $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1536 | - $tpl_component = array(); |
|
| 1537 | - $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1538 | - $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1539 | - $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1540 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1541 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1542 | - foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1543 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1544 | - $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; |
|
| 1545 | - } |
|
| 1546 | - } |
|
| 1547 | - $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; |
|
| 1548 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1549 | - unset($tpl_component); |
|
| 1550 | - } |
|
| 1510 | + /** |
|
| 1511 | + * Define output for product |
|
| 1512 | + * |
|
| 1513 | + * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1514 | + * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1515 | + * |
|
| 1516 | + * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1517 | + */ |
|
| 1518 | + public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1519 | + { |
|
| 1520 | + $content = $attributeContentOutput = ''; |
|
| 1521 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1522 | + /** Log number of view for the current product */ |
|
| 1523 | + $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1524 | + $product_view_number++; |
|
| 1525 | + update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1526 | + |
|
| 1527 | + /** Get product definition */ |
|
| 1528 | + |
|
| 1529 | + $product = self::get_product_data($product_id); |
|
| 1530 | + wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1531 | + |
|
| 1532 | + /** Get the product thumbnail */ |
|
| 1533 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1534 | + if (has_post_thumbnail($product_id)) { |
|
| 1535 | + $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1536 | + $tpl_component = array(); |
|
| 1537 | + $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1538 | + $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1539 | + $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1540 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1541 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1542 | + foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1543 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1544 | + $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; |
|
| 1545 | + } |
|
| 1546 | + } |
|
| 1547 | + $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; |
|
| 1548 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1549 | + unset($tpl_component); |
|
| 1550 | + } |
|
| 1551 | 1551 | |
| 1552 | - $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1553 | - |
|
| 1554 | - /** Retrieve product attributes for output */ |
|
| 1555 | - $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1556 | - |
|
| 1557 | - /** Retrieve product price */ |
|
| 1558 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1559 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1560 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1561 | - $productPrice = ''; |
|
| 1562 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1563 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1564 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1565 | - 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)) { |
|
| 1566 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1567 | - } |
|
| 1552 | + $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1553 | + |
|
| 1554 | + /** Retrieve product attributes for output */ |
|
| 1555 | + $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1556 | + |
|
| 1557 | + /** Retrieve product price */ |
|
| 1558 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1559 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1560 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1561 | + $productPrice = ''; |
|
| 1562 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1563 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1564 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1565 | + 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)) { |
|
| 1566 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1567 | + } |
|
| 1568 | 1568 | |
| 1569 | - /** Check if there is at less 1 product in stock */ |
|
| 1570 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1571 | - $productStock = ($productStock === true) ? 1 : null; |
|
| 1569 | + /** Check if there is at less 1 product in stock */ |
|
| 1570 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1571 | + $productStock = ($productStock === true) ? 1 : null; |
|
| 1572 | 1572 | |
| 1573 | - /** if !product stock check product have variation with stock **/ |
|
| 1573 | + /** if !product stock check product have variation with stock **/ |
|
| 1574 | 1574 | // if ( empty($productStock) ) { |
| 1575 | - $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1576 | - if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1577 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1578 | - if (!empty($variations)) { |
|
| 1579 | - foreach ($variations as $variation) { |
|
| 1580 | - if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1581 | - $productStock = 1; |
|
| 1582 | - } |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - } |
|
| 1575 | + $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1576 | + if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1577 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1578 | + if (!empty($variations)) { |
|
| 1579 | + foreach ($variations as $variation) { |
|
| 1580 | + if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1581 | + $productStock = 1; |
|
| 1582 | + } |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + } |
|
| 1586 | 1586 | // } |
| 1587 | 1587 | |
| 1588 | - /** Define "Add to cart" button */ |
|
| 1589 | - $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'); |
|
| 1590 | - $display_price_state_when_price_is_empty = true; |
|
| 1591 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1592 | - $display_price_state_when_price_is_empty = false; |
|
| 1593 | - } else if (!empty($productPrice)) { |
|
| 1594 | - $display_price_state_when_price_is_empty = true; |
|
| 1595 | - } |
|
| 1596 | - $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') : ''; |
|
| 1597 | - $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)) : ''; |
|
| 1598 | - |
|
| 1599 | - /** Define "Ask a quotation" button */ |
|
| 1600 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1601 | - |
|
| 1602 | - /** Template parameters */ |
|
| 1603 | - $template_part = 'product_complete_tpl'; |
|
| 1604 | - $tpl_component = array(); |
|
| 1605 | - |
|
| 1606 | - $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1607 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1608 | - $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1609 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1610 | - $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1611 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1612 | - $modules_option = get_option('wpshop_modules'); |
|
| 1613 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1614 | - if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1615 | - $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1616 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1617 | - } |
|
| 1588 | + /** Define "Add to cart" button */ |
|
| 1589 | + $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'); |
|
| 1590 | + $display_price_state_when_price_is_empty = true; |
|
| 1591 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1592 | + $display_price_state_when_price_is_empty = false; |
|
| 1593 | + } else if (!empty($productPrice)) { |
|
| 1594 | + $display_price_state_when_price_is_empty = true; |
|
| 1595 | + } |
|
| 1596 | + $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') : ''; |
|
| 1597 | + $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)) : ''; |
|
| 1598 | + |
|
| 1599 | + /** Define "Ask a quotation" button */ |
|
| 1600 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1601 | + |
|
| 1602 | + /** Template parameters */ |
|
| 1603 | + $template_part = 'product_complete_tpl'; |
|
| 1604 | + $tpl_component = array(); |
|
| 1605 | + |
|
| 1606 | + $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1607 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1608 | + $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1609 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1610 | + $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1611 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1612 | + $modules_option = get_option('wpshop_modules'); |
|
| 1613 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1614 | + if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1615 | + $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1616 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1617 | + } |
|
| 1618 | 1618 | |
| 1619 | - /** Gallery **/ |
|
| 1620 | - $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1621 | - |
|
| 1622 | - $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'] : '')); |
|
| 1623 | - |
|
| 1624 | - $product_new = $product_new_def['output']; |
|
| 1625 | - $product_class = $product_new_def['class']; |
|
| 1626 | - |
|
| 1627 | - $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'] : '')); |
|
| 1628 | - $product_featured = $product_featured_def['output']; |
|
| 1629 | - $product_class .= $product_featured_def['class']; |
|
| 1630 | - |
|
| 1631 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1632 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1633 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1634 | - |
|
| 1635 | - $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1636 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1637 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1638 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1639 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1640 | - $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1641 | - $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1642 | - $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1643 | - |
|
| 1644 | - /** Build template */ |
|
| 1645 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1646 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1647 | - /* Include the old way template part */ |
|
| 1648 | - ob_start(); |
|
| 1649 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1650 | - $content = ob_get_contents(); |
|
| 1651 | - ob_end_clean(); |
|
| 1652 | - } else { |
|
| 1653 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1654 | - } |
|
| 1655 | - unset($tpl_component); |
|
| 1656 | - return $content; |
|
| 1657 | - } |
|
| 1619 | + /** Gallery **/ |
|
| 1620 | + $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1621 | + |
|
| 1622 | + $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'] : '')); |
|
| 1623 | + |
|
| 1624 | + $product_new = $product_new_def['output']; |
|
| 1625 | + $product_class = $product_new_def['class']; |
|
| 1626 | + |
|
| 1627 | + $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'] : '')); |
|
| 1628 | + $product_featured = $product_featured_def['output']; |
|
| 1629 | + $product_class .= $product_featured_def['class']; |
|
| 1630 | + |
|
| 1631 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1632 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1633 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1634 | + |
|
| 1635 | + $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1636 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1637 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1638 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1639 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1640 | + $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1641 | + $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1642 | + $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1643 | + |
|
| 1644 | + /** Build template */ |
|
| 1645 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1646 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1647 | + /* Include the old way template part */ |
|
| 1648 | + ob_start(); |
|
| 1649 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1650 | + $content = ob_get_contents(); |
|
| 1651 | + ob_end_clean(); |
|
| 1652 | + } else { |
|
| 1653 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1654 | + } |
|
| 1655 | + unset($tpl_component); |
|
| 1656 | + return $content; |
|
| 1657 | + } |
|
| 1658 | 1658 | |
| 1659 | - 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) |
|
| 1660 | - { |
|
| 1661 | - $content = ''; |
|
| 1662 | - $product_information = $product_class = ''; |
|
| 1659 | + 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) |
|
| 1660 | + { |
|
| 1661 | + $content = ''; |
|
| 1662 | + $product_information = $product_class = ''; |
|
| 1663 | 1663 | |
| 1664 | - /** Get the product thumbnail */ |
|
| 1665 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1666 | - if (has_post_thumbnail($product_id)) { |
|
| 1667 | - $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1668 | - } |
|
| 1664 | + /** Get the product thumbnail */ |
|
| 1665 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1666 | + if (has_post_thumbnail($product_id)) { |
|
| 1667 | + $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1668 | + } |
|
| 1669 | 1669 | |
| 1670 | - $product = self::get_product_data($product_id); |
|
| 1670 | + $product = self::get_product_data($product_id); |
|
| 1671 | 1671 | |
| 1672 | - /** Get the product information for output */ |
|
| 1673 | - if (!empty($product)) { |
|
| 1672 | + /** Get the product information for output */ |
|
| 1673 | + if (!empty($product)) { |
|
| 1674 | 1674 | |
| 1675 | - $product_title = $product['post_title']; |
|
| 1676 | - $product_name = $product['post_name']; |
|
| 1677 | - $product_link = get_permalink($product_id); |
|
| 1678 | - $product_more_informations = $product['product_content']; |
|
| 1679 | - $product_excerpt = $product['product_excerpt']; |
|
| 1675 | + $product_title = $product['post_title']; |
|
| 1676 | + $product_name = $product['post_name']; |
|
| 1677 | + $product_link = get_permalink($product_id); |
|
| 1678 | + $product_more_informations = $product['product_content']; |
|
| 1679 | + $product_excerpt = $product['product_excerpt']; |
|
| 1680 | 1680 | |
| 1681 | - if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1682 | - $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1683 | - $product_more_informations = $post_content[0]; |
|
| 1684 | - } |
|
| 1681 | + if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1682 | + $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1683 | + $product_more_informations = $post_content[0]; |
|
| 1684 | + } |
|
| 1685 | 1685 | |
| 1686 | - } else { |
|
| 1687 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1688 | - $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1689 | - $product_link = ''; |
|
| 1690 | - $product_more_informations = ''; |
|
| 1691 | - $product_excerpt = ''; |
|
| 1692 | - } |
|
| 1686 | + } else { |
|
| 1687 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1688 | + $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1689 | + $product_link = ''; |
|
| 1690 | + $product_more_informations = ''; |
|
| 1691 | + $product_excerpt = ''; |
|
| 1692 | + } |
|
| 1693 | 1693 | |
| 1694 | - /** Retrieve product price */ |
|
| 1695 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1696 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1697 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1698 | - $productPrice = ''; |
|
| 1699 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1700 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1701 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1702 | - 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)) { |
|
| 1703 | - $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1704 | - |
|
| 1705 | - if (!empty($product_price_infos)) { |
|
| 1706 | - $tpl_component_price = array(); |
|
| 1707 | - /** Price piloting **/ |
|
| 1694 | + /** Retrieve product price */ |
|
| 1695 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1696 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1697 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1698 | + $productPrice = ''; |
|
| 1699 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1700 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1701 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1702 | + 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)) { |
|
| 1703 | + $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1704 | + |
|
| 1705 | + if (!empty($product_price_infos)) { |
|
| 1706 | + $tpl_component_price = array(); |
|
| 1707 | + /** Price piloting **/ |
|
| 1708 | 1708 | $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
| 1709 | 1709 | $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
| 1710 | - $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1711 | - $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'])) : ''; |
|
| 1712 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1710 | + $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1711 | + $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'])) : ''; |
|
| 1712 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1713 | 1713 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1714 | 1714 | if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
| 1715 | 1715 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1716 | 1716 | } |
| 1717 | - $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1718 | - $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1719 | - $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1720 | - $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1721 | - } else { |
|
| 1722 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1723 | - } |
|
| 1724 | - } |
|
| 1717 | + $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1718 | + $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1719 | + $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1720 | + $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1721 | + } else { |
|
| 1722 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | 1725 | |
| 1726 | - /** Check if there is at less 1 product in stock */ |
|
| 1727 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1728 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1729 | - $productStock = $productStock === true ? 1 : null; |
|
| 1730 | - |
|
| 1731 | - /** Define "Add to cart" button */ |
|
| 1732 | - $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'); |
|
| 1733 | - $display_price_state_when_price_is_empty = false; |
|
| 1734 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1735 | - $display_price_state_when_price_is_empty = false; |
|
| 1736 | - } else if (!empty($productPrice)) { |
|
| 1737 | - $display_price_state_when_price_is_empty = true; |
|
| 1738 | - } |
|
| 1739 | - $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') : ''; |
|
| 1740 | - $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)) : ''; |
|
| 1726 | + /** Check if there is at less 1 product in stock */ |
|
| 1727 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1728 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1729 | + $productStock = $productStock === true ? 1 : null; |
|
| 1730 | + |
|
| 1731 | + /** Define "Add to cart" button */ |
|
| 1732 | + $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'); |
|
| 1733 | + $display_price_state_when_price_is_empty = false; |
|
| 1734 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1735 | + $display_price_state_when_price_is_empty = false; |
|
| 1736 | + } else if (!empty($productPrice)) { |
|
| 1737 | + $display_price_state_when_price_is_empty = true; |
|
| 1738 | + } |
|
| 1739 | + $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') : ''; |
|
| 1740 | + $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)) : ''; |
|
| 1741 | 1741 | |
| 1742 | - /** Define "Ask a quotation" button */ |
|
| 1743 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1744 | - $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'] : '')); |
|
| 1742 | + /** Define "Ask a quotation" button */ |
|
| 1743 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1744 | + $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'] : '')); |
|
| 1745 | 1745 | |
| 1746 | - $product_new = $product_new_def['output']; |
|
| 1747 | - $product_class .= $product_new_def['class']; |
|
| 1746 | + $product_new = $product_new_def['output']; |
|
| 1747 | + $product_class .= $product_new_def['class']; |
|
| 1748 | 1748 | |
| 1749 | - $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'] : '')); |
|
| 1750 | - $product_featured = $product_featured_def['output']; |
|
| 1751 | - $product_class .= $product_featured_def['class']; |
|
| 1749 | + $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'] : '')); |
|
| 1750 | + $product_featured = $product_featured_def['output']; |
|
| 1751 | + $product_class .= $product_featured_def['class']; |
|
| 1752 | 1752 | |
| 1753 | - if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1754 | - $product_class .= ' wpshop_last_product_of_line'; |
|
| 1755 | - } |
|
| 1753 | + if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1754 | + $product_class .= ' wpshop_last_product_of_line'; |
|
| 1755 | + } |
|
| 1756 | 1756 | |
| 1757 | - if (!empty($product['product_id'])) { |
|
| 1758 | - /** Template parameters */ |
|
| 1759 | - $template_part = 'product_mini_' . $output_type; |
|
| 1760 | - $tpl_component = array(); |
|
| 1761 | - $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1762 | - $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1763 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1764 | - $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1765 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1766 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1767 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1768 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1769 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1770 | - $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1771 | - $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1772 | - $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1773 | - $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1774 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1775 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1776 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1777 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1778 | - |
|
| 1779 | - if (has_post_thumbnail($product_id)) { |
|
| 1780 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1781 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1782 | - $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1783 | - foreach ($existing_image_sizes as $size_name) { |
|
| 1784 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1785 | - $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; |
|
| 1786 | - } |
|
| 1787 | - } |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1791 | - $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1792 | - $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1793 | - |
|
| 1794 | - /** Build template */ |
|
| 1795 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1796 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1797 | - /** Include the old way template part */ |
|
| 1798 | - ob_start(); |
|
| 1799 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1800 | - $content = ob_get_contents(); |
|
| 1801 | - ob_end_clean(); |
|
| 1802 | - } else { |
|
| 1803 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1804 | - } |
|
| 1805 | - unset($tpl_component); |
|
| 1757 | + if (!empty($product['product_id'])) { |
|
| 1758 | + /** Template parameters */ |
|
| 1759 | + $template_part = 'product_mini_' . $output_type; |
|
| 1760 | + $tpl_component = array(); |
|
| 1761 | + $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1762 | + $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1763 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1764 | + $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1765 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1766 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1767 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1768 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1769 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1770 | + $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1771 | + $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1772 | + $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1773 | + $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1774 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1775 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1776 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1777 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1778 | + |
|
| 1779 | + if (has_post_thumbnail($product_id)) { |
|
| 1780 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1781 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1782 | + $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1783 | + foreach ($existing_image_sizes as $size_name) { |
|
| 1784 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1785 | + $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; |
|
| 1786 | + } |
|
| 1787 | + } |
|
| 1788 | + } |
|
| 1806 | 1789 | |
| 1807 | - } |
|
| 1790 | + $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1791 | + $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1792 | + $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1793 | + |
|
| 1794 | + /** Build template */ |
|
| 1795 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1796 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1797 | + /** Include the old way template part */ |
|
| 1798 | + ob_start(); |
|
| 1799 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1800 | + $content = ob_get_contents(); |
|
| 1801 | + ob_end_clean(); |
|
| 1802 | + } else { |
|
| 1803 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1804 | + } |
|
| 1805 | + unset($tpl_component); |
|
| 1808 | 1806 | |
| 1809 | - return $content; |
|
| 1810 | - } |
|
| 1807 | + } |
|
| 1811 | 1808 | |
| 1812 | - /** |
|
| 1813 | - * Get the products (post) of a given category |
|
| 1814 | - * |
|
| 1815 | - * @param string $category_slug The category slug we want to get the product list for |
|
| 1816 | - * |
|
| 1817 | - * @return mixed $widget_content The output for the product list |
|
| 1818 | - */ |
|
| 1819 | - public static function get_product_of_category($category_slug, $category_id) |
|
| 1820 | - { |
|
| 1821 | - global $top_categories; |
|
| 1822 | - $widget_content = ''; |
|
| 1823 | - $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1824 | - if (false == $products) { |
|
| 1825 | - $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1826 | - $products = get_posts($args); |
|
| 1827 | - wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1828 | - } |
|
| 1829 | - if (is_array($products) && (count($products) > 0)) { |
|
| 1830 | - foreach ($products as $product) { |
|
| 1831 | - if ($product->post_status == "publish") { |
|
| 1832 | - ob_start(); |
|
| 1833 | - require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1834 | - $widget_content .= ob_get_contents(); |
|
| 1835 | - ob_end_clean(); |
|
| 1836 | - } |
|
| 1837 | - } |
|
| 1838 | - } |
|
| 1809 | + return $content; |
|
| 1810 | + } |
|
| 1839 | 1811 | |
| 1840 | - echo $widget_content; |
|
| 1841 | - } |
|
| 1812 | + /** |
|
| 1813 | + * Get the products (post) of a given category |
|
| 1814 | + * |
|
| 1815 | + * @param string $category_slug The category slug we want to get the product list for |
|
| 1816 | + * |
|
| 1817 | + * @return mixed $widget_content The output for the product list |
|
| 1818 | + */ |
|
| 1819 | + public static function get_product_of_category($category_slug, $category_id) |
|
| 1820 | + { |
|
| 1821 | + global $top_categories; |
|
| 1822 | + $widget_content = ''; |
|
| 1823 | + $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1824 | + if (false == $products) { |
|
| 1825 | + $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1826 | + $products = get_posts($args); |
|
| 1827 | + wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1828 | + } |
|
| 1829 | + if (is_array($products) && (count($products) > 0)) { |
|
| 1830 | + foreach ($products as $product) { |
|
| 1831 | + if ($product->post_status == "publish") { |
|
| 1832 | + ob_start(); |
|
| 1833 | + require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1834 | + $widget_content .= ob_get_contents(); |
|
| 1835 | + ob_end_clean(); |
|
| 1836 | + } |
|
| 1837 | + } |
|
| 1838 | + } |
|
| 1842 | 1839 | |
| 1843 | - /** |
|
| 1844 | - * |
|
| 1845 | - * @param unknown_type $selected_product |
|
| 1846 | - * @return string |
|
| 1847 | - */ |
|
| 1848 | - public function custom_product_list($selected_product = array()) |
|
| 1849 | - { |
|
| 1850 | - global $wpdb; |
|
| 1851 | - |
|
| 1852 | - /* Start the table definition */ |
|
| 1853 | - $tableId = 'wpshop_product_list'; |
|
| 1854 | - $tableTitles = array(); |
|
| 1855 | - $tableTitles[] = ''; |
|
| 1856 | - $tableTitles[] = __('Id', 'wpshop'); |
|
| 1857 | - $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1858 | - $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1859 | - $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1860 | - $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1861 | - $tableTitles[] = __('Price', 'wpshop'); |
|
| 1862 | - $tableClasses = array(); |
|
| 1863 | - $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1864 | - $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1865 | - $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1866 | - $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1867 | - $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1868 | - $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1869 | - $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1870 | - |
|
| 1871 | - /* Get post list */ |
|
| 1872 | - $has_result = false; |
|
| 1873 | - $current_line_index = 0; |
|
| 1874 | - $posts = query_posts(array( |
|
| 1875 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1876 | - )); |
|
| 1877 | - if (!empty($posts)) { |
|
| 1878 | - $has_result = true; |
|
| 1879 | - foreach ($posts as $post) { |
|
| 1880 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1881 | - |
|
| 1882 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1883 | - |
|
| 1884 | - unset($tableRowValue); |
|
| 1885 | - $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 . '" />'); |
|
| 1886 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1887 | - $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>'); |
|
| 1888 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1889 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1890 | - $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/> |
|
| 1840 | + echo $widget_content; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + /** |
|
| 1844 | + * |
|
| 1845 | + * @param unknown_type $selected_product |
|
| 1846 | + * @return string |
|
| 1847 | + */ |
|
| 1848 | + public function custom_product_list($selected_product = array()) |
|
| 1849 | + { |
|
| 1850 | + global $wpdb; |
|
| 1851 | + |
|
| 1852 | + /* Start the table definition */ |
|
| 1853 | + $tableId = 'wpshop_product_list'; |
|
| 1854 | + $tableTitles = array(); |
|
| 1855 | + $tableTitles[] = ''; |
|
| 1856 | + $tableTitles[] = __('Id', 'wpshop'); |
|
| 1857 | + $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1858 | + $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1859 | + $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1860 | + $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1861 | + $tableTitles[] = __('Price', 'wpshop'); |
|
| 1862 | + $tableClasses = array(); |
|
| 1863 | + $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1864 | + $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1865 | + $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1866 | + $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1867 | + $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1868 | + $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1869 | + $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1870 | + |
|
| 1871 | + /* Get post list */ |
|
| 1872 | + $has_result = false; |
|
| 1873 | + $current_line_index = 0; |
|
| 1874 | + $posts = query_posts(array( |
|
| 1875 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1876 | + )); |
|
| 1877 | + if (!empty($posts)) { |
|
| 1878 | + $has_result = true; |
|
| 1879 | + foreach ($posts as $post) { |
|
| 1880 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1881 | + |
|
| 1882 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1883 | + |
|
| 1884 | + unset($tableRowValue); |
|
| 1885 | + $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 . '" />'); |
|
| 1886 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1887 | + $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>'); |
|
| 1888 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1889 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1890 | + $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/> |
|
| 1891 | 1891 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1892 | - $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() : '')); |
|
| 1893 | - $tableRows[] = $tableRowValue; |
|
| 1892 | + $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() : '')); |
|
| 1893 | + $tableRows[] = $tableRowValue; |
|
| 1894 | 1894 | |
| 1895 | - $current_line_index++; |
|
| 1896 | - } |
|
| 1897 | - wp_reset_query(); |
|
| 1898 | - } |
|
| 1899 | - $posts = query_posts(array( |
|
| 1900 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1901 | - )); |
|
| 1902 | - if (!empty($posts)) { |
|
| 1903 | - $has_result = true; |
|
| 1904 | - foreach ($posts as $post) { |
|
| 1905 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1906 | - |
|
| 1907 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1908 | - |
|
| 1909 | - unset($tableRowValue); |
|
| 1910 | - $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 . '" />'); |
|
| 1911 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1912 | - $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>'); |
|
| 1913 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1914 | - $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1915 | - if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1916 | - $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1917 | - $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1918 | - $option_name = $wpdb->get_var($query); |
|
| 1919 | - $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1920 | - $option_value = $wpdb->get_var($query); |
|
| 1921 | - $parent_post = $parent_product['parent_post']; |
|
| 1922 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1923 | - } else { |
|
| 1924 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - $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/> |
|
| 1895 | + $current_line_index++; |
|
| 1896 | + } |
|
| 1897 | + wp_reset_query(); |
|
| 1898 | + } |
|
| 1899 | + $posts = query_posts(array( |
|
| 1900 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1901 | + )); |
|
| 1902 | + if (!empty($posts)) { |
|
| 1903 | + $has_result = true; |
|
| 1904 | + foreach ($posts as $post) { |
|
| 1905 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1906 | + |
|
| 1907 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1908 | + |
|
| 1909 | + unset($tableRowValue); |
|
| 1910 | + $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 . '" />'); |
|
| 1911 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1912 | + $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>'); |
|
| 1913 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1914 | + $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1915 | + if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1916 | + $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1917 | + $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1918 | + $option_name = $wpdb->get_var($query); |
|
| 1919 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1920 | + $option_value = $wpdb->get_var($query); |
|
| 1921 | + $parent_post = $parent_product['parent_post']; |
|
| 1922 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1923 | + } else { |
|
| 1924 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + $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 | 1928 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1929 | - $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() : '')); |
|
| 1930 | - $tableRows[] = $tableRowValue; |
|
| 1929 | + $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() : '')); |
|
| 1930 | + $tableRows[] = $tableRowValue; |
|
| 1931 | 1931 | |
| 1932 | - $current_line_index++; |
|
| 1933 | - } |
|
| 1934 | - wp_reset_query(); |
|
| 1935 | - } |
|
| 1932 | + $current_line_index++; |
|
| 1933 | + } |
|
| 1934 | + wp_reset_query(); |
|
| 1935 | + } |
|
| 1936 | 1936 | |
| 1937 | - if (!$has_result) { |
|
| 1938 | - $tableRowsId[] = 'no_product_found'; |
|
| 1939 | - unset($tableRowValue); |
|
| 1940 | - $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1941 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1942 | - $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1943 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1944 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1945 | - $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1946 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1947 | - $tableRows[] = $tableRowValue; |
|
| 1948 | - } |
|
| 1937 | + if (!$has_result) { |
|
| 1938 | + $tableRowsId[] = 'no_product_found'; |
|
| 1939 | + unset($tableRowValue); |
|
| 1940 | + $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1941 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1942 | + $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1943 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1944 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1945 | + $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1946 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1947 | + $tableRows[] = $tableRowValue; |
|
| 1948 | + } |
|
| 1949 | 1949 | |
| 1950 | - return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1950 | + return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1951 | 1951 | <script type="text/javascript" > |
| 1952 | 1952 | wpshop(document).ready(function(){ |
| 1953 | 1953 | jQuery("#' . $tableId . '").dataTable( { |
@@ -1956,1533 +1956,1533 @@ discard block |
||
| 1956 | 1956 | }); |
| 1957 | 1957 | }); |
| 1958 | 1958 | </script>'; |
| 1959 | - } |
|
| 1959 | + } |
|
| 1960 | 1960 | |
| 1961 | - /** |
|
| 1962 | - * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1963 | - * |
|
| 1964 | - * @param string $special The type of special type we want to output |
|
| 1965 | - * @param string $output_type The current display type (used for product listing) |
|
| 1966 | - * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 1967 | - * @param datetime $special_state_start The start date if applicable for the special state |
|
| 1968 | - * @param datetime $special_state_end The end date if applicable for the special state |
|
| 1969 | - * |
|
| 1970 | - * @return array $product_special_state The product special state |
|
| 1971 | - */ |
|
| 1972 | - public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 1973 | - { |
|
| 1974 | - $product_special_state = array(); |
|
| 1975 | - $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 1976 | - |
|
| 1977 | - /** Get product special state definition */ |
|
| 1978 | - $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 1979 | - $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 1980 | - $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 1981 | - |
|
| 1982 | - /** Get current time */ |
|
| 1983 | - $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 1984 | - |
|
| 1985 | - /** PRODUCT MARK AS NEW */ |
|
| 1986 | - $show_product_special_state = false; |
|
| 1987 | - if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 1988 | - (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 1989 | - (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 1990 | - $show_product_special_state = true; |
|
| 1991 | - } |
|
| 1961 | + /** |
|
| 1962 | + * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1963 | + * |
|
| 1964 | + * @param string $special The type of special type we want to output |
|
| 1965 | + * @param string $output_type The current display type (used for product listing) |
|
| 1966 | + * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 1967 | + * @param datetime $special_state_start The start date if applicable for the special state |
|
| 1968 | + * @param datetime $special_state_end The end date if applicable for the special state |
|
| 1969 | + * |
|
| 1970 | + * @return array $product_special_state The product special state |
|
| 1971 | + */ |
|
| 1972 | + public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 1973 | + { |
|
| 1974 | + $product_special_state = array(); |
|
| 1975 | + $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 1976 | + |
|
| 1977 | + /** Get product special state definition */ |
|
| 1978 | + $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 1979 | + $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 1980 | + $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 1981 | + |
|
| 1982 | + /** Get current time */ |
|
| 1983 | + $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 1984 | + |
|
| 1985 | + /** PRODUCT MARK AS NEW */ |
|
| 1986 | + $show_product_special_state = false; |
|
| 1987 | + if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 1988 | + (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 1989 | + (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 1990 | + $show_product_special_state = true; |
|
| 1991 | + } |
|
| 1992 | 1992 | |
| 1993 | - if ($show_product_special_state) { |
|
| 1994 | - /** Check the type of special output needed */ |
|
| 1995 | - switch ($special) { |
|
| 1996 | - case 'declare_new': |
|
| 1997 | - $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 1998 | - $template_part = 'product_is_new_sticker'; |
|
| 1999 | - break; |
|
| 2000 | - |
|
| 2001 | - case 'highlight_product': |
|
| 2002 | - $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 2003 | - $template_part = 'product_is_featured_sticker'; |
|
| 2004 | - break; |
|
| 2005 | - } |
|
| 2006 | - |
|
| 2007 | - /** Template parameters */ |
|
| 2008 | - $tpl_component = array(); |
|
| 2009 | - |
|
| 2010 | - /** Build template */ |
|
| 2011 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2012 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2013 | - /** Include the old way template part */ |
|
| 2014 | - ob_start(); |
|
| 2015 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2016 | - $product_special_state['output'] = ob_get_contents(); |
|
| 2017 | - ob_end_clean(); |
|
| 2018 | - } else { |
|
| 2019 | - $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2020 | - } |
|
| 2021 | - unset($tpl_component); |
|
| 2022 | - } |
|
| 1993 | + if ($show_product_special_state) { |
|
| 1994 | + /** Check the type of special output needed */ |
|
| 1995 | + switch ($special) { |
|
| 1996 | + case 'declare_new': |
|
| 1997 | + $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 1998 | + $template_part = 'product_is_new_sticker'; |
|
| 1999 | + break; |
|
| 2023 | 2000 | |
| 2024 | - return $product_special_state; |
|
| 2025 | - } |
|
| 2001 | + case 'highlight_product': |
|
| 2002 | + $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 2003 | + $template_part = 'product_is_featured_sticker'; |
|
| 2004 | + break; |
|
| 2005 | + } |
|
| 2026 | 2006 | |
| 2027 | - /** |
|
| 2028 | - * Prepare product price for saving and easier read later |
|
| 2029 | - * |
|
| 2030 | - * @param integer $element_id Identifier of current product |
|
| 2031 | - */ |
|
| 2032 | - public static function calculate_price($element_id) |
|
| 2033 | - { |
|
| 2034 | - global $wpdb; |
|
| 2035 | - |
|
| 2036 | - /** |
|
| 2037 | - * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2038 | - * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2039 | - * price_ht and tva |
|
| 2040 | - */ |
|
| 2041 | - $query = $wpdb->prepare( |
|
| 2042 | - "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2007 | + /** Template parameters */ |
|
| 2008 | + $tpl_component = array(); |
|
| 2009 | + |
|
| 2010 | + /** Build template */ |
|
| 2011 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2012 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2013 | + /** Include the old way template part */ |
|
| 2014 | + ob_start(); |
|
| 2015 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2016 | + $product_special_state['output'] = ob_get_contents(); |
|
| 2017 | + ob_end_clean(); |
|
| 2018 | + } else { |
|
| 2019 | + $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2020 | + } |
|
| 2021 | + unset($tpl_component); |
|
| 2022 | + } |
|
| 2023 | + |
|
| 2024 | + return $product_special_state; |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + /** |
|
| 2028 | + * Prepare product price for saving and easier read later |
|
| 2029 | + * |
|
| 2030 | + * @param integer $element_id Identifier of current product |
|
| 2031 | + */ |
|
| 2032 | + public static function calculate_price($element_id) |
|
| 2033 | + { |
|
| 2034 | + global $wpdb; |
|
| 2035 | + |
|
| 2036 | + /** |
|
| 2037 | + * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2038 | + * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2039 | + * price_ht and tva |
|
| 2040 | + */ |
|
| 2041 | + $query = $wpdb->prepare( |
|
| 2042 | + "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2043 | 2043 | FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR |
| 2044 | 2044 | RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d)) |
| 2045 | 2045 | WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')", |
| 2046 | - $element_id |
|
| 2047 | - ); |
|
| 2048 | - $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2049 | - |
|
| 2050 | - /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2051 | - if (empty($prices_attribute)) { |
|
| 2052 | - return false; |
|
| 2053 | - } else { |
|
| 2054 | - /** |
|
| 2055 | - * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2056 | - * the base amount according on the shop price control |
|
| 2057 | - */ |
|
| 2058 | - $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2059 | - $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2060 | - $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2064 | - * create an attribute |
|
| 2065 | - */ |
|
| 2066 | - $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2067 | - $language = WPSHOP_CURRENT_LOCALE; |
|
| 2068 | - $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2069 | - |
|
| 2070 | - if (!empty($icl_post_language)) { |
|
| 2071 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2072 | - $language = $wpdb->get_var($query); |
|
| 2073 | - } |
|
| 2074 | - |
|
| 2075 | - /** |
|
| 2076 | - * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2077 | - * Check configuration to know how to make the calcul for the product |
|
| 2078 | - */ |
|
| 2079 | - if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2080 | - $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2081 | - $price_no_vat = $base_price; |
|
| 2082 | - } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2083 | - $price_with_vat = $base_price; |
|
| 2084 | - $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - /** |
|
| 2088 | - * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2089 | - * type que celui-ci / The last parameter allows not to delete the |
|
| 2090 | - * attributes of the same type as this one |
|
| 2091 | - */ |
|
| 2092 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2093 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2094 | - |
|
| 2095 | - /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2096 | - $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2097 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2098 | - |
|
| 2099 | - /** Update the product meta information with the calculated prices */ |
|
| 2100 | - $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2101 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2102 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2103 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2104 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2105 | - |
|
| 2106 | - update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2046 | + $element_id |
|
| 2047 | + ); |
|
| 2048 | + $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2049 | + |
|
| 2050 | + /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2051 | + if (empty($prices_attribute)) { |
|
| 2052 | + return false; |
|
| 2053 | + } else { |
|
| 2054 | + /** |
|
| 2055 | + * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2056 | + * the base amount according on the shop price control |
|
| 2057 | + */ |
|
| 2058 | + $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2059 | + $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2060 | + $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2064 | + * create an attribute |
|
| 2065 | + */ |
|
| 2066 | + $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2067 | + $language = WPSHOP_CURRENT_LOCALE; |
|
| 2068 | + $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2069 | + |
|
| 2070 | + if (!empty($icl_post_language)) { |
|
| 2071 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2072 | + $language = $wpdb->get_var($query); |
|
| 2073 | + } |
|
| 2107 | 2074 | |
| 2108 | - /** Met à jour la meta _wps_price_infos */ |
|
| 2109 | - $p = wpshop_products::get_product_data($element_id); |
|
| 2110 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2111 | - update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2075 | + /** |
|
| 2076 | + * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2077 | + * Check configuration to know how to make the calcul for the product |
|
| 2078 | + */ |
|
| 2079 | + if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2080 | + $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2081 | + $price_no_vat = $base_price; |
|
| 2082 | + } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2083 | + $price_with_vat = $base_price; |
|
| 2084 | + $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2085 | + } |
|
| 2112 | 2086 | |
| 2113 | - /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2114 | - wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2115 | - } |
|
| 2087 | + /** |
|
| 2088 | + * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2089 | + * type que celui-ci / The last parameter allows not to delete the |
|
| 2090 | + * attributes of the same type as this one |
|
| 2091 | + */ |
|
| 2092 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2093 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2094 | + |
|
| 2095 | + /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2096 | + $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2097 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2098 | + |
|
| 2099 | + /** Update the product meta information with the calculated prices */ |
|
| 2100 | + $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2101 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2102 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2103 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2104 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2105 | + |
|
| 2106 | + update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2107 | + |
|
| 2108 | + /** Met à jour la meta _wps_price_infos */ |
|
| 2109 | + $p = wpshop_products::get_product_data($element_id); |
|
| 2110 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2111 | + update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2112 | + |
|
| 2113 | + /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2114 | + wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2115 | + } |
|
| 2116 | 2116 | |
| 2117 | - return true; |
|
| 2118 | - } |
|
| 2117 | + return true; |
|
| 2118 | + } |
|
| 2119 | 2119 | |
| 2120 | - /** |
|
| 2121 | - * Allows to get the good button for adding product to cart |
|
| 2122 | - * |
|
| 2123 | - * @param integer $product_id The product identifier |
|
| 2124 | - * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2125 | - * |
|
| 2126 | - * @return string $button The html output for the button |
|
| 2127 | - */ |
|
| 2128 | - public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2129 | - { |
|
| 2130 | - $button = ''; |
|
| 2120 | + /** |
|
| 2121 | + * Allows to get the good button for adding product to cart |
|
| 2122 | + * |
|
| 2123 | + * @param integer $product_id The product identifier |
|
| 2124 | + * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2125 | + * |
|
| 2126 | + * @return string $button The html output for the button |
|
| 2127 | + */ |
|
| 2128 | + public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2129 | + { |
|
| 2130 | + $button = ''; |
|
| 2131 | 2131 | // $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true ); |
| 2132 | 2132 | |
| 2133 | - 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') ) */) { |
|
| 2134 | - /* |
|
| 2133 | + 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') ) */) { |
|
| 2134 | + /* |
|
| 2135 | 2135 | * Check if current product has variation for button display |
| 2136 | 2136 | */ |
| 2137 | - $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2138 | - $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2137 | + $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2138 | + $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2139 | 2139 | |
| 2140 | - /* |
|
| 2140 | + /* |
|
| 2141 | 2141 | * Template parameters |
| 2142 | 2142 | */ |
| 2143 | 2143 | |
| 2144 | - if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2145 | - /** Check variation stock **/ |
|
| 2146 | - $variations = self::get_variation($product_id); |
|
| 2147 | - if (!empty($variations)) { |
|
| 2148 | - foreach ($variations as $variation) { |
|
| 2149 | - if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2150 | - $productStock += $variation['variation_dif']['product_stock']; |
|
| 2151 | - } |
|
| 2152 | - } |
|
| 2153 | - } |
|
| 2154 | - } |
|
| 2155 | - |
|
| 2156 | - $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2144 | + if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2145 | + /** Check variation stock **/ |
|
| 2146 | + $variations = self::get_variation($product_id); |
|
| 2147 | + if (!empty($variations)) { |
|
| 2148 | + foreach ($variations as $variation) { |
|
| 2149 | + if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2150 | + $productStock += $variation['variation_dif']['product_stock']; |
|
| 2151 | + } |
|
| 2152 | + } |
|
| 2153 | + } |
|
| 2154 | + } |
|
| 2155 | + |
|
| 2156 | + $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2157 | 2157 | $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
| 2158 | 2158 | |
| 2159 | - $tpl_component = array(); |
|
| 2160 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2161 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2162 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2159 | + $tpl_component = array(); |
|
| 2160 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2161 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2162 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2163 | 2163 | |
| 2164 | - /* |
|
| 2164 | + /* |
|
| 2165 | 2165 | * Build template |
| 2166 | 2166 | */ |
| 2167 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2168 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2169 | - /* Include the old way template part */ |
|
| 2170 | - ob_start(); |
|
| 2171 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2172 | - $button = ob_get_contents(); |
|
| 2173 | - ob_end_clean(); |
|
| 2174 | - } else { |
|
| 2175 | - $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)); |
|
| 2176 | - } |
|
| 2177 | - unset($tpl_component); |
|
| 2178 | - } |
|
| 2179 | - return $button; |
|
| 2180 | - } |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * Allows to get the good button for adding product to a quotation |
|
| 2184 | - * |
|
| 2185 | - * @param integer $product_id The product identifier |
|
| 2186 | - * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2187 | - * |
|
| 2188 | - * @return string $button The html output for the button |
|
| 2189 | - */ |
|
| 2190 | - public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2191 | - { |
|
| 2192 | - $quotation_button = ''; |
|
| 2193 | - |
|
| 2194 | - 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'))) { |
|
| 2195 | - $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(); |
|
| 2196 | - /** |
|
| 2197 | - * Template parameters |
|
| 2198 | - */ |
|
| 2199 | - $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2200 | - $tpl_component = array(); |
|
| 2201 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2202 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2203 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2167 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2168 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2169 | + /* Include the old way template part */ |
|
| 2170 | + ob_start(); |
|
| 2171 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2172 | + $button = ob_get_contents(); |
|
| 2173 | + ob_end_clean(); |
|
| 2174 | + } else { |
|
| 2175 | + $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)); |
|
| 2176 | + } |
|
| 2177 | + unset($tpl_component); |
|
| 2178 | + } |
|
| 2179 | + return $button; |
|
| 2180 | + } |
|
| 2204 | 2181 | |
| 2205 | - /** |
|
| 2206 | - * Build template |
|
| 2207 | - */ |
|
| 2208 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2209 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2210 | - /* Include the old way template part */ |
|
| 2211 | - ob_start(); |
|
| 2212 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2213 | - $quotation_button = ob_get_contents(); |
|
| 2214 | - ob_end_clean(); |
|
| 2215 | - } else { |
|
| 2216 | - $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2217 | - } |
|
| 2218 | - unset($tpl_component); |
|
| 2219 | - } |
|
| 2182 | + /** |
|
| 2183 | + * Allows to get the good button for adding product to a quotation |
|
| 2184 | + * |
|
| 2185 | + * @param integer $product_id The product identifier |
|
| 2186 | + * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2187 | + * |
|
| 2188 | + * @return string $button The html output for the button |
|
| 2189 | + */ |
|
| 2190 | + public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2191 | + { |
|
| 2192 | + $quotation_button = ''; |
|
| 2193 | + |
|
| 2194 | + 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'))) { |
|
| 2195 | + $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(); |
|
| 2196 | + /** |
|
| 2197 | + * Template parameters |
|
| 2198 | + */ |
|
| 2199 | + $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2200 | + $tpl_component = array(); |
|
| 2201 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2202 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2203 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2204 | + |
|
| 2205 | + /** |
|
| 2206 | + * Build template |
|
| 2207 | + */ |
|
| 2208 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2209 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2210 | + /* Include the old way template part */ |
|
| 2211 | + ob_start(); |
|
| 2212 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2213 | + $quotation_button = ob_get_contents(); |
|
| 2214 | + ob_end_clean(); |
|
| 2215 | + } else { |
|
| 2216 | + $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2217 | + } |
|
| 2218 | + unset($tpl_component); |
|
| 2219 | + } |
|
| 2220 | 2220 | |
| 2221 | - return $quotation_button; |
|
| 2222 | - } |
|
| 2221 | + return $quotation_button; |
|
| 2222 | + } |
|
| 2223 | 2223 | |
| 2224 | - /** |
|
| 2225 | - * Return the output for a product attachement gallery (picture or document) |
|
| 2226 | - * |
|
| 2227 | - * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2228 | - * @param string $content The gallery content build previously |
|
| 2229 | - * |
|
| 2230 | - * @return string The attachement gallery output |
|
| 2231 | - */ |
|
| 2232 | - public static function display_attachment_gallery($attachement_type, $content) |
|
| 2233 | - { |
|
| 2234 | - $galery_output = ''; |
|
| 2235 | - |
|
| 2236 | - /* |
|
| 2224 | + /** |
|
| 2225 | + * Return the output for a product attachement gallery (picture or document) |
|
| 2226 | + * |
|
| 2227 | + * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2228 | + * @param string $content The gallery content build previously |
|
| 2229 | + * |
|
| 2230 | + * @return string The attachement gallery output |
|
| 2231 | + */ |
|
| 2232 | + public static function display_attachment_gallery($attachement_type, $content) |
|
| 2233 | + { |
|
| 2234 | + $galery_output = ''; |
|
| 2235 | + |
|
| 2236 | + /* |
|
| 2237 | 2237 | * Get the template part for given galery type |
| 2238 | 2238 | */ |
| 2239 | - switch ($attachement_type) { |
|
| 2240 | - case 'picture': |
|
| 2241 | - $template_part = 'product_attachment_picture_galery'; |
|
| 2242 | - break; |
|
| 2243 | - case 'document': |
|
| 2244 | - $template_part = 'product_attachment_galery'; |
|
| 2245 | - break; |
|
| 2246 | - } |
|
| 2239 | + switch ($attachement_type) { |
|
| 2240 | + case 'picture': |
|
| 2241 | + $template_part = 'product_attachment_picture_galery'; |
|
| 2242 | + break; |
|
| 2243 | + case 'document': |
|
| 2244 | + $template_part = 'product_attachment_galery'; |
|
| 2245 | + break; |
|
| 2246 | + } |
|
| 2247 | 2247 | |
| 2248 | - /* |
|
| 2248 | + /* |
|
| 2249 | 2249 | * Template parameters |
| 2250 | 2250 | */ |
| 2251 | - $tpl_component = array(); |
|
| 2252 | - $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2253 | - $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2251 | + $tpl_component = array(); |
|
| 2252 | + $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2253 | + $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2254 | 2254 | |
| 2255 | - /* |
|
| 2255 | + /* |
|
| 2256 | 2256 | * Build template |
| 2257 | 2257 | */ |
| 2258 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2259 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2260 | - /* Include the old way template part */ |
|
| 2261 | - ob_start(); |
|
| 2262 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2263 | - $galery_output = ob_get_contents(); |
|
| 2264 | - ob_end_clean(); |
|
| 2265 | - } else { |
|
| 2266 | - $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2267 | - } |
|
| 2268 | - unset($tpl_component); |
|
| 2258 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2259 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2260 | + /* Include the old way template part */ |
|
| 2261 | + ob_start(); |
|
| 2262 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2263 | + $galery_output = ob_get_contents(); |
|
| 2264 | + ob_end_clean(); |
|
| 2265 | + } else { |
|
| 2266 | + $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2267 | + } |
|
| 2268 | + unset($tpl_component); |
|
| 2269 | 2269 | |
| 2270 | - return $galery_output; |
|
| 2271 | - } |
|
| 2270 | + return $galery_output; |
|
| 2271 | + } |
|
| 2272 | 2272 | |
| 2273 | - /** |
|
| 2274 | - * Define the metabox to display in product edition page in backend |
|
| 2275 | - * @param object $post The current element displayed for edition |
|
| 2276 | - */ |
|
| 2277 | - public static function meta_box_variations($post) |
|
| 2278 | - { |
|
| 2279 | - $output = ''; |
|
| 2280 | - /* Variations container */ |
|
| 2281 | - $tpl_component = array(); |
|
| 2282 | - $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2283 | - $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2284 | - $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2285 | - echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2286 | - } |
|
| 2273 | + /** |
|
| 2274 | + * Define the metabox to display in product edition page in backend |
|
| 2275 | + * @param object $post The current element displayed for edition |
|
| 2276 | + */ |
|
| 2277 | + public static function meta_box_variations($post) |
|
| 2278 | + { |
|
| 2279 | + $output = ''; |
|
| 2280 | + /* Variations container */ |
|
| 2281 | + $tpl_component = array(); |
|
| 2282 | + $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2283 | + $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2284 | + $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2285 | + echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2286 | + } |
|
| 2287 | 2287 | |
| 2288 | - /** |
|
| 2289 | - * Call variation creation function with a list of defined variation |
|
| 2290 | - * |
|
| 2291 | - * @param array $possible_variations A list of variation to create for the current element |
|
| 2292 | - * @param integer $element_id The product we want to create variation for |
|
| 2293 | - * |
|
| 2294 | - * @return mixed The last created variation identifier |
|
| 2295 | - */ |
|
| 2296 | - public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2297 | - { |
|
| 2298 | - /** Get existing variation */ |
|
| 2299 | - $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2300 | - $existing_variations = array(); |
|
| 2301 | - if (!empty($existing_variations_in_db)) { |
|
| 2302 | - foreach ($existing_variations_in_db as $variations_def) { |
|
| 2303 | - $existing_variations[] = $variations_def['variation_def']; |
|
| 2304 | - } |
|
| 2305 | - } |
|
| 2306 | - /** New variation definition */ |
|
| 2307 | - $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2308 | - |
|
| 2309 | - /** Read possible values */ |
|
| 2310 | - foreach ($possible_variations as $variation_definition) { |
|
| 2311 | - if (in_array($variation_definition, $existing_variations)) { |
|
| 2312 | - continue; |
|
| 2313 | - } |
|
| 2314 | - |
|
| 2315 | - $attribute_to_set = array(); |
|
| 2316 | - foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2317 | - $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2318 | - $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2319 | - if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2320 | - $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2321 | - } |
|
| 2322 | - } |
|
| 2323 | - $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2324 | - } |
|
| 2325 | - update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2288 | + /** |
|
| 2289 | + * Call variation creation function with a list of defined variation |
|
| 2290 | + * |
|
| 2291 | + * @param array $possible_variations A list of variation to create for the current element |
|
| 2292 | + * @param integer $element_id The product we want to create variation for |
|
| 2293 | + * |
|
| 2294 | + * @return mixed The last created variation identifier |
|
| 2295 | + */ |
|
| 2296 | + public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2297 | + { |
|
| 2298 | + /** Get existing variation */ |
|
| 2299 | + $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2300 | + $existing_variations = array(); |
|
| 2301 | + if (!empty($existing_variations_in_db)) { |
|
| 2302 | + foreach ($existing_variations_in_db as $variations_def) { |
|
| 2303 | + $existing_variations[] = $variations_def['variation_def']; |
|
| 2304 | + } |
|
| 2305 | + } |
|
| 2306 | + /** New variation definition */ |
|
| 2307 | + $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2326 | 2308 | |
| 2327 | - return !empty($variation_id) ? $variation_id : 0; |
|
| 2328 | - } |
|
| 2309 | + /** Read possible values */ |
|
| 2310 | + foreach ($possible_variations as $variation_definition) { |
|
| 2311 | + if (in_array($variation_definition, $existing_variations)) { |
|
| 2312 | + continue; |
|
| 2313 | + } |
|
| 2329 | 2314 | |
| 2330 | - /** |
|
| 2331 | - * Create a new variation for product |
|
| 2332 | - * |
|
| 2333 | - * @param integer $head_product The product identifier to create the new variation for |
|
| 2334 | - * @param array $variation_attributes Attribute list for the variation |
|
| 2335 | - * |
|
| 2336 | - * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2337 | - */ |
|
| 2338 | - public static function create_variation($head_product, $variation_attributes) |
|
| 2339 | - { |
|
| 2340 | - /** Create custom title */ |
|
| 2341 | - $title_variation = ""; |
|
| 2342 | - if (!empty($variation_attributes)) { |
|
| 2343 | - foreach ($variation_attributes as $type => $array) { |
|
| 2344 | - if (!empty($array)) { |
|
| 2345 | - foreach ($array as $code => $value) { |
|
| 2346 | - $title_variation .= " " . $code . " " . $value; |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2315 | + $attribute_to_set = array(); |
|
| 2316 | + foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2317 | + $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2318 | + $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2319 | + if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2320 | + $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2321 | + } |
|
| 2322 | + } |
|
| 2323 | + $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2324 | + } |
|
| 2325 | + update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2351 | 2326 | |
| 2352 | - $variation = array( |
|
| 2353 | - 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2354 | - 'post_content' => '', |
|
| 2355 | - 'post_status' => 'publish', |
|
| 2356 | - 'post_author' => get_current_user_id(), |
|
| 2357 | - 'post_parent' => $head_product, |
|
| 2358 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2359 | - ); |
|
| 2360 | - $variation_id = wp_insert_post($variation); |
|
| 2361 | - |
|
| 2362 | - wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2363 | - |
|
| 2364 | - /* Update product price looking for shop parameters */ |
|
| 2365 | - wpshop_products::calculate_price($variation_id); |
|
| 2366 | - |
|
| 2367 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2368 | - $productMetaDatas = array(); |
|
| 2369 | - foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2370 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2371 | - if (!empty($attributeValue)) { |
|
| 2372 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2373 | - } |
|
| 2374 | - } |
|
| 2375 | - } |
|
| 2376 | - update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2377 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2378 | - 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)); |
|
| 2327 | + return !empty($variation_id) ? $variation_id : 0; |
|
| 2328 | + } |
|
| 2379 | 2329 | |
| 2380 | - return $variation_id; |
|
| 2381 | - } |
|
| 2330 | + /** |
|
| 2331 | + * Create a new variation for product |
|
| 2332 | + * |
|
| 2333 | + * @param integer $head_product The product identifier to create the new variation for |
|
| 2334 | + * @param array $variation_attributes Attribute list for the variation |
|
| 2335 | + * |
|
| 2336 | + * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2337 | + */ |
|
| 2338 | + public static function create_variation($head_product, $variation_attributes) |
|
| 2339 | + { |
|
| 2340 | + /** Create custom title */ |
|
| 2341 | + $title_variation = ""; |
|
| 2342 | + if (!empty($variation_attributes)) { |
|
| 2343 | + foreach ($variation_attributes as $type => $array) { |
|
| 2344 | + if (!empty($array)) { |
|
| 2345 | + foreach ($array as $code => $value) { |
|
| 2346 | + $title_variation .= " " . $code . " " . $value; |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2382 | 2351 | |
| 2383 | - /** |
|
| 2384 | - * Get variation list for a given product |
|
| 2385 | - * |
|
| 2386 | - * @param integer $head_product The product identifier to get the variation for |
|
| 2387 | - * @return object The variation list |
|
| 2388 | - */ |
|
| 2389 | - public static function get_variation($head_product) |
|
| 2390 | - { |
|
| 2391 | - global $wpdb; |
|
| 2392 | - $variations_output = null; |
|
| 2393 | - $args = array( |
|
| 2394 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2395 | - 'post_parent' => $head_product, |
|
| 2396 | - 'orderby' => 'ID', |
|
| 2397 | - 'order' => 'ASC', |
|
| 2398 | - 'posts_per_page' => -1, |
|
| 2399 | - 'post_status' => 'any', |
|
| 2400 | - ); |
|
| 2401 | - $variations = get_posts($args); |
|
| 2402 | - |
|
| 2403 | - if (!empty($variations)) { |
|
| 2404 | - $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2405 | - |
|
| 2406 | - foreach ($variations as $post_def) { |
|
| 2407 | - $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'"); |
|
| 2408 | - foreach ($data as $content) { |
|
| 2409 | - $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2410 | - if (!empty($content->$attribute_value)) { |
|
| 2411 | - if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2412 | - $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2413 | - } else { |
|
| 2414 | - $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2415 | - } |
|
| 2416 | - } |
|
| 2417 | - } |
|
| 2418 | - $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2419 | - } |
|
| 2420 | - } |
|
| 2421 | - wp_reset_query(); |
|
| 2422 | - return $variations_output; |
|
| 2423 | - } |
|
| 2352 | + $variation = array( |
|
| 2353 | + 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2354 | + 'post_content' => '', |
|
| 2355 | + 'post_status' => 'publish', |
|
| 2356 | + 'post_author' => get_current_user_id(), |
|
| 2357 | + 'post_parent' => $head_product, |
|
| 2358 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2359 | + ); |
|
| 2360 | + $variation_id = wp_insert_post($variation); |
|
| 2361 | + |
|
| 2362 | + wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2363 | + |
|
| 2364 | + /* Update product price looking for shop parameters */ |
|
| 2365 | + wpshop_products::calculate_price($variation_id); |
|
| 2366 | + |
|
| 2367 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2368 | + $productMetaDatas = array(); |
|
| 2369 | + foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2370 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2371 | + if (!empty($attributeValue)) { |
|
| 2372 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2373 | + } |
|
| 2374 | + } |
|
| 2375 | + } |
|
| 2376 | + update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2377 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2378 | + 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)); |
|
| 2424 | 2379 | |
| 2425 | - /** |
|
| 2426 | - * Affichage des variations d'un produit dans l'administration |
|
| 2427 | - * |
|
| 2428 | - * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2429 | - * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2430 | - */ |
|
| 2431 | - public static function display_variation_admin($head_product) |
|
| 2432 | - { |
|
| 2433 | - $output = ''; |
|
| 2434 | - $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2435 | - /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2436 | - $variations = self::get_variation($head_product); |
|
| 2437 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2438 | - |
|
| 2439 | - /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2440 | - if (!empty($variations) && is_array($variations)) { |
|
| 2441 | - $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2442 | - |
|
| 2443 | - foreach ($variations as $variation) { |
|
| 2444 | - $tpl_component = array(); |
|
| 2445 | - |
|
| 2446 | - $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2447 | - $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2448 | - $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2449 | - $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; |
|
| 2450 | - $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2451 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2452 | - |
|
| 2453 | - } else { |
|
| 2454 | - |
|
| 2455 | - } |
|
| 2456 | - $post_obj = $variation['post']; |
|
| 2457 | - |
|
| 2458 | - $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2459 | - if (!empty($parent_product_infos)) { |
|
| 2460 | - $parent_post = $parent_product_infos['parent_post']; |
|
| 2461 | - $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2462 | - if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2463 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2464 | - $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2465 | - } else { |
|
| 2466 | - $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2467 | - } |
|
| 2468 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2469 | - } else { |
|
| 2470 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2471 | - $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2472 | - } else { |
|
| 2473 | - $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2474 | - } |
|
| 2475 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2476 | - } |
|
| 2477 | - $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2478 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - if (!empty($variation['variation_def'])) { |
|
| 2482 | - foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2483 | - if (!empty($variation_value)) { |
|
| 2484 | - $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2485 | - $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'); |
|
| 2486 | - $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2487 | - |
|
| 2488 | - /** Define Link image to variation interface **/ |
|
| 2489 | - 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'))) { |
|
| 2490 | - $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2491 | - |
|
| 2492 | - $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2493 | - if (!empty($media_id_data)) { |
|
| 2494 | - $medias_ids = explode(',', $media_id_data); |
|
| 2495 | - |
|
| 2496 | - if (!empty($medias_ids)) { |
|
| 2497 | - foreach ($medias_ids as $media_id) { |
|
| 2498 | - if (!empty($media_id)) { |
|
| 2499 | - $pictures[] = get_post($media_id); |
|
| 2500 | - } |
|
| 2501 | - } |
|
| 2502 | - } |
|
| 2503 | - } |
|
| 2504 | - |
|
| 2505 | - $pictures_data = ''; |
|
| 2506 | - if (!empty($pictures)) { |
|
| 2507 | - $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2508 | - |
|
| 2509 | - $done_picture = array(); |
|
| 2510 | - foreach ($pictures as $picture) { |
|
| 2511 | - if (!in_array($picture->ID, $done_picture)) { |
|
| 2512 | - if (wp_attachment_is_image($picture->ID)) { |
|
| 2513 | - $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2514 | - $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'); |
|
| 2515 | - |
|
| 2516 | - $done_picture[] = $picture->ID; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - } |
|
| 2521 | - |
|
| 2522 | - $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'); |
|
| 2523 | - } |
|
| 2524 | - |
|
| 2525 | - } |
|
| 2526 | - } |
|
| 2527 | - } |
|
| 2528 | - |
|
| 2529 | - $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2530 | - |
|
| 2531 | - $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2532 | - $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()))); |
|
| 2533 | - $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'); |
|
| 2534 | - |
|
| 2535 | - /* Add the variation definition to output */ |
|
| 2536 | - $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'); |
|
| 2537 | - } |
|
| 2538 | - |
|
| 2539 | - $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'); |
|
| 2540 | - /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2541 | - wp_reset_query(); |
|
| 2542 | - } else { |
|
| 2543 | - $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2544 | - } |
|
| 2380 | + return $variation_id; |
|
| 2381 | + } |
|
| 2545 | 2382 | |
| 2546 | - return $output; |
|
| 2547 | - } |
|
| 2383 | + /** |
|
| 2384 | + * Get variation list for a given product |
|
| 2385 | + * |
|
| 2386 | + * @param integer $head_product The product identifier to get the variation for |
|
| 2387 | + * @return object The variation list |
|
| 2388 | + */ |
|
| 2389 | + public static function get_variation($head_product) |
|
| 2390 | + { |
|
| 2391 | + global $wpdb; |
|
| 2392 | + $variations_output = null; |
|
| 2393 | + $args = array( |
|
| 2394 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2395 | + 'post_parent' => $head_product, |
|
| 2396 | + 'orderby' => 'ID', |
|
| 2397 | + 'order' => 'ASC', |
|
| 2398 | + 'posts_per_page' => -1, |
|
| 2399 | + 'post_status' => 'any', |
|
| 2400 | + ); |
|
| 2401 | + $variations = get_posts($args); |
|
| 2402 | + |
|
| 2403 | + if (!empty($variations)) { |
|
| 2404 | + $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2405 | + |
|
| 2406 | + foreach ($variations as $post_def) { |
|
| 2407 | + $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'"); |
|
| 2408 | + foreach ($data as $content) { |
|
| 2409 | + $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2410 | + if (!empty($content->$attribute_value)) { |
|
| 2411 | + if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2412 | + $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2413 | + } else { |
|
| 2414 | + $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2415 | + } |
|
| 2416 | + } |
|
| 2417 | + } |
|
| 2418 | + $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2419 | + } |
|
| 2420 | + } |
|
| 2421 | + wp_reset_query(); |
|
| 2422 | + return $variations_output; |
|
| 2423 | + } |
|
| 2548 | 2424 | |
| 2549 | - /** |
|
| 2550 | - * Retrieve and display the variation for a given product |
|
| 2551 | - * @param integer $product_id The product identifier to get variation for |
|
| 2552 | - */ |
|
| 2553 | - public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2554 | - { |
|
| 2555 | - global $wp_query; |
|
| 2556 | - $output = ''; |
|
| 2557 | - |
|
| 2558 | - $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2559 | - $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2560 | - $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2561 | - |
|
| 2562 | - /** Get attribute order for current product */ |
|
| 2563 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2564 | - $output_order = array(); |
|
| 2565 | - if (count($product_attribute_order_detail) > 0) { |
|
| 2566 | - if (!empty($product_attribute_order_detail)) { |
|
| 2567 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2568 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2569 | - if (!empty($attribute_def->code)) { |
|
| 2570 | - $output_order[$attribute_def->code] = $position; |
|
| 2571 | - } |
|
| 2572 | - |
|
| 2573 | - } |
|
| 2574 | - } |
|
| 2575 | - } |
|
| 2576 | - } |
|
| 2425 | + /** |
|
| 2426 | + * Affichage des variations d'un produit dans l'administration |
|
| 2427 | + * |
|
| 2428 | + * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2429 | + * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2430 | + */ |
|
| 2431 | + public static function display_variation_admin($head_product) |
|
| 2432 | + { |
|
| 2433 | + $output = ''; |
|
| 2434 | + $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2435 | + /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2436 | + $variations = self::get_variation($head_product); |
|
| 2437 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2438 | + |
|
| 2439 | + /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2440 | + if (!empty($variations) && is_array($variations)) { |
|
| 2441 | + $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2442 | + |
|
| 2443 | + foreach ($variations as $variation) { |
|
| 2444 | + $tpl_component = array(); |
|
| 2445 | + |
|
| 2446 | + $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2447 | + $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2448 | + $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2449 | + $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; |
|
| 2450 | + $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2451 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2452 | + |
|
| 2453 | + } else { |
|
| 2577 | 2454 | |
| 2578 | - $variations_params = array(); |
|
| 2579 | - $variation_attribute = array(); |
|
| 2580 | - $variation_attribute_ordered = array(); |
|
| 2581 | - $possible_values = array(); |
|
| 2582 | - $possible_values_for_selection_calculation = array(); |
|
| 2583 | - |
|
| 2584 | - /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2585 | - $wpshop_variation_list = self::get_variation($product_id); |
|
| 2586 | - if (!empty($wpshop_variation_list)) { |
|
| 2587 | - foreach ($wpshop_variation_list as $variation) { |
|
| 2588 | - if (!empty($variation['variation_def'])) { |
|
| 2589 | - $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2590 | - foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2591 | - if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2592 | - $tpl_component = array(); |
|
| 2593 | - |
|
| 2594 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2595 | - $default_value_is_serial = false; |
|
| 2596 | - $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2597 | - if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2598 | - $default_value_is_serial = true; |
|
| 2599 | - $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2600 | - $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2601 | - } |
|
| 2602 | - |
|
| 2603 | - if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2604 | - $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'); |
|
| 2605 | - } |
|
| 2606 | - |
|
| 2607 | - if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2608 | - $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2609 | - $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2610 | - } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2611 | - $post_def = get_post($attribute_value); |
|
| 2612 | - $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2613 | - $position = $post_def->menu_order; |
|
| 2614 | - } |
|
| 2615 | - |
|
| 2616 | - if (!empty($variation['variation_dif'])) { |
|
| 2617 | - foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2618 | - $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2619 | - $the_value = $attribute_dif_value; |
|
| 2620 | - if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2621 | - $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2622 | - } |
|
| 2623 | - $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2624 | - } |
|
| 2625 | - } |
|
| 2626 | - if (!empty($attribute_value)) { |
|
| 2627 | - $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)); |
|
| 2628 | - $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2629 | - } |
|
| 2630 | - unset($tpl_component); |
|
| 2631 | - } |
|
| 2632 | - } |
|
| 2633 | - } |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - $variation_tpl = array(); |
|
| 2637 | - if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2638 | - foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2639 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2640 | - |
|
| 2641 | - if (!empty($attribute_db_definition)) { |
|
| 2642 | - $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'); |
|
| 2643 | - |
|
| 2644 | - $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; |
|
| 2645 | - if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2646 | - $is_required = true; |
|
| 2647 | - } |
|
| 2648 | - |
|
| 2649 | - $input_def = array(); |
|
| 2650 | - $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2651 | - $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); |
|
| 2652 | - if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2653 | - unset($possible_values[$attribute_code][0]); |
|
| 2654 | - $value = array($value); |
|
| 2655 | - } |
|
| 2656 | - $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2657 | - $input_def['name'] = $attribute_code; |
|
| 2658 | - $real_possible_values = array(); |
|
| 2659 | - if (!empty($possible_values[$attribute_code])) { |
|
| 2660 | - ksort($possible_values[$attribute_code]); |
|
| 2661 | - foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2662 | - foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2663 | - $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2664 | - if (!empty($attribute_value)) { |
|
| 2665 | - global $wpdb; |
|
| 2666 | - $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); |
|
| 2667 | - if ('draft' == $wpdb->get_var($query)) { |
|
| 2668 | - unset($real_possible_values[$attribute_value]); |
|
| 2669 | - } |
|
| 2670 | - } |
|
| 2671 | - } |
|
| 2672 | - } |
|
| 2673 | - } |
|
| 2674 | - $input_def['possible_value'] = $real_possible_values; |
|
| 2675 | - $input_def['valueToPut'] = 'index'; |
|
| 2676 | - $input_def['value'] = $value; |
|
| 2677 | - |
|
| 2678 | - $input_def['options']['more_input'] = ''; |
|
| 2679 | - if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2680 | - foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2681 | - $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 . '" />'; |
|
| 2682 | - } |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - $input_def['options_label']['original'] = true; |
|
| 2686 | - $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) . '" '; |
|
| 2687 | - |
|
| 2688 | - if (!empty($real_possible_values)) { |
|
| 2689 | - $tpl_component = array(); |
|
| 2690 | - $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']; |
|
| 2691 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2692 | - $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)); |
|
| 2693 | - $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2694 | - $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2695 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2696 | - $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2697 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2698 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2699 | - $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; |
|
| 2700 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2701 | - $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2702 | - $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2703 | - } |
|
| 2704 | - |
|
| 2705 | - $variation_attribute[] = $attribute_code; |
|
| 2706 | - } |
|
| 2707 | - } |
|
| 2708 | - } |
|
| 2455 | + } |
|
| 2456 | + $post_obj = $variation['post']; |
|
| 2457 | + |
|
| 2458 | + $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2459 | + if (!empty($parent_product_infos)) { |
|
| 2460 | + $parent_post = $parent_product_infos['parent_post']; |
|
| 2461 | + $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2462 | + if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2463 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2464 | + $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2465 | + } else { |
|
| 2466 | + $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2467 | + } |
|
| 2468 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2469 | + } else { |
|
| 2470 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2471 | + $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2472 | + } else { |
|
| 2473 | + $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2474 | + } |
|
| 2475 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2476 | + } |
|
| 2477 | + $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2478 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2479 | + } |
|
| 2709 | 2480 | |
| 2710 | - } |
|
| 2711 | - $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2712 | - wp_reset_query(); |
|
| 2713 | - |
|
| 2714 | - $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2715 | - if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2716 | - foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2717 | - $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; |
|
| 2718 | - |
|
| 2719 | - $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'); |
|
| 2720 | - 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')) { |
|
| 2721 | - $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] : '')); |
|
| 2722 | - |
|
| 2723 | - $tpl_component = array(); |
|
| 2724 | - $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) . '" '; |
|
| 2725 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2726 | - $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)); |
|
| 2727 | - $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2728 | - $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 . '" ' : ''; |
|
| 2729 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2730 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2731 | - $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2732 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2733 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2734 | - $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; |
|
| 2735 | - $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']; |
|
| 2736 | - $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)]; |
|
| 2737 | - } |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2741 | - if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2742 | - ksort($variation_attribute_ordered); |
|
| 2743 | - foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2744 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2745 | - } |
|
| 2746 | - } |
|
| 2747 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2748 | - $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2749 | - if ($from_admin && !empty($order_id)) { |
|
| 2750 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2751 | - $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2752 | - } |
|
| 2753 | - $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2481 | + if (!empty($variation['variation_def'])) { |
|
| 2482 | + foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2483 | + if (!empty($variation_value)) { |
|
| 2484 | + $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2485 | + $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'); |
|
| 2486 | + $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2487 | + |
|
| 2488 | + /** Define Link image to variation interface **/ |
|
| 2489 | + 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'))) { |
|
| 2490 | + $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2491 | + |
|
| 2492 | + $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2493 | + if (!empty($media_id_data)) { |
|
| 2494 | + $medias_ids = explode(',', $media_id_data); |
|
| 2495 | + |
|
| 2496 | + if (!empty($medias_ids)) { |
|
| 2497 | + foreach ($medias_ids as $media_id) { |
|
| 2498 | + if (!empty($media_id)) { |
|
| 2499 | + $pictures[] = get_post($media_id); |
|
| 2500 | + } |
|
| 2501 | + } |
|
| 2502 | + } |
|
| 2503 | + } |
|
| 2504 | + |
|
| 2505 | + $pictures_data = ''; |
|
| 2506 | + if (!empty($pictures)) { |
|
| 2507 | + $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2508 | + |
|
| 2509 | + $done_picture = array(); |
|
| 2510 | + foreach ($pictures as $picture) { |
|
| 2511 | + if (!in_array($picture->ID, $done_picture)) { |
|
| 2512 | + if (wp_attachment_is_image($picture->ID)) { |
|
| 2513 | + $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2514 | + $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'); |
|
| 2515 | + |
|
| 2516 | + $done_picture[] = $picture->ID; |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + } |
|
| 2521 | + |
|
| 2522 | + $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'); |
|
| 2523 | + } |
|
| 2524 | + |
|
| 2525 | + } |
|
| 2526 | + } |
|
| 2527 | + } |
|
| 2754 | 2528 | |
| 2755 | - return $output; |
|
| 2756 | - } |
|
| 2529 | + $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2757 | 2530 | |
| 2758 | - public static function get_parent_variation($variation_id) |
|
| 2759 | - { |
|
| 2760 | - $result = array(); |
|
| 2761 | - if (!empty($variation_id)) { |
|
| 2762 | - $variation_post = get_post($variation_id); |
|
| 2763 | - if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2764 | - $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2765 | - $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2766 | - } |
|
| 2767 | - } |
|
| 2768 | - return $result; |
|
| 2769 | - } |
|
| 2531 | + $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2532 | + $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()))); |
|
| 2533 | + $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'); |
|
| 2770 | 2534 | |
| 2771 | - /** |
|
| 2772 | - * Display the current configuration for a given product |
|
| 2773 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2774 | - */ |
|
| 2775 | - public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2776 | - { |
|
| 2777 | - $output = ''; |
|
| 2778 | - |
|
| 2779 | - $product_variations_selection_args = array( |
|
| 2780 | - 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2781 | - 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2782 | - ); |
|
| 2783 | - |
|
| 2784 | - $current_user_id = get_current_user_id(); |
|
| 2785 | - |
|
| 2786 | - if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2787 | - foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2788 | - if (!empty($item) && !empty($item['item_id'])) { |
|
| 2789 | - |
|
| 2790 | - $free_variations = array(); |
|
| 2791 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2792 | - foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2793 | - $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2794 | - } |
|
| 2795 | - } |
|
| 2796 | - |
|
| 2797 | - $variations = array(); |
|
| 2798 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2799 | - foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2800 | - |
|
| 2801 | - if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2802 | - foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2803 | - $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2804 | - } |
|
| 2805 | - } |
|
| 2806 | - } |
|
| 2807 | - } |
|
| 2808 | - $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2809 | - |
|
| 2810 | - $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2811 | - } |
|
| 2812 | - } |
|
| 2813 | - } |
|
| 2535 | + /* Add the variation definition to output */ |
|
| 2536 | + $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'); |
|
| 2537 | + } |
|
| 2814 | 2538 | |
| 2815 | - $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2539 | + $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'); |
|
| 2540 | + /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2541 | + wp_reset_query(); |
|
| 2542 | + } else { |
|
| 2543 | + $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2544 | + } |
|
| 2816 | 2545 | |
| 2817 | - echo $output; |
|
| 2818 | - } |
|
| 2546 | + return $output; |
|
| 2547 | + } |
|
| 2548 | + |
|
| 2549 | + /** |
|
| 2550 | + * Retrieve and display the variation for a given product |
|
| 2551 | + * @param integer $product_id The product identifier to get variation for |
|
| 2552 | + */ |
|
| 2553 | + public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2554 | + { |
|
| 2555 | + global $wp_query; |
|
| 2556 | + $output = ''; |
|
| 2557 | + |
|
| 2558 | + $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2559 | + $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2560 | + $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2561 | + |
|
| 2562 | + /** Get attribute order for current product */ |
|
| 2563 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2564 | + $output_order = array(); |
|
| 2565 | + if (count($product_attribute_order_detail) > 0) { |
|
| 2566 | + if (!empty($product_attribute_order_detail)) { |
|
| 2567 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2568 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2569 | + if (!empty($attribute_def->code)) { |
|
| 2570 | + $output_order[$attribute_def->code] = $position; |
|
| 2571 | + } |
|
| 2572 | + |
|
| 2573 | + } |
|
| 2574 | + } |
|
| 2575 | + } |
|
| 2576 | + } |
|
| 2577 | + |
|
| 2578 | + $variations_params = array(); |
|
| 2579 | + $variation_attribute = array(); |
|
| 2580 | + $variation_attribute_ordered = array(); |
|
| 2581 | + $possible_values = array(); |
|
| 2582 | + $possible_values_for_selection_calculation = array(); |
|
| 2583 | + |
|
| 2584 | + /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2585 | + $wpshop_variation_list = self::get_variation($product_id); |
|
| 2586 | + if (!empty($wpshop_variation_list)) { |
|
| 2587 | + foreach ($wpshop_variation_list as $variation) { |
|
| 2588 | + if (!empty($variation['variation_def'])) { |
|
| 2589 | + $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2590 | + foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2591 | + if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2592 | + $tpl_component = array(); |
|
| 2593 | + |
|
| 2594 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2595 | + $default_value_is_serial = false; |
|
| 2596 | + $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2597 | + if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2598 | + $default_value_is_serial = true; |
|
| 2599 | + $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2600 | + $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2601 | + } |
|
| 2602 | + |
|
| 2603 | + if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2604 | + $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'); |
|
| 2605 | + } |
|
| 2606 | + |
|
| 2607 | + if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2608 | + $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2609 | + $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2610 | + } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2611 | + $post_def = get_post($attribute_value); |
|
| 2612 | + $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2613 | + $position = $post_def->menu_order; |
|
| 2614 | + } |
|
| 2615 | + |
|
| 2616 | + if (!empty($variation['variation_dif'])) { |
|
| 2617 | + foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2618 | + $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2619 | + $the_value = $attribute_dif_value; |
|
| 2620 | + if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2621 | + $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2622 | + } |
|
| 2623 | + $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2624 | + } |
|
| 2625 | + } |
|
| 2626 | + if (!empty($attribute_value)) { |
|
| 2627 | + $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)); |
|
| 2628 | + $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2629 | + } |
|
| 2630 | + unset($tpl_component); |
|
| 2631 | + } |
|
| 2632 | + } |
|
| 2633 | + } |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + $variation_tpl = array(); |
|
| 2637 | + if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2638 | + foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2639 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2640 | + |
|
| 2641 | + if (!empty($attribute_db_definition)) { |
|
| 2642 | + $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'); |
|
| 2643 | + |
|
| 2644 | + $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; |
|
| 2645 | + if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2646 | + $is_required = true; |
|
| 2647 | + } |
|
| 2648 | + |
|
| 2649 | + $input_def = array(); |
|
| 2650 | + $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2651 | + $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); |
|
| 2652 | + if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2653 | + unset($possible_values[$attribute_code][0]); |
|
| 2654 | + $value = array($value); |
|
| 2655 | + } |
|
| 2656 | + $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2657 | + $input_def['name'] = $attribute_code; |
|
| 2658 | + $real_possible_values = array(); |
|
| 2659 | + if (!empty($possible_values[$attribute_code])) { |
|
| 2660 | + ksort($possible_values[$attribute_code]); |
|
| 2661 | + foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2662 | + foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2663 | + $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2664 | + if (!empty($attribute_value)) { |
|
| 2665 | + global $wpdb; |
|
| 2666 | + $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); |
|
| 2667 | + if ('draft' == $wpdb->get_var($query)) { |
|
| 2668 | + unset($real_possible_values[$attribute_value]); |
|
| 2669 | + } |
|
| 2670 | + } |
|
| 2671 | + } |
|
| 2672 | + } |
|
| 2673 | + } |
|
| 2674 | + $input_def['possible_value'] = $real_possible_values; |
|
| 2675 | + $input_def['valueToPut'] = 'index'; |
|
| 2676 | + $input_def['value'] = $value; |
|
| 2677 | + |
|
| 2678 | + $input_def['options']['more_input'] = ''; |
|
| 2679 | + if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2680 | + foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2681 | + $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 . '" />'; |
|
| 2682 | + } |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + $input_def['options_label']['original'] = true; |
|
| 2686 | + $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) . '" '; |
|
| 2687 | + |
|
| 2688 | + if (!empty($real_possible_values)) { |
|
| 2689 | + $tpl_component = array(); |
|
| 2690 | + $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']; |
|
| 2691 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2692 | + $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)); |
|
| 2693 | + $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2694 | + $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2695 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2696 | + $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2697 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2698 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2699 | + $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; |
|
| 2700 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2701 | + $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2702 | + $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2703 | + } |
|
| 2704 | + |
|
| 2705 | + $variation_attribute[] = $attribute_code; |
|
| 2706 | + } |
|
| 2707 | + } |
|
| 2708 | + } |
|
| 2709 | + |
|
| 2710 | + } |
|
| 2711 | + $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2712 | + wp_reset_query(); |
|
| 2713 | + |
|
| 2714 | + $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2715 | + if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2716 | + foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2717 | + $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; |
|
| 2718 | + |
|
| 2719 | + $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'); |
|
| 2720 | + 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')) { |
|
| 2721 | + $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] : '')); |
|
| 2722 | + |
|
| 2723 | + $tpl_component = array(); |
|
| 2724 | + $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) . '" '; |
|
| 2725 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2726 | + $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)); |
|
| 2727 | + $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2728 | + $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 . '" ' : ''; |
|
| 2729 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2730 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2731 | + $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2732 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2733 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2734 | + $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; |
|
| 2735 | + $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']; |
|
| 2736 | + $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)]; |
|
| 2737 | + } |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2741 | + if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2742 | + ksort($variation_attribute_ordered); |
|
| 2743 | + foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2744 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2745 | + } |
|
| 2746 | + } |
|
| 2747 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2748 | + $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2749 | + if ($from_admin && !empty($order_id)) { |
|
| 2750 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2751 | + $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2752 | + } |
|
| 2753 | + $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2754 | + |
|
| 2755 | + return $output; |
|
| 2756 | + } |
|
| 2757 | + |
|
| 2758 | + public static function get_parent_variation($variation_id) |
|
| 2759 | + { |
|
| 2760 | + $result = array(); |
|
| 2761 | + if (!empty($variation_id)) { |
|
| 2762 | + $variation_post = get_post($variation_id); |
|
| 2763 | + if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2764 | + $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2765 | + $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2766 | + } |
|
| 2767 | + } |
|
| 2768 | + return $result; |
|
| 2769 | + } |
|
| 2770 | + |
|
| 2771 | + /** |
|
| 2772 | + * Display the current configuration for a given product |
|
| 2773 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2774 | + */ |
|
| 2775 | + public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2776 | + { |
|
| 2777 | + $output = ''; |
|
| 2778 | + |
|
| 2779 | + $product_variations_selection_args = array( |
|
| 2780 | + 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2781 | + 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2782 | + ); |
|
| 2783 | + |
|
| 2784 | + $current_user_id = get_current_user_id(); |
|
| 2785 | + |
|
| 2786 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2787 | + foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2788 | + if (!empty($item) && !empty($item['item_id'])) { |
|
| 2789 | + |
|
| 2790 | + $free_variations = array(); |
|
| 2791 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2792 | + foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2793 | + $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2794 | + } |
|
| 2795 | + } |
|
| 2796 | + |
|
| 2797 | + $variations = array(); |
|
| 2798 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2799 | + foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2800 | + |
|
| 2801 | + if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2802 | + foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2803 | + $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2804 | + } |
|
| 2805 | + } |
|
| 2806 | + } |
|
| 2807 | + } |
|
| 2808 | + $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2809 | + |
|
| 2810 | + $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2811 | + } |
|
| 2812 | + } |
|
| 2813 | + } |
|
| 2814 | + |
|
| 2815 | + $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2816 | + |
|
| 2817 | + echo $output; |
|
| 2818 | + } |
|
| 2819 | + |
|
| 2820 | + /** |
|
| 2821 | + * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2822 | + * |
|
| 2823 | + * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2824 | + * @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 |
|
| 2825 | + * @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 |
|
| 2826 | + * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2827 | + * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2828 | + * |
|
| 2829 | + * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2830 | + */ |
|
| 2831 | + public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2832 | + { |
|
| 2833 | + global $wpdb; |
|
| 2834 | + |
|
| 2835 | + $wpshop_cart = new wps_cart(); |
|
| 2836 | + $wpshop_products = new wpshop_products(); |
|
| 2837 | + |
|
| 2838 | + $response = ''; |
|
| 2839 | + $response_status = $has_variation = false; |
|
| 2840 | + $tpl_component = array(); |
|
| 2841 | + |
|
| 2842 | + // Check if variations exists |
|
| 2843 | + if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2844 | + |
|
| 2845 | + //Recover all selected variations |
|
| 2846 | + $variations_selected = array(); |
|
| 2847 | + if (!empty($wpshop_variation_selected)) { |
|
| 2848 | + foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2849 | + $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2850 | + $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2851 | + } |
|
| 2852 | + } |
|
| 2853 | + |
|
| 2854 | + // Check variations priority |
|
| 2855 | + $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2856 | + |
|
| 2857 | + // Check if $product_with_variation have variations |
|
| 2858 | + if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2859 | + |
|
| 2860 | + $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2861 | + $product_to_add_to_cart = $formatted_product[0]; |
|
| 2862 | + foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2863 | + $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2864 | + |
|
| 2865 | + /** For product with variation */ |
|
| 2866 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2867 | + $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2868 | + $order_items[$pid]['product_variation'] = ''; |
|
| 2869 | + if (!empty($product_more_content['variations'])) { |
|
| 2870 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2871 | + $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2872 | + } |
|
| 2873 | + } |
|
| 2874 | + } |
|
| 2875 | + |
|
| 2876 | + // If Product list is not empty, add products to order |
|
| 2877 | + if (!empty($order_items)) { |
|
| 2878 | + foreach ($order_items as $product_id => $d) { |
|
| 2879 | + $product_key = $product_id; |
|
| 2880 | + |
|
| 2881 | + // Formate datas |
|
| 2882 | + $product_id = $head_product_id = $d['product_id']; |
|
| 2883 | + $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2819 | 2884 | |
| 2820 | - /** |
|
| 2821 | - * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2822 | - * |
|
| 2823 | - * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2824 | - * @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 |
|
| 2825 | - * @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 |
|
| 2826 | - * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2827 | - * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2828 | - * |
|
| 2829 | - * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2830 | - */ |
|
| 2831 | - public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2832 | - { |
|
| 2833 | - global $wpdb; |
|
| 2834 | - |
|
| 2835 | - $wpshop_cart = new wps_cart(); |
|
| 2836 | - $wpshop_products = new wpshop_products(); |
|
| 2837 | - |
|
| 2838 | - $response = ''; |
|
| 2839 | - $response_status = $has_variation = false; |
|
| 2840 | - $tpl_component = array(); |
|
| 2841 | - |
|
| 2842 | - // Check if variations exists |
|
| 2843 | - if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2844 | - |
|
| 2845 | - //Recover all selected variations |
|
| 2846 | - $variations_selected = array(); |
|
| 2847 | - if (!empty($wpshop_variation_selected)) { |
|
| 2848 | - foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2849 | - $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2850 | - $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2851 | - } |
|
| 2852 | - } |
|
| 2853 | - |
|
| 2854 | - // Check variations priority |
|
| 2855 | - $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2856 | - |
|
| 2857 | - // Check if $product_with_variation have variations |
|
| 2858 | - if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2859 | - |
|
| 2860 | - $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2861 | - $product_to_add_to_cart = $formatted_product[0]; |
|
| 2862 | - foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2863 | - $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2864 | - |
|
| 2865 | - /** For product with variation */ |
|
| 2866 | - $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2867 | - $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2868 | - $order_items[$pid]['product_variation'] = ''; |
|
| 2869 | - if (!empty($product_more_content['variations'])) { |
|
| 2870 | - foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2871 | - $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2872 | - } |
|
| 2873 | - } |
|
| 2874 | - } |
|
| 2875 | - |
|
| 2876 | - // If Product list is not empty, add products to order |
|
| 2877 | - if (!empty($order_items)) { |
|
| 2878 | - foreach ($order_items as $product_id => $d) { |
|
| 2879 | - $product_key = $product_id; |
|
| 2880 | - |
|
| 2881 | - // Formate datas |
|
| 2882 | - $product_id = $head_product_id = $d['product_id']; |
|
| 2883 | - $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2884 | - |
|
| 2885 | - // If product is a single variation product |
|
| 2886 | - if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2887 | - $product_id = $product_variation[0]; |
|
| 2888 | - } |
|
| 2889 | - |
|
| 2890 | - // Construct final product |
|
| 2891 | - $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2892 | - $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2885 | + // If product is a single variation product |
|
| 2886 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2887 | + $product_id = $product_variation[0]; |
|
| 2888 | + } |
|
| 2889 | + |
|
| 2890 | + // Construct final product |
|
| 2891 | + $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2892 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2893 | 2893 | $the_product['text_from'] = $product_with_variation['text_from']; |
| 2894 | 2894 | |
| 2895 | - // Add variation to product into cart for storage |
|
| 2896 | - if (!empty($product_variation)) { |
|
| 2897 | - $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2898 | - } |
|
| 2899 | - |
|
| 2900 | - // Free Variations Checking |
|
| 2901 | - if (!empty($d['free_variation'])) { |
|
| 2902 | - $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2903 | - $head_product_id = $the_product['product_id']; |
|
| 2904 | - } |
|
| 2905 | - |
|
| 2906 | - // If product is a variation, we check parent product general |
|
| 2907 | - if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2908 | - $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2909 | - if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2910 | - $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2911 | - $parent_meta = $parent_def['parent_post_meta']; |
|
| 2912 | - 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) { |
|
| 2913 | - $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2914 | - $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2915 | - $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2916 | - } |
|
| 2917 | - } |
|
| 2918 | - } |
|
| 2919 | - } |
|
| 2920 | - } |
|
| 2921 | - |
|
| 2922 | - if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2923 | - $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2924 | - if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2925 | - $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2926 | - $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2927 | - } |
|
| 2928 | - $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']; |
|
| 2929 | - $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']; |
|
| 2930 | - $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']; |
|
| 2931 | - } |
|
| 2932 | - |
|
| 2933 | - $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2934 | - // Add free variations to product |
|
| 2935 | - if (!empty($wpshop_free_variation)) { |
|
| 2936 | - $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2937 | - } |
|
| 2938 | - // Change picture if have a selected variation |
|
| 2939 | - $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; |
|
| 2940 | - $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2941 | - |
|
| 2942 | - // Price Display |
|
| 2943 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2944 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2945 | - $productPrice = ''; |
|
| 2946 | - if ($price_display) { |
|
| 2947 | - $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2948 | - } |
|
| 2949 | - |
|
| 2950 | - //Get Summary cart |
|
| 2951 | - $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2952 | - $response_status = true; |
|
| 2953 | - } else { |
|
| 2954 | - //Product without variations |
|
| 2955 | - $product_data = wpshop_products::get_product_data($product_id); |
|
| 2956 | - $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2957 | - } |
|
| 2958 | - } |
|
| 2895 | + // Add variation to product into cart for storage |
|
| 2896 | + if (!empty($product_variation)) { |
|
| 2897 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2898 | + } |
|
| 2899 | + |
|
| 2900 | + // Free Variations Checking |
|
| 2901 | + if (!empty($d['free_variation'])) { |
|
| 2902 | + $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2903 | + $head_product_id = $the_product['product_id']; |
|
| 2904 | + } |
|
| 2905 | + |
|
| 2906 | + // If product is a variation, we check parent product general |
|
| 2907 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2908 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2909 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2910 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2911 | + $parent_meta = $parent_def['parent_post_meta']; |
|
| 2912 | + 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) { |
|
| 2913 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2914 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2915 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2916 | + } |
|
| 2917 | + } |
|
| 2918 | + } |
|
| 2919 | + } |
|
| 2920 | + } |
|
| 2959 | 2921 | |
| 2960 | - return array($response_status, $response); |
|
| 2961 | - } |
|
| 2922 | + if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2923 | + $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2924 | + if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2925 | + $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2926 | + $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2927 | + } |
|
| 2928 | + $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']; |
|
| 2929 | + $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']; |
|
| 2930 | + $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']; |
|
| 2931 | + } |
|
| 2962 | 2932 | |
| 2963 | - /** |
|
| 2964 | - * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2965 | - * |
|
| 2966 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2967 | - */ |
|
| 2968 | - public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 2969 | - { |
|
| 2970 | - echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 2971 | - } |
|
| 2933 | + $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2934 | + // Add free variations to product |
|
| 2935 | + if (!empty($wpshop_free_variation)) { |
|
| 2936 | + $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2937 | + } |
|
| 2938 | + // Change picture if have a selected variation |
|
| 2939 | + $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; |
|
| 2940 | + $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2941 | + |
|
| 2942 | + // Price Display |
|
| 2943 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2944 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2945 | + $productPrice = ''; |
|
| 2946 | + if ($price_display) { |
|
| 2947 | + $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2948 | + } |
|
| 2972 | 2949 | |
| 2973 | - /** |
|
| 2974 | - * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 2975 | - * |
|
| 2976 | - * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 2977 | - * @param integer $product_id The basic product choose by the user in frontend |
|
| 2978 | - * |
|
| 2979 | - * @return array The product list for adding to the cart build by variation priority |
|
| 2980 | - */ |
|
| 2981 | - public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 2982 | - { |
|
| 2983 | - global $wpdb; |
|
| 2984 | - $all_required_variations_selected = $no_selected_variation = true; |
|
| 2985 | - $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 2986 | - |
|
| 2987 | - // Check if all required variations are selected |
|
| 2988 | - $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 2989 | - foreach ($selected_variation as $k => $value) { |
|
| 2990 | - if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 2991 | - $all_required_variations_selected = false; |
|
| 2992 | - } |
|
| 2993 | - if ($value != 0) { |
|
| 2994 | - $no_selected_variation = false; |
|
| 2995 | - } |
|
| 2996 | - } |
|
| 2997 | - if (!empty($selected_variation)) { |
|
| 2998 | - //Check variations configuration |
|
| 2999 | - $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 3000 | - // Check variations type |
|
| 3001 | - $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 3002 | - $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 3003 | - |
|
| 3004 | - //Check defined variation priority |
|
| 3005 | - $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 3006 | - $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 3007 | - |
|
| 3008 | - // Recover all product variations |
|
| 3009 | - $query_variation = $selected_variation; |
|
| 3010 | - // Delete free variations |
|
| 3011 | - unset($query_variation['free']); |
|
| 3012 | - |
|
| 3013 | - if ($product_variation_type == 'single') { |
|
| 3014 | - // Get single variations |
|
| 3015 | - $single_variations = array(); |
|
| 3016 | - foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 3017 | - if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 3018 | - $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)) . "'", $product_id); |
|
| 3019 | - $single_variation_id = $wpdb->get_var($query); |
|
| 3020 | - if (!empty($single_variation_id)) { |
|
| 3021 | - $single_variations[] = $single_variation_id; |
|
| 3022 | - unset($query_variation[$attribute_code]); |
|
| 3023 | - } |
|
| 3024 | - } |
|
| 3025 | - } |
|
| 3026 | - } else { |
|
| 3027 | - // Get combined variations |
|
| 3028 | - $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); |
|
| 3029 | - $combined_variation_id = $wpdb->get_var($query); |
|
| 3030 | - if (!empty($combined_variation_id)) { |
|
| 3031 | - $combined_variations[] = $combined_variation_id; |
|
| 3032 | - } |
|
| 3033 | - |
|
| 3034 | - } |
|
| 3035 | - |
|
| 3036 | - //If all required variations are not selected |
|
| 3037 | - if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3038 | - $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3039 | - // If we choose to display lower price variation combinaison |
|
| 3040 | - 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']))) { |
|
| 3041 | - //Get lower price variation combinaison |
|
| 3042 | - $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3043 | - if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3044 | - foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3045 | - $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3046 | - } |
|
| 3047 | - } |
|
| 3048 | - $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3049 | - } else { |
|
| 3050 | - $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3051 | - } |
|
| 3052 | - } else { |
|
| 3053 | - $product_to_add_to_cart['text_from'] = ''; |
|
| 3054 | - $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3055 | - } |
|
| 3056 | - } |
|
| 2950 | + //Get Summary cart |
|
| 2951 | + $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2952 | + $response_status = true; |
|
| 2953 | + } else { |
|
| 2954 | + //Product without variations |
|
| 2955 | + $product_data = wpshop_products::get_product_data($product_id); |
|
| 2956 | + $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2957 | + } |
|
| 2958 | + } |
|
| 3057 | 2959 | |
| 3058 | - return $product_to_add_to_cart; |
|
| 3059 | - } |
|
| 2960 | + return array($response_status, $response); |
|
| 2961 | + } |
|
| 3060 | 2962 | |
| 3061 | - public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3062 | - { |
|
| 3063 | - global $wpdb; |
|
| 3064 | - |
|
| 3065 | - if (!empty($product_variations)) { |
|
| 3066 | - // Initialize variations total price datas |
|
| 3067 | - $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3068 | - $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3069 | - $vat_rate = 0; |
|
| 3070 | - $discount_amount = $discount_rate = $special_price = 0; |
|
| 3071 | - // Recover Head product metadata |
|
| 3072 | - $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3073 | - $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3074 | - if (!empty($tva_rate_id)) { |
|
| 3075 | - // Recover VAT Rate of product |
|
| 3076 | - $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3077 | - $vat_rate = $wpdb->get_var($query); |
|
| 3078 | - } |
|
| 3079 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3080 | - foreach ($product_variations as $product_variation) { |
|
| 3081 | - $variation_metadata['product_price'] = 0; |
|
| 3082 | - $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3083 | - if (!empty($variation_metadata)) { |
|
| 3084 | - $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']); |
|
| 3085 | - $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)))); |
|
| 3086 | - |
|
| 3087 | - $variations_total_price['price_et'] += $p_et; |
|
| 3088 | - $variations_total_price['price_ati'] += $p_ati; |
|
| 3089 | - $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3090 | - |
|
| 3091 | - $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3092 | - |
|
| 3093 | - // Check discount |
|
| 3094 | - $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3095 | - if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3096 | - $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3097 | - $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3098 | - $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3099 | - $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3100 | - |
|
| 3101 | - if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3102 | - $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3103 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3104 | - $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3105 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3106 | - $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3107 | - } |
|
| 3108 | - } |
|
| 3109 | - |
|
| 3110 | - $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3111 | - $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3112 | - } |
|
| 3113 | - } |
|
| 3114 | - |
|
| 3115 | - // Check if add or replace variation price to head product |
|
| 3116 | - /** |
|
| 3117 | - * Since 1.4.3.7 |
|
| 3118 | - * L'option du produit remplace le prix du produit de tête. |
|
| 3119 | - */ |
|
| 2963 | + /** |
|
| 2964 | + * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2965 | + * |
|
| 2966 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2967 | + */ |
|
| 2968 | + public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 2969 | + { |
|
| 2970 | + echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 2971 | + } |
|
| 2972 | + |
|
| 2973 | + /** |
|
| 2974 | + * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 2975 | + * |
|
| 2976 | + * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 2977 | + * @param integer $product_id The basic product choose by the user in frontend |
|
| 2978 | + * |
|
| 2979 | + * @return array The product list for adding to the cart build by variation priority |
|
| 2980 | + */ |
|
| 2981 | + public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 2982 | + { |
|
| 2983 | + global $wpdb; |
|
| 2984 | + $all_required_variations_selected = $no_selected_variation = true; |
|
| 2985 | + $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 2986 | + |
|
| 2987 | + // Check if all required variations are selected |
|
| 2988 | + $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 2989 | + foreach ($selected_variation as $k => $value) { |
|
| 2990 | + if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 2991 | + $all_required_variations_selected = false; |
|
| 2992 | + } |
|
| 2993 | + if ($value != 0) { |
|
| 2994 | + $no_selected_variation = false; |
|
| 2995 | + } |
|
| 2996 | + } |
|
| 2997 | + if (!empty($selected_variation)) { |
|
| 2998 | + //Check variations configuration |
|
| 2999 | + $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 3000 | + // Check variations type |
|
| 3001 | + $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 3002 | + $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 3003 | + |
|
| 3004 | + //Check defined variation priority |
|
| 3005 | + $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 3006 | + $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 3007 | + |
|
| 3008 | + // Recover all product variations |
|
| 3009 | + $query_variation = $selected_variation; |
|
| 3010 | + // Delete free variations |
|
| 3011 | + unset($query_variation['free']); |
|
| 3012 | + |
|
| 3013 | + if ($product_variation_type == 'single') { |
|
| 3014 | + // Get single variations |
|
| 3015 | + $single_variations = array(); |
|
| 3016 | + foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 3017 | + if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 3018 | + $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)) . "'", $product_id); |
|
| 3019 | + $single_variation_id = $wpdb->get_var($query); |
|
| 3020 | + if (!empty($single_variation_id)) { |
|
| 3021 | + $single_variations[] = $single_variation_id; |
|
| 3022 | + unset($query_variation[$attribute_code]); |
|
| 3023 | + } |
|
| 3024 | + } |
|
| 3025 | + } |
|
| 3026 | + } else { |
|
| 3027 | + // Get combined variations |
|
| 3028 | + $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); |
|
| 3029 | + $combined_variation_id = $wpdb->get_var($query); |
|
| 3030 | + if (!empty($combined_variation_id)) { |
|
| 3031 | + $combined_variations[] = $combined_variation_id; |
|
| 3032 | + } |
|
| 3033 | + |
|
| 3034 | + } |
|
| 3035 | + |
|
| 3036 | + //If all required variations are not selected |
|
| 3037 | + if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3038 | + $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3039 | + // If we choose to display lower price variation combinaison |
|
| 3040 | + 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']))) { |
|
| 3041 | + //Get lower price variation combinaison |
|
| 3042 | + $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3043 | + if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3044 | + foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3045 | + $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3046 | + } |
|
| 3047 | + } |
|
| 3048 | + $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3049 | + } else { |
|
| 3050 | + $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3051 | + } |
|
| 3052 | + } else { |
|
| 3053 | + $product_to_add_to_cart['text_from'] = ''; |
|
| 3054 | + $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3055 | + } |
|
| 3056 | + } |
|
| 3057 | + |
|
| 3058 | + return $product_to_add_to_cart; |
|
| 3059 | + } |
|
| 3060 | + |
|
| 3061 | + public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3062 | + { |
|
| 3063 | + global $wpdb; |
|
| 3064 | + |
|
| 3065 | + if (!empty($product_variations)) { |
|
| 3066 | + // Initialize variations total price datas |
|
| 3067 | + $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3068 | + $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3069 | + $vat_rate = 0; |
|
| 3070 | + $discount_amount = $discount_rate = $special_price = 0; |
|
| 3071 | + // Recover Head product metadata |
|
| 3072 | + $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3073 | + $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3074 | + if (!empty($tva_rate_id)) { |
|
| 3075 | + // Recover VAT Rate of product |
|
| 3076 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3077 | + $vat_rate = $wpdb->get_var($query); |
|
| 3078 | + } |
|
| 3079 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3080 | + foreach ($product_variations as $product_variation) { |
|
| 3081 | + $variation_metadata['product_price'] = 0; |
|
| 3082 | + $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3083 | + if (!empty($variation_metadata)) { |
|
| 3084 | + $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']); |
|
| 3085 | + $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)))); |
|
| 3086 | + |
|
| 3087 | + $variations_total_price['price_et'] += $p_et; |
|
| 3088 | + $variations_total_price['price_ati'] += $p_ati; |
|
| 3089 | + $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3090 | + |
|
| 3091 | + $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3092 | + |
|
| 3093 | + // Check discount |
|
| 3094 | + $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3095 | + if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3096 | + $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3097 | + $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3098 | + $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3099 | + $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3100 | + |
|
| 3101 | + if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3102 | + $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3103 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3104 | + $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3105 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3106 | + $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3107 | + } |
|
| 3108 | + } |
|
| 3109 | + |
|
| 3110 | + $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3111 | + $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3112 | + } |
|
| 3113 | + } |
|
| 3114 | + |
|
| 3115 | + // Check if add or replace variation price to head product |
|
| 3116 | + /** |
|
| 3117 | + * Since 1.4.3.7 |
|
| 3118 | + * L'option du produit remplace le prix du produit de tête. |
|
| 3119 | + */ |
|
| 3120 | 3120 | if( true ) { |
| 3121 | - //Replace the product price |
|
| 3122 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3123 | - $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3124 | - $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3125 | - |
|
| 3126 | - $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3127 | - $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3128 | - $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3129 | - } else { |
|
| 3130 | - $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3131 | - $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3132 | - $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3133 | - } |
|
| 3134 | - } else { |
|
| 3135 | - // Add variations price to product price |
|
| 3136 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3137 | - $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3138 | - $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3139 | - |
|
| 3140 | - $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3141 | - $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3142 | - $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3143 | - } else { |
|
| 3144 | - $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3145 | - $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3146 | - $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3147 | - } |
|
| 3148 | - // Check parent discount |
|
| 3149 | - $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3150 | - if (!empty($parent_discount_config)) { |
|
| 3151 | - $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']; |
|
| 3152 | - $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']; |
|
| 3153 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3154 | - |
|
| 3155 | - if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3156 | - $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3157 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3158 | - $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3159 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3160 | - $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3161 | - } |
|
| 3162 | - } |
|
| 3163 | - } |
|
| 3164 | - } else { |
|
| 3165 | - // If product have just Free variations |
|
| 3166 | - $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3167 | - if (!empty($discount_config)) { |
|
| 3168 | - $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']; |
|
| 3169 | - $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']; |
|
| 3170 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3171 | - } |
|
| 3172 | - } |
|
| 3121 | + //Replace the product price |
|
| 3122 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3123 | + $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3124 | + $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3125 | + |
|
| 3126 | + $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3127 | + $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3128 | + $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3129 | + } else { |
|
| 3130 | + $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3131 | + $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3132 | + $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3133 | + } |
|
| 3134 | + } else { |
|
| 3135 | + // Add variations price to product price |
|
| 3136 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3137 | + $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3138 | + $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3139 | + |
|
| 3140 | + $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3141 | + $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3142 | + $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3143 | + } else { |
|
| 3144 | + $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3145 | + $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3146 | + $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3147 | + } |
|
| 3148 | + // Check parent discount |
|
| 3149 | + $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3150 | + if (!empty($parent_discount_config)) { |
|
| 3151 | + $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']; |
|
| 3152 | + $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']; |
|
| 3153 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3154 | + |
|
| 3155 | + if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3156 | + $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3157 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3158 | + $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3159 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3160 | + $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3161 | + } |
|
| 3162 | + } |
|
| 3163 | + } |
|
| 3164 | + } else { |
|
| 3165 | + // If product have just Free variations |
|
| 3166 | + $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3167 | + if (!empty($discount_config)) { |
|
| 3168 | + $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']; |
|
| 3169 | + $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']; |
|
| 3170 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3171 | + } |
|
| 3172 | + } |
|
| 3173 | 3173 | |
| 3174 | - // Text From indicator |
|
| 3175 | - if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3176 | - $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3177 | - } |
|
| 3178 | - return $product_into_cart; |
|
| 3179 | - } |
|
| 3174 | + // Text From indicator |
|
| 3175 | + if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3176 | + $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3177 | + } |
|
| 3178 | + return $product_into_cart; |
|
| 3179 | + } |
|
| 3180 | 3180 | |
| 3181 | - /** |
|
| 3182 | - * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3183 | - * |
|
| 3184 | - * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3185 | - * @param array $output_order The good order for attribute defined by administrator |
|
| 3186 | - * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3187 | - * |
|
| 3188 | - * @return array The array containing all product options ordered as the admin configure it |
|
| 3189 | - */ |
|
| 3190 | - public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3191 | - { |
|
| 3192 | - $variation_attribute_ordered = array(); |
|
| 3193 | - $variation_attribute_ordered['prices'] = array(); |
|
| 3194 | - $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3195 | - |
|
| 3196 | - if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3197 | - foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3198 | - $variation_tpl_component = array(); |
|
| 3199 | - foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3200 | - $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); |
|
| 3201 | - } |
|
| 3202 | - $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3203 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3204 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3205 | - $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); |
|
| 3206 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3207 | - $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3208 | - } |
|
| 3209 | - } else { |
|
| 3210 | - $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); |
|
| 3211 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3212 | - $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3213 | - } |
|
| 3214 | - } |
|
| 3215 | - unset($variation_tpl_component); |
|
| 3216 | - } |
|
| 3217 | - } |
|
| 3181 | + /** |
|
| 3182 | + * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3183 | + * |
|
| 3184 | + * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3185 | + * @param array $output_order The good order for attribute defined by administrator |
|
| 3186 | + * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3187 | + * |
|
| 3188 | + * @return array The array containing all product options ordered as the admin configure it |
|
| 3189 | + */ |
|
| 3190 | + public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3191 | + { |
|
| 3192 | + $variation_attribute_ordered = array(); |
|
| 3193 | + $variation_attribute_ordered['prices'] = array(); |
|
| 3194 | + $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3195 | + |
|
| 3196 | + if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3197 | + foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3198 | + $variation_tpl_component = array(); |
|
| 3199 | + foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3200 | + $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); |
|
| 3201 | + } |
|
| 3202 | + $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3203 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3204 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3205 | + $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); |
|
| 3206 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3207 | + $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3208 | + } |
|
| 3209 | + } else { |
|
| 3210 | + $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); |
|
| 3211 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3212 | + $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3213 | + } |
|
| 3214 | + } |
|
| 3215 | + unset($variation_tpl_component); |
|
| 3216 | + } |
|
| 3217 | + } |
|
| 3218 | 3218 | |
| 3219 | - if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3220 | - foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3221 | - $variation_tpl_component = array(); |
|
| 3222 | - foreach ($variation_details as $info_name => $info_value) { |
|
| 3223 | - if ($info_name != 'item_meta') { |
|
| 3224 | - $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); |
|
| 3225 | - } |
|
| 3226 | - } |
|
| 3227 | - foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3228 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3229 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3230 | - $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3231 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3232 | - |
|
| 3233 | - $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3234 | - } |
|
| 3235 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3236 | - $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); |
|
| 3237 | - } |
|
| 3238 | - unset($variation_tpl_component); |
|
| 3239 | - } |
|
| 3240 | - } |
|
| 3219 | + if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3220 | + foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3221 | + $variation_tpl_component = array(); |
|
| 3222 | + foreach ($variation_details as $info_name => $info_value) { |
|
| 3223 | + if ($info_name != 'item_meta') { |
|
| 3224 | + $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); |
|
| 3225 | + } |
|
| 3226 | + } |
|
| 3227 | + foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3228 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3229 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3230 | + $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3231 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3241 | 3232 | |
| 3242 | - /** Free Variation part */ |
|
| 3243 | - if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3244 | - foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3245 | - if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3246 | - $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3247 | - $attribute_code = $variation_definition[0]; |
|
| 3248 | - $attribute_selected_value = $variation_definition[1]; |
|
| 3249 | - } else { |
|
| 3250 | - $attribute_code = $build_variation_key; |
|
| 3251 | - $attribute_selected_value = $build_variation; |
|
| 3252 | - } |
|
| 3253 | - |
|
| 3254 | - $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3255 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3256 | - $value_to_outut = $attribute_selected_value; |
|
| 3257 | - switch ($free_variation_attribute_def->data_type) { |
|
| 3258 | - case 'datetime': |
|
| 3259 | - $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3260 | - break; |
|
| 3261 | - } |
|
| 3262 | - |
|
| 3263 | - if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3264 | - switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3265 | - case 'custom': |
|
| 3266 | - case 'internal': |
|
| 3267 | - $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3268 | - $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3269 | - break; |
|
| 3270 | - } |
|
| 3271 | - } |
|
| 3272 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3273 | - $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3274 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3275 | - if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3276 | - $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); |
|
| 3277 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3278 | - $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3279 | - } |
|
| 3280 | - } |
|
| 3281 | - unset($variation_tpl_component); |
|
| 3282 | - } |
|
| 3283 | - } |
|
| 3284 | - return $variation_attribute_ordered; |
|
| 3285 | - } |
|
| 3233 | + $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3234 | + } |
|
| 3235 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3236 | + $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); |
|
| 3237 | + } |
|
| 3238 | + unset($variation_tpl_component); |
|
| 3239 | + } |
|
| 3240 | + } |
|
| 3286 | 3241 | |
| 3287 | - public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3288 | - { |
|
| 3289 | - $response = array(); |
|
| 3290 | - /** Selected Product image **/ |
|
| 3291 | - $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3292 | - if (!empty($post_thumbnail_id)) { |
|
| 3293 | - $response['img_id'] = $post_thumbnail_id; |
|
| 3294 | - $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3295 | - $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3296 | - } |
|
| 3242 | + /** Free Variation part */ |
|
| 3243 | + if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3244 | + foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3245 | + if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3246 | + $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3247 | + $attribute_code = $variation_definition[0]; |
|
| 3248 | + $attribute_selected_value = $variation_definition[1]; |
|
| 3249 | + } else { |
|
| 3250 | + $attribute_code = $build_variation_key; |
|
| 3251 | + $attribute_selected_value = $build_variation; |
|
| 3252 | + } |
|
| 3297 | 3253 | |
| 3298 | - /** check if have one variation **/ |
|
| 3299 | - if (!empty($variations) && count($variations) == 1) { |
|
| 3300 | - $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3301 | - if (!empty($variation_attached_image_id)) { |
|
| 3302 | - $response['img_id'] = $variation_attached_image_id; |
|
| 3303 | - $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3304 | - $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3305 | - } |
|
| 3306 | - } |
|
| 3307 | - return $response; |
|
| 3308 | - } |
|
| 3254 | + $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3255 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3256 | + $value_to_outut = $attribute_selected_value; |
|
| 3257 | + switch ($free_variation_attribute_def->data_type) { |
|
| 3258 | + case 'datetime': |
|
| 3259 | + $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3260 | + break; |
|
| 3261 | + } |
|
| 3309 | 3262 | |
| 3310 | - /** Add a meta box of product sales history in product administration panel **/ |
|
| 3311 | - public function meta_box_product_sale_informations() |
|
| 3312 | - { |
|
| 3313 | - global $post; |
|
| 3314 | - $product_id = $post->ID; |
|
| 3315 | - |
|
| 3316 | - $variations = self::get_variation($product_id); |
|
| 3317 | - |
|
| 3318 | - $sales_informations = array(); |
|
| 3319 | - /** Query **/ |
|
| 3320 | - $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3321 | - $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'))); |
|
| 3322 | - $orders = new WP_Query($query_args); |
|
| 3323 | - if (!empty($orders) && !empty($orders->posts)) { |
|
| 3324 | - foreach ($orders->posts as $order) { |
|
| 3325 | - $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3326 | - $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3327 | - $sales_informations[] = array( |
|
| 3328 | - 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3329 | - 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3330 | - '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'] : '', |
|
| 3331 | - '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'] : '', |
|
| 3332 | - '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'] : '', |
|
| 3333 | - ); |
|
| 3334 | - } |
|
| 3335 | - } |
|
| 3263 | + if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3264 | + switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3265 | + case 'custom': |
|
| 3266 | + case 'internal': |
|
| 3267 | + $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3268 | + $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3269 | + break; |
|
| 3270 | + } |
|
| 3271 | + } |
|
| 3272 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3273 | + $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3274 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3275 | + if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3276 | + $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); |
|
| 3277 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3278 | + $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3279 | + } |
|
| 3280 | + } |
|
| 3281 | + unset($variation_tpl_component); |
|
| 3282 | + } |
|
| 3283 | + } |
|
| 3284 | + return $variation_attribute_ordered; |
|
| 3285 | + } |
|
| 3336 | 3286 | |
| 3337 | - /** If product has been ordered **/ |
|
| 3338 | - $output = ''; |
|
| 3339 | - if (!empty($sales_informations)) { |
|
| 3340 | - $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3341 | - $output .= '<ul>'; |
|
| 3342 | - foreach ($sales_informations as $sales_information) { |
|
| 3343 | - $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>'; |
|
| 3344 | - } |
|
| 3345 | - $output .= '</ul>'; |
|
| 3346 | - } else { |
|
| 3347 | - $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3348 | - } |
|
| 3287 | + public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3288 | + { |
|
| 3289 | + $response = array(); |
|
| 3290 | + /** Selected Product image **/ |
|
| 3291 | + $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3292 | + if (!empty($post_thumbnail_id)) { |
|
| 3293 | + $response['img_id'] = $post_thumbnail_id; |
|
| 3294 | + $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3295 | + $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3296 | + } |
|
| 3349 | 3297 | |
| 3350 | - echo $output; |
|
| 3351 | - } |
|
| 3298 | + /** check if have one variation **/ |
|
| 3299 | + if (!empty($variations) && count($variations) == 1) { |
|
| 3300 | + $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3301 | + if (!empty($variation_attached_image_id)) { |
|
| 3302 | + $response['img_id'] = $variation_attached_image_id; |
|
| 3303 | + $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3304 | + $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3305 | + } |
|
| 3306 | + } |
|
| 3307 | + return $response; |
|
| 3308 | + } |
|
| 3352 | 3309 | |
| 3353 | - public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3354 | - { |
|
| 3355 | - global $wpdb, $wpshop_payment; |
|
| 3356 | - $output = ''; |
|
| 3357 | - $tpl_component = array(); |
|
| 3358 | - /** Get attribute order for current product */ |
|
| 3359 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3360 | - $output_order = array(); |
|
| 3361 | - if (count($product_attribute_order_detail) > 0) { |
|
| 3362 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3363 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3364 | - if (!empty($attribute_def->code)) { |
|
| 3365 | - $output_order[$attribute_def->code] = $position; |
|
| 3366 | - } |
|
| 3367 | - |
|
| 3368 | - } |
|
| 3369 | - } |
|
| 3370 | - } |
|
| 3371 | - $variation_attribute_ordered = array(); |
|
| 3372 | - |
|
| 3373 | - /** Check if product is a variation and change his name **/ |
|
| 3374 | - $product_post_type = get_post_type($the_product['product_id']); |
|
| 3375 | - if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3376 | - $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3377 | - $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3378 | - $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3379 | - } |
|
| 3310 | + /** Add a meta box of product sales history in product administration panel **/ |
|
| 3311 | + public function meta_box_product_sale_informations() |
|
| 3312 | + { |
|
| 3313 | + global $post; |
|
| 3314 | + $product_id = $post->ID; |
|
| 3315 | + |
|
| 3316 | + $variations = self::get_variation($product_id); |
|
| 3317 | + |
|
| 3318 | + $sales_informations = array(); |
|
| 3319 | + /** Query **/ |
|
| 3320 | + $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3321 | + $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'))); |
|
| 3322 | + $orders = new WP_Query($query_args); |
|
| 3323 | + if (!empty($orders) && !empty($orders->posts)) { |
|
| 3324 | + foreach ($orders->posts as $order) { |
|
| 3325 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3326 | + $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3327 | + $sales_informations[] = array( |
|
| 3328 | + 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3329 | + 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3330 | + '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'] : '', |
|
| 3331 | + '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'] : '', |
|
| 3332 | + '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'] : '', |
|
| 3333 | + ); |
|
| 3334 | + } |
|
| 3335 | + } |
|
| 3380 | 3336 | |
| 3381 | - foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3382 | - if ($product_definition_key != 'item_meta') { |
|
| 3383 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3384 | - if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3385 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3386 | - } |
|
| 3387 | - } else { |
|
| 3388 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3389 | - } |
|
| 3390 | - } |
|
| 3337 | + /** If product has been ordered **/ |
|
| 3338 | + $output = ''; |
|
| 3339 | + if (!empty($sales_informations)) { |
|
| 3340 | + $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3341 | + $output .= '<ul>'; |
|
| 3342 | + foreach ($sales_informations as $sales_information) { |
|
| 3343 | + $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>'; |
|
| 3344 | + } |
|
| 3345 | + $output .= '</ul>'; |
|
| 3346 | + } else { |
|
| 3347 | + $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3348 | + } |
|
| 3391 | 3349 | |
| 3392 | - ksort($variation_attribute_ordered['attribute_list']); |
|
| 3393 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3394 | - foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3395 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3396 | - } |
|
| 3350 | + echo $output; |
|
| 3351 | + } |
|
| 3397 | 3352 | |
| 3398 | - /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3399 | - $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3400 | - if (!empty($attribute_list)) { |
|
| 3401 | - foreach ($attribute_list as $attribute_def) { |
|
| 3402 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3403 | - } |
|
| 3404 | - } |
|
| 3353 | + public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3354 | + { |
|
| 3355 | + global $wpdb, $wpshop_payment; |
|
| 3356 | + $output = ''; |
|
| 3357 | + $tpl_component = array(); |
|
| 3358 | + /** Get attribute order for current product */ |
|
| 3359 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3360 | + $output_order = array(); |
|
| 3361 | + if (count($product_attribute_order_detail) > 0) { |
|
| 3362 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3363 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3364 | + if (!empty($attribute_def->code)) { |
|
| 3365 | + $output_order[$attribute_def->code] = $position; |
|
| 3366 | + } |
|
| 3405 | 3367 | |
| 3406 | - /** Fill the array with all prices for different variations */ |
|
| 3407 | - foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3408 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3409 | - } |
|
| 3368 | + } |
|
| 3369 | + } |
|
| 3370 | + } |
|
| 3371 | + $variation_attribute_ordered = array(); |
|
| 3372 | + |
|
| 3373 | + /** Check if product is a variation and change his name **/ |
|
| 3374 | + $product_post_type = get_post_type($the_product['product_id']); |
|
| 3375 | + if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3376 | + $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3377 | + $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3378 | + $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3379 | + } |
|
| 3410 | 3380 | |
| 3411 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3412 | - $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3413 | - $post_list_with_options = $wpdb->get_results($query); |
|
| 3414 | - if (!empty($post_list_with_options)) { |
|
| 3415 | - $additionnal_price = 0; |
|
| 3416 | - foreach ($post_list_with_options as $product_info) { |
|
| 3417 | - $product_meta = unserialize($product_info->meta_value); |
|
| 3418 | - if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3419 | - $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3420 | - |
|
| 3421 | - $the_product = array_merge(array( |
|
| 3422 | - 'product_id' => $product_info->post_id, |
|
| 3423 | - 'product_qty' => 1, |
|
| 3424 | - ), $product); |
|
| 3425 | - |
|
| 3426 | - $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3427 | - $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3428 | - |
|
| 3429 | - $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)); |
|
| 3430 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3431 | - } |
|
| 3432 | - } |
|
| 3433 | - } |
|
| 3381 | + foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3382 | + if ($product_definition_key != 'item_meta') { |
|
| 3383 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3384 | + if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3385 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3386 | + } |
|
| 3387 | + } else { |
|
| 3388 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3389 | + } |
|
| 3390 | + } |
|
| 3434 | 3391 | |
| 3435 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3436 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3437 | - if (!empty($additionnal_price)) { |
|
| 3438 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3439 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3440 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3441 | - } |
|
| 3392 | + ksort($variation_attribute_ordered['attribute_list']); |
|
| 3393 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3394 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3395 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3396 | + } |
|
| 3442 | 3397 | |
| 3443 | - /** Call informtion for partial payment */ |
|
| 3444 | - $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3445 | - $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3398 | + /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3399 | + $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3400 | + if (!empty($attribute_list)) { |
|
| 3401 | + foreach ($attribute_list as $attribute_def) { |
|
| 3402 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3403 | + } |
|
| 3404 | + } |
|
| 3446 | 3405 | |
| 3447 | - /** Define the current selected currency for the order summary */ |
|
| 3406 | + /** Fill the array with all prices for different variations */ |
|
| 3407 | + foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3408 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3409 | + } |
|
| 3410 | + |
|
| 3411 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3412 | + $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3413 | + $post_list_with_options = $wpdb->get_results($query); |
|
| 3414 | + if (!empty($post_list_with_options)) { |
|
| 3415 | + $additionnal_price = 0; |
|
| 3416 | + foreach ($post_list_with_options as $product_info) { |
|
| 3417 | + $product_meta = unserialize($product_info->meta_value); |
|
| 3418 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3419 | + $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3420 | + |
|
| 3421 | + $the_product = array_merge(array( |
|
| 3422 | + 'product_id' => $product_info->post_id, |
|
| 3423 | + 'product_qty' => 1, |
|
| 3424 | + ), $product); |
|
| 3425 | + |
|
| 3426 | + $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3427 | + $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3428 | + |
|
| 3429 | + $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)); |
|
| 3430 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3431 | + } |
|
| 3432 | + } |
|
| 3433 | + } |
|
| 3434 | + |
|
| 3435 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3436 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3437 | + if (!empty($additionnal_price)) { |
|
| 3438 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3439 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3440 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3441 | + } |
|
| 3442 | + |
|
| 3443 | + /** Call informtion for partial payment */ |
|
| 3444 | + $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3445 | + $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3446 | + |
|
| 3447 | + /** Define the current selected currency for the order summary */ |
|
| 3448 | 3448 | // $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
| 3449 | - $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3450 | - return $output; |
|
| 3451 | - } |
|
| 3449 | + $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3450 | + return $output; |
|
| 3451 | + } |
|
| 3452 | 3452 | |
| 3453 | - /** |
|
| 3454 | - * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3455 | - * @param string $ID ID product variations or not |
|
| 3456 | - * @return string Return ID |
|
| 3457 | - */ |
|
| 3458 | - public static function get_id_variation($ID) |
|
| 3459 | - { |
|
| 3460 | - $result = explode('__', $ID); |
|
| 3461 | - return end($result); |
|
| 3462 | - } |
|
| 3453 | + /** |
|
| 3454 | + * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3455 | + * @param string $ID ID product variations or not |
|
| 3456 | + * @return string Return ID |
|
| 3457 | + */ |
|
| 3458 | + public static function get_id_variation($ID) |
|
| 3459 | + { |
|
| 3460 | + $result = explode('__', $ID); |
|
| 3461 | + return end($result); |
|
| 3462 | + } |
|
| 3463 | 3463 | |
| 3464 | - /** |
|
| 3465 | - * Update all variations definitions who not modified |
|
| 3466 | - * @param array $new_value |
|
| 3467 | - * @param array $old_value |
|
| 3468 | - * @return array $new_value |
|
| 3469 | - */ |
|
| 3470 | - public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3471 | - { |
|
| 3472 | - global $wpdb; |
|
| 3473 | - $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') . '%'); |
|
| 3474 | - foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3475 | - $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3476 | - $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3477 | - update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3478 | - } |
|
| 3479 | - return $new_value; |
|
| 3480 | - } |
|
| 3464 | + /** |
|
| 3465 | + * Update all variations definitions who not modified |
|
| 3466 | + * @param array $new_value |
|
| 3467 | + * @param array $old_value |
|
| 3468 | + * @return array $new_value |
|
| 3469 | + */ |
|
| 3470 | + public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3471 | + { |
|
| 3472 | + global $wpdb; |
|
| 3473 | + $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') . '%'); |
|
| 3474 | + foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3475 | + $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3476 | + $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3477 | + update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3478 | + } |
|
| 3479 | + return $new_value; |
|
| 3480 | + } |
|
| 3481 | 3481 | |
| 3482 | - public static function variation_parameters_save($current_post_id, $options) |
|
| 3483 | - { |
|
| 3482 | + public static function variation_parameters_save($current_post_id, $options) |
|
| 3483 | + { |
|
| 3484 | 3484 | $variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true); |
| 3485 | - $variation_post_meta['options'] = $options; |
|
| 3485 | + $variation_post_meta['options'] = $options; |
|
| 3486 | 3486 | $variation_post_meta['follow_general_config'] = true; |
| 3487 | 3487 | $variations = wpshop_attributes::get_variation_available_attribute($current_post_id); |
| 3488 | 3488 | if( !empty( $variations['available'] ) ) { |
@@ -3491,6 +3491,6 @@ discard block |
||
| 3491 | 3491 | } |
| 3492 | 3492 | } |
| 3493 | 3493 | //$variations = (array) array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array()));exit(); |
| 3494 | - update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3495 | - } |
|
| 3494 | + update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3495 | + } |
|
| 3496 | 3496 | } |
@@ -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; |
@@ -572,12 +572,12 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | $products = array(); |
| 574 | 574 | $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
| 575 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 575 | + $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 576 | 576 | |
| 577 | 577 | if (!empty($data)) { |
| 578 | 578 | if ($data['data_type_to_use'] == 'custom') { |
| 579 | 579 | // Find which table to take |
| 580 | - 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;} |
|
| 580 | + 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; } |
|
| 581 | 581 | |
| 582 | 582 | if (isset($table_name)) { |
| 583 | 583 | // If the value is an id of a select, radio or checkbox |
@@ -727,11 +727,11 @@ discard block |
||
| 727 | 727 | if (!empty($atts['product_type'])) { |
| 728 | 728 | switch ($atts['product_type']) { |
| 729 | 729 | case 'related': |
| 730 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 730 | + $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID(); |
|
| 731 | 731 | $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
| 732 | 732 | $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; |
| 733 | 733 | |
| 734 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 734 | + $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 735 | 735 | if (!empty($pids) && !empty($pids[0])) { |
| 736 | 736 | $pid = implode(',', $pids); |
| 737 | 737 | } |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | { |
| 1251 | 1251 | global $wpdb; |
| 1252 | 1252 | |
| 1253 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1253 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST; |
|
| 1254 | 1254 | // Apply a filter to extra actions |
| 1255 | 1255 | $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
| 1256 | 1256 | |
@@ -1306,7 +1306,7 @@ discard block |
||
| 1306 | 1306 | $attributeValue = str_replace(',', '.', $attributeValue); |
| 1307 | 1307 | } |
| 1308 | 1308 | if (($attributeType == 'integer') && !is_array($attributeValue)) { |
| 1309 | - $attributeValue = (int) $attributeValue; |
|
| 1309 | + $attributeValue = (int)$attributeValue; |
|
| 1310 | 1310 | } |
| 1311 | 1311 | $productMetaDatas[$attributeCode] = $attributeValue; |
| 1312 | 1312 | } |
@@ -1356,7 +1356,7 @@ discard block |
||
| 1356 | 1356 | $attributeValue = str_replace(',', '.', $attribute->$value_key); |
| 1357 | 1357 | } |
| 1358 | 1358 | if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
| 1359 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1359 | + $attributeValue = (int)$attribute->$value_key; |
|
| 1360 | 1360 | } |
| 1361 | 1361 | $variation_metadata[$attribute->code] = $attribute->$value_key; |
| 1362 | 1362 | } |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | $attributeValue = str_replace(',', '.', $attributeValue); |
| 1370 | 1370 | } |
| 1371 | 1371 | if (($attributeType == 'integer') && !is_array($attributeValue)) { |
| 1372 | - $attributeValue = (int) $attributeValue; |
|
| 1372 | + $attributeValue = (int)$attributeValue; |
|
| 1373 | 1373 | } |
| 1374 | 1374 | $variation_metadata[$attributeCode] = $attributeValue; |
| 1375 | 1375 | } |
@@ -1705,13 +1705,13 @@ discard block |
||
| 1705 | 1705 | if (!empty($product_price_infos)) { |
| 1706 | 1706 | $tpl_component_price = array(); |
| 1707 | 1707 | /** Price piloting **/ |
| 1708 | - $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
|
| 1709 | - $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
|
| 1708 | + $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1709 | + $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : ''; |
|
| 1710 | 1710 | $price_ploting = get_option('wpshop_shop_price_piloting'); |
| 1711 | 1711 | $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'])) : ''; |
| 1712 | 1712 | $variations = wpshop_products::get_variation($product_id); |
| 1713 | 1713 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1714 | - if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
|
| 1714 | + if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) { |
|
| 1715 | 1715 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1716 | 1716 | } |
| 1717 | 1717 | $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
@@ -2154,7 +2154,7 @@ discard block |
||
| 2154 | 2154 | } |
| 2155 | 2155 | |
| 2156 | 2156 | $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
| 2157 | - $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
|
| 2157 | + $template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id); |
|
| 2158 | 2158 | |
| 2159 | 2159 | $tpl_component = array(); |
| 2160 | 2160 | $tpl_component['PRODUCT_ID'] = $product_id; |
@@ -3117,7 +3117,7 @@ discard block |
||
| 3117 | 3117 | * Since 1.4.3.7 |
| 3118 | 3118 | * L'option du produit remplace le prix du produit de tête. |
| 3119 | 3119 | */ |
| 3120 | - if( true ) { |
|
| 3120 | + if (true) { |
|
| 3121 | 3121 | //Replace the product price |
| 3122 | 3122 | if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
| 3123 | 3123 | $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
@@ -3485,9 +3485,9 @@ discard block |
||
| 3485 | 3485 | $variation_post_meta['options'] = $options; |
| 3486 | 3486 | $variation_post_meta['follow_general_config'] = true; |
| 3487 | 3487 | $variations = wpshop_attributes::get_variation_available_attribute($current_post_id); |
| 3488 | - if( !empty( $variations['available'] ) ) { |
|
| 3489 | - foreach( $variations['available'] as $key => $value ) { |
|
| 3490 | - echo '<pre>'; print_r( $value ); echo '</pre>'; |
|
| 3488 | + if (!empty($variations['available'])) { |
|
| 3489 | + foreach ($variations['available'] as $key => $value) { |
|
| 3490 | + echo '<pre>'; print_r($value); echo '</pre>'; |
|
| 3491 | 3491 | } |
| 3492 | 3492 | } |
| 3493 | 3493 | //$variations = (array) array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array()));exit(); |
@@ -1,62 +1,62 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_shipping_mode_ajax_actions { |
| 3 | 3 | |
| 4 | 4 | function __construct() { |
| 5 | 5 | /** Ajax Actions **/ |
| 6 | - add_action('wp_ajax_save_shipping_rule',array( $this, 'wpshop_ajax_save_shipping_rule')); |
|
| 7 | - add_action('wp_ajax_display_shipping_rules',array( $this, 'wpshop_ajax_display_shipping_rules')); |
|
| 8 | - add_action('wp_ajax_delete_shipping_rule',array( $this, 'wpshop_ajax_delete_shipping_rule')); |
|
| 9 | - add_action('wp_ajax_wps_add_new_shipping_mode',array( $this, 'wps_add_new_shipping_mode')); |
|
| 10 | - add_action('wp_ajax_wps_delete_shipping_mode',array( $this, 'wps_delete_shipping_mode')); |
|
| 11 | - add_action('wp_ajax_wps_reload_shipping_mode',array( $this, 'wps_reload_shipping_mode')); |
|
| 12 | - add_action('wp_ajax_wps_calculate_shipping_cost',array( $this, 'wps_calculate_shipping_cost')); |
|
| 13 | - add_action( 'wp_ajax_wps_load_shipping_methods', array(&$this, 'wps_load_shipping_methods') ); |
|
| 6 | + add_action('wp_ajax_save_shipping_rule', array($this, 'wpshop_ajax_save_shipping_rule')); |
|
| 7 | + add_action('wp_ajax_display_shipping_rules', array($this, 'wpshop_ajax_display_shipping_rules')); |
|
| 8 | + add_action('wp_ajax_delete_shipping_rule', array($this, 'wpshop_ajax_delete_shipping_rule')); |
|
| 9 | + add_action('wp_ajax_wps_add_new_shipping_mode', array($this, 'wps_add_new_shipping_mode')); |
|
| 10 | + add_action('wp_ajax_wps_delete_shipping_mode', array($this, 'wps_delete_shipping_mode')); |
|
| 11 | + add_action('wp_ajax_wps_reload_shipping_mode', array($this, 'wps_reload_shipping_mode')); |
|
| 12 | + add_action('wp_ajax_wps_calculate_shipping_cost', array($this, 'wps_calculate_shipping_cost')); |
|
| 13 | + add_action('wp_ajax_wps_load_shipping_methods', array(&$this, 'wps_load_shipping_methods')); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * AJAX - Save custom Rules |
| 18 | 18 | **/ |
| 19 | - function wpshop_ajax_save_shipping_rule(){ |
|
| 20 | - check_ajax_referer( 'wpshop_ajax_save_shipping_rule' ); |
|
| 19 | + function wpshop_ajax_save_shipping_rule() { |
|
| 20 | + check_ajax_referer('wpshop_ajax_save_shipping_rule'); |
|
| 21 | 21 | |
| 22 | 22 | global $wpdb; |
| 23 | 23 | $wps_shipping = new wps_shipping(); |
| 24 | 24 | $status = false; |
| 25 | 25 | $reponse = array(); |
| 26 | - $fees_data = ( !empty($_POST['fees_data']) ) ? ( $_POST['fees_data'] ) : null; |
|
| 27 | - $weight_rule = ( !empty($_POST['weight_rule']) ) ? wpshop_tools::varSanitizer( $_POST['weight_rule'] ) : null; |
|
| 28 | - $shipping_price = ( !empty($_POST['shipping_price']) ) ? wpshop_tools::varSanitizer( $_POST['shipping_price'] ) : 0; |
|
| 29 | - $selected_country = ( !empty($_POST['selected_country']) ) ? wpshop_tools::varSanitizer( $_POST['selected_country'] ) : null; |
|
| 30 | - $shipping_rules = $wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 26 | + $fees_data = (!empty($_POST['fees_data'])) ? ($_POST['fees_data']) : null; |
|
| 27 | + $weight_rule = (!empty($_POST['weight_rule'])) ? wpshop_tools::varSanitizer($_POST['weight_rule']) : null; |
|
| 28 | + $shipping_price = (!empty($_POST['shipping_price'])) ? wpshop_tools::varSanitizer($_POST['shipping_price']) : 0; |
|
| 29 | + $selected_country = (!empty($_POST['selected_country'])) ? wpshop_tools::varSanitizer($_POST['selected_country']) : null; |
|
| 30 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 31 | 31 | |
| 32 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 33 | - $query = $wpdb->prepare('SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 34 | - $unity = $wpdb->get_var( $query ); |
|
| 32 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 33 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 34 | + $unity = $wpdb->get_var($query); |
|
| 35 | 35 | |
| 36 | - $weight_rule = ( !empty($unity) && $unity == 'kg' ) ? $weight_rule * 1000 : $weight_rule; |
|
| 36 | + $weight_rule = (!empty($unity) && $unity == 'kg') ? $weight_rule * 1000 : $weight_rule; |
|
| 37 | 37 | //Check if this shipping rule (same country and same weight) already exist in the shipping rules definition |
| 38 | - if( !empty($shipping_rules) ) { |
|
| 38 | + if (!empty($shipping_rules)) { |
|
| 39 | 39 | $existing_country = false; |
| 40 | 40 | $tab_key = -1; |
| 41 | - foreach ( $shipping_rules as $key=>$shipping_rule) { |
|
| 42 | - if ( $shipping_rule['destination'] == $selected_country) { |
|
| 41 | + foreach ($shipping_rules as $key=>$shipping_rule) { |
|
| 42 | + if ($shipping_rule['destination'] == $selected_country) { |
|
| 43 | 43 | $existing_country = true; |
| 44 | 44 | $tab_key = $key; |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - if ( $existing_country && $tab_key > -1) { |
|
| 47 | + if ($existing_country && $tab_key > -1) { |
|
| 48 | 48 | $shipping_rules[$tab_key]['fees'][$weight_rule] = $shipping_price; |
| 49 | 49 | } |
| 50 | 50 | else { |
| 51 | - $shipping_rules[] = array( 'destination' => $selected_country, 'rule' => 'weight', 'fees' => array($weight_rule => $shipping_price) ); |
|
| 51 | + $shipping_rules[] = array('destination' => $selected_country, 'rule' => 'weight', 'fees' => array($weight_rule => $shipping_price)); |
|
| 52 | 52 | } |
| 53 | 53 | $status = true; |
| 54 | 54 | } |
| 55 | 55 | else { |
| 56 | - $shipping_rules = array( '0' => array('destination' => $selected_country, 'rule' => 'weight', 'fees' => array( $weight_rule => $shipping_price)) ); |
|
| 56 | + $shipping_rules = array('0' => array('destination' => $selected_country, 'rule' => 'weight', 'fees' => array($weight_rule => $shipping_price))); |
|
| 57 | 57 | $status = true; |
| 58 | 58 | } |
| 59 | - $reponse = array('status' => $status, 'reponse' => $wps_shipping->shipping_fees_array_2_string( $shipping_rules ) ); |
|
| 59 | + $reponse = array('status' => $status, 'reponse' => $wps_shipping->shipping_fees_array_2_string($shipping_rules)); |
|
| 60 | 60 | echo json_encode($reponse); |
| 61 | 61 | die(); |
| 62 | 62 | } |
@@ -65,18 +65,18 @@ discard block |
||
| 65 | 65 | * AJAX - Delete Custom shipping Rule |
| 66 | 66 | */ |
| 67 | 67 | function wpshop_ajax_delete_shipping_rule() { |
| 68 | - check_ajax_referer( 'wpshop_ajax_delete_shipping_rule' ); |
|
| 68 | + check_ajax_referer('wpshop_ajax_delete_shipping_rule'); |
|
| 69 | 69 | |
| 70 | 70 | global $wpdb; |
| 71 | 71 | $wps_shipping = new wps_shipping(); |
| 72 | - $fees_data = ( !empty($_POST['fees_data']) ) ? ( $_POST['fees_data'] ) : null; |
|
| 73 | - $country_and_weight = ( !empty($_POST['country_and_weight']) ) ? sanitize_text_field( $_POST['country_and_weight'] ) : null; |
|
| 72 | + $fees_data = (!empty($_POST['fees_data'])) ? ($_POST['fees_data']) : null; |
|
| 73 | + $country_and_weight = (!empty($_POST['country_and_weight'])) ? sanitize_text_field($_POST['country_and_weight']) : null; |
|
| 74 | 74 | $datas = explode("|", $country_and_weight); |
| 75 | 75 | $country = $datas[0]; |
| 76 | 76 | $weight = $datas[1]; |
| 77 | 77 | $shipping_mode_id = $datas[2]; |
| 78 | 78 | |
| 79 | - $shipping_rules = $wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 79 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 80 | 80 | |
| 81 | 81 | /** Check the default weight unity **/ |
| 82 | 82 | // $weight_unity_id = get_option('wpshop_shop_default_weight_unity'); |
@@ -89,46 +89,46 @@ discard block |
||
| 89 | 89 | // } |
| 90 | 90 | // } |
| 91 | 91 | |
| 92 | - if ( array_key_exists($country, $shipping_rules) ) { |
|
| 93 | - if ( array_key_exists((string)$weight, $shipping_rules[$country]['fees']) ) { |
|
| 92 | + if (array_key_exists($country, $shipping_rules)) { |
|
| 93 | + if (array_key_exists((string)$weight, $shipping_rules[$country]['fees'])) { |
|
| 94 | 94 | unset($shipping_rules[$country]['fees'][$weight]); |
| 95 | 95 | } |
| 96 | - if ( empty($shipping_rules[$country]['fees']) ) { |
|
| 96 | + if (empty($shipping_rules[$country]['fees'])) { |
|
| 97 | 97 | unset($shipping_rules[$country]); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | } |
| 101 | - foreach ( $shipping_rules as $k=>$shipping_rule ) { |
|
| 102 | - if ( !isset($shipping_rule['fees']) ) { |
|
| 101 | + foreach ($shipping_rules as $k=>$shipping_rule) { |
|
| 102 | + if (!isset($shipping_rule['fees'])) { |
|
| 103 | 103 | unset($shipping_rules[$k]); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $status = true; |
| 108 | 108 | |
| 109 | - if ( !empty( $shipping_rules ) ) { |
|
| 110 | - $rules = $wps_shipping->shipping_fees_array_2_string( $shipping_rules ); |
|
| 109 | + if (!empty($shipping_rules)) { |
|
| 110 | + $rules = $wps_shipping->shipping_fees_array_2_string($shipping_rules); |
|
| 111 | 111 | } |
| 112 | 112 | else { |
| 113 | 113 | $rules = ''; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - wp_die( json_encode( array( 'status' => $status, 'reponse' => $rules, ) ) ); |
|
| 116 | + wp_die(json_encode(array('status' => $status, 'reponse' => $rules,))); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * AJAX - Display Created custom shipping rules |
| 121 | 121 | */ |
| 122 | - function wpshop_ajax_display_shipping_rules () { |
|
| 123 | - check_ajax_referer( 'wpshop_ajax_display_shipping_rules' ); |
|
| 122 | + function wpshop_ajax_display_shipping_rules() { |
|
| 123 | + check_ajax_referer('wpshop_ajax_display_shipping_rules'); |
|
| 124 | 124 | |
| 125 | 125 | $status = false; |
| 126 | - $fees_data = ( !empty($_POST['fees_data']) ) ? ( $_POST['fees_data'] ) : null; |
|
| 127 | - $shipping_mode_id = ( !empty($_POST['shipping_mode_id']) ) ? sanitize_title($_POST['shipping_mode_id']) : null; |
|
| 126 | + $fees_data = (!empty($_POST['fees_data'])) ? ($_POST['fees_data']) : null; |
|
| 127 | + $shipping_mode_id = (!empty($_POST['shipping_mode_id'])) ? sanitize_title($_POST['shipping_mode_id']) : null; |
|
| 128 | 128 | $result = ''; |
| 129 | - if( !empty($fees_data) ) { |
|
| 129 | + if (!empty($fees_data)) { |
|
| 130 | 130 | $wps_shipping_mode_ctr = new wps_shipping_mode_ctr(); |
| 131 | - $result = $wps_shipping_mode_ctr->generate_shipping_rules_table( $fees_data, $shipping_mode_id ); |
|
| 131 | + $result = $wps_shipping_mode_ctr->generate_shipping_rules_table($fees_data, $shipping_mode_id); |
|
| 132 | 132 | $status = true; |
| 133 | 133 | } |
| 134 | 134 | else { |
@@ -146,38 +146,38 @@ discard block |
||
| 146 | 146 | * AJAX - Reload shippig mode interface |
| 147 | 147 | */ |
| 148 | 148 | function wps_reload_shipping_mode() { |
| 149 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 149 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 150 | 150 | |
| 151 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_shipping_mode' ) ) |
|
| 151 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_shipping_mode')) |
|
| 152 | 152 | wp_die(); |
| 153 | 153 | |
| 154 | 154 | $status = false; $allow_order = true; |
| 155 | 155 | $result = ''; |
| 156 | - $address_id = !empty( $_POST['address_id'] ) ? (int) $_POST['address_id'] : 0; |
|
| 157 | - if ( !empty($address_id) ) { |
|
| 156 | + $address_id = !empty($_POST['address_id']) ? (int)$_POST['address_id'] : 0; |
|
| 157 | + if (!empty($address_id)) { |
|
| 158 | 158 | $_SESSION['shipping_address'] = $address_id; |
| 159 | 159 | } |
| 160 | - $shipping_address_id = ( !empty($_SESSION['shipping_address']) ) ? $_SESSION['shipping_address'] : ''; |
|
| 161 | - if ( !empty($shipping_address_id) ) { |
|
| 160 | + $shipping_address_id = (!empty($_SESSION['shipping_address'])) ? $_SESSION['shipping_address'] : ''; |
|
| 161 | + if (!empty($shipping_address_id)) { |
|
| 162 | 162 | //$result = self::generate_shipping_mode_for_an_address(); |
| 163 | 163 | $wps_shipping_mode_ctr = new wps_shipping_mode_ctr(); |
| 164 | 164 | // $shipping_modes = $wps_shipping_mode_ctr->generate_shipping_mode_for_an_address( intval($_POST['address_id']) ); |
| 165 | 165 | |
| 166 | 166 | $status = $allow_order = $shipping_modes[0]; |
| 167 | - if( empty( $shipping_modes[0]) || $shipping_modes[0] == false ) { |
|
| 167 | + if (empty($shipping_modes[0]) || $shipping_modes[0] == false) { |
|
| 168 | 168 | $status = false; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $result = $shipping_modes[1]; |
| 172 | 172 | |
| 173 | - if ( $status == false ) { |
|
| 173 | + if ($status == false) { |
|
| 174 | 174 | $allow_order = false; |
| 175 | - $result = '<div class="error_bloc">' .__('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop' ). '</div>'; |
|
| 175 | + $result = '<div class="error_bloc">' . __('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop') . '</div>'; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | } |
| 179 | - $response = array('status' => $status, 'response' => $result, 'allow_order' => $allow_order ); |
|
| 180 | - echo json_encode( $response ); |
|
| 179 | + $response = array('status' => $status, 'response' => $result, 'allow_order' => $allow_order); |
|
| 180 | + echo json_encode($response); |
|
| 181 | 181 | die(); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -185,26 +185,26 @@ discard block |
||
| 185 | 185 | * AJAX - Calculate Shipping cost |
| 186 | 186 | */ |
| 187 | 187 | function wps_calculate_shipping_cost() { |
| 188 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 188 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 189 | 189 | |
| 190 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_calculate_shipping_cost' ) ) |
|
| 190 | + if (!wp_verify_nonce($_wpnonce, 'wps_calculate_shipping_cost')) |
|
| 191 | 191 | wp_die(); |
| 192 | 192 | |
| 193 | 193 | $status = false; |
| 194 | 194 | $result = ''; |
| 195 | 195 | $chosen_method = !empty($_POST['chosen_method']) ? wpshop_tools::varSanitizer($_POST['chosen_method']) : null; |
| 196 | 196 | |
| 197 | - if( !empty($chosen_method) ) { |
|
| 197 | + if (!empty($chosen_method)) { |
|
| 198 | 198 | $_SESSION['shipping_method'] = $chosen_method; |
| 199 | 199 | $wps_cart = new wps_cart(); |
| 200 | - $order = $wps_cart->calcul_cart_information( array() ); |
|
| 200 | + $order = $wps_cart->calcul_cart_information(array()); |
|
| 201 | 201 | $wps_cart->store_cart_in_session($order); |
| 202 | 202 | |
| 203 | 203 | $status = true; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $response = array('status' => $status ); |
|
| 207 | - echo json_encode( $response ); |
|
| 206 | + $response = array('status' => $status); |
|
| 207 | + echo json_encode($response); |
|
| 208 | 208 | die(); |
| 209 | 209 | } |
| 210 | 210 | |
@@ -212,68 +212,68 @@ discard block |
||
| 212 | 212 | * AJAX - (New checkout Tunnel ) Load available shipping modes |
| 213 | 213 | */ |
| 214 | 214 | function wps_load_shipping_methods() { |
| 215 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 215 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 216 | 216 | |
| 217 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_load_shipping_methods' ) ) |
|
| 217 | + if (!wp_verify_nonce($_wpnonce, 'wps_load_shipping_methods')) |
|
| 218 | 218 | wp_die(); |
| 219 | 219 | |
| 220 | 220 | $status = true; $response = ''; |
| 221 | - $shipping_address_id = ( !empty($_POST['shipping_address']) ) ? intval( $_POST['shipping_address'] ) : null; |
|
| 222 | - if ( !empty($shipping_address_id) ) { |
|
| 221 | + $shipping_address_id = (!empty($_POST['shipping_address'])) ? intval($_POST['shipping_address']) : null; |
|
| 222 | + if (!empty($shipping_address_id)) { |
|
| 223 | 223 | // Check if element is an address |
| 224 | 224 | $check_address_type = get_post($shipping_address_id); |
| 225 | - if ( !empty($check_address_type) && $check_address_type->post_author == get_current_user_id() && $check_address_type->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ) { |
|
| 225 | + if (!empty($check_address_type) && $check_address_type->post_author == get_current_user_id() && $check_address_type->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) { |
|
| 226 | 226 | // Get address metadatas |
| 227 | - $address_metadata = get_post_meta( $shipping_address_id, '_wpshop_address_metadata', true ); |
|
| 228 | - if( !empty($address_metadata) && !empty($address_metadata['country']) ) { |
|
| 227 | + $address_metadata = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true); |
|
| 228 | + if (!empty($address_metadata) && !empty($address_metadata['country'])) { |
|
| 229 | 229 | $country = $address_metadata['country']; |
| 230 | 230 | $postcode = $address_metadata['postcode']; |
| 231 | - $shipping_methods = get_option( 'wps_shipping_mode' ); |
|
| 231 | + $shipping_methods = get_option('wps_shipping_mode'); |
|
| 232 | 232 | $available_shipping_methods = array(); |
| 233 | - if( !empty($shipping_methods) && !empty($shipping_methods['modes']) ) { |
|
| 233 | + if (!empty($shipping_methods) && !empty($shipping_methods['modes'])) { |
|
| 234 | 234 | // Check all shipping methods |
| 235 | - foreach( $shipping_methods['modes'] as $shipping_method_id => $shipping_method ){ |
|
| 236 | - if ( empty($shipping_method['limit_destination']) || ( empty($shipping_method['limit_destination']['country']) || ( !empty($shipping_method['limit_destination']['country']) && in_array($country, $shipping_method['limit_destination']['country']) ) ) ) { |
|
| 237 | - $available_shipping_methods[ $shipping_method_id ] = $shipping_method; |
|
| 235 | + foreach ($shipping_methods['modes'] as $shipping_method_id => $shipping_method) { |
|
| 236 | + if (empty($shipping_method['limit_destination']) || (empty($shipping_method['limit_destination']['country']) || (!empty($shipping_method['limit_destination']['country']) && in_array($country, $shipping_method['limit_destination']['country'])))) { |
|
| 237 | + $available_shipping_methods[$shipping_method_id] = $shipping_method; |
|
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | - if( !empty($available_shipping_methods) ) { |
|
| 241 | - foreach( $available_shipping_methods as $shipping_mode_id => $shipping_mode ) { |
|
| 240 | + if (!empty($available_shipping_methods)) { |
|
| 241 | + foreach ($available_shipping_methods as $shipping_mode_id => $shipping_mode) { |
|
| 242 | 242 | ob_start(); |
| 243 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/","frontend", "shipping-mode", "element") ); |
|
| 243 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/", "frontend", "shipping-mode", "element")); |
|
| 244 | 244 | $response .= ob_get_contents(); |
| 245 | 245 | ob_end_clean(); |
| 246 | 246 | |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | else { |
| 250 | - $response = '<div class="wps-alert-error">' .__( 'No shipping method available for your shipping address', 'wpshop' ). '</div>'; |
|
| 250 | + $response = '<div class="wps-alert-error">' . __('No shipping method available for your shipping address', 'wpshop') . '</div>'; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | } |
| 254 | 254 | else { |
| 255 | - $response = '<div class="wps-alert-info">' .__( 'No shipping method available', 'wpshop' ). '</div>'; |
|
| 255 | + $response = '<div class="wps-alert-info">' . __('No shipping method available', 'wpshop') . '</div>'; |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | else { |
| 261 | - $response = '<div class="wps-alert-info">' .__( 'Please select a shipping address to choose a shipping method', 'wpshop' ). '</div>'; |
|
| 261 | + $response = '<div class="wps-alert-info">' . __('Please select a shipping address to choose a shipping method', 'wpshop') . '</div>'; |
|
| 262 | 262 | } |
| 263 | - echo json_encode( array( 'status' => $status, 'response' => $response) ); |
|
| 263 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 264 | 264 | die(); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | function wps_add_new_shipping_mode() { |
| 269 | - check_ajax_referer( 'wps_add_new_shipping_mode' ); |
|
| 269 | + check_ajax_referer('wps_add_new_shipping_mode'); |
|
| 270 | 270 | |
| 271 | 271 | $status = false; $reponse = ''; |
| 272 | 272 | |
| 273 | - $k = 'wps_custom_shipping_mode_'.time(); |
|
| 273 | + $k = 'wps_custom_shipping_mode_' . time(); |
|
| 274 | 274 | $shipping_mode = array(); |
| 275 | 275 | ob_start(); |
| 276 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/", "backend", "shipping-mode") ); |
|
| 276 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/", "backend", "shipping-mode")); |
|
| 277 | 277 | $response .= ob_get_contents(); |
| 278 | 278 | ob_end_clean(); |
| 279 | 279 | |
@@ -281,23 +281,23 @@ discard block |
||
| 281 | 281 | jQuery("select.chosen_select").chosen( WPSHOP_CHOSEN_ATTRS ); |
| 282 | 282 | } );</script>'; |
| 283 | 283 | |
| 284 | - $status = ( !empty($response) ) ? true : false; |
|
| 284 | + $status = (!empty($response)) ? true : false; |
|
| 285 | 285 | |
| 286 | - echo json_encode( array( 'status' => $status, 'response' => $response) ); |
|
| 286 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 287 | 287 | wp_die(); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | function wps_delete_shipping_mode() { |
| 291 | - check_ajax_referer( 'wps_delete_shipping_mode' ); |
|
| 292 | - $shipping_mode = ! empty( $_POST['shipping_mode'] ) ? sanitize_text_field( $_POST['shipping_mode'] ) : null; |
|
| 293 | - $wps_shipping_mode = get_option( 'wps_shipping_mode' ); |
|
| 294 | - if ( ! empty( $wps_shipping_mode['modes'] ) && array_key_exists( $shipping_mode, $wps_shipping_mode['modes'] ) ) { |
|
| 295 | - unset( $wps_shipping_mode['modes'][ $shipping_mode ] ); |
|
| 296 | - if ( ! empty( $wps_shipping_mode['default_choice'] ) && $wps_shipping_mode['default_choice'] === $shipping_mode ) { |
|
| 291 | + check_ajax_referer('wps_delete_shipping_mode'); |
|
| 292 | + $shipping_mode = !empty($_POST['shipping_mode']) ? sanitize_text_field($_POST['shipping_mode']) : null; |
|
| 293 | + $wps_shipping_mode = get_option('wps_shipping_mode'); |
|
| 294 | + if (!empty($wps_shipping_mode['modes']) && array_key_exists($shipping_mode, $wps_shipping_mode['modes'])) { |
|
| 295 | + unset($wps_shipping_mode['modes'][$shipping_mode]); |
|
| 296 | + if (!empty($wps_shipping_mode['default_choice']) && $wps_shipping_mode['default_choice'] === $shipping_mode) { |
|
| 297 | 297 | $wps_shipping_mode['default_choice'] = 'default_shipping_mode'; |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | - update_option( 'wps_shipping_mode', $wps_shipping_mode ); |
|
| 300 | + update_option('wps_shipping_mode', $wps_shipping_mode); |
|
| 301 | 301 | wp_send_json_success(); |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | $wps_shipping = new wps_shipping(); |
| 3 | -$shipping_rules = $wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 3 | +$shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 4 | 4 | |
| 5 | -if( !empty($shipping_rules) ) : ?> |
|
| 5 | +if (!empty($shipping_rules)) : ?> |
|
| 6 | 6 | |
| 7 | 7 | <div class="wps-table-header wps-table-row"> |
| 8 | 8 | <div class="wps-table-cell"><?php _e('Country', 'wpshop'); ?></div> |
@@ -11,22 +11,22 @@ discard block |
||
| 11 | 11 | <div class="wps-table-cell"><?php _e('Delete', 'wpshop'); ?></div> |
| 12 | 12 | </div> |
| 13 | 13 | |
| 14 | - <?php foreach ( $shipping_rules as $shipping_rule ) : |
|
| 14 | + <?php foreach ($shipping_rules as $shipping_rule) : |
|
| 15 | 15 | $country_name = ''; |
| 16 | 16 | $code_country = explode('-', $shipping_rule['destination']); |
| 17 | 17 | $code_country = $code_country[0]; |
| 18 | - foreach ( $country_list as $key=>$country ) : |
|
| 19 | - if ( $key == $code_country ) : |
|
| 18 | + foreach ($country_list as $key=>$country) : |
|
| 19 | + if ($key == $code_country) : |
|
| 20 | 20 | $country_name = $country; |
| 21 | 21 | endif; |
| 22 | 22 | endforeach; |
| 23 | - if ( !empty($shipping_rule['fees']) ) : |
|
| 24 | - foreach( $shipping_rule['fees'] as $p => $fee ) : ?> |
|
| 23 | + if (!empty($shipping_rule['fees'])) : |
|
| 24 | + foreach ($shipping_rule['fees'] as $p => $fee) : ?> |
|
| 25 | 25 | <div class="wps-table-content wps-table-row" data-element="<?php echo $shipping_rule['destination']; ?>|<?php echo $p; ?>|<?php echo $fee; ?>"> |
| 26 | 26 | <div class="wps-table-cell"><?php echo $country_name; ?> (<?php echo $shipping_rule['destination']; ?>)</div> |
| 27 | - <div class="wps-table-cell"><?php echo ($unity == 'kg') ? $p / 1000 : $p; ?> <?php _e( $unity, 'wpshop')?></div> |
|
| 27 | + <div class="wps-table-cell"><?php echo ($unity == 'kg') ? $p / 1000 : $p; ?> <?php _e($unity, 'wpshop')?></div> |
|
| 28 | 28 | <div class="wps-table-cell"><?php echo $fee; ?> <?php echo wpshop_tools::wpshop_get_currency(); ?></div> |
| 29 | - <div class="wps-table-cell"><a href="#" id="<?php echo $shipping_rule['destination']; ?>|<?php echo $p; ?>|<?php echo $shipping_mode_id; ?>" data-nonce="<?php echo wp_create_nonce( 'wpshop_ajax_delete_shipping_rule' ); ?>" class="delete_rule" title="<?php echo $shipping_mode_id; ?>"><i class="wps-icon-trash"></i></a></div> |
|
| 29 | + <div class="wps-table-cell"><a href="#" id="<?php echo $shipping_rule['destination']; ?>|<?php echo $p; ?>|<?php echo $shipping_mode_id; ?>" data-nonce="<?php echo wp_create_nonce('wpshop_ajax_delete_shipping_rule'); ?>" class="delete_rule" title="<?php echo $shipping_mode_id; ?>"><i class="wps-icon-trash"></i></a></div> |
|
| 30 | 30 | </div> |
| 31 | 31 | <?php |
| 32 | 32 | endforeach; |
@@ -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 ) { |
|
| 96 | + function display_products_list($default = 1, $page = 0) { |
|
| 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,25 +131,25 @@ 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 | - $product_list_interface = $this->display_products_list( $default, $page ); |
|
| 147 | + $product_list_interface = $this->display_products_list($default, $page); |
|
| 148 | 148 | |
| 149 | 149 | // Get pagination |
| 150 | - $pagination = $this->get_products_pagination( $page, $default ); |
|
| 150 | + $pagination = $this->get_products_pagination($page, $default); |
|
| 151 | 151 | |
| 152 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) ); |
|
| 152 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface")); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - function get_products_pagination( $current_page, $attribute_set_id = 1 ) { |
|
| 160 | + function get_products_pagination($current_page, $attribute_set_id = 1) { |
|
| 161 | 161 | global $wpdb; |
| 162 | 162 | $user_id = get_current_user_id(); |
| 163 | 163 | $output = ''; |
| 164 | 164 | /** Define the element number per page. If the user change the default value, take this value */ |
| 165 | - $one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 166 | - $one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20; |
|
| 165 | + $one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 166 | + $one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20; |
|
| 167 | 167 | |
| 168 | 168 | /** Count the number of product existing in the shop */ |
| 169 | 169 | $query = $wpdb->prepare( |
@@ -175,37 +175,37 @@ discard block |
||
| 175 | 175 | AND meta_value = %s |
| 176 | 176 | AND post_status IN ( 'publish', 'draft' )", |
| 177 | 177 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id); |
| 178 | - $products = $wpdb->get_var( $query ); |
|
| 178 | + $products = $wpdb->get_var($query); |
|
| 179 | 179 | |
| 180 | - if( !empty($products) ) { |
|
| 180 | + if (!empty($products)) { |
|
| 181 | 181 | $args = array( |
| 182 | 182 | 'base' => '%_%', |
| 183 | - 'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ), |
|
| 184 | - 'current' => ( $current_page + 1 ), |
|
| 185 | - 'total' => ceil( $products / $one_page_limit ), |
|
| 183 | + 'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'), |
|
| 184 | + 'current' => ($current_page + 1), |
|
| 185 | + 'total' => ceil($products / $one_page_limit), |
|
| 186 | 186 | 'type' => 'array', |
| 187 | 187 | 'prev_next' => false, |
| 188 | 188 | 'show_all' => true, |
| 189 | 189 | ); |
| 190 | - $paginate = paginate_links( $args ); |
|
| 190 | + $paginate = paginate_links($args); |
|
| 191 | 191 | |
| 192 | 192 | $wps_product_ctr = new wps_product_ctr(); |
| 193 | 193 | ob_start(); |
| 194 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) ); |
|
| 194 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination")); |
|
| 195 | 195 | $output = ob_get_contents(); |
| 196 | 196 | ob_end_clean(); |
| 197 | 197 | } |
| 198 | 198 | return $output; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - function wps_product_attached_files( $product_id ) { |
|
| 201 | + function wps_product_attached_files($product_id) { |
|
| 202 | 202 | global $wpdb; |
| 203 | 203 | $output = ''; |
| 204 | - $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%' ); |
|
| 205 | - $files = $wpdb->get_results( $query ); |
|
| 206 | - if( !empty($files) ) { |
|
| 204 | + $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%'); |
|
| 205 | + $files = $wpdb->get_results($query); |
|
| 206 | + if (!empty($files)) { |
|
| 207 | 207 | ob_start(); |
| 208 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) ); |
|
| 208 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list")); |
|
| 209 | 209 | $output = ob_get_contents(); |
| 210 | 210 | ob_end_clean(); |
| 211 | 211 | } |
@@ -217,23 +217,23 @@ discard block |
||
| 217 | 217 | * AJAX - Change page action on mass edit product interface |
| 218 | 218 | */ |
| 219 | 219 | function wps_mass_edit_change_page() { |
| 220 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 220 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 221 | 221 | |
| 222 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) |
|
| 222 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page')) |
|
| 223 | 223 | wp_die(); |
| 224 | 224 | |
| 225 | 225 | $status = false; $response = ''; |
| 226 | - $page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0; |
|
| 227 | - $attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1; |
|
| 228 | - if( !empty($attribute_set_id) ) { |
|
| 226 | + $page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0; |
|
| 227 | + $attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1; |
|
| 228 | + if (!empty($attribute_set_id)) { |
|
| 229 | 229 | // Get tab |
| 230 | - $response = $this->display_products_list( $attribute_set_id, $page ); |
|
| 231 | - $pagination = $this->get_products_pagination( $page, $attribute_set_id ); |
|
| 232 | - if( !empty($response) ) { |
|
| 230 | + $response = $this->display_products_list($attribute_set_id, $page); |
|
| 231 | + $pagination = $this->get_products_pagination($page, $attribute_set_id); |
|
| 232 | + if (!empty($response)) { |
|
| 233 | 233 | $status = true; |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | - echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) ); |
|
| 236 | + echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination)); |
|
| 237 | 237 | wp_die(); |
| 238 | 238 | } |
| 239 | 239 | |
@@ -241,30 +241,30 @@ discard block |
||
| 241 | 241 | * AJAX - Create a draft product and display the line allowing to edit informations for this product |
| 242 | 242 | */ |
| 243 | 243 | function wps_mass_interface_new_product_creation() { |
| 244 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 244 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 245 | 245 | |
| 246 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) |
|
| 246 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation')) |
|
| 247 | 247 | wp_die(); |
| 248 | 248 | |
| 249 | 249 | global $wpdb; |
| 250 | 250 | $output = $pagination = ''; |
| 251 | 251 | $status = false; |
| 252 | 252 | |
| 253 | - $new_product_id = wp_insert_post( array( |
|
| 253 | + $new_product_id = wp_insert_post(array( |
|
| 254 | 254 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
| 255 | 255 | 'post_status' => 'publish', |
| 256 | - 'post_title' => __( 'New product', 'wpshop' ), |
|
| 257 | - ) ); |
|
| 256 | + 'post_title' => __('New product', 'wpshop'), |
|
| 257 | + )); |
|
| 258 | 258 | |
| 259 | - if( !is_object($new_product_id) ) { |
|
| 259 | + if (!is_object($new_product_id)) { |
|
| 260 | 260 | $status = true; |
| 261 | 261 | } |
| 262 | - if ( !empty( $new_product_id ) ) { |
|
| 263 | - $product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1; |
|
| 264 | - update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id ); |
|
| 262 | + if (!empty($new_product_id)) { |
|
| 263 | + $product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1; |
|
| 264 | + update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) ); |
|
| 267 | + echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination)); |
|
| 268 | 268 | wp_die(); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -272,32 +272,32 @@ discard block |
||
| 272 | 272 | * AJAX - Save datas |
| 273 | 273 | */ |
| 274 | 274 | function wps_save_product_quick_interface() { |
| 275 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 275 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 276 | 276 | |
| 277 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) |
|
| 277 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface')) |
|
| 278 | 278 | wp_die(); |
| 279 | 279 | |
| 280 | 280 | global $wpdb; |
| 281 | 281 | $response = ''; $status = false; |
| 282 | 282 | $count_products_to_update = 0; $total_updated_products = 0; |
| 283 | 283 | |
| 284 | - $wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array(); |
|
| 285 | - $wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array(); |
|
| 286 | - $wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array(); |
|
| 284 | + $wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array(); |
|
| 285 | + $wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array(); |
|
| 286 | + $wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array(); |
|
| 287 | 287 | |
| 288 | 288 | // ------------------------------------------------------------------------------------------------------ |
| 289 | 289 | |
| 290 | - foreach( $_REQUEST['concur'] as $post_id => $columns ) { |
|
| 290 | + foreach ($_REQUEST['concur'] as $post_id => $columns) { |
|
| 291 | 291 | $concur = array(); |
| 292 | - for( $i = $count = 0; $i <= $count; $i++ ) { |
|
| 293 | - foreach( $columns as $key => $rows ) { |
|
| 294 | - $count = count( $rows )-1; |
|
| 292 | + for ($i = $count = 0; $i <= $count; $i++) { |
|
| 293 | + foreach ($columns as $key => $rows) { |
|
| 294 | + $count = count($rows) - 1; |
|
| 295 | 295 | $concur[$i][$key] = $rows[$i]; |
| 296 | 296 | } |
| 297 | - if( empty( $concur[$i]['is_row'] ) ) { |
|
| 298 | - unset( $concur[$i] ); |
|
| 297 | + if (empty($concur[$i]['is_row'])) { |
|
| 298 | + unset($concur[$i]); |
|
| 299 | 299 | } else { |
| 300 | - unset( $concur[$i]['is_row'] ); |
|
| 300 | + unset($concur[$i]['is_row']); |
|
| 301 | 301 | |
| 302 | 302 | $dotPos = strrpos($concur[$i]['price'], '.'); |
| 303 | 303 | $commaPos = strrpos($concur[$i]['price'], ','); |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | } else { |
| 308 | 308 | $concur[$i]['price'] = floatval( |
| 309 | 309 | preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], 0, $sep)) . '.' . |
| 310 | - preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep+1, strlen($concur[$i]['price']))) |
|
| 310 | + preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep + 1, strlen($concur[$i]['price']))) |
|
| 311 | 311 | ); |
| 312 | 312 | } |
| 313 | 313 | |
@@ -315,51 +315,51 @@ discard block |
||
| 315 | 315 | $concur[$i]['price'] = $concur[$i]['price']; |
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | - update_post_meta( $post_id, '_concur', $concur ); |
|
| 318 | + update_post_meta($post_id, '_concur', $concur); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | // ------------------------------------------------------------------------------------------------------ |
| 322 | 322 | |
| 323 | - if( !empty($wps_product_quick_save) ) { |
|
| 324 | - $count_products_to_update = count( $wps_product_quick_save ); |
|
| 325 | - foreach( $wps_product_quick_save as $product_to_save ) { |
|
| 323 | + if (!empty($wps_product_quick_save)) { |
|
| 324 | + $count_products_to_update = count($wps_product_quick_save); |
|
| 325 | + foreach ($wps_product_quick_save as $product_to_save) { |
|
| 326 | 326 | $data_to_save = array(); |
| 327 | 327 | // Update post |
| 328 | - $updated_post = wp_update_post( array( 'ID' => $product_to_save, |
|
| 329 | - 'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ), |
|
| 330 | - 'post_content' => wp_kses_post( $wps_mass_interface[$product_to_save]['post_content'] ), |
|
| 328 | + $updated_post = wp_update_post(array('ID' => $product_to_save, |
|
| 329 | + 'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']), |
|
| 330 | + 'post_content' => wp_kses_post($wps_mass_interface[$product_to_save]['post_content']), |
|
| 331 | 331 | ) |
| 332 | 332 | ); |
| 333 | 333 | // Update attributes |
| 334 | - if( !empty($updated_post) ) { |
|
| 334 | + if (!empty($updated_post)) { |
|
| 335 | 335 | // Update Featured picture |
| 336 | - if( !empty($wps_mass_interface[$product_to_save]['picture']) ) { |
|
| 337 | - $thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true ); |
|
| 338 | - if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 339 | - wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) ); |
|
| 340 | - update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] ); |
|
| 336 | + if (!empty($wps_mass_interface[$product_to_save]['picture'])) { |
|
| 337 | + $thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true); |
|
| 338 | + if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 339 | + wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post)); |
|
| 340 | + update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']); |
|
| 341 | 341 | } |
| 342 | - elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 343 | - delete_post_meta( $updated_post, '_thumbnail_id' ); |
|
| 342 | + elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 343 | + delete_post_meta($updated_post, '_thumbnail_id'); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // Update files datas |
| 348 | - if( !empty($wps_mass_interface[$product_to_save]['files']) ) { |
|
| 349 | - $files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) ); |
|
| 350 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 351 | - foreach( $files_data as $file_id ) { |
|
| 352 | - if( !empty($file_id) ) { |
|
| 353 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) ); |
|
| 348 | + if (!empty($wps_mass_interface[$product_to_save]['files'])) { |
|
| 349 | + $files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files'])); |
|
| 350 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 351 | + foreach ($files_data as $file_id) { |
|
| 352 | + if (!empty($file_id)) { |
|
| 353 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post)); |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - $data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save ); |
|
| 360 | - $data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array(); |
|
| 359 | + $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save); |
|
| 360 | + $data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array(); |
|
| 361 | 361 | |
| 362 | - if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 362 | + if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 363 | 363 | // Get current barcode |
| 364 | 364 | $wps_product_mdl = new wps_product_mdl(); |
| 365 | 365 | $attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id; |
@@ -370,34 +370,34 @@ discard block |
||
| 370 | 370 | $data_to_save['user_ID'] = get_current_user_id(); |
| 371 | 371 | $data_to_save['action'] = 'editpost'; |
| 372 | 372 | |
| 373 | - if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) { |
|
| 374 | - wp_trash_post( $product_to_save ); |
|
| 373 | + if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") { |
|
| 374 | + wp_trash_post($product_to_save); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) { |
|
| 377 | + if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) { |
|
| 378 | 378 | $product_class = new wpshop_products(); |
| 379 | - $product_class->save_product_custom_informations( $product_to_save, $data_to_save ); |
|
| 379 | + $product_class->save_product_custom_informations($product_to_save, $data_to_save); |
|
| 380 | 380 | $total_updated_products++; |
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | // Checking status |
| 386 | - $status = ( $total_updated_products == $count_products_to_update ) ? true : false; |
|
| 386 | + $status = ($total_updated_products == $count_products_to_update) ? true : false; |
|
| 387 | 387 | |
| 388 | - if( $status ) { |
|
| 389 | - $response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products ); |
|
| 388 | + if ($status) { |
|
| 389 | + $response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products); |
|
| 390 | 390 | } |
| 391 | 391 | else { |
| 392 | - if( !empty($total_updated_products) ) { |
|
| 393 | - $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 ); |
|
| 392 | + if (!empty($total_updated_products)) { |
|
| 393 | + $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 | 394 | } |
| 395 | 395 | else { |
| 396 | - $response = __( 'No product have been updated', 'wpshop'); |
|
| 396 | + $response = __('No product have been updated', 'wpshop'); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - echo json_encode( array('status' => $status, 'response' => $response ) ); |
|
| 400 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 401 | 401 | wp_die(); |
| 402 | 402 | } |
| 403 | 403 | |
@@ -405,18 +405,18 @@ discard block |
||
| 405 | 405 | * Delete product list |
| 406 | 406 | **/ |
| 407 | 407 | function wps_mass_delete_file() { |
| 408 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 408 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 409 | 409 | |
| 410 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) |
|
| 410 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file')) |
|
| 411 | 411 | wp_die(); |
| 412 | 412 | |
| 413 | 413 | $status = false; |
| 414 | - $file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null; |
|
| 415 | - if( !empty($file_id) ) { |
|
| 416 | - wp_update_post( array('ID' => $file_id, 'post_parent' => 0) ); |
|
| 414 | + $file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null; |
|
| 415 | + if (!empty($file_id)) { |
|
| 416 | + wp_update_post(array('ID' => $file_id, 'post_parent' => 0)); |
|
| 417 | 417 | $status = true; |
| 418 | 418 | } |
| 419 | - echo json_encode( array( 'status' => $status ) ); |
|
| 419 | + echo json_encode(array('status' => $status)); |
|
| 420 | 420 | wp_die(); |
| 421 | 421 | } |
| 422 | 422 | |
@@ -424,32 +424,32 @@ discard block |
||
| 424 | 424 | * Update product files list |
| 425 | 425 | */ |
| 426 | 426 | function wps_mass_edit_update_files_list() { |
| 427 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 427 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 428 | 428 | |
| 429 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) |
|
| 429 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list')) |
|
| 430 | 430 | wp_die(); |
| 431 | 431 | |
| 432 | 432 | $status = false; $response = ''; |
| 433 | - $product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null; |
|
| 434 | - $files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null; |
|
| 435 | - if( !empty($product_id ) ) { |
|
| 433 | + $product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null; |
|
| 434 | + $files = (!empty($_POST['files'])) ? intval($_POST['files']) : null; |
|
| 435 | + if (!empty($product_id)) { |
|
| 436 | 436 | // Update files datas |
| 437 | - if( !empty($files) ) { |
|
| 438 | - $files_data = explode( ',', $files ); |
|
| 439 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 440 | - foreach( $files_data as $file_id ) { |
|
| 441 | - if( !empty($file_id) ) { |
|
| 442 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) ); |
|
| 437 | + if (!empty($files)) { |
|
| 438 | + $files_data = explode(',', $files); |
|
| 439 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 440 | + foreach ($files_data as $file_id) { |
|
| 441 | + if (!empty($file_id)) { |
|
| 442 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id)); |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
| 449 | - $response = $this->wps_product_attached_files( $product_id ); |
|
| 449 | + $response = $this->wps_product_attached_files($product_id); |
|
| 450 | 450 | $status = true; |
| 451 | 451 | } |
| 452 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 452 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 453 | 453 | wp_die(); |
| 454 | 454 | } |
| 455 | 455 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | class wps_shortcodes_ctr |
| 4 | 4 | { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @return string The table of the class |
| 31 | 31 | */ |
| 32 | - function setMessage($message){ |
|
| 32 | + function setMessage($message) { |
|
| 33 | 33 | $this->pageMessage = $message; |
| 34 | 34 | } |
| 35 | 35 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return string The table of the class |
| 39 | 39 | */ |
| 40 | - function getListingSlug(){ |
|
| 40 | + function getListingSlug() { |
|
| 41 | 41 | return self::urlSlugListing; |
| 42 | 42 | } |
| 43 | 43 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return string The table of the class |
| 47 | 47 | */ |
| 48 | - function getEditionSlug(){ |
|
| 48 | + function getEditionSlug() { |
|
| 49 | 49 | return self::urlSlugEdition; |
| 50 | 50 | } |
| 51 | 51 | /** |
@@ -58,33 +58,33 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return string $title The title of the page looking at the environnement |
| 60 | 60 | */ |
| 61 | - function pageTitle(){ |
|
| 61 | + function pageTitle() { |
|
| 62 | 62 | $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : ''; |
| 63 | 63 | $objectInEdition = isset($_REQUEST['id']) ? wpshop_tools::varSanitizer($_REQUEST['id']) : ''; |
| 64 | - $page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 64 | + $page = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
| 65 | 65 | |
| 66 | - $title = __(self::pageTitle, 'wpshop' ); |
|
| 67 | - if($action != ''){ |
|
| 68 | - if(($action == 'edit') || ($action == 'delete')){ |
|
| 66 | + $title = __(self::pageTitle, 'wpshop'); |
|
| 67 | + if ($action != '') { |
|
| 68 | + if (($action == 'edit') || ($action == 'delete')) { |
|
| 69 | 69 | $editedItem = self::getElement($objectInEdition); |
| 70 | 70 | $title = sprintf(__(self::pageEditingTitle, 'wpshop'), str_replace("\\", "", $editedItem->frontend_label) . ' (' . $editedItem->code . ')'); |
| 71 | 71 | } |
| 72 | - elseif($action == 'add'){ |
|
| 72 | + elseif ($action == 'add') { |
|
| 73 | 73 | $title = __(self::pageAddingTitle, 'wpshop'); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | - elseif((self::getEditionSlug() != self::getListingSlug()) && ($page == self::getEditionSlug())){ |
|
| 76 | + elseif ((self::getEditionSlug() != self::getListingSlug()) && ($page == self::getEditionSlug())) { |
|
| 77 | 77 | $title = __(self::pageAddingTitle, 'wpshop'); |
| 78 | 78 | } |
| 79 | 79 | return $title; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - function elementAction(){ |
|
| 82 | + function elementAction() { |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** Définition des shortcodes pour les afficher dans le template list-shortcode */ |
| 87 | - public static function shortcode_definition(){ |
|
| 87 | + public static function shortcode_definition() { |
|
| 88 | 88 | $shortcodes = array(); |
| 89 | 89 | |
| 90 | 90 | /* Product tab */ |
@@ -95,17 +95,17 @@ discard block |
||
| 95 | 95 | $shortcodes['simple_product']['attrs_exemple']['pid'] = '12'; |
| 96 | 96 | $shortcodes['simple_product']['attrs_exemple']['type'] = 'list'; |
| 97 | 97 | |
| 98 | - $shortcodes['wpshop_product_title']['main_title'] = __( 'Product title', 'wpshop' ); |
|
| 98 | + $shortcodes['wpshop_product_title']['main_title'] = __('Product title', 'wpshop'); |
|
| 99 | 99 | $shortcodes['wpshop_product_title']['main_code'] = 'wpshop_product_title'; |
| 100 | 100 | $shortcodes['wpshop_product_title']['attrs_def']['pid'] = 'ID_DU_PRODUIT'; |
| 101 | 101 | $shortcodes['wpshop_product_title']['attrs_exemple']['pid'] = '12'; |
| 102 | 102 | |
| 103 | - $shortcodes['wpshop_product_content']['main_title'] = __( 'Product content', 'wpshop' ); |
|
| 103 | + $shortcodes['wpshop_product_content']['main_title'] = __('Product content', 'wpshop'); |
|
| 104 | 104 | $shortcodes['wpshop_product_content']['main_code'] = 'wpshop_product_content'; |
| 105 | 105 | $shortcodes['wpshop_product_content']['attrs_def']['pid'] = 'ID_DU_PRODUIT'; |
| 106 | 106 | $shortcodes['wpshop_product_content']['attrs_exemple']['pid'] = '12'; |
| 107 | 107 | |
| 108 | - $shortcodes['wpshop_product_thumbnail']['main_title'] = __( 'Product thumbnail', 'wpshop' ); |
|
| 108 | + $shortcodes['wpshop_product_thumbnail']['main_title'] = __('Product thumbnail', 'wpshop'); |
|
| 109 | 109 | $shortcodes['wpshop_product_thumbnail']['main_code'] = 'wpshop_product_thumbnail'; |
| 110 | 110 | $shortcodes['wpshop_product_thumbnail']['attrs_def']['pid'] = 'ID_DU_PRODUIT'; |
| 111 | 111 | $shortcodes['wpshop_product_thumbnail']['attrs_def']['size'] = 'TAILLE_DU_PRODUIT'; |
@@ -208,31 +208,31 @@ discard block |
||
| 208 | 208 | return $shortcodes; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public static function output_shortcode($shortcode_code, $specific_shorcode = '', $more_class_shortcode_helper = ''){ |
|
| 212 | - $shortcode = ( empty($specific_shorcode) ? self::shortcode_definition() : $specific_shorcode ); |
|
| 211 | + public static function output_shortcode($shortcode_code, $specific_shorcode = '', $more_class_shortcode_helper = '') { |
|
| 212 | + $shortcode = (empty($specific_shorcode) ? self::shortcode_definition() : $specific_shorcode); |
|
| 213 | 213 | |
| 214 | - $shortcode_main_title = ( !empty($shortcode[$shortcode_code]['main_title']) ? $shortcode[$shortcode_code]['main_title'] : '' ); |
|
| 215 | - $shorcode_main_code = ( !empty($shortcode[$shortcode_code]['main_code']) ? $shortcode[$shortcode_code]['main_code'] : '' ); |
|
| 214 | + $shortcode_main_title = (!empty($shortcode[$shortcode_code]['main_title']) ? $shortcode[$shortcode_code]['main_title'] : ''); |
|
| 215 | + $shorcode_main_code = (!empty($shortcode[$shortcode_code]['main_code']) ? $shortcode[$shortcode_code]['main_code'] : ''); |
|
| 216 | 216 | $shorcode_attributes_def = ' '; |
| 217 | - if(!empty($shortcode[$shortcode_code]['attrs_def'])){ |
|
| 218 | - foreach($shortcode[$shortcode_code]['attrs_def'] as $attr_name => $attr_values){ |
|
| 219 | - $shorcode_attributes_def .= $attr_name.'="'.$attr_values.'" '; |
|
| 217 | + if (!empty($shortcode[$shortcode_code]['attrs_def'])) { |
|
| 218 | + foreach ($shortcode[$shortcode_code]['attrs_def'] as $attr_name => $attr_values) { |
|
| 219 | + $shorcode_attributes_def .= $attr_name . '="' . $attr_values . '" '; |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | $shorcode_attributes_def = substr($shorcode_attributes_def, 0, -1); |
| 223 | 223 | $shorcode_attributes_exemple = ' '; |
| 224 | - if(!empty($shortcode[$shortcode_code]['attrs_exemple'])){ |
|
| 225 | - foreach($shortcode[$shortcode_code]['attrs_exemple'] as $attr_name => $attr_values){ |
|
| 226 | - $shorcode_attributes_exemple .= $attr_name.'="'.$attr_values.'" '; |
|
| 224 | + if (!empty($shortcode[$shortcode_code]['attrs_exemple'])) { |
|
| 225 | + foreach ($shortcode[$shortcode_code]['attrs_exemple'] as $attr_name => $attr_values) { |
|
| 226 | + $shorcode_attributes_exemple .= $attr_name . '="' . $attr_values . '" '; |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | $shorcode_attributes_exemple = substr($shorcode_attributes_exemple, 0, -1); |
| 230 | 230 | |
| 231 | - require( wpshop_tools::get_template_part( WPS_SHORTCODES_DIR, WPS_SHORTCODES_TEMPLATES_MAIN_DIR, "backend", 'shortcode_help.tpl' ) ); |
|
| 231 | + require(wpshop_tools::get_template_part(WPS_SHORTCODES_DIR, WPS_SHORTCODES_TEMPLATES_MAIN_DIR, "backend", 'shortcode_help.tpl')); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | public static function wysiwyg_button() { |
| 235 | - if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) return; |
|
| 235 | + if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) return; |
|
| 236 | 236 | //if ( get_user_option('rich_editing') == 'true') : |
| 237 | 237 | /*add_filter('mce_external_plugins', array('wps_shortcodes_ctr', 'add_button_to_wysiwyg')); |
| 238 | 238 | add_filter('mce_buttons', array('wps_shortcodes_ctr', 'register_wysiwyg_button'));*/ |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | $ver += 3; |
| 243 | 243 | return $ver; |
| 244 | 244 | } |
| 245 | - public static function add_button_to_wysiwyg($plugin_array){ |
|
| 245 | + public static function add_button_to_wysiwyg($plugin_array) { |
|
| 246 | 246 | $plugin_array['wpshop_wysiwyg_shortcodes'] = WPSHOP_JS_URL . 'pages/wysiwyg_editor.js'; |
| 247 | 247 | return $plugin_array; |
| 248 | 248 | } |
| 249 | - public static function register_wysiwyg_button($existing_button){ |
|
| 249 | + public static function register_wysiwyg_button($existing_button) { |
|
| 250 | 250 | array_push($existing_button, "|", "wpshop_wysiwyg_shortcodes"); |
| 251 | 251 | return $existing_button; |
| 252 | 252 | } |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | - function elementList(){ |
|
| 260 | + function elementList() { |
|
| 261 | 261 | $shortcode_list = ''; |
| 262 | 262 | ob_start(); |
| 263 | - require( wpshop_tools::get_template_part( WPS_SHORTCODES_DIR, WPS_SHORTCODES_TEMPLATES_MAIN_DIR, "backend", 'list', 'shortcode' ) ); |
|
| 263 | + require(wpshop_tools::get_template_part(WPS_SHORTCODES_DIR, WPS_SHORTCODES_TEMPLATES_MAIN_DIR, "backend", 'list', 'shortcode')); |
|
| 264 | 264 | $shortcode_list = ob_get_contents(); |
| 265 | 265 | ob_end_clean(); |
| 266 | 266 | |
@@ -270,45 +270,45 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | public function __construct() { |
| 272 | 272 | add_action('init', array($this, 'help_tab_shortcodes')); |
| 273 | - add_action( "admin_head", array( $this, 'shortcode_text_localization' ) ); |
|
| 273 | + add_action("admin_head", array($this, 'shortcode_text_localization')); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | 277 | * Localize Script |
| 278 | 278 | */ |
| 279 | 279 | function shortcode_text_localization() { |
| 280 | - $plugin_url = plugins_url( '/', __FILE__ ); |
|
| 280 | + $plugin_url = plugins_url('/', __FILE__); |
|
| 281 | 281 | ?> |
| 282 | 282 | <!-- TinyMCE Shortcode Plugin --> |
| 283 | 283 | <script type='text/javascript'> |
| 284 | 284 | var wpshop_mce_shortcode = { |
| 285 | - 'url': "<?php _e('Insert shortcode into page content', 'wpshop' ); ?>", |
|
| 286 | - 'product_listing': "<?php _e('Product listing', 'wpshop' ); ?>", |
|
| 287 | - 'url': "<?php _e('By product ID', 'wpshop' ); ?>", |
|
| 288 | - 'url': "<?php _e('By attribute value', 'wpshop' ); ?>", |
|
| 289 | - 'url': "<?php _e('Wpshop categories', 'wpshop' ); ?>", |
|
| 290 | - 'url': "<?php _e('Attribute value', 'wpshop' ); ?>", |
|
| 291 | - 'url': "<?php _e('Custom message content', 'wpshop' ); ?>", |
|
| 292 | - 'url': "<?php _e('Customer first name', 'wpshop' ); ?>", |
|
| 293 | - 'url': "<?php _e('Customer last name', 'wpshop' ); ?>", |
|
| 294 | - 'url': "<?php _e('Customer email', 'wpshop' ); ?>", |
|
| 295 | - 'url': "<?php _e('Order identifer', 'wpshop' ); ?>", |
|
| 296 | - 'url': "<?php _e('Paypal transaction ID', 'wpshop' ); ?>", |
|
| 297 | - 'url': "<?php _e('Order content', 'wpshop' ); ?>", |
|
| 298 | - 'url': "<?php _e('Customer personnal informations', 'wpshop' ); ?>", |
|
| 299 | - 'url': "<?php _e('Order addresses', 'wpshop' ); ?>", |
|
| 300 | - 'url': "<?php _e('Billing order address', 'wpshop' ); ?>", |
|
| 301 | - 'url': "<?php _e('Shipping order address', 'wpshop' ); ?>", |
|
| 302 | - 'url': "<?php _e('Shipping method', 'wpshop' ); ?>", |
|
| 303 | - 'url': "<?php _e('order payment_method', 'wpshop' ); ?>", |
|
| 304 | - 'url': "<?php _e('Order customer comment', 'wpshop' ); ?>", |
|
| 305 | - 'url': "<?php _e('Wpshop custom tags', 'wpshop' ); ?>", |
|
| 306 | - 'url': "<?php _e('Cart', 'wpshop' ); ?>", |
|
| 307 | - 'url': "<?php _e('Cart widget', 'wpshop' ); ?>", |
|
| 308 | - 'url': "<?php _e('Checkout', 'wpshop' ); ?>", |
|
| 309 | - 'url': "<?php _e('Customer account', 'wpshop' ); ?>", |
|
| 310 | - 'url': "<?php _e('Shop', 'wpshop' ); ?>", |
|
| 311 | - 'url': "<?php _e('Advanced search', 'wpshop' ); ?>", |
|
| 285 | + 'url': "<?php _e('Insert shortcode into page content', 'wpshop'); ?>", |
|
| 286 | + 'product_listing': "<?php _e('Product listing', 'wpshop'); ?>", |
|
| 287 | + 'url': "<?php _e('By product ID', 'wpshop'); ?>", |
|
| 288 | + 'url': "<?php _e('By attribute value', 'wpshop'); ?>", |
|
| 289 | + 'url': "<?php _e('Wpshop categories', 'wpshop'); ?>", |
|
| 290 | + 'url': "<?php _e('Attribute value', 'wpshop'); ?>", |
|
| 291 | + 'url': "<?php _e('Custom message content', 'wpshop'); ?>", |
|
| 292 | + 'url': "<?php _e('Customer first name', 'wpshop'); ?>", |
|
| 293 | + 'url': "<?php _e('Customer last name', 'wpshop'); ?>", |
|
| 294 | + 'url': "<?php _e('Customer email', 'wpshop'); ?>", |
|
| 295 | + 'url': "<?php _e('Order identifer', 'wpshop'); ?>", |
|
| 296 | + 'url': "<?php _e('Paypal transaction ID', 'wpshop'); ?>", |
|
| 297 | + 'url': "<?php _e('Order content', 'wpshop'); ?>", |
|
| 298 | + 'url': "<?php _e('Customer personnal informations', 'wpshop'); ?>", |
|
| 299 | + 'url': "<?php _e('Order addresses', 'wpshop'); ?>", |
|
| 300 | + 'url': "<?php _e('Billing order address', 'wpshop'); ?>", |
|
| 301 | + 'url': "<?php _e('Shipping order address', 'wpshop'); ?>", |
|
| 302 | + 'url': "<?php _e('Shipping method', 'wpshop'); ?>", |
|
| 303 | + 'url': "<?php _e('order payment_method', 'wpshop'); ?>", |
|
| 304 | + 'url': "<?php _e('Order customer comment', 'wpshop'); ?>", |
|
| 305 | + 'url': "<?php _e('Wpshop custom tags', 'wpshop'); ?>", |
|
| 306 | + 'url': "<?php _e('Cart', 'wpshop'); ?>", |
|
| 307 | + 'url': "<?php _e('Cart widget', 'wpshop'); ?>", |
|
| 308 | + 'url': "<?php _e('Checkout', 'wpshop'); ?>", |
|
| 309 | + 'url': "<?php _e('Customer account', 'wpshop'); ?>", |
|
| 310 | + 'url': "<?php _e('Shop', 'wpshop'); ?>", |
|
| 311 | + 'url': "<?php _e('Advanced search', 'wpshop'); ?>", |
|
| 312 | 312 | }; |
| 313 | 313 | </script> |
| 314 | 314 | <!-- TinyMCE Shortcode Plugin --> |
@@ -317,23 +317,23 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | public function shortcode_xmlloader() { |
| 319 | 319 | $shortcodes_list = array(); |
| 320 | - $ini_get_checking = ini_get( 'allow_url_fopen' ); |
|
| 321 | - if ( $ini_get_checking != 0 ) { |
|
| 322 | - $content = @file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/lshortcodes.xml' ); |
|
| 323 | - $list_shortcodes_xml = ( $content !== false ) ? new SimpleXmlElement( $content ) : null; |
|
| 324 | - if ( !empty($list_shortcodes_xml) && !empty($list_shortcodes_xml->channel) ) { |
|
| 320 | + $ini_get_checking = ini_get('allow_url_fopen'); |
|
| 321 | + if ($ini_get_checking != 0) { |
|
| 322 | + $content = @file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/lshortcodes.xml'); |
|
| 323 | + $list_shortcodes_xml = ($content !== false) ? new SimpleXmlElement($content) : null; |
|
| 324 | + if (!empty($list_shortcodes_xml) && !empty($list_shortcodes_xml->channel)) { |
|
| 325 | 325 | global $shortcode_tags; |
| 326 | - foreach( $list_shortcodes_xml->channel->category as $i => $category ) { |
|
| 327 | - $shortcodes_list[(String) $category->title]['desc_cat_' . (String) $category->title] = (String) $category->description; |
|
| 328 | - foreach( $category->item as $j => $item_xml ) { |
|
| 326 | + foreach ($list_shortcodes_xml->channel->category as $i => $category) { |
|
| 327 | + $shortcodes_list[(String)$category->title]['desc_cat_' . (String)$category->title] = (String)$category->description; |
|
| 328 | + foreach ($category->item as $j => $item_xml) { |
|
| 329 | 329 | $item = array(); |
| 330 | - $item['title'] = (String) $item_xml->title; |
|
| 331 | - $item['description'] = (String) $item_xml->description; |
|
| 332 | - foreach( $item_xml->args as $argument) { |
|
| 333 | - $item['args'][(String) $argument->identifier] = (String) $argument->params; |
|
| 330 | + $item['title'] = (String)$item_xml->title; |
|
| 331 | + $item['description'] = (String)$item_xml->description; |
|
| 332 | + foreach ($item_xml->args as $argument) { |
|
| 333 | + $item['args'][(String)$argument->identifier] = (String)$argument->params; |
|
| 334 | 334 | } |
| 335 | - $item['active'] = ( array_key_exists((String) $item_xml->identifier, $shortcode_tags) ) ? 'true' : 'false'; |
|
| 336 | - $shortcodes_list[(String) $category->title]['items'][(String) $item_xml->identifier] = $item; |
|
| 335 | + $item['active'] = (array_key_exists((String)$item_xml->identifier, $shortcode_tags)) ? 'true' : 'false'; |
|
| 336 | + $shortcodes_list[(String)$category->title]['items'][(String)$item_xml->identifier] = $item; |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | } |
@@ -342,10 +342,10 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | public function help_tab_shortcodes() { |
| 345 | - if( current_user_can('edit_posts') && current_user_can('edit_pages') && get_user_option('rich_editing') == 'true' ) { |
|
| 346 | - add_filter( 'mce_external_plugins', array( $this, 'wpshop_add_buttons' ) ); |
|
| 347 | - add_filter( 'mce_buttons', array( $this, 'wpshop_register_buttons' ) ); |
|
| 348 | - add_action( 'admin_footer', array( $this, 'wpshop_get_shortcodes' ) ); |
|
| 345 | + if (current_user_can('edit_posts') && current_user_can('edit_pages') && get_user_option('rich_editing') == 'true') { |
|
| 346 | + add_filter('mce_external_plugins', array($this, 'wpshop_add_buttons')); |
|
| 347 | + add_filter('mce_buttons', array($this, 'wpshop_register_buttons')); |
|
| 348 | + add_action('admin_footer', array($this, 'wpshop_get_shortcodes')); |
|
| 349 | 349 | } |
| 350 | 350 | /*$shortcodes = $this->shortcode_xmlloader(); |
| 351 | 351 | ob_start(); |
@@ -356,12 +356,12 @@ discard block |
||
| 356 | 356 | $wps_help_tabs->set_help_tab( 'shortcodes', __( 'Shortcodes', 'wpshop' ), $content, array('edit-post', 'post', 'edit-page', 'page', 'edit-comments', 'comments', 'edit-wpshop_product', 'wpshop_product', 'edit-wpshop_product_category') );*/ |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - public function wpshop_register_buttons( $buttons ) { |
|
| 360 | - array_push( $buttons, 'separator', 'pushortcodes' ); |
|
| 359 | + public function wpshop_register_buttons($buttons) { |
|
| 360 | + array_push($buttons, 'separator', 'pushortcodes'); |
|
| 361 | 361 | return $buttons; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - public function wpshop_add_buttons( $plugin_array ) { |
|
| 364 | + public function wpshop_add_buttons($plugin_array) { |
|
| 365 | 365 | $plugin_array['pushortcodes'] = WPSHOP_JS_URL . 'pages/shortcode-tinymce-button.js'; |
| 366 | 366 | return $plugin_array; |
| 367 | 367 | } |
@@ -369,12 +369,12 @@ discard block |
||
| 369 | 369 | public function wpshop_get_shortcodes() { |
| 370 | 370 | echo '<script type="text/javascript">var shortcodes_button = new Array();'; |
| 371 | 371 | $count = 0; |
| 372 | - foreach( $this->shortcode_xmlloader() as $category ) { |
|
| 373 | - foreach( $category['items'] as $shortcode => $shortcode_args ) { |
|
| 372 | + foreach ($this->shortcode_xmlloader() as $category) { |
|
| 373 | + foreach ($category['items'] as $shortcode => $shortcode_args) { |
|
| 374 | 374 | echo "shortcodes_button[{$count}] = { text: '[$shortcode]', content: '[$shortcode"; |
| 375 | - if( isset( $shortcode_args['args'] ) ) { |
|
| 376 | - foreach( $shortcode_args['args'] as $argument => $parameter ) { |
|
| 377 | - echo ' ' . $argument . '="' . urlencode( $parameter ) . '"'; |
|
| 375 | + if (isset($shortcode_args['args'])) { |
|
| 376 | + foreach ($shortcode_args['args'] as $argument => $parameter) { |
|
| 377 | + echo ' ' . $argument . '="' . urlencode($parameter) . '"'; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | echo "]' };"; |
@@ -384,9 +384,9 @@ discard block |
||
| 384 | 384 | echo '</script>'; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - public static function wps_shortcodes_wysiwyg_dialog(){ |
|
| 387 | + public static function wps_shortcodes_wysiwyg_dialog() { |
|
| 388 | 388 | global $wpdb; |
| 389 | - require( wpshop_tools::get_template_part( WPS_SHORTCODES_DIR, WPS_SHORTCODES_TEMPLATES_MAIN_DIR, "backend", 'wysiwyg_dialog', 'shortcode' ) ); |
|
| 389 | + require(wpshop_tools::get_template_part(WPS_SHORTCODES_DIR, WPS_SHORTCODES_TEMPLATES_MAIN_DIR, "backend", 'wysiwyg_dialog', 'shortcode')); |
|
| 390 | 390 | die(); |
| 391 | 391 | } |
| 392 | 392 | } |
@@ -15,13 +15,13 @@ |
||
| 15 | 15 | <main id="main" class="site-main" role="main"> |
| 16 | 16 | |
| 17 | 17 | <?php |
| 18 | - /* Start the Loop */ |
|
| 19 | - while ( have_posts() ) : the_post(); |
|
| 18 | + /* Start the Loop */ |
|
| 19 | + while ( have_posts() ) : the_post(); |
|
| 20 | 20 | |
| 21 | - the_content(); |
|
| 21 | + the_content(); |
|
| 22 | 22 | |
| 23 | - endwhile; // End of the loop. |
|
| 24 | - ?> |
|
| 23 | + endwhile; // End of the loop. |
|
| 24 | + ?> |
|
| 25 | 25 | |
| 26 | 26 | </main><!-- #main --> |
| 27 | 27 | </div><!-- #primary --> |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | <?php |
| 18 | 18 | /* Start the Loop */ |
| 19 | - while ( have_posts() ) : the_post(); |
|
| 19 | + while (have_posts()) : the_post(); |
|
| 20 | 20 | |
| 21 | 21 | the_content(); |
| 22 | 22 | |