/**
  * Effectue des actions à l'activation du logiciel de caisse / Do some defautl action on POS addon activation
  */
 public static function action_to_do_on_activation()
 {
     global $wpdb;
     /** Activate Barcode attribute **/
     if (false) {
         $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('status' => 'valid'), array('code' => 'barcode'));
         /** Get the product entity id **/
         $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_name = %s', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
         $product_entity_id = $wpdb->get_var($query);
         /** Check the barcode attribute id **/
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', 'barcode');
         $attribute_barcode_id = $wpdb->get_var($query);
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $product_entity_id);
         $products_groups = $wpdb->get_results($query);
         /** For each attributes groups used for product configuration **/
         foreach ($products_groups as $products_group) {
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $products_group->id, 'general');
             $attributes_set_sections = $wpdb->get_results($query);
             foreach ($attributes_set_sections as $attributes_set_section) {
                 $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $product_entity_id, $products_group->id, $attributes_set_section->id);
                 $max_position = $wpdb->get_var($query);
                 $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d', $product_entity_id, $products_group->id, $attributes_set_section->id, $attribute_barcode_id);
                 $exist_barcode_details_definition = $wpdb->get_results($query);
                 /** Insert the barcode attribute details **/
                 if (!empty($max_position) && empty($exist_barcode_details_definition)) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $product_entity_id, 'attribute_set_id' => $products_group->id, 'attribute_group_id' => $attributes_set_section->id, 'attribute_id' => $attribute_barcode_id, 'position' => (int) $max_position + 1));
                 }
             }
         }
     }
     /** Activate Barcode for search **/
     $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_sort_by' => 'yes', 'is_used_in_quick_add_form' => 'yes'), array('code' => 'barcode'));
     /** Activate attribute for the product quick add form **/
     $price_piloting_option = get_option('wpshop_shop_price_piloting');
     $code = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? 'price_ht' : 'product_price';
     $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_quick_add_form' => 'yes'), array('code' => $code));
     $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_quick_add_form' => 'yes'), array('code' => 'tx_tva'));
     /** Check If Shop Customer attribute set exist - Deprecated **/
     /* $customer_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS );
     		$query = $wpdb->prepare( 'SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE name = %s',  __('Shop Customer', 'wps-pos-i18n') );
     		$exist_attribute_group = $wpdb->get_var( $query ); */
     $exist_attribute_group = 'Nope';
     if (empty($exist_attribute_group)) {
         /** Create a Attributes Group for POS Customer infos **/
         $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'entity_id' => $customer_entity_id, 'name' => __('Shop Customer', 'wps-pos-i18n')));
         $attribute_set_id = $wpdb->insert_id;
         /** Create Attributes Group **/
         $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, array('status' => 'valid', 'default_group' => 'yes', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_set_id' => $attribute_set_id, 'code' => sanitize_title(__('Shop Customer main infos', 'wps-pos-i18n')), 'name' => __('Shop Customer main infos', 'wps-pos-i18n')));
         $main_set_id = $wpdb->insert_id;
         $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_set_id' => $attribute_set_id, 'code' => sanitize_title(__('Shop Customer address infos', 'wps-pos-i18n')), 'name' => __('Shop Customer address infos', 'wps-pos-i18n')));
         $address_set_id = $wpdb->insert_id;
         /** Affect Attributes **/
         $attributes = array('last_name' => $main_set_id, 'first_name' => $main_set_id, 'address_last_name' => $main_set_id, 'address_first_name' => $main_set_id, 'address_user_email' => $main_set_id, 'address' => $address_set_id, 'postcode' => $address_set_id, 'city' => $address_set_id, 'phone' => $address_set_id);
         $i = 1;
         foreach ($attributes as $attribute => $group_id) {
             $attribute_def = wpshop_attributes::getElement($attribute, "'valid'", 'code');
             if (!empty($attribute_def)) {
                 $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'entity_type_id' => $customer_entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $group_id, 'attribute_id' => $attribute_def->id, 'position' => $i));
                 $i++;
             }
         }
     }
     $user_name = 'default_customer';
     $user_id = username_exists($user_name);
     if (!$user_id) {
         $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
         $user_id = wp_create_user($user_name, $random_password, '*****@*****.**');
         if (!empty($user_id)) {
             update_user_meta($user_id, 'last_name', __('Default', 'wps-pos-i18n'));
             update_user_meta($user_id, 'first_name', __('Customer', 'wps-pos-i18n'));
             /** Add the default customer id in Option table **/
             update_option('wpshop_pos_addon_default_customer_id', $user_id);
         }
     }
     /** Get post of user id */
     $customers_associated_to_user = get_posts(array('post_status' => 'draft', 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'author' => $user_id));
     $customer_id = !empty($customers_associated_to_user) && !empty($customers_associated_to_user[0]) && !empty($customers_associated_to_user[0]->ID) ? $customers_associated_to_user[0]->ID : null;
     $customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
     if (!empty($customer_id)) {
         /** Insert attribute data */
         wpshop_attributes::saveAttributeForEntity(array('varchar' => array('last_name' => __('Default', 'wps-pos-i18n'), 'first_name' => __('Customer', 'wps-pos-i18n'), 'user_email' => '*****@*****.**', 'address_last_name' => __('Default', 'wps-pos-i18n'), 'address_first_name' => __('Customer', 'wps-pos-i18n'), 'address_user_email' => '*****@*****.**', 'address' => __('Default address'), 'postcode' => '42420', 'city' => __('Default city'), 'phone' => '0000000042')), $customer_entity_id, $customer_id);
     }
 }
 /**
  * Récupère le pilotage de prix, le nombre de produit avec un prix incohérent, le type de l'entité et la langue de la boutique. 
  * Parcours la tableau de donnée avec la nouvelle valeur des prix par produit incohérent puis met à jour tout les autres prix de 
  * ce produit. Ensuite renvoie le template avec le nombre de prix incohérent qui on été corrigé et le template de la méthode :
  * ajax_checking_products_values si des produits incohérents sont toujours présent. / Get the price piloting, the number of 
  * product with an inconsistent price, type of the entity and the language of the shop. Browse the given table with the new
  * new value pricing of the inconsistent product and updates any other price of this product. Then display the template 
  * of the number of corrected product and the template of the method : ajax_checking_products_values if inconsistent product
  * already present.
  * 
  * @param array $_POST['product_price'] List of the new price for the product like array( $id_product => $new_price )
  * @return JSON Response
  */
 public function ajax_save_product_price()
 {
     header('Content-Type: application/json');
     $response = array();
     $price_piloting_option = get_option('wpshop_shop_price_piloting');
     $inconsistent_product_number = !empty($_POST['product_price']) ? count($_POST['product_price']) : 0;
     $consistent_product_number = 0;
     $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
     $language = WPSHOP_CURRENT_LOCALE;
     if (!empty($_REQUEST['icl_post_language'])) {
         $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $_REQUEST['icl_post_language']);
         $language = $wpdb->get_var($query);
     }
     if (!empty($_POST['product_price'])) {
         foreach ($_POST['product_price'] as $product_id => $price) {
             try {
                 if ($price_piloting_option == 'TTC') {
                     wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price)), $entity_type_id, $product_id, $language, 'wpshop_products');
                 } else {
                     wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price)), $entity_type_id, $product_id, $language, 'wpshop_product');
                 }
                 wpshop_products::calculate_price($product_id);
                 $consistent_product_number++;
             } catch (Exception $e) {
             }
         }
     }
     $response['template_number'] = __(sprintf('Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number), 'wps-product');
     $list_product = wps_product_ctr::get_inconsistent_product();
     ob_start();
     require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data");
     $response['template'] = ob_get_clean();
     wp_die(json_encode($response));
 }
 function get_views()
 {
     $wpshop_attribute_links = array();
     $active_nb = wpshop_attributes::getElement('', "'valid'");
     $unactive_nb = wpshop_attributes::getElement('', "'moderated', 'notused'");
     $deleted_nb = wpshop_attributes::getElement('', "'deleted'");
     $wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_valid' . (empty($_REQUEST['attribute_status']) ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING) . '" >' . __('Used attributes', 'wpshop') . ' (' . count($active_nb) . ')</a>';
     $wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_moderated' . (!empty($_REQUEST['attribute_status']) && $_REQUEST['attribute_status'] == 'unactive' ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING . '&attribute_status=unactive') . '" >' . __('Unactive attributes', 'wpshop') . ' (' . count($unactive_nb) . ')</a>';
     $wpshop_attribute_links['wpshop_attributes_links wpshop_attributes_links_deleted' . (!empty($_REQUEST['attribute_status']) && $_REQUEST['attribute_status'] == 'deleted' ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . WPSHOP_URL_SLUG_ATTRIBUTE_LISTING . '&attribute_status=deleted') . '" >' . __('Trashed attributes', 'wpshop') . ' (' . count($deleted_nb) . ')</a>';
     $wpshop_attribute_links['unit_management_link'] = '<a href="#" id="wpshop_attribute_unit_manager_opener">' . __('Unit management', 'wpshop') . '</a>';
     $wpshop_attribute_links['unit_management_dialog'] = '<div id="wpshop_attribute_unit_manager"title="' . __('Unit management', 'wpshop') . '" class="wpshopHide" ><div class="loading_picture_container" id="product_chooser_picture" ><img src="' . WPSHOP_LOADING_ICON . '" alt="loading..." /></div></div>';
     return $wpshop_attribute_links;
 }
Пример #4
0
 /**
  * Get product product Attributes definition
  *
  * @param integer $product_id
  *
  * @return array
  */
 function get_product_atts_def($product_id)
 {
     $product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
     $element_atribute_list = wpshop_attributes::getElementWithAttributeAndValue($product_entity_id, $product_id, WPSHOP_CURRENT_LOCALE, '', 'frontend');
     $one_product = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
     if (!empty($one_product)) {
         $array1 = !empty($one_product['attribute_set_section']) ? $one_product['attribute_set_section'] : array();
         $array2 = $element_atribute_list[$product_id];
         unset($element_atribute_list);
         foreach ($array2 as $key => $attribute_set_section) {
             foreach ($array1 as $code1 => $value) {
                 if ($code1 == $attribute_set_section['code']) {
                     $element_atribute_list[$product_id][$key] = $attribute_set_section;
                 }
             }
         }
     }
     return $element_atribute_list;
 }
 /**
  * AJAX - Création d'un nouveau produit / Create a new product
  */
 function create_product()
 {
     global $wpdb;
     $response = array('status' => false, 'output' => __('Error at product creation!', 'wpshop'), 'pid' => -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;
     $id_attribute_set = !empty($_POST['wps-product-attribute-set']) ? $_POST['wps-product-attribute-set'] : -1;
     if (-1 != $post_title && -1 != $id_attribute_set) {
         $new_product_id = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'post_title' => $post_title, 'post_content' => $post_content));
         if (!is_wp_error($new_product_id)) {
             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';
             // Get current barcode
             if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
                 // Get current barcode
                 $wps_product_mdl = new wps_product_mdl();
                 $attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id;
                 $barcode_value = wpshop_attributes::wpshop_att_val_func(array('pid' => $new_product_id, 'attid' => $attid));
                 $data_to_save['wpshop_product_attribute']['varchar']['barcode'] = $barcode_value;
             }
             $response['pid'] = $new_product_id;
             $response['status'] = false;
             $response['output'] = __('Product created partially!', 'wpshop');
             $response['letter'] = substr($post_title, 0, 1);
             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);
                 $response['status'] = true;
                 $response['output'] = __('Product created successfully.', 'wpshop');
             }
             $wps_quick_creation_hook = do_action('wps-new-product-quick-created', $new_product_id);
             if (!empty($wps_quick_creation_hook)) {
                 $response[''] = $wps_quick_creation_hook;
             }
         }
     }
     wp_die(json_encode($response));
 }
Пример #6
0
        ?>
</label>
				<div id="<?php 
        echo $signup_field->code;
        ?>
" class="wps-form"><?php 
        echo $attribute_output_def['output'];
        echo $attribute_output_def['options'];
        ?>
