Skip to content

Commit

Permalink
Merge pull request #57 from lukepolo/price_subtotal
Browse files Browse the repository at this point in the history
fixing get price and sub total on the item
  • Loading branch information
lukepolo committed Jan 20, 2016
2 parents a09f2b3 + 623d43d commit 8107c41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function removeSubItem($subItemHash)
*/
public function getPrice($tax = false, $format = true)
{
$price = $this->price * $this->qty;
$price = $this->price + $this->subItemsTotal($tax, false);
if ($tax && $this->taxable) {
$price += $price * $this->tax;
}
Expand All @@ -166,7 +166,7 @@ public function getPrice($tax = false, $format = true)
*/
public function subTotal($tax = false, $format = true, $withDiscount = true)
{
$total = $this->getPrice($tax, false) + $this->subItemsTotal($tax, false);
$total = $this->getPrice($tax, false) * $this->qty;

if ($withDiscount) {
$total -= $this->getDiscount(false);
Expand Down
3 changes: 2 additions & 1 deletion tests/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public function testItemPriceAndQty()
$item = $this->addItem(3, 10);

$this->assertEquals(3, $item->qty);
$this->assertEquals(10, $item->price);
$this->assertEquals(10, $item->getPrice(false, false));
$this->assertEquals(30, $item->subTotal(false, false));
}

/**
Expand Down

0 comments on commit 8107c41

Please sign in to comment.