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

(-)a/C4/Letters.pm (-2 / +4 lines)
Lines 1551-1560 sub _get_tt_params { Link Here
1551
            my $fk = $config->{$table}->{fk};
1551
            my $fk = $config->{$table}->{fk};
1552
1552
1553
            if ( $is_a_loop ) {
1553
            if ( $is_a_loop ) {
1554
                unless ( ref( $tables->{$table} ) eq 'ARRAY' ) {
1554
                my $values = $tables->{$table} || [];
1555
                unless ( ref( $values ) eq 'ARRAY' ) {
1555
                    croak "ERROR processing table $table. Wrong API call.";
1556
                    croak "ERROR processing table $table. Wrong API call.";
1556
                }
1557
                }
1557
                my $objects = $module->search( { $pk => { -in => $tables->{$table} } } );
1558
                my $key = $pk ? $pk : $fk;
1559
                my $objects = $module->search( { $key => { -in => $values } } );
1558
                $params->{ $config->{$table}->{plural} } = $objects;
1560
                $params->{ $config->{$table}->{plural} } = $objects;
1559
            }
1561
            }
1560
            elsif ( $ref eq q{} || $ref eq 'HASH' ) {
1562
            elsif ( $ref eq q{} || $ref eq 'HASH' ) {
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +15 lines)
Lines 283-289 $prepared_letter = GetPreparedLetter( Link Here
283
is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' );
283
is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' );
284
284
285
subtest 'loops' => sub {
285
subtest 'loops' => sub {
286
    plan tests => 1;
286
    plan tests => 2;
287
    my $code = "TEST";
287
    my $code = "TEST";
288
    my $module = "TEST";
288
    my $module = "TEST";
289
289
Lines 298-303 subtest 'loops' => sub { Link Here
298
        my $expected_letter = join '', ( $patron_1->{surname}, $patron_2->{surname} );
298
        my $expected_letter = join '', ( $patron_1->{surname}, $patron_2->{surname} );
299
        is( $letter->{content}, $expected_letter, );
299
        is( $letter->{content}, $expected_letter, );
300
    };
300
    };
301
302
    subtest 'foreign key is used' => sub {
303
        plan tests => 1;
304
        my $patron_1 = $builder->build({ source => 'Borrower' });
305
        my $patron_2 = $builder->build({ source => 'Borrower' });
306
        my $checkout_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $patron_1->{borrowernumber} } } );
307
        my $checkout_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $patron_1->{borrowernumber} } } );
308
309
        my $template = q|[% FOREACH checkout IN checkouts %][% checkout.issue_id %][% END %]|;
310
        reset_template( { template => $template, code => $code, module => $module } );
311
        my $letter = GetPreparedLetter( module => $module, letter_code => $code, loops => { issues => [ $checkout_1->{itemnumber}, $checkout_2->{itemnumber} ] } );
312
        my $expected_letter = join '', ( $checkout_1->{issue_id}, $checkout_2->{issue_id} );
313
        is( $letter->{content}, $expected_letter, );
314
    };
301
};
315
};
302
316
303
sub reset_template {
317
sub reset_template {
304
- 

Return to bug 17971