Jump to content

[SOLVED] My module - add theme PDF invoice template


Guest

Recommended Posts

Hello.
I need to check or insert my own TPL invoice template after installing my module.

Unfortunately, I can't get a link to copy a file from my module to a template.

Problem is in the path of copying and deleting the file $template_path and $template_override_file.

Thank you for your help

public function installTemplate() {
          $template_path = _THEME_DIR_.'/pdf';
          $template_file =  $template_path.'/invoice.product-tab.tpl';
          $template_override_file = _MODULE_DIR_.$this->name.'/views/themes/pdf/invoice.product-tab.tpl';
          
          if (file_exists($template_file)){
          		$template_text = file_get_contents($template_file);
                $template_text = str_replace('{$order_detail.product_name}','{$order_detail.product_name}\r\n{if isset($order_detail.my_value)}\r\n<br />  {$order_detail.my_value}\r\n{/if}',$template_text);
                file_put_contents($template_file,$template_text);
          } else {
          		mk_dir($template_path, 0755, true);
          		copy($template_override_file,$template_file);
          }
    }
    
    public function uninstallTemplate() {
          $template_path = _THEME_DIR_.'/pdf';
          $template_file =  $template_path.'/invoice.product-tab.tpl';
          unlink($template_file);
    }

 

Edited by Guest (see edit history)
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...