add a field in edit product page of prestashop admin

I have add a field "mystock" in product table of prestashop database. Now i want to display/edit this filed in edit product page. It also be update when product will update.


ANSWERS:


This process require some work around in steps. Below i have listed them.

1) Open classes/Product.php. Place public $mystock; in the class properties list, which you can see after the class is started.

2) Down the file, find public static $definition = array( , it will be a long array. Find the 'fields' => array( in it, and there you will see all the database fields placed with validation, data types etc. Place your mystock there in that array as another item and place the correct validations and data types like placed for other fields.

3) Now open adminFolder/themes/default/template/controllers/products/informations.tpl and place your field with the correct name and id in the appropriate place. Please note that the field name / id both should be same like the db field name and the one we added in the Products.php class.

Thats it, Hope you understand the process and will make it work.

Thank you


this one works for me on prestashop 1.5.4

add a file Product.php to \override\classes containing:

    <?php
    Product::$definition['fields']['mystock'] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt');
    class Product extends ProductCore 
    { 
       public $mystock; 
    } 

...supposing you need a field to enter a number.

then 3) of altafhussain's answer

don't forget to add your field to the DB, for number field:
ALTER TABLE ps_product ADD mystock INT NOT NULL;


I came across this article and build my component based on it and it seems to be cleanest solution: basically it describes how to make a module, which adds multilingual field in custom panel on product editing page..

NO need to edit templates, core files or add override files.


The best comprehensive solution in four steps is:

1) add a file Product.php to \override\classes containing:

<?php
Product::$definition['fields']['mystock'] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt');
class Product extends ProductCore 
{ 
   public $mystock; 
} 

2) open adminFolder/themes/default/template/controllers/products/informations.tpl and place your field with the correct name and id in the appropriate place.

3) delete file cache/class_index.php

4) add your field to the DB, for number field:

ALTER TABLE ps_product ADD mystock INT NOT NULL;

[Thanks to Bell418 for 1) and 4) and to Altaf Hussain for 2)]


Thanks altafhussain. You have to add your field to both 'products_shop' and 'products' tables.

ALTER TABLE ps_product_shop ADD `mystock` int NOT NULL DEFAULT 0;
ALTER TABLE ps_product ADD `mystock` int NOT NULL DEFAULT 0;

I'm using ps 1.6.0.6



 MORE:


 ? Strange Characters in database text: Ã, Ã, ¢, â‚ €,
 ? Facebook Like Button Causing Horizontal Scrollbar
 ? How to call a php function inside a smarty .tpl file?
 ? How to get url of current theme in prestashop's .tpl file&
 ? Prestashop no errors / blank page
 ? Issue with creating an intermediate pending order
 ? Products And Order Status Missing In Order Section Backoffice
 ? Why does prestashop project migrated from website to localhost redirect to website?
 ? Prestashop Product Customizations - Saving To Cart
 ? PHP - Random round behavior issue