Skip to content

Commit

Permalink
Merge pull request #6 from whitecube/master
Browse files Browse the repository at this point in the history
Fixed price context mismatch
  • Loading branch information
toonvandenbos authored Mar 4, 2021
2 parents 649a1ea + a6e4a2b commit 15deb4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function getExclusiveAfterVatResult($perUnit)
$vat = $this->price->vat();

$result = [
'amount' => Money::zero($this->price->currency()),
'amount' => Money::zero($this->price->currency(), $this->price->context()),
'modifications' => [],
];

Expand All @@ -163,7 +163,7 @@ protected function getVatResult($perUnit)
$vat = $this->price->vat(true);

if(! $vat) {
return Money::zero($this->price->currency());
return Money::zero($this->price->currency(), $this->price->context());
}

$exclusive = $this->exclusiveBeforeVat($perUnit)['amount'];
Expand Down
10 changes: 10 additions & 0 deletions src/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ public function currency()
return $this->base->getCurrency();
}

/**
* Return the price's underlying context instance
*
* @return \Brick\Money\Context
*/
public function context()
{
return $this->base->getContext();
}

/**
* Return the price's base value
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/HasValueAccessorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Unit;

use Brick\Money\Context;
use Brick\Money\Money;
use Brick\Money\Currency;
use Whitecube\Price\Price;
Expand All @@ -19,4 +20,12 @@

expect($currency)->toBeInstanceOf(Currency::class);
expect($currency->getCurrencyCode())->toBe('EUR');
});

it('can access the context object', function() {
$price = Price::EUR(100);

$context = $price->context();

expect($context)->toBeInstanceOf(Context::class);
});

0 comments on commit 15deb4d

Please sign in to comment.