Page 1 of 1

Order of Total and Subtotal

Posted: 14 Jun 2024, 00:23
by Nidzo
I am trying to reorder Total and Subtotal values in e-mail and PDF with overriding order.php but without success.
I want to Total value displays above Subtotal.
Can you help me please?

Image

Re: Order of Total and Subtotal

Posted: 18 Jun 2024, 16:20
by Jan
Hi,

in file: components/com_phocacart/layouts/order.php

cca on line 844, there is a foreach of all total items:

Code: Select all

$d['total']
This array needs to be run in other pre foreach and reordered and then run in the following foreach.

so e.g. you will set new keys for each item and the last one which is total will be set e.g. as zero, example:

Code: Select all

$newTotal =[];
    $i = 1;
    foreach($d['total'] as $k => $v) {
        $newTotal[$i] = $v;
        $i++;
    }
    // Latest item will become zero and last item removed
    $newTotal[0] = $newTotal[$i-1];
    unset($newTotal[$i-1]);
    ksort($newTotal);
then instead of foreach($d['total'] as $k => $v) { this: foreach($newTotal as $k => $v) {

Image

Jan

Re: Order of Total and Subtotal

Posted: 18 Jun 2024, 23:50
by Nidzo
Jan wrote: 18 Jun 2024, 16:20
Thanks Jan. I am asking this because I get informed that in Sweden practice is when an invoice is issued to a person, the total amount should be listed first. If it is a company, then the subtotal is listed first.
I am trying but with no luck.

Is that row with price 0 necessary and is it necessary to create $newTotal array?

This is //TOTAL// part of order.php in Phoca Cart 5.0.0. Beta61

Code: Select all

// TOTAL
// -----------
$t = array();
$toPay = '';

$tColspanLeft = 5;
$tColspanMid = 2;
$tColspanRight = 2;

if ($tax_calculation > 0) {
	$tColspanLeft = 7;
	$tColspanMid = 3;
	$tColspanRight = 2;
}

if (!empty($d['total'])) {
	foreach($d['total'] as $k => $v) {

		// display or not display shipping and payment methods with zero amount
		//if($v->amount == 0 && $v->amount_currency == 0 && $v->type != 'brutto' && $v->type != 'sbrutto' && $v->type != 'pbrutto') {
			if($v->amount == 0 && $v->amount_currency == 0 && $v->type != 'brutto') {
			// Don't display coupon if null

		} else if ($v->type == 'netto') {
			$t[] = '<tr '.$totalF.'>';
			$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
			$t[] = '<td colspan="'.$tColspanMid.'"><b>'. PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))).'</b></td>';
			$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'"><b>'.$d['price']->getPriceFormat($v->amount).'</b></td>';
			$t[] = '</tr>';

			if ($pR) { $oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))), $d['price']->getPriceFormat($v->amount))); }

		} else if ($v->type == 'brutto') {

			// Brutto or Brutto currency
			$amount = (isset($v->amount_currency) && $v->amount_currency > 0) ? $d['price']->getPriceFormat($v->amount_currency, 0, 1) : $d['price']->getPriceFormat($v->amount);

			$t[] = '<tr '.$totalF.'>';
			$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
			$t[] = '<td colspan="'.$tColspanMid.'"><b>'.PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))).'</b></td>';
			$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'"><b>'.$amount.'</b></td>';
			$t[] = '</tr>';


			if ($pR) {
				$oPr[] = $pP->printSeparator();
				$oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))), $amount), 0, 'pDoubleSize');
				$oPr[] = $pP->printFeed(2);
			}

			if ($d['type'] == 2) {
				$toPay = $amount;
			}

		} else if ($v->type == 'rounding') {

			// Rounding or rounding currency
			$amount = (isset($v->amount_currency) && $v->amount_currency > 0) ? $d['price']->getPriceFormat($v->amount_currency, 0, 1) : $d['price']->getPriceFormat($v->amount);

			$t[] = '<tr '.$totalF.'>';
			$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
			$t[] = '<td colspan="'.$tColspanMid.'">'.PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))).'</td>';
			$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'">'.$amount.'</td>';
			$t[] = '</tr>';

			if ($pR) { $oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))), $amount)); }

		} else {
			$t[] = '<tr '.$totalF.'>';
			$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
			$t[] = '<td colspan="'.$tColspanMid.'">'.PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' - '), 1 => array($v->title_lang_suffix2, ' '))).'</td>';
			$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'">'.$d['price']->getPriceFormat($v->amount).'</td>';
			$t[] = '</tr>';

			if ($pR) { $oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' - '), 1 => array($v->title_lang_suffix2, ' '))), $d['price']->getPriceFormat($v->amount))); }

		}


	}
}

if ($d['type'] != 3) {
	$o[] = implode("\n", $t);
}


if ($tax_calculation > 0 || $d['type'] == 3) {
	$o[] = '<tr><td colspan="12">&nbsp;</td></tr>';
} else {
	$o[] = '<tr><td colspan="9">&nbsp;</td></tr>';
}


// -----------

Re: Order of Total and Subtotal

Posted: 19 Jun 2024, 13:27
by Jan
Hi, this what I have written,is just a proposal, of course you can do it other way, it fully depends on you.

Re: Order of Total and Subtotal

Posted: 20 Jun 2024, 00:53
by Nidzo
I tried really hard yesterday but I couldn't get result you proposed and showed on image :x

Re: Order of Total and Subtotal

Posted: 20 Jun 2024, 15:42
by Jan
Did you apply the code, I pasted, cca on line 844? Including adding new variable $newTotal to foreach.

It just creates new variable instead the old one, where it just moves the one item from total (the final total) to start of the array, so the final total will be rendered as first in the foreach.

Jan

Re: Order of Total and Subtotal

Posted: 20 Jun 2024, 20:52
by Nidzo
I am not good in PHP at all but I am stubborn and I'm running out of that too :) I'm spinning in circles.

I usualy get Unmatched '}' error and when I remove unmached } using Joomla debug I only get Total to pay displayed :roll:

Image

Image

Re: Order of Total and Subtotal

Posted: 21 Jun 2024, 00:31
by Jan
Hi, see the modified file here:
https://github.com/PhocaCz/PhocaCart/re ... /order.php

Jan

Re: Order of Total and Subtotal

Posted: 21 Jun 2024, 14:50
by Nidzo
Thank you Jan. Now I know where I was making a mistake and I totally understand how it works.

Re: Order of Total and Subtotal

Posted: 21 Jun 2024, 15:00
by Jan
OK