Jump to content

how to validate data in hook product update in prestashop


NishantVadgama

Recommended Posts

hello 

I have successfully created new tab in admin with hookDisplayAdminProductsExtra() but when save data with hookActionProductUpdate() save as well but I want to validate before save data and give return back error if exits but I cant return error. It will directly save data.. if I post wrong data then it will give sql error but not mine. I have validate as follows.

public function hookActionProductUpdate()
{
    if (Tools::getValue('id_test'))
    {
          if(!Validate::isInt(Tools::getValue('id_test')))
          {
               $this->context->controller->_errors[] = Tools::displayError('Please enter valid data.');
          }
          if(!count($this->context->controller->_errors))
          {
               someObj = newObj();
               someObj.saveData(Tools::getValue('id_test'));
          }
    }
}
Edited by NishantVadgama (see edit history)
Link to comment
Share on other sites

try without the [] on this line

if(!$this->context->controller->_errors[])

thanks for the help but still not return error that I want I have change as follows

   if(!count($this->context->controller->_errors))
          {
               someObj = newObj();
               someObj.saveData(Tools::getValue('id_test'));
          }
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...