hookHeader in Prestashop, breaks flow whatever I do

100 Views Asked by At

I want to add a custom js file my_sdk.js in my Prestashop module.

I register the hook header and prepare the function, but whatever I do inside, breaks something. My my_sdk.js file is correctly added by addJS() and it works. The problem is that, after that, the cart is no more updated.

Whatever I write inside the hookHeader, it's executed but then the popup showing after the 'add to cart' action, stops working. The popup doesn't show up and the total amount of the cart is not updated until I refresh the page. It's not a problem of my js file, even if I don't import it and write something else (like an echo), I have the same problem.

It works only if I don't write anything (or comment everything) inside function hookHeader().

 public function install() {
        return (bool) $this->registerHook(['header']);
    }


    public function hookHeader($params) {
    
        $this->context->controller->addJS(_PS_MODULE_DIR_ . $this->name . '/views/js/my_sdk.js');  // this line breaks the popup
        echo "hello, this breaks the popup"; // also just this line breaks the popup


    }

I really don't understand why. Tried also with hookDisplayHeader, same thing. The website works, without errors, but the cart is not updated and the popup doesn't show.

0

There are 0 best solutions below