Jump to content

Create custom field in admin product page - PrestaShop 1.6


vladi160

Recommended Posts

Hi, I am trying to add a custom field (HTML textbox) to the admin section in product page. I am following some of the answers in this forum and from Google.

This is my code in override/classes/Product.php class:

class Product extends ProductCore{

    public $product_modal;

    function __construct( $id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null ) {

    	Product::$definition['fields']['product_modal'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
	    parent::__construct( $id_product, $full, $id_lang, $id_shop, $context );
    }

This is in the `informations.tpl` file:

	<div class="form-group">
		<label class="control-label col-lg-3" for="product_modal">
			<span class="label-tooltip" data-toggle="tooltip"
				  title="{l s='Product modal'}">
				{$bullet_common_field} {l s='Product modal'}
			</span>
		</label>
		<div class="col-lg-3">
			<input type="text" id="product_modal" name="product_modal" value="{$product->product_modal|escape:'html':'UTF-8'}" />
		</div>
	</div>

I see the new field in product admin page, but when I try to save I am getting this error:

Quote

An error occurred while updating an object. product ()

How can I add a new field in Product page and is there standard PrestaShop way to make that field like description field textbox or I need to use some kind of third-party jQuery plugin, for the example ?

Link to comment
Share on other sites

  • 1 year later...

Hi!

Try change Product to self and remove the validate.

Product::$definition['fields']['product_modal'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

to

self::$definition['fields']['product_modal'] = array('type' => self::TYPE_STRING, 'shop' => true, 'lang' => true );

And on informations.tpl change

<input type="text" id="product_modal" name="product_modal" value="{$product->product_modal|escape:'html':'UTF-8'}" />

to

{include file="controllers/products/input_text_lang.tpl"
                languages=$languages
                input_value=$product->product_modal
                input_name='product_modal'}

 

Then on front you will have access to this new field via {$product->product_modal}

I hope this will be enough!

  • Like 1
Link to comment
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
×
×
  • Create New...