simonedev Posted April 21, 2015 Share Posted April 21, 2015 (edited) 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 April 21, 2015 by simonedev (see edit history) Link to comment Share on other sites More sharing options...
yaniv14 Posted April 21, 2015 Share Posted April 21, 2015 I have no experience in PS 1.4 but based on the error, you are calling strip_tags function and instead of passing it a string as 1st argument, you are passing an array. Hope it helps. Link to comment Share on other sites More sharing options...
simonedev Posted April 21, 2015 Author Share Posted April 21, 2015 There was an error inside an array of parameters. Link to comment Share on other sites More sharing options...
yaniv14 Posted April 21, 2015 Share Posted April 21, 2015 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 More sharing options...
simonedev Posted April 21, 2015 Author Share Posted April 21, 2015 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 More sharing options...
yaniv14 Posted April 21, 2015 Share Posted April 21, 2015 Oops, my bad. Link to comment Share on other sites More sharing options...
Recommended Posts