Teskuroi Posted February 13, 2015 Share Posted February 13, 2015 (edited) I create a module and put override file "Address.php" to "/override/classes/" in my module directory. When I click install in ACP, Prestashop made file /override/classes/Address.php in root, and plant contents like this: /* * module: nkpitanie * date: 2015-02-13 10:40:43 * version: 1.0.0b */ public static $definition = array ( // another contents... ), ); And when I click "Uninstall" Prestashop delete just a one line. After uninstalling, file /override/classes/Address.php looks like: /* * module: nkpitanie * date: 2015-02-13 10:40:43 * version: 1.0.0b */ ( // another contents... ), ); And, off course, in next time, when i try to install my module Prestashop return an error. How do i fix it? UPDATED 2015.02.15: SOLUTION: Correct way to override static variables in Prestashop classes: <?php class Address extends AddressCore { public function __construct($id = null, $id_lang = null) { self::$definition['fields']['address1'] = array('type' => parent::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128); parent::__construct($id, $id_lang); } } Edited February 15, 2015 by Teskuroi (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted February 13, 2015 Share Posted February 13, 2015 My guess is that you are trying to perform an override of something that cannot be overriden. Since you have completely blurred out your code, it will not be possible for someone to help you. Are you trying to override a function, or a static variable? Link to comment Share on other sites More sharing options...
Teskuroi Posted February 14, 2015 Author Share Posted February 14, 2015 I try to override static variable $definition in Address.php. Link to comment Share on other sites More sharing options...
bellini13 Posted February 14, 2015 Share Posted February 14, 2015 I'm not sure you can override a static variable. What i would suggest you do is instead override the getDefinition function and not use the $definition variable directly. The getDefinition function is a public static function in the ObjectModel class. Address extends ObjectModel but does not override it, so your Address Override class should be able to override and then add or change whatever you need to do, before returning it Link to comment Share on other sites More sharing options...
Teskuroi Posted February 15, 2015 Author Share Posted February 15, 2015 Thanks for your help. Your method too difficult for this task, i guess. I found more elegant way: <?php class Address extends AddressCore { public function __construct($id = null, $id_lang = null) { self::$definition['fields']['address1'] = array('type' => parent::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128); parent::__construct($id, $id_lang); } } P.S. PHP supports overriding static variables: <?php class A { public static $variable = 'Old value.'; } class B extends A { public static $variable = 'New value.'; } echo B::$variable; // return correctly: New value. Anyway thank you bellini13. Link to comment Share on other sites More sharing options...
bellini13 Posted February 15, 2015 Share Posted February 15, 2015 your method is fine too, it provides the same result. PHP may allow it, but we are not talking about PHP inheritance, we are talking about Prestashop overrides, which apparently do not 'support' overriding variables, only functions. Link to comment Share on other sites More sharing options...
igpetru Posted April 27, 2019 Share Posted April 27, 2019 (edited) Hi, Put all public static $definition in a single row. For example: If you have public static $validators = array( 'active' => array('AdminImportController', 'getBoolean'), 'tax_rate' => array('AdminImportController', 'getPrice'), 'price_tex' => array('AdminImportController', 'getPrice'), 'price_tin' => array('AdminImportController', 'getPrice'), 'reduction_price' => array('AdminImportController', 'getPrice'), 'reduction_percent' => array('AdminImportController', 'getPrice'), 'wholesale_price' => array('AdminImportController', 'getPrice'), 'ecotax' => array('AdminImportController', 'getPrice'), 'name' => array('AdminImportController', 'createMultiLangField'), 'description' => array('AdminImportController', 'createMultiLangField'), 'description_short' => array('AdminImportController', 'createMultiLangField'), 'meta_title' => array('AdminImportController', 'createMultiLangField'), 'meta_keywords' => array('AdminImportController', 'createMultiLangField'), 'meta_description' => array('AdminImportController', 'createMultiLangField'), 'link_rewrite' => array('AdminImportController', 'createMultiLangField'), 'available_now' => array('AdminImportController', 'createMultiLangField'), 'available_later' => array('AdminImportController', 'createMultiLangField'), 'category' => array('AdminImportController', 'split'), 'online_only' => array('AdminImportController', 'getBoolean') ); Move in a single row, outside of __construct function but inside of class or controller. public static $validators = array('active' => array('AdminImportController', 'getBoolean'),'tax_rate' => array('AdminImportController', 'getPrice'), rest of code... )); and uninstall will work fine Edited May 3, 2019 by igpetru (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now