@@ -, +, @@ chosen SIP field where and are item table columns of your choosing messages using that item. corrosponding fields! --- C4/SIP/ILS/Item.pm | 32 ++++++++++++++++++++++++++++++++ C4/SIP/Sip/MsgType.pm | 5 +++++ etc/SIPconfig.xml | 1 + t/db_dependent/SIP/Message.t | 31 ++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) --- a/C4/SIP/ILS/Item.pm +++ a/C4/SIP/ILS/Item.pm @@ -14,6 +14,7 @@ use Carp; use Template; use C4::SIP::ILS::Transaction; +use C4::SIP::Sip qw(add_field); use C4::Debug; use C4::Context; @@ -87,6 +88,8 @@ sub new { $self->{'collection_code'} = $item->ccode; $self->{ 'call_number' } = $item->itemcallnumber; + $self->{object} = $item; + my $it = $item->effective_itemtype; my $itemtype = Koha::Database->new()->schema()->resultset('Itemtype')->find( $it ); $self->{sip_media_type} = $itemtype->sip_media_type() if $itemtype; @@ -387,6 +390,35 @@ sub fill_reserve { } return ModReserveFill($hold); } + +=head2 build_additional_item_fields_string + +This method builds the part of the sip message for additional item fields +to send in the item related message responses + +=cut + +sub build_additional_item_fields_string { + my ( $self, $server ) = @_; + + my $string = q{}; + + if ( $server->{account}->{item_field} ) { + my @fields_to_send = + ref $server->{account}->{item_field} eq "ARRAY" + ? @{ $server->{account}->{item_field} } + : ( $server->{account}->{item_field} ); + + foreach my $f ( @fields_to_send ) { + my $code = $f->{code}; + my $value = $self->{object}->$code; + $string .= add_field( $f->{field}, $value ); + } + } + + return $string; +} + 1; __END__ --- a/C4/SIP/Sip/MsgType.pm +++ a/C4/SIP/Sip/MsgType.pm @@ -607,6 +607,8 @@ sub handle_checkout { } } + $resp .= $item->build_additional_item_fields_string( $server ) if $item; + if ( $protocol_version >= 2 ) { # Financials : return irrespective of ok status @@ -674,6 +676,7 @@ sub handle_checkin { if ($item) { $resp .= add_field( FID_PERM_LOCN, $item->permanent_location, $server ); $resp .= maybe_add( FID_TITLE_ID, $item->title_id, $server ); + $resp .= $item->build_additional_item_fields_string( $server ); } if ( $protocol_version >= 2 ) { @@ -1181,6 +1184,8 @@ sub handle_item_information { $resp .= maybe_add( FID_SCREEN_MSG, $item->screen_msg, $server, $server ); $resp .= maybe_add( FID_PRINT_LINE, $item->print_line, $server ); + + $resp .= $item->build_additional_item_fields_string( $server ); } $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); --- a/etc/SIPconfig.xml +++ a/etc/SIPconfig.xml @@ -62,6 +62,7 @@ + 0 --- a/t/db_dependent/SIP/Message.t +++ a/t/db_dependent/SIP/Message.t @@ -21,7 +21,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::MockObject; use Test::MockModule; use Test::Warn; @@ -123,6 +123,35 @@ subtest 'Lastseen response' => sub { $schema->storage->txn_rollback; }; + +subtest "Test build_additional_item_fields_string" => sub { + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 2; + + my $builder = t::lib::TestBuilder->new(); + + my $item = $builder->build( { source => 'Item' } ); + my $ils_item = C4::SIP::ILS::Item->new( $item->{barcode} ); + + my $server = {}; + $server->{account}->{item_field}->{code} = 'itemnumber'; + $server->{account}->{item_field}->{field} = 'XY'; + my $attribute_string = $ils_item->build_additional_item_fields_string( $server ); + is( $attribute_string, "XY$item->{itemnumber}|", 'Attribute field generated correctly with single param' ); + + $server = {}; + $server->{account}->{item_field}->[0]->{code} = 'itemnumber'; + $server->{account}->{item_field}->[0]->{field} = 'XY'; + $server->{account}->{item_field}->[1]->{code} = 'biblionumber'; + $server->{account}->{item_field}->[1]->{field} = 'YZ'; + $attribute_string = $ils_item->build_additional_item_fields_string( $server ); + is( $attribute_string, "XY$item->{itemnumber}|YZ$item->{biblionumber}|", 'Attribute field generated correctly with multiple params' ); + + $schema->storage->txn_rollback; +}; + # Here is room for some more subtests # END of main code --