Skip to content

Commit

Permalink
fixed getTotal returning 0 when there is no conditions added
Browse files Browse the repository at this point in the history
  • Loading branch information
darryldecode committed Feb 24, 2015
1 parent 918d44d commit e455bf0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ public function getTotal()

$conditions = $this->getConditions();

// if no conditions were added, just return the sub total
if( ! $conditions->count() ) return $subTotal;

$conditions->each(function($cond) use ($subTotal, &$newTotal, &$process)
{
if( $cond->getTarget() === 'total' )
Expand Down
13 changes: 13 additions & 0 deletions tests/CartConditionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public function tearDown()
m::close();
}

public function test_total_without_condition()
{
$this->fillCart();

$this->assertEquals(187.49, $this->cart->getSubTotal(), 'Cart should have sub total of 187.49');

// no changes in subtotal as the condition's target added was for total
$this->assertEquals(187.49, $this->cart->getSubTotal(), 'Cart should have sub total of 187.49');

// total should be the same as subtotal
$this->assertEquals(187.49, $this->cart->getTotal(), 'Cart should have a total of 187.49');
}

public function test_total_with_condition()
{
$this->fillCart();
Expand Down

0 comments on commit e455bf0

Please sign in to comment.