@magento/peregrine 12.0.0 → 12.2.0-alpha.1

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.
Files changed (113) hide show
  1. package/lib/Apollo/clearCartDataFromCache.js +11 -12
  2. package/lib/Apollo/clearCustomerDataFromCache.js +15 -8
  3. package/lib/Apollo/policies/index.js +35 -3
  4. package/lib/Toasts/useToasts.js +5 -0
  5. package/lib/context/cart.js +21 -1
  6. package/lib/hooks/useCustomerWishlistSkus/customerWishlist.gql.ce.js +3 -3
  7. package/lib/store/actions/cart/asyncActions.js +2 -3
  8. package/lib/store/actions/user/asyncActions.js +2 -4
  9. package/lib/store/reducers/catalog.js +7 -7
  10. package/lib/store/reducers/user.js +1 -3
  11. package/lib/talons/Adapter/useAdapter.js +80 -11
  12. package/lib/talons/AddToCartDialog/addToCartDialog.gql.js +2 -2
  13. package/lib/talons/AddressBookPage/addressBookPage.gql.js +3 -9
  14. package/lib/talons/Breadcrumbs/breadcrumbs.gql.js +16 -12
  15. package/lib/talons/Breadcrumbs/useBreadcrumbs.js +6 -4
  16. package/lib/talons/CartPage/GiftCards/giftCardQueries.gql.ee.js +2 -2
  17. package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCode.gql.js +2 -3
  18. package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethods.gql.js +1 -1
  19. package/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js +2 -1
  20. package/lib/talons/CartPage/ProductListing/EditModal/__fixtures__/configurableProduct.js +1 -0
  21. package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +10 -7
  22. package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +7 -3
  23. package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +3 -2
  24. package/lib/talons/CartPage/ProductListing/product.gql.js +2 -1
  25. package/lib/talons/CartPage/ProductListing/productListing.gql.ce.js +2 -1
  26. package/lib/talons/CartPage/ProductListing/productListing.gql.ee.js +2 -1
  27. package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +15 -5
  28. package/lib/talons/CartPage/ProductListing/useProduct.js +12 -5
  29. package/lib/talons/CartPage/ProductListing/useProductListing.js +4 -2
  30. package/lib/talons/CartPage/useCartPage.js +4 -3
  31. package/lib/talons/CategoryList/categoryList.gql.js +25 -17
  32. package/lib/talons/CategoryList/useCategoryList.js +6 -1
  33. package/lib/talons/CategoryList/useCategoryTile.js +2 -0
  34. package/lib/talons/CategoryTree/categoryTree.gql.js +18 -12
  35. package/lib/talons/CategoryTree/useCategoryBranch.js +1 -1
  36. package/lib/talons/CategoryTree/useCategoryTree.js +5 -5
  37. package/lib/talons/CheckoutPage/AddressBook/addressBook.gql.js +1 -1
  38. package/lib/talons/CheckoutPage/BillingAddress/billingAddress.gql.js +1 -1
  39. package/lib/talons/CheckoutPage/ItemsReview/__fixtures__/cartItems.js +12 -12
  40. package/lib/talons/CheckoutPage/ItemsReview/itemsReview.gql.js +2 -1
  41. package/lib/talons/CheckoutPage/ItemsReview/itemsReviewFragments.gql.js +11 -5
  42. package/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +12 -6
  43. package/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js +2 -2
  44. package/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js +2 -2
  45. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/customerForm.gql.js +3 -5
  46. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +12 -4
  47. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useGuestForm.js +45 -5
  48. package/lib/talons/CheckoutPage/ShippingInformation/shippingInformation.gql.js +2 -2
  49. package/lib/talons/CheckoutPage/ShippingMethod/shippingMethod.gql.js +1 -1
  50. package/lib/talons/CheckoutPage/checkoutPage.gql.js +2 -2
  51. package/lib/talons/CheckoutPage/checkoutPageFragments.gql.js +4 -2
  52. package/lib/talons/CheckoutPage/useCheckoutPage.js +5 -2
  53. package/lib/talons/Cms/cmsPage.gql.js +0 -4
  54. package/lib/talons/Cms/useCmsPage.js +6 -23
  55. package/lib/talons/CommunicationsPage/communicationsPage.gql.js +2 -2
  56. package/lib/talons/ContactPage/contactUs.gql.js +48 -0
  57. package/lib/talons/ContactPage/index.js +2 -0
  58. package/lib/talons/ContactPage/useContactLink.js +27 -0
  59. package/lib/talons/ContactPage/useContactPage.js +85 -0
  60. package/lib/talons/CreateAccount/createAccount.gql.js +15 -8
  61. package/lib/talons/CreateAccount/useCreateAccount.js +2 -4
  62. package/lib/talons/Footer/footer.gql.js +2 -1
  63. package/lib/talons/FormError/useFormError.js +9 -7
  64. package/lib/talons/Gallery/__fixtures__/apolloMocks.js +2 -2
  65. package/lib/talons/Gallery/gallery.gql.ce.js +2 -1
  66. package/lib/talons/Gallery/gallery.gql.ee.js +2 -1
  67. package/lib/talons/Gallery/useAddToCartButton.js +28 -13
  68. package/lib/talons/Header/storeSwitcher.gql.js +21 -9
  69. package/lib/talons/Header/useCartTrigger.js +3 -3
  70. package/lib/talons/Header/useStoreSwitcher.js +10 -8
  71. package/lib/talons/MagentoRoute/magentoRoute.gql.js +4 -2
  72. package/lib/talons/MagentoRoute/useMagentoRoute.js +39 -33
  73. package/lib/talons/MegaMenu/megaMenu.gql.js +10 -5
  74. package/lib/talons/MegaMenu/useMegaMenu.js +3 -5
  75. package/lib/talons/MegaMenu/useMegaMenuItem.js +5 -0
  76. package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +11 -5
  77. package/lib/talons/MiniCart/miniCart.gql.js +2 -1
  78. package/lib/talons/MiniCart/useItem.js +3 -3
  79. package/lib/talons/MiniCart/useMiniCart.js +8 -7
  80. package/lib/talons/Navigation/navigation.gql.js +4 -3
  81. package/lib/talons/Navigation/useNavigation.js +1 -1
  82. package/lib/talons/Newsletter/newsletter.gql.js +24 -0
  83. package/lib/talons/Newsletter/useNewsletter.js +70 -0
  84. package/lib/talons/OrderHistoryPage/orderHistoryContext.gql.js +2 -1
  85. package/lib/talons/OrderHistoryPage/orderHistoryPage.gql.js +1 -1
  86. package/lib/talons/OrderHistoryPage/orderRow.gql.js +7 -3
  87. package/lib/talons/ProductFullDetail/CustomAttributes/AttributeType/useAttributeType.js +26 -0
  88. package/lib/talons/ProductFullDetail/productFullDetail.gql.ce.js +4 -3
  89. package/lib/talons/ProductFullDetail/productFullDetail.gql.ee.js +2 -1
  90. package/lib/talons/ProductFullDetail/useProductFullDetail.js +35 -3
  91. package/lib/talons/RootComponents/Category/category.gql.js +7 -4
  92. package/lib/talons/RootComponents/Category/categoryContent.gql.js +26 -7
  93. package/lib/talons/RootComponents/Category/categoryFragments.gql.js +5 -2
  94. package/lib/talons/RootComponents/Category/useCategory.js +8 -6
  95. package/lib/talons/RootComponents/Category/useCategoryContent.js +30 -3
  96. package/lib/talons/RootComponents/Category/useNoProductsFound.js +0 -1
  97. package/lib/talons/RootComponents/Product/product.gql.js +3 -1
  98. package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +69 -10
  99. package/lib/talons/SearchPage/searchPage.gql.js +18 -2
  100. package/lib/talons/SearchPage/useSearchPage.js +25 -0
  101. package/lib/talons/SignIn/signIn.gql.js +4 -3
  102. package/lib/talons/SignIn/useSignIn.js +2 -4
  103. package/lib/talons/Wishlist/WishlistDialog/wishlistDialog.gql.js +3 -2
  104. package/lib/talons/WishlistPage/createWishlist.gql.js +2 -1
  105. package/lib/talons/WishlistPage/useWishlistItem.js +2 -2
  106. package/lib/talons/WishlistPage/wishlist.gql.js +2 -2
  107. package/lib/talons/WishlistPage/wishlistConfig.gql.ce.js +2 -1
  108. package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +2 -1
  109. package/lib/talons/WishlistPage/wishlistItemFragments.gql.js +5 -2
  110. package/lib/talons/WishlistPage/wishlistPage.gql.js +1 -1
  111. package/package.json +6 -6
  112. package/lib/Apollo/clearStore.js +0 -26
  113. package/lib/Apollo/deleteCacheEntry.js +0 -87
