Jump to content

Catch PrestaShopException in ajax


Amazzing

Recommended Posts

Hi everyone,
 
I am updating a product using an ajax request.
 
The php code is really basic:
$product = new Product($id);
$produc->description[$lang] = $new_description;
$product->save();
...
die(Tools::jsonEncode($result));

But if for any reason product is not saved, function stops executing and I get an ajax error.

 
For example, I have included an iframe in $new descrpiption for purpose. And I don't allow iframes in prestashop settings. So, if I call that ajax file directly from browser with same params, I can see that there is a Prestashop exception 'Property Product->description is not valid'.
 
So, how can I catch this kind of error, and show it to user?
 
Of course, I can validate the $new_descrtiption before saving the product. But first: in this case, validation code will be executed twice. Second: I am planning to save different fields, so a lot of validation rules have be hardcoded thus making code less adjustable to prestashop updates
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...