@revenexx/cover 0.10.1 → 0.12.0
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/app/api/account.ts +4 -0
- package/app/assets/css/cover.css +9 -0
- package/app/components/RevenexxForm.vue +4 -0
- package/app/components/account/AccountSidebar.vue +2 -5
- package/app/components/account/carts/AccountCartsTable.vue +4 -2
- package/app/components/account/dashboard/AccountDashboardKpis.vue +74 -34
- package/app/components/account/dashboard/AccountDashboardQuickActions.vue +24 -6
- package/app/components/account/organization/AccountOrganization.vue +3 -1
- package/app/components/account/team/AccountTeam.vue +32 -7
- package/app/components/auth/AuthForgotPasswordPanel.vue +9 -4
- package/app/components/auth/AuthLoginPanel.vue +75 -18
- package/app/components/auth/AuthRegisterPanel.vue +1 -1
- package/app/components/cart/actions/CartSaveToListModal.vue +5 -0
- package/app/components/cart/item/CartItem.vue +17 -75
- package/app/components/cart/position/CartPosition.vue +17 -30
- package/app/components/cart/quote/CartQuoteRequestModal.vue +9 -1
- package/app/components/cart/switcher/CartSwitcher.vue +5 -2
- package/app/components/category/view/GridView.vue +10 -1
- package/app/components/category/view/ListView.vue +10 -1
- package/app/components/checkout/confirmation/CheckoutConfirmationActions.vue +2 -0
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +4 -4
- package/app/components/checkout/onepage/CheckoutDeliverySection.vue +18 -2
- package/app/components/checkout/onepage/CheckoutGate.vue +2 -0
- package/app/components/checkout/onepage/CheckoutOnePageView.vue +1 -1
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +10 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +7 -1
- package/app/components/layout/Region.vue +13 -0
- package/app/components/layout/footer/Footer.vue +8 -0
- package/app/components/layout/header/AppBar.vue +4 -3
- package/app/components/layout/header/MainNav.vue +3 -3
- package/app/components/listing/ListingResults.vue +3 -1
- package/app/components/product/card/Compact.vue +10 -1
- package/app/components/product/detail/ProductDetailAddToCart.vue +51 -18
- package/app/components/product/detail/ProductDetailIdentity.vue +1 -1
- package/app/components/product/detail/ProductDetailPriceRequest.vue +1 -1
- package/app/components/product/detail/ProductDetailSaveToList.vue +10 -0
- package/app/composables/useAccountDashboard.ts +0 -10
- package/app/composables/useAccountNavigation.ts +35 -0
- package/app/composables/useAuthStore.ts +6 -2
- package/app/composables/useCategoryListing.ts +6 -0
- package/app/composables/useCheckoutOnePage.ts +21 -2
- package/app/composables/useMasterDataEditable.ts +23 -0
- package/app/composables/useProductCard.ts +29 -2
- package/app/composables/useProductListing.ts +79 -0
- package/app/composables/useQuantityStepper.ts +90 -0
- package/app/composables/useQuickActions.ts +35 -0
- package/app/composables/useRoleGrants.ts +32 -0
- package/app/composables/useSearchListing.ts +4 -0
- package/app/composables/useThemeEvents.ts +144 -0
- package/app/config/accountDashboard.ts +26 -0
- package/app/config/quickActions.ts +40 -5
- package/app/interfaces/account/dashboard.ts +2 -0
- package/app/interfaces/auth.ts +25 -4
- package/app/interfaces/quantity-stepper.ts +17 -0
- package/app/interfaces/shopSettings.ts +84 -0
- package/app/layouts/default.vue +19 -10
- package/app/layouts/focus.vue +28 -7
- package/app/middleware/checkout-guard.ts +7 -1
- package/app/pages/punchout/transfer.vue +22 -0
- package/app/plugins/theme-events.client.ts +132 -0
- package/app/shared/themeEvents.ts +445 -0
- package/i18n/locales/de/account.json +7 -0
- package/i18n/locales/de/auth.json +42 -2
- package/i18n/locales/de/cart.json +4 -2
- package/i18n/locales/de/checkout.json +2 -1
- package/i18n/locales/de/common.json +2 -0
- package/i18n/locales/de/cover.json +44 -0
- package/i18n/locales/de/editor.json +47 -1
- package/i18n/locales/en/account.json +7 -0
- package/i18n/locales/en/auth.json +42 -2
- package/i18n/locales/en/cart.json +4 -2
- package/i18n/locales/en/checkout.json +2 -1
- package/i18n/locales/en/common.json +2 -0
- package/i18n/locales/en/cover.json +44 -0
- package/i18n/locales/en/editor.json +47 -1
- package/nuxt.config.ts +15 -1
- package/package.json +5 -2
- package/server/api/account/orders/[id]/cancel.post.ts +1 -1
- package/server/api/account/orders/[id]/messages.get.ts +1 -1
- package/server/api/account/orders/[id]/messages.post.ts +1 -1
- package/server/api/account/orders/[id]/return.post.ts +1 -0
- package/server/api/account/orders/[id].get.ts +1 -1
- package/server/api/account/pending-approvals/index.get.ts +1 -0
- package/server/api/account/profile.get.ts +3 -1
- package/server/api/auth/login.post.ts +22 -3
- package/server/api/auth/magic-link.put.ts +6 -1
- package/server/api/auth/otp.put.ts +6 -1
- package/server/api/carts/[id]/activate.post.ts +8 -0
- package/server/api/carts/[id]/index.delete.ts +3 -0
- package/server/api/carts/[id]/index.put.ts +1 -0
- package/server/api/carts/[id]/items.post.ts +1 -0
- package/server/api/carts/index.post.ts +4 -0
- package/server/api/orders/index.post.ts +33 -0
- package/server/api/quick-actions.get.ts +6 -38
- package/server/interfaces/auth.ts +10 -1
- package/server/middleware/buyer-principal.ts +18 -0
- package/server/routes/punchout/start.get.ts +6 -15
- package/server/services/ApiAddressBookService.ts +43 -1
- package/server/services/ApiAuthService.ts +119 -22
- package/server/services/ApiCartService.ts +67 -32
- package/server/services/ApiOrganizationService.ts +7 -2
- package/server/services/ApiTeamService.ts +93 -21
- package/server/services/MockAuthService.ts +21 -2
- package/server/utils/buyerIdentity.ts +168 -0
- package/server/utils/cartOwnership.ts +67 -0
- package/server/utils/liveOrderLists.ts +50 -23
- package/server/utils/liveOrders.ts +39 -24
- package/server/utils/livePrices.ts +7 -15
- package/server/utils/masterData.ts +29 -0
- package/server/utils/passwordlessSignIn.ts +13 -4
- package/server/utils/pendingApprovals.ts +29 -7
- package/server/utils/procurementCheckout.ts +2 -0
- package/server/utils/quickActionCatalogue.ts +53 -0
- package/server/utils/revenexxSdk.ts +116 -2
- package/server/utils/shopSettings.ts +5 -0
|
@@ -35,6 +35,40 @@ const quantityInvalid = computed(() => quantity.value < 1);
|
|
|
35
35
|
const quantityExceeded = computed(() =>
|
|
36
36
|
currentCartQuantity.value + quantity.value > effectiveMaxQuantity.value,
|
|
37
37
|
);
|
|
38
|
+
/**
|
|
39
|
+
* What this buy box may still add: the line ceiling less what the cart already
|
|
40
|
+
* holds. Never below 1 — a line that is already full keeps the stepper at 1 and
|
|
41
|
+
* lets add-to-cart explain why it refuses.
|
|
42
|
+
*/
|
|
43
|
+
const remainingQuantity = computed(() =>
|
|
44
|
+
Math.max(1, effectiveMaxQuantity.value - currentCartQuantity.value),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Same stepper rules as the cart page and the mini-cart; here the quantity is
|
|
48
|
+
// the amount to add, not a cart line.
|
|
49
|
+
const {
|
|
50
|
+
inputValue: quantityInput,
|
|
51
|
+
notice: quantityNotice,
|
|
52
|
+
canDecrease,
|
|
53
|
+
decrease,
|
|
54
|
+
increase,
|
|
55
|
+
onInput: onQuantityInput,
|
|
56
|
+
commit: commitQuantity,
|
|
57
|
+
} = useQuantityStepper({
|
|
58
|
+
quantity: () => quantity.value,
|
|
59
|
+
max: () => remainingQuantity.value,
|
|
60
|
+
apply: (next) => {
|
|
61
|
+
quantity.value = next;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Adding to the cart shrinks what is left to add; an amount that no longer fits
|
|
66
|
+
// follows it down, so the next + never makes the number drop.
|
|
67
|
+
watch(remainingQuantity, (remaining) => {
|
|
68
|
+
if (quantity.value > remaining) {
|
|
69
|
+
quantity.value = remaining;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
38
72
|
|
|
39
73
|
let exceededTimer: ReturnType<typeof setTimeout> | null = null;
|
|
40
74
|
const showQuantityExceeded = ref(false);
|
|
@@ -76,17 +110,6 @@ function buildPriceTiers(prices: { [key: string]: number }[]): CartItemPriceTier
|
|
|
76
110
|
.sort((a, b) => a.minQuantity - b.minQuantity);
|
|
77
111
|
}
|
|
78
112
|
|
|
79
|
-
function setQuantity(next: number) {
|
|
80
|
-
quantity.value = Math.max(1, Math.min(next, 999999));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function onQuantityInput(event: Event) {
|
|
84
|
-
const input = event.target as HTMLInputElement;
|
|
85
|
-
const sanitized = input.value.replace(/[^0-9]/g, "").slice(0, 6);
|
|
86
|
-
input.value = sanitized;
|
|
87
|
-
quantity.value = parseInt(sanitized) || 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
113
|
function addToCart() {
|
|
91
114
|
if (quantityInvalid.value) {
|
|
92
115
|
return;
|
|
@@ -146,33 +169,37 @@ onUnmounted(() => {
|
|
|
146
169
|
:icon="icon('minus')"
|
|
147
170
|
color="neutral"
|
|
148
171
|
variant="ghost"
|
|
172
|
+
class="min-h-11 min-w-11 justify-center lg:min-h-0 lg:min-w-0"
|
|
149
173
|
tabindex="0"
|
|
150
|
-
:disabled="
|
|
174
|
+
:disabled="!canDecrease"
|
|
151
175
|
:aria-label="t('cart.item.ariaDecreaseQuantity', { name: product.name })"
|
|
152
|
-
@click="
|
|
176
|
+
@click="decrease"
|
|
153
177
|
/>
|
|
154
178
|
<input
|
|
155
|
-
|
|
179
|
+
v-model="quantityInput"
|
|
156
180
|
type="text"
|
|
157
181
|
inputmode="numeric"
|
|
158
|
-
class="w-12 text-center text-sm font-medium bg-transparent
|
|
182
|
+
class="w-12 self-stretch text-center text-sm font-medium bg-transparent
|
|
159
183
|
focus:outline-none"
|
|
160
184
|
:aria-label="t('product.detail.quantity')"
|
|
161
185
|
@input="onQuantityInput"
|
|
186
|
+
@keydown.enter.prevent="commitQuantity"
|
|
187
|
+
@blur="commitQuantity"
|
|
162
188
|
>
|
|
163
189
|
<UButton
|
|
164
190
|
:icon="icon('plus')"
|
|
165
191
|
color="neutral"
|
|
166
192
|
variant="ghost"
|
|
193
|
+
class="min-h-11 min-w-11 justify-center lg:min-h-0 lg:min-w-0"
|
|
167
194
|
tabindex="0"
|
|
168
195
|
:aria-label="t('cart.item.ariaIncreaseQuantity', { name: product.name })"
|
|
169
|
-
@click="
|
|
196
|
+
@click="increase"
|
|
170
197
|
/>
|
|
171
198
|
</div>
|
|
172
199
|
<UButton
|
|
173
200
|
:icon="icon('cart')"
|
|
174
201
|
size="lg"
|
|
175
|
-
class="flex-1 justify-center"
|
|
202
|
+
class="flex-1 justify-center min-h-11 lg:min-h-0"
|
|
176
203
|
tabindex="0"
|
|
177
204
|
:label="t('product.actions.addToCart')"
|
|
178
205
|
:disabled="quantityInvalid"
|
|
@@ -182,11 +209,17 @@ onUnmounted(() => {
|
|
|
182
209
|
</div>
|
|
183
210
|
|
|
184
211
|
<UiFeedbackErrorBoundary
|
|
185
|
-
v-if="showQuantityExceeded"
|
|
212
|
+
v-if="showQuantityExceeded || quantityNotice === 'max'"
|
|
186
213
|
:title="t('product.actions.maxQuantityReachedTitle', { count: currentCartQuantity })"
|
|
187
214
|
:description="t('product.actions.maxQuantityReachedDescription', { max: effectiveMaxQuantity })"
|
|
188
215
|
:show-retry="false"
|
|
189
216
|
/>
|
|
217
|
+
<UiFeedbackErrorBoundary
|
|
218
|
+
v-if="quantityNotice === 'invalid'"
|
|
219
|
+
:title="t('product.actions.invalidQuantityTitle')"
|
|
220
|
+
:description="t('product.actions.invalidQuantityDescription')"
|
|
221
|
+
:show-retry="false"
|
|
222
|
+
/>
|
|
190
223
|
|
|
191
224
|
<!-- B2B incentives -->
|
|
192
225
|
<ul
|
|
@@ -74,7 +74,7 @@ async function copySku(): Promise<void> {
|
|
|
74
74
|
<button
|
|
75
75
|
type="button"
|
|
76
76
|
tabindex="0"
|
|
77
|
-
class="mt-2 inline-flex items-center gap-1.5 text-sm text-muted
|
|
77
|
+
class="mt-2 inline-flex items-center gap-1.5 min-h-11 lg:min-h-0 text-sm text-muted
|
|
78
78
|
hover:text-highlighted transition-colors cursor-pointer"
|
|
79
79
|
:title="t('product.detail.copySku')"
|
|
80
80
|
@click="copySku"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { OrderList, OrderListPosition } from "../../../interfaces/account/order-lists";
|
|
3
|
+
import { cartEcommerce } from "../../../shared/themeEvents";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* "Add to order list" on the product detail page: shows on how many
|
|
@@ -27,6 +28,12 @@ const { icon } = useIcons();
|
|
|
27
28
|
const { t } = useI18n();
|
|
28
29
|
const toast = useToast();
|
|
29
30
|
const auth = useAuthStore();
|
|
31
|
+
const themeEvents = useThemeEvents();
|
|
32
|
+
|
|
33
|
+
/** `add_to_orderlist` — the article went onto a list (not off one). */
|
|
34
|
+
function reportAdded(): void {
|
|
35
|
+
themeEvents.emit("add_to_orderlist", { ecommerce: cartEcommerce([buildPosition()]) });
|
|
36
|
+
}
|
|
30
37
|
|
|
31
38
|
const open = ref(false);
|
|
32
39
|
const busyListId = ref<string | null>(null);
|
|
@@ -91,6 +98,7 @@ async function toggle(list: OrderList): Promise<void> {
|
|
|
91
98
|
});
|
|
92
99
|
await refresh();
|
|
93
100
|
if (!removing) {
|
|
101
|
+
reportAdded();
|
|
94
102
|
lastUsedId.value = list.id;
|
|
95
103
|
localStorage.setItem(LAST_USED_STORAGE, list.id);
|
|
96
104
|
}
|
|
@@ -122,6 +130,7 @@ async function createAndAdd(): Promise<void> {
|
|
|
122
130
|
body: { name, kind: "shopping", public: false, positions: [buildPosition()] },
|
|
123
131
|
});
|
|
124
132
|
await refresh();
|
|
133
|
+
reportAdded();
|
|
125
134
|
lastUsedId.value = created.id;
|
|
126
135
|
localStorage.setItem(LAST_USED_STORAGE, created.id);
|
|
127
136
|
newListName.value = "";
|
|
@@ -163,6 +172,7 @@ async function createAndAdd(): Promise<void> {
|
|
|
163
172
|
color="neutral"
|
|
164
173
|
variant="outline"
|
|
165
174
|
size="lg"
|
|
175
|
+
class="min-h-11 min-w-11 justify-center lg:min-h-0 lg:min-w-0"
|
|
166
176
|
tabindex="0"
|
|
167
177
|
:icon="icon('order-list')"
|
|
168
178
|
:aria-label="t('orderLists.saveTo.button')"
|
|
@@ -82,22 +82,12 @@ export const useAccountDashboard = () => {
|
|
|
82
82
|
return Number.isNaN(parsed.getTime()) ? value : d(parsed, { dateStyle: "medium" });
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
/* ---- quick actions ----------------------------------------------------- */
|
|
86
|
-
const quickActions = [
|
|
87
|
-
{ to: "/account/direct-order", labelKey: "directOrder.title", token: "direct-order" },
|
|
88
|
-
{ to: "/account/orders", labelKey: "account.nav.orders", token: "orders" },
|
|
89
|
-
{ to: "/account/order-lists", labelKey: "account.nav.orderLists", token: "order-list" },
|
|
90
|
-
{ to: "/account/requisitions", labelKey: "account.nav.requisitions", token: "check" },
|
|
91
|
-
{ to: "/account/cost-centers", labelKey: "account.nav.costCenters", token: "briefcase" },
|
|
92
|
-
];
|
|
93
|
-
|
|
94
85
|
return {
|
|
95
86
|
t,
|
|
96
87
|
auth,
|
|
97
88
|
formatCurrency,
|
|
98
89
|
formatDate,
|
|
99
90
|
statusColors,
|
|
100
|
-
quickActions,
|
|
101
91
|
ordersPending,
|
|
102
92
|
contextPending,
|
|
103
93
|
requisitionsPending,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComputedRef } from "vue";
|
|
2
|
+
|
|
3
|
+
import type { AccountNavGroup } from "../config/navigation";
|
|
4
|
+
|
|
5
|
+
import { accountNavigation } from "../config/navigation";
|
|
6
|
+
|
|
7
|
+
export interface UseAccountNavigationReturn {
|
|
8
|
+
/** The sidebar groups in effect for this request. */
|
|
9
|
+
readonly navigation: ComputedRef<AccountNavGroup[]>;
|
|
10
|
+
/** True when a theme published the tenant's own account menu for this request. */
|
|
11
|
+
readonly isTenantAuthored: ComputedRef<boolean>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The account navigation in effect, resolved in the same priority order the
|
|
16
|
+
* header uses (see MainNav):
|
|
17
|
+
* 1. per-request useState — a theme publishing the tenant's LIVE account
|
|
18
|
+
* menu (request-scoped, so multi-tenant safe)
|
|
19
|
+
* 2. app.config override — a theme's shipped defaults (custom-theme)
|
|
20
|
+
* 3. the layer's built-in full B2B tree
|
|
21
|
+
* The sidebar renders it; the quick-action catalogue is limited by it.
|
|
22
|
+
*/
|
|
23
|
+
export function useAccountNavigation(): UseAccountNavigationReturn {
|
|
24
|
+
const appConfig = useAppConfig();
|
|
25
|
+
const liveAccountNavigation = useState<AccountNavGroup[] | null>("cover:nav:accountNavigation", () => null);
|
|
26
|
+
|
|
27
|
+
const navigation = computed<AccountNavGroup[]>(() =>
|
|
28
|
+
liveAccountNavigation.value
|
|
29
|
+
?? (appConfig.accountNavigation as AccountNavGroup[] | undefined)
|
|
30
|
+
?? accountNavigation,
|
|
31
|
+
);
|
|
32
|
+
const isTenantAuthored = computed(() => liveAccountNavigation.value !== null);
|
|
33
|
+
|
|
34
|
+
return { navigation, isTenantAuthored };
|
|
35
|
+
}
|
|
@@ -40,6 +40,10 @@ function mapAuthError(err: unknown, context: "login" | "recovery" | "register" =
|
|
|
40
40
|
: "auth.login.errors.invalidCredentials";
|
|
41
41
|
case "user_blocked":
|
|
42
42
|
return "auth.login.errors.accountBlocked";
|
|
43
|
+
case "organization_blocked":
|
|
44
|
+
return "auth.login.errors.organizationBlocked";
|
|
45
|
+
case "identifier_not_offered":
|
|
46
|
+
return "auth.login.errors.identifierNotOffered";
|
|
43
47
|
case "general_rate_limit_exceeded":
|
|
44
48
|
return context === "recovery"
|
|
45
49
|
? "auth.recovery.errors.rateLimited"
|
|
@@ -112,13 +116,13 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
112
116
|
}
|
|
113
117
|
};
|
|
114
118
|
|
|
115
|
-
const login = async ({
|
|
119
|
+
const login = async ({ identifier, password }: LoginInput) => {
|
|
116
120
|
loading.value = true;
|
|
117
121
|
error.value = null;
|
|
118
122
|
try {
|
|
119
123
|
const result = await $fetch<{ user: AuthUser; session: StoredSession }>("/api/auth/login", {
|
|
120
124
|
method: "POST",
|
|
121
|
-
body: {
|
|
125
|
+
body: { identifier, password },
|
|
122
126
|
});
|
|
123
127
|
user.value = result.user;
|
|
124
128
|
session.value = result.session;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useDebounceFn } from "@vueuse/core";
|
|
2
2
|
|
|
3
|
+
import { categoryListId } from "../shared/themeEvents";
|
|
4
|
+
|
|
3
5
|
export interface CategoryListingOptions {
|
|
4
6
|
/** Resolved category slug the listing is pinned to. */
|
|
5
7
|
readonly categorySlug: () => string;
|
|
@@ -58,6 +60,10 @@ export const useCategoryListing = (options: CategoryListingOptions) => {
|
|
|
58
60
|
facetFields: () => (subcategorySlug.value
|
|
59
61
|
? ["manufacturer", "available"]
|
|
60
62
|
: ["subcategory", "manufacturer", "available"]),
|
|
63
|
+
// Every shown page of the category is a product list view.
|
|
64
|
+
listEvent: () => (categorySlug.value
|
|
65
|
+
? { event: "view_item_list", listId: categoryListId(categorySlug.value, subcategorySlug.value) }
|
|
66
|
+
: null),
|
|
61
67
|
});
|
|
62
68
|
|
|
63
69
|
const title = computed(() =>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { checkoutApi } from "../api/checkout";
|
|
2
|
+
import type { CartCalculation } from "../interfaces/cart-calculation";
|
|
2
3
|
import type { CheckoutOnePageForm, CheckoutProfile } from "../interfaces/checkout";
|
|
4
|
+
import { browserSession, purchaseFromCart, stashPurchase } from "../shared/themeEvents";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Who is checking out:
|
|
@@ -56,6 +58,9 @@ export function useCheckoutOnePage() {
|
|
|
56
58
|
const cart = useCartStore();
|
|
57
59
|
const { settings } = useB2BContext();
|
|
58
60
|
const psp = usePspCheckout();
|
|
61
|
+
// The server-calculated totals the summary shows (shared state) — read when
|
|
62
|
+
// an order is placed, so the confirmation can report what was bought.
|
|
63
|
+
const calculation = useState<CartCalculation | null>("cart-calculation", () => null);
|
|
59
64
|
const { data: profile, refresh: refreshProfile } = useCheckoutProfileSource();
|
|
60
65
|
const profileLoading = computed(() => profile.value === null);
|
|
61
66
|
|
|
@@ -293,7 +298,7 @@ export function useCheckoutOnePage() {
|
|
|
293
298
|
// (approval limits, quantity rules) against the same data.
|
|
294
299
|
items: cart.items,
|
|
295
300
|
...(isGuest.value ? { contactEmail: guestContact.value.email } : {}),
|
|
296
|
-
...(
|
|
301
|
+
...(form.value.deliveryMethod ? { deliveryMethod: f.deliveryMethod } : {}),
|
|
297
302
|
...(f.requestedDate ? { requestedDate: f.requestedDate } : {}),
|
|
298
303
|
...(f.deliveryNote ? { deliveryNote: f.deliveryNote } : {}),
|
|
299
304
|
...(f.partialDelivery ? { partialDelivery: true } : {}),
|
|
@@ -301,7 +306,7 @@ export function useCheckoutOnePage() {
|
|
|
301
306
|
...(f.quoteNumber ? { quoteNumber: f.quoteNumber } : {}),
|
|
302
307
|
...(f.noOrderConfirmation ? { noOrderConfirmation: true } : {}),
|
|
303
308
|
...(f.orderNote ? { orderNote: f.orderNote } : {}),
|
|
304
|
-
...(
|
|
309
|
+
...(form.value.promoCode ? { promoCode: f.promoCode } : {}),
|
|
305
310
|
};
|
|
306
311
|
}
|
|
307
312
|
|
|
@@ -336,6 +341,20 @@ export function useCheckoutOnePage() {
|
|
|
336
341
|
}
|
|
337
342
|
}
|
|
338
343
|
|
|
344
|
+
// The order as it is placed, kept for the confirmation page's
|
|
345
|
+
// `purchase` event — the cart is cleared below, and a PSP redirect
|
|
346
|
+
// leaves this page altogether. Lines and money only, never who.
|
|
347
|
+
if (import.meta.client) {
|
|
348
|
+
stashPurchase(
|
|
349
|
+
browserSession(),
|
|
350
|
+
purchaseFromCart(cart.items, calculation.value?.totals, { subtotal: cart.subtotal, tax: cart.tax }, {
|
|
351
|
+
...(form.value.paymentMethod ? { payment_type: String(form.value.paymentMethod).slice(0, 64) } : {}),
|
|
352
|
+
...(form.value.deliveryMethod ? { shipping_tier: String(form.value.deliveryMethod).slice(0, 64) } : {}),
|
|
353
|
+
...(form.value.promoCode ? { coupon: String(form.value.promoCode).slice(0, 64) } : {}),
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
339
358
|
const order = await $fetch(checkoutApi.orders(), {
|
|
340
359
|
method: "POST",
|
|
341
360
|
body: payload,
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { ComputedRef } from "vue";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The permission the buyer's role must grant for each area — the same map the
|
|
5
|
+
* BFF refuses the write by. The profile is the buyer's own and needs none.
|
|
6
|
+
*/
|
|
7
|
+
const AREA_PERMISSION: Record<"addresses" | "profile" | "organization" | "team", string | null> = {
|
|
8
|
+
addresses: "addresses.manage",
|
|
9
|
+
profile: null,
|
|
10
|
+
organization: "organization.manage",
|
|
11
|
+
team: "contacts.manage",
|
|
12
|
+
};
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* Whether this buyer may change this part of their own master data.
|
|
5
16
|
*
|
|
@@ -10,10 +21,22 @@ import type { ComputedRef } from "vue";
|
|
|
10
21
|
*
|
|
11
22
|
* `team` follows the company rather than the addresses: a merchant who keeps the
|
|
12
23
|
* company record keeps its people too.
|
|
24
|
+
*
|
|
25
|
+
* Two halves: what the merchant left in buyers' hands, and what this buyer's
|
|
26
|
+
* own role grants (RAD-155) — managing the people takes `contacts.manage`.
|
|
13
27
|
*/
|
|
14
28
|
export function useMasterDataEditable(area: "addresses" | "profile" | "organization" | "team"): ComputedRef<boolean> {
|
|
15
29
|
const { account } = useShopSettings();
|
|
30
|
+
const auth = useAuthStore();
|
|
16
31
|
return computed(() => {
|
|
32
|
+
// The role half: a buyer whose role does not grant the change is not
|
|
33
|
+
// offered it. Only where the platform stated the grants — the demo
|
|
34
|
+
// personas carry none, and the setting alone decides for them.
|
|
35
|
+
const permission = AREA_PERMISSION[area];
|
|
36
|
+
const granted = auth.user?.permissions;
|
|
37
|
+
if (permission && Array.isArray(granted) && !granted.includes(permission)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
17
40
|
switch (account.value?.selfService) {
|
|
18
41
|
case "none":
|
|
19
42
|
return false;
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import type { ProductList } from "../interfaces/product-list";
|
|
2
|
+
import { listingProductToItem } from "../shared/themeEvents";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/** Where a card is shown, for the `select_item` it reports when opened. */
|
|
5
|
+
export interface ProductCardListContext {
|
|
6
|
+
listId?: string;
|
|
7
|
+
/** 1-based position in that list. */
|
|
8
|
+
position?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useProductCard(
|
|
12
|
+
getProduct: () => ProductList,
|
|
13
|
+
getList?: () => ProductCardListContext | undefined,
|
|
14
|
+
) {
|
|
4
15
|
const url = computed(() => useProductUrl(getProduct()).value);
|
|
5
16
|
const { getImage } = useProductImage();
|
|
17
|
+
const { useOffer } = useOffers();
|
|
18
|
+
const { offer } = useOffer(() => getProduct().id);
|
|
19
|
+
const events = useThemeEvents();
|
|
20
|
+
|
|
21
|
+
/** Report that the buyer opened this product from the list it was shown in. */
|
|
22
|
+
function select(): void {
|
|
23
|
+
const list = getList?.();
|
|
24
|
+
const item = listingProductToItem(getProduct(), {
|
|
25
|
+
position: list?.position,
|
|
26
|
+
listId: list?.listId,
|
|
27
|
+
prices: offer.value?.prices,
|
|
28
|
+
});
|
|
29
|
+
events.emit("select_item", {
|
|
30
|
+
ecommerce: { items: [item], ...(list?.listId ? { list_id: list.listId } : {}) },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
6
33
|
|
|
7
|
-
return { url, getImage };
|
|
34
|
+
return { url, getImage, select };
|
|
8
35
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { searchApi } from "../api/search";
|
|
2
2
|
import type { ProductList } from "../interfaces/product-list";
|
|
3
3
|
import type { PriceRange, SearchFacet } from "../interfaces/search-facets";
|
|
4
|
+
import { listingProductToItem } from "../shared/themeEvents";
|
|
4
5
|
|
|
5
6
|
export interface ProductListingOptions {
|
|
6
7
|
/** Unique fetch key per listing surface (e.g. "search", "category"). */
|
|
@@ -16,8 +17,22 @@ export interface ProductListingOptions {
|
|
|
16
17
|
facetFields?: MaybeRefOrGetter<string[]>;
|
|
17
18
|
/** Run the first request even with an empty query (category pages). */
|
|
18
19
|
allowEmptyQuery?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* How a shown page of results is reported to the theme event contract:
|
|
22
|
+
* a category listing is a `view_item_list`, the search page a `search`.
|
|
23
|
+
* Omitted or null → nothing is reported (e.g. the editor's sample listing).
|
|
24
|
+
*/
|
|
25
|
+
listEvent?: () => ListingEvent | null;
|
|
19
26
|
}
|
|
20
27
|
|
|
28
|
+
/** What a listing reports itself as (theme-events/1). */
|
|
29
|
+
export type ListingEvent =
|
|
30
|
+
| { event: "view_item_list"; listId: string }
|
|
31
|
+
| { event: "search"; listId: string; term: string };
|
|
32
|
+
|
|
33
|
+
/** How long a reported listing waits for its prices before it goes out without them. */
|
|
34
|
+
const LIST_EVENT_OFFER_WAIT_MS = 4000;
|
|
35
|
+
|
|
21
36
|
const DEFAULT_FACETS = ["category", "subcategory", "manufacturer", "available"];
|
|
22
37
|
|
|
23
38
|
/** Every sort the layer knows, and the i18n key that names it. */
|
|
@@ -200,6 +215,68 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
200
215
|
}
|
|
201
216
|
}, { immediate: true });
|
|
202
217
|
|
|
218
|
+
/* ---- theme events --------------------------------------------- */
|
|
219
|
+
// Reported once per shown page of results, after the offers for it have
|
|
220
|
+
// settled — a list view without prices tells a tag little. Client-only:
|
|
221
|
+
// `useThemeEvents()` is a no-op on the server and in the editor.
|
|
222
|
+
if (import.meta.client && options.listEvent) {
|
|
223
|
+
const themeEvents = useThemeEvents();
|
|
224
|
+
const offerCache = useState<Record<string, { prices: { [key: string]: number }[] }>>("offers:cache", () => ({}));
|
|
225
|
+
const offerAttempted = useState<Record<string, boolean>>("offers:attempted", () => ({}));
|
|
226
|
+
const offersSettled = (ids: string[]): Promise<void> => new Promise((resolve) => {
|
|
227
|
+
const settled = () => ids.every(id => id in offerCache.value || offerAttempted.value[id]);
|
|
228
|
+
if (settled()) {
|
|
229
|
+
resolve();
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const timer = setTimeout(() => {
|
|
233
|
+
stop();
|
|
234
|
+
resolve();
|
|
235
|
+
}, LIST_EVENT_OFFER_WAIT_MS);
|
|
236
|
+
const stop = watch([offerCache, offerAttempted], () => {
|
|
237
|
+
if (settled()) {
|
|
238
|
+
clearTimeout(timer);
|
|
239
|
+
stop();
|
|
240
|
+
resolve();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
let lastReported = "";
|
|
246
|
+
watch(data, (loaded) => {
|
|
247
|
+
const spec = options.listEvent?.();
|
|
248
|
+
if (!loaded || !spec || !themeEvents.active()) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (spec.event === "search" && (!spec.term.trim() || spec.term.trim() === "*")) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const list = loaded.products ?? [];
|
|
255
|
+
const key = JSON.stringify([spec, loaded.page, list.map(p => p.id)]);
|
|
256
|
+
if (key === lastReported || (spec.event === "view_item_list" && !list.length)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
lastReported = key;
|
|
260
|
+
const offset = (Math.max(1, loaded.page || 1) - 1) * (loaded.perPage || (productsPerPage as number));
|
|
261
|
+
void offersSettled(list.map(p => p.id)).then(() => {
|
|
262
|
+
const items = list.map((product, index) => listingProductToItem(product, {
|
|
263
|
+
position: offset + index + 1,
|
|
264
|
+
listId: spec.listId,
|
|
265
|
+
prices: offerCache.value[product.id]?.prices,
|
|
266
|
+
}));
|
|
267
|
+
if (spec.event === "search") {
|
|
268
|
+
themeEvents.emit("search", {
|
|
269
|
+
search: { search_term: spec.term.trim().slice(0, 256), results_count: loaded.found ?? list.length },
|
|
270
|
+
...(items.length ? { ecommerce: { list_id: spec.listId, items } } : {}),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
themeEvents.emit("view_item_list", { ecommerce: { list_id: spec.listId, items } });
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}, { immediate: true });
|
|
278
|
+
}
|
|
279
|
+
|
|
203
280
|
const found = computed(() => data.value?.found ?? 0);
|
|
204
281
|
const totalPages = computed(() => Math.ceil(found.value / (productsPerPage as number)));
|
|
205
282
|
const isEmpty = computed(() => data.value !== null && data.value !== undefined && products.value.length === 0);
|
|
@@ -254,6 +331,8 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
254
331
|
products, facets, found, totalPages, isEmpty,
|
|
255
332
|
chips, activeFilterCount, removeChip, clearFilters,
|
|
256
333
|
perPage: productsPerPage as number,
|
|
334
|
+
/** The list id cards report a selection from, when the listing reports at all. */
|
|
335
|
+
listId: () => options.listEvent?.()?.listId,
|
|
257
336
|
};
|
|
258
337
|
}
|
|
259
338
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { CART_MAX_QUANTITY } from "../interfaces/cart-item";
|
|
2
|
+
import type { QuantityStepperNotice, QuantityStepperOptions } from "../interfaces/quantity-stepper";
|
|
3
|
+
|
|
4
|
+
/** How long a refused or corrected entry keeps its notice on screen. */
|
|
5
|
+
const NOTICE_DURATION_MS = 2000;
|
|
6
|
+
/** Longest number the field accepts — CART_MAX_QUANTITY has six digits. */
|
|
7
|
+
const MAX_INPUT_DIGITS = 6;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The −/+ stepper with a typed field, as the cart page, the mini-cart and the
|
|
11
|
+
* product buy box all use it — one set of rules so the three cannot drift:
|
|
12
|
+
*
|
|
13
|
+
* - typing only edits the field; Enter or leaving it commits
|
|
14
|
+
* - an empty, zero or unparsable entry reverts to the committed quantity
|
|
15
|
+
* - anything above the ceiling — typed or stepped — lands on the ceiling
|
|
16
|
+
*
|
|
17
|
+
* Each correction raises a short-lived `notice`; a surface that has room for
|
|
18
|
+
* the explanation shows it, one that does not just ignores it.
|
|
19
|
+
*/
|
|
20
|
+
export function useQuantityStepper(options: QuantityStepperOptions) {
|
|
21
|
+
const min = options.min ?? 1;
|
|
22
|
+
|
|
23
|
+
const inputValue = ref(String(options.quantity()));
|
|
24
|
+
const notice = ref<QuantityStepperNotice | null>(null);
|
|
25
|
+
let noticeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
26
|
+
|
|
27
|
+
const ceiling = computed(() => options.max() ?? CART_MAX_QUANTITY);
|
|
28
|
+
const canDecrease = computed(() => options.quantity() > min);
|
|
29
|
+
|
|
30
|
+
watch(options.quantity, (value) => {
|
|
31
|
+
inputValue.value = String(value);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function clearNoticeTimer(): void {
|
|
35
|
+
if (noticeTimer !== null) {
|
|
36
|
+
clearTimeout(noticeTimer);
|
|
37
|
+
noticeTimer = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function raiseNotice(kind: QuantityStepperNotice): void {
|
|
42
|
+
notice.value = kind;
|
|
43
|
+
clearNoticeTimer();
|
|
44
|
+
noticeTimer = setTimeout(() => {
|
|
45
|
+
notice.value = null;
|
|
46
|
+
noticeTimer = null;
|
|
47
|
+
}, NOTICE_DURATION_MS);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function applyQuantity(next: number): void {
|
|
51
|
+
let target = Math.max(next, min);
|
|
52
|
+
if (target > ceiling.value) {
|
|
53
|
+
target = ceiling.value;
|
|
54
|
+
raiseNotice("max");
|
|
55
|
+
}
|
|
56
|
+
if (target !== options.quantity()) {
|
|
57
|
+
options.apply(target);
|
|
58
|
+
}
|
|
59
|
+
// The field shows the committed value even when nothing changed (a
|
|
60
|
+
// typed 12 clamped back onto a quantity that already sat at the ceiling).
|
|
61
|
+
inputValue.value = String(target);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function decrease(): void {
|
|
65
|
+
applyQuantity(options.quantity() - 1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function increase(): void {
|
|
69
|
+
applyQuantity(options.quantity() + 1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function onInput(event: Event): void {
|
|
73
|
+
const input = event.target as HTMLInputElement;
|
|
74
|
+
inputValue.value = input.value.replace(/[^0-9]/g, "").slice(0, MAX_INPUT_DIGITS);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function commit(): void {
|
|
78
|
+
const parsed = Number.parseInt(inputValue.value, 10);
|
|
79
|
+
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
80
|
+
raiseNotice("invalid");
|
|
81
|
+
inputValue.value = String(options.quantity());
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
applyQuantity(parsed);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onScopeDispose(clearNoticeTimer);
|
|
88
|
+
|
|
89
|
+
return { inputValue, notice, canDecrease, decrease, increase, onInput, commit };
|
|
90
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComputedRef } from "vue";
|
|
2
|
+
|
|
3
|
+
import type { QuickAction } from "../config/quickActions";
|
|
4
|
+
|
|
5
|
+
import { allowedQuickActionIds, resolveQuickActions } from "../config/quickActions";
|
|
6
|
+
|
|
7
|
+
export interface UseQuickActionsReturn {
|
|
8
|
+
/** Catalogue ids the account navigation in effect permits, in catalogue order. */
|
|
9
|
+
readonly allowedIds: ComputedRef<string[]>;
|
|
10
|
+
/** Resolves an authored selection, in its own order, minus what the nav does not permit. */
|
|
11
|
+
readonly resolveAllowed: (ids: readonly string[]) => QuickAction[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Quick actions as the current tenant may show them. The picker overlay gets
|
|
16
|
+
* the same limit server-side (the theme's catalogue endpoint), and this is the
|
|
17
|
+
* render-time half: a selection authored before the tenant dropped a nav link
|
|
18
|
+
* — or authored against a wider nav — loses the tiles the nav no longer backs.
|
|
19
|
+
*
|
|
20
|
+
* Only a tenant-authored nav limits the set: the layer's static tree (and a
|
|
21
|
+
* theme's app.config override) is the full B2B account, where every catalogue
|
|
22
|
+
* entry is a real page.
|
|
23
|
+
*/
|
|
24
|
+
export function useQuickActions(): UseQuickActionsReturn {
|
|
25
|
+
const { navigation, isTenantAuthored } = useAccountNavigation();
|
|
26
|
+
|
|
27
|
+
const allowedIds = computed(() => allowedQuickActionIds(isTenantAuthored.value ? navigation.value : null));
|
|
28
|
+
|
|
29
|
+
function resolveAllowed(ids: readonly string[]): QuickAction[] {
|
|
30
|
+
const permitted = new Set(allowedIds.value);
|
|
31
|
+
return resolveQuickActions(ids).filter(action => permitted.has(action.id));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { allowedIds, resolveAllowed };
|
|
35
|
+
}
|