Jump to content

[Module] Download invoice in customer language


Recommended Posts

I made this module for a friend of mine and decided to share: it basically just creates an additional invoice and delivery slip download buttons (tries to locate all links to pdf.php and adds another button before the one it found) for you to download those PDFs in customer's language so you don't have to switch the language in your back office.

No modifications are required, should work with most Prestashop versions, mainly a javascript module.

invoicecustlang.zip

  • Like 2

Share this post


Link to post
Share on other sites
  • 1 month later...

Dear Eihwaz,

 

I have the m4pdf plugin that allows me to print the invoices with extra text and barcodes

 

It works well with the incoice module (which is great by the way) except in 1 place where I need it the most, on the invoice tab / generate pdf by status option.

 

I noticed that the way the pdf's are called is the same in the order tab and on the order page (there it works)

but different on the invoice tab where the extra button is, somehow it uses different code in a way it skippes the m4 templates.

 

Would you be willing to help me with this?

 

I would be very grateful if you could help, it's probable something small

 

Kind regards

Willem

Share this post


Link to post
Share on other sites
  • 3 weeks later...

I made this module for a friend of mine and decided to share: it basically just creates an additional invoice and delivery slip download buttons (tries to locate all links to pdf.php and adds another button before the one it found) for you to download those PDFs in customer's language so you don't have to switch the language in your back office.

No modifications are required, should work with most Prestashop versions, mainly a javascript module.

 

Sorry but how to use your files in prestashop to have options?

Thank you

Share this post


Link to post
Share on other sites

Hi everyone,

 

Sorry for not responding, for some reason I haven't receive any notifications about replies.

 

2 Willem: could you drop me a PM with a screenshot, because I didn't quite understand the link problem :)

 

2 soskom: This module doesn't have any options, it only adds a few additional icons - e.g., it doesn't replace anything, you just have to install it and it's instantly available where ever there's a link to a pdf file.

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 2 weeks later...
  • 4 months later...

Hey,

 

I just have Installed this "awsome" module and now I cant install or uninstall any MODULES! I cant Even see the installed modules, I dont know what the fuck this module does, but this sucs

why nobody has even tested this module before it was posted?!

Edited by greeed (see edit history)

Share this post


Link to post
Share on other sites

ok I have solved this shit

These problems appear when you let a mokey write the code....

 

The modelus js breaks down bacends module sections js and as a result you can't configure/install/see/unsee... modules

so teh solution is to delete this module to hell!

Share this post


Link to post
Share on other sites

I made this module for a friend of mine and decided to share: it basically just creates an additional invoice and delivery slip download buttons (tries to locate all links to pdf.php and adds another button before the one it found) for you to download those PDFs in customer's language so you don't have to switch the language in your back office.

No modifications are required, should work with most Prestashop versions, mainly a javascript module.

 

This module seems to be exactly what I need - installed it and it also says that it is installed. However, I don't see any different behavior. PS = 1.5.0.17.

 

I've made small changes to the PDF class my self (mostly margins adjustment). Could it be the case, that the patch does not work due to these (minor) changes?

 

Any help is really appreciated!

Share this post


Link to post
Share on other sites
  • 4 months later...
  • 2 months later...
  • 3 months later...

I found a way to generate the pdf files in the order language (the language that the customer selected when placing the order):

 

in classes\pdf\HTMLTemplate.php :

 

 protected function getTemplate($template_name)
{
 $template = false;
 $default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
 $overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
 if (file_exists($overriden_template))
  $template = $overriden_template;
 else if (file_exists($default_template))
  $template = $default_template;

 // SELECT ORDER LANGUAGE FOR THE TEMPLATE
 if ( $this->order )
   Context::getContext()->language = new Language($this->order->id_lang);

 return $template;
}

 

I am using 1.5.4.1

Edited by Modulotech (see edit history)
  • Like 5

Share this post


Link to post
Share on other sites
  • 1 month later...

I found a way to generate the pdf files in the order language (the language that the customer selected when placing the order):

 

in classes\pdf\HTMLTemplate.php :

 

protected function getTemplate($template_name)
{
  $template = false;
  $default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
  $overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
  if (file_exists($overriden_template))
   $template = $overriden_template;
  else if (file_exists($default_template))
   $template = $default_template;
  
  // SELECT ORDER LANGUAGE FOR THE TEMPLATE
  if ( $this->order )
    Context::getContext()->language = new Language($this->order->id_lang);
  
  return $template;
}
I am using 1.5.4.1

 

 

Works perfect.  Thanks Modulotech  :)

Share this post


Link to post
Share on other sites

i'm sorry, i have a question.

if i want to edit the invoices PDF. what should i do ???

i'm newbie in PrestaShop and using PrestaShop 1.4.7.3.

Thanks.

Hope someone can help me.

