/** * @param $quantity * @param $taxRate * @param $basePrice * @param $shippingPrice * @return array */ public function getValues($quantity, $taxRate, $basePrice, $shippingPrice) { $subTotal = $quantity * $basePrice; $tax = TaxCalculator::totalPlusTax($basePrice, $taxRate, $quantity); $shippingTotal = $shippingPrice === null ? null : $shippingPrice * $quantity; return ['total' => $subTotal, 'shipping' => $shippingTotal, 'tax' => $tax, 'shippingBeforeTax' => $shippingTotal, 'totalBeforeTax' => $subTotal]; }
/** * @param $orderShippingPrice * @param $chargeTaxOnShipping * @param $freeShipping * @param $defaultTaxRate * @param $items * @return mixed */ public function getValues($orderShippingPrice, $chargeTaxOnShipping, $freeShipping, $defaultTaxRate, $items) { $subTotal = 0; $shipping = $orderShippingPrice; $tax = 0; // add up values for each item foreach ($items as $cartItem) { /* @var $cartItem CartItem */ $cartItemTotals = $cartItem->getValues(new CartItemValuesVATExcludedTransformer()); $subTotal += $cartItemTotals['total']; $shipping += $cartItemTotals['shipping']; $tax += $cartItemTotals['tax']; } // calculate tax on shipping $shippingTax = TaxCalculator::totalPlusTax($shipping, $defaultTaxRate, 1); return ['subTotal' => $subTotal + $tax, 'displayTotal' => $subTotal, 'shipping' => $freeShipping ? 0 : $shipping + $shippingTax, 'shippingTax' => $shippingTax, 'displayShipping' => $shipping, 'tax' => $tax + $shippingTax, 'total' => $subTotal + $shipping + $tax + $shippingTax]; }
/** * @return int */ public function getTotalPrice() { if (!$this->items) { return 0; } $total = 0; foreach ($this->getItems() as $item) { $total += $item->getPrice() + TaxCalculator::totalPlusTax($item->getPrice(), $item->getTaxRate()); } return $total; }