phpprestashopprestashop-1.6prestashop-1.5

how overriding in Prestashop works


When we mimic a function in our overriding class, does Prestashop simply replace the whole function with the original one or does it append to it. for eg.

/mymodule/override/classes/Product.php:

class Product extends ProductCore {
   public function add() {
      // some function
   }
}

Is it going to append // some function or is it going to replace the whole class add()


Solution

  • The short answer is that it will replace the whole function. You should look into PHP classes heritage mechanism.

    You still have the possibility to execute the original Product add() method in your override by adding parent::add() in your code.

    class Product extends ProductCore {
        public function add() {
            // do something before adding
            parent::add();
        }
    }