Skip to content
Snippets Groups Projects
Verified Commit 96263514 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Cistka konfigurace, zmena mapovani id produktu

parent 42a1897d
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ image: docker:20.10.9 ...@@ -2,7 +2,7 @@ image: docker:20.10.9
variables: variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.13.4 IMAGE_VER: 0.14.0
services: services:
- docker:20.10.9-dind - docker:20.10.9-dind
......
...@@ -2,15 +2,4 @@ ...@@ -2,15 +2,4 @@
secrets => ['14283e549647774b17d10e1d75bcf16c2969673e'], secrets => ['14283e549647774b17d10e1d75bcf16c2969673e'],
oauth_url => 'https://auth.pirati.cz/auth/realms/pirati', oauth_url => 'https://auth.pirati.cz/auth/realms/pirati',
groups_url => 'https://iapi.pirati.cz/v1/octopus/groups', groups_url => 'https://iapi.pirati.cz/v1/octopus/groups',
pretix_api => 'https://pretix.pir-test.eu/api/v1',
pretix_token => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
pretix_testmode => 1,
pretix_organizer => 'pirati',
pretix_event => 'cf2022',
pretix_qid_sso => 29, # identifikator otazky SSO UID
pretix_qid_region => 8, # identifikator otazky Kraj
pretix_qid_photo => 28, # identifikator otazky Foto
pretix_product_member => 1, # produkt pro cleny (NEMAPOVANY!)
pretix_product_regp => 2, # produkt pro regp (NEMAPOVANY!)
mail_domain => 'pirati.cz',
} }
...@@ -4,11 +4,6 @@ use Mojo::UserAgent; ...@@ -4,11 +4,6 @@ use Mojo::UserAgent;
use Mojo::Asset::File; use Mojo::Asset::File;
use Image::PNG::QRCode 'qrpng'; use Image::PNG::QRCode 'qrpng';
use constant MAIN_PRODUCTS => qr/^(1|2|3)$/; # typy akreditace
use constant NONFREE_PRODUCTS => qr/^(1)$/; # akreditace vyzadujici token
use constant SUBSIDY_PRODUCTS => qr/^(58)$/; # prispevkove polozky
use constant FALLBACK_PRODUCT => 2; # fallback akreditace
use constant TPL_VS => '%d%07d'; use constant TPL_VS => '%d%07d';
use constant TPL_PAYMENT => 'SPD*1.0*ACC:%s*AM:%f*MSG:%s, %s*X-ID:%s*X-VS:%d*X-SS:%d*X-KS:%d'; use constant TPL_PAYMENT => 'SPD*1.0*ACC:%s*AM:%f*MSG:%s, %s*X-ID:%s*X-VS:%d*X-SS:%d*X-KS:%d';
...@@ -25,6 +20,15 @@ sub create ($c ) { ...@@ -25,6 +20,15 @@ sub create ($c ) {
my $accredited = 0; my $accredited = 0;
my $accreditation = 0; my $accreditation = 0;
# clasifikator typu
my $pt = {};
CLASS:
foreach my $class ( qw(main nonfree subsidy) ) {
foreach my $id ( split /\D+/, $cfg->{"products_$class"} ) {
$pt->{$class}{$id} = 1;
}
}
my $url = sprintf ('%s/organizers/%s/events/%s/orders/', my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
$c->config->{pretix_api}, $c->config->{pretix_api},
$c->config->{pretix_organizer}, $c->config->{pretix_organizer},
...@@ -60,7 +64,7 @@ sub create ($c ) { ...@@ -60,7 +64,7 @@ sub create ($c ) {
}, },
); );
$accreditation = $c->config->{'pretix_product_' . $group->{role}}; $accreditation = $c->config->{'products_' . $group->{role}};
if ( $group->{role} eq 'member' ) { if ( $group->{role} eq 'member' ) {
$args->{email} = $claims->{preferred_username} $args->{email} = $claims->{preferred_username}
...@@ -90,16 +94,18 @@ sub create ($c ) { ...@@ -90,16 +94,18 @@ sub create ($c ) {
PRODUCT: PRODUCT:
foreach my $product ( @{ $args->{products} } ) { foreach my $product ( @{ $args->{products} } ) {
next PRODUCT if $product->{id} =~ SUBSIDY_PRODUCTS && ! $product->{price}; $product->{id} = $c->mapped_product_id($product->{id});
next PRODUCT if $pt->{subsidy}{$product->{id}} && ! $product->{price};
if ( $product->{id} =~ MAIN_PRODUCTS ) { if ( $pt->{main}{ $product->{id} } ) {
next PRODUCT if $accredited++; # neumoznit dvoji akreditace next PRODUCT if $accredited++; # neumoznit dvoji akreditace
if ( $accreditation ) { if ( $accreditation ) {
$product->{id} = $accreditation; $product->{id} = $accreditation;
} }
elsif ($product->{id} =~ NONFREE_PRODUCTS) { elsif ( $pt->{nonfree}{ $product->{id} } ) {
$product->{id} = FALLBACK_PRODUCT; $product->{id} = $cfg->{products_fallback};
} }
} }
...@@ -108,7 +114,7 @@ sub create ($c ) { ...@@ -108,7 +114,7 @@ sub create ($c ) {
} }
# fallback akreditace # fallback akreditace
@products = ( { id => FALLBACK_PRODUCT}, @products ) if ! $accredited; @products = ( { id => $cfg->{products_fallback} }, @products ) if ! $accredited;
my $order = { my $order = {
email => $args->{email}, email => $args->{email},
...@@ -136,7 +142,7 @@ sub create ($c ) { ...@@ -136,7 +142,7 @@ sub create ($c ) {
foreach my $product ( @products ) { foreach my $product ( @products ) {
my $item = { my $item = {
item => $c->mapped_product_id($product->{id}), item => $product->{id},
variation => $c->mapped_variation_id($product->{variation}), variation => $c->mapped_variation_id($product->{variation}),
attendee_name => $args->{name}, attendee_name => $args->{name},
price => $product->{price}, price => $product->{price},
......
...@@ -5,22 +5,56 @@ use Mojo::UserAgent; ...@@ -5,22 +5,56 @@ use Mojo::UserAgent;
sub list { sub list {
my $c = shift->openapi->valid_input or return; my $c = shift->openapi->valid_input or return;
my $url = sprintf ('%s/organizers/%s/events/%s/items/', my $ua = Mojo::UserAgent->new;
my $products = $ua->get( sprintf ('%s/organizers/%s/events/%s/items/',
$c->config->{pretix_api}, $c->config->{pretix_api},
$c->config->{pretix_organizer}, $c->config->{pretix_organizer},
$c->config->{pretix_event}, $c->config->{pretix_event},
); ), {
Authorization => 'Token ' . $c->config->{pretix_token}
} )->result->json;
my $ua = Mojo::UserAgent->new; my $quotas = $ua->get( sprintf ('%s/organizers/%s/events/%s/quotas/',
$c->config->{pretix_api},
$c->config->{pretix_organizer},
$c->config->{pretix_event},
), {
Authorization => 'Token ' . $c->config->{pretix_token}
} )->result->json;
my $records = $ua->get( $url, { my $q = {};
QUOTE:
foreach my $record ( @{ $quotas->{results} } ) {
next if ! $record->{size};
my $quota = $ua->get( sprintf ('%s/organizers/%s/events/%s/quotas/%d/availability/',
$c->config->{pretix_api},
$c->config->{pretix_organizer},
$c->config->{pretix_event},
$record->{id},
), {
Authorization => 'Token ' . $c->config->{pretix_token} Authorization => 'Token ' . $c->config->{pretix_token}
} )->result->json; } )->result->json;
ITEM:
foreach my $item_id ( @{ $record->{items} } ) {
$q->{$item_id}{total} += $quota->{total_size};
$q->{$item_id}{available} += $quota->{available_number};
foreach my $variation_id ( @{ $record->{variations} } ) {
$q->{$item_id}{$variation_id}{total} += $quota->{total_size};
$q->{$item_id}{$variation_id}{available} += $quota->{available_number};
}
}
}
$c->trace($q);
my @options = (); my @options = ();
RECORD: RECORD:
foreach my $record ( @{ $records->{results} } ) { foreach my $record ( @{ $products->{results} } ) {
next RECORD if ! $record->{active}; next RECORD if ! $record->{active};
push @options, { push @options, {
...@@ -29,11 +63,13 @@ sub list { ...@@ -29,11 +63,13 @@ sub list {
price => $record->{default_price} + 0, price => $record->{default_price} + 0,
free_price => $record->{free_price}, free_price => $record->{free_price},
category_id => $record->{category}, category_id => $record->{category},
quotes => $q->{$record->{id}},
variations => [ variations => [
map {{ map {{
id => $_->{id}, id => $_->{id},
value => $_->{value}{en}, value => $_->{value}{en},
price => $_->{price} + 0 price => $_->{price} + 0,
quotes => $q->{$record->{id}}{$_->{id} },
}} @{ $record->{variations} } }} @{ $record->{variations} }
], ],
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment