Skip to content

Commit

Permalink
Merge pull request #83 from aalyusuf/master
Browse files Browse the repository at this point in the history
Additional needed methods
  • Loading branch information
darryldecode authored Mar 9, 2017
2 parents 2822e0f + b43ee3d commit 4e5716f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,22 @@ public function clearCartConditions()
);
}

/**
* get cart sub total without conditions
* @param bool $formatted
* @return float
*/
public function getSubTotalWithoutConditions($formatted = true)
{
$cart = $this->getContent();

$sum = $cart->sum(function ($item) {
return $item->getPriceSum();
});

return Helpers::formatValue(floatval($sum), $formatted, $this->config);
}

/**
* get cart sub total
* @param bool $formatted
Expand Down
11 changes: 11 additions & 0 deletions src/Darryldecode/Cart/ItemCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public function hasConditions()
return false;
}

/**
* check if item has conditions
*
* @return mixed|null
*/
public function getConditions()
{
if(! $this->hasConditions() ) return [];
return $this['conditions'];
}

/**
* get the single price in which conditions are already applied
* @param bool $formatted
Expand Down
33 changes: 33 additions & 0 deletions tests/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Darryldecode\Cart\Cart;
use Mockery as m;
use Darryldecode\Cart\CartCondition;

require_once __DIR__.'/helpers/SessionMock.php';

Expand Down Expand Up @@ -55,4 +56,36 @@ public function test_item_get_sum_price_using_array_style()

$this->assertEquals(201.98, $item->getPriceSum(), 'Item summed price should be 201.98');
}

public function test_item_get_conditions_empty()
{
$this->cart->add(455, 'Sample Item', 100.99, 2, array());

$item = $this->cart->get(455);

$this->assertEmpty($item->getConditions(), 'Item should have no conditions');
}

public function test_item_get_conditions_with_conditions()
{
$itemCondition1 = new \Darryldecode\Cart\CartCondition(array(
'name' => 'SALE 5%',
'type' => 'sale',
'target' => 'item',
'value' => '-5%',
));

$itemCondition2 = new CartCondition(array(
'name' => 'Item Gift Pack 25.00',
'type' => 'promo',
'target' => 'item',
'value' => '-25',
));

$this->cart->add(455, 'Sample Item', 100.99, 2, array(),[$itemCondition1,$itemCondition2]);

$item = $this->cart->get(455);

$this->assertCount(2,$item->getConditions(), 'Item should have two conditions');
}
}

0 comments on commit 4e5716f

Please sign in to comment.