Ezequielb Posted January 21, 2021 Share Posted January 21, 2021 Hello all, I am trying to show a custom invoice description based on the group the customer belongs to; I succeeded with the code below to show custom text for each group but only front customer's view. When admin tries to generate the invoice the code does not work (showing only the last {else}). What should be the solution to get the customer default group based on the order id? {if Customer::getDefaultGroupId(Context::getContext()->customer->id) == 4} custom code 1..... {elseif Customer::getDefaultGroupId(Context::getContext()->customer->id) == 7} custom code 2..... {else} custom code 3... {/if} Best regards! Link to comment Share on other sites More sharing options...
Guest Posted January 21, 2021 Share Posted January 21, 2021 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Ezequielb Posted January 21, 2021 Author Share Posted January 21, 2021 Thanks, I did in .tpl. Then how do I get customer group id inside HTMLTemplateInvoice.php? Am using P.S 1.7.7 Link to comment Share on other sites More sharing options...
Guest Posted January 21, 2021 Share Posted January 21, 2021 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Ezequielb Posted January 21, 2021 Author Share Posted January 21, 2021 Thanks, I have tried several ways, but I get "Notice: Undefined index: customer_group". It seems the variable is not getting the data. What could be happening? Link to comment Share on other sites More sharing options...
Ezequielb Posted January 21, 2021 Author Share Posted January 21, 2021 Testing again, I found that custom text shows everywhere in the pdf invoice but not in header. Link to comment Share on other sites More sharing options...
Guest Posted January 22, 2021 Share Posted January 22, 2021 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Ezequielb Posted January 23, 2021 Author Share Posted January 23, 2021 Text show perfectly in other .tpl file but no for header.tpl. Thanks fot your kind support. Link to comment Share on other sites More sharing options...
Guest Posted January 23, 2021 Share Posted January 23, 2021 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted January 23, 2021 Share Posted January 23, 2021 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Ezequielb Posted January 24, 2021 Author Share Posted January 24, 2021 Thanks my friend, I appreciate your help. 👍 Link to comment Share on other sites More sharing options...
Guest Posted January 24, 2021 Share Posted January 24, 2021 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Nickovitshj Posted July 12, 2021 Share Posted July 12, 2021 Hey @Guest First of, thanks so much for already providing the code and logic above. invoice-custom.tpl: {if $custom_text}<span>{$custom_text|cleanHtml nofilter}</span>{/if} HTMLTemplateInvoice.php: $legal_free_text = Hook::exec('displayInvoiceLegalFreeText', array('order' => $this->order)); if (!$legal_free_text) { $legal_free_text = Configuration::get('PS_INVOICE_LEGAL_FREE_TEXT', (int) Context::getContext()->language->id, null, (int) $this->order->id_shop); } $customer_ = new Customer((int)$this->order->id_customer); $customer_group = $customer_->id_default_group; $custom_text = ‘’; if($customer_group == '4'){ $custom_text = 'Company SARL'; } elseif($customer_group == '5') { $custom_text = 'Company NV'; } $data = array( 'custom_text' => $custom_text, 'order' => $this->order, 'order_invoice' => $this->order_invoice, I have created 2 new customer groups with id 4 and 5. But now in my custom .tpl file as a result in the PDF I get the following: '' Instead of Company SARL or Company NV Any idea as to what could be the cause of this? Thanks in advance, Nick Link to comment Share on other sites More sharing options...
Nickovitshj Posted July 12, 2021 Share Posted July 12, 2021 After looking further into this I found the issue at hand. Will post it so that other people with the same issue might use this. The default customer group from your end-user is important. Once I had set this to one of my new customer groups the logic started working in the exported PDF's. See image attached. 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