Bug 14570: Make it possible to add multiple guarantors to a record
[koha.git] / Koha / Patrons / Import.pm
index b18db0d..3575b8a 100644 (file)
@@ -216,6 +216,11 @@ sub import_patrons {
             next LINE;
         }
 
+        my $relationship        = $borrower{relationship};
+        my $guarantor_id        = $borrower{guarantor_id};
+        delete $borrower{relationship};
+        delete $borrower{guarantor_id};
+
         if ($borrowernumber) {
 
             # borrower exists
@@ -352,6 +357,17 @@ sub import_patrons {
                 );
             }
         }
+
+        # Add a guarantor if we are given a relationship
+        if ( $guarantor_id ) {
+            Koha::Patron::Relationship->new(
+                {
+                    guarantee_id => $borrowernumber,
+                    relationship => $relationship,
+                    guarantor_id => $guarantor_id,
+                }
+            )->store();
+        }
     }
 
     return {