@magento/peregrine 12.1.0 → 12.2.0-beta.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/hooks/useCustomerWishlistSkus/customerWishlist.gql.ce.js +3 -3
  6. package/lib/store/actions/cart/asyncActions.js +1 -2
  7. package/lib/store/actions/user/asyncActions.js +2 -4
  8. package/lib/store/reducers/catalog.js +7 -7
  9. package/lib/store/reducers/user.js +1 -3
  10. package/lib/talons/Adapter/useAdapter.js +80 -11
  11. package/lib/talons/AddToCartDialog/addToCartDialog.gql.js +2 -2
  12. package/lib/talons/AddressBookPage/addressBookPage.gql.js +3 -9
  13. package/lib/talons/Breadcrumbs/breadcrumbs.gql.js +16 -12
  14. package/lib/talons/Breadcrumbs/useBreadcrumbs.js +6 -4
  15. package/lib/talons/CartPage/GiftCards/giftCardQueries.gql.ee.js +2 -2
  16. package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCode.gql.js +2 -3
  17. package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethods.gql.js +1 -1
  18. package/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js +2 -1
  19. package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +3 -3
  20. package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +6 -3
  21. package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +1 -0
  22. package/lib/talons/CartPage/ProductListing/product.gql.js +2 -1
  23. package/lib/talons/CartPage/ProductListing/productListing.gql.ce.js +2 -1
  24. package/lib/talons/CartPage/ProductListing/productListing.gql.ee.js +2 -1
  25. package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +14 -5
  26. package/lib/talons/CartPage/ProductListing/useProduct.js +8 -1
  27. package/lib/talons/CartPage/ProductListing/useProductListing.js +4 -2
  28. package/lib/talons/CartPage/useCartPage.js +4 -3
  29. package/lib/talons/CategoryList/categoryList.gql.js +25 -17
  30. package/lib/talons/CategoryList/useCategoryList.js +6 -1
  31. package/lib/talons/CategoryList/useCategoryTile.js +2 -0
  32. package/lib/talons/CategoryTree/categoryTree.gql.js +18 -12
  33. package/lib/talons/CategoryTree/useCategoryBranch.js +1 -1
  34. package/lib/talons/CategoryTree/useCategoryTree.js +5 -5
  35. package/lib/talons/CheckoutPage/AddressBook/addressBook.gql.js +1 -1
  36. package/lib/talons/CheckoutPage/BillingAddress/billingAddress.gql.js +1 -1
  37. package/lib/talons/CheckoutPage/ItemsReview/__fixtures__/cartItems.js +12 -12
  38. package/lib/talons/CheckoutPage/ItemsReview/itemsReview.gql.js +2 -1
  39. package/lib/talons/CheckoutPage/ItemsReview/itemsReviewFragments.gql.js +11 -5
  40. package/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +12 -6
  41. package/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js +2 -2
  42. package/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js +2 -2
  43. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/customerForm.gql.js +3 -5
  44. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +12 -4
  45. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useGuestForm.js +45 -5
  46. package/lib/talons/CheckoutPage/ShippingInformation/shippingInformation.gql.js +2 -2
  47. package/lib/talons/CheckoutPage/ShippingMethod/shippingMethod.gql.js +1 -1
  48. package/lib/talons/CheckoutPage/checkoutPage.gql.js +2 -2
  49. package/lib/talons/CheckoutPage/checkoutPageFragments.gql.js +4 -2
  50. package/lib/talons/CheckoutPage/useCheckoutPage.js +5 -2
  51. package/lib/talons/Cms/cmsPage.gql.js +0 -4
  52. package/lib/talons/Cms/useCmsPage.js +6 -23
  53. package/lib/talons/CommunicationsPage/communicationsPage.gql.js +2 -2
  54. package/lib/talons/ContactPage/contactUs.gql.js +48 -0
  55. package/lib/talons/ContactPage/index.js +2 -0
  56. package/lib/talons/ContactPage/useContactLink.js +27 -0
  57. package/lib/talons/ContactPage/useContactPage.js +85 -0
  58. package/lib/talons/CreateAccount/createAccount.gql.js +15 -8
  59. package/lib/talons/CreateAccount/useCreateAccount.js +2 -4
  60. package/lib/talons/FilterModal/helpers.js +29 -0
  61. package/lib/talons/FilterModal/useFilterModal.js +9 -2
  62. package/lib/talons/FilterSidebar/useFilterSidebar.js +4 -1
  63. package/lib/talons/Footer/footer.gql.js +2 -1
  64. package/lib/talons/FormError/useFormError.js +9 -7
  65. package/lib/talons/Gallery/__fixtures__/apolloMocks.js +2 -2
  66. package/lib/talons/Gallery/gallery.gql.ce.js +2 -1
  67. package/lib/talons/Gallery/gallery.gql.ee.js +2 -1
  68. package/lib/talons/Gallery/useAddToCartButton.js +12 -11
  69. package/lib/talons/Header/storeSwitcher.gql.js +21 -9
  70. package/lib/talons/Header/useCartTrigger.js +3 -3
  71. package/lib/talons/Header/useStoreSwitcher.js +10 -8
  72. package/lib/talons/MagentoRoute/magentoRoute.gql.js +4 -2
  73. package/lib/talons/MagentoRoute/useMagentoRoute.js +39 -33
  74. package/lib/talons/MegaMenu/megaMenu.gql.js +10 -5
  75. package/lib/talons/MegaMenu/useMegaMenu.js +3 -5
  76. package/lib/talons/MegaMenu/useMegaMenuItem.js +5 -0
  77. package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +10 -5
  78. package/lib/talons/MiniCart/miniCart.gql.js +2 -1
  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 +14 -1
  83. package/lib/talons/Newsletter/useNewsletter.js +31 -12
  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 +28 -2
  91. package/lib/talons/RootComponents/Category/category.gql.js +7 -4
  92. package/lib/talons/RootComponents/Category/categoryContent.gql.js +27 -7
  93. package/lib/talons/RootComponents/Category/categoryFragments.gql.js +4 -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 +2 -1
  98. package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +70 -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
