From 1e1ecfe611e6c07ed4cf908f62bb36afde37f4b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 12 Aug 2015 14:46:48 +0200 Subject: [PATCH] =?utf8?q?Auftrags-Controller:=20bei=20neuem=20Auftrags-Ob?= =?utf8?q?jekt=20leere=20orderitems=20anlegen,=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit damit add_items auch bei Aufträgen ohne items die items nicht nur zum Speichern hinzufügt. Sonst kann man bis zum Speichern nicht auf die hinzugefügten items via items oder orderitems zugreifen. --- SL/Controller/Order.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 5c8513264..f4d567dee 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -143,12 +143,7 @@ sub action_add_item { $new_attr{discount} = $cv_discount if ! $item->{discount}; $item->assign_attributes(%new_attr); - # add_items seems to fail if no items had been added before - if ($self->order->items) { - $self->order->add_items($item); - } else { - $self->order->items([$item]); - } + $self->order->add_items($item); $self->_setup(); @@ -297,7 +292,12 @@ sub build_tax_rows { sub _make_order { my ($self) = @_; - my $order = SL::DB::Manager::Order->find_by_or_create(id => $::form->{id}); + # add_items adds items to an order with no items for saving, but they cannot + # be retrieved via items until the order is saved. Adding empty items to new + # order here solves this problem. + my $order; + $order = SL::DB::Manager::Order->find_by(id => $::form->{id}) if $::form->{id}; + $order ||= SL::DB::Order->new(orderitems => []); $order->assign_attributes(%{$::form->{order}}); -- 2.20.1