<%once> use JSON::XS; my $json = JSON::XS->new->utf8; <%args> $name => undef $rusname => undef $check => undef <%init> my $fields = $check ? $json->decode($check) : {}; my @fields; while ( my ($reg_id, $cost) = each %$fields ) { push @fields, { region => $reg_id, cost => $cost }; } @fields = sort { int($a->{cost}) <=> int($b->{cost}) } @fields; my $regions = $keeper->get_documents ( class => 'webshop::Area', status => 1, order_by => 'name', return_mode => 'array_ref', ); my %pid = map { $_->pid => 1 } @$regions; my @pid = keys %pid; my $countries = @pid ? $keeper->get_documents ( id => \@pid, class => 'webshop::Country', return_mode => 'hash_ref', ) : {}; $m->out(''); $m->out(''); $m->out(''); $m->out(''); my $max = scalar @fields + 4; for my $i ( 1..$max ) { my $rusname = "$rusname N$i"; my $object = $fields[$i-1]; $m->comp('.field', name => $name, object => $object, number => $i, regions => $regions, countries => $countries, ); } $m->out('
Регион:
Стоимость доставки (число):
'); <%def .field> <%args> $name => undef $object => undef $number => undef $regions => [] $countries => {} <%init>