@akinon/next 1.60.0 → 1.61.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +668 -0
- package/api/client.ts +23 -2
- package/assets/styles/index.css +49 -0
- package/assets/styles/index.css.map +1 -0
- package/assets/styles/index.scss +50 -26
- package/bin/pz-generate-translations.js +41 -0
- package/bin/pz-install-plugins.js +0 -0
- package/bin/pz-install-theme.js +0 -0
- package/bin/pz-postbuild.js +0 -0
- package/bin/pz-postdev.js +0 -0
- package/bin/pz-postinstall.js +0 -0
- package/bin/pz-poststart.js +0 -0
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/bin/pz-prestart.js +0 -0
- package/components/file-input.tsx +8 -0
- package/components/index.ts +1 -0
- package/components/input.tsx +21 -7
- package/components/link.tsx +17 -13
- package/components/plugin-module.tsx +8 -3
- package/components/price.tsx +11 -4
- package/components/pz-root.tsx +15 -3
- package/components/selected-payment-option-view.tsx +2 -1
- package/data/client/account.ts +3 -2
- package/data/client/api.ts +1 -1
- package/data/client/b2b.ts +35 -2
- package/data/client/basket.ts +6 -5
- package/data/client/checkout.ts +55 -10
- package/data/client/user.ts +3 -2
- package/data/server/category.ts +39 -19
- package/data/server/flatpage.ts +29 -7
- package/data/server/form.ts +29 -11
- package/data/server/landingpage.ts +26 -7
- package/data/server/list.ts +12 -6
- package/data/server/menu.ts +15 -2
- package/data/server/product.ts +29 -12
- package/data/server/seo.ts +17 -24
- package/data/server/special-page.ts +10 -5
- package/data/server/widget.ts +14 -7
- package/data/urls.ts +17 -4
- package/hocs/server/with-segment-defaults.tsx +4 -1
- package/hooks/index.ts +2 -1
- package/hooks/use-message-listener.ts +24 -0
- package/hooks/use-pagination.ts +2 -2
- package/hooks/use-payment-options.ts +2 -1
- package/lib/cache.ts +4 -6
- package/middlewares/complete-gpay.ts +1 -1
- package/middlewares/complete-masterpass.ts +1 -1
- package/middlewares/currency.ts +1 -0
- package/middlewares/default.ts +226 -167
- package/middlewares/index.ts +3 -1
- package/middlewares/oauth-login.ts +6 -1
- package/middlewares/pretty-url.ts +7 -1
- package/middlewares/saved-card-redirection.ts +179 -0
- package/middlewares/three-d-redirection.ts +1 -1
- package/middlewares/url-redirection.ts +14 -2
- package/package.json +2 -2
- package/plugins.d.ts +6 -0
- package/plugins.js +2 -1
- package/redux/middlewares/checkout.ts +77 -13
- package/redux/reducers/checkout.ts +23 -3
- package/redux/reducers/index.ts +3 -1
- package/routes/pretty-url.tsx +7 -9
- package/types/commerce/address.ts +1 -1
- package/types/commerce/b2b.ts +12 -2
- package/types/commerce/checkout.ts +31 -0
- package/types/commerce/order.ts +1 -0
- package/types/index.ts +15 -1
- package/utils/app-fetch.ts +15 -7
- package/utils/index.ts +27 -6
- package/utils/redirection-iframe.ts +85 -0
- package/utils/server-translation.ts +11 -1
- package/with-pz-config.js +2 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';
|
|
2
|
+
import Settings from 'settings';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import logger from '../utils/log';
|
|
5
|
+
import { getUrlPathWithLocale } from '../utils/localization';
|
|
6
|
+
import { PzNextRequest } from '.';
|
|
7
|
+
|
|
8
|
+
const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
|
|
9
|
+
if (stream) {
|
|
10
|
+
const chunks = [];
|
|
11
|
+
let result = '';
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
for await (const chunk of stream as any) {
|
|
15
|
+
chunks.push(Buffer.from(chunk));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
result = Buffer.concat(chunks).toString('utf-8');
|
|
19
|
+
} catch (error) {
|
|
20
|
+
logger.error('Error while reading body stream', {
|
|
21
|
+
middleware: 'saved-card-redirection',
|
|
22
|
+
error
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const withSavedCardRedirection =
|
|
32
|
+
(middleware: NextMiddleware) =>
|
|
33
|
+
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
34
|
+
const url = req.nextUrl.clone();
|
|
35
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
36
|
+
const sessionId = req.cookies.get('osessionid');
|
|
37
|
+
|
|
38
|
+
if (url.search.indexOf('SavedCardThreeDSecurePage') === -1) {
|
|
39
|
+
return middleware(req, event);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
|
|
43
|
+
const requestHeaders = {
|
|
44
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
45
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
|
+
Cookie: req.headers.get('cookie') ?? '',
|
|
47
|
+
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
48
|
+
'x-forwarded-for': ip
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const body = await streamToString(req.body);
|
|
53
|
+
|
|
54
|
+
if (!sessionId) {
|
|
55
|
+
logger.warn(
|
|
56
|
+
'Make sure that the SESSION_COOKIE_SAMESITE environment variable is set to None in Commerce.',
|
|
57
|
+
{
|
|
58
|
+
middleware: 'saved-card-redirection',
|
|
59
|
+
ip
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return NextResponse.redirect(
|
|
64
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
65
|
+
'/orders/checkout/',
|
|
66
|
+
req.cookies.get('pz-locale')?.value
|
|
67
|
+
)}`,
|
|
68
|
+
303
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const request = await fetch(requestUrl, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: requestHeaders,
|
|
75
|
+
body
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
logger.info('Complete 3D payment request', {
|
|
79
|
+
requestUrl,
|
|
80
|
+
status: request.status,
|
|
81
|
+
requestHeaders,
|
|
82
|
+
ip
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const response = await request.json();
|
|
86
|
+
|
|
87
|
+
const { context_list: contextList, errors } = response;
|
|
88
|
+
const redirectionContext = contextList?.find(
|
|
89
|
+
(context) => context.page_context?.redirect_url
|
|
90
|
+
);
|
|
91
|
+
const redirectUrl = redirectionContext?.page_context?.redirect_url;
|
|
92
|
+
|
|
93
|
+
if (errors && Object.keys(errors).length) {
|
|
94
|
+
logger.error('Error while completing 3D payment', {
|
|
95
|
+
middleware: 'saved-card-redirection',
|
|
96
|
+
errors,
|
|
97
|
+
requestHeaders,
|
|
98
|
+
ip
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return NextResponse.redirect(
|
|
102
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
103
|
+
'/orders/checkout/',
|
|
104
|
+
req.cookies.get('pz-locale')?.value
|
|
105
|
+
)}`,
|
|
106
|
+
{
|
|
107
|
+
status: 303,
|
|
108
|
+
headers: {
|
|
109
|
+
'Set-Cookie': `pz-pos-error=${JSON.stringify(errors)}; path=/;`
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
logger.info('Order success page context list', {
|
|
116
|
+
middleware: 'saved-card-redirection',
|
|
117
|
+
contextList,
|
|
118
|
+
ip
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (!redirectUrl) {
|
|
122
|
+
logger.warn(
|
|
123
|
+
'No redirection url for order success page found in page_context. Redirecting to checkout page.',
|
|
124
|
+
{
|
|
125
|
+
middleware: 'saved-card-redirection',
|
|
126
|
+
requestHeaders,
|
|
127
|
+
response: JSON.stringify(response),
|
|
128
|
+
ip
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
133
|
+
'/orders/checkout/',
|
|
134
|
+
req.cookies.get('pz-locale')?.value
|
|
135
|
+
)}`;
|
|
136
|
+
|
|
137
|
+
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
141
|
+
redirectUrl,
|
|
142
|
+
req.cookies.get('pz-locale')?.value
|
|
143
|
+
)}`;
|
|
144
|
+
|
|
145
|
+
logger.info('Redirecting to order success page', {
|
|
146
|
+
middleware: 'saved-card-redirection',
|
|
147
|
+
redirectUrlWithLocale,
|
|
148
|
+
ip
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Using POST method while redirecting causes an error,
|
|
152
|
+
// So we use 303 status code to change the method to GET
|
|
153
|
+
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
154
|
+
|
|
155
|
+
nextResponse.headers.set(
|
|
156
|
+
'Set-Cookie',
|
|
157
|
+
request.headers.get('set-cookie') ?? ''
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return nextResponse;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
logger.error('Error while completing 3D payment', {
|
|
163
|
+
middleware: 'saved-card-redirection',
|
|
164
|
+
error,
|
|
165
|
+
requestHeaders,
|
|
166
|
+
ip
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return NextResponse.redirect(
|
|
170
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
171
|
+
'/orders/checkout/',
|
|
172
|
+
req.cookies.get('pz-locale')?.value
|
|
173
|
+
)}`,
|
|
174
|
+
303
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export default withSavedCardRedirection;
|
|
@@ -43,7 +43,7 @@ const withThreeDRedirection =
|
|
|
43
43
|
const requestHeaders = {
|
|
44
44
|
'X-Requested-With': 'XMLHttpRequest',
|
|
45
45
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
|
-
Cookie:
|
|
46
|
+
Cookie: req.headers.get('cookie') ?? '',
|
|
47
47
|
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
48
48
|
'x-forwarded-for': ip
|
|
49
49
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextFetchEvent, NextMiddleware } from 'next/server';
|
|
1
|
+
import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';
|
|
2
2
|
import settings from 'settings';
|
|
3
3
|
import { PzNextRequest } from '.';
|
|
4
4
|
import logger from '../utils/log';
|
|
@@ -58,7 +58,19 @@ const withUrlRedirection =
|
|
|
58
58
|
req.middlewareParams.rewrites.locale
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
const setCookies = request.headers.getSetCookie();
|
|
62
|
+
|
|
63
|
+
const response = NextResponse.redirect(redirectUrl.toString(), {
|
|
64
|
+
status: request.status
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (setCookies && setCookies.length > 0) {
|
|
68
|
+
for (const cookie of setCookies) {
|
|
69
|
+
response.headers.append('Set-Cookie', cookie);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return response;
|
|
62
74
|
}
|
|
63
75
|
} catch (error) {
|
|
64
76
|
logger.error('withUrlRedirection error', {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/next",
|
|
3
3
|
"description": "Core package for Project Zero Next",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.61.0-rc.23",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"set-cookie-parser": "2.6.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@akinon/eslint-plugin-projectzero": "1.
|
|
33
|
+
"@akinon/eslint-plugin-projectzero": "1.61.0-rc.23",
|
|
34
34
|
"@types/react-redux": "7.1.30",
|
|
35
35
|
"@types/set-cookie-parser": "2.4.7",
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
package/plugins.d.ts
CHANGED
|
@@ -21,4 +21,10 @@ declare module '@akinon/pz-otp' {
|
|
|
21
21
|
|
|
22
22
|
declare module '@akinon/pz-otp/src/redux/reducer' {
|
|
23
23
|
export const showPopup: any;
|
|
24
|
+
export const hidePopup: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '@akinon/pz-saved-card' {
|
|
28
|
+
export const savedCardReducer: any;
|
|
29
|
+
export const SavedCardOption: any;
|
|
24
30
|
}
|
package/plugins.js
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
import { Middleware } from '@reduxjs/toolkit';
|
|
4
4
|
import {
|
|
5
5
|
setAddressList,
|
|
6
|
+
setAttributeBasedShippingOptions,
|
|
6
7
|
setBankAccounts,
|
|
7
8
|
setCanGuestPurchase,
|
|
8
9
|
setCardType,
|
|
10
|
+
setCreditPaymentOptions,
|
|
11
|
+
setDataSourceShippingOptions,
|
|
9
12
|
setDeliveryOptions,
|
|
10
13
|
setErrors,
|
|
11
14
|
setHasGiftBox,
|
|
@@ -16,8 +19,7 @@ import {
|
|
|
16
19
|
setPreOrder,
|
|
17
20
|
setRetailStores,
|
|
18
21
|
setShippingOptions,
|
|
19
|
-
setShippingStepCompleted
|
|
20
|
-
setCreditPaymentOptions
|
|
22
|
+
setShippingStepCompleted
|
|
21
23
|
} from '../../redux/reducers/checkout';
|
|
22
24
|
import { RootState, TypedDispatch } from 'redux/store';
|
|
23
25
|
import { checkoutApi } from '../../data/client/checkout';
|
|
@@ -26,6 +28,7 @@ import { getCookie, setCookie } from '../../utils';
|
|
|
26
28
|
import settings from 'settings';
|
|
27
29
|
import { LocaleUrlStrategy } from '../../localization';
|
|
28
30
|
import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
|
|
31
|
+
import { showRedirectionIframe } from '../../utils/redirection-iframe';
|
|
29
32
|
|
|
30
33
|
interface CheckoutResult {
|
|
31
34
|
payload: {
|
|
@@ -73,8 +76,10 @@ export const preOrderMiddleware: Middleware = ({
|
|
|
73
76
|
deliveryOptions,
|
|
74
77
|
addressList: addresses,
|
|
75
78
|
shippingOptions,
|
|
79
|
+
dataSourceShippingOptions,
|
|
76
80
|
paymentOptions,
|
|
77
|
-
installmentOptions
|
|
81
|
+
installmentOptions,
|
|
82
|
+
attributeBasedShippingOptions
|
|
78
83
|
} = getState().checkout;
|
|
79
84
|
const { endpoints: apiEndpoints } = checkoutApi;
|
|
80
85
|
|
|
@@ -107,7 +112,8 @@ export const preOrderMiddleware: Middleware = ({
|
|
|
107
112
|
if (
|
|
108
113
|
(!preOrder.shipping_address || !preOrder.billing_address) &&
|
|
109
114
|
addresses.length > 0 &&
|
|
110
|
-
preOrder.delivery_option
|
|
115
|
+
(!preOrder.delivery_option ||
|
|
116
|
+
preOrder.delivery_option.delivery_option_type === 'customer')
|
|
111
117
|
) {
|
|
112
118
|
dispatch(
|
|
113
119
|
apiEndpoints.setAddresses.initiate({
|
|
@@ -125,11 +131,49 @@ export const preOrderMiddleware: Middleware = ({
|
|
|
125
131
|
dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
|
|
126
132
|
}
|
|
127
133
|
|
|
134
|
+
if (
|
|
135
|
+
dataSourceShippingOptions.length > 0 &&
|
|
136
|
+
!preOrder.data_source_shipping_options
|
|
137
|
+
) {
|
|
138
|
+
const selectedDataSourceShippingOptionsPks =
|
|
139
|
+
dataSourceShippingOptions.map(
|
|
140
|
+
(opt) => opt.data_source_shipping_options[0].pk
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
dispatch(
|
|
144
|
+
apiEndpoints.setDataSourceShippingOptions.initiate(
|
|
145
|
+
selectedDataSourceShippingOptionsPks
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
Object.keys(attributeBasedShippingOptions).length > 0 &&
|
|
152
|
+
!preOrder.attribute_based_shipping_options
|
|
153
|
+
) {
|
|
154
|
+
const initialSelectedOptions: Record<string, number> = Object.fromEntries(
|
|
155
|
+
Object.entries(attributeBasedShippingOptions).map(([key, options]) => [
|
|
156
|
+
key,
|
|
157
|
+
options.attribute_based_shipping_options[0].pk
|
|
158
|
+
])
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
dispatch(
|
|
162
|
+
apiEndpoints.setAttributeBasedShippingOptions.initiate(
|
|
163
|
+
initialSelectedOptions
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
128
168
|
if (!preOrder.payment_option && paymentOptions.length > 0) {
|
|
129
169
|
dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
|
|
130
170
|
}
|
|
131
171
|
|
|
132
|
-
if (
|
|
172
|
+
if (
|
|
173
|
+
!preOrder.installment &&
|
|
174
|
+
preOrder.payment_option?.payment_type !== 'saved_card' &&
|
|
175
|
+
installmentOptions.length > 0
|
|
176
|
+
) {
|
|
133
177
|
dispatch(
|
|
134
178
|
apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
|
|
135
179
|
);
|
|
@@ -163,6 +207,7 @@ export const contextListMiddleware: Middleware = ({
|
|
|
163
207
|
if (result?.payload?.context_list) {
|
|
164
208
|
result.payload.context_list.forEach((context) => {
|
|
165
209
|
const redirectUrl = context.page_context.redirect_url;
|
|
210
|
+
const isIframe = context.page_context.is_frame ?? false;
|
|
166
211
|
|
|
167
212
|
if (redirectUrl) {
|
|
168
213
|
const currentLocale = getCookie('pz-locale');
|
|
@@ -181,16 +226,19 @@ export const contextListMiddleware: Middleware = ({
|
|
|
181
226
|
}
|
|
182
227
|
|
|
183
228
|
const urlObj = new URL(url, window.location.origin);
|
|
229
|
+
const isMobileDevice =
|
|
230
|
+
isMobileApp ||
|
|
231
|
+
/iPad|iPhone|iPod|Android/i.test(navigator.userAgent);
|
|
232
|
+
const isIframePaymentOptionExcluded =
|
|
233
|
+
settings.checkout?.iframeExcludedPaymentOptions?.includes(
|
|
234
|
+
result.payload?.pre_order?.payment_option?.slug
|
|
235
|
+
);
|
|
184
236
|
urlObj.searchParams.set('t', new Date().getTime().toString());
|
|
185
237
|
|
|
186
|
-
if (
|
|
187
|
-
(isMobileApp ||
|
|
188
|
-
/iPad|iPhone|iPod|Android/i.test(navigator.userAgent)) &&
|
|
189
|
-
!settings.checkout?.iframeExcludedPaymentOptions?.includes(
|
|
190
|
-
result.payload?.pre_order?.payment_option?.slug
|
|
191
|
-
)
|
|
192
|
-
) {
|
|
238
|
+
if (isMobileDevice && !isIframePaymentOptionExcluded) {
|
|
193
239
|
showMobile3dIframe(urlObj.toString());
|
|
240
|
+
} else if (isIframe && !isIframePaymentOptionExcluded) {
|
|
241
|
+
showRedirectionIframe(urlObj.toString());
|
|
194
242
|
} else {
|
|
195
243
|
window.location.href = urlObj.toString();
|
|
196
244
|
}
|
|
@@ -220,12 +268,28 @@ export const contextListMiddleware: Middleware = ({
|
|
|
220
268
|
dispatch(setShippingOptions(context.page_context.shipping_options));
|
|
221
269
|
}
|
|
222
270
|
|
|
271
|
+
if (context.page_context.data_sources) {
|
|
272
|
+
dispatch(
|
|
273
|
+
setDataSourceShippingOptions(context.page_context.data_sources)
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (context.page_context.attribute_based_shipping_options) {
|
|
278
|
+
dispatch(
|
|
279
|
+
setAttributeBasedShippingOptions(
|
|
280
|
+
context.page_context.attribute_based_shipping_options
|
|
281
|
+
)
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
223
285
|
if (context.page_context.payment_options) {
|
|
224
286
|
dispatch(setPaymentOptions(context.page_context.payment_options));
|
|
225
287
|
}
|
|
226
288
|
|
|
227
289
|
if (context.page_context.credit_payment_options) {
|
|
228
|
-
dispatch(
|
|
290
|
+
dispatch(
|
|
291
|
+
setCreditPaymentOptions(context.page_context.credit_payment_options)
|
|
292
|
+
);
|
|
229
293
|
}
|
|
230
294
|
|
|
231
295
|
if (context.page_context.payment_choices) {
|
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
CheckoutCreditPaymentOption,
|
|
15
15
|
PreOrder,
|
|
16
16
|
RetailStore,
|
|
17
|
-
ShippingOption
|
|
17
|
+
ShippingOption,
|
|
18
|
+
DataSource,
|
|
19
|
+
AttributeBasedShippingOption
|
|
18
20
|
} from '../../types';
|
|
19
21
|
|
|
20
22
|
export interface CheckoutState {
|
|
@@ -36,6 +38,7 @@ export interface CheckoutState {
|
|
|
36
38
|
addressList: Address[];
|
|
37
39
|
deliveryOptions: DeliveryOption[];
|
|
38
40
|
shippingOptions: ShippingOption[];
|
|
41
|
+
dataSourceShippingOptions: DataSource[];
|
|
39
42
|
paymentOptions: PaymentOption[];
|
|
40
43
|
creditPaymentOptions: CheckoutCreditPaymentOption[];
|
|
41
44
|
selectedCreditPaymentPk: number;
|
|
@@ -46,6 +49,8 @@ export interface CheckoutState {
|
|
|
46
49
|
selectedBankAccountPk: number;
|
|
47
50
|
loyaltyBalance?: string;
|
|
48
51
|
retailStores: RetailStore[];
|
|
52
|
+
attributeBasedShippingOptions: AttributeBasedShippingOption[];
|
|
53
|
+
selectedShippingOptions: Record<string, number>;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
const initialState: CheckoutState = {
|
|
@@ -67,6 +72,7 @@ const initialState: CheckoutState = {
|
|
|
67
72
|
addressList: [],
|
|
68
73
|
deliveryOptions: [],
|
|
69
74
|
shippingOptions: [],
|
|
75
|
+
dataSourceShippingOptions: [],
|
|
70
76
|
paymentOptions: [],
|
|
71
77
|
creditPaymentOptions: [],
|
|
72
78
|
selectedCreditPaymentPk: null,
|
|
@@ -75,7 +81,9 @@ const initialState: CheckoutState = {
|
|
|
75
81
|
installmentOptions: [],
|
|
76
82
|
bankAccounts: [],
|
|
77
83
|
selectedBankAccountPk: null,
|
|
78
|
-
retailStores: []
|
|
84
|
+
retailStores: [],
|
|
85
|
+
attributeBasedShippingOptions: [],
|
|
86
|
+
selectedShippingOptions: {}
|
|
79
87
|
};
|
|
80
88
|
|
|
81
89
|
const checkoutSlice = createSlice({
|
|
@@ -121,6 +129,9 @@ const checkoutSlice = createSlice({
|
|
|
121
129
|
setShippingOptions(state, { payload }) {
|
|
122
130
|
state.shippingOptions = payload;
|
|
123
131
|
},
|
|
132
|
+
setDataSourceShippingOptions(state, { payload }) {
|
|
133
|
+
state.dataSourceShippingOptions = payload;
|
|
134
|
+
},
|
|
124
135
|
setPaymentOptions(state, { payload }) {
|
|
125
136
|
state.paymentOptions = payload;
|
|
126
137
|
},
|
|
@@ -150,6 +161,12 @@ const checkoutSlice = createSlice({
|
|
|
150
161
|
},
|
|
151
162
|
setRetailStores(state, { payload }) {
|
|
152
163
|
state.retailStores = payload;
|
|
164
|
+
},
|
|
165
|
+
setAttributeBasedShippingOptions(state, { payload }) {
|
|
166
|
+
state.attributeBasedShippingOptions = payload;
|
|
167
|
+
},
|
|
168
|
+
setSelectedShippingOptions: (state, { payload }) => {
|
|
169
|
+
state.selectedShippingOptions = payload;
|
|
153
170
|
}
|
|
154
171
|
}
|
|
155
172
|
});
|
|
@@ -168,6 +185,7 @@ export const {
|
|
|
168
185
|
setAddressList,
|
|
169
186
|
setDeliveryOptions,
|
|
170
187
|
setShippingOptions,
|
|
188
|
+
setDataSourceShippingOptions,
|
|
171
189
|
setPaymentOptions,
|
|
172
190
|
setCreditPaymentOptions,
|
|
173
191
|
setSelectedCreditPaymentPk,
|
|
@@ -177,7 +195,9 @@ export const {
|
|
|
177
195
|
setBankAccounts,
|
|
178
196
|
setSelectedBankAccountPk,
|
|
179
197
|
setLoyaltyBalance,
|
|
180
|
-
setRetailStores
|
|
198
|
+
setRetailStores,
|
|
199
|
+
setAttributeBasedShippingOptions,
|
|
200
|
+
setSelectedShippingOptions
|
|
181
201
|
} = checkoutSlice.actions;
|
|
182
202
|
|
|
183
203
|
export default checkoutSlice.reducer;
|
package/redux/reducers/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { api } from '../../data/client/api';
|
|
|
7
7
|
// Plugin reducers
|
|
8
8
|
import { masterpassReducer } from '@akinon/pz-masterpass';
|
|
9
9
|
import { otpReducer } from '@akinon/pz-otp';
|
|
10
|
+
import { savedCardReducer } from '@akinon/pz-saved-card';
|
|
10
11
|
|
|
11
12
|
const reducers = {
|
|
12
13
|
[api.reducerPath]: api.reducer,
|
|
@@ -15,7 +16,8 @@ const reducers = {
|
|
|
15
16
|
config: configReducer,
|
|
16
17
|
header: headerReducer,
|
|
17
18
|
masterpass: masterpassReducer,
|
|
18
|
-
otp: otpReducer
|
|
19
|
+
otp: otpReducer,
|
|
20
|
+
savedCard: savedCardReducer
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export default reducers;
|
package/routes/pretty-url.tsx
CHANGED
|
@@ -63,14 +63,12 @@ export async function generateMetadata({ params }: PageProps) {
|
|
|
63
63
|
.filter((x) => !x.startsWith('searchparams'))
|
|
64
64
|
.join('/');
|
|
65
65
|
|
|
66
|
-
const searchParams =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
) ?? {}
|
|
73
|
-
).entries()
|
|
66
|
+
const searchParams = new URLSearchParams(
|
|
67
|
+
decodeURIComponent(
|
|
68
|
+
prettyurl
|
|
69
|
+
.find((x) => x.startsWith('searchparams'))
|
|
70
|
+
?.replace('searchparams%7C', '')
|
|
71
|
+
) ?? {}
|
|
74
72
|
);
|
|
75
73
|
|
|
76
74
|
const prettyUrlResult = await resolvePrettyUrlHandler(pageSlug, null)();
|
|
@@ -162,7 +160,7 @@ export default async function Page({ params }) {
|
|
|
162
160
|
...params,
|
|
163
161
|
pk: result.pk
|
|
164
162
|
},
|
|
165
|
-
searchParams
|
|
163
|
+
searchParams: new URLSearchParams(searchParams)
|
|
166
164
|
};
|
|
167
165
|
|
|
168
166
|
if (result.path.startsWith('/category/')) {
|
package/types/commerce/b2b.ts
CHANGED
|
@@ -72,7 +72,7 @@ export type BasketItemType = {
|
|
|
72
72
|
divisions: BasketItemDivision[];
|
|
73
73
|
product: ProductB2b;
|
|
74
74
|
product_remote_id: number;
|
|
75
|
-
}
|
|
75
|
+
};
|
|
76
76
|
|
|
77
77
|
export type BasketParams = {
|
|
78
78
|
division: string;
|
|
@@ -91,7 +91,7 @@ export type CreateQuotationParams = {
|
|
|
91
91
|
export type UpdateProductParams = {
|
|
92
92
|
product_remote_id: number;
|
|
93
93
|
division: number;
|
|
94
|
-
quantity: number
|
|
94
|
+
quantity: number;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
export type DeleteProductParams = {
|
|
@@ -115,3 +115,13 @@ export type DraftResponse = {
|
|
|
115
115
|
total_amount: number;
|
|
116
116
|
total_quantity: number;
|
|
117
117
|
};
|
|
118
|
+
|
|
119
|
+
export type BasketStatusResponse = {
|
|
120
|
+
is_ready: boolean;
|
|
121
|
+
status: string;
|
|
122
|
+
url: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type ExportBasketResponse = {
|
|
126
|
+
cache_key: string;
|
|
127
|
+
};
|
|
@@ -34,6 +34,23 @@ export interface ShippingOption {
|
|
|
34
34
|
slug: string;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export interface DataSource {
|
|
38
|
+
pk: number;
|
|
39
|
+
name: string;
|
|
40
|
+
data_source_shipping_options: DataSourceShippingOption[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DataSourceShippingOption {
|
|
44
|
+
pk: number;
|
|
45
|
+
shipping_amount: string;
|
|
46
|
+
shipping_option_name: string;
|
|
47
|
+
shipping_option_logo: string | null;
|
|
48
|
+
data_source: {
|
|
49
|
+
pk: number;
|
|
50
|
+
title: string | null;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
37
54
|
export interface CheckoutAddressType {
|
|
38
55
|
label: string;
|
|
39
56
|
text: string;
|
|
@@ -69,6 +86,7 @@ export interface PreOrder {
|
|
|
69
86
|
total_amount?: string;
|
|
70
87
|
total_amount_with_interest?: string;
|
|
71
88
|
unpaid_amount?: string;
|
|
89
|
+
notes?: string;
|
|
72
90
|
user_phone_number?: string;
|
|
73
91
|
loyalty_money?: string;
|
|
74
92
|
currency_type_label?: string;
|
|
@@ -79,6 +97,8 @@ export interface PreOrder {
|
|
|
79
97
|
retail_store?: RetailStore;
|
|
80
98
|
gift_box?: GiftBox;
|
|
81
99
|
credit_payment_option?: CheckoutCreditPaymentOption;
|
|
100
|
+
data_source_shipping_options: any;
|
|
101
|
+
attribute_based_shipping_options?: AttributeBasedShippingOption[];
|
|
82
102
|
bags?: Product[];
|
|
83
103
|
bags_fee?: string;
|
|
84
104
|
extra_field?: ExtraField;
|
|
@@ -123,6 +143,7 @@ export interface CheckoutContext {
|
|
|
123
143
|
redirect_url?: string;
|
|
124
144
|
context_data?: any;
|
|
125
145
|
balance?: string;
|
|
146
|
+
attribute_based_shipping_options?: AttributeBasedShippingOption[];
|
|
126
147
|
[key: string]: any;
|
|
127
148
|
};
|
|
128
149
|
}
|
|
@@ -148,3 +169,13 @@ export interface BankAccount {
|
|
|
148
169
|
pk: number;
|
|
149
170
|
sort_order: number;
|
|
150
171
|
}
|
|
172
|
+
|
|
173
|
+
export interface AttributeBasedShippingOption {
|
|
174
|
+
pk: number;
|
|
175
|
+
shipping_amount: string | null;
|
|
176
|
+
shipping_option_name: string | null;
|
|
177
|
+
shipping_option_logo: string | null;
|
|
178
|
+
attribute_value: string | null;
|
|
179
|
+
attribute_key: string;
|
|
180
|
+
[key: string]: any;
|
|
181
|
+
}
|