function display_order_customer_informations() { global $post_id; global $wpdb; $output = ''; if (!empty($post_id)) { $order_postmeta = get_post_meta($post_id, '_order_postmeta', true); $order_info = get_post_meta($post_id, '_order_info', true); /** Check the order status **/ if (!empty($order_postmeta)) { if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] != 'awaiting_payment') { $output = wps_address::display_an_address($order_info['billing']['address']); $output .= wps_address::display_an_address($order_info['shipping']['address']); } else { $output = wps_address::display_an_address($order_info['billing']['address']); } } } else { /** Display "Choose customer or create one" Interface **/ $tpl_component = array(); $args = array('show_option_all' => __('Choose a customer', 'wpshop'), 'orderby' => 'display_name', 'order' => 'ASC', 'include' => null, 'exclude' => null, 'multi' => false, 'show' => 'display_name', 'echo' => false, 'selected' => false, 'include_selected' => false, 'name' => 'user', 'id' => null, 'class' => 'chosen_select', 'blog_id' => $GLOBALS['blog_id'], 'who' => null); $tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users($args); $output = wpshop_display::display_template_element('wps_orders_choose_customer_interface', $tpl_component, array(), 'admin'); } return $output; }
function latest_products_ordered($orders) { global $wpdb; $product_id = $output = ''; $products = array(); $display_option = get_option('wpshop_display_option'); if (!empty($orders) && !empty($display_option) && !empty($display_option['latest_products_ordered'])) { foreach ($orders as $order) { $order_content = get_post_meta($order->ID, '_order_postmeta', true); if (!empty($order_content) && !empty($order_content['order_items'])) { foreach ($order_content['order_items'] as $item) { if (count($products) >= $display_option['latest_products_ordered']) { continue; } $product_id = $item['item_id']; if (!empty($item) && !empty($item['item_meta']) && !empty($item['item_meta']['variation_definition'])) { $parent_def = wpshop_products::get_parent_variation($item['item_id']); if (!empty($parent_def)) { $parent_post = $parent_def['parent_post']; $product_id = $parent_post->ID; } } if (!in_array($product_id, $products)) { $products[] = $product_id; } } } } if (!empty($products)) { $products_id = implode(",", $products); $output = wpshop_display::display_template_element('latest_products_ordered', array('LATEST_PRODUCTS_ORDERED' => do_shortcode('[wpshop_products pid="' . $products_id . '"]'))); } } return $output; }
function add_gift_product_to_cart($cartContent, $order) { global $wpdb; if (!empty($order['cart_rule']) && !empty($order['cart_rule']['discount_value']) && !empty($order['cart_rule']['discount_type']) && $order['cart_rule']['discount_type'] == 'gift_product') { $product = get_post($order['cart_rule']['discount_value']); $option_name = ''; if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_product_infos = wpshop_products::get_parent_variation($product->ID); if (!empty($parent_product_infos) && !empty($parent_product_infos['parent_post'])) { $parent_post_infos = $parent_product_infos['parent_post']; $product_title = $parent_post_infos->post_title; $product_options = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); if (!empty($product_options) && is_array($product_options)) { $option_name = ''; foreach ($product_options as $k => $product_option) { $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', $k); $option_name .= $wpdb->get_var($query) . ' '; $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $product_option); $option_name .= $wpdb->get_var($query) . ' '; } $discount_value = $product_title; } } } else { $discount_value = $product->post_title; } $tpl_component['CART_PRODUCT_MORE_INFO'] = $option_name; $tpl_component['CART_LINE_ITEM_ID'] = $order['cart_rule']['discount_value']; $tpl_component['CART_LINE_ITEM_PUHT'] = number_format(0, 2); $tpl_component['CART_LINE_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2); $tpl_component['CART_LINE_ITEM_TPHT'] = number_format(0, 2); $tpl_component['CART_LINE_ITEM_TPTTC'] = number_format(0, 2); $tpl_component['CART_LINE_ITEM_QTY_'] = 1; $tpl_component['CART_LINE_ITEM_REMOVER'] = ''; $tpl_component['CART_PRODUCT_NAME'] = $discount_value . ' (' . __('Gift product', 'wpshop') . ')'; $cartContent .= wpshop_display::display_template_element('cart_line', $tpl_component); } return $cartContent; }
/** * Display the differents forms fields * @param string $type : Type of address * @param string $first : Customer first address ? * @param string $referer : Referer website page * @param string $admin : Display this form in admin panel */ public static function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '') { global $wpshop, $wpshop_form, $wpdb; $choosen_address = get_option('wpshop_billing_address'); $shipping_address = get_option('wpshop_shipping_address_choice'); $output_form_fields = $form_model = ''; $user_id = !empty($other_customer) ? $other_customer : get_current_user_id(); if (empty($type)) { $type = $choosen_address['choice']; } $result = wps_address::get_addresss_form_fields_by_type($type, $id); /** Check if it's shipping or billing **/ if ($type == $choosen_address['choice']) { $form_model = !empty($choosen_address['display_model']) ? $choosen_address['display_model'] : null; } elseif ($type == $shipping_address['choice']) { $form_model = !empty($shipping_address['display_model']) ? $shipping_address['display_model'] : null; } $form = $result[$type]; // Take the post id to make the link with the post meta of address $values = array(); // take the address informations $current_item_edited = !empty($id) ? (int) wpshop_tools::varSanitizer($id) : null; foreach ($form as $group_id => $group_fields) { if (empty($options) || !empty($options) && $options['title']) { $output_form_fields .= '<h2>' . __($group_fields['name'], 'wpshop') . '</h2>'; } $end_line_indicator = 0; $fields_limit_per_line = -1; foreach ($group_fields['content'] as $key => $field) { $attribute_def = wpshop_attributes::getElement($field['name'], $element_status = "'valid'", $field_to_search = 'code'); /** Grid opening **/ if (!empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1) { $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]); $current_attribute_key = array_search('attribute_' . $attribute_def->id, $form_model[$group_id]); if ($current_attribute_key > $current_key) { // /** Define limit **/ // if( in_array('wps-attribute-end-line-' . ($end_line_indicator + 1 ) , $form_model[$group_id]) ) { // $next_key = array_search( 'wps-attribute-end-line-'.( $end_line_indicator + 1 ), $form_model[$group_id] ); // $fields_limit_per_line = $next_key - $current_key - 1; // $fields_limit_per_line = ( $fields_limit_per_line > 6 ) ? 6 : $fields_limit_per_line; // } // else { // $current_key = array_search( 'wps-attribute-end-line-'.$end_line_indicator, $form_model[$group_id] ); // $end_tab = count($form_model[$group_id]) - 1; // $fields_limit_per_line = $end_tab - $current_key - 1; // $fields_limit_per_line = ( $fields_limit_per_line > 6 ) ? 6 : $fields_limit_per_line; // } if (!empty($fields_limit_per_line) && $fields_limit_per_line != -1) { if ($fields_limit_per_line == 1) { $output_form_fields .= '<div class="wps-row">'; } else { $output_form_fields .= '<div class="wps-row wps-gridwrapper' . $fields_limit_per_line . '-padded">'; } } } } if (empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array($key, $options['field_to_hide'])) { $attributeInputDomain = 'attribute[' . $type . '][' . $field['data_type'] . ']'; // Test if there is POST var or if user have already fill his address infos and fill the fields with these infos if (!empty($_POST)) { $referer = !empty($_POST['referer']) ? $_POST['referer'] : ''; if (!empty($form['id']) && !empty($field['name']) && isset($_POST[$form['id'] . "_" . $field['name']])) { $value = $_POST[$form['id'] . "_" . $field['name']]; } } // Fill Automaticly some fields when it's an address creation switch ($field['name']) { case 'address_title': if (empty($field['value'])) { /** Count Billing and shipping address **/ $billing_address_count = $shipping_address_count = 1; if (get_current_user_id() != 0) { $addresses = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft')); if (!empty($addresses)) { foreach ($addresses as $address) { $address_type = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true); if (!empty($address_type)) { if (!empty($shipping_address_choice['choice']) && $address_type == $shipping_address_choice['choice']) { $shipping_address_count++; } else { $billing_address_count++; } } } } } $field['value'] = $type == $choosen_address['choice'] ? __('Billing address', 'wpshop') . ($billing_address_count > 1 ? ' ' . $billing_address_count : '') : __('Shipping address', 'wpshop') . ($shipping_address_count > 1 ? ' ' . $shipping_address_count : ''); } break; case 'address_last_name': if (empty($field['value'])) { $usermeta_last_name = get_user_meta($user_id, 'last_name', true); $field['value'] = !empty($usermeta_last_name) ? $usermeta_last_name : ''; } break; case 'address_first_name': if (empty($field['value'])) { $usermeta_first_name = get_user_meta($user_id, 'first_name', true); $field['value'] = !empty($usermeta_first_name) ? $usermeta_first_name : ''; } break; case 'address_user_email': if (empty($field['value'])) { $user_infos = get_userdata($user_id); $field['value'] = !empty($user_infos) && !empty($user_infos->user_email) ? $user_infos->user_email : ''; } break; default: $field['value'] = !empty($field['value']) ? $field['value'] : ''; break; } /** Fill fields if $_POST exist **/ if (!empty($_POST['attribute'][$type][$field['data_type']][$field['name']])) { $field['value'] = $_POST['attribute'][$type][$field['data_type']][$field['name']]; } if ($field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop')) { $value = __('Billing address', 'wpshop'); } elseif ($field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop')) { $value = __('Shipping address', 'wpshop'); } if (!empty($special_values[$field['name']])) { $field['value'] = $special_values[$field['name']]; } $template = 'wpshop_account_form_input'; if ($field['type'] == 'hidden') { $template = 'wpshop_account_form_hidden_input'; } if ($field['frontend_verification'] == 'country') { $field['type'] = 'select'; /** display a country list **/ $countries_list = unserialize(WPSHOP_COUNTRY_LIST); $possible_values = array_merge(array('' => __('Choose a country')), $countries_list); $limit_countries_list = get_option('wpshop_limit_country_list'); $default_country_choice = get_option('wpshop_country_default_choice'); if (!empty($limit_countries_list)) { $possible_values = array(); if (count($limit_countries_list) > 1) { $possible_values[''] = __('Choose a country'); } foreach ($limit_countries_list as $country_code) { if (!empty($countries_list) && !empty($countries_list[$country_code])) { $possible_values[$country_code] = $countries_list[$country_code]; } } } $field['value'] = !empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values) ? $default_country_choice : ''; $field['possible_value'] = $possible_values; $field['valueToPut'] = 'index'; } $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option']))); $input_tpl_component = array(); //$input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = $field['type'] != 'hidden' ? stripslashes(__($field['label'], 'wpshop')) . ($field['required'] == 'yes' ? ' <em>*</em>' : '') : ''; $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain); //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop'); unset($input_tpl_component); if ($field['_need_verification'] == 'yes') { $field['name'] = $field['name'] . '2'; $field['id'] = $field['id'] . '2'; $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option']))); $input_tpl_component = array(); $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __($field['label'], 'wpshop') . ($field['required'] == 'yes' && !is_admin() || $field['name'] == 'address_user_email' && is_admin() ? ' <span class="required">*</span>' : ''); $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; $input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf(__('Confirm %s', 'wpshop'), strtolower(__($field['label'], 'wpshop'))) . ($field['required'] == 'yes' && !is_admin() ? ' <span class="required">*</span>' : ''); $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain) . $field['options']; //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop'); unset($input_tpl_component); } } /** Grid closing **/ if ($fields_limit_per_line != -1 && !empty($fields_limit_per_line)) { $fields_limit_per_line--; if ($fields_limit_per_line == 0) { $output_form_fields .= '</div>'; $fields_limit_per_line = -1; $end_line_indicator++; } } } } if ($type == $choosen_address['choice']) { $output_form_fields .= '<input type="hidden" name="billing_address" value="' . $choosen_address['choice'] . '" />'; } $shipping_address_options = get_option('wpshop_shipping_address_choice'); if ($type == $shipping_address_options['choice']) { $output_form_fields .= '<input type="hidden" name="shipping_address" value="' . $shipping_address_options['choice'] . '" />'; } $output_form_fields .= '<input type="hidden" name="type_of_form" value="' . $type . '" /><input type="hidden" name="attribute[' . $type . '][item_id]" value="' . $current_item_edited . '" />'; $output_form_fields .= $user_id != get_current_user_id() ? '<input type="hidden" name="user[customer_id]" value="' . $user_id . '" />' : ''; if (empty($first)) { $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); } return $output_form_fields; }
function ajax_wpshop_load_create_new_customer_interface() { $billing_address_option = get_option('wpshop_billing_address'); $shipping_address_option = get_option('wpshop_shipping_address_choice'); $tpl_component = array(); $tpl_component['LOADING_ICON'] = WPSHOP_LOADING_ICON; if (!empty($billing_address)) { echo wpshop_account::get_addresses_by_type($billing_address, __('Billing address', 'wpshop'), array('only_display' => 'yes')); } $tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] = wpshop_account::display_form_fields($billing_address_option['choice'], '', 'first'); if ($shipping_address_option['activate']) { $tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '<p class="formField"><label><input type="checkbox" name="shiptobilling" id="shiptobilling_checkbox" checked="checked" /> ' . __('Use as shipping information', 'wpshop') . '</label></p><br/>'; $display = 'display:none;'; $tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '<div id="shipping_infos_bloc" style="' . $display . '">'; $tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= wpshop_account::display_form_fields($shipping_address_option['choice'], '', 'first'); $tpl_component['CUSTOMER_ADDRESSES_FORM_CONTENT'] .= '</div><br/>'; } $tpl_component['CUSTOMER_ADDRESSES_FORM_BUTTONS'] = '<p class="formField"><input type="submit" name="submitbillingAndShippingInfo" id="submitbillingAndShippingInfo" value="' . __('Save', 'wpshop') . '" /></p>'; $output = wpshop_display::display_template_element('wpshop_customer_addresses_form_admin', $tpl_component, array(), 'admin'); unset($tpl_component); $result = json_encode(array(true, $output)); echo $result; die; }
/** * Check if a given list of attributes exist for a given custom post type * * @param string $identifier The custom post type identifier. This identifier is unique into database * @param array $tpl_component An array with already existing template element (Allows to merge existing and new) * @param boolean $has_error The current state of request. Could be false if the parent custom post type does not exist * * @return array The different response element for the request. $has_error: A boolean information for request result / $output: The complete html output for attribute check */ public static function check_default_cpt_attributes($identifier, $tpl_component, $has_error, $custom_file = '') { global $wpdb, $attribute_displayed_field; $output = ''; $cpt_attributes_file_uri = !empty($custom_file) ? $custom_file : WPSHOP_TEMPLATES_DIR . 'default_datas/' . $identifier . '-attributes.csv'; if (is_file($cpt_attributes_file_uri)) { /** Read lines into file defining default datas */ $csv_file_default_data = file($cpt_attributes_file_uri, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!empty($csv_file_default_data)) { $header_line = explode(';', $csv_file_default_data[0]); unset($csv_file_default_data[0]); $code_column = null; $available_columns = array(); foreach ($header_line as $column_key => $column_value) { if ($column_value == 'code') { $code_column = $column_key; // $available_columns[$column_value] = $column_key; } else { if (in_array($column_value, array('frontend_label'))) { $available_columns[$column_value] = $column_key; } } } /** Read the complete file content */ $attribute_ok = $attribute_not_ok = ' '; foreach ($csv_file_default_data as $line_index => $line_content) { $line_contents = explode(';', $line_content); $query = $wpdb->prepare("SELECT id, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $line_contents[$code_column], wpshop_entities::get_entity_identifier_from_code($identifier)); $attribute = $wpdb->get_row($query); if (!empty($line_contents)) { foreach ($line_contents as $line_column => $line_column_value) { if (in_array($line_column, $available_columns)) { if (!empty($attribute)) { $attribute_ok .= $attribute->frontend_label . ', '; } else { $attribute_not_ok .= $line_column_value . ', '; $has_error = true; } } } } } $attribute_not_ok = substr($attribute_not_ok, 2, -2); if (!empty($attribute_not_ok)) { $output .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element_content_attributes_error', array_merge($tpl_component, array('CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES_LIST' => $attribute_not_ok)), array(), 'admin'); } $attribute_ok = substr($attribute_ok, 2, -2); if (!empty($attribute_ok)) { $output .= wpshop_display::display_template_element('wpshop_admin_tools_default_datas_check_main_element_content_attributes_no_error', array_merge($tpl_component, array('CUSTOM_POST_TYPE_DEFAULT_ATTRIBUTES_LIST' => $attribute_ok)), array(), 'admin'); } } } return array($has_error, $output); }
public static function get_product_complete_sheet_attachments($product_id) { /** Get attachement file for the current product */ $product_picture_galery_content = $product_document_galery_content = ''; $picture_number = $document_number = $index_li = 0; $attachments = self::get_attachments($product_id, 'attachments'); if (is_array($attachments) && count($attachments) > 0) { $picture_increment = $document_increment = 1; foreach ($attachments as $attachment) { $tpl_component = array(); $tpl_component['ATTACHMENT_ITEM_GUID'] = wp_get_attachment_url($attachment->ID); $tpl_component['ATTACHMENT_ITEM_TITLE'] = $attachment->post_title; if (is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) { $tpl_component['ATTACHMENT_ITEM_TYPE'] = 'document'; $tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = !($document_increment % WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE) ? 'wpshop_gallery_document_last' : ''; /** Template parameters */ $template_part = 'product_attachment_item_document'; $tpl_component['PRODUCT_ID'] = $product_id; /** 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]); $product_document_galery_content .= ob_get_contents(); ob_end_clean(); } else { $product_document_galery_content .= wpshop_display::display_template_element($template_part, $tpl_component); } $document_number++; $document_increment++; } unset($tpl_component); } } return $product_document_galery = $document_number >= 1 ? self::display_attachment_gallery('document', $product_document_galery_content) : ''; }
/** * Display a category in a list * * @param object $category The category definition * @param string $output_type The output type defined from plugin option * * @return mixed $content Output the category list */ public static function category_mini_output($category, $output_type = 'list') { $content = ''; /* Get the different informations for output */ $category_meta_information = !empty($category) && !empty($category->term_id) ? get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category->term_id) : ''; $categoryThumbnail = '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail" />'; /* Check if there is already a picture for the selected category */ if (!empty($category_meta_information['wpshop_category_picture'])) { $image_post = wp_get_attachment_image($category_meta_information['wpshop_category_picture'], 'thumbnail', false, array('class' => 'category_thumbnail')); $categoryThumbnail = !empty($image_post) ? $image_post : '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail" />'; } $category_title = !empty($category) && !empty($category->name) ? $category->name : ''; $category_more_informations = !empty($category) && !empty($category->description) ? $category->description : ''; $category_link = !empty($category) && !empty($category->term_id) ? get_term_link((int) $category->term_id, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES) : ''; $item_width = null; /* Make some treatment in case we are in grid mode */ if ($output_type == 'grid') { /* Determine the width of a component in a line grid */ $element_width = 100 / WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; $item_width = round($element_width) - 1 . '%'; } /* * Template parameters */ $template_part = 'category_mini_' . $output_type; $tpl_component = array(); $tpl_component['CATEGORY_LINK'] = $category_link; $tpl_component['CATEGORY_THUMBNAIL'] = $categoryThumbnail; $tpl_component['CATEGORY_TITLE'] = $category_title; $tpl_component['CATEGORY_DESCRIPTION'] = $category_more_informations; $tpl_component['ITEM_WIDTH'] = $item_width; $tpl_component['CATEGORY_ID'] = !empty($category) && !empty($category->term_id) ? $category->term_id : ''; $tpl_component['CATEGORY_DISPLAY_TYPE'] = $output_type; /* * 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 = ob_get_contents(); ob_end_clean(); } else { $content = wpshop_display::display_template_element($template_part, $tpl_component); } unset($tpl_component); return $content; }
/** * Return the list page content, containing the table that present the item list * * @return string $listItemOutput The html code that output the item list */ public static function unit_group_list() { $listItemOutput = ''; /* Start the table definition */ $tableId = self::getDbTable() . '_group_list'; $tableSummary = __('Existing attributes listing', 'wpshop'); $tableTitles = array(); $tableTitles[] = __('Attribute unit group name', 'wpshop'); $tableClasses = array(); $tableClasses[] = 'wpshop_' . self::currentPageCode . '_label_column'; $line = 0; $elementList = self::get_unit_group(); if (is_array($elementList) && count($elementList) > 0) { foreach ($elementList as $element) { $tableRowsId[$line] = self::getDbTable() . '_' . $element->id; $elementLabel = __($element->name, 'wpshop'); $subRowActions = ''; $attributeSlugUrl = self::getListingSlug(); if (current_user_can('wpshop_add_attributes_unit_group')) { $attributeSlugUrl = self::getEditionSlug(); } if (current_user_can('wpshop_edit_attributes_unit_group')) { $editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&action=edit&id=' . $element->id); $subRowActions .= ' <a href="#" id="edit_attribute_unit_group_' . $element->id . '" class="edit_attribute_unit_group" >' . __('Edit', 'wpshop') . '</a>'; } elseif (current_user_can('wpshop_view_attributes_unit_group')) { $editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&action=edit&id=' . $element->id); } if (current_user_can('wpshop_delete_attributes_unit_group')) { if ($subRowActions != '') { $subRowActions .= ' | '; } $subRowActions .= ' <a href="#" id="delete_attribute_unit_group_' . $element->id . '" class="delete_attribute_unit_group" >' . __('Delete', 'wpshop') . '</a>'; } $rowActions = ' <div id="rowAction' . $element->id . '" class="wpshopRowAction" >' . $subRowActions . ' </div>'; unset($tableRowValue); $tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => str_replace('\\', '', $elementLabel) . $rowActions); $tableRows[] = $tableRowValue; $line++; } } else { unset($tableRowValue); $tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => __('No element to ouput here', 'wpshop')); $tableRows[] = $tableRowValue; } if (current_user_can('wpshop_add_attributes_unit_group')) { $listItemOutput .= ' <input type="button" value="' . __('Add an unit group', 'wpshop') . '" class="button-secondary alignleft" name="add_attribute_unit_group" id="add_attribute_unit_group" />'; } $listItemOutput .= wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, $tableSummary, true) . ' <script type="text/javascript" > wpshop(document).ready(function(){ jQuery("#' . $tableId . '").dataTable(); jQuery("#wpshop_unit_list_tab").show();'; if (current_user_can('wpshop_delete_attributes_unit_group')) { $listItemOutput .= ' wpshop(".delete_attribute_unit_group").click(function(){ if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this unit group', 'wpshop') . ' ?"))){ wpshop("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, { "post": "true", "elementCode": "attribute_unit_management", "action": "delete_attribute_unit_group", "elementIdentifier": wpshop(this).attr("id").replace("delete_attribute_unit_group_", "") }); } });'; } if (current_user_can('wpshop_edit_attributes_unit_group')) { $listItemOutput .= ' wpshop(".edit_attribute_unit_group").click(function(){ wpshop("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, { "post": "true", "elementCode": "attribute_unit_management", "action": "edit_attribute_unit_group", "elementIdentifier": wpshop(this).attr("id").replace("edit_attribute_unit_group_", "") }); });'; } if (current_user_can('wpshop_add_attributes_unit_group')) { $listItemOutput .= ' wpshop("#add_attribute_unit_group").click(function(){ wpshop("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, { "post": "true", "elementCode": "attribute_unit_management", "action": "add_attribute_unit_group" }); });'; } $listItemOutput .= ' }); </script>'; return $listItemOutput; }
/* Wordpress - Main bootstrap file that load wordpress basic files */ require_once '../../../../wp-load.php'; /* Wordpress - Admin page that define some needed vars and include file */ require_once ABSPATH . 'wp-admin/includes/admin.php'; $order_id = !empty($_GET['order_id']) ? wpshop_tools::varSanitizer($_GET['order_id']) : null; $invoice_ref = !empty($_GET['credit_ref']) ? wpshop_tools::varSanitizer($_GET['credit_ref']) : null; $mode = !empty($_GET['mode']) ? wpshop_tools::varSanitizer($_GET['mode']) : 'html'; // $is_credit_slip = (!empty($_GET['credit_slip'])) ? wpshop_tools::varSanitizer($_GET['credit_slip']) : null; if (!empty($order_id)) { // /** Order reading */ $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); $html_content = wps_credit::generate_credit_slip($order_id, $invoice_ref); if ($mode == 'pdf') { require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'; try { $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; $html2pdf = new HTML2PDF('P', 'A4', 'fr'); $html2pdf->setDefaultFont('Arial'); $html2pdf->writeHTML($html_content); $html2pdf->Output('order_' . $order_id . '.pdf', 'D'); } catch (HTML2PDF_exception $e) { echo $e; exit; } } else { $tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common'); $tpl_component['INVOICE_MAIN_PAGE'] = $html_content; $tpl_component['INVOICE_TITLE_PAGE'] = sprintf(__('Credit slip #%s for Order #%s', 'wpshop'), $invoice_ref, $order_postmeta['order_key']); echo wpshop_display::display_template_element('invoice_page', $tpl_component, array(), 'common'); } }
/** * Genrate Footer invoice * @return Ambigous <string, string> */ public static function generate_footer_invoice() { $output = ''; $company = get_option('wpshop_company_info', array()); $emails = get_option('wpshop_emails', array()); if (!empty($company)) { $tpl_component['COMPANY_EMAIL'] = !empty($emails) && !empty($emails['contact_email']) ? $emails['contact_email'] : ''; $tpl_component['COMPANY_WEBSITE'] = site_url(); foreach ($company as $company_info_key => $company_info_value) { switch ($company_info_key) { case 'company_rcs': $data = !empty($company_info_value) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; break; case 'company_capital': $data = !empty($company_info_value) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; break; case 'company_siren': $data = !empty($company_info_value) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; break; case 'company_siret': $data = !empty($company_info_value) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; break; case 'company_tva_intra': $data = !empty($company_info_value) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; break; default: $data = $company_info_value; break; } $tpl_component[strtoupper($company_info_key)] = $data; } $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common'); } return $output; }
public static function get_product_price($product, $return_type, $output_type = '', $only_price = false, $price_checking_done = false) { $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); // $wpshop_price_piloting_option = 'TTC'; /** Price for Mini-output **/ if (!$price_checking_done) { /** Checking if it's a product with variation **/ $variation_option_checking = get_post_meta($product['product_id'], '_wpshop_variation_defining', true); if (!empty($variation_option_checking)) { $variations_exists = wpshop_products::get_variation($product['product_id']); } if (!empty($variation_option_checking) && !empty($variations_exists)) { if (!empty($variation_option_checking['attributes'])) { foreach ($variation_option_checking['attributes'] as $attribute) { $selected_variation[$attribute] = 0; if (!empty($variation_option_checking['options']) && !empty($variation_option_checking['options']['attributes_default_value']) && array_key_exists($attribute, $variation_option_checking['options']['attributes_default_value'])) { if ($variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') { $selected_variation[$attribute] = $variation_option_checking['options']['attributes_default_value'][$attribute]; } } } } if (!empty($selected_variation)) { $product_with_variation = wpshop_products::get_variation_by_priority($selected_variation, $product['product_id']); } if (empty($product_with_variation[$product['product_id']]['variations'])) { $product_with_variation[$product['product_id']]['variations'] = array(); } if (!empty($product_with_variation[$product['product_id']]['variation_priority'])) { $product = wpshop_products::get_variation_price_behaviour($product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : '')); } } else { /** It's Simple product Check Discounts for products **/ $discount_config = self::check_discount_for_product($product['product_id']); if (!empty($discount_config)) { if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') { $product['price_ttc_before_discount'] = $product['product_price']; $product['price_ht_before_discount'] = $product['price_ht']; $product['price_ht'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100); $product['product_price'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value']; $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); } elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') { $product['price_ttc_before_discount'] = $product['product_price']; $product['price_ht_before_discount'] = $product['price_ht']; $product['price_ht'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $product['price_ht_before_discount'] - $discount_config['value'] : ($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100); $product['product_price'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value']; $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); } elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { $product['price_ttc_before_discount'] = $product['product_price']; $product['price_ht_before_discount'] = $product['price_ht']; $product['price_ht'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100) : $product['price_ttc_before_discount'] * (1 - $discount_config['value'] / 100) / (1 + $product['tx_tva'] / 100); $product['product_price'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - $discount_config['value'] / 100); $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); } } } } $price_infos = self::check_product_price($product); $productCurrency = '<span class="wps-currency">' . wpshop_tools::wpshop_get_currency() . '</span>'; $wps_marketing_tools = new wps_marketing_tools_ctr(); if (!empty($price_infos)) { if ($return_type == 'check_only') { /** Check if the product price has been set */ if (isset($price_infos['ati']) && $price_infos['ati'] === '') { return __('This product cannot be purchased - the price is not yet announced', 'wpshop'); } /** Check if the product price is coherent (not less than 0) */ if (isset($price_infos['ati']) && $price_infos['ati'] < 0) { return __('This product cannot be purchased - its price is negative', 'wpshop'); } return true; } elseif ($return_type == 'just_price_infos') { $tpl_component = array(); $price = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $price_infos['et'] : $price_infos['ati']; $exploded_price = explode('.', number_format($price, 2, '.', '')); $price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">,' . (!empty($exploded_price[1]) ? $exploded_price[1] : '') . '</span>'; $tpl_component['TAX_PILOTING'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? __('ET', 'wpshop') : ''; $tpl_component['CROSSED_OUT_PRICE'] = ''; $tpl_component['MESSAGE_SAVE_MONEY'] = ''; if (!empty($price_infos['discount']['discount_exist'])) { $crossed_out_price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency; $tpl_component['CROSSED_OUT_PRICE'] = $crossed_out_price; if (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') { $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', '')); } else { $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', '')); } $discount_price = $exploded_discount_price[0] . '<span class="wpshop_price_centimes_display">,' . (!empty($exploded_discount_price[1]) ? $exploded_discount_price[1] : '') . '</span>'; $tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">' . $discount_price . '</span> ' . $productCurrency; $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_infos); } else { $tpl_component['PRODUCT_PRICE'] = $price . ' ' . $productCurrency; } $post_type = get_post_type($product['product_id']); if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { $price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true); } elseif ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_def = wpshop_products::get_parent_variation($product['product_id']); if (!empty($parent_def) && !empty($parent_def['parent_post'])) { $parent_post = $parent_def['parent_post']; $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); } } $price_display_option = get_option('wpshop_catalog_product_option'); $tpl_component['PRICE_FROM'] = !empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) || !empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']))) ? 'on' : ''; return $tpl_component; } else { if ($return_type == 'price_display') { $tpl_component = array(); $price = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $price_infos['et'] : $price_infos['ati']; $price_data = $price_infos; $exploded_price = explode('.', number_format($price, 2, '.', '')); $price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . (!empty($exploded_price[1]) ? $exploded_price[1] : '') . '</span>'; $tpl_component['TAX_PILOTING'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? __('ET', 'wpshop') : ''; $tpl_component['CROSSED_OUT_PRICE'] = ''; $tpl_component['MESSAGE_SAVE_MONEY'] = ''; if (!empty($price_infos['discount']['discount_exist'])) { $text_from = false; /** Get variation defining **/ $post_type = get_post_type($product['product_id']); if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_def = wpshop_products::get_parent_variation($product['product_id']); if (!empty($parent_def) && !empty($parent_def['parent_post'])) { $parent_post = $parent_def['parent_post']; $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); } } else { $price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true); } $text_from = !empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) || !empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']))) && !empty($product['text_from']) ? true : false; $exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', '')); $price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . (!empty($exploded_price[1]) ? $exploded_price[1] : '') . '</span>'; $exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', '')); $price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . (!empty($exploded_price[1]) ? $exploded_price[1] : '') . '</span>'; $crossed_out_price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency; $tpl_component['CROSSED_OUT_PRICE'] = str_replace('.', ',', ($text_from ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price))); $tpl_component['PRODUCT_PRICE'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? '<span class="wps-absolute-price">' . $price_infos['discount']['discount_et_price'] . '</span> ' . $productCurrency : '<span class="wps-absolute-price">' . $price_infos['discount']['discount_ati_price'] . '</span> ' . $productCurrency; $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_data); } else { if (get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_def = wpshop_products::get_parent_variation($product['product_id']); $pid = $parent_def['parent_post']; $pid = $pid->ID; } else { $pid = $product['product_id']; } $text_from = false; /** Get variation defining **/ $post_type = get_post_type($pid); if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_def = wpshop_products::get_parent_variation($pid); if (!empty($parent_def) && !empty($parent_def['parent_post'])) { $parent_post = $parent_def['parent_post']; $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); } } else { $price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true); } $price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true); $text_from = !empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) || !empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']))) ? true : false; $tpl_component['PRODUCT_PRICE'] = $text_from && !empty($product['text_from']) ? __('Price from', 'wpshop') . ' ' : ''; $tpl_component['PRODUCT_PRICE'] .= $price . ' ' . $productCurrency; } // Replace . by , $tpl_component['PRODUCT_PRICE'] = str_replace('.', ',', $tpl_component['PRODUCT_PRICE']); if ($output_type == 'complete_sheet') { $price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component); } elseif ($output_type == 'mini_output' || in_array('mini_output', $output_type)) { $price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component); } return $price_tpl; } } } return false; }
alert(wpshopConvertAccentTojs("<?php _e('Default attributes translation has been updated', 'wpshop'); ?> ")); } else { alert(wpshopConvertAccentTojs("<?php _e('An error occured while attempting to repair default attributes', 'wpshop'); ?> ")); } }, 'json'); }); }); </script><?php echo wpshop_display::displayPageFooter(false); $tpl_element['wpshop_admin_tools_main_page'] = ob_get_contents(); ob_end_clean(); ob_start(); ?> <div id="wps_tools_mas_action_message_copy_betwwen_attributes" ></div><form method="post" id="wps_tools_mass_update_form" action="<?php echo admin_url('admin-ajax.php'); ?> " ><input type="hidden" name="action" value="wps_mass_action_update_attribute" /><?php _e('Copy the different values of a given attribute into another attribute for products', 'wpshop'); ?> <br/><?php echo sprintf(__('Copy values from %s to %s', 'wpshop'), '{WPSHOP_ATTRIBUTE_LIST_FROM}', '{WPSHOP_ATTRIBUTE_LIST_TO}'); ?> <select name="wps_entity_to_transfert" > <option value="wpshop_product" ><?php
/** * Allows to inform customer that he would pay a partial amount on this order * * @param float $current_order_total The current order total to pay before partial amount calcul * @return array The amount to pay / A html output with amount to pay and different information */ function partial_payment_calcul($current_order_total) { $output = ''; $tpl_component = array(); /** Get current configuration */ $partial_payment_configuration = get_option('wpshop_payment_partial', array('for_all' => array())); if (!empty($partial_payment_configuration['for_all']) && !empty($partial_payment_configuration['for_all']['activate']) && $partial_payment_configuration['for_all']['activate'] == 'on') { $amount_of_partial_payment = 0; if (!empty($partial_payment_configuration['for_all']['value'])) { $amount_of_partial_payment = $partial_payment_configuration['for_all']['value']; } $partial_amount_to_pay = 0; $type_of_partial_payment = null; if (!empty($partial_payment_configuration['for_all']) && !empty($partial_payment_configuration['for_all']['type'])) { switch ($partial_payment_configuration['for_all']['type']) { case 'percentage': $type_of_partial_payment = '%'; $partial_amount_to_pay = $current_order_total * $amount_of_partial_payment / 100; break; case 'amount': $type_of_partial_payment = wpshop_tools::wpshop_get_currency(); $partial_amount_to_pay = $current_order_total - $amount_of_partial_payment; break; default: $type_of_partial_payment = wpshop_tools::wpshop_get_currency(); $partial_amount_to_pay = $current_order_total - $amount_of_partial_payment; break; } } $output['amount_of_partial_payment'] = $amount_of_partial_payment; $output['type_of_partial_payment'] = $type_of_partial_payment; $output['amount_to_pay'] = $partial_amount_to_pay; $tpl_component['CURRENT_ORDER_TOTAL_AMOUNT'] = $current_order_total; $tpl_component['PARTIAL_PAYMENT_CONFIG_AMOUNT'] = !empty($amount_of_partial_payment) ? $amount_of_partial_payment : ''; $tpl_component['PARTIAL_PAYMENT_CONFIG_TYPE'] = !empty($type_of_partial_payment) ? $type_of_partial_payment : ''; $tpl_component['PARTIAL_PAYMENT_AMOUNT'] = $partial_amount_to_pay; $output['display'] = wpshop_display::display_template_element('wpshop_partial_payment_display', $tpl_component); unset($tpl_component); } return $output; }
/** * Affiche la page des groupes */ public static function display_page() { self::manage_post(); ob_start(); wpshop_display::displayPageHeader(__('Groups', 'wpshop'), '', __('Groups', 'wpshop'), __('Groups', 'wpshop'), true, 'admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '&action=add', ''); $content = ob_get_contents(); ob_end_clean(); $wps_customer_mdl = new wps_customer_mdl(); // Si on re�oit une action if (!empty($_GET['action'])) { $readonly_name_field = ''; switch ($_GET['action']) { case 'delete': if (!empty($_GET['code'])) { $roles = get_option('wp_user_roles', array()); if (isset($roles[$_GET['code']]) && $_GET['code'] != 'customer' && $_GET['code'] != 'wpshop_customer') { unset($roles[$_GET['code']]); $this->unaffectUsersToGroup($_GET['code']); update_option('wp_user_roles', $roles); } } wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); break; case 'edit': $readonly_name_field = 'readonly'; if (!empty($_GET['code'])) { $role = $this->getRole($_GET['code']); if (!empty($role)) { $group_name = $role['name']; $group_description = $role['description']; $group_parent = $role['parent']; $submit_button_value = __('Edit the group', 'wpshop'); $submit_button_name = 'editrole'; // ROLES $roles = get_option('wp_user_roles', array()); $select_parent = '<option value="">--</option>'; foreach ($roles as $code => $role) { if ($code != $_GET['code']) { $selected = $group_parent == $code ? 'selected' : ''; $select_parent .= '<option value="' . $code . '" ' . $selected . '>' . $role['name'] . '</option>'; } } // USERS $users = $wps_customer_mdl->getUserList(); if (!empty($users)) { $select_users = ''; foreach ($users as $user) { if ($user->ID != 1) { $u = new WP_User($user->ID); $selected = isset($u->roles[0]) && $u->roles[0] == $_GET['code'] ? 'selected' : ''; $select_users .= '<option value="' . $user->ID . '" ' . $selected . '>' . $user->user_login . '</option>'; } } } } else { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); exit; } } else { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); exit; } break; case 'add': $group_name = $group_description = ''; $submit_button_value = __('Create the group', 'wpshop'); $submit_button_name = 'addrole'; // ROLES $roles = get_option('wp_user_roles', array()); $select_parent = '<option value="">--</option>'; foreach ($roles as $code => $role) { $select_parent .= '<option value="' . $code . '">' . $role['name'] . '</option>'; } // USERS $users = $wps_customer_mdl->getUserList(); $select_users = ''; if (!empty($users)) { foreach ($users as $user) { if ($user->ID != 1) { $select_users .= '<option value="' . $user->ID . '">' . $user->user_login . '</option>'; } } } break; } $content .= ' <form method="post"> <label>' . __('Name', 'wpshop') . '</label><br /><input type="text" name="group-name" style="width:500px;" value="' . $group_name . '" ' . $readonly_name_field . ' /><br /><br /> <label>' . __('Parent', 'wpshop') . '</label><br /> <select name="group-parent" class="chosen_select" style="width:500px;"> ' . $select_parent . ' </select><br /><br /> <label>' . __('Users', 'wpshop') . '</label><br /> <select name="group-users[]" class="chosen_select" multiple style="width:500px;"> ' . $select_users . ' </select><br /><br /> <label>' . __('Description', 'wpshop') . '</label><br /><textarea name="group-description" style="width:500px;">' . $group_description . '</textarea><br /><br /> <input type="submit" class="button-primary" name="' . $submit_button_name . '" value="' . $submit_button_value . '" /> <a href="admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '">' . __('Cancel', 'wpshop') . '</a> </form> '; } else { $wpshop_list_table = new wpshop_groups_custom_List_table(); //Fetch, prepare, sort, and filter our data... $status = "'valid'"; if (!empty($_REQUEST['attribute_status'])) { switch ($_REQUEST['attribute_status']) { case 'unactive': $status = "'moderated', 'notused'"; if (empty($_REQUEST['orderby']) && empty($_REQUEST['order'])) { $_REQUEST['orderby'] = 'status'; $_REQUEST['order'] = 'asc'; } break; default: $status = "'" . $_REQUEST['attribute_status'] . "'"; break; } } $roles = get_option('wp_user_roles', array()); $i = 0; $attribute_set_list = array(); $group_not_to_display = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); $wpshop_groups_meta = get_option('wpshop_groups_meta', array()); foreach ($roles as $code => $role) { if (!in_array($code, $group_not_to_display)) { $description = !empty($wpshop_groups_meta[$code]['description']) ? $wpshop_groups_meta[$code]['description'] : '--'; $attribute_set_list[$i]['name'] = $role['name']; $attribute_set_list[$i]['description'] = $description; $attribute_set_list[$i]['code'] = $code; $i++; } } $wpshop_list_table->prepare_items($attribute_set_list); ob_start(); $wpshop_list_table->display(); $element_output = ob_get_contents(); ob_end_clean(); $content .= $element_output; } $content .= '</div>'; echo $content; }
/** Credit Slip Generation **/ function generate_credit_slip($order_id, $credit_ref) { $order_meta = get_post_meta($order_id, '_order_postmeta', true); $credit_meta = get_post_meta($order_id, '_wps_order_credit', true); if (!empty($credit_meta)) { foreach ($credit_meta as $id => $credit_def) { if ($credit_def['ref'] == $credit_ref) { $credit = $credit_meta[$id]; } } } $credit_date = !empty($credit) && !empty($credit['credit_date']) ? $credit['credit_date'] : ''; $logo_options = get_option('wpshop_logo'); $tpl_component['INVOICE_SUMMARY_MORE'] = ''; $tpl_component['INVOICE_LOGO'] = !empty($logo_options) ? '<img src="' . $logo_options . '" alt="" />' : ''; $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = sprintf(__('Correction on order n. %s', 'wpshop'), $order_meta['order_key']); $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = sprintf(__('Credit slip date %s', 'wpshop'), $credit_date); $tpl_component['INVOICE_VALIDATE_TIME'] = ''; $tpl_component['IBAN_INFOS'] = ''; $tpl_component['AMOUNT_INFORMATION'] = sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)); /** Header **/ $tpl_component['INVOICE_TITLE'] = __('Credit slip', 'wpshop'); $tpl_component['INVOICE_ORDER_INVOICE_REF'] = $credit_ref; $tpl_component['INVOICE_SENDER'] = wpshop_modules_billing::generate_invoice_sender_part(); $tpl_component['INVOICE_RECEIVER'] = wpshop_modules_billing::generate_receiver_part($order_id); /** Tab **/ $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('credit_slip_row_header', array(), array(), 'common'); /** Rows **/ $tpl_component['INVOICE_ROWS'] = ''; $total_HT = $total_TTC = 0; $credit_TVA = array(); if (!empty($credit['items'])) { foreach ($credit['items'] as $item) { $sub_tpl_component = array(); $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item['item_name']; $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($item['item_total_ht'], 2, '.', ''); $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = '-' . number_format($item['item_tva_total_amount'], 2, '.', '') . ' (' . $item['item_tva_rate'] . '%)'; $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($item['item_total_ttc'], 2, '.', ''); $total_HT += $item['item_total_ht']; $total_TTC += $item['item_total_ttc']; if (empty($credit_TVA[(string) $item['item_tva_rate']])) { $credit_TVA[$item['item_tva_rate']] = $item['item_tva_total_amount']; } else { $credit_TVA[(string) $item['item_tva_rate']] += $item['item_tva_total_amount']; } $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('credit_slip_row', $sub_tpl_component, array(), 'common'); unset($sub_tpl_component); } } $d = ''; foreach ($credit_TVA as $tx => $value) { $tva_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Tax amount (%s %s)', 'wpshop'), $tx, '%'); $tva_tpl_component['SUMMARY_ROW_VALUE'] = '-' . number_format($value, '2', '.', '') . ' ' . wpshop_tools::wpshop_get_currency(false); $d .= wpshop_display::display_template_element('invoice_summary_row', $tva_tpl_component, array(), 'common'); unset($tva_tpl_component); } $sub_tpl_component['CREDIT_SLIP_SUMMARY_TVA'] = $d; $sub_tpl_component['INVOICE_SUMMARY_MORE'] = ''; $sub_tpl_component['CREDIT_SLIP_TOTAL_HT'] = '-' . number_format($total_HT, '2', '.', ''); $sub_tpl_component['CREDIT_SLIP_ORDER_GRAND_TOTAL'] = '-' . number_format($total_TTC, '2', '.', ''); $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('credit_slip_summary_part', $sub_tpl_component, array(), 'common'); $tpl_component['RECEIVED_PAYMENT'] = ''; $tpl_component['INVOICE_FOOTER'] = wpshop_modules_billing::generate_footer_invoice(); $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common'); unset($tpl_component); return $output; }
/** * Display the main option page. Read all groups/subgroups and options fields defined in wpshop core and modules/addons */ public static function option_main_page() { global $options_errors; $tpl_component = array(); $options_list = wpshop_options::declare_options_groups(); ob_start(); settings_fields('wpshop_options'); $tpl_component['ADMIN_OPTIONS_FIELDS_FOR_NONCE'] = ob_get_contents(); ob_end_clean(); $tpl_component['ADMIN_OPTIONS_TAB_LIST'] = ''; $tpl_component['ADMIN_OPTIONS_TAB_CONTENT_LIST'] = ''; if (!empty($options_list)) { foreach ($options_list as $group_key => $group_content) { $sub_tpl_component = array(); if (!empty($group_content['subgroups']) && is_array($group_content['subgroups'])) { $sub_tpl_component['ADMIN_OPTIONS_GROUP_CONTENT'] = ''; $sub_tpl_component['ADMIN_OPTIONS_TAB_KEY'] = $group_key; $sub_tpl_component['ADMIN_OPTIONS_TAB_LABEL'] = !empty($group_content['label']) ? $group_content['label'] : ''; $tpl_component['ADMIN_OPTIONS_TAB_LIST'] .= wpshop_display::display_template_element('wpshop_admin_options_group_tab', $sub_tpl_component, array(), 'admin'); foreach ($group_content['subgroups'] as $subgroup_key => $subgroup_def) { ob_start(); do_settings_sections($subgroup_key); $sub_tpl_component['ADMIN_OPTIONS_SUBGROUP_CONTENT'] = ob_get_contents(); ob_end_clean(); $sub_tpl_component['ADMIN_OPTIONS_SUBGROUP_CLASS'] = $subgroup_def['class']; $sub_tpl_component['ADMIN_OPTIONS_GROUP_CONTENT'] .= wpshop_display::display_template_element('wpshop_admin_options_subgroup_container', $sub_tpl_component, array(), 'admin'); } $tpl_component['ADMIN_OPTIONS_TAB_CONTENT_LIST'] .= wpshop_display::display_template_element('wpshop_admin_options_group_container', $sub_tpl_component, array(), 'admin'); } } } echo wpshop_display::display_template_element('wpshop_admin_options_main_page', $tpl_component, array(), 'admin'); }
function get_billing_address_summary() { $output = ''; if (!empty($_SESSION['billing_address'])) { $address_infos = get_post_meta($_SESSION['billing_address'], '_wpshop_address_metadata', true); $tpl_component['ADDRESS'] = self::display_an_address($address_infos); $tpl_component['TITLE'] = __('Billing informations', 'wpshop'); $tpl_component['ADDRESS_ID'] = $_SESSION['billing_address']; $output = wpshop_display::display_template_element('wps_shipping_address_summary', $tpl_component, array(), 'wpshop'); unset($tpl_component); } return $output; }
/** * Define the tools main page */ public static function main_page() { echo wpshop_display::display_template_element('wpshop_admin_tools_main_page', array(), array(), 'admin'); }
/** * Frontend javascript caller */ public static function frontend_js_instruction() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-form'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-effects-core'); wp_enqueue_script('jquery-effects-highlight'); wp_enqueue_script('jquery-ui-slider'); wp_enqueue_script('wpshop_frontend_main_js', wpshop_display::get_template_file('frontend_main.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true); // wp_enqueue_script('wpshop_jquery_jqzoom_core_js', wpshop_display::get_template_file('jquery.jqzoom-core.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true); wp_enqueue_script('fancyboxmousewheel', WPSHOP_JS_URL . 'fancybox/jquery.mousewheel-3.0.4.pack.js', '', WPSHOP_VERSION, true); wp_enqueue_script('fancybox', WPSHOP_JS_URL . 'fancybox/jquery.fancybox-1.3.4.pack.js', '', WPSHOP_VERSION, true); wp_enqueue_script('jquery_address', WPSHOP_JS_URL . 'jquery-libs/jquery.address-1.5.min.js', '', WPSHOP_VERSION); wp_enqueue_script('wps_api', wpshop_display::get_template_file('wps-api.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true); wp_enqueue_script('jquery.nouislider.min', wpshop_display::get_template_file('jquery.nouislider.min.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true); wp_enqueue_script('wps_owl_caroussel', wpshop_display::get_template_file('owl.carousel.min.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true); ?> <script type="text/javascript"> var WPSHOP_AJAX_URL = "<?php echo WPSHOP_AJAX_FILE_URL; ?> "; var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?> "; var CURRENT_PAGE_URL = "<?php !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; ?> "; var WPSHOP_REQUIRED_FIELD_ERROR_MESSAGE = "<?php _e('Every fields marked as required must be filled', 'wpshop'); ?> "; var WPSHOP_INVALID_EMAIL_ERROR_MESSAGE = "<?php _e('Email invalid', 'wpshop'); ?> "; var WPSHOP_UNMATCHABLE_PASSWORD_ERROR_MESSAGE = "<?php _e('Both passwords must match', 'wpshop'); ?> "; var WPSHOP_CHOSEN_NO_RESULT = "<?php _e('No result found for your search', 'wpshop'); ?> "; var WPSHOP_CHOSEN_SELECT_FROM_MULTI_LIST = "<?php _e('Select values from list', 'wpshop'); ?> "; var WPSHOP_CHOSEN_SELECT_FROM_LIST = "<?php _e('Select an Option', 'wpshop'); ?> "; var WPSHOP_AJAX_CHOSEN_KEEP_TYPING = "<?php _e('Keep typing for search launching', 'wpshop'); ?> "; var WPSHOP_AJAX_CHOSEN_SEARCHING = "<?php _e('Searching in progress for', 'wpshop'); ?> "; var WPSHOP_PRODUCT_VARIATION_REQUIRED_MSG = "<div id='wpshop_product_add_to_cart_form_result' class='error_bloc' ><?php _e('Please select all required value', 'wpshop'); ?> </div>"; var WPSHOP_ACCEPT_TERMS_OF_SALE = "<?php _e('You must accept the terms of sale.', 'wpshop'); ?> "; var WPSHOP_MUST_CHOOSE_SHIPPING_MODE = "<?php _e('You must to choose a shipping mode', 'wpshop'); ?> "; var WPSHOP_NO_SHIPPING_MODE_AVAILABLE = "<?php _e('You can\'t order because no shipping mode is available.', 'wpshop'); ?> "; var WPSHOP_LOADER_ICON_JQUERY_ADDRESS = "<img src=\"<?php echo WPSHOP_LOADING_ICON; ?> \" alt=\"Loading...\" />"; var WPSHOP_CONFIRM_DELETE_ADDRESS = "<?php _e('Do you really want to delete this address ?', 'wpshop'); ?> "; var wps_speed_slideUpDown = 200; var MODAL_URL = '<?php echo WPSHOP_TEMPLATES_URL; ?> wpshop/modal.php'; </script> <?php }
/** * Definition for the wyswiwyg editor * * @param object $object The type of element currently edited */ public static function wpshop_add_form($object = '') { global $pagenow; $content = is_object($object) && isset($object->description) ? html_entity_decode($object->description, ENT_COMPAT | ENT_HTML401, 'UTF-8') : ''; if (in_array($pagenow, array('edit-tags.php'))) { $editor_id = 'tag_description'; $editor_selector = 'description'; } else { $editor_id = $editor_selector = 'category_description'; } /* * Template parameters */ $template_part = 'wpshop_transform_taxonomy_description_field_into_wysiwyg'; if (!empty($_GET['action']) && $_GET['action'] == 'edit') { $template_part = 'wpshop_transform_taxonomy_description_field_into_wysiwyg_for_full_page'; } $tpl_component = array(); ob_start(); wp_editor($content, $editor_id, array('textarea_name' => $editor_selector, 'editor_css' => wpshop_display::display_template_element('wpshop_taxonomy_wysiwyg_editor_css', array(), array(), 'admin'))); $tpl_component['ADMIN_TAXONOMY_WYSIWYG'] = ob_get_contents(); ob_end_clean(); echo wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); unset($tpl_component); }
/** * Display the WPShop Breadcrumb */ function display_wpshop_breadcrumb() { global $wpdb; global $wp_query; global $wpdb; $output = $breadcrumb = ''; /** Check if the queried object is aproduct or a category **/ if (!empty($wp_query) && !empty($wp_query->queried_object_id)) { $current_id = $wp_query->queried_object_id; $object = $wp_query; $taxonomy = !empty($object->queried_object->taxonomy) ? $object->queried_object->taxonomy : ''; $on_product_page = false; /** Check if we are on a product_page OR Taxonomy Page**/ if (!empty($object->queried_object->post_type) && $object->queried_object->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { $taxonomy = WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES; $breadcrumb_definition = array(); $query = $wpdb->prepare('SELECT term_taxonomy_id FROM ' . $wpdb->term_relationships . ' WHERE object_id = %d', $wp_query->queried_object_id); $product_categories = $wpdb->get_results($query); $max = $deeper_category_id = 0; if (!empty($product_categories)) { foreach ($product_categories as $product_category) { $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE term_taxonomy_id = %d LIMIT 1', $product_category->term_taxonomy_id); $cat_id = $wpdb->get_var($query); $tmp_breadcrumb_definition = $this->get_breadcrumb($cat_id); if ($max <= count($tmp_breadcrumb_definition)) { $max = count($tmp_breadcrumb_definition); $deeper_category_id = $product_category->term_taxonomy_id; } } } $deeper_category_id = !empty($cat_id) ? $cat_id : $deeper_category_id; $breadcrumb_definition = $this->get_breadcrumb($deeper_category_id); $on_product_page = true; } elseif (!empty($object->queried_object->post_type) && $object->queried_object->post_type != WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { $breadcrumb_definition = $this->get_breadcrumb($object->queried_object->ID, 'custom_post_type', $object->queried_object->post_type); } elseif (!empty($object->queried_object->taxonomy)) { $breadcrumb_definition = $this->get_breadcrumb($object->queried_object->term_id, 'taxonomy', $object->queried_object->taxonomy); } else { $breadcrumb_definition = array(); } /** Construct the breadcrumb **/ if (!empty($breadcrumb_definition)) { $count_breadcrumb_definition = count($breadcrumb_definition); for ($i = $count_breadcrumb_definition - 1; $i >= 0; $i--) { if ($breadcrumb_definition[$i]['category_parent_id'] == 0) { $category_name = get_bloginfo(); $category_link = site_url(); } else { if (!empty($taxonomy)) { $term = get_term($breadcrumb_definition[$i]['category_parent_id'], $taxonomy); $category_name = !empty($term) && !empty($term->name) ? $term->name : ''; $category_link = !empty($term) && !empty($term->slug) ? get_term_link($term->slug, $taxonomy) : ''; } elseif (!empty($object->queried_object->post_type) && $object->queried_object->post_type != WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { $post = get_post($breadcrumb_definition[$i]['category_parent_id']); $category_name = $post->post_title; $category_link = get_permalink($breadcrumb_definition[$i]['category_parent_id']); } } if ($i == 0 && !$on_product_page) { $output .= wpshop_display::display_template_element('wpshop_breadcrumb_first_element', array('CATEGORY_NAME' => $category_name), array(), 'wpshop'); } else { $tpl_component = $sub_tpl_component = array(); $elements_list = $element_list = $tpl_component['OTHERS_CATEGORIES_LIST'] = ''; if (isset($breadcrumb_definition[$i]['category_parent_id'])) { if (!empty($breadcrumb_definition[$i]['category_children']) && is_array($breadcrumb_definition[$i]['category_children'])) { foreach ($breadcrumb_definition[$i]['category_children'] as $child_category) { $child_term = get_term($child_category, $taxonomy); $child_category_name = $child_term->name; $child_category_link = get_term_link($child_term->slug, $taxonomy); $element_list .= wpshop_display::display_template_element('wpshop_breadcrumb_others_categories_list_element', array('ELEMENT_LIST_CATEGORY_NAME' => $child_category_name, 'ELEMENT_LIST_CATEGORY_LINK' => $child_category_link), array(), 'wpshop'); } $elements_list = wpshop_display::display_template_element('wpshop_breadcrumb_others_categories_list', array('ELEMENTS_LIST' => $element_list), array(), 'wpshop'); } $tpl_component['CATEGORY_LINK'] = $category_link; $tpl_component['OTHERS_CATEGORIES_LIST'] = $elements_list; $tpl_component['CATEGORY_NAME'] = $category_name; $output .= wpshop_display::display_template_element('wpshop_breadcrumb_element', $tpl_component, array(), 'wpshop'); unset($tpl_component); } } } } if (!empty($post) && !empty($post->ID) && !empty($post->post_type) && $post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { // $tpl_component['CATEGORY_LINK'] = get_permalink( $post->ID ); // $tpl_component['OTHERS_CATEGORIES_LIST'] = ''; // $tpl_component['CATEGORY_NAME'] = $post->post_title; // $output .= wpshop_display::display_template_element('wpshop_breadcrumb_element', $tpl_component, array(), 'wpshop'); $output .= '<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="#">' . $post->post_title . '</a></li>'; } $breadcrumb = wpshop_display::display_template_element('wpshop_breadcrumb', array('BREADCRUMB_CONTENT' => $output), array(), 'wpshop'); return $breadcrumb; } }
function wps_get_summary_variations_product($product_id, $the_product, $has_variation) { global $wpdb; global $wpshop_payment; $output = ''; $tpl_component = array(); /** 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) { 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; } } } } $variation_attribute_ordered = array(); /** Check if product is a variation and change his name **/ $product_post_type = get_post_type($the_product['product_id']); if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); $parent_post = !empty($parent_infos) && !empty($parent_infos['parent_post']) ? $parent_infos['parent_post'] : array(); $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; } foreach ($the_product as $product_definition_key => $product_definition_value) { if ($product_definition_key != 'item_meta') { $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; } } else { $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); } } ksort($variation_attribute_ordered['attribute_list']); $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; } /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); if (!empty($attribute_list)) { foreach ($attribute_list as $attribute_def) { $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; } } /** Fill the array with all prices for different variations */ foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; } $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); $post_list_with_options = $wpdb->get_results($query); if (!empty($post_list_with_options)) { $additionnal_price = 0; foreach ($post_list_with_options as $product_info) { $product_meta = unserialize($product_info->meta_value); if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && $product_meta['cart']['auto_add'] == 'yes') { $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); $the_product = array_merge(array('product_id' => $product_info->post_id, 'product_qty' => 1), $product); $additionnal_price += !$different_currency || $change_rate == 1 ? $the_product['product_price'] : $the_product['product_price'] * $change_rate; $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; $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); $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); } } } $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; if (!empty($additionnal_price)) { $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price; $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); } /** Call informtion for partial payment */ $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; /** Define the current selected currency for the order summary */ // $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; return $output; }
/** * Get attribute defined as product option specific attribute * * @param array $variations_attribute_parameters Allows to give some parameters for customize list * @return string The output for all specific attribute in each product with option */ public static function get_variation_attribute($variations_attribute_parameters) { $output = ''; $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_in_variation", true); if (!empty($attribute_list)) { $tpl_component = array(); $tpl_component['ADMIN_VARIATION_DETAIL'] = ''; $price_piloting_option = get_option('wpshop_shop_price_piloting'); foreach ($attribute_list as $attribute_def) { $variations_attribute_parameters['field_custom_name_prefix'] = $variations_attribute_parameters['field_name'] . '[attribute][' . $attribute_def->data_type . ']'; $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_def, !empty($variations_attribute_parameters['variation_dif_values'][$attribute_def->code]) ? $variations_attribute_parameters['variation_dif_values'][$attribute_def->code] : '', $variations_attribute_parameters); $field_output = $attribute_output_def['output']; /* Build array for output complete customization */ $tpl_component['ADMIN_VARIATION_DETAIL_LABEL_' . strtoupper($attribute_def->code)] = $attribute_output_def['label']; $tpl_component['ADMIN_VARIATION_DETAIL_INPUT_' . strtoupper($attribute_def->code)] = $field_output; $sub_tpl_component = array(); $sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_CODE'] = ' wpshop_variation_special_value_container_' . $attribute_output_def['name']; $sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_ID'] = $attribute_output_def['id']; $sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_LABEL'] = $attribute_output_def['label']; $sub_tpl_component['ADMIN_VARIATION_DETAIL_DEF_INPUT'] = $field_output; $tpl_component['ADMIN_VARIATION_DETAIL'] .= wpshop_display::display_template_element('wpshop_admin_variation_item_details_line', $sub_tpl_component, array(), 'admin'); unset($sub_tpl_component); } $output .= wpshop_display::display_template_element('wpshop_admin_variation_item_details', $tpl_component, array(), 'admin'); } return $output; }
/** * Display inteface allowing to manage the attribute set and group details * * @param object $atributeSetId The element's identifier we have to manage the details for * * @return string $attributeSetDetailsManagement The html output of management interface */ public static function attributeSetDetailsManagement($attributeSetId = '') { global $validAttributeList; global $wpdb; $user_more_script = $add_button = ''; $end_line_display = array(); /** Check if it's billing or Shipping **/ if (!empty($attributeSetId)) { $shipping_option = get_option('wpshop_shipping_address_choice'); $billing_option = get_option('wpshop_billing_address'); if (!empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $attributeSetId) { $end_line_display = !empty($shipping_option['display_model']) ? $shipping_option['display_model'] : array(); } if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $attributeSetId) { $end_line_display = !empty($billing_option['display_model']) ? $billing_option['display_model'] : array(); } } $attributeSetDetailsManagement = ' <div id="managementContainer" >'; if (current_user_can('wpshop_add_attribute_group')) { $dialog_title = __('New attribute set section name', 'wpshop'); $dialog_identifier = 'wpshop_new_set_section_add'; $dialog_input_identifier = 'wpshop_new_attribute_set_section_name'; ob_start(); include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php'; $attributeSetDetailsManagement .= ob_get_contents(); ob_end_clean(); $add_button_text = __('Add a section for this group', 'wpshop'); $add_button_parent_class = 'attribute_set_section_add_new_button'; $add_button_name = 'wpshop_create_new_set_section_top'; ob_start(); include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_with_dialog.tpl.php'; $add_button = ob_get_contents(); ob_end_clean(); $user_more_script .= ' jQuery("#' . $dialog_identifier . '").dialog({ modal: true, dialogClass: "wpshop_uidialog_box", autoOpen:false, show: "blind", resizable: false, buttons:{ "' . __('Add', 'wpshop') . '": function(){ jQuery("#managementContainer").load(WPSHOP_AJAX_FILE_URL,{ "post": "true", "elementCode": "' . self::currentPageCode . '", "action": "saveNewAttributeSetSection", "elementType": "attributeSetSection", "elementIdentifier": "' . $attributeSetId . '", "attributeSetSectionName": jQuery("#' . $dialog_input_identifier . '").val() }); jQuery(this).children("img").show(); }, "' . __('Cancel', 'wpshop') . '": function(){ jQuery(this).dialog("close"); } }, close:function(){ jQuery("#' . $dialog_input_identifier . '").val(""); } }); jQuery(".' . $add_button_parent_class . ' input").click(function(){ jQuery("#' . $dialog_identifier . '").dialog("open"); });'; } $attributeSetDetailsManagement .= ' <input class="newOrder" type="hidden" name="wpshop_attribute_set_section_order" id="wpshop_attribute_set_section_order" value="" /> <ul class="attribute_set_group_details wpshop_cls" >' . $add_button; /* Get information about the current attribute set we are editing */ $attributeSetDetails = self::getAttributeSetDetails($attributeSetId); if (is_array($attributeSetDetails) && count($attributeSetDetails) > 0) { /* Build output with the current attribute set details */ foreach ($attributeSetDetails as $attributeSetIDGroup => $attributeSetDetailsGroup) { /* Check possible action for general code */ $elementActionClass = 'wpshop_attr_set_section_name'; $edition_area = $edit_button = ''; if (current_user_can('wpshop_edit_attribute_group')) { $elementActionClass = 'wpshop_attr_set_section_name_editable'; $edit_button = ' <a class="wpshop_attr_tool_box_button wpshop_attr_tool_box_edit wpshop_attr_tool_box_edit_attribute_set_section" id="wpshop_set_section_edit_' . $attributeSetDetailsGroup['id'] . '" title="' . __('Edit this section', 'wpshop') . '"></a>'; $tpl_component = array(); $tpl_component['ADMIN_GROUP_IDENTIFIER'] = str_replace('-', '_', sanitize_title($attributeSetDetailsGroup['id'])); $tpl_component['ADMIN_GROUP_ID'] = $attributeSetDetailsGroup['id']; $tpl_component['ADMIN_GROUP_NAME'] = __($attributeSetDetailsGroup['name'], 'wpshop'); $tpl_component['ADMIN_GROUP_DISPLAY_TYPE_TAB'] = !empty($attributeSetDetailsGroup['backend_display_type']) && $attributeSetDetailsGroup['backend_display_type'] == 'fixed-tab' ? ' selected="selected"' : ''; $tpl_component['ADMIN_GROUP_DISPLAY_TYPE_BOX'] = !empty($attributeSetDetailsGroup['backend_display_type']) && $attributeSetDetailsGroup['backend_display_type'] == 'movable-tab' ? ' selected="selected"' : ''; $tpl_component['ADMIN_GROUP_DISPLAY_ON_FRONTEND'] = !empty($attributeSetDetailsGroup['display_on_frontend']) && $attributeSetDetailsGroup['display_on_frontend'] == 'yes' ? ' checked="checked"' : ''; $edition_area = wpshop_display::display_template_element('wpshop_admin_attr_set_section_params', $tpl_component, array(), 'admin'); unset($tpl_component); } //<td rowspan="2" class="wpshop_attribute_set_section_detail_table_default_td" ><input title="'.__('Default section', 'wpshop').'" type="radio" name="wpshop_attribute_set_section_is_default_of_set" '.($is_default?'checked="checked" ':'').'id="wpshop_attribute_set_section_is_default_of_set_'.$attributeSetDetailsGroup['id'].'" value="'.$attributeSetDetailsGroup['id'].'" /></td> $is_default = !empty($attributeSetDetailsGroup['is_default_group']) && $attributeSetDetailsGroup['is_default_group'] == 'yes' ? true : false; $attributeSetDetailsManagement .= ' <li id="attribute_group_' . $attributeSetIDGroup . '" class="attribute_set_section_container attribute_set_section_container_' . ($is_default ? 'is_default' : 'normal') . '" > <table class="wpshpop_attribute_set_section_detail_table" > <tr> <td id="wpshop_attr_set_section_name_' . $attributeSetDetailsGroup['id'] . '" class="' . $elementActionClass . '" >' . __($attributeSetDetailsGroup['name'], 'wpshop') . '</td> </tr> <tr> <td> <input class="newOrder" type="hidden" name="attribute_group_order[newOrder' . $attributeSetIDGroup . ']" id="newOrder' . $attributeSetIDGroup . '" value="' . (!empty($end_line_display) && !empty($end_line_display[$attributeSetIDGroup]) ? implode(',', $end_line_display[$attributeSetIDGroup]) : '') . '" />'; /* Add the set section details */ $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); $no_delete_button = false; if (is_array($attributeSetDetailsGroup['attribut']) && count($attributeSetDetailsGroup['attribut']) >= 1) { $attributeSetDetailsManagement .= ' <ul id="attribute_group_' . $attributeSetIDGroup . '_details" class="wpshop_attr_set_section_details" >'; ksort($attributeSetDetailsGroup['attribut']); $end_line_id = 0; foreach ($attributeSetDetailsGroup['attribut'] as $attributInGroup) { if (in_array($attributInGroup->code, $price_tab)) { $no_delete_button = true; } if (!empty($attributInGroup->id) && $attributInGroup->code != 'product_attribute_set_id') { $attributeSetDetailsManagement .= ' <li class="ui-state-default attribute' . (in_array($attributInGroup->code, $price_tab) ? ' ui-state-disabled' : '') . '" id="attribute_' . $attributInGroup->id . '" >' . __($attributInGroup->frontend_label, 'wpshop') . '</li>'; if (!empty($end_line_display) && !empty($end_line_display[$attributeSetIDGroup]) && in_array('attribute_' . $attributInGroup->id, $end_line_display[$attributeSetIDGroup])) { $key = array_search('attribute_' . $attributInGroup->id, $end_line_display[$attributeSetIDGroup]); if (!empty($end_line_display[$attributeSetIDGroup][$key + 1]) && $end_line_display[$attributeSetIDGroup][$key + 1] == 'wps-attribute-end-line-' . $end_line_id) { $attributeSetDetailsManagement .= '<li class="ui-state-green attribute_end_line" id="wps-attribute-end-line">' . __('End line', 'wpshop') . '</li>'; $end_line_id++; } } } } $attributeSetDetailsManagement .= ' </ul>'; } $attributeSetDetailsManagement .= $edition_area . ' </td> </tr> </table> <div class="wpshop_admin_toolbox wpshop_attr_set_section_tool_box" >' . $edit_button; if (current_user_can('wpshop_delete_attribute_group') && !$no_delete_button) { $attributeSetDetailsManagement .= ' <a class="wpshop_attr_tool_box_button wpshop_attr_tool_box_delete wpshop_attr_tool_box_delete_attribute_set_section" id="wpshop_set_section_delete_' . $attributeSetDetailsGroup['id'] . '" title="' . __('Delete this section', 'wpshop') . '"></a>'; } $attributeSetDetailsManagement .= ' </div> </li>'; } } /* Add the interface for not-affected attribute */ $attributeSetDetailsManagement .= $add_button . ' </ul> <div class="attribute_set_not_affected_attribute" > <fieldset> <legend id="attributeSetUnaffectedAttributeSection" class="attributeSetSectionName" >' . __('Attribute not affected at this group', 'wpshop') . '</legend> <ul id="attribute_group_NotAffectedAttribute_details" class="wpshop_attr_set_section_details" >'; /* Get the not affected attribute list */ $notAffectedAttributeList = self::get_not_affected_attribute($attributeSetId, $attributeSetDetailsGroup['entity_id']); if (count($notAffectedAttributeList) > 0) { foreach ($notAffectedAttributeList as $notAffectedAttribute) { if ((is_null($validAttributeList) || !in_array($notAffectedAttribute->id, $validAttributeList)) && $notAffectedAttribute->code != 'product_attribute_set_id' && $attributeSetDetailsGroup['entity_id'] == $notAffectedAttribute->entity_id) { $attributeSetDetailsManagement .= ' <li class="ui-state-default attribute" id="attribute_' . $notAffectedAttribute->id . '" >' . __($notAffectedAttribute->frontend_label, 'wpshop') . '</li>'; } } } $attributeSetDetailsManagement .= ' </ul> <input class="newOrder" type="hidden" name="attribute_group_order[newOrderNotAffectedAttribute]" id="newOrderNotAffectedAttribute" value="" /> </fieldset> </div>'; if (!empty($attributeSetId)) { $query = $wpdb->prepare('SELECT entity_id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d', $attributeSetId); $entity_id = $wpdb->get_var($query); if (!empty($entity_id)) { $entity_post = get_post($entity_id); if (!empty($entity_post) && !empty($entity_post->post_type) && $entity_post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES && !empty($entity_post->post_name) && $entity_post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) { $attributeSetDetailsManagement .= '<ul class="wps_attribute_set_end_line"><li class="ui-state-green attribute_end_line" id="wps-attribute-end-line">' . __('End line', 'wpshop') . '</li></ul>'; } } } if (current_user_can('wpshop_delete_attribute_group')) { $user_more_script .= ' jQuery(".wpshop_attr_tool_box_delete").click(function(){ if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this atribute set section?', 'wpshop') . '"))){ jQuery("#ajax-response").load(WPSHOP_AJAX_FILE_URL,{ "post": "true", "elementCode": "' . self::currentPageCode . '", "action": "deleteAttributeSetSection", "elementType": "attributeSetSection", "elementIdentifier": "' . $attributeSetId . '", "attributeSetSectionId": jQuery(this).attr("id").replace("wpshop_set_section_delete_","") }); } });'; } $attributeSetDetailsManagement .= ' <script type="text/javascript" > wpshop(document).ready(function(){ make_list_sortable("' . WPSHOP_DBT_ATTRIBUTE_SET . '");' . $user_more_script . ' }); </script> <div class="wpshop_cls"></div> '; /* // Address Display Managment if ( !empty($attributeSetId) ) { $query = $wpdb->prepare( 'SELECT entity_id FROM '.WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE id = %d', $attributeSetId ); $entity_id = $wpdb->get_var( $query ); if ( !empty($entity_id) ) { $entity_post = get_post( $entity_id ); if( !empty( $entity_post) && !empty($entity_post->post_type) && $entity_post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES && !empty($entity_post->post_name) && $entity_post->post_name == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ) { $billing_option = get_option( 'wpshop_billing_address' ); $shipping_option = get_option( 'wpshop_shipping_address_choice' ); $display_managment = ''; if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option == $attributeSetId ) { $display_managment = ( !empty($billing_option['display_model']) ) ? $billing_option['display_model'] : ''; } if( !empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $attributeSetId ) { $display_managment = ( !empty($shipping_option['display_model']) ) ? $shipping_option['display_model'] : ''; } $attributeSetDetailsManagement .= '<div><h3>' .__( 'Address display', 'wpshop'). ': </h3>'; $attributeSetDetailsManagement .= '<em>'.__( 'Here manages your address form display and address display. Build your form display in write attributes shortcodes in textearea', 'wpshop').'</em><br/>'; $attributeSetDetailsManagement .= '<textarea name="wps_address_form_display_managment" style="width : 50%; height : 200px;">' .$display_managment. '</textarea><br/>'; $attributeSetDetailsManagement .= '<strong><u>' .__('Available attributes shortcodes', 'wpshop'). ' :</u></strong><em> '; if ( !empty($validAttributeList) ) { $attributes_id_list = implode( ',', $validAttributeList ); $query = $wpdb->prepare( 'SELECT code FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE id IN (' .$attributes_id_list. ')', ''); $available_attributes = $wpdb->get_results( $query ); if ( !empty($available_attributes) ) { foreach( $available_attributes as $available_attribute ) { $attributeSetDetailsManagement .= ' [' .$available_attribute->code. '] '; } } } $attributeSetDetailsManagement .= '</em><br/>'; $attributeSetDetailsManagement .= '<strong>' .__( 'IMPORTANT ! All your valid attributes must be present in the address display managment textearea. If you don\'t want to use an attribute please drop it in the non-affected attribute area', 'wpshop' ). '</strong>'; $attributeSetDetailsManagement .= '</div>'; } } } */ $attributeSetDetailsManagement .= '</div>'; return $attributeSetDetailsManagement; }