</div>
			</div>
		<?php 
        /** Check confirmation field **/
        if ($signup_field->_need_verification == 'yes') {
            $signup_field->code = $signup_field->code . '2';
            $attribute_output_def = wpshop_attributes::get_attribute_field_definition($signup_field, '', array());
            ?>
				<div class="wps-form-group">
					<label for="<?php 
            echo $signup_field->code;
            ?>
"><?php 
            printf(__('Confirm %s', 'wpshop'), stripslashes(strtolower(__($signup_field->frontend_label, 'wpshop'))));
            ?>
 <?php 
            echo !empty($attribute_output_def['required']) && $attribute_output_def['required'] == 'yes' ? '<em>*</em>' : '';
            ?>
</label>
					<div id="<?php 
            echo $signup_field->code;
            ?>
	</td>*/
?>
	
	<?php 
if (!empty($quick_add_form_attributes)) {
    $i = 0;
    ?>
		<?php 
    foreach ($quick_add_form_attributes as $attribute_id => $att_def) {
        $att = null;
        $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_id = %d AND status = %s', $default, $attribute_id, 'valid');
        $checking_display_att = $wpdb->get_results($query);
        if (!empty($checking_display_att)) {
            $current_value = wpshop_attributes::getAttributeValueForEntityInSet($att_def['data_type'], $attribute_id, $product_entity_id, $product['post_datas']->ID);
            $output_specs = array('page_code' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'element_identifier' => $product['post_datas']->ID, 'field_id' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product['post_datas']->ID . '_', 'current_value' => !empty($current_value->value) ? $current_value->value : '');
            $att = wpshop_attributes::display_attribute($att_def['code'], 'admin', $output_specs);
        }
        ?>
			<td class="wps_mass_interface_line">
				<div class="wps-form-group">
					<?php 
        /*<label><?php  _e( $att['field_definition']['label'], 'wpshop' ); ?></label>*/
        ?>
					<div class="wps-form"><?php 
        echo str_replace('name="wpshop_product_attribute', 'name="wpshop_product_attribute[' . $product['post_datas']->ID . ']', $att['field_definition']['output']);
        ?>
</div>
				</div>
			</td>
		<?php 
        $i++;
Пример #8
0
 public static function get_inconsistent_product()
 {
     $price_piloting_option = get_option('wpshop_shop_price_piloting');
     $entity_id = wpshop_entities::get_entity_identifier_from_code('wpshop_product');
     $attribute_def = wpshop_attributes::getElement($price_piloting_option == 'TTC' ? 'product_price' : 'price_ht', "'valid'", 'code');
     $attribute_id = $attribute_def->id;
     global $wpdb;
     $wpdb->query('SET SESSION group_concat_max_len = 10000');
     $query = "\n\t\tSELECT \t\tpost.ID, post.post_title, attr_val_dec.value as price_attribute, GROUP_CONCAT(postmeta.meta_key, '&sep&', postmeta.meta_value, '&&' ORDER BY postmeta.meta_key) as price\n\t\t\tFROM \t\t{$wpdb->posts} as post\n\t\tJOIN\t\t{$wpdb->postmeta} as postmeta\n\t\t\tON\t\t\tpost.ID=postmeta.post_id\n\t\tJOIN\t\t" . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " attr_val_dec\n\t\t\tON\t\t\tpost.ID=attr_val_dec.entity_id\n\t\tWHERE\t\tpost.post_type='wpshop_product'\n\t\t\tAND\t\t\tattr_val_dec.entity_type_id=%d\n\t\t\tAND\t\t\tattr_val_dec.attribute_id=%d\n\t\t\tAND\t\t\tpostmeta.meta_key IN( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata' )\n\t\tGROUP BY\tpost.ID";
     $list_product = $wpdb->get_results($wpdb->prepare($query, array($entity_id, $attribute_id)));
     if (!empty($list_product)) {
         foreach ($list_product as $key_product => &$product) {
             $product->price = explode('&&,', $product->price);
             if (!empty($product->price) && is_array($product->price)) {
                 $array_price = array();
                 foreach ($product->price as &$price) {
                     if (strpos($price, '&&')) {
                         $price = substr($price, 0, -2);
                     }
                     $tmp_price = explode('&sep&', $price);
                     $key = $tmp_price[0];
                     $price = maybe_unserialize($tmp_price[1]);
                     /** _wpshop_product_metadata */
                     if ($key == '_wpshop_product_metadata') {
                         $array_price[$key] = $price_piloting_option == 'TTC' ? $price['product_price'] : $price['price_ht'];
                     }
                     /** _wps_price_infos */
                     if ($key == '_wps_price_infos') {
                         $array_price[$key] = !empty($price['PRODUCT_PRICE']) ? $price['PRODUCT_PRICE'] : '-';
                     }
                     if ($key == '_product_price') {
                         $array_price[$key] = $price_piloting_option == 'TTC' ? $price : '-';
                     }
                     if ($key == '_wpshop_displayed_price') {
                         $array_price[$key] = $price;
                     }
                     unset($price);
                 }
                 $array_meta_list = array('_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata');
                 foreach ($array_meta_list as $meta_list) {
                     if (!array_key_exists($meta_list, $array_price)) {
                         $array_price[$meta_list] = 0;
                     }
                 }
                 $product->price = $array_price;
                 if ($product->price_attribute === $product->price['_wpshop_product_metadata']) {
                     unset($list_product[$key_product]);
                 }
             }
         }
         unset($product);
     }
     return $list_product;
 }
    ?>
" />
		</div>
		
		<div class="customer_address wps-boxed">
			<span class="wps-h4"><?php 
    _e('Billing address', 'wpshop');
    ?>
</span>
			<?php 
    $billing_option = get_option('wpshop_billing_address');
    $addresses_customer = wps_address::get_addresses_list_no_hidden_attributes($customer_id);
    if (!empty($addresses_customer[$billing_option['choice']])) {
        $billing = reset($addresses_customer[$billing_option['choice']]);
        //echo '<strong>' . $billing['address_title']['value'] . '</strong>' . '' . '<br>';
        echo @(__(wpshop_attributes::get_attribute_type_select_option_info($billing['civility']['value'], 'label', 'custom')) . ' <strong>' . $billing['address_first_name']['value'] . ' ' . $billing['address_last_name']['value'] . '</strong><br>');
        echo @($billing['address']['value'] . '<br>');
        echo @($billing['city']['value'] . ' ' . $billing['postcode']['value'] . ' ' . $billing['country']['value']) . '<br>';
    }
    ?>
		</div>
		
		<div class="order_historic wps-boxed">
			<a href="#" class="toggle-historic dashicons dashicons-arrow-down alignright"></a>
			<span class="wps-h4"><?php 
    _e('Historic', 'wpshop');
    ?>
</span>
			<?php 
    foreach ($this->get_orders_customer(3, $customer_id) as $order) {
        ?>
 /**
  * AJAX - Save datas
  */
 function wps_save_product_quick_interface()
 {
     global $wpdb;
     $response = '';
     $status = false;
     $count_products_to_update = 0;
     $total_updated_products = 0;
     if (!empty($_REQUEST['wps_product_quick_save'])) {
         $count_products_to_update = count($_REQUEST['wps_product_quick_save']);
         foreach ($_REQUEST['wps_product_quick_save'] as $product_to_save) {
             $data_to_save = array();
             // Update post
             $updated_post = wp_update_post(array('ID' => $product_to_save, 'post_title' => $_REQUEST['wps_mass_interface'][$product_to_save]['post_title'], 'post_content' => $_REQUEST['wps_mass_interface'][$product_to_save]['post_content']));
             // Update attributes
             if (!empty($updated_post)) {
                 // Update Featured picture
                 if (!empty($_REQUEST['wps_mass_interface'][$product_to_save]['picture'])) {
                     $thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true);
                     if ($_REQUEST['wps_mass_interface'][$product_to_save]['picture'] != 'deleted') {
                         wp_update_post(array('ID' => $_REQUEST['wps_mass_interface'][$product_to_save]['picture'], 'post_parent' => $updated_post));
                         update_post_meta($updated_post, '_thumbnail_id', $_REQUEST['wps_mass_interface'][$product_to_save]['picture']);
                     } elseif ($_REQUEST['wps_mass_interface'][$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
                         delete_post_meta($updated_post, '_thumbnail_id');
                     }
                 }
                 // Update files datas
                 if (!empty($_REQUEST['wps_mass_interface'][$product_to_save]['files'])) {
                     $files_data = explode(',', $_REQUEST['wps_mass_interface'][$product_to_save]['files']);
                     if (!empty($files_data) && is_array($files_data)) {
                         foreach ($files_data as $file_id) {
                             if (!empty($file_id)) {
                                 wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post));
                             }
                         }
                     }
                 }
                 $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save);
                 $data_to_save['wpshop_product_attribute'] = !empty($_REQUEST['wpshop_product_attribute'][$product_to_save]) ? $_REQUEST['wpshop_product_attribute'][$product_to_save] : array();
                 if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
                     // Get current barcode
                     $wps_product_mdl = new wps_product_mdl();
                     $attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id;
                     $barcode_value = wpshop_attributes::wpshop_att_val_func(array('pid' => $data_to_save['post_ID'], 'attid' => $attid));
                     $data_to_save['wpshop_product_attribute']['varchar']['barcode'] = $barcode_value;
                 }
                 $data_to_save['user_ID'] = get_current_user_id();
                 $data_to_save['action'] = 'editpost';
                 if (!empty($_REQUEST['wps_mass_interface'][$product_to_save]['post_delete']) && $_REQUEST['wps_mass_interface'][$product_to_save]['post_delete'] == "true") {
                     wp_trash_post($product_to_save);
                 }
                 if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) {
                     $product_class = new wpshop_products();
                     $product_class->save_product_custom_informations($product_to_save, $data_to_save);
                     $total_updated_products++;
                 }
             }
         }
     }
     // Checking status
     $status = $total_updated_products == $count_products_to_update ? true : false;
     if ($status) {
         $response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products);
     } else {
         if (!empty($total_updated_products)) {
             $response = sprintf(__('All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update);
         } else {
             $response = __('No product have been updated', 'wpshop');
         }
     }
     echo json_encode(array('status' => $status, 'response' => $response));
     wp_die();
 }
<?php 
            $specific_options = ob_get_contents();
            ob_end_clean();
            break;
        case 'product':
            $query = $wpdb->prepare("SELECT COUNT(ID) as WPSHOP_PRODUCT_NB FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
            $wpshop_product_nb = $wpdb->get_var($query);
            $content = sprintf(__('Due to product number, you have to search for product or click on "%s" button', 'wpshop'), __('View all element', 'wpshop'));
            if ($wpshop_product_nb <= 100) {
                $content = wpshop_products::product_list(true);
            }
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_products pid';
            break;
        case 'product_by_attribute':
            $content_explanation = '<p>' . __('Generate product listing shortcode from a selected attribute value', 'wpshop') . '</p>';
            $content = wpshop_attributes::get_attribute_list(null, $type);
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_products att_name';
            $display_option_grouped = false;
            $display_search_form = false;
            break;
    }
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php 
language_attributes();
?>
>
<head>
	<meta http-equiv="Content-Type" content="<?php 
bloginfo('html_type');
Пример #12
0
 /** Recalculate prices in mass **/
 function mass_update_prices()
 {
     global $wpdb;
     $status = false;
     $result = '';
     @ini_set('max_execution_time', '500');
     $price_piloting_option = get_option('wpshop_shop_price_piloting');
     $output_type_option = get_option('wpshop_display_option');
     $output_type = $output_type_option['wpshop_display_list_type'];
     /** Get tx_tva attribute_id **/
     $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', 'tx_tva');
     $tx_tva_attribute_id = $wpdb->get_var($query);
     /** Product entity Definition **/
     $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
     /** Attributes def **/
     $tva_attribute_def = wpshop_attributes::getElement('tva', "'valid'", 'code');
     $product_price_attribute_def = wpshop_attributes::getElement('product_price', "'valid'", 'code');
     $price_ht_attribute_def = wpshop_attributes::getElement('price_ht', "'valid'", 'code');
     if (!empty($tx_tva_attribute_id)) {
         $query = $wpdb->prepare('SELECT id, value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid');
         $tx_tva = $wpdb->get_results($query);
         $tva_array = array();
         /** Transform array to easy teatment **/
         foreach ($tx_tva as $t) {
             $tva_array[$t->id] = $t->value;
         }
         if (!empty($tx_tva)) {
             $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             for ($i = 0; $i <= $count_products->publish; $i += 100) {
                 $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
                 $products = $wpdb->get_results($query);
                 if (!empty($products)) {
                     foreach ($products as $product) {
                         $product_data = get_post_meta($product->ID, '_wpshop_product_metadata', true);
                         if (!empty($product_data)) {
                             if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) {
                                 if (!empty($price_piloting_option) && $price_piloting_option == 'HT') {
                                     /** Update post meta **/
                                     $product_data['price_ht'] = (double) str_replace(',', '.', $product_data['price_ht']);
                                     $product_data['product_price'] = $product_data['price_ht'] * (1 + $tva_array[$product_data['tx_tva']] / 100);
                                     $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100);
                                     update_post_meta($product->ID, '_wpshop_product_metadata', $product_data);
                                     /** Update attributes values **/
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (double) $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (double) $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (double) $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID));
                                     /** Update Display price meta **/
                                     $p = wpshop_products::get_product_data($product->ID);
                                     $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
                                     update_post_meta($product->ID, '_wps_price_infos', $price);
                                 } else {
                                     /** Update post meta **/
                                     $product_data['product_price'] = (double) str_replace(',', '.', $product_data['product_price']);
                                     $product_data['price_ht'] = $product_data['product_price'] / (1 + $tva_array[$product_data['tx_tva']] / 100);
                                     $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100);
                                     update_post_meta($product->ID, '_wpshop_product_metadata', $product_data);
                                     /** Update attributes values **/
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID));
                                     /** Update Display price meta **/
                                     $p = wpshop_products::get_product_data($product->ID);
                                     $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
                                     update_post_meta($product->ID, '_wps_price_infos', $price);
                                 }
                             }
                         }
                     }
                 }
             }
             unset($products);
             $count_variations = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION);
             for ($i = 0; $i <= $count_variations->publish; $i += 100) {
                 $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish');
                 $product_variations = $wpdb->get_results($query);
                 /** Update Products Variations **/
                 if (!empty($product_variations)) {
                     foreach ($product_variations as $product_variation) {
                         $product_data = get_post_meta($product_variation->ID, '_wpshop_product_metadata', true);
                         if (!empty($product_data)) {
                             if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) {
                                 if (!empty($price_piloting_option) && $price_piloting_option == 'HT') {
                                     /** Update post meta **/
                                     $product_data['price_ht'] = (double) str_replace(',', '.', $product_data['price_ht']);
                                     $product_data['product_price'] = $product_data['price_ht'] * (1 + $tva_array[$product_data['tx_tva']] / 100);
                                     $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100);
                                     update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data);
                                     /** Update attributes values **/
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID));
                                 } else {
                                     /** Update post meta **/
                                     $product_data['product_price'] = (double) str_replace(',', '.', $product_data['product_price']);
                                     $product_data['price_ht'] = $product_data['product_price'] / (1 + $tva_array[$product_data['tx_tva']] / 100);
                                     $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100);
                                     update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data);
                                     /** Update attributes values **/
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID));
                                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID));
                                 }
                             }
                         }
                     }
                 }
             }
             $result = __('Prices updated', 'wpshop');
             $status = true;
         } else {
             $result = __('No VAT rates was found', 'wpshop');
         }
     } else {
         $result = __('VAT rate attribute was not found', 'wpshop');
     }
     return array($status, $result);
 }
    /**
     * Define the different field available for bulk edition for entities. Attributes to display are defined by checking box in attribute option
     *
     * @param string $column_name The column name for output type definition
     * @param string $post_type The current
     *
     */
    function bulk_edit($column_name, $entity)
    {
        switch ($entity) {
            case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                $attribute_def = wpshop_attributes::getElement($column_name, "'valid'", 'code');
                if (!empty($attribute_def)) {
                    $input_def = self::get_attribute_field_definition($attribute_def, '', array('input_class' => ' wpshop_bulk_and_quick_edit_input'));
                    $input = wpshop_form::check_input_type($input_def, $input_def['input_domain']);
                    ?>
	<div class="wpshop_bulk_and_quick_edit_column_container wpshop_bulk_and_quick_edit_column_<?php 
                    echo $column_name;
                    ?>
_container">
		<span class="wpshop_bulk_and_quick_edit_column_label wpshop_bulk_and_quick_edit_column_<?php 
                    echo $column_name;
                    ?>
_label"><?php 
                    _e($attribute_def->frontend_label, 'wpshop');
                    ?>
</span>
		<?php 
                    echo str_replace('chosen_select', '', str_replace('alignleft', '', $input));
                    ?>
		<!-- <input class="wpshop_bulk_and_quick_edit_input wpshop_bulk_and_quick_edit_input_data_type_<?php 
                    echo $attribute_def->data_type;
                    ?>
 wpshop_bulk_and_quick_edit_input_data_code_<?php 
                    echo $attribute_def->code;
                    ?>
" type="text" name="<?php 
                    echo $entity;
                    ?>
_-code-_<?php 
                    echo $attribute_def->code;
                    ?>
" value="" />  -->
	</div>
<?php 
                }
                break;
        }
    }
