LukePOLO\LaraCart\LaraCart::taxTotal PHP Method

taxTotal() public method

Gets the total tax for the cart.
public taxTotal ( boolean | true $format = true ) : string
$format boolean | true
return string
    public function taxTotal($format = true)
    {
        $totalTax = 0;
        $discounted = 0;
        $totalDiscount = $this->totalDiscount(false);
        if ($this->count() != 0) {
            foreach ($this->getItems() as $item) {
                if ($discounted >= $totalDiscount) {
                    $totalTax += $item->tax();
                } else {
                    $itemPrice = $item->subTotal(false);
                    if ($discounted + $itemPrice > $totalDiscount) {
                        $totalTax += $item->tax($totalDiscount - $discounted);
                    }
                    $discounted += $itemPrice;
                }
            }
        }
        foreach ($this->getFees() as $fee) {
            if ($fee->taxable) {
                $totalTax += $fee->amount * $fee->tax;
            }
        }
        return $this->formatMoney($totalTax, null, null, $format);
    }