@akinon/next 1.43.0-rc.7 → 1.43.0-rc.9

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.43.0-rc.9
4
+
5
+ ### Minor Changes
6
+
7
+ - bc2b411: ZERO-2825: Add attribute-based shipping options to checkout page
8
+
9
+ ## 1.43.0-rc.8
10
+
11
+ ### Minor Changes
12
+
13
+ - 70279e7: ZERO-2817: Add metrics endpoint in default middleware
14
+ - 9d94f7e: ZERO-2820: update parent pk usage for menu generator
15
+
3
16
  ## 1.43.0-rc.7
4
17
 
5
18
  ### Minor Changes
@@ -676,6 +676,25 @@ export const checkoutApi = api.injectEndpoints({
676
676
  notes
677
677
  }
678
678
  })
679
+ }),
680
+ setAttributeBasedShippingOptions: build.mutation<
681
+ CheckoutResponse,
682
+ Record<string, number>
683
+ >({
684
+ query: (options) => ({
685
+ url: buildClientRequestUrl(checkout.setAttributeBasedShippingOption, {
686
+ useFormData: true
687
+ }),
688
+ method: 'POST',
689
+ body: {
690
+ attribute_based_shipping_options: JSON.stringify(options)
691
+ }
692
+ }),
693
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
694
+ dispatch(setShippingStepBusy(true));
695
+ await queryFulfilled;
696
+ dispatch(setShippingStepBusy(false));
697
+ }
679
698
  })
680
699
  }),
681
700
  overrideExisting: false
@@ -711,5 +730,6 @@ export const {
711
730
  useCompleteLoyaltyPaymentMutation,
712
731
  useGetCheckoutLoyaltyBalanceQuery,
713
732
  usePayWithLoyaltyBalanceMutation,
714
- useSetOrderNoteMutation
733
+ useSetOrderNoteMutation,
734
+ useSetAttributeBasedShippingOptionsMutation
715
735
  } = checkoutApi;
package/data/urls.ts CHANGED
@@ -110,7 +110,9 @@ export const checkout = {
110
110
  completeLoyaltyPayment: '/orders/checkout/?page=LoyaltyPaymentSelectedPage',
111
111
  loyaltyMoneyUsage: '/orders/checkout/?page=LoyaltyMoneyUsagePage',
112
112
  setOrderNote: '/orders/checkout/?page=OrderNotePage',
113
- couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage'
113
+ couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage',
114
+ setAttributeBasedShippingOption:
115
+ '/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage'
114
116
  };
115
117
 
116
118
  export const flatpage = {
@@ -69,6 +69,10 @@ const withPzDefault =
69
69
  return NextResponse.json({ status: 'ok' });
70
70
  }
71
71
 
