Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override PrestShop 1.7.7 module classes?

I want to override class MySQL of PrestaShop module ps_facetedsearch that is located in file: mystore/modules/ps_facetedsearch/src/Adapter/MySQL.php

How do I achieve this?


EDIT:

Class MySQL that I want to override is defined in file mystore/modules/ps_facetedsearch/src/Adapter/MySQL.php. This class is used by class Search of same module and is defined in file mystore/modules/ps_facetedsearch/src/Product/Search.php. Class Search is used by another module class and so on, so there is a long 'chain' of classes.

Do I need to extend all chained classes or can I somehow override only the MySQL class that really requires modification?

like image 950
Marek J. Avatar asked Jan 24 '26 16:01

Marek J.


1 Answers

Override Module Classes

To modify behavior of a module’s class you have to put your modified class at

ROOT/override/modules/MODULENAME/OVERRIDECLASS.php

You have to create a PHP file on the location below and call it ps_facetedsearch.php

ROOT/override/modules/ps_facetedsearch/ps_facetedsearch.php

Inside the overriding class you can add the code below.

<?php
    class Ps_FacetedsearchOverride extends Ps_Facetedsearch
    {
        public function getContent()
        {
            return "Hello store owner! this code is brought to you by crezzur.com";
        }
    }
?>

After saving your ps_facetedsearch.php override and clearing the Prestashop cache you will see the message "Hello store owner! this code is brought to you by crezzur.com" when you open the module ps_facetedsearch.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!