Post by Karonia69 » Tue Mar 09, 2021 6:46 pm

Hi,

I'm trying to modify the Recent_Info.twig file to highlight orders in value bands, I've tried what I thought would be a simple piece of code, but I just can't get it to work, wondered if anyone had an insight as to why...

{% if order.total == 0 %} <td class="text-right"><span style="color:red">{{ order.total }}</span></td>
{% elseif order.total != 0 %} <td class="text-right"><span style="color:green">{{ order.total }}</span></td>
{% else %} <td class="text-right">{{ order.total }}</td>
{% endif %}

Did this range as a simple test, but it always shows the value in RED... is it because ORDER.TOTAL is formatted as £0.00 ? What should I be testing in the condition ??

TIA for any help.
Last edited by Karonia69 on Thu Mar 11, 2021 12:25 am, edited 1 time in total.

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by JNeuhoff » Tue Mar 09, 2021 7:02 pm

Try the replace filter, e.g.

Code: Select all

{% if order.total|replace({ "£":"" }) == 0 %}

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Karonia69 » Tue Mar 09, 2021 7:31 pm

Hi,

Thanks, but no, still doesn't work. I tried displaying the value after the replace and it has a ? in a diamond instead!!

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by JNeuhoff » Tue Mar 09, 2021 7:56 pm

Add

Code: Select all

<!-- order.total='{{ order.total }}' -->
to your template and refresh the page, then go to browser's source view to see what the exact content is. It may contain some other non-numeric characters which may have to be filtered out.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Karonia69 » Tue Mar 09, 2021 8:05 pm

LOL... This was supposed to be something easy, which is turning out to be a bit of a mare, I'll test another field instead as this is quickly going down the rabbit hole!! Thanks for your help though

The replacement character (often displayed as a black diamond with a white question mark) is a symbol found in the Unicode standard at code point U+FFFD in the Specials table. It is used to indicate problems when a system is unable to render a stream of data to a correct symbol.

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by JNeuhoff » Tue Mar 09, 2021 8:12 pm

Well, you should use UTF-8 to start with.

Still, I agree, Twig is a pain. Twig is poorly designed and poorly implemented template language, it has bad syntax, not a proper LALR(1) syntax grammar, and does not directly translate into the final HTML, and it silently ignores undefined variables.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by mikeinterserv » Tue Mar 09, 2021 9:59 pm

EDIT
The amounts are actually text you just need to add the decimal places.

Code: Select all

{% if order.total == "0.00" %} <td class="text-right"><span style="color:red">{{ order.total }}</span></td>
{% elseif order.total !="0.00" %} <td class="text-right"><span style="color:green">{{ order.total }}</span></td>
{% else %} <td class="text-right">{{ order.total }}</td>
{% endif %}
Also the first 2 conditions cover all possiblities if zero be RED if NOT ZERO be green
There is no need for the last else - your total is going to be red or green

You could shorten it to this if you like

Code: Select all

{% if order.total == "0.00" %} <td class="text-right"><span style="color:red">{{ order.total }}</span></td>
{% else %}  <td class="text-right"><span style="color:green">{{ order.total }}</span></td>
}

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by Karonia69 » Wed Mar 10, 2021 12:26 am

Thanks for that, still doesn't work though, they're all Green :( , did you try the code or are you just putting what it should logically be ?
The 1st block of code was right in as much as it was an excerpt, which is why it had the catch-all at the end.
When I check the value in the browser it has a '£' , tried including it in the comparison, stripping it before the comparison.

I just don't get it, shouldn't be this difficult!! I've used the same code to change the colour on statii with no issues.

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by mikeinterserv » Wed Mar 10, 2021 2:24 am

Sorry I didn't check it against the page I see you mentioned
So yes pretty much how it would be generally but I should have known the order.total is coming from an array.
When I get home I will do it on the same page :-) and update you.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by Karonia69 » Wed Mar 10, 2021 2:32 am

Much appreciated, can't wait to get an answer to this...driving me crazy!!! LOL

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by mikeinterserv » Wed Mar 10, 2021 8:09 am

Well it did not work for a few reasons so I used jquery like this.
Just paste the script in the page. I can make it as an OCMod for you if you like.
Just make sure your order.total is in a span tag and it will work
The code is GBP if your currency symbol is different just replace \u00a3

Code: Select all

  <script type="text/javascript"> 
    $(document).ready(function(){
    $("span").each(function(){
      if($(this).text() == "\u00a30.00"){
       $(this).css('color','red');   
     } else {  
       $(this).css('color','blue');   
     }     
    });
 }); </script>
just need a plain span tag <span> no style
I made it blue not green because I could barely tell green from black on my screen :-)
AND you don't have to worry about Twig oddities and arrays :-)

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by Karonia69 » Wed Mar 10, 2021 5:16 pm

