Repository navigation
Customer Account
This page covers the customer and shop context of a storefront: loading the shop (with baskets, club and pending payments), the signed-in customer, currency and exchange rates, language packs, push-notification tokens, and the small local database the SDK keeps per shop. Login itself is covered in Authentication.
shop.fetchShop() is the bootstrap call of every storefront. Call it on start-up, after login or logout, and when a basket call returns refresh: true.
const {
shop, // Shop + transportations, shop_exchange_rates, gateways, menus, product_badges, popup, guest_code
baskets, // open baskets of the customer or guest, one per product type
pending_transactions, // unfinished payments of this customer
club, // customer club (loyalty) level, or null
orders_state, // [{ count, delivery_state, type }] for order badges
initial_location, // location estimated from the visitor's IP
seen_pops, // popups already shown to this visitor
} = await window.$storefront.shop.fetchShop();Endpoint: GET /shops/@{shop}/info (with recent guest codes, so guests can see pending payments).
Two values need follow-up work:
-
shop.guest_code: save it and send it asS-Guest. See Basket and Checkout. -
seen_pops: save it so the nextSetup()sends it in theS-Popsheader and the same popup is not shown twice:
import { StorefrontLocalStorages } from "@selldone/core-js/helper/local-storage/StorefrontLocalStorages";
if (seen_pops) {
localStorage.setItem(
StorefrontLocalStorages.GetSeenPopups(window.$storefront.local_storage_path),
JSON.stringify(seen_pops),
);
}| API | Description |
|---|---|
window.$storefront.USER |
The current customer object, or null. |
user.fetchMyInfo(onSuccess, onError?) |
Loads the customer from GET /me and stores it in USER. Callback based and debounced (1 s). |
user.setCurrentUser(user) |
Sets USER manually. |
See Authentication for an example and the response fields.
window.$storefront.currency is the selected currency (an ICurrency object from Selldone Core with code, name, unicode, floats, format…). It is stored per shop in local storage. Without a saved choice it falls back to the default-currency meta tag, then to USD.
Change it by assigning an ICurrency or a currency code:
import { Currency } from "@selldone/core-js/enums/payment/Currency";
window.$storefront.currency = "EUR"; // or Currency.EUR
console.log(window.$storefront.currency.unicode); // "€"
// Tell the server, so open baskets are re-priced, then refresh
await window.$storefront.user.setUserCurrency("EUR");
await window.$storefront.shop.fetchShop();Only offer the currencies the shop supports (shop.currencies). The official Storefront also reloads coupons and offers after a currency change, because both are currency-specific.
| Method | Endpoint |
|---|---|
user.setUserCurrency(currency) |
PUT /shops/@{shop}/currency (also works for guests; a "guest shopping disabled" error is accepted as a normal response) |
window.$storefront.shop.exchange.fetchRates(
({ rates }) => {
shop.shop_exchange_rates = rates;
},
(error) => console.error(error),
);fetchRates is callback based and debounced by 2 seconds. Endpoint: GET /shops/@{shop}/exchange/rates. Use PriceHelper from Selldone Core to convert product prices with these rates.
The shop's default language is shop.language. The customer's choice is stored per shop:
const saved = window.$storefront.database.language.getLanguage(); // ILanguage | null
window.$storefront.database.language.setLanguage("de"); // code or ILanguageShops can override UI texts. Load the override pack for a locale and merge it into your i18n messages:
const pack = await window.$storefront.shop.language.fetchLanguagePack("de");
// The official Storefront merges pack.global into its "global" messages and pack.shop at the root.Endpoint: GET /shops/@{shop}/languages/{language}.
Register a Firebase Cloud Messaging token for the signed-in customer:
await window.$storefront.user.setFcmToken(fcmToken); // POST /shops/@{shop}/fcm/tokenwindow.$storefront.database (StorefrontDatabase) wraps the browser's localStorage, scoped to the shop:
| Store | Methods | Key |
|---|---|---|
database.coupon |
getCouponCodes(), addCouponCode(code), removeCouponCode(code)
|
shop/@{shop}/coupon-codes |
database.currency |
getCurrency(), saveCurrency(currency)
|
shop/@{shop}/user-currency |
database.language |
getLanguage(), setLanguage(language)
|
local-shop-{shop} |
Saved coupon codes are sent automatically by coupon.fetchAvailableCoupons(); see Coupons, Offers, Cashback and Lottery.
Profile, addresses, wishlist, orders, gift cards and wallets are available as XAPI URL builders on window.XAPI. Send the request with window.axios, which already has the customer token and headers:
| Feature | URL builder | Endpoint |
|---|---|---|
| Save profile | POST_SAVE_MY_CUSTOMER_PROFILE(shop) |
POST /shops/@{shop}/customer |
| Subscribe to / unsubscribe from the shop, leave the shop |
POST_SUBSCRIBE(shop), POST_LEAVE_SHOP(shop)
|
POST /shops/@{shop}/subscribe, /leave
|
| Addresses |
GET_MY_ADDRESSES(), POST_ADDRESS(), PUT_ADDRESS(id), DELETE_MY_ADDRESSES(id)
|
/address/all, /address, … |
| Wishlist |
PUT_WISHLIST_PRODUCT(shop, product_id), DELETE_WISHLIST_PRODUCT(shop, product_id)
|
/shops/@{shop}/products/{product_id}/wishlist |
| Orders |
GET_MY_ORDERS_HISTORY_PHYSICAL(shop, type), GET_ORDER_BASKET_INFO(shop, basket_id)
|
/shops/@{shop}/basket/orders-{type}, /shops/@{shop}/baskets/{basket_id}
|
| Return requests | GET_MY_BASKET_ITEM_RETURNS(shop) |
/shops/@{shop}/basket/orders/return-requests |
| Comments | GET_MY_COMMENTS(shop) |
/shops/@{shop}/comments |
| Gift cards and wallets |
GET_MY_GIFT_CARDS(shop), GET_MY_WALLETS(shop)
|
/shops/@{shop}/giftcards, /wallets
|
const { data } = await window.axios.get(window.XAPI.GET_MY_WALLETS(window.$storefront.name));To list wishlist products, you can also use products.list(null, 0, 20, { only_in_wishlist: true }). Payload details for each endpoint are documented in ai-guideline/storefront/11-checkout-payment-account-deep-dive.md.