From: Tamino Date: Tue, 29 Dec 2020 09:50:11 +0000 (+0100) Subject: ShopConnector: set OrderStatus in Shop X-Git-Tag: kivitendo-mebil_0.1-0~9^2~373 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f71e1c67e070d737390634bce3b6b67a2a2a1a1c;p=kivitendo-erp.git ShopConnector: set OrderStatus in Shop --- diff --git a/SL/IS.pm b/SL/IS.pm index 5fe66cf47..bda82bc76 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1441,6 +1441,21 @@ SQL } } + # update shop status + my $invoice = SL::DB::Invoice->new( id => $form->{id} )->load; + my @linked_shop_orders = $invoice->linked_records( + from => 'ShopOrder', + via => ['Order', 'DeliveryOrder'], + ); + if (scalar @linked_shop_orders == 1){ + #do update + my $shop_order = $linked_shop_orders[0][0]; + require SL::Shop; + my $shop_config = SL::DB::Manager::Shop->get_first( query => [ id => $shop_order->shop_id ] ); + my $shop = SL::Shop->new( config => $shop_config ); + $shop->connector->set_orderstatus($shop_order->shop_trans_id, "completed"); + } + return 1; } diff --git a/SL/ShopConnector/Base.pm b/SL/ShopConnector/Base.pm index 4aa3b8905..56127e4c4 100644 --- a/SL/ShopConnector/Base.pm +++ b/SL/ShopConnector/Base.pm @@ -15,9 +15,11 @@ sub update_part { die 'update_part needs to be implemented' } sub get_article { die 'get_article needs to be implemented' } -sub get_categories { die 'get_order needs to be implemented' } +sub get_categories { die 'get_categories needs to be implemented' } -sub get_version { die 'get_order needs to be implemented' } +sub get_version { die 'get_version needs to be implemented' } + +sub set_orderstatus { die 'set_orderstatus needs to be implemented' } 1; @@ -50,6 +52,8 @@ __END__ =item C +=item C + =back =head1 SEE ALSO diff --git a/SL/ShopConnector/Shopware.pm b/SL/ShopConnector/Shopware.pm index 9cd766e90..256f84b55 100644 --- a/SL/ShopConnector/Shopware.pm +++ b/SL/ShopConnector/Shopware.pm @@ -46,6 +46,7 @@ sub get_one_order { }; if(!@errors){ + $self->set_orderstatus($import->{data}->{id}, "fetched"); $of++; }else{ flash_later('error', $::locale->text('Database errors: #1', @errors)); @@ -100,6 +101,7 @@ sub get_new_orders { }; if(!@errors){ + $self->set_orderstatus($shoporder->{id}, "fetched"); $of++; }else{ flash_later('error', $::locale->text('Database errors: #1', @errors)); @@ -401,6 +403,15 @@ sub get_article { return SL::JSON::decode_json($data_json); } +sub set_orderstatus { + my ($self,$order_id, $status) = @_; + if ($status eq "fetched") { $status = 1; } + if ($status eq "completed") { $status = 2; } + my %new_status = (orderStatusId => $status); + my $new_status_json = SL::JSON::to_json(\%new_status); + $self->connector->put($self->url . "api/orders/$order_id", Content => $new_status_json); +} + sub init_url { my ($self) = @_; $self->url($self->config->protocol . "://" . $self->config->server . ":" . $self->config->port . $self->config->path);