function get_views()
 {
     $wpshop_attribute_links = array();
     $active_nb = wpshop_attributes_set::getElement('', "'moderated','valid'");
     $deleted_nb = wpshop_attributes_set::getElement('', "'deleted'");
     $wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_valid' . (empty($_REQUEST['attribute_groups_status']) ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . wpshop_attributes_set::getEditionSlug()) . '" >' . __('Attribute groups', 'wpshop') . ' (' . count($active_nb) . ')</a>';
     $wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_deleted' . (!empty($_REQUEST['attribute_groups_status']) && $_REQUEST['attribute_groups_status'] == 'deleted' ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . wpshop_attributes_set::getEditionSlug() . '&attribute_groups_status=deleted') . '" >' . __('Trashed attribute groups', 'wpshop') . ' (' . count($deleted_nb) . ')</a>';
     return $wpshop_attribute_links;
 }
 public function wps_create_new_free_product()
 {
     global $wpdb;
     $status = false;
     $output = __('Error at product creation!', 'wpshop');
     $new_product_id = -1;
     $post_title = !empty($_POST['post_title']) ? $_POST['post_title'] : -1;
     $post_content = !empty($_POST['post_content']) ? $_POST['post_content'] : '';
     $attributes = !empty($_POST['attribute']) ? $_POST['attribute'] : -1;
     if ($post_title != -1) {
         $new_product_id = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'free_product', 'post_title' => $post_title, 'post_content' => $post_content));
         if (!is_object($new_product_id)) {
             $attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code('wpshop_product'));
             $id_attribute_set = null;
             foreach ($attribute_set_list as $attribute_set) {
                 if ($attribute_set->name == 'free_product') {
                     $id_attribute_set = $attribute_set->id;
                     break;
                 }
             }
             update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $id_attribute_set);
             $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($new_product_id);
             $data_to_save['wpshop_product_attribute'] = !empty($attributes) ? $attributes : array();
             $data_to_save['user_ID'] = get_current_user_id();
             $data_to_save['action'] = 'editpost';
             $status = false;
             $output = __('Product created partially!', 'wpshop');
             if (!empty($new_product_id) && !empty($data_to_save['user_ID'])) {
                 $product_class = new wpshop_products();
                 $product_class->save_product_custom_informations($new_product_id, $data_to_save);
                 $status = true;
                 $output = __('Product created successfully.', 'wpshop');
             }
         }
     }
     echo json_encode(array('status' => $status, 'message' => $output, 'pid' => $new_product_id));
     wp_die();
 }
				<textarea name="post_content" id="post_content" class="wpshop_product_post_content wpshop_attributes_display" rows="2"></textarea>
			</div>
		</div>
		
	</div>
	
	<?php 
$attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code('wpshop_product'));
$id_attribute_set = null;
foreach ($attribute_set_list as $attribute_set) {
    if ($attribute_set->name == 'free_product') {
        $id_attribute_set = $attribute_set->id;
        break;
    }
}
$list = empty($id_attribute_set) ? array() : wpshop_attributes_set::getAttributeSetDetails($id_attribute_set);
foreach ($list as $group) {
    ?>
	
	<div class="wps-boxed">
		<span class="wps-h5"><?php 
    echo $group['name'];
    ?>
</span>
		<?php 
    foreach ($group['attribut'] as $attribute_key => $attribute) {
        if (!empty($attribute_key) && $attribute->status == 'valid') {
            $output = wpshop_attributes::display_attribute($attribute->code);
            echo $output['field'];
        }
    }
	<div id="wps-product-quick-creation-form-attributes" class="wps-bloc-loader" >
		<?php 
$attribute_list = wpshop_attributes_set::getAttributeSetDetails($chosen_set);
?>
		<?php 
if (!empty($attribute_list)) {
    ?>
			<?php 
    foreach ($attribute_list as $attribute_set) {
        ?>
			<?php 
        $attributes = '';
        foreach ($attribute_set['attribut'] as $attribute_key => $attribute) {
            if (!empty($attribute_key) && $attribute->status == 'valid' && 'yes' == $attribute->is_used_in_quick_add_form) {
                $output = wpshop_attributes::display_attribute($attribute->code);
                $attributes .= $output['field'];
            }
        }
        ?>
			<?php 
        if (!empty($attributes)) {
            ?>
	<div class="wps-boxed">
		<span class="wps-h5"><?php 
            echo $attribute_set['name'];
            ?>
</span>
		<?php 
            echo $attributes;
            ?>
	</div>
Exemple #5
0
     if ($attributeSetSectionDefault == 'yes') {
         $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, array('last_update_date' => current_time('mysql', 0), 'default_group' => 'no'), array('attribute_set_id' => $elementIdentifier));
     }
     $attributeSetInfos = array();
     $attributeSetInfos['last_update_date'] = current_time('mysql', 0);
     $attributeSetInfos['name'] = $attributeSetSectionName;
     $attributeSetInfos['default_group'] = $attributeSetSectionDefault;
     $attributeSetInfos['backend_display_type'] = $backend_display_type;
     $attributeSetInfos['display_on_frontend'] = $display_on_frontend;
     $attributeSetSectionCreation = wpshop_database::update($attributeSetInfos, $attributeSetSectionId, WPSHOP_DBT_ATTRIBUTE_GROUP);
     if ($attributeSetSectionCreation == 'done') {
         $attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been updated successfully', 'wpshop');
     } else {
         $attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while updating the section', 'wpshop');
     }
     echo wpshop_attributes_set::attributeSetDetailsManagement($elementIdentifier) . '<script type="text/javascript" >wpshopShowMessage("' . $attributeSetSectionCreation_Result . '");hideShowMessage(5000);</script>';
     break;
 case 'deleteAttributeSetSection':
     $attributeSetSectionId = wpshop_tools::varSanitizer($_REQUEST['attributeSetSectionId']);
     $attributeSetInfos = array();
     $attributeSetInfos['status'] = 'deleted';
     $attributeSetInfos['last_update_date'] = current_time('mysql', 0);
     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $attributeSetSectionId));
     $attributeSetSectionCreation = wpshop_database::update($attributeSetInfos, $attributeSetSectionId, WPSHOP_DBT_ATTRIBUTE_GROUP);
     $more_script = '';
     if ($attributeSetSectionCreation == 'done') {
         $attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_SUCCES_ICON . '\' alt=\'action_success\' class=\'wpshopPageMessage_Icon\' />' . __('The section has been successfully been deleted', 'wpshop');
         $more_script .= 'jQuery("#attribute_group_' . $attributeSetSectionId . '").remove();';
     } else {
         $attributeSetSectionCreation_Result = '<img src=\'' . WPSHOP_ERROR_ICON . '\' alt=\'action_error\' class=\'wpshopPageMessage_Icon\' />' . __('An error occured while deleting the section', 'wpshop');
     }
<?php

if (!empty($address_meta) && !empty($address_meta['_wpshop_address_attribute_set_id']) && !empty($address_meta['_wpshop_address_attribute_set_id'][0])) {
    ?>
	<?php 
    $address_attribute_set = wpshop_attributes_set::getElement($address_meta['_wpshop_address_attribute_set_id'][0]);
    ?>
	<a target="_wps_attribute_set_edition_page" href="<?php 
    echo admin_url('admin.php?page=wpshop_attribute_group&action=edit&id=' . $address_attribute_set->id);
    ?>
" ><?php 
    echo $address_attribute_set->name;
    ?>
</a>
<?php 
} else {
    ?>
	<div class="wps-alert-info"><?php 
    _e('No type setted for address', 'wpshop');
    ?>
</div>
<?php 
}
		<div class="wpshop_cls" >
			<div class="wpshop_form_label _description_label alignleft" >
				<label for="attribute_description" ><?php 
_e('Description', 'wpshop');
?>
</label>
			</div>
			<div class="wpshop_form_input_element _description_input alignleft" >
				<textarea name="post_content" id="post_content" class="wpshop_product_post_content wpshop_attributes_display" rows="2"></textarea>
			</div>
		</div>
	</div>

<?php 
/**	Get the attribute set list	*/
$attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code('wpshop_product'));
$default_set = 0;
if (1 == count($attribute_set_list)) {
    $default_set = $attribute_set_list[0]->id;
}
?>
	<?php 
