From 14e8a405347752b2cfde1689d5fce30dacac357a Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Fri, 27 Sep 2019 19:00:10 +0200 Subject: [PATCH] Changed $taxRate from private to public, Solve https://github.com/Crinsane/LaravelShoppingcart/issues/436 --- src/CartItem.php | 14 +++++++------- tests/CartTest.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/CartItem.php b/src/CartItem.php index 579c6b6..5a49ef2 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -58,6 +58,13 @@ class CartItem implements Arrayable, Jsonable */ public $options; + /** + * The tax rate for the cart item. + * + * @var int|float + */ + public $taxRate = 0; + /** * The FQN of the associated model. * @@ -65,13 +72,6 @@ class CartItem implements Arrayable, Jsonable */ private $associatedModel = null; - /** - * The tax rate for the cart item. - * - * @var int|float - */ - private $taxRate = 0; - /** * The discount rate for the cart item. * diff --git a/tests/CartTest.php b/tests/CartTest.php index fc8f6ab..e9acea9 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -756,6 +756,20 @@ class CartTest extends TestCase $this->assertEquals('1.050,00', $cart->tax(2, ',', '.')); } + /** @test */ + public function it_can_access_tax_as_percentage() + { + $cart = $this->getCart(); + + $cart->add(new BuyableProduct(1, 'Some title', 10.00), 1); + + $cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19); + + $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); + + $this->assertEquals(19, $cartItem->taxRate); + } + /** @test */ public function it_can_return_the_subtotal() {