GitHub - Breczek/nbpcurrency: Automatic NBP exchange rate sync for PrestaShop — keeps your shop's currencies up to date with Poland's central bank rates. · GitHub
Skip to content

About

Automatic NBP exchange rate sync for PrestaShop — keeps your shop's currencies up to date with Poland's central bank rates.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

nbpcurrency — NBP exchange rates for PrestaShop

A PrestaShop 8/9 module that fetches currency exchange rates from the National Bank of Poland (NBP) public API and writes them into PrestaShop's own currency conversion rates — no manual updates, no third-party paid services.

Why this exists

  • Why am I still updating exchange rates by hand every day?
  • Why do currency-rate modules on the marketplace charge a subscription for something a free central-bank API already provides?
  • I only need a couple of currencies tracked (not a full 150-currency dashboard) — why is every existing option so heavy?

This module talks directly to api.nbp.pl, so rates are grounded in the actual published NBP tables (A/B/C) rather than a paraphrased or scraped copy — pick which currencies to track and it keeps PrestaShop's conversion rates in sync (per shop in multistore), on a schedule you control.

What's inside

Item What it does
nbpcurrency.php Module class — NBP API client, cross-rate math (PLN-anchored), tracked-currency CRUD, hook + cron entry points
controllers/admin/AdminNbpCurrencyController.php Back-office page: add/edit/remove tracked currencies, manual refresh, rate log
cron/update.php Token-authenticated HTTP endpoint for external cron, for shops without the CronJobs module
views/templates/admin/configuration.tpl Back-office configuration screen
upgrade/ Upgrade scripts run by PrestaShop when updating from an older version

Install

  1. Zip the nbpcurrency/ folder.
  2. PrestaShop back office → Modules → Upload a module → select the zip.
  3. Open the module's configuration page, add the currencies you want tracked and pick an NBP table (A, B, or C) per currency.

How to use

  • Each tracked currency is matched against one of NBP's three published tables — A (32 major currencies, daily mid rate), B (116 less-liquid currencies, weekly mid rate), C (13 currencies, daily bid/ask). The module validates your choice against the currency codes NBP actually publishes in each table.
  • If your shop's default currency isn't PLN, that default currency must itself be tracked — NBP always quotes against PLN, so it's the anchor used to compute every other tracked currency's cross rate.
  • Multistore: choose which shops get updated. Each shop is handled according to its own default currency, and the rate is written to that shop's ps_currency_shop row. Module settings are global, so it doesn't matter which shop's domain the cron URL is called on.
  • Rates are only written when they actually change — a run with no new NBP table (weekend, holiday, table B outside Wednesday) writes nothing, and the module never flushes the Smarty cache.
  • Enable auto update to refresh rates via the actionCronJob hook (PrestaShop's CronJobs module), or call cron/update.php?token=... from an external cron — the token is generated on install and shown on the configuration page.
  • Every fetch (success or failure) is written to a rate log, visible on the configuration page, for troubleshooting a missed or rejected update.

Requirements

  • Verified against: PrestaShop 9.1.4, PHP 8.x, MariaDB.
  • Declared compatibility: PrestaShop 8.0+ (ps_versions_compliancy in nbpcurrency.php) — not yet manually tested on 8.x, only on 9.1.4.
  • Outbound HTTPS access to api.nbp.pl is required from the shop's server.
  • NBP's currency lists (which codes live in which table) are hardcoded as class constants, checked directly against the live API — table membership can change over time; open an issue if NBP adds/removes a currency and the module rejects it incorrectly.

Changelog

1.1.0

  • Fixed: the module no longer calls Tools::clearSmartyCache() after every rate write. That flushed the whole Smarty cache and all compiled templates on every cron run, so the next storefront requests had to rebuild every module's cached output — a database load spike once a day (or several times, one per tracked currency).
  • Fixed: conversion rates are no longer saved through Currency::save(), which overwrote the currency's localized names and symbols in all languages with the value of the current context language.
  • Fixed (multistore): settings are stored globally and rates are written per shop. Previously the shop context of the request (e.g. the domain the cron URL was called on) decided where settings were saved and which shop's rates were updated.
  • Added: shop selection in the back office and per-shop conversion rates in the tracked-currency table.
  • Changed: unchanged NBP tables are not logged again on scheduled runs; a manual "fetch now" always logs.

1.0.0

  • Initial release.

Contributing

Corrections and additions welcome — NBP's published tables and PrestaShop's core both keep moving. Open an issue or PR with the PrestaShop version you observed.

License

MIT.

Author

Marcin Bręczewski (@Breczek) — PrestaShop development.

About

Automatic NBP exchange rate sync for PrestaShop — keeps your shop's currencies up to date with Poland's central bank rates.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages