summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/api/shop/generate-recomendation.js6
-rw-r--r--src/pages/my/recomendation/components/products-recomendatison.jsx141
2 files changed, 126 insertions, 21 deletions
diff --git a/src/pages/api/shop/generate-recomendation.js b/src/pages/api/shop/generate-recomendation.js
index a2a9ee40..11dd153e 100644
--- a/src/pages/api/shop/generate-recomendation.js
+++ b/src/pages/api/shop/generate-recomendation.js
@@ -3,7 +3,7 @@ import axios from 'axios';
import camelcaseObjectDeep from 'camelcase-object-deep';
export default async function handler(req, res) {
- const { q = null } = req.query
+ const { q = null, op = 'AND' } = req.query
if (!q) {
return res.status(422).json({ error: 'parameter missing' })
@@ -11,13 +11,13 @@ export default async function handler(req, res) {
let parameter = [
`q=${escapeSolrQuery(q)}`,
- `q.op=AND`,
+ `q.op=${op}`,
`indent=true`,
`fq=-publish_b:false`,
`qf=name_s^2 description_s`,
`facetch=true`,
`fq=price_tier1_v2_f:[1 TO *]`,
- `rows=1`,
+ `rows=10`,
`sort=product_rating_f DESC, price_discount_f DESC`,
];
let result = await axios(
diff --git a/src/pages/my/recomendation/components/products-recomendatison.jsx b/src/pages/my/recomendation/components/products-recomendatison.jsx
index 72b858e8..bb5950c8 100644
--- a/src/pages/my/recomendation/components/products-recomendatison.jsx
+++ b/src/pages/my/recomendation/components/products-recomendatison.jsx
@@ -14,10 +14,11 @@ const ProductsRecomendation = ({ id }) => {
const [isLoading, setIsLoading] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const [variantsOpen, setVariantsOpen] = useState([]);
+ const [otherRec, setOtherRec] = useState(false);
const mappingProducts = async ({ index, product, result, variants }) => {
const resultMapping = {
- index : index,
+ index: index,
product: product,
result: {
id: result?.id || '-',
@@ -34,25 +35,51 @@ const ProductsRecomendation = ({ id }) => {
return resultMapping;
};
- const searchRecomendation = async ({ product, index }) => {
+ const searchRecomendation = async ({ product, index, operator = 'AND' }) => {
let variants = [];
+ let resultMapping = {};
const searchProduct = await axios.post(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/generate-recomendation?q=${product}`
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/generate-recomendation?q=${product}&op=${operator}`
);
- const result =
- searchProduct.data.response.numFound > 0
- ? searchProduct.data.response.products[0]
- : null;
+ if (operator === 'AND') {
+ const result =
+ searchProduct.data.response.numFound > 0
+ ? searchProduct.data.response.products[0]
+ : null;
- if (result?.variantTotal > 1) {
- const searchVariants = await axios.post(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=${result.id}`
- );
- variants = searchVariants.data[0].variants;
- }
+ if (result?.variantTotal > 1) {
+ const searchVariants = await axios.post(
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=${result.id}`
+ );
+ variants = searchVariants.data[0].variants;
+ }
+
+ resultMapping = await mappingProducts({
+ index,
+ product,
+ result,
+ variants,
+ });
+ } else {
+ const result =
+ searchProduct.data.response.numFound > 0
+ ? searchProduct.data.response.products
+ : null;
+
+ result.map((item) => {
+ if (item.variantTotal > 1) {
+ const searchVariants = axios.post(
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=${item.id}`
+ );
+ variants = searchVariants.data[0].variants;
+ }
+ });
- const resultMapping = await mappingProducts({ index, product, result, variants });
+ console.log('ini result', searchProduct.data.response);
+
+
+ }
return resultMapping;
};
@@ -102,6 +129,14 @@ const ProductsRecomendation = ({ id }) => {
}
setIsOpen(false);
};
+
+ const handlingOtherRec = ({ product }) => {
+ console.log('ini product', product);
+ const result = async () =>
+ await searchRecomendation({ product, index: 0, operator: 'OR' });
+
+ result();
+ };
return (
<>
<BottomPopup
@@ -160,6 +195,64 @@ const ProductsRecomendation = ({ id }) => {
</table>
</div>
</BottomPopup>
+ <BottomPopup
+ active={otherRec}
+ close={() => setOtherRec(false)}
+ className='w-full md:!w-[60%]'
+ title='Other Recomendations'
+ >
+ <div className='container'>
+ <table className='table-data'>
+ <thead>
+ <tr>
+ <th>Product</th>
+ <th>Item Code </th>
+ <th>Description</th>
+ <th>Brand</th>
+ <th>Price</th>
+ <th>Image</th>
+ </tr>
+ </thead>
+ <tbody>
+ {variantsOpen?.map((variant, index) => (
+ <tr key={index}>
+ <td>{variant.code}</td>
+ <td>{variant.attributes.join(', ') || '-'}</td>
+ <td>
+ {variant.price.discountPercentage > 0 && (
+ <div className='flex items-center gap-x-1'>
+ <div className={style['disc-badge']}>
+ {Math.floor(variant.price.discountPercentage)}%
+ </div>
+ <div className={style['disc-price']}>
+ Rp {formatCurrency(variant.price.price)}
+ </div>
+ </div>
+ )}
+ {variant.price.priceDiscount > 0 &&
+ `Rp ${formatCurrency(variant.price.priceDiscount)}`}
+ {variant.price.priceDiscount === 0 && '-'}
+ </td>
+ <td>
+ <Button
+ size='sm'
+ w='100%'
+ onClick={() =>
+ hadnliChooseVariants({
+ id: variant.parent.id,
+ variant: variant,
+ })
+ }
+ >
+ Pilih
+ </Button>
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ </BottomPopup>
<div className='container mx-auto flex py-10'>
<div className='w-3/12 pr-4'>
<Menu />
@@ -216,10 +309,10 @@ const ProductsRecomendation = ({ id }) => {
<thead>
<tr>
<th>Product</th>
- <th>Item code</th>
- <th>Keterangan</th>
+ <th>Item Code </th>
+ <th>Description</th>
<th>Brand</th>
- <th>Harga</th>
+ <th>Price</th>
<th>Image</th>
<th>lainnya</th>
</tr>
@@ -284,7 +377,19 @@ const ProductsRecomendation = ({ id }) => {
'-'
)}
</td>
- <td></td>
+ <td>
+ {' '}
+ <Button
+ border='2px'
+ borderColor='red.500'
+ size='sm'
+ onClick={() =>
+ handlingOtherRec({ product: product.product })
+ }
+ >
+ Other
+ </Button>
+ </td>
</tr>
))}
</tbody>