Page 1 of 2

Hide sub-total in v.3.0.0.6

Posted: Thu Jan 14, 2021 5:16 pm
by Sladdaren
Hi
Need som help again. I know the sub-total has to be calculated to show the Total, but isn´t there a way to just hide it and still keep it in the calculation?I.
I have searched other threads about this topic, and found a solved thread but in version 1,5 opencart.
viewtopic.php?t=84695
I tried to do step by step in that instruction, but the file path or codes dont match.
The question is how do i hide SUB-TOTAL in checkout and in cart? I cant just do the sub-total inactive, but i know i could maybe hide it for showing. ???

Re: Hide sub-total in v.3.0.0.6

Posted: Thu Jan 14, 2021 5:21 pm
by IP_CAM
There is no OC v.3.0.0.6... ??? And what Theme and Extensions do you use ?

Re: Hide sub-total in v.3.0.0.6

Posted: Thu Jan 14, 2021 5:34 pm
by thekrotek
And you want to hide it why?

Re: Hide sub-total in v.3.0.0.6

Posted: Fri Jan 15, 2021 5:57 pm
by paulfeakins
As above, get the version right and give us the "why" for this bizarre request.

Re: Hide sub-total in v.3.0.0.6

Posted: Fri Jan 15, 2021 11:08 pm
by mikeinterserv
paulfeakins wrote:
Fri Jan 15, 2021 5:57 pm
As above, get the version right and give us the "why" for this bizarre request.
What's it got to do with any one else
He wants to do it
We can help him or NOT :-)

Do you still want to do that volvosweden
Its not that difficult if you really want but I don't want to waste my time if you changed your mind :-)

Re: Hide sub-total in v.3.0.0.6

Posted: Fri Jan 15, 2021 11:27 pm
by thekrotek
mikeinterserv wrote:
Fri Jan 15, 2021 11:08 pm
What's it got to do with any one else
He wants to do it
We can help him or NOT :-)
He might also want to jump from the cliff. Please, help him, don't ask why does he want to do it.

Re: Hide sub-total in v.3.0.0.6

Posted: Fri Jan 15, 2021 11:29 pm
by mikeinterserv
thekrotek wrote:
Fri Jan 15, 2021 11:27 pm
mikeinterserv wrote:
Fri Jan 15, 2021 11:08 pm
What's it got to do with any one else
He wants to do it
We can help him or NOT :-)
He might also want to jump from the cliff. Please, help him, don't ask why does he want to do it.
Yeah and some of us are able to discern the difference between the two and act ACCORDINGLY

Re: Hide sub-total in v.3.0.0.6

Posted: Fri Jan 15, 2021 11:34 pm
by OSWorX
Sladdaren wrote:
Thu Jan 14, 2021 5:16 pm
I know the sub-total has to be calculated to show the Total, but isn´t there a way to just hide it and still keep it in the calculation?

The question is how do i hide SUB-TOTAL in checkout and in cart? I cant just do the sub-total inactive, but i know i could maybe hide it for showing. ???
Before this discussion extends about the question "useful or not", the simple solution for your request is:
disable the assigning of the output in the model sub_total

To do so, edit the file ../catalog/model/extension/sub_total.php and surround the code with a /** and */
It should look finaly:

Code: Select all

/**
		$total['totals'][] = array(
			'code'       => 'sub_total',
			'title'      => $this->language->get('text_sub_total'),
			'value'      => $sub_total,
			'sort_order' => $this->config->get('sub_total_sort_order')
		);
*/
In you case you could also delete this part completely ..

Note: this is the simpliest and most foolproof solution.
It could be done also in another way by creating an event, but for you this should be enough for the moment without paying anything.

p.s.: this code can be applied to all 2.x and 3.x versions.

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:00 am
by by mona
@OSWorkX ;)

Or of course you could just go into admin => extensions => extensions => order totals and just disable sub-total ..

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:07 am
by mikeinterserv
by mona wrote:
Sat Jan 16, 2021 12:00 am
@OSWorkX ;)

Or of course you could just go into admin => extensions => extensions => order totals and just disable sub-total ..
That will not work
Try it and see what you see :-)

OSWorX provided a good solution - If not I have another I didn't try his yet.
The SUB TOTAL MUST be ACTIVE to work correctly - in this case it must just be HIDDEN and NOT eliminated.

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:15 am
by by mona
Firstly OSWorx is fully aware I have the utmost respect for him and would never question the quality of his work
Secondly - try refreshing your browser ..

Actually you are correct - the total is wrong .. that is a bug ..

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:23 am
by mikeinterserv
by mona wrote:
Sat Jan 16, 2021 12:15 am
Firstly OSWorx is fully aware I have the utmost respect for him and would never question the quality of his work
Secondly - try refreshing your browser ..

Actually you are correct - the total is wrong .. that is a bug ..
Did you bother to look at the differing amounts now in your screenshots - It is CLEARLY WRONG
Its not a bug its just how it works.
OSWorX solution is fine I can confirm :-)

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:23 am
by OSWorX
by mona wrote:
Sat Jan 16, 2021 12:00 am
@OSWorkX ;)

Or of course you could just go into admin => extensions => extensions => order totals and just disable sub-total ..
No .. not really.
Why not simply disabling?
Because then the totals are completely NOT calculated correct ..

Therefore, either "hiding" the output by fiddling around inside the templates (cart and checkout and so on ..), or use my solution (which I have tested before publishing).
And "my" solution simply is not creating the HTML output to the totals array - which is enough for this task.

p.s.: OSWorX ;)

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:28 am
by mikeinterserv
^^^^ WINNER
and an excellent quick solution for this problem - THE END :-)

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 12:36 am
by xxvirusxx
Edit and remove the tax code..

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 1:18 am
by by mona
@OSWorX - :-[ I can pronounce it correctly !

yes - thank you - it has to go through sub_total.php, but that is insane - and very dangerous
There appears to be no valid reason for the ability to disable and not to calculate correctly - Is there a reason?

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 1:26 am
by mikeinterserv
by mona wrote:
Sat Jan 16, 2021 1:18 am
@OSWorX - :-[ I can pronounce it correctly !

yes - thank you - it has to go through sub_total.php, but that is insane - and very dangerous
There appears to be no valid reason for the ability to disable and not to calculate correctly - Is there a reason?
Because its an extension and that's how they work - whether disabling or uninstallng breaks something, which it often can as you've discovered, that's how they work.

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 1:40 am
by OSWorX
xxvirusxx wrote:
Sat Jan 16, 2021 12:36 am
Edit and remove the tax code..
Well, we could start now a "Contest" who is providing the most useful or best solution.
While a respect your work, I think that your solution maybe a bit "over sophisticated" when editing several files while 1 line could to it also.
Therefore attached a small OCMod (available for OC 2.x and 3.x) - doing such I proposed above.

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 1:54 am
by OSWorX
by mona wrote:
Sat Jan 16, 2021 1:18 am
@OSWorX - :-[ I can pronounce it correctly !

yes - thank you - it has to go through sub_total.php, but that is insane - and very dangerous
There appears to be no valid reason for the ability to disable and not to calculate correctly - Is there a reason?
Don't worry about - important you find me and my Website if you need it ;)

The reason why it has to go through the file, is - the sums (subtotal and total) are calculated inside.
Subtotal is in 99% of all shops the first line in the cart - displaying the net value of the whole cart.
This is done inside the cart controller (system file) by calling the function getSubtotal():

Code: Select all

	public function getSubTotal() {
		$total = 0;

		foreach ($this->getProducts() as $product) {
			$total += $product['total'];
		}

		return $total;
	}
As can be seen here, it loops through all products are in the cart and summarize the net value ($total) which is then returned (into the sub_total controller):

Code: Select all

$sub_total = $this->cart->getSubTotal();
After getting the subtotal in the subtotal controller, a check is made if there are any voucher values to add.
Then, the subtotal controller builds the output:

Code: Select all

		$total['totals'][] = array(
			'code'       => 'sub_total',
			'title'      => $this->language->get('text_sub_total'),
			'value'      => $sub_total,
			'sort_order' => $this->config->get('sub_total_sort_order')
		);
which we do not need here in this case (or this request).

After that, the last line is:

Code: Select all

$total['total'] += $sub_total;
which adds the former build subtotal to the total value ($total['total']) which itself is available later in some controllers (e.g. payment_method).

And this is the reason why this subtotal function (available through the menu Extensions > Extensions >Order Totals >> Sub-Total) shall NOT be disabled.
Because if, the whole further calculation is not correct.

Hope I could explain it good enough ..

What could be done to extend the core code by adding a setting to "hide" the output.
A "feature request" - maybe usefull for users and cases like this here: simply define if output yes or no inside the order totals definitions.
But calculation is done in every case.

And yes, simply disabling this order total module/extension can lead to some very unwanted results ..

Re: Hide sub-total in v.3.0.0.6

Posted: Sat Jan 16, 2021 1:55 am
by mikeinterserv
If you can't get to sub_total.php and edit that file with just 5 character comment tag then maybe you shouldn't be fiddling with opencart at all :-)
OSWorX original solution is the easiest - quickest - and most easily REVERSBALE solution with NO side effects etc available for this question. There should be NOTHING left to discuss and OSWorX explanation as to WHY, goes well above and beyond.