sub action_edit {
my ($self) = @_;
- $self->load_order;
+ if ($::form->{id}) {
+ $self->load_order;
+
+ } else {
+ # this is to edit an order from an unsaved order object
+
+ # set item ids to new fake id, to identify them as new items
+ foreach my $item (@{$self->order->items_sorted}) {
+ $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+ }
+ # trigger rendering values for second row/longdescription as hidden,
+ # because they are loaded only on demand. So we need to keep the values
+ # from the source.
+ $_->{render_second_row} = 1 for @{ $self->order->items_sorted };
+ $_->{render_longdescription} = 1 for @{ $self->order->items_sorted };
+ }
+
$self->recalc();
$self->pre_render();
$self->render(
sub order {
$main::lxdebug->enter_sub();
+ _order();
+
+ if ($::instance_conf->get_feature_experimental) {
+ my $order = _make_record();
+ $order->globalproject_id(undef) if !$order->globalproject_id;
+ $order->payment_id(undef) if !$order->payment_id;
+ my $row = 1;
+ foreach my $item (@{$order->items_sorted}) {
+ $item->custom_variables([]);
+
+ $item->price_factor_id(undef) if !$item->price_factor_id;
+ $item->project_id(undef) if !$item->project_id;
+ $item->discount($item->discount/100.0);
+
+ # autovivify all cvars that are not in the form (cvars_by_config can do it).
+ # workaround to pre-parse number-cvars (parse_custom_variable_values does not parse number values).
+ foreach my $var (@{ $item->cvars_by_config }) {
+ my $key = 'ic_cvar_' . $var->config->name . '_' . $row;
+ $var->unparsed_value($::form->{$key});
+ $var->unparsed_value($::form->parse_amount(\%::myconfig, $var->{__unparsed_value})) if ($var->config->type eq 'number' && exists($var->{__unparsed_value}));
+ }
+ $item->parse_custom_variable_values;
+
+ $row++;
+ }
+
+ require SL::Controller::Order;
+ my $c = SL::Controller::Order->new(order => $order);
+ $c->action_edit();
+
+ $main::lxdebug->leave_sub();
+ $::dispatcher->end_request;
+ }
+
+ &display_form;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _order {
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
}
&prepare_order;
- &display_form;
-
- $main::lxdebug->leave_sub();
}
sub quotation {