Пример #14
0
 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;
 }
Пример #15
0
 /** Give the content by column
  * @return array
  */
 public static function orders_custom_columns($column, $post_id)
 {
     if (get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
         global $civility, $order_status;
         $metadata = get_post_custom();
         $order_postmeta = isset($metadata['_order_postmeta'][0]) ? unserialize($metadata['_order_postmeta'][0]) : '';
         $addresses = get_post_meta($post_id, '_order_info', true);
         switch ($column) {
             case "order_identifier":
                 if (!empty($order_postmeta['order_key'])) {
                     echo '<b>' . $order_postmeta['order_key'] . '</b><br>';
                 }
                 if (!empty($order_postmeta['order_invoice_ref'])) {
                     echo !empty($order_postmeta['order_temporary_key']) ? '<b>' . $order_postmeta['order_invoice_ref'] . '</b>' : '<i>' . $order_postmeta['order_invoice_ref'] . '</i>';
                 }
                 break;
             case "order_status":
                 echo !empty($order_postmeta['order_status']) ? sprintf('<mark class="%s" id="order_status_' . $post_id . '">%s</mark>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) : __('Unknown Status', 'wpshop');
                 break;
             case "order_billing":
                 if (!empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address'])) {
                     $billing = $addresses['billing']['address'];
                 } else {
                     if (!empty($addresses['billing'])) {
                         $billing = $addresses['billing'];
                     }
                 }
                 if (!empty($billing)) {
                     echo (!empty($billing['civility']) ? __(wpshop_attributes::get_attribute_type_select_option_info($billing['civility'], 'label', 'custom'), 'wpshop') : null) . ' <strong>' . (!empty($billing['address_first_name']) ? $billing['address_first_name'] : null) . ' ' . (!empty($billing['address_last_name']) ? $billing['address_last_name'] : null) . '</strong>';
                     echo empty($billing['company']) ? '<br />' : ', <i>' . $billing['company'] . '</i><br />';
                     echo (!empty($billing['address']) ? $billing['address'] : null) . '<br />';
                     echo (!empty($billing['postcode']) ? $billing['postcode'] : null) . ' ' . (!empty($billing['city']) ? $billing['city'] : null) . ', ' . (!empty($billing['country']) ? $billing['country'] : null);
                 } else {
                     echo __('No information available for user billing', 'wpshop');
                 }
                 break;
             case "order_shipping":
                 if (!empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address'])) {
                     $shipping = $addresses['shipping']['address'];
                 } else {
                     if (!empty($addresses['shipping'])) {
                         $shipping = $addresses['shipping'];
                     }
                 }
                 if (!empty($shipping)) {
                     echo '<strong>' . (!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null) . ' ' . (!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null) . '</strong>';
                     echo empty($shipping['company']) ? '<br />' : ', <i>' . $shipping['company'] . '</i><br />';
                     echo (!empty($shipping['address']) ? $shipping['address'] : null) . '<br />';
                     echo (!empty($shipping['postcode']) ? $shipping['postcode'] : null) . ' ' . (!empty($shipping['city']) ? $shipping['city'] : null) . ', ' . (!empty($shipping['country']) ? $shipping['country'] : null);
                 } else {
                     echo __('No information available for user shipping', 'wpshop');
                 }
                 break;
             case "order_type":
                 echo '<a href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . (!empty($order_postmeta['order_temporary_key']) ? __('Quotation', 'wpshop') : __('Basic order', 'wpshop')) . '</a>';
                 $buttons = '<p class="row-actions">';
                 // Voir la commande
                 $buttons .= '<a class="button button-small" href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . __('View', 'wpshop') . '</a>';
                 // Marquer comme envoy�
                 if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] == 'completed') {
                     $buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_' . $post_id . ' wps-bton-loader">' . __('Mark as shipped', 'wpshop') . '</a> ';
                 } else {
                     if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] == 'awaiting_payment') {
                         //		$buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' ';
                     }
                 }
                 $buttons .= '</p>';
                 $buttons .= '<input type="hidden" name="input_wpshop_change_order_state" id="input_wpshop_change_order_state" value="' . wp_create_nonce("wpshop_change_order_state") . '" />';
                 $buttons .= '<input type="hidden" name="input_wpshop_dialog_inform_shipping_number" id="input_wpshop_dialog_inform_shipping_number" value="' . wp_create_nonce("wpshop_dialog_inform_shipping_number") . '" />';
                 $buttons .= '<input type="hidden" name="input_wpshop_validate_payment_method" id="input_wpshop_validate_payment_method" value="' . wp_create_nonce("wpshop_validate_payment_method") . '" />';
                 echo $buttons;
                 break;
             case "order_total":
                 $currency = !empty($order_postmeta['order_currency']) ? $order_postmeta['order_currency'] : get_option('wpshop_shop_default_currency');
                 echo isset($order_postmeta['order_grand_total']) ? number_format($order_postmeta['order_grand_total'], 2, '.', '') . ' ' . wpshop_tools::wpshop_get_sigle($currency) : 'NaN';
                 break;
                 /*case "order_actions":
                 					$buttons = '<p class="row-actions">';
                 					// Marquer comme envoy�
                 					if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'completed')) {
                 							$buttons .= '<a class="button markAsShipped order_'.$post_id.'">'.__('Mark as shipped', 'wpshop').'</a> ';
                 					}
                 					else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment' )) {
                 					//		$buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' ';
                 					}
                 
                 					// Voir la commande
                 					$buttons .= '<a class="button alignright" href="'.admin_url('post.php?post='.$post_id.'&action=edit').'">'.__('View', 'wpshop').'</a>';
                 					$buttons .= '</p>';
                 					$buttons .= '<input type="hidden" name="input_wpshop_change_order_state" id="input_wpshop_change_order_state" value="' . wp_create_nonce("wpshop_change_order_state") . '" />';
                 					$buttons .= '<input type="hidden" name="input_wpshop_dialog_inform_shipping_number" id="input_wpshop_dialog_inform_shipping_number" value="' . wp_create_nonce("wpshop_dialog_inform_shipping_number") . '" />';
                 					$buttons .= '<input type="hidden" name="input_wpshop_validate_payment_method" id="input_wpshop_validate_payment_method" value="' . wp_create_nonce("wpshop_validate_payment_method") . '" />';
                 
                 					echo $buttons;
                 				break;*/
         }
     }
 }
	       	'<?php 
echo !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['country']) ? $order_info['billing']['address']['country'] : '';
?>
']);

	<?php 
if (!empty($order_meta['order_items']) && is_array($order_meta['order_items'])) {
    ?>
		<?php 
    foreach ($order_meta['order_items'] as $item) {
        /** Variation **/
        $variation = '';
        $variation_definition = get_post_meta($item['item_id'], '_wpshop_variations_attribute_def', true);
        if (!empty($variation_definition) && is_array($variation_definition)) {
            foreach ($variation_definition as $k => $value) {
                $attribute_def = wpshop_attributes::getElement($k, '"valid"', 'code');
                if (!empty($attribute_def)) {
                    $variation .= $attribute_def->frontend_label . ' : ';
                    if ($attribute_def->data_type_to_use == 'custom') {
                        $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $value);
                        $variation .= $wpdb->get_var($query);
                    } else {
                        $variation .= get_the_title($value);
                    }
                }
            }
        }
        $item_meta = get_post_meta($item['item_id'], '_wpshop_product_metadata', true);
        ?>
		_gaq.push(['_addItem',
		   		'<?php 
Пример #17
0
 /**
  * Restock the product after credit
  * @param int $product_id
  * @param int $product_qty
  */
 function restock_product_after_credit($product_id, $product_qty)
 {
     global $wpdb;
     $stock_attribute_def = wpshop_attributes::getElement('product_stock', '"valid"', 'code');
     $product_type_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
     if (!empty($product_id) && !empty($product_qty)) {
         $product_postmeta = get_post_meta($product_id, '_wpshop_product_metadata', true);
         $product_postmeta['product_stock'] = str_replace(',', '.', $product_postmeta['product_stock']) + $product_qty;
         update_post_meta($product_id, '_wpshop_product_metadata', $product_postmeta);
         $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_postmeta['product_stock']), array('entity_type_id' => $product_type_entity_id, 'attribute_id' => $stock_attribute_def->id, 'entity_id' => $product_id));
     }
 }
 /**
  * AJAX - Action to search with selected attributes values
  */
 function wpshop_ajax_filter_search_action()
 {
     global $wpdb;
     $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_category_id']) : 0;
     $filter_search_elements = $this->pick_up_filter_search_elements_type($category_id);
     $page_id = !empty($_POST['wpshop_filter_search_current_page_id']) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_current_page_id']) : 1;
     $request_cmd = '';
     $status = false;
     $data = array();
     foreach ($filter_search_elements as $k => $filter_search_element) {
         $datatype_element = array('select_value', 'multiple_select_value', 'fork_values');
         if (in_array($filter_search_element['type'], $datatype_element) && (isset($_REQUEST['filter_search' . $k]) && $_REQUEST['filter_search' . $k] == 'all_attribute_values') || ($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value') && !isset($_REQUEST['filter_search' . $k]) || $filter_search_element['type'] == 'fork_values' && (!isset($_REQUEST['amount_min' . $k]) || !isset($_REQUEST['amount_max' . $k]))) {
             unset($filter_search_elements[$k]);
         }
     }
     /** SQL request Construct for pick up all product with one of filter search element value **/
     if (!empty($filter_search_elements) && !empty($_REQUEST)) {
         $request_cmd = '';
         $first = true;
         $i = 1;
         $filter_search_elements_count = count($filter_search_elements);
         /** Get subcategories **/
         $current_category_children = array();
         $args = array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, 'child_of' => $category_id);
         $current_category_children = get_categories($args);
         /** Construct the array for SELECT query IN **/
         $categories_id = array();
         $categories_id[] = $category_id;
         if (!empty($current_category_children)) {
             foreach ($current_category_children as $current_category_child) {
                 $categories_id[] = $current_category_child->term_taxonomy_id;
             }
         }
         /** Make the array **/
         $array_for_query = implode(',', $categories_id);
         foreach ($filter_search_elements as $k => $filter_search_element) {
             if (!empty($filter_search_element['type']) && !empty($_REQUEST['filter_search' . $k]) && $filter_search_element['type'] == 'select_value' && $_REQUEST['filter_search' . $k] != 'all_attribute_values') {
                 $request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON  post_id = ID WHERE (meta_key = "' . $k . '" AND meta_value = "' . wpshop_tools::varSanitizer($_REQUEST['filter_search' . $k]) . '") AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish" ';
                 $request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) ';
             } else {
                 if ($filter_search_element['type'] == 'fork_values') {
                     $request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON  post_id = ID WHERE (meta_key = "' . (!empty($k) && $k == '_product_price' ? '_wpshop_displayed_price' : $k) . '" AND meta_value BETWEEN ' . wpshop_tools::varSanitizer($_REQUEST['amount_min' . $k]) . ' AND ' . wpshop_tools::varSanitizer($_REQUEST['amount_max' . $k]) . ') AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish"';
                     $request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) ';
                 } else {
                     if ($filter_search_element['type'] == 'multiple_select_value') {
                         /** Check the attribute id **/
                         $attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code');
                         if (!empty($attribute_def)) {
                             $request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' . WPSHOP_DBT_ATTRIBUTE . ', ' . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . ' AS ATT_INT WHERE attribute_id = id AND attribute_id = ' . $attribute_def->id;
                             $first = true;
                             if (!empty($_REQUEST['filter_search' . $k]) && is_array($_REQUEST['filter_search' . $k])) {
                                 foreach ($_REQUEST['filter_search' . $k] as $r) {
                                     if ($first) {
                                         $request_cmd .= ' AND (value ="' . wpshop_tools::varSanitizer($r) . '"';
                                         $first = false;
                                     } else {
                                         $request_cmd .= ' OR value ="' . wpshop_tools::varSanitizer($r) . '"';
                                     }
                                 }
                                 $request_cmd .= ')';
                             } elseif (!empty($_REQUEST['filter_search' . $k])) {
                                 $request_cmd .= ' AND (value ="' . wpshop_tools::varSanitizer($_REQUEST['filter_search' . $k]) . '" )';
                             }
                             $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) ';
                         }
                     }
                 }
             }
             if ($i < count($filter_search_elements)) {
                 $request_cmd .= ' UNION ';
             }
             $i++;
         }
         /** SQL Request execution **/
         $query = $wpdb->prepare($request_cmd, '');
         $results = $wpdb->get_results($query);
         $first = true;
         $final_result = array();
         $temp_result = array();
         $first_key = null;
         $last = '';
         /** Transform the query result array **/
         foreach ($results as $result) {
             $result->meta_key = !empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price' ? '_product_price' : $result->meta_key;
             if ($last != $result->meta_key) {
                 $filter_search_elements[$result->meta_key]['count'] = 1;
                 $last = $result->meta_key;
             } else {
                 $filter_search_elements[$result->meta_key]['count']++;
             }
             $filter_search_elements[$result->meta_key]['values'][$result->post_id] = $result->post_id;
         }
         /** Check the smaller array of attributes **/
         $smaller_array = '';
         $smaller_array_count = -1;
         foreach ($filter_search_elements as $k => $filter_search_element) {
             if (empty($filter_search_element['count'])) {
                 $smaller_array_count = 0;
                 $smaller_array = $k;
             } elseif ($smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count) {
                 $smaller_array_count = $filter_search_element['count'];
                 $smaller_array = $k;
             }
         }
         /** Compare the smaller array with the others **/
         if (!empty($smaller_array_count)) {
             $temp_tab = $filter_search_elements[$smaller_array]['values'];
             foreach ($filter_search_elements as $filter_search) {
                 foreach ($temp_tab as $value) {
                     if (!in_array($value, $filter_search['values'])) {
                         /** If value don't exist in the smaller array, delete it **/
                         $key = array_key_exists($value, $temp_tab);
                         if ($key) {
                             unset($temp_tab[$value]);
                         }
                     }
                 }
             }
             /** Final result to display the products **/
             if (!empty($temp_tab)) {
                 $final_result = $temp_tab;
             }
         } else {
             $final_result = array();
         }
         $products_count = count($final_result);
         $products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'), $products_count);
         /** If there is products for this filter search **/
         $status = true;
         if (!empty($final_result)) {
             $data['status'] = true;
             $data['result'] = do_shortcode('[wpshop_products pid="' . implode(',', $final_result) . '" container="no" ]');
             $data['products_count'] = $products_count;
         } else {
             $data['status'] = false;
             $data['result'] = '<div class="container_product_listing">' . __('There is no product for this filter search.', 'wpshop') . '</div>';
             $data['products_count'] = __('No products corresponds to your search', 'wpshop');
         }
     }
     echo json_encode($data);
     die;
 }
