Isoo Posted October 25, 2016 Share Posted October 25, 2016 (edited) my prestashop module return some error messages and i get more questions about solve this errors i want add some tips for this errors. when insert new product to database this code line return error mesage for example "name is empty" $lang_field_error = $productObj->validateFieldsLang(self::UNFRIENDLY_ERROR, true) and i show errror msg look like this $error_tmp = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); if ($error_tmp != '') { $this->error_msg[] = sprintf( Tools::displayError('Product (ID: %1$s) cannot be saved. %2$s'), (isset($product['id_product']) && !empty($product['id_product'])) ? Tools::safeOutput( $product['id_product'] ) : 'No ID', $error_tmp ); } $productObj->validateFieldsLang() this method comes from ObjectModel class public function validateFieldsLang($die = true, $error_return = false) { foreach ($this->def['fields'] as $field => $data) { if (empty($data['lang'])) { continue; } $values = $this->$field; // If the object has not been loaded in multilanguage, then the value is the one for the current language of the object if (!is_array($values)) { $values = array($this->id_lang => $values); } // The value for the default must always be set, so we put an empty string if it does not exists if (!isset($values[Configuration::get('PS_LANG_DEFAULT')])) { $values[Configuration::get('PS_LANG_DEFAULT')] = ''; } foreach ($values as $id_lang => $value) { if (is_array($this->update_fields) && empty($this->update_fields[$field][$id_lang])) { continue; } $message = $this->validateField($field, $value, $id_lang); if ($message !== true) { if ($die) { throw new PrestaShopException($message); } return $error_return ? $message : false; } } } return true; } and return error msg for display, for example if error msg is "the name field is empty" i want add error tip look like "you products name cannot be empty " I must catch errors kind,(not from string) Can anyone Help me? Edited October 25, 2016 by Isoo (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now