Jump to content

[SOLVED] Can't override PDFGenerator.php?


Recommended Posts

Hello guys  :) 

Why am i not able to override PDFGenerator.php file?

 

Under "Override/classes/pdf/" i have created the same file, which is PDFGenerator.php. Within that file i have put code below, because i want to define different header and footer height. The problem is, that override doesn't work at all, even if i disable cache and delete class_index.php file within cache directory. What am i doing wrong? Is there maybe a bug or something?

<?php

class PDFGeneratorCoreOverride extends PDFGeneratorCore {

    /* Header and Footer HEIGHT change */
    public function writePage() {
        
        $this->SetHeaderMargin(10);
        $this->SetFooterMargin(30);
        $this->setMargins(10, 40, 10);

        $this->AddPage();

        $this->writeHTML($this->content, true, false, true, false, '');
    }
    
} 

I am using Prestashop version 1.6.0.14.

 

If i change code directly, it affects PDF, when it is exported. It works as it should but no results, when overriding PDFGenerator.php file. Overriding works good for modules as well.

Could you guys take a look and help me here please?

Thank you and best regards,
Housy

Edited by Housy (see edit history)
Link to comment
Share on other sites

bellini13, it works properly now  :)

 

Could you please explain, why does it matter, how you name the class? How did you know that you have to name it PDFGenerator? You'll maybe laugh, but i'm not good with classes at all and i thought it doesn't matter how you name it and it is only important that you extend the right class ofcourse.

 

Thank you for saving my ass, you are the man!  :D

 

Regards,

Housy

 

 

This is not the correct code

class PDFGeneratorCoreOverride extends PDFGeneratorCore {

It should be this...

class PDFGenerator extends PDFGeneratorCore {
Link to comment
Share on other sites

Overrideclass  should have the same name that the original class, it's all.

 

In Prestashop, you can call native class adding Core suffix.

 

 

if you write class PDFGeneratorCoreOverride extends PDFGeneratorCore {...} you create a new class, but not an override^^

  • Like 1
Link to comment
Share on other sites

But that is not true for overriding modules, right? Because for example, i have modified "cashondelivery.php" and within override php file i have code below and it works. The class name is different than original class but it does work.

<?php

class CashOnDeliveryOverride extends CashOnDelivery {

    // some code

}

Overrideclass  should have the same name that the original class, it's all.

 

In Prestashop, you can call native class adding Core suffix.

 

 

if you write class PDFGeneratorCoreOverride extends PDFGeneratorCore {...} you create a new class, but not an override^^

Edited by Housy (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...