Unverified Commit 1f525e4d authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Skip multi-component offers; hide upsell by default

parent 9012931f
Loading
Loading
Loading
Loading
+29 −9
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@ use Travel::Routing::DE::DBRIS;

my ( $date, $time, $arrival, $from, $to, $language );
my $mots;
my ( $show_jid,       $show_full_route, $show_offers );
my ( $show_jid,       $show_full_route );
my ( $show_offers,    $show_upsell_offers, $show_cross_offers );
my ( $first_class,    $passengers );
my ( $developer_mode, $verbose );
my ( $json_output,    $raw_json_output );
@@ -56,6 +57,8 @@ GetOptions(
	'm|modes-of-transit=s' => \$mots,
	'l|language=s'         => \$language,
	'o|with-offers'        => \$show_offers,
	'with-upsell-offers'   => \$show_upsell_offers,
	'with-cross-offers'    => \$show_cross_offers,
	'p|passengers=s'       => \$passengers,
	't|time=s'             => \$time,
	'v|verbose'            => \$verbose,
@@ -383,12 +386,29 @@ for my $connection ( $ris->connections ) {
			say STDERR "Request error while looking up offers: ${err}";
		}
		for my $offer ( $offers_req->offers ) {
			printf('- %5.2f %s %s', $offer->price, $offer->price_unit =~ s{EUR}{€}r, $offer->name);
			if ($first_class and $offer->class == 2 or not $first_class and $offer->class == 1) {
			if ( $offer->needs_context ) {

				# offers that are only valid when also bying, e.g., a BC25 or BC50
				# Note that this automatically skips cross-sell offers.
				next;
			}
			if ( $offer->is_upsell and not $show_upsell_offers ) {
				next;
			}
			if ( $offer->is_cross_sell and not $show_cross_offers ) {
				next;
			}
			printf( '- %5.2f %s %s',
				$offer->price, $offer->price_unit =~ s{EUR}{€}r,
				$offer->name );
			if ( $first_class and $offer->class == 2
				or not $first_class and $offer->class == 1 )
			{
				printf( " %d. Klasse", $offer->class );
			}
			if ( scalar $offer->conditions ) {
				printf(' (%s)', join(q{ · }, map { $_->{textKurz} } $offer->conditions));
				printf( ' (%s)',
					join( q{ · }, map { $_->{textKurz} } $offer->conditions ) );
			}
			say q{};
		}
+16 −6
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ use parent 'Class::Accessor';
our $VERSION = '0.03';

Travel::Routing::DE::DBRIS::Offer->mk_ro_accessors(
	qw(class name price price_unit));
	qw(class name price price_unit is_upsell is_cross_sell needs_context));

sub new {
	my ( $obj, %opt ) = @_;
@@ -23,8 +23,18 @@ sub new {
		price         => $json->{preis}{betrag},
		price_unit    => $json->{preis}{waehrung},
		conditions    => $json->{konditionsAnzeigen},
		is_upsell     => exists $json->{upsellInfos}    ? 1 : 0,
		is_cross_sell => exists $json->{crosssellInfos} ? 1 : 0,
	};

	for my $relation ( @{ $json->{angebotsbeziehungList} // [] } ) {
		for my $offer_ref ( @{ $relation->{referenzen} // [] } ) {
			if ( $offer_ref->{referenzAngebotsoption} eq 'PFLICHT' ) {
				$ref->{needs_context} = 1;
			}
		}
	}

	bless( $ref, $obj );

	return $ref;