Is there a way to change the font size after the decimal point?
I have attached an example.
Thank you.
Posted 12 December 2018 - 04:00 PM #1
Is there a way to change the font size after the decimal point?
I have attached an example.
Thank you.
Posted 12 December 2018 - 05:47 PM #2
No attachement. But you should override the common/price.tpl template in both backend and frontend to alter how price is displayed.
I.e. design/themes/responsive/templates/common/price.tpl
To override this, copy that file to:
design/themes/responsive/templates/addons/my_changes/overrides/common/price.tpl
Be sure to clear your cache and you should be all set. Add a comment at the top like:
<!-- override price.tpl -->
Then in your browser inspector, just search for 'override' and you should find you comment showing that the override was successful.
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 13 December 2018 - 01:55 AM #4
Same info/advice applies with our without the attachment!
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 13 December 2018 - 11:02 PM #5
Assuming you are familiar enough with code to do the following:
Put this function in your my_changes/func.php file (create it if it doesn't exist).
function my_format_price($price, $currency, $span_id='', $class='', $is_secondary=false, $live_editor_name='') { $value = fn_format_rate_value($price, 'F', $currency['decimals'], $currency['decimals_separator'], $currency['thousands_separator'], $currency['coefficient']); /* Set this to the class name you want to use to format numbers to the right of the decimal */ $decimal_class = 'my-decimal-class'; $pieces = explode($currency['decimals_separator'], $value); // This is the real modification to the code if( count($pieces) == 2 ) { $value = $pieces[0] . '<span class="' . $decimal_class . '">' . $pieces[1] . '</span>'; } if( !empty($span_id) && $is_secondary ) { $span_id = 'sec_'.$span_id; } $span_id = !empty($span_id) ? (' id="' . $span_id . '"') : ''; $class = !empty($class) ? (' class="' . $class . '"') : ''; $live_editor_attrs = ''; if( Registry::get('runtime.customization_mode.live_editor') && !empty($live_editor_name) ) { $live_editor_attrs = 'data-ca-live-editor-obj="' . $live_editor_name . '"'; } if( $class ) { $currency['symbol'] = '<span ' . $class . '>' . $currency['symbol'] . '</span>'; } $data = array( '<span' . $span_id . $class . $live_editor_attrs . '>', $value, '</span>' ); if( $currency['after'] == 'Y' ) { array_push($data, ' ' . $currency['symbol']); } else { array_unshift($data, $currency['symbol']); } return implode('', $data); }
In the override file you created, change all 'format_price' references to 'my_format_price' and save the file.
Either add a css class for .my-decimal-class to your liking or use the following css class:
.my-decimal-class { font-size: 70%; vertical-align: top; color:red;}
That should then show your prices with the decimal portion in red as a super-script with the height being 70% of the parent height.
tony
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 14 December 2018 - 02:24 PM #6
I have overridden the common/price.tpl in:
design/themes/energot/templates/addons/my_changes/overrides/common/price.tpl
and
design/backend/templates/addons/my_changes/overrides/common/price.tpl
I have added
<!-- override price.tpl -->
And I see it when I`m inspecting.
Next, I made
app/addons/my_changes/func.php and then added:
<?php function my_format_price($price, $currency, $span_id='', $class='', $is_secondary=false, $live_editor_name='') { $value = fn_format_rate_value($price, 'F', $currency['decimals'], $currency['decimals_separator'], $currency['thousands_separator'], $currency['coefficient']); /* Set this to the class name you want to use to format numbers to the right of the decimal */ $decimal_class = 'my-decimal-class'; $pieces = explode($currency['decimals_separator'], $value); // This is the real modification to the code if( count($pieces) == 2 ) { $value = $pieces[0] . '<span class="' . $decimal_class . '">' . $pieces[1] . '</span>'; } if( !empty($span_id) && $is_secondary ) { $span_id = 'sec_'.$span_id; } $span_id = !empty($span_id) ? (' id="' . $span_id . '"') : ''; $class = !empty($class) ? (' class="' . $class . '"') : ''; $live_editor_attrs = ''; if( Registry::get('runtime.customization_mode.live_editor') && !empty($live_editor_name) ) { $live_editor_attrs = 'data-ca-live-editor-obj="' . $live_editor_name . '"'; } if( $class ) { $currency['symbol'] = '<span ' . $class . '>' . $currency['symbol'] . '</span>'; } $data = array( '<span' . $span_id . $class . $live_editor_attrs . '>', $value, '</span>' ); if( $currency['after'] == 'Y' ) { array_push($data, ' ' . $currency['symbol']); } else { array_unshift($data, $currency['symbol']); } return implode('', $data); }
Then I go again to the overridden price.tpl in:
design/themes/energot/templates/addons/my_changes/overrides/common/price.tpl
and
design/backend/templates/addons/my_changes/overrides/common/price.tpl
and changed format_price with my_format_prices like this:
<!-- override price.tpl --> {strip} {if $settings.General.alternative_currency == "use_selected_and_alternative"} {$value|my_format_price:$currencies.$primary_currency:$span_id:$class:false:$live_editor_name:$live_editor_phrase nofilter} {if $secondary_currency != $primary_currency} {if $class}<span class="{$class}">{/if} ( {if $class}</span>{/if} <bdi>{$value|my_format_price:$currencies.$secondary_currency:$span_id:$class:true:$is_integer:$live_editor_name:$live_editor_phrase nofilter}</bdi> {if $class}<span class="{$class}">{/if} ) {if $class}</span>{/if} {/if} {else} <bdi>{$value|my_format_price:$currencies.$secondary_currency:$span_id:$class:true:$live_editor_name:$live_editor_phrase nofilter}</bdi> {/if} {/strip}
I added the css:
.my-decimal-class { font-size: 70%; vertical-align: top; color:red;}
I have cleared the cache, manually and with ?cc&ctpl
And The Problem is that on the storefront I receive Service unavailable, sorry services is temporarily unavailable.
What am I doing wrong?
Thank you very much for the help!
Posted 14 December 2018 - 10:12 PM #7
There could be a syntax error from the copy. Check your PHP error_log for your site. But I tested the function here before posting so it should be okay.
Given you're seeing the overridden template, that would mean that the my_changes addon is active. You can "right click" on the Unavailable page and click 'inspect' that should show you the html for that page and in it should be comments about the exception that occurred.
You can send me a link and I'll review it for you if you want. You can send it to me at support AT ez-mx.com.
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 15 December 2018 - 02:50 PM #8
error_log
PHP Fatal error: Uncaught Error: Class 'Registry' not found in /app/addons/my_changes/func.php:21 Stack trace: #0 /app/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code(70): my_format_price('169.00', Array, ' id="sec_list_p...', ' class="ty-list...', true, NULL, NULL) #1 /app/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(188): content_5c151242d39aa9_78620175(Object(Smarty_Internal_Template)) #2 /app/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(304): Smarty_Internal_TemplateBase->fetch(Object(Smarty_Internal_Template), NULL, NULL, NULL, false, false, true) #3 /app/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code(1674): Smarty_Internal_Template->getSubTemplate('common/price.tp...', NULL, NULL, 0, NULL, Array, 0) #4 /app/addons/my_changes/func.php on line 21
Inspecting gives me the same error
func.php:21
if( registry::get('runtime.customization_mode.live_editor') && !empty($live_editor_name) ) { $live_editor_attrs = 'data-ca-live-editor-obj="' . $live_editor_name . '"'; }
Thank you very very much !
Posted 15 December 2018 - 05:44 PM #9
Add:
use Tygh\Registry;
Just above the first line of code in func.php
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 16 December 2018 - 10:04 PM #10
Everything works perfectly now
Thank you very much for everything!!!!
Posted 17 December 2018 - 02:34 AM #11
No problem. Slow time of year for us developers!
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 22 July 2020 - 11:20 AM #12
You can use sup for decimals.