View | Details | Raw Unified | Return to bug 38093
Collapse All | Expand All

(-)a/Koha/Biblio.pm (+40 lines)
Lines 1999-2004 sub link_marc_host { Link Here
1999
    return $self;
1999
    return $self;
2000
}
2000
}
2001
2001
2002
=head3 link_marc_bundled_item
2003
2004
  $biblio->link_marc_bundled_item({ bundled_item => $item });
2005
  $biblio->link_marc_bundled_item({ bundled_item => $itemnumber });
2006
2007
Links a parent MARC record to the child. Expects either the biblio object or biblionumber of the host to link to.
2008
2009
=cut
2010
2011
sub link_marc_bundled_item {
2012
    my ( $self, $params ) = @_;
2013
2014
    my $host_link_field;
2015
    my $bundled_item;
2016
    if ( ref( $params->{bundled_item} ) eq 'Koha::Item' ) {
2017
        $bundled_item = $params->{bundled_item};
2018
    } else {
2019
        my $bundled_item = Koha::Items->find( $params->{host} );
2020
    }
2021
2022
    my $record = $self->metadata->record;
2023
    my $tag    = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '462' : '774';
2024
    # Remove fields that references the same itemnumber
2025
    # to avoid duplicates
2026
    my @fields           = $record->field($tag);
2027
    my @duplicate_fields = grep { $_->subfield('9') eq $bundled_item->itemnumber; } @fields;
2028
    $record->delete_fields(@duplicate_fields);
2029
    my $field = MARC::Field->new(
2030
        $tag, '', '',
2031
        't' => $bundled_item->biblio->title,
2032
        '0' => $bundled_item->biblionumber,
2033
        '9' => $bundled_item->itemnumber
2034
    );
2035
    $record->insert_fields_ordered($field);
2036
2037
    C4::Biblio::ModBiblio( $record, $self->biblionumber );
2038
2039
    return $self;
2040
}
2041
2002
=head3 recalls
2042
=head3 recalls
2003
2043
2004
    my $recalls = $biblio->recalls;
2044
    my $recalls = $biblio->recalls;
(-)a/Koha/REST/V1/Items.pm (-1 / +1 lines)
Lines 327-332 sub add_to_bundle { Link Here
327
        my $link = $item->add_to_bundle( $bundle_item, $options );
327
        my $link = $item->add_to_bundle( $bundle_item, $options );
328
        if ($add_link) {
328
        if ($add_link) {
329
            $bundle_item->biblio->link_marc_host( { host => $item->biblio } );
329
            $bundle_item->biblio->link_marc_host( { host => $item->biblio } );
330
            $item->biblio->link_marc_bundled_item( { bundled_item => $bundle_item } );
330
        }
331
        }
331
        return $c->render(
332
        return $c->render(
332
            status  => 201,
333
            status  => 201,
333
- 

Return to bug 38093