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 Header from "@/components/layout/Header";
|
||||
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");
|
||||
}
|
||||
|
||||
const filteredProducts = products?.filter(
|
||||
(p: any) => !p.name.includes("2x Set") && !p.name.includes("3x Set")
|
||||
);
|
||||
const featuredProducts = filteredProducts?.slice(0, 4) || [];
|
||||
const filteredProducts = filterOutBundles(products);
|
||||
const featuredProducts = filteredProducts.slice(0, 4);
|
||||
const hasProducts = featuredProducts.length > 0;
|
||||
|
||||
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 Header from "@/components/layout/Header";
|
||||
import Footer from "@/components/layout/Footer";
|
||||
@@ -20,9 +20,7 @@ export async function generateStaticParams() {
|
||||
try {
|
||||
const saleorLocale = locale === "sr" ? "SR" : "EN";
|
||||
const products = await getProducts(saleorLocale, 100);
|
||||
const filteredProducts = products.filter(
|
||||
(p: Product) => !p.name.includes("2x Set") && !p.name.includes("3x Set")
|
||||
);
|
||||
const filteredProducts = filterOutBundles(products);
|
||||
filteredProducts.forEach((product: Product) => {
|
||||
params.push({ locale, slug: product.slug });
|
||||
});
|
||||
@@ -92,9 +90,8 @@ export default async function ProductPage({ params }: ProductPageProps) {
|
||||
let bundleProducts: Product[] = [];
|
||||
try {
|
||||
const allProducts = await getProducts(saleorLocale, 50);
|
||||
relatedProducts = allProducts
|
||||
relatedProducts = filterOutBundles(allProducts)
|
||||
.filter((p: Product) => p.id !== product.id)
|
||||
.filter((p) => !p.name.includes("2x Set") && !p.name.includes("3x Set"))
|
||||
.slice(0, 4);
|
||||
} 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 Header from "@/components/layout/Header";
|
||||
import Footer from "@/components/layout/Footer";
|
||||
@@ -29,9 +29,7 @@ export default async function ProductsPage({ params }: ProductsPageProps) {
|
||||
const saleorLocale = getSaleorLocale(validLocale as Locale);
|
||||
const allProducts = await getProducts(saleorLocale);
|
||||
|
||||
const products = allProducts.filter((product) => {
|
||||
return !product.name.includes("2x Set") && !product.name.includes("3x Set");
|
||||
});
|
||||
const products = filterOutBundles(allProducts);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MetadataRoute } from "next";
|
||||
import { getProducts } from "@/lib/saleor";
|
||||
import { getProducts, filterOutBundles } from "@/lib/saleor";
|
||||
import { SUPPORTED_LOCALES, type Locale } from "@/lib/i18n/locales";
|
||||
|
||||
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(
|
||||
(p: any) => !p.name.includes("2x Set") && !p.name.includes("3x Set")
|
||||
);
|
||||
const filteredProducts = filterOutBundles(products);
|
||||
|
||||
const productUrls: SitemapEntry[] = [];
|
||||
|
||||
|
||||
@@ -35,4 +35,8 @@ export {
|
||||
getLocalizedProduct,
|
||||
parseDescription,
|
||||
getBundleProducts,
|
||||
getBundleProductsForProduct,
|
||||
getProductBundleComponents,
|
||||
isBundleProduct,
|
||||
filterOutBundles,
|
||||
} from "./products";
|
||||
|
||||
@@ -217,3 +217,7 @@ export function getProductBundleComponents(product: Product): number | null {
|
||||
export function isBundleProduct(product: Product): boolean {
|
||||
return getProductBundleComponents(product) !== null;
|
||||
}
|
||||
|
||||
export function filterOutBundles(products: Product[]): Product[] {
|
||||
return products.filter((product) => !isBundleProduct(product));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user