summaryrefslogtreecommitdiff
path: root/storefront/lib
diff options
context:
space:
mode:
authorertopogo <erwin.t.pombett@gmail.com>2026-02-01 02:53:13 +0100
committerertopogo <erwin.t.pombett@gmail.com>2026-02-01 02:53:13 +0100
commitbc6f65dc9afa29fbb94038b1cfd5cbee2d87719c (patch)
tree745095c67dc674567d4e0823388252b104a2e17e /storefront/lib
parente704383cb20e7016794ccc793eda057a609be835 (diff)
feat: mise à jour storefront + checkout
Diffstat (limited to 'storefront/lib')
-rw-r--r--storefront/lib/format.js22
-rw-r--r--storefront/lib/storefront.js132
2 files changed, 77 insertions, 77 deletions
diff --git a/storefront/lib/format.js b/storefront/lib/format.js
index 2f44c2e..9e92a8b 100644
--- a/storefront/lib/format.js
+++ b/storefront/lib/format.js
@@ -1,11 +1,11 @@
-export const formatAmount = (amount, currencyCode = "EUR") => {
- if (typeof amount !== "number") {
- return ""
- }
-
- const normalizedCurrency = currencyCode.toUpperCase()
- return new Intl.NumberFormat("fr-FR", {
- style: "currency",
- currency: normalizedCurrency,
- }).format(amount / 100)
-}
+export const formatAmount = (amount, currencyCode = "EUR") => {
+ if (typeof amount !== "number") {
+ return ""
+ }
+
+ const normalizedCurrency = currencyCode.toUpperCase()
+ return new Intl.NumberFormat("fr-FR", {
+ style: "currency",
+ currency: normalizedCurrency,
+ }).format(amount / 100)
+}
diff --git a/storefront/lib/storefront.js b/storefront/lib/storefront.js
index b6433a9..ccfe1cd 100644
--- a/storefront/lib/storefront.js
+++ b/storefront/lib/storefront.js
@@ -1,66 +1,66 @@
-export const cartStorageKey = "lsb_cart_id"
-export const tokenStorageKey = "lsb_customer_token"
-
-export const getStoredCartId = () => {
- if (typeof window === "undefined") {
- return null
- }
- return window.localStorage.getItem(cartStorageKey)
-}
-
-export const setStoredCartId = (cartId) => {
- if (typeof window === "undefined") {
- return
- }
- window.localStorage.setItem(cartStorageKey, cartId)
-}
-
-export const clearStoredCartId = () => {
- if (typeof window === "undefined") {
- return
- }
- window.localStorage.removeItem(cartStorageKey)
-}
-
-export const getStoredToken = () => {
- if (typeof window === "undefined") {
- return null
- }
- return window.localStorage.getItem(tokenStorageKey)
-}
-
-export const setStoredToken = (token) => {
- if (typeof window === "undefined") {
- return
- }
- window.localStorage.setItem(tokenStorageKey, token)
-}
-
-export const clearStoredToken = () => {
- if (typeof window === "undefined") {
- return
- }
- window.localStorage.removeItem(tokenStorageKey)
-}
-
-export const ensureCart = async (client) => {
- const storedCartId = getStoredCartId()
-
- if (storedCartId) {
- try {
- const { cart } = await client.carts.retrieve(storedCartId)
- return cart
- } catch (error) {
- clearStoredCartId()
- }
- }
-
- const { regions } = await client.regions.list()
- if (!regions?.length) {
- throw new Error("Aucune région disponible pour créer un panier.")
- }
-
- const { cart } = await client.carts.create({ region_id: regions[0].id })
- setStoredCartId(cart.id)
- return cart
-}
+export const cartStorageKey = "lsb_cart_id"
+export const tokenStorageKey = "lsb_customer_token"
+
+export const getStoredCartId = () => {
+ if (typeof window === "undefined") {
+ return null
+ }
+ return window.localStorage.getItem(cartStorageKey)
+}
+
+export const setStoredCartId = (cartId) => {
+ if (typeof window === "undefined") {
+ return
+ }
+ window.localStorage.setItem(cartStorageKey, cartId)
+}
+
+export const clearStoredCartId = () => {
+ if (typeof window === "undefined") {
+ return
+ }
+ window.localStorage.removeItem(cartStorageKey)
+}
+
+export const getStoredToken = () => {
+ if (typeof window === "undefined") {
+ return null
+ }
+ return window.localStorage.getItem(tokenStorageKey)
+}
+
+export const setStoredToken = (token) => {
+ if (typeof window === "undefined") {
+ return
+ }
+ window.localStorage.setItem(tokenStorageKey, token)
+}
+
+export const clearStoredToken = () => {
+ if (typeof window === "undefined") {
+ return
+ }
+ window.localStorage.removeItem(tokenStorageKey)
+}
+
+export const ensureCart = async (client) => {
+ const storedCartId = getStoredCartId()
+
+ if (storedCartId) {
+ try {
+ const { cart } = await client.carts.retrieve(storedCartId)
+ return cart
+ } catch (error) {
+ clearStoredCartId()
+ }
+ }
+
+ const { regions } = await client.regions.list()
+ if (!regions?.length) {
+ throw new Error("Aucune région disponible pour créer un panier.")
+ }
+
+ const { cart } = await client.carts.create({ region_id: regions[0].id })
+ setStoredCartId(cart.id)
+ return cart
+}