if ( defined($SESSION) && exists($SESSION->{cartproducts}) && exists($SESSION->{cartproducts}->[0]) && exists($SESSION->{cartproducts}->[0]->{id}) ) { [...] }