Sorry about my language :D

Share this post


Link to post
Share on other sites

i'm sorry, i have a question.

if i want to edit the invoices PDF. what should i do ???

i'm newbie in PrestaShop and using PrestaShop 1.4.7.3.

 

Thanks.

Hope someone can help me.

Sorry about my language :D

You have to edit the INVOICE.TPL file. 

Which can be found in either your theme directory like:  /themes/yourtheme/pdf/invoice.tpl

And if your using standard theme find it: /pdf/invoice.tpl

 

succes

 

ps. If your a newbie, why are you using version 1.4.7.3

Edited by weckie (see edit history)

Share this post


Link to post
Share on other sites

You have to edit the INVOICE.TPL file. 

Which can be found in either your theme directory like:  /themes/yourtheme/pdf/invoice.tpl

And if your using standard theme find it: /pdf/invoice.tpl

 

succes

 

ps. If your a newbie, why are you using version 1.4.7.3

 

There is no folder pdf in /themes/mytheme/ sir, but i have finish it with my friend help.

I edit the pdf.php in folder /classes/.

I'm working in Webdesign company. I recently joined the company 1 week ago after my graduation.

My Boss give me this work, but i dont know how to use it. My boss have the PrestaShop version 1.4.7.3.

Thanks for your advice.

Share this post


Link to post
Share on other sites
  • 6 months later...

Thanks for this. 

 

One addition though for all those new to Prestashop. You should copy classes\pdf\HTMLTemplate.php to override\classes\pdf\HTMLTemplate.php first and edit that file with the above improvement (bugfix)

Share this post


Link to post
Share on other sites

There is no folder pdf in /themes/mytheme/ sir, but i have finish it with my friend help.

I edit the pdf.php in folder /classes/.

I'm working in Webdesign company. I recently joined the company 1 week ago after my graduation.

My Boss give me this work, but i dont know how to use it. My boss have the PrestaShop version 1.4.7.3.

Thanks for your advice.

 

Last instructions are intended for PrestaShop v1.5 only. Version 1.4 is completely different.

Share this post


Link to post
Share on other sites

I found a way to generate the pdf files in the order language (the language that the customer selected when placing the order):

 

in classes\pdf\HTMLTemplate.php :

 

protected function getTemplate($template_name)
{
  $template = false;
  $default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
  $overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
  if (file_exists($overriden_template))
   $template = $overriden_template;
  else if (file_exists($default_template))
   $template = $default_template;
  
  // SELECT ORDER LANGUAGE FOR THE TEMPLATE
  if ( $this->order )
    Context::getContext()->language = new Language($this->order->id_lang);
  
  return $template;
}
I am using 1.5.4.1

 

 

great, running in PS 1.5.6.2

Share this post


Link to post
Share on other sites
  • 5 months later...

The product name is stored in database in customer's language. The only possible solution is to print actual product name in employee's language. Of course, that name can be different than previously saved one.

 

The M4 PDF Extensions module can easily print the product name in actual invoice language.

Share this post


Link to post
Share on other sites

The product name is stored in database in customer's language. The only possible solution is to print actual product name in employee's language. Of course, that name can be different than previously saved one.

 

The M4 PDF Extensions module can easily print the product name in actual invoice language.

Yes, I know that your module could do this trick, but 100 eur only for one thing is too much for my. So im looking solution to deal with this problem. So I should get product name not from order_detail.product_name ? How should I do to get this result in default PS16? 

Share this post


Link to post
Share on other sites
  • 7 months later...
  • 2 months later...
  • 1 month later...
  • 2 years later...
  • 1 year later...
En 20/8/2013 a las 6:19 PM, Modulotech dijo:

I found a way to generate the pdf files in the order language (the language that the customer selected when placing the order):

 

in classes\pdf\HTMLTemplate.php :

 

 


 protected function getTemplate($template_name)
{
 $template = false;
 $default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
 $overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
 if (file_exists($overriden_template))
  $template = $overriden_template;
 else if (file_exists($default_template))
  $template = $default_template;

 // SELECT ORDER LANGUAGE FOR THE TEMPLATE
 if ( $this->order )
   Context::getContext()->language = new Language($this->order->id_lang);

 return $template;
}
 

 

 

I am using 1.5.4.1

Hi!

I see that many people served your solution. But with Prestashop 1.7.5.1 it doesn't work for me. Any idea how you could get the same solution with prestashop 1.7? Was your solution also for the invoice attached in the purchase confirmation email?

Thx

Share this post


Link to post
Share on other sites

Hi PauBaig,

According to this topic https://github.com/PrestaShop/PrestaShop/issues/13928 The context language returns an object now:

Context::getContext()->language =>
Language Object ( [id] => 1 [name] => English (English) [iso_code] => en [locale] => en-US [language_code] => en-us

I was not able to test this because this is an old project but I guess you can try to use this code:

// SELECT ORDER LANGUAGE FOR THE TEMPLATE
 if ( $this->order )
   Context::getContext()->language->id = new Language($this->order->id_lang);

Hope this will work.

Best,

Modulotech

  • Like 1

Share this post


Link to post
Share on other sites
En 4/12/2019 a las 11:36 AM, Modulotech dijo:

Hi PauBaig,

According to this topic https://github.com/PrestaShop/PrestaShop/issues/13928 The context language returns an object now:

Context::getContext()->language =>
Language Object ( [id] => 1 [name] => English (English) [iso_code] => en [locale] => en-US [language_code] => en-us

I was not able to test this because this is an old project but I guess you can try to use this code:


// SELECT ORDER LANGUAGE FOR THE TEMPLATE
 if ( $this->order )
   Context::getContext()->language->id = new Language($this->order->id_lang);

Hope this will work.

Best,

Modulotech

Thank you very much for answering! I did not expect it, in such an old post. Luckily, prestashop has a large community of users willing to help others.

Unfortunately, the solution does not work for me. I don't appreciate any kind of change :(

Keep generating the invoice with the language of the backoffice and not with the language of the buyer :(

Anyway, thanks again for trying!

Share this post


Link to post
Share on other sites
Am 21.8.2013 um 1:19 AM schrieb Modulotech:

I found a way to generate the pdf files in the order language (the language that the customer selected when placing the order):

 

in classes\pdf\HTMLTemplate.php :

 

 


 protected function getTemplate($template_name)
{
 $template = false;
 $default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
 $overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
 if (file_exists($overriden_template))
  $template = $overriden_template;
 else if (file_exists($default_template))
  $template = $default_template;

 // SELECT ORDER LANGUAGE FOR THE TEMPLATE
 if ( $this->order )
   Context::getContext()->language = new Language($this->order->id_lang);

 return $template;
}
 

 

 

I am using 1.5.4.1

Thanks for sharing this solution. I can confirm that it also works with 1.6.1 but I realized a small detail.
Unfortunately it does not change the header of the invoice which means that "INVOICE" on the top remains in the BO language and does not change to to customers language.

Share this post


Link to post
Share on other sites
  • 2 weeks later...
En 7/12/2019 a las 1:30 AM, NSN dijo:

Thanks for sharing this solution. I can confirm that it also works with 1.6.1 but I realized a small detail.
Unfortunately it does not change the header of the invoice which means that "INVOICE" on the top remains in the BO language and does not change to to customers language.

If you refer to the header inside the PDF, you can modify anything in /pdf/header.tpl

I don't have the word INVOICE anywhere. I only use Catalan and Spanish.

Edit: ..... Well, in prestashop 1.7 😅

Edited by PauBaig (see edit history)

Share this post


Link to post
Share on other sites
Am 20.12.2019 um 12:14 PM schrieb PauBaig:

If you refer to the header inside the PDF, you can modify anything in /pdf/header.tpl

I don't have the word INVOICE anywhere. I only use Catalan and Spanish.

Edit: ..... Well, in prestashop 1.7 😅

Thanks for your feedback.

In 1.6 it seems to be slightly different as there is no designated header.tpl but the part can be found in the other tpl too.
Anyway, my needs have changed and I only need invoices in a defined language, no matter what the customers language is. I realized it by changing the code

// SELECT ORDER LANGUAGE FOR THE TEMPLATE if ( $this->order ) Context::getContext()->language = new Language($this->order->id_lang);

to

// SELECT ORDER LANGUAGE FOR THE TEMPLATE if ( $this->order ) Context::getContext()->language = new Language(3);

So far everything works well besides the fact that the country, stated at the customers billing and shipping address, remains in the customers language.
If I find the solution to get the country name also in a defined language I will post it.

Share this post


Link to post
Share on other sites
  • 1 year later...

It seems not to work in PS 1.7.7. The problem is still the same, with the goods there is needed documentation in customer language, not shop admin. If to look for the function

"protected function getTemplate($template_name)" then right after that is the translation block. How to change it for getting the pdf  documents in customer language?

 

 

    /**
     * Translation method.
     *
     * @param string $string
     *
     * @return string translated text
     */
    protected static function l($string)
    {
        return Translate::getPdfTranslation($string);
    }

    protected function setShopId()
    {
        if (isset($this->order) && Validate::isLoadedObject($this->order)) {
            $id_shop = (int) $this->order->id_shop;
        } else {
            $id_shop = (int) Context::getContext()->shop->id;
        }

        $this->shop = new Shop($id_shop);
        if (Validate::isLoadedObject($this->shop)) {
            Shop::setContext(Shop::CONTEXT_SHOP, (int) $this->shop->id);
        }
    }

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