@@ -1,25 +1,42 @@
1
- import { useCallback, useRef, useState, useMemo } from 'react';
2
- import { useMutation } from '@apollo/client';
1
+ import { useCallback, useRef, useMemo, useState } from 'react';
2
+ import { useMutation, useQuery } from '@apollo/client';
3
3
  import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
4
4
  import DEFAULT_OPERATIONS from './newsletter.gql';
5
5
 
6
6
  export const useNewsletter = (props = {}) => {
7
- const { subscribeMutation } = mergeOperations(
7
+ const { subscribeMutation, getStoreConfigQuery } = mergeOperations(
8
8
  DEFAULT_OPERATIONS,
9
9
  props.operations
10
10
  );
11
- const [subscribing, setSubscribing] = useState(false);
12
- const [subscribeNewsLetter, { error: newsLetterError, data }] = useMutation(
13
- subscribeMutation,
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,
14
28
  {
15
- fetchPolicy: 'no-cache'
29
+ fetchPolicy: 'cache-and-network'
16
30
  }
17
31
  );
18
- const formApiRef = useRef(null);
32
+
33
+ const isEnabled = useMemo(() => {
34
+ return !!storeConfigData?.storeConfig?.newsletter_enabled;
35
+ }, [storeConfigData]);
36
+
19
37
  const setFormApi = useCallback(api => (formApiRef.current = api), []);
20
38
  const handleSubmit = useCallback(
21
39
  async ({ email }) => {
22
- setSubscribing(true);
23
40
  try {
24
41
  await subscribeNewsLetter({
25
42
  variables: { email }
@@ -32,7 +49,6 @@ export const useNewsletter = (props = {}) => {
32
49
  console.error(error);
33
50
  }
34
51
  }
35
- setSubscribing(false);
36
52
  },
37
53
  [subscribeNewsLetter]
38
54
  );
@@ -42,10 +58,13 @@ export const useNewsletter = (props = {}) => {
42
58
  );
43
59
 
44
60
  return {
61
+ isEnabled,
45
62
  errors,
46
63
  handleSubmit,
47
- isBusy: subscribing,
64
+ isBusy: subscribeLoading,
65
+ isLoading: configLoading,
48
66
  setFormApi,
49
- newsLetterResponse: data && data.subscribeEmailToNewsletter
67
+ newsLetterResponse: data && data.subscribeEmailToNewsletter,
68
+ clearErrors
50
69
  };
51
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 }]}
@@ -488,6 +513,7 @@ export const useProductFullDetail = props => {
488
513
  storeConfigData &&
489
514
  !!storeConfigData.storeConfig.magento_wishlist_general_is_enabled,
490
515
  productDetails,
516
+ customAttributes,
491
517
  wishlistButtonProps,
492
518
  wishlistItemOptions
493
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
@@ -13,22 +13,42 @@ export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
13
13
  label
14
14
  value
15
15
  }
16
+ position
16
17
  }
17
18
  }
18
19
  }
19
20
  `;
20
21
 
21
22
  export const GET_CATEGORY_CONTENT = gql`
22
- query getCategoryData($id: Int!) {
23
- category(id: $id) {
24
- id
25
- name
26
- description
23
+ query getCategoryData($id: String!) {
24
+ categories(filters: { category_uid: { in: [$id] } }) {
25
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
26
+ items {
27
+ uid
28
+ name
29
+ description
30
+ }
31
+ }
32
+ }
33
+ `;
34
+
35
+ export const GET_CATEGORY_AVAILABLE_SORT_METHODS = gql`
36
+ query getCategoryAvailableSortMethods(
37
+ $categoryIdFilter: FilterEqualTypeInput!
38
+ ) {
39
+ products(filter: { category_uid: $categoryIdFilter }) {
40
+ sort_fields {
41
+ options {
42
+ label
43
+ value
44
+ }
45
+ }
27
46
  }
28
47
  }
29
48
  `;
30
49
 
31
50
  export default {
32
51
  getCategoryContentQuery: GET_CATEGORY_CONTENT,
33
- getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY
52
+ getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
53
+ getCategoryAvailableSortMethodsQuery: GET_CATEGORY_AVAILABLE_SORT_METHODS
34
54
  };
@@ -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
@@ -28,7 +29,8 @@ export const ProductsFragment = gql`
28
29
  url
29
30
  }
30
31
  stock_status
31
- type_id
32
+ rating_summary
33
+ __typename
32
34
  url_key
33
35
  }
