Skip to content

Commit

Permalink
change Cart's find method to use HandlesVia Array's first
Browse files Browse the repository at this point in the history
  • Loading branch information
SysPete committed Feb 29, 2016
1 parent 3e349f8 commit 274f5d8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/Interchange6/Cart.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ has products => (
clear => 'clear',
count => 'count',
is_empty => 'is_empty',
product_first => 'first',
product_get => 'get',
product_index => 'first_index',
products_array => 'elements',
Expand Down Expand Up @@ -334,7 +335,7 @@ sub add {

=head2 find
Searches for an cart product with the given SKU.
Searches for a cart product with the given SKU.
Returns cart product in case of sucess or undef on failure.
if ($product = $cart->find(9780977920174)) {
Expand All @@ -345,14 +346,7 @@ Returns cart product in case of sucess or undef on failure.

sub find {
my ( $self, $sku ) = @_;

for my $cartproduct ( $self->products_array ) {
if ( $sku eq $cartproduct->sku ) {
return $cartproduct;
}
}

return undef;
$self->product_first( sub { $sku eq $_->sku } );
}

=head2 has_subtotal
Expand Down

0 comments on commit 274f5d8

Please sign in to comment.