Jump to content

Custom text on invoice header based on customer group


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!

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

If you want to edit the header.tpl and add text below the invoice number, you must change the code elsewhere.

The fastest way is to program the module.
There are hooks that are simple.

obrazek.thumb.png.e155bdc180f017718a4ef50fa34aad7c.png

Share this post


Link to post
Share on other sites

Example of a simple and minimalist module:

<?php

class customInvoiceText extends Module {

    public function __construct()
    {
        $this->author = 'Daniel Tengler';
        $this->author_email = '';
        $this->author_website = '';
        $this->name = 'customInvoiceText';
        $this->tab = 'other';
        $this->version = '1.0.0';
        $this->need_instance = 1;
        $this->bootstrap = true;
        parent::__construct();
        $this->displayName = $this->l('Custom invoice text');
        $this->description = $this->l('Module add or change invoice title params');
        $this->confirmUninstall = $this->l('Uninstall ?');
        $this->ps_versions_compliancy = array('min' => '1.7.0.0', 'max' => '1.7.7.0');
        $this->default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
    }

    public function install() 
    {     
        if (Shop::isFeatureActive()){Shop::setContext(Shop::CONTEXT_ALL);}
        if (!parent::install()){return false;}
	$this->registerHook('displayPDFInvoice');
        return true;
    }
  
    public function uninstall()
    {                               
        if (Shop::isFeatureActive()){Shop::setContext(Shop::CONTEXT_ALL);}
        if (!parent::uninstall()){return false;}
        $this->unregisterHook('displayPDFInvoice');
        return true;
    }

    public function hookDisplayPDFInvoice($hookArgs)
    {
    	$customer = $this->context->customer;
	// title = {$title|escape:'html':'UTF-8'}
    	$hookArgs['object']->title = $hookArgs['object']->title . $this->customText($customer->id_default_group);
    }

    private function customText($cliente_group)
    {
	$tipo_cliente = ''; 

    	if($cliente_group == '4'){
	    $tipo_cliente = 'Text1';
	} elseif ($cliente_group == '7'){
	    $tipo_cliente = 'Text2';
	} else {
	    $tipo_cliente = 'Text3';
	}

	return '<br />'.$tipo_cliente;
    }

}

 

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More