gdfgdfg
gdfgdfg

Reputation: 3566

Add custom field PrestaShop 1.6

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:

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 third-party jQuery plugin, for the example ?

Upvotes: 0

Views: 592

Answers (1)

Rolige
Rolige

Reputation: 948

Lang fields are not related with the table ps_product, lang fields are related to the table ps_product_lang, that's your problem.

Upvotes: 1

Related Questions