Getting the Customer’s Address Country For Tax Calculations
The following will perform the following fallbacks:
-The quote’s shipping address
-The customer’s shipping address
-The customer’s billing address
-The default system configuration country
class Namespace_Module_Helper_Data extends Mage_Core_Helper_Abstract { const COUNTRY_CODE_GB = "GB"; public function isDeliveryAddressUk(){ /** @var Mage_Sales_Model_Quote $quote */ $quote = Mage::getSingleton('checkout/session')->getQuote(); $address = $quote->getShippingAddress(); if($address && $address->getCountryId()){ return $address->getCountryId() == self::COUNTRY_CODE_GB; } $cSession = Mage::getSingleton('customer/session'); if($cSession->isLoggedIn()){ $customer = $cSession->getCustomer(); $address = $customer->getDefaultShippingAddress(); if($address && $address->getCountryId()){ return $address->getCountryId() == self::COUNTRY_CODE_GB; } $customer->getDefaultBillingAddress(); if($address && $address->getCountryId()){ return $address->getCountryId() == self::COUNTRY_CODE_GB; } } return Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY) == self::COUNTRY_CODE_GB; } }
Checking the Tax Display Type
// Including Tax if(Mage::helper('tax')->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX){ ... } // Excluding Tax if(Mage::helper('tax')->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX){ ... }