Projekt

Allgemein

Profil

Herunterladen (4,06 KB) Statistiken
| Zweig: | Markierung: | Revision:
eebe8e90 Sven Schöling
package SL::PriceSource::Price;

use strict;

use parent 'SL::DB::Object';
use Rose::Object::MakeMethods::Generic (
128b0775 Sven Schöling
scalar => [ qw(price description spec price_source invalid missing unknown) ],
2dfa3a4c Sven Schöling
'scalar --get_set_init' => [ qw(priority editable) ],
eebe8e90 Sven Schöling
);

89b26688 Sven Schöling
require SL::DB::Helper::Attr;
df1b03d5 Sven Schöling
SL::DB::Helper::Attr::make(__PACKAGE__,
price => 'numeric(15,5)',
);

0409db7c Sven Schöling
sub source {
$_[0]->price_source
89b26688 Sven Schöling
? $_[0]->price_source->name . '/' . $_[0]->spec
0409db7c Sven Schöling
: '';
}

eebe8e90 Sven Schöling
sub full_description {
my ($self) = @_;

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

cf63992e Sven Schöling
sub source_description {
my ($self) = @_;

$self->price_source
? $self->price_source->description
89b26688 Sven Schöling
: $self->description
cf63992e Sven Schöling
}

df1b03d5 Sven Schöling
sub to_str {
89b26688 Sven Schöling
"source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price ]}, description: @{[ $_[0]->description ]}"
df1b03d5 Sven Schöling
}

9f666261 Sven Schöling
sub init_priority {
3
}

2dfa3a4c Sven Schöling
sub init_editable {
0
}

eebe8e90 Sven Schöling
1;
418f0e70 Sven Schöling
__END__

=encoding utf-8

=head1 NAME

6a973df2 Geoffrey Richardson
SL::PriceSource::Price - container to pass calculated prices around
418f0e70 Sven Schöling
=head1 SYNOPSIS

# in PriceSource::Base implementation
$price = SL::PriceSource::Price->new(
price => 10.3,
89b26688 Sven Schöling
spec => '3', # something you can easily parse later
description => t8('Fix price 10.3 for customer 3'),
418f0e70 Sven Schöling
price_source => $self,
)

89b26688 Sven Schöling
# special empty price in SL::PriceSource, for internal use.
418f0e70 Sven Schöling
SL::PriceSource::Price->new(
description => t8('None (PriceSource)'),
);

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

89b26688 Sven Schöling
# invalid price
418f0e70 Sven Schöling
SL::PriceSource::Price->new(
89b26688 Sven Schöling
price => $original_price,
418f0e70 Sven Schöling
spec => $original_spec,
89b26688 Sven Schöling
description => $original_description,
invalid => t8('Offer expired #1 weeks ago', $dt->delta_weeks),
418f0e70 Sven Schöling
price_source => $self,
);

=head1 DESCRIPTION

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

This is a container for prices that are generated by L<SL::PriceSource::Base>
implementations.

=head1 CONSTRUCTOR FIELDS

=over 4

=item C<price>

The price. A price of 0 is special and is considered undesirable. If passed as
part of C<available_prices> it will be filtered out. If returned as
89b26688 Sven Schöling
C<best_price> or C<price_from_source> it will trigger a warning.
418f0e70 Sven Schöling
=item C<spec>

A unique string that can later be understood by the creating implementation.
Can be empty if the implementation only supports one price for a given
record_item.

=item C<description>

A localized short description of the origins of this price.

=item C<price_source>

A ref to the creating algorithm.

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

6a973df2 Geoffrey Richardson
OPTIONAL. Prices may supply a numerical priority. Higher will trump lower, even when
9f666261 Sven Schöling
supplying higher prices. Defaults to 3 (as in middle of 1-5).

2dfa3a4c Sven Schöling
=item C<editable>

OPTIONAL. Prices may flag themselves as editable. An editable price will still
be subject to checks for higher or lower prices, but will be rendered in a
fashion that allows the user to overwrite it.

This is potentially very distracting if the price is usually a default price
and will be changed in a lot of instances so use with caution.

On the other hand it can provide the capability that users unfamiliar with the
system will intuitively expect so it can be a good way to introduce the system.

418f0e70 Sven Schöling
=item C<missing>

OPTIONAL. Both indicator and localized message that the price with this spec
could not be reproduced and should be changed.

89b26688 Sven Schöling
If price is missing, you do not need to supply anything except C<source>.

418f0e70 Sven Schöling
=item C<invalid>

OPTIONAL. Both indicator and localized message that the conditions for this
price are no longer valid, and that the price should be changed.

89b26688 Sven Schöling
If price is missing, you do not need to supply anything except C<source>.

128b0775 Sven Schöling
=item C<unknown>

OPTIONAL. Boolean indicator that this price was not computed for performance
reasons. This is only valid for PriceSources flagged as C<fast>. This price
must be ignored.

418f0e70 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