|
@@ -4,11 +4,17 @@ import { notFound } from "next/navigation";
|
|
|
// import FilterList from "@components/theme/filters/FilterList";
|
|
// import FilterList from "@components/theme/filters/FilterList";
|
|
|
// import Pagination from "@components/catalog/Pagination";
|
|
// import Pagination from "@components/catalog/Pagination";
|
|
|
import ProductListing from "./_components/ProductListing";
|
|
import ProductListing from "./_components/ProductListing";
|
|
|
-import { ProductsResponse } from "@components/catalog/type";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ ProductsResponse,
|
|
|
|
|
+ GetCategoryAttrFiltersResult,
|
|
|
|
|
+ CategoryProductsResult,
|
|
|
|
|
+} from "@components/catalog/type";
|
|
|
import {
|
|
import {
|
|
|
GET_FILTER_PRODUCTS,
|
|
GET_FILTER_PRODUCTS,
|
|
|
// GET_TREE_CATEGORIES,
|
|
// GET_TREE_CATEGORIES,
|
|
|
GET_CATEHORY_BY_ID,
|
|
GET_CATEHORY_BY_ID,
|
|
|
|
|
+ GET_CATEGORY_ATTR_FILTERS,
|
|
|
|
|
+ CATEGORY_PRODUCTS,
|
|
|
} from "@/graphql";
|
|
} from "@/graphql";
|
|
|
import {
|
|
import {
|
|
|
// cachedGraphQLRequest,
|
|
// cachedGraphQLRequest,
|
|
@@ -26,7 +32,7 @@ import FilterListSkeleton from "@components/common/skeleton/FilterSkeleton";
|
|
|
import {
|
|
import {
|
|
|
// extractNumericId,
|
|
// extractNumericId,
|
|
|
// findCategoryBySlug,
|
|
// findCategoryBySlug,
|
|
|
- buildProductFilters,
|
|
|
|
|
|
|
+ newBuildProductFilters,
|
|
|
} from "@utils/helper";
|
|
} from "@utils/helper";
|
|
|
import { serverGraphqlFetch } from "@/utils/bagisto/index";
|
|
import { serverGraphqlFetch } from "@/utils/bagisto/index";
|
|
|
import {
|
|
import {
|
|
@@ -98,9 +104,29 @@ export default async function CategoryPage({
|
|
|
const categories = treeData?.treeCategories || [];
|
|
const categories = treeData?.treeCategories || [];
|
|
|
const categoryItem = findCategoryBySlug(categories, categorySlug);
|
|
const categoryItem = findCategoryBySlug(categories, categorySlug);
|
|
|
*/
|
|
*/
|
|
|
- const filterAttributes = await getFilterAttributes(); // 这个不能用
|
|
|
|
|
|
|
+ //const filterAttributes = await getFilterAttributes(); // 这个不能用
|
|
|
|
|
+ const filterAttributesRes = await serverGraphqlFetch<
|
|
|
|
|
+ GetCategoryAttrFiltersResult,
|
|
|
|
|
+ { slug: string; first: number }
|
|
|
|
|
+ >({
|
|
|
|
|
+ query: GET_CATEGORY_ATTR_FILTERS,
|
|
|
|
|
+ variables: {
|
|
|
|
|
+ slug: _categorySlug || "Ready To Go Wig",
|
|
|
|
|
+ first: 50,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 错误判断
|
|
|
|
|
+ if (filterAttributesRes.error) {
|
|
|
|
|
+ console.error("获取分类筛选属性失败", filterAttributesRes.error);
|
|
|
|
|
+ throw new Error(filterAttributesRes.error.message);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- console.log("filterAttributes---------------:", filterAttributes);
|
|
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ "filterAttributesRes---------------AAA",
|
|
|
|
|
+ filterAttributesRes.data?.categoryAttributeFilters,
|
|
|
|
|
+ );
|
|
|
|
|
+ console.log("filterAttributes---------------:", resolvedParams);
|
|
|
const { data: categoryData } = await serverGraphqlFetch<
|
|
const { data: categoryData } = await serverGraphqlFetch<
|
|
|
CategorySingleResponse,
|
|
CategorySingleResponse,
|
|
|
{ id: number }
|
|
{ id: number }
|
|
@@ -125,20 +151,20 @@ export default async function CategoryPage({
|
|
|
// } = (resolvedParams || {}) as {
|
|
// } = (resolvedParams || {}) as {
|
|
|
// [key: string]: string;
|
|
// [key: string]: string;
|
|
|
// };
|
|
// };
|
|
|
- const searchValue = getSearchParam(resolvedParams?.q) ?? "";
|
|
|
|
|
|
|
+ const searchValue = resolvedParams?.q ?? "";
|
|
|
|
|
|
|
|
// const page = getSearchParam(resolvedParams?.page);
|
|
// const page = getSearchParam(resolvedParams?.page);
|
|
|
|
|
|
|
|
const cursor = getSearchParam(resolvedParams?.cursor);
|
|
const cursor = getSearchParam(resolvedParams?.cursor);
|
|
|
|
|
|
|
|
const before = getSearchParam(resolvedParams?.before);
|
|
const before = getSearchParam(resolvedParams?.before);
|
|
|
- const itemsPerPage = 12;
|
|
|
|
|
|
|
+ const itemsPerPage = 15;
|
|
|
// const currentPage = page ? parseInt(page) - 1 : 0;
|
|
// const currentPage = page ? parseInt(page) - 1 : 0;
|
|
|
const sortValue = getSearchParam(resolvedParams?.sort) ?? "name-asc";
|
|
const sortValue = getSearchParam(resolvedParams?.sort) ?? "name-asc";
|
|
|
const selectedSort =
|
|
const selectedSort =
|
|
|
SortByFields.find((s) => s.key === sortValue) || SortByFields[0];
|
|
SortByFields.find((s) => s.key === sortValue) || SortByFields[0];
|
|
|
|
|
|
|
|
- const { filterObject: baseFilterObject } = buildProductFilters(
|
|
|
|
|
|
|
+ const { filterObject: baseFilterObject } = newBuildProductFilters(
|
|
|
resolvedParams || {},
|
|
resolvedParams || {},
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -151,7 +177,31 @@ export default async function CategoryPage({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const filterInput = JSON.stringify(filterObject);
|
|
const filterInput = JSON.stringify(filterObject);
|
|
|
-
|
|
|
|
|
|
|
+ // 默认获取产品数据接口:
|
|
|
|
|
+ const { data: categoryProductDatas } = await serverGraphqlFetch<
|
|
|
|
|
+ CategoryProductsResult,
|
|
|
|
|
+ any
|
|
|
|
|
+ >({
|
|
|
|
|
+ query: CATEGORY_PRODUCTS,
|
|
|
|
|
+ variables: {
|
|
|
|
|
+ slug: _categorySlug || "Ready To Go Wig",
|
|
|
|
|
+ filter: filterInput,
|
|
|
|
|
+ id: Number(categoryId),
|
|
|
|
|
+ ...(before
|
|
|
|
|
+ ? {
|
|
|
|
|
+ last: itemsPerPage,
|
|
|
|
|
+ before,
|
|
|
|
|
+ }
|
|
|
|
|
+ : {
|
|
|
|
|
+ first: itemsPerPage,
|
|
|
|
|
+ after: cursor || null,
|
|
|
|
|
+ }),
|
|
|
|
|
+ sortKey: selectedSort.sortKey,
|
|
|
|
|
+ reverse: selectedSort.reverse,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log("categoryProductDatas-----------:",categoryProductDatas);
|
|
|
|
|
+
|
|
|
// 这个也改成 serverGraphqlFetch
|
|
// 这个也改成 serverGraphqlFetch
|
|
|
const productVariables = {
|
|
const productVariables = {
|
|
|
query: searchValue || "",
|
|
query: searchValue || "",
|
|
@@ -196,9 +246,9 @@ export default async function CategoryPage({
|
|
|
selectedSort,
|
|
selectedSort,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const products = data?.products?.edges?.map((e) => e.node) || [];
|
|
|
|
|
- const pageInfo = data?.products?.pageInfo;
|
|
|
|
|
- const totalCount = data?.products?.totalCount || 0;
|
|
|
|
|
|
|
+ const products = categoryProductDatas?.categoryProducts?.products?.map((e) => e.node) || [];
|
|
|
|
|
+ const pageInfo = categoryProductDatas?.categoryProducts?.pageInfo;
|
|
|
|
|
+ const totalCount = categoryProductDatas?.categoryProducts?.totalCount || 0;
|
|
|
const translation = categoryItem.translation;
|
|
const translation = categoryItem.translation;
|
|
|
console.log("initialQuery------------", {
|
|
console.log("initialQuery------------", {
|
|
|
search: searchValue,
|
|
search: searchValue,
|
|
@@ -267,12 +317,15 @@ export default async function CategoryPage({
|
|
|
</div> */}
|
|
</div> */}
|
|
|
<ProductListing
|
|
<ProductListing
|
|
|
categoryId={numericId}
|
|
categoryId={numericId}
|
|
|
- filterAttributes={filterAttributes}
|
|
|
|
|
|
|
+ slug={_categorySlug}
|
|
|
|
|
+ filterAttributes={
|
|
|
|
|
+ filterAttributesRes.data?.categoryAttributeFilters.edges
|
|
|
|
|
+ }
|
|
|
initialProducts={products}
|
|
initialProducts={products}
|
|
|
initialPageInfo={pageInfo}
|
|
initialPageInfo={pageInfo}
|
|
|
initialTotal={totalCount}
|
|
initialTotal={totalCount}
|
|
|
initialQuery={{
|
|
initialQuery={{
|
|
|
- search: searchValue,
|
|
|
|
|
|
|
+ // search: searchValue,
|
|
|
sort: sortValue,
|
|
sort: sortValue,
|
|
|
filters: baseFilterObject,
|
|
filters: baseFilterObject,
|
|
|
cursor,
|
|
cursor,
|