1 package SL::PriceSource::Discount;
 
   5 use parent 'SL::DB::Object';
 
   6 use Rose::Object::MakeMethods::Generic (
 
   7   scalar => [ qw(discount description spec price_source invalid missing) ],
 
   8   'scalar --get_set_init' => [ qw(priority) ],
 
  11 require SL::DB::Helper::Attr;
 
  12 SL::DB::Helper::Attr::make(__PACKAGE__,
 
  13   discount => 'numeric(15,5)',
 
  18   ? $_[0]->price_source->name . '/' . $_[0]->spec
 
  22 sub full_description {
 
  26     ? $self->price_source->description . ': ' . $self->description
 
  30 sub source_description {
 
  34     ? $self->price_source->description
 
  39   "source: @{[ $_[0]->source ]}, discount: @{[ $_[0]->discount ]}, description: @{[ $_[0]->description ]}"
 
  54 SL::PriceSource::Discount - container to pass calculated discounts around
 
  58   # in PriceSource::Base implementation
 
  59   $price = SL::PriceSource::Discount->new(
 
  61     spec         => 'summersale2014', # something you can easily parse later
 
  62     description  => t8('10% discount during summer sale 2014'),
 
  63     price_source => $self,
 
  66   # special empty discount in SL::PriceSource, for internal use.
 
  67   SL::PriceSource::Discount->new(
 
  68     description => t8('None (PriceSource)'),
 
  71   # price can't be restored
 
  72   SL::PriceSource::Discount->new(
 
  73     missing      => t8('Um, sorry, cannot find that one'),
 
  74     price_source => $self,
 
  78   SL::PriceSource::Discount->new(
 
  79     discount     => $original_discount,
 
  80     spec         => $original_spec,
 
  81     description  => $original_description,
 
  82     invalid      => t8('Offer expired #1 weeks ago', $dt->delta_weeks),
 
  83     price_source => $self,
 
  88 See L<SL::PriceSource> for information about the mechanism.
 
  90 This is a container for discounts that are generated by L<SL::PriceSource::Base>
 
  93 =head1 CONSTRUCTOR FIELDS
 
  99 The discount in percent. A discount of 0 will be ignored. If passed as
 
 100 part of C<available_prices> it will be filtered out. If returned as
 
 101 C<best_discount> or C<discount_from_source> it will trigger a warning.
 
 105 A unique string that can later be understood by the creating implementation.
 
 106 Can be empty if the implementation only supports one discount for a given
 
 111 A localized short description of the origins of this discount.
 
 113 =item C<price_source>
 
 115 A ref to the creating algorithm.
 
 119 OPTIONAL. Discounts may supply a numerical priority. Higher will trump over lower, even when
 
 120 supplying lower discounts. Defaults to 3 (as in middle of 1-5).
 
 124 OPTIONAL. Both indicator and localized message that the discount with this spec
 
 125 could not be reproduced and should be changed.
 
 127 If discount is missing, you do not need to supply anything except C<source>.
 
 131 OPTIONAL. Both indicator and localized message that the conditions for this
 
 132 discount are no longer valid, and that the discount should be changed.
 
 134 If discount is missing, you do not need to supply anything except C<source>.
 
 141 L<SL::PriceSource::Base>,
 
 142 L<SL::PriceSource::ALL>
 
 150 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>