Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
[~TASK] Basic implementation for issue #13 - needs more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
therouv committed May 18, 2012
1 parent c3364a5 commit fac0967
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 5 deletions.
88 changes: 88 additions & 0 deletions src/app/code/community/FireGento/GermanSetup/Model/Tax/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* This file is part of the FIREGENTO project.
*
* FireGento_GermanSetup is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* PHP version 5
*
* @category FireGento
* @package FireGento_GermanSetup
* @author FireGento Team <team@firegento.com>
* @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 <team@firegento.com>
* @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;
}
}
15 changes: 10 additions & 5 deletions src/app/code/community/FireGento/GermanSetup/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
</FireGento_GermanSetup>
</modules>
<global>
<models>
<germansetup>
<class>FireGento_GermanSetup_Model</class>
</germansetup>
</models>
<blocks>
<germansetup>
<class>FireGento_GermanSetup_Block</class>
Expand All @@ -26,6 +21,16 @@
<class>FireGento_GermanSetup_Helper</class>
</germansetup>
</helpers>
<models>
<germansetup>
<class>FireGento_GermanSetup_Model</class>
</germansetup>
<tax>
<rewrite>
<config>FireGento_GermanSetup_Model_Tax_Config</config>
</rewrite>
</tax>
</models>
<resources>
<germansetup_setup>
<setup>
Expand Down
18 changes: 18 additions & 0 deletions src/app/code/community/FireGento/GermanSetup/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,23 @@
</analytics>
</groups>
</google>
<tax>
<groups>
<classes>
<fields>
<shipping_tax_on_product_tax translate="label,comment" module="germansetup">
<label>Shipping Tax Class on Product Tax Class</label>
<comment>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!</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>11</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</shipping_tax_on_product_tax>
</fields>
</classes>
</groups>
</tax>
</sections>
</config>

0 comments on commit fac0967

Please sign in to comment.