Пример #19
0
 /**
  *	Build an array with the different items to add to an order
  *
  *	@param array $products The item list to add to the order
  *
  *	@return array $item_list The item to add to order
  */
 function add_product_to_order($product)
 {
     global $wpdb;
     if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) {
         $price_infos = wpshop_prices::check_product_price($product, true);
         $product['price_ht'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
         $product['product_price'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
         $product['tva'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
     }
     $price_piloting = get_option('wpshop_shop_price_piloting');
     if (!empty($price_piloting) && $price_piloting == 'HT') {
         $total_ht = $product['price_ht'] * $product['product_qty'];
         $tva_total_amount = $total_ht * ($product['tx_tva'] / 100);
         $total_ttc = $total_ht + $tva_total_amount;
     } else {
         $total_ttc = $product['product_price'] * $product['product_qty'];
         $total_ht = $total_ttc / (1 + $product['tx_tva'] / 100);
         $tva_total_amount = $total_ttc - $total_ht;
     }
     $tva = !empty($product[WPSHOP_PRODUCT_PRICE_TAX]) ? $product[WPSHOP_PRODUCT_PRICE_TAX] : null;
     $item_discount_type = $item_discount_value = $item_discount_amount = 0;
     $d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null;
     $d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null;
     $d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null;
     if (!empty($d_amount)) {
         $item_discount_type = 'discount_amount';
         $item_discount_amount = $product['discount_amount'];
         $item_discount_value = $product['discount_amount'];
     } elseif (!empty($d_rate)) {
         $item_discount_type = 'discount_rate';
         $item_discount_amount = $product['discount_rate'];
         $item_discount_value = $product['discount_rate'];
     } elseif (!empty($d_special)) {
         $item_discount_type = 'special_price';
         $item_discount_amount = $product['special_price'];
         $item_discount_value = $product['special_price'];
     }
     $item = array('item_id' => $product['product_id'], 'item_ref' => !empty($product['product_reference']) ? $product['product_reference'] : null, 'item_name' => !empty($product['product_name']) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array());
     $array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations');
     if (!empty($product['item_meta'])) {
         foreach ($product['item_meta'] as $key => $value) {
             if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) {
                 $item['item_' . $key] = $product[$key];
             }
         }
     }
     /** Check if it's a variation product **/
     if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) {
         foreach ($product['item_meta']['variations'] as $k => $variation) {
             $product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true);
             if (!empty($product_variation_def)) {
                 foreach ($product_variation_def as $attribute_code => $variation_id) {
                     $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
                     if (!empty($variation_attribute_def)) {
                         $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
                         if ($variation_attribute_def->data_type_to_use == 'custom') {
                             $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
                             $variation_name = $wpdb->get_var($query);
                         } else {
                             $variation_post = get_post($variation_id);
                             $variation_name = $variation_post->post_title;
                         }
                         $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
                         $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name;
                     }
                 }
             }
         }
     } else {
         /** Check if it's product with one variation **/
         $product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true);
         if (!empty($product_variation_def)) {
             foreach ($product_variation_def as $attribute_code => $variation_id) {
                 $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
                 if (!empty($variation_attribute_def)) {
                     $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
                     if ($variation_attribute_def->data_type_to_use == 'custom') {
                         $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
                         $variation_name = $wpdb->get_var($query);
                     } else {
                         $variation_post = get_post($variation_id);
                         $variation_name = $variation_post->post_title;
                     }
                     $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
                     $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name;
                 }
             }
         }
     }
     return $item;
 }