@@ -45,7 +45,8 @@ export const useMiniCart = props => {
45
45
  fetchPolicy: 'cache-and-network',
46
46
  nextFetchPolicy: 'cache-first',
47
47
  variables: { cartId },
48
- skip: !cartId
48
+ skip: !cartId,
49
+ errorPolicy: 'all'
49
50
  }
50
51
  );
51
52
 
@@ -75,20 +76,20 @@ export const useMiniCart = props => {
75
76
  ] = useMutation(removeItemMutation);
76
77
 
77
78
  const totalQuantity = useMemo(() => {
78
- if (!miniCartLoading && miniCartData) {
79
- return miniCartData.cart.total_quantity;
79
+ if (!miniCartLoading) {
80
+ return miniCartData?.cart?.total_quantity;
80
81
  }
81
82
  }, [miniCartData, miniCartLoading]);
82
83
 
83
84
  const subTotal = useMemo(() => {
84
- if (!miniCartLoading && miniCartData) {
85
- return miniCartData.cart.prices.subtotal_excluding_tax;
85
+ if (!miniCartLoading) {
86
+ return miniCartData?.cart?.prices?.subtotal_excluding_tax;
86
87
  }
87
88
  }, [miniCartData, miniCartLoading]);
88
89
 
89
90
  const productList = useMemo(() => {
90
- if (!miniCartLoading && miniCartData) {
91
- return miniCartData.cart.items;
91
+ if (!miniCartLoading) {
92
+ return miniCartData?.cart?.items;
92
93
  }
93
94
  }, [miniCartData, miniCartLoading]);
94
95
 
@@ -2,8 +2,8 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_CUSTOMER = gql`
4
4
  query GetCustomerForLeftNav {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  customer {
6
- id
7
7
  email
8
8
  firstname
9
9
  lastname
@@ -14,9 +14,10 @@ export const GET_CUSTOMER = gql`
14
14
 
15
15
  const GET_ROOT_CATEGORY_ID = gql`
16
16
  query getRootCategoryId {
17
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
17
18
  storeConfig {
18
- id
19
- root_category_id
19
+ store_code
20
+ root_category_uid
20
21
  }
21
22
  }
22
23
  `;
@@ -38,7 +38,7 @@ export const useNavigation = (props = {}) => {
38
38
 
39
39
  const rootCategoryId = useMemo(() => {
40
40
  if (getRootCategoryData) {
41
- return getRootCategoryData.storeConfig.root_category_id;
41
+ return getRootCategoryData.storeConfig.root_category_uid;
42
42
  }
43
43
  }, [getRootCategoryData]);
44
44
 
@@ -0,0 +1,24 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const SUBSCRIBE_TO_NEWSLETTER = gql`
4
+ mutation SubscribeToNewsletter($email: String!) {
5
+ subscribeEmailToNewsletter(email: $email) {
6
+ status
7
+ }
8
+ }
9
+ `;
10
+
11
+ export const GET_STORE_CONFIG_DATA = gql`
12
+ query GetStoreConfigForNewsletter {
13
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
14
+ storeConfig {
15
+ store_code
16
+ newsletter_enabled
17
+ }
18
+ }
19
+ `;
20
+
21
+ export default {
22
+ subscribeMutation: SUBSCRIBE_TO_NEWSLETTER,
23
+ getStoreConfigQuery: GET_STORE_CONFIG_DATA
24
+ };
@@ -0,0 +1,70 @@
1
+ import { useCallback, useRef, useMemo, useState } from 'react';
2
+ import { useMutation, useQuery } from '@apollo/client';
3
+ import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
4
+ import DEFAULT_OPERATIONS from './newsletter.gql';
5
+
6
+ export const useNewsletter = (props = {}) => {
7
+ const { subscribeMutation, getStoreConfigQuery } = mergeOperations(
8
+ DEFAULT_OPERATIONS,
9
+ props.operations
10
+ );
11
+
12
+ const formApiRef = useRef(null);
13
+
14
+ const [newsLetterError, setNewsLetterError] = useState(null);
15
+
16
+ const clearErrors = () => setNewsLetterError(null);
17
+
18
+ const [
19
+ subscribeNewsLetter,
20
+ { data, loading: subscribeLoading }
21
+ ] = useMutation(subscribeMutation, {
22
+ fetchPolicy: 'no-cache',
23
+ onError: setNewsLetterError
24
+ });
25
+
26
+ const { data: storeConfigData, loading: configLoading } = useQuery(
27
+ getStoreConfigQuery,
28
+ {
29
+ fetchPolicy: 'cache-and-network'
30
+ }
31
+ );
32
+
33
+ const isEnabled = useMemo(() => {
34
+ return !!storeConfigData?.storeConfig?.newsletter_enabled;
35
+ }, [storeConfigData]);
36
+
37
+ const setFormApi = useCallback(api => (formApiRef.current = api), []);
38
+ const handleSubmit = useCallback(
39
+ async ({ email }) => {
40
+ try {
41
+ await subscribeNewsLetter({
42
+ variables: { email }
43
+ });
44
+ if (formApiRef.current) {
45
+ formApiRef.current.reset();
46
+ }
47
+ } catch (error) {
48
+ if (process.env.NODE_ENV !== 'production') {
49
+ console.error(error);
50
+ }
51
+ }
52
+ },
53
+ [subscribeNewsLetter]
54
+ );
55
+ const errors = useMemo(
56
+ () => new Map([['subscribeMutation', newsLetterError]]),
57
+ [newsLetterError]
58
+ );
59
+
60
+ return {
61
+ isEnabled,
62
+ errors,
63
+ handleSubmit,
64
+ isBusy: subscribeLoading,
65
+ isLoading: configLoading,
66
+ setFormApi,
67
+ newsLetterResponse: data && data.subscribeEmailToNewsletter,
68
+ clearErrors
69
+ };
70
+ };
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  const GET_PRODUCT_URL_SUFFIX = gql`
4
4
  query GetProductURLSuffix {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  product_url_suffix
8
9
  }
9
10
  }
@@ -98,8 +98,8 @@ export const GET_CUSTOMER_ORDERS = gql`
98
98
  $filter: CustomerOrdersFilterInput
99
99
  $pageSize: Int!
100
100
  ) {
101
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
101
102
  customer {
102
- id
103
103
  orders(filter: $filter, pageSize: $pageSize) {
104
104
  ...CustomerOrdersFragment
105
105
  }
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_CONFIGURABLE_THUMBNAIL_SOURCE = gql`
4
4
  query getConfigurableThumbnailSource {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  configurable_thumbnail_source
8
9
  }
9
10
  }
@@ -12,19 +13,22 @@ export const GET_CONFIGURABLE_THUMBNAIL_SOURCE = gql`
12
13
  export const GET_PRODUCT_THUMBNAILS_BY_URL_KEY = gql`
13
14
  query GetProductThumbnailsByURLKey($urlKeys: [String!]!) {
14
15
  products(filter: { url_key: { in: $urlKeys } }) {
16
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
15
17
  items {
16
- id
18
+ uid
17
19
  sku
18
20
  thumbnail {
19
21
  label
20
22
  url
21
23
  }
22
24
  url_key
25
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
23
26
  ... on ConfigurableProduct {
24
27
  variants {
28
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
25
29
  product {
26
30
  sku
27
- id
31
+ uid
28
32
  thumbnail {
29
33
  label
30
34
  url
@@ -0,0 +1,26 @@
1
+ import { useCallback } from 'react';
2
+
3
+ /**
4
+ * @param {Object} props.typeConfig - component types configuration object
5
+ *
6
+ * @returns {{
7
+ * getAttributeTypeConfig: function
8
+ * }}
9
+ */
10
+ export const useAttributeType = props => {
11
+ const { typeConfig = {} } = props;
12
+
13
+ // Retrieve a attribute types configuration
14
+ const getAttributeTypeConfig = useCallback(
15
+ attributeType => {
16
+ if (typeConfig[attributeType]) {
17
+ return typeConfig[attributeType];
18
+ }
19
+ },
20
+ [typeConfig]
21
+ );
22
+
23
+ return {
24
+ getAttributeTypeConfig
25
+ };
26
+ };
@@ -19,8 +19,9 @@ export const ADD_PRODUCT_TO_CART = gql`
19
19
 
20
20
  export const GET_WISHLIST_CONFIG = gql`
21
21
  query GetWishlistConfigForProductCE {
22
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
22
23
  storeConfig {
23
- id
24
+ store_code
24
25
  magento_wishlist_general_is_enabled
25
26
  }
26
27
  }
@@ -46,7 +47,7 @@ export const ADD_CONFIGURABLE_MUTATION = gql`
46
47
  }
47
48
  ]
48
49
  }
49
- ) @connection(key: "addConfigurableProductsToCart") {
50
+ ) {
50
51
  cart {
51
52
  id
52
53
  # Update the cart trigger when adding an item.
@@ -74,7 +75,7 @@ export const ADD_SIMPLE_MUTATION = gql`
74
75
  cart_id: $cartId
75
76
  cart_items: [{ data: { quantity: $quantity, sku: $sku } }]
76
77
  }
77
- ) @connection(key: "addSimpleProductsToCart") {
78
+ ) {
78
79
  cart {
79
80
  id
80
81
  # Update the cart trigger when adding an item.
@@ -4,8 +4,9 @@ import defaultOperations from './productFullDetail.gql.ce';
4
4
 
5
5
  export const GET_WISHLIST_CONFIG = gql`
6
6
  query GetWishlistConfigForProductEE {
7
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
7
8
  storeConfig {
8
- id
9
+ store_code
9
10
  magento_wishlist_general_is_enabled
10
11
  enable_multiple_wishlists
11
12
  }
@@ -135,12 +135,12 @@ const getBreadcrumbCategoryId = categories => {
135
135
  // Until we can get the single canonical breadcrumb path to a product we
136
136
  // will just return the first category id of the potential leaf categories.
137
137
  const leafCategory = categories.find(
138
- category => !breadcrumbSet.has(category.id)
138
+ category => !breadcrumbSet.has(category.uid)
139
139
  );
140
140
 
141
141
  // If we couldn't find a leaf category then just use the first category
142
142
  // in the list for this product.
143
- return leafCategory.id || categories[0].id;
143
+ return leafCategory.uid || categories[0].uid;
144
144
  };
145
145
 
146
146
  const getConfigPrice = (product, optionCodes, optionSelections) => {
@@ -170,6 +170,26 @@ const getConfigPrice = (product, optionCodes, optionSelections) => {
170
170
  return value;
171
171
  };
172
172
 
173
+ const getCustomAttributes = (product, optionCodes, optionSelections) => {
174
+ const { custom_attributes, variants } = product;
175
+ const isConfigurable = isProductConfigurable(product);
176
+ const optionsSelected =
177
+ Array.from(optionSelections.values()).filter(value => !!value).length >
178
+ 0;
179
+
180
+ if (isConfigurable && optionsSelected) {
181
+ const item = findMatchingVariant({
182
+ optionCodes,
183
+ optionSelections,
184
+ variants
185
+ });
186
+
187
+ return item.product.custom_attributes;
188
+ }
189
+
190
+ return custom_attributes;
191
+ };
192
+
173
193
  /**
174
194
  * @param {GraphQLDocument} props.addConfigurableProductToCartMutation - configurable product mutation
175
195
  * @param {GraphQLDocument} props.addSimpleProductToCartMutation - configurable product mutation
@@ -276,6 +296,11 @@ export const useProductFullDetail = props => {
276
296
  [product, optionCodes, optionSelections]
277
297
  );
278
298
 
299
+ const customAttributes = useMemo(
300
+ () => getCustomAttributes(product, optionCodes, optionSelections),
301
+ [product, optionCodes, optionSelections]
302
+ );
303
+
279
304
  // The map of ids to values (and their uids)
280
305
  // For example:
281
306
  // { "179" => [{ uid: "abc", value_index: 1 }, { uid: "def", value_index: 2 }]}
@@ -368,7 +393,13 @@ export const useProductFullDetail = props => {
368
393
  product: {
369
394
  sku: product.sku,
370
395
  quantity
371
- }
396
+ },
397
+ entered_options: [
398
+ {
399
+ uid: product.uid,
400
+ value: product.name
401
+ }
402
+ ]
372
403
  };
373
404
 
374
405
  if (selectedOptionsArray.length) {
@@ -482,6 +513,7 @@ export const useProductFullDetail = props => {
482
513
  storeConfigData &&
483
514
  !!storeConfigData.storeConfig.magento_wishlist_general_is_enabled,
484
515
  productDetails,
516
+ customAttributes,
485
517
  wishlistButtonProps,
486
518
  wishlistItemOptions
487
519
  };
@@ -4,15 +4,18 @@ import { CategoryFragment, ProductsFragment } from './categoryFragments.gql';
4
4
 
5
5
  export const GET_CATEGORY = gql`
6
6
  query GetCategories(
7
- $id: Int!
7
+ $id: String!
8
8
  $pageSize: Int!
9
9
  $currentPage: Int!
10
10
  $filters: ProductAttributeFilterInput!
11
11
  $sort: ProductAttributeSortInput
12
12
  ) {
13
- category(id: $id) {
14
- id
15
- ...CategoryFragment
13
+ categories(filters: { category_uid: { in: [$id] } }) {
14
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
15
+ items {
16
+ uid
17
+ ...CategoryFragment
18
+ }
16
19
  }
17
20
  products(
18
21
  pageSize: $pageSize
@@ -4,7 +4,7 @@ export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
4
4
  query getProductFiltersByCategory(
5
5
  $categoryIdFilter: FilterEqualTypeInput!
6
6
  ) {
7
- products(filter: { category_id: $categoryIdFilter }) {
7
+ products(filter: { category_uid: $categoryIdFilter }) {
8
8
  aggregations {
9
9
  label
10
10
  count
@@ -19,16 +19,35 @@ export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
19
19
  `;
20
20
 
21
21
  export const GET_CATEGORY_CONTENT = gql`
22
- query getCategoryData($id: Int!) {
23
- category(id: $id) {
24
- id
25
- name
26
- description
22
+ query getCategoryData($id: String!) {
23
+ categories(filters: { category_uid: { in: [$id] } }) {
24
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
25
+ items {
26
+ uid
27
+ name
28
+ description
29
+ }
30
+ }
31
+ }
32
+ `;
33
+
34
+ export const GET_CATEGORY_AVAILABLE_SORT_METHODS = gql`
35
+ query getCategoryAvailableSortMethods(
36
+ $categoryIdFilter: FilterEqualTypeInput!
37
+ ) {
38
+ products(filter: { category_uid: $categoryIdFilter }) {
39
+ sort_fields {
40
+ options {
41
+ label
42
+ value
43
+ }
44
+ }
27
45
  }
28
46
  }
29
47
  `;
30
48
 
31
49
  export default {
32
50
  getCategoryContentQuery: GET_CATEGORY_CONTENT,
33
- getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY
51
+ getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
52
+ getCategoryAvailableSortMethodsQuery: GET_CATEGORY_AVAILABLE_SORT_METHODS
34
53
  };
@@ -1,8 +1,9 @@
1
1
  import { gql } from '@apollo/client';
2
2
 
3
3
  export const CategoryFragment = gql`
4
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
4
5
  fragment CategoryFragment on CategoryTree {
5
- id
6
+ uid
6
7
  meta_title
7
8
  meta_keywords
8
9
  meta_description
@@ -13,6 +14,7 @@ export const ProductsFragment = gql`
13
14
  fragment ProductsFragment on Products {
14
15
  items {
15
16
  id
17
+ uid
16
18
  name
17
19
  price_range {
18
20
  maximum_price {
@@ -27,7 +29,8 @@ export const ProductsFragment = gql`
27
29
  url
28
30
  }
29
31
  stock_status
30
- type_id
32
+ rating_summary
33
+ __typename
31
34
  url_key
32
35
  }
33
36
  page_info {
@@ -21,7 +21,7 @@ import DEFAULT_OPERATIONS from './category.gql';
21
21
  * @kind function
22
22
  *
23
23
  * @param {object} props
24
- * @param {number} props.id - Category Id.
24
+ * @param {String} props.id - Category uid.
25
25
  * @param {GraphQLAST} props.operations.getCategoryQuery - Fetches category using a server query
26
26
  * @param {GraphQLAST} props.operations.getFilterInputsQuery - Fetches "allowed" filters using a server query
27
27
  * @param {GraphQLAST} props.queries.getStoreConfig - Fetches store configuration using a server query
@@ -133,14 +133,14 @@ export const useCategory = props => {
133
133
  newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
134
134
  });
135
135
 
136
- // Use the category id for the current category page regardless of the
136
+ // Use the category uid for the current category page regardless of the
137
137
  // applied filters. Follow-up in PWA-404.
138
- newFilters['category_id'] = { eq: String(id) };
138
+ newFilters['category_uid'] = { eq: id };
139
139
 
140
140
  runQuery({
141
141
  variables: {
142
142
  currentPage: Number(currentPage),
143
- id: Number(id),
143
+ id: id,
144
144
  filters: newFilters,
145
145
  pageSize: Number(pageSize),
146
146
  sort: { [currentSort.sortAttribute]: currentSort.sortDirection }
@@ -201,8 +201,10 @@ export const useCategory = props => {
201
201
 
202
202
  const categoryData = categoryLoading && !data ? null : data;
203
203
  const metaDescription =
204
- data && data.category && data.category.meta_description
205
- ? data.category.meta_description
204
+ data &&
205
+ data.categories.items[0] &&
206
+ data.categories.items[0].meta_description
207
+ ? data.categories.items[0].meta_description
206
208
  : '';
207
209
 
208
210
  // When only categoryLoading is involved, noProductsFound component flashes for a moment
@@ -24,7 +24,8 @@ export const useCategoryContent = props => {
24
24
 
25
25
  const {
26
26
  getCategoryContentQuery,
27
- getProductFiltersByCategoryQuery
27
+ getProductFiltersByCategoryQuery,
28
+ getCategoryAvailableSortMethodsQuery
28
29
  } = operations;
29
30
 
30
31
  const placeholderItems = Array.from({ length: pageSize }).fill(null);
@@ -37,6 +38,14 @@ export const useCategoryContent = props => {
37
38
  }
38
39
  );
39
40
 
41
+ const [getSortMethods, { data: sortData }] = useLazyQuery(
42
+ getCategoryAvailableSortMethodsQuery,
43
+ {
44
+ fetchPolicy: 'cache-and-network',
45
+ nextFetchPolicy: 'cache-first'
46
+ }
47
+ );
48
+
40
49
  const { data: categoryData } = useQuery(getCategoryContentQuery, {
41
50
  fetchPolicy: 'cache-and-network',
42
51
  nextFetchPolicy: 'cache-first',
@@ -58,18 +67,36 @@ export const useCategoryContent = props => {
58
67
  }
59
68
  }, [categoryId, getFilters]);
60
69
 
70
+ useEffect(() => {
71
+ if (categoryId) {
72
+ getSortMethods({
73
+ variables: {
74
+ categoryIdFilter: {
75
+ in: categoryId
76
+ }
77
+ }
78
+ });
79
+ }
80
+ }, [categoryId, getSortMethods]);
81
+
61
82
  const filters = filterData ? filterData.products.aggregations : null;
62
83
  const items = data ? data.products.items : placeholderItems;
63
84
  const totalPagesFromData = data
64
85
  ? data.products.page_info.total_pages
65
86
  : null;
66
87
  const totalCount = data ? data.products.total_count : null;
67
- const categoryName = categoryData ? categoryData.category.name : null;
88
+ const categoryName = categoryData
89
+ ? categoryData.categories.items[0].name
90
+ : null;
68
91
  const categoryDescription = categoryData
69
- ? categoryData.category.description
92
+ ? categoryData.categories.items[0].description
93
+ : null;
94
+ const availableSortMethods = sortData
95
+ ? sortData.products.sort_fields.options
70
96
  : null;
71
97
 
72
98
  return {
99
+ availableSortMethods,
73
100
  categoryName,
74
101
  categoryDescription,
75
102
  filters,
@@ -13,7 +13,6 @@ const isNonDefaultCategory = category => Boolean(category.parentId);
13
13
  * @param {number} props.categoryId - The ID of the category that has no products.
14
14
  *
15
15
  * @returns {object}
16
- * @param {array} recommendedCategories - A list of categories for the UI to recommend.
17
16
  */
18
17
  export const useNoProductsFound = props => {
19
18
  const { categoryId } = props;
@@ -4,8 +4,9 @@ import { ProductDetailsFragment } from './productDetailFragment.gql';
4
4
 
5
5
  export const GET_STORE_CONFIG_DATA = gql`
6
6
  query getStoreConfigData {
7
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
7
8
  storeConfig {
8
- id
9
+ store_code
9
10
  product_url_suffix
10
11
  }
11
12
  }
@@ -16,6 +17,7 @@ export const GET_PRODUCT_DETAIL_QUERY = gql`
16
17
  products(filter: { url_key: { eq: $urlKey } }) {
17
18
  items {
18
19
  id
20
+ uid
19
21
  ...ProductDetailsFragment
20
22
  }
21
23
  }