diff --git a/src/app/code/community/FireGento/GermanSetup/Model/Tax/Config.php b/src/app/code/community/FireGento/GermanSetup/Model/Tax/Config.php new file mode 100644 index 0000000..a5e01fd --- /dev/null +++ b/src/app/code/community/FireGento/GermanSetup/Model/Tax/Config.php @@ -0,0 +1,88 @@ + + * @copyright 2011 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +/** + * Tax config model with new shipping tax class calculation + * + * @category FireGento + * @package FireGento_GermanSetup + * @author FireGento Team + * @copyright 2011 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.6.2 + */ +class FireGento_GermanSetup_Model_Tax_Config extends Mage_Tax_Model_Config +{ + const XML_PATH_SHIPPING_TAX_ON_PRODUCT_TAX = 'tax/classes/shipping_tax_on_product_tax'; + + /** + * Get tax class id specified for shipping tax estimation + * + * CUSTOM: Select shipping tax class based on highest product tax rate + * + * @param store $store + * @return int + */ + public function getShippingTaxClass($store=null) + { + /* @var $session Mage_Checkout_Model_Session */ + $session = Mage::getSingleton('checkout/session'); + + $quoteItems = $session->getQuote()->getAllItems(); + $taxClassIds = array(); + $highestTaxRate = null; + + // Check if feature is enabled and if there are products in cart + if (!Mage::getStoreConfigFlag(self::XML_PATH_SHIPPING_TAX_ON_PRODUCT_TAX, $store) + || count($quoteItems) == 0 + ) { + $taxClassId = (int) Mage::getStoreConfig(self::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store); + return $taxClassId; + } + + + foreach ($quoteItems as $item) { + if ($item->getParentItem()) { + continue; + } + + $taxPercent = $item->getTaxPercent(); + if (is_float($taxPercent) && !in_array($taxPercent, $taxClassIds)) { + $taxClassIds[$taxPercent] = $item->getTaxClassId(); + } + } + + ksort($taxClassIds); + if (count($taxClassIds)) { + $highestTaxRate = array_pop($taxClassIds); + } + + if (!$highestTaxRate || is_null($highestTaxRate)) { + $taxClassId = 0; + } else { + $taxClassId = $highestTaxRate; + } + + return (int) $taxClassId; + } +} \ No newline at end of file diff --git a/src/app/code/community/FireGento/GermanSetup/etc/config.xml b/src/app/code/community/FireGento/GermanSetup/etc/config.xml index 613684e..2bcfecd 100644 --- a/src/app/code/community/FireGento/GermanSetup/etc/config.xml +++ b/src/app/code/community/FireGento/GermanSetup/etc/config.xml @@ -6,11 +6,6 @@ - - - FireGento_GermanSetup_Model - - FireGento_GermanSetup_Block @@ -26,6 +21,16 @@ FireGento_GermanSetup_Helper + + + FireGento_GermanSetup_Model + + + + FireGento_GermanSetup_Model_Tax_Config + + + diff --git a/src/app/code/community/FireGento/GermanSetup/etc/system.xml b/src/app/code/community/FireGento/GermanSetup/etc/system.xml index 8670918..b9a3096 100644 --- a/src/app/code/community/FireGento/GermanSetup/etc/system.xml +++ b/src/app/code/community/FireGento/GermanSetup/etc/system.xml @@ -253,5 +253,23 @@ + + + + + + + Set to "yes" if you want to calculate the shipping tax rate based on the highest product tax rate. Attention: This setting overwrites the tax class setting above! + select + adminhtml/system_config_source_yesno + 11 + 1 + 1 + 0 + + + + + \ No newline at end of file