From a729c4a745aea1bafb82377f235ee7512b618055 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 8 Jun 2023 14:15:16 +0200
Subject: [PATCH] Bug 33958: Koha::Biblio::normalized_oclc

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
 C4/Koha.pm     |  2 ++
 Koha/Biblio.pm | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index c98665f2fa..124d5362a0 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -669,6 +669,8 @@ sub GetNormalizedOCLCNumber {
     my ($marcrecord,$marcflavour) = @_;
     return unless $marcrecord;
 
+    $marcflavour ||= C4::Context->preference('marcflavour');
+
     if ($marcflavour ne 'UNIMARC' ) {
         my @fields = $marcrecord->field('035');
         foreach my $field (@fields) {
diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm
index 95c787860a..a82fc01d12 100644
--- a/Koha/Biblio.pm
+++ b/Koha/Biblio.pm
@@ -23,7 +23,7 @@ use List::MoreUtils qw( any );
 use URI;
 use URI::Escape qw( uri_escape_utf8 );
 
-use C4::Koha qw( GetNormalizedISBN GetNormalizedUPC );
+use C4::Koha qw( GetNormalizedISBN GetNormalizedUPC GetNormalizedOCLCNumber );
 
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
@@ -1294,6 +1294,20 @@ sub normalized_upc {
     return C4::Koha::GetNormalizedUPC($marc_record);
 }
 
+=head3 normalized_oclc
+
+    my $normalized_oclc = $biblio->normalized_oclc
+
+Normalizes and returns the OCLC number found in the MARC record.
+
+=cut
+
+sub normalized_oclc {
+    my ( $self ) = @_;
+    my $marc_record = $self->metadata->record;
+    return C4::Koha::GetNormalizedOCLCNumber( $marc_record );
+}
+
 =head3 to_api
 
     my $json = $biblio->to_api;
-- 
2.30.2