marden Posted March 11, 2012 Share Posted March 11, 2012 I want to extend Product model by adding an extra text field. The ProductCore class contains static property $definition. How can I extend it in the overriden class without copypasting whole property or modifying the core class? Thanks! Link to comment Share on other sites More sharing options...
Raphaël Malié Posted March 12, 2012 Share Posted March 12, 2012 Hello, for now there are no easy way to do this. But since $definition is public, you can do this in your override file : <?php ProductCore::$definition['fields']['my_custom_field'] = array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isString'); class Product extends ProductCore { /// My custom code } Regards Link to comment Share on other sites More sharing options...
DrGren Posted April 30, 2012 Share Posted April 30, 2012 Hello PrestArchitecte! This doesn't seem to work. The following gives me an error: <?php AddressCore::$definition['fields']['contactemail'] => array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128); AddressCore::$definition['fields']['subsidiary'] => array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true); AddressCore::$definition['fields']['agency'] => array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true); class Address extends AddressCore { } Best Regards Henrik Link to comment Share on other sites More sharing options...
mexique1 Posted May 2, 2012 Share Posted May 2, 2012 Do you want it saved in database ? Then I wouldn't recommend to do this. Can't you use the product features as a hack for want to you want to do ? Link to comment Share on other sites More sharing options...
Raphaël Malié Posted May 2, 2012 Share Posted May 2, 2012 Hello DrGreen, can you give me the error you have with this code ? Try to use Address:: and not AddressCore::, I think this should work better. Regards Link to comment Share on other sites More sharing options...
Tafou Posted May 14, 2012 Share Posted May 14, 2012 Hello Raphaël, I'd like to add an extra field on admin product product. This is my code : Product::$definition['fields']['etiquette'] = array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isString'); class Product extends ProductCore { public $etiquette = null; } My field has been created in ps_product and I had a text field on the image tab but when I save nothing happens. Any idea? Link to comment Share on other sites More sharing options...
ZhenIT Software Posted February 12, 2013 Share Posted February 12, 2013 I have had the same problem. In order to have this new fields stored in the DB, you should extend the $definition in the constructor. It would be somethin like this: class Product extends ProductCore { public $etiquette = null; public function __construct($id_product = null) { self::$definition['fields']['etiquette'] = array('type' => self::TYPE_STRING, 'validate' => 'isString'); parent::__construct($id_product); } } 1 Link to comment Share on other sites More sharing options...
enovo Posted May 28, 2013 Share Posted May 28, 2013 <div>Hi, I need to extend functionality of prestashop products and features thereof, my idea is to develop a module that is self-installable, my question is, in the implementation of my module I can overwrite behavior prestashop products or I need to do besides adding a new file in the override folder for this purpose and from there extend its functionality?</div> <div> </div> <div>I did not find documentation that specifies this, I want to be a downloadable module with my new functionality.</div> Link to comment Share on other sites More sharing options...
Recommended Posts