@magento/peregrine 13.1.1 → 13.2.1-alpha.2

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.
@@ -178,10 +178,13 @@ export const useBillingAddress = props => {
178
178
  * shipping address.
179
179
  */
180
180
  const setShippingAddressAsBillingAddress = useCallback(() => {
181
- const shippingAddress = shippingAddressData
181
+ var shippingAddress = shippingAddressData
182
182
  ? mapAddressData(shippingAddressData.cart.shippingAddresses[0])
183
183
  : {};
184
184
 
185
+ shippingAddress.region =
186
+ shippingAddress.region == null ? '' : shippingAddress.region;
187
+
185
188
  updateBillingAddress({
186
189
  variables: {
187
190
  cartId,
@@ -234,10 +234,13 @@ export const useCreditCard = props => {
234
234
  * shipping address.
235
235
  */
236
236
  const setShippingAddressAsBillingAddress = useCallback(() => {
237
- const shippingAddress = shippingAddressData
237
+ var shippingAddress = shippingAddressData
238
238
  ? mapAddressData(shippingAddressData.cart.shippingAddresses[0])
239
239
  : {};
240
240
 
241
+ shippingAddress.region =
242
+ shippingAddress.region == null ? '' : shippingAddress.region;
243
+
241
244
  updateBillingAddress({
242
245
  variables: {
243
246
  cartId,
@@ -70,9 +70,8 @@ export const useGuestForm = props => {
70
70
  ...address,
71
71
  // Cleans up the street array when values are null or undefined
72
72
  street: address.street.filter(e => e),
73
- // region_id is used for field select and region is used for field input
74
- region: region.region_id || region.region,
75
- country_code: country
73
+ country_code: country,
74
+ region: region.region_id || region.region
76
75
  }
77
76
  }
78
77
  });
@@ -80,7 +79,6 @@ export const useGuestForm = props => {
80
79
  } catch {
81
80
  return;
82
81
  }
83
-
84
82
  if (afterSubmit) {
85
83
  afterSubmit();
86
84
  }
@@ -4,5 +4,6 @@ export const CartTriggerFragment = gql`
4
4
  fragment CartTriggerFragment on Cart {
5
5
  id
6
6
  total_quantity
7
+ total_summary_quantity_including_config
7
8
  }
8
9
  `;
@@ -52,7 +52,7 @@ export const useCartTrigger = props => {
52
52
  errorPolicy: 'all'
53
53
  });
54
54
 
55
- const itemCount = data?.cart?.total_quantity || 0;
55
+ const itemCount = data?.cart?.total_summary_quantity_including_config || 0;
56
56
 
57
57
  const handleTriggerClick = useCallback(() => {
58
58
  // Open the mini cart.
@@ -11,6 +11,10 @@ export const ADD_PRODUCT_TO_CART = gql`
11
11
  ...CartTriggerFragment
12
12
  ...MiniCartFragment
13
13
  }
14
+ user_errors {
15
+ code
16
+ message
17
+ }
14
18
  }
15
19
  }
16
20
  ${CartTriggerFragment}
@@ -289,7 +289,11 @@ export const useProductFullDetail = props => {
289
289
 
290
290
  const [
291
291
  addProductToCart,
292
- { error: errorAddingProductToCart, loading: isAddProductLoading }
292
+ {
293
+ data: addToCartResponseData,
294
+ error: errorAddingProductToCart,
295
+ loading: isAddProductLoading
296
+ }
293
297
  ] = useMutation(operations.addProductToCartMutation);
294
298
 
295
299
  const breadcrumbCategoryId = useMemo(
@@ -556,12 +560,14 @@ export const useProductFullDetail = props => {
556
560
  deriveErrorMessage([
557
561
  errorAddingSimpleProduct,
558
562
  errorAddingConfigurableProduct,
559
- errorAddingProductToCart
563
+ errorAddingProductToCart,
564
+ ...(addToCartResponseData?.addProductsToCart?.user_errors || [])
560
565
  ]),
561
566
  [
562
567
  errorAddingConfigurableProduct,
563
568
  errorAddingProductToCart,
564
- errorAddingSimpleProduct
569
+ errorAddingSimpleProduct,
570
+ addToCartResponseData
565
571
  ]
566
572
  );
567
573
 
@@ -100,10 +100,7 @@ export const useCategory = props => {
100
100
  called: introspectionCalled,
101
101
  data: introspectionData,
102
102
  loading: introspectionLoading
103
- } = useQuery(getFilterInputsQuery, {
104
- fetchPolicy: 'cache-and-network',
105
- nextFetchPolicy: 'cache-first'
106
- });
103
+ } = useQuery(getFilterInputsQuery);
107
104
 
108
105
  // Create a type map we can reference later to ensure we pass valid args
109
106
  // to the graphql query.
@@ -27,6 +27,16 @@ export const GET_PRODUCT_FILTERS_BY_SEARCH = gql`
27
27
  }
28
28
  `;
29
29
 
30
+ export const GET_SEARCH_TERM_DATA = gql`
31
+ query getSearchTermData($search: String) {
32
+ searchTerm(Search: $search) {
33
+ query_text
34
+ redirect
35
+ popularity
36
+ }
37
+ }
38
+ `;
39
+
30
40
  export const PRODUCT_SEARCH = gql`
31
41
  query ProductSearch(
32
42
  $currentPage: Int = 1
@@ -106,6 +116,7 @@ export const GET_SEARCH_AVAILABLE_SORT_METHODS = gql`
106
116
  export default {
107
117
  getFilterInputsQuery: GET_FILTER_INPUTS,
108
118
  getPageSize: GET_PAGE_SIZE,
119
+ getSearchTermData: GET_SEARCH_TERM_DATA,
109
120
  getProductFiltersBySearchQuery: GET_PRODUCT_FILTERS_BY_SEARCH,
110
121
  getSearchAvailableSortMethods: GET_SEARCH_AVAILABLE_SORT_METHODS,
111
122
  productSearchQuery: PRODUCT_SEARCH
@@ -26,6 +26,7 @@ export const useSearchPage = (props = {}) => {
26
26
  const {
27
27
  getFilterInputsQuery,
28
28
  getPageSize,
29
+ getSearchTermData,
29
30
  getProductFiltersBySearchQuery,
30
31
  getSearchAvailableSortMethods,
31
32
  productSearchQuery
@@ -36,6 +37,18 @@ export const useSearchPage = (props = {}) => {
36
37
  nextFetchPolicy: 'cache-first'
37
38
  });
38
39
 
40
+ const [getSearchTermMethod, { data: SearchTermQueryData }] = useLazyQuery(
41
+ getSearchTermData
42
+ );
43
+
44
+ if (SearchTermQueryData !== undefined) {
45
+ const [...redirectData] = [SearchTermQueryData];
46
+ const redirectUrl = redirectData[0].searchTerm?.redirect;
47
+ if (redirectUrl !== null) {
48
+ window.location.replace(redirectUrl);
49
+ }
50
+ }
51
+
39
52
  const [getSortMethods, { data: sortData }] = useLazyQuery(
40
53
  getSearchAvailableSortMethods,
41
54
  {
@@ -231,6 +244,16 @@ export const useSearchPage = (props = {}) => {
231
244
  };
232
245
  }, [data, setTotalPages]);
233
246
 
247
+ useEffect(() => {
248
+ if (inputText) {
249
+ getSearchTermMethod({
250
+ variables: {
251
+ search: inputText
252
+ }
253
+ });
254
+ }
255
+ }, [inputText, getSearchTermMethod]);
256
+
234
257
  useEffect(() => {
235
258
  if (inputText) {
236
259
  getSortMethods({
@@ -273,7 +296,7 @@ export const useSearchPage = (props = {}) => {
273
296
  useScrollTopOnChange(currentPage);
274
297
 
275
298
  const availableSortMethods = sortData
276
- ? sortData.products.sort_fields.options
299
+ ? sortData.products.sort_fields?.options
277
300
  : null;
278
301
 
279
302
  return {
@@ -13,6 +13,7 @@ import { useEventingContext } from '../../context/eventing';
13
13
 
14
14
  export const useSignIn = props => {
15
15
  const {
16
+ handleTriggerClick,
16
17
  getCartDetailsQuery,
17
18
  setDefaultUsername,
18
19
  showCreateAccount,
@@ -66,6 +67,7 @@ export const useSignIn = props => {
66
67
  const handleSubmit = useCallback(
67
68
  async ({ email, password }) => {
68
69
  setIsSigningIn(true);
70
+ handleTriggerClick();
69
71
  try {
70
72
  // Get source cart id (guest cart id).
71
73
  const sourceCartId = cartId;
@@ -142,7 +144,8 @@ export const useSignIn = props => {
142
144
  fetchUserDetails,
143
145
  getCartDetails,
144
146
  fetchCartDetails,
145
- dispatch
147
+ dispatch,
148
+ handleTriggerClick
146
149
  ]
147
150
  );
148
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magento/peregrine",
3
- "version": "13.1.1",
3
+ "version": "13.2.1-alpha.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },