webdna / commerce-currency-prices

Add a product price for each currency
Other
3 stars 5 forks source link

Currency error in orders #18

Open palomamtnez opened 3 years ago

palomamtnez commented 3 years ago

Description

  1. The main currency is set up as NZD, however, the grid shows orders that were paid in USD showing without the currency code.

  2. Shipping is displaying in NZD when the order was paid in a different currency.

Examples 1. Screen Shot 2021-02-10 at 10 25 39 AM

Screen Shot 2021-02-10 at 10 25 19 AM

2. Screen Shot 2021-02-10 at 10 24 50 AM

To Reproduce How, and what happened? As screenshots

Expected behavior

  1. Show all orders in the grid with their respective currency codes.
  2. Show shipping with their respective currency code.

Additional info

Stripe for Craft Commerce: 2.3.2.1 PayPal for Craft Commerce: 2.1.0.1

onetdev commented 3 years ago

Hi @palomamtnez,

So I've ran into the same issue as you did and here is what I found.

This issue will occure when craftcms\commerc\elements\Order->currency has different value other than what is set to base currency.

I think this is the intended behavior on Commerce side but still feels wrong: image

This helped the transaction to remain valid when having same currency and payment currency but not the same as base currency:

use craft\commerce\events\TransactionEvent;
use craft\commerce\services\Transactions;

Event::on(Transactions::class, Transactions::EVENT_AFTER_CREATE_TRANSACTION, function (TransactionEvent $event) {
        $tx = &$event->transaction;
        if ($tx->currency !== $tx->paymentCurrency) { return; }
        $tx->paymentCurrency = $tx->currency;
        $tx->paymentAmount = $tx->amount;
        $tx->paymentRate = 1;
});

Do you have currency issue on the transaction tab?