Forums / Bug Reports / Admin: Incorrect order totals display for non-default currency order

Admin: Incorrect order totals display for non-default currency order

Views: 1,718

Results 1 to 6 of 6
21 Jun 2013, 1:04 PM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,111
Plugin Contributions:
56

Admin: Incorrect order totals display for non-default currency order

Running an unmodified Zen Cart v1.5.1 installation with the demo products installed. If an order is placed in a currency other than the default (USD), when that order's details are displayed using the admin's Customers->Orders, the order-total values are always displayed using the default currency.
Attachment 12686
(My apologies for the teeny screenshot, but I don't know how to get the image uploader to stop shrinking it)

To reproduce the issue:

  1. Change the currency to EUR
  2. Add an item to your cart; I chose 'Test Seven' (products_id=120)
  3. Checkout via the Check/Money Order payment method
  4. Go to the admin and view the order's details. While the product prices are shown in EUR, the order total values are shown in USD (the default currency).
    The issue lies in /YOUR_ADMIN/orders.php, lines 596-603:
<?php
    for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
      echo '              <tr>' . "\n" .
           '                <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Text">' . $order->totals[$i]['title'] . '</td>' . "\n" .
           '                <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Amount">' . $currencies->format($order->totals[$i]['value'], false) . '</td>' . "\n" .
           '              </tr>' . "\n";
    }
?>

... as the default currency is being used to format the total value. To correct the issue, make the highlighted change:

<?php
    for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
      echo '              <tr>' . "\n" .
           '                <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Text">' . $order->totals[$i]['title'] . '</td>' . "\n" .
           '                <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Amount">' . /*-bof-c-lat9 $currencies->format($order->totals[$i]['value'], false)*/ $order->totals[$i]['text'] /*-eof-c-lat9*/ . '</td>' . "\n" .
           '              </tr>' . "\n";
    }
?>
21 Jun 2013, 5:09 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Admin: Incorrect order totals display for non-default currency order

This is possibly a better fix ...

I have both values displaying in this example, for testing purposes, the calculated amount vs the text amount ... the calculated amount is using the exchange rate stored in the orders table:

<?php
    for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
      echo '              <tr>' . "\n" .
           '                <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Text">' . $order->totals[$i]['title'] . '</td>' . "\n" .
           '                <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Amount">' . [B]$currencies->format($order->totals[$i]['value'], true, $order->info['currency'], $order->info['currency_value']) . ' vs ' . $order->totals[$i]['text'][/B] . '</td>' . "\n" .
           '              </tr>' . "\n";
    }
?>

While either can work, do you have an opinion on which is the better one?

I lean towards the calculated one, as it keeps in line with the other code in the orders.php class ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

21 Jun 2013, 6:54 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,111
Plugin Contributions:
56

Re: Admin: Incorrect order totals display for non-default currency order

Ajeh, I'd lean towards the 'text' value for the following reasons:

  1. The 'text' rather than the calculated value is what is shown to the customer on the account_history_info page (consistency in display).
  2. If, for some unseen reason, a shop owner decides that they are no longer going to use a currency (like when the Euro came into being and many of the extant European currencies became obsolete) and they remove that currency, then the calculated method will fail because the currency no longer exists in the store's database.
21 Jun 2013, 7:39 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Admin: Incorrect order totals display for non-default currency order

There is the rub ...

If you delete the currency in the admin, because you no longer use it, you loose the layout of the currency and that breaks many other things for both the Store and the Admin as now the Product details cannot be displayed correctly ...

The better option is to customize the currency sidebox to skip the currency to be removed from the store, but leave it in the Currency definitions in the Admin so that everything can still look correct for both Store and Admin on Customer History and existing Orders from the past, before the Currency was determined not to be used any longer ... even when the value for the currency is set to 0, it still functions correctly as the exchange rate is in the orders table ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

21 Jun 2013, 10:39 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,111
Plugin Contributions:
56

Re: Admin: Incorrect order totals display for non-default currency order

Ajeh, sounds like you've (as always) thought this out. I defer to your judgement.

22 Jun 2013, 1:57 AM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Admin: Incorrect order totals display for non-default currency order

Thought it out then tested it out, as you did have sound reasoning ... but I found way too much broken to just delete a currency rather than exclude it on the currency choices on the Store ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!