New field for Product in back office

Today I want to show you how to create new product field in back office on product edit page (informations tab). Of course you will be able to fill field with own value and this value will be stored in database. This tutorial is an answer for a Dean request. He is a owner of dekom.co.rs store. Here is his request:

What I need is another text field which I can add to a product. This text field should be similar to a field where you put the product name.

To achieve what he expect it will be necessary to modify several things. Hope that this tutorial will be helpful also for other merchants with similar needs. This tutorial is a great "pattern" for other modifications related to own fields in back office. So we want to create field named: internal name. Of course you can use your own name.

 

Step 1

The first step is related to database. We need to create new field in ps_product table. so, open phpmyadmin and alter ps_product table. Add new VARCHAR(200) field (i think that 200 chars for internal name are enough, am i right?) field name: internal_name, specification:

Internal name field in database, ps_product table (click to enlarge)

new field prestashop database in ps_product table

 

 

Step 2

Now it's time to extend product object, in this case we need to modify core files. Open classes/product.php file, you can find there code like: 

class ProductCore extends ObjectModel
{
	/** @var string Tax name */
	public $tax_name;

	/** @var string Tax rate */
	public $tax_rate;
...
...
...

add there new field definition:

/** @var string Tax rate */
	public $internal_name;

After modifications our code should looks like: (i highlighted added two lines of code)

class ProductCore extends ObjectModel
{
	/** @var string Tax name */
	public $tax_name;

	/** @var string Tax rate */
	public $tax_rate;

        /** @var string Tax rate */
        public $internal_name;
...
...
...

We need also to extend object definition: add: 'internal_name' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml') to object definition code.

 

Step 3

Now we must edit back office template file. We must modify product edit .tpl file located in this path: ADMIN_DIR/themes/default/template/controllers/products/informations.tpl file.(ADMIN_DIR is of course your admin directory). What we have to do there? We must add code with our new field. So, below code:

               <tr>
			<td class="col-left">
				{include file="controllers/products/multishop/checkbox.tpl" field="name" type="default" multilang="true"}
				<label>{l s='Name:'}</label>
			</td>
			<td style="padding-bottom:5px;" class="translatable">
			{foreach from=$languages item=language}
				<div class="lang_{$language.id_lang}" style="{if !$language.is_default}display: none;{/if} float: left;">
						<input class="{$class_input_ajax}{if !$product->id}copy2friendlyUrl{/if} updateCurrentText" size="43" type="text" {if !$product->id}disabled="disabled"{/if}
						id="name_{$language.id_lang}" name="name_{$language.id_lang}"
						value="{$product->name[$language.id_lang]|htmlentitiesUTF8|default:''}"/><sup> *</sup>
					<span class="hint" name="help_box">{l s='Invalid characters:'} <>;=#{}<span class="hint-pointer">&nbsp;</span>
					</span>
				</div>
			{/foreach}
			</td>
		</tr>

add this one:

<tr>
            <td class="col-left">
    		    <label>{l s='Internal Name:'}</label>
    		</td>
    		<td style="padding-bottom:5px;">
    			<input type="text" id="internal_name" name="internal_name" value="{$product->internal_name|default:''}"/>
    		</td>
        </tr>

Code that we added has got definition of our new field. We named this field as you probably remember as "internal_name" - use there your field name :)

 

Effect

New field on product edit page (click to enlarge)

 

 

 

new field in back office

author milos myszczuk
Article by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation
1.4 version 1.4.11 1.6 404 addon admin advertise ahref ajax alpha animation api app application authentication back office backup badge banner basics block bootstrap button cache carrier cart catalog category certificate changelog chat class clear client clip cms code colors columns comments configuration contact container content controller cookie counter country coupon css csv currency customer dashboard database debug default delete delivery desktop developer device disable discount displayNav displayTop download dynamic editor effect empty encrypt engine error exchange exclude export facebook faceshop fade fancoupon fancybox fanpage fatal feature feed field file fix fixed font footer free friendly url front ftp full gallery generate gift global godaddy google google+ gray grid groupon header help hide highlight homefeatured homepage hook hosting hover howto htaccess html html5 ID image import include input instagram installation integration iPhone issue javascript jquery kgb knowhow languages law left likebox link list livingsocial loading log login logo loyality mail mailing maintenance manufacturer marketing marquee mcrypt menu meta mobile modification module movie moving multilanguage multiupload must have mysql news newsletter notification number open graph order override page password performance PHP phpmyadmin picture pinterest plugin popup post prestashop prestashop 1.0 prestashop 1.1 prestashop 1.2 prestashop 1.3 prestashop 1.4 prestashop 1.5 price rules problem product profile promotion proslider purifier quantity query quick tip random rates register reinsurance release reporting reset responsive restore results ribbon rich text right sales search security seo service shadow share shipping shop shopmania slider smarty social networks SQL SSL statistics stock store style subcategory superuser support switcher tab tablet tag tax template text theme tinyMCE tips and tricks tpl tracking translations tree trends trigger tumblr tutorial twitter update upgrade upload variables video visits voucher vulnerability web2print wide widget width window wishlist wysiwyg youtube zip zopim