It'd be much better for themers if it was possible to customize currency sign. Adding some html like <span class="currency-sign">$sign</span> probably would be enough.

Thank you.

CommentFileSizeAuthor
#6 1085634-theming-currency-sign.patch544 bytesSergey Naumov

Comments

tr’s picture

Can you just use .uc-price:first-letter ?

Sergey Naumov’s picture

Unfortunately for some countries currency sign goes after the price and can consist of more than one letter/symbol. Even in Ubercart store settings one can decide where to display the currency sign - after the price or before.

tr’s picture

OK.

Sergey Naumov’s picture

Any update on this?

Thank you.

longwave’s picture

If you can make a patch with your suggested changes, this feature is likely to get added more quickly.

Sergey Naumov’s picture

StatusFileSize
new544 bytes

OK, this is my first patch. I hope it works :)

Sergey Naumov’s picture

Status: Active » Needs review
Sergey Naumov’s picture

*bump*

Equ’s picture

subscribing

Sergey Naumov’s picture

I'm sorry for asking, but is this so difficult to implement? Why is it taking more than two months just to add one extra <span>? The patch is ready and working. We need this. Really.

Thank you and sorry once again for complaining.

longwave’s picture

uc_currency_format() returns a plain string at present, not HTML, so this is technically an API change - we have to be sure that the output is never check_plain()'ed or similar anywhere before committing this. Otherwise, unexpected HTML tags may be displayed to the user.

I am not fully convinced this is useful for most users, so perhaps this would be better handled by overriding theme_uc_price() in your local theme - which raises the further point that we now have theme('uc_price') and uc_currency_format() which do very similar things.

Sergey Naumov’s picture

Status: Needs review » Closed (won't fix)

Overriding theme_uc_price() in my local theme is not working for me. So I've overriden it in the module. In case if someone needs it:

function MYMODULE_theme_registry_alter(&$theme_registry) {
    $theme_registry['uc_price']['function'] = 'MYMODULE_theme_uc_price';
}

function MYMODULE_theme_uc_price($variables) {
    return '<span class="uc-price">' . MYMODULE_currency_format($variables['price']) . '</span>';
}

function MYMODULE_currency_format($value, $sign = NULL, $thou = NULL, $dec = NULL) {
    if ($value === NULL) {
        return NULL;
    }

    $output = '';

    $sign_after = variable_get('uc_sign_after_amount', FALSE);
    $prec = variable_get('uc_currency_prec', 2);
    if (is_null($sign)) {
        $sign = variable_get('uc_currency_sign', '$');
    }
    if (is_null($thou)) {
        $thou = variable_get('uc_currency_thou', ',');
    }
    if (is_null($dec)) {
        $dec = variable_get('uc_currency_dec', '.');
    }

    // If the value is significantly less than the minimum precision, zero it.
    if ($prec > 0 && round(abs($value), $prec + 1) < pow(10, -$prec)) {
        $value = 0;
    }

    // Force the price to a positive value and add a negative sign if necessary.
    if ($value < 0) {
        $value = abs($value);
        $output .= '-';
    }

    // Add theming to currency sign.
    if ($sign) {
        $sign = '<span class="uc-currency-sign">'.$sign.'</span>';
    }

    // Add the currency sign first if specified.
    if ($sign && !$sign_after) {
        $output .= $sign;
    }

    // Format the number, like 1234.567 => 1,234.57
    $output .= number_format($value, $prec, $dec, $thou);

    // Add the currency sign last if specified.
    if ($sign && $sign_after) {
        $output .= $sign;
    }

    return $output;
}
edicting’s picture

The patch has improper showing on store control panel.

Pls check my upload image:

http://oi64.tinypic.com/2w5n2v4.jpg