Jump to content

Add Manufacturer new data into database


forddyce
 Share

Recommended Posts

My Prestashop version is 1.5.5.0.

 

I need to add a manufacturer code into the prestashop to be printed into invoice later. Like Manufacturer 1 is M1, so the invoice later will look like M100001.

 

So far, I've successful in adding the custom field in add manufacturer form (renderForm function in AdminManufacturersController.php). But I can't seem to find the code where the data is actually inserted to the database.

 

Can anyone point me to where I can find the code? Thank you.

Share this post


Link to post
Share on other sites

Hi forddyce,

Have a look in classes/Manufacturer.php

 

there you have the class of Manufacturer, where you have to add a few things:

 

at the top, you see lines like this:

/** @var string Object creation date */
public $date_add;
 
/** @var string Object last modification date */
public $date_upd;
 
so add your variable you use for storing your value
/** @var string Object manufacturer code */
public $man_code;       (or whatever you called it exactly)
 
then a little down, you see the following code, add something like the red line :
 
 
public static $definition = array(
'table' => 'manufacturer',
'primary' => 'id_manufacturer',
'multilang' => true,
'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
'active' => array('type' => self::TYPE_BOOL),
'date_add' => array('type' => self::TYPE_DATE),
'date_upd' => array('type' => self::TYPE_DATE),
'man_code' => array('type' =>self::TYPE_STRING, 'validate' => 'isString', 'required' => true, 'size' => 16),
 
// Lang fields
'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
'short_description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 254),
...
 
 
N.B. check if required: true/false, size of field in database indeed 16/??, any validation needed?)
 
Make sure you use the variable on the screen as well. Look at the code around the place you added, like 'active' variable or so how they do it. (Some similar example how to add to input screen here, although for older version, quite similar: http://strife.pl/2011/12/how-to-add-new-custom-field-in-prestashop/ )
 
Out of memory, so hope I don't forget anything...
 

Hope this helps,

pascal

  • Like 2

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More