From 02ff6591ba83e1b8a934ec8017f8af7a45657fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sat, 24 Jul 2021 12:28:46 +0800 Subject: Origins and destinations can now be more than one --- catalog.cfg | 4 +++- config/pikul.tag | 54 +++++++++++++++++++++++++++++++++++--------------- config/pikul_cost.tag | 5 +++-- config/pikul_order.tag | 1 + 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/catalog.cfg b/catalog.cfg index 87aeebe..5f84b3f 100644 --- a/catalog.cfg +++ b/catalog.cfg @@ -757,4 +757,6 @@ SearchProfile include/profiles/searchprofiles Jobs log __LOGDIR__/jobs.log Jobs base_directory etc/jobs -Variable PIKUL_ANTERAJA 0 +Variable PIKUL 0 +Variable PIKUL_ANTERAJA 1 +Variable PIKUL_END 2 diff --git a/config/pikul.tag b/config/pikul.tag index bbbbd8d..db2d8ea 100644 --- a/config/pikul.tag +++ b/config/pikul.tag @@ -9,23 +9,45 @@ sub { for my $item (@{$Carts->{main}}) { $weight += $Tag->data('products', 'weight', $item->{code}) * $item->{quantity}; } - my @provisions = ( - $Global::Variable->{ANTERAJA_ACCESS_KEY_ID}, - $Global::Variable->{ANTERAJA_SECRET_ACCESS_KEY}, - $Global::Variable->{ANTERAJA_BASE_PATH} - ); - my @code_prefixes = ( - 'anteraja_' - ); - my @name_prefixes = ( - 'Anteraja ' - ); + my (@origins, @destinations, @code_prefixes, @name_prefixes); use Pikul; - Pikul::init($::Variable->{PIKUL_ANTERAJA}, \@provisions); - my $elements = Pikul::html( - $::Variable->{ANTERAJA_ORIGIN}, - $Tag->query({sql => "SELECT code FROM anteraja WHERE district='$district' AND city='$city' \ - AND province='$province'", wantarray => 1})->[0]->[0] || '', + for (my $company = $::Variable->{PIKUL}; $company < $::Variable->{PIKUL_END}; $company++) { + if ($company == $::Variable->{PIKUL}) { + $origins[$company] = undef; + $destinations[$company] = undef; + $code_prefixes[$company] = undef; + $name_prefixes[$company] = undef; + } elsif ($company == $::Variable->{PIKUL_ANTERAJA}) { + my $access_key_id = $::Variable->{ANTERAJA_ACCESS_KEY_ID} + || $Global::Variable->{ANTERAJA_ACCESS_KEY_ID}; + my $secret_access_key = $::Variable->{ANTERAJA_SECRET_ACCESS_KEY} + || $Global::Variable->{ANTERAJA_SECRET_ACCESS_KEY}; + my $base_path = $::Variable->{ANTERAJA_BASE_PATH} + || $Global::Variable->{ANTERAJA_BASE_PATH}; + if (!$access_key_id || !$secret_access_key || !$base_path) { + $origins[$company] = undef; + $destinations[$company] = undef; + $code_prefixes[$company] = undef; + $name_prefixes[$company] = undef; + next; + } + Pikul::init($company, [ + $access_key_id, + $secret_access_key, + $base_path + ]); + $origins[$company] = $::Variable->{ANTERAJA_ORIGIN} + || $Global::Variable->{ANTERAJA_ORIGIN}; + $destinations[$company] = $Tag->query({sql => "SELECT code FROM anteraja WHERE \ + district='$district' AND city='$city' AND province='$province'", + wantarray => 1})->[0]->[0] || ''; + $code_prefixes[$company] = 'anteraja_'; + $name_prefixes[$company] = 'Anteraja '; + } + } + my $elements = Pikul::html( + \@origins, + \@destinations, $weight, $widget, $extra, diff --git a/config/pikul_cost.tag b/config/pikul_cost.tag index 2cea3f2..4b8aad0 100644 --- a/config/pikul_cost.tag +++ b/config/pikul_cost.tag @@ -15,14 +15,15 @@ sub { use Pikul; Pikul::init($company, \@provisions); my $cost = Pikul::cost( + $company, + $service, $origin, $Tag->query({ sql => "SELECT code FROM $table WHERE district='$district' AND \ city='$city' AND province='$province'", wantarray => 1 })->[0]->[0] || '', - $weight, - $service); + $weight); Pikul::cleanup(); return $cost; } diff --git a/config/pikul_order.tag b/config/pikul_order.tag index e5541f1..f8bf255 100644 --- a/config/pikul_order.tag +++ b/config/pikul_order.tag @@ -35,6 +35,7 @@ sub { use Pikul; Pikul::init($company, \@provisions); my $tracking_number = Pikul::order( + $company, $order_number, $service, $::Variable->{COMPANY}, -- cgit v1.2.3