Skip to content
Advertisement

HTML Template PHP get Header() – How access to its content?

I’m new with PHP and I’m trying to modify the header of a pdf created by a prestashop module. enter image description here I would like to delete the logo image “spo devis”.

I searched during long time and I finaly found the page where is the header. Unfortunatly I don’t understand how it’s works.

This is the class structure

class HTMLTemplateQuotationPdf extends HTMLTemplate
{
    public $cart;
    public $quotation;
    public $context;
    private $isSeven;

    public function __construct($quotation, $smarty)
    { ... }

    public function getContent()
    { ... }

    public function getHeader()
    { ... }

    public function getFooter()
    { ... }

    public function getFilename()
    { ... }

    public function getBulkFilename()
    { ... }

    protected function opartdevisGetTemplate($template_name)
    { ... }
}

For the footer it’s simple a tpl exists and the code call it.

public function getFooter()
    {
        $shop_address = $this->getShopAddress();

        $this->smarty->assign(array(
            'available_in_your_account' => $this->available_in_your_account,
            'shop_address' => $shop_address,
            'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, (int)$this->cart->id_shop),
            'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, (int)$this->cart->id_shop),
            'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int)$this->cart->id_shop),
            'free_text' => Configuration::get('PS_INVOICE_FREE_TEXT', (int)Context::getContext()->language->id, null, (int)$this->cart->id_shop)
        ));

        return $this->smarty->fetch($this->opartdevisGetTemplate('footer'));
    }

 protected function opartdevisGetTemplate($template_name)
    {
        $template = false;
        $default_template = rtrim(_PS_MODULE_DIR_, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'opartdevis/views/templates/front/pdf'.DIRECTORY_SEPARATOR.$template_name.'.tpl';

        if ($this->isSeven) {
            $overridden_template = _PS_ALL_THEMES_DIR_.$this->shop->theme->getName().DIRECTORY_SEPARATOR.'modules/opartdevis/views/templates/front/pdf'.DIRECTORY_SEPARATOR.$template_name.'.tpl';
        } else {
            $overridden_template = _PS_ALL_THEMES_DIR_.$this->shop->getTheme().DIRECTORY_SEPARATOR.'modules/opartdevis/views/templates/front/pdf'.DIRECTORY_SEPARATOR.$template_name.'.tpl';
        }

        if (file_exists($overridden_template)) {
            $template = $overridden_template;
        } elseif (file_exists($default_template)) {
            $template = $default_template;
        }

        return $template;
    }

But for the header, I’m lost.

 public function getHeader()
    {
        $this->assignCommonHeaderData();

        $this->smarty->assign(array(
            'header' => $this->module->l('Quotation', 'htmltemplatequotationpdf'),
            'title' => '# '.$this->quotation->id,
            'date' => Tools::displayDate($this->cart->date_upd),
        ));

        return $this->smarty->fetch($this->getTemplate('header'));
    }

I have the impression that it called itself (htmltemplatequotationpdf) …

I did not find the header template (tpl) and I ask myself if it really exists. I searched in all img tags, src tags, ‘header’ word and ‘pdf’ word.

It’s like the header have a different shape than classical template.

Could you help me pls ?

Thanks in advance

Advertisement

Answer

The method you are looking for is in classes/pdf/HTMLTemplate.php, and it’s assignCommonHeaderData.

The one you are poiting is a module call.

You can find

$this->smarty->assign([
            'logo_path' => Tools::getShopProtocol() . Tools::getMediaServer(_PS_IMG_) . _PS_IMG_ . $logo,
            'img_ps_dir' => Tools::getShopProtocol() . Tools::getMediaServer(_PS_IMG_) . _PS_IMG_,
            'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
            'date' => $this->date,
            'title' => $this->title,
            'shop_name' => $shop_name,
            'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int) $id_shop),
            'width_logo' => $width,
            'height_logo' => $height,
        ]);

This is from PS 1.7.7.0, but everything you need is there.

By the way, give a check to the tpl file just to be sure to not referr to a variable that is not going to be passed anymore.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement