basklee-nuxt 0.9.4 → 0.9.5
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/README.md +4 -0
- package/package.json +2 -2
- package/templates/app/components/basklee/account/StorefrontLogout.README.md +2 -0
- package/templates/app/components/basklee/orders/OrderDetails.README.md +2 -0
- package/templates/app/components/basklee/orders/OrderDetails.vue +5 -0
- package/templates/app/components/basklee/storefront/StorefrontFooter.README.md +6 -0
- package/templates/app/components/basklee/storefront/StorefrontFooter.vue +21 -4
- package/templates/app/components/basklee/stores/StorefrontStores.README.md +2 -0
- package/templates/app/components/basklee/stores/StorefrontStores.vue +2 -1
- package/templates/app/composables/useBaskleeCart.ts +356 -2
- package/templates/app/layouts/default.vue +2 -1
- package/templates/app/pages/browse.vue +2 -2
- package/templates/app/utils/basklee/activityLabels.ts +15 -0
- package/templates/app/utils/basklee/browseLabels.ts +12 -0
- package/templates/app/utils/basklee/cartLabels.ts +124 -0
- package/templates/app/utils/basklee/cartMemory.ts +614 -0
- package/templates/app/utils/basklee/contactLabels.ts +12 -0
- package/templates/app/utils/basklee/directoryLabels.ts +3 -0
- package/templates/app/utils/basklee/featureLabels.ts +12 -0
- package/templates/app/utils/basklee/footerLabels.ts +3 -0
- package/templates/app/utils/basklee/photoDetail.ts +59 -0
- package/templates/app/utils/basklee/productActions.ts +8 -0
- package/templates/app/utils/basklee/profile.ts +52 -0
- package/templates/app/utils/basklee/profileLabels.ts +15 -0
- package/templates/app/utils/basklee/reviewLabels.ts +6 -0
- package/templates/app/utils/basklee/sellerDirectory.ts +112 -0
- package/templates/app/utils/basklee/sessionLabels.ts +6 -6
- package/templates/app/utils/basklee/storeDirectory.ts +26 -0
- package/templates/app/utils/basklee/subscriptionLabels.ts +3 -0
- package/templates/app/utils/basklee/tabLocation.ts +37 -0
- package/templates/app/utils/basklee/ticketDraft.ts +56 -0
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ICartAddress,
|
|
3
|
+
ICartDelivery,
|
|
4
|
+
ICartOptionGroup,
|
|
5
|
+
ICartSummary,
|
|
6
|
+
ICurrencyAmounts,
|
|
7
|
+
IDeliveryType,
|
|
8
|
+
} from '@/interfaces/basklee/cart/ICartData';
|
|
9
|
+
import type { IProduct } from '@/interfaces/basklee/products/IProduct';
|
|
10
|
+
import { cartOptionMaxQuantity } from '@/utils/basklee/cartOptions';
|
|
11
|
+
import {
|
|
12
|
+
getAvailableNestedValueFromObject,
|
|
13
|
+
getAvailableValueFromObject,
|
|
14
|
+
} from '@/utils/basklee/presentation';
|
|
15
|
+
|
|
16
|
+
// What the customer chose during checkout, kept by the storefront.
|
|
17
|
+
//
|
|
18
|
+
// The backend drops every shipment of the checkout when the cart goes back to
|
|
19
|
+
// «Cart» to change a quantity, and when a price changed between the quote and
|
|
20
|
+
// the order («Cart was modified»): the delivery method, the pickup point and
|
|
21
|
+
// the chosen extras are gone and the customer starts again. The storefront
|
|
22
|
+
// remembers them here, asks the backend for the same choices again through
|
|
23
|
+
// the ordinary calls (so every one is checked and priced anew), and tells the
|
|
24
|
+
// customer what was kept, what could not be kept and what changed in price.
|
|
25
|
+
|
|
26
|
+
/** An extra (gift wrap, a card) chosen for a line of the cart. */
|
|
27
|
+
export interface ICartOptionChoice {
|
|
28
|
+
/** Product ID of the cart line the extra belongs to. */
|
|
29
|
+
line: number;
|
|
30
|
+
/** ID of the option group's name: the same before and after a rebuild. */
|
|
31
|
+
group: number;
|
|
32
|
+
/** Product ID of the chosen extra. */
|
|
33
|
+
product: number;
|
|
34
|
+
quantity: number;
|
|
35
|
+
title: ICartOptionGroup['option_name'];
|
|
36
|
+
name: IProduct['locale'];
|
|
37
|
+
price: ICurrencyAmounts | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A text typed for a line (a card's message). Files cannot be kept. */
|
|
41
|
+
export interface ICartOptionText {
|
|
42
|
+
line: number;
|
|
43
|
+
group: number;
|
|
44
|
+
text: string;
|
|
45
|
+
title: ICartOptionGroup['option_name'];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ICartPointChoice {
|
|
49
|
+
code: string;
|
|
50
|
+
city: string;
|
|
51
|
+
address: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The choices of one shipment. */
|
|
55
|
+
export interface ICartShipmentChoice {
|
|
56
|
+
store: number | null;
|
|
57
|
+
lines: number[];
|
|
58
|
+
method: IDeliveryType | null;
|
|
59
|
+
point: ICartPointChoice | null;
|
|
60
|
+
price: ICurrencyAmounts | undefined;
|
|
61
|
+
dateFrom: string;
|
|
62
|
+
dateTo: string;
|
|
63
|
+
options: ICartOptionChoice[];
|
|
64
|
+
texts: ICartOptionText[];
|
|
65
|
+
/** The line had a file attached: it must be attached again. */
|
|
66
|
+
files: ICartOptionText[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ICartMemory {
|
|
70
|
+
/** The delivery address the choices were made for. */
|
|
71
|
+
address: string;
|
|
72
|
+
total: ICurrencyAmounts | undefined;
|
|
73
|
+
shipments: ICartShipmentChoice[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** One call that asks the backend for a remembered choice again. */
|
|
77
|
+
export interface ICartRestoreStep {
|
|
78
|
+
endpoint: string;
|
|
79
|
+
input: Record<string, unknown>;
|
|
80
|
+
params: Record<string, number>;
|
|
81
|
+
/** What to report when the backend refuses the call. */
|
|
82
|
+
lost: ICartLostChoice;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ICartLostChoice {
|
|
86
|
+
kind: 'delivery' | 'option' | 'text' | 'file';
|
|
87
|
+
/** The delivery method, or the names of the extra's group and product. */
|
|
88
|
+
method?: IDeliveryType;
|
|
89
|
+
point?: string;
|
|
90
|
+
title?: ICartOptionGroup['option_name'];
|
|
91
|
+
name?: IProduct['locale'];
|
|
92
|
+
reason: 'address' | 'unavailable' | 'refused' | 'file';
|
|
93
|
+
/** The backend's own words when it refused. */
|
|
94
|
+
message?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ICartChoiceChange {
|
|
98
|
+
kind: 'delivery_price' | 'delivery_date' | 'total';
|
|
99
|
+
method?: IDeliveryType;
|
|
100
|
+
before: ICurrencyAmounts | string | undefined;
|
|
101
|
+
after: ICurrencyAmounts | string | undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** What a restore did, for the notice above the checkout. */
|
|
105
|
+
export interface ICartRestoreReport {
|
|
106
|
+
/** `back`: the customer returned from the cart; `requote`: a price changed at the order. */
|
|
107
|
+
reason: 'back' | 'requote';
|
|
108
|
+
kept: number;
|
|
109
|
+
lost: ICartLostChoice[];
|
|
110
|
+
changes: ICartChoiceChange[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function groupKey(group: ICartOptionGroup) {
|
|
114
|
+
const named = Object.values(group.option_name ?? {}).find(
|
|
115
|
+
(name) => typeof name?.id === 'number',
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return named?.id ?? group.option_type?.id ?? 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isTextGroup(group: ICartOptionGroup) {
|
|
122
|
+
return ['text', 'textarea', 'file'].includes(
|
|
123
|
+
group.option_type?.option_type || '',
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The address as one line: choices made for another address are not replayed. */
|
|
128
|
+
export function cartAddressKey(address: ICartAddress | null | undefined) {
|
|
129
|
+
return address
|
|
130
|
+
? [
|
|
131
|
+
address.country?.id ?? '',
|
|
132
|
+
address.postcode,
|
|
133
|
+
address.city,
|
|
134
|
+
address.line1,
|
|
135
|
+
address.house_number,
|
|
136
|
+
].join('|')
|
|
137
|
+
: '';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Reads the customer's choices from a checkout answer. */
|
|
141
|
+
export function cartMemory(
|
|
142
|
+
summary: Pick<ICartSummary, 'cart_address' | 'prices'>,
|
|
143
|
+
deliveries: ICartDelivery[],
|
|
144
|
+
): ICartMemory {
|
|
145
|
+
return {
|
|
146
|
+
address: cartAddressKey(summary.cart_address),
|
|
147
|
+
total: summary.prices?.summary_price,
|
|
148
|
+
shipments: deliveries.map((delivery) => {
|
|
149
|
+
const data = delivery.delivery_data;
|
|
150
|
+
const method =
|
|
151
|
+
Object.values(delivery.from_store?.deliveries ?? {}).find(
|
|
152
|
+
(item) => item.id === data.method,
|
|
153
|
+
) ?? null;
|
|
154
|
+
const options: ICartOptionChoice[] = [];
|
|
155
|
+
const texts: ICartOptionText[] = [];
|
|
156
|
+
const files: ICartOptionText[] = [];
|
|
157
|
+
|
|
158
|
+
for (const line of delivery.product_items) {
|
|
159
|
+
for (const group of line?.option_group ?? []) {
|
|
160
|
+
const base = {
|
|
161
|
+
line: line!.id,
|
|
162
|
+
group: groupKey(group),
|
|
163
|
+
title: group.option_name,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (isTextGroup(group)) {
|
|
167
|
+
if (group.option_file_data) {
|
|
168
|
+
files.push({ ...base, text: group.option_file_data });
|
|
169
|
+
} else if (group.option_text_data) {
|
|
170
|
+
texts.push({ ...base, text: group.option_text_data });
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
for (const option of group.options ?? []) {
|
|
175
|
+
if (option.quantity > 0 && option.product) {
|
|
176
|
+
options.push({
|
|
177
|
+
...base,
|
|
178
|
+
product: option.product.id,
|
|
179
|
+
quantity: option.quantity,
|
|
180
|
+
name: option.product.locale,
|
|
181
|
+
price: option.option_price?.options_price_after_promo,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
store: delivery.from_store?.id ?? null,
|
|
190
|
+
lines: delivery.product_items
|
|
191
|
+
.flatMap((line) => (line ? [line.id] : []))
|
|
192
|
+
.sort((left, right) => left - right),
|
|
193
|
+
method,
|
|
194
|
+
point:
|
|
195
|
+
method?.delivery_to_carrier_point && data.delivery_to_code
|
|
196
|
+
? {
|
|
197
|
+
code: data.delivery_to_code,
|
|
198
|
+
city: data.delivery_to_city_code ?? '',
|
|
199
|
+
address: data.delivery_address,
|
|
200
|
+
}
|
|
201
|
+
: null,
|
|
202
|
+
price: method ? delivery.prices?.delivery_price_after_promo : undefined,
|
|
203
|
+
dateFrom: data.delivery_date_from?.date ?? '',
|
|
204
|
+
dateTo: data.delivery_date_to?.date ?? '',
|
|
205
|
+
options,
|
|
206
|
+
texts,
|
|
207
|
+
files,
|
|
208
|
+
};
|
|
209
|
+
}),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** True when the memory holds anything worth asking for again. */
|
|
214
|
+
export function cartMemoryHasChoices(memory: ICartMemory | undefined) {
|
|
215
|
+
return Boolean(
|
|
216
|
+
memory?.shipments.some(
|
|
217
|
+
(shipment) =>
|
|
218
|
+
shipment.method ||
|
|
219
|
+
shipment.options.length ||
|
|
220
|
+
shipment.texts.length ||
|
|
221
|
+
shipment.files.length,
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The shipment of the new checkout that carries a remembered shipment's
|
|
227
|
+
// products: the same store and at least one of the same lines.
|
|
228
|
+
function matchShipment(
|
|
229
|
+
choice: ICartShipmentChoice,
|
|
230
|
+
deliveries: ICartDelivery[],
|
|
231
|
+
taken: Set<number>,
|
|
232
|
+
) {
|
|
233
|
+
return deliveries.find(
|
|
234
|
+
(delivery) =>
|
|
235
|
+
!taken.has(delivery.delivery_from_id) &&
|
|
236
|
+
(delivery.from_store?.id ?? null) === choice.store &&
|
|
237
|
+
delivery.product_items.some(
|
|
238
|
+
(line) => line && choice.lines.includes(line.id),
|
|
239
|
+
),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function findGroup(
|
|
244
|
+
delivery: ICartDelivery,
|
|
245
|
+
line: number,
|
|
246
|
+
group: number,
|
|
247
|
+
) {
|
|
248
|
+
return delivery.product_items
|
|
249
|
+
.find((item) => item?.id === line)
|
|
250
|
+
?.option_group?.find((item) => groupKey(item) === group);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The calls that bring the remembered choices back into a rebuilt checkout,
|
|
255
|
+
* and the choices that cannot be asked for at all. A choice the new checkout
|
|
256
|
+
* already holds needs no call; a line the customer removed is not a loss.
|
|
257
|
+
*/
|
|
258
|
+
export function cartRestorePlan(
|
|
259
|
+
memory: ICartMemory,
|
|
260
|
+
summary: Pick<ICartSummary, 'cart_address'>,
|
|
261
|
+
deliveries: ICartDelivery[],
|
|
262
|
+
) {
|
|
263
|
+
const steps: ICartRestoreStep[] = [];
|
|
264
|
+
const lost: ICartLostChoice[] = [];
|
|
265
|
+
const taken = new Set<number>();
|
|
266
|
+
const sameAddress =
|
|
267
|
+
memory.address === cartAddressKey(summary.cart_address);
|
|
268
|
+
|
|
269
|
+
for (const choice of memory.shipments) {
|
|
270
|
+
const delivery = matchShipment(choice, deliveries, taken);
|
|
271
|
+
|
|
272
|
+
if (!delivery) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
taken.add(delivery.delivery_from_id);
|
|
276
|
+
|
|
277
|
+
if (choice.method && !delivery.delivery_data.method) {
|
|
278
|
+
const offered = Object.values(delivery.from_store?.deliveries ?? {}).some(
|
|
279
|
+
(item) => item.id === choice.method!.id,
|
|
280
|
+
);
|
|
281
|
+
const loss = {
|
|
282
|
+
kind: 'delivery' as const,
|
|
283
|
+
method: choice.method,
|
|
284
|
+
point: choice.point?.address,
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
if (!sameAddress) {
|
|
288
|
+
lost.push({ ...loss, reason: 'address' });
|
|
289
|
+
} else if (!offered) {
|
|
290
|
+
lost.push({ ...loss, reason: 'unavailable' });
|
|
291
|
+
} else {
|
|
292
|
+
const input = {
|
|
293
|
+
delivery_from: delivery.delivery_from_id,
|
|
294
|
+
delivery_type: choice.method.id,
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
steps.push(
|
|
298
|
+
choice.point
|
|
299
|
+
? {
|
|
300
|
+
endpoint: 'cart_customer_delivery_pickup_set',
|
|
301
|
+
input: {
|
|
302
|
+
...input,
|
|
303
|
+
delivery_to_code: choice.point.code,
|
|
304
|
+
delivery_to_city_code: choice.point.city,
|
|
305
|
+
delivery_to_code_full_address: choice.point.address,
|
|
306
|
+
},
|
|
307
|
+
params: {},
|
|
308
|
+
lost: { ...loss, reason: 'refused' },
|
|
309
|
+
}
|
|
310
|
+
: {
|
|
311
|
+
endpoint: 'cart_customer_delivery_courier_set',
|
|
312
|
+
input,
|
|
313
|
+
params: {},
|
|
314
|
+
lost: { ...loss, reason: 'refused' },
|
|
315
|
+
},
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
for (const option of choice.options) {
|
|
321
|
+
const group = findGroup(delivery, option.line, option.group);
|
|
322
|
+
|
|
323
|
+
if (!group && !delivery.product_items.some((line) => line?.id === option.line)) {
|
|
324
|
+
// The line itself is gone: the customer removed the product.
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const row = group?.options?.find(
|
|
329
|
+
(item) => item.product?.id === option.product,
|
|
330
|
+
);
|
|
331
|
+
const loss = {
|
|
332
|
+
kind: 'option' as const,
|
|
333
|
+
title: option.title,
|
|
334
|
+
name: option.name,
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
if (!group || !row) {
|
|
338
|
+
lost.push({ ...loss, reason: 'unavailable' });
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (row.quantity > 0) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const quantity = Math.min(option.quantity, cartOptionMaxQuantity(group, row));
|
|
346
|
+
|
|
347
|
+
if (quantity < 1) {
|
|
348
|
+
lost.push({ ...loss, reason: 'unavailable' });
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
steps.push({
|
|
352
|
+
endpoint: 'cart_customer_option_first_set',
|
|
353
|
+
input: { quantity },
|
|
354
|
+
params: { delivery_option_item_id: row.id },
|
|
355
|
+
lost: { ...loss, reason: 'refused' },
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
for (const text of choice.texts) {
|
|
360
|
+
const group = findGroup(delivery, text.line, text.group);
|
|
361
|
+
|
|
362
|
+
if (!group || group.option_text_data) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
steps.push({
|
|
366
|
+
endpoint: 'cart_customer_option_add_additional',
|
|
367
|
+
input: { option_text_data: text.text },
|
|
368
|
+
params: { option_group_id: group.id },
|
|
369
|
+
lost: { kind: 'text', title: text.title, reason: 'refused' },
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
for (const file of choice.files) {
|
|
374
|
+
const group = findGroup(delivery, file.line, file.group);
|
|
375
|
+
|
|
376
|
+
if (group && !group.option_file_data) {
|
|
377
|
+
lost.push({ kind: 'file', title: file.title, reason: 'file' });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return { steps, lost };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function amount(
|
|
386
|
+
amounts: ICurrencyAmounts | undefined,
|
|
387
|
+
currencyId: string | number,
|
|
388
|
+
) {
|
|
389
|
+
const value = Number(amounts?.[String(currencyId)]?.transform_value);
|
|
390
|
+
|
|
391
|
+
return Number.isFinite(value) ? value : undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* What differs between the remembered checkout and the new one, in the
|
|
396
|
+
* currency the customer sees: a delivery price, its dates, the total.
|
|
397
|
+
* Only a shipment that kept its method is compared.
|
|
398
|
+
*/
|
|
399
|
+
export function cartChoiceChanges(
|
|
400
|
+
memory: ICartMemory,
|
|
401
|
+
summary: Pick<ICartSummary, 'prices'>,
|
|
402
|
+
deliveries: ICartDelivery[],
|
|
403
|
+
currencyId: string | number,
|
|
404
|
+
) {
|
|
405
|
+
const changes: ICartChoiceChange[] = [];
|
|
406
|
+
const taken = new Set<number>();
|
|
407
|
+
|
|
408
|
+
for (const choice of memory.shipments) {
|
|
409
|
+
const delivery = matchShipment(choice, deliveries, taken);
|
|
410
|
+
|
|
411
|
+
if (!delivery) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
taken.add(delivery.delivery_from_id);
|
|
415
|
+
if (!choice.method || delivery.delivery_data.method !== choice.method.id) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const price = delivery.prices?.delivery_price_after_promo;
|
|
420
|
+
|
|
421
|
+
if (
|
|
422
|
+
amount(choice.price, currencyId) !== undefined &&
|
|
423
|
+
amount(price, currencyId) !== undefined &&
|
|
424
|
+
amount(choice.price, currencyId) !== amount(price, currencyId)
|
|
425
|
+
) {
|
|
426
|
+
changes.push({
|
|
427
|
+
kind: 'delivery_price',
|
|
428
|
+
method: choice.method,
|
|
429
|
+
before: choice.price,
|
|
430
|
+
after: price,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const before = cartDateRange(choice.dateFrom, choice.dateTo);
|
|
435
|
+
const after = cartDateRange(
|
|
436
|
+
delivery.delivery_data.delivery_date_from?.date ?? '',
|
|
437
|
+
delivery.delivery_data.delivery_date_to?.date ?? '',
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
if (before && after && before !== after) {
|
|
441
|
+
changes.push({
|
|
442
|
+
kind: 'delivery_date',
|
|
443
|
+
method: choice.method,
|
|
444
|
+
before,
|
|
445
|
+
after,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const total = summary.prices?.summary_price;
|
|
451
|
+
|
|
452
|
+
if (
|
|
453
|
+
amount(memory.total, currencyId) !== undefined &&
|
|
454
|
+
amount(total, currencyId) !== undefined &&
|
|
455
|
+
amount(memory.total, currencyId) !== amount(total, currencyId)
|
|
456
|
+
) {
|
|
457
|
+
changes.push({ kind: 'total', before: memory.total, after: total });
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return changes;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Delivery dates as text: «22 Nov — 25 Nov», or one date when the range
|
|
465
|
+
* starts and ends on the same day (a same-day estimate is not a range).
|
|
466
|
+
*/
|
|
467
|
+
export function cartDateRange(from: string, to: string) {
|
|
468
|
+
const first = from.trim();
|
|
469
|
+
const last = to.trim();
|
|
470
|
+
|
|
471
|
+
if (!first || !last || first === last) {
|
|
472
|
+
return first || last;
|
|
473
|
+
}
|
|
474
|
+
return `${first} — ${last}`;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const STORAGE = 'basklee-cart-choices';
|
|
478
|
+
|
|
479
|
+
function storage() {
|
|
480
|
+
try {
|
|
481
|
+
return typeof window === 'undefined' ? undefined : window.sessionStorage;
|
|
482
|
+
} catch {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* The memory survives a reload of the tab (session storage, one cart ID) and
|
|
489
|
+
* nothing longer; the server keeps nothing of it. It holds the delivery
|
|
490
|
+
* choice and the extras' names, no payment data.
|
|
491
|
+
*/
|
|
492
|
+
export function readCartMemory(cartId: number | undefined) {
|
|
493
|
+
if (!cartId) {
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
try {
|
|
497
|
+
const saved = JSON.parse(storage()?.getItem(STORAGE) ?? 'null') as
|
|
498
|
+
| { cart: number; memory: ICartMemory }
|
|
499
|
+
| null;
|
|
500
|
+
|
|
501
|
+
return saved?.cart === cartId && Array.isArray(saved.memory?.shipments)
|
|
502
|
+
? saved.memory
|
|
503
|
+
: undefined;
|
|
504
|
+
} catch {
|
|
505
|
+
return undefined;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** `undefined` forgets the choices: the order is placed or the cart is empty. */
|
|
510
|
+
export function keepCartMemory(
|
|
511
|
+
cartId: number | undefined,
|
|
512
|
+
memory: ICartMemory | undefined,
|
|
513
|
+
) {
|
|
514
|
+
try {
|
|
515
|
+
if (cartId && memory) {
|
|
516
|
+
storage()?.setItem(STORAGE, JSON.stringify({ cart: cartId, memory }));
|
|
517
|
+
} else {
|
|
518
|
+
storage()?.removeItem(STORAGE);
|
|
519
|
+
}
|
|
520
|
+
} catch {
|
|
521
|
+
// A full or blocked storage only costs the memory across a reload.
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** The words of a restore report (`cartLabels` gives them). */
|
|
526
|
+
export interface ICartRestoreLabels {
|
|
527
|
+
restoredKept: string;
|
|
528
|
+
restoredLost: string;
|
|
529
|
+
requoteChanged: string;
|
|
530
|
+
requoteSame: string;
|
|
531
|
+
lostAddress: string;
|
|
532
|
+
lostUnavailable: string;
|
|
533
|
+
lostRefused: string;
|
|
534
|
+
lostFile: string;
|
|
535
|
+
changeDeliveryPrice: string;
|
|
536
|
+
changeDeliveryDate: string;
|
|
537
|
+
changeTotal: string;
|
|
538
|
+
delivery: string;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function methodName(method: IDeliveryType | undefined, locale: string) {
|
|
542
|
+
return (
|
|
543
|
+
getAvailableValueFromObject(method?.locales, locale)?.tariff_name ||
|
|
544
|
+
(method ? `#${method.id}` : '')
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* A restore report as a notice: its tone, its first line and one line per
|
|
550
|
+
* lost choice or changed sum. `money` formats amounts in the shown currency.
|
|
551
|
+
* Nothing to say (a silent restore of nothing) gives `undefined`.
|
|
552
|
+
*/
|
|
553
|
+
export function cartRestoreNotice(
|
|
554
|
+
report: ICartRestoreReport | undefined,
|
|
555
|
+
labels: ICartRestoreLabels,
|
|
556
|
+
locale: string,
|
|
557
|
+
money: (amounts: ICurrencyAmounts | undefined) => string,
|
|
558
|
+
) {
|
|
559
|
+
if (!report) {
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const reasons = {
|
|
564
|
+
address: labels.lostAddress,
|
|
565
|
+
unavailable: labels.lostUnavailable,
|
|
566
|
+
refused: labels.lostRefused,
|
|
567
|
+
file: labels.lostFile,
|
|
568
|
+
};
|
|
569
|
+
const lost = report.lost.map((item) => {
|
|
570
|
+
const group = getAvailableValueFromObject(item.title, locale)
|
|
571
|
+
?.option_group_display_name;
|
|
572
|
+
const name =
|
|
573
|
+
item.kind === 'delivery'
|
|
574
|
+
? [`${labels.delivery}: ${methodName(item.method, locale)}`, item.point]
|
|
575
|
+
.filter(Boolean)
|
|
576
|
+
.join(', ')
|
|
577
|
+
: [
|
|
578
|
+
group,
|
|
579
|
+
getAvailableNestedValueFromObject(item.name, locale, 'product_name'),
|
|
580
|
+
]
|
|
581
|
+
.filter(Boolean)
|
|
582
|
+
.join(': ');
|
|
583
|
+
|
|
584
|
+
return `${name} — ${item.reason === 'refused' && item.message ? item.message : reasons[item.reason]}`;
|
|
585
|
+
});
|
|
586
|
+
const text = (value: ICurrencyAmounts | string | undefined) =>
|
|
587
|
+
typeof value === 'string' ? value : money(value);
|
|
588
|
+
const changes = report.changes.map((item) =>
|
|
589
|
+
(item.kind === 'delivery_price'
|
|
590
|
+
? labels.changeDeliveryPrice
|
|
591
|
+
: item.kind === 'delivery_date'
|
|
592
|
+
? labels.changeDeliveryDate
|
|
593
|
+
: labels.changeTotal
|
|
594
|
+
)
|
|
595
|
+
.replace('{name}', methodName(item.method, locale))
|
|
596
|
+
.replace('{before}', text(item.before))
|
|
597
|
+
.replace('{after}', text(item.after)),
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
if (report.reason === 'back' && !lost.length && !report.kept) {
|
|
601
|
+
return undefined;
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
tone: lost.length || report.reason === 'requote' ? 'attention' : 'success',
|
|
605
|
+
lead: lost.length
|
|
606
|
+
? labels.restoredLost
|
|
607
|
+
: report.reason === 'requote'
|
|
608
|
+
? changes.length
|
|
609
|
+
? labels.requoteChanged
|
|
610
|
+
: labels.requoteSame
|
|
611
|
+
: labels.restoredKept,
|
|
612
|
+
lines: [...lost, ...changes],
|
|
613
|
+
};
|
|
614
|
+
}
|
|
@@ -36,6 +36,10 @@ const en = {
|
|
|
36
36
|
newsletter: 'Stop receiving newsletters',
|
|
37
37
|
products: 'Stop product availability emails',
|
|
38
38
|
unsubscribeDone: 'You have unsubscribed from these emails.',
|
|
39
|
+
invalidLinkHelp:
|
|
40
|
+
'No longer have that email? You can switch these emails off in your profile, or write to the shop.',
|
|
41
|
+
emailSettings: 'Email settings',
|
|
42
|
+
writeToShop: 'Contact the shop',
|
|
39
43
|
invalidLink:
|
|
40
44
|
'This link is incomplete. Open the unsubscribe link from your email.',
|
|
41
45
|
event: 'Take part in this offer',
|
|
@@ -86,6 +90,10 @@ const ru: typeof en = {
|
|
|
86
90
|
newsletter: 'Отказаться от новостной рассылки',
|
|
87
91
|
products: 'Отказаться от писем о наличии товаров',
|
|
88
92
|
unsubscribeDone: 'Вы отписались от этих писем.',
|
|
93
|
+
invalidLinkHelp:
|
|
94
|
+
'Письма уже нет? Отключить рассылку можно в профиле, или напишите в магазин.',
|
|
95
|
+
emailSettings: 'Настройки писем',
|
|
96
|
+
writeToShop: 'Написать в магазин',
|
|
89
97
|
invalidLink: 'Ссылка неполная. Откройте ссылку отписки из письма.',
|
|
90
98
|
event: 'Участвовать в акции',
|
|
91
99
|
eventDescription: 'Подтвердите участие, чтобы получить предложение по почте.',
|
|
@@ -135,6 +143,10 @@ const es: typeof en = {
|
|
|
135
143
|
newsletter: 'Dejar de recibir boletines',
|
|
136
144
|
products: 'Dejar de recibir correos de disponibilidad',
|
|
137
145
|
unsubscribeDone: 'Te has dado de baja de estos correos.',
|
|
146
|
+
invalidLinkHelp:
|
|
147
|
+
'¿Ya no tienes ese correo? Puedes desactivar estos correos en tu perfil o escribir a la tienda.',
|
|
148
|
+
emailSettings: 'Ajustes de correo',
|
|
149
|
+
writeToShop: 'Contactar con la tienda',
|
|
138
150
|
invalidLink:
|
|
139
151
|
'Este enlace está incompleto. Abre el enlace de baja desde tu correo.',
|
|
140
152
|
event: 'Participa en esta oferta',
|
|
@@ -11,6 +11,7 @@ const en = {
|
|
|
11
11
|
letter: 'Names starting with',
|
|
12
12
|
rating: 'Seller rating',
|
|
13
13
|
reviews: 'Reviews',
|
|
14
|
+
noRatings: 'No ratings yet',
|
|
14
15
|
since: 'Selling since',
|
|
15
16
|
hours: 'Opening hours',
|
|
16
17
|
phone: 'Phone',
|
|
@@ -75,6 +76,7 @@ const ru: typeof en = {
|
|
|
75
76
|
letter: 'Названия на букву',
|
|
76
77
|
rating: 'Рейтинг продавца',
|
|
77
78
|
reviews: 'Отзывы',
|
|
79
|
+
noRatings: 'Оценок пока нет',
|
|
78
80
|
since: 'Продаёт с',
|
|
79
81
|
hours: 'Часы работы',
|
|
80
82
|
phone: 'Телефон',
|
|
@@ -140,6 +142,7 @@ const es: typeof en = {
|
|
|
140
142
|
letter: 'Nombres que empiezan por',
|
|
141
143
|
rating: 'Valoración del vendedor',
|
|
142
144
|
reviews: 'Reseñas',
|
|
145
|
+
noRatings: 'Aún sin valoraciones',
|
|
143
146
|
since: 'Vende desde',
|
|
144
147
|
hours: 'Horario',
|
|
145
148
|
phone: 'Teléfono',
|