Jump to content

Error adding a translatable custom fields for products


Recommended Posts

Good morning everybody. I need to add a translatable field in my Prestashop v1.4 backoffice panel.

Here's what I did:

(1) added a new field "info_url" into ps_product_lang table (varchar 250)

(2) added a block of code inside /tabs/AdminProducts.php

<tr>
    <td class="col-left">'.$this->l('More info url:').'</td>
    
    <td style="padding-bottom:5px;" class="translatable">';

    foreach ($this->_languages as $language) {
        echo '<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
        <input size="40" type="text" id="info_url_'.$language['id_lang'].'" name="info_url_'.$language['id_lang'].'" value="'.stripslashes(htmlspecialchars($this->getFieldValue($obj, 'info_url', $language['id_lang']))).'"'.((!$obj->id) ? ' onkeyup="if (isArrowKey(event)) return; copy2friendlyURL();"' : '').' onkeyup="if (isArrowKey(event)) return; updateCurrentText();" onchange="updateCurrentText();" />
        <span class="hint" name="help_box">'.$this->l('Url of the info page') . '</span> 
        </div>';

echo '</td> </tr>'
.... 

(3) added these lines inside classes/Product.php
 

class ProductCore extends ObjectModel
{
    ...
    ...
    /** @var string infourl */
    public      $info_url;

    ...
    ...

    protected $fieldsValidate = array(
    ...
    'info_url' => 'isString',
    );

    protected $fieldsRequiredLang = array('link_rewrite', 'name', 'info_url');

    protected $fieldsSizeLang = array('meta_description' => 255,..., 'info_url' => 250);
    protected $fieldsValidateLang = array( 'meta_description' => 'isGenericName', ..., 'info_url' => 'IsGenericName');

    ...

    public function getFields()
    {
        parent::validateFields();
        $fields['info_url'] = pSQL($this->info_url);
    }

    public function getTranslationsFieldsChild()
    {
        self::validateFieldsLang();

        $fieldsArray = array('meta_description', 'meta_keywords', 'meta_title', 'link_rewrite', 'name', 'available_now', 'available_later', 'info_url');
    }
}

All seems ok in my panel, but when I save, i get this error: 
Warning: strip_tags() expects parameter 1 to be string, array given in /var/www/itart/store/classes/Tools.php on line 530 Fatal error (Product -> info_url = )

What's the matter?

 

Edited by simonedev (see edit history)
Link to comment
Share on other sites

But still the error is for strip_tags function, check where you are calling that function, maybe getfieldvalue().

Try printing your object in the template before you submit for save and see if you are submitting the correct variables.

Link to comment
Share on other sites

But still the error is for strip_tags function, check where you are calling that function, maybe getfieldvalue().

Try printing your object in the template before you submit for save and see if you are submitting the correct variables.

As I said, there was a simple error inside an array. I did not to validate my field in the normal way, there's a special function for translatable ones.

 

Now it works

Link to comment
Share on other sites

×
×
  • Create New...