Skip to content

getPackageShippingCost returns Packlink API price in service currency without converting to cart currency - #76

Open
matteolavaggi wants to merge 1 commit into
packlink-dev:masterfrom
matteolavaggi:fix/cart-currency-conversion
Open

matteolavaggi wants to merge 1 commit into
packlink-dev:masterfrom
matteolavaggi:fix/cart-currency-conversion

Conversation

@matteolavaggi

Copy link
Copy Markdown

Summary

  • Add ShippingCostCurrencyConverter to convert Packlink API/service prices from the shipping method currency to the cart currency using PrestaShop conversion_rate (same logic as Tools::convertPriceFull, without requiring front-office context).
  • Update PackageCostCalculator to convert costs on every return path before applying shop free-shipping settings.
  • Update SystemInfoService::getCurrencies() to return all enabled shop currencies via Currency::getCurrenciesByIdShop() instead of only PS_CURRENCY_DEFAULT.

Environment

  • PrestaShop 1.7 / 8 / 9 with multiple currencies enabled
  • Shop default currency: EUR
  • Customer checkout currency: e.g. NOK, SEK, GBP (any non-default)
  • Packlink PRO PrestaShop module 3.5.x / 3.6.0

Steps to reproduce

  1. Enable a secondary currency (e.g. NOK) in PrestaShop.
  2. Customer selects NOK at checkout and a Norway delivery address.
  3. Packlink carrier is available; API returns rates in EUR (e.g. FedEx base_price: 17.96, currency: EUR).
  4. Complete order.

Expected

Shipping cost shown and stored in cart currency (NOK), e.g. ~194 NOK for 17.96 EUR (using PS conversion_rate).

Actual (before fix)

EUR amount is passed to PrestaShop unchanged and displayed/stored as NOK, e.g. 23.35 NOK instead of ~252 NOK.

Root cause

PackageCostCalculator::getPackageCost() returns ShippingCostCalculator / API costs without converting from the shipping method currency to $cart->id_currency.

SystemInfoService::getCurrencies() only exposes PS_CURRENCY_DEFAULT, not all shop currencies — related for multi-currency misconfiguration handling.

Verification

// Order with id_currency = NOK, Packlink API FedEx base_price 17.96 EUR
// Before fix: PackageCostCalculator returns ~23.35
// After fix:  returns ~194.20 NOK (rate-dependent)

Manual test:

  1. Enable a non-default checkout currency (e.g. NOK) with a realistic conversion_rate vs EUR.
  2. Place a test order with a Packlink carrier whose API rate is returned in EUR.
  3. Confirm checkout shipping cost and order total use the converted NOK amount, not the raw EUR value.

Test plan

  • Checkout with cart currency = default (EUR): shipping cost unchanged
  • Checkout with cart currency = secondary (e.g. NOK): cost converted from service currency
  • Backup carrier path: min cost computed after per-method conversion
  • Packlink admin system info lists all enabled shop currencies

Made with Cursor

Convert API/service prices from the shipping method currency to the
cart currency before returning from PackageCostCalculator, and expose
all enabled shop currencies in SystemInfoService for multi-currency
configuration.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant