Exemple #1
0
function fn_calculate_tax_rates($taxes, $price, $amount, $auth, &$cart)
{
    static $destination_id;
    static $tax_description;
    static $user_data;
    $taxed_price = $price;
    if (!empty($cart['user_data']) && !fn_is_empty($cart['user_data'])) {
        $profile_fields = fn_get_profile_fields('O', $auth);
        $billing_population = fn_check_profile_fields_population($cart['user_data'], 'B', $profile_fields);
        $shipping_population = fn_check_profile_fields_population($cart['user_data'], 'S', $profile_fields);
        if (empty($auth['user_id']) && (!$shipping_population || !$billing_population)) {
            fn_define('ESTIMATION', true);
        }
    }
    if (empty($auth['user_id']) && (empty($cart['user_data']) || fn_is_empty($cart['user_data']) || $billing_population != true || $shipping_population != true) && Registry::get('runtime.checkout') && Registry::get('settings.Appearance.taxes_using_default_address') !== 'Y' && !defined('ESTIMATION')) {
        return false;
    }
    if (empty($destination_id) || $user_data != @$cart['user_data']) {
        // Get billing location
        $location = fn_get_customer_location($auth, $cart, true);
        $destination_id['B'] = fn_get_available_destination($location);
        // Get shipping location
        $location = fn_get_customer_location($auth, $cart);
        $destination_id['S'] = fn_get_available_destination($location);
    }
    if (!empty($cart['user_data'])) {
        $user_data = $cart['user_data'];
    }
    $_tax = 0;
    $previous_priority = -1;
    $previous_price = '';
    foreach ($taxes as $key => $tax) {
        if (empty($tax['tax_id'])) {
            $tax['tax_id'] = $key;
        }
        if (empty($tax['priority'])) {
            $tax['priority'] = 0;
        }
        $_is_zero = floatval($taxed_price);
        if (empty($_is_zero)) {
            continue;
        }
        if (!empty($cart['stored_taxes']) && $cart['stored_taxes'] == 'Y' && (!empty($tax['rate_type']) || isset($cart['taxes'][$tax['tax_id']]['rate_value']))) {
            $rate = array('rate_value' => isset($cart['taxes'][$tax['tax_id']]['rate_value']) ? $cart['taxes'][$tax['tax_id']]['rate_value'] : $tax['rate_value'], 'rate_type' => isset($cart['taxes'][$tax['tax_id']]['rate_type']) ? $cart['taxes'][$tax['tax_id']]['rate_type'] : $tax['rate_type']);
        } else {
            if (!isset($destination_id[$tax['address_type']])) {
                continue;
            }
            $rate = db_get_row("SELECT destination_id, rate_value, rate_type FROM ?:tax_rates WHERE tax_id = ?i AND destination_id = ?i", $tax['tax_id'], $destination_id[$tax['address_type']]);
            if (!@floatval($rate['rate_value'])) {
                continue;
            }
        }
        $base_price = $tax['priority'] == $previous_priority ? $previous_price : $taxed_price;
        if ($rate['rate_type'] == 'P') {
            // Percent dependence
            // If tax is included into the price
            if ($tax['price_includes_tax'] == 'Y') {
                $_tax = fn_format_price($base_price - $base_price / (1 + $rate['rate_value'] / 100));
                // If tax is NOT included into the price
            } else {
                $_tax = fn_format_price($base_price * ($rate['rate_value'] / 100));
                $taxed_price += $_tax;
            }
        } else {
            $_tax = fn_format_price($rate['rate_value']);
            // If tax is NOT included into the price
            if ($tax['price_includes_tax'] != 'Y') {
                $taxed_price += $_tax;
            }
        }
        $previous_priority = $tax['priority'];
        $previous_price = $base_price;
        if (empty($tax_description[$tax['tax_id']])) {
            $tax_description[$tax['tax_id']] = db_get_field("SELECT tax FROM ?:tax_descriptions WHERE tax_id = ?i AND lang_code = ?s", $tax['tax_id'], CART_LANGUAGE);
        }
        $taxes_data[$tax['tax_id']] = array('rate_type' => $rate['rate_type'], 'rate_value' => $rate['rate_value'], 'price_includes_tax' => $tax['price_includes_tax'], 'regnumber' => @$tax['regnumber'], 'priority' => @$tax['priority'], 'tax_subtotal' => fn_format_price($_tax * $amount), 'description' => $tax_description[$tax['tax_id']]);
    }
    return empty($taxes_data) ? false : $taxes_data;
}
Exemple #2
0
 // Check fields population on first and second steps
 if (($contact_info_population || $guest_checkout) && empty($_SESSION['failed_registration'])) {
     if (!fn_check_profile_fields_population($cart['user_data'], 'C', $profile_fields)) {
         $recheck_edit_step = false;
         if ($cart['edit_step'] != 'step_one') {
             fn_set_notification('W', __('notice'), __('text_fill_the_mandatory_fields'));
             return array(CONTROLLER_STATUS_REDIRECT, "checkout.checkout?edit_step=step_one");
         }
     }
     $completed_steps['step_one'] = true;
     // All mandatory Billing address data exist.
     $billing_population = fn_check_profile_fields_population($cart['user_data'], 'B', $profile_fields);
     Tygh::$app['view']->assign('billing_population', $billing_population);
     if ($billing_population == true || empty($profile_fields['B'])) {
         // All mandatory Shipping address data exist.
         $shipping_population = fn_check_profile_fields_population($cart['user_data'], 'S', $profile_fields);
         Tygh::$app['view']->assign('shipping_population', $shipping_population);
         if ($shipping_population == true || empty($profile_fields['S'])) {
             $completed_steps['step_two'] = true;
         }
     }
 } elseif ($guest_checkout && !empty($_SESSION['failed_registration'])) {
     $completed_steps['step_one'] = true;
 }
 // Define the variable only if the profiles have not been changed and settings.General.user_multiple_profiles == Y.
 if (fn_need_shipping_recalculation($cart) == false && (!empty($cart['product_groups']) && (Registry::get('settings.General.user_multiple_profiles') != "Y" || Registry::get('settings.General.user_multiple_profiles') == "Y" && (isset($user_data['profile_id']) && empty($user_data['profile_id']) || !empty($user_data['profile_id']) && $user_data['profile_id'] == $cart['profile_id'])) || empty($cart['product_groups']) && Registry::get('settings.General.user_multiple_profiles') == "Y" && isset($user_data['profile_id']) && empty($user_data['profile_id']))) {
     define('CACHED_SHIPPING_RATES', true);
 }
 if ($cart['edit_step'] == 'step_three' || $cart['edit_step'] == 'step_four' || $completed_steps['step_two']) {
     $cart['calculate_shipping'] = true;
 }
Exemple #3
0
/**
 * Checks if user data are complete
 *
 * @param array $user_data Array of user data @see fn_get_user_info
 * @param string $location Location identifier
 * @param array $auth - authentication information
 * @return bool True on success, false otherwise
 */
function fn_check_profile_fields($user_data, $location = 'C', $auth = array())
{
    $result = true;
    $profile_fields = fn_get_profile_fields($location, $auth);
    if ($location == 'O') {
        unset($profile_fields['E']);
    }
    foreach ($profile_fields as $section => $fields) {
        if (!fn_check_profile_fields_population($user_data, $section, $profile_fields)) {
            $result = false;
            break;
        }
    }
    return $result;
}