AbanteCart Community
Shopping Cart Operations => Support => General Support => Topic started by: hus2020 on February 24, 2017, 03:58:33 AM
-
Hi guys,
I noticed the file /storefront/model/total/balance.php has some bug. The sort_order is defaulted and hard coded to 999 which makes the back end setting Extensions > Order Total to not work. In back-end if I change calculation order to 2, the balance is still deducted from Order Total and not Sub Total. Can anyone advice what changes are needed to the code below so that the calculation order that is set is respected in checkout.
<?php
/*------------------------------------------------------------------------------
$Id$
AbanteCart, Ideal OpenSource Ecommerce Solution
http://www.AbanteCart.com
Copyright © 2011-2016 Belavier Commerce LLC
This source file is subject to Open Software License (OSL 3.0)
License details is bundled with this package in the file LICENSE.txt.
It is also available at this URL:
<http://www.opensource.org/licenses/OSL-3.0>
UPGRADE NOTE:
Do not edit or add to this file if you wish to upgrade AbanteCart to newer
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/
if (! defined ( 'DIR_CORE' )) {
header ( 'Location: static_pages/' );
}
class ModelTotalBalance extends Model {
public function getTotal(&$total_data, &$total, &$taxes, &$cust_data) {
if ($this->config->get('balance_status')) {
if((float)$cust_data['used_balance']){
$total_data[] = array(
'id' => 'balance',
'title' => $this->language->get('text_balance_checkout'),
'text' => '-'.$this->currency->format($cust_data['used_balance']),
'value' => - $this->session->data['used_balance'],
'sort_order' => 999,
'total_type' => 'balance'
);
$total -= $cust_data['used_balance'];
}
}
}
}
-
Are you sure? You can not change the order I think.
-
This is not a bug. Balance should be always applied last in the sequence of total. Purpose of the balance applied to final order total (not sub total)
-
This is not a bug. Balance should be always applied last in the sequence of total. Purpose of the balance applied to final order total (not sub total)
OK point taken. But then the Order Total extension becomes useless. The customization of calculation order will always be ignored. Can this be customized so it behaves similar like handling.php which always follow whatever calculation order we define. Tq.
-
See how Hadling fee works and made changes to the your total
https://github.com/abantecart/abantecart-src/blob/master/public_html/storefront/model/total/handling.php#L69
-
See how Hadling fee works and made changes to the your total
https://github.com/abantecart/abantecart-src/blob/master/public_html/storefront/model/total/handling.php#L69
I have tried to mimic the handling.php code on balance.php to be able to reflect the calculation order. However, when I upload the new balance.php file, the account balance value dissapears completely from order summary. Can anyone check my code, and pinpoint where did I do wrong.
p/s: Recap : What I want achieve is that to be able to apply account balance after sub-total immediately, and not after full order total as the default. I do not want any value such as tax etc to be deducted using account balance.
<?php
/*------------------------------------------------------------------------------
$Id$
AbanteCart, Ideal OpenSource Ecommerce Solution
http://www.AbanteCart.com
Copyright © 2011-2016 Belavier Commerce LLC
This source file is subject to Open Software License (OSL 3.0)
License details is bundled with this package in the file LICENSE.txt.
It is also available at this URL:
<http://www.opensource.org/licenses/OSL-3.0>
UPGRADE NOTE:
Do not edit or add to this file if you wish to upgrade AbanteCart to newer
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/
if (! defined ( 'DIR_CORE' )) {
header ( 'Location: static_pages/' );
}
class ModelTotalBalance extends Model {
public function getTotal(&$total_data, &$total, &$taxes, &$cust_data) {
if ($this->config->get('balance_status')){
$conf_blc_subtotal = 0;
//$conf_blc_tax_id = $this->config->get('handling_tax_class_id');
$pre_total = $total;
if($this->config->get('balance_prefix')=='%'){
$conf_blc_fee = $pre_total*(float)$this->config->get('balance_fee')/100.00;
}else{
$conf_blc_fee = (float)$this->config->get('balance_fee');
}
$per_payment = unserialize($this->config->get('balance_per_payment'));
if(is_array($per_payment)){
$customer_payment = $cust_data['payment_method']['id'];
foreach($per_payment['balance_payment'] as $i=>$payment_id){
if($customer_payment==$payment_id){
if($pre_total<(float)$per_payment['balance_payment_subtotal'][$i]){
$conf_blc_subtotal = (float)$per_payment['balance_payment_subtotal'][$i];
if($per_payment['balance_payment_prefix'][$i]=='%'){
if((float)$per_payment['balance_payment_fee'][$i]>0){
$conf_blc_fee = $pre_total*(float)$per_payment['balance_payment_fee'][$i]/100.00;
}
}else{
$conf_blc_fee = (float)$per_payment['balance_payment_fee'][$i];
}
break;
}
}
}
}
// if fee for payment is not set - use default fee
$conf_blc_subtotal = !$conf_blc_subtotal ? (float)$this->config->get('balance_total') : $conf_blc_subtotal;
if ($pre_total < $conf_blc_subtotal && $conf_blc_fee>0) {
$this->load->language('total/balance');
$this->load->model('localisation/currency');
$total_data[] = array(
'id' => 'balance',
'title' => $this->language->get('text_balance'),
'text' => $this->currency->format($conf_blc_fee),
'value' => $conf_blc_fee,
'sort_order' => $this->config->get('balance_sort_order'),
'total_type' => $this->config->get('balance_fee_total_type')
);
//if ($conf_blc_tax_id) {
//if (!isset($taxes[$conf_blc_tax_id])) {
// $taxes[$conf_blc_tax_id]['total'] = $conf_blc_fee;
// $taxes[$conf_blc_tax_id]['tax'] = $this->tax->calcTotalTaxAmount($conf_blc_fee, $conf_blc_tax_id);
//} else {
// $taxes[$conf_blc_tax_id]['total'] += $conf_blc_fee;
// $taxes[$conf_blc_tax_id]['tax'] += $this->tax->calcTotalTaxAmount($conf_blc_fee, $conf_blc_tax_id);
//}
//}
$total += $conf_blc_fee;
}
}
}
}
-
I checked the code and I can not see any issue with it. Can you debug it and see if it getting called?
Check if this has correct value:
'total_type' => $this->config->get('balance_fee_total_type')
-
Im running Abantecart live on my hosting package and not in an IDE. Not sure how do I debug it. When you're free can you help me look into it.
So far the code snippet that I send was just the exact copy of handling code, but modifying the variables. Im not even sure im calling the right variables.
And lets say if this way does not work, how can I just hardcode the calculation order.
I need the account balance to deduct just from the order sub total and not the final total.
I checked the code and I can not see any issue with it. Can you debug it and see if it getting called?
Check if this has correct value:
'total_type' => $this->config->get('balance_fee_total_type')
-
Hii.. Anyone kind enough to help me with this please......