php - Prestashop: override core module class -


i override homeslide class module homeslider, created file homeslide.php , placed under override/modules/homeslider. tried homeslide.php :

class homeslide  extends homeslidecore {     public $start_date;     public $end_date;      public  function __construct($id_slide = null, $id_lang = null, $id_shop = null, context $context = null)     {         self::$definition['fields']['start_date'] =   array('type' => self::type_date, 'validate' => 'isdate');         self::$definition['fields']['end_date'] =   array('type' => self::type_date, 'validate' => 'isdate');          parent::__construct($id_slide, $id_lang, $id_shop);     } } 

but got error

 class 'homeslidecore' not found 

any appreciated. thanks.

yeah problem homeslide class not prestashop core class class used module means can't override this.

simplest way alter homeslide class , alter again after module updates (it's not practice alternatives aren't better).

another way overriding module , include extended version of homeslide class.

extended homeslide class

require_once 'path_to_original_homeslide_class';  class myhomeslide extends homeslide {     // overrides class } 

overriden homeslider module

require_once 'path_to_my_homeslide_class';  class homeslideroverride extends homeslider {      // module method overrides } 

problem approach have copy paste overriden module every method module uses homeslide class , replace myhomeslide. can nuisance if original module gets these methods updated , have repeat copy pasting process again. pretty same altering original class not gained here.

the third option override module or create new module , use hook actiondispatcher alter homeclass.

public function hookactiondispatcher() {     // add class definitions on every page load - add checks if module loaded on pages     require_once 'path_to_homeslide_class';      homeslide::$definition['fields']['start_date'] = array('type' => objectmodel::type_date, 'validate' => 'isdate');     homeslide::$definition['fields']['end_date'] = array('type' => objectmodel::type_date, 'validate' => 'isdate'); } 

however big problem here there's no (simple) way add non-static properties without instance @ runtime. can done monkey patching that's not considered practice.

tl;dr

modify original file or have custom data in separate table in 1:1 relation homeslider_slides table , use object model hooks detect insert/update/delete events.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -