Anonymous No.2 Posted September 7, 2021 Share Posted September 7, 2021 (edited) I need to format price in my module's javascript. As I figured out, I need to use formatCurrencyCldr(). I included tools.js where formatCurrencyCldr is defined: public function hookHeader() { $this->context->controller->addJqueryUI('ui.autocomplete'); $this->context->controller->registerJavascript('modules-mymodule0', 'js/tools.js', ['position' => 'bottom', 'priority' => 1]); $this->context->controller->registerJavascript('modules-mymodule', 'modules/'.$this->name.'/mymodule.js', ['position' => 'bottom', 'priority' => 150]); $this->context->controller->addCSS($this->_path.'front.css', 'all'); } However I get Quote window.cldr is undefined getCurrencyFormatter@http://...../js/tools.js:177:3 What I am doing wrong? Edited September 7, 2021 by Anonymous No.2 removed typo errors (see edit history) Link to comment Share on other sites More sharing options...
vlgalik Posted October 25, 2023 Share Posted October 25, 2023 (edited) Had the same problem. Then I included: // fixes undefined currency_specifications & number_specifications Media::addJsDef( [ 'currency_specifications' => $this->preparePriceSpecifications($this->context), 'number_specifications' => $this->prepareNumberSpecifications($this->context), ] ); // fixes undefined cldr // cldr.bundle.js is copied from /admin-XXXXXX/themes/new-theme/public/cldr.bundle.js - so I don't disclose the admin url $this->context->controller->registerJavascript('modules-mymodule1', 'js/cldr.bundle.js', ['position' => 'bottom', 'priority' => 1]); // contains formatCurrencyCldr function $this->context->controller->registerJavascript('modules-mymodule0', 'js/tools.js', ['position' => 'bottom', 'priority' => 1]); And these two methods: // copied from classes/controller/AdminController.php private function preparePriceSpecifications(Context $context) { /* @var Currency */ $currency = $context->currency; /* @var PriceSpecification */ $priceSpecification = $context->getCurrentLocale()->getPriceSpecification($currency->iso_code); if (empty($priceSpecification)) { return []; } return array_merge( ['symbol' => $priceSpecification->getSymbolsByNumberingSystem(Locale::NUMBERING_SYSTEM_LATIN)->toArray()], $priceSpecification->toArray() ); } // copied from classes/controller/AdminController.php private function prepareNumberSpecifications(Context $context) { /* @var NumberSpecification */ $numberSpecification = $context->getCurrentLocale()->getNumberSpecification(); if (empty($numberSpecification)) { return []; } return array_merge( ['symbol' => $numberSpecification->getSymbolsByNumberingSystem(Locale::NUMBERING_SYSTEM_LATIN)->toArray()], $numberSpecification->toArray() ); } After that formatCurrencyCldr finally worked in FO. In BO you only need to include the tools.js. Edited October 25, 2023 by vlgalik (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now