From 77e49bf7f69a0712da632ddec5b9bd0926389955 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 26 May 2025 14:23:40 +0700 Subject: filter based on stock quantity for ready stock page --- src/api/productApi.js | 14 ++++++++------ src/pages/api/shop/search.js | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/api/productApi.js b/src/api/productApi.js index 4a29b59d..dc96a77e 100644 --- a/src/api/productApi.js +++ b/src/api/productApi.js @@ -1,13 +1,15 @@ -import axios from 'axios' +import axios from 'axios'; export const popularProductApi = () => { return async () => { const today = new Date(); - const dayOfYear = Math.floor((today - new Date(today.getFullYear(), 0, 0)) / 86400000); + const dayOfYear = Math.floor( + (today - new Date(today.getFullYear(), 0, 0)) / 86400000 + ); const page = (dayOfYear % 24) + 1; const dataPopularProducts = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=${page}&orderBy=stock&priceFrom=1` - ) - return dataPopularProducts.data.response - } -} + ); + return dataPopularProducts.data.response; + }; +}; diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index a1eecc52..8ab5c87c 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -89,6 +89,10 @@ export default async function handler(req, res) { 'price_tier1_v2_f:[1 TO *]', ]; + if (orderBy === 'stock') { + filterQueries.push('stock_total_f:{0 TO *}'); // Hanya produk dengan stock > 0 + } + if (fq && source != 'similar' && typeof fq != 'string') { // filterQueries.push(fq); fq.push(...filterQueries); -- cgit v1.2.3