/**
 * Refresh Price in complete product sheet and Cart summary display
 */
function wpshop_ajax_wpshop_variation_selection()
{
    global $wpdb;
    $wpshop_cart = new wps_cart();
    $wpshop_products = new wpshop_products();
    $response = '';
    $response_status = $has_variation = false;
    $tpl_component = array();
    //Sended vars
    $product_id = isset($_POST['wpshop_pdt']) ? intval(wpshop_tools::varSanitizer($_POST['wpshop_pdt'])) : null;
    $wpshop_variation_selected = isset($_POST['wpshop_variation']) ? $_POST['wpshop_variation'] : null;
    $wpshop_free_variation = isset($_POST['wpshop_free_variation']) ? $_POST['wpshop_free_variation'] : null;
    $wpshop_current_for_display = isset($_POST['wpshop_current_for_display']) ? $_POST['wpshop_current_for_display'] : null;
    $product_qty = isset($_POST['product_qty']) ? $_POST['product_qty'] : 1;
    // Check if variations exists
    if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
        //Recover all selected variations
        $variations_selected = array();
        if (!empty($wpshop_variation_selected)) {
            foreach ($wpshop_variation_selected as $selected_variation) {
                $variation_definition = explode('-_variation_val_-', $selected_variation);
                $variations_selected[$variation_definition[0]] = $variation_definition[1];
            }
        }
        // Check variations priority
        $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
        // Check if $product_with_variation have variations
        if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
            $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
            $product_to_add_to_cart = $formatted_product[0];
            foreach ($formatted_product[0] as $pid => $product_more_content) {
                $order_items[$pid]['product_id'] = $product_more_content['id'];
                /** For product with variation	*/
                $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
                $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
                $order_items[$pid]['product_variation'] = '';
                if (!empty($product_more_content['variations'])) {
                    foreach ($product_more_content['variations'] as $variation_id) {
                        $order_items[$pid]['product_variation'][] = $variation_id;
                    }
                }
            }
            // If Product list is not empty, add products to order
            if (!empty($order_items)) {
                foreach ($order_items as $product_id => $d) {
                    $product_key = $product_id;
                    // Formate datas
                    $product_id = $head_product_id = $d['product_id'];
                    $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
                    // If product is a single variation product
                    if (!empty($product_variation) && count($product_variation) == 1) {
                        $product_id = $product_variation[0];
                    }
                    // Construct final product
                    $product = wpshop_products::get_product_data($d['product_id'], true);
                    $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
                    //	Add variation to product into cart for storage
                    if (!empty($product_variation)) {
                        $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
                    }
                    // Free Variations Checking
                    if (!empty($d['free_variation'])) {
                        $the_product['item_meta']['free_variation'] = $d['free_variation'];
                        $head_product_id = $the_product['product_id'];
                    }
                    // If product is a variation, we check parent product general
                    if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                        $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
                        if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                            $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
                            $parent_meta = $parent_def['parent_post_meta'];
                            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) {
                                $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
                                $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
                                $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
                            }
                        }
                    }
                }
            }
            if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
                $price_infos = wpshop_prices::check_product_price($the_product, true);
                if (!empty($price_infos['discount']['discount_exist'])) {
                    $the_product['price_ttc_before_discount'] = $the_product['product_price'];
                    $the_product['price_ht_before_discount'] = $the_product['price_ht'];
                }
                $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'];
                $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'];
                $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'];
            }
            $product = wpshop_products::get_product_data($product_id, true);
            // Add free variations to product
            if (!empty($wpshop_free_variation)) {
                $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
            }
            // Change picture if have a selected variation
            $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;
            $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
            // Price Display
            $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
            $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
            $productPrice = '';
            if ($price_display) {
                $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
            }
            //Get Summary cart
            $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, !empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false);
            $response_status = true;
        } else {
            //Product without variations
            $product_data = wpshop_products::get_product_data($product_id);
            $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
        }
    }
    echo json_encode(array($response_status, $response));
    wp_die();
}
 /**
  * Output the different tabs into an entity sheet
  *
  * @param string $element_code The current element type represented by the code
  * @param integer $element_id The current element identifier to dislay tabs for
  * @param array $element_definition An array with the different configuration for the current element
  *
  * @return string The html code to output directly tabs
  */
 public static function attribute_of_entity_to_tab($element_code, $element_id, $element_definition)
 {
     $attributeContentOutput = '';
     /**	Get the different attribute affected to the entity	*/
     $element_atribute_list = wpshop_attributes::getElementWithAttributeAndValue($element_code, $element_id, WPSHOP_CURRENT_LOCALE, '', 'frontend');
     if (is_array($element_atribute_list) && count($element_atribute_list) > 0) {
         foreach ($element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent) {
             $attributeToShowNumber = 0;
             $attributeOutput = '';
             foreach ($attributeSetContent['attributes'] as $attributeId => $attributeDefinition) {
                 /**	Check the value type to check if empty or not	*/
                 if ($attributeDefinition['data_type'] == 'int') {
                     $attributeDefinition['value'] = (int) $attributeDefinition['value'];
                 } else {
                     if ($attributeDefinition['data_type'] == 'decimal') {
                         $attributeDefinition['value'] = (double) $attributeDefinition['value'];
                     }
                 }
                 /** Check if the attribute is set to be displayed in frontend	*/
                 $attribute_display_state = wpshop_attributes::check_attribute_display($attributeDefinition['is_visible_in_front'], $element_definition['custom_display'], 'attribute', $attributeDefinition['code'], 'complete_sheet');
                 /**	Output the field if the value is not null	*/
                 if ((is_array($attributeDefinition['value']) || !empty($attributeDefinition['value'])) && $attribute_display_state) {
                     $attribute_display = wpshop_attributes::wps_attribute_values_display($attributeDefinition);
                     $attribute_value = $attribute_display[0];
                     $attributeDefinition['value'] = $attribute_display[1];
                     $attribute_unit_list = $attribute_display[2];
                     /** Template parameters	*/
                     $template_part = 'product_attribute_display';
                     $tpl_component = array();
                     $tpl_component['PDT_ENTITY_CODE'] = self::currentPageCode;
                     $tpl_component['ATTRIBUTE_CODE'] = $attributeDefinition['attribute_code'];
                     $tpl_component['ATTRIBUTE_LABEL'] = __($attributeDefinition['frontend_label'], 'wpshop');
                     $tpl_component['ATTRIBUTE_VALUE'] = !is_array($attribute_value) ? stripslashes($attribute_value) : $attribute_value;
                     $tpl_component['ATTRIBUTE_VALUE_UNIT'] = $attribute_unit_list;
                     /** Build template	*/
                     $attributeOutput .= wpshop_display::display_template_element($template_part, $tpl_component);
                     unset($tpl_component);
                     $attributeToShowNumber++;
                 }
             }
             /** Check if the attribute set section is set to be displayed in frontend	*/
             $attribute_set_display_state = wpshop_attributes::check_attribute_display($attributeSetContent['display_on_frontend'], $element_definition['custom_display'], 'attribute_set_section', $attributeSetContent['code'], 'complete_sheet');
             if (!$attribute_set_display_state) {
                 $attributeToShowNumber = 0;
                 $attributeOutput = '';
             }
             $element_atribute_list[$element_id][$attributeSetSectionName]['count'] = $attributeToShowNumber;
             $element_atribute_list[$element_id][$attributeSetSectionName]['output'] = $attributeOutput;
         }
         /** Gestion de l'affichage	*/
         $tab_list = $content_list = '';
         foreach ($element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent) {
             if (!empty($attributeSetContent['count']) > 0) {
                 /** Template parameters	*/
                 $template_part = 'product_attribute_tabs';
                 $tpl_component = array();
                 $tpl_component['ATTRIBUTE_SET_CODE'] = $attributeSetContent['code'];
                 $tpl_component['ATTRIBUTE_SET_NAME'] = __($attributeSetSectionName, 'wpshop');
                 /** Build template	*/
                 $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
                 if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
                     /*	Include the old way template part	*/
                     ob_start();
                     require wpshop_display::get_template_file($tpl_way_to_take[1]);
                     $tab_list .= ob_get_contents();
                     ob_end_clean();
                 } else {
                     $tab_list .= wpshop_display::display_template_element($template_part, $tpl_component);
                 }
                 unset($tpl_component);
                 /** Template parameters	*/
                 $template_part = 'product_attribute_tabs_detail';
                 $tpl_component = array();
                 $tpl_component['ATTRIBUTE_SET_CODE'] = $attributeSetContent['code'];
                 $tpl_component['ATTRIBUTE_SET_CONTENT'] = $attributeSetContent['output'];
                 /** Build template	*/
                 $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
                 if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
                     /*	Include the old way template part	*/
                     ob_start();
                     require wpshop_display::get_template_file($tpl_way_to_take[1]);
                     $content_list .= ob_get_contents();
                     ob_end_clean();
                 } else {
                     $content_list .= wpshop_display::display_template_element($template_part, $tpl_component);
                 }
                 unset($tpl_component);
             }
         }
         if ($tab_list != '') {
             /** Template parameters	*/
             $template_part = 'product_attribute_container';
             $tpl_component = array();
             $tpl_component['PDT_TABS'] = apply_filters('wpshop_extra_tabs_menu_before', '') . $tab_list . apply_filters('wpshop_extra_tabs_menu_after', '');
             $tpl_component['PDT_TAB_DETAIL'] = apply_filters('wpshop_extra_tabs_content_before', '') . $content_list . apply_filters('wpshop_extra_tabs_content_after', '');
             /** Build template	*/
             $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
             if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
                 /*	Include the old way template part	*/
                 ob_start();
                 require wpshop_display::get_template_file($tpl_way_to_take[1]);
                 $attributeContentOutput = ob_get_contents();
                 ob_end_clean();
             } else {
                 $attributeContentOutput = wpshop_display::display_template_element($template_part, $tpl_component);
             }
             unset($tpl_component);
         }
     }
     return $attributeContentOutput;
 }
 /**
  * Retrieve and display the variation for a given product
  * @param integer $product_id The product identifier to get variation for
  */
 public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
 {
     global $wp_query;
     $output = '';
     $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
     $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
     $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
     /**	Get attribute order for current product	*/
     $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
     $output_order = array();
     if (count($product_attribute_order_detail) > 0) {
         if (!empty($product_attribute_order_detail)) {
             foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
                 foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
                     if (!empty($attribute_def->code)) {
                         $output_order[$attribute_def->code] = $position;
                     }
                 }
             }
         }
     }
     $variations_params = array();
     $variation_attribute = array();
     $variation_attribute_ordered = array();
     $possible_values = array();
     $possible_values_for_selection_calculation = array();
     /*	Vérification de l'existence de déclinaison pour le produit	*/
     $wpshop_variation_list = self::get_variation($product_id);
     if (!empty($wpshop_variation_list)) {
         foreach ($wpshop_variation_list as $variation) {
             if (!empty($variation['variation_def'])) {
                 $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
                 foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
                     if (empty($display_option) || !empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet'])) {
                         $tpl_component = array();
                         $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
                         $default_value_is_serial = false;
                         $attribute_list_first_element = $attribute_db_definition->default_value;
                         if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || @unserialize($attribute_db_definition->default_value) !== false)) {
                             $default_value_is_serial = true;
                             $tmp_default_value = unserialize($attribute_db_definition->default_value);
                             $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
                         }
                         if ($default_value_is_serial && !empty($attribute_list_first_element) && $attribute_list_first_element != 'none') {
                             $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');
                         }
                         if (!empty($attribute_value) && $attribute_db_definition->data_type_to_use == 'custom') {
                             $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
                             $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
                         } else {
                             if (!empty($attribute_value) && $attribute_db_definition->data_type_to_use == 'internal') {
                                 $post_def = get_post($attribute_value);
                                 $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
                                 $position = $post_def->menu_order;
                             }
                         }
                         if (!empty($variation['variation_dif'])) {
                             foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
                                 $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
                                 $the_value = $attribute_dif_value;
                                 if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
                                     $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
                                 }
                                 $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
                             }
                         }
                         if (!empty($attribute_value)) {
                             $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));
                             $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
                         }
                         unset($tpl_component);
                     }
                 }
             }
         }
         $variation_tpl = array();
         if (!empty($head_wpshop_variation_definition['attributes'])) {
             foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
                 $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
                 if (!empty($attribute_db_definition)) {
                     $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');
                     $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;
                     if (!$is_required && $attribute_db_definition->is_required == 'yes') {
                         $is_required = true;
                     }
                     $input_def = array();
                     $input_def['type'] = $attribute_db_definition->frontend_input;
                     $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);
                     if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
                         unset($possible_values[$attribute_code][0]);
                         $value = array($value);
                     }
                     $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
                     $input_def['name'] = $attribute_code;
                     $real_possible_values = array();
                     if (!empty($possible_values[$attribute_code])) {
                         ksort($possible_values[$attribute_code]);
                         foreach ($possible_values[$attribute_code] as $position => $def) {
                             foreach ($def as $attribute_value => $attribute_value_output) {
                                 $real_possible_values[$attribute_value] = $attribute_value_output;
                             }
                         }
                     }
                     $input_def['possible_value'] = $real_possible_values;
                     $input_def['valueToPut'] = 'index';
                     $input_def['value'] = $value;
                     $input_def['options']['more_input'] = '';
                     if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
                         foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
                             $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 . '" />';
                         }
                     }
                     $input_def['options_label']['original'] = true;
                     $input_def['option'] = ' 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) . '" ';
                     if (!empty($real_possible_values)) {
                         $tpl_component = array();
                         $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'];
                         $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
                         $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);
                         $tpl_component['VARIATION_CODE'] = $attribute_code;
                         $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
                         $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
                         $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
                         $tpl_component['VARIATION_PARENT_ID'] = $product_id;
                         $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
                         $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;
                         $tpl_component['VARIATION_REQUIRED_INDICATION'] = $is_required ? __('Required variation', 'wpshop') : '';
                         $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
                         $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
                     }
                     $variation_attribute[] = $attribute_code;
                 }
             }
         }
     }
     $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
     wp_reset_query();
     $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
     if (!empty($attribute_defined_to_be_user_defined)) {
         foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
             $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;
             $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');
             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') {
                 $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] : null);
                 $tpl_component = array();
                 $attribute_output_def['option'] = ' 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) . '" ';
                 $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
                 $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);
                 $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
                 $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 . '" ' : '';
                 $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
                 $tpl_component['VARIATION_REQUIRED_INDICATION'] = $is_required ? __('Required variation', 'wpshop') : '';
                 $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
                 $tpl_component['VARIATION_PARENT_ID'] = $product_id;
                 $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
                 $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;
                 $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'];
                 $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)];
             }
         }
     }
     $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
     if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
         ksort($variation_attribute_ordered);
         foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
             $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
         }
     }
     $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
     $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = !empty($qty) ? $qty : 1;
     if ($from_admin && !empty($order_id)) {
         $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
         $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
     }
     $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
     return $output;
 }