Post by spstore » Mon Jul 01, 2024 5:48 am

Hello,

I am using OC 3.0.3.8

I am trying to create a printable shipping label for local delivery and I need to print only the order total without sub-total, discounts etc.
The format would be something like: Total: XX€ (the amount should be formatted according to the order total, including taxes and everything)

The general template is based on the invoice twig template.

I have located the parts that need to be changed but I don't get how can I receive only the total without all the other sub-totals, discounts, etc.
So my current code is:

For the twig:

Code: Select all

 {% for total in order.total %}
    <table class="table table-bordered">
       <tbody>
        <tr>
          <td class="text-right"><b>{{ total.title }}</b></td>
          <td class="text-right">{{ total.text }}</td>
        </tr>
        {% endfor %}
        
and on admin/controller/sale/order.php

Code: Select all

	$total_data = array();

				$totals = $this->model_sale_order->getOrderTotals($order_id);

				foreach ($totals as $total) {
					$total_data[] = array(
						'title' => $total['title'],
						'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
					);
				}
				
I am attaching a screenshot to understand better the part that I only need to be displayed.

So how could I get only the order total? What part should I modify?

Thanks, everyone in advance.

Attachments

order total.jpg

order total.jpg (23.39 KiB) Viewed 564 times

Last edited by spstore on Mon Jul 01, 2024 8:04 pm, edited 1 time in total.

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens

Post by softmonke » Mon Jul 01, 2024 11:05 am

spstore wrote:
Mon Jul 01, 2024 5:48 am
Hello,

I am using OC 3.0.3.8

I am trying to create a printable shipping label for local delivery and I need to print only the order total without sub-total, discounts etc.
The format would be something like: Total: XX€ (the amount should be formatted according to the order total, including taxes and everything)

The general template is based on the invoice twig template.

I have located the parts that need to be changed but I don't get how can I receive only the total without all the other sub-totals, discounts, etc.
So my current code is:

For the twig:

Code: Select all

 {% for total in order.total %}
    <table class="table table-bordered">
       <tbody>
        <tr>
          <td class="text-right"><b>{{ total.title }}</b></td>
          <td class="text-right">{{ total.text }}</td>
        </tr>
        {% endfor %}
        
and on admin/controller/sale/order.php

Code: Select all

	$total_data = array();

				$totals = $this->model_sale_order->getOrderTotals($order_id);

				foreach ($totals as $total) {
					$total_data[] = array(
						'title' => $total['title'],
						'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
					);
				}
				
I am attaching a screenshot to understand better the part that I only need to be displayed.

So how could I get only the order total? What part should I modify?

Thanks, everyone in advance.
Since you just want to get the "Total", in your controller file, just do a check if the code is "total", otherwise, skip it:

Code: Select all

foreach ($totals as $total) {
    if ($total['code'] == "total") {
        $total_data[] = array(
            'title' => $total['title'],
            'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
        );
        
        break;
    }
}
or you can do:

Code: Select all

foreach ($totals as $total) {
    if ($total['code'] != "total") {
        continue;
    }
    
    $total_data[] = array(
        'title' => $total['title'],
        'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
    );
}
Or you can also check it in your template twig file.

Check out our ever-growing list of extensions for OpenCart here.
Some useful extensions for a better admin experience: Image File Manager ProDrag & Drop Sort Order

Reach out to us at hello@softmonke.com for your OpenCart web development needs or feedback for our extensions.


User avatar
Active Member

Posts

Joined
Tue May 23, 2023 4:42 am


Post by spstore » Mon Jul 01, 2024 7:56 pm

softmonke wrote:
Mon Jul 01, 2024 11:05 am
spstore wrote:
Mon Jul 01, 2024 5:48 am
Hello,

I am using OC 3.0.3.8

I am trying to create a printable shipping label for local delivery and I need to print only the order total without sub-total, discounts etc.
The format would be something like: Total: XX€ (the amount should be formatted according to the order total, including taxes and everything)

The general template is based on the invoice twig template.

I have located the parts that need to be changed but I don't get how can I receive only the total without all the other sub-totals, discounts, etc.
So my current code is:

For the twig:

Code: Select all

 {% for total in order.total %}
    <table class="table table-bordered">
       <tbody>
        <tr>
          <td class="text-right"><b>{{ total.title }}</b></td>
          <td class="text-right">{{ total.text }}</td>
        </tr>
        {% endfor %}
        
and on admin/controller/sale/order.php

Code: Select all

	$total_data = array();

				$totals = $this->model_sale_order->getOrderTotals($order_id);

				foreach ($totals as $total) {
					$total_data[] = array(
						'title' => $total['title'],
						'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
					);
				}
				
I am attaching a screenshot to understand better the part that I only need to be displayed.

So how could I get only the order total? What part should I modify?

Thanks, everyone in advance.
Since you just want to get the "Total", in your controller file, just do a check if the code is "total", otherwise, skip it:

Code: Select all

foreach ($totals as $total) {
    if ($total['code'] == "total") {
        $total_data[] = array(
            'title' => $total['title'],
            'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
        );
        
        break;
    }
}
or you can do:

Code: Select all

foreach ($totals as $total) {
    if ($total['code'] != "total") {
        continue;
    }
    
    $total_data[] = array(
        'title' => $total['title'],
        'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
    );
}
Or you can also check it in your template twig file.
Thank you a lot softmonke!

This works perfectly in both solutions!

By the way, is the "break;" necessary?
I am new to coding so this is maybe a silly question.

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens

Post by softmonke » Tue Jul 02, 2024 3:08 am

No problem! Hmm, in this situation, "break" is not necessary - it's simply to help exit the for-loop early since we've already found what we needed so there's no need to continue looping the rest of the order totals. If we have a large enough number of order totals, then "break" would be more efficient. But in this case, the efficiency is probably negligible since the number of order totals would usually be in the single-digit range only so "break" or no "break" isn't too important here.

Check out our ever-growing list of extensions for OpenCart here.
Some useful extensions for a better admin experience: Image File Manager ProDrag & Drop Sort Order

Reach out to us at hello@softmonke.com for your OpenCart web development needs or feedback for our extensions.


User avatar
Active Member

Posts

Joined
Tue May 23, 2023 4:42 am


Post by spstore » Fri Jul 05, 2024 11:55 pm

softmonke wrote:
Tue Jul 02, 2024 3:08 am
No problem! Hmm, in this situation, "break" is not necessary - it's simply to help exit the for-loop early since we've already found what we needed so there's no need to continue looping the rest of the order totals. If we have a large enough number of order totals, then "break" would be more efficient. But in this case, the efficiency is probably negligible since the number of order totals would usually be in the single-digit range only so "break" or no "break" isn't too important here.
Thank you for the explanation. It was very clear. I appreciate your time and effort for this!

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens
Who is online

Users browsing this forum: Bing [Bot] and 15 guests