From 35293612a8d0efa932bf376b7855b17cc29d6d5c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Feb 2024 07:55:55 +0000 Subject: [PATCH] Bug 35969: Add error code in opac-sendbasket.pl No need to carp about empty basket or no reply address. Just add a simple explanation on the form. Note that it makes no sense to show the form if the patron has no email address. We need it as reply-to. Test plan: Try opac-sendbasket.pl?bib_list=null Remove email address from your account, try again. Signed-off-by: Marcel de Rooy Signed-off-by: David Nind Signed-off-by: Emily Lamancusa Signed-off-by: Katrin Fischer --- .../en/modules/opac-sendbasketform.tt | 8 ++++- opac/opac-sendbasket.pl | 31 +++++++------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt index edfec7b919..75ab018779 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt @@ -22,7 +22,13 @@ [% IF ( error ) %]
-

There was an error sending the cart.

+ [% IF error == 'NO_BODY' %] +

There was an error sending the cart: No valid biblio records found.

+ [% ELSIF error == 'NO_REPLY_ADDRESS' %] +

Since we do not have your email address, we cannot send a mail. We need your email address as reply-to address.

+ [% ELSE %] +

There was an error sending the cart.

+ [% END %]
[% END %] diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl index 65dc94b9e6..de984d01c3 100755 --- a/opac/opac-sendbasket.pl +++ b/opac/opac-sendbasket.pl @@ -21,13 +21,9 @@ use Modern::Perl; use CGI qw ( -utf8 ); use Encode; -use Carp qw( carp ); -use Try::Tiny qw( catch try ); -use C4::Biblio qw( - GetMarcSubjects -); -use C4::Auth qw( get_template_and_user ); +use C4::Auth qw( get_template_and_user ); +use C4::Biblio qw(GetMarcSubjects); use C4::Output qw( output_html_with_http_headers ); use C4::Templates; use Koha::Biblios; @@ -43,16 +39,14 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( type => "opac", } ); +my $patron = Koha::Patrons->find($borrowernumber); +my $user_email = $patron ? $patron->notice_email_address : undef; my $op = $query->param('op') || q{}; my $bib_list = $query->param('bib_list') || ''; my $email_add = $query->param('email_add'); -if ( $op eq "cud-send" && $email_add ) { - - my $patron = Koha::Patrons->find($borrowernumber); - my $user_email = $patron->notice_email_address; - +if ( $op eq "cud-send" && $email_add && $user_email ) { my $comment = $query->param('comment'); my @bibs = split( /\//, $bib_list ); @@ -63,12 +57,7 @@ if ( $op eq "cud-send" && $email_add ) { } if ( !defined $iso2709 ) { - carp "Error sending mail: empty basket"; - $template->param( error => 1 ); - } - elsif ( !defined $user_email or $user_email eq '' ) { - carp "Error sending mail: sender's email address is invalid"; - $template->param( error => 1 ); + $template->param( error => 'NO_BODY' ); } else { my %loops = ( biblio => \@bibs, ); @@ -111,8 +100,12 @@ if ( $op eq "cud-send" && $email_add ) { $template->param( email_add => $email_add ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -} -else { + +} elsif( !$user_email ) { + $template->param( email_add => 1, error => 'NO_REPLY_ADDRESS' ); + output_html_with_http_headers $query, $cookie, $template->output; + +} else { my $new_session_id = $query->cookie('CGISESSID'); $template->param( bib_list => $bib_list, -- 2.20.1