/** * * @param integer $current_entity_id The current element edited * @return Ambigous <string, string, mixed> */ public static function get_variation_available_attribute_display($current_entity_id, $variation_type = 'multiple') { $attribute_list = wpshop_attributes::get_variation_available_attribute($current_entity_id); $attribute_defined_as_available_for_variation = ''; if (!empty($attribute_list)) { foreach ($attribute_list as $list_type => $attribute_list_by_type) { $sub_attribute_list = ''; foreach ($attribute_list_by_type as $attribute_code => $attribute_def) { $tpl_component = array(); if ($list_type == 'available') { $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_LABEL_STATE'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL_EXPLAINATION'] = ''; } else { $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_LABEL_STATE'] = ' class="wpshop_unavailable_label_variation_definition" '; $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = ' disabled="disabled"'; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL_EXPLAINATION'] = ''; } $tpl_component['ADMIN_ATTRIBUTE_CODE_FOR_VARIATION'] = $attribute_code; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_NAME'] = $attribute_code; $tpl_component['ADMIN_VARIATION_ATTRIBUTE_CONTAINER_CLASS'] = ' wpshop_attribute_for_variation_' . $attribute_code; $tpl_component['ADMIN_VARIATION_NEW_SINGLE_LABEL'] = __($attribute_def['label'], 'wpshop'); $tpl_component['ADMIN_VARIATION_NEW_SINGLE_INPUT'] = ''; if ($variation_type == 'single') { $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_def['attribute_complete_def'], $attribute_def['values'], array('from' => 'frontend', 'field_custom_name_prefix' => 'variation_attr', 'input_class' => ' variation_attribute_usable_input')); if (!empty($attribute_output_def['possible_value'])) { foreach ($attribute_output_def['possible_value'] as $value_id => $value) { if (!in_array($value_id, $attribute_def['values'])) { unset($attribute_output_def['possible_value'][$value_id]); } } } $tpl_component['ADMIN_VARIATION_NEW_SINGLE_INPUT'] = wpshop_form::check_input_type($attribute_output_def, $attribute_output_def['input_domain']); } $sub_attribute_list .= wpshop_display::display_template_element('wpshop_admin_variation_attribute_line', $tpl_component, array(), 'admin'); unset($tpl_component); } $attribute_defined_as_available_for_variation .= wpshop_display::display_template_element($list_type == 'available' ? 'wpshop_admin_attribute_for_variation_list' : 'wpshop_admin_unvailable_attribute_for_variation_list', array('ADMIN_VARIATIONS_DEF_LIST_CONTAINER_CLASS' => '', 'ADMIN_VARIATIONS_DEF_LIST_CONTAINER' => $sub_attribute_list), array(), 'admin'); } } return array($attribute_defined_as_available_for_variation, !empty($attribute_list['available']) ? $attribute_list['available'] : '', !empty($attribute_list['unavailable']) ? $attribute_list['unavailable'] : ''); }
function wpshop_ajax_admin_variation_parameters() { check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce'); $current_post_id = isset($_POST['current_post_id']) ? wpshop_tools::varSanitizer($_POST['current_post_id']) : null; $output = ''; /* Display variation options */ $options_tpl_component = array(); $head_wpshop_variation_definition = get_post_meta($current_post_id, '_wpshop_variation_defining', true); $options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRIORITY_SINGLE'] = empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['priority'][0]) || !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['priority'][0]) && $head_wpshop_variation_definition['options']['priority'][0] == 'single' ? ' checked="checked"' : ''; $options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRIORITY_COMBINED'] = empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['priority'][0]) || !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['priority'][0]) && $head_wpshop_variation_definition['options']['priority'][0] == 'combined' ? ' checked="checked"' : ''; $options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_BEHAVIOUR_ADDITION'] = empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) || !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) && $head_wpshop_variation_definition['options']['price_behaviour'][0] == 'addition' ? ' checked="checked"' : ''; $options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_BEHAVIOUR_REPLACEMENT'] = empty($head_wpshop_variation_definition['options']) || empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) || !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_behaviour'][0]) && $head_wpshop_variation_definition['options']['price_behaviour'][0] == 'replacement' ? ' checked="checked"' : ''; $options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRICE_DISPLAY_TEXT_FROM'] = empty($head_wpshop_variation_definition['options']) || !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_display']['text_from']) && $head_wpshop_variation_definition['options']['price_display']['text_from'] == 'on' ? ' checked="checked"' : ''; $options_tpl_component['ADMIN_VARIATION_OPTIONS_SELECTED_PRICE_DISPLAY_LOWER_PRICE'] = empty($head_wpshop_variation_definition['options']) || !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['price_display']['lower_price']) && $head_wpshop_variation_definition['options']['price_display']['lower_price'] == 'on' ? ' checked="checked"' : ''; $options_tpl_component['ADMIN_VARIATION_PARAMETERS_FORM_HEAD_PRODUCT_ID'] = $current_post_id; $options_tpl_component['ADMIN_VARIATION_PARAMETERS_FORM_HEAD_NOUNCE'] = wp_create_nonce("wpshop_variation_parameters"); $options_tpl_component['ADMIN_MORE_OPTIONS_FOR_VARIATIONS'] = ''; $attribute_list_for_variations = wpshop_attributes::get_variation_available_attribute($current_post_id); $default_value_for_attributes = $required_attributes = ''; $attribute_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => get_post_type($current_post_id))); if (!empty($attribute_user_defined)) { foreach ($attribute_user_defined as $attribute_def) { $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_LABEL_STATE'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL_EXPLAINATION'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_CODE'] = $attribute_def->code; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_NAME'] = $attribute_def->code; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL'] = __($attribute_def->frontend_label, 'wpshop'); $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CONTAINER_CLASS'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = !empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && in_array($attribute_def->code, $head_wpshop_variation_definition['options']['required_attributes']) ? ' checked="checked"' : ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_ID'] = 'required_' . $attribute_def->code; $required_attributes .= str_replace('wpshop_attribute_to_use_for_variation', 'wps_pdt_variations[options][required_attributes]', str_replace('variation_attribute_usable', 'variation_attribute_required', wpshop_display::display_template_element('wpshop_admin_attribute_for_variation_item', $tpl_component, array(), 'admin'))); } } if (!empty($attribute_list_for_variations['available'])) { $head_wpshop_variation_definition = get_post_meta($current_post_id, '_wpshop_variation_defining', true); foreach ($attribute_list_for_variations['available'] as $attribute_code => $attribute_definition) { /** Default value for attribute */ $tpl_component = array(); $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CONTAINER_CLASS'] = ' variation_attribute_container_default_value_' . $attribute_code; $attribute_for_default_value = wpshop_attributes::get_attribute_field_definition($attribute_definition['attribute_complete_def'], is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : 'none', array('from' => 'frontend', 'field_custom_name_prefix' => 'empty')); switch ($attribute_for_default_value['type']) { case 'select': case 'multiple-select': case 'radio': case 'checkbox': $attribute_for_default_value['type'] = 'select'; break; default: $attribute_for_default_value['type'] = 'text'; break; } if (!empty($attribute_for_default_value['possible_value'])) { $attribute_for_default_value['possible_value']['none'] = __('No default value', 'wpshop'); foreach ($attribute_for_default_value['possible_value'] as $value_id => $value) { if (!empty($value_id) && $value_id != 'none' && !in_array($value_id, $attribute_definition['values'])) { unset($attribute_for_default_value['possible_value'][$value_id]); } } ksort($attribute_for_default_value['possible_value']); $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_ID'] = $attribute_for_default_value['id']; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_DEFAULT_VALUE_LABEL'] = sprintf(__('Default value for %s', 'wpshop'), $attribute_for_default_value['label']); $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_DEFAULT_VALUE_INPUT'] = wpshop_form::check_input_type($attribute_for_default_value, 'wps_pdt_variations[options][attributes_default_value]'); $default_value_for_attributes .= wpshop_display::display_template_element('wpshop_admin_attribute_for_variation_item_for_default', $tpl_component, array(), 'admin'); } /** Required attribute for variations */ $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_LABEL_STATE'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL_EXPLAINATION'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_CODE'] = $attribute_code; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_NAME'] = $attribute_code; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_LABEL'] = __($attribute_definition['label'], 'wpshop'); $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CONTAINER_CLASS'] = ''; $tpl_component['ADMIN_VARIATIONS_DEF_LIST_ATTRIBUTE_CHECKBOX_STATE'] = !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']) ? ' checked="checked"' : ''; $tpl_component['ADMIN_VARIATIONS_DEF_ATTRIBUTE_TO_USE_ID'] = 'required_' . $attribute_code; $required_attributes .= str_replace('wpshop_attribute_to_use_for_variation', 'wps_pdt_variations[options][required_attributes]', str_replace('variation_attribute_usable', 'variation_attribute_required', wpshop_display::display_template_element('wpshop_admin_attribute_for_variation_item', $tpl_component, array(), 'admin'))); } $options_tpl_component['ADMIN_MORE_OPTIONS_FOR_VARIATIONS'] .= !empty($required_attributes) ? wpshop_display::display_template_element('wpshop_admin_variation_options_required_attribute_container', array('ADMIN_VARIATION_OPTIONS_REQUIRED_ATTRIBUTE' => $required_attributes), array(), 'admin') : ''; $options_tpl_component['ADMIN_MORE_OPTIONS_FOR_VARIATIONS'] .= !empty($default_value_for_attributes) ? wpshop_display::display_template_element('wpshop_admin_variation_options_default_value_container', array('ADMIN_VARIATION_OPTIONS_ATTRIBUTE_DEFAULT_VALUE' => $default_value_for_attributes), array(), 'admin') : ''; } $output .= wpshop_display::display_template_element('wpshop_admin_variation_options_container', $options_tpl_component, array(), 'admin'); unset($options_tpl_component); echo $output; die; }