diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2023-10-09 04:31:44 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2023-10-09 04:31:44 +0000 |
| commit | 35c60323133fe66dbfa6bfe39248741cd695b181 (patch) | |
| tree | 9290c2f754238eff3758ac0c474a87487773f35e /src/pages | |
| parent | dc6d6df514375c7002686e31e6270f828b5a0ccf (diff) | |
| parent | 07601d9d59b70cd1f200a9a6ebf1d01801990960 (diff) | |
Merged in CR/Pricelist (pull request #97)
CR/Pricelist
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/api/shop/variant-detail.js | 18 | ||||
| -rw-r--r-- | src/pages/shop/product/variant/[slug].jsx | 10 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/pages/api/shop/variant-detail.js b/src/pages/api/shop/variant-detail.js new file mode 100644 index 00000000..fadbe000 --- /dev/null +++ b/src/pages/api/shop/variant-detail.js @@ -0,0 +1,18 @@ +import { productMappingSolr, variantsMappingSolr } from '@/utils/solrMapping' +import axios from 'axios' + +export default async function handler(req, res) { + try { + let productVariants = await axios( + process.env.SOLR_HOST + + `/solr/variants/select?q=id:${req.query.id}&q.op=OR&indent=true` + ) + let auth = req.query.auth === 'false' ? JSON.parse(req.query.auth) : req.query.auth + let result = variantsMappingSolr('',productVariants.data.response.docs, auth || false) + + res.status(200).json(result) + } catch (error) { + console.error('Error fetching data from Solr:', error) + res.status(500).json({ error: 'Internal Server Error' }) + } +}
\ No newline at end of file diff --git a/src/pages/shop/product/variant/[slug].jsx b/src/pages/shop/product/variant/[slug].jsx index 88ac1c7f..455b248b 100644 --- a/src/pages/shop/product/variant/[slug].jsx +++ b/src/pages/shop/product/variant/[slug].jsx @@ -6,6 +6,7 @@ import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import cookie from 'cookie' import variantApi from '@/lib/product/api/variantApi' +import axios from 'axios' import { useProductContext } from '@/contexts/ProductContext' import { useEffect } from 'react' @@ -17,9 +18,16 @@ export async function getServerSideProps(context) { const cookies = context.req.headers.cookie const cookieObj = cookies ? cookie.parse(cookies) : {} const auth = cookieObj.auth ? JSON.parse(cookieObj.auth) : {} + const tier = auth.pricelist ? auth.pricelist : false const authToken = auth?.token || '' - let product = await variantApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) + + let response = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=` + getIdFromSlug(slug) +'&auth=' + tier + ) + let product = response.data + // let product = await variantApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) + if (product?.length == 1) { product = product[0] /* const regexHtmlTags = /(<([^>]+)>)/gi |