34
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
  }
@@ -3,11 +3,11 @@ import { gql } from '@apollo/client';
3
3
  export const ProductDetailsFragment = gql`
4
4
  fragment ProductDetailsFragment on ProductInterface {
5
5
  __typename
6
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
6
7
  categories {
7
- id
8
8
  uid
9
9
  breadcrumbs {
10
- category_id
10
+ category_uid
11
11
  }
12
12
  }
13
13
  description {
@@ -15,10 +15,8 @@ export const ProductDetailsFragment = gql`
15
15
  }
16
16
  id
17
17
  uid
18
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
18
19
  media_gallery_entries {
19
- # id is deprecated and unused in our code, but lint rules require we
20
- # request it if available
21
- id
22
20
  uid
23
21
  label
24
22
  position
@@ -41,12 +39,45 @@ export const ProductDetailsFragment = gql`
41
39
  }
42
40
  stock_status
43
41
  url_key
42
+ custom_attributes {
43
+ selected_attribute_options {
44
+ attribute_option {
45
+ uid
46
+ label
47
+ is_default
48
+ }
49
+ }
50
+ entered_attribute_value {
51
+ value
52
+ }
53
+ attribute_metadata {
54
+ uid
55
+ code
56
+ label
57
+ attribute_labels {
58
+ store_code
59
+ label
60
+ }
61
+ data_type
62
+ is_system
63
+ entity_type
64
+ ui_input {
65
+ ui_input_type
66
+ is_html_allowed
67
+ }
68
+ ... on ProductAttributeMetadata {
69
+ used_in_components
70
+ }
71
+ }
72
+ }
44
73
  ... on ConfigurableProduct {
74
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
45
75
  configurable_options {
46
76
  attribute_code
47
77
  attribute_id
48
- id
78
+ uid
49
79
  label
80
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
50
81
  values {
51
82
  uid
52
83
  default_label
@@ -67,13 +98,11 @@ export const ProductDetailsFragment = gql`
67
98
  code
68
99
  value_index
69
100
  }
101
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
70
102
  product {
71
- id
72
103
  uid
104
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
73
105
  media_gallery_entries {
74
- # id is deprecated and unused in our code, but lint rules require we
75
- # request it if available
76
- id
77
106
  uid
78
107
  disabled
79
108
  file
@@ -90,6 +119,37 @@ export const ProductDetailsFragment = gql`
90
119
  }
91
120
  }
92
121
  }
122
+ custom_attributes {
123
+ selected_attribute_options {
124
+ attribute_option {
125
+ uid
126
+ label
127
+ is_default
128
+ }
129
+ }
130
+ entered_attribute_value {
131
+ value
132
+ }
133
+ attribute_metadata {
134
+ uid
135
+ code
136
+ label
137
+ attribute_labels {
138
+ store_code
139
+ label
140
+ }
141
+ data_type
142
+ is_system
143
+ entity_type
144
+ ui_input {
145
+ ui_input_type
146
+ is_html_allowed
147
+ }
148
+ ... on ProductAttributeMetadata {
149
+ used_in_components
150
+ }
151
+ }
152
+ }
93
153
  }
94
154
  }
95
155
  }
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_PAGE_SIZE = gql`
4
4
  query getPageSize {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  grid_per_page
8
9
  }
9
10
  }
@@ -20,6 +21,7 @@ export const GET_PRODUCT_FILTERS_BY_SEARCH = gql`
20
21
  label
21
22
  value
22
23
  }
24
+ position
23
25
  }
24
26
  }
25
27
  }
@@ -57,7 +59,7 @@ export const PRODUCT_SEARCH = gql`
57
59
  url
58
60
  }
59
61
  stock_status
60
- type_id
62
+ __typename
61
63
  url_key
62
64
  }
63
65
  page_info {
@@ -81,9 +83,23 @@ export const GET_FILTER_INPUTS = gql`
81
83
  }
82
84
  `;
83
85
 
86
+ export const GET_SEARCH_AVAILABLE_SORT_METHODS = gql`
87
+ query getSearchAvailableSortMethods($search: String!) {
88
+ products(search: $search) {
89
+ sort_fields {
90
+ options {
91
+ label
92
+ value
93
+ }
94
+ }
95
+ }
96
+ }
97
+ `;
98
+
84
99
  export default {
85
100
  getFilterInputsQuery: GET_FILTER_INPUTS,
86
101
  getPageSize: GET_PAGE_SIZE,
87
102
  getProductFiltersBySearchQuery: GET_PRODUCT_FILTERS_BY_SEARCH,
103
+ getSearchAvailableSortMethods: GET_SEARCH_AVAILABLE_SORT_METHODS,
88
104
  productSearchQuery: PRODUCT_SEARCH
89
105
  };