Jump to content

Override model definition


Recommended Posts

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

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

  • 1 month later...

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

  • 2 weeks later...

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

  • 8 months later...

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);
   }
}

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

<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

×
×
  • Create New...