// Selected tax by country
public static function getTaxByRegion($taxId)
{
$regionId = (int) self::getUserRegionId();
$taxChangedA = array();
$taxChangedA['taxrate'] = '';
// the rate can be 0 and zero is OK
$taxChangedA['taxtitle'] = '';
$taxChangedA['taxcountryid'] = 0;
$taxChangedA['taxregionid'] = 0;
// tax rate -1 means that the tax is not used but it exists yet (will be not completely removed because of the used ID in system
// for example if the country tax is specific and has ID 10 and it will be deleted - then it still exists but with -1 as tax rate
// when such tax will be newly recreated it gets the same ID as it has previously - which will unique tax rates for country in history
// even if the tax rate changes it uniques the tax type for each country/region
if ((int) $taxId > 0 && $regionId > 0) {
$db = Factory::getDBO();
$q = 'SELECT tr.id, tr.title, tr.tax_rate' . ' FROM #__phocacart_tax_regions as tr' . ' WHERE tr.region_id = ' . (int) $regionId . ' AND tr.tax_id = ' . (int) $taxId . ' AND tr.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['taxregionid'] = $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;
}