diff --git a/src/Calculator.php b/src/Calculator.php index ed6d603..f5f9f91 100644 --- a/src/Calculator.php +++ b/src/Calculator.php @@ -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' => [], ]; @@ -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']; diff --git a/src/Price.php b/src/Price.php index f35421c..ab7ef52 100644 --- a/src/Price.php +++ b/src/Price.php @@ -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 * diff --git a/tests/Unit/HasValueAccessorsTest.php b/tests/Unit/HasValueAccessorsTest.php index a8da64e..c765f2f 100644 --- a/tests/Unit/HasValueAccessorsTest.php +++ b/tests/Unit/HasValueAccessorsTest.php @@ -2,6 +2,7 @@ namespace Tests\Unit; +use Brick\Money\Context; use Brick\Money\Money; use Brick\Money\Currency; use Whitecube\Price\Price; @@ -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); }); \ No newline at end of file