Created
October 7, 2012 19:35
-
-
Save jaromirmuller/3849333 to your computer and use it in GitHub Desktop.
Mage_Tax_Model_Calculation::getRateRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mage_Tax_Model_Calculation extends Mage_Core_Model_Abstract | |
{ | |
/** there is many methods **/ | |
/** | |
* Get request object with information necessary for getting tax rate | |
* Request object contain: | |
* country_id (->getCountryId()) | |
* region_id (->getRegionId()) | |
* postcode (->getPostcode()) | |
* customer_class_id (->getCustomerClassId()) | |
* store (->getStore()) | |
* | |
* @param null|false|Varien_Object $shippingAddress | |
* @param null|false|Varien_Object $billingAddress | |
* @param null|int $customerTaxClass | |
* @param null|int $store | |
* @return Varien_Object | |
*/ | |
public function getRateRequest( | |
$shippingAddress = null, | |
$billingAddress = null, | |
$customerTaxClass = null, | |
$store = null) | |
{ | |
if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) { | |
return $this->getRateOriginRequest($store); | |
} | |
$address = new Varien_Object(); | |
$customer = $this->getCustomer(); | |
$basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store); | |
if (($shippingAddress === false && $basedOn == 'shipping') | |
|| ($billingAddress === false && $basedOn == 'billing')) { | |
$basedOn = 'default'; | |
} else { | |
if ((($billingAddress === false || is_null($billingAddress) || !$billingAddress->getCountryId()) | |
&& $basedOn == 'billing') | |
|| (($shippingAddress === false || is_null($shippingAddress) || !$shippingAddress->getCountryId()) | |
&& $basedOn == 'shipping') | |
){ | |
if ($customer) { | |
$defBilling = $customer->getDefaultBillingAddress(); | |
$defShipping = $customer->getDefaultShippingAddress(); | |
if ($basedOn == 'billing' && $defBilling && $defBilling->getCountryId()) { | |
$billingAddress = $defBilling; | |
} else if ($basedOn == 'shipping' && $defShipping && $defShipping->getCountryId()) { | |
$shippingAddress = $defShipping; | |
} else { | |
$basedOn = 'default'; | |
} | |
} else { | |
$basedOn = 'default'; | |
} | |
} | |
} | |
switch ($basedOn) { | |
case 'billing': | |
$address = $billingAddress; | |
break; | |
case 'shipping': | |
/** | |
* This is fix for getting correct VAT in basket | |
* jaro. | |
*/ | |
$address = clone $shippingAddress; | |
if ( (!$shippingAddress->getRegionId() || !$shippingAddress->getPostcode()) && | |
$shippingAddress->getCountryId() == Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store) | |
) { | |
$address | |
->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store)) | |
->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store)); | |
} | |
break; | |
case 'origin': | |
$address = $this->getRateOriginRequest($store); | |
break; | |
case 'default': | |
$address | |
->setCountryId(Mage::getStoreConfig( | |
Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, | |
$store)) | |
->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store)) | |
->setPostcode(Mage::getStoreConfig( | |
Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, | |
$store)); | |
break; | |
} | |
if (is_null($customerTaxClass) && $customer) { | |
$customerTaxClass = $customer->getTaxClassId(); | |
} elseif (($customerTaxClass === false) || !$customer) { | |
$customerTaxClass = $this->getDefaultCustomerTaxClass($store); | |
} | |
$request = new Varien_Object(); | |
$request | |
->setCountryId($address->getCountryId()) | |
->setRegionId($address->getRegionId()) | |
->setPostcode($address->getPostcode()) | |
->setStore($store) | |
->setCustomerClassId($customerTaxClass); | |
return $request; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment