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

(-)a/C4/Letters.pm (-2 / +4 lines)
Lines 1557-1566 sub _get_tt_params { Link Here
1557
            my $fk = $config->{$table}->{fk};
1557
            my $fk = $config->{$table}->{fk};
1558
1558
1559
            if ( $is_a_loop ) {
1559
            if ( $is_a_loop ) {
1560
                unless ( ref( $tables->{$table} ) eq 'ARRAY' ) {
1560
                my $values = $tables->{$table} || [];
1561
                unless ( ref( $values ) eq 'ARRAY' ) {
1561
                    croak "ERROR processing table $table. Wrong API call.";
1562
                    croak "ERROR processing table $table. Wrong API call.";
1562
                }
1563
                }
1563
                my $objects = $module->search( { $pk => { -in => $tables->{$table} } } );
1564
                my $key = $pk ? $pk : $fk;
1565
                my $objects = $module->search( { $key => { -in => $values } } );
1564
                $params->{ $config->{$table}->{plural} } = $objects;
1566
                $params->{ $config->{$table}->{plural} } = $objects;
1565
            }
1567
            }
1566
            elsif ( $ref eq q{} || $ref eq 'HASH' ) {
1568
            elsif ( $ref eq q{} || $ref eq 'HASH' ) {
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +15 lines)
Lines 327-333 subtest 'regression tests' => sub { Link Here
327
};
327
};
328
328
329
subtest 'loops' => sub {
329
subtest 'loops' => sub {
330
    plan tests => 1;
330
    plan tests => 2;
331
    my $code = "TEST";
331
    my $code = "TEST";
332
    my $module = "TEST";
332
    my $module = "TEST";
333
333
Lines 342-347 subtest 'loops' => sub { Link Here
342
        my $expected_letter = join '', ( $patron_1->{surname}, $patron_2->{surname} );
342
        my $expected_letter = join '', ( $patron_1->{surname}, $patron_2->{surname} );
343
        is( $letter->{content}, $expected_letter, );
343
        is( $letter->{content}, $expected_letter, );
344
    };
344
    };
345
346
    subtest 'foreign key is used' => sub {
347
        plan tests => 1;
348
        my $patron_1 = $builder->build({ source => 'Borrower' });
349
        my $patron_2 = $builder->build({ source => 'Borrower' });
350
        my $checkout_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $patron_1->{borrowernumber} } } );
351
        my $checkout_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $patron_1->{borrowernumber} } } );
352
353
        my $template = q|[% FOREACH checkout IN checkouts %][% checkout.issue_id %][% END %]|;
354
        reset_template( { template => $template, code => $code, module => $module } );
355
        my $letter = GetPreparedLetter( module => $module, letter_code => $code, loops => { issues => [ $checkout_1->{itemnumber}, $checkout_2->{itemnumber} ] } );
356
        my $expected_letter = join '', ( $checkout_1->{issue_id}, $checkout_2->{issue_id} );
357
        is( $letter->{content}, $expected_letter, );
358
    };
345
};
359
};
346
360
347
sub reset_template {
361
sub reset_template {
348
- 

Return to bug 17971