+
+ $object->delivery_term_id($terms->id);
+
+ # register delivery_term_id for method copying later
+ $self->clone_methods->{delivery_term_id} = 1;
+ }
+
+ return 1;
+}
+
+sub save_objects {
+ my ($self, %params) = @_;
+
+ my $data = $params{data} || $self->controller->data;
+
+ return unless $data->[0];
+ return unless $data->[0]{object};
+
+ $self->controller->track_progress(phase => 'saving data', progress => 0); # scale from 45..95%;
+
+ my $last_index = $#$data;
+ my $chunk_size = 100; # one transaction and progress update every 100 objects
+
+ for my $chunk (0 .. $last_index / $chunk_size) {
+ $self->controller->track_progress(progress => ($chunk_size * $chunk)/scalar(@$data) * 100); # scale from 45..95%;
+ SL::DB->client->with_transaction(sub {
+ foreach my $entry_index ($chunk_size * $chunk .. min( $last_index, $chunk_size * ($chunk + 1) - 1 )) {
+ my $entry = $data->[$entry_index];
+ next if @{ $entry->{errors} };
+
+ my $object = $entry->{object_to_save} || $entry->{object};
+
+ my $ret;
+ if (!eval { $ret = $object->save(cascade => !!$self->save_with_cascade()); 1 }) {
+ push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $EVAL_ERROR);
+ } elsif ( !$ret ) {
+ push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $object->db->error);
+ } else {
+ $self->_save_history($object);
+ $self->controller->num_imported($self->controller->num_imported + 1);
+ }
+ }
+ 1;
+ }) or do { die SL::DB->client->error };