add a field in edit product page of prestashop adm

2019-02-05 10:14发布

问题:

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.

回答1:

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



回答2:

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;



回答3:

I came across this article and build my component based on it and it seems to be cleanest solution: http://nemops.com/prestashop-products-new-tabs-fields/ 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.



回答4:

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)]



回答5:

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