Jump to content

can't get rid of frontend Notice message


bramwolf
 Share

Recommended Posts

Hi Guys,

I found that my site is producing this notice on the front end, even when $config->debug = false and also when admin is
not even logged in. How do I keep the site from displaying this message to front end users? The notice is about a few vars
being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance
wrap the $discountCode = blabla in a if($order) { ...  } statement than I'm again testing for $order which isn't a object in this case
which throws another notice..

This is the notice:
1067507995_Schermafbeelding2020-05-04om10_51_20.thumb.png.79d7382001c96ee91562ab50619d4a32.png

Here is my current code:

// PAD DISCOUNT CODE HOOK
	
		// First we see if we have active discount code
    	if ($this->session->orderId) {
    	  $order = $this->pages->get($this->session->orderId);
    	}
	
		if($product->geen_korting == 1) {
			$nodisc = $product->geen_korting;
		} else {
			$nodisc = $product->parent->geen_korting;
		}
	
	   	$discountCode = $this->sanitizer->selectorValue($order->pad_discount_code);
		$dc = $this->pages->get("template=paddiscount, title=$discountCode");
	
	    if ($dc->id) {
	
	  		if ($nodisc) {
        		$discount = 0;
      		} elseif ($dc->pad_percentage) {
        		$discount = $newprice * ($dc->pad_percentage / 100);
      		}
		}

    	$event->return = $newprice - $discount;


Thanks in advance 🙂

Link to comment
Share on other sites

Quote

The notice is about a few vars being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance wrap the $discountCode = blabla in a if($order) { ...  } statement than I'm again testing for $order which isn't a object in this case which throws another notice..

You can check if a variable is defined with isset. This will not throw an error even if the variable does not exist in the current scope. If you want to also check if the variable is not empty (falsy), you can use empty, which will also not throw an error if the the variable does not exist.

// this will throw a warning if $order does not exist
if ($order) {}

// this will never throw a warning, and will be true if $order is defined, even if it's value is null
if (isset($order)) {}

// this will never throw a warning, and will be true if $order is defined AND a holds non-falsy value
if (!empty($order)) {}

As a side note, in your production environment you should configure PHP to not display any errors on the webpage, and instead log those to a logfile that only you have access to. To do this, change the following settings in your PHP.ini:

display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
log_errors = On
error_log = /path/to/error.log

 

  • Like 4
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
 Share

×
×
  • Create New...