function fn_calculate_product_taxes($product_id, $product_price) { $product_taxes = fn_get_set_taxes(db_get_field('SELECT tax_ids FROM ?:products WHERE product_id = ?i', $product_id)); $calculated_data = fn_calculate_tax_rates($product_taxes, $product_price, 1, $auth, $_SESSION['cart']); // Apply taxes to product subtotal if (!empty($calculated_data)) { foreach ($calculated_data as $_k => $v) { $tax_value += $v['tax_subtotal']; if ($v['price_includes_tax'] != 'Y') { $included_tax = true; $product_price += $v['tax_subtotal']; } } } $product_tax['clean_price'] = $product_price - $tax_value; $product_tax['taxed_price'] = $product_price; $product_tax['taxes'] = $calculated_data; $product_tax['included_tax'] = $included_tax; return $product_tax; }
function fn_get_taxed_and_clean_prices(&$product, &$auth) { $tax_value = 0; $included_tax = false; if (empty($product) || empty($product['product_id']) || empty($product['tax_ids'])) { return false; } if (isset($product['subtotal'])) { $tx_price = $product['subtotal']; } elseif (empty($product['price'])) { $tx_price = 0; } elseif (isset($product['discounted_price'])) { $tx_price = $product['discounted_price']; } else { $tx_price = $product['price']; } $product_taxes = fn_get_set_taxes($product['tax_ids']); $calculated_data = fn_calculate_tax_rates($product_taxes, $tx_price, 1, $auth, $_SESSION['cart']); // Apply taxes to product subtotal if (!empty($calculated_data)) { foreach ($calculated_data as $_k => $v) { $tax_value += $v['tax_subtotal']; if ($v['price_includes_tax'] != 'Y') { $included_tax = true; $tx_price += $v['tax_subtotal']; } } } $product['clean_price'] = $tx_price - $tax_value; $product['taxed_price'] = $tx_price; $product['taxes'] = $calculated_data; $product['included_tax'] = $included_tax; return true; }