Projekt

Allgemein

Profil

Herunterladen (3,42 KB) Statistiken
| Zweig: | Markierung: | Revision:
89b26688 Sven Schöling
package SL::PriceSource::Discount;

use strict;

use parent 'SL::DB::Object';
use Rose::Object::MakeMethods::Generic (
scalar => [ qw(discount description spec price_source invalid missing) ],
9f666261 Sven Schöling
'scalar --get_set_init' => [ qw(priority) ],
89b26688 Sven Schöling
);

require SL::DB::Helper::Attr;
SL::DB::Helper::Attr::make(__PACKAGE__,
discount => 'numeric(15,5)',
);

sub source {
$_[0]->price_source
? $_[0]->price_source->name . '/' . $_[0]->spec
: '';
}

sub full_description {
my ($self) = @_;

$self->price_source
? $self->price_source->description . ': ' . $self->description
: $self->description
}

sub source_description {
my ($self) = @_;

$self->price_source
? $self->price_source->description
: $self->description
}

sub to_str {
"source: @{[ $_[0]->source ]}, discount: @{[ $_[0]->discount ]}, description: @{[ $_[0]->description ]}"
}

9f666261 Sven Schöling
sub init_priority {
3
}

89b26688 Sven Schöling
1;

__END__

=encoding utf-8

=head1 NAME

fd6f0f82 Geoffrey Richardson
SL::PriceSource::Discount - container to pass calculated discounts around
89b26688 Sven Schöling
=head1 SYNOPSIS

# in PriceSource::Base implementation
226002b0 Sven Schöling
$price = SL::PriceSource::Discount->new(
89b26688 Sven Schöling
discount => 10,
spec => 'summersale2014', # something you can easily parse later
description => t8('10% discount during summer sale 2014'),
price_source => $self,
)

226002b0 Sven Schöling
# special empty discount in SL::PriceSource, for internal use.
SL::PriceSource::Discount->new(
89b26688 Sven Schöling
description => t8('None (PriceSource)'),
);

# price can't be restored
226002b0 Sven Schöling
SL::PriceSource::Discount->new(
89b26688 Sven Schöling
missing => t8('Um, sorry, cannot find that one'),
price_source => $self,
);

226002b0 Sven Schöling
# invalid discount
fd6f0f82 Geoffrey Richardson
SL::PriceSource::Discount->new(
226002b0 Sven Schöling
discount => $original_discount,
89b26688 Sven Schöling
spec => $original_spec,
description => $original_description,
invalid => t8('Offer expired #1 weeks ago', $dt->delta_weeks),
price_source => $self,
);

=head1 DESCRIPTION

See L<SL::PriceSource> for information about the mechanism.

226002b0 Sven Schöling
This is a container for discounts that are generated by L<SL::PriceSource::Base>
89b26688 Sven Schöling
implementations.

=head1 CONSTRUCTOR FIELDS

=over 4

=item C<discount>

The discount in percent. A discount of 0 will be ignored. If passed as
part of C<available_prices> it will be filtered out. If returned as
226002b0 Sven Schöling
C<best_discount> or C<discount_from_source> it will trigger a warning.
89b26688 Sven Schöling
=item C<spec>

A unique string that can later be understood by the creating implementation.
226002b0 Sven Schöling
Can be empty if the implementation only supports one discount for a given
89b26688 Sven Schöling
record_item.

=item C<description>

226002b0 Sven Schöling
A localized short description of the origins of this discount.
89b26688 Sven Schöling
=item C<price_source>

A ref to the creating algorithm.

9f666261 Sven Schöling
=item C<priority>

OPTIONAL. Discounts may supply a numerical priority. Higher will trump over lower, even when
supplying lower discounts. Defaults to 3 (as in middle of 1-5).

89b26688 Sven Schöling
=item C<missing>

226002b0 Sven Schöling
OPTIONAL. Both indicator and localized message that the discount with this spec
89b26688 Sven Schöling
could not be reproduced and should be changed.

226002b0 Sven Schöling
If discount is missing, you do not need to supply anything except C<source>.
89b26688 Sven Schöling
=item C<invalid>

OPTIONAL. Both indicator and localized message that the conditions for this
226002b0 Sven Schöling
discount are no longer valid, and that the discount should be changed.
89b26688 Sven Schöling
226002b0 Sven Schöling
If discount is missing, you do not need to supply anything except C<source>.
89b26688 Sven Schöling
=back

=head1 SEE ALSO

L<SL::PriceSource>,
L<SL::PriceSource::Base>,
L<SL::PriceSource::ALL>

=head1 BUGS

None yet. :)

=head1 AUTHOR

Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>

=cut