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

(-)a/Koha/Schema/Result/Item.pm (-3 / +4 lines)
Lines 643-657 __PACKAGE__->belongs_to( Link Here
643
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
643
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
644
);
644
);
645
645
646
use C4::Context;
646
sub effective_itemtype {
647
sub effective_itemtype {
647
    my ( $self ) = @_;
648
    my ( $self ) = @_;
648
649
649
    my $pref = $self->result_source->schema->resultset('Systempreference')->find('item-level_itypes');
650
    my $pref = C4::Context->preference('item-level_itypes');
650
    if ( $pref->value() && $self->itype() ) {
651
    if ( $pref && $self->itype() ) {
651
        return $self->itype();
652
        return $self->itype();
652
    } else {
653
    } else {
653
        warn "item-level_itypes set but no itemtype set for item ($self->itemnumber)"
654
        warn "item-level_itypes set but no itemtype set for item ($self->itemnumber)"
654
          if $pref->value();
655
          if $pref;
655
        return $self->biblioitemnumber()->itemtype();
656
        return $self->biblioitemnumber()->itemtype();
656
    }
657
    }
657
}
658
}
(-)a/t/db_dependent/Items.t (-3 / +2 lines)
Lines 245-254 subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { Link Here
245
    my ( $item ) = $bi[0]->items();
245
    my ( $item ) = $bi[0]->items();
246
246
247
    t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
247
    t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
248
    ok( $item->effective_itemtype() eq 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' );
248
    is( $item->effective_itemtype(), 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' );
249
249
250
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
250
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
251
    ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is enabled' );
251
    is( $item->effective_itemtype(), 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is enabled' );
252
252
253
    # If itemtype is not defined and item-level_level item types are set
253
    # If itemtype is not defined and item-level_level item types are set
254
    # fallback to biblio-level itemtype (Bug 14651) and warn
254
    # fallback to biblio-level itemtype (Bug 14651) and warn
255
- 

Return to bug 11998