/** * Get product product Attributes definition * * @param integer $product_id * * @return array */ function get_product_atts_def($product_id) { $product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); $element_atribute_list = wpshop_attributes::getElementWithAttributeAndValue($product_entity_id, $product_id, WPSHOP_CURRENT_LOCALE, '', 'frontend'); $one_product = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); if (!empty($one_product)) { $array1 = !empty($one_product['attribute_set_section']) ? $one_product['attribute_set_section'] : array(); $array2 = $element_atribute_list[$product_id]; unset($element_atribute_list); foreach ($array2 as $key => $attribute_set_section) { foreach ($array1 as $code1 => $value) { if ($code1 == $attribute_set_section['code']) { $element_atribute_list[$product_id][$key] = $attribute_set_section; } } } } return $element_atribute_list; }
/** * 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; }
/** * Define the metabox content for product custom display in product * @param object $post The current element being edited * @return string The metabox content */ public static function product_frontend_display_config_meta_box($post) { $content = ''; $product_attribute_frontend_display_config = null; if (!empty($post->ID)) { $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); $extra_options = get_option('wpshop_extra_options', array()); $column_count = !empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3; $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); $column = 1; if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { $sub_tpl_component = array(); $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); $tpl_component = array(); $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; $button_is_set_to_be_displayed = WPSHOP_DEFINED_SHOP_TYPE == 'sale' ? 'yes' : 'no'; $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"' : ''; $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"' : ''; $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); unset($tpl_component); $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); } if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { if (!isset($sub_content[$column])) { $sub_content[$column] = ''; } $attribute_sub_output = ''; foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { $tpl_component = array(); $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; $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"' : ''; $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"' : ''; $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); unset($tpl_component); } } $tpl_component = array(); $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; $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"' : ''; $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>'; $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); $column++; if ($column > $column_count) { $column = 1; } } } $tpl_component = array(); $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; for ($i = 1; $i <= $column_count; $i++) { if (!empty($sub_content[$i])) { $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; } } $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; $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>'; } return $content; }