Jump to content

Error on custom field in product class


Recommended Posts

Hi, I created a new input for the products. Everything works fine, It saves the field on the database, It shows the input on the admin panel, but when I save the product, it shows an error saving, but it saves it.

The prestashop version is 1.6.1.4

 

 

I created the field on the database.

I created the product.php on the override/classes

 

<?php

class Product extends ProductCore
{
    //ALTER TABLE `ps_product` ADD label_tip VARCHAR(256) default NULL;
    //ALTER TABLE `ps_product_shop` ADD label_tip VARCHAR(256) default NULL;
    public $label_tip;

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['label_tip'] = array('type' => ObjectModel::TYPE_STRING, 'shop' => true, 'validate' => 'isString');
        //self::$definition['fields']['label_tip'] = array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
}

 

I deleted the class_index on the cache.

And I added the field on the informations.tpl

 

<div class="form-group">
        <label class="control-label col-lg-3" for="label_tip">
            <span class="label-tooltip" data-toggle="tooltip"
            title="{l s='Etiqueta img:'}">
                {$bullet_common_field} {l s='Etiqueta img:'}
            </span>
        </label>
        <div class="col-lg-5">
            <input type="text" id="label_tip" name="label_tip" value="{$product->label_tip|htmlentitiesUTF8}" />
        </div>
    </div>

 

Anyone can show me how to solve this issue?

 

Thanks for all.

Link to comment
Share on other sites

Hi,

 

It simply says the tipical error, error while updating product. It's a little bit anoying because it saves the changes, but only shows that error.

Maybe I need to do a override to the function that saves the product on the admin side?

 

Thanks!

Link to comment
Share on other sites

okay

i did the same as you

and i had the same message

qANzMm4.png

 

 

i changed variable name from lablel_tip to lab_tip

 

o79lqXZ.png

 

 

its because prestashop treats label_XXXX as a variable that represents fields related to customization

 

enjoy ! :-)

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...