Skip to content

Commit d5c899c

Browse files
authored
Merge pull request #1076 from w3bdesign/1001-refactor-code
Re-enable SSR
2 parents b1af793 + 1c97c59 commit d5c899c

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

nuxt.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import { defineNuxtConfig } from "nuxt/config";
44

55
export default defineNuxtConfig({
6-
//ssr: true,
7-
ssr: false,
6+
ssr: true,
87
components: true,
98
css: ["~/assets/css/main.css", "~/assets/css/animate.min.css"],
109
modules: [

utils/functions.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { uid } from "uid";
22

3-
const config = useRuntimeConfig();
4-
53
/**
64
* Checks if the given data object has any variations by accessing the product's variations nodes array.
75
*
@@ -15,19 +13,28 @@ export function hasVariations(data) {
1513
}
1614

1715
/**
18-
* Formats the given price to the currency specified in the config file using the Intl.NumberFormat object.
16+
* Formats a given price into a string with a currency symbol and locale.
1917
*
20-
* @param {number} price - The price to be formatted.
21-
* @return {string} The formatted price as a string with the currency symbol and no decimal places.
18+
* @param {string} price - The price to format.
19+
* @param {string} currency - The currency to use. Defaults to "NOK".
20+
* @param {string} currencyLocale - The locale to use for the currency symbol. Defaults to "nb-NO".
21+
* @return {string} The formatted price as a string with the currency symbol and locale.
2222
*/
23-
export function formatPrice(price) {
24-
// Convert the price string to a numerical float value
23+
export function formatPrice(price, currency, currencyLocale) {
24+
// Set default values
25+
const currencyPrice = currency || "NOK";
26+
const currencySymbol = currencyLocale || "nb-NO";
2527

28+
if (!price) {
29+
return;
30+
}
31+
32+
// Convert the price string to a numerical float value
2633
const numericPrice = parseFloat(price.replace(/[^\d.]/g, ""));
2734

28-
return new Intl.NumberFormat(config.public.currencyLocale, {
35+
return new Intl.NumberFormat(currencySymbol, {
2936
style: "currency",
30-
currency: config.public.currency,
37+
currency: currencyPrice,
3138
minimumFractionDigits: 0,
3239
maximumFractionDigits: 0,
3340
}).format(numericPrice);

0 commit comments

Comments
 (0)