refactor: centralize bundle filtering with filterOutBundles helper
Some checks failed
Build and Deploy / build (push) Has been cancelled
Some checks failed
Build and Deploy / build (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { getProducts } from "@/lib/saleor";
|
import { getProducts, filterOutBundles } from "@/lib/saleor";
|
||||||
import { getTranslations, setRequestLocale } from "next-intl/server";
|
import { getTranslations, setRequestLocale } from "next-intl/server";
|
||||||
import Header from "@/components/layout/Header";
|
import Header from "@/components/layout/Header";
|
||||||
import Footer from "@/components/layout/Footer";
|
import Footer from "@/components/layout/Footer";
|
||||||
@@ -40,10 +40,8 @@ export default async function Homepage({ params }: { params: Promise<{ locale: s
|
|||||||
console.log("Failed to fetch products during build");
|
console.log("Failed to fetch products during build");
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredProducts = products?.filter(
|
const filteredProducts = filterOutBundles(products);
|
||||||
(p: any) => !p.name.includes("2x Set") && !p.name.includes("3x Set")
|
const featuredProducts = filteredProducts.slice(0, 4);
|
||||||
);
|
|
||||||
const featuredProducts = filteredProducts?.slice(0, 4) || [];
|
|
||||||
const hasProducts = featuredProducts.length > 0;
|
const hasProducts = featuredProducts.length > 0;
|
||||||
|
|
||||||
const basePath = `/${validLocale}`;
|
const basePath = `/${validLocale}`;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getProductBySlug, getProducts, getLocalizedProduct, getBundleProducts } from "@/lib/saleor";
|
import { getProductBySlug, getProducts, getLocalizedProduct, getBundleProducts, filterOutBundles } from "@/lib/saleor";
|
||||||
import { getTranslations, setRequestLocale } from "next-intl/server";
|
import { getTranslations, setRequestLocale } from "next-intl/server";
|
||||||
import Header from "@/components/layout/Header";
|
import Header from "@/components/layout/Header";
|
||||||
import Footer from "@/components/layout/Footer";
|
import Footer from "@/components/layout/Footer";
|
||||||
@@ -20,9 +20,7 @@ export async function generateStaticParams() {
|
|||||||
try {
|
try {
|
||||||
const saleorLocale = locale === "sr" ? "SR" : "EN";
|
const saleorLocale = locale === "sr" ? "SR" : "EN";
|
||||||
const products = await getProducts(saleorLocale, 100);
|
const products = await getProducts(saleorLocale, 100);
|
||||||
const filteredProducts = products.filter(
|
const filteredProducts = filterOutBundles(products);
|
||||||
(p: Product) => !p.name.includes("2x Set") && !p.name.includes("3x Set")
|
|
||||||
);
|
|
||||||
filteredProducts.forEach((product: Product) => {
|
filteredProducts.forEach((product: Product) => {
|
||||||
params.push({ locale, slug: product.slug });
|
params.push({ locale, slug: product.slug });
|
||||||
});
|
});
|
||||||
@@ -92,9 +90,8 @@ export default async function ProductPage({ params }: ProductPageProps) {
|
|||||||
let bundleProducts: Product[] = [];
|
let bundleProducts: Product[] = [];
|
||||||
try {
|
try {
|
||||||
const allProducts = await getProducts(saleorLocale, 50);
|
const allProducts = await getProducts(saleorLocale, 50);
|
||||||
relatedProducts = allProducts
|
relatedProducts = filterOutBundles(allProducts)
|
||||||
.filter((p: Product) => p.id !== product.id)
|
.filter((p: Product) => p.id !== product.id)
|
||||||
.filter((p) => !p.name.includes("2x Set") && !p.name.includes("3x Set"))
|
|
||||||
.slice(0, 4);
|
.slice(0, 4);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getProducts } from "@/lib/saleor";
|
import { getProducts, filterOutBundles } from "@/lib/saleor";
|
||||||
import { getTranslations, setRequestLocale } from "next-intl/server";
|
import { getTranslations, setRequestLocale } from "next-intl/server";
|
||||||
import Header from "@/components/layout/Header";
|
import Header from "@/components/layout/Header";
|
||||||
import Footer from "@/components/layout/Footer";
|
import Footer from "@/components/layout/Footer";
|
||||||
@@ -29,9 +29,7 @@ export default async function ProductsPage({ params }: ProductsPageProps) {
|
|||||||
const saleorLocale = getSaleorLocale(validLocale as Locale);
|
const saleorLocale = getSaleorLocale(validLocale as Locale);
|
||||||
const allProducts = await getProducts(saleorLocale);
|
const allProducts = await getProducts(saleorLocale);
|
||||||
|
|
||||||
const products = allProducts.filter((product) => {
|
const products = filterOutBundles(allProducts);
|
||||||
return !product.name.includes("2x Set") && !product.name.includes("3x Set");
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { MetadataRoute } from "next";
|
import { MetadataRoute } from "next";
|
||||||
import { getProducts } from "@/lib/saleor";
|
import { getProducts, filterOutBundles } from "@/lib/saleor";
|
||||||
import { SUPPORTED_LOCALES, type Locale } from "@/lib/i18n/locales";
|
import { SUPPORTED_LOCALES, type Locale } from "@/lib/i18n/locales";
|
||||||
|
|
||||||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://dev.manoonoils.com";
|
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://dev.manoonoils.com";
|
||||||
@@ -80,9 +80,7 @@ export default async function sitemap(): Promise<SitemapEntry[]> {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const filteredProducts = products.filter(
|
const filteredProducts = filterOutBundles(products);
|
||||||
(p: any) => !p.name.includes("2x Set") && !p.name.includes("3x Set")
|
|
||||||
);
|
|
||||||
|
|
||||||
const productUrls: SitemapEntry[] = [];
|
const productUrls: SitemapEntry[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,8 @@ export {
|
|||||||
getLocalizedProduct,
|
getLocalizedProduct,
|
||||||
parseDescription,
|
parseDescription,
|
||||||
getBundleProducts,
|
getBundleProducts,
|
||||||
|
getBundleProductsForProduct,
|
||||||
|
getProductBundleComponents,
|
||||||
|
isBundleProduct,
|
||||||
|
filterOutBundles,
|
||||||
} from "./products";
|
} from "./products";
|
||||||
|
|||||||
@@ -217,3 +217,7 @@ export function getProductBundleComponents(product: Product): number | null {
|
|||||||
export function isBundleProduct(product: Product): boolean {
|
export function isBundleProduct(product: Product): boolean {
|
||||||
return getProductBundleComponents(product) !== null;
|
return getProductBundleComponents(product) !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function filterOutBundles(products: Product[]): Product[] {
|
||||||
|
return products.filter((product) => !isBundleProduct(product));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user