Skip to content

Commit

Permalink
completely comment out tier_pricing method in Product result class
Browse files Browse the repository at this point in the history
see gh #187
  • Loading branch information
SysPete committed Feb 9, 2016
1 parent 63ece80 commit 9526bce
Showing 1 changed file with 88 additions and 88 deletions.
176 changes: 88 additions & 88 deletions lib/Interchange6/Schema/Result/Product.pm
Original file line number Diff line number Diff line change
Expand Up @@ -585,94 +585,94 @@ sub path {
return wantarray ? @path : \@path;
}

=head2 tier_pricing
Tier pricing can be calculated for a single role and also a combination of several roles.
=over 4
=item Arguments: array reference of L<Role names|Interchange6::Schema::Result::Role/name>
=item Return Value: in scalar context an array reference ordered by quantity ascending of hash references of quantity and price, in list context returns an array instead of array reference
=back
The method always returns the best price for specific price points including
any PriceModifier rows where roles_id is undef.
my $aref = $product->tier_pricing( 'trade' );
# [
# { quantity => 1, price => 20 },
# { quantity => 10, price => 19 },
# { quantity => 100, price => 18 },
# ]
=cut

# TODO: SysPete is not happy with the initial version of this method.
# Patches always welcome.

sub tier_pricing {
my ( $self, $args ) = @_;

my $cond = { 'role.name' => undef };

if ( $args ) {
$self->throw_exception(
"Argument to tier_pricing must be an array reference")
unless ref($args) eq 'ARRAY';

$cond = { 'role.name' => [ undef, { -in => $args } ] };
}

my @result = $self->price_modifiers->search(
$cond,
{
join => 'role',
select => [ 'quantity', { min => 'price' } ],
as => [ 'quantity', 'price' ],
group_by => 'quantity',
order_by => { -asc => 'quantity' },
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
},
)->all;

if ( scalar @result && $result[0]->{quantity} < 1 ) {

# zero or minus qty should not be possible so we adjust to one if found

$result[0]->{quantity} = 1;
}

# maybe no qty 1 tier is defined so make sure we've got one

if ( scalar @result && $result[0]->{quantity} == 1 ) {
$result[0]->{price} = $self->price
if $self->price < $result[0]->{price};
}
else {
unshift @result, +{ quantity => 1, price => $self->price };
}

# Remove quantities that are inappropriate due to price at higher
# quantity being higher (or same as) that a price at a lower quantity.
# Normally caused when there are different price breaks for different
# roles but we have been asked to combine multiple roles.

my @return;
my $previous;
foreach my $i ( @result ) {
push @return, $i;
unless ( defined $previous ) {
$previous = $i->{price};
next;
}
pop @return unless $i->{price} < $previous;
}

return wantarray ? @return : \@return;
}
#=head2 tier_pricing
#
#Tier pricing can be calculated for a single role and also a combination of several roles.
#
#=over 4
#
#=item Arguments: array reference of L<Role names|Interchange6::Schema::Result::Role/name>
#
#=item Return Value: in scalar context an array reference ordered by quantity ascending of hash references of quantity and price, in list context returns an array instead of array reference
#
#=back
#
#The method always returns the best price for specific price points including
#any PriceModifier rows where roles_id is undef.
#
# my $aref = $product->tier_pricing( 'trade' );
#
# # [
# # { quantity => 1, price => 20 },
# # { quantity => 10, price => 19 },
# # { quantity => 100, price => 18 },
# # ]
#
#=cut
#
## TODO: SysPete is not happy with the initial version of this method.
## Patches always welcome.
#
#sub tier_pricing {
# my ( $self, $args ) = @_;
#
# my $cond = { 'role.name' => undef };
#
# if ( $args ) {
# $self->throw_exception(
# "Argument to tier_pricing must be an array reference")
# unless ref($args) eq 'ARRAY';
#
# $cond = { 'role.name' => [ undef, { -in => $args } ] };
# }
#
# my @result = $self->price_modifiers->search(
# $cond,
# {
# join => 'role',
# select => [ 'quantity', { min => 'price' } ],
# as => [ 'quantity', 'price' ],
# group_by => 'quantity',
# order_by => { -asc => 'quantity' },
# result_class => 'DBIx::Class::ResultClass::HashRefInflator',
# },
# )->all;
#
# if ( scalar @result && $result[0]->{quantity} < 1 ) {
#
# # zero or minus qty should not be possible so we adjust to one if found
#
# $result[0]->{quantity} = 1;
# }
#
# # maybe no qty 1 tier is defined so make sure we've got one
#
# if ( scalar @result && $result[0]->{quantity} == 1 ) {
# $result[0]->{price} = $self->price
# if $self->price < $result[0]->{price};
# }
# else {
# unshift @result, +{ quantity => 1, price => $self->price };
# }
#
# # Remove quantities that are inappropriate due to price at higher
# # quantity being higher (or same as) that a price at a lower quantity.
# # Normally caused when there are different price breaks for different
# # roles but we have been asked to combine multiple roles.
#
# my @return;
# my $previous;
# foreach my $i ( @result ) {
# push @return, $i;
# unless ( defined $previous ) {
# $previous = $i->{price};
# next;
# }
# pop @return unless $i->{price} < $previous;
# }
#
# return wantarray ? @return : \@return;
#}

=head2 selling_price
Expand Down

0 comments on commit 9526bce

Please sign in to comment.