@eldrajs/theme-cli 0.2.5 → 0.2.6

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.
Files changed (90) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/block-types.d.ts +1 -1
  3. package/template/.eldra/manifest.json +30 -2
  4. package/template/.eldra/previews.json +35 -35
  5. package/template/app/app.vue +15 -0
  6. package/template/app/composables/useStorefront.ts +7 -2
  7. package/template/app/plugins/eldra-storefront.ts +9 -0
  8. package/template/app/storefront/analytics.ts +15 -7
  9. package/template/app/storefront/cart.ts +228 -51
  10. package/template/app/storefront/commerce.ts +8 -2
  11. package/template/app/storefront/currency.ts +205 -0
  12. package/template/app/storefront/demo.ts +10 -2
  13. package/template/app/storefront/feedback.ts +2 -0
  14. package/template/app/storefront/gateway.ts +153 -35
  15. package/template/app/storefront/money.ts +6 -18
  16. package/template/app/storefront/structuredData.ts +16 -5
  17. package/template/app/storefront/toProductCard.ts +14 -14
  18. package/template/app/storefront/types.ts +13 -0
  19. package/template/app/storefront/volatile.ts +4 -0
  20. package/template/app/utils/seoInput.ts +4 -3
  21. package/template/blocks/announcement-bar/preview.png +0 -0
  22. package/template/blocks/article/preview.png +0 -0
  23. package/template/blocks/article-list/preview.png +0 -0
  24. package/template/blocks/breadcrumbs/preview.png +0 -0
  25. package/template/blocks/cart/Block.vue +41 -22
  26. package/template/blocks/cart/__tests__/Block.spec.ts +2 -3
  27. package/template/blocks/cart/__tests__/loadFailed.spec.ts +135 -0
  28. package/template/blocks/cart/__tests__/notSold.spec.ts +109 -0
  29. package/template/blocks/cart/parts/CartLines.vue +14 -2
  30. package/template/blocks/cart/parts/CheckoutButton.vue +45 -0
  31. package/template/blocks/cart/parts/LoadFailed.vue +37 -0
  32. package/template/blocks/cart/parts/NotSoldNotice.vue +69 -0
  33. package/template/blocks/cart/parts/Summary.vue +9 -21
  34. package/template/blocks/cart/parts/notSold.ts +19 -0
  35. package/template/blocks/cart/preview.png +0 -0
  36. package/template/blocks/collection-grid/Block.vue +15 -2
  37. package/template/blocks/collection-grid/__tests__/Block.spec.ts +14 -0
  38. package/template/blocks/collection-grid/preview.png +0 -0
  39. package/template/blocks/collection-header/preview.png +0 -0
  40. package/template/blocks/contact/preview.png +0 -0
  41. package/template/blocks/cta/preview.png +0 -0
  42. package/template/blocks/faq/preview.png +0 -0
  43. package/template/blocks/feature-grid/preview.png +0 -0
  44. package/template/blocks/footer/Block.vue +20 -45
  45. package/template/blocks/footer/preview.png +0 -0
  46. package/template/blocks/form/preview.png +0 -0
  47. package/template/blocks/gallery/preview.png +0 -0
  48. package/template/blocks/hero/preview.png +0 -0
  49. package/template/blocks/image/preview.png +0 -0
  50. package/template/blocks/logo-cloud/preview.png +0 -0
  51. package/template/blocks/navigation/Block.vue +39 -3
  52. package/template/blocks/navigation/preview.png +0 -0
  53. package/template/blocks/newsletter/preview.png +0 -0
  54. package/template/blocks/order-status/Block.vue +15 -6
  55. package/template/blocks/order-status/preview.png +0 -0
  56. package/template/blocks/pricing-table/preview.png +0 -0
  57. package/template/blocks/product-carousel/Block.vue +5 -2
  58. package/template/blocks/product-carousel/preview.png +0 -0
  59. package/template/blocks/product-detail/Block.vue +46 -10
  60. package/template/blocks/product-detail/__tests__/Block.spec.ts +78 -1
  61. package/template/blocks/product-detail/preview.png +0 -0
  62. package/template/blocks/quote/preview.png +0 -0
  63. package/template/blocks/rich-text/preview.png +0 -0
  64. package/template/blocks/search/Block.vue +8 -2
  65. package/template/blocks/search/TypeSection.vue +8 -2
  66. package/template/blocks/search/preview.png +0 -0
  67. package/template/blocks/search/results.ts +5 -2
  68. package/template/blocks/split-content/preview.png +0 -0
  69. package/template/blocks/stats/preview.png +0 -0
  70. package/template/blocks/tabs/preview.png +0 -0
  71. package/template/blocks/team/preview.png +0 -0
  72. package/template/blocks/testimonials/preview.png +0 -0
  73. package/template/blocks/timeline/preview.png +0 -0
  74. package/template/blocks/trust-strip/preview.png +0 -0
  75. package/template/blocks/video-embed/preview.png +0 -0
  76. package/template/blocks/wishlist/Block.vue +5 -1
  77. package/template/blocks/wishlist/preview.png +0 -0
  78. package/template/i18n/en-US.json +19 -3
  79. package/template/i18n/is-IS.json +19 -3
  80. package/template/test/currencyPicker.spec.ts +66 -0
  81. package/template/test/seoInput.spec.ts +22 -0
  82. package/template/test/storefront/analytics.spec.ts +15 -0
  83. package/template/test/storefront/cart.spec.ts +4 -4
  84. package/template/test/storefront/currency.spec.ts +549 -0
  85. package/template/test/storefront/currencyStore.spec.ts +845 -0
  86. package/template/test/storefront/gateway.spec.ts +22 -0
  87. package/template/test/storefront/money.spec.ts +2 -8
  88. package/template/test/storefront/structuredData.spec.ts +45 -0
  89. package/template/test/storefront/toProductCard.spec.ts +1 -1
  90. package/template/test/storefront/volatile.spec.ts +11 -0
