Back to PhocacartTax class

Method getTaxByCountry

public static
getTaxByCountry
(mixed $taxId)

Method getTaxByCountry - Source code

// Selected tax by country
public static function getTaxByCountry($taxId)
{
    $countryId = (int) self::getUserCountryId();
    $taxChangedA = array();
    $taxChangedA['taxrate'] = '';
    // the rate can be 0 and zero is OK
    $taxChangedA['taxtitle'] = '';
    $taxChangedA['taxcountryid'] = 0;
    $taxChangedA['taxregionid'] = 0;
    if ((int) $taxId > 0 && $countryId > 0) {
        $db = Factory::getDBO();
        $q = 'SELECT tc.id, tc.title, tc.tax_rate' . ' FROM #__phocacart_tax_countries as tc' . ' WHERE tc.country_id = ' . (int) $countryId . ' AND tc.tax_id = ' . (int) $taxId . ' AND tc.tax_rate > -1' . ' LIMIT 1';
        $db->setQuery($q);
        $taxO = $db->loadObject();
        if (isset($taxO->tax_rate) && $taxO->tax_rate != '') {
            $taxChangedA['taxrate'] = $taxO->tax_rate;
        }
        if (isset($taxO->title) && $taxO->title != '') {
            $taxChangedA['taxtitle'] = $taxO->title;
        }
        if (isset($taxO->id) && $taxO->id != '') {
            $taxChangedA['taxcountryid'] = $taxO->id;
        }
        // CONDITIONS:
        // $taxChangedA['taxrate'] > 0 ... not used - the rate can be 0
        // $taxChangedA['taxtitle'] ... not used - the title can be empty
        // if ($taxChangedA['taxrate'] > 0 && $taxChangedA['taxtitle'] != '') { // the rate can be 0
        //
        if ($taxChangedA['taxrate'] != '') {
            return $taxChangedA;
            // if 0, it is valid
        }
    }
    return false;
}