Jump to content

[SOLVED] How to change invoice logo refering to language


guessous

Recommended Posts

Create all image paths in getHeader() function in /classes/pdf/HTMLTemplate.php. Then use a condition to switch between the paths according to the language in /pdf/header.tpl - replace

        {if $logo_path}
            <img src="{$logo_path}" style="width:{$width_logo}px; height:{$height_logo}px;" />
        {/if}
  • Like 1
Link to comment
Share on other sites

 

Create all image paths in getHeader() function in /classes/pdf/HTMLTemplate.php. Then use a condition to switch between the paths according to the language in /pdf/header.tpl - replace

        {if $logo_path}
            <img src="{$logo_path}" style="width:{$width_logo}px; height:{$height_logo}px;" />
        {/if}

thanks 

but how i cant create a condition to switch between the paths according to the language in /pdf/header.tpl - replace

Link to comment
Share on other sites

Maybe easier solution is to create the condition right in the getHeader() function.

$path_logo = $this->getLogo();
$id_lang = (int)Context::getContext()->language->id;
if ($id_lang == 1)
    $path_logo = ..... here define the logo path for the first language
elseif ($id_lang == 2)
    $path_logo = ..... here define the logo path for the second language
....
  • Like 2
Link to comment
Share on other sites

 

Maybe easier solution is to create the condition right in the getHeader() function.

$path_logo = $this->getLogo();
$id_lang = (int)Context::getContext()->language->id;
if ($id_lang == 1)
    $path_logo = ..... here define the logo path for the first language
elseif ($id_lang == 2)
    $path_logo = ..... here define the logo path for the second language
....

thanks you so matsh mr tuk

i hav one more question 

$path_logo = $this->getLogo();

 

so if i want change  image paths you must create a new function to get url logo !!!

Link to comment
Share on other sites

Like this 

	protected function getLogo()
	{
		$logo = '';

		$physical_uri = Context::getContext()->shop->physical_uri.'img/';

		if (Configuration::get('PS_LOGO_INVOICE', null, null, (int)$this->order->id_shop) != false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_INVOICE', null, null, (int)$this->order->id_shop)))
			$logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO_INVOICE', null, null, (int)$this->order->id_shop);
		elseif (Configuration::get('PS_LOGO', null, null, (int)$this->order->id_shop) != false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO', null, null, (int)$this->order->id_shop)))
			$logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO', null, null, (int)$this->order->id_shop);
		return $logo;
	}
    	protected function getLogo2()
	{
		$logo = '';

		$physical_uri = Context::getContext()->shop->physical_uri.'img2/';

		if (Configuration::get('PS_LOGO_INVOICE', null, null, (int)$this->order->id_shop) != false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_INVOICE', null, null, (int)$this->order->id_shop)))
			$logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO_INVOICE', null, null, (int)$this->order->id_shop);
		elseif (Configuration::get('PS_LOGO', null, null, (int)$this->order->id_shop) != false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO', null, null, (int)$this->order->id_shop)))
			$logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO', null, null, (int)$this->order->id_shop);
		return $logo;
	}

and getHeader()

	public function getHeader()
	{    
	   
       
        $id_lang = (int)Context::getContext()->language->id;
        print $id_lang;
        if ($id_lang == 1){
        $path_logo = $this->getLogo();
        }
        elseif ($id_lang == 2){
        $path_logo = $this->getLogo2();
        }
    
		$shop_name = Configuration::get('PS_SHOP_NAME', null, null, (int)$this->order->id_shop);
		if ($id_lang == 1){
        $path_logo = $this->getLogo();
        }
        elseif ($id_lang == 2){
        $path_logo = $this->getLogo2();
        }

		$width = 0;
		$height = 0;
		if (!empty($path_logo))
			list($width, $height) = getimagesize($path_logo);
        
        
        
        
		$this->smarty->assign(array(
			'logo_path' => $path_logo,
			'img_ps_dir' => 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_,
			'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
			'title' => $this->title,
			'date' => $this->date,
			'shop_name' => $shop_name,
			'width_logo' => $width,
			'height_logo' => $height
		));

		return $this->smarty->fetch($this->getTemplate('header'));
	}
Link to comment
Share on other sites

If you have all logos in the /img folder just use:

$path_logo = _PS_IMG_DIR_."your_logo_file_name_number_1.jpg";

in the condition.

Like this ?

	public function getHeader()
	{    
	   $path_logo = $this->getLogo();
       
        $id_lang = (int)Context::getContext()->language->id;
  		$shop_name = Configuration::get('PS_SHOP_NAME', null, null, (int)$this->order->id_shop);
        if ($id_lang == 1){
        $path_logo =_PS_IMG_DIR_."logo1.jpg";;}
        elseif ($id_lang == 2){
        $path_logo =_PS_IMG_DIR_."logo2.jpg";;}
    

		

		$width = 0;
		$height = 0;
		if (!empty($path_logo))
			list($width, $height) = getimagesize($path_logo);
 
		$this->smarty->assign(array(
			'logo_path' => $path_logo,
			'img_ps_dir' => 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_,
			'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
			'title' => $this->title,
			'date' => $this->date,
			'shop_name' => $shop_name,
			'width_logo' => $width,
			'height_logo' => $height
		));

		return $this->smarty->fetch($this->getTemplate('header'));
	}
Edited by guessous (see edit history)
Link to comment
Share on other sites

  • 8 months later...

Hi !

 

Thank you for your topic and the clear answer.

 

I just want to know how you choose the language to generate the invoice from back-office.

There is a way to translate the PDF right from the back-office, regardless of the back-office language ?

 

Thank you very much for your help.

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...