Is there a way to change the font size after the decimal point?
I have attached an example.
Thank you.
Is there a way to change the font size after the decimal point?
I have attached an example.
Thank you.
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:
Then in your browser inspector, just search for 'override' and you should find you comment showing that the override was successful.
Same info/advice applies with our without the attachment! :-)
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] . ‘’ . $pieces[1] . ‘’;
}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’] = ‘’ . $currency[‘symbol’] . ‘’;
}
$data = array( ‘’,
$value,
‘’
);
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
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
And I see it when I`m inspecting.
Next, I made
app/addons/my_changes/func.php and then added:
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] . ‘’ . $pieces[1] . ‘’;
}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’] = ‘’ . $currency[‘symbol’] . ‘’;
}
$data = array( ‘’,
$value,
‘’
);
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:
{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}{/if} ( {if $class}{/if} {$value|my_format_price:$currencies.$secondary_currency:$span_id:$class:true:$is_integer:$live_editor_name:$live_editor_phrase nofilter} {if $class}{/if} ) {if $class}{/if} {/if} {else} {$value|my_format_price:$currencies.$secondary_currency:$span_id:$class:true:$live_editor_name:$live_editor_phrase nofilter} {/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!
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.
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 !
Add:
use Tygh\Registry;
Just above the first line of code in func.php
Everything works perfectly now
Thank you very much for everything!!!!
No problem. Slow time of year for us developers! :-)
You can use sup for decimals.