From 196da0e775a9bf7b33e87c2027d7993f4cbc9f34 Mon Sep 17 00:00:00 2001 From: Tamino Date: Wed, 30 Dec 2020 12:22:06 +0100 Subject: [PATCH] ShopConnector: WooCommerce set OrderStatus added --- SL/ShopConnector/WooCommerce.pm | 35 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/SL/ShopConnector/WooCommerce.pm b/SL/ShopConnector/WooCommerce.pm index 9a3f8eafb..f65570d96 100644 --- a/SL/ShopConnector/WooCommerce.pm +++ b/SL/ShopConnector/WooCommerce.pm @@ -32,18 +32,16 @@ sub get_one_order { my $shoporder = $answer->{data}; $dbh->with_transaction( sub{ - unless ($self->import_data_to_shop_order($shoporder)) { return 0;} - #update status on server $shoporder->{status} = "processing"; - my %new_status = ( status => "processing" ); - my $status_json = SL::JSON::to_json( \%new_status); - $answer = $self->send_request("orders/$shoporder->{id}", $status_json, "put"); - unless($answer->{success}){ + my $anser = $self->set_orderstatus($$shoporder->{id}, "fetched"); + unless($answer){ push @errors,($::locale->text('Saving failed. Error message from the server: #1', $answer->message)); - return 0 + return 0; } + unless ($self->import_data_to_shop_order($shoporder)) { return 0;} + 1; })or do { push @errors,($::locale->text('Saving failed. Error message from the database: #1', $dbh->error)); @@ -87,18 +85,16 @@ sub get_new_orders { foreach my $shoporder(@{$orders}){ $dbh->with_transaction( sub{ - unless ($self->import_data_to_shop_order($shoporder)) { return 0;} - #update status on server $shoporder->{status} = "processing"; - my %new_status = ( status => "processing" ); - my $status_json = SL::JSON::to_json( \%new_status); - $answer = $self->send_request("orders/$shoporder->{id}", $status_json, "put"); - unless($answer->{success}){ + my $anser = $self->set_orderstatus($$shoporder->{id}, "fetched"); + unless($answer){ push @errors,($::locale->text('Saving failed. Error message from the server: #1', $answer->message)); return 0; } + unless ($self->import_data_to_shop_order($shoporder)) { return 0;} + 1; })or do { push @errors,($::locale->text('Saving failed. Error message from the database: #1', $dbh->error)); @@ -446,6 +442,19 @@ sub get_version { } } +sub set_orderstatus { + my ($self,$order_id, $status) = @_; + if ($status eq "fetched") { $status = "processing"; } + if ($status eq "completed") { $status = "completed"; } + my %new_status = (status => $status); + my $status_json = SL::JSON::to_json( \%new_status); + my $answer = $self->send_request("orders/$order_id", $status_json, "put"); + unless($answer->{success}){ + return 0; + } + return 1; +} + sub create_url { my ($self) = @_; my $request = $_[1]; -- 2.20.1