Order of Total and Subtotal

Phoca Cart - complex e-commerce extension
User avatar
Nidzo
Phoca Professional
Phoca Professional
Posts: 390
Joined: 07 Nov 2018, 14:55

Order of Total and Subtotal

Post 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
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Order of Total and Subtotal

Post 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
If you find Phoca extensions useful, please support the project
User avatar
Nidzo
Phoca Professional
Phoca Professional
Posts: 390
Joined: 07 Nov 2018, 14:55

Re: Order of Total and Subtotal

Post 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>';
}


// -----------
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Order of Total and Subtotal

Post 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.
If you find Phoca extensions useful, please support the project
User avatar
Nidzo
Phoca Professional
Phoca Professional
Posts: 390
Joined: 07 Nov 2018, 14:55

Re: Order of Total and Subtotal

Post by Nidzo »

I tried really hard yesterday but I couldn't get result you proposed and showed on image :x
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Order of Total and Subtotal

Post 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
If you find Phoca extensions useful, please support the project
User avatar
Nidzo
Phoca Professional
Phoca Professional
Posts: 390
Joined: 07 Nov 2018, 14:55

Re: Order of Total and Subtotal

Post 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
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Order of Total and Subtotal

Post by Jan »

Hi, see the modified file here:
https://github.com/PhocaCz/PhocaCart/re ... /order.php

Jan
If you find Phoca extensions useful, please support the project
User avatar
Nidzo
Phoca Professional
Phoca Professional
Posts: 390
Joined: 07 Nov 2018, 14:55

Re: Order of Total and Subtotal

Post by Nidzo »

Thank you Jan. Now I know where I was making a mistake and I totally understand how it works.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Order of Total and Subtotal

Post by Jan »

OK
If you find Phoca extensions useful, please support the project
Post Reply