Thanks, that works!!! Unfortunately, it colours other sections of my screen in Blue too, as I already have code in there to colourise the status field.

Code: Select all

	        {% if order.status == 'Shipped' %} <td><span style="color:orange">{{ order.status }}</span></td>
		{% elseif order.status == 'Pending' %} <td><span style="color:red">{{ order.status }}</span></td>
		{% elseif order.status == 'Complete' %} <td><span style="color:green">{{ order.status }}</span></td>
		{% elseif order.status == 'Collected' %} <td><span style="color:green">{{ order.status }}</span></td>
		{% elseif order.status == 'Processing' %} <td><span style="color:blue">{{ order.status }}</span></td>
		{% elseif order.status == 'Store Collection' %} <td><span style="color:orange">{{ order.status }}</span></td>
		{% elseif order.status == 'Pre-order' %} <td><span style="color:orange">{{ order.status }}</span></td>
		{% elseif order.status == 'Cancelled' %} <td><span style="color:red">{{ order.status }}</span></td>
		{% elseif order.status == 'Refunded' %} <td><span style="color:red">{{ order.status }}</span></td>
		{% elseif order.status == 'Processed' %} <td><span style="color:#0096ff">{{ order.status }}</span></td>
		{% else %} <td>{{ order.status }}</td>
		{% endif %}

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by Karonia69 » Wed Mar 10, 2021 6:48 pm

Thanks for the idea, I modified it slightly to add a span class so I can limit the effect to a single column.
Again, Many Thanks... MUCH APPRECIATED.

Code: Select all

<script type="text/javascript"> 
    $(document).ready(function(){
    $("span.js_color").each(function(){
      if($(this).text() == "\u00a30.00"){
       $(this).css('color','red');   
     } else {  
       $(this).css('color','green');   
     }     
    });
 }); 
</script>

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by mikeinterserv » Wed Mar 10, 2021 11:29 pm

Glad you got
my mind reading skills re all the added spans are not what they used to be :-)
Well done for making the change required - its exactly what I would have suggested.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by Karonia69 » Thu Mar 11, 2021 12:24 am

Thanks... Now for the next step, to make it conditional on other values on the line!! LOL

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by mikeinterserv » Thu Mar 11, 2021 1:05 am

How did I know the limitations of this method might come around :-)
This is a style ONLY method - If you require some if statements to build BANDS from values as you say then more work is required to achieve that.
The values are in an array and the order.total is formatted.
What do you want to do exactly.

These are your options
you work with the array as is - harder
you eliminate formatting BEFORE array arrives on this page. - not hard - requires code changes - still leaves you working with array but makes life easier.
you write something specific for this functionality you require - all depends on what and how you want things and how much effort to make it work how you want.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by Karonia69 » Thu Mar 11, 2021 2:53 am

I'll have to go and have a think, don't want to put too much effort into it the minute, added the extra fields we needed and coloured the fields we wanted. May just look at adding an extra filter, instead of using the colours :)

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by mikeinterserv » Thu Mar 11, 2021 12:49 pm

Had another look at it
Came up with this if you want full comparison/condition function to change span tags in recent info
As its not critical the recent info this is ok to play with
This is purely an example you can adapt it as you wish as the totals are now integers NOT currency.

You need to change
admin/view/template/extension/dashboard/recent_info.twig

Code: Select all

  {% if order.total == 0.00 %} 
   {% set mytd = 'red' %}
   {% elseif order.total > '0.00' and order.total < '20.00' %}
{% set mytd = 'blue' %}
{% elseif order.total > '20.00' and order.total < '30.00' %}
{% set mytd = 'orange' %}
{% elseif order.total > '30.00' and order.total < '40.00' %}
{% set mytd = 'green' %}
{% endif %} 
   
   <span style="color:{{ mytd }}">&pound;{{ order.total }}</span>  
admin/controller/extension/dashboard/recent.php
find

Code: Select all

'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
replace with

Code: Select all

'total'      =>  number_format($result['total'], 2),

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by Karonia69 » Thu Mar 11, 2021 8:34 pm

Thanks, I'll have a play :)

New member

Posts

Joined
Thu May 17, 2018 4:09 pm

Post by xxvirusxx » Thu Mar 11, 2021 8:59 pm

Karonia69 wrote:
Wed Mar 10, 2021 5:16 pm
Thanks, that works!!! Unfortunately, it colours other sections of my screen in Blue too, as I already have code in there to colourise the status field.

Code: Select all

	        {% if order.status == 'Shipped' %} <td><span style="color:orange">{{ order.status }}</span></td>
		{% elseif order.status == 'Pending' %} <td><span style="color:red">{{ order.status }}</span></td>
......
		{% endif %}
If you want to have colors on order status, there are many free extensions.

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România
Who is online

Users browsing this forum: SohBH and 269 guests