/**	Check if attribute set list is not empty in order to display a dropdown for sélection	*/
?>
	<?php 
if (!empty($attribute_set_list) && 1 <= count($attribute_set_list)) {
    ?>
	<div style=" width:80%; margin: 0 auto 10px auto; " >
		<?php 
    _e('Product type to create', 'wpshop');
    ?>
    /**
     *
     * @param unknown_type $attributeSetId
     * @param unknown_type $currentPageCode
     * @param unknown_type $itemToEdit
     * @param unknown_type $outputType
     * @return Ambigous <multitype:, string>
     */
    public static function entities_attribute_box($attributeSetId, $currentPageCode, $itemToEdit, $outputType = 'box')
    {
        $box = $box['box'] = $box['boxContent'] = $box['generalTabContent'] = array();
        /*	Get the attribute set details in order to build the product interface	*/
        $productAttributeSetDetails = wpshop_attributes_set::getAttributeSetDetails($attributeSetId, "'valid'");
        $attribute_specification = array('page_code' => $currentPageCode, 'element_identifier' => $itemToEdit, 'field_id' => $currentPageCode . '_' . $itemToEdit . '_');
        if (count($productAttributeSetDetails) > 0) {
            /*	Read the attribute list in order to output	*/
            $shortcodes_attr = '';
            $shortcodes_to_display = false;
            $attribute_set_id_is_present = false;
            foreach ($productAttributeSetDetails as $productAttributeSetDetail) {
                $shortcodes = $currentTabContent = '';
                $output_nb = 0;
                if (count($productAttributeSetDetail['attribut']) >= 1) {
                    foreach ($productAttributeSetDetail['attribut'] as $attribute) {
                        if (!empty($attribute->id)) {
                            if ($attribute->code == 'product_attribute_set_id') {
                                $attribute_set_id_is_present = true;
                            }
                            /** Generic part for attribute field output	*/
                            $value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code($currentPageCode), $itemToEdit, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input));
                            $product_meta = get_post_meta($itemToEdit, '_wpshop_product_metadata', true);
                            /**	Check if value is empty and get value in meta if not empty	*/
                            $value = empty($value) && !empty($product_meta[$attribute->code]) ? $product_meta[$attribute->code] : (!empty($value) ? $value : null);
                            /*	Manage specific field as the attribute_set_id in product form	*/
                            if ($attribute->code == 'product_attribute_set_id') {
                                $value = empty($value) ? $attributeSetId : $value;
                            }
                            $attribute_specification['current_value'] = $value;
                            $attribute_output_def = wpshop_attributes::display_attribute($attribute->code, 'admin', $attribute_specification);
                            if ($attribute_output_def['field_definition']['type'] != 'hidden' && $attribute->code != 'product_attribute_set_id') {
                                $currentTabContent .= $attribute_output_def['field'];
                                $shortcode_code_def = array();
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['main_code'] = 'wpshop_att_val';
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['type'] = $attribute->data_type;
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['attid'] = $attribute->id;
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['pid'] = $itemToEdit;
                                ob_start();
                                wps_shortcodes_ctr::output_shortcode('attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])), $shortcode_code_def, 'wpshop_product_shortcode_display wpshop_product_attribute_shortcode_display wpshop_product_attribute_shortcode_display_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])) . ' wpshop_cls');
                                $shortcodes .= '<li class="wpshop_cls" >' . sprintf(__('Insertion code for the attribute %s for this product', 'wpshop'), '<span>' . __($attribute_output_def['field_definition']['label'], 'wpshop') . '</span>') . ob_get_contents() . '</li>';
                                ob_end_clean();
                            } else {
                                if ($attribute->code == 'product_attribute_set_id') {
                                    $attribute_output_def['field_definition']['type'] = 'hidden';
                                }
                                $currentTabContent .= wpshop_form::check_input_type($attribute_output_def['field_definition'], $attribute_output_def['field_definition']['input_domain']);
                            }
                            $output_nb++;
                        }
                    }
                    $shortcode_code['attributes_set']['main_code'] = 'wpshop_att_group';
                    $shortcode_code['attributes_set']['attrs_exemple']['pid'] = $itemToEdit;
                    $shortcode_code['attributes_set']['attrs_exemple']['sid'] = $productAttributeSetDetail['id'];
                    ob_start();
                    wps_shortcodes_ctr::output_shortcode('attributes_set', $shortcode_code, 'wpshop_product_shortcode_display wpshop_product_attribute_group_shortcode_display wpshop_product_attribute_group_shortcode_display_' . str_replace('-', '_', sanitize_title($productAttributeSetDetail['name'])) . ' cls');
                    $attribute_group_display = sprintf(__('Insertion code for attribute group %s for this product', 'wpshop'), '<span>' . $productAttributeSetDetail['name'] . '</span>') . ob_get_contents() . '<ul class="" >' . $shortcodes . '</ul>';
                    ob_end_clean();
                    if (WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE == 'each-box') {
                        $currentTabContent .= '<div class="wpshop_cls" ><strong>' . __('Shortcodes', 'wpshop') . '</strong> - <a href="#" class="show-hide-shortcodes">' . __('Display', 'wpshop') . '</a><div class="wpshop_product_shortcode_display wpshop_product_shortcode_display_container wpshopHide" >' . $attribute_group_display . '</div></div>';
                    } else {
                        $shortcodes_attr .= $attribute_group_display;
                    }
                    if ($output_nb <= 0) {
                        $currentTabContent = __('Nothing avaiblable here. You can go in attribute management interface in order to add content here.', 'wpshop');
                    }
                }
                if ($output_nb > 0) {
                    $shortcodes_to_display = true;
                    if ($outputType == 'box') {
                        $box['box'][$productAttributeSetDetail['code']] = $productAttributeSetDetail['name'];
                        $box['box'][$productAttributeSetDetail['code'] . '_backend_display_type'] = $productAttributeSetDetail['backend_display_type'];
                        $box['boxContent'][$productAttributeSetDetail['code']] = '
			<div id="wpshop_' . $currentPageCode . '_' . wpshop_tools::slugify($productAttributeSetDetail['code'], array('noAccent')) . '_form" >' . $currentTabContent . '
							</div><div class="wpshop_cls" ></div>';
                    } else {
                        if ($outputType == 'column') {
                            $currentTabContent = str_replace('wpshop_form_input_element', 'wpshop_form_input_column', $currentTabContent);
                            $currentTabContent = str_replace('wpshop_form_label', 'wpshop_form_label_column', $currentTabContent);
                            $box['columnTitle'][$productAttributeSetDetail['code']] = __($productAttributeSetDetail['name'], 'wpshop');
                            $box['columnContent'][$productAttributeSetDetail['code']] = $currentTabContent;
                        }
                    }
                }
            }
            if (!$attribute_set_id_is_present) {
                /*	Get attribute definition	*/
                $attribute_def = wpshop_attributes::getElement('product_attribute_set_id', "'valid'", 'code');
                /*	Get attribute input definition	*/
                $input = wpshop_attributes::get_attribute_field_definition($attribute_def, $attributeSetId, array_merge($attribute_specification, array('input_class' => ' wpshop_attributes_display', 'from' => 'admin')));
                $input['type'] = 'hidden';
                $box['boxMore'] = wpshop_form::check_input_type($input, $input['input_domain']);
            }
            /*	Ajout de la boite permettant d'ajouter des valeurs aux attributs de type liste deroulante a la volee	*/
            $dialog_title = __('New value for attribute', 'wpshop');
            $dialog_identifier = 'wpshop_new_attribute_option_value_add';
            $dialog_input_identifier = 'wpshop_new_attribute_option_value';
            ob_start();
            include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php';
            $box['boxMore'] .= ob_get_contents();
            ob_end_clean();
            $box['boxMore'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
            if ($shortcodes_to_display) {
                switch (WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE) {
                    case 'fixed-tab':
                    case 'movable-tab':
                        if ($outputType == 'box') {
                            $box['box']['shortcode'] = __('Product Shortcodes', 'wpshop');
                            $box['boxContent']['shortcode'] = $shortcodes_attr;
                            $box['box']['shortcode_backend_display_type'] = WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE;
                        } else {
                            $box['columnTitle']['shortcode'] = __('Product Shortcodes', 'wpshop');
                            $box['columnContent']['shortcode'] = $shortcodes_attr;
                        }
                        break;
                }
            }
        }
        return $box;
    }
 /**
  * Récupération des groupes et/ou sous-groupes d'attributs pour une entité donnée
  *
  * @param integer $entity_id Identifiant de l'entité dont on veut récupérer la liste des groupes et/ou sous-groupes
  * @param string $table Permet de définir quel est l'élément en cours d'édition
  * @param string $page_code Code de la page courante
  * @param boolean $complete_tree Si ce paramètre est à vrai alors on affiche les sous-groupes, dans le cas contraire on affiche uniquement les groupes
  *
  * @return string Le code html permettant d'afficher la liste des groupes et/ou sous-groupes d'attributs
  */
 public static function get_attribute_set_complete_list($entity_id, $table, $page_code, $complete_tree = true)
 {
     $the_input = __('There is no attribute set for this entity', 'wpshop');
     $attr_set_list = wpshop_attributes_set::getElement($entity_id, "'valid'", 'entity_id', 'all');
     if (!empty($attr_set_list)) {
         $the_input = '<select name="' . $table . '[set_section]" class="wpshop_' . $page_code . '_set_section" >';
         if (!$complete_tree) {
             $the_input .= '<option value="0">' . __('None', 'wpshop') . '</option>';
         }
         foreach ($attr_set_list as $attr_set_index => $attr_set) {
             if (!empty($attr_set->id)) {
                 $attribute_set_details = wpshop_attributes_set::getAttributeSetDetails($attr_set->id, "'valid'");
                 if (!empty($attribute_set_details)) {
                     if ($complete_tree) {
                         $the_input .= '<optgroup label="' . __($attr_set->name, 'wpshop') . '" >';
                         foreach ($attribute_set_details as $set_details) {
                             $selected = $attr_set->default_set == 'yes' && $set_details['is_default_group'] == 'yes' ? ' selected="selected"' : '';
                             $the_input .= '<option' . $selected . ' value="' . $attr_set->id . '_' . $set_details['id'] . '">' . __($set_details['name'], 'wpshop') . '</option>';
                         }
                         $the_input .= '</optgroup>';
                     } else {
                         $the_input .= '<option value="' . $attr_set->id . '">' . __($attr_set->name, 'wpshop') . '</option>';
                     }
                 }
             }
         }
         $the_input .= '</select>';
     }
     return $the_input;
 }
 /**
  * AJAX - Création d'un nouveau client / Create a new customer
  */
 function create_customer()
 {
     global $wpdb;
     $response = array('status' => false, 'output' => __('An error occured while saving customer', 'wpshop'), 'customer_id' => -1);
     /**	Check if a attribute set id have been sended in order to check if therer are some check to do on sended input	*/
     $customer_attributes = wpshop_attributes_set::getAttributeSetDetails($_POST['wps-customer-account-set-id'], "'valid'");
     /**	Read sended values for checking	*/
     $email_founded = false;
     $email_field = $last_name_field = $first_name_field = '';
     if (!empty($_POST)) {
         foreach ($_POST['attribute'] as $attribute_type => $attributes) {
             foreach ($attributes as $attribute_code => $attribute_value) {
                 $query = $wpdb->prepare("SELECT frontend_verification FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_code);
                 $current_attribute = $wpdb->get_var($query);
                 if ('email' == $current_attribute) {
                     $email_founded = true;
                     $email_field = $attribute_code;
                     $email_field_type = $attribute_type;
                 } else {
                     if (strpos($attribute_code, 'last_name')) {
                         $last_name_field = $attribute_code;
                         $last_name_field_type = $attribute_type;
                     } else {
                         if (strpos($attribute_code, 'first_name')) {
                             $first_name_field = $attribute_code;
                             $first_name_field_type = $attribute_type;
                         }
                     }
                 }
             }
         }
     }
     /**	Define customer email field value	*/
     $customer_email = $_POST['attribute'][$email_field_type][$email_field];
     $customer_last_name = !empty($_POST) && !empty($_POST['attribute']) && !empty($_POST['attribute'][$last_name_field_type]) && !empty($_POST['attribute'][$last_name_field_type][$last_name_field]) ? $_POST['attribute'][$last_name_field_type][$last_name_field] : '';
     $customer_first_name = !empty($_POST) && !empty($_POST['attribute']) && !empty($_POST['attribute'][$first_name_field_type]) && !empty($_POST['attribute'][$first_name_field_type][$first_name_field]) ? $_POST['attribute'][$first_name_field_type][$first_name_field] : '';
     if ($email_founded && is_email($customer_email)) {
         /**	Check if current e-mail address does not already exists	*/
         $user_id = username_exists($customer_email);
         if (empty($user_id)) {
             /**	Create the user with a random password	*/
             $random_password = wp_generate_password(12, false);
             $user_id = wp_create_user($customer_email, $random_password, $customer_email);
             if (!is_wp_error($user_id)) {
                 update_user_meta($user_id, 'last_name', $customer_last_name);
                 update_user_meta($user_id, 'first_name', $customer_first_name);
                 /**	Build a response for customer first letter - Specific action (POS)	*/
                 if (!empty($customer_last_name)) {
                     $field_for_letter = $customer_last_name;
                 } elseif (!empty($customer_first_name)) {
                     $field_for_letter = $customer_first_name;
                 } else {
                     $field_for_letter = $customer_email;
                 }
                 $response['letter'] = substr($field_for_letter, 0, 1);
                 /**	Build response	*/
                 $response['status'] = true;
                 $response['output'] = __('Customer created succesfully', 'wpshop');
                 /** Create customer address from sended data **/
                 $_REQUEST['user']['customer_id'] = $user_id;
                 $attribute_to_save = $_POST['attribute'];
                 unset($_POST['attribute']);
                 $_POST['attribute'][$_POST['wps-customer-account-set-id']] = $attribute_to_save;
                 wps_address::save_address_infos($_POST['wps-customer-account-set-id']);
             }
         } else {
             $response['output'] = __('An account is already created with this e-mail address', 'wpshop');
         }
         $response['customer_id'] = $user_id;
     } else {
         $response['output'] = __('An email address is required', 'wpshop');
     }
     wp_die(json_encode($response));
 }
/**
 * Get the attribute set list when creating a new attribute for direct affectation
 */
function ajax_attribute_set_entity_selection_callback()
{
    check_ajax_referer('wpshop_attribute_set_entity_selection', 'wpshop_ajax_nonce');
    $current_entity_id = isset($_POST['current_entity_id']) ? intval(wpshop_tools::varSanitizer($_POST['current_entity_id'])) : null;
    $the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id, wpshop_attributes_set::getDbTable(), wpshop_attributes::currentPageCode, false);
    echo json_encode($the_input);
    die;
}
 /**
  * Generate an array with all fields for the address form construction. Classified by address type.
  * @param $typeof
  * @return array
  */
 function get_addresss_form_fields_by_type($typeof, $id = '')
 {
     $current_item_edited = isset($id) ? (int) wpshop_tools::varSanitizer($id) : null;
     $address = array();
     $all_addresses = '';
     /*	Get the attribute set details in order to build the product interface	*/
     $atribute_set_details = wpshop_attributes_set::getAttributeSetDetails($typeof, "'valid'");
     if (!empty($atribute_set_details)) {
         foreach ($atribute_set_details as $productAttributeSetDetail) {
             $address = array();
             $group_name = $productAttributeSetDetail['name'];
             if (count($productAttributeSetDetail['attribut']) >= 1) {
                 foreach ($productAttributeSetDetail['attribut'] as $attribute) {
                     if (!empty($attribute->id)) {
                         if (!empty($_POST['submitbillingAndShippingInfo'])) {
                             $value = $_POST['attribute'][$typeof][$attribute->data_type][$attribute->code];
                         } else {
                             $value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS), $current_item_edited, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input));
                         }
                         $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute, $value, array());
                         $attribute_output_def['id'] = 'address_' . $typeof . '_' . $attribute_output_def['id'];
                         $address[str_replace('-', '_', sanitize_title($group_name)) . '_' . $attribute->code] = $attribute_output_def;
                     }
                 }
             }
             $all_addresses[$productAttributeSetDetail['attribute_set_id']][$productAttributeSetDetail['id']]['name'] = $group_name;
             $all_addresses[$productAttributeSetDetail['attribute_set_id']][$productAttributeSetDetail['id']]['content'] = $address;
             $all_addresses[$productAttributeSetDetail['attribute_set_id']][$productAttributeSetDetail['id']]['id'] = str_replace('-', '_', sanitize_title($group_name));
             $all_addresses[$productAttributeSetDetail['attribute_set_id']][$productAttributeSetDetail['id']]['attribute_set_id'] = $productAttributeSetDetail['attribute_set_id'];
         }
     }
     return $all_addresses;
 }
 /**
  * Display a form allowing to create an entity from frontend with a shortcode
  * @param array $shortcode_args The different parameters for the shortocde: the field list for the form, different parameters for the entity to create
  */
 public static function wpshop_entities_shortcode($shortcode_args)
 {
     global $wpshop_account, $wpdb;
     $output = $form_content = '';
     if (get_current_user_id() > 0) {
         if (!empty($_POST['quick_entity_add_button'])) {
             $attributes = array();
             foreach ($_POST['attribute'] as $attribute_type => $attribute) {
                 foreach ($attribute as $attribute_code => $attribute_value) {
                     $attributes[$attribute_code] = $attribute_value;
                 }
             }
             $result = wpshop_products::addProduct($_POST['wp_fields']['post_title'], '', $attributes, 'complete');
         }
         if (empty($shortcode_args['attribute_set_id']) || empty($shortcode_args['post_type'])) {
             $output = __('This form page is invalid because no set or type or content is defined. Please contact administrator with this error message', 'wpshop');
         } else {
             $entity_identifier = wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']);
             $attribute_set_def = wpshop_attributes_set::getElement($shortcode_args['attribute_set_id'], "'valid'");
             if (empty($entity_identifier) || empty($attribute_set_def) || $entity_identifier != $attribute_set_def->entity_id) {
                 $output = __('This form page is invalid because type and set are not linked. Please contact administrator with this error message', 'wpshop');
             } else {
                 /** Display wordpress fields */
                 foreach (explode(', ', $shortcode_args['fields']) as $field_name) {
                     $label = '';
                     switch ($field_name) {
                         case 'post_title':
                             switch ($shortcode_args['post_type']) {
                                 case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                                     $label = __('Product title', 'wpshop');
                                     break;
                                 default:
                                     $label = __('Name', 'wpshop');
                                     break;
                             }
                             $field_type = 'text';
                             break;
                         case 'post_thumbnail':
                             switch ($shortcode_args['post_type']) {
                                 case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                                     $label = __('Product picture', 'wpshop');
                                     break;
                                 default:
                                     $label = __('Default picture', 'wpshop');
                                     break;
                             }
                             $field_type = 'file';
                             break;
                     }
                     if (!empty($label)) {
                         $template_part = 'quick_entity_wp_internal_field_' . $field_type;
                         $tpl_component = array();
                         $tpl_component['WP_FIELD_NAME'] = $field_name;
                         $tpl_component['WP_FIELD_VALUE'] = '';
                         $input = wpshop_display::display_template_element($template_part, $tpl_component);
                         unset($tpl_component);
                         $template_part = 'quick_entity_wp_internal_field_output';
                         $tpl_component = array();
                         $tpl_component['ENTITY_TYPE_TO_CREATE'] = $shortcode_args['post_type'];
                         $tpl_component['WP_FIELD_NAME'] = $field_name;
                         $tpl_component['WP_FIELD_LABEL'] = $label;
                         $tpl_component['WP_FIELD_INPUT'] = $input;
                         $form_content .= wpshop_display::display_template_element($template_part, $tpl_component);
                         unset($tpl_component);
                     }
                 }
                 /** Display attributes fields	*/
                 $query = $wpdb->prepare("\nSELECT ATT.code\nFROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATT\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET ON ((ATTR_DET.status = 'valid') AND (ATTR_DET.attribute_id = ATT.id) AND (ATTR_DET.entity_type_id = ATT.entity_id))\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATT_GROUP ON ((ATT_GROUP.status = 'valid') AND (ATT_GROUP.attribute_set_id = ATTR_DET.attribute_set_id) AND (ATT_GROUP.id = ATTR_DET.attribute_group_id))\nWHERE ATT.is_used_in_quick_add_form = %s\n\tAND ATT.status= %s\n\tAND ATT.entity_id = %d\n\tAND ATTR_DET.attribute_set_id = %d\nGROUP BY ATT.code\nORDER BY ATT_GROUP.position, ATTR_DET.position", 'yes', 'valid', wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']), $shortcode_args['attribute_set_id']);
                 $attribute_for_creation = $wpdb->get_results($query);
                 foreach ($attribute_for_creation as $attribute) {
                     $attr_field = wpshop_attributes::display_attribute($attribute->code, 'frontend');
                     $form_content .= $attr_field['field'];
                 }
                 /**	Check if there are extra parameters	*/
                 if (!empty($shortcode_args['extra_element'])) {
                     $extra_element = explode(', ', $shortcode_args['extra_element']);
                     foreach ($extra_element as $element) {
                         $element_def = explode('!#wps#!', $element);
                         $element_type = $element_def[0];
                         $element_id = $element_def[1];
                         if ($element_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) {
                             $form_content .= '<div class="wpshop_entity_address_container">';
                             // 								$form_content .= $wpshop_account->display_form_fields($element_id, null, 'not');
                             $form_content .= '</div><div class="wpshop_cls"></div>';
                         }
                     }
                 }
             }
         }
         $template_part = 'quick_entity_add_form';
         $tpl_component = array();
         $tpl_component['ENTITY_TYPE'] = $shortcode_args['post_type'];
         $tpl_component['ENTITY_ATTRIBUTE_SET_ID'] = !empty($shortcode_args['attribute_set_id']) ? $shortcode_args['attribute_set_id'] : 0;
         $tpl_component['NEW_ENTITY_FORM_DETAILS'] = $form_content;
         $tpl_component['ENTITY_QUICK_ADDING_FORM_NONCE'] = wp_create_nonce("wpshop_add_new_entity_ajax_nonce");
         $tpl_component['ENTITY_QUICK_ADD_BUTTON_TEXT'] = __($shortcode_args['button_text'], 'wpshop');
         /*	Ajout de la boite permettant d'ajouter des valeurs aux attributs de type liste deroulante a la volee	*/
         $dialog_title = __('New value', 'wpshop');
         $dialog_identifier = 'new_value_for_entity';
         $dialog_input_identifier = 'wpshop_new_attribute_option_value';
         ob_start();
         include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php';
         $tpl_component['DIALOG_BOX'] = ob_get_contents();
         ob_end_clean();
         $tpl_component['DIALOG_BOX'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
         $tpl_component['DIALOG_BOX'] = '';
         $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'wpshop');
         echo $output;
     } else {
         echo $wpshop_account->display_login_form();
     }
 }
 /**
  * ACCOUNT - Edit account informations data
  */
 function account_informations_form()
 {
     global $wpdb;
     $output = '';
     if (get_current_user_id() != 0) {
         // Customer ID data
         $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
         $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id());
         $cid = $wpdb->get_var($query);
         $fields_to_output = $signup_fields = array();
         $password_attribute = $signup_form_attributes = array();
         $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
         $customer_entity_id = $wpdb->get_var($query);
         $attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
         $account_attributes = wpshop_attributes_set::getAttributeSetDetails(!empty($attributes_set->id) ? $attributes_set->id : '', "'valid'");
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id);
         $customer_attributes_sections = $wpdb->get_results($query);
         foreach ($customer_attributes_sections as $k => $customer_attributes_section) {
             if (!empty($account_attributes[$customer_attributes_section->id])) {
                 foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) {
                     $signup_fields[] = $attribute;
                 }
             }
         }
         ob_start();
         require wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_form");
         $output = ob_get_contents();
         ob_end_clean();
     }
     return $output;
 }
	<?php 
