summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-24 09:29:31 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-24 09:29:31 +0700
commite9f3435ceb5d85e4926f26c3a893b96edb898918 (patch)
tree0a2ee9910ffec53bc2ef17a5e44f012066223448 /src
parente17210013af6aa12e1641cd9055d892e16409e1e (diff)
<iman> update ready stock search
Diffstat (limited to 'src')
-rw-r--r--src/core/components/elements/Navbar/NavbarDesktop.jsx2
-rw-r--r--src/lib/product/components/ProductSearch.jsx2
-rw-r--r--src/pages/api/shop/search.js5
3 files changed, 6 insertions, 3 deletions
diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index 2ddf5efe..6c308f11 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -291,7 +291,7 @@ const NavbarDesktop = () => {
<Link
href='/shop/search?orderBy=stock'
className={`${
- router.asPath === '/shop/search?orderBy=stock' &&
+ router.asPath.includes('/shop/search?orderBy=stock') &&
'bg-gray_r-3'
} p-4 flex-1 flex justify-center items-center !text-gray_r-12/80 hover:bg-gray_r-3 idt-transition group`}
target='_blank'
diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx
index 9f19aced..24cdc690 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -42,7 +42,7 @@ const ProductSearch = ({
const [q, setQ] = useState(query?.q || '*');
const [search, setSearch] = useState(query?.q || '*');
const [limit, setLimit] = useState(router.query?.limit || 30);
- const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular');
+ const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'stock');
const [finalQuery, setFinalQuery] = useState({});
const [queryFinal, setQueryFinal] = useState({});
const [dataCategoriesProduct, setDataCategoriesProduct] = useState([])
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js
index 6f98efcb..eadccede 100644
--- a/src/pages/api/shop/search.js
+++ b/src/pages/api/shop/search.js
@@ -18,6 +18,8 @@ export default async function handler(req, res) {
let { stock = '' } = req.query;
+ let isStock = false
+
let paramOrderBy = '';
switch (orderBy) {
case 'price-asc':
@@ -33,6 +35,7 @@ export default async function handler(req, res) {
paramOrderBy += 'search_rank_weekly_i DESC';
break;
case 'stock':
+ isStock = true
paramOrderBy += 'product_rating_f DESC, stock_total_f DESC';
break;
case 'flashsale-price-asc':
@@ -94,7 +97,7 @@ export default async function handler(req, res) {
.join(' OR ')}`
);
// if (category) parameter.push(`fq=category_name:${capitalizeFirstLetter(category.replace(/,/g, ' OR '))}`)
- if (stock) parameter.push(`fq=stock_total_f:{1 TO *}`);
+ if (stock || isStock) parameter.push(`fq=stock_total_f:[0.1 TO *]`);
// Single fq in url params
if (typeof fq === 'string') parameter.push(`fq=${fq}`);