72
+ if (url.pathname.startsWith('/metrics')) {
73
+ return new NextResponse(null, { status: 200 });
74
+ }
75
+
72
76
  if (req.nextUrl.pathname.startsWith('/.well-known')) {
73
77
  const url = new URL(`${Settings.commerceUrl}${req.nextUrl.pathname}`);
74
78
  const req_ = await fetch(url.toString());
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.43.0-rc.7",
4
+ "version": "1.43.0-rc.9",
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.43.0-rc.7",
33
+ "@akinon/eslint-plugin-projectzero": "1.43.0-rc.9",
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",
@@ -18,7 +18,8 @@ import {
18
18
  setShippingOptions,
19
19
  setDataSourceShippingOptions,
20
20
  setShippingStepCompleted,
21
- setCreditPaymentOptions
21
+ setCreditPaymentOptions,
22
+ setAttributeBasedShippingOptions
22
23
  } from '../../redux/reducers/checkout';
23
24
  import { RootState, TypedDispatch } from 'redux/store';
24
25
  import { checkoutApi } from '../../data/client/checkout';
@@ -77,7 +78,8 @@ export const preOrderMiddleware: Middleware = ({
77
78
  shippingOptions,
78
79
  dataSourceShippingOptions,
79
80
  paymentOptions,
80
- installmentOptions
81
+ installmentOptions,
82
+ attributeBasedShippingOptions
81
83
  } = getState().checkout;
82
84
  const { endpoints: apiEndpoints } = checkoutApi;
83
85
 
@@ -144,6 +146,24 @@ export const preOrderMiddleware: Middleware = ({
144
146
  );
145
147
  }
146
148
 
149
+ if (
150
+ Object.keys(attributeBasedShippingOptions).length > 0 &&
151
+ !preOrder.attribute_based_shipping_options
152
+ ) {
153
+ const initialSelectedOptions: Record<string, number> = Object.fromEntries(
154
+ Object.entries(attributeBasedShippingOptions).map(([key, options]) => [
155
+ key,
156
+ options[0].pk
157
+ ])
158
+ );
159
+
160
+ dispatch(
161
+ apiEndpoints.setAttributeBasedShippingOptions.initiate(
162
+ initialSelectedOptions
163
+ )
164
+ );
165
+ }
166
+
147
167
  if (!preOrder.payment_option && paymentOptions.length > 0) {
148
168
  dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
149
169
  }
@@ -249,6 +269,14 @@ export const contextListMiddleware: Middleware = ({
249
269
  );
250
270
  }
251
271
 
272
+ if (context.page_context.attribute_based_shipping_options) {
273
+ dispatch(
274
+ setAttributeBasedShippingOptions(
275
+ context.page_context.attribute_based_shipping_options
276
+ )
277
+ );
278
+ }
279
+
252
280
  if (context.page_context.payment_options) {
253
281
  dispatch(setPaymentOptions(context.page_context.payment_options));
254
282
  }
@@ -15,7 +15,8 @@ import {
15
15
  PreOrder,
16
16
  RetailStore,
17
17
  ShippingOption,
18
- DataSource
18
+ DataSource,
19
+ AttributeBasedShippingOption
19
20
  } from '../../types';
20
21
 
21
22
  export interface CheckoutState {
@@ -48,6 +49,8 @@ export interface CheckoutState {
48
49
  selectedBankAccountPk: number;
49
50
  loyaltyBalance?: string;
50
51
  retailStores: RetailStore[];
52
+ attributeBasedShippingOptions: AttributeBasedShippingOption[];
53
+ selectedShippingOptions: Record<string, number>;
51
54
  }
52
55
 
53
56
  const initialState: CheckoutState = {
@@ -78,7 +81,9 @@ const initialState: CheckoutState = {
78
81
  installmentOptions: [],
79
82
  bankAccounts: [],
80
83
  selectedBankAccountPk: null,
81
- retailStores: []
84
+ retailStores: [],
85
+ attributeBasedShippingOptions: [],
86
+ selectedShippingOptions: {}
82
87
  };
83
88
 
84
89
  const checkoutSlice = createSlice({
@@ -156,6 +161,12 @@ const checkoutSlice = createSlice({
156
161
  },
157
162
  setRetailStores(state, { payload }) {
158
163
  state.retailStores = payload;
164
+ },
165
+ setAttributeBasedShippingOptions(state, { payload }) {
166
+ state.attributeBasedShippingOptions = payload;
167
+ },
168
+ setSelectedShippingOptions: (state, { payload }) => {
169
+ state.selectedShippingOptions = payload;
159
170
  }
160
171
  }
161
172
  });
@@ -184,7 +195,9 @@ export const {
184
195
  setBankAccounts,
185
196
  setSelectedBankAccountPk,
186
197
  setLoyaltyBalance,
187
- setRetailStores
198
+ setRetailStores,
199
+ setAttributeBasedShippingOptions,
200
+ setSelectedShippingOptions
188
201
  } = checkoutSlice.actions;
189
202
 
190
203
  export default checkoutSlice.reducer;
@@ -96,6 +96,7 @@ export interface PreOrder {
96
96
  gift_box?: GiftBox;
97
97
  credit_payment_option?: CheckoutCreditPaymentOption;
98
98
  data_source_shipping_options: any;
99
+ attribute_based_shipping_options?: AttributeBasedShippingOption[];
99
100
  }
100
101
 
101
102
  export interface GuestLoginFormParams {
@@ -135,6 +136,7 @@ export interface CheckoutContext {
135
136
  redirect_url?: string;
136
137
  context_data?: any;
137
138
  balance?: string;
139
+ attribute_based_shipping_options?: AttributeBasedShippingOption[];
138
140
  [key: string]: any;
139
141
  };
140
142
  }
@@ -160,3 +162,13 @@ export interface BankAccount {
160
162
  pk: number;
161
163
  sort_order: number;
162
164
  }
165
+
166
+ export interface AttributeBasedShippingOption {
167
+ pk: number;
168
+ shipping_amount: string | null;
169
+ shipping_option_name: string | null;
170
+ shipping_option_logo: string | null;
171
+ attribute_value: string | null;
172
+ attribute_key: string;
173
+ [key: string]: any;
174
+ }
@@ -13,8 +13,8 @@ export const menuGenerator = (arr: MenuItemType[]) => {
13
13
  });
14
14
 
15
15
  Object.values(data).forEach((item) => {
16
- if (item.parent) {
17
- data[item.parent.pk].children.push(item);
16
+ if (item.parent_pk) {
17
+ data[item.parent_pk].children.push(item);
18
18
  } else {
19
19
  tree.push(item);
20
20
  }