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

(-)a/Koha/Exceptions/Item/Bundle.pm (+49 lines)
Line 0 Link Here
1
package Koha::Exceptions::Item::Bundle;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Exception;
21
22
use Exception::Class (
23
24
    'Koha::Exceptions::Item::Bundle' => {
25
        isa => 'Koha::Exception',
26
    },
27
    'Koha::Exceptions::Item::Bundle::IsBundle' => {
28
        isa         => 'Koha::Exceptions::Item::Bundle',
29
        description => "A bundle cannot be added to a bundle",
30
    }
31
);
32
33
=head1 NAME
34
35
Koha::Exceptions::Item::Bundle - Base class for Bundle exceptions
36
37
=head1 Exceptions
38
39
=head2 Koha::Exceptions::Item::Bundle
40
41
Generic Item::Bundle exception
42
43
=head2 Koha::Exceptions::Item::Bundle::IsBundle
44
45
Exception to be used when attempting to add one bundle into another.
46
47
=cut
48
49
1;
(-)a/Koha/Item.pm (+6 lines)
Lines 38-43 use Koha::CirculationRules; Link Here
38
use Koha::CoverImages;
38
use Koha::CoverImages;
39
use Koha::Exceptions::Item::Transfer;
39
use Koha::Exceptions::Item::Transfer;
40
use Koha::Item::Attributes;
40
use Koha::Item::Attributes;
41
use Koha::Exceptions::Item::Bundle;
41
use Koha::Item::Transfer::Limits;
42
use Koha::Item::Transfer::Limits;
42
use Koha::Item::Transfers;
43
use Koha::Item::Transfers;
43
use Koha::ItemTypes;
44
use Koha::ItemTypes;
Lines 1608-1613 Adds the bundle_item passed to this item Link Here
1608
sub add_to_bundle {
1609
sub add_to_bundle {
1609
    my ( $self, $bundle_item ) = @_;
1610
    my ( $self, $bundle_item ) = @_;
1610
1611
1612
    Koha::Exceptions::Item::Bundle::IsBundle->throw()
1613
      if ( $self->itemnumber eq $bundle_item->itemnumber
1614
        || $bundle_item->is_bundle
1615
        || $self->in_bundle );
1616
1611
    my $schema = Koha::Database->new->schema;
1617
    my $schema = Koha::Database->new->schema;
1612
1618
1613
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
1619
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
(-)a/Koha/REST/V1/Items.pm (+8 lines)
Lines 229-234 sub add_to_bundle { Link Here
229
                }
229
                }
230
            );
230
            );
231
        }
231
        }
232
        elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) {
233
            return $c->render(
234
                status => 400,
235
                openapi => {
236
                    error => 'Bundles cannot be nested'
237
                }
238
            );
239
        }
232
        else {
240
        else {
233
            $c->unhandled_exception($_);
241
            $c->unhandled_exception($_);
234
        }
242
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-1 / +7 lines)
Lines 1784-1789 Note that permanent location is a code, and location may be an authval. Link Here
1784
                          }
1784
                          }
1785
                      } else if ( data.status === 404 ) {
1785
                      } else if ( data.status === 404 ) {
1786
                          $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>');
1786
                          $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>');
1787
                      } else if ( data.status === 400 ) {
1788
                          var response = data.responseJSON;
1789
                          if ( response.error === "Bundles cannot be nested" ) {
1790
                              $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' is a bundle and bundles cannot be nested").format(barcode)+'</div>');
1791
                          } else {
1792
                              $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>');
1793
                          }
1787
                      } else {
1794
                      } else {
1788
                          $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>');
1795
                          $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>');
1789
                      }
1796
                      }
1790
- 

Return to bug 31080