Add config option to get tax based on billing address instead of shipping addres

Started by razor7, December 11, 2012, 02:08:18 AM

Previous topic - Next topic

razor7

Hi, recently I needed to base all taxes in billing address instead of shipping address, so I needed to tweak core file administrator/components/com_virtuemart/helpers/calculationh.php. As you can see in the code below, VM tryes to load shipping address first, but in my case, i needed to use billing address

if (!empty($this->_cart->ST['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->ST['virtuemart_country_id'];
} else if (!empty($this->_cart->BT['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->BT['virtuemart_country_id'];
}

if (!empty($this->_cart->ST['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->ST['virtuemart_state_id'];
} else if (!empty($cart->BT['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->BT['virtuemart_state_id'];
}


I think that with a minor tweak, you can add config option to let VM admins select if tax may be calculated by billing or shipping addres, with something like this

if (VmConfig::get('taxbasedonshipping','1')!='0' && !empty($this->_cart->ST['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->ST['virtuemart_country_id'];
} else if (!empty($this->_cart->BT['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->BT['virtuemart_country_id'];
}

if (VmConfig::get('taxbasedonshipping','1')!='0' && !empty($this->_cart->ST['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->ST['virtuemart_state_id'];
} else if (!empty($cart->BT['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->BT['virtuemart_state_id'];
}


It would be great to have that feature enabled!
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

Milbo

added like this:

$stBased = VmConfig::get('taxSTbased',TRUE);
if ($stBased and !empty($this->_cart->ST['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->ST['virtuemart_country_id'];
} else if (!empty($this->_cart->BT['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->BT['virtuemart_country_id'];
}

if ($stBased and !empty($this->_cart->ST['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->ST['virtuemart_state_id'];
} else if (!empty($cart->BT['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->BT['virtuemart_state_id'];
}


But there wont be any gui for 2.0.x family. I wanna add it for vm2.2 then. But if you know how to use the tools and the configuration file, then it is a permanent solution for you.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

giannisth

Quote from: Milbo on December 18, 2012, 14:30:22 PM
added like this:

$stBased = VmConfig::get('taxSTbased',TRUE);
if ($stBased and !empty($this->_cart->ST['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->ST['virtuemart_country_id'];
} else if (!empty($this->_cart->BT['virtuemart_country_id'])) {
$this->_deliveryCountry = (int)$this->_cart->BT['virtuemart_country_id'];
}

if ($stBased and !empty($this->_cart->ST['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->ST['virtuemart_state_id'];
} else if (!empty($cart->BT['virtuemart_state_id'])) {
$this->_deliveryState = (int)$this->_cart->BT['virtuemart_state_id'];
}


But there wont be any gui for 2.0.x family. I wanna add it for vm2.2 then. But if you know how to use the tools and the configuration file, then it is a permanent solution for you.
hi there, very interesting but in which line of code do we put this in?we replace the original part or do we put it along with the other?
i am using v.2.0.18a with joomla 1.5.28
thanks a lot :D