diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index c1989122c7..ac109dee40 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -32,6 +32,7 @@ use Koha::Authorities; use Koha::Authority::MergeRequest; use Koha::Authority::Types; use Koha::Authority; +use Koha::Libraries; use Koha::SearchEngine; use Koha::SearchEngine::Search; @@ -605,12 +606,17 @@ sub AddAuthority { SetUTF8Flag($record); if ($format eq "MARC21") { + my $userenv = C4::Context->userenv; + my $library; + if ( $userenv && $userenv->{'branch'} ) { + $library = Koha::Libraries->find( $userenv->{'branch'} ); + } if (!$record->leader) { $record->leader($leader); } if (!$record->field('003')) { $record->insert_fields_ordered( - MARC::Field->new('003',C4::Context->preference('MARCOrgCode')) + MARC::Field->new('003', $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode')) ); } my $date=POSIX::strftime("%y%m%d",localtime); @@ -629,8 +635,8 @@ sub AddAuthority { if (!$record->field('040')) { $record->insert_fields_ordered( MARC::Field->new('040','','', - 'a' => C4::Context->preference('MARCOrgCode'), - 'c' => C4::Context->preference('MARCOrgCode') + 'a' => $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode'), + 'c' => $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode') ) ); } diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 12e6e7f470..baaa325e0c 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -568,6 +568,11 @@ sub LinkBibHeadingsToAuthorities { # of change to a core API just before the 3.0 release. if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { + my $userenv = C4::Context->userenv; + my $library; + if ( $userenv && $userenv->{'branch'} ) { + $library = Koha::Libraries->find( $userenv->{'branch'} ); + } $marcrecordauth->insert_fields_ordered( MARC::Field->new( '667', '', '', @@ -582,7 +587,7 @@ sub LinkBibHeadingsToAuthorities { $cite =~ s/[\s\,]*$//; $cite = "Work cat.: (" - . C4::Context->preference('MARCOrgCode') . ")" + . ( $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode') ) . ")" . $bib->subfield( '999', 'c' ) . ": " . $cite; $marcrecordauth->insert_fields_ordered( diff --git a/Koha/Library.pm b/Koha/Library.pm index 44088ea0fd..7cfb749955 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -21,6 +21,8 @@ use Modern::Perl; use Carp; +use C4::Context; + use Koha::Database; use base qw(Koha::Object); @@ -54,6 +56,12 @@ sub add_to_categories { } } +sub get_effective_marcorgcode { + my ( $self ) = @_; + + return $self->marcorgcode || C4::Context->preference("MARCOrgCode"); +} + =head3 type =cut diff --git a/cataloguing/value_builder/marc21_orgcode.pl b/cataloguing/value_builder/marc21_orgcode.pl index 48a30ab23f..6724fc8905 100755 --- a/cataloguing/value_builder/marc21_orgcode.pl +++ b/cataloguing/value_builder/marc21_orgcode.pl @@ -23,9 +23,12 @@ use Modern::Perl; use C4::Context; +use Koha::Libraries; + my $builder = sub { my ( $params ) = @_; - my $org = C4::Context->preference('MARCOrgCode'); + my $library = Koha::Libraries->find( C4::Context->userenv->{'branch'} ); + my $org = $library->get_effective_marcorgcode; return <<"HERE";