@@ -205,6 +205,10 @@ function applyPrice(current: StorefrontPrice | null, next: StorefrontPrice): Sto
205
205
  // catalogue the page has never had, not a value being refreshed over one it is already showing, so
206
206
  // the rule above does not apply to it.
207
207
  if (current === null) return next;
208
+ // A price in another currency is a different price, `from` and all.
209
+ if (current.currency !== next.currency || current.soldInCurrency !== next.soldInCurrency) {
210
+ return next;
211
+ }
208
212
  const compareAt = next.compareAt ?? null;
209
213
  if (current.amount === next.amount && (current.compareAt ?? null) === compareAt) return current;
210
214
  return { ...current, amount: next.amount, compareAt };
@@ -82,9 +82,10 @@ export function seoInput(parts: SeoInputParts): SeoInput {
82
82
  if (catalogKind === 'collection') contentImage = shareImage(entryData.image);
83
83
  }
84
84
 
85
- // A catalog object is not an authored document: its own fields are not an `seo` value, only the
86
- // shared route template's are.
87
- const entry = catalogKind === null ? seoValue(parts.page?.data?.seo) : null;
85
+ // A catalog object carries the merchant's own `seo` value in the same shape a CMS entry does
86
+ // (contract 6.6.0: title, description, canonicalUrl, ogTitle, ogDescription, imageUrl, noindex),
87
+ // so it is the route's entry value and wins over the shared route template's, field by field.
88
+ const entry = seoValue(catalogKind === null ? parts.page?.data?.seo : entryData.seo);
88
89
  const template = seoValue(parts.template?.data?.seo);
89
90
 
