Mian Waqas Posted April 27, 2020 Share Posted April 27, 2020 (edited) Hi, i am trying to add "if a customer is new or not" on pdf invoice and delivery slip , i am trying to do it by checking if customer had orders greater then 1 order, but this is not working and i am not sure how i will make it work. i am writing this code in header.tpl inside the pdf folder {if (count($customer_orders) >1) } <td>old customer</td> {else} <td">new customer</td> {/if} i am using prestashop 1.7.6.4 Thanks in advance Edited April 27, 2020 by waqas1 (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted April 27, 2020 Share Posted April 27, 2020 You must edit HTMLInvoice.php first. You will create your own variables in this file. You call the query in the database and pass the result to the variable. Then you insert the condition into the tpl template. Link to comment Share on other sites More sharing options...
Guest Posted April 27, 2020 Share Posted April 27, 2020 (edited) .classes/pdf/HTMLTemplateInvoice.php Find: $data = array( 'order' => $this->order, 'order_invoice' => $this->order_invoice, 'order_details' => $order_details, 'carrier' => $carrier, 'cart_rules' => $cart_rules, 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address), 'tax_excluded_display' => $tax_excluded_display, 'display_product_images' => $display_product_images, 'layout' => $layout, 'tax_tab' => $this->getTaxTabContent(), 'customer' => $customer, 'footer' => $footer, 'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_, 'round_type' => $round_type, 'legal_free_text' => $legal_free_text, ); Add before: $customer_count = Db::getInstance()->getValue('SELECT COUNT(id_customer) AS customer_cnt FROM '._DB_PREFIX_.'orders WHERE id_customer = '.$this->order->id_customer); and add variable to array: 'customer_count' => $customer_count['customer_cnt'], $data = array( 'order' => $this->order, 'order_invoice' => $this->order_invoice, 'order_details' => $order_details, 'carrier' => $carrier, 'cart_rules' => $cart_rules, 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address), 'tax_excluded_display' => $tax_excluded_display, 'display_product_images' => $display_product_images, 'layout' => $layout, 'tax_tab' => $this->getTaxTabContent(), 'customer' => $customer, 'footer' => $footer, 'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_, 'round_type' => $round_type, 'legal_free_text' => $legal_free_text, 'customer_count' => $customer_count['customer_cnt'], ); ./pdf/header.tpl {if $customer_count > 1} <td>old customer</td> {else} <td>new customer</td> {/if} Edited April 27, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 27, 2020 Author Share Posted April 27, 2020 that worked , thank you so much just one thing if i had to do it for header.tpl i have to do the same in classes/pdf/HTMLTemplate.php Thank again - You rocks Link to comment Share on other sites More sharing options...
Guest Posted April 27, 2020 Share Posted April 27, 2020 Yes, I forgot to write it in the post. I gladly helped. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now