Jump to content

Custom text on invoice header based on customer group


Ezequielb

Recommended Posts

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

  • 5 months later...

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

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.

Screenshot 2021-07-12 at 16.23.19.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...