diff --git a/src/CanBeBought.php b/src/CanBeBought.php index eb9810f..d3e52cc 100644 --- a/src/CanBeBought.php +++ b/src/CanBeBought.php @@ -54,4 +54,16 @@ trait CanBeBought return 0; } + + /** + * Get the taxRate of the Buyable item. + */ + public function getBuyableTaxRate(CartItemOptions $options): float + { + if (($taxRate = $this->getAttribute('taxRate'))) { + return $taxRate; + } + + return config('cart.tax', 0.21); + } } diff --git a/src/Contracts/Buyable.php b/src/Contracts/Buyable.php index 675e378..3ebdb24 100644 --- a/src/Contracts/Buyable.php +++ b/src/Contracts/Buyable.php @@ -28,4 +28,9 @@ interface Buyable * Get the weight of the Buyable item. */ public function getBuyableWeight(CartItemOptions $options): int; + + /** + * Get the taxRate of the Buyable item. + */ + public function getBuyableTaxRate(CartItemOptions $options): float; } diff --git a/tests/Fixtures/BuyableProduct.php b/tests/Fixtures/BuyableProduct.php index 9265aab..18de007 100644 --- a/tests/Fixtures/BuyableProduct.php +++ b/tests/Fixtures/BuyableProduct.php @@ -68,4 +68,9 @@ class BuyableProduct extends Model implements Buyable { return $this->weight; } + + public function getBuyableTaxRate(CartItemOptions $options): float + { + return $this->tax_rate; + } }