if (!empty($order_items)) {
    ?>
		<?php 
    foreach ($order_items as $order_item_id => $order_item) {
        ?>
		<li id="wps_product_<?php 
        echo $order_item_id;
        ?>
" class="wps-clearfix cart-item" >
			<div class="wps-cart-item-content">
				<?php 
        echo wpshop_tools::trunk($order_item['item_name'], 50);
        ?>
				<?php 
        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($order_item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
        $output_order = array();
        if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) {
            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
                    if (!empty($attribute_def->code)) {
                        $output_order[$attribute_def->code] = $position;
                    }
                }
            }
        }
        $variation_attribute_ordered = wpshop_products::get_selected_variation_display($order_item['item_meta'], $output_order, 'cart');
        ksort($variation_attribute_ordered['attribute_list']);
        ?>
				<?php 
        if (!empty($variation_attribute_ordered['attribute_list'])) {
 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;
 }
 /**
  * Install default configuration in database if not present
  */
 public function install()
 {
     global $table_prefix, $wpdb;
     /*Create config informations*/
     $conf = get_option('wps_barcode');
     if (empty($conf)) {
         $conf['type'] = 'internal';
         $conf['internal_client'] = '040';
         $conf['internal_provider'] = '041';
         $conf['internal_invoice_client'] = '042';
         $conf['internal_do_client'] = '043';
         $conf['internal_product'] = '044';
         $conf['internal_assets_client'] = '050';
         $conf['internal_coupons'] = '051';
         $conf['internal_invoice_provider'] = '045';
         $conf['internal_do_provider'] = '046';
         $conf['normal_country_code'] = '320';
         $conf['normal_enterprise_code'] = '0001';
         add_option('wps_barcode', $conf);
         /*Adding barcode for existing products*/
         $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpshop_product'));
         foreach ($posts as $post) {
             $meta = get_post_meta($post->ID);
             $attr = wpshop_attributes_set::getAttributeSetDetails($meta['_wpshop_product_attribute_set_id']);
             $output_order = array();
             if (count($attr) > 0) {
                 if (!empty($attr)) {
                     foreach ($attr as $product_attr_group_id => $product_attr_group_detail) {
                         foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
                             if (!empty($attribute_def->code) and $attribute_def->code === 'barcode') {
                                 $types_with_barcode = array(WPSHOP_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, WPSHOP_NEWTYPE_IDENTIFIER_COUPON, WPSHOP_NEWTYPE_IDENTIFIER_ORDER);
                                 if (!empty($post->post_type) && in_array($post->post_type, $types_with_barcode)) {
                                     $ref = '';
                                     if (strlen($post->ID) < 5) {
                                         $length = 5 - strlen($post->ID);
                                         for ($i = 0; $i < $length; $i++) {
                                             $ref .= '0';
                                         }
                                     }
                                     $ref .= strval($post->ID);
                                     if ($conf['type'] === 'normal') {
                                         $array['normal'] = array('country' => $conf['normal_country_code'], 'enterprise' => $conf['normal_enterprise_code'], 'ID' => $ref);
                                     } else {
                                         if ($conf['type'] === 'internal') {
                                             $pDate = new DateTime($post->post_date);
                                             $date = $pDate->format('my');
                                             if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || $post->post_type === WPSHOP_IDENTIFIER_PRODUCT) {
                                                 $type = $conf['internal_product'];
                                             } else {
                                                 if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
                                                     $type = $conf['internal_invoice_client'];
                                                 } else {
                                                     if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) {
                                                         $type = $conf['internal_coupons'];
                                                     } else {
                                                         $type = '000';
                                                     }
                                                 }
                                             }
                                             $array['internal'] = array('type' => $type, 'date' => $date, 'ID' => $ref);
                                         }
                                     }
                                     $barcode = $this->wps_generate_barcode($array);
                                     $data = array('entity_type_id' => 4, 'attribute_id' => '12', 'entity_id' => $post->ID, 'user_id' => $post->post_author, 'value' => $barcode, 'creation_date_value' => date('Y-m-d H:i:s'));
                                     $query = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\t\t\t\tSELECT *\r\n\t\t\t\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE entity_id = %d\r\n\t\t\t\t\t\t\t\t\t\t\t\tAND attribute_id = (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE . "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE code = %s\r\n\t\t\t\t\t\t\t\t\t\t\t\t)", $post->ID, 'barcode');
                                     $result = $wpdb->get_results($query, ARRAY_A);
                                     if (empty($result)) {
                                         $wpdb->insert($table_prefix . 'wpshop__attribute_value_varchar', $data);
                                     } elseif (empty($result[0]['value'])) {
                                         $wpdb->update($table_prefix . 'wpshop__attribute_value_varchar', $data, array('value_id' => $result[0]['value_id']));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         /*Adding barcode for existing coupon*/
         $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpshop_shop_coupon'));
         foreach ($posts as $post) {
             $meta = get_post_meta($post->ID);
             if (empty($meta['wpshop_coupon_barcode'])) {
                 if ($conf['type'] === 'normal') {
                     $array['normal'] = array('country' => $conf['normal_country_code'], 'enterprise' => $conf['normal_enterprise_code'], 'ID' => $ref);
                 } else {
                     if ($conf['type'] === 'internal') {
                         $pDate = new DateTime($post->post_date);
                         $date = $pDate->format('my');
                         if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) {
                             $type = $conf['internal_coupons'];
                         } else {
                             $type = '000';
                         }
                         $ref = '';
                         var_dump($post->ID);
                         if (strlen($post->ID) < 5) {
                             $length = 5 - strlen($post->ID);
                             for ($i = 0; $i < $length; $i++) {
                                 $ref .= '0';
                             }
                         }
                         $ref .= strval($post->ID);
                         $array['internal'] = array('type' => $type, 'date' => $date, 'ID' => $ref);
                     }
                 }
                 $barcode = $this->wps_generate_barcode($array);
                 update_post_meta($post->ID, 'wpshop_coupon_barcode', $barcode);
             }
         }
     }
 }
Exemple #18
-1
 /**
  * Generate output for an invoice
  *
  * @param integer $order_id
  * @param string $invoice_ref
  *
  * @return string The invoice output in case no error is found. The error in other case
  */
 public static function generate_html_invoice($order_id, $invoice_ref)
 {
     global $wpdb;
     $date_output_format = get_option('date_format') . ' ' . get_option('time_format');
     $count_products = 0;
     if (!empty($order_id)) {
         $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
         $discounts_exists = false;
         $is_quotation = empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) ? true : false;
         /** Check if it's a partial payment bill **/
         $is_partial_payment = !empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_status'] == 'partially_paid' && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref || empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid' || !empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref ? true : false;
         /** Check it is a shipping slip **/
         $bon_colisage = !empty($_GET['bon_colisage']) ? true : false;
         if (!empty($order_postmeta)) {
             $tpl_component = array();
             /** Billing Header **/
             //Logo
             $logo_options = get_option('wpshop_logo');
             $tpl_component['INVOICE_LOGO'] = !empty($logo_options) ? '<img src="' . $logo_options . '" alt="" />' : '';
             // Title
             $tpl_component['INVOICE_TITLE'] = $is_quotation ? __('Quotation', 'wpshop') : ($is_partial_payment ? __('Bill payment', 'wpshop') : __('Invoice', 'wpshop'));
             // 					if ( empty($order_postmeta['order_invoice_ref']) ) {
             // 						$tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop');
             // 						$is_partial_payment = true;
             // 					}
             if ($bon_colisage) {
                 $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop');
             }
             $tpl_component['INVOICE_ORDER_INVOICE_REF'] = !empty($invoice_ref) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null);
             if ($bon_colisage) {
                 $tpl_component['INVOICE_ORDER_INVOICE_REF'] = '';
             }
             $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = $is_quotation ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']);
             $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = $is_quotation ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true));
             /** Validate period for Quotation **/
             if ($is_quotation) {
                 $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']);
             } else {
                 $tpl_component['INVOICE_VALIDATE_TIME'] = '';
             }
             $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME'];
             $tpl_component['AMOUNT_INFORMATION'] = !$bon_colisage ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : '';
             // Sender & receiver addresses
             $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part();
             $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage);
             $tpl_component['INVOICE_TRACKING'] = '';
             $first = false;
             if (!empty($order_postmeta['order_trackingNumber'])) {
                 $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber'];
                 $first = true;
             }
             if (!empty($order_postmeta['order_trackingLink'])) {
                 if (!$first) {
                     $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink'];
                 } else {
                     $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink'];
                 }
             }
             /** Items Tab **/
             $order_tva = array();
             if ($bon_colisage) {
                 $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common');
             } else {
                 $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common');
                 if (!$is_quotation) {
                     /** Check if products have discounts **/
                     if (!empty($order_postmeta['order_items']) && !$is_partial_payment) {
                         foreach ($order_postmeta['order_items'] as $item_id => $item) {
                             if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) {
                                 $discounts_exists = true;
                             }
                         }
                     }
                     if ($discounts_exists) {
                         $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common');
                     }
                 }
             }
             $total_discounted = 0;
             $tpl_component['INVOICE_ROWS'] = '';
             if (!$is_partial_payment) {
                 if (!empty($order_postmeta['order_items'])) {
                     foreach ($order_postmeta['order_items'] as $item_id => $item) {
                         $sub_tpl_component = array();
                         $count_products++;
                         $barcode = get_post_meta($item['item_id'], '_barcode', true);
                         if (empty($barcode)) {
                             $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true);
                             $barcode = !empty($product_metadata) && !empty($product_metadata['barcode']) ? $product_metadata['barcode'] : '';
                             if (empty($barcode)) {
                                 $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
                                 $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code');
                                 $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']);
                                 $barcode = $wpdb->get_var($query);
                             }
                         }
                         $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = !empty($barcode) ? $barcode : '-';
                         $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = !empty($barcode) ? $barcode : $item['item_ref'];
                         /** Item name **/
                         $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item['item_name'];
                         /**	Get attribute order for current product	*/
                         $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
                         $output_order = array();
                         if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) {
                             foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
                                 foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
                                     if (!empty($attribute_def->code)) {
                                         $output_order[$attribute_def->code] = $position;
                                     }
                                 }
                             }
                         }
                         $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common');
                         ksort($variation_attribute_ordered['attribute_list']);
                         $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = '';
                         foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
                             $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output;
                         }
                         $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : '';
                         unset($detail_tpl_component);
                         $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty'];
                         $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = !empty($item['item_pu_ht_before_discount']) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', '');
                         $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = !empty($item['item_discount_value']) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', '');
                         $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($item['item_pu_ht'] * $item['item_qty'], 2, '.', '');
                         /** TVA **/
                         $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', '');
                         $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate'];
                         $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', '');
                         /** Checking Rate amount **/
                         if (!$bon_colisage) {
                             $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id);
                             if (!$checking) {
                                 return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop');
                             }
                         }
                         if ($bon_colisage) {
                             $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common');
                         } else {
                             if ($discounts_exists) {
                                 $discounted_total_per_item = $item['item_total_ht'];
                                 /** Unit Discount **/
                                 if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) {
                                     $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', '');
                                     $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount'];
                                 } else {
                                     $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
                                 }
                                 /** Global Discount **/
                                 if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) {
                                     $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', '');
                                     $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount'];
                                 } else {
                                     $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
                                 }
                                 $total_discounted += $discounted_total_per_item;
                                 /** Total HT Discounted **/
                                 $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', '');
                                 $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common');
                             } else {
                                 $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
                             }
                         }
                         unset($sub_tpl_component);
                         /** Check TVA **/
                         if (empty($order_tva[$item['item_tva_rate']])) {
                             $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount'];
                         } else {
                             $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount'];
                         }
                     }
                 }
                 /** Display Partials payments **/
                 $total_partial_payment = 0;
                 $last_payment = 0;
                 $order_invoice_ref = !empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : '';
                 if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) {
                     foreach ($order_postmeta['order_payment']['received'] as $received_payment) {
                         if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) {
                             if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) {
                                 $sub_tpl_component = array();
                                 $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref'];
                                 /** Item name **/
                                 $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']);
                                 $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = '';
                                 $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1;
                                 $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
                                 $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
                                 $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
                                 /** TVA **/
                                 $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '');
                                 $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0;
                                 $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
                                 if ($discounts_exists) {
                                     $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
                                     $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', '');
                                     $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common');
                                 } else {
                                     $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
                                 }
                             }
                             unset($sub_tpl_component);
                             $total_partial_payment += !empty($received_payment['received_amount']) ? $received_payment['received_amount'] : 0;
                         } else {
                             if ('payment_received' == $received_payment['status']) {
                                 $last_payment += !empty($received_payment['received_amount']) ? $received_payment['received_amount'] : 0;
                             }
                         }
                     }
                 }
             } else {
                 /** Display Partials payments **/
                 $total_partial_payment = 0;
                 $last_payment = 0;
                 if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) {
                     foreach ($order_postmeta['order_payment']['received'] as $received_payment) {
                         if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) {
                             $sub_tpl_component = array();
                             $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref'];
                             /** Item name **/
                             $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']);
                             $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = '';
                             $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1;
                             $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', '');
                             $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', '');
                             $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', '');
                             /** TVA **/
                             $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', '');
                             $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0;
                             $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', '');
                             $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common');
                             unset($sub_tpl_component);
                             $total_partial_payment += $received_payment['received_amount'];
                         }
                     }
                 }
             }
             /** Summary of order **/
             $summary_tpl_component = array();
             $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = '';
             if (!$bon_colisage) {
                 if (!empty($order_tva)) {
                     foreach ($order_tva as $tax_rate => $tax_amount) {
                         if ($tax_amount > 0) {
                             $tax_rate = !empty($tax_rate) && $tax_rate == 'VAT_shipping_cost' ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate;
                             $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%');
                             $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency();
                             $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
                             unset($sub_tpl_component);
                         } elseif ($is_partial_payment) {
                             $tax_rate = 0;
                             $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency();
                             $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%');
                             $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency();
                             $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
                             unset($sub_tpl_component);
                         }
                     }
                 }
                 /** If Discount Exist **/
                 if (!empty($total_discounted) && $discounts_exists) {
                     $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total ET', 'wpshop');
                     $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency();
                     $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
                     unset($sub_tpl_component);
                 } else {
                     $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = '';
                 }
                 $shipping_et = 0;
                 if (!$is_partial_payment) {
                     if (!empty($order_postmeta['order_shipping_cost'])) {
                         $shipping_et = $order_postmeta['order_shipping_cost'];
                     }
                 }
                 $shipping_taxes = WPSHOP_VAT_ON_SHIPPING_COST / 100 * $shipping_et;
                 $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_et, 2, ',', '');
                 $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', '');
                 //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' );
                 $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = $is_partial_payment ? number_format($total_partial_payment, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', '');
                 // - $total_partial_payment , 2, ',', '' );
                 $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = $is_partial_payment ? number_format($total_partial_payment, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', '');
                 $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', '');
                 $total_payment = 0;
                 /** Amount paid **/
                 if (empty($order_postmeta['order_invoice_ref'])) {
                     foreach ($order_postmeta['order_payment']['received'] as $key => $value) {
                         if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) {
                             $total_payment = number_format($value['received_amount'], 2, ',', '');
                         }
                     }
                 } else {
                     $total_payment = $total_partial_payment + $last_payment !== $order_postmeta['order_grand_total'] ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total'];
                 }
                 $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop');
                 $sub_tpl_component['SUMMARY_ROW_VALUE'] = $total_payment . ' ' . wpshop_tools::wpshop_get_currency();
                 //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ?  number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency();
                 $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
                 unset($sub_tpl_component);
                 $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop');
                 $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products;
                 $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common');
                 unset($sub_tpl_component);
                 /** If Discount Exist **/
                 if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) {
                     $tpl_discount_component = array();
                     $tpl_discount_component['DISCOUNT_VALUE'] = $order_postmeta['order_discount_type'] == 'percent' ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', '');
                     $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', '');
                     $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common');
                     unset($tpl_discount_component);
                 } else {
                     $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = '';
                 }
                 $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC');
                 $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop');
                 $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common');
                 unset($summary_tpl_component);
             }
             /** IBAN Include on quotation **/
             if ($is_quotation) {
                 /** If admin want to include his IBAN to quotation */
                 $iban_options = get_option('wpshop_paymentMethod_options');
                 $payment_options = get_option('wps_payment_mode');
                 if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') {
                     if (!empty($iban_options) && !empty($iban_options['banktransfer'])) {
                         $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>';
                         $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . (!empty($iban_options['banktransfer']['bank_name']) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>';
                         $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . (!empty($iban_options['banktransfer']['iban']) ? $iban_options['banktransfer']['iban'] : '') . '<br/>';
                         $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . (!empty($iban_options['banktransfer']['bic']) ? $iban_options['banktransfer']['bic'] : '') . '<br/>';
                         $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . (!empty($iban_options['banktransfer']['accountowner']) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>';
                     }
                 } else {
                     $tpl_component['IBAN_INFOS'] = '';
                 }
             } else {
                 $tpl_component['IBAN_INFOS'] = '';
             }
             /** Received payements **/
             if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) {
                 $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id);
             } else {
                 $tpl_component['RECEIVED_PAYMENT'] = '';
             }
             /** Invoice footer **/
             $tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice();
             $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common');
         } else {
             $output = __('No order information has been found', 'wpshop');
         }
     } else {
         $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop');
     }
     return $output;
 }