@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -13,217 +13,217 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | /** Check if billing class does not exist before creating the class */ |
| 15 | 15 | if (!class_exists("wpshop_modules_billing")) { |
| 16 | - /** |
|
| 17 | - * Billing module utilities definition |
|
| 18 | - * |
|
| 19 | - * @author Alexandre Techer - Eoxia dev team <[email protected]> |
|
| 20 | - * @version 0.1 |
|
| 21 | - * @package includes |
|
| 22 | - * @subpackage modules |
|
| 23 | - */ |
|
| 24 | - class wpshop_modules_billing |
|
| 25 | - { |
|
| 26 | - /** |
|
| 27 | - * Create a new instance for the current module - Billing |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - /** Add custom template for current module */ |
|
| 32 | - add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
| 33 | - |
|
| 34 | - /** In case wpshop is set on sale mode and not on view catalog only, Ad billign options */ |
|
| 35 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 36 | - $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 37 | - $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 38 | - |
|
| 39 | - if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 40 | - && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 41 | - /** Add module option to wpshop general options */ |
|
| 42 | - add_filter('wpshop_options', array(&$this, 'add_options'), 9); |
|
| 43 | - add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Filter |
|
| 48 | - add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Load module/addon automatically to existing template list |
|
| 53 | - * |
|
| 54 | - * @param array $templates The current template definition |
|
| 55 | - * |
|
| 56 | - * @return array The template with new elements |
|
| 57 | - */ |
|
| 58 | - public function custom_template_load($templates) |
|
| 59 | - { |
|
| 60 | - include 'templates/common/main_elements.tpl.php'; |
|
| 61 | - $wpshop_template = $tpl_element; |
|
| 62 | - /* Get custom frontend template */ |
|
| 63 | - if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) { |
|
| 64 | - require_once get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php'; |
|
| 65 | - if (!empty($tpl_element)) { |
|
| 66 | - $wpshop_template['common']['custom'] = ($tpl_element); |
|
| 67 | - } |
|
| 68 | - unset($tpl_element); |
|
| 69 | - } |
|
| 70 | - $wpshop_display = new wpshop_display(); |
|
| 71 | - $templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates); |
|
| 72 | - |
|
| 73 | - unset($tpl_element); |
|
| 74 | - |
|
| 75 | - return $templates; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Declare option groups for the module |
|
| 80 | - */ |
|
| 81 | - public function add_options($option_group) |
|
| 82 | - { |
|
| 83 | - $option_group['wpshop_billing_info'] = |
|
| 84 | - array('label' => __('Billing', 'wpshop'), |
|
| 85 | - 'subgroups' => array( |
|
| 86 | - 'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'), |
|
| 87 | - ), |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - return $option_group; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Declare the different options in groups for the module |
|
| 95 | - */ |
|
| 96 | - public function declare_options() |
|
| 97 | - { |
|
| 98 | - add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info'); |
|
| 99 | - |
|
| 100 | - register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures')); |
|
| 101 | - add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 102 | - |
|
| 103 | - register_setting('wpshop_options', 'wpshop_billing_address', array(&$this, 'wpshop_billing_address_validator')); |
|
| 104 | - add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 105 | - add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 106 | - |
|
| 107 | - $quotation_option = get_option('wpshop_addons'); |
|
| 108 | - if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) { |
|
| 109 | - add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info'); |
|
| 110 | - |
|
| 111 | - register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time')); |
|
| 112 | - add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 113 | - $payment_option = get_option('wps_payment_mode'); |
|
| 114 | - if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) { |
|
| 115 | - register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation')); |
|
| 116 | - add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 117 | - } |
|
| 118 | - register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation')); |
|
| 119 | - add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function wpshop_options_validate_wpshop_bic_to_quotation($input) |
|
| 125 | - { |
|
| 126 | - return $input; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function wpshop_bic_to_quotation_field() |
|
| 130 | - { |
|
| 131 | - $add_quotation_option = get_option('wpshop_paymentMethod_options'); |
|
| 132 | - $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />'; |
|
| 133 | - echo $output; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function billing_options_main_explanation() |
|
| 137 | - { |
|
| 138 | - |
|
| 139 | - } |
|
| 140 | - public function quotation_options_main_explanation() |
|
| 141 | - { |
|
| 142 | - |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function wpshop_options_validate_quotation_validate_time($input) |
|
| 146 | - { |
|
| 147 | - return $input; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function wpshop_billing_number_figures_field() |
|
| 151 | - { |
|
| 152 | - $wpshop_billing_number_figures = get_option('wpshop_billing_number_figures'); |
|
| 153 | - $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null; |
|
| 154 | - if (empty($wpshop_billing_number_figures)) { |
|
| 155 | - $wpshop_billing_number_figures = 5; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' /> |
|
| 16 | + /** |
|
| 17 | + * Billing module utilities definition |
|
| 18 | + * |
|
| 19 | + * @author Alexandre Techer - Eoxia dev team <[email protected]> |
|
| 20 | + * @version 0.1 |
|
| 21 | + * @package includes |
|
| 22 | + * @subpackage modules |
|
| 23 | + */ |
|
| 24 | + class wpshop_modules_billing |
|
| 25 | + { |
|
| 26 | + /** |
|
| 27 | + * Create a new instance for the current module - Billing |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + /** Add custom template for current module */ |
|
| 32 | + add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
| 33 | + |
|
| 34 | + /** In case wpshop is set on sale mode and not on view catalog only, Ad billign options */ |
|
| 35 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 36 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 37 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 38 | + |
|
| 39 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 40 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 41 | + /** Add module option to wpshop general options */ |
|
| 42 | + add_filter('wpshop_options', array(&$this, 'add_options'), 9); |
|
| 43 | + add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Filter |
|
| 48 | + add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Load module/addon automatically to existing template list |
|
| 53 | + * |
|
| 54 | + * @param array $templates The current template definition |
|
| 55 | + * |
|
| 56 | + * @return array The template with new elements |
|
| 57 | + */ |
|
| 58 | + public function custom_template_load($templates) |
|
| 59 | + { |
|
| 60 | + include 'templates/common/main_elements.tpl.php'; |
|
| 61 | + $wpshop_template = $tpl_element; |
|
| 62 | + /* Get custom frontend template */ |
|
| 63 | + if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) { |
|
| 64 | + require_once get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php'; |
|
| 65 | + if (!empty($tpl_element)) { |
|
| 66 | + $wpshop_template['common']['custom'] = ($tpl_element); |
|
| 67 | + } |
|
| 68 | + unset($tpl_element); |
|
| 69 | + } |
|
| 70 | + $wpshop_display = new wpshop_display(); |
|
| 71 | + $templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates); |
|
| 72 | + |
|
| 73 | + unset($tpl_element); |
|
| 74 | + |
|
| 75 | + return $templates; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Declare option groups for the module |
|
| 80 | + */ |
|
| 81 | + public function add_options($option_group) |
|
| 82 | + { |
|
| 83 | + $option_group['wpshop_billing_info'] = |
|
| 84 | + array('label' => __('Billing', 'wpshop'), |
|
| 85 | + 'subgroups' => array( |
|
| 86 | + 'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'), |
|
| 87 | + ), |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + return $option_group; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Declare the different options in groups for the module |
|
| 95 | + */ |
|
| 96 | + public function declare_options() |
|
| 97 | + { |
|
| 98 | + add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info'); |
|
| 99 | + |
|
| 100 | + register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures')); |
|
| 101 | + add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 102 | + |
|
| 103 | + register_setting('wpshop_options', 'wpshop_billing_address', array(&$this, 'wpshop_billing_address_validator')); |
|
| 104 | + add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 105 | + add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 106 | + |
|
| 107 | + $quotation_option = get_option('wpshop_addons'); |
|
| 108 | + if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) { |
|
| 109 | + add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info'); |
|
| 110 | + |
|
| 111 | + register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time')); |
|
| 112 | + add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 113 | + $payment_option = get_option('wps_payment_mode'); |
|
| 114 | + if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) { |
|
| 115 | + register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation')); |
|
| 116 | + add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 117 | + } |
|
| 118 | + register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation')); |
|
| 119 | + add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function wpshop_options_validate_wpshop_bic_to_quotation($input) |
|
| 125 | + { |
|
| 126 | + return $input; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function wpshop_bic_to_quotation_field() |
|
| 130 | + { |
|
| 131 | + $add_quotation_option = get_option('wpshop_paymentMethod_options'); |
|
| 132 | + $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />'; |
|
| 133 | + echo $output; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function billing_options_main_explanation() |
|
| 137 | + { |
|
| 138 | + |
|
| 139 | + } |
|
| 140 | + public function quotation_options_main_explanation() |
|
| 141 | + { |
|
| 142 | + |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function wpshop_options_validate_quotation_validate_time($input) |
|
| 146 | + { |
|
| 147 | + return $input; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function wpshop_billing_number_figures_field() |
|
| 151 | + { |
|
| 152 | + $wpshop_billing_number_figures = get_option('wpshop_billing_number_figures'); |
|
| 153 | + $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null; |
|
| 154 | + if (empty($wpshop_billing_number_figures)) { |
|
| 155 | + $wpshop_billing_number_figures = 5; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' /> |
|
| 159 | 159 | <a href="#" title="' . __('Number of figures to make appear on invoices', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>'; |
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function wpshop_options_validate_billing_number_figures($input) |
|
| 163 | - { |
|
| 164 | - return $input; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - public function wpshop_billing_address_validator($input) |
|
| 168 | - { |
|
| 169 | - global $wpdb; |
|
| 170 | - $t = wps_address::get_addresss_form_fields_by_type($input['choice']); |
|
| 171 | - |
|
| 172 | - $the_code = ''; |
|
| 173 | - foreach ($t[$input['choice']] as $group_id => $group_def) { |
|
| 174 | - if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) { |
|
| 175 | - $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name']; |
|
| 176 | - continue; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $the_code; |
|
| 180 | - |
|
| 181 | - if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') { |
|
| 182 | - if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { |
|
| 183 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code)); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $billing_option = get_option('wpshop_billing_address'); |
|
| 188 | - if (!empty($billing_option) && !empty($billing_option['display_model'])) { |
|
| 189 | - $input['display_model'] = $billing_option['display_model']; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return $input; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - public function wpshop_billing_address_choice_field() |
|
| 196 | - { |
|
| 197 | - global $wpdb; |
|
| 198 | - $output = ''; |
|
| 199 | - |
|
| 200 | - $wpshop_billing_address = get_option('wpshop_billing_address'); |
|
| 201 | - |
|
| 202 | - $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 203 | - $entity_id = $wpdb->get_var($query); |
|
| 204 | - |
|
| 205 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 206 | - $content = $wpdb->get_results($query); |
|
| 207 | - |
|
| 208 | - /* Field for billing address type choice */ |
|
| 209 | - $input_def['name'] = 'wpshop_billing_address[choice]'; |
|
| 210 | - $input_def['id'] = 'wpshop_billing_address_choice'; |
|
| 211 | - $input_def['possible_value'] = $content; |
|
| 212 | - $input_def['type'] = 'select'; |
|
| 213 | - $input_def['value'] = $wpshop_billing_address['choice']; |
|
| 214 | - $output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>'; |
|
| 215 | - |
|
| 216 | - /* Field for integrate billign form into register form */ |
|
| 217 | - $input_def = array(); |
|
| 218 | - $input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]'; |
|
| 219 | - $input_def['id'] = 'wpshop_billing_address_integrate_into_register_form'; |
|
| 220 | - $input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop')); |
|
| 221 | - $input_def['valueToPut'] = 'index'; |
|
| 222 | - $input_def['options_label']['original'] = true; |
|
| 223 | - $input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" '; |
|
| 224 | - $input_def['type'] = 'checkbox'; |
|
| 225 | - $input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : ''); |
|
| 226 | - $output .= ' |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + public function wpshop_options_validate_billing_number_figures($input) |
|
| 163 | + { |
|
| 164 | + return $input; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + public function wpshop_billing_address_validator($input) |
|
| 168 | + { |
|
| 169 | + global $wpdb; |
|
| 170 | + $t = wps_address::get_addresss_form_fields_by_type($input['choice']); |
|
| 171 | + |
|
| 172 | + $the_code = ''; |
|
| 173 | + foreach ($t[$input['choice']] as $group_id => $group_def) { |
|
| 174 | + if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) { |
|
| 175 | + $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name']; |
|
| 176 | + continue; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $the_code; |
|
| 180 | + |
|
| 181 | + if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') { |
|
| 182 | + if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { |
|
| 183 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code)); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 188 | + if (!empty($billing_option) && !empty($billing_option['display_model'])) { |
|
| 189 | + $input['display_model'] = $billing_option['display_model']; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return $input; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + public function wpshop_billing_address_choice_field() |
|
| 196 | + { |
|
| 197 | + global $wpdb; |
|
| 198 | + $output = ''; |
|
| 199 | + |
|
| 200 | + $wpshop_billing_address = get_option('wpshop_billing_address'); |
|
| 201 | + |
|
| 202 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 203 | + $entity_id = $wpdb->get_var($query); |
|
| 204 | + |
|
| 205 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 206 | + $content = $wpdb->get_results($query); |
|
| 207 | + |
|
| 208 | + /* Field for billing address type choice */ |
|
| 209 | + $input_def['name'] = 'wpshop_billing_address[choice]'; |
|
| 210 | + $input_def['id'] = 'wpshop_billing_address_choice'; |
|
| 211 | + $input_def['possible_value'] = $content; |
|
| 212 | + $input_def['type'] = 'select'; |
|
| 213 | + $input_def['value'] = $wpshop_billing_address['choice']; |
|
| 214 | + $output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>'; |
|
| 215 | + |
|
| 216 | + /* Field for integrate billign form into register form */ |
|
| 217 | + $input_def = array(); |
|
| 218 | + $input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]'; |
|
| 219 | + $input_def['id'] = 'wpshop_billing_address_integrate_into_register_form'; |
|
| 220 | + $input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop')); |
|
| 221 | + $input_def['valueToPut'] = 'index'; |
|
| 222 | + $input_def['options_label']['original'] = true; |
|
| 223 | + $input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" '; |
|
| 224 | + $input_def['type'] = 'checkbox'; |
|
| 225 | + $input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : ''); |
|
| 226 | + $output .= ' |
|
| 227 | 227 | <div class="wpshop_include_billing_form_into_register_container" > |
| 228 | 228 | ' . wpshop_form::check_input_type($input_def) . ' |
| 229 | 229 | <input type="hidden" name="wpshop_ajax_integrate_billin_into_register" id="wpshop_ajax_integrate_billin_into_register" value="' . wp_create_nonce('wpshop_ajax_integrate_billin_into_register') . '" /> |
@@ -231,892 +231,892 @@ discard block |
||
| 231 | 231 | <div class="wpshop_include_billing_form_into_register_where" ></div> |
| 232 | 232 | </div>'; |
| 233 | 233 | |
| 234 | - echo $output; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - public function wpshop_billing_address_include_into_register_field() |
|
| 238 | - { |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - public function wpshop_quotation_validate_time_field() |
|
| 243 | - { |
|
| 244 | - $quotation_option = get_option('wpshop_quotation_validate_time'); |
|
| 245 | - $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />'; |
|
| 246 | - $output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">'; |
|
| 247 | - $output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>'; |
|
| 248 | - $output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>'; |
|
| 249 | - $output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>'; |
|
| 250 | - $output .= '</select>'; |
|
| 251 | - |
|
| 252 | - echo $output; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Generate a new invoice number |
|
| 257 | - * |
|
| 258 | - * @param integer $order_id The order identifier we want to generate the new invoice number for |
|
| 259 | - * |
|
| 260 | - * @return string The new invoice number |
|
| 261 | - */ |
|
| 262 | - public static function generate_invoice_number($order_id) |
|
| 263 | - { |
|
| 264 | - /** Get configuration about the number of figure dor invoice number */ |
|
| 265 | - |
|
| 266 | - $number_figures = get_option('wpshop_billing_number_figures', false); |
|
| 267 | - |
|
| 268 | - /** If the number doesn't exist, we create a default one */ |
|
| 269 | - if (!$number_figures) { |
|
| 270 | - update_option('wpshop_billing_number_figures', 5); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** sleep my script, SLEEP I SAY ! **/ |
|
| 274 | - $rand_time = rand(1000, 200000); |
|
| 275 | - usleep($rand_time); |
|
| 276 | - /** GET UP !! **/ |
|
| 277 | - |
|
| 278 | - /** Get last invoice number */ |
|
| 279 | - $billing_current_number = get_option('wpshop_billing_current_number', false); |
|
| 280 | - |
|
| 281 | - /** If the counter doesn't exist, we initiate it */ |
|
| 282 | - if (!$billing_current_number) { |
|
| 283 | - $billing_current_number = 1; |
|
| 284 | - } else { |
|
| 285 | - $billing_current_number++; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** Check if number exists **/ |
|
| 289 | - $billing_current_number_checking = get_option('wpshop_billing_current_number', false); |
|
| 290 | - if ($billing_current_number_checking == $billing_current_number) { |
|
| 291 | - $billing_current_number++; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - update_option('wpshop_billing_current_number', $billing_current_number); |
|
| 295 | - |
|
| 296 | - /** Create the new invoice number with all parameters viewed above */ |
|
| 297 | - $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 298 | - |
|
| 299 | - return $invoice_ref; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Generate output for an invoice |
|
| 304 | - * |
|
| 305 | - * @param integer $order_id |
|
| 306 | - * @param string $invoice_ref |
|
| 307 | - * |
|
| 308 | - * @return string The invoice output in case no error is found. The error in other case |
|
| 309 | - */ |
|
| 310 | - public static function generate_html_invoice($order_id, $invoice_ref) |
|
| 311 | - { |
|
| 312 | - global $wpdb; |
|
| 313 | - |
|
| 314 | - $date_output_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 315 | - $count_products = 0; |
|
| 316 | - |
|
| 317 | - if (!empty($order_id)) { |
|
| 318 | - $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 319 | - |
|
| 320 | - $discounts_exists = false; |
|
| 321 | - |
|
| 322 | - $is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false; |
|
| 323 | - /** Check if it's a partial payment bill **/ |
|
| 324 | - $is_partial_payment = false; |
|
| 325 | - if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 326 | - foreach ($order_postmeta['order_payment']['received'] as $key => $payment) { |
|
| 327 | - if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) { |
|
| 328 | - $is_partial_payment = true; |
|
| 329 | - break; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) { |
|
| 333 | - $is_partial_payment = true; |
|
| 334 | - } elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 335 | - $is_partial_payment = true; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** Check it is a shipping slip **/ |
|
| 339 | - $bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false; |
|
| 340 | - if ($bon_colisage) { |
|
| 341 | - $bon_colisage = true; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - if (!empty($order_postmeta)) { |
|
| 345 | - $tpl_component = array(); |
|
| 346 | - |
|
| 347 | - /** Billing Header **/ |
|
| 348 | - //Logo |
|
| 349 | - $logo_options = get_option('wpshop_logo'); |
|
| 350 | - $tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : ''; |
|
| 351 | - |
|
| 352 | - // Title |
|
| 353 | - $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop')); |
|
| 234 | + echo $output; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + public function wpshop_billing_address_include_into_register_field() |
|
| 238 | + { |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + public function wpshop_quotation_validate_time_field() |
|
| 243 | + { |
|
| 244 | + $quotation_option = get_option('wpshop_quotation_validate_time'); |
|
| 245 | + $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />'; |
|
| 246 | + $output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">'; |
|
| 247 | + $output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>'; |
|
| 248 | + $output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>'; |
|
| 249 | + $output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>'; |
|
| 250 | + $output .= '</select>'; |
|
| 251 | + |
|
| 252 | + echo $output; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Generate a new invoice number |
|
| 257 | + * |
|
| 258 | + * @param integer $order_id The order identifier we want to generate the new invoice number for |
|
| 259 | + * |
|
| 260 | + * @return string The new invoice number |
|
| 261 | + */ |
|
| 262 | + public static function generate_invoice_number($order_id) |
|
| 263 | + { |
|
| 264 | + /** Get configuration about the number of figure dor invoice number */ |
|
| 265 | + |
|
| 266 | + $number_figures = get_option('wpshop_billing_number_figures', false); |
|
| 267 | + |
|
| 268 | + /** If the number doesn't exist, we create a default one */ |
|
| 269 | + if (!$number_figures) { |
|
| 270 | + update_option('wpshop_billing_number_figures', 5); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** sleep my script, SLEEP I SAY ! **/ |
|
| 274 | + $rand_time = rand(1000, 200000); |
|
| 275 | + usleep($rand_time); |
|
| 276 | + /** GET UP !! **/ |
|
| 277 | + |
|
| 278 | + /** Get last invoice number */ |
|
| 279 | + $billing_current_number = get_option('wpshop_billing_current_number', false); |
|
| 280 | + |
|
| 281 | + /** If the counter doesn't exist, we initiate it */ |
|
| 282 | + if (!$billing_current_number) { |
|
| 283 | + $billing_current_number = 1; |
|
| 284 | + } else { |
|
| 285 | + $billing_current_number++; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** Check if number exists **/ |
|
| 289 | + $billing_current_number_checking = get_option('wpshop_billing_current_number', false); |
|
| 290 | + if ($billing_current_number_checking == $billing_current_number) { |
|
| 291 | + $billing_current_number++; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + update_option('wpshop_billing_current_number', $billing_current_number); |
|
| 295 | + |
|
| 296 | + /** Create the new invoice number with all parameters viewed above */ |
|
| 297 | + $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 298 | + |
|
| 299 | + return $invoice_ref; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Generate output for an invoice |
|
| 304 | + * |
|
| 305 | + * @param integer $order_id |
|
| 306 | + * @param string $invoice_ref |
|
| 307 | + * |
|
| 308 | + * @return string The invoice output in case no error is found. The error in other case |
|
| 309 | + */ |
|
| 310 | + public static function generate_html_invoice($order_id, $invoice_ref) |
|
| 311 | + { |
|
| 312 | + global $wpdb; |
|
| 313 | + |
|
| 314 | + $date_output_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 315 | + $count_products = 0; |
|
| 316 | + |
|
| 317 | + if (!empty($order_id)) { |
|
| 318 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 319 | + |
|
| 320 | + $discounts_exists = false; |
|
| 321 | + |
|
| 322 | + $is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false; |
|
| 323 | + /** Check if it's a partial payment bill **/ |
|
| 324 | + $is_partial_payment = false; |
|
| 325 | + if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 326 | + foreach ($order_postmeta['order_payment']['received'] as $key => $payment) { |
|
| 327 | + if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) { |
|
| 328 | + $is_partial_payment = true; |
|
| 329 | + break; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) { |
|
| 333 | + $is_partial_payment = true; |
|
| 334 | + } elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 335 | + $is_partial_payment = true; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** Check it is a shipping slip **/ |
|
| 339 | + $bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false; |
|
| 340 | + if ($bon_colisage) { |
|
| 341 | + $bon_colisage = true; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + if (!empty($order_postmeta)) { |
|
| 345 | + $tpl_component = array(); |
|
| 346 | + |
|
| 347 | + /** Billing Header **/ |
|
| 348 | + //Logo |
|
| 349 | + $logo_options = get_option('wpshop_logo'); |
|
| 350 | + $tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : ''; |
|
| 351 | + |
|
| 352 | + // Title |
|
| 353 | + $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop')); |
|
| 354 | 354 | |
| 355 | 355 | // if ( empty($order_postmeta['order_invoice_ref']) ) { |
| 356 | - // $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop'); |
|
| 357 | - // $is_partial_payment = true; |
|
| 358 | - // } |
|
| 359 | - |
|
| 360 | - if ($bon_colisage) { |
|
| 361 | - $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop'); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null); |
|
| 365 | - if ($bon_colisage) { |
|
| 366 | - $tpl_component['INVOICE_ORDER_INVOICE_REF'] = ''; |
|
| 367 | - } |
|
| 368 | - $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']); |
|
| 369 | - $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)); |
|
| 370 | - |
|
| 371 | - /** Validate period for Quotation **/ |
|
| 372 | - if ($is_quotation) { |
|
| 373 | - $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']); |
|
| 374 | - } else { |
|
| 375 | - $tpl_component['INVOICE_VALIDATE_TIME'] = ''; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME']; |
|
| 379 | - |
|
| 380 | - $tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : ''; |
|
| 381 | - |
|
| 382 | - // Sender & receiver addresses |
|
| 383 | - $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part(); |
|
| 384 | - $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage); |
|
| 385 | - |
|
| 386 | - $tpl_component['INVOICE_TRACKING'] = ''; |
|
| 387 | - $first = false; |
|
| 388 | - if (!empty($order_postmeta['order_trackingNumber'])) { |
|
| 389 | - $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber']; |
|
| 390 | - $first = true; |
|
| 391 | - } |
|
| 392 | - if (!empty($order_postmeta['order_trackingLink'])) { |
|
| 393 | - if (!$first) { |
|
| 394 | - $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink']; |
|
| 395 | - } else { |
|
| 396 | - $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink']; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** Items Tab **/ |
|
| 401 | - $order_tva = array(); |
|
| 402 | - if ($bon_colisage) { |
|
| 403 | - $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common'); |
|
| 404 | - } else { |
|
| 405 | - $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common'); |
|
| 406 | - //if ( !$is_quotation ) { |
|
| 407 | - /** Check if products have discounts **/ |
|
| 408 | - if (!empty($order_postmeta['order_items']) && !$is_partial_payment) { |
|
| 409 | - foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 410 | - if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) { |
|
| 411 | - $discounts_exists = true; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if ($discounts_exists) { |
|
| 417 | - $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common'); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - //} |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - $total_discounted = 0; |
|
| 424 | - $tpl_component['INVOICE_ROWS'] = ''; |
|
| 425 | - |
|
| 426 | - if (!$is_partial_payment) { |
|
| 427 | - if (!empty($order_postmeta['order_items'])) { |
|
| 428 | - foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 429 | - $sub_tpl_component = array(); |
|
| 430 | - $count_products += $item['item_qty']; |
|
| 431 | - $barcode = get_post_meta($item['item_id'], '_barcode', true); |
|
| 432 | - if (empty($barcode)) { |
|
| 433 | - $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true); |
|
| 434 | - $barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : ''; |
|
| 435 | - |
|
| 436 | - if (empty($barcode)) { |
|
| 437 | - $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 438 | - $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code'); |
|
| 439 | - $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']); |
|
| 440 | - $barcode = $wpdb->get_var($query); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-'; |
|
| 444 | - |
|
| 445 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref']; |
|
| 446 | - |
|
| 447 | - /** Item name **/ |
|
| 448 | - $is_variation = false; |
|
| 449 | - if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 450 | - $is_variation = true; |
|
| 451 | - $parent_def = wpshop_products::get_parent_variation($item['item_id']); |
|
| 452 | - if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 453 | - $parent_post = $parent_def['parent_post']; |
|
| 454 | - $item_parent_id = $parent_post->ID; |
|
| 455 | - $item_title = $parent_post->post_title; |
|
| 456 | - } |
|
| 457 | - } else { |
|
| 458 | - $item_title = $item['item_name']; |
|
| 459 | - } |
|
| 460 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title; |
|
| 461 | - /** Get attribute order for current product */ |
|
| 462 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 463 | - $output_order = array(); |
|
| 464 | - if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 465 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 466 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 467 | - if (!empty($attribute_def->code)) { |
|
| 468 | - $output_order[$attribute_def->code] = $position; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common'); |
|
| 475 | - ksort($variation_attribute_ordered['attribute_list']); |
|
| 476 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = ''; |
|
| 477 | - foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 478 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output; |
|
| 479 | - } |
|
| 480 | - $post_content = get_post_field('post_content', $item['item_id']); |
|
| 481 | - if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/!empty($post_content) && false) { |
|
| 482 | - if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) { |
|
| 483 | - //$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>'; |
|
| 484 | - } |
|
| 485 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>'; |
|
| 486 | - } |
|
| 487 | - $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : ''; |
|
| 488 | - unset($detail_tpl_component); |
|
| 489 | - |
|
| 490 | - $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty']; |
|
| 491 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', '')); |
|
| 492 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', '')); |
|
| 493 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', ''); |
|
| 494 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', ''); |
|
| 495 | - /** TVA **/ |
|
| 496 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', ''); |
|
| 497 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate']; |
|
| 498 | - |
|
| 499 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', ''); |
|
| 500 | - |
|
| 501 | - /** Checking Rate amount **/ |
|
| 502 | - if (!$bon_colisage) { |
|
| 503 | - $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id); |
|
| 504 | - if (!$checking) { |
|
| 505 | - return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop'); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - if ($bon_colisage) { |
|
| 510 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common'); |
|
| 511 | - } else { |
|
| 512 | - if ($discounts_exists) { |
|
| 513 | - $discounted_total_per_item = $item['item_total_ht']; |
|
| 514 | - /** Unit Discount **/ |
|
| 515 | - if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) { |
|
| 516 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', ''); |
|
| 517 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', ''); |
|
| 518 | - $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount']; |
|
| 519 | - } else { |
|
| 520 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 521 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** Global Discount **/ |
|
| 525 | - if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) { |
|
| 526 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', ''); |
|
| 527 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', ''); |
|
| 528 | - $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount']; |
|
| 529 | - } else { |
|
| 530 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 531 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $total_discounted += $discounted_total_per_item; |
|
| 535 | - /** Total HT Discounted **/ |
|
| 536 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', ''); |
|
| 537 | - |
|
| 538 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 539 | - } else { |
|
| 540 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - unset($sub_tpl_component); |
|
| 544 | - |
|
| 545 | - /** Check TVA **/ |
|
| 546 | - if (empty($order_tva[$item['item_tva_rate']])) { |
|
| 547 | - $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 548 | - } else { |
|
| 549 | - $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** Display Partials payments **/ |
|
| 556 | - $total_partial_payment = 0; |
|
| 557 | - $last_payment = 0; |
|
| 558 | - $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 559 | - if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 560 | - foreach ($order_postmeta['order_payment']['received'] as $received_payment) { |
|
| 561 | - if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) { |
|
| 562 | - if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) { |
|
| 563 | - $sub_tpl_component = array(); |
|
| 564 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 565 | - |
|
| 566 | - /** Item name **/ |
|
| 567 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']); |
|
| 568 | - $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 569 | - $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 570 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 571 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 572 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 573 | - |
|
| 574 | - /** TVA **/ |
|
| 575 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 576 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 577 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 578 | - |
|
| 579 | - if ($discounts_exists) { |
|
| 580 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 581 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 582 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 583 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 584 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 585 | - |
|
| 586 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 587 | - } else { |
|
| 588 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - unset($sub_tpl_component); |
|
| 593 | - $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 594 | - } else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) { |
|
| 595 | - $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - } else { |
|
| 601 | - /** Display Partials payments **/ |
|
| 602 | - $total_partial_payment = 0; |
|
| 603 | - $last_payment = 0; |
|
| 604 | - if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 605 | - foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) { |
|
| 606 | - if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) { |
|
| 607 | - $sub_tpl_component = array(); |
|
| 608 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 609 | - /** Item name **/ |
|
| 610 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1); |
|
| 611 | - $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 612 | - $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 613 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 614 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 615 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 616 | - /** TVA **/ |
|
| 617 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 618 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 619 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 620 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 621 | - unset($sub_tpl_component); |
|
| 622 | - $total_partial_payment += $received_payment['received_amount']; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** Summary of order **/ |
|
| 629 | - $summary_tpl_component = array(); |
|
| 630 | - $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = ''; |
|
| 631 | - if (!$bon_colisage) { |
|
| 632 | - if (!empty($order_tva)) { |
|
| 633 | - foreach ($order_tva as $tax_rate => $tax_amount) { |
|
| 634 | - if ($tax_amount > 0) { |
|
| 635 | - $tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate; |
|
| 636 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 637 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 638 | - $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 639 | - unset($sub_tpl_component); |
|
| 640 | - } elseif ($is_partial_payment) { |
|
| 641 | - $tax_rate = 0; |
|
| 642 | - $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 643 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 644 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 645 | - $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 646 | - unset($sub_tpl_component); |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** If Discount Exist **/ |
|
| 652 | - // Checking Discounts on order |
|
| 653 | - if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) { |
|
| 654 | - $discounts_exists = true; |
|
| 655 | - // Calcul discount on Order |
|
| 656 | - switch ($order_postmeta['order_discount_type']) { |
|
| 657 | - case 'amount': |
|
| 658 | - $total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', ''); |
|
| 659 | - break; |
|
| 660 | - case 'percent': |
|
| 661 | - $total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100); |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - if (!empty($total_discounted) && $discounts_exists) { |
|
| 666 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop'); |
|
| 667 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 668 | - $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 669 | - unset($sub_tpl_component); |
|
| 670 | - } else { |
|
| 671 | - $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = ''; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - $shipping_cost = 0; |
|
| 675 | - if (!$is_partial_payment) { |
|
| 676 | - if (!empty($order_postmeta['order_shipping_cost'])) { |
|
| 677 | - $shipping_cost = $order_postmeta['order_shipping_cost']; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC'); |
|
| 681 | - $shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100)); |
|
| 682 | - $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', ''); |
|
| 683 | - $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', ''); |
|
| 684 | - //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' ); |
|
| 685 | - |
|
| 686 | - $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' ); |
|
| 687 | - $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', ''); |
|
| 688 | - |
|
| 689 | - $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 690 | - |
|
| 691 | - $total_payment = 0; |
|
| 692 | - |
|
| 693 | - /** Amount paid **/ |
|
| 694 | - if (empty($order_postmeta['order_invoice_ref'])) { |
|
| 695 | - foreach ($order_postmeta['order_payment']['received'] as $key => $value) { |
|
| 696 | - if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) { |
|
| 697 | - $total_payment = number_format($value['received_amount'], 2, ',', ''); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - } else { |
|
| 701 | - $total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total']; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop'); |
|
| 705 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 706 | - //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ? number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 707 | - $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 708 | - unset($sub_tpl_component); |
|
| 709 | - |
|
| 710 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop'); |
|
| 711 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products; |
|
| 712 | - $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 713 | - unset($sub_tpl_component); |
|
| 714 | - |
|
| 715 | - /** If Discount Exist **/ |
|
| 716 | - if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) { |
|
| 717 | - $tpl_discount_component = array(); |
|
| 718 | - $tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', ''); |
|
| 719 | - |
|
| 720 | - $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 721 | - $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common'); |
|
| 722 | - unset($tpl_discount_component); |
|
| 723 | - } else { |
|
| 724 | - $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = ''; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop'); |
|
| 728 | - |
|
| 729 | - $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common'); |
|
| 730 | - unset($summary_tpl_component); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** IBAN Include on quotation **/ |
|
| 734 | - if ($is_quotation) { |
|
| 735 | - /** If admin want to include his IBAN to quotation */ |
|
| 736 | - $iban_options = get_option('wpshop_paymentMethod_options'); |
|
| 737 | - $payment_options = get_option('wps_payment_mode'); |
|
| 738 | - if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') { |
|
| 739 | - if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) { |
|
| 740 | - $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>'; |
|
| 741 | - $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>'; |
|
| 742 | - $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>'; |
|
| 743 | - $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>'; |
|
| 744 | - $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>'; |
|
| 745 | - } |
|
| 746 | - } else { |
|
| 747 | - $tpl_component['IBAN_INFOS'] = ''; |
|
| 748 | - } |
|
| 749 | - } else { |
|
| 750 | - $tpl_component['IBAN_INFOS'] = ''; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - /** Received payements **/ |
|
| 754 | - if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) { |
|
| 755 | - $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id); |
|
| 756 | - } else { |
|
| 757 | - $tpl_component['RECEIVED_PAYMENT'] = ''; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** Invoice footer **/ |
|
| 761 | - $tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice(); |
|
| 762 | - |
|
| 763 | - $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common'); |
|
| 764 | - } else { |
|
| 765 | - $output = __('No order information has been found', 'wpshop'); |
|
| 766 | - } |
|
| 767 | - } else { |
|
| 768 | - $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop'); |
|
| 769 | - } |
|
| 770 | - return $output; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Return the payment list part |
|
| 775 | - * @param integer $order_id |
|
| 776 | - * @return string |
|
| 777 | - */ |
|
| 778 | - public static function generate_received_payment_part($order_id) |
|
| 779 | - { |
|
| 780 | - $date_ouput_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 781 | - $output = ''; |
|
| 782 | - $tpl_component = array(); |
|
| 783 | - $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = ''; |
|
| 784 | - if (!empty($order_id)) { |
|
| 785 | - $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 786 | - if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) { |
|
| 787 | - $wps_payment_option = get_option('wps_payment_mode'); |
|
| 788 | - foreach ($order_postmeta['order_payment']['received'] as $payment) { |
|
| 789 | - if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) { |
|
| 790 | - $sub_tpl_component = array(); |
|
| 791 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0; |
|
| 792 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : ''; |
|
| 793 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : '')); |
|
| 794 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : ''; |
|
| 795 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : ''; |
|
| 796 | - $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - $output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 801 | - unset($tpl_component); |
|
| 802 | - } |
|
| 803 | - return $output; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** Return the validity period of a quotation **/ |
|
| 807 | - public static function quotation_validate_period($quotation_date) |
|
| 808 | - { |
|
| 809 | - $quotation_options = get_option('wpshop_quotation_validate_time'); |
|
| 810 | - if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) { |
|
| 811 | - $timestamp_quotation = strtotime($quotation_date); |
|
| 812 | - $timestamp_validity_date_quotation = 0; |
|
| 813 | - $query = ''; |
|
| 814 | - $date = ''; |
|
| 815 | - global $wpdb; |
|
| 816 | - switch ($quotation_options['time_type']) { |
|
| 817 | - case 'day': |
|
| 818 | - $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s DAY)", $quotation_date, $quotation_options['number']); |
|
| 819 | - break; |
|
| 820 | - case 'month': |
|
| 821 | - $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s MONTH)", $quotation_date, $quotation_options['number']); |
|
| 822 | - break; |
|
| 823 | - case 'year': |
|
| 824 | - $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s YEAR)", $quotation_date, $quotation_options['number']); |
|
| 825 | - break; |
|
| 826 | - default: |
|
| 827 | - $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL '15' DAY)", $quotation_date); |
|
| 828 | - break; |
|
| 829 | - } |
|
| 830 | - if ($query != null) { |
|
| 831 | - $date = mysql2date('d F Y', $wpdb->get_var($query), true); |
|
| 832 | - } |
|
| 833 | - return sprintf(__('Quotation validity date %s', 'wpshop'), $date); |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Generate HTML invoice to be sended by email |
|
| 839 | - * @param integer $order_id |
|
| 840 | - * @param string $invoice_ref |
|
| 841 | - * @return string |
|
| 842 | - */ |
|
| 843 | - public static function generate_invoice_for_email($order_id, $invoice_ref = '') |
|
| 844 | - { |
|
| 845 | - /** Generate the PDF file for the invoice **/ |
|
| 846 | - $is_ok = false; |
|
| 847 | - if (!empty($invoice_ref)) { |
|
| 848 | - require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'; |
|
| 849 | - try { |
|
| 850 | - $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref); |
|
| 851 | - $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
|
| 852 | - $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
|
| 853 | - |
|
| 854 | - $html2pdf->setDefaultFont('Arial'); |
|
| 855 | - $html2pdf->writeHTML($html_content); |
|
| 856 | - $html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F'); |
|
| 857 | - $is_ok = true; |
|
| 858 | - } catch (HTML2PDF_exception $e) { |
|
| 859 | - echo $e; |
|
| 860 | - exit; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : ''; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * Generate Sender part invoice template |
|
| 868 | - * @return Ambigous <string, string> |
|
| 869 | - */ |
|
| 870 | - public static function generate_invoice_sender_part() |
|
| 871 | - { |
|
| 872 | - $output = ''; |
|
| 873 | - $company = get_option('wpshop_company_info', array()); |
|
| 874 | - $emails = get_option('wpshop_emails', array()); |
|
| 875 | - if (!empty($company)) { |
|
| 876 | - $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 877 | - $tpl_component['COMPANY_WEBSITE'] = get_option('siteurl'); |
|
| 878 | - foreach ($company as $company_info_key => $company_info_value) { |
|
| 879 | - switch ($company_info_key) { |
|
| 880 | - case 'company_rcs': |
|
| 881 | - $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 882 | - break; |
|
| 883 | - case 'company_capital': |
|
| 884 | - $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 885 | - break; |
|
| 886 | - case 'company_siren': |
|
| 887 | - $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 888 | - break; |
|
| 889 | - case 'company_siret': |
|
| 890 | - $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 891 | - break; |
|
| 892 | - case 'company_tva_intra': |
|
| 893 | - $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 894 | - break; |
|
| 895 | - case 'company_legal_statut': |
|
| 896 | - $array_state_compagny = wpshop_company_options::get_legal_status(); |
|
| 897 | - $data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop'); |
|
| 898 | - break; |
|
| 899 | - default: |
|
| 900 | - $data = $company_info_value; |
|
| 901 | - break; |
|
| 902 | - } |
|
| 903 | - $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 904 | - } |
|
| 905 | - $output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common'); |
|
| 906 | - } |
|
| 907 | - return $output; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * Generate Receiver part template |
|
| 912 | - * @param unknown_type $order_id |
|
| 913 | - * @param unknown_type $bon_colisage |
|
| 914 | - * @return Ambigous <string, string> |
|
| 915 | - */ |
|
| 916 | - public static function generate_receiver_part($order_id, $bon_colisage = false) |
|
| 917 | - { |
|
| 918 | - $output = ''; |
|
| 919 | - $order_customer_postmeta = get_post_meta($order_id, '_order_info', true); |
|
| 920 | - $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 921 | - |
|
| 922 | - if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) { |
|
| 923 | - $address_info = $order_customer_postmeta['shipping']['address']; |
|
| 924 | - } else { |
|
| 925 | - if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) { |
|
| 926 | - $address_info = $order_customer_postmeta['billing']['address']; |
|
| 927 | - } else { |
|
| 928 | - $address_info = array(); |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - if (!empty($order_customer_postmeta) && !empty($address_info)) { |
|
| 933 | - $default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY'); |
|
| 934 | - foreach ($default_address_attributes as $default_address_attribute) { |
|
| 935 | - $tpl_component[$default_address_attribute] = ''; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - foreach ($address_info as $order_customer_info_key => $order_customer_info_value) { |
|
| 939 | - $tpl_component[strtoupper($order_customer_info_key)] = ''; |
|
| 940 | - if ($order_customer_info_key == 'civility') { |
|
| 941 | - global $wpdb; |
|
| 942 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value); |
|
| 943 | - $civility = $wpdb->get_row($query); |
|
| 944 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : ''; |
|
| 945 | - } else if ($order_customer_info_key == 'country') { |
|
| 946 | - foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) { |
|
| 947 | - if ($order_customer_info_value == $key) { |
|
| 948 | - $tpl_component[strtoupper($order_customer_info_key)] = $value; |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - } elseif ($order_customer_info_key == 'phone') { |
|
| 952 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : ''; |
|
| 953 | - } else { |
|
| 954 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : ''; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - if (empty($tpl_component['PHONE'])) { |
|
| 959 | - $tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : ''; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) { |
|
| 963 | - $user_info = get_userdata($order_postmeta['customer_id']); |
|
| 964 | - $tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : ''; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - $output = wpshop_display::display_template_element('invoice_receiver_formatted_address', $tpl_component, array(), 'common'); |
|
| 968 | - } |
|
| 969 | - return $output; |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - /** |
|
| 973 | - * Genrate Footer invoice |
|
| 974 | - * @return Ambigous <string, string> |
|
| 975 | - */ |
|
| 976 | - public static function generate_footer_invoice() |
|
| 977 | - { |
|
| 978 | - $output = ''; |
|
| 979 | - $company = get_option('wpshop_company_info', array()); |
|
| 980 | - $emails = get_option('wpshop_emails', array()); |
|
| 981 | - if (!empty($company)) { |
|
| 982 | - $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 983 | - $tpl_component['COMPANY_WEBSITE'] = site_url(); |
|
| 984 | - foreach ($company as $company_info_key => $company_info_value) { |
|
| 985 | - |
|
| 986 | - switch ($company_info_key) { |
|
| 987 | - case 'company_rcs': |
|
| 988 | - $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 989 | - break; |
|
| 990 | - case 'company_capital': |
|
| 991 | - $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 992 | - break; |
|
| 993 | - case 'company_siren': |
|
| 994 | - $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 995 | - break; |
|
| 996 | - case 'company_siret': |
|
| 997 | - $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 998 | - break; |
|
| 999 | - case 'company_tva_intra': |
|
| 1000 | - $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1001 | - break; |
|
| 1002 | - default: |
|
| 1003 | - $data = $company_info_value; |
|
| 1004 | - break; |
|
| 1005 | - } |
|
| 1006 | - $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 1007 | - } |
|
| 1008 | - $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common'); |
|
| 1009 | - } |
|
| 1010 | - return $output; |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * Check product price |
|
| 1015 | - * @param float $price_ht |
|
| 1016 | - * @param float $price_ati |
|
| 1017 | - * @param float $tva_amount |
|
| 1018 | - * @param float $tva_rate |
|
| 1019 | - * @param id $product_id |
|
| 1020 | - * @param string $invoice_ref |
|
| 1021 | - */ |
|
| 1022 | - public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id) |
|
| 1023 | - { |
|
| 1024 | - $checking = true; |
|
| 1025 | - $error_percent = 1; |
|
| 1026 | - |
|
| 1027 | - /** Check VAT Amount **/ |
|
| 1028 | - $formatted_tva_amount = number_format($tva_amount, 2, '.', ''); |
|
| 1029 | - $formatted_price_ht = number_format($price_ht, 2, '.', ''); |
|
| 1030 | - $formatted_price_ati = number_format($price_ati, 2, '.', ''); |
|
| 1031 | - $calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100)); |
|
| 1032 | - $unformatted = $formatted_price_ati - $calculated_price_excluding_tax; |
|
| 1033 | - $checked_tva_amount = number_format($unformatted, 2, '.', ''); |
|
| 1034 | - |
|
| 1035 | - if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) { |
|
| 1036 | - $error_infos = array(); |
|
| 1037 | - $error_infos['real_datas']['price_ati'] = $formatted_price_ati; |
|
| 1038 | - $error_infos['real_datas']['price_ht'] = $formatted_price_ht; |
|
| 1039 | - $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount; |
|
| 1040 | - |
|
| 1041 | - $error_infos['corrected_data'] = $checked_tva_amount; |
|
| 1042 | - self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos); |
|
| 1043 | - $checking = false; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - /** Check price ati **/ |
|
| 1047 | - $checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100)); |
|
| 1048 | - if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) { |
|
| 1049 | - self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id); |
|
| 1050 | - $checking = false; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - return $checking; |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * Alert administrator when have invoice error |
|
| 1058 | - * @param string $invoice_ref |
|
| 1059 | - * @param string $object |
|
| 1060 | - * @param unknown_type $product_id |
|
| 1061 | - */ |
|
| 1062 | - public function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array()) |
|
| 1063 | - { |
|
| 1064 | - $wpshop_email_option = get_option('wpshop_emails'); |
|
| 1065 | - if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) { |
|
| 1066 | - $headers = "MIME-Version: 1.0\r\n"; |
|
| 1067 | - $headers .= "Content-type: text/html; charset=UTF-8\r\n"; |
|
| 1068 | - $headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n"; |
|
| 1069 | - $message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>'; |
|
| 1070 | - $message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>'; |
|
| 1071 | - $message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>'; |
|
| 1072 | - $message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>'; |
|
| 1073 | - |
|
| 1074 | - if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) { |
|
| 1075 | - $message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>'; |
|
| 1076 | - foreach ($errors_infos['real_datas'] as $k => $errors_info) { |
|
| 1077 | - $message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>'; |
|
| 1078 | - } |
|
| 1079 | - $message .= '</ul>'; |
|
| 1080 | - if (!empty($errors_infos['corrected_data'])) { |
|
| 1081 | - $message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data']; |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers); |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * Force Invoice Generation. Function called on save order custom informations action |
|
| 1091 | - * @param array $order_metadata |
|
| 1092 | - * @param array $posted_datas |
|
| 1093 | - * @return string |
|
| 1094 | - */ |
|
| 1095 | - public function force_invoice_generation_on_order($order_metadata, $posted_datas) |
|
| 1096 | - { |
|
| 1097 | - if (!empty($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') { |
|
| 1098 | - $order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']); |
|
| 1099 | - } |
|
| 1100 | - return $order_metadata; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - public function wpshop_quotation_payment_partial_validation($input) |
|
| 1104 | - { |
|
| 1105 | - return $input; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - public function wpshop_quotation_payment_partial() |
|
| 1109 | - { |
|
| 1110 | - $output = ''; |
|
| 1111 | - |
|
| 1112 | - $partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
|
| 1113 | - |
|
| 1114 | - $partial_for_quotation_is_activate = false; |
|
| 1115 | - if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) { |
|
| 1116 | - $partial_for_quotation_is_activate = true; |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - $output .= ' |
|
| 356 | + // $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop'); |
|
| 357 | + // $is_partial_payment = true; |
|
| 358 | + // } |
|
| 359 | + |
|
| 360 | + if ($bon_colisage) { |
|
| 361 | + $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop'); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null); |
|
| 365 | + if ($bon_colisage) { |
|
| 366 | + $tpl_component['INVOICE_ORDER_INVOICE_REF'] = ''; |
|
| 367 | + } |
|
| 368 | + $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']); |
|
| 369 | + $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)); |
|
| 370 | + |
|
| 371 | + /** Validate period for Quotation **/ |
|
| 372 | + if ($is_quotation) { |
|
| 373 | + $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']); |
|
| 374 | + } else { |
|
| 375 | + $tpl_component['INVOICE_VALIDATE_TIME'] = ''; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME']; |
|
| 379 | + |
|
| 380 | + $tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : ''; |
|
| 381 | + |
|
| 382 | + // Sender & receiver addresses |
|
| 383 | + $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part(); |
|
| 384 | + $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage); |
|
| 385 | + |
|
| 386 | + $tpl_component['INVOICE_TRACKING'] = ''; |
|
| 387 | + $first = false; |
|
| 388 | + if (!empty($order_postmeta['order_trackingNumber'])) { |
|
| 389 | + $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber']; |
|
| 390 | + $first = true; |
|
| 391 | + } |
|
| 392 | + if (!empty($order_postmeta['order_trackingLink'])) { |
|
| 393 | + if (!$first) { |
|
| 394 | + $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink']; |
|
| 395 | + } else { |
|
| 396 | + $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink']; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** Items Tab **/ |
|
| 401 | + $order_tva = array(); |
|
| 402 | + if ($bon_colisage) { |
|
| 403 | + $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common'); |
|
| 404 | + } else { |
|
| 405 | + $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common'); |
|
| 406 | + //if ( !$is_quotation ) { |
|
| 407 | + /** Check if products have discounts **/ |
|
| 408 | + if (!empty($order_postmeta['order_items']) && !$is_partial_payment) { |
|
| 409 | + foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 410 | + if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) { |
|
| 411 | + $discounts_exists = true; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if ($discounts_exists) { |
|
| 417 | + $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common'); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + //} |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + $total_discounted = 0; |
|
| 424 | + $tpl_component['INVOICE_ROWS'] = ''; |
|
| 425 | + |
|
| 426 | + if (!$is_partial_payment) { |
|
| 427 | + if (!empty($order_postmeta['order_items'])) { |
|
| 428 | + foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 429 | + $sub_tpl_component = array(); |
|
| 430 | + $count_products += $item['item_qty']; |
|
| 431 | + $barcode = get_post_meta($item['item_id'], '_barcode', true); |
|
| 432 | + if (empty($barcode)) { |
|
| 433 | + $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true); |
|
| 434 | + $barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : ''; |
|
| 435 | + |
|
| 436 | + if (empty($barcode)) { |
|
| 437 | + $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 438 | + $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code'); |
|
| 439 | + $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']); |
|
| 440 | + $barcode = $wpdb->get_var($query); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-'; |
|
| 444 | + |
|
| 445 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref']; |
|
| 446 | + |
|
| 447 | + /** Item name **/ |
|
| 448 | + $is_variation = false; |
|
| 449 | + if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 450 | + $is_variation = true; |
|
| 451 | + $parent_def = wpshop_products::get_parent_variation($item['item_id']); |
|
| 452 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 453 | + $parent_post = $parent_def['parent_post']; |
|
| 454 | + $item_parent_id = $parent_post->ID; |
|
| 455 | + $item_title = $parent_post->post_title; |
|
| 456 | + } |
|
| 457 | + } else { |
|
| 458 | + $item_title = $item['item_name']; |
|
| 459 | + } |
|
| 460 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title; |
|
| 461 | + /** Get attribute order for current product */ |
|
| 462 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 463 | + $output_order = array(); |
|
| 464 | + if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 465 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 466 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 467 | + if (!empty($attribute_def->code)) { |
|
| 468 | + $output_order[$attribute_def->code] = $position; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common'); |
|
| 475 | + ksort($variation_attribute_ordered['attribute_list']); |
|
| 476 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = ''; |
|
| 477 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 478 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output; |
|
| 479 | + } |
|
| 480 | + $post_content = get_post_field('post_content', $item['item_id']); |
|
| 481 | + if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/!empty($post_content) && false) { |
|
| 482 | + if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) { |
|
| 483 | + //$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>'; |
|
| 484 | + } |
|
| 485 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>'; |
|
| 486 | + } |
|
| 487 | + $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : ''; |
|
| 488 | + unset($detail_tpl_component); |
|
| 489 | + |
|
| 490 | + $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty']; |
|
| 491 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', '')); |
|
| 492 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', '')); |
|
| 493 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', ''); |
|
| 494 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', ''); |
|
| 495 | + /** TVA **/ |
|
| 496 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', ''); |
|
| 497 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate']; |
|
| 498 | + |
|
| 499 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', ''); |
|
| 500 | + |
|
| 501 | + /** Checking Rate amount **/ |
|
| 502 | + if (!$bon_colisage) { |
|
| 503 | + $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id); |
|
| 504 | + if (!$checking) { |
|
| 505 | + return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop'); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ($bon_colisage) { |
|
| 510 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common'); |
|
| 511 | + } else { |
|
| 512 | + if ($discounts_exists) { |
|
| 513 | + $discounted_total_per_item = $item['item_total_ht']; |
|
| 514 | + /** Unit Discount **/ |
|
| 515 | + if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) { |
|
| 516 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', ''); |
|
| 517 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', ''); |
|
| 518 | + $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount']; |
|
| 519 | + } else { |
|
| 520 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 521 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** Global Discount **/ |
|
| 525 | + if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) { |
|
| 526 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', ''); |
|
| 527 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', ''); |
|
| 528 | + $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount']; |
|
| 529 | + } else { |
|
| 530 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 531 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $total_discounted += $discounted_total_per_item; |
|
| 535 | + /** Total HT Discounted **/ |
|
| 536 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', ''); |
|
| 537 | + |
|
| 538 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 539 | + } else { |
|
| 540 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + unset($sub_tpl_component); |
|
| 544 | + |
|
| 545 | + /** Check TVA **/ |
|
| 546 | + if (empty($order_tva[$item['item_tva_rate']])) { |
|
| 547 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 548 | + } else { |
|
| 549 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** Display Partials payments **/ |
|
| 556 | + $total_partial_payment = 0; |
|
| 557 | + $last_payment = 0; |
|
| 558 | + $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 559 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 560 | + foreach ($order_postmeta['order_payment']['received'] as $received_payment) { |
|
| 561 | + if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) { |
|
| 562 | + if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) { |
|
| 563 | + $sub_tpl_component = array(); |
|
| 564 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 565 | + |
|
| 566 | + /** Item name **/ |
|
| 567 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']); |
|
| 568 | + $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 569 | + $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 570 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 571 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 572 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 573 | + |
|
| 574 | + /** TVA **/ |
|
| 575 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 576 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 577 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 578 | + |
|
| 579 | + if ($discounts_exists) { |
|
| 580 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 581 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 582 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 583 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 584 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 585 | + |
|
| 586 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 587 | + } else { |
|
| 588 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + unset($sub_tpl_component); |
|
| 593 | + $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 594 | + } else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) { |
|
| 595 | + $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + } else { |
|
| 601 | + /** Display Partials payments **/ |
|
| 602 | + $total_partial_payment = 0; |
|
| 603 | + $last_payment = 0; |
|
| 604 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 605 | + foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) { |
|
| 606 | + if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) { |
|
| 607 | + $sub_tpl_component = array(); |
|
| 608 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 609 | + /** Item name **/ |
|
| 610 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1); |
|
| 611 | + $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 612 | + $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 613 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 614 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 615 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 616 | + /** TVA **/ |
|
| 617 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 618 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 619 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 620 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 621 | + unset($sub_tpl_component); |
|
| 622 | + $total_partial_payment += $received_payment['received_amount']; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + /** Summary of order **/ |
|
| 629 | + $summary_tpl_component = array(); |
|
| 630 | + $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = ''; |
|
| 631 | + if (!$bon_colisage) { |
|
| 632 | + if (!empty($order_tva)) { |
|
| 633 | + foreach ($order_tva as $tax_rate => $tax_amount) { |
|
| 634 | + if ($tax_amount > 0) { |
|
| 635 | + $tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate; |
|
| 636 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 637 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 638 | + $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 639 | + unset($sub_tpl_component); |
|
| 640 | + } elseif ($is_partial_payment) { |
|
| 641 | + $tax_rate = 0; |
|
| 642 | + $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 643 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 644 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 645 | + $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 646 | + unset($sub_tpl_component); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** If Discount Exist **/ |
|
| 652 | + // Checking Discounts on order |
|
| 653 | + if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) { |
|
| 654 | + $discounts_exists = true; |
|
| 655 | + // Calcul discount on Order |
|
| 656 | + switch ($order_postmeta['order_discount_type']) { |
|
| 657 | + case 'amount': |
|
| 658 | + $total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', ''); |
|
| 659 | + break; |
|
| 660 | + case 'percent': |
|
| 661 | + $total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100); |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + if (!empty($total_discounted) && $discounts_exists) { |
|
| 666 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop'); |
|
| 667 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 668 | + $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 669 | + unset($sub_tpl_component); |
|
| 670 | + } else { |
|
| 671 | + $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = ''; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + $shipping_cost = 0; |
|
| 675 | + if (!$is_partial_payment) { |
|
| 676 | + if (!empty($order_postmeta['order_shipping_cost'])) { |
|
| 677 | + $shipping_cost = $order_postmeta['order_shipping_cost']; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC'); |
|
| 681 | + $shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100)); |
|
| 682 | + $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', ''); |
|
| 683 | + $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', ''); |
|
| 684 | + //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' ); |
|
| 685 | + |
|
| 686 | + $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' ); |
|
| 687 | + $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', ''); |
|
| 688 | + |
|
| 689 | + $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 690 | + |
|
| 691 | + $total_payment = 0; |
|
| 692 | + |
|
| 693 | + /** Amount paid **/ |
|
| 694 | + if (empty($order_postmeta['order_invoice_ref'])) { |
|
| 695 | + foreach ($order_postmeta['order_payment']['received'] as $key => $value) { |
|
| 696 | + if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) { |
|
| 697 | + $total_payment = number_format($value['received_amount'], 2, ',', ''); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + } else { |
|
| 701 | + $total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total']; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop'); |
|
| 705 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 706 | + //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ? number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 707 | + $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 708 | + unset($sub_tpl_component); |
|
| 709 | + |
|
| 710 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop'); |
|
| 711 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products; |
|
| 712 | + $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 713 | + unset($sub_tpl_component); |
|
| 714 | + |
|
| 715 | + /** If Discount Exist **/ |
|
| 716 | + if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) { |
|
| 717 | + $tpl_discount_component = array(); |
|
| 718 | + $tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', ''); |
|
| 719 | + |
|
| 720 | + $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 721 | + $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common'); |
|
| 722 | + unset($tpl_discount_component); |
|
| 723 | + } else { |
|
| 724 | + $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = ''; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop'); |
|
| 728 | + |
|
| 729 | + $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common'); |
|
| 730 | + unset($summary_tpl_component); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** IBAN Include on quotation **/ |
|
| 734 | + if ($is_quotation) { |
|
| 735 | + /** If admin want to include his IBAN to quotation */ |
|
| 736 | + $iban_options = get_option('wpshop_paymentMethod_options'); |
|
| 737 | + $payment_options = get_option('wps_payment_mode'); |
|
| 738 | + if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') { |
|
| 739 | + if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) { |
|
| 740 | + $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>'; |
|
| 741 | + $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>'; |
|
| 742 | + $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>'; |
|
| 743 | + $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>'; |
|
| 744 | + $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>'; |
|
| 745 | + } |
|
| 746 | + } else { |
|
| 747 | + $tpl_component['IBAN_INFOS'] = ''; |
|
| 748 | + } |
|
| 749 | + } else { |
|
| 750 | + $tpl_component['IBAN_INFOS'] = ''; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + /** Received payements **/ |
|
| 754 | + if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) { |
|
| 755 | + $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id); |
|
| 756 | + } else { |
|
| 757 | + $tpl_component['RECEIVED_PAYMENT'] = ''; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** Invoice footer **/ |
|
| 761 | + $tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice(); |
|
| 762 | + |
|
| 763 | + $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common'); |
|
| 764 | + } else { |
|
| 765 | + $output = __('No order information has been found', 'wpshop'); |
|
| 766 | + } |
|
| 767 | + } else { |
|
| 768 | + $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop'); |
|
| 769 | + } |
|
| 770 | + return $output; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Return the payment list part |
|
| 775 | + * @param integer $order_id |
|
| 776 | + * @return string |
|
| 777 | + */ |
|
| 778 | + public static function generate_received_payment_part($order_id) |
|
| 779 | + { |
|
| 780 | + $date_ouput_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 781 | + $output = ''; |
|
| 782 | + $tpl_component = array(); |
|
| 783 | + $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = ''; |
|
| 784 | + if (!empty($order_id)) { |
|
| 785 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 786 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) { |
|
| 787 | + $wps_payment_option = get_option('wps_payment_mode'); |
|
| 788 | + foreach ($order_postmeta['order_payment']['received'] as $payment) { |
|
| 789 | + if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) { |
|
| 790 | + $sub_tpl_component = array(); |
|
| 791 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0; |
|
| 792 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : ''; |
|
| 793 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : '')); |
|
| 794 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : ''; |
|
| 795 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : ''; |
|
| 796 | + $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + $output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 801 | + unset($tpl_component); |
|
| 802 | + } |
|
| 803 | + return $output; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** Return the validity period of a quotation **/ |
|
| 807 | + public static function quotation_validate_period($quotation_date) |
|
| 808 | + { |
|
| 809 | + $quotation_options = get_option('wpshop_quotation_validate_time'); |
|
| 810 | + if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) { |
|
| 811 | + $timestamp_quotation = strtotime($quotation_date); |
|
| 812 | + $timestamp_validity_date_quotation = 0; |
|
| 813 | + $query = ''; |
|
| 814 | + $date = ''; |
|
| 815 | + global $wpdb; |
|
| 816 | + switch ($quotation_options['time_type']) { |
|
| 817 | + case 'day': |
|
| 818 | + $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s DAY)", $quotation_date, $quotation_options['number']); |
|
| 819 | + break; |
|
| 820 | + case 'month': |
|
| 821 | + $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s MONTH)", $quotation_date, $quotation_options['number']); |
|
| 822 | + break; |
|
| 823 | + case 'year': |
|
| 824 | + $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL %s YEAR)", $quotation_date, $quotation_options['number']); |
|
| 825 | + break; |
|
| 826 | + default: |
|
| 827 | + $query = $wpdb->prepare("SELECT DATE_ADD(%s, INTERVAL '15' DAY)", $quotation_date); |
|
| 828 | + break; |
|
| 829 | + } |
|
| 830 | + if ($query != null) { |
|
| 831 | + $date = mysql2date('d F Y', $wpdb->get_var($query), true); |
|
| 832 | + } |
|
| 833 | + return sprintf(__('Quotation validity date %s', 'wpshop'), $date); |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Generate HTML invoice to be sended by email |
|
| 839 | + * @param integer $order_id |
|
| 840 | + * @param string $invoice_ref |
|
| 841 | + * @return string |
|
| 842 | + */ |
|
| 843 | + public static function generate_invoice_for_email($order_id, $invoice_ref = '') |
|
| 844 | + { |
|
| 845 | + /** Generate the PDF file for the invoice **/ |
|
| 846 | + $is_ok = false; |
|
| 847 | + if (!empty($invoice_ref)) { |
|
| 848 | + require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'; |
|
| 849 | + try { |
|
| 850 | + $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref); |
|
| 851 | + $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
|
| 852 | + $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
|
| 853 | + |
|
| 854 | + $html2pdf->setDefaultFont('Arial'); |
|
| 855 | + $html2pdf->writeHTML($html_content); |
|
| 856 | + $html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F'); |
|
| 857 | + $is_ok = true; |
|
| 858 | + } catch (HTML2PDF_exception $e) { |
|
| 859 | + echo $e; |
|
| 860 | + exit; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : ''; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * Generate Sender part invoice template |
|
| 868 | + * @return Ambigous <string, string> |
|
| 869 | + */ |
|
| 870 | + public static function generate_invoice_sender_part() |
|
| 871 | + { |
|
| 872 | + $output = ''; |
|
| 873 | + $company = get_option('wpshop_company_info', array()); |
|
| 874 | + $emails = get_option('wpshop_emails', array()); |
|
| 875 | + if (!empty($company)) { |
|
| 876 | + $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 877 | + $tpl_component['COMPANY_WEBSITE'] = get_option('siteurl'); |
|
| 878 | + foreach ($company as $company_info_key => $company_info_value) { |
|
| 879 | + switch ($company_info_key) { |
|
| 880 | + case 'company_rcs': |
|
| 881 | + $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 882 | + break; |
|
| 883 | + case 'company_capital': |
|
| 884 | + $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 885 | + break; |
|
| 886 | + case 'company_siren': |
|
| 887 | + $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 888 | + break; |
|
| 889 | + case 'company_siret': |
|
| 890 | + $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 891 | + break; |
|
| 892 | + case 'company_tva_intra': |
|
| 893 | + $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 894 | + break; |
|
| 895 | + case 'company_legal_statut': |
|
| 896 | + $array_state_compagny = wpshop_company_options::get_legal_status(); |
|
| 897 | + $data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop'); |
|
| 898 | + break; |
|
| 899 | + default: |
|
| 900 | + $data = $company_info_value; |
|
| 901 | + break; |
|
| 902 | + } |
|
| 903 | + $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 904 | + } |
|
| 905 | + $output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common'); |
|
| 906 | + } |
|
| 907 | + return $output; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * Generate Receiver part template |
|
| 912 | + * @param unknown_type $order_id |
|
| 913 | + * @param unknown_type $bon_colisage |
|
| 914 | + * @return Ambigous <string, string> |
|
| 915 | + */ |
|
| 916 | + public static function generate_receiver_part($order_id, $bon_colisage = false) |
|
| 917 | + { |
|
| 918 | + $output = ''; |
|
| 919 | + $order_customer_postmeta = get_post_meta($order_id, '_order_info', true); |
|
| 920 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 921 | + |
|
| 922 | + if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) { |
|
| 923 | + $address_info = $order_customer_postmeta['shipping']['address']; |
|
| 924 | + } else { |
|
| 925 | + if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) { |
|
| 926 | + $address_info = $order_customer_postmeta['billing']['address']; |
|
| 927 | + } else { |
|
| 928 | + $address_info = array(); |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + if (!empty($order_customer_postmeta) && !empty($address_info)) { |
|
| 933 | + $default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY'); |
|
| 934 | + foreach ($default_address_attributes as $default_address_attribute) { |
|
| 935 | + $tpl_component[$default_address_attribute] = ''; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + foreach ($address_info as $order_customer_info_key => $order_customer_info_value) { |
|
| 939 | + $tpl_component[strtoupper($order_customer_info_key)] = ''; |
|
| 940 | + if ($order_customer_info_key == 'civility') { |
|
| 941 | + global $wpdb; |
|
| 942 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value); |
|
| 943 | + $civility = $wpdb->get_row($query); |
|
| 944 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : ''; |
|
| 945 | + } else if ($order_customer_info_key == 'country') { |
|
| 946 | + foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) { |
|
| 947 | + if ($order_customer_info_value == $key) { |
|
| 948 | + $tpl_component[strtoupper($order_customer_info_key)] = $value; |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + } elseif ($order_customer_info_key == 'phone') { |
|
| 952 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : ''; |
|
| 953 | + } else { |
|
| 954 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : ''; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + if (empty($tpl_component['PHONE'])) { |
|
| 959 | + $tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : ''; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) { |
|
| 963 | + $user_info = get_userdata($order_postmeta['customer_id']); |
|
| 964 | + $tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : ''; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + $output = wpshop_display::display_template_element('invoice_receiver_formatted_address', $tpl_component, array(), 'common'); |
|
| 968 | + } |
|
| 969 | + return $output; |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + /** |
|
| 973 | + * Genrate Footer invoice |
|
| 974 | + * @return Ambigous <string, string> |
|
| 975 | + */ |
|
| 976 | + public static function generate_footer_invoice() |
|
| 977 | + { |
|
| 978 | + $output = ''; |
|
| 979 | + $company = get_option('wpshop_company_info', array()); |
|
| 980 | + $emails = get_option('wpshop_emails', array()); |
|
| 981 | + if (!empty($company)) { |
|
| 982 | + $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 983 | + $tpl_component['COMPANY_WEBSITE'] = site_url(); |
|
| 984 | + foreach ($company as $company_info_key => $company_info_value) { |
|
| 985 | + |
|
| 986 | + switch ($company_info_key) { |
|
| 987 | + case 'company_rcs': |
|
| 988 | + $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 989 | + break; |
|
| 990 | + case 'company_capital': |
|
| 991 | + $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 992 | + break; |
|
| 993 | + case 'company_siren': |
|
| 994 | + $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 995 | + break; |
|
| 996 | + case 'company_siret': |
|
| 997 | + $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 998 | + break; |
|
| 999 | + case 'company_tva_intra': |
|
| 1000 | + $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1001 | + break; |
|
| 1002 | + default: |
|
| 1003 | + $data = $company_info_value; |
|
| 1004 | + break; |
|
| 1005 | + } |
|
| 1006 | + $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 1007 | + } |
|
| 1008 | + $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common'); |
|
| 1009 | + } |
|
| 1010 | + return $output; |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * Check product price |
|
| 1015 | + * @param float $price_ht |
|
| 1016 | + * @param float $price_ati |
|
| 1017 | + * @param float $tva_amount |
|
| 1018 | + * @param float $tva_rate |
|
| 1019 | + * @param id $product_id |
|
| 1020 | + * @param string $invoice_ref |
|
| 1021 | + */ |
|
| 1022 | + public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id) |
|
| 1023 | + { |
|
| 1024 | + $checking = true; |
|
| 1025 | + $error_percent = 1; |
|
| 1026 | + |
|
| 1027 | + /** Check VAT Amount **/ |
|
| 1028 | + $formatted_tva_amount = number_format($tva_amount, 2, '.', ''); |
|
| 1029 | + $formatted_price_ht = number_format($price_ht, 2, '.', ''); |
|
| 1030 | + $formatted_price_ati = number_format($price_ati, 2, '.', ''); |
|
| 1031 | + $calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100)); |
|
| 1032 | + $unformatted = $formatted_price_ati - $calculated_price_excluding_tax; |
|
| 1033 | + $checked_tva_amount = number_format($unformatted, 2, '.', ''); |
|
| 1034 | + |
|
| 1035 | + if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) { |
|
| 1036 | + $error_infos = array(); |
|
| 1037 | + $error_infos['real_datas']['price_ati'] = $formatted_price_ati; |
|
| 1038 | + $error_infos['real_datas']['price_ht'] = $formatted_price_ht; |
|
| 1039 | + $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount; |
|
| 1040 | + |
|
| 1041 | + $error_infos['corrected_data'] = $checked_tva_amount; |
|
| 1042 | + self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos); |
|
| 1043 | + $checking = false; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + /** Check price ati **/ |
|
| 1047 | + $checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100)); |
|
| 1048 | + if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) { |
|
| 1049 | + self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id); |
|
| 1050 | + $checking = false; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + return $checking; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Alert administrator when have invoice error |
|
| 1058 | + * @param string $invoice_ref |
|
| 1059 | + * @param string $object |
|
| 1060 | + * @param unknown_type $product_id |
|
| 1061 | + */ |
|
| 1062 | + public function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array()) |
|
| 1063 | + { |
|
| 1064 | + $wpshop_email_option = get_option('wpshop_emails'); |
|
| 1065 | + if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) { |
|
| 1066 | + $headers = "MIME-Version: 1.0\r\n"; |
|
| 1067 | + $headers .= "Content-type: text/html; charset=UTF-8\r\n"; |
|
| 1068 | + $headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n"; |
|
| 1069 | + $message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>'; |
|
| 1070 | + $message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>'; |
|
| 1071 | + $message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>'; |
|
| 1072 | + $message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>'; |
|
| 1073 | + |
|
| 1074 | + if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) { |
|
| 1075 | + $message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>'; |
|
| 1076 | + foreach ($errors_infos['real_datas'] as $k => $errors_info) { |
|
| 1077 | + $message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>'; |
|
| 1078 | + } |
|
| 1079 | + $message .= '</ul>'; |
|
| 1080 | + if (!empty($errors_infos['corrected_data'])) { |
|
| 1081 | + $message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data']; |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers); |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * Force Invoice Generation. Function called on save order custom informations action |
|
| 1091 | + * @param array $order_metadata |
|
| 1092 | + * @param array $posted_datas |
|
| 1093 | + * @return string |
|
| 1094 | + */ |
|
| 1095 | + public function force_invoice_generation_on_order($order_metadata, $posted_datas) |
|
| 1096 | + { |
|
| 1097 | + if (!empty($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') { |
|
| 1098 | + $order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']); |
|
| 1099 | + } |
|
| 1100 | + return $order_metadata; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + public function wpshop_quotation_payment_partial_validation($input) |
|
| 1104 | + { |
|
| 1105 | + return $input; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + public function wpshop_quotation_payment_partial() |
|
| 1109 | + { |
|
| 1110 | + $output = ''; |
|
| 1111 | + |
|
| 1112 | + $partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
|
| 1113 | + |
|
| 1114 | + $partial_for_quotation_is_activate = false; |
|
| 1115 | + if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) { |
|
| 1116 | + $partial_for_quotation_is_activate = true; |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + $output .= ' |
|
| 1120 | 1120 | <input type="checkbox" name="wpshop_payment_partial[for_quotation][activate]"' . ($partial_for_quotation_is_activate ? ' checked="checked"' : '') . ' id="wpshop_payment_partial_on_quotation_activation_state" /> <label for="wpshop_payment_partial_on_quotation_activation_state" >' . __('Activate partial command for quotations', 'wpshop') . '</label><a href="#" title="' . __('If you want that customer pay a part o f total amount of there order, check this box then fill fields below', 'wpshop') . '" class="wpshop_infobulle_marker">?</a> |
| 1121 | 1121 | <div class="wpshop_partial_payment_quotation_config_container' . ($partial_for_quotation_is_activate ? '' : ' wpshopHide') . '" id="wpshop_partial_payment_quotation_config_container" > |
| 1122 | 1122 | <div class="alignleft" > |
@@ -1132,13 +1132,13 @@ discard block |
||
| 1132 | 1132 | </div> |
| 1133 | 1133 | </div>'; |
| 1134 | 1134 | |
| 1135 | - echo $output; |
|
| 1136 | - } |
|
| 1137 | - } |
|
| 1135 | + echo $output; |
|
| 1136 | + } |
|
| 1137 | + } |
|
| 1138 | 1138 | |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** Instanciate the module utilities if not */ |
| 1142 | 1142 | if (class_exists("wpshop_modules_billing")) { |
| 1143 | - $wpshop_modules_billing = new wpshop_modules_billing(); |
|
| 1143 | + $wpshop_modules_billing = new wpshop_modules_billing(); |
|
| 1144 | 1144 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | /* Check if file is include. No direct access possible with file url */ |
| 16 | 16 | if (!defined('WPSHOP_VERSION')) { |
| 17 | - die(__('Access is not allowed by this way', 'wpshop')); |
|
| 17 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -26,160 +26,160 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class wpshop_products |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * Définition du code de la classe courante |
|
| 31 | - */ |
|
| 32 | - const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 33 | - const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION; |
|
| 34 | - |
|
| 35 | - public function add_product_to_current_order_interface() |
|
| 36 | - { |
|
| 37 | - $output = ''; |
|
| 38 | - $output .= self::products_list_js(); |
|
| 39 | - $output .= '<input type="text" id="wps_order_search_product" />'; |
|
| 40 | - echo $output; |
|
| 41 | - die(); |
|
| 42 | - } |
|
| 29 | + /** |
|
| 30 | + * Définition du code de la classe courante |
|
| 31 | + */ |
|
| 32 | + const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 33 | + const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION; |
|
| 34 | + |
|
| 35 | + public function add_product_to_current_order_interface() |
|
| 36 | + { |
|
| 37 | + $output = ''; |
|
| 38 | + $output .= self::products_list_js(); |
|
| 39 | + $output .= '<input type="text" id="wps_order_search_product" />'; |
|
| 40 | + echo $output; |
|
| 41 | + die(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function products_list_js() |
|
| 45 | - { |
|
| 46 | - global $wpdb; |
|
| 47 | - /** Create a JS Array of products **/ |
|
| 44 | + public function products_list_js() |
|
| 45 | + { |
|
| 46 | + global $wpdb; |
|
| 47 | + /** Create a JS Array of products **/ |
|
| 48 | 48 | // $query = $wpdb->prepare('SELECT ID, post_title FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_status = %s', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
| 49 | - // $products_post = $wpdb->get_results( $query ); |
|
| 50 | - |
|
| 51 | - $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1)); |
|
| 52 | - |
|
| 53 | - if (!empty($products_post)) { |
|
| 54 | - $products_js_array = 'var products = ['; |
|
| 55 | - foreach ($products_post as $product) { |
|
| 56 | - $barcode = get_post_meta($product->ID, '_barcode', true); |
|
| 57 | - $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", '; |
|
| 58 | - $products_js_array .= 'value:"' . $product->ID . '", '; |
|
| 59 | - $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},'; |
|
| 60 | - } |
|
| 61 | - $products_js_array .= '];'; |
|
| 62 | - } |
|
| 63 | - $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin'); |
|
| 64 | - return $output; |
|
| 65 | - } |
|
| 49 | + // $products_post = $wpdb->get_results( $query ); |
|
| 50 | + |
|
| 51 | + $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1)); |
|
| 52 | + |
|
| 53 | + if (!empty($products_post)) { |
|
| 54 | + $products_js_array = 'var products = ['; |
|
| 55 | + foreach ($products_post as $product) { |
|
| 56 | + $barcode = get_post_meta($product->ID, '_barcode', true); |
|
| 57 | + $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", '; |
|
| 58 | + $products_js_array .= 'value:"' . $product->ID . '", '; |
|
| 59 | + $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},'; |
|
| 60 | + } |
|
| 61 | + $products_js_array .= '];'; |
|
| 62 | + } |
|
| 63 | + $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin'); |
|
| 64 | + return $output; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Déclaration des produits et variations en tant que "post" de wordpress |
|
| 69 | - * |
|
| 70 | - * @see register_post_type() |
|
| 71 | - */ |
|
| 72 | - public static function create_wpshop_products_type() |
|
| 73 | - { |
|
| 74 | - |
|
| 75 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 76 | - //$options2 = get_option('wpshop_catalog_categories_option', array()); |
|
| 77 | - /*echo '<pre>'; print_r( $options ); echo '</pre>'; |
|
| 67 | + /** |
|
| 68 | + * Déclaration des produits et variations en tant que "post" de wordpress |
|
| 69 | + * |
|
| 70 | + * @see register_post_type() |
|
| 71 | + */ |
|
| 72 | + public static function create_wpshop_products_type() |
|
| 73 | + { |
|
| 74 | + |
|
| 75 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 76 | + //$options2 = get_option('wpshop_catalog_categories_option', array()); |
|
| 77 | + /*echo '<pre>'; print_r( $options ); echo '</pre>'; |
|
| 78 | 78 | echo '<pre>'; print_r( $options2 ); echo '</pre>'; exit();*/ |
| 79 | 79 | |
| 80 | - $slug = array( |
|
| 81 | - 'slug' => '', |
|
| 82 | - 'with_front' => false, |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') { |
|
| 86 | - $slug = false; |
|
| 87 | - } else { |
|
| 88 | - $slug['slug'] = $options['wpshop_catalog_product_slug']; |
|
| 89 | - if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 90 | - $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%'; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/ |
|
| 94 | - |
|
| 95 | - /* Définition des produits */ |
|
| 96 | - register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array( |
|
| 97 | - 'labels' => array( |
|
| 98 | - 'name' => __('Products', 'wpshop'), |
|
| 99 | - 'singular_name' => __('Catalog', 'wpshop'), |
|
| 100 | - 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 101 | - 'add_new' => __('Add new product', 'wpshop'), |
|
| 102 | - 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 103 | - 'edit_item' => __('Edit product', 'wpshop'), |
|
| 104 | - 'new_item' => __('New product', 'wpshop'), |
|
| 105 | - 'view_item' => __('View product', 'wpshop'), |
|
| 106 | - 'search_items' => __('Search products', 'wpshop'), |
|
| 107 | - 'not_found' => __('No products found', 'wpshop'), |
|
| 108 | - 'not_found_in_trash' => __('No products found in Trash', 'wpshop'), |
|
| 109 | - 'parent_item_colon' => '', |
|
| 110 | - ), |
|
| 111 | - 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 112 | - 'public' => true, |
|
| 113 | - 'has_archive' => false, |
|
| 114 | - 'show_in_nav_menus' => true, |
|
| 115 | - //'rewrite' => false, // For information see below |
|
| 116 | - 'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES), |
|
| 117 | - 'menu_icon' => 'dashicons-archive', |
|
| 118 | - 'rewrite' => $slug, |
|
| 119 | - ))); |
|
| 120 | - |
|
| 121 | - /* Définition des variations de produit (Déclinaisons) */ |
|
| 122 | - register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array( |
|
| 123 | - 'labels' => array( |
|
| 124 | - 'name' => __('Variations', 'wpshop'), |
|
| 125 | - 'singular_name' => __('Variation', 'wpshop'), |
|
| 126 | - 'add_new' => __('Add Variation', 'wpshop'), |
|
| 127 | - 'add_new_item' => __('Add New Variation', 'wpshop'), |
|
| 128 | - 'edit' => __('Edit', 'wpshop'), |
|
| 129 | - 'edit_item' => __('Edit Variation', 'wpshop'), |
|
| 130 | - 'new_item' => __('New Variation', 'wpshop'), |
|
| 131 | - 'view' => __('View Variation', 'wpshop'), |
|
| 132 | - 'view_item' => __('View Variation', 'wpshop'), |
|
| 133 | - 'search_items' => __('Search Variations', 'wpshop'), |
|
| 134 | - 'not_found' => __('No Variations found', 'wpshop'), |
|
| 135 | - 'not_found_in_trash' => __('No Variations found in trash', 'wpshop'), |
|
| 136 | - 'parent_item_colon' => '', |
|
| 137 | - ), |
|
| 138 | - 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 139 | - 'public' => true, |
|
| 140 | - 'has_archive' => true, |
|
| 141 | - 'show_in_nav_menus' => false, |
|
| 142 | - 'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 143 | - |
|
| 144 | - 'publicly_queryable' => false, |
|
| 145 | - 'exclude_from_search' => true, |
|
| 146 | - 'hierarchical' => false, |
|
| 147 | - |
|
| 148 | - // 'public' => true, |
|
| 149 | - // 'show_ui' => false, |
|
| 150 | - // 'rewrite' => false, |
|
| 151 | - // 'query_var' => true, |
|
| 152 | - // 'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ), |
|
| 153 | - // 'show_in_nav_menus' => false |
|
| 154 | - ) |
|
| 155 | - )); |
|
| 156 | - |
|
| 157 | - // add to our plugin init function |
|
| 158 | - //global $wp_rewrite; |
|
| 159 | - /* Slug url is set into option */ |
|
| 160 | - /*$options = get_option('wpshop_catalog_product_option', array()); |
|
| 80 | + $slug = array( |
|
| 81 | + 'slug' => '', |
|
| 82 | + 'with_front' => false, |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') { |
|
| 86 | + $slug = false; |
|
| 87 | + } else { |
|
| 88 | + $slug['slug'] = $options['wpshop_catalog_product_slug']; |
|
| 89 | + if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 90 | + $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%'; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/ |
|
| 94 | + |
|
| 95 | + /* Définition des produits */ |
|
| 96 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array( |
|
| 97 | + 'labels' => array( |
|
| 98 | + 'name' => __('Products', 'wpshop'), |
|
| 99 | + 'singular_name' => __('Catalog', 'wpshop'), |
|
| 100 | + 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 101 | + 'add_new' => __('Add new product', 'wpshop'), |
|
| 102 | + 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 103 | + 'edit_item' => __('Edit product', 'wpshop'), |
|
| 104 | + 'new_item' => __('New product', 'wpshop'), |
|
| 105 | + 'view_item' => __('View product', 'wpshop'), |
|
| 106 | + 'search_items' => __('Search products', 'wpshop'), |
|
| 107 | + 'not_found' => __('No products found', 'wpshop'), |
|
| 108 | + 'not_found_in_trash' => __('No products found in Trash', 'wpshop'), |
|
| 109 | + 'parent_item_colon' => '', |
|
| 110 | + ), |
|
| 111 | + 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 112 | + 'public' => true, |
|
| 113 | + 'has_archive' => false, |
|
| 114 | + 'show_in_nav_menus' => true, |
|
| 115 | + //'rewrite' => false, // For information see below |
|
| 116 | + 'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES), |
|
| 117 | + 'menu_icon' => 'dashicons-archive', |
|
| 118 | + 'rewrite' => $slug, |
|
| 119 | + ))); |
|
| 120 | + |
|
| 121 | + /* Définition des variations de produit (Déclinaisons) */ |
|
| 122 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array( |
|
| 123 | + 'labels' => array( |
|
| 124 | + 'name' => __('Variations', 'wpshop'), |
|
| 125 | + 'singular_name' => __('Variation', 'wpshop'), |
|
| 126 | + 'add_new' => __('Add Variation', 'wpshop'), |
|
| 127 | + 'add_new_item' => __('Add New Variation', 'wpshop'), |
|
| 128 | + 'edit' => __('Edit', 'wpshop'), |
|
| 129 | + 'edit_item' => __('Edit Variation', 'wpshop'), |
|
| 130 | + 'new_item' => __('New Variation', 'wpshop'), |
|
| 131 | + 'view' => __('View Variation', 'wpshop'), |
|
| 132 | + 'view_item' => __('View Variation', 'wpshop'), |
|
| 133 | + 'search_items' => __('Search Variations', 'wpshop'), |
|
| 134 | + 'not_found' => __('No Variations found', 'wpshop'), |
|
| 135 | + 'not_found_in_trash' => __('No Variations found in trash', 'wpshop'), |
|
| 136 | + 'parent_item_colon' => '', |
|
| 137 | + ), |
|
| 138 | + 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 139 | + 'public' => true, |
|
| 140 | + 'has_archive' => true, |
|
| 141 | + 'show_in_nav_menus' => false, |
|
| 142 | + 'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 143 | + |
|
| 144 | + 'publicly_queryable' => false, |
|
| 145 | + 'exclude_from_search' => true, |
|
| 146 | + 'hierarchical' => false, |
|
| 147 | + |
|
| 148 | + // 'public' => true, |
|
| 149 | + // 'show_ui' => false, |
|
| 150 | + // 'rewrite' => false, |
|
| 151 | + // 'query_var' => true, |
|
| 152 | + // 'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ), |
|
| 153 | + // 'show_in_nav_menus' => false |
|
| 154 | + ) |
|
| 155 | + )); |
|
| 156 | + |
|
| 157 | + // add to our plugin init function |
|
| 158 | + //global $wp_rewrite; |
|
| 159 | + /* Slug url is set into option */ |
|
| 160 | + /*$options = get_option('wpshop_catalog_product_option', array()); |
|
| 161 | 161 | $gallery_structure = (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : 'catalog'); |
| 162 | 162 | $gallery_structure .= !empty($options['wpshop_catalog_product_slug_with_category']) ? '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%' : ''; |
| 163 | 163 | $gallery_structure .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%'; |
| 164 | 164 | $wp_rewrite->add_permastruct(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $gallery_structure, false); |
| 165 | 165 | $wp_rewrite->add_rewrite_tag('%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%', '([^/]+)', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "=");*/ |
| 166 | - // flush_rewrite_rules(); |
|
| 167 | - } |
|
| 166 | + // flush_rewrite_rules(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - public static function hidden_meta_boxes($hidden, $screen, $use_defaults) |
|
| 170 | - { |
|
| 171 | - global $wpdb; |
|
| 172 | - if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) { |
|
| 173 | - $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 174 | - foreach ($user_meta_for_wpshop as $meta_to_check) { |
|
| 175 | - $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true); |
|
| 176 | - if (empty($metas_hidden) && !is_array($metas_hidden)) { |
|
| 177 | - $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - return $hidden; |
|
| 182 | - } |
|
| 169 | + public static function hidden_meta_boxes($hidden, $screen, $use_defaults) |
|
| 170 | + { |
|
| 171 | + global $wpdb; |
|
| 172 | + if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) { |
|
| 173 | + $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 174 | + foreach ($user_meta_for_wpshop as $meta_to_check) { |
|
| 175 | + $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true); |
|
| 176 | + if (empty($metas_hidden) && !is_array($metas_hidden)) { |
|
| 177 | + $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + return $hidden; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | public static function admin_menu() { |
| 185 | 185 | global $submenu; |
@@ -206,35 +206,35 @@ discard block |
||
| 206 | 206 | $submenu['edit.php?post_type=wpshop_product'] = $submenu_reorder; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Create the different bow for the product management page looking for the attribute set to create the different boxes |
|
| 211 | - */ |
|
| 212 | - public static function add_meta_boxes() |
|
| 213 | - { |
|
| 214 | - global $post, $currentTabContent; |
|
| 215 | - |
|
| 216 | - if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) { |
|
| 217 | - /* Get the attribute set list for the current entity */ |
|
| 218 | - $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
|
| 219 | - /* Check if the meta information of the current product already exists */ |
|
| 220 | - $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 221 | - /* Check if the product has been saved without meta information set */ |
|
| 222 | - $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); |
|
| 223 | - /* Unset 'free_product' from list of attributes set */ |
|
| 224 | - foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
|
| 225 | - if ($attribute_set->slug == 'free_product') { |
|
| 226 | - unset($attributeEntitySetList[$key_attribute_set]); |
|
| 227 | - break; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ |
|
| 232 | - if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) { |
|
| 233 | - if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) { |
|
| 234 | - $post_attribute_set_id = $attributeEntitySetList[0]->id; |
|
| 235 | - } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) { |
|
| 236 | - $post_attribute_set_id = $attribute_set_id->value; |
|
| 237 | - } |
|
| 209 | + /** |
|
| 210 | + * Create the different bow for the product management page looking for the attribute set to create the different boxes |
|
| 211 | + */ |
|
| 212 | + public static function add_meta_boxes() |
|
| 213 | + { |
|
| 214 | + global $post, $currentTabContent; |
|
| 215 | + |
|
| 216 | + if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) { |
|
| 217 | + /* Get the attribute set list for the current entity */ |
|
| 218 | + $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
|
| 219 | + /* Check if the meta information of the current product already exists */ |
|
| 220 | + $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 221 | + /* Check if the product has been saved without meta information set */ |
|
| 222 | + $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); |
|
| 223 | + /* Unset 'free_product' from list of attributes set */ |
|
| 224 | + foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
|
| 225 | + if ($attribute_set->slug == 'free_product') { |
|
| 226 | + unset($attributeEntitySetList[$key_attribute_set]); |
|
| 227 | + break; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ |
|
| 232 | + if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) { |
|
| 233 | + if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) { |
|
| 234 | + $post_attribute_set_id = $attributeEntitySetList[0]->id; |
|
| 235 | + } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) { |
|
| 236 | + $post_attribute_set_id = $attribute_set_id->value; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | /*$post_attribute_set_id = (int) get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
| 240 | 240 | |
@@ -252,32 +252,32 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | }*/ |
| 254 | 254 | |
| 255 | - $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); |
|
| 256 | - |
|
| 257 | - $fixed_box_exist = false; |
|
| 258 | - /* Get all the other attribute set for hte current entity */ |
|
| 259 | - if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { |
|
| 260 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 261 | - if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) { |
|
| 262 | - add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); |
|
| 263 | - } else { |
|
| 264 | - $fixed_box_exist = true; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - if ($fixed_box_exist) { |
|
| 270 | - add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 271 | - add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 275 | - // Actions |
|
| 276 | - // @since 1.4.3.7 Deleted |
|
| 277 | - //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 278 | - |
|
| 279 | - /** Product option */ |
|
| 280 | - add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 255 | + $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); |
|
| 256 | + |
|
| 257 | + $fixed_box_exist = false; |
|
| 258 | + /* Get all the other attribute set for hte current entity */ |
|
| 259 | + if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { |
|
| 260 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 261 | + if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) { |
|
| 262 | + add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); |
|
| 263 | + } else { |
|
| 264 | + $fixed_box_exist = true; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + if ($fixed_box_exist) { |
|
| 270 | + add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 271 | + add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent)); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 275 | + // Actions |
|
| 276 | + // @since 1.4.3.7 Deleted |
|
| 277 | + //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 278 | + |
|
| 279 | + /** Product option */ |
|
| 280 | + add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 281 | 281 | /*add_meta_box('wpshop_histo_attrs', __('Historic attributes', 'wpshop'), function($post) { |
| 282 | 282 | global $wpdb; |
| 283 | 283 | $limit = 40; |
@@ -310,21 +310,21 @@ discard block |
||
| 310 | 310 | 'total' => $max_page |
| 311 | 311 | ) ); |
| 312 | 312 | }, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');*/ |
| 313 | - } else if (count($attributeEntitySetList) > 1) { |
|
| 314 | - $input_def['id'] = 'product_attribute_set_id'; |
|
| 315 | - $input_def['name'] = 'product_attribute_set_id'; |
|
| 316 | - $input_def['value'] = ''; |
|
| 317 | - $input_def['type'] = 'select'; |
|
| 318 | - $input_def['possible_value'] = $attributeEntitySetList; |
|
| 319 | - |
|
| 320 | - $input_def['value'] = ''; |
|
| 321 | - foreach ($attributeEntitySetList as $set) { |
|
| 322 | - if ($set->default_set == 'yes') { |
|
| 323 | - $input_def['value'] = $set->id; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 313 | + } else if (count($attributeEntitySetList) > 1) { |
|
| 314 | + $input_def['id'] = 'product_attribute_set_id'; |
|
| 315 | + $input_def['name'] = 'product_attribute_set_id'; |
|
| 316 | + $input_def['value'] = ''; |
|
| 317 | + $input_def['type'] = 'select'; |
|
| 318 | + $input_def['possible_value'] = $attributeEntitySetList; |
|
| 319 | + |
|
| 320 | + $input_def['value'] = ''; |
|
| 321 | + foreach ($attributeEntitySetList as $set) { |
|
| 322 | + if ($set->default_set == 'yes') { |
|
| 323 | + $input_def['value'] = $set->id; |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 328 | 328 | <ul class="attribute_set_selector" > |
| 329 | 329 | <li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li> |
| 330 | 330 | <li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . __('Choose an attribute group for this product', 'wpshop') . '</label> ' . wpshop_form::check_input_type($input_def, self::currentPageCode . '_attribute[integer]') . '</li> |
@@ -332,791 +332,791 @@ discard block |
||
| 332 | 332 | <li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li> |
| 333 | 333 | </ul>'; |
| 334 | 334 | |
| 335 | - add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector')); |
|
| 336 | - } |
|
| 337 | - } |
|
| 335 | + add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector')); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - } |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Add a box into product edition page for options on the product |
|
| 343 | - * |
|
| 344 | - * @param object $post |
|
| 345 | - */ |
|
| 346 | - public static function product_options_meta_box_content($post) |
|
| 347 | - { |
|
| 348 | - $output = ''; |
|
| 341 | + /** |
|
| 342 | + * Add a box into product edition page for options on the product |
|
| 343 | + * |
|
| 344 | + * @param object $post |
|
| 345 | + */ |
|
| 346 | + public static function product_options_meta_box_content($post) |
|
| 347 | + { |
|
| 348 | + $output = ''; |
|
| 349 | 349 | |
| 350 | - $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 350 | + $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 351 | 351 | |
| 352 | - $tpl_component = array(); |
|
| 353 | - $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 354 | - $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 352 | + $tpl_component = array(); |
|
| 353 | + $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 354 | + $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 355 | 355 | |
| 356 | - echo $output; |
|
| 357 | - } |
|
| 356 | + echo $output; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * Display the fixed box |
|
| 361 | - */ |
|
| 362 | - public static function product_data_meta_box($post, $metaboxArgs) |
|
| 363 | - { |
|
| 364 | - $output = ''; |
|
| 359 | + /** |
|
| 360 | + * Display the fixed box |
|
| 361 | + */ |
|
| 362 | + public static function product_data_meta_box($post, $metaboxArgs) |
|
| 363 | + { |
|
| 364 | + $output = ''; |
|
| 365 | 365 | |
| 366 | - $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 366 | + $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 367 | 367 | |
| 368 | - echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 368 | + echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 369 | 369 | <ul>'; |
| 370 | - if (!empty($currentTabContent['box'])) { |
|
| 371 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 372 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 373 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 374 | - echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 380 | - echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 381 | - echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 382 | - echo '</ul>'; |
|
| 383 | - |
|
| 384 | - if (!empty($currentTabContent['box'])) { |
|
| 385 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 386 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 387 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 388 | - echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 370 | + if (!empty($currentTabContent['box'])) { |
|
| 371 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 372 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 373 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 374 | + echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 380 | + echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 381 | + echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 382 | + echo '</ul>'; |
|
| 383 | + |
|
| 384 | + if (!empty($currentTabContent['box'])) { |
|
| 385 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 386 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 387 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 388 | + echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 395 | - echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>'; |
|
| 396 | - echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 397 | - if (!empty($currentTabContent['boxMore'])) { |
|
| 398 | - echo $currentTabContent['boxMore']; |
|
| 399 | - } |
|
| 400 | - echo '</div>'; |
|
| 394 | + echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 395 | + echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>'; |
|
| 396 | + echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 397 | + if (!empty($currentTabContent['boxMore'])) { |
|
| 398 | + echo $currentTabContent['boxMore']; |
|
| 399 | + } |
|
| 400 | + echo '</div>'; |
|
| 401 | 401 | |
| 402 | - echo $output; |
|
| 403 | - } |
|
| 402 | + echo $output; |
|
| 403 | + } |
|
| 404 | 404 | |
| 405 | - /** |
|
| 406 | - * Output the content for related product metabox |
|
| 407 | - * @param object $post The current edited post |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public static function related_products_meta_box_content($post) |
|
| 411 | - { |
|
| 412 | - $content = $existing_selection = ''; |
|
| 413 | - |
|
| 414 | - if (!empty($post->ID)) { |
|
| 415 | - $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 416 | - if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 417 | - foreach ($related_products_id as $related_product_id) { |
|
| 418 | - $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 405 | + /** |
|
| 406 | + * Output the content for related product metabox |
|
| 407 | + * @param object $post The current edited post |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public static function related_products_meta_box_content($post) |
|
| 411 | + { |
|
| 412 | + $content = $existing_selection = ''; |
|
| 413 | + |
|
| 414 | + if (!empty($post->ID)) { |
|
| 415 | + $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 416 | + if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 417 | + foreach ($related_products_id as $related_product_id) { |
|
| 418 | + $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - $content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p> |
|
| 423 | + $content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p> |
|
| 424 | 424 | <select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select> |
| 425 | 425 | <input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" /> |
| 426 | 426 | <input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 427 | 427 | |
| 428 | - return $content; |
|
| 429 | - } |
|
| 428 | + return $content; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - /** |
|
| 432 | - * Output the content for related product metabox |
|
| 433 | - * @param object $post The current edited post |
|
| 434 | - * @return string |
|
| 435 | - */ |
|
| 436 | - public static function provider_products_meta_box_content($post) |
|
| 437 | - { |
|
| 438 | - $content = $existing_selection = ''; |
|
| 439 | - |
|
| 440 | - if (!empty($post->ID)) { |
|
| 441 | - $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true); |
|
| 442 | - if (!empty($providers_id) && !empty($providers_id[0])) { |
|
| 443 | - foreach ($providers_id as $provider_id) { |
|
| 444 | - $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>'; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 431 | + /** |
|
| 432 | + * Output the content for related product metabox |
|
| 433 | + * @param object $post The current edited post |
|
| 434 | + * @return string |
|
| 435 | + */ |
|
| 436 | + public static function provider_products_meta_box_content($post) |
|
| 437 | + { |
|
| 438 | + $content = $existing_selection = ''; |
|
| 439 | + |
|
| 440 | + if (!empty($post->ID)) { |
|
| 441 | + $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true); |
|
| 442 | + if (!empty($providers_id) && !empty($providers_id[0])) { |
|
| 443 | + foreach ($providers_id as $provider_id) { |
|
| 444 | + $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>'; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p> |
|
| 449 | + $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p> |
|
| 450 | 450 | <select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select> |
| 451 | 451 | <input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" /> |
| 452 | 452 | <input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 453 | 453 | |
| 454 | - return $content; |
|
| 455 | - } |
|
| 454 | + return $content; |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * Define the metabox content for the action box |
|
| 459 | - * @param obejct $post The current element being edited |
|
| 460 | - */ |
|
| 461 | - public static function product_actions_meta_box_content($post) |
|
| 462 | - { |
|
| 463 | - $output = ''; |
|
| 464 | - /* |
|
| 457 | + /** |
|
| 458 | + * Define the metabox content for the action box |
|
| 459 | + * @param obejct $post The current element being edited |
|
| 460 | + */ |
|
| 461 | + public static function product_actions_meta_box_content($post) |
|
| 462 | + { |
|
| 463 | + $output = ''; |
|
| 464 | + /* |
|
| 465 | 465 | * Template parameters |
| 466 | 466 | */ |
| 467 | - $template_part = 'wpshop_duplicate_product'; |
|
| 468 | - $tpl_component = array(); |
|
| 469 | - $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 470 | - $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 471 | - /* |
|
| 467 | + $template_part = 'wpshop_duplicate_product'; |
|
| 468 | + $tpl_component = array(); |
|
| 469 | + $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 470 | + $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 471 | + /* |
|
| 472 | 472 | * Build template |
| 473 | 473 | */ |
| 474 | - $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 475 | - unset($tpl_component); |
|
| 474 | + $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 475 | + unset($tpl_component); |
|
| 476 | 476 | |
| 477 | - echo $output; |
|
| 478 | - } |
|
| 477 | + echo $output; |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - /** |
|
| 481 | - * Define the content of the product main information box |
|
| 482 | - */ |
|
| 483 | - public static function meta_box_content($post, $metaboxArgs) |
|
| 484 | - { |
|
| 485 | - global $currentTabContent; |
|
| 480 | + /** |
|
| 481 | + * Define the content of the product main information box |
|
| 482 | + */ |
|
| 483 | + public static function meta_box_content($post, $metaboxArgs) |
|
| 484 | + { |
|
| 485 | + global $currentTabContent; |
|
| 486 | 486 | |
| 487 | - /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 488 | - echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 489 | - } |
|
| 487 | + /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 488 | + echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - /** |
|
| 492 | - * Define the metabox content for product custom display in product |
|
| 493 | - * @param object $post The current element being edited |
|
| 494 | - * @return string The metabox content |
|
| 495 | - */ |
|
| 496 | - public static function product_frontend_display_config_meta_box($post) |
|
| 497 | - { |
|
| 498 | - $content = ''; |
|
| 499 | - |
|
| 500 | - $product_attribute_frontend_display_config = null; |
|
| 501 | - if (!empty($post->ID)) { |
|
| 502 | - $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 503 | - |
|
| 504 | - $extra_options = get_option('wpshop_extra_options', array()); |
|
| 505 | - $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 506 | - $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 507 | - $column = 1; |
|
| 508 | - |
|
| 509 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 510 | - $sub_tpl_component = array(); |
|
| 511 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 512 | - |
|
| 513 | - $tpl_component = array(); |
|
| 514 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 515 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 516 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 517 | - $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 518 | - |
|
| 519 | - $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 520 | - $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : ''; |
|
| 521 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 522 | - unset($tpl_component); |
|
| 523 | - |
|
| 524 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 525 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 526 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 527 | - $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 531 | - foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 532 | - if (!isset($sub_content[$column])) { |
|
| 533 | - $sub_content[$column] = ''; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - $attribute_sub_output = ''; |
|
| 537 | - foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 538 | - if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 539 | - $tpl_component = array(); |
|
| 540 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 541 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 542 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 543 | - $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 544 | - $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : ''; |
|
| 545 | - $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 546 | - unset($tpl_component); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $tpl_component = array(); |
|
| 551 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 552 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 553 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 554 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 555 | - $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 556 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>'; |
|
| 557 | - $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 558 | - $column++; |
|
| 559 | - if ($column > $column_count) { |
|
| 560 | - $column = 1; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - $tpl_component = array(); |
|
| 565 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 566 | - for ($i = 1; $i <= $column_count; $i++) { |
|
| 567 | - if (!empty($sub_content[$i])) { |
|
| 568 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - } |
|
| 572 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 573 | - $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 574 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 575 | - |
|
| 576 | - $content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>'; |
|
| 577 | - } |
|
| 491 | + /** |
|
| 492 | + * Define the metabox content for product custom display in product |
|
| 493 | + * @param object $post The current element being edited |
|
| 494 | + * @return string The metabox content |
|
| 495 | + */ |
|
| 496 | + public static function product_frontend_display_config_meta_box($post) |
|
| 497 | + { |
|
| 498 | + $content = ''; |
|
| 499 | + |
|
| 500 | + $product_attribute_frontend_display_config = null; |
|
| 501 | + if (!empty($post->ID)) { |
|
| 502 | + $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 503 | + |
|
| 504 | + $extra_options = get_option('wpshop_extra_options', array()); |
|
| 505 | + $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 506 | + $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 507 | + $column = 1; |
|
| 508 | + |
|
| 509 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 510 | + $sub_tpl_component = array(); |
|
| 511 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 512 | + |
|
| 513 | + $tpl_component = array(); |
|
| 514 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 515 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 516 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 517 | + $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 518 | + |
|
| 519 | + $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 520 | + $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : ''; |
|
| 521 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 522 | + unset($tpl_component); |
|
| 523 | + |
|
| 524 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 525 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 526 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 527 | + $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 528 | + } |
|
| 578 | 529 | |
| 579 | - return $content; |
|
| 580 | - } |
|
| 530 | + if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 531 | + foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 532 | + if (!isset($sub_content[$column])) { |
|
| 533 | + $sub_content[$column] = ''; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + $attribute_sub_output = ''; |
|
| 537 | + foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 538 | + if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 539 | + $tpl_component = array(); |
|
| 540 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 541 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 542 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 543 | + $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 544 | + $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : ''; |
|
| 545 | + $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 546 | + unset($tpl_component); |
|
| 547 | + } |
|
| 548 | + } |
|
| 581 | 549 | |
| 582 | - /** |
|
| 583 | - * Retrieve the attribute list used for sorting product into frontend listing |
|
| 584 | - * @return array The attribute list to use for listing sorting |
|
| 585 | - */ |
|
| 586 | - public static function get_sorting_criteria() |
|
| 587 | - { |
|
| 588 | - global $wpdb; |
|
| 550 | + $tpl_component = array(); |
|
| 551 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 552 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 553 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 554 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 555 | + $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : ''; |
|
| 556 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>'; |
|
| 557 | + $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 558 | + $column++; |
|
| 559 | + if ($column > $column_count) { |
|
| 560 | + $column = 1; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + $tpl_component = array(); |
|
| 565 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 566 | + for ($i = 1; $i <= $column_count; $i++) { |
|
| 567 | + if (!empty($sub_content[$i])) { |
|
| 568 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 569 | + } |
|
| 589 | 570 | |
| 590 | - $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop'))); |
|
| 571 | + } |
|
| 572 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 573 | + $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 574 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 591 | 575 | |
| 592 | - $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 593 | - $results = $wpdb->get_results($query, ARRAY_A); |
|
| 594 | - if (!empty($results)) { |
|
| 595 | - $data = array_merge($data, $results); |
|
| 596 | - } |
|
| 576 | + $content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>'; |
|
| 577 | + } |
|
| 597 | 578 | |
| 598 | - return $data; |
|
| 599 | - } |
|
| 579 | + return $content; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Retrieve the attribute list used for sorting product into frontend listing |
|
| 584 | + * @return array The attribute list to use for listing sorting |
|
| 585 | + */ |
|
| 586 | + public static function get_sorting_criteria() |
|
| 587 | + { |
|
| 588 | + global $wpdb; |
|
| 589 | + |
|
| 590 | + $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop'))); |
|
| 591 | + |
|
| 592 | + $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 593 | + $results = $wpdb->get_results($query, ARRAY_A); |
|
| 594 | + if (!empty($results)) { |
|
| 595 | + $data = array_merge($data, $results); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return $data; |
|
| 599 | + } |
|
| 600 | 600 | |
| 601 | - public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 602 | - { |
|
| 603 | - global $wpdb; |
|
| 601 | + public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 602 | + { |
|
| 603 | + global $wpdb; |
|
| 604 | 604 | |
| 605 | - $products = array(); |
|
| 606 | - $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 607 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 605 | + $products = array(); |
|
| 606 | + $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 607 | + $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 608 | 608 | |
| 609 | - if (!empty($data)) { |
|
| 610 | - if ($data['data_type_to_use'] == 'custom') { |
|
| 611 | - // Find which table to take |
|
| 612 | - if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;} |
|
| 609 | + if (!empty($data)) { |
|
| 610 | + if ($data['data_type_to_use'] == 'custom') { |
|
| 611 | + // Find which table to take |
|
| 612 | + if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;} |
|
| 613 | 613 | |
| 614 | - if (isset($table_name)) { |
|
| 615 | - // If the value is an id of a select, radio or checkbox |
|
| 616 | - if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 614 | + if (isset($table_name)) { |
|
| 615 | + // If the value is an id of a select, radio or checkbox |
|
| 616 | + if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 617 | 617 | |
| 618 | - $query = $wpdb->prepare(" |
|
| 618 | + $query = $wpdb->prepare(" |
|
| 619 | 619 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 620 | 620 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 621 | 621 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 622 | 622 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id |
| 623 | 623 | WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value |
| 624 | - ); |
|
| 625 | - $data = $wpdb->get_results($query); |
|
| 626 | - } else { |
|
| 624 | + ); |
|
| 625 | + $data = $wpdb->get_results($query); |
|
| 626 | + } else { |
|
| 627 | 627 | |
| 628 | - $query = $wpdb->prepare(" |
|
| 628 | + $query = $wpdb->prepare(" |
|
| 629 | 629 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 630 | 630 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 631 | 631 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 632 | 632 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 633 | 633 | WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000 |
| 634 | - ); |
|
| 635 | - $data = $wpdb->get_results($query); |
|
| 636 | - |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 643 | - /** Check the ID of manufacturer **/ |
|
| 644 | - $default_value = unserialize($data['default_value']); |
|
| 645 | - if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 646 | - $query = get_post($attr_value); |
|
| 647 | - $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 648 | - if (!empty($pid)) { |
|
| 649 | - $query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid); |
|
| 650 | - $data = $wpdb->get_results($query); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } else { |
|
| 654 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - } else { |
|
| 658 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 659 | - } |
|
| 634 | + ); |
|
| 635 | + $data = $wpdb->get_results($query); |
|
| 660 | 636 | |
| 661 | - if (!empty($data)) { |
|
| 662 | - foreach ($data as $p) { |
|
| 663 | - if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 664 | - $products[] = $p->entity_id; |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - return $products; |
|
| 669 | - } |
|
| 637 | + } |
|
| 638 | + } else { |
|
| 639 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 640 | + } |
|
| 670 | 641 | |
| 671 | - /** |
|
| 672 | - * Related product shortcode reader |
|
| 673 | - * |
|
| 674 | - * @param array $atts { |
|
| 675 | - * pid : Product idenfifier to get related element for |
|
| 676 | - * display_mode : The output mode if defined (grid || list) |
|
| 677 | - * } |
|
| 678 | - * |
|
| 679 | - * @return string |
|
| 680 | - * |
|
| 681 | - */ |
|
| 682 | - public static function wpshop_related_products_func($atts) |
|
| 683 | - { |
|
| 684 | - global $wp_query; |
|
| 642 | + } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 643 | + /** Check the ID of manufacturer **/ |
|
| 644 | + $default_value = unserialize($data['default_value']); |
|
| 645 | + if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 646 | + $query = get_post($attr_value); |
|
| 647 | + $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 648 | + if (!empty($pid)) { |
|
| 649 | + $query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid); |
|
| 650 | + $data = $wpdb->get_results($query); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } else { |
|
| 654 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 655 | + } |
|
| 685 | 656 | |
| 686 | - $atts['product_type'] = 'related'; |
|
| 687 | - if (empty($atts['pid'])) { |
|
| 688 | - $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 689 | - } |
|
| 657 | + } else { |
|
| 658 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + if (!empty($data)) { |
|
| 662 | + foreach ($data as $p) { |
|
| 663 | + if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 664 | + $products[] = $p->entity_id; |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + return $products; |
|
| 669 | + } |
|
| 690 | 670 | |
| 691 | - $related_product_output = self::wpshop_products_func($atts); |
|
| 671 | + /** |
|
| 672 | + * Related product shortcode reader |
|
| 673 | + * |
|
| 674 | + * @param array $atts { |
|
| 675 | + * pid : Product idenfifier to get related element for |
|
| 676 | + * display_mode : The output mode if defined (grid || list) |
|
| 677 | + * } |
|
| 678 | + * |
|
| 679 | + * @return string |
|
| 680 | + * |
|
| 681 | + */ |
|
| 682 | + public static function wpshop_related_products_func($atts) |
|
| 683 | + { |
|
| 684 | + global $wp_query; |
|
| 685 | + |
|
| 686 | + $atts['product_type'] = 'related'; |
|
| 687 | + if (empty($atts['pid'])) { |
|
| 688 | + $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 689 | + } |
|
| 692 | 690 | |
| 693 | - $output = ''; |
|
| 694 | - if (!empty($related_product_output)) { |
|
| 695 | - ob_start(); |
|
| 696 | - require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 697 | - $output = ob_get_contents(); |
|
| 698 | - ob_end_clean(); |
|
| 699 | - } |
|
| 691 | + $related_product_output = self::wpshop_products_func($atts); |
|
| 700 | 692 | |
| 701 | - return $output; |
|
| 702 | - } |
|
| 693 | + $output = ''; |
|
| 694 | + if (!empty($related_product_output)) { |
|
| 695 | + ob_start(); |
|
| 696 | + require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 697 | + $output = ob_get_contents(); |
|
| 698 | + ob_end_clean(); |
|
| 699 | + } |
|
| 703 | 700 | |
| 704 | - /** |
|
| 705 | - * Display a list of product from a shortcode |
|
| 706 | - * |
|
| 707 | - * @param array $atts { |
|
| 708 | - * limit : The number of element to display |
|
| 709 | - * order : The information to order list by |
|
| 710 | - * sorting : List order (ASC | DESC) |
|
| 711 | - * display : Display size (normal | mini) |
|
| 712 | - * type : Display tyep (grid | list) only work with display=normal |
|
| 713 | - * pagination : The number of element per page |
|
| 714 | - * display_pagination : Display the pagination or not |
|
| 715 | - * } |
|
| 716 | - * |
|
| 717 | - * @return string |
|
| 718 | - * |
|
| 719 | - **/ |
|
| 720 | - public static function wpshop_products_func($atts) |
|
| 721 | - { |
|
| 722 | - global $wpdb, $wp_query; |
|
| 723 | - |
|
| 724 | - $string = ''; |
|
| 725 | - $have_results = false; |
|
| 726 | - $output_results = true; |
|
| 727 | - $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 728 | - $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 729 | - $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 730 | - $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 731 | - $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 732 | - $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 733 | - $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 734 | - $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 735 | - $attr = ''; |
|
| 736 | - |
|
| 737 | - $sorting_criteria = self::get_sorting_criteria(); |
|
| 738 | - |
|
| 739 | - /** Get products which have att_name equal to att_value */ |
|
| 740 | - if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 741 | - $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 742 | - |
|
| 743 | - $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 744 | - |
|
| 745 | - // Foreach on the found products |
|
| 746 | - if (!empty($products)) { |
|
| 747 | - $pid = implode(',', $products); |
|
| 748 | - if (empty($pid)) { |
|
| 749 | - $output_results = false; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - } else { |
|
| 753 | - $output_results = false; |
|
| 754 | - } |
|
| 701 | + return $output; |
|
| 702 | + } |
|
| 755 | 703 | |
| 756 | - } |
|
| 704 | + /** |
|
| 705 | + * Display a list of product from a shortcode |
|
| 706 | + * |
|
| 707 | + * @param array $atts { |
|
| 708 | + * limit : The number of element to display |
|
| 709 | + * order : The information to order list by |
|
| 710 | + * sorting : List order (ASC | DESC) |
|
| 711 | + * display : Display size (normal | mini) |
|
| 712 | + * type : Display tyep (grid | list) only work with display=normal |
|
| 713 | + * pagination : The number of element per page |
|
| 714 | + * display_pagination : Display the pagination or not |
|
| 715 | + * } |
|
| 716 | + * |
|
| 717 | + * @return string |
|
| 718 | + * |
|
| 719 | + **/ |
|
| 720 | + public static function wpshop_products_func($atts) |
|
| 721 | + { |
|
| 722 | + global $wpdb, $wp_query; |
|
| 723 | + |
|
| 724 | + $string = ''; |
|
| 725 | + $have_results = false; |
|
| 726 | + $output_results = true; |
|
| 727 | + $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 728 | + $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 729 | + $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 730 | + $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 731 | + $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 732 | + $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 733 | + $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 734 | + $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 735 | + $attr = ''; |
|
| 736 | + |
|
| 737 | + $sorting_criteria = self::get_sorting_criteria(); |
|
| 738 | + |
|
| 739 | + /** Get products which have att_name equal to att_value */ |
|
| 740 | + if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 741 | + $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 742 | + |
|
| 743 | + $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 744 | + |
|
| 745 | + // Foreach on the found products |
|
| 746 | + if (!empty($products)) { |
|
| 747 | + $pid = implode(',', $products); |
|
| 748 | + if (empty($pid)) { |
|
| 749 | + $output_results = false; |
|
| 750 | + } |
|
| 757 | 751 | |
| 758 | - /** Get related products */ |
|
| 759 | - if (!empty($atts['product_type'])) { |
|
| 760 | - switch ($atts['product_type']) { |
|
| 761 | - case 'related': |
|
| 762 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 763 | - $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 764 | - $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 765 | - |
|
| 766 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 767 | - if (!empty($pids) && !empty($pids[0])) { |
|
| 768 | - $pid = implode(',', $pids); |
|
| 769 | - } |
|
| 770 | - if (empty($pid) || $pid == $product_id) { |
|
| 771 | - $output_results = false; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - break; |
|
| 775 | - } |
|
| 776 | - } |
|
| 752 | + } else { |
|
| 753 | + $output_results = false; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + } |
|
| 777 | 757 | |
| 778 | - /** Output all the products */ |
|
| 779 | - if ($output_results) { |
|
| 780 | - $data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination); |
|
| 758 | + /** Get related products */ |
|
| 759 | + if (!empty($atts['product_type'])) { |
|
| 760 | + switch ($atts['product_type']) { |
|
| 761 | + case 'related': |
|
| 762 | + $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 763 | + $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 764 | + $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
|
| 765 | + |
|
| 766 | + $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 767 | + if (!empty($pids) && !empty($pids[0])) { |
|
| 768 | + $pid = implode(',', $pids); |
|
| 769 | + } |
|
| 770 | + if (empty($pid) || $pid == $product_id) { |
|
| 771 | + $output_results = false; |
|
| 772 | + } |
|
| 781 | 773 | |
| 782 | - if ($data[0]) { |
|
| 783 | - $have_results = true; |
|
| 784 | - $string = $data[1]; |
|
| 785 | - } |
|
| 786 | - } |
|
| 774 | + break; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + /** Output all the products */ |
|
| 779 | + if ($output_results) { |
|
| 780 | + $data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination); |
|
| 781 | + |
|
| 782 | + if ($data[0]) { |
|
| 783 | + $have_results = true; |
|
| 784 | + $string = $data[1]; |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + /** If there are result to display */ |
|
| 789 | + if ($have_results) { |
|
| 790 | + $sorting = ''; |
|
| 791 | + if (!empty($pid)) { |
|
| 792 | + $product_list = explode(',', $pid); |
|
| 793 | + if (count($product_list) == 1) { |
|
| 794 | + $atts['sorting'] = 'no'; |
|
| 795 | + } |
|
| 796 | + } |
|
| 787 | 797 | |
| 788 | - /** If there are result to display */ |
|
| 789 | - if ($have_results) { |
|
| 790 | - $sorting = ''; |
|
| 791 | - if (!empty($pid)) { |
|
| 792 | - $product_list = explode(',', $pid); |
|
| 793 | - if (count($product_list) == 1) { |
|
| 794 | - $atts['sorting'] = 'no'; |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - /* |
|
| 798 | + /* |
|
| 799 | 799 | * Template parameters |
| 800 | 800 | */ |
| 801 | - $template_part = 'product_listing_sorting'; |
|
| 802 | - $tpl_component = array(); |
|
| 801 | + $template_part = 'product_listing_sorting'; |
|
| 802 | + $tpl_component = array(); |
|
| 803 | 803 | |
| 804 | - /* |
|
| 804 | + /* |
|
| 805 | 805 | * Build template |
| 806 | 806 | */ |
| 807 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 808 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 809 | - /* Include the old way template part */ |
|
| 810 | - ob_start(); |
|
| 811 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 812 | - $sorting = ob_get_contents(); |
|
| 813 | - ob_end_clean(); |
|
| 814 | - } else { |
|
| 815 | - /* |
|
| 807 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 808 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 809 | + /* Include the old way template part */ |
|
| 810 | + ob_start(); |
|
| 811 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 812 | + $sorting = ob_get_contents(); |
|
| 813 | + ob_end_clean(); |
|
| 814 | + } else { |
|
| 815 | + /* |
|
| 816 | 816 | * Display hidden field every times |
| 817 | 817 | */ |
| 818 | - $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 819 | - $sub_tpl_component = array(); |
|
| 820 | - $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 821 | - $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 822 | - $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 823 | - $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 824 | - $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 825 | - $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 826 | - $sub_tpl_component['ATTR'] = $attr; |
|
| 827 | - $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 828 | - unset($sub_tpl_component); |
|
| 829 | - |
|
| 830 | - if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 831 | - $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 832 | - $sub_tpl_component = array(); |
|
| 833 | - $criteria = ''; |
|
| 834 | - foreach ($sorting_criteria as $c): |
|
| 835 | - $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 836 | - endforeach; |
|
| 837 | - $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 838 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 839 | - unset($sub_tpl_component); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 843 | - $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 844 | - $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 845 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 846 | - } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 847 | - $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 848 | - $sub_tpl_component = array(); |
|
| 849 | - $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 850 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 851 | - unset($sub_tpl_component); |
|
| 852 | - |
|
| 853 | - $template_part = 'product_listing_sorting_hidden'; |
|
| 854 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - unset($tpl_component); |
|
| 858 | - |
|
| 859 | - if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 860 | - $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 861 | - } else { |
|
| 862 | - $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>'; |
|
| 863 | - } |
|
| 864 | - } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 865 | - $string = __('There is nothing to output here', 'wpshop'); |
|
| 866 | - } |
|
| 818 | + $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 819 | + $sub_tpl_component = array(); |
|
| 820 | + $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 821 | + $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 822 | + $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 823 | + $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 824 | + $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 825 | + $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 826 | + $sub_tpl_component['ATTR'] = $attr; |
|
| 827 | + $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 828 | + unset($sub_tpl_component); |
|
| 829 | + |
|
| 830 | + if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 831 | + $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 832 | + $sub_tpl_component = array(); |
|
| 833 | + $criteria = ''; |
|
| 834 | + foreach ($sorting_criteria as $c): |
|
| 835 | + $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 836 | + endforeach; |
|
| 837 | + $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 838 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 839 | + unset($sub_tpl_component); |
|
| 840 | + } |
|
| 867 | 841 | |
| 868 | - return do_shortcode($string); |
|
| 869 | - } |
|
| 842 | + if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 843 | + $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 844 | + $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 845 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 846 | + } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 847 | + $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 848 | + $sub_tpl_component = array(); |
|
| 849 | + $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 850 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 851 | + unset($sub_tpl_component); |
|
| 852 | + |
|
| 853 | + $template_part = 'product_listing_sorting_hidden'; |
|
| 854 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + unset($tpl_component); |
|
| 870 | 858 | |
| 871 | - 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) |
|
| 872 | - { |
|
| 873 | - global $wpdb; |
|
| 859 | + if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 860 | + $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 861 | + } else { |
|
| 862 | + $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>'; |
|
| 863 | + } |
|
| 864 | + } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 865 | + $string = __('There is nothing to output here', 'wpshop'); |
|
| 866 | + } |
|
| 874 | 867 | |
| 875 | - $string = '<span id="wpshop_loading"> </span>'; |
|
| 876 | - $have_results = false; |
|
| 877 | - $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 868 | + return do_shortcode($string); |
|
| 869 | + } |
|
| 878 | 870 | |
| 879 | - /** Check if Discount are activated */ |
|
| 880 | - $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 871 | + 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) |
|
| 872 | + { |
|
| 873 | + global $wpdb; |
|
| 881 | 874 | |
| 882 | - if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 883 | - $criteria = 'wpshop_displayed_price'; |
|
| 884 | - } |
|
| 875 | + $string = '<span id="wpshop_loading"> </span>'; |
|
| 876 | + $have_results = false; |
|
| 877 | + $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 885 | 878 | |
| 886 | - $query = array( |
|
| 887 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 888 | - 'order' => $order, |
|
| 889 | - 'posts_per_page' => $products_per_page, |
|
| 890 | - 'paged' => $page_number, |
|
| 891 | - 'post_status' => 'publish', |
|
| 892 | - ); |
|
| 893 | - |
|
| 894 | - // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 895 | - if ($nb_of_product_limit > 0) { |
|
| 896 | - $query['posts_per_page'] = $nb_of_product_limit; |
|
| 897 | - unset($query['paged']); |
|
| 898 | - } |
|
| 899 | - if (!empty($pid)) { |
|
| 900 | - if (!is_array($pid)) { |
|
| 901 | - $pid = explode(',', $pid); |
|
| 902 | - } |
|
| 879 | + /** Check if Discount are activated */ |
|
| 880 | + $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 903 | 881 | |
| 904 | - $query['post__in'] = $pid; |
|
| 905 | - } |
|
| 906 | - if (!empty($cid)) { |
|
| 907 | - $cid = explode(',', $cid); |
|
| 908 | - $query['tax_query'] = array(array( |
|
| 909 | - 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 910 | - 'field' => 'id', |
|
| 911 | - 'terms' => $cid, |
|
| 912 | - 'operator' => 'IN', |
|
| 913 | - )); |
|
| 914 | - } |
|
| 915 | - if ($criteria != null) { |
|
| 916 | - switch ($criteria) { |
|
| 917 | - case 'creator': |
|
| 918 | - case 'author': |
|
| 919 | - $query['author'] = get_current_user_id(); |
|
| 920 | - break; |
|
| 921 | - case 'none': |
|
| 922 | - case 'ID': |
|
| 923 | - case 'title': |
|
| 924 | - case 'date': |
|
| 925 | - case 'modified': |
|
| 926 | - case 'relevance': |
|
| 927 | - case 'post__in': |
|
| 928 | - case 'rand': |
|
| 929 | - $query['orderby'] = $criteria; |
|
| 930 | - break; |
|
| 931 | - default: |
|
| 932 | - if (!empty($pid)) { |
|
| 933 | - $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 934 | - } else { |
|
| 935 | - $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 936 | - $post_meta = $wpdb->get_var($check_meta); |
|
| 937 | - } |
|
| 938 | - if (!empty($post_meta)) { |
|
| 939 | - if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 940 | - $query['orderby'] = 'meta_value_num'; |
|
| 941 | - } else { |
|
| 942 | - $query['orderby'] = 'meta_value'; |
|
| 943 | - } |
|
| 944 | - $query['meta_key'] = '_' . $criteria; |
|
| 945 | - } |
|
| 946 | - break; |
|
| 947 | - } |
|
| 948 | - } else { |
|
| 949 | - $query['orderby'] = 'menu_order ID'; |
|
| 950 | - } |
|
| 951 | - $post_per_page = $query['posts_per_page']; |
|
| 952 | - $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 953 | - if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 954 | - $tmp_array = array(); |
|
| 955 | - |
|
| 956 | - if (empty($page_number) || $page_number == 1) { |
|
| 957 | - for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 958 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 959 | - } |
|
| 960 | - } else { |
|
| 961 | - $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 962 | - for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 963 | - if (!empty($query['post__in'][$i])) { |
|
| 964 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - unset($query['post__in']); |
|
| 969 | - $query['post__in'] = $tmp_array; |
|
| 970 | - $query['posts_per_page'] = -1; |
|
| 971 | - } |
|
| 882 | + if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 883 | + $criteria = 'wpshop_displayed_price'; |
|
| 884 | + } |
|
| 972 | 885 | |
| 973 | - $query['post_status'] = 'publish'; |
|
| 974 | - |
|
| 975 | - $custom_query = new WP_Query($query); |
|
| 976 | - |
|
| 977 | - if ($custom_query->have_posts()) { |
|
| 978 | - $have_results = true; |
|
| 979 | - |
|
| 980 | - // ---------------- // |
|
| 981 | - // Products listing // |
|
| 982 | - // ---------------- // |
|
| 983 | - $current_position = 1; |
|
| 984 | - $product_list = ''; |
|
| 985 | - while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 986 | - $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 987 | - $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 988 | - $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 989 | - $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 990 | - $current_position++; |
|
| 991 | - endwhile; |
|
| 992 | - $tpl_component = array(); |
|
| 993 | - $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 994 | - $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 995 | - $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 996 | - $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 997 | - $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 998 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 999 | - $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 1000 | - |
|
| 1001 | - // --------------------- // |
|
| 1002 | - // Pagination management // |
|
| 1003 | - // --------------------- // |
|
| 1004 | - if ( $display_pagination ) { |
|
| 1005 | - if ($nb_of_product_limit == 0) { |
|
| 1006 | - |
|
| 1007 | - $paginate = paginate_links(array( |
|
| 1008 | - 'base' => '%_%', |
|
| 1009 | - 'format' => '/?page_product=%#%', |
|
| 1010 | - 'current' => $page_number, |
|
| 1011 | - 'total' => $custom_query->max_num_pages, |
|
| 1012 | - 'type' => 'array', |
|
| 1013 | - 'prev_next' => false, |
|
| 1014 | - )); |
|
| 1015 | - if (!empty($paginate)) { |
|
| 1016 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 1017 | - foreach ($paginate as $p) { |
|
| 1018 | - $string .= '<li>' . $p . '</li>'; |
|
| 1019 | - } |
|
| 1020 | - $string .= '</ul>'; |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 1025 | - $paginate = paginate_links(array( |
|
| 1026 | - 'base' => '%_%', |
|
| 1027 | - 'format' => '/?page_product=%#%', |
|
| 1028 | - 'current' => $page_number, |
|
| 1029 | - 'total' => ceil(count($total_products) / $post_per_page), |
|
| 1030 | - 'type' => 'array', |
|
| 1031 | - 'prev_next' => false, |
|
| 1032 | - )); |
|
| 1033 | - if (!empty($paginate)) { |
|
| 1034 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 1035 | - foreach ($paginate as $p) { |
|
| 1036 | - $string .= '<li>' . $p . '</li>'; |
|
| 1037 | - } |
|
| 1038 | - $string .= '</ul>'; |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 886 | + $query = array( |
|
| 887 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 888 | + 'order' => $order, |
|
| 889 | + 'posts_per_page' => $products_per_page, |
|
| 890 | + 'paged' => $page_number, |
|
| 891 | + 'post_status' => 'publish', |
|
| 892 | + ); |
|
| 893 | + |
|
| 894 | + // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 895 | + if ($nb_of_product_limit > 0) { |
|
| 896 | + $query['posts_per_page'] = $nb_of_product_limit; |
|
| 897 | + unset($query['paged']); |
|
| 898 | + } |
|
| 899 | + if (!empty($pid)) { |
|
| 900 | + if (!is_array($pid)) { |
|
| 901 | + $pid = explode(',', $pid); |
|
| 902 | + } |
|
| 1042 | 903 | |
| 1043 | - } |
|
| 1044 | - wp_reset_query(); // important |
|
| 904 | + $query['post__in'] = $pid; |
|
| 905 | + } |
|
| 906 | + if (!empty($cid)) { |
|
| 907 | + $cid = explode(',', $cid); |
|
| 908 | + $query['tax_query'] = array(array( |
|
| 909 | + 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 910 | + 'field' => 'id', |
|
| 911 | + 'terms' => $cid, |
|
| 912 | + 'operator' => 'IN', |
|
| 913 | + )); |
|
| 914 | + } |
|
| 915 | + if ($criteria != null) { |
|
| 916 | + switch ($criteria) { |
|
| 917 | + case 'creator': |
|
| 918 | + case 'author': |
|
| 919 | + $query['author'] = get_current_user_id(); |
|
| 920 | + break; |
|
| 921 | + case 'none': |
|
| 922 | + case 'ID': |
|
| 923 | + case 'title': |
|
| 924 | + case 'date': |
|
| 925 | + case 'modified': |
|
| 926 | + case 'relevance': |
|
| 927 | + case 'post__in': |
|
| 928 | + case 'rand': |
|
| 929 | + $query['orderby'] = $criteria; |
|
| 930 | + break; |
|
| 931 | + default: |
|
| 932 | + if (!empty($pid)) { |
|
| 933 | + $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 934 | + } else { |
|
| 935 | + $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 936 | + $post_meta = $wpdb->get_var($check_meta); |
|
| 937 | + } |
|
| 938 | + if (!empty($post_meta)) { |
|
| 939 | + if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 940 | + $query['orderby'] = 'meta_value_num'; |
|
| 941 | + } else { |
|
| 942 | + $query['orderby'] = 'meta_value'; |
|
| 943 | + } |
|
| 944 | + $query['meta_key'] = '_' . $criteria; |
|
| 945 | + } |
|
| 946 | + break; |
|
| 947 | + } |
|
| 948 | + } else { |
|
| 949 | + $query['orderby'] = 'menu_order ID'; |
|
| 950 | + } |
|
| 951 | + $post_per_page = $query['posts_per_page']; |
|
| 952 | + $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 953 | + if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 954 | + $tmp_array = array(); |
|
| 955 | + |
|
| 956 | + if (empty($page_number) || $page_number == 1) { |
|
| 957 | + for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 958 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 959 | + } |
|
| 960 | + } else { |
|
| 961 | + $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 962 | + for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 963 | + if (!empty($query['post__in'][$i])) { |
|
| 964 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + unset($query['post__in']); |
|
| 969 | + $query['post__in'] = $tmp_array; |
|
| 970 | + $query['posts_per_page'] = -1; |
|
| 971 | + } |
|
| 1045 | 972 | |
| 1046 | - return array($have_results, $string); |
|
| 1047 | - } |
|
| 973 | + $query['post_status'] = 'publish'; |
|
| 974 | + |
|
| 975 | + $custom_query = new WP_Query($query); |
|
| 976 | + |
|
| 977 | + if ($custom_query->have_posts()) { |
|
| 978 | + $have_results = true; |
|
| 979 | + |
|
| 980 | + // ---------------- // |
|
| 981 | + // Products listing // |
|
| 982 | + // ---------------- // |
|
| 983 | + $current_position = 1; |
|
| 984 | + $product_list = ''; |
|
| 985 | + while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 986 | + $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 987 | + $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 988 | + $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 989 | + $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 990 | + $current_position++; |
|
| 991 | + endwhile; |
|
| 992 | + $tpl_component = array(); |
|
| 993 | + $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 994 | + $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 995 | + $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 996 | + $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 997 | + $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 998 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 999 | + $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 1000 | + |
|
| 1001 | + // --------------------- // |
|
| 1002 | + // Pagination management // |
|
| 1003 | + // --------------------- // |
|
| 1004 | + if ( $display_pagination ) { |
|
| 1005 | + if ($nb_of_product_limit == 0) { |
|
| 1006 | + |
|
| 1007 | + $paginate = paginate_links(array( |
|
| 1008 | + 'base' => '%_%', |
|
| 1009 | + 'format' => '/?page_product=%#%', |
|
| 1010 | + 'current' => $page_number, |
|
| 1011 | + 'total' => $custom_query->max_num_pages, |
|
| 1012 | + 'type' => 'array', |
|
| 1013 | + 'prev_next' => false, |
|
| 1014 | + )); |
|
| 1015 | + if (!empty($paginate)) { |
|
| 1016 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 1017 | + foreach ($paginate as $p) { |
|
| 1018 | + $string .= '<li>' . $p . '</li>'; |
|
| 1019 | + } |
|
| 1020 | + $string .= '</ul>'; |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1048 | 1023 | |
| 1049 | - /** |
|
| 1050 | - * Update quantity for a product |
|
| 1051 | - * @param integer $product_id The product we want to update quantity for |
|
| 1052 | - * @param decimal $qty The new quantity |
|
| 1053 | - */ |
|
| 1054 | - public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') |
|
| 1055 | - { |
|
| 1056 | - global $wpdb; |
|
| 1057 | - |
|
| 1058 | - $product = self::get_product_data($product_id); |
|
| 1059 | - /** Check if there is variation ***/ |
|
| 1060 | - if (!empty($variation_id) && $variation_id != $product_id) { |
|
| 1061 | - $variation_post_type = get_post_type($variation_id); |
|
| 1062 | - if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1063 | - /** Check if variation def is combined **/ |
|
| 1064 | - $variations = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1065 | - if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) { |
|
| 1066 | - /** Get post meta of variation */ |
|
| 1067 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1068 | - if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) { |
|
| 1069 | - $product = self::get_product_data($variation_id); |
|
| 1070 | - $product_id = $variation_id; |
|
| 1071 | - } |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1024 | + if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 1025 | + $paginate = paginate_links(array( |
|
| 1026 | + 'base' => '%_%', |
|
| 1027 | + 'format' => '/?page_product=%#%', |
|
| 1028 | + 'current' => $page_number, |
|
| 1029 | + 'total' => ceil(count($total_products) / $post_per_page), |
|
| 1030 | + 'type' => 'array', |
|
| 1031 | + 'prev_next' => false, |
|
| 1032 | + )); |
|
| 1033 | + if (!empty($paginate)) { |
|
| 1034 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 1035 | + foreach ($paginate as $p) { |
|
| 1036 | + $string .= '<li>' . $p . '</li>'; |
|
| 1037 | + } |
|
| 1038 | + $string .= '</ul>'; |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + } |
|
| 1044 | + wp_reset_query(); // important |
|
| 1075 | 1045 | |
| 1076 | - if (!empty($product)) { |
|
| 1077 | - $newQty = $product['product_stock'] - $qty; |
|
| 1078 | - $value_id = 0; |
|
| 1079 | - if ($newQty >= 0) { |
|
| 1080 | - $query = ' |
|
| 1046 | + return array($have_results, $string); |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * Update quantity for a product |
|
| 1051 | + * @param integer $product_id The product we want to update quantity for |
|
| 1052 | + * @param decimal $qty The new quantity |
|
| 1053 | + */ |
|
| 1054 | + public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') |
|
| 1055 | + { |
|
| 1056 | + global $wpdb; |
|
| 1057 | + |
|
| 1058 | + $product = self::get_product_data($product_id); |
|
| 1059 | + /** Check if there is variation ***/ |
|
| 1060 | + if (!empty($variation_id) && $variation_id != $product_id) { |
|
| 1061 | + $variation_post_type = get_post_type($variation_id); |
|
| 1062 | + if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1063 | + /** Check if variation def is combined **/ |
|
| 1064 | + $variations = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1065 | + if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) { |
|
| 1066 | + /** Get post meta of variation */ |
|
| 1067 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1068 | + if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) { |
|
| 1069 | + $product = self::get_product_data($variation_id); |
|
| 1070 | + $product_id = $variation_id; |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + if (!empty($product)) { |
|
| 1077 | + $newQty = $product['product_stock'] - $qty; |
|
| 1078 | + $value_id = 0; |
|
| 1079 | + if ($newQty >= 0) { |
|
| 1080 | + $query = ' |
|
| 1081 | 1081 | SELECT wp_wpshop__attribute_value_decimal.value_id |
| 1082 | 1082 | FROM wp_wpshop__attribute_value_decimal |
| 1083 | 1083 | LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id |
| 1084 | 1084 | WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock" |
| 1085 | 1085 | LIMIT 1 |
| 1086 | 1086 | '; |
| 1087 | - $value_id = $wpdb->get_var($query); |
|
| 1088 | - $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id)); |
|
| 1089 | - } |
|
| 1090 | - // Historic |
|
| 1091 | - $attribute_histo_content = array(); |
|
| 1092 | - $attribute_histo_content['status'] = 'valid'; |
|
| 1093 | - $attribute_histo_content['creation_date'] = current_time('mysql', 0); |
|
| 1094 | - $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0); |
|
| 1095 | - $attribute_histo_content['original_value_id'] = $value_id; |
|
| 1096 | - $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1097 | - $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code'); |
|
| 1098 | - $attribute_histo_content['attribute_id'] = $stock_atribute->id; |
|
| 1099 | - $attribute_histo_content['entity_id'] = $product_id; |
|
| 1100 | - $attribute_histo_content['value'] = $product['product_stock']; |
|
| 1101 | - $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal'; |
|
| 1102 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content); |
|
| 1103 | - |
|
| 1104 | - $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 1105 | - $product_meta['product_stock'] = $newQty; |
|
| 1106 | - update_post_meta($product_id, '_wpshop_product_metadata', $product_meta); |
|
| 1107 | - } |
|
| 1108 | - } |
|
| 1087 | + $value_id = $wpdb->get_var($query); |
|
| 1088 | + $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id)); |
|
| 1089 | + } |
|
| 1090 | + // Historic |
|
| 1091 | + $attribute_histo_content = array(); |
|
| 1092 | + $attribute_histo_content['status'] = 'valid'; |
|
| 1093 | + $attribute_histo_content['creation_date'] = current_time('mysql', 0); |
|
| 1094 | + $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0); |
|
| 1095 | + $attribute_histo_content['original_value_id'] = $value_id; |
|
| 1096 | + $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1097 | + $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code'); |
|
| 1098 | + $attribute_histo_content['attribute_id'] = $stock_atribute->id; |
|
| 1099 | + $attribute_histo_content['entity_id'] = $product_id; |
|
| 1100 | + $attribute_histo_content['value'] = $product['product_stock']; |
|
| 1101 | + $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal'; |
|
| 1102 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content); |
|
| 1103 | + |
|
| 1104 | + $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 1105 | + $product_meta['product_stock'] = $newQty; |
|
| 1106 | + update_post_meta($product_id, '_wpshop_product_metadata', $product_meta); |
|
| 1107 | + } |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - /** |
|
| 1111 | - * Retrieve an array with complete information about a given product |
|
| 1112 | - * @param integer $product_id |
|
| 1113 | - * @param boolean $for_cart_storage |
|
| 1114 | - * @return array Information about the product defined by first parameter |
|
| 1115 | - */ |
|
| 1116 | - public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1117 | - { |
|
| 1118 | - global $wpdb; |
|
| 1119 | - $query = $wpdb->prepare(' |
|
| 1110 | + /** |
|
| 1111 | + * Retrieve an array with complete information about a given product |
|
| 1112 | + * @param integer $product_id |
|
| 1113 | + * @param boolean $for_cart_storage |
|
| 1114 | + * @return array Information about the product defined by first parameter |
|
| 1115 | + */ |
|
| 1116 | + public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1117 | + { |
|
| 1118 | + global $wpdb; |
|
| 1119 | + $query = $wpdb->prepare(' |
|
| 1120 | 1120 | SELECT P.*, PM.meta_value AS attribute_set_id |
| 1121 | 1121 | FROM ' . $wpdb->posts . ' AS P |
| 1122 | 1122 | INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID) |
@@ -1128,398 +1128,398 @@ discard block |
||
| 1128 | 1128 | LIMIT 1 |
| 1129 | 1129 | ', $product_id); |
| 1130 | 1130 | |
| 1131 | - $product = $wpdb->get_row($query); |
|
| 1132 | - |
|
| 1133 | - $product_data = array(); |
|
| 1134 | - $product_meta = array(); |
|
| 1135 | - |
|
| 1136 | - if (!empty($product)) { |
|
| 1137 | - $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1138 | - $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1139 | - $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1140 | - $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1141 | - |
|
| 1142 | - $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1143 | - $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1144 | - $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1145 | - $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1146 | - |
|
| 1147 | - $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1148 | - |
|
| 1149 | - $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); |
|
| 1150 | - if (!empty($data)) { |
|
| 1151 | - foreach ($data as $attribute) { |
|
| 1152 | - $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1153 | - $value = $attribute->$data_type; |
|
| 1154 | - if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1155 | - $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - /** Special traitment regarding attribute_code */ |
|
| 1159 | - switch ($attribute->attribute_code) { |
|
| 1160 | - case 'product_weight': |
|
| 1161 | - $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1162 | - if (!empty($default_weight_unity)) { |
|
| 1163 | - $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1164 | - $unity = $wpdb->get_var($query); |
|
| 1165 | - if ($unity == 'kg') { |
|
| 1166 | - $value *= 1000; |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - } |
|
| 1170 | - break; |
|
| 1171 | - default: |
|
| 1172 | - $value = !empty($value) ? $value : 0; |
|
| 1173 | - break; |
|
| 1174 | - } |
|
| 1175 | - $product_data[$attribute->attribute_code] = $value; |
|
| 1176 | - |
|
| 1177 | - if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1178 | - $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1179 | - if (!empty($meta)) { |
|
| 1180 | - $product_meta[$attribute->attribute_code] = $meta; |
|
| 1181 | - } |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1185 | - $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1186 | - } |
|
| 1187 | - if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1188 | - $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - } else { |
|
| 1192 | - |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - /** Get datas about product options */ |
|
| 1196 | - if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1197 | - $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1198 | - |
|
| 1199 | - foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1200 | - $variation_id = $attribute_value; |
|
| 1201 | - $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1202 | - |
|
| 1203 | - $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)); |
|
| 1204 | - $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1205 | - switch ($attribute_definition->backend_input) { |
|
| 1206 | - case 'select': |
|
| 1207 | - case 'multiple-select': |
|
| 1208 | - case 'radio': |
|
| 1209 | - case 'checkbox': |
|
| 1210 | - $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1211 | - break; |
|
| 1212 | - } |
|
| 1213 | - $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1214 | - $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1219 | - |
|
| 1220 | - /** Get the display definition for the current product for checking custom display */ |
|
| 1221 | - $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1222 | - } |
|
| 1131 | + $product = $wpdb->get_row($query); |
|
| 1223 | 1132 | |
| 1224 | - return $product_data; |
|
| 1225 | - } |
|
| 1133 | + $product_data = array(); |
|
| 1134 | + $product_meta = array(); |
|
| 1226 | 1135 | |
| 1227 | - /** |
|
| 1228 | - * Add a product into the db. This function is used for the EDI |
|
| 1229 | - * @param $name Name of the product |
|
| 1230 | - * @param $description Description of the product |
|
| 1231 | - * @param $attrs List of the attributes and values of the product |
|
| 1232 | - * @return boolean |
|
| 1233 | - */ |
|
| 1234 | - public function addProduct($name, $description, $attrs = array()) |
|
| 1235 | - { |
|
| 1236 | - $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1237 | - return $new_product[0]; |
|
| 1238 | - } |
|
| 1136 | + if (!empty($product)) { |
|
| 1137 | + $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1138 | + $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1139 | + $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1140 | + $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1239 | 1141 | |
| 1240 | - /** |
|
| 1241 | - * Retrieve a product listing |
|
| 1242 | - * @param boolean $formated If the output have to be formated or not |
|
| 1243 | - * @param string $product_search Optionnal Define a search term for request |
|
| 1244 | - * @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 |
|
| 1245 | - */ |
|
| 1246 | - public static function product_list($formated = false, $product_search = null) |
|
| 1247 | - { |
|
| 1248 | - global $wpdb; |
|
| 1249 | - |
|
| 1250 | - $query_extra_params = $query_extra_params_value = ''; |
|
| 1251 | - if (!empty($product_search)) { |
|
| 1252 | - $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1253 | - if (is_array($product_search)) { |
|
| 1254 | - $query_extra_params = " AND ID IN (%s)"; |
|
| 1255 | - $query_extra_params_value = implode(",", $product_search); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1142 | + $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1143 | + $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1144 | + $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1145 | + $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1146 | + |
|
| 1147 | + $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1148 | + |
|
| 1149 | + $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); |
|
| 1150 | + if (!empty($data)) { |
|
| 1151 | + foreach ($data as $attribute) { |
|
| 1152 | + $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1153 | + $value = $attribute->$data_type; |
|
| 1154 | + if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1155 | + $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + /** Special traitment regarding attribute_code */ |
|
| 1159 | + switch ($attribute->attribute_code) { |
|
| 1160 | + case 'product_weight': |
|
| 1161 | + $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1162 | + if (!empty($default_weight_unity)) { |
|
| 1163 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1164 | + $unity = $wpdb->get_var($query); |
|
| 1165 | + if ($unity == 'kg') { |
|
| 1166 | + $value *= 1000; |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + } |
|
| 1170 | + break; |
|
| 1171 | + default: |
|
| 1172 | + $value = !empty($value) ? $value : 0; |
|
| 1173 | + break; |
|
| 1174 | + } |
|
| 1175 | + $product_data[$attribute->attribute_code] = $value; |
|
| 1176 | + |
|
| 1177 | + if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1178 | + $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1179 | + if (!empty($meta)) { |
|
| 1180 | + $product_meta[$attribute->attribute_code] = $meta; |
|
| 1181 | + } |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1185 | + $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1186 | + } |
|
| 1187 | + if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1188 | + $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + } else { |
|
| 1192 | + |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + /** Get datas about product options */ |
|
| 1196 | + if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1197 | + $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1198 | + |
|
| 1199 | + foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1200 | + $variation_id = $attribute_value; |
|
| 1201 | + $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1202 | + |
|
| 1203 | + $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)); |
|
| 1204 | + $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1205 | + switch ($attribute_definition->backend_input) { |
|
| 1206 | + case 'select': |
|
| 1207 | + case 'multiple-select': |
|
| 1208 | + case 'radio': |
|
| 1209 | + case 'checkbox': |
|
| 1210 | + $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1211 | + break; |
|
| 1212 | + } |
|
| 1213 | + $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1214 | + $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1219 | + |
|
| 1220 | + /** Get the display definition for the current product for checking custom display */ |
|
| 1221 | + $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + return $product_data; |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Add a product into the db. This function is used for the EDI |
|
| 1229 | + * @param $name Name of the product |
|
| 1230 | + * @param $description Description of the product |
|
| 1231 | + * @param $attrs List of the attributes and values of the product |
|
| 1232 | + * @return boolean |
|
| 1233 | + */ |
|
| 1234 | + public function addProduct($name, $description, $attrs = array()) |
|
| 1235 | + { |
|
| 1236 | + $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1237 | + return $new_product[0]; |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * Retrieve a product listing |
|
| 1242 | + * @param boolean $formated If the output have to be formated or not |
|
| 1243 | + * @param string $product_search Optionnal Define a search term for request |
|
| 1244 | + * @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 |
|
| 1245 | + */ |
|
| 1246 | + public static function product_list($formated = false, $product_search = null) |
|
| 1247 | + { |
|
| 1248 | + global $wpdb; |
|
| 1249 | + |
|
| 1250 | + $query_extra_params = $query_extra_params_value = ''; |
|
| 1251 | + if (!empty($product_search)) { |
|
| 1252 | + $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1253 | + if (is_array($product_search)) { |
|
| 1254 | + $query_extra_params = " AND ID IN (%s)"; |
|
| 1255 | + $query_extra_params_value = implode(",", $product_search); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | - $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); |
|
| 1260 | - $data = $wpdb->get_results($query); |
|
| 1259 | + $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); |
|
| 1260 | + $data = $wpdb->get_results($query); |
|
| 1261 | 1261 | |
| 1262 | - /* |
|
| 1262 | + /* |
|
| 1263 | 1263 | * Make some arangement on output if parameter is given |
| 1264 | 1264 | */ |
| 1265 | - if ($formated) { |
|
| 1266 | - $product_string = ''; |
|
| 1267 | - foreach ($data as $d) { |
|
| 1268 | - $product_string .= ' |
|
| 1265 | + if ($formated) { |
|
| 1266 | + $product_string = ''; |
|
| 1267 | + foreach ($data as $d) { |
|
| 1268 | + $product_string .= ' |
|
| 1269 | 1269 | <li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" > |
| 1270 | 1270 | <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> |
| 1271 | 1271 | </li>'; |
| 1272 | - } |
|
| 1273 | - } |
|
| 1272 | + } |
|
| 1273 | + } |
|
| 1274 | 1274 | |
| 1275 | - return $formated ? $product_string : $data; |
|
| 1276 | - } |
|
| 1275 | + return $formated ? $product_string : $data; |
|
| 1276 | + } |
|
| 1277 | 1277 | |
| 1278 | - /** |
|
| 1279 | - * Enregistrement des données pour le produit |
|
| 1280 | - */ |
|
| 1281 | - public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1282 | - { |
|
| 1283 | - global $wpdb; |
|
| 1284 | - |
|
| 1285 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1286 | - // Apply a filter to extra actions |
|
| 1287 | - $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1288 | - |
|
| 1289 | - 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"))) { |
|
| 1290 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1291 | - /* Fill the product reference automatically if nothing is sent */ |
|
| 1292 | - if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1293 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1294 | - $last_ref = $wpdb->get_var($query); |
|
| 1295 | - $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; |
|
| 1296 | - } else { |
|
| 1297 | - /* Check if the product reference existing in the database */ |
|
| 1298 | - $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1299 | - $query = $wpdb->prepare( |
|
| 1300 | - "SELECT value_id |
|
| 1278 | + /** |
|
| 1279 | + * Enregistrement des données pour le produit |
|
| 1280 | + */ |
|
| 1281 | + public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1282 | + { |
|
| 1283 | + global $wpdb; |
|
| 1284 | + |
|
| 1285 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1286 | + // Apply a filter to extra actions |
|
| 1287 | + $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1288 | + |
|
| 1289 | + 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"))) { |
|
| 1290 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1291 | + /* Fill the product reference automatically if nothing is sent */ |
|
| 1292 | + if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1293 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1294 | + $last_ref = $wpdb->get_var($query); |
|
| 1295 | + $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; |
|
| 1296 | + } else { |
|
| 1297 | + /* Check if the product reference existing in the database */ |
|
| 1298 | + $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1299 | + $query = $wpdb->prepare( |
|
| 1300 | + "SELECT value_id |
|
| 1301 | 1301 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
| 1302 | 1302 | INNER JOIN {$wpdb->posts} ON ( ID = entity_id ) |
| 1303 | 1303 | WHERE value = %s |
| 1304 | 1304 | AND entity_id != %d |
| 1305 | 1305 | AND entity_type_id = %d" |
| 1306 | - , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1307 | - $existing_reference = $wpdb->get_var($query); |
|
| 1308 | - |
|
| 1309 | - /* If this product reference exist -> Create a new product reference */ |
|
| 1310 | - if ($wpdb->num_rows > 0) { |
|
| 1311 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1312 | - $last_ref = $wpdb->get_var($query); |
|
| 1313 | - $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; |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /* Save the attributes values into wpshop eav database */ |
|
| 1318 | - $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1319 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1320 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1321 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1322 | - $lang = $wpdb->get_var($query); |
|
| 1323 | - } |
|
| 1324 | - 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); |
|
| 1325 | - |
|
| 1326 | - /* Update product price looking for shop parameters */ |
|
| 1327 | - wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1328 | - |
|
| 1329 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1330 | - $productMetaDatas = array(); |
|
| 1331 | - foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1332 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1333 | - if ($attributeCode == 'product_attribute_set_id') { |
|
| 1334 | - /* Update the attribute set id for the current product */ |
|
| 1335 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1336 | - } |
|
| 1337 | - if ($attributeType == 'decimal') { |
|
| 1338 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1339 | - } |
|
| 1340 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1341 | - $attributeValue = (int) $attributeValue; |
|
| 1342 | - } |
|
| 1343 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1344 | - } |
|
| 1345 | - } |
|
| 1346 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1350 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1351 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1352 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1356 | - if (empty($product['product_id'])) { |
|
| 1357 | - $product['product_id'] = $data_to_save['post_ID']; |
|
| 1358 | - } |
|
| 1359 | - $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1360 | - update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1361 | - |
|
| 1362 | - /** Save product variation */ |
|
| 1363 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1364 | - foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1365 | - |
|
| 1366 | - foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1367 | - $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1368 | - 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])) { |
|
| 1369 | - $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; |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1373 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1374 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1375 | - $lang = $wpdb->get_var($query); |
|
| 1376 | - } |
|
| 1377 | - wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1378 | - |
|
| 1379 | - /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1380 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1381 | - if (!empty($variation_metadata)) { |
|
| 1382 | - $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1383 | - if (!empty($attributes_list)) { |
|
| 1384 | - foreach ($attributes_list as $attribute) { |
|
| 1385 | - $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1386 | - $attributeValue = $attribute->$value_key; |
|
| 1387 | - if ($attribute->data_type == 'decimal') { |
|
| 1388 | - $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1389 | - } |
|
| 1390 | - if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1391 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1392 | - } |
|
| 1393 | - $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1399 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1400 | - if ($attributeType == 'decimal') { |
|
| 1401 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1402 | - } |
|
| 1403 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1404 | - $attributeValue = (int) $attributeValue; |
|
| 1405 | - } |
|
| 1406 | - $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1407 | - } |
|
| 1408 | - } |
|
| 1409 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1410 | - |
|
| 1411 | - /** Save attached picture id **/ |
|
| 1412 | - $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']) : ''; |
|
| 1413 | - $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1414 | - |
|
| 1415 | - /* Update product price looking for shop parameters */ |
|
| 1416 | - wpshop_products::calculate_price($variation_id); |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - /* Update the related products list*/ |
|
| 1421 | - if (!empty($data_to_save['related_products_list'])) { |
|
| 1422 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1423 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1424 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1425 | - } |
|
| 1426 | - /* Update the provider list*/ |
|
| 1427 | - if (!empty($data_to_save['provider_list'])) { |
|
| 1428 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1429 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1430 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - /* Update product options */ |
|
| 1434 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1435 | - update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1436 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1437 | - delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1438 | - } |
|
| 1439 | - |
|
| 1440 | - /** Add flag on variations to check which type of variation **/ |
|
| 1441 | - $check_product_have_variations = self::get_variation($post_id); |
|
| 1442 | - if (!empty($check_product_have_variations)) { |
|
| 1443 | - $variation_flag = self::check_variation_type($post_id); |
|
| 1444 | - $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1445 | - $variation_defining['variation_type'] = $variation_flag; |
|
| 1446 | - update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1447 | - } |
|
| 1448 | - 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); |
|
| 1449 | - } |
|
| 1306 | + , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1307 | + $existing_reference = $wpdb->get_var($query); |
|
| 1308 | + |
|
| 1309 | + /* If this product reference exist -> Create a new product reference */ |
|
| 1310 | + if ($wpdb->num_rows > 0) { |
|
| 1311 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1312 | + $last_ref = $wpdb->get_var($query); |
|
| 1313 | + $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; |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1450 | 1316 | |
| 1451 | - flush_rewrite_rules(); |
|
| 1452 | - } |
|
| 1317 | + /* Save the attributes values into wpshop eav database */ |
|
| 1318 | + $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1319 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1320 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1321 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1322 | + $lang = $wpdb->get_var($query); |
|
| 1323 | + } |
|
| 1324 | + 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); |
|
| 1325 | + |
|
| 1326 | + /* Update product price looking for shop parameters */ |
|
| 1327 | + wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1328 | + |
|
| 1329 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1330 | + $productMetaDatas = array(); |
|
| 1331 | + foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1332 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1333 | + if ($attributeCode == 'product_attribute_set_id') { |
|
| 1334 | + /* Update the attribute set id for the current product */ |
|
| 1335 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1336 | + } |
|
| 1337 | + if ($attributeType == 'decimal') { |
|
| 1338 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1339 | + } |
|
| 1340 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1341 | + $attributeValue = (int) $attributeValue; |
|
| 1342 | + } |
|
| 1343 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1344 | + } |
|
| 1345 | + } |
|
| 1346 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1347 | + } |
|
| 1453 | 1348 | |
| 1454 | - /** |
|
| 1455 | - * Return the variation type |
|
| 1456 | - * @param integer $post_id |
|
| 1457 | - * @return string |
|
| 1458 | - */ |
|
| 1459 | - public function check_variation_type($post_id) |
|
| 1460 | - { |
|
| 1461 | - $variation_type = 'single'; |
|
| 1462 | - if (!empty($variation_type)) { |
|
| 1463 | - $variations = self::get_variation($post_id); |
|
| 1464 | - if (!empty($variations)) { |
|
| 1465 | - foreach ($variations as $variation_id => $variation_data) { |
|
| 1466 | - if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1467 | - return 'single'; |
|
| 1468 | - } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1469 | - $variation_type = 'combined'; |
|
| 1470 | - } |
|
| 1471 | - } |
|
| 1472 | - } |
|
| 1473 | - } |
|
| 1474 | - return $variation_type; |
|
| 1475 | - } |
|
| 1349 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1350 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1351 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1352 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1353 | + } |
|
| 1476 | 1354 | |
| 1477 | - /** |
|
| 1478 | - * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1479 | - * |
|
| 1480 | - * @param mixed $permalink The actual permalink of the element |
|
| 1481 | - * @param object $post The post we want to set the permalink for |
|
| 1482 | - * @param void |
|
| 1483 | - * |
|
| 1484 | - * @return mixed The new permalink for the current element |
|
| 1485 | - */ |
|
| 1486 | - public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1487 | - { |
|
| 1488 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1489 | - |
|
| 1490 | - if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1491 | - if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1492 | - return $permalink; |
|
| 1493 | - } else { |
|
| 1494 | - $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1495 | - $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1496 | - if (empty($product_categories)) { |
|
| 1497 | - $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1498 | - } else { |
|
| 1499 | - $product_category_slug = $product_categories[0]->slug; |
|
| 1500 | - } |
|
| 1501 | - $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1502 | - } |
|
| 1503 | - } |
|
| 1355 | + $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1356 | + if (empty($product['product_id'])) { |
|
| 1357 | + $product['product_id'] = $data_to_save['post_ID']; |
|
| 1358 | + } |
|
| 1359 | + $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1360 | + update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1361 | + |
|
| 1362 | + /** Save product variation */ |
|
| 1363 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1364 | + foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1365 | + |
|
| 1366 | + foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1367 | + $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1368 | + 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])) { |
|
| 1369 | + $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; |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1373 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1374 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1375 | + $lang = $wpdb->get_var($query); |
|
| 1376 | + } |
|
| 1377 | + wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1378 | + |
|
| 1379 | + /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1380 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1381 | + if (!empty($variation_metadata)) { |
|
| 1382 | + $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1383 | + if (!empty($attributes_list)) { |
|
| 1384 | + foreach ($attributes_list as $attribute) { |
|
| 1385 | + $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1386 | + $attributeValue = $attribute->$value_key; |
|
| 1387 | + if ($attribute->data_type == 'decimal') { |
|
| 1388 | + $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1389 | + } |
|
| 1390 | + if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1391 | + $attributeValue = (int) $attribute->$value_key; |
|
| 1392 | + } |
|
| 1393 | + $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1504 | 1397 | |
| 1505 | - return $permalink; |
|
| 1398 | + foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1399 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1400 | + if ($attributeType == 'decimal') { |
|
| 1401 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1402 | + } |
|
| 1403 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1404 | + $attributeValue = (int) $attributeValue; |
|
| 1405 | + } |
|
| 1406 | + $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1407 | + } |
|
| 1408 | + } |
|
| 1409 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1506 | 1410 | |
| 1507 | - //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1411 | + /** Save attached picture id **/ |
|
| 1412 | + $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']) : ''; |
|
| 1413 | + $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1508 | 1414 | |
| 1509 | - //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1415 | + /* Update product price looking for shop parameters */ |
|
| 1416 | + wpshop_products::calculate_price($variation_id); |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1510 | 1419 | |
| 1511 | - /*if(false) { |
|
| 1512 | - global $wp_query; |
|
| 1513 | - $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES ); |
|
| 1420 | + /* Update the related products list*/ |
|
| 1421 | + if (!empty($data_to_save['related_products_list'])) { |
|
| 1422 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1423 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1424 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1425 | + } |
|
| 1426 | + /* Update the provider list*/ |
|
| 1427 | + if (!empty($data_to_save['provider_list'])) { |
|
| 1428 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1429 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1430 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + /* Update product options */ |
|
| 1434 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1435 | + update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1436 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1437 | + delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1438 | + } |
|
| 1439 | + |
|
| 1440 | + /** Add flag on variations to check which type of variation **/ |
|
| 1441 | + $check_product_have_variations = self::get_variation($post_id); |
|
| 1442 | + if (!empty($check_product_have_variations)) { |
|
| 1443 | + $variation_flag = self::check_variation_type($post_id); |
|
| 1444 | + $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1445 | + $variation_defining['variation_type'] = $variation_flag; |
|
| 1446 | + update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1447 | + } |
|
| 1448 | + 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); |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + flush_rewrite_rules(); |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + /** |
|
| 1455 | + * Return the variation type |
|
| 1456 | + * @param integer $post_id |
|
| 1457 | + * @return string |
|
| 1458 | + */ |
|
| 1459 | + public function check_variation_type($post_id) |
|
| 1460 | + { |
|
| 1461 | + $variation_type = 'single'; |
|
| 1462 | + if (!empty($variation_type)) { |
|
| 1463 | + $variations = self::get_variation($post_id); |
|
| 1464 | + if (!empty($variations)) { |
|
| 1465 | + foreach ($variations as $variation_id => $variation_data) { |
|
| 1466 | + if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1467 | + return 'single'; |
|
| 1468 | + } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1469 | + $variation_type = 'combined'; |
|
| 1470 | + } |
|
| 1471 | + } |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + return $variation_type; |
|
| 1475 | + } |
|
| 1476 | + |
|
| 1477 | + /** |
|
| 1478 | + * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1479 | + * |
|
| 1480 | + * @param mixed $permalink The actual permalink of the element |
|
| 1481 | + * @param object $post The post we want to set the permalink for |
|
| 1482 | + * @param void |
|
| 1483 | + * |
|
| 1484 | + * @return mixed The new permalink for the current element |
|
| 1485 | + */ |
|
| 1486 | + public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1487 | + { |
|
| 1488 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1489 | + |
|
| 1490 | + if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1491 | + if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1492 | + return $permalink; |
|
| 1493 | + } else { |
|
| 1494 | + $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1495 | + $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1496 | + if (empty($product_categories)) { |
|
| 1497 | + $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1498 | + } else { |
|
| 1499 | + $product_category_slug = $product_categories[0]->slug; |
|
| 1500 | + } |
|
| 1501 | + $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1502 | + } |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + return $permalink; |
|
| 1506 | + |
|
| 1507 | + //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1508 | + |
|
| 1509 | + //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1510 | + |
|
| 1511 | + /*if(false) { |
|
| 1512 | + global $wp_query; |
|
| 1513 | + $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES ); |
|
| 1514 | 1514 | |
| 1515 | 1515 | if(count($product_categories) == 0){ /* Product has only one category we get the only available slug */ |
| 1516 | - /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1516 | + /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1517 | 1517 | } |
| 1518 | 1518 | elseif(count($product_categories) == 1){ /* Product has only one category we get the only available slug */ |
| 1519 | - /* $product_category_slug = $product_categories[0]->slug; |
|
| 1519 | + /* $product_category_slug = $product_categories[0]->slug; |
|
| 1520 | 1520 | } |
| 1521 | 1521 | else{ /* Product has several categories choose the slug of the we want */ |
| 1522 | - /* $product_category_slugs = array(); |
|
| 1522 | + /* $product_category_slugs = array(); |
|
| 1523 | 1523 | foreach($product_categories as $product_category){ |
| 1524 | 1524 | $product_category_slugs[] = $product_category->slug; |
| 1525 | 1525 | } |
@@ -1529,457 +1529,457 @@ discard block |
||
| 1529 | 1529 | $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
| 1530 | 1530 | return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID ); |
| 1531 | 1531 | }*/ |
| 1532 | - } |
|
| 1532 | + } |
|
| 1533 | 1533 | |
| 1534 | - public static function set_product_request_by_name($query) |
|
| 1535 | - { |
|
| 1536 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1534 | + public static function set_product_request_by_name($query) |
|
| 1535 | + { |
|
| 1536 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1537 | 1537 | |
| 1538 | - if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1539 | - // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1540 | - } |
|
| 1538 | + if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1539 | + // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1540 | + } |
|
| 1541 | 1541 | |
| 1542 | - /** |
|
| 1543 | - * Define output for product |
|
| 1544 | - * |
|
| 1545 | - * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1546 | - * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1547 | - * |
|
| 1548 | - * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1549 | - */ |
|
| 1550 | - public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1551 | - { |
|
| 1552 | - $content = $attributeContentOutput = ''; |
|
| 1553 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1554 | - /** Log number of view for the current product */ |
|
| 1555 | - $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1556 | - $product_view_number++; |
|
| 1557 | - update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1558 | - |
|
| 1559 | - /** Get product definition */ |
|
| 1560 | - |
|
| 1561 | - $product = self::get_product_data($product_id); |
|
| 1562 | - wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1563 | - |
|
| 1564 | - /** Get the product thumbnail */ |
|
| 1565 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1566 | - if (has_post_thumbnail($product_id)) { |
|
| 1567 | - $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1568 | - $tpl_component = array(); |
|
| 1569 | - $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1570 | - $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1571 | - $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1572 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1573 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1574 | - foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1575 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1576 | - $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; |
|
| 1577 | - } |
|
| 1578 | - } |
|
| 1579 | - $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; |
|
| 1580 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1581 | - unset($tpl_component); |
|
| 1582 | - } |
|
| 1542 | + /** |
|
| 1543 | + * Define output for product |
|
| 1544 | + * |
|
| 1545 | + * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1546 | + * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1547 | + * |
|
| 1548 | + * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1549 | + */ |
|
| 1550 | + public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1551 | + { |
|
| 1552 | + $content = $attributeContentOutput = ''; |
|
| 1553 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1554 | + /** Log number of view for the current product */ |
|
| 1555 | + $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1556 | + $product_view_number++; |
|
| 1557 | + update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1558 | + |
|
| 1559 | + /** Get product definition */ |
|
| 1560 | + |
|
| 1561 | + $product = self::get_product_data($product_id); |
|
| 1562 | + wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1563 | + |
|
| 1564 | + /** Get the product thumbnail */ |
|
| 1565 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1566 | + if (has_post_thumbnail($product_id)) { |
|
| 1567 | + $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1568 | + $tpl_component = array(); |
|
| 1569 | + $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1570 | + $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1571 | + $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1572 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1573 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1574 | + foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1575 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1576 | + $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; |
|
| 1577 | + } |
|
| 1578 | + } |
|
| 1579 | + $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; |
|
| 1580 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1581 | + unset($tpl_component); |
|
| 1582 | + } |
|
| 1583 | 1583 | |
| 1584 | - $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1585 | - |
|
| 1586 | - /** Retrieve product attributes for output */ |
|
| 1587 | - $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1588 | - |
|
| 1589 | - /** Retrieve product price */ |
|
| 1590 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1591 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1592 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1593 | - $productPrice = ''; |
|
| 1594 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1595 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1596 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1597 | - 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)) { |
|
| 1598 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1599 | - } |
|
| 1584 | + $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1585 | + |
|
| 1586 | + /** Retrieve product attributes for output */ |
|
| 1587 | + $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1588 | + |
|
| 1589 | + /** Retrieve product price */ |
|
| 1590 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1591 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1592 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1593 | + $productPrice = ''; |
|
| 1594 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1595 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1596 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1597 | + 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)) { |
|
| 1598 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1599 | + } |
|
| 1600 | 1600 | |
| 1601 | - /** Check if there is at less 1 product in stock */ |
|
| 1602 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1603 | - $productStock = ($productStock === true) ? 1 : null; |
|
| 1601 | + /** Check if there is at less 1 product in stock */ |
|
| 1602 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1603 | + $productStock = ($productStock === true) ? 1 : null; |
|
| 1604 | 1604 | |
| 1605 | - /** if !product stock check product have variation with stock **/ |
|
| 1605 | + /** if !product stock check product have variation with stock **/ |
|
| 1606 | 1606 | // if ( empty($productStock) ) { |
| 1607 | - $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1608 | - if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1609 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1610 | - if (!empty($variations)) { |
|
| 1611 | - foreach ($variations as $variation) { |
|
| 1612 | - if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1613 | - $productStock = 1; |
|
| 1614 | - } |
|
| 1615 | - } |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1607 | + $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1608 | + if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1609 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1610 | + if (!empty($variations)) { |
|
| 1611 | + foreach ($variations as $variation) { |
|
| 1612 | + if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1613 | + $productStock = 1; |
|
| 1614 | + } |
|
| 1615 | + } |
|
| 1616 | + } |
|
| 1617 | + } |
|
| 1618 | 1618 | // } |
| 1619 | 1619 | |
| 1620 | - /** Define "Add to cart" button */ |
|
| 1621 | - $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'); |
|
| 1622 | - $display_price_state_when_price_is_empty = true; |
|
| 1623 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1624 | - $display_price_state_when_price_is_empty = false; |
|
| 1625 | - } else if (!empty($productPrice)) { |
|
| 1626 | - $display_price_state_when_price_is_empty = true; |
|
| 1627 | - } |
|
| 1628 | - $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') : ''; |
|
| 1629 | - $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)) : ''; |
|
| 1630 | - |
|
| 1631 | - /** Define "Ask a quotation" button */ |
|
| 1632 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1633 | - |
|
| 1634 | - /** Template parameters */ |
|
| 1635 | - $template_part = 'product_complete_tpl'; |
|
| 1636 | - $tpl_component = array(); |
|
| 1637 | - |
|
| 1638 | - $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1639 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1640 | - $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1641 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1642 | - $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1643 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1644 | - $modules_option = get_option('wpshop_modules'); |
|
| 1645 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1646 | - if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1647 | - $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1648 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1649 | - } |
|
| 1620 | + /** Define "Add to cart" button */ |
|
| 1621 | + $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'); |
|
| 1622 | + $display_price_state_when_price_is_empty = true; |
|
| 1623 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1624 | + $display_price_state_when_price_is_empty = false; |
|
| 1625 | + } else if (!empty($productPrice)) { |
|
| 1626 | + $display_price_state_when_price_is_empty = true; |
|
| 1627 | + } |
|
| 1628 | + $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') : ''; |
|
| 1629 | + $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)) : ''; |
|
| 1630 | + |
|
| 1631 | + /** Define "Ask a quotation" button */ |
|
| 1632 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1633 | + |
|
| 1634 | + /** Template parameters */ |
|
| 1635 | + $template_part = 'product_complete_tpl'; |
|
| 1636 | + $tpl_component = array(); |
|
| 1637 | + |
|
| 1638 | + $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1639 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1640 | + $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1641 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1642 | + $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1643 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1644 | + $modules_option = get_option('wpshop_modules'); |
|
| 1645 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1646 | + if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1647 | + $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1648 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1649 | + } |
|
| 1650 | 1650 | |
| 1651 | - /** Gallery **/ |
|
| 1652 | - $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1653 | - |
|
| 1654 | - $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'] : '')); |
|
| 1655 | - |
|
| 1656 | - $product_new = $product_new_def['output']; |
|
| 1657 | - $product_class = $product_new_def['class']; |
|
| 1658 | - |
|
| 1659 | - $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'] : '')); |
|
| 1660 | - $product_featured = $product_featured_def['output']; |
|
| 1661 | - $product_class .= $product_featured_def['class']; |
|
| 1662 | - |
|
| 1663 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1664 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1665 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1666 | - |
|
| 1667 | - $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1668 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1669 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1670 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1671 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1672 | - $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1673 | - $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1674 | - $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1675 | - |
|
| 1676 | - /** Build template */ |
|
| 1677 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1678 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1679 | - /* Include the old way template part */ |
|
| 1680 | - ob_start(); |
|
| 1681 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1682 | - $content = ob_get_contents(); |
|
| 1683 | - ob_end_clean(); |
|
| 1684 | - } else { |
|
| 1685 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1686 | - } |
|
| 1687 | - unset($tpl_component); |
|
| 1688 | - return $content; |
|
| 1689 | - } |
|
| 1651 | + /** Gallery **/ |
|
| 1652 | + $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1653 | + |
|
| 1654 | + $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'] : '')); |
|
| 1655 | + |
|
| 1656 | + $product_new = $product_new_def['output']; |
|
| 1657 | + $product_class = $product_new_def['class']; |
|
| 1658 | + |
|
| 1659 | + $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'] : '')); |
|
| 1660 | + $product_featured = $product_featured_def['output']; |
|
| 1661 | + $product_class .= $product_featured_def['class']; |
|
| 1662 | + |
|
| 1663 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1664 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1665 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1666 | + |
|
| 1667 | + $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1668 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1669 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1670 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1671 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1672 | + $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1673 | + $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1674 | + $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1675 | + |
|
| 1676 | + /** Build template */ |
|
| 1677 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1678 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1679 | + /* Include the old way template part */ |
|
| 1680 | + ob_start(); |
|
| 1681 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1682 | + $content = ob_get_contents(); |
|
| 1683 | + ob_end_clean(); |
|
| 1684 | + } else { |
|
| 1685 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1686 | + } |
|
| 1687 | + unset($tpl_component); |
|
| 1688 | + return $content; |
|
| 1689 | + } |
|
| 1690 | 1690 | |
| 1691 | - 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) |
|
| 1692 | - { |
|
| 1693 | - $content = ''; |
|
| 1694 | - $product_information = $product_class = ''; |
|
| 1691 | + 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) |
|
| 1692 | + { |
|
| 1693 | + $content = ''; |
|
| 1694 | + $product_information = $product_class = ''; |
|
| 1695 | 1695 | |
| 1696 | - /** Get the product thumbnail */ |
|
| 1697 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1698 | - if (has_post_thumbnail($product_id)) { |
|
| 1699 | - $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1700 | - } |
|
| 1696 | + /** Get the product thumbnail */ |
|
| 1697 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1698 | + if (has_post_thumbnail($product_id)) { |
|
| 1699 | + $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1700 | + } |
|
| 1701 | 1701 | |
| 1702 | - $product = self::get_product_data($product_id); |
|
| 1702 | + $product = self::get_product_data($product_id); |
|
| 1703 | 1703 | |
| 1704 | - /** Get the product information for output */ |
|
| 1705 | - if (!empty($product)) { |
|
| 1704 | + /** Get the product information for output */ |
|
| 1705 | + if (!empty($product)) { |
|
| 1706 | 1706 | |
| 1707 | - $product_title = $product['post_title']; |
|
| 1708 | - $product_name = $product['post_name']; |
|
| 1709 | - $product_link = get_permalink($product_id); |
|
| 1710 | - $product_more_informations = $product['product_content']; |
|
| 1711 | - $product_excerpt = $product['product_excerpt']; |
|
| 1707 | + $product_title = $product['post_title']; |
|
| 1708 | + $product_name = $product['post_name']; |
|
| 1709 | + $product_link = get_permalink($product_id); |
|
| 1710 | + $product_more_informations = $product['product_content']; |
|
| 1711 | + $product_excerpt = $product['product_excerpt']; |
|
| 1712 | 1712 | |
| 1713 | - if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1714 | - $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1715 | - $product_more_informations = $post_content[0]; |
|
| 1716 | - } |
|
| 1713 | + if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1714 | + $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1715 | + $product_more_informations = $post_content[0]; |
|
| 1716 | + } |
|
| 1717 | 1717 | |
| 1718 | - } else { |
|
| 1719 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1720 | - $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1721 | - $product_link = ''; |
|
| 1722 | - $product_more_informations = ''; |
|
| 1723 | - $product_excerpt = ''; |
|
| 1724 | - } |
|
| 1718 | + } else { |
|
| 1719 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1720 | + $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1721 | + $product_link = ''; |
|
| 1722 | + $product_more_informations = ''; |
|
| 1723 | + $product_excerpt = ''; |
|
| 1724 | + } |
|
| 1725 | 1725 | |
| 1726 | - /** Retrieve product price */ |
|
| 1727 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1728 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1729 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1730 | - $productPrice = ''; |
|
| 1731 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1732 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1733 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1734 | - 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)) { |
|
| 1735 | - $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1736 | - |
|
| 1737 | - if (!empty($product_price_infos)) { |
|
| 1738 | - $tpl_component_price = array(); |
|
| 1739 | - /** Price piloting **/ |
|
| 1726 | + /** Retrieve product price */ |
|
| 1727 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1728 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1729 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1730 | + $productPrice = ''; |
|
| 1731 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1732 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1733 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1734 | + 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)) { |
|
| 1735 | + $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1736 | + |
|
| 1737 | + if (!empty($product_price_infos)) { |
|
| 1738 | + $tpl_component_price = array(); |
|
| 1739 | + /** Price piloting **/ |
|
| 1740 | 1740 | $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
| 1741 | 1741 | $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
| 1742 | - $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1743 | - $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'])) : ''; |
|
| 1744 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1742 | + $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1743 | + $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'])) : ''; |
|
| 1744 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1745 | 1745 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1746 | 1746 | if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
| 1747 | 1747 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1748 | 1748 | } |
| 1749 | - $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1750 | - $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1751 | - $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1752 | - $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1753 | - } else { |
|
| 1754 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1755 | - } |
|
| 1756 | - } |
|
| 1749 | + $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1750 | + $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1751 | + $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1752 | + $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1753 | + } else { |
|
| 1754 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1755 | + } |
|
| 1756 | + } |
|
| 1757 | 1757 | |
| 1758 | - /** Check if there is at less 1 product in stock */ |
|
| 1759 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1760 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1761 | - $productStock = $productStock === true ? 1 : null; |
|
| 1762 | - |
|
| 1763 | - /** Define "Add to cart" button */ |
|
| 1764 | - $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'); |
|
| 1765 | - $display_price_state_when_price_is_empty = false; |
|
| 1766 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1767 | - $display_price_state_when_price_is_empty = false; |
|
| 1768 | - } else if (!empty($productPrice)) { |
|
| 1769 | - $display_price_state_when_price_is_empty = true; |
|
| 1770 | - } |
|
| 1771 | - $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') : ''; |
|
| 1772 | - $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)) : ''; |
|
| 1758 | + /** Check if there is at less 1 product in stock */ |
|
| 1759 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1760 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1761 | + $productStock = $productStock === true ? 1 : null; |
|
| 1762 | + |
|
| 1763 | + /** Define "Add to cart" button */ |
|
| 1764 | + $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'); |
|
| 1765 | + $display_price_state_when_price_is_empty = false; |
|
| 1766 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1767 | + $display_price_state_when_price_is_empty = false; |
|
| 1768 | + } else if (!empty($productPrice)) { |
|
| 1769 | + $display_price_state_when_price_is_empty = true; |
|
| 1770 | + } |
|
| 1771 | + $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') : ''; |
|
| 1772 | + $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)) : ''; |
|
| 1773 | 1773 | |
| 1774 | - /** Define "Ask a quotation" button */ |
|
| 1775 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1776 | - $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'] : '')); |
|
| 1774 | + /** Define "Ask a quotation" button */ |
|
| 1775 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1776 | + $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'] : '')); |
|
| 1777 | 1777 | |
| 1778 | - $product_new = $product_new_def['output']; |
|
| 1779 | - $product_class .= $product_new_def['class']; |
|
| 1778 | + $product_new = $product_new_def['output']; |
|
| 1779 | + $product_class .= $product_new_def['class']; |
|
| 1780 | 1780 | |
| 1781 | - $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'] : '')); |
|
| 1782 | - $product_featured = $product_featured_def['output']; |
|
| 1783 | - $product_class .= $product_featured_def['class']; |
|
| 1781 | + $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'] : '')); |
|
| 1782 | + $product_featured = $product_featured_def['output']; |
|
| 1783 | + $product_class .= $product_featured_def['class']; |
|
| 1784 | 1784 | |
| 1785 | - if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1786 | - $product_class .= ' wpshop_last_product_of_line'; |
|
| 1787 | - } |
|
| 1785 | + if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1786 | + $product_class .= ' wpshop_last_product_of_line'; |
|
| 1787 | + } |
|
| 1788 | 1788 | |
| 1789 | - if (!empty($product['product_id'])) { |
|
| 1790 | - /** Template parameters */ |
|
| 1791 | - $template_part = 'product_mini_' . $output_type; |
|
| 1792 | - $tpl_component = array(); |
|
| 1793 | - $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1794 | - $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1795 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1796 | - $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1797 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1798 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1799 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1800 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1801 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1802 | - $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1803 | - $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1804 | - $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1805 | - $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1806 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1807 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1808 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1809 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1810 | - |
|
| 1811 | - if (has_post_thumbnail($product_id)) { |
|
| 1812 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1813 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1814 | - $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1815 | - foreach ($existing_image_sizes as $size_name) { |
|
| 1816 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1817 | - $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; |
|
| 1818 | - } |
|
| 1819 | - } |
|
| 1820 | - } |
|
| 1821 | - |
|
| 1822 | - $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1823 | - $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1824 | - $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1825 | - |
|
| 1826 | - /** Build template */ |
|
| 1827 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1828 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1829 | - /** Include the old way template part */ |
|
| 1830 | - ob_start(); |
|
| 1831 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1832 | - $content = ob_get_contents(); |
|
| 1833 | - ob_end_clean(); |
|
| 1834 | - } else { |
|
| 1835 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1836 | - } |
|
| 1837 | - unset($tpl_component); |
|
| 1789 | + if (!empty($product['product_id'])) { |
|
| 1790 | + /** Template parameters */ |
|
| 1791 | + $template_part = 'product_mini_' . $output_type; |
|
| 1792 | + $tpl_component = array(); |
|
| 1793 | + $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1794 | + $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1795 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1796 | + $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1797 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1798 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1799 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1800 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1801 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1802 | + $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1803 | + $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1804 | + $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1805 | + $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1806 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1807 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1808 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1809 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1810 | + |
|
| 1811 | + if (has_post_thumbnail($product_id)) { |
|
| 1812 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1813 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1814 | + $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1815 | + foreach ($existing_image_sizes as $size_name) { |
|
| 1816 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1817 | + $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; |
|
| 1818 | + } |
|
| 1819 | + } |
|
| 1820 | + } |
|
| 1838 | 1821 | |
| 1839 | - } |
|
| 1822 | + $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1823 | + $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1824 | + $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1825 | + |
|
| 1826 | + /** Build template */ |
|
| 1827 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1828 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1829 | + /** Include the old way template part */ |
|
| 1830 | + ob_start(); |
|
| 1831 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1832 | + $content = ob_get_contents(); |
|
| 1833 | + ob_end_clean(); |
|
| 1834 | + } else { |
|
| 1835 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1836 | + } |
|
| 1837 | + unset($tpl_component); |
|
| 1840 | 1838 | |
| 1841 | - return $content; |
|
| 1842 | - } |
|
| 1839 | + } |
|
| 1843 | 1840 | |
| 1844 | - /** |
|
| 1845 | - * Get the products (post) of a given category |
|
| 1846 | - * |
|
| 1847 | - * @param string $category_slug The category slug we want to get the product list for |
|
| 1848 | - * |
|
| 1849 | - * @return mixed $widget_content The output for the product list |
|
| 1850 | - */ |
|
| 1851 | - public static function get_product_of_category($category_slug, $category_id) |
|
| 1852 | - { |
|
| 1853 | - global $top_categories; |
|
| 1854 | - $widget_content = ''; |
|
| 1855 | - $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1856 | - if (false == $products) { |
|
| 1857 | - $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1858 | - $products = get_posts($args); |
|
| 1859 | - wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1860 | - } |
|
| 1861 | - if (is_array($products) && (count($products) > 0)) { |
|
| 1862 | - foreach ($products as $product) { |
|
| 1863 | - if ($product->post_status == "publish") { |
|
| 1864 | - ob_start(); |
|
| 1865 | - require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1866 | - $widget_content .= ob_get_contents(); |
|
| 1867 | - ob_end_clean(); |
|
| 1868 | - } |
|
| 1869 | - } |
|
| 1870 | - } |
|
| 1841 | + return $content; |
|
| 1842 | + } |
|
| 1871 | 1843 | |
| 1872 | - echo $widget_content; |
|
| 1873 | - } |
|
| 1844 | + /** |
|
| 1845 | + * Get the products (post) of a given category |
|
| 1846 | + * |
|
| 1847 | + * @param string $category_slug The category slug we want to get the product list for |
|
| 1848 | + * |
|
| 1849 | + * @return mixed $widget_content The output for the product list |
|
| 1850 | + */ |
|
| 1851 | + public static function get_product_of_category($category_slug, $category_id) |
|
| 1852 | + { |
|
| 1853 | + global $top_categories; |
|
| 1854 | + $widget_content = ''; |
|
| 1855 | + $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1856 | + if (false == $products) { |
|
| 1857 | + $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1858 | + $products = get_posts($args); |
|
| 1859 | + wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1860 | + } |
|
| 1861 | + if (is_array($products) && (count($products) > 0)) { |
|
| 1862 | + foreach ($products as $product) { |
|
| 1863 | + if ($product->post_status == "publish") { |
|
| 1864 | + ob_start(); |
|
| 1865 | + require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1866 | + $widget_content .= ob_get_contents(); |
|
| 1867 | + ob_end_clean(); |
|
| 1868 | + } |
|
| 1869 | + } |
|
| 1870 | + } |
|
| 1871 | + |
|
| 1872 | + echo $widget_content; |
|
| 1873 | + } |
|
| 1874 | 1874 | |
| 1875 | - /** |
|
| 1876 | - * |
|
| 1877 | - * @param unknown_type $selected_product |
|
| 1878 | - * @return string |
|
| 1879 | - */ |
|
| 1880 | - public function custom_product_list($selected_product = array()) |
|
| 1881 | - { |
|
| 1882 | - global $wpdb; |
|
| 1883 | - |
|
| 1884 | - /* Start the table definition */ |
|
| 1885 | - $tableId = 'wpshop_product_list'; |
|
| 1886 | - $tableTitles = array(); |
|
| 1887 | - $tableTitles[] = ''; |
|
| 1888 | - $tableTitles[] = __('Id', 'wpshop'); |
|
| 1889 | - $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1890 | - $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1891 | - $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1892 | - $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1893 | - $tableTitles[] = __('Price', 'wpshop'); |
|
| 1894 | - $tableClasses = array(); |
|
| 1895 | - $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1896 | - $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1897 | - $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1898 | - $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1899 | - $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1900 | - $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1901 | - $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1902 | - |
|
| 1903 | - /* Get post list */ |
|
| 1904 | - $has_result = false; |
|
| 1905 | - $current_line_index = 0; |
|
| 1906 | - $posts = query_posts(array( |
|
| 1907 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1908 | - )); |
|
| 1909 | - if (!empty($posts)) { |
|
| 1910 | - $has_result = true; |
|
| 1911 | - foreach ($posts as $post) { |
|
| 1912 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1913 | - |
|
| 1914 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1915 | - |
|
| 1916 | - unset($tableRowValue); |
|
| 1917 | - $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 . '" />'); |
|
| 1918 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1919 | - $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>'); |
|
| 1920 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1921 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1922 | - $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/> |
|
| 1875 | + /** |
|
| 1876 | + * |
|
| 1877 | + * @param unknown_type $selected_product |
|
| 1878 | + * @return string |
|
| 1879 | + */ |
|
| 1880 | + public function custom_product_list($selected_product = array()) |
|
| 1881 | + { |
|
| 1882 | + global $wpdb; |
|
| 1883 | + |
|
| 1884 | + /* Start the table definition */ |
|
| 1885 | + $tableId = 'wpshop_product_list'; |
|
| 1886 | + $tableTitles = array(); |
|
| 1887 | + $tableTitles[] = ''; |
|
| 1888 | + $tableTitles[] = __('Id', 'wpshop'); |
|
| 1889 | + $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1890 | + $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1891 | + $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1892 | + $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1893 | + $tableTitles[] = __('Price', 'wpshop'); |
|
| 1894 | + $tableClasses = array(); |
|
| 1895 | + $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1896 | + $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1897 | + $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1898 | + $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1899 | + $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1900 | + $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1901 | + $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1902 | + |
|
| 1903 | + /* Get post list */ |
|
| 1904 | + $has_result = false; |
|
| 1905 | + $current_line_index = 0; |
|
| 1906 | + $posts = query_posts(array( |
|
| 1907 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1908 | + )); |
|
| 1909 | + if (!empty($posts)) { |
|
| 1910 | + $has_result = true; |
|
| 1911 | + foreach ($posts as $post) { |
|
| 1912 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1913 | + |
|
| 1914 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1915 | + |
|
| 1916 | + unset($tableRowValue); |
|
| 1917 | + $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 . '" />'); |
|
| 1918 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1919 | + $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>'); |
|
| 1920 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1921 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1922 | + $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/> |
|
| 1923 | 1923 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1924 | - $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() : '')); |
|
| 1925 | - $tableRows[] = $tableRowValue; |
|
| 1924 | + $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() : '')); |
|
| 1925 | + $tableRows[] = $tableRowValue; |
|
| 1926 | 1926 | |
| 1927 | - $current_line_index++; |
|
| 1928 | - } |
|
| 1929 | - wp_reset_query(); |
|
| 1930 | - } |
|
| 1931 | - $posts = query_posts(array( |
|
| 1932 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1933 | - )); |
|
| 1934 | - if (!empty($posts)) { |
|
| 1935 | - $has_result = true; |
|
| 1936 | - foreach ($posts as $post) { |
|
| 1937 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1938 | - |
|
| 1939 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1940 | - |
|
| 1941 | - unset($tableRowValue); |
|
| 1942 | - $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 . '" />'); |
|
| 1943 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1944 | - $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>'); |
|
| 1945 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1946 | - $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1947 | - if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1948 | - $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1949 | - $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1950 | - $option_name = $wpdb->get_var($query); |
|
| 1951 | - $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1952 | - $option_value = $wpdb->get_var($query); |
|
| 1953 | - $parent_post = $parent_product['parent_post']; |
|
| 1954 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1955 | - } else { |
|
| 1956 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1957 | - } |
|
| 1958 | - |
|
| 1959 | - $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/> |
|
| 1927 | + $current_line_index++; |
|
| 1928 | + } |
|
| 1929 | + wp_reset_query(); |
|
| 1930 | + } |
|
| 1931 | + $posts = query_posts(array( |
|
| 1932 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1933 | + )); |
|
| 1934 | + if (!empty($posts)) { |
|
| 1935 | + $has_result = true; |
|
| 1936 | + foreach ($posts as $post) { |
|
| 1937 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1938 | + |
|
| 1939 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1940 | + |
|
| 1941 | + unset($tableRowValue); |
|
| 1942 | + $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 . '" />'); |
|
| 1943 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1944 | + $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>'); |
|
| 1945 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1946 | + $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1947 | + if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1948 | + $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1949 | + $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1950 | + $option_name = $wpdb->get_var($query); |
|
| 1951 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1952 | + $option_value = $wpdb->get_var($query); |
|
| 1953 | + $parent_post = $parent_product['parent_post']; |
|
| 1954 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1955 | + } else { |
|
| 1956 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1957 | + } |
|
| 1958 | + |
|
| 1959 | + $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/> |
|
| 1960 | 1960 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1961 | - $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() : '')); |
|
| 1962 | - $tableRows[] = $tableRowValue; |
|
| 1961 | + $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() : '')); |
|
| 1962 | + $tableRows[] = $tableRowValue; |
|
| 1963 | 1963 | |
| 1964 | - $current_line_index++; |
|
| 1965 | - } |
|
| 1966 | - wp_reset_query(); |
|
| 1967 | - } |
|
| 1964 | + $current_line_index++; |
|
| 1965 | + } |
|
| 1966 | + wp_reset_query(); |
|
| 1967 | + } |
|
| 1968 | 1968 | |
| 1969 | - if (!$has_result) { |
|
| 1970 | - $tableRowsId[] = 'no_product_found'; |
|
| 1971 | - unset($tableRowValue); |
|
| 1972 | - $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1973 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1974 | - $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1975 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1976 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1977 | - $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1978 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1979 | - $tableRows[] = $tableRowValue; |
|
| 1980 | - } |
|
| 1969 | + if (!$has_result) { |
|
| 1970 | + $tableRowsId[] = 'no_product_found'; |
|
| 1971 | + unset($tableRowValue); |
|
| 1972 | + $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1973 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1974 | + $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1975 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1976 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1977 | + $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1978 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1979 | + $tableRows[] = $tableRowValue; |
|
| 1980 | + } |
|
| 1981 | 1981 | |
| 1982 | - return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1982 | + return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1983 | 1983 | <script type="text/javascript" > |
| 1984 | 1984 | wpshop(document).ready(function(){ |
| 1985 | 1985 | jQuery("#' . $tableId . '").dataTable( { |
@@ -1988,1533 +1988,1533 @@ discard block |
||
| 1988 | 1988 | }); |
| 1989 | 1989 | }); |
| 1990 | 1990 | </script>'; |
| 1991 | - } |
|
| 1991 | + } |
|
| 1992 | 1992 | |
| 1993 | - /** |
|
| 1994 | - * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1995 | - * |
|
| 1996 | - * @param string $special The type of special type we want to output |
|
| 1997 | - * @param string $output_type The current display type (used for product listing) |
|
| 1998 | - * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 1999 | - * @param datetime $special_state_start The start date if applicable for the special state |
|
| 2000 | - * @param datetime $special_state_end The end date if applicable for the special state |
|
| 2001 | - * |
|
| 2002 | - * @return array $product_special_state The product special state |
|
| 2003 | - */ |
|
| 2004 | - public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 2005 | - { |
|
| 2006 | - $product_special_state = array(); |
|
| 2007 | - $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 2008 | - |
|
| 2009 | - /** Get product special state definition */ |
|
| 2010 | - $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 2011 | - $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 2012 | - $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 2013 | - |
|
| 2014 | - /** Get current time */ |
|
| 2015 | - $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 2016 | - |
|
| 2017 | - /** PRODUCT MARK AS NEW */ |
|
| 2018 | - $show_product_special_state = false; |
|
| 2019 | - if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 2020 | - (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 2021 | - (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 2022 | - $show_product_special_state = true; |
|
| 2023 | - } |
|
| 1993 | + /** |
|
| 1994 | + * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1995 | + * |
|
| 1996 | + * @param string $special The type of special type we want to output |
|
| 1997 | + * @param string $output_type The current display type (used for product listing) |
|
| 1998 | + * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 1999 | + * @param datetime $special_state_start The start date if applicable for the special state |
|
| 2000 | + * @param datetime $special_state_end The end date if applicable for the special state |
|
| 2001 | + * |
|
| 2002 | + * @return array $product_special_state The product special state |
|
| 2003 | + */ |
|
| 2004 | + public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 2005 | + { |
|
| 2006 | + $product_special_state = array(); |
|
| 2007 | + $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 2008 | + |
|
| 2009 | + /** Get product special state definition */ |
|
| 2010 | + $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 2011 | + $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 2012 | + $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 2013 | + |
|
| 2014 | + /** Get current time */ |
|
| 2015 | + $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 2016 | + |
|
| 2017 | + /** PRODUCT MARK AS NEW */ |
|
| 2018 | + $show_product_special_state = false; |
|
| 2019 | + if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 2020 | + (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 2021 | + (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 2022 | + $show_product_special_state = true; |
|
| 2023 | + } |
|
| 2024 | 2024 | |
| 2025 | - if ($show_product_special_state) { |
|
| 2026 | - /** Check the type of special output needed */ |
|
| 2027 | - switch ($special) { |
|
| 2028 | - case 'declare_new': |
|
| 2029 | - $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 2030 | - $template_part = 'product_is_new_sticker'; |
|
| 2031 | - break; |
|
| 2032 | - |
|
| 2033 | - case 'highlight_product': |
|
| 2034 | - $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 2035 | - $template_part = 'product_is_featured_sticker'; |
|
| 2036 | - break; |
|
| 2037 | - } |
|
| 2038 | - |
|
| 2039 | - /** Template parameters */ |
|
| 2040 | - $tpl_component = array(); |
|
| 2041 | - |
|
| 2042 | - /** Build template */ |
|
| 2043 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2044 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2045 | - /** Include the old way template part */ |
|
| 2046 | - ob_start(); |
|
| 2047 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2048 | - $product_special_state['output'] = ob_get_contents(); |
|
| 2049 | - ob_end_clean(); |
|
| 2050 | - } else { |
|
| 2051 | - $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2052 | - } |
|
| 2053 | - unset($tpl_component); |
|
| 2054 | - } |
|
| 2025 | + if ($show_product_special_state) { |
|
| 2026 | + /** Check the type of special output needed */ |
|
| 2027 | + switch ($special) { |
|
| 2028 | + case 'declare_new': |
|
| 2029 | + $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 2030 | + $template_part = 'product_is_new_sticker'; |
|
| 2031 | + break; |
|
| 2055 | 2032 | |
| 2056 | - return $product_special_state; |
|
| 2057 | - } |
|
| 2033 | + case 'highlight_product': |
|
| 2034 | + $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 2035 | + $template_part = 'product_is_featured_sticker'; |
|
| 2036 | + break; |
|
| 2037 | + } |
|
| 2058 | 2038 | |
| 2059 | - /** |
|
| 2060 | - * Prepare product price for saving and easier read later |
|
| 2061 | - * |
|
| 2062 | - * @param integer $element_id Identifier of current product |
|
| 2063 | - */ |
|
| 2064 | - public static function calculate_price($element_id) |
|
| 2065 | - { |
|
| 2066 | - global $wpdb; |
|
| 2067 | - |
|
| 2068 | - /** |
|
| 2069 | - * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2070 | - * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2071 | - * price_ht and tva |
|
| 2072 | - */ |
|
| 2073 | - $query = $wpdb->prepare( |
|
| 2074 | - "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2039 | + /** Template parameters */ |
|
| 2040 | + $tpl_component = array(); |
|
| 2041 | + |
|
| 2042 | + /** Build template */ |
|
| 2043 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2044 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2045 | + /** Include the old way template part */ |
|
| 2046 | + ob_start(); |
|
| 2047 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2048 | + $product_special_state['output'] = ob_get_contents(); |
|
| 2049 | + ob_end_clean(); |
|
| 2050 | + } else { |
|
| 2051 | + $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2052 | + } |
|
| 2053 | + unset($tpl_component); |
|
| 2054 | + } |
|
| 2055 | + |
|
| 2056 | + return $product_special_state; |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + /** |
|
| 2060 | + * Prepare product price for saving and easier read later |
|
| 2061 | + * |
|
| 2062 | + * @param integer $element_id Identifier of current product |
|
| 2063 | + */ |
|
| 2064 | + public static function calculate_price($element_id) |
|
| 2065 | + { |
|
| 2066 | + global $wpdb; |
|
| 2067 | + |
|
| 2068 | + /** |
|
| 2069 | + * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2070 | + * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2071 | + * price_ht and tva |
|
| 2072 | + */ |
|
| 2073 | + $query = $wpdb->prepare( |
|
| 2074 | + "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2075 | 2075 | FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR |
| 2076 | 2076 | RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d)) |
| 2077 | 2077 | WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')", |
| 2078 | - $element_id |
|
| 2079 | - ); |
|
| 2080 | - $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2081 | - |
|
| 2082 | - /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2083 | - if (empty($prices_attribute)) { |
|
| 2084 | - return false; |
|
| 2085 | - } else { |
|
| 2086 | - /** |
|
| 2087 | - * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2088 | - * the base amount according on the shop price control |
|
| 2089 | - */ |
|
| 2090 | - $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2091 | - $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2092 | - $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2093 | - |
|
| 2094 | - /** |
|
| 2095 | - * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2096 | - * create an attribute |
|
| 2097 | - */ |
|
| 2098 | - $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2099 | - $language = WPSHOP_CURRENT_LOCALE; |
|
| 2100 | - $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2101 | - |
|
| 2102 | - if (!empty($icl_post_language)) { |
|
| 2103 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2104 | - $language = $wpdb->get_var($query); |
|
| 2105 | - } |
|
| 2106 | - |
|
| 2107 | - /** |
|
| 2108 | - * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2109 | - * Check configuration to know how to make the calcul for the product |
|
| 2110 | - */ |
|
| 2111 | - if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2112 | - $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2113 | - $price_no_vat = $base_price; |
|
| 2114 | - } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2115 | - $price_with_vat = $base_price; |
|
| 2116 | - $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - /** |
|
| 2120 | - * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2121 | - * type que celui-ci / The last parameter allows not to delete the |
|
| 2122 | - * attributes of the same type as this one |
|
| 2123 | - */ |
|
| 2124 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2125 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2126 | - |
|
| 2127 | - /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2128 | - $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2129 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2130 | - |
|
| 2131 | - /** Update the product meta information with the calculated prices */ |
|
| 2132 | - $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2133 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2134 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2135 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2136 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2137 | - |
|
| 2138 | - update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2078 | + $element_id |
|
| 2079 | + ); |
|
| 2080 | + $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2081 | + |
|
| 2082 | + /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2083 | + if (empty($prices_attribute)) { |
|
| 2084 | + return false; |
|
| 2085 | + } else { |
|
| 2086 | + /** |
|
| 2087 | + * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2088 | + * the base amount according on the shop price control |
|
| 2089 | + */ |
|
| 2090 | + $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2091 | + $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2092 | + $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2093 | + |
|
| 2094 | + /** |
|
| 2095 | + * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2096 | + * create an attribute |
|
| 2097 | + */ |
|
| 2098 | + $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2099 | + $language = WPSHOP_CURRENT_LOCALE; |
|
| 2100 | + $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2101 | + |
|
| 2102 | + if (!empty($icl_post_language)) { |
|
| 2103 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2104 | + $language = $wpdb->get_var($query); |
|
| 2105 | + } |
|
| 2139 | 2106 | |
| 2140 | - /** Met à jour la meta _wps_price_infos */ |
|
| 2141 | - $p = wpshop_products::get_product_data($element_id); |
|
| 2142 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2143 | - update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2107 | + /** |
|
| 2108 | + * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2109 | + * Check configuration to know how to make the calcul for the product |
|
| 2110 | + */ |
|
| 2111 | + if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2112 | + $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2113 | + $price_no_vat = $base_price; |
|
| 2114 | + } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2115 | + $price_with_vat = $base_price; |
|
| 2116 | + $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2117 | + } |
|
| 2144 | 2118 | |
| 2145 | - /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2146 | - wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2147 | - } |
|
| 2119 | + /** |
|
| 2120 | + * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2121 | + * type que celui-ci / The last parameter allows not to delete the |
|
| 2122 | + * attributes of the same type as this one |
|
| 2123 | + */ |
|
| 2124 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2125 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2126 | + |
|
| 2127 | + /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2128 | + $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2129 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2130 | + |
|
| 2131 | + /** Update the product meta information with the calculated prices */ |
|
| 2132 | + $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2133 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2134 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2135 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2136 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2137 | + |
|
| 2138 | + update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2139 | + |
|
| 2140 | + /** Met à jour la meta _wps_price_infos */ |
|
| 2141 | + $p = wpshop_products::get_product_data($element_id); |
|
| 2142 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2143 | + update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2144 | + |
|
| 2145 | + /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2146 | + wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2147 | + } |
|
| 2148 | 2148 | |
| 2149 | - return true; |
|
| 2150 | - } |
|
| 2149 | + return true; |
|
| 2150 | + } |
|
| 2151 | 2151 | |
| 2152 | - /** |
|
| 2153 | - * Allows to get the good button for adding product to cart |
|
| 2154 | - * |
|
| 2155 | - * @param integer $product_id The product identifier |
|
| 2156 | - * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2157 | - * |
|
| 2158 | - * @return string $button The html output for the button |
|
| 2159 | - */ |
|
| 2160 | - public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2161 | - { |
|
| 2162 | - $button = ''; |
|
| 2152 | + /** |
|
| 2153 | + * Allows to get the good button for adding product to cart |
|
| 2154 | + * |
|
| 2155 | + * @param integer $product_id The product identifier |
|
| 2156 | + * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2157 | + * |
|
| 2158 | + * @return string $button The html output for the button |
|
| 2159 | + */ |
|
| 2160 | + public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2161 | + { |
|
| 2162 | + $button = ''; |
|
| 2163 | 2163 | // $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true ); |
| 2164 | 2164 | |
| 2165 | - 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') ) */) { |
|
| 2166 | - /* |
|
| 2165 | + 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') ) */) { |
|
| 2166 | + /* |
|
| 2167 | 2167 | * Check if current product has variation for button display |
| 2168 | 2168 | */ |
| 2169 | - $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2170 | - $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2169 | + $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2170 | + $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2171 | 2171 | |
| 2172 | - /* |
|
| 2172 | + /* |
|
| 2173 | 2173 | * Template parameters |
| 2174 | 2174 | */ |
| 2175 | 2175 | |
| 2176 | - if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2177 | - /** Check variation stock **/ |
|
| 2178 | - $variations = self::get_variation($product_id); |
|
| 2179 | - if (!empty($variations)) { |
|
| 2180 | - foreach ($variations as $variation) { |
|
| 2181 | - if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2182 | - $productStock += $variation['variation_dif']['product_stock']; |
|
| 2183 | - } |
|
| 2184 | - } |
|
| 2185 | - } |
|
| 2186 | - } |
|
| 2187 | - |
|
| 2188 | - $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2176 | + if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2177 | + /** Check variation stock **/ |
|
| 2178 | + $variations = self::get_variation($product_id); |
|
| 2179 | + if (!empty($variations)) { |
|
| 2180 | + foreach ($variations as $variation) { |
|
| 2181 | + if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2182 | + $productStock += $variation['variation_dif']['product_stock']; |
|
| 2183 | + } |
|
| 2184 | + } |
|
| 2185 | + } |
|
| 2186 | + } |
|
| 2187 | + |
|
| 2188 | + $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2189 | 2189 | $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
| 2190 | 2190 | |
| 2191 | - $tpl_component = array(); |
|
| 2192 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2193 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2194 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2191 | + $tpl_component = array(); |
|
| 2192 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2193 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2194 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2195 | 2195 | |
| 2196 | - /* |
|
| 2196 | + /* |
|
| 2197 | 2197 | * Build template |
| 2198 | 2198 | */ |
| 2199 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2200 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2201 | - /* Include the old way template part */ |
|
| 2202 | - ob_start(); |
|
| 2203 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2204 | - $button = ob_get_contents(); |
|
| 2205 | - ob_end_clean(); |
|
| 2206 | - } else { |
|
| 2207 | - $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)); |
|
| 2208 | - } |
|
| 2209 | - unset($tpl_component); |
|
| 2210 | - } |
|
| 2211 | - return $button; |
|
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - /** |
|
| 2215 | - * Allows to get the good button for adding product to a quotation |
|
| 2216 | - * |
|
| 2217 | - * @param integer $product_id The product identifier |
|
| 2218 | - * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2219 | - * |
|
| 2220 | - * @return string $button The html output for the button |
|
| 2221 | - */ |
|
| 2222 | - public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2223 | - { |
|
| 2224 | - $quotation_button = ''; |
|
| 2225 | - |
|
| 2226 | - 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'))) { |
|
| 2227 | - $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(); |
|
| 2228 | - /** |
|
| 2229 | - * Template parameters |
|
| 2230 | - */ |
|
| 2231 | - $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2232 | - $tpl_component = array(); |
|
| 2233 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2234 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2235 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2199 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2200 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2201 | + /* Include the old way template part */ |
|
| 2202 | + ob_start(); |
|
| 2203 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2204 | + $button = ob_get_contents(); |
|
| 2205 | + ob_end_clean(); |
|
| 2206 | + } else { |
|
| 2207 | + $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)); |
|
| 2208 | + } |
|
| 2209 | + unset($tpl_component); |
|
| 2210 | + } |
|
| 2211 | + return $button; |
|
| 2212 | + } |
|
| 2236 | 2213 | |
| 2237 | - /** |
|
| 2238 | - * Build template |
|
| 2239 | - */ |
|
| 2240 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2241 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2242 | - /* Include the old way template part */ |
|
| 2243 | - ob_start(); |
|
| 2244 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2245 | - $quotation_button = ob_get_contents(); |
|
| 2246 | - ob_end_clean(); |
|
| 2247 | - } else { |
|
| 2248 | - $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2249 | - } |
|
| 2250 | - unset($tpl_component); |
|
| 2251 | - } |
|
| 2214 | + /** |
|
| 2215 | + * Allows to get the good button for adding product to a quotation |
|
| 2216 | + * |
|
| 2217 | + * @param integer $product_id The product identifier |
|
| 2218 | + * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2219 | + * |
|
| 2220 | + * @return string $button The html output for the button |
|
| 2221 | + */ |
|
| 2222 | + public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2223 | + { |
|
| 2224 | + $quotation_button = ''; |
|
| 2225 | + |
|
| 2226 | + 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'))) { |
|
| 2227 | + $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(); |
|
| 2228 | + /** |
|
| 2229 | + * Template parameters |
|
| 2230 | + */ |
|
| 2231 | + $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2232 | + $tpl_component = array(); |
|
| 2233 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2234 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2235 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2236 | + |
|
| 2237 | + /** |
|
| 2238 | + * Build template |
|
| 2239 | + */ |
|
| 2240 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2241 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2242 | + /* Include the old way template part */ |
|
| 2243 | + ob_start(); |
|
| 2244 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2245 | + $quotation_button = ob_get_contents(); |
|
| 2246 | + ob_end_clean(); |
|
| 2247 | + } else { |
|
| 2248 | + $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2249 | + } |
|
| 2250 | + unset($tpl_component); |
|
| 2251 | + } |
|
| 2252 | 2252 | |
| 2253 | - return $quotation_button; |
|
| 2254 | - } |
|
| 2253 | + return $quotation_button; |
|
| 2254 | + } |
|
| 2255 | 2255 | |
| 2256 | - /** |
|
| 2257 | - * Return the output for a product attachement gallery (picture or document) |
|
| 2258 | - * |
|
| 2259 | - * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2260 | - * @param string $content The gallery content build previously |
|
| 2261 | - * |
|
| 2262 | - * @return string The attachement gallery output |
|
| 2263 | - */ |
|
| 2264 | - public static function display_attachment_gallery($attachement_type, $content) |
|
| 2265 | - { |
|
| 2266 | - $galery_output = ''; |
|
| 2267 | - |
|
| 2268 | - /* |
|
| 2256 | + /** |
|
| 2257 | + * Return the output for a product attachement gallery (picture or document) |
|
| 2258 | + * |
|
| 2259 | + * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2260 | + * @param string $content The gallery content build previously |
|
| 2261 | + * |
|
| 2262 | + * @return string The attachement gallery output |
|
| 2263 | + */ |
|
| 2264 | + public static function display_attachment_gallery($attachement_type, $content) |
|
| 2265 | + { |
|
| 2266 | + $galery_output = ''; |
|
| 2267 | + |
|
| 2268 | + /* |
|
| 2269 | 2269 | * Get the template part for given galery type |
| 2270 | 2270 | */ |
| 2271 | - switch ($attachement_type) { |
|
| 2272 | - case 'picture': |
|
| 2273 | - $template_part = 'product_attachment_picture_galery'; |
|
| 2274 | - break; |
|
| 2275 | - case 'document': |
|
| 2276 | - $template_part = 'product_attachment_galery'; |
|
| 2277 | - break; |
|
| 2278 | - } |
|
| 2271 | + switch ($attachement_type) { |
|
| 2272 | + case 'picture': |
|
| 2273 | + $template_part = 'product_attachment_picture_galery'; |
|
| 2274 | + break; |
|
| 2275 | + case 'document': |
|
| 2276 | + $template_part = 'product_attachment_galery'; |
|
| 2277 | + break; |
|
| 2278 | + } |
|
| 2279 | 2279 | |
| 2280 | - /* |
|
| 2280 | + /* |
|
| 2281 | 2281 | * Template parameters |
| 2282 | 2282 | */ |
| 2283 | - $tpl_component = array(); |
|
| 2284 | - $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2285 | - $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2283 | + $tpl_component = array(); |
|
| 2284 | + $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2285 | + $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2286 | 2286 | |
| 2287 | - /* |
|
| 2287 | + /* |
|
| 2288 | 2288 | * Build template |
| 2289 | 2289 | */ |
| 2290 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2291 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2292 | - /* Include the old way template part */ |
|
| 2293 | - ob_start(); |
|
| 2294 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2295 | - $galery_output = ob_get_contents(); |
|
| 2296 | - ob_end_clean(); |
|
| 2297 | - } else { |
|
| 2298 | - $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2299 | - } |
|
| 2300 | - unset($tpl_component); |
|
| 2290 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2291 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2292 | + /* Include the old way template part */ |
|
| 2293 | + ob_start(); |
|
| 2294 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2295 | + $galery_output = ob_get_contents(); |
|
| 2296 | + ob_end_clean(); |
|
| 2297 | + } else { |
|
| 2298 | + $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2299 | + } |
|
| 2300 | + unset($tpl_component); |
|
| 2301 | 2301 | |
| 2302 | - return $galery_output; |
|
| 2303 | - } |
|
| 2302 | + return $galery_output; |
|
| 2303 | + } |
|
| 2304 | 2304 | |
| 2305 | - /** |
|
| 2306 | - * Define the metabox to display in product edition page in backend |
|
| 2307 | - * @param object $post The current element displayed for edition |
|
| 2308 | - */ |
|
| 2309 | - public static function meta_box_variations($post) |
|
| 2310 | - { |
|
| 2311 | - $output = ''; |
|
| 2312 | - /* Variations container */ |
|
| 2313 | - $tpl_component = array(); |
|
| 2314 | - $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2315 | - $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2316 | - $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2317 | - echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2318 | - } |
|
| 2305 | + /** |
|
| 2306 | + * Define the metabox to display in product edition page in backend |
|
| 2307 | + * @param object $post The current element displayed for edition |
|
| 2308 | + */ |
|
| 2309 | + public static function meta_box_variations($post) |
|
| 2310 | + { |
|
| 2311 | + $output = ''; |
|
| 2312 | + /* Variations container */ |
|
| 2313 | + $tpl_component = array(); |
|
| 2314 | + $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2315 | + $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2316 | + $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2317 | + echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2318 | + } |
|
| 2319 | 2319 | |
| 2320 | - /** |
|
| 2321 | - * Call variation creation function with a list of defined variation |
|
| 2322 | - * |
|
| 2323 | - * @param array $possible_variations A list of variation to create for the current element |
|
| 2324 | - * @param integer $element_id The product we want to create variation for |
|
| 2325 | - * |
|
| 2326 | - * @return mixed The last created variation identifier |
|
| 2327 | - */ |
|
| 2328 | - public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2329 | - { |
|
| 2330 | - /** Get existing variation */ |
|
| 2331 | - $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2332 | - $existing_variations = array(); |
|
| 2333 | - if (!empty($existing_variations_in_db)) { |
|
| 2334 | - foreach ($existing_variations_in_db as $variations_def) { |
|
| 2335 | - $existing_variations[] = $variations_def['variation_def']; |
|
| 2336 | - } |
|
| 2337 | - } |
|
| 2338 | - /** New variation definition */ |
|
| 2339 | - $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2340 | - |
|
| 2341 | - /** Read possible values */ |
|
| 2342 | - foreach ($possible_variations as $variation_definition) { |
|
| 2343 | - if (in_array($variation_definition, $existing_variations)) { |
|
| 2344 | - continue; |
|
| 2345 | - } |
|
| 2346 | - |
|
| 2347 | - $attribute_to_set = array(); |
|
| 2348 | - foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2349 | - $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2350 | - $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2351 | - if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2352 | - $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2353 | - } |
|
| 2354 | - } |
|
| 2355 | - $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2356 | - } |
|
| 2357 | - update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2320 | + /** |
|
| 2321 | + * Call variation creation function with a list of defined variation |
|
| 2322 | + * |
|
| 2323 | + * @param array $possible_variations A list of variation to create for the current element |
|
| 2324 | + * @param integer $element_id The product we want to create variation for |
|
| 2325 | + * |
|
| 2326 | + * @return mixed The last created variation identifier |
|
| 2327 | + */ |
|
| 2328 | + public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2329 | + { |
|
| 2330 | + /** Get existing variation */ |
|
| 2331 | + $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2332 | + $existing_variations = array(); |
|
| 2333 | + if (!empty($existing_variations_in_db)) { |
|
| 2334 | + foreach ($existing_variations_in_db as $variations_def) { |
|
| 2335 | + $existing_variations[] = $variations_def['variation_def']; |
|
| 2336 | + } |
|
| 2337 | + } |
|
| 2338 | + /** New variation definition */ |
|
| 2339 | + $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2358 | 2340 | |
| 2359 | - return !empty($variation_id) ? $variation_id : 0; |
|
| 2360 | - } |
|
| 2341 | + /** Read possible values */ |
|
| 2342 | + foreach ($possible_variations as $variation_definition) { |
|
| 2343 | + if (in_array($variation_definition, $existing_variations)) { |
|
| 2344 | + continue; |
|
| 2345 | + } |
|
| 2361 | 2346 | |
| 2362 | - /** |
|
| 2363 | - * Create a new variation for product |
|
| 2364 | - * |
|
| 2365 | - * @param integer $head_product The product identifier to create the new variation for |
|
| 2366 | - * @param array $variation_attributes Attribute list for the variation |
|
| 2367 | - * |
|
| 2368 | - * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2369 | - */ |
|
| 2370 | - public static function create_variation($head_product, $variation_attributes) |
|
| 2371 | - { |
|
| 2372 | - /** Create custom title */ |
|
| 2373 | - $title_variation = ""; |
|
| 2374 | - if (!empty($variation_attributes)) { |
|
| 2375 | - foreach ($variation_attributes as $type => $array) { |
|
| 2376 | - if (!empty($array)) { |
|
| 2377 | - foreach ($array as $code => $value) { |
|
| 2378 | - $title_variation .= " " . $code . " " . $value; |
|
| 2379 | - } |
|
| 2380 | - } |
|
| 2381 | - } |
|
| 2382 | - } |
|
| 2347 | + $attribute_to_set = array(); |
|
| 2348 | + foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2349 | + $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2350 | + $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2351 | + if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2352 | + $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2353 | + } |
|
| 2354 | + } |
|
| 2355 | + $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2356 | + } |
|
| 2357 | + update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2383 | 2358 | |
| 2384 | - $variation = array( |
|
| 2385 | - 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2386 | - 'post_content' => '', |
|
| 2387 | - 'post_status' => 'publish', |
|
| 2388 | - 'post_author' => get_current_user_id(), |
|
| 2389 | - 'post_parent' => $head_product, |
|
| 2390 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2391 | - ); |
|
| 2392 | - $variation_id = wp_insert_post($variation); |
|
| 2393 | - |
|
| 2394 | - wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2395 | - |
|
| 2396 | - /* Update product price looking for shop parameters */ |
|
| 2397 | - wpshop_products::calculate_price($variation_id); |
|
| 2398 | - |
|
| 2399 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2400 | - $productMetaDatas = array(); |
|
| 2401 | - foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2402 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2403 | - if (!empty($attributeValue)) { |
|
| 2404 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2405 | - } |
|
| 2406 | - } |
|
| 2407 | - } |
|
| 2408 | - update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2409 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2410 | - 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)); |
|
| 2359 | + return !empty($variation_id) ? $variation_id : 0; |
|
| 2360 | + } |
|
| 2411 | 2361 | |
| 2412 | - return $variation_id; |
|
| 2413 | - } |
|
| 2362 | + /** |
|
| 2363 | + * Create a new variation for product |
|
| 2364 | + * |
|
| 2365 | + * @param integer $head_product The product identifier to create the new variation for |
|
| 2366 | + * @param array $variation_attributes Attribute list for the variation |
|
| 2367 | + * |
|
| 2368 | + * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2369 | + */ |
|
| 2370 | + public static function create_variation($head_product, $variation_attributes) |
|
| 2371 | + { |
|
| 2372 | + /** Create custom title */ |
|
| 2373 | + $title_variation = ""; |
|
| 2374 | + if (!empty($variation_attributes)) { |
|
| 2375 | + foreach ($variation_attributes as $type => $array) { |
|
| 2376 | + if (!empty($array)) { |
|
| 2377 | + foreach ($array as $code => $value) { |
|
| 2378 | + $title_variation .= " " . $code . " " . $value; |
|
| 2379 | + } |
|
| 2380 | + } |
|
| 2381 | + } |
|
| 2382 | + } |
|
| 2414 | 2383 | |
| 2415 | - /** |
|
| 2416 | - * Get variation list for a given product |
|
| 2417 | - * |
|
| 2418 | - * @param integer $head_product The product identifier to get the variation for |
|
| 2419 | - * @return object The variation list |
|
| 2420 | - */ |
|
| 2421 | - public static function get_variation($head_product, $type = 'any') |
|
| 2422 | - { |
|
| 2423 | - global $wpdb; |
|
| 2424 | - $variations_output = null; |
|
| 2425 | - $args = array( |
|
| 2426 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2427 | - 'post_parent' => $head_product, |
|
| 2428 | - 'orderby' => 'ID', |
|
| 2429 | - 'order' => 'ASC', |
|
| 2430 | - 'posts_per_page' => -1, |
|
| 2431 | - 'post_status' => $type, |
|
| 2432 | - ); |
|
| 2433 | - $variations = get_posts($args); |
|
| 2434 | - |
|
| 2435 | - if (!empty($variations)) { |
|
| 2436 | - $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2437 | - |
|
| 2438 | - foreach ($variations as $post_def) { |
|
| 2439 | - $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'"); |
|
| 2440 | - foreach ($data as $content) { |
|
| 2441 | - $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2442 | - if (!empty($content->$attribute_value)) { |
|
| 2443 | - if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2444 | - $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2445 | - } else { |
|
| 2446 | - $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2447 | - } |
|
| 2448 | - } |
|
| 2449 | - } |
|
| 2450 | - $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2451 | - } |
|
| 2452 | - } |
|
| 2453 | - wp_reset_query(); |
|
| 2454 | - return $variations_output; |
|
| 2455 | - } |
|
| 2384 | + $variation = array( |
|
| 2385 | + 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2386 | + 'post_content' => '', |
|
| 2387 | + 'post_status' => 'publish', |
|
| 2388 | + 'post_author' => get_current_user_id(), |
|
| 2389 | + 'post_parent' => $head_product, |
|
| 2390 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2391 | + ); |
|
| 2392 | + $variation_id = wp_insert_post($variation); |
|
| 2393 | + |
|
| 2394 | + wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2395 | + |
|
| 2396 | + /* Update product price looking for shop parameters */ |
|
| 2397 | + wpshop_products::calculate_price($variation_id); |
|
| 2398 | + |
|
| 2399 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2400 | + $productMetaDatas = array(); |
|
| 2401 | + foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2402 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2403 | + if (!empty($attributeValue)) { |
|
| 2404 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2405 | + } |
|
| 2406 | + } |
|
| 2407 | + } |
|
| 2408 | + update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2409 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2410 | + 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)); |
|
| 2456 | 2411 | |
| 2457 | - /** |
|
| 2458 | - * Affichage des variations d'un produit dans l'administration |
|
| 2459 | - * |
|
| 2460 | - * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2461 | - * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2462 | - */ |
|
| 2463 | - public static function display_variation_admin($head_product) |
|
| 2464 | - { |
|
| 2465 | - $output = ''; |
|
| 2466 | - $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2467 | - /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2468 | - $variations = self::get_variation($head_product); |
|
| 2469 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2470 | - |
|
| 2471 | - /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2472 | - if (!empty($variations) && is_array($variations)) { |
|
| 2473 | - $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2474 | - |
|
| 2475 | - foreach ($variations as $variation) { |
|
| 2476 | - $tpl_component = array(); |
|
| 2477 | - |
|
| 2478 | - $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2479 | - $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2480 | - $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2481 | - $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; |
|
| 2482 | - $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2483 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2484 | - |
|
| 2485 | - } else { |
|
| 2486 | - |
|
| 2487 | - } |
|
| 2488 | - $post_obj = $variation['post']; |
|
| 2489 | - |
|
| 2490 | - $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2491 | - if (!empty($parent_product_infos)) { |
|
| 2492 | - $parent_post = $parent_product_infos['parent_post']; |
|
| 2493 | - $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2494 | - if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2495 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2496 | - $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2497 | - } else { |
|
| 2498 | - $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2499 | - } |
|
| 2500 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2501 | - } else { |
|
| 2502 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2503 | - $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2504 | - } else { |
|
| 2505 | - $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2506 | - } |
|
| 2507 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2508 | - } |
|
| 2509 | - $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2510 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2511 | - } |
|
| 2512 | - |
|
| 2513 | - if (!empty($variation['variation_def'])) { |
|
| 2514 | - foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2515 | - if (!empty($variation_value)) { |
|
| 2516 | - $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2517 | - $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'); |
|
| 2518 | - $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2519 | - |
|
| 2520 | - /** Define Link image to variation interface **/ |
|
| 2521 | - 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'))) { |
|
| 2522 | - $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2523 | - |
|
| 2524 | - $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2525 | - if (!empty($media_id_data)) { |
|
| 2526 | - $medias_ids = explode(',', $media_id_data); |
|
| 2527 | - |
|
| 2528 | - if (!empty($medias_ids)) { |
|
| 2529 | - foreach ($medias_ids as $media_id) { |
|
| 2530 | - if (!empty($media_id)) { |
|
| 2531 | - $pictures[] = get_post($media_id); |
|
| 2532 | - } |
|
| 2533 | - } |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - $pictures_data = ''; |
|
| 2538 | - if (!empty($pictures)) { |
|
| 2539 | - $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2540 | - |
|
| 2541 | - $done_picture = array(); |
|
| 2542 | - foreach ($pictures as $picture) { |
|
| 2543 | - if (!in_array($picture->ID, $done_picture)) { |
|
| 2544 | - if (wp_attachment_is_image($picture->ID)) { |
|
| 2545 | - $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2546 | - $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'); |
|
| 2547 | - |
|
| 2548 | - $done_picture[] = $picture->ID; |
|
| 2549 | - } |
|
| 2550 | - } |
|
| 2551 | - } |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - $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'); |
|
| 2555 | - } |
|
| 2556 | - |
|
| 2557 | - } |
|
| 2558 | - } |
|
| 2559 | - } |
|
| 2560 | - |
|
| 2561 | - $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2562 | - |
|
| 2563 | - $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2564 | - $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()))); |
|
| 2565 | - $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'); |
|
| 2566 | - |
|
| 2567 | - /* Add the variation definition to output */ |
|
| 2568 | - $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'); |
|
| 2569 | - } |
|
| 2570 | - |
|
| 2571 | - $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'); |
|
| 2572 | - /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2573 | - wp_reset_query(); |
|
| 2574 | - } else { |
|
| 2575 | - $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2576 | - } |
|
| 2412 | + return $variation_id; |
|
| 2413 | + } |
|
| 2577 | 2414 | |
| 2578 | - return $output; |
|
| 2579 | - } |
|
| 2415 | + /** |
|
| 2416 | + * Get variation list for a given product |
|
| 2417 | + * |
|
| 2418 | + * @param integer $head_product The product identifier to get the variation for |
|
| 2419 | + * @return object The variation list |
|
| 2420 | + */ |
|
| 2421 | + public static function get_variation($head_product, $type = 'any') |
|
| 2422 | + { |
|
| 2423 | + global $wpdb; |
|
| 2424 | + $variations_output = null; |
|
| 2425 | + $args = array( |
|
| 2426 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2427 | + 'post_parent' => $head_product, |
|
| 2428 | + 'orderby' => 'ID', |
|
| 2429 | + 'order' => 'ASC', |
|
| 2430 | + 'posts_per_page' => -1, |
|
| 2431 | + 'post_status' => $type, |
|
| 2432 | + ); |
|
| 2433 | + $variations = get_posts($args); |
|
| 2434 | + |
|
| 2435 | + if (!empty($variations)) { |
|
| 2436 | + $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2437 | + |
|
| 2438 | + foreach ($variations as $post_def) { |
|
| 2439 | + $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'"); |
|
| 2440 | + foreach ($data as $content) { |
|
| 2441 | + $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2442 | + if (!empty($content->$attribute_value)) { |
|
| 2443 | + if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2444 | + $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2445 | + } else { |
|
| 2446 | + $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2447 | + } |
|
| 2448 | + } |
|
| 2449 | + } |
|
| 2450 | + $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2451 | + } |
|
| 2452 | + } |
|
| 2453 | + wp_reset_query(); |
|
| 2454 | + return $variations_output; |
|
| 2455 | + } |
|
| 2580 | 2456 | |
| 2581 | - /** |
|
| 2582 | - * Retrieve and display the variation for a given product |
|
| 2583 | - * @param integer $product_id The product identifier to get variation for |
|
| 2584 | - */ |
|
| 2585 | - public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2586 | - { |
|
| 2587 | - global $wp_query; |
|
| 2588 | - $output = ''; |
|
| 2589 | - |
|
| 2590 | - $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2591 | - $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2592 | - $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2593 | - |
|
| 2594 | - /** Get attribute order for current product */ |
|
| 2595 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2596 | - $output_order = array(); |
|
| 2597 | - if (count($product_attribute_order_detail) > 0) { |
|
| 2598 | - if (!empty($product_attribute_order_detail)) { |
|
| 2599 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2600 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2601 | - if (!empty($attribute_def->code)) { |
|
| 2602 | - $output_order[$attribute_def->code] = $position; |
|
| 2603 | - } |
|
| 2604 | - |
|
| 2605 | - } |
|
| 2606 | - } |
|
| 2607 | - } |
|
| 2608 | - } |
|
| 2457 | + /** |
|
| 2458 | + * Affichage des variations d'un produit dans l'administration |
|
| 2459 | + * |
|
| 2460 | + * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2461 | + * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2462 | + */ |
|
| 2463 | + public static function display_variation_admin($head_product) |
|
| 2464 | + { |
|
| 2465 | + $output = ''; |
|
| 2466 | + $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2467 | + /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2468 | + $variations = self::get_variation($head_product); |
|
| 2469 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2470 | + |
|
| 2471 | + /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2472 | + if (!empty($variations) && is_array($variations)) { |
|
| 2473 | + $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2474 | + |
|
| 2475 | + foreach ($variations as $variation) { |
|
| 2476 | + $tpl_component = array(); |
|
| 2477 | + |
|
| 2478 | + $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2479 | + $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2480 | + $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2481 | + $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; |
|
| 2482 | + $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2483 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2484 | + |
|
| 2485 | + } else { |
|
| 2609 | 2486 | |
| 2610 | - $variations_params = array(); |
|
| 2611 | - $variation_attribute = array(); |
|
| 2612 | - $variation_attribute_ordered = array(); |
|
| 2613 | - $possible_values = array(); |
|
| 2614 | - $possible_values_for_selection_calculation = array(); |
|
| 2615 | - |
|
| 2616 | - /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2617 | - $wpshop_variation_list = self::get_variation($product_id); |
|
| 2618 | - if (!empty($wpshop_variation_list)) { |
|
| 2619 | - foreach ($wpshop_variation_list as $variation) { |
|
| 2620 | - if (!empty($variation['variation_def'])) { |
|
| 2621 | - $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2622 | - foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2623 | - if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2624 | - $tpl_component = array(); |
|
| 2625 | - |
|
| 2626 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2627 | - $default_value_is_serial = false; |
|
| 2628 | - $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2629 | - if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2630 | - $default_value_is_serial = true; |
|
| 2631 | - $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2632 | - $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2636 | - $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'); |
|
| 2637 | - } |
|
| 2638 | - |
|
| 2639 | - if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2640 | - $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2641 | - $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2642 | - } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2643 | - $post_def = get_post($attribute_value); |
|
| 2644 | - $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2645 | - $position = $post_def->menu_order; |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - if (!empty($variation['variation_dif'])) { |
|
| 2649 | - foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2650 | - $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2651 | - $the_value = $attribute_dif_value; |
|
| 2652 | - if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2653 | - $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2654 | - } |
|
| 2655 | - $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2656 | - } |
|
| 2657 | - } |
|
| 2658 | - if (!empty($attribute_value)) { |
|
| 2659 | - $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)); |
|
| 2660 | - $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2661 | - } |
|
| 2662 | - unset($tpl_component); |
|
| 2663 | - } |
|
| 2664 | - } |
|
| 2665 | - } |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - $variation_tpl = array(); |
|
| 2669 | - if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2670 | - foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2671 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2672 | - |
|
| 2673 | - if (!empty($attribute_db_definition)) { |
|
| 2674 | - $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'); |
|
| 2675 | - |
|
| 2676 | - $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; |
|
| 2677 | - if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2678 | - $is_required = true; |
|
| 2679 | - } |
|
| 2680 | - |
|
| 2681 | - $input_def = array(); |
|
| 2682 | - $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2683 | - $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); |
|
| 2684 | - if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2685 | - unset($possible_values[$attribute_code][0]); |
|
| 2686 | - $value = array($value); |
|
| 2687 | - } |
|
| 2688 | - $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2689 | - $input_def['name'] = $attribute_code; |
|
| 2690 | - $real_possible_values = array(); |
|
| 2691 | - if (!empty($possible_values[$attribute_code])) { |
|
| 2692 | - ksort($possible_values[$attribute_code]); |
|
| 2693 | - foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2694 | - foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2695 | - $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2696 | - if (!empty($attribute_value)) { |
|
| 2697 | - global $wpdb; |
|
| 2698 | - $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); |
|
| 2699 | - if ('draft' == $wpdb->get_var($query)) { |
|
| 2700 | - unset($real_possible_values[$attribute_value]); |
|
| 2701 | - } |
|
| 2702 | - } |
|
| 2703 | - } |
|
| 2704 | - } |
|
| 2705 | - } |
|
| 2706 | - $input_def['possible_value'] = $real_possible_values; |
|
| 2707 | - $input_def['valueToPut'] = 'index'; |
|
| 2708 | - $input_def['value'] = $value; |
|
| 2709 | - |
|
| 2710 | - $input_def['options']['more_input'] = ''; |
|
| 2711 | - if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2712 | - foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2713 | - $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 . '" />'; |
|
| 2714 | - } |
|
| 2715 | - } |
|
| 2716 | - |
|
| 2717 | - $input_def['options_label']['original'] = true; |
|
| 2718 | - $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) . '" '; |
|
| 2719 | - |
|
| 2720 | - if (!empty($real_possible_values)) { |
|
| 2721 | - $tpl_component = array(); |
|
| 2722 | - $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']; |
|
| 2723 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2724 | - $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)); |
|
| 2725 | - $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2726 | - $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2727 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2728 | - $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2729 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2730 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2731 | - $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; |
|
| 2732 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2733 | - $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2734 | - $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2735 | - } |
|
| 2736 | - |
|
| 2737 | - $variation_attribute[] = $attribute_code; |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - } |
|
| 2487 | + } |
|
| 2488 | + $post_obj = $variation['post']; |
|
| 2489 | + |
|
| 2490 | + $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2491 | + if (!empty($parent_product_infos)) { |
|
| 2492 | + $parent_post = $parent_product_infos['parent_post']; |
|
| 2493 | + $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2494 | + if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2495 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2496 | + $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2497 | + } else { |
|
| 2498 | + $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2499 | + } |
|
| 2500 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2501 | + } else { |
|
| 2502 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2503 | + $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2504 | + } else { |
|
| 2505 | + $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2506 | + } |
|
| 2507 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2508 | + } |
|
| 2509 | + $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2510 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2511 | + } |
|
| 2741 | 2512 | |
| 2742 | - } |
|
| 2743 | - $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2744 | - wp_reset_query(); |
|
| 2745 | - |
|
| 2746 | - $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2747 | - if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2748 | - foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2749 | - $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; |
|
| 2750 | - |
|
| 2751 | - $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'); |
|
| 2752 | - 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')) { |
|
| 2753 | - $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] : '')); |
|
| 2754 | - |
|
| 2755 | - $tpl_component = array(); |
|
| 2756 | - $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) . '" '; |
|
| 2757 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2758 | - $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)); |
|
| 2759 | - $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2760 | - $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 . '" ' : ''; |
|
| 2761 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2762 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2763 | - $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2764 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2765 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2766 | - $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; |
|
| 2767 | - $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']; |
|
| 2768 | - $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)]; |
|
| 2769 | - } |
|
| 2770 | - } |
|
| 2771 | - } |
|
| 2772 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2773 | - if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2774 | - ksort($variation_attribute_ordered); |
|
| 2775 | - foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2776 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2777 | - } |
|
| 2778 | - } |
|
| 2779 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2780 | - $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2781 | - if ($from_admin && !empty($order_id)) { |
|
| 2782 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2783 | - $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2784 | - } |
|
| 2785 | - $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2513 | + if (!empty($variation['variation_def'])) { |
|
| 2514 | + foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2515 | + if (!empty($variation_value)) { |
|
| 2516 | + $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2517 | + $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'); |
|
| 2518 | + $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2519 | + |
|
| 2520 | + /** Define Link image to variation interface **/ |
|
| 2521 | + 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'))) { |
|
| 2522 | + $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2523 | + |
|
| 2524 | + $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2525 | + if (!empty($media_id_data)) { |
|
| 2526 | + $medias_ids = explode(',', $media_id_data); |
|
| 2527 | + |
|
| 2528 | + if (!empty($medias_ids)) { |
|
| 2529 | + foreach ($medias_ids as $media_id) { |
|
| 2530 | + if (!empty($media_id)) { |
|
| 2531 | + $pictures[] = get_post($media_id); |
|
| 2532 | + } |
|
| 2533 | + } |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + $pictures_data = ''; |
|
| 2538 | + if (!empty($pictures)) { |
|
| 2539 | + $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2540 | + |
|
| 2541 | + $done_picture = array(); |
|
| 2542 | + foreach ($pictures as $picture) { |
|
| 2543 | + if (!in_array($picture->ID, $done_picture)) { |
|
| 2544 | + if (wp_attachment_is_image($picture->ID)) { |
|
| 2545 | + $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2546 | + $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'); |
|
| 2547 | + |
|
| 2548 | + $done_picture[] = $picture->ID; |
|
| 2549 | + } |
|
| 2550 | + } |
|
| 2551 | + } |
|
| 2552 | + } |
|
| 2553 | + |
|
| 2554 | + $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'); |
|
| 2555 | + } |
|
| 2556 | + |
|
| 2557 | + } |
|
| 2558 | + } |
|
| 2559 | + } |
|
| 2786 | 2560 | |
| 2787 | - return $output; |
|
| 2788 | - } |
|
| 2561 | + $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2789 | 2562 | |
| 2790 | - public static function get_parent_variation($variation_id) |
|
| 2791 | - { |
|
| 2792 | - $result = array(); |
|
| 2793 | - if (!empty($variation_id)) { |
|
| 2794 | - $variation_post = get_post($variation_id); |
|
| 2795 | - if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2796 | - $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2797 | - $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2798 | - } |
|
| 2799 | - } |
|
| 2800 | - return $result; |
|
| 2801 | - } |
|
| 2563 | + $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2564 | + $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()))); |
|
| 2565 | + $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'); |
|
| 2802 | 2566 | |
| 2803 | - /** |
|
| 2804 | - * Display the current configuration for a given product |
|
| 2805 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2806 | - */ |
|
| 2807 | - public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2808 | - { |
|
| 2809 | - $output = ''; |
|
| 2810 | - |
|
| 2811 | - $product_variations_selection_args = array( |
|
| 2812 | - 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2813 | - 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2814 | - ); |
|
| 2815 | - |
|
| 2816 | - $current_user_id = get_current_user_id(); |
|
| 2817 | - |
|
| 2818 | - if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2819 | - foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2820 | - if (!empty($item) && !empty($item['item_id'])) { |
|
| 2821 | - |
|
| 2822 | - $free_variations = array(); |
|
| 2823 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2824 | - foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2825 | - $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2826 | - } |
|
| 2827 | - } |
|
| 2828 | - |
|
| 2829 | - $variations = array(); |
|
| 2830 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2831 | - foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2832 | - |
|
| 2833 | - if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2834 | - foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2835 | - $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2836 | - } |
|
| 2837 | - } |
|
| 2838 | - } |
|
| 2839 | - } |
|
| 2840 | - $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2841 | - |
|
| 2842 | - $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2843 | - } |
|
| 2844 | - } |
|
| 2845 | - } |
|
| 2567 | + /* Add the variation definition to output */ |
|
| 2568 | + $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'); |
|
| 2569 | + } |
|
| 2846 | 2570 | |
| 2847 | - $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2571 | + $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'); |
|
| 2572 | + /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2573 | + wp_reset_query(); |
|
| 2574 | + } else { |
|
| 2575 | + $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2576 | + } |
|
| 2848 | 2577 | |
| 2849 | - echo $output; |
|
| 2850 | - } |
|
| 2578 | + return $output; |
|
| 2579 | + } |
|
| 2580 | + |
|
| 2581 | + /** |
|
| 2582 | + * Retrieve and display the variation for a given product |
|
| 2583 | + * @param integer $product_id The product identifier to get variation for |
|
| 2584 | + */ |
|
| 2585 | + public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2586 | + { |
|
| 2587 | + global $wp_query; |
|
| 2588 | + $output = ''; |
|
| 2589 | + |
|
| 2590 | + $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2591 | + $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2592 | + $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2593 | + |
|
| 2594 | + /** Get attribute order for current product */ |
|
| 2595 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2596 | + $output_order = array(); |
|
| 2597 | + if (count($product_attribute_order_detail) > 0) { |
|
| 2598 | + if (!empty($product_attribute_order_detail)) { |
|
| 2599 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2600 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2601 | + if (!empty($attribute_def->code)) { |
|
| 2602 | + $output_order[$attribute_def->code] = $position; |
|
| 2603 | + } |
|
| 2604 | + |
|
| 2605 | + } |
|
| 2606 | + } |
|
| 2607 | + } |
|
| 2608 | + } |
|
| 2609 | + |
|
| 2610 | + $variations_params = array(); |
|
| 2611 | + $variation_attribute = array(); |
|
| 2612 | + $variation_attribute_ordered = array(); |
|
| 2613 | + $possible_values = array(); |
|
| 2614 | + $possible_values_for_selection_calculation = array(); |
|
| 2615 | + |
|
| 2616 | + /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2617 | + $wpshop_variation_list = self::get_variation($product_id); |
|
| 2618 | + if (!empty($wpshop_variation_list)) { |
|
| 2619 | + foreach ($wpshop_variation_list as $variation) { |
|
| 2620 | + if (!empty($variation['variation_def'])) { |
|
| 2621 | + $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2622 | + foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2623 | + if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2624 | + $tpl_component = array(); |
|
| 2625 | + |
|
| 2626 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2627 | + $default_value_is_serial = false; |
|
| 2628 | + $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2629 | + if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2630 | + $default_value_is_serial = true; |
|
| 2631 | + $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2632 | + $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2636 | + $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'); |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2640 | + $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2641 | + $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2642 | + } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2643 | + $post_def = get_post($attribute_value); |
|
| 2644 | + $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2645 | + $position = $post_def->menu_order; |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + if (!empty($variation['variation_dif'])) { |
|
| 2649 | + foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2650 | + $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2651 | + $the_value = $attribute_dif_value; |
|
| 2652 | + if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2653 | + $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2654 | + } |
|
| 2655 | + $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2656 | + } |
|
| 2657 | + } |
|
| 2658 | + if (!empty($attribute_value)) { |
|
| 2659 | + $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)); |
|
| 2660 | + $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2661 | + } |
|
| 2662 | + unset($tpl_component); |
|
| 2663 | + } |
|
| 2664 | + } |
|
| 2665 | + } |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + $variation_tpl = array(); |
|
| 2669 | + if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2670 | + foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2671 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2672 | + |
|
| 2673 | + if (!empty($attribute_db_definition)) { |
|
| 2674 | + $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'); |
|
| 2675 | + |
|
| 2676 | + $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; |
|
| 2677 | + if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2678 | + $is_required = true; |
|
| 2679 | + } |
|
| 2680 | + |
|
| 2681 | + $input_def = array(); |
|
| 2682 | + $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2683 | + $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); |
|
| 2684 | + if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2685 | + unset($possible_values[$attribute_code][0]); |
|
| 2686 | + $value = array($value); |
|
| 2687 | + } |
|
| 2688 | + $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2689 | + $input_def['name'] = $attribute_code; |
|
| 2690 | + $real_possible_values = array(); |
|
| 2691 | + if (!empty($possible_values[$attribute_code])) { |
|
| 2692 | + ksort($possible_values[$attribute_code]); |
|
| 2693 | + foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2694 | + foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2695 | + $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2696 | + if (!empty($attribute_value)) { |
|
| 2697 | + global $wpdb; |
|
| 2698 | + $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); |
|
| 2699 | + if ('draft' == $wpdb->get_var($query)) { |
|
| 2700 | + unset($real_possible_values[$attribute_value]); |
|
| 2701 | + } |
|
| 2702 | + } |
|
| 2703 | + } |
|
| 2704 | + } |
|
| 2705 | + } |
|
| 2706 | + $input_def['possible_value'] = $real_possible_values; |
|
| 2707 | + $input_def['valueToPut'] = 'index'; |
|
| 2708 | + $input_def['value'] = $value; |
|
| 2709 | + |
|
| 2710 | + $input_def['options']['more_input'] = ''; |
|
| 2711 | + if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2712 | + foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2713 | + $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 . '" />'; |
|
| 2714 | + } |
|
| 2715 | + } |
|
| 2716 | + |
|
| 2717 | + $input_def['options_label']['original'] = true; |
|
| 2718 | + $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) . '" '; |
|
| 2719 | + |
|
| 2720 | + if (!empty($real_possible_values)) { |
|
| 2721 | + $tpl_component = array(); |
|
| 2722 | + $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']; |
|
| 2723 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2724 | + $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)); |
|
| 2725 | + $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2726 | + $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2727 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2728 | + $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2729 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2730 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2731 | + $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; |
|
| 2732 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2733 | + $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2734 | + $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2735 | + } |
|
| 2736 | + |
|
| 2737 | + $variation_attribute[] = $attribute_code; |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + } |
|
| 2741 | + |
|
| 2742 | + } |
|
| 2743 | + $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2744 | + wp_reset_query(); |
|
| 2745 | + |
|
| 2746 | + $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2747 | + if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2748 | + foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2749 | + $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; |
|
| 2750 | + |
|
| 2751 | + $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'); |
|
| 2752 | + 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')) { |
|
| 2753 | + $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] : '')); |
|
| 2754 | + |
|
| 2755 | + $tpl_component = array(); |
|
| 2756 | + $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) . '" '; |
|
| 2757 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2758 | + $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)); |
|
| 2759 | + $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2760 | + $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 . '" ' : ''; |
|
| 2761 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2762 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2763 | + $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2764 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2765 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2766 | + $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; |
|
| 2767 | + $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']; |
|
| 2768 | + $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)]; |
|
| 2769 | + } |
|
| 2770 | + } |
|
| 2771 | + } |
|
| 2772 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2773 | + if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2774 | + ksort($variation_attribute_ordered); |
|
| 2775 | + foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2776 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2777 | + } |
|
| 2778 | + } |
|
| 2779 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2780 | + $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2781 | + if ($from_admin && !empty($order_id)) { |
|
| 2782 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2783 | + $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2784 | + } |
|
| 2785 | + $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2786 | + |
|
| 2787 | + return $output; |
|
| 2788 | + } |
|
| 2789 | + |
|
| 2790 | + public static function get_parent_variation($variation_id) |
|
| 2791 | + { |
|
| 2792 | + $result = array(); |
|
| 2793 | + if (!empty($variation_id)) { |
|
| 2794 | + $variation_post = get_post($variation_id); |
|
| 2795 | + if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2796 | + $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2797 | + $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2798 | + } |
|
| 2799 | + } |
|
| 2800 | + return $result; |
|
| 2801 | + } |
|
| 2802 | + |
|
| 2803 | + /** |
|
| 2804 | + * Display the current configuration for a given product |
|
| 2805 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2806 | + */ |
|
| 2807 | + public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2808 | + { |
|
| 2809 | + $output = ''; |
|
| 2810 | + |
|
| 2811 | + $product_variations_selection_args = array( |
|
| 2812 | + 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2813 | + 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2814 | + ); |
|
| 2815 | + |
|
| 2816 | + $current_user_id = get_current_user_id(); |
|
| 2817 | + |
|
| 2818 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2819 | + foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2820 | + if (!empty($item) && !empty($item['item_id'])) { |
|
| 2821 | + |
|
| 2822 | + $free_variations = array(); |
|
| 2823 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2824 | + foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2825 | + $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2826 | + } |
|
| 2827 | + } |
|
| 2851 | 2828 | |
| 2852 | - /** |
|
| 2853 | - * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2854 | - * |
|
| 2855 | - * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2856 | - * @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 |
|
| 2857 | - * @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 |
|
| 2858 | - * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2859 | - * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2860 | - * |
|
| 2861 | - * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2862 | - */ |
|
| 2863 | - public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2864 | - { |
|
| 2865 | - global $wpdb; |
|
| 2866 | - |
|
| 2867 | - $wpshop_cart = new wps_cart(); |
|
| 2868 | - $wpshop_products = new wpshop_products(); |
|
| 2869 | - |
|
| 2870 | - $response = ''; |
|
| 2871 | - $response_status = $has_variation = false; |
|
| 2872 | - $tpl_component = array(); |
|
| 2873 | - |
|
| 2874 | - // Check if variations exists |
|
| 2875 | - if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2876 | - |
|
| 2877 | - //Recover all selected variations |
|
| 2878 | - $variations_selected = array(); |
|
| 2879 | - if (!empty($wpshop_variation_selected)) { |
|
| 2880 | - foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2881 | - $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2882 | - $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2883 | - } |
|
| 2884 | - } |
|
| 2885 | - |
|
| 2886 | - // Check variations priority |
|
| 2887 | - $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2888 | - |
|
| 2889 | - // Check if $product_with_variation have variations |
|
| 2890 | - if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2891 | - |
|
| 2892 | - $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2893 | - $product_to_add_to_cart = $formatted_product[0]; |
|
| 2894 | - foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2895 | - $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2896 | - |
|
| 2897 | - /** For product with variation */ |
|
| 2898 | - $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2899 | - $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2900 | - $order_items[$pid]['product_variation'] = ''; |
|
| 2901 | - if (!empty($product_more_content['variations'])) { |
|
| 2902 | - foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2903 | - $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2904 | - } |
|
| 2905 | - } |
|
| 2906 | - } |
|
| 2907 | - |
|
| 2908 | - // If Product list is not empty, add products to order |
|
| 2909 | - if (!empty($order_items)) { |
|
| 2910 | - foreach ($order_items as $product_id => $d) { |
|
| 2911 | - $product_key = $product_id; |
|
| 2912 | - |
|
| 2913 | - // Formate datas |
|
| 2914 | - $product_id = $head_product_id = $d['product_id']; |
|
| 2915 | - $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2916 | - |
|
| 2917 | - // If product is a single variation product |
|
| 2918 | - if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2919 | - $product_id = $product_variation[0]; |
|
| 2920 | - } |
|
| 2921 | - |
|
| 2922 | - // Construct final product |
|
| 2923 | - $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2924 | - $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2829 | + $variations = array(); |
|
| 2830 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2831 | + foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2832 | + |
|
| 2833 | + if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2834 | + foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2835 | + $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2836 | + } |
|
| 2837 | + } |
|
| 2838 | + } |
|
| 2839 | + } |
|
| 2840 | + $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2841 | + |
|
| 2842 | + $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2843 | + } |
|
| 2844 | + } |
|
| 2845 | + } |
|
| 2846 | + |
|
| 2847 | + $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2848 | + |
|
| 2849 | + echo $output; |
|
| 2850 | + } |
|
| 2851 | + |
|
| 2852 | + /** |
|
| 2853 | + * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2854 | + * |
|
| 2855 | + * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2856 | + * @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 |
|
| 2857 | + * @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 |
|
| 2858 | + * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2859 | + * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2860 | + * |
|
| 2861 | + * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2862 | + */ |
|
| 2863 | + public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2864 | + { |
|
| 2865 | + global $wpdb; |
|
| 2866 | + |
|
| 2867 | + $wpshop_cart = new wps_cart(); |
|
| 2868 | + $wpshop_products = new wpshop_products(); |
|
| 2869 | + |
|
| 2870 | + $response = ''; |
|
| 2871 | + $response_status = $has_variation = false; |
|
| 2872 | + $tpl_component = array(); |
|
| 2873 | + |
|
| 2874 | + // Check if variations exists |
|
| 2875 | + if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2876 | + |
|
| 2877 | + //Recover all selected variations |
|
| 2878 | + $variations_selected = array(); |
|
| 2879 | + if (!empty($wpshop_variation_selected)) { |
|
| 2880 | + foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2881 | + $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2882 | + $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2883 | + } |
|
| 2884 | + } |
|
| 2885 | + |
|
| 2886 | + // Check variations priority |
|
| 2887 | + $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2888 | + |
|
| 2889 | + // Check if $product_with_variation have variations |
|
| 2890 | + if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2891 | + |
|
| 2892 | + $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2893 | + $product_to_add_to_cart = $formatted_product[0]; |
|
| 2894 | + foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2895 | + $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2896 | + |
|
| 2897 | + /** For product with variation */ |
|
| 2898 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2899 | + $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2900 | + $order_items[$pid]['product_variation'] = ''; |
|
| 2901 | + if (!empty($product_more_content['variations'])) { |
|
| 2902 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2903 | + $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2904 | + } |
|
| 2905 | + } |
|
| 2906 | + } |
|
| 2907 | + |
|
| 2908 | + // If Product list is not empty, add products to order |
|
| 2909 | + if (!empty($order_items)) { |
|
| 2910 | + foreach ($order_items as $product_id => $d) { |
|
| 2911 | + $product_key = $product_id; |
|
| 2912 | + |
|
| 2913 | + // Formate datas |
|
| 2914 | + $product_id = $head_product_id = $d['product_id']; |
|
| 2915 | + $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2916 | + |
|
| 2917 | + // If product is a single variation product |
|
| 2918 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2919 | + $product_id = $product_variation[0]; |
|
| 2920 | + } |
|
| 2921 | + |
|
| 2922 | + // Construct final product |
|
| 2923 | + $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2924 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2925 | 2925 | $the_product['text_from'] = $product_with_variation['text_from']; |
| 2926 | 2926 | |
| 2927 | - // Add variation to product into cart for storage |
|
| 2928 | - if (!empty($product_variation)) { |
|
| 2929 | - $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2930 | - } |
|
| 2931 | - |
|
| 2932 | - // Free Variations Checking |
|
| 2933 | - if (!empty($d['free_variation'])) { |
|
| 2934 | - $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2935 | - $head_product_id = $the_product['product_id']; |
|
| 2936 | - } |
|
| 2937 | - |
|
| 2938 | - // If product is a variation, we check parent product general |
|
| 2939 | - if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2940 | - $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2941 | - if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2942 | - $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2943 | - $parent_meta = $parent_def['parent_post_meta']; |
|
| 2944 | - 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) { |
|
| 2945 | - $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2946 | - $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2947 | - $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2948 | - } |
|
| 2949 | - } |
|
| 2950 | - } |
|
| 2951 | - } |
|
| 2952 | - } |
|
| 2953 | - |
|
| 2954 | - if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2955 | - $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2956 | - if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2957 | - $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2958 | - $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2959 | - } |
|
| 2960 | - $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']; |
|
| 2961 | - $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']; |
|
| 2962 | - $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']; |
|
| 2963 | - } |
|
| 2964 | - |
|
| 2965 | - $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2966 | - // Add free variations to product |
|
| 2967 | - if (!empty($wpshop_free_variation)) { |
|
| 2968 | - $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2969 | - } |
|
| 2970 | - // Change picture if have a selected variation |
|
| 2971 | - $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; |
|
| 2972 | - $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2973 | - |
|
| 2974 | - // Price Display |
|
| 2975 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2976 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2977 | - $productPrice = ''; |
|
| 2978 | - if ($price_display) { |
|
| 2979 | - $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2980 | - } |
|
| 2981 | - |
|
| 2982 | - //Get Summary cart |
|
| 2983 | - $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2984 | - $response_status = true; |
|
| 2985 | - } else { |
|
| 2986 | - //Product without variations |
|
| 2987 | - $product_data = wpshop_products::get_product_data($product_id); |
|
| 2988 | - $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2989 | - } |
|
| 2990 | - } |
|
| 2927 | + // Add variation to product into cart for storage |
|
| 2928 | + if (!empty($product_variation)) { |
|
| 2929 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2930 | + } |
|
| 2931 | + |
|
| 2932 | + // Free Variations Checking |
|
| 2933 | + if (!empty($d['free_variation'])) { |
|
| 2934 | + $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2935 | + $head_product_id = $the_product['product_id']; |
|
| 2936 | + } |
|
| 2937 | + |
|
| 2938 | + // If product is a variation, we check parent product general |
|
| 2939 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2940 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2941 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2942 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2943 | + $parent_meta = $parent_def['parent_post_meta']; |
|
| 2944 | + 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) { |
|
| 2945 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2946 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2947 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2948 | + } |
|
| 2949 | + } |
|
| 2950 | + } |
|
| 2951 | + } |
|
| 2952 | + } |
|
| 2991 | 2953 | |
| 2992 | - return array($response_status, $response); |
|
| 2993 | - } |
|
| 2954 | + if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2955 | + $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2956 | + if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2957 | + $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2958 | + $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2959 | + } |
|
| 2960 | + $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']; |
|
| 2961 | + $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']; |
|
| 2962 | + $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']; |
|
| 2963 | + } |
|
| 2994 | 2964 | |
| 2995 | - /** |
|
| 2996 | - * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2997 | - * |
|
| 2998 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2999 | - */ |
|
| 3000 | - public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 3001 | - { |
|
| 3002 | - echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 3003 | - } |
|
| 2965 | + $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2966 | + // Add free variations to product |
|
| 2967 | + if (!empty($wpshop_free_variation)) { |
|
| 2968 | + $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2969 | + } |
|
| 2970 | + // Change picture if have a selected variation |
|
| 2971 | + $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; |
|
| 2972 | + $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2973 | + |
|
| 2974 | + // Price Display |
|
| 2975 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2976 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2977 | + $productPrice = ''; |
|
| 2978 | + if ($price_display) { |
|
| 2979 | + $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2980 | + } |
|
| 3004 | 2981 | |
| 3005 | - /** |
|
| 3006 | - * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 3007 | - * |
|
| 3008 | - * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 3009 | - * @param integer $product_id The basic product choose by the user in frontend |
|
| 3010 | - * |
|
| 3011 | - * @return array The product list for adding to the cart build by variation priority |
|
| 3012 | - */ |
|
| 3013 | - public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 3014 | - { |
|
| 3015 | - global $wpdb; |
|
| 3016 | - $all_required_variations_selected = $no_selected_variation = true; |
|
| 3017 | - $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 3018 | - |
|
| 3019 | - // Check if all required variations are selected |
|
| 3020 | - $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 3021 | - foreach ($selected_variation as $k => $value) { |
|
| 3022 | - if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 3023 | - $all_required_variations_selected = false; |
|
| 3024 | - } |
|
| 3025 | - if ($value != 0) { |
|
| 3026 | - $no_selected_variation = false; |
|
| 3027 | - } |
|
| 3028 | - } |
|
| 3029 | - if (!empty($selected_variation)) { |
|
| 3030 | - //Check variations configuration |
|
| 3031 | - $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 3032 | - // Check variations type |
|
| 3033 | - $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 3034 | - $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 3035 | - |
|
| 3036 | - //Check defined variation priority |
|
| 3037 | - $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 3038 | - $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 3039 | - |
|
| 3040 | - // Recover all product variations |
|
| 3041 | - $query_variation = $selected_variation; |
|
| 3042 | - // Delete free variations |
|
| 3043 | - unset($query_variation['free']); |
|
| 3044 | - |
|
| 3045 | - if ($product_variation_type == 'single') { |
|
| 3046 | - // Get single variations |
|
| 3047 | - $single_variations = array(); |
|
| 3048 | - foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 3049 | - if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 3050 | - $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); |
|
| 3051 | - $single_variation_id = $wpdb->get_var($query); |
|
| 3052 | - if (!empty($single_variation_id)) { |
|
| 3053 | - $single_variations[] = $single_variation_id; |
|
| 3054 | - unset($query_variation[$attribute_code]); |
|
| 3055 | - } |
|
| 3056 | - } |
|
| 3057 | - } |
|
| 3058 | - } else { |
|
| 3059 | - // Get combined variations |
|
| 3060 | - $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); |
|
| 3061 | - $combined_variation_id = $wpdb->get_var($query); |
|
| 3062 | - if (!empty($combined_variation_id)) { |
|
| 3063 | - $combined_variations[] = $combined_variation_id; |
|
| 3064 | - } |
|
| 3065 | - |
|
| 3066 | - } |
|
| 3067 | - |
|
| 3068 | - //If all required variations are not selected |
|
| 3069 | - if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3070 | - $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3071 | - // If we choose to display lower price variation combinaison |
|
| 3072 | - 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']))) { |
|
| 3073 | - //Get lower price variation combinaison |
|
| 3074 | - $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3075 | - if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3076 | - foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3077 | - $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3078 | - } |
|
| 3079 | - } |
|
| 3080 | - $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3081 | - } else { |
|
| 3082 | - $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3083 | - } |
|
| 3084 | - } else { |
|
| 3085 | - $product_to_add_to_cart['text_from'] = ''; |
|
| 3086 | - $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3087 | - } |
|
| 3088 | - } |
|
| 2982 | + //Get Summary cart |
|
| 2983 | + $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2984 | + $response_status = true; |
|
| 2985 | + } else { |
|
| 2986 | + //Product without variations |
|
| 2987 | + $product_data = wpshop_products::get_product_data($product_id); |
|
| 2988 | + $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2989 | + } |
|
| 2990 | + } |
|
| 3089 | 2991 | |
| 3090 | - return $product_to_add_to_cart; |
|
| 3091 | - } |
|
| 2992 | + return array($response_status, $response); |
|
| 2993 | + } |
|
| 3092 | 2994 | |
| 3093 | - public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3094 | - { |
|
| 3095 | - global $wpdb; |
|
| 3096 | - |
|
| 3097 | - if (!empty($product_variations)) { |
|
| 3098 | - // Initialize variations total price datas |
|
| 3099 | - $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3100 | - $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3101 | - $vat_rate = 0; |
|
| 3102 | - $discount_amount = $discount_rate = $special_price = 0; |
|
| 3103 | - // Recover Head product metadata |
|
| 3104 | - $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3105 | - $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3106 | - if (!empty($tva_rate_id)) { |
|
| 3107 | - // Recover VAT Rate of product |
|
| 3108 | - $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3109 | - $vat_rate = $wpdb->get_var($query); |
|
| 3110 | - } |
|
| 3111 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3112 | - foreach ($product_variations as $product_variation) { |
|
| 3113 | - $variation_metadata['product_price'] = 0; |
|
| 3114 | - $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3115 | - if (!empty($variation_metadata)) { |
|
| 3116 | - $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']); |
|
| 3117 | - $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)))); |
|
| 3118 | - |
|
| 3119 | - $variations_total_price['price_et'] += $p_et; |
|
| 3120 | - $variations_total_price['price_ati'] += $p_ati; |
|
| 3121 | - $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3122 | - |
|
| 3123 | - $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3124 | - |
|
| 3125 | - // Check discount |
|
| 3126 | - $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3127 | - if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3128 | - $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3129 | - $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3130 | - $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3131 | - $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3132 | - |
|
| 3133 | - if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3134 | - $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3135 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3136 | - $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3137 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3138 | - $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3139 | - } |
|
| 3140 | - } |
|
| 3141 | - |
|
| 3142 | - $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3143 | - $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3144 | - } |
|
| 3145 | - } |
|
| 3146 | - |
|
| 3147 | - // Check if add or replace variation price to head product |
|
| 3148 | - /** |
|
| 3149 | - * Since 1.4.3.7 |
|
| 3150 | - * L'option du produit remplace le prix du produit de tête. |
|
| 3151 | - */ |
|
| 2995 | + /** |
|
| 2996 | + * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2997 | + * |
|
| 2998 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2999 | + */ |
|
| 3000 | + public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 3001 | + { |
|
| 3002 | + echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 3003 | + } |
|
| 3004 | + |
|
| 3005 | + /** |
|
| 3006 | + * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 3007 | + * |
|
| 3008 | + * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 3009 | + * @param integer $product_id The basic product choose by the user in frontend |
|
| 3010 | + * |
|
| 3011 | + * @return array The product list for adding to the cart build by variation priority |
|
| 3012 | + */ |
|
| 3013 | + public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 3014 | + { |
|
| 3015 | + global $wpdb; |
|
| 3016 | + $all_required_variations_selected = $no_selected_variation = true; |
|
| 3017 | + $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 3018 | + |
|
| 3019 | + // Check if all required variations are selected |
|
| 3020 | + $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 3021 | + foreach ($selected_variation as $k => $value) { |
|
| 3022 | + if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 3023 | + $all_required_variations_selected = false; |
|
| 3024 | + } |
|
| 3025 | + if ($value != 0) { |
|
| 3026 | + $no_selected_variation = false; |
|
| 3027 | + } |
|
| 3028 | + } |
|
| 3029 | + if (!empty($selected_variation)) { |
|
| 3030 | + //Check variations configuration |
|
| 3031 | + $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 3032 | + // Check variations type |
|
| 3033 | + $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 3034 | + $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 3035 | + |
|
| 3036 | + //Check defined variation priority |
|
| 3037 | + $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 3038 | + $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 3039 | + |
|
| 3040 | + // Recover all product variations |
|
| 3041 | + $query_variation = $selected_variation; |
|
| 3042 | + // Delete free variations |
|
| 3043 | + unset($query_variation['free']); |
|
| 3044 | + |
|
| 3045 | + if ($product_variation_type == 'single') { |
|
| 3046 | + // Get single variations |
|
| 3047 | + $single_variations = array(); |
|
| 3048 | + foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 3049 | + if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 3050 | + $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); |
|
| 3051 | + $single_variation_id = $wpdb->get_var($query); |
|
| 3052 | + if (!empty($single_variation_id)) { |
|
| 3053 | + $single_variations[] = $single_variation_id; |
|
| 3054 | + unset($query_variation[$attribute_code]); |
|
| 3055 | + } |
|
| 3056 | + } |
|
| 3057 | + } |
|
| 3058 | + } else { |
|
| 3059 | + // Get combined variations |
|
| 3060 | + $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); |
|
| 3061 | + $combined_variation_id = $wpdb->get_var($query); |
|
| 3062 | + if (!empty($combined_variation_id)) { |
|
| 3063 | + $combined_variations[] = $combined_variation_id; |
|
| 3064 | + } |
|
| 3065 | + |
|
| 3066 | + } |
|
| 3067 | + |
|
| 3068 | + //If all required variations are not selected |
|
| 3069 | + if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3070 | + $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3071 | + // If we choose to display lower price variation combinaison |
|
| 3072 | + 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']))) { |
|
| 3073 | + //Get lower price variation combinaison |
|
| 3074 | + $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3075 | + if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3076 | + foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3077 | + $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3078 | + } |
|
| 3079 | + } |
|
| 3080 | + $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3081 | + } else { |
|
| 3082 | + $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3083 | + } |
|
| 3084 | + } else { |
|
| 3085 | + $product_to_add_to_cart['text_from'] = ''; |
|
| 3086 | + $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3087 | + } |
|
| 3088 | + } |
|
| 3089 | + |
|
| 3090 | + return $product_to_add_to_cart; |
|
| 3091 | + } |
|
| 3092 | + |
|
| 3093 | + public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3094 | + { |
|
| 3095 | + global $wpdb; |
|
| 3096 | + |
|
| 3097 | + if (!empty($product_variations)) { |
|
| 3098 | + // Initialize variations total price datas |
|
| 3099 | + $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3100 | + $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3101 | + $vat_rate = 0; |
|
| 3102 | + $discount_amount = $discount_rate = $special_price = 0; |
|
| 3103 | + // Recover Head product metadata |
|
| 3104 | + $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3105 | + $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3106 | + if (!empty($tva_rate_id)) { |
|
| 3107 | + // Recover VAT Rate of product |
|
| 3108 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3109 | + $vat_rate = $wpdb->get_var($query); |
|
| 3110 | + } |
|
| 3111 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3112 | + foreach ($product_variations as $product_variation) { |
|
| 3113 | + $variation_metadata['product_price'] = 0; |
|
| 3114 | + $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3115 | + if (!empty($variation_metadata)) { |
|
| 3116 | + $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']); |
|
| 3117 | + $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)))); |
|
| 3118 | + |
|
| 3119 | + $variations_total_price['price_et'] += $p_et; |
|
| 3120 | + $variations_total_price['price_ati'] += $p_ati; |
|
| 3121 | + $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3122 | + |
|
| 3123 | + $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3124 | + |
|
| 3125 | + // Check discount |
|
| 3126 | + $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3127 | + if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3128 | + $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3129 | + $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3130 | + $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3131 | + $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3132 | + |
|
| 3133 | + if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3134 | + $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3135 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3136 | + $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3137 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3138 | + $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3139 | + } |
|
| 3140 | + } |
|
| 3141 | + |
|
| 3142 | + $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3143 | + $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3144 | + } |
|
| 3145 | + } |
|
| 3146 | + |
|
| 3147 | + // Check if add or replace variation price to head product |
|
| 3148 | + /** |
|
| 3149 | + * Since 1.4.3.7 |
|
| 3150 | + * L'option du produit remplace le prix du produit de tête. |
|
| 3151 | + */ |
|
| 3152 | 3152 | if( true ) { |
| 3153 | - //Replace the product price |
|
| 3154 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3155 | - $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3156 | - $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3157 | - |
|
| 3158 | - $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3159 | - $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3160 | - $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3161 | - } else { |
|
| 3162 | - $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3163 | - $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3164 | - $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3165 | - } |
|
| 3166 | - } else { |
|
| 3167 | - // Add variations price to product price |
|
| 3168 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3169 | - $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3170 | - $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3171 | - |
|
| 3172 | - $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3173 | - $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3174 | - $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3175 | - } else { |
|
| 3176 | - $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3177 | - $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3178 | - $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3179 | - } |
|
| 3180 | - // Check parent discount |
|
| 3181 | - $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3182 | - if (!empty($parent_discount_config)) { |
|
| 3183 | - $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']; |
|
| 3184 | - $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']; |
|
| 3185 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3186 | - |
|
| 3187 | - if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3188 | - $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3189 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3190 | - $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3191 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3192 | - $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3193 | - } |
|
| 3194 | - } |
|
| 3195 | - } |
|
| 3196 | - } else { |
|
| 3197 | - // If product have just Free variations |
|
| 3198 | - $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3199 | - if (!empty($discount_config)) { |
|
| 3200 | - $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']; |
|
| 3201 | - $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']; |
|
| 3202 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3203 | - } |
|
| 3204 | - } |
|
| 3153 | + //Replace the product price |
|
| 3154 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3155 | + $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3156 | + $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3157 | + |
|
| 3158 | + $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3159 | + $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3160 | + $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3161 | + } else { |
|
| 3162 | + $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3163 | + $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3164 | + $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3165 | + } |
|
| 3166 | + } else { |
|
| 3167 | + // Add variations price to product price |
|
| 3168 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3169 | + $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3170 | + $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3171 | + |
|
| 3172 | + $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3173 | + $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3174 | + $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3175 | + } else { |
|
| 3176 | + $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3177 | + $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3178 | + $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3179 | + } |
|
| 3180 | + // Check parent discount |
|
| 3181 | + $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3182 | + if (!empty($parent_discount_config)) { |
|
| 3183 | + $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']; |
|
| 3184 | + $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']; |
|
| 3185 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3186 | + |
|
| 3187 | + if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3188 | + $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3189 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3190 | + $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3191 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3192 | + $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3193 | + } |
|
| 3194 | + } |
|
| 3195 | + } |
|
| 3196 | + } else { |
|
| 3197 | + // If product have just Free variations |
|
| 3198 | + $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3199 | + if (!empty($discount_config)) { |
|
| 3200 | + $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']; |
|
| 3201 | + $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']; |
|
| 3202 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3203 | + } |
|
| 3204 | + } |
|
| 3205 | 3205 | |
| 3206 | - // Text From indicator |
|
| 3207 | - if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3208 | - $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3209 | - } |
|
| 3210 | - return $product_into_cart; |
|
| 3211 | - } |
|
| 3206 | + // Text From indicator |
|
| 3207 | + if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3208 | + $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3209 | + } |
|
| 3210 | + return $product_into_cart; |
|
| 3211 | + } |
|
| 3212 | 3212 | |
| 3213 | - /** |
|
| 3214 | - * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3215 | - * |
|
| 3216 | - * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3217 | - * @param array $output_order The good order for attribute defined by administrator |
|
| 3218 | - * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3219 | - * |
|
| 3220 | - * @return array The array containing all product options ordered as the admin configure it |
|
| 3221 | - */ |
|
| 3222 | - public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3223 | - { |
|
| 3224 | - $variation_attribute_ordered = array(); |
|
| 3225 | - $variation_attribute_ordered['prices'] = array(); |
|
| 3226 | - $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3227 | - |
|
| 3228 | - if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3229 | - foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3230 | - $variation_tpl_component = array(); |
|
| 3231 | - foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3232 | - $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); |
|
| 3233 | - } |
|
| 3234 | - $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3235 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3236 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3237 | - $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); |
|
| 3238 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3239 | - $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3240 | - } |
|
| 3241 | - } else { |
|
| 3242 | - $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); |
|
| 3243 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3244 | - $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3245 | - } |
|
| 3246 | - } |
|
| 3247 | - unset($variation_tpl_component); |
|
| 3248 | - } |
|
| 3249 | - } |
|
| 3213 | + /** |
|
| 3214 | + * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3215 | + * |
|
| 3216 | + * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3217 | + * @param array $output_order The good order for attribute defined by administrator |
|
| 3218 | + * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3219 | + * |
|
| 3220 | + * @return array The array containing all product options ordered as the admin configure it |
|
| 3221 | + */ |
|
| 3222 | + public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3223 | + { |
|
| 3224 | + $variation_attribute_ordered = array(); |
|
| 3225 | + $variation_attribute_ordered['prices'] = array(); |
|
| 3226 | + $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3227 | + |
|
| 3228 | + if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3229 | + foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3230 | + $variation_tpl_component = array(); |
|
| 3231 | + foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3232 | + $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); |
|
| 3233 | + } |
|
| 3234 | + $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3235 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3236 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3237 | + $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); |
|
| 3238 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3239 | + $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3240 | + } |
|
| 3241 | + } else { |
|
| 3242 | + $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); |
|
| 3243 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3244 | + $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3245 | + } |
|
| 3246 | + } |
|
| 3247 | + unset($variation_tpl_component); |
|
| 3248 | + } |
|
| 3249 | + } |
|
| 3250 | 3250 | |
| 3251 | - if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3252 | - foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3253 | - $variation_tpl_component = array(); |
|
| 3254 | - foreach ($variation_details as $info_name => $info_value) { |
|
| 3255 | - if ($info_name != 'item_meta') { |
|
| 3256 | - $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); |
|
| 3257 | - } |
|
| 3258 | - } |
|
| 3259 | - foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3260 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3261 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3262 | - $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3263 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3264 | - |
|
| 3265 | - $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3266 | - } |
|
| 3267 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3268 | - $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); |
|
| 3269 | - } |
|
| 3270 | - unset($variation_tpl_component); |
|
| 3271 | - } |
|
| 3272 | - } |
|
| 3251 | + if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3252 | + foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3253 | + $variation_tpl_component = array(); |
|
| 3254 | + foreach ($variation_details as $info_name => $info_value) { |
|
| 3255 | + if ($info_name != 'item_meta') { |
|
| 3256 | + $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); |
|
| 3257 | + } |
|
| 3258 | + } |
|
| 3259 | + foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3260 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3261 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3262 | + $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3263 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3273 | 3264 | |
| 3274 | - /** Free Variation part */ |
|
| 3275 | - if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3276 | - foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3277 | - if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3278 | - $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3279 | - $attribute_code = $variation_definition[0]; |
|
| 3280 | - $attribute_selected_value = $variation_definition[1]; |
|
| 3281 | - } else { |
|
| 3282 | - $attribute_code = $build_variation_key; |
|
| 3283 | - $attribute_selected_value = $build_variation; |
|
| 3284 | - } |
|
| 3285 | - |
|
| 3286 | - $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3287 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3288 | - $value_to_outut = $attribute_selected_value; |
|
| 3289 | - switch ($free_variation_attribute_def->data_type) { |
|
| 3290 | - case 'datetime': |
|
| 3291 | - $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3292 | - break; |
|
| 3293 | - } |
|
| 3294 | - |
|
| 3295 | - if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3296 | - switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3297 | - case 'custom': |
|
| 3298 | - case 'internal': |
|
| 3299 | - $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3300 | - $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3301 | - break; |
|
| 3302 | - } |
|
| 3303 | - } |
|
| 3304 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3305 | - $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3306 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3307 | - if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3308 | - $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); |
|
| 3309 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3310 | - $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3311 | - } |
|
| 3312 | - } |
|
| 3313 | - unset($variation_tpl_component); |
|
| 3314 | - } |
|
| 3315 | - } |
|
| 3316 | - return $variation_attribute_ordered; |
|
| 3317 | - } |
|
| 3265 | + $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3266 | + } |
|
| 3267 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3268 | + $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); |
|
| 3269 | + } |
|
| 3270 | + unset($variation_tpl_component); |
|
| 3271 | + } |
|
| 3272 | + } |
|
| 3318 | 3273 | |
| 3319 | - public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3320 | - { |
|
| 3321 | - $response = array(); |
|
| 3322 | - /** Selected Product image **/ |
|
| 3323 | - $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3324 | - if (!empty($post_thumbnail_id)) { |
|
| 3325 | - $response['img_id'] = $post_thumbnail_id; |
|
| 3326 | - $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3327 | - $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3328 | - } |
|
| 3274 | + /** Free Variation part */ |
|
| 3275 | + if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3276 | + foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3277 | + if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3278 | + $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3279 | + $attribute_code = $variation_definition[0]; |
|
| 3280 | + $attribute_selected_value = $variation_definition[1]; |
|
| 3281 | + } else { |
|
| 3282 | + $attribute_code = $build_variation_key; |
|
| 3283 | + $attribute_selected_value = $build_variation; |
|
| 3284 | + } |
|
| 3329 | 3285 | |
| 3330 | - /** check if have one variation **/ |
|
| 3331 | - if (!empty($variations) && count($variations) == 1) { |
|
| 3332 | - $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3333 | - if (!empty($variation_attached_image_id)) { |
|
| 3334 | - $response['img_id'] = $variation_attached_image_id; |
|
| 3335 | - $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3336 | - $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3337 | - } |
|
| 3338 | - } |
|
| 3339 | - return $response; |
|
| 3340 | - } |
|
| 3286 | + $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3287 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3288 | + $value_to_outut = $attribute_selected_value; |
|
| 3289 | + switch ($free_variation_attribute_def->data_type) { |
|
| 3290 | + case 'datetime': |
|
| 3291 | + $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3292 | + break; |
|
| 3293 | + } |
|
| 3341 | 3294 | |
| 3342 | - /** Add a meta box of product sales history in product administration panel **/ |
|
| 3343 | - public function meta_box_product_sale_informations() |
|
| 3344 | - { |
|
| 3345 | - global $post; |
|
| 3346 | - $product_id = $post->ID; |
|
| 3347 | - |
|
| 3348 | - $variations = self::get_variation($product_id); |
|
| 3349 | - |
|
| 3350 | - $sales_informations = array(); |
|
| 3351 | - /** Query **/ |
|
| 3352 | - $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3353 | - $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'))); |
|
| 3354 | - $orders = new WP_Query($query_args); |
|
| 3355 | - if (!empty($orders) && !empty($orders->posts)) { |
|
| 3356 | - foreach ($orders->posts as $order) { |
|
| 3357 | - $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3358 | - $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3359 | - $sales_informations[] = array( |
|
| 3360 | - 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3361 | - 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3362 | - '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'] : '', |
|
| 3363 | - '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'] : '', |
|
| 3364 | - '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'] : '', |
|
| 3365 | - ); |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3295 | + if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3296 | + switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3297 | + case 'custom': |
|
| 3298 | + case 'internal': |
|
| 3299 | + $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3300 | + $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3301 | + break; |
|
| 3302 | + } |
|
| 3303 | + } |
|
| 3304 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3305 | + $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3306 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3307 | + if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3308 | + $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); |
|
| 3309 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3310 | + $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3311 | + } |
|
| 3312 | + } |
|
| 3313 | + unset($variation_tpl_component); |
|
| 3314 | + } |
|
| 3315 | + } |
|
| 3316 | + return $variation_attribute_ordered; |
|
| 3317 | + } |
|
| 3368 | 3318 | |
| 3369 | - /** If product has been ordered **/ |
|
| 3370 | - $output = ''; |
|
| 3371 | - if (!empty($sales_informations)) { |
|
| 3372 | - $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3373 | - $output .= '<ul>'; |
|
| 3374 | - foreach ($sales_informations as $sales_information) { |
|
| 3375 | - $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>'; |
|
| 3376 | - } |
|
| 3377 | - $output .= '</ul>'; |
|
| 3378 | - } else { |
|
| 3379 | - $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3380 | - } |
|
| 3319 | + public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3320 | + { |
|
| 3321 | + $response = array(); |
|
| 3322 | + /** Selected Product image **/ |
|
| 3323 | + $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3324 | + if (!empty($post_thumbnail_id)) { |
|
| 3325 | + $response['img_id'] = $post_thumbnail_id; |
|
| 3326 | + $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3327 | + $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3328 | + } |
|
| 3381 | 3329 | |
| 3382 | - echo $output; |
|
| 3383 | - } |
|
| 3330 | + /** check if have one variation **/ |
|
| 3331 | + if (!empty($variations) && count($variations) == 1) { |
|
| 3332 | + $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3333 | + if (!empty($variation_attached_image_id)) { |
|
| 3334 | + $response['img_id'] = $variation_attached_image_id; |
|
| 3335 | + $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3336 | + $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3337 | + } |
|
| 3338 | + } |
|
| 3339 | + return $response; |
|
| 3340 | + } |
|
| 3384 | 3341 | |
| 3385 | - public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3386 | - { |
|
| 3387 | - global $wpdb, $wpshop_payment; |
|
| 3388 | - $output = ''; |
|
| 3389 | - $tpl_component = array(); |
|
| 3390 | - /** Get attribute order for current product */ |
|
| 3391 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3392 | - $output_order = array(); |
|
| 3393 | - if (count($product_attribute_order_detail) > 0) { |
|
| 3394 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3395 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3396 | - if (!empty($attribute_def->code)) { |
|
| 3397 | - $output_order[$attribute_def->code] = $position; |
|
| 3398 | - } |
|
| 3399 | - |
|
| 3400 | - } |
|
| 3401 | - } |
|
| 3402 | - } |
|
| 3403 | - $variation_attribute_ordered = array(); |
|
| 3404 | - |
|
| 3405 | - /** Check if product is a variation and change his name **/ |
|
| 3406 | - $product_post_type = get_post_type($the_product['product_id']); |
|
| 3407 | - if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3408 | - $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3409 | - $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3410 | - $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3411 | - } |
|
| 3342 | + /** Add a meta box of product sales history in product administration panel **/ |
|
| 3343 | + public function meta_box_product_sale_informations() |
|
| 3344 | + { |
|
| 3345 | + global $post; |
|
| 3346 | + $product_id = $post->ID; |
|
| 3347 | + |
|
| 3348 | + $variations = self::get_variation($product_id); |
|
| 3349 | + |
|
| 3350 | + $sales_informations = array(); |
|
| 3351 | + /** Query **/ |
|
| 3352 | + $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3353 | + $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'))); |
|
| 3354 | + $orders = new WP_Query($query_args); |
|
| 3355 | + if (!empty($orders) && !empty($orders->posts)) { |
|
| 3356 | + foreach ($orders->posts as $order) { |
|
| 3357 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3358 | + $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3359 | + $sales_informations[] = array( |
|
| 3360 | + 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3361 | + 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3362 | + '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'] : '', |
|
| 3363 | + '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'] : '', |
|
| 3364 | + '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'] : '', |
|
| 3365 | + ); |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3412 | 3368 | |
| 3413 | - foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3414 | - if ($product_definition_key != 'item_meta') { |
|
| 3415 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3416 | - if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3417 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3418 | - } |
|
| 3419 | - } else { |
|
| 3420 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3421 | - } |
|
| 3422 | - } |
|
| 3369 | + /** If product has been ordered **/ |
|
| 3370 | + $output = ''; |
|
| 3371 | + if (!empty($sales_informations)) { |
|
| 3372 | + $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3373 | + $output .= '<ul>'; |
|
| 3374 | + foreach ($sales_informations as $sales_information) { |
|
| 3375 | + $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>'; |
|
| 3376 | + } |
|
| 3377 | + $output .= '</ul>'; |
|
| 3378 | + } else { |
|
| 3379 | + $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3380 | + } |
|
| 3423 | 3381 | |
| 3424 | - ksort($variation_attribute_ordered['attribute_list']); |
|
| 3425 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3426 | - foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3427 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3428 | - } |
|
| 3382 | + echo $output; |
|
| 3383 | + } |
|
| 3429 | 3384 | |
| 3430 | - /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3431 | - $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3432 | - if (!empty($attribute_list)) { |
|
| 3433 | - foreach ($attribute_list as $attribute_def) { |
|
| 3434 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3435 | - } |
|
| 3436 | - } |
|
| 3385 | + public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3386 | + { |
|
| 3387 | + global $wpdb, $wpshop_payment; |
|
| 3388 | + $output = ''; |
|
| 3389 | + $tpl_component = array(); |
|
| 3390 | + /** Get attribute order for current product */ |
|
| 3391 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3392 | + $output_order = array(); |
|
| 3393 | + if (count($product_attribute_order_detail) > 0) { |
|
| 3394 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3395 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3396 | + if (!empty($attribute_def->code)) { |
|
| 3397 | + $output_order[$attribute_def->code] = $position; |
|
| 3398 | + } |
|
| 3437 | 3399 | |
| 3438 | - /** Fill the array with all prices for different variations */ |
|
| 3439 | - foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3440 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3441 | - } |
|
| 3400 | + } |
|
| 3401 | + } |
|
| 3402 | + } |
|
| 3403 | + $variation_attribute_ordered = array(); |
|
| 3404 | + |
|
| 3405 | + /** Check if product is a variation and change his name **/ |
|
| 3406 | + $product_post_type = get_post_type($the_product['product_id']); |
|
| 3407 | + if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3408 | + $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3409 | + $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3410 | + $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3411 | + } |
|
| 3442 | 3412 | |
| 3443 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3444 | - $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3445 | - $post_list_with_options = $wpdb->get_results($query); |
|
| 3446 | - if (!empty($post_list_with_options)) { |
|
| 3447 | - $additionnal_price = 0; |
|
| 3448 | - foreach ($post_list_with_options as $product_info) { |
|
| 3449 | - $product_meta = unserialize($product_info->meta_value); |
|
| 3450 | - if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3451 | - $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3452 | - |
|
| 3453 | - $the_product = array_merge(array( |
|
| 3454 | - 'product_id' => $product_info->post_id, |
|
| 3455 | - 'product_qty' => 1, |
|
| 3456 | - ), $product); |
|
| 3457 | - |
|
| 3458 | - $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3459 | - $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3460 | - |
|
| 3461 | - $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)); |
|
| 3462 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3463 | - } |
|
| 3464 | - } |
|
| 3465 | - } |
|
| 3413 | + foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3414 | + if ($product_definition_key != 'item_meta') { |
|
| 3415 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3416 | + if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3417 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3418 | + } |
|
| 3419 | + } else { |
|
| 3420 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3421 | + } |
|
| 3422 | + } |
|
| 3466 | 3423 | |
| 3467 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3468 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3469 | - if (!empty($additionnal_price)) { |
|
| 3470 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3471 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3472 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3473 | - } |
|
| 3424 | + ksort($variation_attribute_ordered['attribute_list']); |
|
| 3425 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3426 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3427 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3428 | + } |
|
| 3429 | + |
|
| 3430 | + /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3431 | + $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3432 | + if (!empty($attribute_list)) { |
|
| 3433 | + foreach ($attribute_list as $attribute_def) { |
|
| 3434 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3435 | + } |
|
| 3436 | + } |
|
| 3437 | + |
|
| 3438 | + /** Fill the array with all prices for different variations */ |
|
| 3439 | + foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3440 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3441 | + } |
|
| 3442 | + |
|
| 3443 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3444 | + $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3445 | + $post_list_with_options = $wpdb->get_results($query); |
|
| 3446 | + if (!empty($post_list_with_options)) { |
|
| 3447 | + $additionnal_price = 0; |
|
| 3448 | + foreach ($post_list_with_options as $product_info) { |
|
| 3449 | + $product_meta = unserialize($product_info->meta_value); |
|
| 3450 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3451 | + $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3452 | + |
|
| 3453 | + $the_product = array_merge(array( |
|
| 3454 | + 'product_id' => $product_info->post_id, |
|
| 3455 | + 'product_qty' => 1, |
|
| 3456 | + ), $product); |
|
| 3457 | + |
|
| 3458 | + $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3459 | + $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3460 | + |
|
| 3461 | + $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)); |
|
| 3462 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3463 | + } |
|
| 3464 | + } |
|
| 3465 | + } |
|
| 3474 | 3466 | |
| 3475 | - /** Call informtion for partial payment */ |
|
| 3476 | - $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3477 | - $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3467 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3468 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3469 | + if (!empty($additionnal_price)) { |
|
| 3470 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3471 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3472 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3473 | + } |
|
| 3478 | 3474 | |
| 3479 | - /** Define the current selected currency for the order summary */ |
|
| 3475 | + /** Call informtion for partial payment */ |
|
| 3476 | + $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3477 | + $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3478 | + |
|
| 3479 | + /** Define the current selected currency for the order summary */ |
|
| 3480 | 3480 | // $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
| 3481 | - $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3482 | - return $output; |
|
| 3483 | - } |
|
| 3481 | + $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3482 | + return $output; |
|
| 3483 | + } |
|
| 3484 | 3484 | |
| 3485 | - /** |
|
| 3486 | - * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3487 | - * @param string $ID ID product variations or not |
|
| 3488 | - * @return string Return ID |
|
| 3489 | - */ |
|
| 3490 | - public static function get_id_variation($ID) |
|
| 3491 | - { |
|
| 3492 | - $result = explode('__', $ID); |
|
| 3493 | - return end($result); |
|
| 3494 | - } |
|
| 3485 | + /** |
|
| 3486 | + * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3487 | + * @param string $ID ID product variations or not |
|
| 3488 | + * @return string Return ID |
|
| 3489 | + */ |
|
| 3490 | + public static function get_id_variation($ID) |
|
| 3491 | + { |
|
| 3492 | + $result = explode('__', $ID); |
|
| 3493 | + return end($result); |
|
| 3494 | + } |
|
| 3495 | 3495 | |
| 3496 | - /** |
|
| 3497 | - * Update all variations definitions who not modified |
|
| 3498 | - * @param array $new_value |
|
| 3499 | - * @param array $old_value |
|
| 3500 | - * @return array $new_value |
|
| 3501 | - */ |
|
| 3502 | - public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3503 | - { |
|
| 3504 | - global $wpdb; |
|
| 3505 | - $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') . '%'); |
|
| 3506 | - foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3507 | - $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3508 | - $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3509 | - update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3510 | - } |
|
| 3511 | - return $new_value; |
|
| 3512 | - } |
|
| 3496 | + /** |
|
| 3497 | + * Update all variations definitions who not modified |
|
| 3498 | + * @param array $new_value |
|
| 3499 | + * @param array $old_value |
|
| 3500 | + * @return array $new_value |
|
| 3501 | + */ |
|
| 3502 | + public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3503 | + { |
|
| 3504 | + global $wpdb; |
|
| 3505 | + $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') . '%'); |
|
| 3506 | + foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3507 | + $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3508 | + $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3509 | + update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3510 | + } |
|
| 3511 | + return $new_value; |
|
| 3512 | + } |
|
| 3513 | 3513 | |
| 3514 | - public static function variation_parameters_save($current_post_id, $options) |
|
| 3515 | - { |
|
| 3514 | + public static function variation_parameters_save($current_post_id, $options) |
|
| 3515 | + { |
|
| 3516 | 3516 | $variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true); |
| 3517 | - $variation_post_meta['options'] = $options; |
|
| 3517 | + $variation_post_meta['options'] = $options; |
|
| 3518 | 3518 | $variation_post_meta['follow_general_config'] = true; |
| 3519 | 3519 | if( $variation_post_meta['follow_general_config'] ) { |
| 3520 | 3520 | $shop_option = get_option('wpshop_catalog_product_option', array()); |
@@ -3530,6 +3530,6 @@ discard block |
||
| 3530 | 3530 | } |
| 3531 | 3531 | } |
| 3532 | 3532 | } |
| 3533 | - update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3534 | - } |
|
| 3533 | + update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3534 | + } |
|
| 3535 | 3535 | } |