Пример #20
0
function wps_mass_action_on_entity_launch()
{
    global $wpdb;
    $response = '';
    $element_to_output = array();
    $attributes_to_test = array('decimal' => '6,36', 'varchar' => '12', 'integer' => '85', 'text' => '120, 118');
    $decimal_attribute = $attributes_to_test['decimal'];
    //,30,28
    $query = $wpdb->prepare("\n\t\t\t\tSELECT P.ID, P.post_title,\n\t\t\t\t\tD.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value\n\t\t\t\tFROM {$wpdb->posts} AS P\n\t\t\t\t\tINNER JOIN wp_wpshop__attribute_value_decimal AS D ON ( D.entity_id = P.ID )\n\t\t\t\t\tINNER JOIN wp_wpshop__attribute_value__histo AS H ON (( H.entity_type_id = D.entity_type_id ) AND ( H.attribute_id = D.attribute_id ) AND ( H.entity_id = D.entity_id ))\n\t\t\t\tWHERE ( (P.post_type = %s ) OR (P.post_type = %s ) )\n\t\t\t\t\tAND post_status = %s\n\t\t\t\t\tAND D.attribute_id IN ( " . $decimal_attribute . " )\n\t\t\t\t\tAND D.value = 0.00000\n\t\t\t\t\tAND H.value != 0.00000\n\t\t\t\t\tAND H.value_type = 'wp_wpshop__attribute_value_decimal'\n\n\t\t\t\tORDER BY H.entity_id ASC, H.value_id DESC", array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish"));
    $list_of_element = $wpdb->get_results($query);
    if (!empty($list_of_element)) {
        foreach ($list_of_element as $element) {
            $element_to_output[$element->ID]['title'] = $element->post_title;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
        }
    }
    $attribute_list = $attributes_to_test['varchar'];
    $query = $wpdb->prepare("\n\t\t\tSELECT P.ID, P.post_title,\n\t\t\t\tD.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value\n\t\t\tFROM {$wpdb->posts} AS P\n\t\t\tINNER JOIN wp_wpshop__attribute_value_varchar AS D ON ( D.entity_id = P.ID )\n\t\t\tINNER JOIN wp_wpshop__attribute_value__histo AS H ON (( H.entity_type_id = D.entity_type_id ) AND ( H.attribute_id = D.attribute_id ) AND ( H.entity_id = D.entity_id ))\n\t\t\tWHERE ( (P.post_type = %s ) OR (P.post_type = %s ) )\n\t\t\t\tAND post_status = %s\n\t\t\t\tAND D.attribute_id IN ( " . $attribute_list . " )\n\t\t\t\tAND ( D.value = '' OR D.value LIKE 'PDCT%%' )\n\t\t\t\tAND H.value != ''\n\t\t\t\tAND H.value_type = 'wp_wpshop__attribute_value_varchar'\n\t\t\tORDER BY H.creation_date", array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish"));
    $list_of_element = $wpdb->get_results($query);
    if (!empty($list_of_element)) {
        foreach ($list_of_element as $element) {
            $element_to_output[$element->ID]['title'] = $element->post_title;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
        }
    }
    $attribute_list = $attributes_to_test['text'];
    $query = $wpdb->prepare("\n\t\t\t\tSELECT P.ID, P.post_title,\n\t\t\t\tD.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value\n\t\t\t\tFROM {$wpdb->posts} AS P\n\t\t\t\tINNER JOIN wp_wpshop__attribute_value_text AS D ON ( D.entity_id = P.ID )\n\t\t\t\tINNER JOIN wp_wpshop__attribute_value__histo AS H ON (( H.entity_type_id = D.entity_type_id ) AND ( H.attribute_id = D.attribute_id ) AND ( H.entity_id = D.entity_id ))\n\t\t\t\tWHERE ( (P.post_type = %s ) OR (P.post_type = %s ) )\n\t\t\t\tAND post_status = %s\n\t\t\t\tAND D.attribute_id IN ( " . $attribute_list . " )\n\t\t\t\tAND ( D.value = '' )\n\t\t\t\tAND H.value != ''\n\t\t\t\tAND H.value_type = 'wp_wpshop__attribute_value_text'\n\t\t\tORDER BY H.creation_date", array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish"));
    $list_of_element = $wpdb->get_results($query);
    if (!empty($list_of_element)) {
        foreach ($list_of_element as $element) {
            $element_to_output[$element->ID]['title'] = $element->post_title;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
        }
    }
    $attribute_list = $attributes_to_test['integer'];
    $query = $wpdb->prepare("\n\t\t\t\tSELECT P.ID, P.post_title,\n\t\t\t\tD.value_id, H.value_id, D.attribute_id, D.entity_id, H.creation_date, D.creation_date_value, D.value AS current_value, H.value AS last_history_value\n\t\t\t\tFROM {$wpdb->posts} AS P\n\t\t\t\tINNER JOIN wp_wpshop__attribute_value_integer AS D ON ( D.entity_id = P.ID )\n\t\t\t\tINNER JOIN wp_wpshop__attribute_value__histo AS H ON (( H.entity_type_id = D.entity_type_id ) AND ( H.attribute_id = D.attribute_id ) AND ( H.entity_id = D.entity_id ))\n\t\t\t\tWHERE ( (P.post_type = %s ) OR (P.post_type = %s ) )\n\t\t\t\tAND post_status = %s\n\t\t\t\tAND D.attribute_id IN ( " . $attribute_list . " )\n\t\t\t\tAND ( D.value = '' OR D.value LIKE 'PDCT%%' )\n\t\t\t\tAND H.value != ''\n\t\t\t\tAND H.value_type = 'wp_wpshop__attribute_value_integer'\n\t\t\tORDER BY H.creation_date", array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "publish"));
    $list_of_element = $wpdb->get_results($query);
    if (!empty($list_of_element)) {
        foreach ($list_of_element as $element) {
            $element_to_output[$element->ID]['title'] = $element->post_title;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['current'] = $element->current_value;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_id'] = $element->value_id;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value_date'] = $element->creation_date;
            $element_to_output[$element->ID]['content'][$element->attribute_id][$element->creation_date]['histo']['value'] = $element->last_history_value;
        }
    }
    $array_done = array();
    if (!empty($element_to_output)) {
        $lines = '';
        $done_header = array();
        /** Formate informations **/
        $formatted_datas = array();
        $controller_rows_array = array();
        foreach ($attributes_to_test as $attribute_to_test) {
            $atts = explode(',', $attribute_to_test);
            foreach ($atts as $att) {
                $controller_rows_array[$att] = false;
            }
        }
        foreach ($element_to_output as $element_id => $element_definition) {
            $formatted_datas[$element_id]['title'] = $element_definition['title'];
            $formatted_datas[$element_id]['content'] = array();
            foreach ($attributes_to_test as $attribute_to_test) {
                $atts = explode(',', $attribute_to_test);
                foreach ($atts as $att) {
                    if (!empty($element_definition['content'][$att])) {
                        $formatted_datas[$element_id]['content'][$att] = $element_definition['content'][$att];
                        $controller_rows_array[$att] = true;
                    } else {
                        $formatted_datas[$element_id]['content'][$att] = array();
                    }
                }
            }
        }
        foreach ($formatted_datas as $element_id => $element_definition) {
            if (!in_array($element_id, $array_done)) {
                $lines .= '<tr  style="border:1px solid black;"><td  style="border:1px solid black;" >#' . $element_id . ' - ' . $element_definition['title'] . '</td>';
                ksort($element_definition['content']);
                foreach ($element_definition['content'] as $atribute_id => $value_on_date) {
                    if ($controller_rows_array[$atribute_id]) {
                        $current_attribute = wpshop_attributes::getElement($atribute_id);
                        if (!in_array($atribute_id, $done_header)) {
                            $more_header .= '<td style="border:1px solid black;" >' . __($current_attribute->frontend_label, 'wpshop') . '</td>';
                            $done_header[] = $atribute_id;
                        }
                        $last_value = 'XXXXX';
                        $counter_for_line = 0;
                        $content_line = '';
                        foreach ($value_on_date as $date => $value) {
                            if ($value['histo']['value'] != $last_value) {
                                $current_val = $value['current'];
                                $old_val = $value['histo']['value'];
                                // Test if attribute data Type is integer
                                if ($current_attribute->data_type == 'integer') {
                                    if ($current_attribute->data_type_to_use == 'internal') {
                                        $current_val = get_the_title($current_val);
                                        $old_val = get_the_title($old_val);
                                    } else {
                                        $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $old_val);
                                        $old_val = $wpdb->get_var($query);
                                        $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $current_val);
                                        $current_val = $wpdb->get_var($query);
                                    }
                                }
                                $content_line .= '<label ><input type="radio" name="value_to_take[' . $element_id . '][' . $atribute_id . ']" value="' . $value['histo']['value_id'] . '"' . checked(0 == $counter_for_line ? true : false, true, false) . '/>' . __('Current value', 'wpshop') . ' : ' . $current_val . ' / ' . __('Last value', 'wpshop') . ' : ' . $old_val . '</label><br/>';
                                $last_value = $value['histo']['value'];
                                $counter_for_line++;
                            }
                        }
                        $lines .= '<td style="border:1px solid black;" >';
                        $lines .= $content_line;
                        $lines .= '</td>';
                    }
                }
                $lines .= '</tr>';
                $array_done[$element_id];
            }
        }
        $response = '
				<form action="' . admin_url('admin-ajax.php') . '" method="POST" id="wps_put_histo_back" >
					<input type="text" name="action" value="wps_put_history_back" />
					<table style="border-collapse: collapse;border:1px solid black;" cellpadding="0" cellspacing="0" >
						<tr style="border:1px solid black;"><td style="border:1px solid black;" >' . __('Product', 'wpshop') . '</td>' . $more_header . '</tr>
						' . $lines . '
					</table>
				</form><script type="text/javascript" >
				jQuery( document ).ready( function(){
					jQuery( "#wps_put_histo_back" ).ajaxForm( function( response ){

					});
				});
			</script>';
    }
    return $response;
}
Пример #21
0
 /**
  * Manage special operation on wpshop plugin update
  */
 public static function make_specific_operation_on_update($version)
 {
     global $wpdb, $wp_rewrite;
     $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
     switch ($version) {
         case 3:
         case 6:
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 8:
             /**	Change metaboxes order for product in case it already exists	*/
             $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product');
             $customer_metaboxes_order = $wpdb->get_results($query);
             if (!empty($customer_metaboxes_order)) {
                 foreach ($customer_metaboxes_order as $customer_metabox_order) {
                     $do_changes = false;
                     $current_order = unserialize($customer_metabox_order->meta_value);
                     if (array_key_exists('normal', $current_order) && false !== strpos('wpshop_product_important_datas', $current_order['normal'])) {
                         str_replace('wpshop_product_important_datas,', '', $current_order['normal']);
                         $do_changes = true;
                     }
                     if (array_key_exists('side', $current_order)) {
                         str_replace('wpshop_product_important_datas,', '', $current_order['side']);
                         str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']);
                         $do_changes = true;
                     }
                     if (true === $do_changes) {
                         $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id));
                     }
                 }
             } else {
                 $users = get_users(array('role' => 'administrator'));
                 if (!empty($users)) {
                     foreach ($users as $user) {
                         $user_meta = array('side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', 'advanced' => '');
                         update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta);
                     }
                 }
             }
             /*	Update the product prices into database	*/
             $query = $wpdb->prepare("\nSELECT\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva');
             $product_prices = $wpdb->get_row($query);
             $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva));
             $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price);
             $price_list = $wpdb->get_results($query);
             foreach ($price_list as $existing_ttc_price) {
                 $tax_rate = 1.2;
                 $price_ht = $existing_ttc_price->value / $tax_rate;
                 $tax_amount = $existing_ttc_price->value - $price_ht;
                 $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0)));
                 $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0)));
                 $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0)));
             }
             /*	Update orders structure into database	*/
             $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
             foreach ($orders_id as $o) {
                 $myorder = get_post_meta($o->ID, '_order_postmeta', true);
                 $neworder = array();
                 $items = array();
                 if (!isset($myorder['order_tva'])) {
                     $order_total_ht = 0;
                     $order_total_ttc = 0;
                     $order_tva = array('20' => 0);
                     foreach ($myorder['order_items'] as $item) {
                         /* item */
                         $pu_ht = $item['cost'] / 1.2;
                         $pu_tva = $item['cost'] - $pu_ht;
                         $total_ht = $pu_ht * $item['qty'];
                         $tva_total_amount = $pu_tva * $item['qty'];
                         $total_ttc = $item['cost'] * $item['qty'];
                         /* item */
                         $order_total_ht += $total_ht;
                         $order_total_ttc += $total_ttc;
                         $order_tva['20'] += $tva_total_amount;
                         $items[] = array('item_id' => $item['id'], 'item_ref' => 'Nc', 'item_name' => $item['name'], 'item_qty' => $item['qty'], 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), 'item_ecotaxe_tva' => 20, 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), 'item_discount_type' => 0, 'item_discount_value' => 0, 'item_discount_amount' => number_format(0, 2, '.', ''), 'item_tva_rate' => 20, 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), 'item_total_ht' => number_format($total_ht, 2, '.', ''), 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), 'item_total_ttc' => number_format($total_ttc, 2, '.', ''));
                     }
                     $neworder = array('order_key' => $myorder['order_key'], 'customer_id' => $myorder['customer_id'], 'order_status' => $myorder['order_status'], 'order_date' => $myorder['order_date'], 'order_payment_date' => $myorder['order_payment_date'], 'order_shipping_date' => $myorder['order_shipping_date'], 'payment_method' => $myorder['payment_method'], 'order_invoice_ref' => '', 'order_currency' => $myorder['order_currency'], 'order_total_ht' => $order_total_ht, 'order_total_ttc' => $order_total_ttc, 'order_grand_total' => $order_total_ttc, 'order_shipping_cost' => number_format(0, 2, '.', ''), 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), 'order_items' => $items);
                     /* Update the order postmeta */
                     update_post_meta($o->ID, '_order_postmeta', $neworder);
                 }
             }
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 12:
             $query = "SELECT ID FROM " . $wpdb->users;
             $user_list = $wpdb->get_results($query);
             foreach ($user_list as $user) {
                 $user_first_name = get_user_meta($user->ID, 'first_name', true);
                 $user_last_name = get_user_meta($user->ID, 'last_name', true);
                 $shipping_info = get_user_meta($user->ID, 'shipping_info', true);
                 if ($user_first_name == '' && !empty($shipping_info['first_name'])) {
                     update_user_meta($user->ID, 'first_name', $shipping_info['first_name']);
                 }
                 if ($user_last_name == '' && !empty($shipping_info['last_name'])) {
                     update_user_meta($user->ID, 'last_name', $shipping_info['last_name']);
                 }
             }
             /*	Update orders structure into database	*/
             $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
             foreach ($orders_id as $o) {
                 $myorder = get_post_meta($o->ID, '_order_postmeta', true);
                 if (!empty($myorder)) {
                     $new_items = array();
                     foreach ($myorder['order_items'] as $item) {
                         $new_items = $item;
                         $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount';
                         // unset($new_items['item_discount_rate']);
                         $new_items['item_discount_value'] = 0;
                     }
                     $myorder['order_items'] = $new_items;
                     /* Update the order postmeta */
                     update_post_meta($o->ID, '_order_postmeta', $myorder);
                 }
             }
             /*	Delete useless database table	*/
             $query = "DROP TABLE " . WPSHOP_DBT_CART;
             $wpdb->query($query);
             $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS;
             $wpdb->query($query);
             return true;
             break;
         case 13:
             $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true);
             foreach ($attribute_used_for_sort_by as $attribute) {
                 $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
                 foreach ($data as $post) {
                     $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true);
                     if (!empty($postmeta[$attribute->code])) {
                         update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]);
                     }
                 }
                 wp_reset_query();
             }
             return true;
             break;
         case 17:
             $products = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes');
             $default_attribute_set = $wpdb->get_var($query);
             foreach ($products as $product) {
                 $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
                 if (empty($p_att_set_id)) {
                     /*	Update the attribute set id for the current product	*/
                     update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set);
                 }
                 wp_reset_query();
             }
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 18:
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 19:
             $wp_rewrite->flush_rules();
             return true;
             break;
         case 21:
             /**
              * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement
              */
             $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock');
             $manage_stock_option = $wpdb->get_results($query);
             if (!empty($manage_stock_option)) {
                 $no_is_present = false;
                 $attribute_id = $manage_stock_option[0]->attribute_id;
                 foreach ($manage_stock_option as $manage_definition) {
                     if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) {
                         $no_is_present = true;
                     }
                 }
                 if (!$no_is_present) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop')));
                 }
             }
             /** Change price attribute set section order for default set */
             $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES);
             unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]);
             $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')";
             $attribute_ids = $wpdb->get_var($query);
             $query = $wpdb->prepare("\nSELECT ATTR_DET.attribute_group_id\nFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTR_GROUP ON ((ATTR_GROUP.id = ATTR_DET.attribute_group_id) AND (ATTR_GROUP.code = %s))\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTR_SET ON ((ATTR_SET.id = ATTR_GROUP.attribute_set_id) AND (ATTR_SET.name = %s))\nWHERE ATTR_DET.attribute_id IN (" . $attribute_ids . ")", 'prices', __('default', 'wpshop'));
             $list = $wpdb->get_results($query);
             if (!empty($list)) {
                 $change_order = true;
                 $old_value = $list[0]->attribute_group_id;
                 unset($list[0]);
                 if (!empty($list)) {
                     foreach ($list as $data) {
                         if ($old_value != $data->attribute_group_id) {
                             $change_order = false;
                         }
                     }
                     if ($change_order) {
                         foreach ($price_tab as $price_code) {
                             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code);
                             $attribute_id = $wpdb->get_var($query);
                             switch ($price_code) {
                                 case WPSHOP_PRODUCT_PRICE_HT:
                                     $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 1 : 3;
                                     break;
                                 case WPSHOP_PRODUCT_PRICE_TAX:
                                     $position = 2;
                                     break;
                                 case WPSHOP_PRODUCT_PRICE_TTC:
                                     $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 3 : 1;
                                     break;
                                 case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT:
                                     $position = 4;
                                     break;
                             }
                             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id));
                         }
                     }
                 }
             }
             return true;
             break;
         case 22:
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             $product_entity_id = $wpdb->get_var($query);
             if (empty($product_entityd_id) || $product_entity_id <= 0 || !$product_entity_id) {
                 /*	Create the product entity into post table	*/
                 $product_entity = array('post_title' => __('Products', 'wpshop'), 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), 'post_status' => 'publish', 'post_author' => 1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
                 $product_entity_id = wp_insert_post($product_entity);
             }
             /*	Update eav table with the new entity id for product	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             /*	Create an element of customer entity for each existing user	*/
             $user_list = get_users();
             foreach ($user_list as $user) {
                 wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID);
             }
             return true;
             break;
         case 23:
             /*	Delete duplicate entities	*/
             $query = "SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' ";
             $product_entity_list = $wpdb->get_results($query);
             if (count($product_entity_list) > 1) {
                 $i = 0;
                 foreach ($product_entity_list as $product_entity) {
                     if ($i > 0) {
                         wp_delete_post($product_entity->ID);
                     }
                 }
             }
             return true;
             break;
         case 24:
             /*	Update the link status for disabled attribute set	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted');
             $deleted_attribute_group = $wpdb->get_results($query);
             if (!empty($deleted_attribute_group)) {
                 foreach ($deleted_attribute_group as $group) {
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id));
                 }
             }
             /*	Update entities meta management	*/
             $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES));
             if (!empty($entities)) {
                 foreach ($entities as $entity) {
                     $support = get_post_meta($entity->ID, '_wpshop_entity_support', true);
                     $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true);
                     update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite)));
                 }
             }
             wp_reset_query();
             return true;
             break;
         case 25:
             /*	Get the first entities of product and customer	*/
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
             $product_entity_id = $wpdb->get_var($query);
             /*	Update attributes that are not linked with entities	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0));
             /*	Get entities that have been created a lot of time and delete them	*/
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
             $entities_to_delete = $wpdb->get_results($query);
             if (!empty($entities_to_delete) && is_array($entities_to_delete)) {
                 foreach ($entities_to_delete as $entity) {
                     wp_delete_post($entity->ID, true);
                 }
             }
             /*	Get post list that are children of entities created a lot of time */
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%");
             $entities_to_update = $wpdb->get_results($query);
             if (!empty($entities_to_update) && is_array($entities_to_update)) {
                 foreach ($entities_to_update as $entity) {
                     wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS));
                 }
             }
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%");
             $entities_to_update = $wpdb->get_results($query);
             if (!empty($entities_to_update) && is_array($entities_to_update)) {
                 foreach ($entities_to_update as $entity) {
                     wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
                 }
             }
             /*	Change addons managament	*/
             $wpshop_addons_options = get_option('wpshop_addons_state', array());
             if (!empty($wpshop_addons_options)) {
                 foreach ($wpshop_addons_options as $addon_name => $addon_state) {
                     $options_args = array();
                     $options_args[$addon_name]['activate'] = $addon_state;
                     $options_args[$addon_name]['activation_date'] = current_time('mysql', 0);
                     if (!$addon_state) {
                         $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0);
                     }
                     add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args);
                 }
                 delete_option('wpshop_addons_state');
             }
             /*	Update the different entities id into attribute set details table	*/
             $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
             $wpdb->query($query);
             return true;
             break;
         case 26:
             $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' ";
             $results = $wpdb->get_results($query);
             foreach ($results as $result) {
                 $order_info = unserialize($result->meta_value);
                 update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']);
                 update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']);
                 update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']);
             }
             /*	Update the different entities id into attribute set details table	*/
             $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
             $wpdb->query($query);
             return true;
             break;
         case 29:
             $billing_title = __('Billing address', 'wpshop');
             $shipping_title = __('Shipping address', 'wpshop');
             //UPDATE USERS ADDRESSES
             $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"';
             $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"';
             $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query);
             $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query);
             //Add Address & Google Map API KEY options
             add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes');
             add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes');
             add_option('wpshop_google_map_api_key', '', '', 'yes');
             $query = 'SELECT * FROM ' . $wpdb->users . '';
             $results = $wpdb->get_results($query);
             foreach ($results as $result) {
                 $billing_infos = get_user_meta($result->ID, 'billing_info', true);
                 $shipping_infos = get_user_meta($result->ID, 'shipping_info', true);
                 if (!empty($billing_infos)) {
                     //Save Billing Infos
                     $billing_address = array();
                     if (!empty($billing_infos['civility'])) {
                         switch ($billing_infos['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', 'civility' => $civility);
                     //Create the post and post_meta for the billing address
                     $post_address = array('post_author' => $result->ID, 'post_title' => $billing_title, 'post_status' => 'publish', 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => $result->ID);
                     $post_address_id = wp_insert_post($post_address);
                     //Create the post_meta with the address infos
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address);
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id);
                 }
                 if (!empty($shipping_infos)) {
                     //Save Shipping Infos
                     if (!empty($shipping_infos['civility'])) {
                         switch ($shipping_infos['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $shipping_address = array();
                     $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', 'civility' => $civility);
                     //Create the post and post_meta for the billing address
                     $post_address = array('post_author' => $result->ID, 'post_title' => $shipping_title, 'post_status' => 'publish', 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => $result->ID);
                     $post_address_id = wp_insert_post($post_address);
                     //Create the post_meta with the address infos
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address);
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id);
                 }
             }
             // FORMATE THE ORDER ADDRESSES INFOS
             $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
             foreach ($results as $result) {
                 $address = get_post_meta($result->ID, '_order_info', true);
                 $billing_address = array();
                 if (!empty($address['billing'])) {
                     if (!empty($address['billing']['civility'])) {
                         switch ($address['billing']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                             default:
                                 $civility = $mister_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', 'civility' => $civility);
                 }
                 $shipping_address = array();
                 if (!empty($address['shipping'])) {
                     if (!empty($address['shipping']['civility'])) {
                         switch ($address['shipping']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', 'civility' => $civility);
                 }
                 $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address);
                 $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address);
                 $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content);
                 //Update the post meta
                 update_post_meta($result->ID, '_order_info', $array_new_format);
             }
             /*	Update entities meta management	*/
             $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1));
             if (!empty($entities)) {
                 foreach ($entities as $entity) {
                     $params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
                     $support = !empty($params['support']) ? $params['support'] : '';
                     $rewrite = !empty($params['rewrite']) ? $params['rewrite'] : '';
                     $display_admin_menu = 'on';
                     update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu));
                 }
             }
             wp_reset_query();
             // Default Weight unity and Currency Options
             add_option('wpshop_shop_weight_group', 3, '', 'yes');
             add_option('wpshop_shop_default_weight_unity', 6, '', 'yes');
             add_option('wpshop_shop_currency_group', 4, '', 'yes');
             $default_currency = get_option('wpshop_shop_default_currency');
             foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
                 if ($default_currency == $k) {
                     $symbol = $v;
                 }
             }
             if (!empty($symbol)) {
                 $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"';
                 $currency = $wpdb->get_row($query);
                 if (!empty($currency)) {
                     update_option('wpshop_shop_default_currency', $currency->id);
                     // Update the change rate of the default currency
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
                 }
             }
             // Update the field for variation and user definition field
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes'));
             // Update field type for frontend output selection
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array());
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select'));
             add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page')));
             return true;
             break;
         case '30':
             /**	Update the current price piloting field for using it into variation specific attributes	*/
             $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute));
             /**	Update the product reference field for using it into variation specific attributes	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference'));
             /**	Insert new message for admin when a customer make an order	*/
             $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
             if (empty($admin_new_order_message)) {
                 wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
             }
             /**	Update all amount for paypal orders	*/
             $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal');
             $paypal_payment_list = $wpdb->get_results($query);
             if (!empty($paypal_payment_list)) {
                 foreach ($paypal_payment_list as $post) {
                     $order_meta = get_post_meta($post->post_id, '_order_postmeta', true);
                     $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true);
                     if (!empty($order_meta['order_status']) && $order_meta['order_status'] == 'incorrect_amount') {
                         if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) {
                             $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5);
                             $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5);
                             if ($order_amount_payed == $order_amount_to_pay) {
                                 wpshop_payment::setOrderPaymentStatus($order_id, 'completed');
                             }
                         }
                     }
                 }
             }
             /**	Save existing orders address information	*/
             $billing_title = __('Billing address', 'wpshop');
             $shipping_title = __('Shipping address', 'wpshop');
             $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
             foreach ($results as $result) {
                 $address = get_post_meta($result->ID, '_order_info', true);
                 $address_format = array();
                 $billing_address = array();
                 if (!empty($address['billing']) && empty($address['billing']['id'])) {
                     if (!empty($address['billing']['civility'])) {
                         switch ($address['billing']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                             default:
                                 $civility = $mister_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', 'civility' => $civility);
                     $billing_address_option = get_option('wpshop_billing_address');
                     $address_format['billing']['id'] = $billing_address_option['choice'];
                     $address_format['billing']['address'] = $shipping_address;
                 }
                 $shipping_address = array();
                 if (!empty($address['shipping']) && empty($address['shipping']['id'])) {
                     if (!empty($address['shipping']['civility'])) {
                         switch ($address['shipping']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', 'civility' => $civility);
                     $shipping_address_options = get_option('wpshop_shipping_address_choice');
                     $address_format['shipping']['id'] = $shipping_address_options['choice'];
                     $address_format['shipping']['address'] = $shipping_address;
                 }
                 if (!empty($address_format)) {
                     update_post_meta($result->ID, '_order_info', $address_format);
                 }
             }
             /**	Delete username from frontend form	*/
             $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code');
             if (!empty($attribute_login)) {
                 $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id));
             }
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted'));
             return true;
             break;
         case '31':
             /**	Change order structure in order to support several payment	*/
             $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish')));
             if (!empty($existing_orders)) {
                 foreach ($existing_orders as $order_main_informations) {
                     /**	Transfer payment return data form old meta to new	*/
                     $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true);
                     update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data);
                     delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data');
                     /**	Transfer old payment storage method to new storage method	*/
                     $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true);
                     if (!empty($order_meta['order_status'])) {
                         $order_meta['order_payment']['customer_choice'] = array('method' => !empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : ''));
                         unset($order_meta['payment_method']);
                         $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0;
                         $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method'];
                         $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date'];
                         $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment';
                         $order_meta['order_payment']['received'][0]['comment'] = '';
                         $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
                         if (in_array($order_meta['order_status'], array('completed', 'shipped'))) {
                             $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total'];
                             $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID);
                             $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date'];
                             $order_meta['order_payment']['received'][0]['status'] = 'payment_received';
                             $order_meta['order_payment']['received'][0]['comment'] = '';
                             $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
                             $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref'];
                         }
                         update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta);
                         if (!empty($order_meta['order_payment']['customer_choice'])) {
                             switch ($order_meta['order_payment']['customer_choice']) {
                                 case 'check':
                                     delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true));
                                     break;
                                 case 'paypal':
                                     delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true));
                                     break;
                                 case 'cic':
                                     delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true));
                                     break;
                             }
                         }
                     }
                 }
             }
             $wps_messages = new wps_message_ctr();
             $wps_messages->wpshop_messages_historic_correction();
             wp_reset_query();
             $default_currency = get_option('wpshop_shop_default_currency');
             foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
                 if ($default_currency == $k) {
                     $symbol = $v;
                 }
             }
             if (!empty($symbol)) {
                 $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', '');
                 $currency = $wpdb->get_row($query);
                 if (!empty($currency)) {
                     update_option('wpshop_shop_default_currency', $currency->id);
                     // Update the change rate of the default currency
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
                 }
             }
             $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE');
             if (!empty($shipping_confirmation_message)) {
                 $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop');
                 $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message);
                 wp_update_post($post);
             }
             return true;
             break;
         case '32':
             /**	Update product set id that are null 	*/
             $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id');
             $wpdb->query($query);
             $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME);
             if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) {
                 $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
                 if (empty($admin_new_quotation_message)) {
                     wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
                 }
                 $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
                 if (empty($admin_new_quotation_confirm_message)) {
                     wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
                 }
             }
             /**	Allows the administrator to manage a little bit more the catalog rewrite parameters	*/
             $options = get_option('wpshop_catalog_product_option');
             $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category'];
             update_option('wpshop_catalog_product_option', $options);
             /**	Create a new page for unsuccessfull payment return	*/
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             /**	Update the iso code of currencies	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar'));
             /** Update VAT Rate*/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva');
             $attribute_ids = $wpdb->get_results($query);
             foreach ($attribute_ids as $attribute_id) {
                 $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id);
                 $wpdb->query($query);
             }
             return true;
             break;
         case '33':
             /** Update the user_mail for the new system of log in/register */
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"');
             /** Put discount attributes in price attribute set section*/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
             $prices_section_id = $wpdb->get_var($query);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount');
             $attributes = $wpdb->get_results($query);
             if (!empty($attributes) && !empty($prices_section_id)) {
                 foreach ($attributes as $attribute) {
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id);
                 }
             }
             return true;
             break;
         case '34':
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
             $prices_section_id = $wpdb->get_var($query);
             $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id);
             $last_position_id = $wpdb->get_var($query);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE  attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id);
             $attribute_example = $wpdb->get_row($query);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to');
             $attributes = $wpdb->get_results($query);
             $i = 1;
             if (!empty($attributes) && !empty($prices_section_id)) {
                 foreach ($attributes as $attribute) {
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id));
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i));
                     $i++;
                 }
             }
             $discount_options = get_option('wpshop_catalog_product_option');
             $status = !empty($discount_options) && !empty($discount_options['discount']) ? 'valid' : 'notused';
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to'));
             return true;
             break;
         case '35':
             $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS));
             return true;
             break;
         case '36':
             wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
             @set_time_limit(900);
             /** Change the path for old categories pictures */
             @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755);
             $query = 'SELECT * FROM ' . $wpdb->terms;
             $terms = $wpdb->get_results($query);
             if (!empty($terms)) {
                 foreach ($terms as $term) {
                     @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755);
                     /** Check if a picture exists **/
                     $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id);
                     if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) {
                         $wp_upload_dir = wp_upload_dir();
                         $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'];
                         $img_basename = basename($img_path);
                         $wp_filetype = wp_check_filetype($img_basename, null);
                         /** Check if there is an image with the same name, if yes we add a rand number to image's name **/
                         $rand_name = is_file($wp_upload_dir['path'] . '/' . $img_basename) ? rand() : '';
                         $img_basename = !empty($rand_name) ? $rand_name . '_' . $img_basename : $img_basename;
                         if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
                             $attachment = array('guid' => $wp_upload_dir['url'] . '/' . $img_basename, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $img_basename), 'post_content' => '', 'post_status' => 'inherit');
                             $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
                             /** Generate differnts sizes for this image **/
                             require_once ABSPATH . 'wp-admin/includes/image.php';
                             $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
                             wp_update_attachment_metadata($attach_id, $attach_data);
                             /** Update option picture **/
                             $term_option['wpshop_category_picture'] = $attach_id;
                             update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option);
                         }
                     }
                 }
             }
             /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
             $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus');
             $meta_keys = $wpdb->get_results($query);
             if (!empty($meta_keys) && is_array($meta_keys)) {
                 foreach ($meta_keys as $meta_key) {
                     $user_id = $meta_key->user_id;
                     $meta_value = unserialize($meta_key->meta_value);
                     if (!empty($meta_value) && is_array($meta_value)) {
                         $data_to_delete = array_search('add-wpshop_product_category', $meta_value);
                         if ($data_to_delete !== false) {
                             unset($meta_value[$data_to_delete]);
                         }
                     }
                     update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value);
                 }
             }
             return true;
             break;
         case '37':
             @set_time_limit(900);
             /** Change the path for old categories pictures */
             @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755);
             /** Read all categories folders **/
             $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category';
             if (file_exists($categories_main_dir)) {
                 $main_folder_content = scandir($categories_main_dir);
                 /** For each category folder **/
                 foreach ($main_folder_content as $category_folder) {
                     if ($category_folder && substr($category_folder, 0, 1) != '.') {
                         $category_id = $category_folder;
                         @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755);
                         $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder);
                         /** For each Picture of category **/
                         $file_time = 0;
                         $save_this_picture = false;
                         while (false !== ($fichier = readdir($scan_category_folder))) {
                             if ($fichier && substr($fichier, 0, 1) != '.') {
                                 if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) {
                                     $save_this_picture = true;
                                     $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier);
                                 }
                                 /** Select category option **/
                                 $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id);
                                 $wp_upload_dir = wp_upload_dir();
                                 $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier;
                                 $img_basename = basename($img_path);
                                 $wp_filetype = wp_check_filetype($img_basename, null);
                                 /** Check if there is an image with the same name, if yes we add a rand number to image's name **/
                                 $rand_name = is_file($wp_upload_dir['path'] . '/' . $img_basename) ? rand() : '';
                                 $img_basename = !empty($rand_name) ? $rand_name . '_' . $img_basename : $img_basename;
                                 if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
                                     $attachment = array('guid' => $wp_upload_dir['url'] . '/' . $img_basename, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $img_basename), 'post_content' => '', 'post_status' => 'inherit');
                                     $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
                                     /** Generate differnts sizes for this image **/
                                     require_once ABSPATH . 'wp-admin/includes/image.php';
                                     $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
                                     wp_update_attachment_metadata($attach_id, $attach_data);
                                     /** Update option picture **/
                                     $term_option['wpshop_category_picture'] = $attach_id;
                                     if ($save_this_picture) {
                                         update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option);
                                     }
                                     $save_this_picture = false;
                                 }
                             }
                         }
                     }
                 }
             }
             return true;
             break;
         case '38':
             wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE');
             return true;
             break;
         case '39':
             $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
             /** Check if the 7% VAT Rate is not already created **/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7');
             $exist_vat_rate = $wpdb->get_results($query);
             if (empty($exist_vat_rate)) {
                 /** Get Max Position **/
                 $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
                 $max_position = $wpdb->get_var($query);
                 if (!empty($attribute_def) && !empty($attribute_def->id)) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7'));
                 }
             }
             /** Filter Search optimization **/
             @set_time_limit(900);
             $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
             $categories = $wpdb->get_results($query);
             $cats = array();
             if (!empty($categories)) {
                 foreach ($categories as $category) {
                     $cats[] = $category->term_id;
                 }
                 $wpshop_filter_search = new wps_filter_search();
                 $wpshop_filter_search->stock_values_for_attribute($cats);
             }
             return true;
             break;
         case '40':
             /**	Store watt in puissance unit group	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop'));
             $puissance_unit_group_id = $wpdb->get_var($query);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt'));
             /**	Store day/week/year in duration unit group	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop'));
             $duration_unit_group_id = $wpdb->get_var($query);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year'));
             /**	Store day/week/year in duration unit group	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop'));
             $length_unit_group_id = $wpdb->get_var($query);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm'));
             return true;
             break;
         case '41':
             /**	Get distinct attribute set and delete doublons	*/
             $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1";
             $list_of_set = $wpdb->get_results($query);
             foreach ($list_of_set as $set_infos) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET);
             /**	Get and delete attribute set section	*/
             $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )";
             $wpdb->query($query);
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP);
             /**	Get and delete attribute set details	*/
             $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
             $wpdb->query($query);
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
             $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
             $affectation_list = $wpdb->get_results($query);
             foreach ($affectation_list as $affectation_to_treat) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
             /**	Get and delete double unit	*/
             $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1";
             $list_of_set = $wpdb->get_results($query);
             foreach ($list_of_set as $set_infos) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT);
             $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1";
             $list_of_set = $wpdb->get_results($query);
             foreach ($list_of_set as $set_infos) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
             /**	Get and delete attribute set details	*/
             $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
             $wpdb->query($query);
             $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
             $affectation_list = $wpdb->get_results($query);
             foreach ($affectation_list as $list) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, '');
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
             return true;
             break;
         case '42':
             $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
             if (empty($available_downloadable_product)) {
                 wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
             }
             return true;
             break;
         case '43':
             $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED');
             if (empty($available_downloadable_product)) {
                 wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED');
             }
             return true;
             break;
         case '44':
             $display_option = get_option('wpshop_display_option');
             if (!empty($display_option) && empty($display_option['latest_products_ordered'])) {
                 $display_option['latest_products_ordered'] = 3;
                 update_option('wpshop_display_option', $display_option);
             }
             /** Check messages for customization **/
             $messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED);
             if (!empty($messages)) {
                 foreach ($messages as $key => $message) {
                     $message_option = get_option($key);
                     if (!empty($message_option)) {
                         $post_message = get_post($message_option);
                         $original_message = !empty($post_message) && !empty($post_message->post_content) ? $post_message->post_content : '';
                         $tags = array('<p>', '</p>');
                         if (str_replace($tags, '', $original_message) == str_replace($tags, '', __($message, 'wpshop'))) {
                             wp_update_post(array('ID' => $message_option, 'post_content' => wps_message_ctr::customize_message($original_message)));
                         }
                     }
                 }
             }
             return true;
             break;
         case '45':
             $shipping_mode_ctr = new wps_shipping_mode_ctr();
             $shipping_mode_ctr->migrate_default_shipping_mode();
             return true;
             break;
         case '46':
             wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE');
             wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE);
             return true;
             break;
         case '47':
             wps_payment_mode::migrate_payment_modes();
             return true;
             break;
         case '48':
             @ini_set('max_execution_time', '500');
             $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             $output_type_option = get_option('wpshop_display_option');
             $output_type = $output_type_option['wpshop_display_list_type'];
             for ($i = 0; $i <= $count_products->publish; $i += 20) {
                 $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
                 $products = $wpdb->get_results($query);
                 if (!empty($products)) {
                     foreach ($products as $product) {
                         $p = wpshop_products::get_product_data($product->ID);
                         $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
                         update_post_meta($product->ID, '_wps_price_infos', $price);
                     }
                 }
             }
             return true;
             break;
         case '49':
             update_option('wpshop_send_invoice', true);
             return true;
             break;
         case '50':
             $price_display_option = get_option('wpshop_catalog_product_option');
             $price_display_option['price_display']['text_from'] = 'on';
             $price_display_option['price_display']['lower_price'] = 'on';
             update_option('wpshop_catalog_product_option', $price_display_option);
             self::wpshop_insert_default_pages();
             return true;
             break;
         case '51':
             /**	Insert new message for direct payment link	*/
             $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
             if (empty($direct_payment_link_message)) {
                 wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
             }
             return true;
             break;
         case '52':
             $account_page_option = get_option('wpshop_myaccount_page_id');
             if (!empty($account_page_option)) {
                 $page_account = get_post($account_page_option);
                 $page_content = !empty($page_account) && !empty($page_account->post_content) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]';
                 wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content));
             }
             return true;
             break;
         case '53':
             $payment_modes_option = get_option('wps_payment_mode');
             if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) {
                 $payment_modes_option['mode']['cash_on_delivery'] = array('name' => __('Cash on delivery', 'wpshop'), 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', 'description' => __('Pay your order on delivery', 'wpshop'));
                 update_option('wps_payment_mode', $payment_modes_option);
             }
             // Mass action on products to add a flag on variation definition
             $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
             if (!empty($products)) {
                 foreach ($products as $p) {
                     $post_id = $p->ID;
                     $check_product_have_variations = wpshop_products::get_variation($post_id);
                     if (!empty($check_product_have_variations)) {
                         $variation_flag = wpshop_products::check_variation_type($post_id);
                         $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
                         $variation_defining['variation_type'] = $variation_flag;
                         update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
                     }
                 }
             }
             return true;
             break;
         case '54':
             // Change shortcode of sign up page
             $signup_page_id = get_option('wpshop_signup_page_id');
             if (!empty($signup_page_id)) {
                 $signup_page = get_post($signup_page_id);
                 $signup_page_content = !empty($signup_page) && !empty($signup_page->post_content) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]';
                 wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content));
             }
             // Change Terms of sale default content
             $terms_page_id = get_option('wpshop_terms_of_sale_page_id');
             if (!empty($terms_page_id)) {
                 $terms_sale_page = get_post($terms_page_id);
                 if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') {
                     $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>';
                     $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>';
                     $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
                     $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>';
                     $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
                     $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>';
                     $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
                     $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>';
                     $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name'));
                     wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data));
                 }
             }
             return true;
             break;
         case '55':
             $checkout_page_id = get_option('wpshop_checkout_page_id');
             $checkout_page = get_post($checkout_page_id);
             $checkout_page_content = !empty($checkout_page) && !empty($checkout_page->post_content) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]';
             wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content));
             // Update cart page id
             update_option('wpshop_cart_page_id', $checkout_page_id);
             return true;
             break;
         case '56':
             $wps_entities = new wpshop_entities();
             $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id);
             $set = $wpdb->get_row($query);
             if (!empty($set)) {
                 $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('default_set' => 'yes'), array('id' => $set->id));
             }
             // Update Opinions activation option
             update_option('wps_opinion', array('active' => 'on'));
             return true;
             break;
         case '57':
             $wpshop_cart_option = get_option('wpshop_cart_option');
             $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes';
             $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes';
             update_option('wpshop_cart_option', $wpshop_cart_option);
             return true;
             break;
         case '58':
             /** Turn customers publish into draft **/
             $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
             $wpdb->query($query);
             $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
             /** Check if the 0% VAT Rate is not already created **/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0');
             $exist_vat_rate = $wpdb->get_results($query);
             if (empty($exist_vat_rate)) {
                 /** Get Max Position **/
                 $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
                 $max_position = $wpdb->get_var($query);
                 if (!empty($attribute_def) && !empty($attribute_def->id)) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0'));
                 }
             }
             return true;
             break;
         case '59':
             /** Move old images gallery to the new gallery, and remove old links **/
             $allowed = get_allowed_mime_types();
             $args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => array('publish', 'draft', 'trash'));
             $posts = get_posts($args);
             $result = array();
             foreach ($posts as $post) {
                 $array = array();
                 $array['Post'] = $post;
                 $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true);
                 $array['Attachments'] = get_attached_media($allowed, $post->ID);
                 $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true);
                 if (!empty($array['TrueAttachmentsString'])) {
                     $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']);
                 }
                 $array['OldAttachmentsString'] = '';
                 foreach ($array['Attachments'] as $attachment) {
                     $filename = basename(get_attached_file($attachment->ID));
                     $pos_ext = strrpos($filename, '.');
                     $filename_no_ext = substr($filename, 0, $pos_ext);
                     if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !preg_match('#' . $filename_no_ext . '#', $post->post_content) && (empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID'])) {
                         $array['OldAttachmentsString'] .= $attachment->ID . ',';
                     }
                 }
                 unset($TrueAttachments_id);
                 $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString'];
                 update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]);
             }
             return true;
             break;
         case '60':
             /* Create default emails */
             wps_message_ctr::create_default_message();
             /** Update entries for quick add */
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"');
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"');
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"');
             switch (WPSHOP_PRODUCT_PRICE_PILOT) {
                 case 'HT':
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"');
                     break;
                 default:
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"');
                     break;
             }
             /* Default country with WP language */
             $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice');
             if (empty($wpshop_country_default_choice_option)) {
                 update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3));
             }
             return true;
             break;
         case '61':
             /** Import the xml for guided tour */
             wpsBubble_ctr::import_xml();
             /* Hide admin bar */
             $wpshop_display_option = get_option('wpshop_display_option');
             if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) {
                 $wpshop_display_option['wpshop_hide_admin_bar'] = 'on';
                 update_option('wpshop_display_option', $wpshop_display_option);
             }
             return true;
             break;
         case '62':
             /** Install user default for POS */
             wps_pos_addon::action_to_do_on_activation();
             return true;
             break;
         case '63':
             $data = get_option('wps_shipping_mode');
             if (empty($data['modes']['default_shipping_mode_for_pos'])) {
                 $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop');
                 $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop');
                 update_option('wps_shipping_mode', $data);
             }
             return true;
             break;
         case '64':
             $options = get_option('wpshop_catalog_product_option');
             if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
                 unset($options['wpshop_catalog_product_slug_with_category']);
                 update_option('wpshop_catalog_product_option', $options);
             }
             return true;
             break;
             /*	Always add specific case before this bloc	*/
         /*	Always add specific case before this bloc	*/
         case 'dev':
             wp_cache_flush();
             // Newsletters options
             $wp_rewrite->flush_rules();
             return true;
             break;
         default:
             return true;
             break;
     }
 }
