Skip to content

Commit

Permalink
Merge pull request #280 from sumitwebkul/gli-653
Browse files Browse the repository at this point in the history
Wrong amount displayed in Order confirmation page in the payment gateways PaymentReturn Hook
  • Loading branch information
rohit053 authored Jan 31, 2022
2 parents 2b637c7 + 7e582da commit 6da951d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 43 deletions.
22 changes: 13 additions & 9 deletions classes/order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -1913,18 +1913,22 @@ public function getTotalPaid($currency = null)
}

/**
* Get the sum of total_paid_tax_incl of the orders with similar reference
*
* @since 1.5.0.1
* Get the sum of total_paid_tax_incl/advance_paid_amount of the orders with similar reference
* @param integer $getAdvancePaid (send 1 if want total advance paid amount)
* @return float
*/
public function getOrdersTotalPaid()
public function getOrdersTotalPaid($getAdvancePaid = 0)
{
return Db::getInstance()->getValue('
SELECT SUM(total_paid_tax_incl)
FROM `'._DB_PREFIX_.'orders`
WHERE `reference` = \''.pSQL($this->reference).'\'
AND `id_cart` = '.(int)$this->id_cart);
$sql = 'SELECT';
if ($getAdvancePaid) {
$sql .= ' SUM(advance_paid_amount)';
} else {
$sql .= ' SUM(total_paid_tax_incl)';
}
$sql .= 'FROM `'._DB_PREFIX_.'orders` WHERE `reference` = \''.pSQL($this->reference).
'\' AND `id_cart` = '.(int)$this->id_cart;

return Db::getInstance()->getValue($sql);
}

/**
Expand Down
42 changes: 24 additions & 18 deletions modules/bankwire/bankwire.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,37 @@ public function hookPaymentReturn($params)
if (!$this->active) {
return;
}

$objOrder = $params['objOrder'];
$cart = new Cart($objOrder->id_cart);
$state = $objOrder->getCurrentState();
if (in_array($state, array(Configuration::get('PS_OS_BANKWIRE'), Configuration::get('PS_OS_OUTOFSTOCK'), Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')))) {
if ($objOrder->is_advance_payment) {
$order_total = $objOrder->advance_paid_amount;
$orderState = $objOrder->getCurrentState();
$smartyVars = array();
if (in_array(
$orderState,
array(
Configuration::get('PS_OS_BANKWIRE'),
Configuration::get('PS_OS_OUTOFSTOCK'),
Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')
)
)) {
$objCart = new Cart($objOrder->id_cart);
if ($objCart->is_advance_payment) {
$cartTotal = $objOrder->getOrdersTotalPaid(1);
} else {
$order_total = $objOrder->total_paid;
$cartTotal = $objOrder->getOrdersTotalPaid();
}

$this->smarty->assign(array(
'total_to_pay' => Tools::displayPrice($order_total, $params['currencyObj'], false),
'bankwireDetails' => Tools::nl2br($this->details),
'bankwireAddress' => Tools::nl2br($this->address),
'bankwireOwner' => $this->owner,
'status' => 'ok',
'id_order' => $objOrder->id
));
if (isset($objOrder->reference) && !empty($objOrder->reference)) {
$this->smarty->assign('reference', $objOrder->reference);
}
$smartyVars['total_to_pay'] = Tools::displayPrice($cartTotal, $params['currencyObj'], false);
$smartyVars['bankwireDetails'] = Tools::nl2br($this->details);
$smartyVars['bankwireAddress'] = Tools::nl2br($this->address);
$smartyVars['bankwireOwner'] = $this->owner;
$smartyVars['status'] = 'ok';
$smartyVars['id_order'] = $objOrder->id;
$smartyVars['reference'] = $objOrder->reference;
} else {
$this->smarty->assign('status', 'failed');
$smartyVars['status'] = 'failed';
}

$this->smarty->assign($smartyVars);
return $this->display(__FILE__, 'payment_return.tpl');
}

Expand Down
37 changes: 21 additions & 16 deletions modules/cheque/cheque.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,33 @@ public function hookPaymentReturn($params)
return;
}
$objOrder = $params['objOrder'];
$cart = new Cart($objOrder->id_cart);
$state = $objOrder->getCurrentState();
if (in_array($state, array(Configuration::get('PS_OS_CHEQUE'), Configuration::get('PS_OS_OUTOFSTOCK'), Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')))) {
if ($objOrder->is_advance_payment) {
$order_total = $objOrder->advance_paid_amount;
$orderState = $objOrder->getCurrentState();
if (in_array(
$orderState,
array(
Configuration::get('PS_OS_CHEQUE'),
Configuration::get('PS_OS_OUTOFSTOCK'),
Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')
)
)) {
$objCart = new Cart($objOrder->id_cart);
if ($objCart->is_advance_payment) {
$cartTotal = $objOrder->getOrdersTotalPaid(1);
} else {
$order_total = $objOrder->total_paid;
$cartTotal = $objOrder->getOrdersTotalPaid();
}

$this->smarty->assign(array(
'total_to_pay' => Tools::displayPrice($order_total, $params['currencyObj'], false),
'chequeName' => $this->chequeName,
'chequeAddress' => Tools::nl2br($this->address),
'status' => 'ok',
'id_order' => $objOrder->id
));
if (isset($objOrder->reference) && !empty($objOrder->reference))
$this->smarty->assign('reference', $objOrder->reference);
$smartyVars['total_to_pay'] = Tools::displayPrice($cartTotal, $params['currencyObj'], false);
$smartyVars['chequeName'] = $this->chequeName;
$smartyVars['chequeAddress'] = Tools::nl2br($this->address);
$smartyVars['status'] = 'ok';
$smartyVars['id_order'] = $objOrder->id;
$smartyVars['reference'] = $objOrder->reference;
} else {
$this->smarty->assign('status', 'failed');
$smartyVars['status'] = 'failed';
}

$this->smarty->assign($smartyVars);
return $this->display(__FILE__, 'payment_return.tpl');
}

Expand Down

0 comments on commit 6da951d

Please sign in to comment.