24/7 Support: 800.608.6482

Videos

Developer Videos

Videos | Debugging Custom Fields

One nice feature about Miva Merchant Custom Fields is they provide a built in debug function. This function can be used anytime you have problems reading or writing a custom field. There may be a case where you have some custom field logic on a page and for some reason or another it's not working. The Debug function was created to specifically help identify these type of issues.
ver. 9.0 and later

Video Transcript

One nice feature about Miva Merchant’s custom fields is that they provide a built in debug function. This function can be used any time you’re having problems reading or writing a custom field. There may be a case where you have some custom field logic on a page and for some reason or another, it’s not working. Maybe it’s a syntax error, or a typo, or a combination of the two. The debug function was created to specifically help identify these type of issues. It will output error messages displaying things like syntax issues, or maybe you’re trying to reference a product or custom field that does not exist. Here is what the item tax looks like when you’re using the debug function. It’s the same as the rest of the custom fields functions. In the product tag instead of using read product code or read product id, you just simply put “Debug ()” with empty parameters.

Now let’s copy this and drop it into Miva and see what it actually outputs. So I’m going to go to the About Us page and add this to the page header. So back at the front end, here I am at the About Us page. Now if I refresh this page, you’ll see in the top right “Custom Fields Debug Console.” It shows no errors have occurred. This is what it outputs to the page whenever you have that debug function called. Since I don’t have any custom field logic code here so there’s nothing to output. We will create some errors in a second and see how it gets displayed.

One important thing to know with this, is that any page that has this debug function will always display this in the top right. You probably don’t want to do that on a live site. So an easy solution using Miva’s “if statement” is to limit it to your ip address only. This is a common practice we use every day. Any time you’re using this debug function, you first need to wrap it in an “if statement” so you only show it for your ip address. This way, regular customers and shoppers won’t see any of the error messages. You can look at the bottom of this page to see what the code looks like. Just make sure to replace the ip address with your own. Once you upload this, it should only show the error console log if you’re coming from your ip address, which is exactly what we want.

We’ll take this code and replace the normal debug code in the header on our About Us page. When we refresh, we should get the exact same thing because we are coming from our own ip address. Let’s add a custom field to this page so we can see how this debug console works. Back in the Miva Merchant Admin and above the debug function call. One important thing to note is that the debug function call but be at the bottom of any of your custom fields calls you have on the page. It won’t output any error messages on custom field calls after it. So always make sure that the debug function is the last thing on the page. So here I am going to paste in some code for “read product code” and the product code I’m going to work on is a product code of test, my custom field code is msrp, and I’m saving that value back into g.msrp.

Let’s output that to the page and make sure it actually works. Once we save it, go back onto our Storefront page and hit refresh, you’ll see it now has our MSRP price on the page, so we know that custom field function is working and we have no errors here. Now let’s actually introduce an error to see how it gets displayed. Instead of test I’m just going to add some fake text to it. This product code shouldn’t exist. We’ll hit update and then go back over to our store and hit refresh. As you can see the msrp code is now broken and on the Custom Field Debug Console we actually get an error message. So it tells us “Product Code (and then the fake product code I put in) can not be found. This is great debugging information to be able to identify why something isn’t working. If I mistype the custom field code because of a typo or if it doesn’t exist, you should get the same error message. If I add a 1 to the end of this fake code I put in, hit update then go back over to our store and hit refresh, you’ll see we got a new error message saying custom field msrp1 could not be found. This is a great way to identify problems within your custom fields syntax.

The last thing this custom field debug output is actually syntax errors. Say you forgot to add the closing quote to a statement. This will output an error to show you what’s wrong. Let me go back and introduce a new error here. I’m going to fix this and I’m going to get rid of this trailing single quote here. I’ll hit update, then go back to our store and hit refresh. Now you’ll see the error “Missing single quote.”

The Custom Field Debug function is a great tool to help you troubleshoot and solve problems when things aren’t working as you would expect. It will output useful error messages to hopefully help you identify the problem quickly.



Example Code

Reference Documentation




Looking for Developer Docs?

We have a whole section for that, including: Developer Training Series, Template Language docs, Module Development tutorials and much, much more.

Head to the Developer Section

This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

Accept

Copyright © 1997 – 2024 Miva®, Miva Merchant®, MivaPay®, MivaCon®, Camp Miva®, Miva Connect®, Miva, Inc. All Rights Reserved.