I just started studying OpenCart, downloaded latest version of opencart and reading the documentation about where to find the function definition of tax calculate function.
In the non admin side, opening any Products shows data with tax calculation. Here is code it uses it.
$this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))
Is there any link to check the location of tax class for checking the calculate function definition?
Not quite sure what exactly do you want to achieve. But the calculate function you can find in system/library/cart/tax.php.
public function calculate($value, $tax_class_id, $calculate = true) {
if ($tax_class_id && $calculate) {
$amount = 0;
$tax_rates = $this->getRates($value, $tax_class_id);
foreach ($tax_rates as $tax_rate) {
if ($calculate != 'P' && $calculate != 'F') {
$amount += $tax_rate['amount'];
} elseif ($tax_rate['type'] == $calculate) {
$amount += $tax_rate['amount'];
}
}
return $value + $amount;
} else {
return $value;
}
}
Although in this file you will find a lot of interesting connected with tax processing in OpenCart.
If this information not enough - please, describe the desired result with more details and I will try to help.
Related
Trying to understand, why I'm not able to popup users balance using paypal sandox.
Here is my AccountBalance.php part code, when user paid in paypal
public function rebuildBalance($user_id, $amount, $bonus = 0, $frozen = false, $currency) {
$balance = UserBalance::where('user_id', $user_id)->where('currency_id', $currency)->first();
if ($bonus == 0) {
if ($frozen) {
$balance->balance_frozen += $amount;
} else {
$balance->balance += $amount;
}
} else {
$balance->bonus += $amount;
}
And when transaction is over, I got Creating default object from empty value
to this part $balance->balance += $amount;
Thankx
This is because your $balance variable is null from this query:
$balance = UserBalance::where('user_id', $user_id)->where('currency_id', $currency)->first();
Figure out why this query doesn't work the way you intend it to and you should be fine. A good start would be to figure out what $currency variable holds - and make sure you pass it correctly when calling rebuildBalance(args).
If you try to assign a property to null you get your exact error.
I'm trying to make magento modification when user enter vat number on checkout remove tax from order.
I found a code on stackoverflow which support on magento older version but it not work with new version 1.9,
I made few modifications for work the condition and return 0,even it return 0 checkout still shows tax.
here is my code which is on file
/app/code/core/Mage/Tax/Model/Calculation.php line number 268
public function getRate($request)
{
if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
return 0;
}
//my code
$ctax= Mage::getSingleton('checkout/session')->getQuote()->getCustomerTaxvat();
if ($this->getCustomer() && $ctax !='') {
//echo 'test';
return 0;
}
//end my code
$cacheKey = $this->_getRequestCacheKey($request);
if (!isset($this->_rateCache[$cacheKey])) {
$this->unsRateValue();
$this->unsCalculationProcess();
$this->unsEventModuleId();
Mage::dispatchEvent('tax_rate_data_fetch', array(
'request' => $request));
if (!$this->hasRateValue()) {
$rateInfo = $this->_getResource()->getRateInfo($request);
$this->setCalculationProcess($rateInfo['process']);
$this->setRateValue($rateInfo['value']);
} else {
$this->setCalculationProcess($this->_formCalculationProcess());
}
$this->_rateCache[$cacheKey] = $this->getRateValue();
$this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
}
return $this->_rateCache[$cacheKey];
}
Anyone can help me to make tax 0 when user enters vat number on checkout, Thanks a lot
I've managed to solve my problem by following this thread : Modify tax rate on cart quote items and recalculate
I have added an Observer to the event sales_quote_collect_totals_before.
And here is the content of my observer, very simple :
public function removetax($observer)
{
$customer_id = Mage::getSingleton('customer/session')->getId();
$customer = Mage::getModel("customer/customer")->load($customer_id);
if($customer->getIsTaxExempt() == 1)
{
$items = $observer->getEvent()->getQuote()->getAllVisibleItems();
foreach($items as $item)
$item->getProduct()->setTaxClassId(0);
}
}
If customer is tax exempt, I grab the current cart content and for each item, I set the product tax class to 0. It is mandatory to not save the product or the item. The aim here is to set a value for the following calculation, not to save it in the database. Tax classes need to stay to the initial value in the db.
You can use sales_quote_collect_totals_before event.
then you have to define logic for remove tax on checkout page.
This link you can refer.
Go to Calculation.php and find the calcTaxAmount() and add billing condditions
public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$billing = Mage::getModel('checkout/session')->getQuote()->getCustomerTaxvat();
if($billing !="")
{
return 0;
}
}
When creating an invoice with SugarCRM, I would like to add a line to the invoice header section displaying details of the total amount of the invoice (VAT included and VAT excluded) total amount. The two values can be calculated using the price keyed in in the invoice detail section.
I am told to implement this functionality using the logic hook function of SugarCRM. Since I am new to SugarCRM, could you please advise ?
This is what I have done so far :
<?php
class AddLines {
function update_amount(&$bean, $event, $arguments)
{
//Query c_inv_fee_distribution table for detail_amount value of parent
$bean->client_po = 'working';
}
}
class PriceCalc {
function taxdetail(&$bean, $event, $arguments)
{
$total_amt_excl = 0;
$total_amt_incl = 0;
$line_price = $number_units * $unit_price;
$invoicelength = count($bean->invoice);
for ($line_number=0; $line_number < $invoicelength); $line_number++)
{
if $VAT = true {
$total_amt_excl += $line_price[line_number];
$total_amt_incl += $line_price[line_number] * 1.14;
}else {
$total_amt_excl += $line_price[line_number];
$total_amt_incl += $line_price[line_number];
}
}
}
?>
I want to make an option if the customer want same day delivery the delivery charges will be $10 else it will be standard charges. just want to add check-box for same day delivery.i have that much information only, if someone can help I would be really happy since its been tough for me.
Assuming you have passed deliveryDate in request shipping object.
If we consider code of flat rate.Then in below function
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
If($request->Deliverydate == Today )// replace code for getting today
{
ShippingPrice=10;
}
elseif ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
} else {
$shippingPrice = false;
}
I am trying to get the subtotal amount on checkout success page. It works good for registred users:
$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$amount = $_order->getData('subtotal');
$total = number_format($amount, 2);
But when the order is processed by a guest, $total is empty.
What can be done?
P.S.: I am using Magento 1.6.1 CE
Taken from Magento's app/code/core/Mage/Checkout/Block/Onepage.php:
if (!$this->isCustomerLoggedIn()) {
return $this->getQuote()->getShippingAddress();
} else {
return Mage::getModel('sales/quote_address');
}
I am 99% sure you can do exactly the same with getOrder() and with Mage_Checkout_Block_Success =)
Note: the isCustomerLoggedIn() method is defined at Mage_Checkout_Block_Onepage_Abstract which is not inherited by Mage_Checkout_Block_Success. So, you could simply use its implementation:
public function isCustomerLoggedIn()
{
return Mage::getSingleton('customer/session')->isLoggedIn();
}
E.g. your code now shall look like this:
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
$order = Mage::getSingleton('checkout/session')->getOrder();
} else {
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
}
Sorry for saying non-sense things before...