@riosst100/pwa-marketplace 2.3.3 → 2.3.5
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/package.json +1 -1
- package/src/components/FilterTop/FilterBlockList/filterTopItem.js +4 -1
- package/src/components/ProductContent/index.js +1 -0
- package/src/components/ProductContent/productContent.js +240 -0
- package/src/components/SellerDetail/sellerDetail.js +1 -1
- package/src/components/SellerProducts/productContent.js +238 -0
- package/src/components/SellerProducts/sellerProducts.js +109 -46
- package/src/components/ShopBySets/shopBySets.js +2 -2
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/categoryContent.gql.js +26 -3
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/useCategory.js +3 -3
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/useCategoryContent.js +78 -6
- package/src/overwrites/venia-ui/lib/RootComponents/Category/categoryContent.js +6 -0
- package/src/overwrites/venia-ui/lib/components/FilterSidebar/filterSidebar.js +28 -20
- package/src/talons/CollectibleGameSets/useCollectibleGameSets.js +2 -2
- package/src/talons/ProductContent/index.js +1 -0
- package/src/talons/ProductContent/productContent.gql.js +98 -0
- package/src/talons/ProductContent/useProductContent.js +192 -0
- package/src/talons/SellerProducts/categoryFragments.gql.js +103 -0
- package/src/talons/SellerProducts/index.js +2 -0
- package/src/talons/SellerProducts/productContent.gql.js +98 -0
- package/src/talons/SellerProducts/sellerProducts.gql.js +63 -0
- package/src/talons/SellerProducts/useProductContent.js +194 -0
- package/src/talons/SellerProducts/useSellerProducts.js +264 -0
- package/src/talons/SetsData/useSetsData.js +2 -2
|
@@ -168,8 +168,8 @@ const ShopBySets = props => {
|
|
|
168
168
|
// alpha = availableGroups;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
console.log('==productType')
|
|
172
|
-
console.log(productType)
|
|
171
|
+
// console.log('==productType')
|
|
172
|
+
// console.log(productType)
|
|
173
173
|
|
|
174
174
|
let title = "A2ll Sets";
|
|
175
175
|
if (productType == "expansion_sets") {
|
|
@@ -2,9 +2,9 @@ import { gql } from '@apollo/client';
|
|
|
2
2
|
|
|
3
3
|
export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
|
|
4
4
|
query getProductFiltersByCategory(
|
|
5
|
-
$
|
|
5
|
+
$filters: ProductAttributeFilterInput!
|
|
6
6
|
) {
|
|
7
|
-
products(filter:
|
|
7
|
+
products(filter: $filters) {
|
|
8
8
|
aggregations {
|
|
9
9
|
label
|
|
10
10
|
count
|
|
@@ -89,10 +89,33 @@ export const GET_STORE_CONFIG_DATA = gql`
|
|
|
89
89
|
}
|
|
90
90
|
`;
|
|
91
91
|
|
|
92
|
+
export const GET_FILTER_INPUTS = gql`
|
|
93
|
+
query GetFilterInputsForCategory {
|
|
94
|
+
__type(name: "ProductAttributeFilterInput") {
|
|
95
|
+
inputFields {
|
|
96
|
+
name
|
|
97
|
+
type {
|
|
98
|
+
name
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
export const GET_MASTER_ATTRIBUTES = gql`
|
|
106
|
+
query GetMasterAttributes {
|
|
107
|
+
masterAttributes {
|
|
108
|
+
attribute_code
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
|
|
92
113
|
|
|
93
114
|
export default {
|
|
94
115
|
getCategoryContentQuery: GET_CATEGORY_CONTENT,
|
|
95
116
|
getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
|
|
96
117
|
getCategoryAvailableSortMethodsQuery: GET_CATEGORY_AVAILABLE_SORT_METHODS,
|
|
97
|
-
getStoreConfigQuery: GET_STORE_CONFIG_DATA
|
|
118
|
+
getStoreConfigQuery: GET_STORE_CONFIG_DATA,
|
|
119
|
+
getFilterInputsQuery: GET_FILTER_INPUTS,
|
|
120
|
+
getMasterAttributesQuery: GET_MASTER_ATTRIBUTES
|
|
98
121
|
};
|
|
@@ -107,9 +107,9 @@ export const useCategory = props => {
|
|
|
107
107
|
loading: introspectionLoading
|
|
108
108
|
} = useQuery(getFilterInputsQuery);
|
|
109
109
|
|
|
110
|
-
console.log(introspectionCalled)
|
|
111
|
-
console.log(introspectionLoading)
|
|
112
|
-
console.log(introspectionData)
|
|
110
|
+
// console.log(introspectionCalled)
|
|
111
|
+
// console.log(introspectionLoading)
|
|
112
|
+
// console.log(introspectionData)
|
|
113
113
|
|
|
114
114
|
// Create a type map we can reference later to ensure we pass valid args
|
|
115
115
|
// to the graphql query.
|
|
@@ -3,8 +3,12 @@ import { useLazyQuery, useQuery } from '@apollo/client';
|
|
|
3
3
|
|
|
4
4
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
5
5
|
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
6
|
-
|
|
6
|
+
import { useLocation } from 'react-router-dom';
|
|
7
7
|
import DEFAULT_OPERATIONS from './categoryContent.gql';
|
|
8
|
+
import {
|
|
9
|
+
getFiltersFromSearch,
|
|
10
|
+
getFilterInput
|
|
11
|
+
} from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Returns props necessary to render the categoryContent component.
|
|
@@ -27,7 +31,9 @@ export const useCategoryContent = props => {
|
|
|
27
31
|
getCategoryContentQuery,
|
|
28
32
|
getProductFiltersByCategoryQuery,
|
|
29
33
|
getCategoryAvailableSortMethodsQuery,
|
|
30
|
-
getStoreConfigQuery
|
|
34
|
+
getStoreConfigQuery,
|
|
35
|
+
getFilterInputsQuery,
|
|
36
|
+
getMasterAttributesQuery
|
|
31
37
|
} = operations;
|
|
32
38
|
|
|
33
39
|
const placeholderItems = Array.from({ length: pageSize }).fill(null);
|
|
@@ -72,18 +78,75 @@ export const useCategoryContent = props => {
|
|
|
72
78
|
);
|
|
73
79
|
|
|
74
80
|
const [, { dispatch }] = useEventingContext();
|
|
81
|
+
const { search } = useLocation();
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
called: introspectionCalled,
|
|
85
|
+
data: introspectionData,
|
|
86
|
+
loading: introspectionLoading
|
|
87
|
+
} = useQuery(getFilterInputsQuery);
|
|
88
|
+
|
|
89
|
+
const filterTypeMap = useMemo(() => {
|
|
90
|
+
const typeMap = new Map();
|
|
91
|
+
if (introspectionData) {
|
|
92
|
+
introspectionData.__type.inputFields.forEach(({ name, type }) => {
|
|
93
|
+
typeMap.set(name, type.name);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return typeMap;
|
|
97
|
+
}, [introspectionData]);
|
|
98
|
+
|
|
99
|
+
// MASTER ATTRIBUTES
|
|
100
|
+
const {
|
|
101
|
+
called: masterAttributesCalled,
|
|
102
|
+
data: masterAttributesData,
|
|
103
|
+
loading: masterAttributesLoading
|
|
104
|
+
} = useQuery(getMasterAttributesQuery,
|
|
105
|
+
{
|
|
106
|
+
fetchPolicy: 'cache-and-network',
|
|
107
|
+
nextFetchPolicy: 'cache-first'
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const masterAttributes = useMemo(() => {
|
|
111
|
+
const masterAttributes = [];
|
|
112
|
+
|
|
113
|
+
if (masterAttributesData) {
|
|
114
|
+
masterAttributesData.masterAttributes.forEach(({ attribute_code }) => {
|
|
115
|
+
masterAttributes.push(attribute_code);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return masterAttributes;
|
|
120
|
+
}, [masterAttributesData]);
|
|
121
|
+
|
|
75
122
|
|
|
76
123
|
useEffect(() => {
|
|
77
124
|
if (categoryId) {
|
|
125
|
+
|
|
126
|
+
// categoryIdFilter: {
|
|
127
|
+
// eq: categoryId
|
|
128
|
+
// }
|
|
129
|
+
if (!filterTypeMap.size) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const filters = getFiltersFromSearch(search);
|
|
134
|
+
|
|
135
|
+
// Construct the filter arg object.
|
|
136
|
+
const newFilters = {};
|
|
137
|
+
filters.forEach((values, key) => {
|
|
138
|
+
if (masterAttributes.includes(key)) {
|
|
139
|
+
newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
78
143
|
getFilters({
|
|
79
144
|
variables: {
|
|
80
|
-
|
|
81
|
-
eq: categoryId
|
|
82
|
-
}
|
|
145
|
+
filters: newFilters
|
|
83
146
|
}
|
|
84
147
|
});
|
|
85
148
|
}
|
|
86
|
-
}, [categoryId, getFilters]);
|
|
149
|
+
}, [categoryId, getFilters, filterTypeMap, search, masterAttributes]);
|
|
87
150
|
|
|
88
151
|
useEffect(() => {
|
|
89
152
|
if (categoryId) {
|
|
@@ -97,6 +160,9 @@ export const useCategoryContent = props => {
|
|
|
97
160
|
}
|
|
98
161
|
}, [categoryId, getSortMethods]);
|
|
99
162
|
|
|
163
|
+
// console.log('filterData')
|
|
164
|
+
// console.log(filterData)
|
|
165
|
+
|
|
100
166
|
const rawFilters = filterData ? filterData.products.aggregations : null;
|
|
101
167
|
const items = data ? data.products.items : placeholderItems;
|
|
102
168
|
const category =
|
|
@@ -110,8 +176,14 @@ export const useCategoryContent = props => {
|
|
|
110
176
|
|
|
111
177
|
const filters = [];
|
|
112
178
|
|
|
179
|
+
// console.log('rawFilters')
|
|
180
|
+
// console.log(rawFilters)
|
|
181
|
+
|
|
113
182
|
rawFilters && rawFilters.map((filter, index) => {
|
|
114
183
|
|
|
184
|
+
// console.log('filter')
|
|
185
|
+
// console.log(filter)
|
|
186
|
+
|
|
115
187
|
const filterOptions = [];
|
|
116
188
|
let label = filter.label;
|
|
117
189
|
if (filter.attribute_code == "category_uid") {
|
|
@@ -163,6 +163,12 @@ const CategoryContent = props => {
|
|
|
163
163
|
<FilterModal filters={filters} />
|
|
164
164
|
) : null;
|
|
165
165
|
|
|
166
|
+
// console.log('filters')
|
|
167
|
+
// console.log(filters)
|
|
168
|
+
|
|
169
|
+
// console.log('shouldShowFilterButtons')
|
|
170
|
+
// console.log(shouldShowFilterButtons)
|
|
171
|
+
|
|
166
172
|
const sidebar = shouldShowFilterButtons ? (
|
|
167
173
|
<FilterSidebar hideFilters={category && category.hide_filters ? true : false} children={children} filters={filters} allowedFilters={category ? category.allowed_filters : []} />
|
|
168
174
|
) : shouldShowFilterShimmer ? (
|
|
@@ -33,6 +33,12 @@ const FilterSidebar = props => {
|
|
|
33
33
|
handleReset
|
|
34
34
|
} = talonProps;
|
|
35
35
|
|
|
36
|
+
// console.log('RIO')
|
|
37
|
+
// console.log('filters')
|
|
38
|
+
// console.log(filters)
|
|
39
|
+
// console.log('filterCountToOpen'+filterCountToOpen)
|
|
40
|
+
// console.log('hideFilters'+hideFilters)
|
|
41
|
+
|
|
36
42
|
const filterRef = useRef();
|
|
37
43
|
const classes = useStyle(defaultClasses, props.classes);
|
|
38
44
|
|
|
@@ -80,9 +86,9 @@ const FilterSidebar = props => {
|
|
|
80
86
|
|
|
81
87
|
const allowedFiltersArr = [];
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
allowedFilters?.length && allowedFilters.map((val, index) => {
|
|
90
|
+
allowedFiltersArr.push(val.code);
|
|
91
|
+
});
|
|
86
92
|
|
|
87
93
|
const filtersList = useMemo(
|
|
88
94
|
() =>
|
|
@@ -92,24 +98,26 @@ const FilterSidebar = props => {
|
|
|
92
98
|
const frontendInput = filterFrontendInput.get(group);
|
|
93
99
|
|
|
94
100
|
const hideFilters = ['trains','trains_locomotives','trains_supplies_type','lof_preorder','auction','special_price','sc_baseball_inserts','sc_baseball_parallel','sale','sc_set_type','sc_brands'];
|
|
95
|
-
if (!
|
|
101
|
+
if (!allowedFiltersArr?.length || filterState.size && allowedFiltersArr.length || !filterState.size && allowedFiltersArr.length && allowedFiltersArr.includes(group)) {
|
|
102
|
+
if (!hideFilters.includes(group) && groupName) {
|
|
96
103
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
// if (!allowedFiltersArr?.length && group != "category_uid" || allowedFiltersArr?.length && allowedFiltersArr.includes(group)) {
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<FilterBlock
|
|
109
|
+
key={group}
|
|
110
|
+
filterApi={filterApi}
|
|
111
|
+
filterState={blockState}
|
|
112
|
+
filterFrontendInput={frontendInput}
|
|
113
|
+
group={group}
|
|
114
|
+
items={items}
|
|
115
|
+
name={groupName}
|
|
116
|
+
onApply={group == "category_uid" ? handleCategoryApplyFilter : handleApplyFilter}
|
|
117
|
+
initialOpen={true}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
113
121
|
}
|
|
114
122
|
}),
|
|
115
123
|
[
|
|
@@ -91,8 +91,8 @@ export const useCollectibleGameSets = props => {
|
|
|
91
91
|
// const availableReleaseYears = collectibleGameSets && collectibleGameSets.length ? collectibleGameSets.map(({ data }) => data.release_year) : [];
|
|
92
92
|
const availableReleaseYears = [];
|
|
93
93
|
|
|
94
|
-
console.log('collectibleGameSets')
|
|
95
|
-
console.log(collectibleGameSets)
|
|
94
|
+
// console.log('collectibleGameSets')
|
|
95
|
+
// console.log(collectibleGameSets)
|
|
96
96
|
|
|
97
97
|
const filteredCollectibleGameSets = useMemo(() => {
|
|
98
98
|
if (!collectibleGameSets) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useProductContent } from './useProductContent';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
|
|
4
|
+
query getProductFiltersByCategory(
|
|
5
|
+
$categoryIdFilter: FilterEqualTypeInput!
|
|
6
|
+
) {
|
|
7
|
+
products(filter: { category_uid: $categoryIdFilter }) {
|
|
8
|
+
aggregations {
|
|
9
|
+
label
|
|
10
|
+
count
|
|
11
|
+
attribute_code
|
|
12
|
+
options {
|
|
13
|
+
label
|
|
14
|
+
value
|
|
15
|
+
}
|
|
16
|
+
position
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const GET_CATEGORY_CONTENT = gql`
|
|
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
|
+
url_key
|
|
31
|
+
url_path
|
|
32
|
+
hide_filters
|
|
33
|
+
allowed_filters {
|
|
34
|
+
code
|
|
35
|
+
}
|
|
36
|
+
custom_subcategory {
|
|
37
|
+
name
|
|
38
|
+
path
|
|
39
|
+
}
|
|
40
|
+
attributes_block {
|
|
41
|
+
label
|
|
42
|
+
code
|
|
43
|
+
items {
|
|
44
|
+
label
|
|
45
|
+
value
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
parent {
|
|
49
|
+
uid
|
|
50
|
+
name
|
|
51
|
+
position
|
|
52
|
+
url_path
|
|
53
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
54
|
+
}
|
|
55
|
+
children {
|
|
56
|
+
uid
|
|
57
|
+
name
|
|
58
|
+
position
|
|
59
|
+
url_path
|
|
60
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
export const GET_CATEGORY_AVAILABLE_SORT_METHODS = gql`
|
|
68
|
+
query getCategoryAvailableSortMethods(
|
|
69
|
+
$categoryIdFilter: FilterEqualTypeInput!
|
|
70
|
+
) {
|
|
71
|
+
products(filter: { category_uid: $categoryIdFilter }) {
|
|
72
|
+
sort_fields {
|
|
73
|
+
options {
|
|
74
|
+
label
|
|
75
|
+
value
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
export const GET_STORE_CONFIG_DATA = gql`
|
|
83
|
+
query GetStoreConfigForBreadcrumbs {
|
|
84
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
85
|
+
storeConfig {
|
|
86
|
+
store_code
|
|
87
|
+
custommarketplace_plp_filters_virtualcategory
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
export default {
|
|
94
|
+
getCategoryContentQuery: GET_CATEGORY_CONTENT,
|
|
95
|
+
getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
|
|
96
|
+
getCategoryAvailableSortMethodsQuery: GET_CATEGORY_AVAILABLE_SORT_METHODS,
|
|
97
|
+
getStoreConfigQuery: GET_STORE_CONFIG_DATA
|
|
98
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { useLazyQuery, useQuery } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
5
|
+
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
6
|
+
|
|
7
|
+
import DEFAULT_OPERATIONS from './productContent.gql';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns props necessary to render the categoryContent component.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} props.data - The results of a getCategory GraphQL query.
|
|
13
|
+
*
|
|
14
|
+
* @returns {object} result
|
|
15
|
+
* @returns {string} result.categoryDescription - This category's description.
|
|
16
|
+
* @returns {string} result.categoryName - This category's name.
|
|
17
|
+
* @returns {object} result.filters - The filters object.
|
|
18
|
+
* @returns {object} result.items - The items in this category.
|
|
19
|
+
* @returns {number} result.totalPagesFromData - The total amount of pages for the query.
|
|
20
|
+
*/
|
|
21
|
+
export const useProductContent = props => {
|
|
22
|
+
const { categoryId, data, pageSize = 6 } = props;
|
|
23
|
+
|
|
24
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
getCategoryContentQuery,
|
|
28
|
+
getProductFiltersByCategoryQuery,
|
|
29
|
+
getCategoryAvailableSortMethodsQuery,
|
|
30
|
+
getStoreConfigQuery
|
|
31
|
+
} = operations;
|
|
32
|
+
|
|
33
|
+
const placeholderItems = Array.from({ length: pageSize }).fill(null);
|
|
34
|
+
|
|
35
|
+
const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
|
|
36
|
+
fetchPolicy: 'cache-and-network'
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const virtualCategoryFilters = useMemo(() => {
|
|
40
|
+
if (storeConfigData) {
|
|
41
|
+
const data = storeConfigData.storeConfig.custommarketplace_plp_filters_virtualcategory;
|
|
42
|
+
return data ? data.split(',') : [];
|
|
43
|
+
}
|
|
44
|
+
}, [storeConfigData]);
|
|
45
|
+
|
|
46
|
+
const [getFilters, { data: filterData }] = useLazyQuery(
|
|
47
|
+
getProductFiltersByCategoryQuery,
|
|
48
|
+
{
|
|
49
|
+
fetchPolicy: 'cache-and-network',
|
|
50
|
+
nextFetchPolicy: 'cache-first'
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const [getSortMethods, { data: sortData }] = useLazyQuery(
|
|
55
|
+
getCategoryAvailableSortMethodsQuery,
|
|
56
|
+
{
|
|
57
|
+
fetchPolicy: 'cache-and-network',
|
|
58
|
+
nextFetchPolicy: 'cache-first'
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
63
|
+
getCategoryContentQuery,
|
|
64
|
+
{
|
|
65
|
+
fetchPolicy: 'cache-and-network',
|
|
66
|
+
nextFetchPolicy: 'cache-first',
|
|
67
|
+
skip: !categoryId,
|
|
68
|
+
variables: {
|
|
69
|
+
id: categoryId
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const [, { dispatch }] = useEventingContext();
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (categoryId) {
|
|
78
|
+
getFilters({
|
|
79
|
+
variables: {
|
|
80
|
+
categoryIdFilter: {
|
|
81
|
+
eq: categoryId
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}, [categoryId, getFilters]);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (categoryId) {
|
|
90
|
+
getSortMethods({
|
|
91
|
+
variables: {
|
|
92
|
+
categoryIdFilter: {
|
|
93
|
+
in: categoryId
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, [categoryId, getSortMethods]);
|
|
99
|
+
|
|
100
|
+
const rawFilters = filterData ? filterData.products.aggregations : null;
|
|
101
|
+
const items = data ? data.products.items : placeholderItems;
|
|
102
|
+
const category =
|
|
103
|
+
categoryData && categoryData.categories.items.length
|
|
104
|
+
? categoryData.categories.items[0]
|
|
105
|
+
: null;
|
|
106
|
+
const children =
|
|
107
|
+
categoryData && categoryData.categories.items.length
|
|
108
|
+
? categoryData.categories.items[0].children
|
|
109
|
+
: null;
|
|
110
|
+
|
|
111
|
+
const filters = [];
|
|
112
|
+
|
|
113
|
+
rawFilters && rawFilters.map((filter, index) => {
|
|
114
|
+
|
|
115
|
+
const filterOptions = [];
|
|
116
|
+
let label = filter.label;
|
|
117
|
+
if (filter.attribute_code == "category_uid") {
|
|
118
|
+
children && children.map((category, index) => {
|
|
119
|
+
filterOptions.push({
|
|
120
|
+
'label': category.name,
|
|
121
|
+
'value': category.uid,
|
|
122
|
+
'path': category.url_path
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
label = category ? category.name : label;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const newFilter = {
|
|
130
|
+
attribute_code: filter.attribute_code,
|
|
131
|
+
count: filter.count,
|
|
132
|
+
label: label,
|
|
133
|
+
position: filter.position,
|
|
134
|
+
options: filterOptions.length ? filterOptions : filter.options
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
filters.push(newFilter);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const attributesBlock = categoryData && categoryData.categories.items.length
|
|
141
|
+
? categoryData.categories.items[0].attributes_block
|
|
142
|
+
: null;
|
|
143
|
+
const parent =
|
|
144
|
+
categoryData && categoryData.categories.items.length
|
|
145
|
+
? categoryData.categories.items[0].parent
|
|
146
|
+
: null;
|
|
147
|
+
const totalPagesFromData = data
|
|
148
|
+
? data.products.page_info.total_pages
|
|
149
|
+
: null;
|
|
150
|
+
const totalCount = data ? data.products.total_count : null;
|
|
151
|
+
|
|
152
|
+
const categoryName =
|
|
153
|
+
categoryData && categoryData.categories.items.length
|
|
154
|
+
? categoryData.categories.items[0].name
|
|
155
|
+
: null;
|
|
156
|
+
const categoryDescription =
|
|
157
|
+
categoryData && categoryData.categories.items.length
|
|
158
|
+
? categoryData.categories.items[0].description
|
|
159
|
+
: null;
|
|
160
|
+
const availableSortMethods = sortData
|
|
161
|
+
? sortData.products.sort_fields.options
|
|
162
|
+
: null;
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (!categoryLoading && categoryData.categories.items.length > 0) {
|
|
166
|
+
dispatch({
|
|
167
|
+
type: 'CATEGORY_PAGE_VIEW',
|
|
168
|
+
payload: {
|
|
169
|
+
id: categoryData.categories.items[0].uid,
|
|
170
|
+
name: categoryData.categories.items[0].name,
|
|
171
|
+
url_key: categoryData.categories.items[0].url_key,
|
|
172
|
+
url_path: categoryData.categories.items[0].url_path
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}, [categoryData, dispatch, categoryLoading]);
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
availableSortMethods,
|
|
180
|
+
categoryName,
|
|
181
|
+
categoryDescription,
|
|
182
|
+
filters,
|
|
183
|
+
items,
|
|
184
|
+
totalCount,
|
|
185
|
+
totalPagesFromData,
|
|
186
|
+
children,
|
|
187
|
+
parent,
|
|
188
|
+
attributesBlock,
|
|
189
|
+
category,
|
|
190
|
+
virtualCategoryFilters
|
|
191
|
+
};
|
|
192
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const CategoryFragment = gql`
|
|
4
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
5
|
+
fragment CategoryFragment on CategoryTree {
|
|
6
|
+
uid
|
|
7
|
+
meta_title
|
|
8
|
+
meta_keywords
|
|
9
|
+
meta_description
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const ProductsFragment = gql`
|
|
14
|
+
fragment ProductsFragment on Products {
|
|
15
|
+
items {
|
|
16
|
+
id
|
|
17
|
+
uid
|
|
18
|
+
name
|
|
19
|
+
preorder {
|
|
20
|
+
is_preorder
|
|
21
|
+
preorder_notes
|
|
22
|
+
preorder_availability
|
|
23
|
+
}
|
|
24
|
+
auction_data {
|
|
25
|
+
is_auction
|
|
26
|
+
}
|
|
27
|
+
seller {
|
|
28
|
+
name
|
|
29
|
+
}
|
|
30
|
+
custom_attributes {
|
|
31
|
+
selected_attribute_options {
|
|
32
|
+
attribute_option {
|
|
33
|
+
uid
|
|
34
|
+
label
|
|
35
|
+
is_default
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
entered_attribute_value {
|
|
39
|
+
value
|
|
40
|
+
}
|
|
41
|
+
attribute_metadata {
|
|
42
|
+
uid
|
|
43
|
+
code
|
|
44
|
+
label
|
|
45
|
+
attribute_labels {
|
|
46
|
+
store_code
|
|
47
|
+
label
|
|
48
|
+
}
|
|
49
|
+
data_type
|
|
50
|
+
is_system
|
|
51
|
+
entity_type
|
|
52
|
+
ui_input {
|
|
53
|
+
ui_input_type
|
|
54
|
+
is_html_allowed
|
|
55
|
+
}
|
|
56
|
+
... on ProductAttributeMetadata {
|
|
57
|
+
used_in_components
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
price_range {
|
|
62
|
+
maximum_price {
|
|
63
|
+
final_price {
|
|
64
|
+
currency
|
|
65
|
+
value
|
|
66
|
+
}
|
|
67
|
+
regular_price {
|
|
68
|
+
currency
|
|
69
|
+
value
|
|
70
|
+
}
|
|
71
|
+
discount {
|
|
72
|
+
amount_off
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
minimum_price {
|
|
76
|
+
final_price {
|
|
77
|
+
currency
|
|
78
|
+
value
|
|
79
|
+
}
|
|
80
|
+
regular_price {
|
|
81
|
+
currency
|
|
82
|
+
value
|
|
83
|
+
}
|
|
84
|
+
discount {
|
|
85
|
+
amount_off
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
sku
|
|
90
|
+
small_image {
|
|
91
|
+
url
|
|
92
|
+
}
|
|
93
|
+
stock_status
|
|
94
|
+
rating_summary
|
|
95
|
+
__typename
|
|
96
|
+
url_key
|
|
97
|
+
}
|
|
98
|
+
page_info {
|
|
99
|
+
total_pages
|
|
100
|
+
}
|
|
101
|
+
total_count
|
|
102
|
+
}
|
|
103
|
+
`;
|