Jump to content
bramwolf

can't get rid of frontend Notice message

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 🙂

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks Moritzlost!

That does just what I needed 🙂 (Y) 

You rock! 🙂

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By RyanJ
      I have quite the pickle. 
      The admin no matter where I am at in it, times out constantly. I either get a 504 gateway or and execution timeout. I am banging my head why its across the board. The frontend of the site works great.
      The site does have a lot of pages, 164,889 to be exact.  Most of that is due to image pages created by media manager and having repeater matrix installed which is used on most of the pages. For some reason, if I can manage  click the "Clear file compiler" without it timing out, the site perks back up and I can access the admin again and it is quite speedy. However if I walk away leaving the browser sitting for about an hour and come back, I have to start the process all over again.
      The site has 52 various fields. Not every field is assigned to every template. a lot of the fields are used by the matrix to create a page builder.
      I can't accept that PW can't handle such. I have other sites that run triple the amount of pages, but don't rely on the matrix to build the layout.
      I have disabled any custom module that I thought could possibly cause an issue. I have overwrote every module and the wire core thinking something may have got corrupted. I guess my next step is starting with a fresh install, but I thought I would reach out to see if I am missing something. 
      Some background on pages:
      All the pages are imported using the command line which bootstraps PW and uses the api. This is a dev site, so I blow away the pages if I need to reimport them, until I get it correct.
      PW Version 3.0.172, PHP 7.3, Innodb 5.7.27-30.
      I appreciate any suggestions or thoughts. 

       

       

    • By dfile
      Hello,
      I am running ProcessWire 3.0.165 but $input->urlSegmentLast or $input->urlSegment(-1) does not work as expected.
      Or do I something wrong?
      Thank you.

    • By bramwolf
      Hi Guys,

      I found here: https://processwire.com/docs/selectors/#finding2 that I can exclude results from my $pages->find($selctor); query by using parent!=123 ( parent ID ) But I was wondering if I can
      also do so based on the parent template? I've tried doing it by itterating over the matches array and dropping the matches with the parent but since the result is limited for use with the paginator
      it only drops the items from the batch displayed on this page. Say from the results within matches 0 - 20 and not the entire 0 - 220.

      Anybody have a idea of how to achieve this? 🙂

      Thanks in advace!
      Bram 
    • By LAPS
      I've pages using the custom-page-template and I would like to display a simple message at the top of the page form when editing those pages in the Admin.
      I thought about hooking ProcessPageEdit::buildForm() but I do not well how to use that hook in order to display the message just for the custom-page-template pages.
      Any help?
       
       
      UPDATE: Solution found
      wire()->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) { $ProcessPageEdit = $event->object; $form = $event->arguments('form'); switch ($ProcessPageEdit->getPage()->template->name) { case 'custom-page-template': $form->prependMarkup("<div style='margin-bottom: 3.6em; margin-top: 1em; background: #ffd;'>MY MESSAGE</div>"); break; default: // do nothing } }); Any improvement is welcome!
    • By Sten
      Sorry I can't find any submit button to save my configuration on a template in the admin interface. The file is fine.
×
×
  • Create New...