Skip to content

Commit

Permalink
Add ability to send CURBSIDE notice for Holds module when a pickup is…
Browse files Browse the repository at this point in the history
… scheduled.
  • Loading branch information
kylemhall committed Aug 17, 2020
1 parent 4a96de8 commit d464a73
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.5] - 2020-08-17
## Changed
- Added support for CURBSIDE notice, which will be sent upon initial creation of a curbside pickup

## [1.0.4] - 2020-08-12
## Changed
- Remove dangling code, make fields required, prevent ISE when patron not found.

## [1.0.3] - 2020-08-11
## Added
- This changelog!
Expand All @@ -12,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Switched from `use` to `require` to allow installation to proceed without errors. Still requires plack to be restarted before using the plugin.
### Removed
- Installation debugging code
- Installation debugging code.

## [1.0.1] - 2020-08-11
### Added
Expand Down
62 changes: 62 additions & 0 deletions Koha/Plugin/Com/ByWaterSolutions/CurbsidePickup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ sub tool {
notes => $notes,
}
)->store();
$self->_notify_new_pickup($curbside_pickup);
}
}
elsif ( $action eq 'cancel' ) {
Expand Down Expand Up @@ -221,6 +222,67 @@ sub tool {
$self->output_html( $template->output() );
}

sub _notify_new_pickup {
my ($self, $pickup_id) = @_;

my $pickup = Koha::CurbsidePickups->find($pickup_id);

my $patron = $pickup->patron;

# Try to get the borrower's email address
my $to_address = $patron->notice_email_address;

my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
borrowernumber => $borrowernumber,
message_name => 'Hold_Filled'
} );

my $library = $pickup->library->unblessed;

my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress');

my %letter_params = (
module => 'reserves',
branchcode => $pickup->branchcode,
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $patron->unblessed,
},
substitute => {
curbside_pickup => $pickup,
}
);

my $send_notification = sub {
my ( $mtt, $letter_code ) = (@_);
return unless defined $letter_code;
$letter_params{letter_code} = $letter_code;
$letter_params{message_transport_type} = $mtt;
my $letter = C4::Letters::GetPreparedLetter ( %letter_params );
unless ($letter) {
warn "Could not find a letter called '$letter_params{'letter_code'}' for $mtt in the 'reserves' module";
return;
}

C4::Letters::EnqueueLetter( {
letter => $letter,
borrowernumber => $borrowernumber,
from_address => $admin_email_address,
message_transport_type => $mtt,
} );
};

while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
next if (
( $mtt eq 'email' and not $to_address ) # No email address
or ( $mtt eq 'sms' and not $patron->smsalertnumber ) # No SMS number
);

$send_notification($mtt, 'CURBSIDE');
}
}

sub opac_js {
my ($self) = @_;

Expand Down

0 comments on commit d464a73

Please sign in to comment.