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.
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
Code: Select all
<!-- order.total='{{ order.total }}' -->
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
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.
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
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 %}
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>
}
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.
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.
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>
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 :-)
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 %}
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>
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.
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.
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 }}">£{{ order.total }}</span>
find
Code: Select all
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
Code: Select all
'total' => number_format($result['total'], 2),
If you want to have colors on order status, there are many free extensions.Karonia69 wrote: ↑Wed Mar 10, 2021 5:16 pmThanks, 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 %}
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Users browsing this forum: edkny, nonnedelectari and 402 guests