From e7b09d70ab1b6bf529fc8144279df1075aecc593 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Mon, 4 Dec 2017 16:16:52 +0000
Subject: [PATCH] Bug 19743: Update header and footer on each item for checkin
 / checkout / renewal notices

When generating the checkout notice for a patron we only update the
section in between the '---' tags

For template toolkit purposes it means we cannot affect the content
based on more than a single item. For instance, we want to add the total
cost of all items checked out.

Test Plan:
1) Add "Thank you for visiting <<branches.branchname>>." to the bottom of the checkout notice. Below the second '----'.
2) Check out an item to a patron to generate that notice
3) Note the branch name in the notice
4) Update the branch name in the branches editor, change it to something else
5) Check out a 2nd item to that patron
6) Notice the items list updated, but the branch name did not
7) Apply this patch
8) Check out a 3rd item to that patron
9) Notice the branch name updated this time

Signed-off-by: Te Rauhina Jackson <terauhina.jackson@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 C4/Message.pm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/C4/Message.pm b/C4/Message.pm
index 30b71c827c..3783ce85b9 100644
--- a/C4/Message.pm
+++ b/C4/Message.pm
@@ -311,10 +311,12 @@ If passed a string, it'll append the string to the message.
 # $object->append($letter_or_item) -- add a new item to a message's content
 sub append {
     my ($self, $letter_or_item, $format) = @_;
-    my $item;
+    my ( $item, $header, $footer );
     if (ref($letter_or_item)) {
         my $letter   = $letter_or_item;
         my $metadata = _metadata($letter);
+        $header = $metadata->{header};
+        $footer = $metadata->{footer};
         $item = $metadata->{body}->[0];
     } else {
         $item = $letter_or_item;
@@ -325,6 +327,8 @@ sub append {
     }
     my $metadata = $self->metadata;
     push @{$metadata->{body}}, $item;
+    $metadata->{header} = $header;
+    $metadata->{footer} = $footer;
     $self->metadata($metadata);
     my $new_content = $self->render_metadata($format);
     return $self->content($new_content);
-- 
2.11.0