Back to PhocacartTax class

Method getUserRegionId

public static
getUserRegionId
()

Method getUserRegionId - Source code

public static function getUserRegionId()
{
    // 1. We get information about country stored by user
    // 2. Possible improvement get country by IP (but possible problem)
    $user = PhocacartUser::getUser();
    $app = Factory::getApplication();
    $paramsC = PhocacartUtils::getComponentParameters();
    $dynamic_tax_rate = $paramsC->get('dynamic_tax_rate', 0);
    $type = 0;
    if ($dynamic_tax_rate == 1) {
        $type = 0;
        // BILLING
    } else {
        if ($dynamic_tax_rate == 2) {
            $type = 1;
            // SHIPPING
        }
    }
    if (isset($user->id) && (int) $user->id > 0 && (int) $dynamic_tax_rate > 0) {
        $db = Factory::getDBO();
        $q = 'SELECT region' . ' FROM #__phocacart_users' . ' WHERE user_id = ' . (int) $user->id . ' AND type = ' . (int) $type . ' LIMIT 1';
        $db->setQuery($q);
        $regionId = $db->loadResult();
        if ((int) $regionId > 0) {
            return $regionId;
        }
    }
    return 0;
}