@revenexx/cover 0.2.36 → 0.2.37
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/components/cart/view/CartSummaryPanel.vue +79 -17
- package/app/components/cart/view/CartView.vue +24 -2
- package/app/components/punchout/action/PunchoutTransferAction.vue +69 -0
- package/app/composables/useCartCalculation.ts +1 -0
- package/app/composables/useCartStore.ts +62 -1
- package/app/composables/usePunchoutVisit.ts +55 -0
- package/app/interfaces/cart-calculation.ts +6 -0
- package/app/interfaces/punchout.ts +79 -0
- package/app/layouts/default.vue +7 -0
- package/app/pages/punchout/transfer.vue +158 -0
- package/i18n/locales/de/cart.json +5 -2
- package/i18n/locales/de/punchout.json +45 -0
- package/i18n/locales/en/cart.json +5 -2
- package/i18n/locales/en/punchout.json +45 -0
- package/nuxt.config.ts +28 -0
- package/package.json +2 -1
- package/server/api/cart/calculate.post.ts +41 -2
- package/server/api/orders/index.post.ts +101 -0
- package/server/api/punchout/return.post.ts +66 -0
- package/server/api/punchout/session.get.ts +15 -0
- package/server/interfaces/cartCalculation.ts +16 -0
- package/server/interfaces/punchout.ts +57 -0
- package/server/routes/punchout/start.get.ts +261 -0
- package/server/services/MockCartCalculationService.ts +19 -5
- package/server/utils/promotionsService.ts +275 -0
- package/server/utils/punchoutLanding.ts +159 -0
- package/server/utils/punchoutVisit.ts +134 -0
- package/server/utils/revenexxSdk.ts +34 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import CartApprovalsPanel from "./CartApprovalsPanel.vue";
|
|
3
3
|
import CartWorkflowPickerModal from "../actions/CartWorkflowPickerModal.vue";
|
|
4
|
+
import PunchoutTransferAction from "../../punchout/action/PunchoutTransferAction.vue";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Cart summary 2.0: the calculated totals block in document order, the
|
|
@@ -14,8 +15,24 @@ const cart = useCartStore();
|
|
|
14
15
|
const actions = useCartActions();
|
|
15
16
|
const { calculation, pending } = useCartCalculation();
|
|
16
17
|
const { settings, role, workflows } = useB2BContext();
|
|
18
|
+
// Inside a punchout visit the cart does not end in an order here: it is handed
|
|
19
|
+
// back to the buyer's own procurement system, which decides. So the checkout
|
|
20
|
+
// CTA is replaced rather than joined — two primary actions would be an
|
|
21
|
+
// invitation to order twice.
|
|
22
|
+
const { isPunchout, isReadOnly } = usePunchoutVisit();
|
|
17
23
|
const { formatCurrency } = useCartSummaryFormatting();
|
|
18
24
|
|
|
25
|
+
const codeInput = ref("");
|
|
26
|
+
|
|
27
|
+
function applyCode(): void {
|
|
28
|
+
const code = codeInput.value.trim();
|
|
29
|
+
if (!code) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
cart.addVoucherCode(code);
|
|
33
|
+
codeInput.value = "";
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
const totals = computed(() =>
|
|
20
37
|
(calculation.value?.totals ?? []).filter(row => row.alwaysVisible || row.amount !== 0),
|
|
21
38
|
);
|
|
@@ -132,6 +149,47 @@ const trustItems = computed(() => {
|
|
|
132
149
|
</template>
|
|
133
150
|
</div>
|
|
134
151
|
|
|
152
|
+
<!--
|
|
153
|
+
Promotion codes. Entering one recalculates the cart, because what
|
|
154
|
+
a code is worth is the promotions app's answer and depends on the
|
|
155
|
+
moment it is asked — the buyer, the time, the budget left. A code
|
|
156
|
+
that is worth nothing still shows: removing it silently would
|
|
157
|
+
leave the buyer wondering where their discount went.
|
|
158
|
+
-->
|
|
159
|
+
<div class="flex flex-col gap-2">
|
|
160
|
+
<div class="flex gap-2">
|
|
161
|
+
<UInput
|
|
162
|
+
v-model="codeInput"
|
|
163
|
+
:placeholder="t('cart.summary.voucherPlaceholder')"
|
|
164
|
+
size="sm"
|
|
165
|
+
class="flex-1"
|
|
166
|
+
@keyup.enter="applyCode"
|
|
167
|
+
/>
|
|
168
|
+
<UButton
|
|
169
|
+
size="sm"
|
|
170
|
+
variant="subtle"
|
|
171
|
+
:disabled="!codeInput.trim()"
|
|
172
|
+
@click="applyCode"
|
|
173
|
+
>
|
|
174
|
+
{{ t('cart.summary.voucherApply') }}
|
|
175
|
+
</UButton>
|
|
176
|
+
</div>
|
|
177
|
+
<div
|
|
178
|
+
v-if="cart.voucherCodes.length"
|
|
179
|
+
class="flex flex-wrap gap-1.5"
|
|
180
|
+
>
|
|
181
|
+
<UBadge
|
|
182
|
+
v-for="code in cart.voucherCodes"
|
|
183
|
+
:key="code"
|
|
184
|
+
variant="soft"
|
|
185
|
+
class="cursor-pointer"
|
|
186
|
+
@click="cart.removeVoucherCode(code)"
|
|
187
|
+
>
|
|
188
|
+
{{ code }} ×
|
|
189
|
+
</UBadge>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
135
193
|
<dl
|
|
136
194
|
v-if="totals.length"
|
|
137
195
|
class="flex flex-col gap-2.5 m-0"
|
|
@@ -169,23 +227,26 @@ const trustItems = computed(() => {
|
|
|
169
227
|
|
|
170
228
|
<CartApprovalsPanel :limits="calculation?.approvalLimits ?? []" />
|
|
171
229
|
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
230
|
+
<PunchoutTransferAction v-if="isPunchout" />
|
|
231
|
+
<template v-else>
|
|
232
|
+
<UButton
|
|
233
|
+
color="primary"
|
|
234
|
+
variant="solid"
|
|
235
|
+
size="lg"
|
|
236
|
+
class="w-full justify-center mt-2"
|
|
237
|
+
:disabled="!orderable"
|
|
238
|
+
:loading="pending"
|
|
239
|
+
:label="isRequester ? t('cart.cta.requisition') : t('cart.cta.checkout')"
|
|
240
|
+
tabindex="0"
|
|
241
|
+
@click="onCheckout"
|
|
242
|
+
/>
|
|
243
|
+
<p
|
|
244
|
+
v-if="!orderable"
|
|
245
|
+
class="text-xs text-muted text-center"
|
|
246
|
+
>
|
|
247
|
+
{{ t('cart.cta.notOrderable') }}
|
|
248
|
+
</p>
|
|
249
|
+
</template>
|
|
189
250
|
|
|
190
251
|
<!-- Trust: the promises that close B2B orders -->
|
|
191
252
|
<ul
|
|
@@ -230,6 +291,7 @@ const trustItems = computed(() => {
|
|
|
230
291
|
@click="printCart"
|
|
231
292
|
/>
|
|
232
293
|
<UButton
|
|
294
|
+
v-if="!isReadOnly"
|
|
233
295
|
:icon="icon('delete')"
|
|
234
296
|
color="neutral"
|
|
235
297
|
variant="ghost"
|
|
@@ -30,6 +30,11 @@ const selection = useCartSelection();
|
|
|
30
30
|
const actions = useCartActions();
|
|
31
31
|
const { role, workflows, settings } = useB2BContext();
|
|
32
32
|
const { calculation, linesByKey } = useCartCalculation({ orchestrate: true });
|
|
33
|
+
// A requisition a procurement system reopened for INSPECTION only: the buyer
|
|
34
|
+
// may look at it and not change it (cxml-entry AC-9). The positions already
|
|
35
|
+
// carry a `readonly` mode for exactly this; here is where it is switched on,
|
|
36
|
+
// and the cart store refuses the same writes behind it.
|
|
37
|
+
const { isReadOnly } = usePunchoutVisit();
|
|
33
38
|
|
|
34
39
|
const hydrated = ref(false);
|
|
35
40
|
onMounted(() => {
|
|
@@ -185,7 +190,10 @@ const messageColor = (severity: string) =>
|
|
|
185
190
|
class="mb-6"
|
|
186
191
|
/>
|
|
187
192
|
<div class="grid sm:grid-cols-2 gap-8 items-start">
|
|
188
|
-
<div
|
|
193
|
+
<div
|
|
194
|
+
v-if="!isReadOnly"
|
|
195
|
+
class="border border-(--ui-border) rounded-xl p-4 md:p-5 space-y-3"
|
|
196
|
+
>
|
|
189
197
|
<h2 class="text-sm font-semibold text-highlighted">
|
|
190
198
|
{{ t('cart.quickAdd.title') }}
|
|
191
199
|
</h2>
|
|
@@ -235,12 +243,25 @@ const messageColor = (severity: string) =>
|
|
|
235
243
|
<template v-else>
|
|
236
244
|
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6 lg:gap-8 items-start">
|
|
237
245
|
<section class="lg:col-span-8 border border-(--ui-border) rounded-xl px-4 md:px-5 pb-2">
|
|
238
|
-
<
|
|
246
|
+
<UAlert
|
|
247
|
+
v-if="isReadOnly"
|
|
248
|
+
color="info"
|
|
249
|
+
variant="soft"
|
|
250
|
+
:icon="icon('info')"
|
|
251
|
+
:title="t('punchout.readOnly.badge')"
|
|
252
|
+
:description="t('punchout.readOnly.hint')"
|
|
253
|
+
class="my-4 print:hidden"
|
|
254
|
+
/>
|
|
255
|
+
<CartListHeader
|
|
256
|
+
v-else
|
|
257
|
+
class="print:hidden"
|
|
258
|
+
/>
|
|
239
259
|
|
|
240
260
|
<CartPositionList
|
|
241
261
|
v-if="freeItems.length"
|
|
242
262
|
:items="freeItems"
|
|
243
263
|
:lines-by-key="linesByKey"
|
|
264
|
+
:readonly="isReadOnly"
|
|
244
265
|
/>
|
|
245
266
|
|
|
246
267
|
<div
|
|
@@ -253,6 +274,7 @@ const messageColor = (severity: string) =>
|
|
|
253
274
|
:requisition="requisition"
|
|
254
275
|
:items="itemsByRequisition.get(requisition.id) ?? []"
|
|
255
276
|
:lines-by-key="linesByKey"
|
|
277
|
+
:readonly="isReadOnly"
|
|
256
278
|
/>
|
|
257
279
|
</div>
|
|
258
280
|
</section>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* "Transfer cart" — the end of a punchout visit, as the buyer meets it.
|
|
4
|
+
*
|
|
5
|
+
* Offered ONLY inside a punchout session, and worded by that session's
|
|
6
|
+
* protocol: the same button is "transfer the basket back" to an SRM buyer,
|
|
7
|
+
* "return the requisition" to a cXML one and "send the cart to your trade
|
|
8
|
+
* software" to an IDS craftsman.
|
|
9
|
+
*
|
|
10
|
+
* It does not hand anything back itself. Pressing it goes to the interstitial,
|
|
11
|
+
* which is where the payload is fetched and the form is submitted from — the
|
|
12
|
+
* buyer is leaving this shop, and that deserves a page rather than a button
|
|
13
|
+
* that silently navigates a browser off-site.
|
|
14
|
+
*/
|
|
15
|
+
const { icon } = useIcons();
|
|
16
|
+
const { t } = useI18n();
|
|
17
|
+
const { to } = useAppUrl();
|
|
18
|
+
const { isPunchout, isReadOnly, protocol, transferLabelKey } = usePunchoutVisit();
|
|
19
|
+
const cart = useCartStore();
|
|
20
|
+
|
|
21
|
+
const props = withDefaults(defineProps<{
|
|
22
|
+
/** Rendered full width in the cart summary, inline elsewhere. */
|
|
23
|
+
readonly block?: boolean;
|
|
24
|
+
}>(), { block: true });
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An empty cart has nothing to hand over, and a procurement system that
|
|
28
|
+
* received one would show its buyer an empty requisition with no way to tell
|
|
29
|
+
* whether that was the answer or a fault.
|
|
30
|
+
*/
|
|
31
|
+
const isEmpty = computed(() => cart.items.length === 0);
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<div
|
|
36
|
+
v-if="isPunchout"
|
|
37
|
+
class="space-y-2"
|
|
38
|
+
>
|
|
39
|
+
<UButton
|
|
40
|
+
color="primary"
|
|
41
|
+
variant="solid"
|
|
42
|
+
size="lg"
|
|
43
|
+
:block="props.block"
|
|
44
|
+
:icon="icon('upload')"
|
|
45
|
+
:disabled="isEmpty"
|
|
46
|
+
:to="to('/punchout/transfer')"
|
|
47
|
+
tabindex="0"
|
|
48
|
+
:label="t(transferLabelKey)"
|
|
49
|
+
/>
|
|
50
|
+
<p
|
|
51
|
+
v-if="isEmpty"
|
|
52
|
+
class="text-xs text-muted text-center"
|
|
53
|
+
>
|
|
54
|
+
{{ t('punchout.transfer.emptyCart') }}
|
|
55
|
+
</p>
|
|
56
|
+
<p
|
|
57
|
+
v-else-if="isReadOnly"
|
|
58
|
+
class="text-xs text-muted text-center"
|
|
59
|
+
>
|
|
60
|
+
{{ t('punchout.readOnly.hint') }}
|
|
61
|
+
</p>
|
|
62
|
+
<p
|
|
63
|
+
v-else
|
|
64
|
+
class="text-xs text-muted text-center"
|
|
65
|
+
>
|
|
66
|
+
{{ t(`punchout.transfer.hint.${protocol ?? 'oci'}`) }}
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
</template>
|
|
@@ -30,6 +30,7 @@ export function useCartCalculation(options?: {
|
|
|
30
30
|
headers: { "x-locale": locale.value },
|
|
31
31
|
body: {
|
|
32
32
|
items: cart.items,
|
|
33
|
+
...(cart.voucherCodes?.length ? { voucherCodes: cart.voucherCodes } : {}),
|
|
33
34
|
...(options?.deliveryMethod?.value
|
|
34
35
|
? { deliveryMethod: options.deliveryMethod.value }
|
|
35
36
|
: {}),
|
|
@@ -38,6 +38,27 @@ export const useCartStore = defineStore("cart", () => {
|
|
|
38
38
|
const items = skipHydrate(ref<CartItem[]>([]));
|
|
39
39
|
/** Meta of requisitions currently loaded into the cart. */
|
|
40
40
|
const requisitions = skipHydrate(ref<CartRequisitionMeta[]>([]));
|
|
41
|
+
/**
|
|
42
|
+
* Promotion codes the buyer typed, in the order they typed them. Intent, not
|
|
43
|
+
* a result: what a code is worth is decided by the promotions app on every
|
|
44
|
+
* recalculation, so nothing about its value is kept here — an expired code
|
|
45
|
+
* simply stops being worth anything and stays visible, because removing it
|
|
46
|
+
* silently would leave the buyer wondering where their discount went.
|
|
47
|
+
*/
|
|
48
|
+
const voucherCodes = skipHydrate(ref<string[]>([]));
|
|
49
|
+
|
|
50
|
+
function addVoucherCode(code: string): void {
|
|
51
|
+
const trimmed = code.trim().toUpperCase();
|
|
52
|
+
if (!trimmed || voucherCodes.value.includes(trimmed)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
voucherCodes.value = [...voucherCodes.value, trimmed];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function removeVoucherCode(code: string): void {
|
|
59
|
+
voucherCodes.value = voucherCodes.value.filter(c => c !== code);
|
|
60
|
+
}
|
|
61
|
+
|
|
41
62
|
const isOpen = ref(false);
|
|
42
63
|
|
|
43
64
|
/* ---- live carts (carts app via the BFF) ----------------------------- */
|
|
@@ -197,10 +218,33 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
|
|
|
197
218
|
);
|
|
198
219
|
const total = computed(() => subtotal.value + tax.value);
|
|
199
220
|
|
|
221
|
+
/**
|
|
222
|
+
* A cart the buyer may look at and not change.
|
|
223
|
+
*
|
|
224
|
+
* cXML's `inspect` operation reopens a requisition for inspection only, and
|
|
225
|
+
* the punchout session records that (cxml-entry AC-9). The promise is that
|
|
226
|
+
* such a visit "offers them no way to change it", so the guard sits on the
|
|
227
|
+
* mutations themselves rather than only on the buttons: a shop with a dozen
|
|
228
|
+
* add-to-cart affordances would otherwise keep exactly the one nobody
|
|
229
|
+
* remembered to hide.
|
|
230
|
+
*
|
|
231
|
+
* Set from the shop shell once the visit is known
|
|
232
|
+
* (`usePunchoutVisit()` in the default layout), and false for every
|
|
233
|
+
* ordinary visit — which is all of them outside punchout.
|
|
234
|
+
*/
|
|
235
|
+
const isReadOnly = ref(false);
|
|
236
|
+
|
|
237
|
+
const setReadOnly = (readOnly: boolean): void => {
|
|
238
|
+
isReadOnly.value = readOnly;
|
|
239
|
+
};
|
|
240
|
+
|
|
200
241
|
const addItem = (
|
|
201
242
|
product: Omit<CartItem, "quantity">,
|
|
202
243
|
options?: { chooseTarget?: boolean },
|
|
203
244
|
): boolean => {
|
|
245
|
+
if (isReadOnly.value) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
204
248
|
const existing = items.value.find(i => i.id === product.id && !i.requisitionId);
|
|
205
249
|
let addedKey: string | null = null;
|
|
206
250
|
if (existing) {
|
|
@@ -229,10 +273,16 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
|
|
|
229
273
|
};
|
|
230
274
|
|
|
231
275
|
const removeItem = (id: string) => {
|
|
276
|
+
if (isReadOnly.value) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
232
279
|
items.value = items.value.filter(i => i.id !== id);
|
|
233
280
|
};
|
|
234
281
|
|
|
235
282
|
const updateQuantity = (id: string, quantity: number) => {
|
|
283
|
+
if (isReadOnly.value) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
236
286
|
if (quantity <= 0) {
|
|
237
287
|
removeItem(id);
|
|
238
288
|
return;
|
|
@@ -248,6 +298,9 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
|
|
|
248
298
|
};
|
|
249
299
|
|
|
250
300
|
const clearCart = () => {
|
|
301
|
+
if (isReadOnly.value) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
251
304
|
items.value = [];
|
|
252
305
|
requisitions.value = [];
|
|
253
306
|
};
|
|
@@ -258,12 +311,18 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
|
|
|
258
311
|
items.value.find(i => keyOf(i) === lineKey);
|
|
259
312
|
|
|
260
313
|
const removeByKeys = (lineKeys: string[]) => {
|
|
314
|
+
if (isReadOnly.value) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
261
317
|
const keys = new Set(lineKeys);
|
|
262
318
|
items.value = items.value.filter(i => !keys.has(keyOf(i)));
|
|
263
319
|
pruneEmptyRequisitions();
|
|
264
320
|
};
|
|
265
321
|
|
|
266
322
|
const updateQuantityByKey = (lineKey: string, quantity: number) => {
|
|
323
|
+
if (isReadOnly.value) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
267
326
|
const item = findByKey(lineKey);
|
|
268
327
|
if (!item) {
|
|
269
328
|
return;
|
|
@@ -836,9 +895,11 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
|
|
|
836
895
|
}
|
|
837
896
|
|
|
838
897
|
return {
|
|
839
|
-
items, requisitions, isOpen, itemCount,
|
|
898
|
+
items, requisitions, isOpen, itemCount,
|
|
899
|
+
voucherCodes, addVoucherCode, removeVoucherCode, effectivePrices, getEffectivePrice,
|
|
840
900
|
subtotal, subtotalDisplay, visibleTaxRows, tax, total, TAX_RATE, isEmpty,
|
|
841
901
|
addItem, removeItem, updateQuantity, clearCart,
|
|
902
|
+
isReadOnly, setReadOnly,
|
|
842
903
|
keyOf, removeByKeys, updateQuantityByKey, setCostCenter, setPositionDetails,
|
|
843
904
|
moveWithinScope, addRequisition, removeRequisition,
|
|
844
905
|
openCart, closeCart, toggleCart,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PunchoutVisitView } from "../interfaces/punchout";
|
|
2
|
+
|
|
3
|
+
const EMPTY: PunchoutVisitView = {
|
|
4
|
+
active: false,
|
|
5
|
+
protocol: null,
|
|
6
|
+
channelCode: null,
|
|
7
|
+
entryAction: null,
|
|
8
|
+
readOnly: false,
|
|
9
|
+
cartId: null,
|
|
10
|
+
expiresAt: null,
|
|
11
|
+
handedBack: false,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether this visit is a punchout session, and what it is called.
|
|
16
|
+
*
|
|
17
|
+
* The shop asks this in three places and nowhere else: the transfer action is
|
|
18
|
+
* offered ONLY inside a punchout session, its wording follows the session's
|
|
19
|
+
* protocol, and a visit the external system marked view-only offers no way to
|
|
20
|
+
* change the cart.
|
|
21
|
+
*
|
|
22
|
+
* Fetched once and shared under one key, like the B2B context beside it, so
|
|
23
|
+
* SSR and the client agree and the action never appears a moment after the
|
|
24
|
+
* page did — a button that moves under a buyer about to press checkout is
|
|
25
|
+
* worse than one that was never there.
|
|
26
|
+
*
|
|
27
|
+
* It carries no handle: the hand-back goes through the BFF, which holds it.
|
|
28
|
+
*/
|
|
29
|
+
export function usePunchoutVisit() {
|
|
30
|
+
const { data, refresh } = useFetch<PunchoutVisitView>("/api/punchout/session", {
|
|
31
|
+
key: "punchout-visit",
|
|
32
|
+
default: () => EMPTY,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const visit = computed(() => data.value ?? EMPTY);
|
|
36
|
+
const isPunchout = computed(() => visit.value.active);
|
|
37
|
+
/** A visit that may be looked at and not changed — cXML `inspect`. */
|
|
38
|
+
const isReadOnly = computed(() => visit.value.active && visit.value.readOnly);
|
|
39
|
+
const protocol = computed(() => visit.value.protocol);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What the transfer action is called, in the buyer's own vocabulary.
|
|
43
|
+
*
|
|
44
|
+
* A buyer in SAP SRM is transferring the basket back, a cXML buyer is
|
|
45
|
+
* returning a requisition to their procurement system, and an IDS craftsman
|
|
46
|
+
* is sending the cart back to their trade software. One label for all three
|
|
47
|
+
* would be wrong in at least two of them, so the protocol picks the key and
|
|
48
|
+
* translation does the rest.
|
|
49
|
+
*/
|
|
50
|
+
const transferLabelKey = computed(() =>
|
|
51
|
+
`punchout.transfer.action.${visit.value.protocol ?? "oci"}`,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return { visit, isPunchout, isReadOnly, protocol, transferLabelKey, refresh };
|
|
55
|
+
}
|
|
@@ -101,6 +101,12 @@ export interface CartMessage {
|
|
|
101
101
|
export interface CartCalculationRequest {
|
|
102
102
|
items: CartItem[];
|
|
103
103
|
deliveryMethod?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Promotion codes the buyer typed. Sent with every recalculation because
|
|
106
|
+
* what a code is worth depends on the moment it is asked about — the cart,
|
|
107
|
+
* the buyer, the time, and what budget the promotion has left.
|
|
108
|
+
*/
|
|
109
|
+
voucherCodes?: string[];
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
/**
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One punchout visit, as the shop sees it.
|
|
3
|
+
*
|
|
4
|
+
* A punchout session belongs to the punchout app — it owns the handle, the
|
|
5
|
+
* four states and the expiry. What the storefront keeps is a copy of the
|
|
6
|
+
* context that visit carries, because everything the shop does for the rest of
|
|
7
|
+
* the visit reads it: which channel the buyer shops, what they came here to
|
|
8
|
+
* do, and what the transfer action is called.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** The three protocols a visit can be entered by. */
|
|
12
|
+
export type PunchoutProtocol = "oci" | "cxml" | "ids";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What the visit is FOR, in the punchout app's own words rather than any
|
|
16
|
+
* protocol's. The shop branches on this and never on OCI's `FUNCTION`, cXML's
|
|
17
|
+
* `operation` or IDS's `action`.
|
|
18
|
+
*/
|
|
19
|
+
export interface PunchoutIntent {
|
|
20
|
+
readonly kind?: string;
|
|
21
|
+
/** `article`: the article number the external system named. */
|
|
22
|
+
readonly supplier_part_id?: string;
|
|
23
|
+
/** `search`: the term to run. */
|
|
24
|
+
readonly term?: string;
|
|
25
|
+
/** `inbound_cart`: a visit the buyer may look at and not change. */
|
|
26
|
+
readonly read_only?: boolean;
|
|
27
|
+
readonly [key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The visit as the BROWSER sees it — everything the UI needs and nothing it
|
|
32
|
+
* does not. No handle, no contact, no secret: the transfer action goes through
|
|
33
|
+
* the BFF, which holds the handle server-side.
|
|
34
|
+
*/
|
|
35
|
+
export interface PunchoutVisitView {
|
|
36
|
+
readonly active: boolean;
|
|
37
|
+
readonly protocol: PunchoutProtocol | null;
|
|
38
|
+
/** The channel this buyer shops. */
|
|
39
|
+
readonly channelCode: string | null;
|
|
40
|
+
/** What the visit is for — drives where the buyer landed. */
|
|
41
|
+
readonly entryAction: string | null;
|
|
42
|
+
/** A visit the external system marked as view-only (cXML `inspect`). */
|
|
43
|
+
readonly readOnly: boolean;
|
|
44
|
+
/** The cart this visit fills, when the external system named one. */
|
|
45
|
+
readonly cartId: string | null;
|
|
46
|
+
/** When the visit runs out. */
|
|
47
|
+
readonly expiresAt: string | null;
|
|
48
|
+
/** True once the cart has been handed back — the visit is over. */
|
|
49
|
+
readonly handedBack: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The hand-back payload, answered by `punchout.sessions.return` and turned
|
|
54
|
+
* into a form the buyer's browser submits.
|
|
55
|
+
*
|
|
56
|
+
* Three things decide what that form looks like, and all three come from here:
|
|
57
|
+
* `encoding` (url-encoded for OCI and cXML, multipart for IDS, whose standard
|
|
58
|
+
* rules a query string out because a cart does not fit in one), how many
|
|
59
|
+
* fields there are (cXML and IDS carry the whole document in ONE field, OCI
|
|
60
|
+
* carries many), and whether `target_url` is null — which is what a secured
|
|
61
|
+
* OCI visit looks like, where the procurement system fetches the cart on its
|
|
62
|
+
* own back channel and the browser must post nothing at all.
|
|
63
|
+
*/
|
|
64
|
+
export interface PunchoutReturnPayload {
|
|
65
|
+
readonly target_url: string | null;
|
|
66
|
+
readonly method: string;
|
|
67
|
+
readonly encoding: string;
|
|
68
|
+
readonly fields: Record<string, string>;
|
|
69
|
+
readonly document?: string;
|
|
70
|
+
readonly correlation_key: string;
|
|
71
|
+
readonly transfer_id: string;
|
|
72
|
+
readonly transferred_at: string | null;
|
|
73
|
+
/**
|
|
74
|
+
* True when this visit had already been handed back and this is the
|
|
75
|
+
* payload it produced then. Submit it — a browser that came back to a page
|
|
76
|
+
* it had already submitted must get the form, not an error.
|
|
77
|
+
*/
|
|
78
|
+
readonly replayed: boolean;
|
|
79
|
+
}
|
package/app/layouts/default.vue
CHANGED
|
@@ -4,6 +4,13 @@ const { navigateToSearch } = useSearch();
|
|
|
4
4
|
const route = useRoute();
|
|
5
5
|
const cart = useCartStore();
|
|
6
6
|
|
|
7
|
+
// The shop shell is where the punchout visit is resolved: every page has it,
|
|
8
|
+
// so the transfer action and the view-only guard are known before the first
|
|
9
|
+
// paint rather than a fetch later. Outside a punchout visit this answers "no"
|
|
10
|
+
// and nothing below it changes.
|
|
11
|
+
const { isReadOnly } = usePunchoutVisit();
|
|
12
|
+
watch(isReadOnly, readOnly => cart.setReadOnly(readOnly), { immediate: true });
|
|
13
|
+
|
|
7
14
|
const isCartOrCheckoutPage = computed(() => /\/(cart|checkout)(\/|$)/.test(route.path));
|
|
8
15
|
|
|
9
16
|
watch(isCartOrCheckoutPage, (isRestrictedPage) => {
|