@eldrajs/theme-cli 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +1 -1
- package/template/.eldra/manifest.json +2 -0
- package/template/.eldra/previews.json +2 -2
- package/template/app/storefront/commerce.ts +12 -8
- package/template/app/storefront/currency.ts +94 -27
- package/template/app/storefront/feedback.ts +1 -0
- package/template/blocks/cart/__tests__/notSold.spec.ts +41 -0
- package/template/blocks/cart/parts/NotSoldNotice.vue +7 -2
- package/template/blocks/product-detail/Block.vue +29 -7
- package/template/blocks/product-detail/__tests__/Block.spec.ts +112 -1
- package/template/i18n/en-US.json +1 -0
- package/template/i18n/is-IS.json +1 -0
- package/template/test/storefront/currencyDefault.spec.ts +475 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- The starter template builds its pages in the store's default currency (`commerce.defaultCurrency`), and never offers the store's own currency once the store turned it off; a cart left in that currency moves to the default, and a business customer's cart stays in ISK (`currency.keepOwnCurrency()` for a theme with business sign-in) (WS-1399).
|
|
8
9
|
- `eldra-theme types` asks the gateway for the `declare module '@eldrajs/sdk'` augmentation and
|
|
9
10
|
writes it with the CMS types, so `product.extensions` is typed through the SDK's
|
|
10
11
|
`EldraProductExtensions` registry (WS-434, contract 6.1.0). It is on by default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "CLI for Eldra themes: init from the starter, scaffold blocks, validate, generate types, deploy a static build to Eldra.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"citty": "^0.1.6",
|
|
44
44
|
"tar": "^7.4.3",
|
|
45
|
-
"@eldrajs/
|
|
46
|
-
"@eldrajs/theme
|
|
45
|
+
"@eldrajs/theme-core": "^0.3.6",
|
|
46
|
+
"@eldrajs/vite-plugin-theme": "^0.3.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"execa": "^9.5.2"
|
|
@@ -432,7 +432,7 @@ declare global {
|
|
|
432
432
|
|
|
433
433
|
/** The theme's own message keys (`i18n/<tag>.json`'s default locale),
|
|
434
434
|
* flattened to dotted paths — vue-i18n's `t()` argument. */
|
|
435
|
-
type MessageKey = 'announcement.dismiss' | 'announcement.hintHelp' | 'announcement.hintLabel' | 'announcement.region' | 'article.authorHintHelp' | 'article.authorHintLabel' | 'article.bodyHintHelp' | 'article.bodyHintLabel' | 'article.byline' | 'article.coverHintHelp' | 'article.coverHintLabel' | 'article.dekHintLabel' | 'article.metaHintLabel' | 'article.richTextTableLabel' | 'article.titleHintLabel' | 'articleList.filterNav' | 'articleList.headingHintHelp' | 'articleList.headingHintLabel' | 'articleList.itemsHintHelp' | 'articleList.itemsHintLabel' | 'articleList.pages' | 'breadcrumbs.hintHelp' | 'breadcrumbs.hintLabel' | 'breadcrumbs.home' | 'cart.added' | 'cart.applied' | 'cart.apply' | 'cart.applyFailed' | 'cart.applyUnsupported' | 'cart.awayFromFree' | 'cart.checkout' | 'cart.columnProduct' | 'cart.columnQuantity' | 'cart.columnTotal' | 'cart.continueShopping' | 'cart.discount' | 'cart.discountCode' | 'cart.discountPlaceholder' | 'cart.drawerHintHelp' | 'cart.drawerHintHosted' | 'cart.drawerHintLabel' | 'cart.each' | 'cart.emptyFallbackTitle' | 'cart.freeUnlocked' | 'cart.invalidCode' | 'cart.itemCountMany' | 'cart.itemCountOne' | 'cart.items' | 'cart.lineTotal' | 'cart.loadFailed' | 'cart.paymentsAccepted' | 'cart.quantityFor' | 'cart.removeCode' | 'cart.removeItem' | 'cart.removeItemVariant' | 'cart.removed' | 'cart.shipping' | 'cart.shippingFree' | 'cart.shippingPending' | 'cart.subtotal' | 'cart.summary' | 'cart.title' | 'cart.total' | 'cart.tryAgain' | 'cart.undo' | 'cart.viewCart' | 'collection.countMany' | 'collection.countOne' | 'collection.readLess' | 'collection.readMore' | 'collection.subcategories' | 'collection.subcollections' | 'collection.titleHintHelp' | 'collection.titleHintLabel' | 'contact.addressLabel' | 'contact.detailsHintHelp' | 'contact.detailsHintLabel' | 'contact.emailFieldLabel' | 'contact.emailInvalidError' | 'contact.emailLabel' | 'contact.formTitleDefault' | 'contact.headingHintHelp' | 'contact.headingHintLabel' | 'contact.hoursLabel' | 'contact.introHintLabel' | 'contact.mapHintHelp' | 'contact.mapHintLabel' | 'contact.mapTitle' | 'contact.mapTitleWithAddress' | 'contact.messageLabel' | 'contact.messageRequiredError' | 'contact.nameLabel' | 'contact.nameRequiredError' | 'contact.orderNumberLabel' | 'contact.orderNumberPlaceholder' | 'contact.phoneLabel' | 'contact.replyTime' | 'contact.sendAnother' | 'contact.sendMessage' | 'contact.sending' | 'contact.serverError' | 'contact.serverErrorGeneric' | 'contact.successTextDefault' | 'contact.successTitle' | 'contact.summaryTitleMany' | 'contact.summaryTitleOne' | 'contact.topicLabel' | 'cta.buttonHintLabel' | 'cta.headingHintHelp' | 'cta.headingHintLabel' | 'cta.textHintLabel' | 'currency.cartNotSold' | 'currency.cartWillSwitch' | 'currency.checkoutWithout' | 'currency.label' | 'currency.movedTo' | 'currency.notIncludedMany' | 'currency.notIncludedOne' | 'currency.notSoldIn' | 'currency.notSoldInLong' | 'currency.shopIn' | 'editor.addLink' | 'error' | 'faq.headingHintLabel' | 'faq.introHintLabel' | 'faq.itemHintHelp' | 'faq.itemHintLabel' | 'faq.richTextTableLabel' | 'featureGrid.fallbackLabel' | 'featureGrid.headingHintLabel' | 'featureGrid.imageHintLabel' | 'featureGrid.itemHintHelp' | 'featureGrid.itemHintLabel' | 'footer.currencyLabel' | 'footer.descriptionHintLabel' | 'footer.emailError' | 'footer.emailInvalid' | 'footer.emailLabel' | 'footer.groupsHintHelp' | 'footer.groupsHintLabel' | 'footer.localeLabel' | 'footer.nav' | 'footer.newsletterAriaLabel' | 'footer.newsletterHintLabel' | 'footer.social.facebook' | 'footer.social.instagram' | 'footer.social.pinterest' | 'footer.social.tiktok' | 'footer.social.youtube' | 'footer.socialLinkName' | 'footer.subscribe' | 'footer.subscribed' | 'footer.subscribing' | 'footer.title' | 'form.formHintHelp' | 'form.formHintLabel' | 'form.headingHintLabel' | 'form.invalidEmail' | 'form.invalidForm' | 'form.invalidFormat' | 'form.invalidNumber' | 'form.invalidUrl' | 'form.loadFailed' | 'form.loading' | 'form.rateLimited' | 'form.required' | 'form.requiredCheckbox' | 'form.richTextTableLabel' | 'form.selectPlaceholder' | 'form.sendAnother' | 'form.submit' | 'form.submitting' | 'form.successTitle' | 'form.successTitlePending' | 'form.tooLarge' | 'form.tooLong' | 'form.tooShort' | 'form.turnstileFailed' | 'form.turnstileRequired' | 'form.unavailable' | 'form.unsupported' | 'gallery.carouselFallback' | 'gallery.headingHintHelp' | 'gallery.headingHintLabel' | 'gallery.imageHintLabel' | 'gallery.itemsHintHelp' | 'gallery.itemsHintLabel' | 'gallery.viewLarger' | 'gallery.viewer' | 'gallery.viewerHeading' | 'grid.activeFilters' | 'grid.availabilityInStock' | 'grid.availabilityOutOfStock' | 'grid.clearAll' | 'grid.clearFilters' | 'grid.columns' | 'grid.filter' | 'grid.filters' | 'grid.legendAvailability' | 'grid.legendCategory' | 'grid.legendCollection' | 'grid.legendColour' | 'grid.legendSize' | 'grid.nActive' | 'grid.nProducts' | 'grid.noCategoryHelp' | 'grid.noCategoryLabel' | 'grid.noCollectionHelp' | 'grid.noCollectionLabel' | 'grid.noResultsTitle' | 'grid.nothingIn' | 'grid.oneProduct' | 'grid.pagination' | 'grid.price' | 'grid.products' | 'grid.productsNoun' | 'grid.sectionLabel' | 'grid.sortBestSelling' | 'grid.sortBy' | 'grid.sortFeatured' | 'grid.sortNewest' | 'grid.sortPriceAsc' | 'grid.sortPriceDesc' | 'grid.updating' | 'header.cart' | 'header.cartEmpty' | 'header.cartMany' | 'header.cartOne' | 'header.menu' | 'header.openMenu' | 'header.primary' | 'header.search' | 'header.searchField' | 'header.viewAll' | 'header.viewAllOf' | 'header.wishlistEmpty' | 'header.wishlistMany' | 'header.wishlistOne' | 'hero.buttonHintLabel' | 'hero.carouselFallback' | 'hero.headingHintHelp' | 'hero.headingHintLabel' | 'hero.imageHintLabel' | 'hero.subheadingHintLabel' | 'imageBlock.captionHintLabel' | 'imageBlock.hintHelp' | 'imageBlock.hintLabel' | 'loading' | 'logoCloud.headingHintHelp' | 'logoCloud.headingHintLabel' | 'logoCloud.itemHintHelp' | 'logoCloud.itemHintLabel' | 'logoCloud.linkContext' | 'nav.menu' | 'nav.skipToContent' | 'newsletter.consentCheckboxLabel' | 'newsletter.consentRequired' | 'newsletter.emailLabel' | 'newsletter.emailPlaceholder' | 'newsletter.failed' | 'newsletter.headingHintLabel' | 'newsletter.invalidEmail' | 'newsletter.richTextTableLabel' | 'newsletter.subscribe' | 'newsletter.subscribing' | 'newsletter.successTitle' | 'newsletter.textHintLabel' | 'notFound.back' | 'notFound.body' | 'notFound.eyebrow' | 'notFound.title' | 'order.cardEnding' | 'order.carrierEta' | 'order.completed' | 'order.deliveryAddress' | 'order.detailsLabel' | 'order.estimated' | 'order.inProgress' | 'order.items' | 'order.needHelp' | 'order.notYet' | 'order.number' | 'order.payment' | 'order.placedMany' | 'order.placedOne' | 'order.progress' | 'order.qty' | 'order.shipping' | 'order.shippingFree' | 'order.showAllItems' | 'order.statusPrefix' | 'order.subtotal' | 'order.tax' | 'order.total' | 'order.trackOpens' | 'order.trackPackage' | 'order.trackingNumber' | 'pricing.headingHintLabel' | 'pricing.included' | 'pricing.includedIn' | 'pricing.introHintLabel' | 'pricing.mostPopular' | 'pricing.notIncluded' | 'pricing.planHintHelp' | 'pricing.planHintLabel' | 'product.addToCart' | 'product.backorder' | 'product.backorderNote' | 'product.backorderPending' | 'product.backorderShips' | 'product.hintHelp' | 'product.hintLabel' | 'product.imageIndex' | 'product.images' | 'product.inStock' | 'product.information' | 'product.lowStockMany' | 'product.lowStockManyIn' | 'product.lowStockOne' | 'product.lowStockOneIn' | 'product.notifyEmail' | 'product.notifyInvalid' | 'product.notifyMe' | 'product.notifySubmit' | 'product.notifySuccess' | 'product.notifyTitle' | 'product.notifyUnsupported' | 'product.quantity' | 'product.quickAdd' | 'product.quickAddMeta' | 'product.removeFromWishlist' | 'product.restockNote' | 'product.saleBadge' | 'product.saveToWishlist' | 'product.saving' | 'product.showImage' | 'product.sizeGuide' | 'product.soldOut' | 'product.soldOutIn' | 'product.tabsLabel' | 'product.taxNote' | 'product.viewer' | 'product.zoom' | 'productCarousel.carouselLabel' | 'productCarousel.clearHistory' | 'productCarousel.headingHintHelp' | 'productCarousel.headingHintLabel' | 'productCarousel.viewAllContext' | 'quote.headingFor' | 'quote.nameHintLabel' | 'quote.quoteHintHelp' | 'quote.quoteHintLabel' | 'richTextBlock.bodyHintHelp' | 'richTextBlock.bodyHintLabel' | 'richTextBlock.headingHintHelp' | 'richTextBlock.headingHintLabel' | 'richTextBlock.richTextTableLabel' | 'search.all' | 'search.customersLove' | 'search.didYouMean' | 'search.headingHintHelp' | 'search.headingHintLabel' | 'search.idleTitle' | 'search.noResultsAdvice' | 'search.noResultsTitle' | 'search.pageMany' | 'search.pageOne' | 'search.popularHintHelp' | 'search.popularHintLabel' | 'search.popularSearches' | 'search.productMany' | 'search.productOne' | 'search.resultMany' | 'search.resultOne' | 'search.resultTabs' | 'search.resultsHeading' | 'search.searchLabel' | 'search.searching' | 'search.storyMany' | 'search.storyOne' | 'search.title' | 'search.typeJournal' | 'search.typePages' | 'search.typeProducts' | 'search.viewAllJournal' | 'search.viewAllPages' | 'search.viewAllProducts' | 'splitContent.headingHintHelp' | 'splitContent.headingHintLabel' | 'splitContent.imageHintLabel' | 'splitContent.label' | 'splitContent.richTextTableLabel' | 'stats.headingHintLabel' | 'stats.introHintLabel' | 'stats.itemHintHelp' | 'stats.itemHintLabel' | 'storefront.cartOutOfDate' | 'storefront.error' | 'storefront.loading' | 'storefront.mutationFailed' | 'storefront.notFound' | 'storefront.orderStatus.cancelled' | 'storefront.orderStatus.delayed' | 'storefront.orderStatus.delivered' | 'storefront.orderStatus.processing' | 'storefront.orderStatus.shipped' | 'storefront.orderSteps.delivered' | 'storefront.orderSteps.ordered' | 'storefront.orderSteps.packed' | 'storefront.orderSteps.shipped' | 'storefront.outOfStock' | 'storefront.unavailable' | 'storefront.unresolvedCollectionHelp' | 'storefront.unresolvedCollectionLabel' | 'storefront.updatingValues' | 'tabsBlock.headingHintLabel' | 'tabsBlock.introHintLabel' | 'tabsBlock.itemHintHelp' | 'tabsBlock.itemHintLabel' | 'tabsBlock.richTextTableLabel' | 'tabsBlock.tabPlaceholderLabel' | 'team.emailPerson' | 'team.headingHintHelp' | 'team.headingHintLabel' | 'team.itemHintHelp' | 'team.itemHintLabel' | 'team.onInstagram' | 'team.onPinterest' | 'team.onTiktok' | 'team.portraitOf' | 'team.website' | 'testimonials.carousel' | 'testimonials.headingHintHelp' | 'testimonials.headingHintLabel' | 'testimonials.itemHintHelp' | 'testimonials.itemHintLabel' | 'timeline.headingHintHelp' | 'timeline.headingHintLabel' | 'timeline.itemHintHelp' | 'timeline.itemHintLabel' | 'timeline.step' | 'trust.applePay' | 'trust.itemHintHelp' | 'trust.itemHintLabel' | 'trust.mastercard' | 'trust.payments' | 'trust.paypal' | 'trust.scrollRegion' | 'trust.title' | 'trust.visa' | 'ui.breadcrumbLabel' | 'ui.cancel' | 'ui.clear' | 'ui.clearRecent' | 'ui.clearSearch' | 'ui.close' | 'ui.closeLightbox' | 'ui.closeSearch' | 'ui.currencyPickerLabel' | 'ui.decrease' | 'ui.dismissNotification' | 'ui.done' | 'ui.error' | 'ui.filterPanelApplied' | 'ui.filterPanelClearAll' | 'ui.filterPanelLabel' | 'ui.filterPanelMax' | 'ui.filterPanelMin' | 'ui.filterPanelNoneAvailable' | 'ui.filterPanelOrMore' | 'ui.filterPanelShowFewer' | 'ui.filterPanelShowProducts' | 'ui.filterPanelSizeGuide' | 'ui.filterPanelTitle' | 'ui.from' | 'ui.increase' | 'ui.learnMore' | 'ui.lightboxImages' | 'ui.loadMore' | 'ui.loading' | 'ui.loadingProduct' | 'ui.maximum' | 'ui.minimum' | 'ui.multiSelectPlaceholder' | 'ui.newBadge' | 'ui.next' | 'ui.nextImage' | 'ui.nextPage' | 'ui.noImage' | 'ui.noImageAvailable' | 'ui.noResults' | 'ui.noReviews' | 'ui.noneSelected' | 'ui.notifications' | 'ui.opensInNewTab' | 'ui.optional' | 'ui.pagination' | 'ui.pause' | 'ui.play' | 'ui.popularSearches' | 'ui.previous' | 'ui.previousImage' | 'ui.previousPage' | 'ui.quantity' | 'ui.quickAddLabel' | 'ui.recentSearches' | 'ui.regularPrice' | 'ui.required' | 'ui.salePrice' | 'ui.search' | 'ui.searchAdvice' | 'ui.searchCollections' | 'ui.searchEscHint' | 'ui.searchJournal' | 'ui.searchLoading' | 'ui.searchMoveHint' | 'ui.searchOpenHint' | 'ui.searchProducts' | 'ui.searchSuggestions' | 'ui.searchTheShop' | 'ui.selectPlaceholder' | 'ui.selected' | 'ui.shortcutHint' | 'ui.slideInstructions' | 'ui.slides' | 'ui.soldOut' | 'ui.stockIn' | 'ui.stockistSite' | 'ui.to' | 'ui.tryAgain' | 'ui.updatingPrice' | 'ui.updatingStock' | 'video.errorLink' | 'video.errorText' | 'video.errorTitle' | 'video.headingHintLabel' | 'video.introHintLabel' | 'video.minuteMany' | 'video.minuteOne' | 'video.play' | 'video.playWithDuration' | 'video.privacyNoteDefault' | 'video.secondMany' | 'video.secondOne' | 'video.urlHintHelp' | 'video.urlHintLabel' | 'wishlist.continueShopping' | 'wishlist.editorHintHelp' | 'wishlist.editorHintLabel' | 'wishlist.emptyText' | 'wishlist.emptyTitle' | 'wishlist.itemCountMany' | 'wishlist.itemCountOne' | 'wishlist.items' | 'wishlist.removed' | 'wishlist.removedNamed' | 'wishlist.saved' | 'wishlist.title' | 'wishlist.view';
|
|
435
|
+
type MessageKey = 'announcement.dismiss' | 'announcement.hintHelp' | 'announcement.hintLabel' | 'announcement.region' | 'article.authorHintHelp' | 'article.authorHintLabel' | 'article.bodyHintHelp' | 'article.bodyHintLabel' | 'article.byline' | 'article.coverHintHelp' | 'article.coverHintLabel' | 'article.dekHintLabel' | 'article.metaHintLabel' | 'article.richTextTableLabel' | 'article.titleHintLabel' | 'articleList.filterNav' | 'articleList.headingHintHelp' | 'articleList.headingHintLabel' | 'articleList.itemsHintHelp' | 'articleList.itemsHintLabel' | 'articleList.pages' | 'breadcrumbs.hintHelp' | 'breadcrumbs.hintLabel' | 'breadcrumbs.home' | 'cart.added' | 'cart.applied' | 'cart.apply' | 'cart.applyFailed' | 'cart.applyUnsupported' | 'cart.awayFromFree' | 'cart.checkout' | 'cart.columnProduct' | 'cart.columnQuantity' | 'cart.columnTotal' | 'cart.continueShopping' | 'cart.discount' | 'cart.discountCode' | 'cart.discountPlaceholder' | 'cart.drawerHintHelp' | 'cart.drawerHintHosted' | 'cart.drawerHintLabel' | 'cart.each' | 'cart.emptyFallbackTitle' | 'cart.freeUnlocked' | 'cart.invalidCode' | 'cart.itemCountMany' | 'cart.itemCountOne' | 'cart.items' | 'cart.lineTotal' | 'cart.loadFailed' | 'cart.paymentsAccepted' | 'cart.quantityFor' | 'cart.removeCode' | 'cart.removeItem' | 'cart.removeItemVariant' | 'cart.removed' | 'cart.shipping' | 'cart.shippingFree' | 'cart.shippingPending' | 'cart.subtotal' | 'cart.summary' | 'cart.title' | 'cart.total' | 'cart.tryAgain' | 'cart.undo' | 'cart.viewCart' | 'collection.countMany' | 'collection.countOne' | 'collection.readLess' | 'collection.readMore' | 'collection.subcategories' | 'collection.subcollections' | 'collection.titleHintHelp' | 'collection.titleHintLabel' | 'contact.addressLabel' | 'contact.detailsHintHelp' | 'contact.detailsHintLabel' | 'contact.emailFieldLabel' | 'contact.emailInvalidError' | 'contact.emailLabel' | 'contact.formTitleDefault' | 'contact.headingHintHelp' | 'contact.headingHintLabel' | 'contact.hoursLabel' | 'contact.introHintLabel' | 'contact.mapHintHelp' | 'contact.mapHintLabel' | 'contact.mapTitle' | 'contact.mapTitleWithAddress' | 'contact.messageLabel' | 'contact.messageRequiredError' | 'contact.nameLabel' | 'contact.nameRequiredError' | 'contact.orderNumberLabel' | 'contact.orderNumberPlaceholder' | 'contact.phoneLabel' | 'contact.replyTime' | 'contact.sendAnother' | 'contact.sendMessage' | 'contact.sending' | 'contact.serverError' | 'contact.serverErrorGeneric' | 'contact.successTextDefault' | 'contact.successTitle' | 'contact.summaryTitleMany' | 'contact.summaryTitleOne' | 'contact.topicLabel' | 'cta.buttonHintLabel' | 'cta.headingHintHelp' | 'cta.headingHintLabel' | 'cta.textHintLabel' | 'currency.cartNotSold' | 'currency.cartWillSwitch' | 'currency.checkoutWithout' | 'currency.label' | 'currency.movedTo' | 'currency.notIncludedMany' | 'currency.notIncludedOne' | 'currency.notSoldIn' | 'currency.notSoldInLong' | 'currency.shopIn' | 'editor.addLink' | 'error' | 'faq.headingHintLabel' | 'faq.introHintLabel' | 'faq.itemHintHelp' | 'faq.itemHintLabel' | 'faq.richTextTableLabel' | 'featureGrid.fallbackLabel' | 'featureGrid.headingHintLabel' | 'featureGrid.imageHintLabel' | 'featureGrid.itemHintHelp' | 'featureGrid.itemHintLabel' | 'footer.currencyLabel' | 'footer.descriptionHintLabel' | 'footer.emailError' | 'footer.emailInvalid' | 'footer.emailLabel' | 'footer.groupsHintHelp' | 'footer.groupsHintLabel' | 'footer.localeLabel' | 'footer.nav' | 'footer.newsletterAriaLabel' | 'footer.newsletterHintLabel' | 'footer.social.facebook' | 'footer.social.instagram' | 'footer.social.pinterest' | 'footer.social.tiktok' | 'footer.social.youtube' | 'footer.socialLinkName' | 'footer.subscribe' | 'footer.subscribed' | 'footer.subscribing' | 'footer.title' | 'form.formHintHelp' | 'form.formHintLabel' | 'form.headingHintLabel' | 'form.invalidEmail' | 'form.invalidForm' | 'form.invalidFormat' | 'form.invalidNumber' | 'form.invalidUrl' | 'form.loadFailed' | 'form.loading' | 'form.rateLimited' | 'form.required' | 'form.requiredCheckbox' | 'form.richTextTableLabel' | 'form.selectPlaceholder' | 'form.sendAnother' | 'form.submit' | 'form.submitting' | 'form.successTitle' | 'form.successTitlePending' | 'form.tooLarge' | 'form.tooLong' | 'form.tooShort' | 'form.turnstileFailed' | 'form.turnstileRequired' | 'form.unavailable' | 'form.unsupported' | 'gallery.carouselFallback' | 'gallery.headingHintHelp' | 'gallery.headingHintLabel' | 'gallery.imageHintLabel' | 'gallery.itemsHintHelp' | 'gallery.itemsHintLabel' | 'gallery.viewLarger' | 'gallery.viewer' | 'gallery.viewerHeading' | 'grid.activeFilters' | 'grid.availabilityInStock' | 'grid.availabilityOutOfStock' | 'grid.clearAll' | 'grid.clearFilters' | 'grid.columns' | 'grid.filter' | 'grid.filters' | 'grid.legendAvailability' | 'grid.legendCategory' | 'grid.legendCollection' | 'grid.legendColour' | 'grid.legendSize' | 'grid.nActive' | 'grid.nProducts' | 'grid.noCategoryHelp' | 'grid.noCategoryLabel' | 'grid.noCollectionHelp' | 'grid.noCollectionLabel' | 'grid.noResultsTitle' | 'grid.nothingIn' | 'grid.oneProduct' | 'grid.pagination' | 'grid.price' | 'grid.products' | 'grid.productsNoun' | 'grid.sectionLabel' | 'grid.sortBestSelling' | 'grid.sortBy' | 'grid.sortFeatured' | 'grid.sortNewest' | 'grid.sortPriceAsc' | 'grid.sortPriceDesc' | 'grid.updating' | 'header.cart' | 'header.cartEmpty' | 'header.cartMany' | 'header.cartOne' | 'header.menu' | 'header.openMenu' | 'header.primary' | 'header.search' | 'header.searchField' | 'header.viewAll' | 'header.viewAllOf' | 'header.wishlistEmpty' | 'header.wishlistMany' | 'header.wishlistOne' | 'hero.buttonHintLabel' | 'hero.carouselFallback' | 'hero.headingHintHelp' | 'hero.headingHintLabel' | 'hero.imageHintLabel' | 'hero.subheadingHintLabel' | 'imageBlock.captionHintLabel' | 'imageBlock.hintHelp' | 'imageBlock.hintLabel' | 'loading' | 'logoCloud.headingHintHelp' | 'logoCloud.headingHintLabel' | 'logoCloud.itemHintHelp' | 'logoCloud.itemHintLabel' | 'logoCloud.linkContext' | 'nav.menu' | 'nav.skipToContent' | 'newsletter.consentCheckboxLabel' | 'newsletter.consentRequired' | 'newsletter.emailLabel' | 'newsletter.emailPlaceholder' | 'newsletter.failed' | 'newsletter.headingHintLabel' | 'newsletter.invalidEmail' | 'newsletter.richTextTableLabel' | 'newsletter.subscribe' | 'newsletter.subscribing' | 'newsletter.successTitle' | 'newsletter.textHintLabel' | 'notFound.back' | 'notFound.body' | 'notFound.eyebrow' | 'notFound.title' | 'order.cardEnding' | 'order.carrierEta' | 'order.completed' | 'order.deliveryAddress' | 'order.detailsLabel' | 'order.estimated' | 'order.inProgress' | 'order.items' | 'order.needHelp' | 'order.notYet' | 'order.number' | 'order.payment' | 'order.placedMany' | 'order.placedOne' | 'order.progress' | 'order.qty' | 'order.shipping' | 'order.shippingFree' | 'order.showAllItems' | 'order.statusPrefix' | 'order.subtotal' | 'order.tax' | 'order.total' | 'order.trackOpens' | 'order.trackPackage' | 'order.trackingNumber' | 'pricing.headingHintLabel' | 'pricing.included' | 'pricing.includedIn' | 'pricing.introHintLabel' | 'pricing.mostPopular' | 'pricing.notIncluded' | 'pricing.planHintHelp' | 'pricing.planHintLabel' | 'product.addToCart' | 'product.backorder' | 'product.backorderNote' | 'product.backorderPending' | 'product.backorderShips' | 'product.hintHelp' | 'product.hintLabel' | 'product.imageIndex' | 'product.images' | 'product.inStock' | 'product.information' | 'product.lowStockMany' | 'product.lowStockManyIn' | 'product.lowStockOne' | 'product.lowStockOneIn' | 'product.notifyEmail' | 'product.notifyInvalid' | 'product.notifyMe' | 'product.notifySubmit' | 'product.notifySuccess' | 'product.notifyTitle' | 'product.notifyUnsupported' | 'product.quantity' | 'product.quickAdd' | 'product.quickAddMeta' | 'product.removeFromWishlist' | 'product.restockNote' | 'product.saleBadge' | 'product.saveToWishlist' | 'product.saving' | 'product.showImage' | 'product.sizeGuide' | 'product.soldOut' | 'product.soldOutIn' | 'product.tabsLabel' | 'product.taxNote' | 'product.viewer' | 'product.zoom' | 'productCarousel.carouselLabel' | 'productCarousel.clearHistory' | 'productCarousel.headingHintHelp' | 'productCarousel.headingHintLabel' | 'productCarousel.viewAllContext' | 'quote.headingFor' | 'quote.nameHintLabel' | 'quote.quoteHintHelp' | 'quote.quoteHintLabel' | 'richTextBlock.bodyHintHelp' | 'richTextBlock.bodyHintLabel' | 'richTextBlock.headingHintHelp' | 'richTextBlock.headingHintLabel' | 'richTextBlock.richTextTableLabel' | 'search.all' | 'search.customersLove' | 'search.didYouMean' | 'search.headingHintHelp' | 'search.headingHintLabel' | 'search.idleTitle' | 'search.noResultsAdvice' | 'search.noResultsTitle' | 'search.pageMany' | 'search.pageOne' | 'search.popularHintHelp' | 'search.popularHintLabel' | 'search.popularSearches' | 'search.productMany' | 'search.productOne' | 'search.resultMany' | 'search.resultOne' | 'search.resultTabs' | 'search.resultsHeading' | 'search.searchLabel' | 'search.searching' | 'search.storyMany' | 'search.storyOne' | 'search.title' | 'search.typeJournal' | 'search.typePages' | 'search.typeProducts' | 'search.viewAllJournal' | 'search.viewAllPages' | 'search.viewAllProducts' | 'splitContent.headingHintHelp' | 'splitContent.headingHintLabel' | 'splitContent.imageHintLabel' | 'splitContent.label' | 'splitContent.richTextTableLabel' | 'stats.headingHintLabel' | 'stats.introHintLabel' | 'stats.itemHintHelp' | 'stats.itemHintLabel' | 'storefront.businessOwnCurrency' | 'storefront.cartOutOfDate' | 'storefront.error' | 'storefront.loading' | 'storefront.mutationFailed' | 'storefront.notFound' | 'storefront.orderStatus.cancelled' | 'storefront.orderStatus.delayed' | 'storefront.orderStatus.delivered' | 'storefront.orderStatus.processing' | 'storefront.orderStatus.shipped' | 'storefront.orderSteps.delivered' | 'storefront.orderSteps.ordered' | 'storefront.orderSteps.packed' | 'storefront.orderSteps.shipped' | 'storefront.outOfStock' | 'storefront.unavailable' | 'storefront.unresolvedCollectionHelp' | 'storefront.unresolvedCollectionLabel' | 'storefront.updatingValues' | 'tabsBlock.headingHintLabel' | 'tabsBlock.introHintLabel' | 'tabsBlock.itemHintHelp' | 'tabsBlock.itemHintLabel' | 'tabsBlock.richTextTableLabel' | 'tabsBlock.tabPlaceholderLabel' | 'team.emailPerson' | 'team.headingHintHelp' | 'team.headingHintLabel' | 'team.itemHintHelp' | 'team.itemHintLabel' | 'team.onInstagram' | 'team.onPinterest' | 'team.onTiktok' | 'team.portraitOf' | 'team.website' | 'testimonials.carousel' | 'testimonials.headingHintHelp' | 'testimonials.headingHintLabel' | 'testimonials.itemHintHelp' | 'testimonials.itemHintLabel' | 'timeline.headingHintHelp' | 'timeline.headingHintLabel' | 'timeline.itemHintHelp' | 'timeline.itemHintLabel' | 'timeline.step' | 'trust.applePay' | 'trust.itemHintHelp' | 'trust.itemHintLabel' | 'trust.mastercard' | 'trust.payments' | 'trust.paypal' | 'trust.scrollRegion' | 'trust.title' | 'trust.visa' | 'ui.breadcrumbLabel' | 'ui.cancel' | 'ui.clear' | 'ui.clearRecent' | 'ui.clearSearch' | 'ui.close' | 'ui.closeLightbox' | 'ui.closeSearch' | 'ui.currencyPickerLabel' | 'ui.decrease' | 'ui.dismissNotification' | 'ui.done' | 'ui.error' | 'ui.filterPanelApplied' | 'ui.filterPanelClearAll' | 'ui.filterPanelLabel' | 'ui.filterPanelMax' | 'ui.filterPanelMin' | 'ui.filterPanelNoneAvailable' | 'ui.filterPanelOrMore' | 'ui.filterPanelShowFewer' | 'ui.filterPanelShowProducts' | 'ui.filterPanelSizeGuide' | 'ui.filterPanelTitle' | 'ui.from' | 'ui.increase' | 'ui.learnMore' | 'ui.lightboxImages' | 'ui.loadMore' | 'ui.loading' | 'ui.loadingProduct' | 'ui.maximum' | 'ui.minimum' | 'ui.multiSelectPlaceholder' | 'ui.newBadge' | 'ui.next' | 'ui.nextImage' | 'ui.nextPage' | 'ui.noImage' | 'ui.noImageAvailable' | 'ui.noResults' | 'ui.noReviews' | 'ui.noneSelected' | 'ui.notifications' | 'ui.opensInNewTab' | 'ui.optional' | 'ui.pagination' | 'ui.pause' | 'ui.play' | 'ui.popularSearches' | 'ui.previous' | 'ui.previousImage' | 'ui.previousPage' | 'ui.quantity' | 'ui.quickAddLabel' | 'ui.recentSearches' | 'ui.regularPrice' | 'ui.required' | 'ui.salePrice' | 'ui.search' | 'ui.searchAdvice' | 'ui.searchCollections' | 'ui.searchEscHint' | 'ui.searchJournal' | 'ui.searchLoading' | 'ui.searchMoveHint' | 'ui.searchOpenHint' | 'ui.searchProducts' | 'ui.searchSuggestions' | 'ui.searchTheShop' | 'ui.selectPlaceholder' | 'ui.selected' | 'ui.shortcutHint' | 'ui.slideInstructions' | 'ui.slides' | 'ui.soldOut' | 'ui.stockIn' | 'ui.stockistSite' | 'ui.to' | 'ui.tryAgain' | 'ui.updatingPrice' | 'ui.updatingStock' | 'video.errorLink' | 'video.errorText' | 'video.errorTitle' | 'video.headingHintLabel' | 'video.introHintLabel' | 'video.minuteMany' | 'video.minuteOne' | 'video.play' | 'video.playWithDuration' | 'video.privacyNoteDefault' | 'video.secondMany' | 'video.secondOne' | 'video.urlHintHelp' | 'video.urlHintLabel' | 'wishlist.continueShopping' | 'wishlist.editorHintHelp' | 'wishlist.editorHintLabel' | 'wishlist.emptyText' | 'wishlist.emptyTitle' | 'wishlist.itemCountMany' | 'wishlist.itemCountOne' | 'wishlist.items' | 'wishlist.removed' | 'wishlist.removedNamed' | 'wishlist.saved' | 'wishlist.title' | 'wishlist.view';
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
export {};
|
|
@@ -8643,6 +8643,7 @@
|
|
|
8643
8643
|
"storefront.outOfStock": "This item is out of stock.",
|
|
8644
8644
|
"storefront.unavailable": "This item is no longer available.",
|
|
8645
8645
|
"storefront.cartOutOfDate": "Your cart is out of date. Reload the page and try again.",
|
|
8646
|
+
"storefront.businessOwnCurrency": "Business customers shop in ISK.",
|
|
8646
8647
|
"storefront.unresolvedCollectionLabel": "Publish to load products",
|
|
8647
8648
|
"storefront.unresolvedCollectionHelp": "The collection is picked. Its products appear here once this page is published.",
|
|
8648
8649
|
"storefront.orderStatus.processing": "Processing",
|
|
@@ -9204,6 +9205,7 @@
|
|
|
9204
9205
|
"storefront.outOfStock": "Þessi vara er ekki til á lager.",
|
|
9205
9206
|
"storefront.unavailable": "Þessi vara er ekki lengur í boði.",
|
|
9206
9207
|
"storefront.cartOutOfDate": "Karfan þín er ekki uppfærð. Endurnýjaðu síðuna og prófaðu aftur.",
|
|
9208
|
+
"storefront.businessOwnCurrency": "Fyrirtæki versla í krónum.",
|
|
9207
9209
|
"storefront.unresolvedCollectionLabel": "Birtu síðuna til að hlaða vörum",
|
|
9208
9210
|
"storefront.unresolvedCollectionHelp": "Vörulistinn er valinn. Vörurnar úr honum birtast hér þegar síðan hefur verið birt.",
|
|
9209
9211
|
"storefront.orderStatus.processing": "Í vinnslu",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"article": "46689140a4cc1e04b70bfa1c69fc8ac2ae8e5b0ce669e7a2c23157bb2ac79876",
|
|
4
4
|
"article-list": "c99dbf56425ed57161d348b28f67a23dcb609d9cf9b602da2995baea584070d6",
|
|
5
5
|
"breadcrumbs": "db7e456eec13ac6e6688fcd67b12cec63ffd876defdebd3085f28fdb5d8d6206",
|
|
6
|
-
"cart": "
|
|
6
|
+
"cart": "ce507a5b1961646df5292f308a287732d13205ac9e32afddfc7d10fb4369cd98",
|
|
7
7
|
"collection-grid": "9c4603f5de2891b3f066c0532bbb480003f7eb2ee1834475e2bd2097f149d57d",
|
|
8
8
|
"collection-header": "e0f8c97068a4cfd20585d7c055244a1e078f52d9a6eef59373b09dfde7337bdc",
|
|
9
9
|
"contact": "c8e558e99456095a7b3a0eb6baa06aa4ba2d246839bae123d769c88b8958ada8",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"order-status": "1a7b4d108117fe7c67789adf9b55796364c16ab9c8f5ab652ac40d6c49d6f80e",
|
|
22
22
|
"pricing-table": "43b16d3abea292d7878a2a2f86dc35a6a069d9fb934bdb601305ee9731afe020",
|
|
23
23
|
"product-carousel": "70cc990a853c3ac33394e26cf071966ce2ce2c58e7254b5650f83c25b1402fa2",
|
|
24
|
-
"product-detail": "
|
|
24
|
+
"product-detail": "3979ef86314e70d970befe738f1792888b2919055801539d5506f5f3f874de86",
|
|
25
25
|
"quote": "d771f4097ca14d70320c90fd88c54d980a996c1fe43a4448ab10f89c2bfe6d3d",
|
|
26
26
|
"rich-text": "6062e831392f12e805968882a0edbfde00dfd1296d00395a3e9a27492a242118",
|
|
27
27
|
"search": "30c9627f44da0c88f289d63de62e639ed7553cea079dac5cbe5010acf058229a",
|
|
@@ -26,17 +26,21 @@ export function toStorefrontCommerce(value: unknown): StorefrontCommerce | null
|
|
|
26
26
|
// report.
|
|
27
27
|
if (value === null || value === undefined || value === '') return null;
|
|
28
28
|
if (typeof value !== 'object') return discard(value, 'commerce is not an object');
|
|
29
|
-
const { currency, taxInclusivePricing, defaultTaxRate, currencies } =
|
|
30
|
-
string,
|
|
31
|
-
unknown
|
|
32
|
-
>;
|
|
29
|
+
const { currency, taxInclusivePricing, defaultTaxRate, currencies, defaultCurrency } =
|
|
30
|
+
value as Record<string, unknown>;
|
|
33
31
|
if (typeof currency !== 'string' || currency === '') return discard(value, 'currency');
|
|
34
32
|
if (typeof taxInclusivePricing !== 'boolean') return discard(value, 'taxInclusivePricing');
|
|
35
33
|
if (typeof defaultTaxRate !== 'number') return discard(value, 'defaultTaxRate');
|
|
36
|
-
//
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
// Both were cleaned at build (`@eldrajs/theme-nuxt`); here they are only checked for type.
|
|
35
|
+
return {
|
|
36
|
+
currency,
|
|
37
|
+
taxInclusivePricing,
|
|
38
|
+
defaultTaxRate,
|
|
39
|
+
...(Array.isArray(currencies) && currencies.every((code) => typeof code === 'string')
|
|
40
|
+
? { currencies: currencies as string[] }
|
|
41
|
+
: {}),
|
|
42
|
+
...(typeof defaultCurrency === 'string' && defaultCurrency !== '' ? { defaultCurrency } : {}),
|
|
43
|
+
};
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
/**
|
|
@@ -4,13 +4,15 @@ import { resolveVisitorCurrency, VISITOR_COUNTRY_PATH } from '@eldrajs/theme-cor
|
|
|
4
4
|
import type { CartStore } from './cart';
|
|
5
5
|
import type { StorefrontFailure } from './feedback';
|
|
6
6
|
|
|
7
|
-
/** The visitor's currency, derived: the cart's, else the preference, else
|
|
7
|
+
/** The visitor's currency, derived: the cart's, else the preference, else the default (docs/starter-kit.md, "Currencies"). */
|
|
8
8
|
export interface CurrencyStore {
|
|
9
|
-
/** The store's own currency, or `undefined` when it publishes none. */
|
|
9
|
+
/** The store's own currency, or `undefined` when it publishes none. Offered or not, every product has a price in it. */
|
|
10
10
|
base: string | undefined;
|
|
11
|
-
/** What
|
|
11
|
+
/** What pages are built in and a visitor starts in: `base` unless the store turned it off. */
|
|
12
|
+
defaultCurrency: string | undefined;
|
|
13
|
+
/** What the visitor may pick from, `defaultCurrency` first. One entry or none: no picker. */
|
|
12
14
|
offered: Ref<readonly string[]>;
|
|
13
|
-
/** The currency the site shows: `
|
|
15
|
+
/** The currency the site shows: `defaultCurrency` until `start` settles, then the cart's, the preference's or the default. */
|
|
14
16
|
active: ComputedRef<string | undefined>;
|
|
15
17
|
/** `start` has settled. */
|
|
16
18
|
started: Ref<boolean>;
|
|
@@ -18,15 +20,20 @@ export interface CurrencyStore {
|
|
|
18
20
|
pending: ComputedRef<boolean>;
|
|
19
21
|
/** A move of the cart is in flight or queued. */
|
|
20
22
|
busy: ComputedRef<boolean>;
|
|
21
|
-
/** The currency catalog reads ask for, or `undefined` to read in `base
|
|
23
|
+
/** The currency catalog reads ask for, or `undefined` to read in `base`, as a read naming none does. */
|
|
22
24
|
requested: ComputedRef<string | undefined>;
|
|
25
|
+
/** A business customer, whose cart the store keeps in `base` even while it is not offered: no picker, no move. */
|
|
26
|
+
ownCurrencyOnly: Ref<boolean>;
|
|
23
27
|
/** Set when the visitor was moved off a currency, for a one-time notice. */
|
|
24
28
|
movedTo: Ref<string | null>;
|
|
25
29
|
/** A cart move that failed for another reason than the currency, for an error toast. */
|
|
26
30
|
failure: Ref<StorefrontFailure | null>;
|
|
27
31
|
/** The visitor's explicit choice. With a cart it moves the cart, last choice wins. */
|
|
28
32
|
choose(code: string): void;
|
|
33
|
+
/** Chooses `defaultCurrency`; named for when the default was always the store's own. */
|
|
29
34
|
chooseBase(): void;
|
|
35
|
+
/** For a theme with business sign-in, on every page load while signed in: keeps them in `base` and moves a cart there; `false` on sign-out. */
|
|
36
|
+
keepOwnCurrency(on?: boolean): void;
|
|
30
37
|
/** Stops following other tabs; for a store made for one component (a demo, a story), not the app's. */
|
|
31
38
|
dispose(): void;
|
|
32
39
|
/** Reads the stored preference, else the visitor's country. Call once, after mount. */
|
|
@@ -34,6 +41,7 @@ export interface CurrencyStore {
|
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
export const CURRENCY_NOT_SOLD = 'CART_CURRENCY_NOT_SOLD';
|
|
44
|
+
export const CUSTOMER_ISK_ONLY = 'CART_CURRENCY_CUSTOMER_ISK_ONLY';
|
|
37
45
|
const CURRENCY_PREFERENCE_KEY = 'eldra.currency';
|
|
38
46
|
|
|
39
47
|
function refusedForCurrency(failure: StorefrontFailure | null): boolean {
|
|
@@ -42,42 +50,61 @@ function refusedForCurrency(failure: StorefrontFailure | null): boolean {
|
|
|
42
50
|
|
|
43
51
|
/** Builds the store over `cart`; the returned cart's `add` retries once when its currency is refused. */
|
|
44
52
|
export function createCurrencyStore(
|
|
45
|
-
commerce: { currency: string; currencies?: readonly string[] } | null,
|
|
53
|
+
commerce: { currency: string; currencies?: readonly string[]; defaultCurrency?: string } | null,
|
|
46
54
|
cart: CartStore,
|
|
47
55
|
preference: EldraCurrencyPreference = createCurrencyPreference()
|
|
48
56
|
): { currency: CurrencyStore; cart: CartStore } {
|
|
49
57
|
const base = commerce?.currency;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
const defaultCurrency = commerce?.defaultCurrency ?? base;
|
|
59
|
+
const listed: readonly string[] =
|
|
60
|
+
defaultCurrency === undefined ? [] : (commerce?.currencies ?? [defaultCurrency]);
|
|
61
|
+
const offered = ref<readonly string[]>(listed);
|
|
53
62
|
const preferred = ref<string | null>(null);
|
|
54
63
|
const started = ref(false);
|
|
55
64
|
const movedTo = ref<string | null>(null);
|
|
56
65
|
const failure = ref<StorefrontFailure | null>(null);
|
|
66
|
+
const ownCurrencyOnly = ref(false);
|
|
67
|
+
let signInChanges = 0;
|
|
68
|
+
const fallback = (): string | undefined => (ownCurrencyOnly.value ? base : defaultCurrency);
|
|
57
69
|
|
|
58
70
|
const active = computed(() => {
|
|
59
|
-
if (!started.value) return
|
|
71
|
+
if (!started.value) return defaultCurrency;
|
|
60
72
|
const own = cart.currency.value;
|
|
61
73
|
if (own !== undefined) return own;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
: base;
|
|
74
|
+
if (preferred.value !== null && offered.value.includes(preferred.value)) return preferred.value;
|
|
75
|
+
return fallback();
|
|
65
76
|
});
|
|
66
77
|
const requested = computed(() => (active.value === base ? undefined : active.value));
|
|
67
78
|
const pending = computed(() => !started.value && offered.value.length > 1);
|
|
68
79
|
|
|
69
80
|
function withdraw(code: string): void {
|
|
70
|
-
if (code ===
|
|
81
|
+
if (code === defaultCurrency) return;
|
|
71
82
|
offered.value = offered.value.filter((offer) => offer !== code);
|
|
72
83
|
if (preference.read() === code) preference.forget();
|
|
73
84
|
if (preferred.value === code) preferred.value = null;
|
|
74
85
|
}
|
|
75
86
|
|
|
87
|
+
async function keepInBase(): Promise<void> {
|
|
88
|
+
if (base === undefined) return;
|
|
89
|
+
ownCurrencyOnly.value = true;
|
|
90
|
+
offered.value = [base];
|
|
91
|
+
const own = cart.currency.value;
|
|
92
|
+
if (own !== undefined && own !== base) await move(base, true);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function leaveBase(): void {
|
|
96
|
+
ownCurrencyOnly.value = false;
|
|
97
|
+
offered.value = listed;
|
|
98
|
+
}
|
|
99
|
+
|
|
76
100
|
// Moves go through the cart's own write queue, where a newer choice replaces a waiting one.
|
|
77
101
|
const busy = computed(() => cart.pending.value);
|
|
78
102
|
|
|
79
103
|
async function move(code: string, notice = false): Promise<void> {
|
|
104
|
+
const sentAs = signInChanges;
|
|
80
105
|
const answer = await cart.setCurrency(code);
|
|
106
|
+
// An answer about who the visitor was before they signed in or out says nothing about who they are now.
|
|
107
|
+
const sameVisitor = sentAs === signInChanges;
|
|
81
108
|
// A later choice replaced this one before it was sent.
|
|
82
109
|
if (answer === undefined) return;
|
|
83
110
|
if (answer === null) {
|
|
@@ -87,9 +114,18 @@ export function createCurrencyStore(
|
|
|
87
114
|
preference.remember(code);
|
|
88
115
|
} else if (cart.currency.value === code) {
|
|
89
116
|
preferred.value = code;
|
|
90
|
-
|
|
117
|
+
// A business customer's ISK is the store's rule, not a choice to keep for whoever comes next.
|
|
118
|
+
if (!ownCurrencyOnly.value) preference.remember(code);
|
|
91
119
|
if (notice) movedTo.value = code;
|
|
92
120
|
}
|
|
121
|
+
} else if (answer.errorId === CUSTOMER_ISK_ONLY) {
|
|
122
|
+
// The store's own move off a dropped currency is no choice of the visitor's, so nothing to report.
|
|
123
|
+
if (!notice) failure.value = answer;
|
|
124
|
+
if (sameVisitor) await keepInBase();
|
|
125
|
+
} else if (ownCurrencyOnly.value && code === base && refusedForCurrency(answer)) {
|
|
126
|
+
// The store sees no business customer after all (signed out, or no token on the cart): back to what it offers.
|
|
127
|
+
leaveBase();
|
|
128
|
+
if (!notice) failure.value = answer;
|
|
93
129
|
} else {
|
|
94
130
|
if (refusedForCurrency(answer)) withdraw(code);
|
|
95
131
|
failure.value = answer;
|
|
@@ -102,14 +138,15 @@ export function createCurrencyStore(
|
|
|
102
138
|
|
|
103
139
|
const leavingDropped = (): boolean => {
|
|
104
140
|
const own = cart.currency.value;
|
|
105
|
-
return own !== undefined &&
|
|
141
|
+
return own !== undefined && defaultCurrency !== undefined && !offered.value.includes(own);
|
|
106
142
|
};
|
|
107
143
|
|
|
108
|
-
// A cart in a currency this build no longer offers is moved to the
|
|
144
|
+
// A cart in a currency this build no longer offers is moved to the default; the watch fires on a change only, so a failed move is not retried in a loop.
|
|
109
145
|
watch([started, cart.currency], ([isStarted, own]) => {
|
|
110
|
-
|
|
146
|
+
const to = fallback();
|
|
147
|
+
if (!isStarted || own === undefined || to === undefined) return;
|
|
111
148
|
if (offered.value.includes(own)) return;
|
|
112
|
-
void move(
|
|
149
|
+
void move(to, true);
|
|
113
150
|
});
|
|
114
151
|
|
|
115
152
|
const onStorage = (event: StorageEvent): void => {
|
|
@@ -122,6 +159,7 @@ export function createCurrencyStore(
|
|
|
122
159
|
|
|
123
160
|
const currency: CurrencyStore = {
|
|
124
161
|
base,
|
|
162
|
+
defaultCurrency,
|
|
125
163
|
offered,
|
|
126
164
|
active,
|
|
127
165
|
started,
|
|
@@ -130,6 +168,19 @@ export function createCurrencyStore(
|
|
|
130
168
|
requested,
|
|
131
169
|
movedTo,
|
|
132
170
|
failure,
|
|
171
|
+
ownCurrencyOnly,
|
|
172
|
+
keepOwnCurrency(on = true) {
|
|
173
|
+
signInChanges += 1;
|
|
174
|
+
if (on) {
|
|
175
|
+
void keepInBase();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
leaveBase();
|
|
179
|
+
const own = cart.currency.value;
|
|
180
|
+
if (own !== undefined && defaultCurrency !== undefined && !offered.value.includes(own)) {
|
|
181
|
+
void move(defaultCurrency, true);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
133
184
|
choose(code) {
|
|
134
185
|
if (!offered.value.includes(code)) return;
|
|
135
186
|
// Only with no cart and nothing in flight is a choice just a preference; else it queues behind that work.
|
|
@@ -144,12 +195,16 @@ export function createCurrencyStore(
|
|
|
144
195
|
if (listens) window.removeEventListener('storage', onStorage);
|
|
145
196
|
},
|
|
146
197
|
chooseBase() {
|
|
147
|
-
if (
|
|
198
|
+
if (defaultCurrency !== undefined) currency.choose(defaultCurrency);
|
|
148
199
|
},
|
|
149
200
|
async start(country) {
|
|
150
201
|
let forgotten = false;
|
|
151
|
-
|
|
152
|
-
|
|
202
|
+
const stored = defaultCurrency === undefined ? null : preference.read();
|
|
203
|
+
// With one currency there is no picker and nothing on screen moves, so a stale choice goes quietly.
|
|
204
|
+
const quietlyStale =
|
|
205
|
+
stored !== null && stored !== defaultCurrency && offered.value.length === 1;
|
|
206
|
+
if (quietlyStale && defaultCurrency !== base) preference.forget();
|
|
207
|
+
if (defaultCurrency !== undefined && offered.value.length > 1) {
|
|
153
208
|
if (stored !== null && offered.value.includes(stored)) {
|
|
154
209
|
if (preferred.value === null) preferred.value = stored;
|
|
155
210
|
} else {
|
|
@@ -159,16 +214,17 @@ export function createCurrencyStore(
|
|
|
159
214
|
// A choice made during the lookup, or a cart, wins over the country.
|
|
160
215
|
if (cart.currency.value === undefined && preferred.value === null) {
|
|
161
216
|
const fromCountry = resolveVisitorCurrency({
|
|
162
|
-
base,
|
|
217
|
+
base: defaultCurrency,
|
|
163
218
|
offered: offered.value,
|
|
164
219
|
country: visitorCountry,
|
|
165
220
|
});
|
|
166
|
-
if (fromCountry !==
|
|
221
|
+
if (fromCountry !== defaultCurrency) preferred.value = fromCountry;
|
|
167
222
|
}
|
|
168
223
|
}
|
|
169
224
|
}
|
|
170
225
|
started.value = true;
|
|
171
|
-
|
|
226
|
+
// A cart in a dropped currency is about to move; the move says where prices are.
|
|
227
|
+
if (forgotten && !leavingDropped()) movedTo.value = active.value ?? null;
|
|
172
228
|
},
|
|
173
229
|
};
|
|
174
230
|
|
|
@@ -176,12 +232,23 @@ export function createCurrencyStore(
|
|
|
176
232
|
...cart,
|
|
177
233
|
async add(input) {
|
|
178
234
|
// The visitor's next cart action tries again to leave a currency the store no longer offers.
|
|
179
|
-
|
|
235
|
+
const to = fallback();
|
|
236
|
+
if (leavingDropped() && to !== undefined) await move(to, true);
|
|
180
237
|
const hadCart = cart.currency.value !== undefined;
|
|
181
238
|
const sentIn = active.value;
|
|
239
|
+
const sentAs = signInChanges;
|
|
182
240
|
const answer = await cart.add(input);
|
|
241
|
+
if (answer?.errorId === CUSTOMER_ISK_ONLY && sentIn !== base && sentAs === signInChanges) {
|
|
242
|
+
await keepInBase();
|
|
243
|
+
return cart.add(input);
|
|
244
|
+
}
|
|
183
245
|
// The store checks the currency only when the add creates the cart.
|
|
184
|
-
if (
|
|
246
|
+
if (
|
|
247
|
+
hadCart ||
|
|
248
|
+
!refusedForCurrency(answer) ||
|
|
249
|
+
sentIn === undefined ||
|
|
250
|
+
sentIn === defaultCurrency
|
|
251
|
+
) {
|
|
185
252
|
return answer;
|
|
186
253
|
}
|
|
187
254
|
withdraw(sentIn);
|
|
@@ -75,6 +75,7 @@ const MESSAGE_BY_ERROR_ID: Record<string, MessageKey> = {
|
|
|
75
75
|
// store has moved on from, and reloading is the one thing that fixes it.
|
|
76
76
|
CART_NOT_FOUND: 'storefront.cartOutOfDate',
|
|
77
77
|
CART_ITEM_NOT_FOUND: 'storefront.cartOutOfDate',
|
|
78
|
+
CART_CURRENCY_CUSTOMER_ISK_ONLY: 'storefront.businessOwnCurrency',
|
|
78
79
|
// Refused in the browser: the cart could not be read, so nothing was sent.
|
|
79
80
|
CART_NOT_LOADED: 'cart.loadFailed',
|
|
80
81
|
};
|
|
@@ -107,3 +107,44 @@ describe('a cart with a line not sold in its currency', () => {
|
|
|
107
107
|
expect(checkout?.attributes('href')).toBe('/checkout/demo-cart');
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
|
+
|
|
111
|
+
describe('the way out with the store currency turned off (WS-1399)', () => {
|
|
112
|
+
async function mountIn(cartCurrency: string) {
|
|
113
|
+
const storefront = createDemoStorefront({
|
|
114
|
+
cartLines: [NOT_SOLD, SOLD],
|
|
115
|
+
commerce: {
|
|
116
|
+
currency: 'USD',
|
|
117
|
+
taxInclusivePricing: false,
|
|
118
|
+
defaultTaxRate: 0,
|
|
119
|
+
currencies: ['EUR', 'GBP'],
|
|
120
|
+
defaultCurrency: 'EUR',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
await flushPromises();
|
|
124
|
+
storefront.cart.currency.value = cartCurrency;
|
|
125
|
+
const options = mountOptions({ entry: { id: 'cart', data: { ...mock, variant: 'page' } } });
|
|
126
|
+
const wrapper = mount(Block, {
|
|
127
|
+
...options,
|
|
128
|
+
attachTo: document.body,
|
|
129
|
+
global: {
|
|
130
|
+
...options.global,
|
|
131
|
+
provide: { ...options.global.provide, [STOREFRONT_KEY]: storefront },
|
|
132
|
+
stubs: { ...options.global.stubs, transition: false, 'transition-group': false },
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
await flushPromises();
|
|
136
|
+
return wrapper
|
|
137
|
+
.get('[data-eldra-not-sold-notice]')
|
|
138
|
+
.findAll('button')
|
|
139
|
+
.map((node) => node.text());
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
it('offers the default currency from another one', async () => {
|
|
143
|
+
expect(await mountIn('GBP')).toContain('Shop in EUR');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('offers no way out from the default itself', async () => {
|
|
147
|
+
const buttons = await mountIn('EUR');
|
|
148
|
+
expect(buttons).toEqual(['Remove and check out']);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
2
3
|
import { Button, Notice } from '@eldrajs/ui';
|
|
3
4
|
import { useI18n } from 'vue-i18n';
|
|
4
5
|
import { useStorefront } from '../../../app/composables/useStorefront';
|
|
@@ -11,6 +12,10 @@ const cart = storefront.cart;
|
|
|
11
12
|
const feedback = useStorefrontFeedback();
|
|
12
13
|
const { t } = useI18n();
|
|
13
14
|
const sentence = useNotSoldSentence(cart);
|
|
15
|
+
const shopInDefault = computed(() => {
|
|
16
|
+
const fallback = storefront.currency.defaultCurrency;
|
|
17
|
+
return fallback !== undefined && cart.currency.value !== fallback;
|
|
18
|
+
});
|
|
14
19
|
|
|
15
20
|
let leaving = false;
|
|
16
21
|
|
|
@@ -56,13 +61,13 @@ async function removeThenCheckout(): Promise<void> {
|
|
|
56
61
|
{{ t('currency.checkoutWithout') }}
|
|
57
62
|
</Button>
|
|
58
63
|
<Button
|
|
59
|
-
v-if="
|
|
64
|
+
v-if="shopInDefault"
|
|
60
65
|
variant="outline"
|
|
61
66
|
size="sm"
|
|
62
67
|
type="button"
|
|
63
68
|
@click="storefront.currency.chooseBase()"
|
|
64
69
|
>
|
|
65
|
-
{{ t('currency.shopIn', { currency: storefront.currency.
|
|
70
|
+
{{ t('currency.shopIn', { currency: storefront.currency.defaultCurrency }) }}
|
|
66
71
|
</Button>
|
|
67
72
|
</template>
|
|
68
73
|
</Notice>
|
|
@@ -263,11 +263,30 @@ const formattedPrice = computed(() =>
|
|
|
263
263
|
: money.format(product.value.price.amount, product.value.price.currency)
|
|
264
264
|
);
|
|
265
265
|
|
|
266
|
-
/** No price in the visitor's currency: shown, but not for sale until they shop in the
|
|
266
|
+
/** No price in the visitor's currency: shown, but not for sale until they shop in the default. */
|
|
267
267
|
const notSold = computed(() => product.value?.price.soldInCurrency === false);
|
|
268
268
|
const shopperCurrency = computed(() => storefront.currency.active.value ?? '');
|
|
269
|
-
const
|
|
270
|
-
const
|
|
269
|
+
const defaultCurrency = computed(() => storefront.currency.defaultCurrency ?? '');
|
|
270
|
+
const inDefault = computed(() => shopperCurrency.value === defaultCurrency.value);
|
|
271
|
+
// A read that failed keeps the last currency's answer on screen; only one made in this currency can say it is sold nowhere.
|
|
272
|
+
const readIn = ref(shopperCurrency.value);
|
|
273
|
+
watch(
|
|
274
|
+
() => productResult.data.value,
|
|
275
|
+
() => {
|
|
276
|
+
readIn.value = shopperCurrency.value;
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
// Every product has a price in the store's own currency, so only a default that is not it can lack one for real.
|
|
280
|
+
const notSoldAnywhere = computed(
|
|
281
|
+
() =>
|
|
282
|
+
notSold.value &&
|
|
283
|
+
inDefault.value &&
|
|
284
|
+
readIn.value === shopperCurrency.value &&
|
|
285
|
+
defaultCurrency.value !== storefront.currency.base
|
|
286
|
+
);
|
|
287
|
+
const cartWillSwitch = computed(
|
|
288
|
+
() => notSold.value && !notSoldAnywhere.value && storefront.cart.lines.value.length > 0
|
|
289
|
+
);
|
|
271
290
|
|
|
272
291
|
/** Spec States, Sale row: 'The saving badge ("Save $32") is calculated from the two prices, never
|
|
273
292
|
* typed in.' Only a real sale counts — a `compareAt` at or below the current price is ignored, the
|
|
@@ -427,7 +446,8 @@ const cartBusy = computed(
|
|
|
427
446
|
);
|
|
428
447
|
|
|
429
448
|
const addToCartLabel = computed(() => {
|
|
430
|
-
if (
|
|
449
|
+
if (notSoldAnywhere.value) return t('currency.notSoldIn', { currency: defaultCurrency.value });
|
|
450
|
+
if (notSold.value) return t('currency.shopIn', { currency: defaultCurrency.value });
|
|
431
451
|
if (soldOut.value) return t('product.notifyMe');
|
|
432
452
|
if (isBackorder.value) return t('product.backorder');
|
|
433
453
|
return t('product.addToCart', { price: formattedPrice.value });
|
|
@@ -514,8 +534,9 @@ watch(
|
|
|
514
534
|
*/
|
|
515
535
|
async function primaryAction(): Promise<void> {
|
|
516
536
|
if (notSold.value) {
|
|
517
|
-
|
|
518
|
-
|
|
537
|
+
if (notSoldAnywhere.value) return;
|
|
538
|
+
// Already in the default (its product read failed): read the product again.
|
|
539
|
+
if (inDefault.value) void productResult.refresh();
|
|
519
540
|
else storefront.currency.chooseBase();
|
|
520
541
|
return;
|
|
521
542
|
}
|
|
@@ -780,6 +801,7 @@ function tabValue(index: number): string {
|
|
|
780
801
|
size="lg"
|
|
781
802
|
block
|
|
782
803
|
:loading="cartBusy"
|
|
804
|
+
:disabled="notSoldAnywhere"
|
|
783
805
|
:label="addToCartLabel"
|
|
784
806
|
>
|
|
785
807
|
<template v-if="soldOut" #leadingIcon>
|
|
@@ -804,7 +826,7 @@ function tabValue(index: number): string {
|
|
|
804
826
|
</Button>
|
|
805
827
|
</div>
|
|
806
828
|
<p v-if="cartWillSwitch" class="text-muted text-body-sm -mt-2">
|
|
807
|
-
{{ t('currency.cartWillSwitch', { currency:
|
|
829
|
+
{{ t('currency.cartWillSwitch', { currency: defaultCurrency }) }}
|
|
808
830
|
</p>
|
|
809
831
|
</form>
|
|
810
832
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { flushPromises, mount } from '@vue/test-utils';
|
|
3
|
-
import { computed, defineComponent, h, nextTick, ref } from 'vue';
|
|
3
|
+
import { computed, defineComponent, h, nextTick, ref, watch } from 'vue';
|
|
4
4
|
import { ELDRA_KEY, type EldraLocaleState } from '@eldrajs/theme-vue';
|
|
5
5
|
import { EldraHttpError } from '@eldrajs/sdk';
|
|
6
6
|
import { useToast, type ToastAction } from '@eldrajs/ui';
|
|
@@ -1567,3 +1567,114 @@ describe('product-detail block', () => {
|
|
|
1567
1567
|
});
|
|
1568
1568
|
});
|
|
1569
1569
|
});
|
|
1570
|
+
|
|
1571
|
+
describe('with the store currency turned off (WS-1399)', () => {
|
|
1572
|
+
function storefrontOffering(patch: Partial<StorefrontProduct>) {
|
|
1573
|
+
const source = createDemoStorefront({
|
|
1574
|
+
commerce: {
|
|
1575
|
+
currency: 'USD',
|
|
1576
|
+
taxInclusivePricing: false,
|
|
1577
|
+
defaultTaxRate: 0,
|
|
1578
|
+
currencies: ['EUR', 'GBP'],
|
|
1579
|
+
defaultCurrency: 'EUR',
|
|
1580
|
+
},
|
|
1581
|
+
});
|
|
1582
|
+
return {
|
|
1583
|
+
...source,
|
|
1584
|
+
catalog: {
|
|
1585
|
+
...source.catalog,
|
|
1586
|
+
product: (handle: Parameters<typeof source.catalog.product>[0]) => {
|
|
1587
|
+
const result = source.catalog.product(handle);
|
|
1588
|
+
return {
|
|
1589
|
+
...result,
|
|
1590
|
+
data: computed(() => (result.data.value ? { ...result.data.value, ...patch } : null)),
|
|
1591
|
+
};
|
|
1592
|
+
},
|
|
1593
|
+
},
|
|
1594
|
+
} as ReturnType<typeof storefrontWith>;
|
|
1595
|
+
}
|
|
1596
|
+
const notSoldPrice = { amount: 96, compareAt: null, currency: 'USD', soldInCurrency: false };
|
|
1597
|
+
|
|
1598
|
+
it('offers the default currency, not the store currency, as the way out', async () => {
|
|
1599
|
+
const storefront = storefrontOffering({ price: notSoldPrice });
|
|
1600
|
+
storefront.currency.started.value = true;
|
|
1601
|
+
storefront.currency.choose('GBP');
|
|
1602
|
+
await vi.waitFor(() => expect(storefront.currency.active.value).toBe('GBP'));
|
|
1603
|
+
const wrapper = await mountReady(mock, { storefront });
|
|
1604
|
+
|
|
1605
|
+
expect(addToCart(wrapper).text()).toBe('Shop in EUR');
|
|
1606
|
+
await wrapper.get('form').trigger('submit');
|
|
1607
|
+
await flushPromises();
|
|
1608
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
1609
|
+
});
|
|
1610
|
+
|
|
1611
|
+
it('shows no way out in the default currency, and holds the button', async () => {
|
|
1612
|
+
const storefront = storefrontOffering({ price: notSoldPrice });
|
|
1613
|
+
storefront.currency.started.value = true;
|
|
1614
|
+
const wrapper = await mountReady(mock, { storefront });
|
|
1615
|
+
|
|
1616
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
1617
|
+
expect(wrapper.get('[data-eldra-not-sold]').text()).toBe('Not available in EUR.');
|
|
1618
|
+
expect(addToCart(wrapper).text()).toBe('Not available in EUR');
|
|
1619
|
+
expect(addToCart(wrapper).attributes('disabled')).toBeDefined();
|
|
1620
|
+
expect(wrapper.text()).not.toContain('Shop in');
|
|
1621
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
describe('a product read that failed after a currency change (WS-1399)', () => {
|
|
1626
|
+
it("does not take the last currency's availability for the new one", async () => {
|
|
1627
|
+
const source = createDemoStorefront({
|
|
1628
|
+
commerce: {
|
|
1629
|
+
currency: 'USD',
|
|
1630
|
+
taxInclusivePricing: false,
|
|
1631
|
+
defaultTaxRate: 0,
|
|
1632
|
+
currencies: ['EUR', 'GBP'],
|
|
1633
|
+
defaultCurrency: 'EUR',
|
|
1634
|
+
},
|
|
1635
|
+
});
|
|
1636
|
+
const refreshes: number[] = [];
|
|
1637
|
+
const storefront = {
|
|
1638
|
+
...source,
|
|
1639
|
+
catalog: {
|
|
1640
|
+
...source.catalog,
|
|
1641
|
+
product: (handle: Parameters<typeof source.catalog.product>[0]) => {
|
|
1642
|
+
const result = source.catalog.product(handle);
|
|
1643
|
+
const kept = ref<StorefrontProduct | null>(null);
|
|
1644
|
+
// The read in GBP answered; the one in EUR failed and left it on screen.
|
|
1645
|
+
watch(
|
|
1646
|
+
result.data,
|
|
1647
|
+
(loaded) => {
|
|
1648
|
+
if (loaded !== null && kept.value === null) {
|
|
1649
|
+
kept.value = {
|
|
1650
|
+
...loaded,
|
|
1651
|
+
price: { amount: 96, compareAt: null, currency: 'USD', soldInCurrency: false },
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
},
|
|
1655
|
+
{ immediate: true }
|
|
1656
|
+
);
|
|
1657
|
+
return {
|
|
1658
|
+
...result,
|
|
1659
|
+
data: kept,
|
|
1660
|
+
refresh: async () => {
|
|
1661
|
+
refreshes.push(1);
|
|
1662
|
+
},
|
|
1663
|
+
};
|
|
1664
|
+
},
|
|
1665
|
+
},
|
|
1666
|
+
} as ReturnType<typeof storefrontWith>;
|
|
1667
|
+
storefront.currency.started.value = true;
|
|
1668
|
+
storefront.currency.choose('GBP');
|
|
1669
|
+
await vi.waitFor(() => expect(storefront.currency.active.value).toBe('GBP'));
|
|
1670
|
+
const wrapper = await mountReady(mock, { storefront });
|
|
1671
|
+
|
|
1672
|
+
storefront.currency.choose('EUR');
|
|
1673
|
+
await flushPromises();
|
|
1674
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
1675
|
+
expect(addToCart(wrapper).attributes('disabled')).toBeUndefined();
|
|
1676
|
+
await wrapper.get('form').trigger('submit');
|
|
1677
|
+
await flushPromises();
|
|
1678
|
+
expect(refreshes).toHaveLength(1);
|
|
1679
|
+
});
|
|
1680
|
+
});
|
package/template/i18n/en-US.json
CHANGED
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"outOfStock": "This item is out of stock.",
|
|
96
96
|
"unavailable": "This item is no longer available.",
|
|
97
97
|
"cartOutOfDate": "Your cart is out of date. Reload the page and try again.",
|
|
98
|
+
"businessOwnCurrency": "Business customers shop in ISK.",
|
|
98
99
|
"unresolvedCollectionLabel": "Publish to load products",
|
|
99
100
|
"unresolvedCollectionHelp": "The collection is picked. Its products appear here once this page is published.",
|
|
100
101
|
"orderStatus": {
|
package/template/i18n/is-IS.json
CHANGED
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"outOfStock": "Þessi vara er ekki til á lager.",
|
|
96
96
|
"unavailable": "Þessi vara er ekki lengur í boði.",
|
|
97
97
|
"cartOutOfDate": "Karfan þín er ekki uppfærð. Endurnýjaðu síðuna og prófaðu aftur.",
|
|
98
|
+
"businessOwnCurrency": "Fyrirtæki versla í krónum.",
|
|
98
99
|
"unresolvedCollectionLabel": "Birtu síðuna til að hlaða vörum",
|
|
99
100
|
"unresolvedCollectionHelp": "Vörulistinn er valinn. Vörurnar úr honum birtast hér þegar síðan hefur verið birt.",
|
|
100
101
|
"orderStatus": {
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { ref, watch } from 'vue';
|
|
3
|
+
import { EldraHttpError, type EldraClient } from '@eldrajs/sdk';
|
|
4
|
+
import { toStorefrontCommerce } from '../../app/storefront/commerce';
|
|
5
|
+
import { failureMessageKey } from '../../app/storefront/feedback';
|
|
6
|
+
import { createGatewayStorefront } from '../../app/storefront/gateway';
|
|
7
|
+
import type { StorefrontCommerce, StorefrontRoute } from '../../app/storefront/types';
|
|
8
|
+
|
|
9
|
+
const PREFERENCE_KEY = 'eldra.currency';
|
|
10
|
+
const CART_KEY = 'eldra.cartId';
|
|
11
|
+
|
|
12
|
+
const ISK_OFF: StorefrontCommerce = {
|
|
13
|
+
currency: 'ISK',
|
|
14
|
+
taxInclusivePricing: true,
|
|
15
|
+
defaultTaxRate: 0.24,
|
|
16
|
+
currencies: ['EUR', 'USD'],
|
|
17
|
+
defaultCurrency: 'EUR',
|
|
18
|
+
};
|
|
19
|
+
const EUR_ONLY: StorefrontCommerce = {
|
|
20
|
+
currency: 'ISK',
|
|
21
|
+
taxInclusivePricing: true,
|
|
22
|
+
defaultTaxRate: 0.24,
|
|
23
|
+
defaultCurrency: 'EUR',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function route(): StorefrontRoute {
|
|
27
|
+
return {
|
|
28
|
+
productHandle: null,
|
|
29
|
+
collectionHandle: null,
|
|
30
|
+
categorySlug: null,
|
|
31
|
+
categoryPath: null,
|
|
32
|
+
orderToken: null,
|
|
33
|
+
query: null,
|
|
34
|
+
page: 1,
|
|
35
|
+
sort: null,
|
|
36
|
+
columns: null,
|
|
37
|
+
filters: {},
|
|
38
|
+
setQuery: () => {},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function installStorage(initial: Record<string, string> = {}): Map<string, string> {
|
|
43
|
+
const data = new Map(Object.entries(initial));
|
|
44
|
+
(globalThis as { localStorage?: Storage }).localStorage = {
|
|
45
|
+
getItem: (key: string) => data.get(key) ?? null,
|
|
46
|
+
setItem: (key: string, value: string) => void data.set(key, value),
|
|
47
|
+
removeItem: (key: string) => void data.delete(key),
|
|
48
|
+
clear: () => data.clear(),
|
|
49
|
+
key: () => null,
|
|
50
|
+
get length() {
|
|
51
|
+
return data.size;
|
|
52
|
+
},
|
|
53
|
+
} as Storage;
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
delete (globalThis as { localStorage?: Storage }).localStorage;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function cartAnswer(currency: string): Record<string, unknown> {
|
|
62
|
+
return {
|
|
63
|
+
id: 'cart-1',
|
|
64
|
+
currency,
|
|
65
|
+
items: [
|
|
66
|
+
{
|
|
67
|
+
id: 'line-1',
|
|
68
|
+
productId: 'p1',
|
|
69
|
+
variantId: 'v1',
|
|
70
|
+
title: 'Mug',
|
|
71
|
+
price: currency === 'ISK' ? 2900 : 19.9,
|
|
72
|
+
quantity: 1,
|
|
73
|
+
soldInCurrency: true,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
totals: { subtotal: 0, discount: 0, taxAmount: 0, total: 0 },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function notSold(): EldraHttpError {
|
|
81
|
+
return new EldraHttpError(new Response('{}', { status: 400, statusText: 'Bad Request' }), {
|
|
82
|
+
errorId: 'CART_CURRENCY_NOT_SOLD',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function shopClient(cart: Record<string, unknown> | null = null) {
|
|
87
|
+
const productOptions: unknown[] = [];
|
|
88
|
+
const calls: Array<{ method: string; args: unknown[] }> = [];
|
|
89
|
+
let current = cart;
|
|
90
|
+
const client = {
|
|
91
|
+
catalog: {
|
|
92
|
+
getProduct: async (_handle: string, options: Record<string, unknown> | undefined) => {
|
|
93
|
+
productOptions.push(options);
|
|
94
|
+
return {
|
|
95
|
+
id: 'p1',
|
|
96
|
+
slug: 'mug',
|
|
97
|
+
title: 'Mug',
|
|
98
|
+
status: 'ACTIVE',
|
|
99
|
+
options: [],
|
|
100
|
+
categoryIds: [],
|
|
101
|
+
mediaLinks: [],
|
|
102
|
+
variants: [
|
|
103
|
+
{
|
|
104
|
+
id: 'v1',
|
|
105
|
+
sku: 'M',
|
|
106
|
+
price: 19.9,
|
|
107
|
+
currency: options?.currency ?? 'ISK',
|
|
108
|
+
soldInCurrency: true,
|
|
109
|
+
status: 'ACTIVE',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
listCategories: async () => [],
|
|
115
|
+
},
|
|
116
|
+
inventory: { availability: async () => [] },
|
|
117
|
+
cart: {
|
|
118
|
+
get: async () => current,
|
|
119
|
+
addItem: async (input: Record<string, unknown>) => {
|
|
120
|
+
calls.push({ method: 'addItem', args: [input] });
|
|
121
|
+
if (input.currency === 'ISK') throw notSold();
|
|
122
|
+
current = cartAnswer((input.currency as string | undefined) ?? 'ISK');
|
|
123
|
+
return current;
|
|
124
|
+
},
|
|
125
|
+
setCurrency: async (cartId: string, currency: string) => {
|
|
126
|
+
calls.push({ method: 'setCurrency', args: [cartId, currency] });
|
|
127
|
+
if (currency === 'ISK') throw notSold();
|
|
128
|
+
current = cartAnswer(currency);
|
|
129
|
+
return current;
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
checkout: { url: async () => 'https://checkout.example/x' },
|
|
133
|
+
} as unknown as EldraClient;
|
|
134
|
+
return { client, productOptions, calls };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
describe('a store with its own currency turned off', () => {
|
|
138
|
+
it('builds pages in the default currency: every read names it, before and after start', async () => {
|
|
139
|
+
installStorage();
|
|
140
|
+
const { client, productOptions } = shopClient();
|
|
141
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
142
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
143
|
+
const product = storefront.catalog.product(ref('mug'));
|
|
144
|
+
await vi.waitFor(() => expect(product.data.value).not.toBeNull());
|
|
145
|
+
expect(productOptions[0]).toEqual({ currency: 'EUR' });
|
|
146
|
+
expect(product.data.value?.price.currency).toBe('EUR');
|
|
147
|
+
|
|
148
|
+
await storefront.currency.start(async () => null);
|
|
149
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
150
|
+
expect(storefront.currency.requested.value).toBe('EUR');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('never offers the store currency in the picker', () => {
|
|
154
|
+
installStorage();
|
|
155
|
+
const { client } = shopClient();
|
|
156
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
157
|
+
expect(storefront.currency.offered.value).toEqual(['EUR', 'USD']);
|
|
158
|
+
expect(storefront.currency.defaultCurrency).toBe('EUR');
|
|
159
|
+
expect(storefront.currency.base).toBe('ISK');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('starts an Icelandic visitor, whose country currency is not offered, in the default', async () => {
|
|
163
|
+
installStorage();
|
|
164
|
+
const { client } = shopClient();
|
|
165
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
166
|
+
await storefront.currency.start(async () => 'IS');
|
|
167
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('drops a saved ISK preference and says where prices are now', async () => {
|
|
171
|
+
const data = installStorage({ [PREFERENCE_KEY]: 'ISK' });
|
|
172
|
+
const { client } = shopClient();
|
|
173
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
174
|
+
await storefront.currency.start(async () => null);
|
|
175
|
+
expect(data.has(PREFERENCE_KEY)).toBe(false);
|
|
176
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
177
|
+
expect(storefront.currency.movedTo.value).toBe('EUR');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('drops a saved ISK preference in a store offering one currency, with no notice', async () => {
|
|
181
|
+
const data = installStorage({ [PREFERENCE_KEY]: 'ISK' });
|
|
182
|
+
const { client } = shopClient();
|
|
183
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: EUR_ONLY });
|
|
184
|
+
expect(storefront.currency.offered.value).toEqual(['EUR']);
|
|
185
|
+
await storefront.currency.start(async () => null);
|
|
186
|
+
expect(data.has(PREFERENCE_KEY)).toBe(false);
|
|
187
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
188
|
+
expect(storefront.currency.movedTo.value).toBeNull();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('leaves a saved choice alone in a store selling in its own currency only, as before', async () => {
|
|
192
|
+
const data = installStorage({ [PREFERENCE_KEY]: 'EUR' });
|
|
193
|
+
const { client } = shopClient();
|
|
194
|
+
const storefront = createGatewayStorefront(client, {
|
|
195
|
+
route: route(),
|
|
196
|
+
commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
|
|
197
|
+
});
|
|
198
|
+
await storefront.currency.start(async () => null);
|
|
199
|
+
expect(data.get(PREFERENCE_KEY)).toBe('EUR');
|
|
200
|
+
expect(storefront.currency.active.value).toBe('ISK');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('creates a new cart in the default currency', async () => {
|
|
204
|
+
installStorage();
|
|
205
|
+
const { client, calls } = shopClient();
|
|
206
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: EUR_ONLY });
|
|
207
|
+
await storefront.currency.start(async () => null);
|
|
208
|
+
await storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
209
|
+
expect(calls[0]?.args[0]).toMatchObject({ currency: 'EUR' });
|
|
210
|
+
expect(storefront.cart.currency.value).toBe('EUR');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('moves a cart from before ISK was turned off to the default currency', async () => {
|
|
214
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
215
|
+
const { client, calls } = shopClient(cartAnswer('ISK'));
|
|
216
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
217
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
218
|
+
await storefront.currency.start(async () => null);
|
|
219
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
220
|
+
expect(calls).toEqual([{ method: 'setCurrency', args: ['cart-1', 'EUR'] }]);
|
|
221
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
222
|
+
expect(storefront.currency.movedTo.value).toBe('EUR');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('says prices are in the default only once, after moving a cart left in ISK', async () => {
|
|
226
|
+
installStorage({ [CART_KEY]: 'cart-1', [PREFERENCE_KEY]: 'ISK' });
|
|
227
|
+
const { client } = shopClient(cartAnswer('ISK'));
|
|
228
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
229
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
230
|
+
const notices: Array<string | null> = [];
|
|
231
|
+
watch(storefront.currency.movedTo, (code) => notices.push(code), { flush: 'sync' });
|
|
232
|
+
await storefront.currency.start(async () => null);
|
|
233
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
234
|
+
expect(notices).toEqual(['EUR']);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('never withdraws the default when a move to it is refused', async () => {
|
|
238
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
239
|
+
const { client } = shopClient(cartAnswer('USD'));
|
|
240
|
+
client.cart.setCurrency = (async () => {
|
|
241
|
+
throw notSold();
|
|
242
|
+
}) as typeof client.cart.setCurrency;
|
|
243
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
244
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('USD'));
|
|
245
|
+
await storefront.currency.start(async () => null);
|
|
246
|
+
storefront.currency.chooseBase();
|
|
247
|
+
await vi.waitFor(() => expect(storefront.currency.failure.value).not.toBeNull());
|
|
248
|
+
expect(storefront.currency.offered.value).toEqual(['EUR', 'USD']);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('withdraws ISK when the store refuses a move to it', async () => {
|
|
252
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
253
|
+
const { client } = shopClient(cartAnswer('EUR'));
|
|
254
|
+
const storefront = createGatewayStorefront(client, {
|
|
255
|
+
route: route(),
|
|
256
|
+
commerce: { ...ISK_OFF, currencies: ['EUR', 'ISK'] },
|
|
257
|
+
});
|
|
258
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
259
|
+
await storefront.currency.start(async () => null);
|
|
260
|
+
storefront.currency.choose('ISK');
|
|
261
|
+
await vi.waitFor(() => expect(storefront.currency.offered.value).toEqual(['EUR']));
|
|
262
|
+
expect(storefront.currency.active.value).toBe('EUR');
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('toStorefrontCommerce', () => {
|
|
267
|
+
it('keeps the default currency the build wrote', () => {
|
|
268
|
+
expect(toStorefrontCommerce({ ...EUR_ONLY })).toEqual(EUR_ONLY);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('a business customer, whose cart the store keeps in ISK', () => {
|
|
273
|
+
function iskOnly(): EldraHttpError {
|
|
274
|
+
return new EldraHttpError(new Response('{}', { status: 409, statusText: 'Conflict' }), {
|
|
275
|
+
errorId: 'CART_CURRENCY_CUSTOMER_ISK_ONLY',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function businessClient(cart: Record<string, unknown> | null) {
|
|
280
|
+
const built = shopClient(cart);
|
|
281
|
+
let current = cart;
|
|
282
|
+
built.client.cart.get = (async () => current) as typeof built.client.cart.get;
|
|
283
|
+
built.client.cart.addItem = (async (input: Record<string, unknown>) => {
|
|
284
|
+
built.calls.push({ method: 'addItem', args: [input] });
|
|
285
|
+
const into = (input.currency as string | undefined) ?? (current?.currency as string) ?? 'ISK';
|
|
286
|
+
if (into !== 'ISK') throw iskOnly();
|
|
287
|
+
current = cartAnswer('ISK');
|
|
288
|
+
return current;
|
|
289
|
+
}) as typeof built.client.cart.addItem;
|
|
290
|
+
built.client.cart.setCurrency = (async (cartId: string, currency: string) => {
|
|
291
|
+
built.calls.push({ method: 'setCurrency', args: [cartId, currency] });
|
|
292
|
+
if (currency !== 'ISK') throw iskOnly();
|
|
293
|
+
current = cartAnswer('ISK');
|
|
294
|
+
return current;
|
|
295
|
+
}) as typeof built.client.cart.setCurrency;
|
|
296
|
+
return built;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
it('keeps their ISK cart after one refused move, quietly, with no picker', async () => {
|
|
300
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
301
|
+
const { client, calls } = businessClient(cartAnswer('ISK'));
|
|
302
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
303
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
304
|
+
await storefront.currency.start(async () => null);
|
|
305
|
+
await vi.waitFor(() => expect(storefront.currency.ownCurrencyOnly.value).toBe(true));
|
|
306
|
+
|
|
307
|
+
expect(storefront.currency.active.value).toBe('ISK');
|
|
308
|
+
expect(storefront.currency.requested.value).toBeUndefined();
|
|
309
|
+
expect(storefront.currency.offered.value).toEqual(['ISK']);
|
|
310
|
+
expect(storefront.currency.failure.value).toBeNull();
|
|
311
|
+
expect(storefront.currency.movedTo.value).toBeNull();
|
|
312
|
+
|
|
313
|
+
await storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
314
|
+
expect(calls.filter((call) => call.method === 'setCurrency')).toHaveLength(1);
|
|
315
|
+
expect(storefront.cart.currency.value).toBe('ISK');
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('creates their cart in ISK when the default is refused for them', async () => {
|
|
319
|
+
installStorage();
|
|
320
|
+
const { client, calls } = businessClient(null);
|
|
321
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
322
|
+
await storefront.currency.start(async () => null);
|
|
323
|
+
|
|
324
|
+
const failure = await storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
325
|
+
|
|
326
|
+
expect(failure).toBeNull();
|
|
327
|
+
expect(calls.map((call) => (call.args[0] as { currency?: string }).currency)).toEqual([
|
|
328
|
+
'EUR',
|
|
329
|
+
undefined,
|
|
330
|
+
]);
|
|
331
|
+
expect(storefront.cart.currency.value).toBe('ISK');
|
|
332
|
+
expect(storefront.currency.offered.value).toEqual(['ISK']);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('moves a signed-in business customer’s cart to ISK when the theme says so', async () => {
|
|
336
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
337
|
+
const { client, calls } = businessClient(cartAnswer('EUR'));
|
|
338
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
339
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
340
|
+
await storefront.currency.start(async () => null);
|
|
341
|
+
storefront.currency.keepOwnCurrency();
|
|
342
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
343
|
+
|
|
344
|
+
expect(calls).toEqual([{ method: 'setCurrency', args: ['cart-1', 'ISK'] }]);
|
|
345
|
+
expect(storefront.currency.active.value).toBe('ISK');
|
|
346
|
+
expect(storefront.currency.offered.value).toEqual(['ISK']);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('says why when they pick a currency the store keeps from them', async () => {
|
|
350
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
351
|
+
const { client } = businessClient(cartAnswer('ISK'));
|
|
352
|
+
const storefront = createGatewayStorefront(client, {
|
|
353
|
+
route: route(),
|
|
354
|
+
commerce: { ...ISK_OFF, currencies: ['ISK', 'EUR'], defaultCurrency: 'ISK' },
|
|
355
|
+
});
|
|
356
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
357
|
+
await storefront.currency.start(async () => null);
|
|
358
|
+
storefront.currency.choose('EUR');
|
|
359
|
+
await vi.waitFor(() => expect(storefront.currency.failure.value).not.toBeNull());
|
|
360
|
+
expect(failureMessageKey(storefront.currency.failure.value)).toBe(
|
|
361
|
+
'storefront.businessOwnCurrency'
|
|
362
|
+
);
|
|
363
|
+
expect(storefront.currency.offered.value).toEqual(['ISK']);
|
|
364
|
+
expect(storefront.cart.currency.value).toBe('ISK');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('moves their cart to ISK when a pick of theirs is refused, and keeps ISK', async () => {
|
|
368
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
369
|
+
const { client } = businessClient(cartAnswer('EUR'));
|
|
370
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
371
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
372
|
+
await storefront.currency.start(async () => null);
|
|
373
|
+
storefront.currency.choose('USD');
|
|
374
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
375
|
+
expect(storefront.currency.offered.value).toEqual(['ISK']);
|
|
376
|
+
expect(storefront.currency.active.value).toBe('ISK');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('moves their cart to ISK and adds again when an add to it is refused', async () => {
|
|
380
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
381
|
+
const { client, calls } = businessClient(cartAnswer('EUR'));
|
|
382
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
383
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
384
|
+
await storefront.currency.start(async () => null);
|
|
385
|
+
const failure = await storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
386
|
+
expect(failure).toBeNull();
|
|
387
|
+
expect(calls.map((call) => call.method)).toEqual(['addItem', 'setCurrency', 'addItem']);
|
|
388
|
+
expect(storefront.cart.currency.value).toBe('ISK');
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('keeps no ISK choice for whoever uses the browser next', async () => {
|
|
392
|
+
const data = installStorage({ [CART_KEY]: 'cart-1' });
|
|
393
|
+
const { client } = businessClient(cartAnswer('EUR'));
|
|
394
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
395
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
396
|
+
await storefront.currency.start(async () => null);
|
|
397
|
+
storefront.currency.keepOwnCurrency();
|
|
398
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
399
|
+
expect(data.has(PREFERENCE_KEY)).toBe(false);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('goes back to what the store offers when the store sees no business customer', async () => {
|
|
403
|
+
installStorage();
|
|
404
|
+
const { client, calls } = shopClient();
|
|
405
|
+
client.cart.addItem = (async (input: Record<string, unknown>) => {
|
|
406
|
+
calls.push({ method: 'addItem', args: [input] });
|
|
407
|
+
return cartAnswer((input.currency as string | undefined) ?? 'EUR');
|
|
408
|
+
}) as typeof client.cart.addItem;
|
|
409
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
410
|
+
storefront.currency.keepOwnCurrency();
|
|
411
|
+
await storefront.currency.start(async () => null);
|
|
412
|
+
await storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
413
|
+
await vi.waitFor(() => expect(storefront.currency.ownCurrencyOnly.value).toBe(false));
|
|
414
|
+
expect(storefront.currency.offered.value).toEqual(['EUR', 'USD']);
|
|
415
|
+
expect(storefront.currency.failure.value).toBeNull();
|
|
416
|
+
await storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
417
|
+
expect(calls.filter((call) => call.method === 'setCurrency')).toHaveLength(1);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('lets go on sign-out and moves an ISK cart to the default', async () => {
|
|
421
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
422
|
+
const { client } = businessClient(cartAnswer('ISK'));
|
|
423
|
+
client.cart.setCurrency = (async (_cartId: string, currency: string) =>
|
|
424
|
+
cartAnswer(currency)) as typeof client.cart.setCurrency;
|
|
425
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
426
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('ISK'));
|
|
427
|
+
storefront.currency.keepOwnCurrency();
|
|
428
|
+
await storefront.currency.start(async () => null);
|
|
429
|
+
expect(storefront.cart.currency.value).toBe('ISK');
|
|
430
|
+
storefront.currency.keepOwnCurrency(false);
|
|
431
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
432
|
+
expect(storefront.currency.offered.value).toEqual(['EUR', 'USD']);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('ignores a refusal that answers for a visitor who has signed out since', async () => {
|
|
436
|
+
installStorage({ [CART_KEY]: 'cart-1' });
|
|
437
|
+
const { client } = businessClient(cartAnswer('EUR'));
|
|
438
|
+
let refuse: (() => void) | null = null;
|
|
439
|
+
client.cart.setCurrency = (() =>
|
|
440
|
+
new Promise((_, reject) => {
|
|
441
|
+
refuse = () => reject(iskOnly());
|
|
442
|
+
})) as typeof client.cart.setCurrency;
|
|
443
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
444
|
+
await vi.waitFor(() => expect(storefront.cart.currency.value).toBe('EUR'));
|
|
445
|
+
await storefront.currency.start(async () => null);
|
|
446
|
+
storefront.currency.choose('USD');
|
|
447
|
+
await vi.waitFor(() => expect(refuse).not.toBeNull());
|
|
448
|
+
storefront.currency.keepOwnCurrency(false);
|
|
449
|
+
refuse!();
|
|
450
|
+
await vi.waitFor(() => expect(storefront.currency.busy.value).toBe(false));
|
|
451
|
+
expect(storefront.currency.ownCurrencyOnly.value).toBe(false);
|
|
452
|
+
expect(storefront.currency.offered.value).toEqual(['EUR', 'USD']);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('neither keeps nor retries in ISK when an add answers after the visitor signed out', async () => {
|
|
456
|
+
installStorage();
|
|
457
|
+
const { client, calls } = businessClient(null);
|
|
458
|
+
let refuse: (() => void) | null = null;
|
|
459
|
+
client.cart.addItem = ((input: Record<string, unknown>) => {
|
|
460
|
+
calls.push({ method: 'addItem', args: [input] });
|
|
461
|
+
return new Promise((_, reject) => {
|
|
462
|
+
refuse = () => reject(iskOnly());
|
|
463
|
+
});
|
|
464
|
+
}) as typeof client.cart.addItem;
|
|
465
|
+
const storefront = createGatewayStorefront(client, { route: route(), commerce: ISK_OFF });
|
|
466
|
+
await storefront.currency.start(async () => null);
|
|
467
|
+
const adding = storefront.cart.add({ productId: 'p1', variantId: 'v1', quantity: 1 });
|
|
468
|
+
await vi.waitFor(() => expect(refuse).not.toBeNull());
|
|
469
|
+
storefront.currency.keepOwnCurrency(false);
|
|
470
|
+
refuse!();
|
|
471
|
+
await adding;
|
|
472
|
+
expect(storefront.currency.ownCurrencyOnly.value).toBe(false);
|
|
473
|
+
expect(calls).toHaveLength(1);
|
|
474
|
+
});
|
|
475
|
+
});
|