Sometimes you may need to know how much the current outstanding and paid amount. Especially you accept the preorder and customer only paid deposit on it.
Aslo it is easier to make mistake when you manually add the order thru the backoffice for the offline order like whatsapp, email, phone channel. For the new version of order page, you need to scroll down to the bottom for payment detail. Therefore, an outstanding and paid amount display will be very convenient.
I will not recommend this method. Directly modifing the core code will be very dangerous when you need to upgrade. During the version, all of your code will be gone. Our introduction here is only for reference because we don’t want to spend a paragraph to teach how to write a module for that.
In order to introduce a fastest solution with few paragraphs, you can follow the below tutorial.
Add the following content after line 532
// start – edited by admin @22Jul2022
$paidAmount = 0;
$balanceAmount = 0;
$amountToPay = $orderForViewing->getPrices()->getTotalAmountFormatted();
$amountToPay = floatval(preg_replace(‘/[^\d\.]+/’, ”, $amountToPay));
$paymentArrayAmt = array_values((array)$orderForViewing->getPayments());
foreach($paymentArrayAmt[0] as $key){
//echo “<pre>”;
$originvalue = $key->getAmount(); // Adrian
// is negative number
$neg = strpos((string)$originvalue, ‘-‘) !== false;
// remove everything except numbers and dot “.”
$originvalue = preg_replace(“/[^0-9\.]/”, “”, $originvalue);
// Set negative number
if( $neg ) {
$originvalue = ‘-‘.$originvalue;
}
//convert string to float
$originvalue = (float) $originvalue;
// sum all order payment amount
$paidAmount += $originvalue;
}
// calculate from Total Amount substract Paid Amount
$balanceAmount = $amountToPay – $paidAmount;
// verify null value if true store default value 0 and set the price format
if (empty($balanceAmount)) {
$balanceAmount = $this->getContextLocale()->formatPrice(0, $orderCurrency->iso_code);
}else{
$balanceAmount = $this->getContextLocale()->formatPrice($balanceAmount, $orderCurrency->iso_code);
}
if (empty($paidAmount)) {
$paidAmount = $this->getContextLocale()->formatPrice(0, $orderCurrency->iso_code);
} else {
$paidAmount = $this->getContextLocale()->formatPrice($paidAmount, $orderCurrency->iso_code);
}
// end – edited by admin @23Jul2022
return$this->render(‘@PrestaShop/Admin/Sell/Order/Order/view.html.twig’, [
// start – edited by admin @@23Jul2022
‘outstandingAmt’ => $balanceAmount,
‘orderPaymentPaidAmt’ => $paidAmount,
// end – edited by admin @@23Jul2022
/src/PrestaShopBundle/Resources/views/Admin/Sell/Order/Order/Blocks/View/products.html.twig
/src/PrestaShopBundle/Resources/views/Admin/Sell/Order/Order/Blocks/View/payments_alert.html.twig