'NZD' currency not found during rate calculation

Created on 11 May 2024, about 2 months ago
Updated 10 June 2024, 20 days ago

Problem/Motivation

When attempting to calculate shipping rates using the `commerce_shipping_order_percentage` module in a Drupal Commerce setup, an When attempting to calculate shipping rates using the commerce_shipping_order_percentage module in a Drupal Commerce setup, an exception is thrown indicating that the "NZD" currency could not be loaded. This issue prevents the completion of the shipping rate calculation process, potentially disrupting e-commerce operations that rely on accurate shipping costs.

Steps to reproduce

1. Set up a Drupal Commerce site with the `commerce_shipping_order_percentage` module enabled.
2. Configure the shipping method to use NZD (New Zealand Dollar) as the currency.
3. Add products to the cart and proceed to checkout.
4. Attempt to finalize the checkout process where shipping rates need to be calculated.

Proposed resolution

Modify the commerce_shipping_order_percentage module to dynamically load the default currency code from the store configuration instead of using a hardcoded "NZD". This change will ensure that the module is more flexible and can handle any store currency configuration, preventing similar issues in the future.

Changes to the module should include:

Accessing the current store’s default currency setting using the CurrentStoreInterface.
Using this currency code in the rate calculation logic.
Here is a brief code snippet illustrating how to retrieve the default currency code:

// Use $current_currency in rate calculations
$current_currency = $this->currentStore->getStore()->getDefaultCurrencyCode();

Remaining tasks

- Verification: Update the module code to dynamically fetch and use the default store currency.
- Testing: Verify that the default currency is correctly retrieved and used in the shipping calculation.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024