From 9f66626118ec0cdcee8082b3d81f288bbfa23648 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 8 Dec 2014 14:11:21 +0100 Subject: [PATCH] =?utf8?q?PriceSource:=20Priorit=C3=A4t=20auf=20Preisquell?= =?utf8?q?enebene=20verstehen=20und=20umsetzen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Priorität kann jetzt von den einzelnen Preisquellen durchgereicht werden --- SL/PriceSource.pm | 4 ++-- SL/PriceSource/Discount.pm | 10 ++++++++++ SL/PriceSource/Price.pm | 10 ++++++++++ SL/PriceSource/PriceRules.pm | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/SL/PriceSource.pm b/SL/PriceSource.pm index ac419a670..89dffba89 100644 --- a/SL/PriceSource.pm +++ b/SL/PriceSource.pm @@ -40,11 +40,11 @@ sub available_discounts { } sub best_price { - min_by { $_->price } grep { $_->price > 0 } grep { $_ } map { $_->best_price } $_[0]->all_price_sources; + min_by { $_->price } max_by { $_->priority } grep { $_->price > 0 } grep { $_ } map { $_->best_price } $_[0]->all_price_sources; } sub best_discount { - max_by { $_->discount } grep { $_->discount } grep { $_ } map { $_->best_discount } $_[0]->all_price_sources; + max_by { $_->discount } max_by { $_->priority } grep { $_->discount } grep { $_ } map { $_->best_discount } $_[0]->all_price_sources; } sub empty_price { diff --git a/SL/PriceSource/Discount.pm b/SL/PriceSource/Discount.pm index ded123a81..a7475eae2 100644 --- a/SL/PriceSource/Discount.pm +++ b/SL/PriceSource/Discount.pm @@ -5,6 +5,7 @@ use strict; use parent 'SL::DB::Object'; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(discount description spec price_source invalid missing) ], + 'scalar --get_set_init' => [ qw(priority) ], ); require SL::DB::Helper::Attr; @@ -38,6 +39,10 @@ sub to_str { "source: @{[ $_[0]->source ]}, discount: @{[ $_[0]->discount ]}, description: @{[ $_[0]->description ]}" } +sub init_priority { + 3 +} + 1; __END__ @@ -109,6 +114,11 @@ A localized short description of the origins of this discount. A ref to the creating algorithm. +=item C + +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). + =item C OPTIONAL. Both indicator and localized message that the discount with this spec diff --git a/SL/PriceSource/Price.pm b/SL/PriceSource/Price.pm index 71bd1ff4f..b17fb36d8 100644 --- a/SL/PriceSource/Price.pm +++ b/SL/PriceSource/Price.pm @@ -5,6 +5,7 @@ use strict; use parent 'SL::DB::Object'; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(price description spec price_source invalid missing) ], + 'scalar --get_set_init' => [ qw(priority) ], ); require SL::DB::Helper::Attr; @@ -38,6 +39,10 @@ sub to_str { "source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price ]}, description: @{[ $_[0]->description ]}" } +sub init_priority { + 3 +} + 1; __END__ @@ -109,6 +114,11 @@ A localized short description of the origins of this price. A ref to the creating algorithm. +=item C + +OPTIONAL. Prices may supply a numerical priority. Higher will trump over lower, even when +supplying higher prices. Defaults to 3 (as in middle of 1-5). + =item C OPTIONAL. Both indicator and localized message that the price with this spec diff --git a/SL/PriceSource/PriceRules.pm b/SL/PriceSource/PriceRules.pm index 140706d47..e1d1c126b 100644 --- a/SL/PriceSource/PriceRules.pm +++ b/SL/PriceSource/PriceRules.pm @@ -92,6 +92,7 @@ sub make_price_from_rule { price => $self->price_for_rule($rule), spec => $rule->id, description => $rule->name, + priority => $rule->priority, price_source => $self, (invalid => t8('This Price Rule is no longer valid'))x!!$rule->obsolete, ) @@ -104,6 +105,7 @@ sub make_discount_from_rule { discount => $rule->discount / 100, spec => $rule->id, description => $rule->name, + priority => $rule->priority, price_source => $self, (invalid => t8('This Price Rule is no longer valid'))x!!$rule->obsolete, ) -- 2.20.1