Пример #22
0
 /**
  * Create a new element for a entity type into database
  * @param string $entity_type The type of element to create
  * @param string $name The element name to create
  * @param string $description A description for the element to create
  * @param array $attributes A list containing all attributes defining the element to create
  * @param array $extra_params A list of extra parameters for the element creation
  * @return array The new entity identifier AND the status of attribute save with a messaege in case the save action failed
  */
 public static function create_new_entity($entity_type, $name, $description, $attributes = array(), $extra_params = array())
 {
     global $wpdb;
     /** Check if user is already connected	*/
     $user_id = function_exists('is_user_logged_in') && is_user_logged_in() ? get_current_user_id() : 'NaN';
     /** The arguments needed for a entity (post) creation	*/
     $entity_args = array('post_type' => $entity_type, 'post_title' => $name, 'post_status' => 'publish', 'post_excerpt' => $description, 'post_content' => $description, 'post_author' => $user_id, 'comment_status' => 'closed');
     /** Add the new product	*/
     $entity_id = wp_insert_post($entity_args);
     do_action('wps_entity_more_action', $entity_id, $attributes);
     /** Update the attribute set id for the current product	*/
     if (!empty($extra_params['attribute_set_id'])) {
         $attribute_set_id = $extra_params['attribute_set_id'];
     } else {
         $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE status = %s AND entity_id = %d AND default_set = %s", 'valid', wpshop_entities::get_entity_identifier_from_code($entity_type), 'yes');
         $attribute_set_id = $wpdb->get_var($query);
     }
     update_post_meta($entity_id, '_' . $entity_type . '_attribute_set_id', $attribute_set_id);
     $response = wpshop_attributes::setAttributesValuesForItem($entity_id, $attributes, true);
     return array($response, $entity_id);
 }
