+ if (!defined $basket->{branch} or $basket->{branch} eq $userenv->{branch}) {
+ push @branches_loop, {
+ branchcode => $userenv->{branch},
+ branchname => $userenv->{branchname},
+ selected => 1,
+ };
+ }
+ } else {
+ # get branches
+ my $branches = C4::Branch::GetBranches;
+ my @branchcodes = sort {
+ $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
+ } keys %$branches;
+ foreach my $branch (@branchcodes) {
+ my $selected = 0;
+ if (defined $basket->{branch}) {
+ $selected = 1 if $branch eq $basket->{branch};
+ } else {
+ $selected = 1 if $branch eq C4::Context->userenv->{branch};
+ }
+ push @branches_loop, {
+ branchcode => $branch,
+ branchname => $branches->{$branch}->{branchname},
+ selected => $selected
+ };
+ }