I'm attaching a patch to include and option to remove the decimals from the price when it is shown if they are zero.

El saludo!

Comments

tr’s picture

I think this is a theming issue and does not belong in Ubercart core. You can format the price how you want using the standard Drupal theming mechanism of overriding theme_uc_product_price(), or you can hook into the Ubercart price formatter.

carlitus’s picture

I know, i've made this before with the hooks but i think this can be useful to lot of people, we use it every time.

What is the difference between this and the currency sign in the left or in the right?

tr’s picture

Status: Active » Closed (won't fix)

Marking as won't fix because this can and should be done in the theme.

loparr’s picture

Status: Closed (won't fix) » Active

Hi,
Sorry to open this issue. I don't want to hack core as well. Can anybody help me with theming prices?
I only want to remove the decimals when they are 00. For example 5,00 € should be 5 €, but 5,50 € should remain the same, not 5,5 €.
Thank you very much.

tr’s picture

Status: Active » Closed (won't fix)

I answered that in #1. If you need help using core Drupal theming, I suggest trying the Drupal IRC channels, reading the theming documentation on drupal.org, or reading a book on Drupal.

ufku’s picture

Version: 6.x-2.0 » 7.x-3.x-dev
Category: task » feature
Status: Closed (won't fix) » Active

I suppose this is impossible to override solely by theming because uc_currency_format(), which can not be overridden, is used everywhere especially during logging. It should either support zero removal or be replaced by theme calls.

longwave’s picture

Status: Active » Postponed (maintainer needs more info)

Exactly which of those references would you like to see changed? It's not feasible to change all of them; the tests probably shouldn't be changed, and neither should any calls used to create payment method requests. And for logging, does it really matter if the admin sees .00 at the end of a price? Or do you mean something else?

ufku’s picture

I think there should be a distinction between themable price and non-themable price. All themable prices, regardless of where(logging, reports, views) they are used, should be passed to theme function.

philsward’s picture

Here's my template.php "theme override" to accomplish this task:

/* change uc price to remove .00 */
function asd_uc_price($variables) {
  $output = '<span class="uc-price">' . str_replace(".00","",uc_currency_format($variables['price'])) . '</span>';
  if (!empty($variables['suffixes'])) {
    $output .= '<span class="price-suffixes">' . implode(' ', $variables['suffixes']) . '</span>';
  }
  return $output;
}

Where asd_uc_price($variables) needs to be changed to reflect your theme name [for example if it's the bartik theme: bartik_uc_price($variables)]

Duplicate issue to same feature request: https://drupal.org/node/1924376

---

On a side note, if you're using views, you'll have to change the price format from "Ubercart" to "Numeric" and set the Thousands Marker to "None"

philsward’s picture

Exactly which of those references would you like to see changed? It's not feasible to change all of them; the tests probably shouldn't be changed, and neither should any calls used to create payment method requests. And for logging, does it really matter if the admin sees .00 at the end of a price? Or do you mean something else?

@longwave My guess would strictly be the "user" output only, not the admin stuff... Take a look at Point #7 in: http://blog.hubspot.com/blog/tabid/6307/bid/34118/7-Pricing-Mistakes-Tha...

I'm guessing this is the "psychology" behind removing the trailing empty zeros but you'll probably want to hear from the issue author before proceeding.

loparr’s picture

longwave’s picture

#2002748: uc_product_handler_field_price should render trough theme_uc_price would avoid the need to change the price format setting in Views.

Still waiting to hear which user-visible output, other than Views, cannot be reformatted using the theme override described in #9 (which is the correct way to implement this).

tr’s picture

I still think this is something that should be left to the end user to theme, if desired.* I think the default behavior should be to display the decimal portion of *all* prices, just as we do now. If you don't want to ever want to display the decimal portion of a price, or if you want to display it only under certain circumstances or in certain contexts (on the product node page, for instance), then that should be done in the site-specific theme. If there's no way to do that with the current theming functions, then fixing *that* should be a feature request. But I don't think we should automatically hide the decimal portion and make people jump through hoops to try to restore it.

*Yes, I did read the pricing study cited in #10, and it's fine with me if you want to suppress trailing zeros and thousands separators on your site. It also suggests that all prices should end in "9" for optimal revenue. Again, go ahead and try that on your site if you want. I just don't think that either of these strategies should be the *default* for Ubercart's price display. I think all prices should by default be formatted the same, with currency symbol, thousands and decimal separators, and decimal amount UNLESS you specify otherwise (which you would do through theming).

philsward’s picture

@TR I can understand your view on the matter but the one thing to keep in mind, many of the people, if not most who use Drupal, know very little or absolutely nothing about programming or "theming". Unless the code is completely cut and dry (which in most cases it never is), those of us who have a mental block when it comes to coding, just live without the whistles and bells or find a solution that doesn't involve any code.

It's not a matter of "we're too lazy to add it to our template files", it's a matter of "we have absolutely no clue how, unless somebody spells it out for us". Now, I speak for myself when I say that I do my best to find a solution, even if it includes a few lines of code. Had I not been adamant about testing the "no trailing .00" theory from the article in #10, I would have given up at the theming solution and moved on. (Glad I stuck with it and DanZ gave me some great focal insight to figure it out)

If I knew how to code, I would gladly come up with a patch but unfortunately the best I can do is be a royal pain in the butt for maintainers like you guys ;-)

---

@longwave I "think" the only place that needs attention is views which it looks like the patch you mentioned, might be just the trick. I personally can't see why someone would need to remove the trailing zeros from the admin reports... The theme override from #9 doesn't even remove them... (Thousand marker from the store settings does remove it from the admin reports though)

---

If the general consensus of the maintainers is to "enable this through the theme", then my question is: What can we do as the Ubercart community, to create a repository of "easy to use code" for overriding the various theming functions of UC? I don't want to say ubercart.org is dead, but it isn't utilized like it used to be. Much of the info is completely outdated and irrelevant to UC3, but would make a great place to have a section of "code that works" for various situations. Instead of adding something like this request to core, it could be added to ubercart.org and linked over from the issue queue for the "proper solution". (Just thinking aloud)

---

"If" a patch were presented to include this in core, would it be accepted as a viable feature request? Or is the template.php theming route the only way to go?

At this point, I'm fine with the theming route because I have a fairly cut-and-dry solution. But ultimately, I would love to see this in core and I have a feeling a lot more people would use it, if it were widely available.

longwave’s picture

I agree with TR in that we should definitely leave this up to the end user to solve via theming; writing small custom theme functions is a common thing to do on any Drupal site to customise the output for specific needs.

The override function in #9, or any other theming override, can also be built into a small custom module that implements hook_theme_registry_alter to provide the altered output simply by installing the module.

philsward’s picture

Well, if that is the collective decision, then that's it.

Do either of you guys have access to ubercart.org? Do you think we can get a page area going where folks can share with the community and post theme override code for specific things like this?

longwave’s picture

Category: feature » support
Status: Postponed (maintainer needs more info) » Fixed

We currently recommend adding documentation to drupal.org rather than ubercart.org. Any of the pages under https://drupal.org/documentation/modules/ubercart can be edited, and there is a HowTos section at https://drupal.org/node/1326726 which seems an appropriate place for someone to add this theme override snippet. It would be very helpful if someone who uses this functionality could add a short note there!

philsward’s picture

longwave’s picture

Thank you :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

haysuess’s picture

Issue summary: View changes

I've tried the solution in #9 and it ONLY works in Views that display prices using "Ubercart price".

My node template calls for prices like this:

<?php print uc_currency_format($node->list_price); ?>
<?php print uc_currency_format($node->sell_price); ?>

Do I need to call the prices differently in the node template to get the theme override in #9 to work?

haysuess’s picture

I figured it out, you have to print them like this:

<?php print render ($content['sell_price']); ?>

Then I had to use String Override to rename "Price:" to "something else" and "List price:" to "Regular Price:"