Пример #23
0
        ?>
</label>
				<div id="<?php 
        echo $signup_field->code;
        ?>
" class="wps-form"><?php 
        echo $attribute_output_def['output'];
        echo $attribute_output_def['options'];
        ?>
</div>
			</div>
		<?php 
        /** Check confirmation field **/
        if ($signup_field->_need_verification == 'yes') {
            $signup_field->code = $signup_field->code . '2';
            $attribute_output_def = wpshop_attributes::get_attribute_field_definition($signup_field, $value, array('from' => 'frontend'));
            ?>
				<div class="wps-form-group">
					<label for="<?php 
            echo $signup_field->code;
            ?>
"><?php 
            printf(__('Confirm %s', 'wpshop'), stripslashes(strtolower(__($signup_field->frontend_label, 'wpshop'))));
            ?>
 <?php 
            echo !empty($attribute_output_def['required']) && $attribute_output_def['required'] == 'yes' ? '<em>*</em>' : '';
            ?>
</label>
					<div id="<?php 
            echo $signup_field->code;
            ?>
 function shipping_to_billing($shipping_address_type_id, $billing_address_type_id)
 {
     global $wpdb;
     $tmp_array = array();
     $tmp_array = !empty($_POST) ? $_POST : $_REQUEST;
     $billing_fields = array();
     if (!empty($tmp_array) && !empty($tmp_array['attribute']) && !empty($tmp_array['attribute'][$shipping_address_type_id])) {
         foreach ($tmp_array['attribute'][$shipping_address_type_id] as $key => $attribute_group) {
             if (is_array($attribute_group)) {
                 foreach ($attribute_group as $field_name => $value) {
                     $attribute_def = wpshop_attributes::getElement($field_name, "'valid'", 'code');
                     if (!empty($attribute_def)) {
                         $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE status = %s AND attribute_id = %d AND attribute_set_id = %s', 'valid', $attribute_def->id, $billing_address_type_id);
                         $attribute_exist = $wpdb->get_var($query);
                         if (!empty($attribute_exist)) {
                             $tmp_array['attribute'][$billing_address_type_id][$attribute_def->data_type][$field_name] = $value;
                         }
                     }
                 }
             }
         }
         $_POST = $tmp_array;
     }
 }
Пример #25
0
 /**
  *	Add additionnal fields to the category edition form
  */
 public static function category_edit_fields()
 {
     $category_id = wpshop_tools::varSanitizer($_REQUEST["tag_ID"]);
     $category_meta_information = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id);
     $tpl_component = array();
     $category_thumbnail_preview = '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail_preview" />';
     /*	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_preview'));
         $category_thumbnail_preview = !empty($image_post) ? $image_post : '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail_preview" />';
     }
     $tpl_component['CATEGORY_DELETE_PICTURE_BUTTON'] = '';
     if (!empty($category_meta_information) && !empty($category_meta_information['wpshop_category_picture'])) {
         $tpl_component['CATEGORY_DELETE_PICTURE_BUTTON'] = '<a href="#" role="button" id="wps-delete-category-picture" class="wps-bton-second-mini-rounded">' . __('Delete the category picture', 'wpshop') . '</a> ';
     }
     $tpl_component['CATEGORY_PICTURE_ID'] = !empty($category_meta_information['wpshop_category_picture']) ? $category_meta_information['wpshop_category_picture'] : '';
     $tpl_component['CATEGORY_THUMBNAIL_PREVIEW'] = $category_thumbnail_preview;
     if (isset($_GET['tag_ID'])) {
         $tpl_component['CATEGORY_TAG_ID'] = $_GET['tag_ID'];
         $tpl_component['CATEGORY_FILTERABLE_ATTRIBUTES'] = '';
         $wpshop_category_products = wpshop_categories::get_product_of_category($_GET['tag_ID']);
         $filterable_attributes_list = array();
         foreach ($wpshop_category_products as $wpshop_category_product) {
             $elementId = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             if (!empty($elementId)) {
                 $product_attributes = wpshop_attributes::get_attribute_list_for_item($elementId, $wpshop_category_product);
                 if (!empty($product_attributes)) {
                     foreach ($product_attributes as $key => $product_attribute) {
                         if (!empty($product_attribute) && !empty($product_attribute->is_filterable) && strtolower(__($product_attribute->is_filterable, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
                             if (!array_key_exists($product_attribute->attribute_id, $filterable_attributes_list)) {
                                 $filterable_attributes_list[$product_attribute->attribute_id] = $product_attribute;
                                 $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_ID'] = $product_attribute->attribute_id;
                                 $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_NAME'] = __($product_attribute->frontend_label, 'wpshop');
                                 if (!empty($category_meta_information) && !empty($category_meta_information['wpshop_category_filterable_attributes']) && array_key_exists($product_attribute->attribute_id, $category_meta_information['wpshop_category_filterable_attributes'])) {
                                     $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_CHECKED'] = 'checked="checked"';
                                 } else {
                                     $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_CHECKED'] = '';
                                 }
                                 $tpl_component['CATEGORY_FILTERABLE_ATTRIBUTES'] .= wpshop_display::display_template_element('wpshop_category_filterable_attribute_element', $sub_tpl_component, array(), 'admin');
                                 unset($sub_tpl_component);
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $tpl_component['CATEGORY_TAG_ID'] = 1;
     }
     $output = wpshop_display::display_template_element('wpshop_category_edit_interface_admin', $tpl_component, array(), 'admin');
     echo $output;
 }
	<input type="hidden" name="wps-customer-account-set-id" value="wps-customer-quick-add" />

	<?php 
if (!empty($customer_attributes)) {
    ?>
		<?php 
    foreach ($customer_attributes as $customer_attribute_group) {
        ?>
	<div class="wps-boxed">
		<span class="wps-h5"><?php 
        echo stripslashes($customer_attribute_group['name']);
        ?>
</span>
<?php 
        foreach ($customer_attribute_group['attribut'] as $attribute) {
            $output = wpshop_attributes::display_attribute($attribute->code);
            echo $output['field'];
        }
        ?>
	</div>
		<?php 
    }
    ?>
	<?php 
}
?>

	<button class="wps-bton-first-mini-rounded alignRight" ><?php 
_e('Add customer', 'wpshop');
?>
</button>
Пример #27
0
 if (!empty($order)) {
     $download_codes = get_user_meta($user_id, '_order_download_codes_' . $_GET['oid'], true);
     if (!empty($download_codes) && is_array($download_codes)) {
         foreach ($download_codes as $downloadable_product_id => $d) {
             $is_encrypted = false;
             if ($d['download_code'] == $_GET['download']) {
                 wpshop_tools::create_custom_hook('encrypt_actions_for_downloadable_product', array('order_id' => $_GET['oid'], 'download_product_id' => $downloadable_product_id));
                 if (get_post_type($downloadable_product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                     $parent_def = wpshop_products::get_parent_variation($downloadable_product_id);
                     if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                         $parent_post = $parent_def['parent_post'];
                         $variation_id = $downloadable_product_id;
                         $downloadable_product_id = $parent_post->ID;
                     }
                 }
                 $link = wpshop_attributes::get_attribute_option_output(array('item_id' => $downloadable_product_id, 'item_is_downloadable_' => 'yes'), 'is_downloadable_', 'file_url', $order);
                 if ($link !== false) {
                     $uploads = wp_upload_dir();
                     $basedir = $uploads['basedir'];
                     $pos = strpos($link, 'uploads');
                     $link = $basedir . substr($link, $pos + 7);
                     /** If plugin is encrypted **/
                     $encrypted_plugin_path = get_post_meta($_GET['oid'], '_download_file_path_' . $_GET['oid'] . '_' . (!empty($variation_id) && get_post_type($variation_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ? $variation_id : $downloadable_product_id), true);
                     if (!empty($encrypted_plugin_path)) {
                         $link = WPSHOP_UPLOAD_DIR . $encrypted_plugin_path;
                         $is_encrypted = true;
                     }
                     wpshop_tools::forceDownload($link, $is_encrypted);
                 }
             }
         }
 /**
  * Action to do when the activation code is OK
  */
 function action_to_do_to_activate()
 {
     global $wpdb;
     /** Activate the plug in **/
     $addon_option = get_option('wpshop_addons');
     $addon_option['WPSHOP_ADDONS_QUOTATION']['activate'] = true;
     $addon_option['WPSHOP_ADDONS_QUOTATION']['activation_date'] = current_time('mysql', 0);
     update_option('wpshop_addons', $addon_option);
     /** Activate the Quotation attribute **/
     $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('status' => 'valid'), array('code' => 'quotation_allowed'));
     $attribute_def = wpshop_attributes::getElement('quotation_allowed', '"valid"', 'code');
     /** Add the attribute in attributes groups section **/
     $query = $wpdb->prepare('SELECT id, attribute_set_id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'general');
     $attribute_set_sections = $wpdb->get_results($query);
     if (!empty($attribute_set_sections)) {
         $entity_type_def = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
         if (!empty($entity_type_def)) {
             foreach ($attribute_set_sections as $attribute_set_section) {
                 $query = $wpdb->prepare('SELECT COUNT(*) AS count_attribute_affectation FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d', $entity_type_def, $attribute_set_section->attribute_set_id, $attribute_set_section->id, $attribute_def->id);
                 $count_attribute_affectation = $wpdb->get_var($query);
                 if ($count_attribute_affectation == 0) {
                     $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_type_def, $attribute_set_section->attribute_set_id, $attribute_set_section->id);
                     $max_position = $wpdb->get_var($query);
                     /** Insert attribute detail **/
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_type_def, 'attribute_set_id' => $attribute_set_section->attribute_set_id, 'attribute_group_id' => $attribute_set_section->id, 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1));
                 }
             }
         }
     }
 }
