Commerce: Wrong payment currencies in orders

Created on 24 Nov 2020  路  5Comments  路  Source: craftcms/commerce

Description
I have set up multiple payment currencies for craft commerce:
NZD - which is the base currency, AUD, EUR, GBP, JPY, USD.

When I go to Commerce -> Orders -> All orders, the total price of the order is rendered as expected in the grid as shown in the picture:
image

But when I click on the order, the order summary always shows in NZD even if it was paid for in another currency:
image

I'm not sure if this is a bug or I am missing something.

Expected behavior
To have the order summary in the currency the order was paid in.

Additional info

  • Craft version: Pro 3.5.14
  • Commerce version:
  • PHP version: 7.3.19
  • Database driver & version: MySQL 5.6.48
  • Other Plugins & versions:

Abandoned Cart for Craft Commerce 1.5.3
Asset Rev 6.0.2
Cloudflare 0.5.1
Colorit 1.0.9.3
Commerce Currency Prices 2.6.4
Craft Commerce 3.1.9
Element API 2.6.0
Embedded Assets 2.2.6
Facebook Product Catalog 1.2.0
Freeform 3.6.12
Google Shopping Feed 1.2.1
Imager v2.4.0
Image Resizer 2.0.9
Instant Analytics 1.1.7
HTTP2 Server Push 1.0.1
Mailgun 1.4.3
Matrix Toolbar 1.0.6
Navigation 1.3.20
Neo 2.7.19
PayPal for Craft Commerce 2.1.0.1
Redactor 2.6.1
Retour 3.1.39
SEO 3.3.8
Stripe for Craft Commerce 2.3.1.1
Typed link field 1.0.23

馃悶 bug 馃攲 plugin 馃Ь orders

Most helpful comment

Hi @pdaleramirez, I'm one of the developers at Kurious Agency, before we implement a change to the Commerce Currency Prices plugin can I confirm this is not a bug in Commerce.

In the LineItem model behaviours method (vendor/craftcms/commerce/src/models/LineItem.php line 231) there's a check to use the order currency as the default currency before using the primary payment currency:

$behaviors['currencyAttributes'] = [  
    'class' => CurrencyAttributeBehavior::class,
    'defaultCurrency' => $this->_order->currency ?? Plugin::getInstance()->getPaymentCurrencies()->getPrimaryPaymentCurrencyIso(),
    'currencyAttributes' => $this->currencyAttributes()
];

$this->_order->currency always returns null as $this->_order is never set, is this correct?

@mcjackson18 Fixed this issue on next release. It should get the order's currency.

All 5 comments

@palomamtnez
Hi, Commerce actually only displays the primary currency that was set. You'll see the other currencies on payment and on order transaction tab. I see that your setup is using a plugin to display multiple currencies specifically Commerce Currency Prices 2.6.4. You would have to submit an issue to them here https://github.com/KuriousAgency/commerce-currency-prices

Hi @pdaleramirez, I'm one of the developers at Kurious Agency, before we implement a change to the Commerce Currency Prices plugin can I confirm this is not a bug in Commerce.

In the LineItem model behaviours method (vendor/craftcms/commerce/src/models/LineItem.php line 231) there's a check to use the order currency as the default currency before using the primary payment currency:

$behaviors['currencyAttributes'] = [  
    'class' => CurrencyAttributeBehavior::class,
    'defaultCurrency' => $this->_order->currency ?? Plugin::getInstance()->getPaymentCurrencies()->getPrimaryPaymentCurrencyIso(),
    'currencyAttributes' => $this->currencyAttributes()
];

$this->_order->currency always returns null as $this->_order is never set, is this correct?

Hi @mcjackson18,

I have made the test as requested and yes, it returns null

The way I did it was to just add a var_dump() in LineItem::behaviors like this:

        $behaviors['currencyAttributes'] = [
            'class' => CurrencyAttributeBehavior::class,
            'defaultCurrency' => $this->_order->currency ?? Plugin::getInstance()->getPaymentCurrencies()->getPrimaryPaymentCurrencyIso(),
            'currencyAttributes' => $this->currencyAttributes()
        ];

        var_dump($this->_order); // NEW LINE

        return $behaviors;

Result:

Screen Shot 2020-12-09 at 9 08 41 AM

Note: If I tried with $this->_order->currency, it returns the error:

Trying to get property 'currency' of non-object

Would you consider then it's a problem from Commerce @pdaleramirez ?
Thank you!!

Hi @pdaleramirez, I'm one of the developers at Kurious Agency, before we implement a change to the Commerce Currency Prices plugin can I confirm this is not a bug in Commerce.

In the LineItem model behaviours method (vendor/craftcms/commerce/src/models/LineItem.php line 231) there's a check to use the order currency as the default currency before using the primary payment currency:

$behaviors['currencyAttributes'] = [  
    'class' => CurrencyAttributeBehavior::class,
    'defaultCurrency' => $this->_order->currency ?? Plugin::getInstance()->getPaymentCurrencies()->getPrimaryPaymentCurrencyIso(),
    'currencyAttributes' => $this->currencyAttributes()
];

$this->_order->currency always returns null as $this->_order is never set, is this correct?

@mcjackson18 Fixed this issue on next release. It should get the order's currency.

Awesome, that fixed the issue. Thank you! 馃槉

Was this page helpful?
0 / 5 - 0 ratings