my ($self, $source, $spec) = @_;
my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec);
+
+ return SL::PriceSource::Discount->new(
+ price_source => $self,
+ missing => t8('The price rule for this price does not exist anymore'),
+ ) if !$rule;
+
+ if ($rule->price_type != SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) {
+ return $self->make_price_from_rule($rule);
+ } else {
+ return SL::PriceSource::Price->new(
+ price_source => $self,
+ invalid => t8('The price rule is not a rule for prices'),
+ );
+ }
+}
+
+sub discount_from_source {
+ my ($self, $source, $spec) = @_;
+
+ my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec);
+
+ return SL::PriceSource::Discount->new(
+ price_source => $self,
+ missing => t8('The price rule for this discount does not exist anymore'),
+ ) if !$rule;
+
if ($rule->price_type == SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) {
return $self->make_discount_from_rule($rule);
} else {
- return $self->make_price_from_rule($rule);
+ return SL::PriceSource::Discount->new(
+ price_source => $self,
+ invalid => t8('The price rule is not a rule for discounts'),
+ );
}
}
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,
)
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,
)