Пример #29
-1
 /**
  * ACCOUNT - Save account informations
  */
 function wps_save_account_informations()
 {
     global $wpdb;
     global $wpshop;
     $status = false;
     $response = '';
     $exclude_user_meta = array('user_email', 'user_pass');
     $wps_entities = new wpshop_entities();
     $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
     $user_id = get_current_user_id();
     if (!empty($element_id) && !empty($user_id)) {
         $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
         $cid = $wpdb->get_var($query);
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
         $attribute_set_id = $wpdb->get_var($query);
         if (!empty($attribute_set_id)) {
             $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
             foreach ($group as $attribute_sets) {
                 foreach ($attribute_sets as $attribute_set_field) {
                     $validate = $wpshop->validateForm($attribute_set_field['content'], $_POST['attribute']);
                     if (empty($wpshop->errors)) {
                         $user_name = !empty($_POST['attribute']['varchar']['user_login']) ? $_POST['attribute']['varchar']['user_login'] : $_POST['attribute']['varchar']['user_email'];
                         $user_pass = !empty($_POST['attribute']['varchar']['user_pass']) ? $_POST['attribute']['varchar']['user_pass'] : '';
                         $wpshop_attributes = new wpshop_attributes();
                         foreach ($attribute_set_field['content'] as $attribute) {
                             $attribute_def = wpshop_attributes::getElement($attribute['name'], "'valid'", 'code');
                             if (!in_array($attribute['name'], $exclude_user_meta)) {
                                 update_user_meta($user_id, $attribute['name'], wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']]));
                             } else {
                                 wp_update_user(array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])));
                             }
                             //Save data in attribute tables, ckeck first if exist to know if Insert or Update
                             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $cid, $attribute_def->id);
                             $checking_attribute_exist = $wpdb->get_results($query);
                             if (!empty($checking_attribute_exist)) {
                                 $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']), array('value' => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])), array('entity_type_id' => $element_id, 'entity_id' => $cid, 'attribute_id' => $attribute_def->id));
                             } else {
                                 $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']), array('entity_type_id' => $element_id, 'attribute_id' => $attribute_def->id, 'entity_id' => $cid, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])));
                             }
                         }
                         /** Update newsletter user preferences **/
                         $newsletter_preferences = array();
                         if (!empty($_POST['newsletters_site'])) {
                             $newsletter_preferences['newsletters_site'] = 1;
                         }
                         if (!empty($_POST['newsletters_site_partners'])) {
                             $newsletter_preferences['newsletters_site_partners'] = 1;
                         }
                         update_user_meta($user_id, 'user_preferences', $newsletter_preferences);
                         $status = true;
                     } else {
                         $response = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>';
                         foreach ($wpshop->errors as $error) {
                             $response .= '<li>' . $error . '</li>';
                         }
                         $response .= '</div>';
                     }
                 }
             }
         }
     }
     echo json_encode(array('status' => $status, 'response' => $response));
     wp_die();
 }
Пример #30
-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;
 }