90
91
  if (parts.isNotFound) {
Binary file
@@ -49,6 +49,7 @@ import {
49
49
  nextTick,
50
50
  onBeforeUnmount,
51
51
  onMounted,
52
+ provide,
52
53
  ref,
53
54
  watch,
54
55
  type Component,
@@ -58,6 +59,7 @@ import {
58
59
  Container,
59
60
  Drawer,
60
61
  EditorPlaceholder,
62
+ CURRENCY_KEY,
61
63
  EmptyState,
62
64
  Link,
63
65
  Price,
@@ -76,6 +78,9 @@ import { useMoney } from '../../app/storefront/money';
76
78
  import CartLines from './parts/CartLines.vue';
77
79
  import ShippingBar from './parts/ShippingBar.vue';
78
80
  import Summary from './parts/Summary.vue';
81
+ import NotSoldNotice from './parts/NotSoldNotice.vue';
82
+ import CheckoutButton from './parts/CheckoutButton.vue';
83
+ import LoadFailed from './parts/LoadFailed.vue';
79
84
 
80
85
  const props = defineProps<{
81
86
  entry: EldraBlockEntry<'cart'>;
@@ -91,7 +96,14 @@ const editing = useEditing();
91
96
  const { t } = useI18n();
92
97
  /** The cart subtotal is major units (`app/storefront/types.ts`); `<Price>` reads minor. */
93
98
  const money = useMoney();
94
- const cart = useStorefront().cart;
99
+ const storefront = useStorefront();
100
+ const cart = storefront.cart;
101
+ // Every price under the cart is in the cart's own currency, which can differ from the store's.
102
+ provide(CURRENCY_KEY, () => cart.currency.value ?? money.currency.value);
103
+ const cartInStoreCurrency = computed(
104
+ () => cart.currency.value === undefined || cart.currency.value === storefront.currency.base
105
+ );
106
+ const hasNotSold = computed(() => cart.notSold.value.length > 0);
95
107
 
96
108
  const uid = useUiId();
97
109
  const headingId = `cart-title-${uid}`;
@@ -160,11 +172,9 @@ const hasContinueLink = computed(() => emptyLinkHref.value !== null);
160
172
 
161
173
  const showDiscountField = computed(() => data.value.showDiscountField ?? true);
162
174
  const showPaymentIcons = computed(() => data.value.showPaymentIcons ?? true);
163
- const threshold = computed(() => (data.value.freeShippingThreshold ?? '').trim());
164
-
165
- const checkoutHref = computed(() => safeHref(cart.checkoutUrl.value));
166
- const checkoutAs = computed(() =>
167
- checkoutHref.value !== null && isInternalHref(checkoutHref.value) ? EldraRouterLink : undefined
175
+ /** Typed in the store's own currency, so it says nothing about a cart in another. */
176
+ const threshold = computed(() =>
177
+ cartInStoreCurrency.value ? (data.value.freeShippingThreshold ?? '').trim() : ''
168
178
  );
169
179
 
170
180
  /** The theme's own cart page path — the same one `blocks/navigation/Block.vue` sends the bag to
@@ -241,7 +251,9 @@ const DRAWER_CLASSES = {
241
251
  >
242
252
  <template v-if="isEmpty">
243
253
  <div ref="emptyRoot" class="my-6 px-4">
254
+ <LoadFailed />
244
255
  <EmptyState
256
+ v-if="!cart.loadFailed.value"
245
257
  plain
246
258
  :icon="ShoppingBagIcon"
247
259
  :title="emptyTitle || t('cart.emptyFallbackTitle')"
@@ -262,6 +274,8 @@ const DRAWER_CLASSES = {
262
274
  <template v-else>
263
275
  <ShippingBar panel="edge" :threshold="threshold" :subtotal="subtotal" />
264
276
  <div class="px-4">
277
+ <LoadFailed class="mt-4" />
278
+ <NotSoldNotice v-if="hasNotSold" class="mt-4" />
265
279
  <CartLines :lines="lines" @removing="onRemoving" />
266
280
  </div>
267
281
  </template>
@@ -270,25 +284,23 @@ const DRAWER_CLASSES = {
270
284
  <div class="flex items-baseline justify-between gap-4">
271
285
  <span class="text-text text-base font-semibold">{{ t('cart.subtotal') }}</span>
272
286
  <Price
273
- :amount="money.minor(subtotal)"
287
+ :amount="money.minor(subtotal, cart.currency.value)"
274
288
  class="text-text text-base font-semibold tabular-nums"
275
289
  />
276
290
  </div>
277
- <p v-if="note" class="text-muted text-body-sm text-center">{{ note }}</p>
278
- <Button
279
- v-if="checkoutHref"
280
- variant="primary"
281
- size="lg"
282
- block
283
- :href="checkoutHref"
284
- :as="checkoutAs"
285
- @click="cart.beginCheckout()"
291
+ <p
292
+ v-if="cart.notSold.value.length > 0"
293
+ class="text-muted text-body-sm"
294
+ data-eldra-not-included
286
295
  >
287
- <template #leadingIcon>
288
- <EldraIcon name="lock" size="sm" />
289
- </template>
290
- {{ t('cart.checkout') }}
291
- </Button>
296
+ {{
297
+ cart.notSold.value.length === 1
298
+ ? t('currency.notIncludedOne')
299
+ : t('currency.notIncludedMany', { count: cart.notSold.value.length })
300
+ }}
301
+ </p>
302
+ <p v-if="note" class="text-muted text-body-sm text-center">{{ note }}</p>
303
+ <CheckoutButton />
292
304
  <!-- No `@click` close: this is a router link like the line titles beside it, and the app
293
305
  shell closes the drawer on the route change (`app/storefront/cart.ts`, `drawerOpen`). -->
294
306
  <Button
@@ -310,7 +322,10 @@ const DRAWER_CLASSES = {
310
322
  class="font-heading text-text @tablet:text-h2 flex flex-wrap items-baseline gap-3 text-[1.625rem] leading-[1.15] font-bold tracking-[-0.015em]"
311
323
  >
312
324
  {{ t('cart.title') }}
313
- <span class="font-body text-muted text-base font-normal tracking-normal">
325
+ <span
326
+ v-if="!cart.loadFailed.value"
327
+ class="font-body text-muted text-base font-normal tracking-normal"
328
+ >
314
329
  {{ countLabel }}
315
330
  </span>
316
331
  </h1>
@@ -327,7 +342,9 @@ const DRAWER_CLASSES = {
327
342
  </div>
328
343
 
329
344
  <div v-if="isEmpty" ref="emptyRoot">
345
+ <LoadFailed />
330
346
  <EmptyState
347
+ v-if="!cart.loadFailed.value"
331
348
  :icon="ShoppingBagIcon"
332
349
  :heading-level="2"
333
350
  :title="emptyTitle || t('cart.emptyFallbackTitle')"
@@ -350,6 +367,8 @@ const DRAWER_CLASSES = {
350
367
  >
351
368
  <div class="grid min-w-0 gap-2">
352
369
  <ShippingBar panel="card" :threshold="threshold" :subtotal="subtotal" />
370
+ <LoadFailed />
371
+ <NotSoldNotice v-if="hasNotSold" />
353
372
  <div
354
373
  aria-hidden="true"
355
374
  class="border-border text-body-sm text-muted @tablet:grid hidden grid-cols-[6rem_1fr_11rem_6rem] gap-x-4 border-b pt-4 pb-3"
@@ -451,9 +451,8 @@ describe('cart block', () => {
451
451
 
452
452
  expect(alertToast()?.textContent).toContain('This item is out of stock.');
453
453
  expect(toastRoot()?.textContent ?? '').not.toContain('removed');
454
- // The line is back on screen — the restore is local and deliberate — which is exactly why the
455
- // shopper has to be told the shop could not take it back.
456
- expect(storefront.cart.lines.value.map((line) => line.title)).toContain(
454
+ // The cart shows what the shop holds: the line it could not take back stays out.
455
+ expect(storefront.cart.lines.value.map((line) => line.title)).not.toContain(
457
456
  'Merino crew sweater'
458
457
  );
459
458
  expect(await axe(wrapper.element)).toHaveNoViolations();
@@ -0,0 +1,135 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { defineComponent, h, ref } from 'vue';
4
+ import { Toaster, useToast } from '@eldrajs/ui';
5
+ import { afterEach, describe, expect, it } from 'vitest';
6
+ import { axe } from '../../../test/support/axe';
7
+ import { mountOptions } from '../../../test/support/mountBlock';
8
+ import { createCartStore, type CartSnapshot } from '../../../app/storefront/cart';
9
+ import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
10
+ import { STOREFRONT_KEY, type StorefrontSource } from '../../../app/storefront/types';
11
+ import Navigation from '../../navigation/Block.vue';
12
+ import navigationMock from '../../navigation/mock.json';
13
+ import Block from '../Block.vue';
14
+ import mock from '../mock.json';
15
+
16
+ afterEach(() => {
17
+ useToast().clear?.();
18
+ document.body.innerHTML = '';
19
+ });
20
+
21
+ const fails = async (): Promise<CartSnapshot> => {
22
+ throw new Error('timeout');
23
+ };
24
+ const answersLines = async (): Promise<CartSnapshot> => ({
25
+ lines: DEMO_CART_LINES,
26
+ totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
27
+ });
28
+
29
+ /** A storefront whose cart reads answer in turn: by default the first fails and the next answers. */
30
+ function unreadCartStorefront(
31
+ answers: Array<() => Promise<CartSnapshot>> = [fails, answersLines]
32
+ ): StorefrontSource {
33
+ const unused = async (): Promise<never> => {
34
+ throw new Error('unused');
35
+ };
36
+ const cart = createCartStore({
37
+ init: () => answers.shift()!(),
38
+ add: unused,
39
+ setQuantity: unused,
40
+ remove: unused,
41
+ applyDiscount: async () => ({ ack: { ok: false, reason: 'failed' } }),
42
+ removeDiscount: unused,
43
+ checkoutUrl: ref(null),
44
+ });
45
+ return { ...createDemoStorefront(), cart };
46
+ }
47
+
48
+ async function mountWith(
49
+ component: object,
50
+ data: Record<string, unknown>,
51
+ storefront: StorefrontSource
52
+ ) {
53
+ const options = mountOptions({ entry: { id: 'cart', data } });
54
+ const wrapper = mount(component, {
55
+ ...options,
56
+ props: { entry: { id: 'cart', data } },
57
+ attachTo: document.body,
58
+ global: {
59
+ ...options.global,
60
+ provide: { ...options.global.provide, [STOREFRONT_KEY]: storefront },
61
+ stubs: { ...options.global.stubs, transition: false, 'transition-group': false },
62
+ },
63
+ });
64
+ await flushPromises();
65
+ return wrapper;
66
+ }
67
+
68
+ describe('a cart whose read failed', () => {
69
+ it('shows only the error and Try again on the cart page, no count and no empty state', async () => {
70
+ const storefront = unreadCartStorefront();
71
+ const wrapper = await mountWith(Block, { ...mock, variant: 'page' }, storefront);
72
+
73
+ const notice = wrapper.get('[data-eldra-cart-load-failed]');
74
+ expect(notice.text()).toContain("We couldn't load your cart.");
75
+ expect(wrapper.text()).not.toContain('Your cart is empty');
76
+ expect(wrapper.text()).not.toContain('0 items');
77
+ expect(await axe(wrapper.element)).toHaveNoViolations();
78
+
79
+ await notice.get('button').trigger('click');
80
+ await flushPromises();
81
+ expect(wrapper.find('[data-eldra-cart-load-failed]').exists()).toBe(false);
82
+ expect(storefront.cart.lines.value).toHaveLength(DEMO_CART_LINES.length);
83
+ });
84
+
85
+ it('shows only the error in the drawer, accessibly', async () => {
86
+ const storefront = unreadCartStorefront();
87
+ storefront.cart.drawerOpen.value = true;
88
+ const wrapper = await mountWith(Block, { ...mock, variant: 'drawer' }, storefront);
89
+ const dialog = document.body.querySelector<HTMLElement>('dialog')!;
90
+ expect(dialog.querySelector('[data-eldra-cart-load-failed]')).not.toBeNull();
91
+ expect(dialog.textContent).not.toContain('Your cart is empty');
92
+ expect(await axe(dialog)).toHaveNoViolations();
93
+ wrapper.unmount();
94
+ });
95
+
96
+ it('4662896752: says so again when Try again fails too', async () => {
97
+ const storefront = unreadCartStorefront([fails, fails]);
98
+ const Harness = defineComponent({
99
+ setup: () => () =>
100
+ h('div', [
101
+ h(Block as never, { entry: { id: 'cart', data: { ...mock, variant: 'page' } } }),
102
+ h(Toaster),
103
+ ]),
104
+ });
105
+ const wrapper = await mountWith(Harness, {}, storefront);
106
+ await wrapper.get('[data-eldra-cart-load-failed] button').trigger('click');
107
+ await flushPromises();
108
+ // The notice itself is an alert too; the new signal is a toast outside it.
109
+ const toasts = [...document.body.querySelectorAll('[role="alert"]')].filter(
110
+ (node) => node.closest('[data-eldra-cart-load-failed]') === null
111
+ );
112
+ expect(toasts.map((node) => node.textContent).join(' ')).toContain(
113
+ 'Something went wrong. Please try again.'
114
+ );
115
+ });
116
+
117
+ it('Block.vue:252: shows the error over the lines a cart kept when a later read fails', async () => {
118
+ const storefront = unreadCartStorefront([answersLines, fails]);
119
+ const wrapper = await mountWith(Block, { ...mock, variant: 'page' }, storefront);
120
+ expect(wrapper.find('[data-eldra-cart-load-failed]').exists()).toBe(false);
121
+ await storefront.cart.reload();
122
+ await flushPromises();
123
+ expect(wrapper.find('[data-eldra-cart-load-failed]').exists()).toBe(true);
124
+ expect(storefront.cart.lines.value).toHaveLength(DEMO_CART_LINES.length);
125
+ });
126
+
127
+ it('gives the header bag no count', async () => {
128
+ const storefront = unreadCartStorefront();
129
+ const wrapper = await mountWith(Navigation, navigationMock, storefront);
130
+ const bag = wrapper
131
+ .findAll('[data-eldra-header-actions] a, [data-eldra-header-actions] button')
132
+ .find((node) => (node.attributes('aria-label') ?? '').startsWith('Cart'));
133
+ expect(bag?.attributes('aria-label')).toBe('Cart');
134
+ });
135
+ });
@@ -0,0 +1,109 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { computed } from 'vue';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import { axe } from '../../../test/support/axe';
6
+ import { mountOptions } from '../../../test/support/mountBlock';
7
+ import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
8
+ import { STOREFRONT_KEY } from '../../../app/storefront/types';
9
+ import Block from '../Block.vue';
10
+ import mock from '../mock.json';
11
+
12
+ const NOT_SOLD = { ...DEMO_CART_LINES[0]!, soldInCurrency: false };
13
+ const SOLD = DEMO_CART_LINES[1]!;
14
+
15
+ afterEach(() => {
16
+ document.body.innerHTML = '';
17
+ vi.restoreAllMocks();
18
+ });
19
+
20
+ async function mountCart(lines = [NOT_SOLD, SOLD], checkoutStaysOpen = false) {
21
+ const demo = createDemoStorefront({ cartLines: lines });
22
+ const storefront = checkoutStaysOpen
23
+ ? { ...demo, cart: { ...demo.cart, checkoutUrl: computed(() => '/checkout/demo-cart') } }
24
+ : demo;
25
+ const options = mountOptions({ entry: { id: 'cart', data: { ...mock, variant: 'page' } } });
26
+ const wrapper = mount(Block, {
27
+ ...options,
28
+ attachTo: document.body,
29
+ global: {
30
+ ...options.global,
31
+ provide: { ...options.global.provide, [STOREFRONT_KEY]: storefront },
32
+ stubs: { ...options.global.stubs, transition: false, 'transition-group': false },
33
+ },
34
+ });
35
+ await flushPromises();
36
+ return { wrapper, storefront };
37
+ }
38
+
39
+ describe('a cart with a line not sold in its currency', () => {
40
+ it('holds Check out with the reason under it, rather than hiding it', async () => {
41
+ const { wrapper } = await mountCart();
42
+ const checkout = wrapper.findAll('button, a').find((node) => node.text().includes('Check out'));
43
+ expect(checkout).toBeDefined();
44
+ expect(checkout!.attributes('disabled')).toBeDefined();
45
+ const reasonId = checkout!.attributes('aria-describedby')!;
46
+ expect(wrapper.get(`[id="${reasonId}"]`).text()).toContain(NOT_SOLD.title);
47
+ expect(await axe(wrapper.element)).toHaveNoViolations();
48
+ });
49
+
50
+ it('says the total leaves the line out and turns its stepper off', async () => {
51
+ const { wrapper } = await mountCart();
52
+ expect(wrapper.get('[data-eldra-not-included]').text()).toBe('1 item not included');
53
+ const row = wrapper.get('[data-eldra-line-not-sold]').element.closest('li')!;
54
+ const steppers = [...row.querySelectorAll('[role="group"] button')] as HTMLButtonElement[];
55
+ expect(steppers.length).toBeGreaterThan(0);
56
+ expect(steppers.every((button) => button.disabled)).toBe(true);
57
+ });
58
+
59
+ it('checks out once the lines are removed', async () => {
60
+ const { wrapper, storefront } = await mountCart();
61
+ const assign = vi.fn();
62
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, assign } as Location);
63
+ const remove = wrapper
64
+ .get('[data-eldra-not-sold-notice]')
65
+ .findAll('button')
66
+ .find((node) => node.text() === 'Remove and check out')!;
67
+ await remove.trigger('click');
68
+ await flushPromises();
69
+ expect(storefront.cart.notSold.value).toEqual([]);
70
+ expect(assign).toHaveBeenCalledWith('/checkout/demo-cart');
71
+ });
72
+
73
+ it('4662896758: a second press while the first is working checks out once', async () => {
74
+ const { wrapper, storefront } = await mountCart();
75
+ const assign = vi.fn();
76
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, assign } as Location);
77
+ const removeNotSold = vi.spyOn(storefront.cart, 'removeNotSold');
78
+ const remove = wrapper
79
+ .get('[data-eldra-not-sold-notice]')
80
+ .findAll('button')
81
+ .find((node) => node.text() === 'Remove and check out')!;
82
+ await remove.trigger('click');
83
+ await remove.trigger('click');
84
+ await flushPromises();
85
+ expect(removeNotSold).toHaveBeenCalledTimes(1);
86
+ expect(assign).toHaveBeenCalledTimes(1);
87
+ });
88
+
89
+ it('stays on the cart when removing the lines leaves it empty', async () => {
90
+ const { wrapper, storefront } = await mountCart([NOT_SOLD], true);
91
+ const assign = vi.fn();
92
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, assign } as Location);
93
+ const remove = wrapper
94
+ .get('[data-eldra-not-sold-notice]')
95
+ .findAll('button')
96
+ .find((node) => node.text() === 'Remove and check out')!;
97
+ await remove.trigger('click');
98
+ await flushPromises();
99
+ expect(storefront.cart.lines.value).toEqual([]);
100
+ expect(assign).not.toHaveBeenCalled();
101
+ });
102
+
103
+ it('shows no note and a working Check out when every line is sold', async () => {
104
+ const { wrapper } = await mountCart([SOLD]);
105
+ expect(wrapper.find('[data-eldra-not-included]').exists()).toBe(false);
106
+ const checkout = wrapper.findAll('a').find((node) => node.text().includes('Check out'));
107
+ expect(checkout?.attributes('href')).toBe('/checkout/demo-cart');
108
+ });
109
+ });
@@ -203,7 +203,14 @@ const STEPPER_CLASSES = {
203
203
  </Link>
204
204
  <p v-else class="text-text text-base font-semibold">{{ line.title }}</p>
205
205
  <p v-if="line.variantLabel" class="text-muted text-body-sm">{{ line.variantLabel }}</p>
206
- <div v-if="line.quantity > 1" class="text-body-sm flex flex-wrap gap-x-1">
206
+ <p
207
+ v-if="line.soldInCurrency === false"
208
+ class="text-body-sm text-warning"
209
+ data-eldra-line-not-sold
210
+ >
211
+ {{ t('currency.notSoldIn', { currency: money.currency.value ?? '' }) }}
212
+ </p>
213
+ <div v-else-if="line.quantity > 1" class="text-body-sm flex flex-wrap gap-x-1">
207
214
  <Price
208
215
  :amount="money.minor(line.unitPrice)"
209
216
  size="sm"
@@ -219,7 +226,11 @@ const STEPPER_CLASSES = {
219
226
  :aria-busy="busy"
220
227
  >
221
228
  <VisuallyHidden>{{ t('cart.lineTotal') }}</VisuallyHidden>
222
- <Price :amount="money.minor(line.lineTotal)" class="inline" />
229
+ <Price
230
+ v-if="line.soldInCurrency !== false"
231
+ :amount="money.minor(line.lineTotal)"
232
+ class="inline"
233
+ />
223
234
  </div>
224
235
 
225
236
  <div
@@ -234,6 +245,7 @@ const STEPPER_CLASSES = {
234
245
  size="sm"
235
246
  :model-value="line.quantity"
236
247
  :max="line.max ?? undefined"
248
+ :disabled="line.soldInCurrency === false"
237
249
  :item-name="line.title"
238
250
  :classes="STEPPER_CLASSES"
239
251
  @change="(value: number) => void onQuantity(line, value)"
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue';
3
+ import { Button } from '@eldrajs/ui';
4
+ import { useI18n } from 'vue-i18n';
5
+ import { useStorefront } from '../../../app/composables/useStorefront';
6
+ import EldraIcon from '../../../app/components/EldraIcon.vue';
7
+ import EldraRouterLink from '../../../app/components/EldraRouterLink.vue';
8
+ import { useUiId } from '../../../app/composables/useUiId';
9
+ import { isInternalHref, safeHref } from '../../../app/utils/links';
10
+ import { useNotSoldSentence } from './notSold';
11
+
12
+ const { t } = useI18n();
13
+ const cart = useStorefront().cart;
14
+
15
+ const checkoutHref = computed(() => safeHref(cart.checkoutUrl.value));
16
+ const checkoutAs = computed(() =>
17
+ checkoutHref.value !== null && isInternalHref(checkoutHref.value) ? EldraRouterLink : undefined
18
+ );
19
+ /** Held, not hidden, while a line has no price in the cart's currency, so the reason sits where the shopper looks. */
20
+ const held = computed(() => cart.notSold.value.length > 0);
21
+ const reason = useNotSoldSentence(cart);
22
+ const reasonId = `cart-checkout-held-${useUiId()}`;
23
+ </script>
24
+
25
+ <template>
26
+ <Button
27
+ v-if="checkoutHref || held"
28
+ variant="primary"
29
+ size="lg"
30
+ block
31
+ :href="held ? undefined : (checkoutHref ?? undefined)"
32
+ :as="held ? undefined : checkoutAs"
33
+ :disabled="held"
34
+ :aria-describedby="held ? reasonId : undefined"
35
+ @click="cart.beginCheckout()"
36
+ >
37
+ <template #leadingIcon>
38
+ <EldraIcon name="lock" size="sm" />
39
+ </template>
40
+ {{ t('cart.checkout') }}
41
+ </Button>
42
+ <p v-if="held" :id="reasonId" class="text-muted text-body-sm text-center">
43
+ {{ reason }}
44
+ </p>
45
+ </template>
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ import { Button, Notice } from '@eldrajs/ui';
3
+ import { useI18n } from 'vue-i18n';
4
+ import { useStorefront } from '../../../app/composables/useStorefront';
5
+ import { useStorefrontFeedback } from '../../../app/composables/useStorefrontFeedback';
6
+
7
+ const cart = useStorefront().cart;
8
+ const feedback = useStorefrontFeedback();
9
+ const { t } = useI18n();
10
+
11
+ async function tryAgain(): Promise<void> {
12
+ const failure = await cart.reload();
13
+ if (failure !== null) feedback.report(failure, { id: 'cart-load' });
14
+ }
15
+ </script>
16
+
17
+ <template>
18
+ <Notice
19
+ v-if="cart.loadFailed.value"
20
+ tone="danger"
21
+ :text="t('cart.loadFailed')"
22
+ class="mb-4"
23
+ data-eldra-cart-load-failed
24
+ >
25
+ <template #actions>
26
+ <Button
27
+ variant="outline"
28
+ size="sm"
29
+ type="button"
30
+ :loading="cart.pending.value"
31
+ @click="tryAgain"
32
+ >
33
+ {{ t('cart.tryAgain') }}
34
+ </Button>
35
+ </template>
36
+ </Notice>
37
+ </template>
@@ -0,0 +1,69 @@
1
+ <script setup lang="ts">
2
+ import { Button, Notice } from '@eldrajs/ui';
3
+ import { useI18n } from 'vue-i18n';
4
+ import { useStorefront } from '../../../app/composables/useStorefront';
5
+ import { useStorefrontFeedback } from '../../../app/composables/useStorefrontFeedback';
6
+ import { safeHref } from '../../../app/utils/links';
7
+ import { useNotSoldSentence } from './notSold';
8
+
9
+ const storefront = useStorefront();
10
+ const cart = storefront.cart;
11
+ const feedback = useStorefrontFeedback();
12
+ const { t } = useI18n();
13
+ const sentence = useNotSoldSentence(cart);
14
+
15
+ let leaving = false;
16
+
17
+ async function checkoutWithout(): Promise<void> {
18
+ if (leaving) return;
19
+ leaving = true;
20
+ try {
21
+ await removeThenCheckout();
22
+ } finally {
23
+ leaving = false;
24
+ }
25
+ }
26
+
27
+ async function removeThenCheckout(): Promise<void> {
28
+ const failure = await cart.removeNotSold();
29
+ if (failure !== null) {
30
+ feedback.report(failure);
31
+ return;
32
+ }
33
+ const checkout = safeHref(cart.checkoutUrl.value);
34
+ if (checkout !== null && cart.lines.value.length > 0) {
35
+ cart.beginCheckout();
36
+ window.location.assign(checkout);
37
+ }
38
+ }
39
+ </script>
40
+
41
+ <template>
42
+ <Notice
43
+ tone="warning"
44
+ :text="sentence"
45
+ :classes="{ content: 'text-start' }"
46
+ data-eldra-not-sold-notice
47
+ >
48
+ <template #actions>
49
+ <Button
50
+ variant="primary"
51
+ size="sm"
52
+ type="button"
53
+ :loading="cart.pending.value"
54
+ @click="checkoutWithout"
55
+ >
56
+ {{ t('currency.checkoutWithout') }}
57
+ </Button>
58
+ <Button
59
+ v-if="storefront.currency.base"
60
+ variant="outline"
61
+ size="sm"
62
+ type="button"
63
+ @click="storefront.currency.chooseBase()"
64
+ >
65
+ {{ t('currency.shopIn', { currency: storefront.currency.base }) }}
66
+ </Button>
67
+ </template>
68
+ </Notice>
69
+ </template>