VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: razor7 on December 11, 2012, 02:08:18 AM

Title: Add config option to get tax based on billing address instead of shipping addres
Post by: razor7 on December 11, 2012, 02:08:18 AM
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!
Title: Re: Add config option to get tax based on billing address instead of shipping addres
Post by: 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.
Title: Re: Add config option to get tax based on billing address instead of shipping addres
Post by: giannisth on January 13, 2013, 15:53:02 PM
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