Jump to content

Error Handling.


mytheory.

Recommended Posts

Hello all,

I just have a brief question regarding how PS handles errors... more specifically (and as an example), cart.php seems to store its error messages in the $errors array. So for example, if you add more than the qty in stock it would input the "maximum qty already in cart" error into this array.

My question is... how are these arrays outputted? So for the above example, the error in that array is outputted on the screen via a popup. I'm trying to figure out how and where that array is actually being called to display that error and popup. I can't seem to find any code within cart.php that displays the errors, so I was wondering if there was another file(s) that was responsible for executing this array.

I hope this makes sense. Thanks!

Link to comment
Share on other sites

From looking at the bottom of cart.php, it appears that the error messages are displayed when AJAX mode is turned off, but not when AJAX mode is on. In that case, modules/blockcart/blockcart-ajax.php is called, which calls ajax-cart.js with the modules/blockcart/blockcart-json.tpl data. The errors should be accessible in blockcart-ajax.php, but they won't be accessible in ajax-cart.js. To convert a PHP error message to a Javascript popup box is actually quite difficult. The only way I could think of would be use code like the following:

echo '<script type="text/javascript">alert("' . $error . '");</script>';

Link to comment
Share on other sites

Thanks rocky, but this above line of code throws a "TECHNICAL ERROR." I think it has something to do with the extra apostrophes (').

Also, I don't see any errors being called in the blockcart-ajax.php (I'm talking about the "default" errors that PS throws when something out of the ordinary in added to the cart). I see some lines of code near the end of blockcart-json.tpl that seems to be calling the $error array...

{if isset($errors) && $errors}
'hasError' : true,
errors : [
{foreach from=$errors key=k item=error name='errors'}
   '{$error|addslashes|html_entity_decode:2:'UTF-8'}'
   {if !$smarty.foreach.errors.last},{/if}
{/foreach}
]
{else}
'hasError' : false
{/if}



Is this the block of code that is actually displaying all the errors for the cart or should I be looking someplace else?

Thanks!

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...