summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/product/components/Product/ProductDesktopVariant.jsx18
-rw-r--r--src/lib/product/components/Product/ProductMobileVariant.jsx18
-rw-r--r--src/pages/api/shop/variant-detail.js18
-rw-r--r--src/pages/shop/product/variant/[slug].jsx10
4 files changed, 45 insertions, 19 deletions
diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx
index 51739bc9..ef61bafd 100644
--- a/src/lib/product/components/Product/ProductDesktopVariant.jsx
+++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx
@@ -140,7 +140,7 @@ const ProductDesktopVariant = ({ product, wishlist, toggleWishlist, isVariant })
<div className='w-full flex flex-wrap'>
<div className='w-5/12'>
<Image
- src={product.parent.image}
+ src={product.image}
alt={product.name}
className='h-[430px] object-contain object-center w-full border border-gray_r-4'
/>
@@ -270,32 +270,32 @@ const ProductDesktopVariant = ({ product, wishlist, toggleWishlist, isVariant })
</div> */}
</div>
<div className='w-[25%]'>
- {product?.flashSale?.remainingTime > 0 ? (
+ {product?.isFlashsale > 0 && product?.price?.discountPercentage > 0? (
<>
<div className='flex gap-x-1 items-center mt-2'>
<div className='badge-solid-red text-caption-1'>
- {lowestPrice?.discountPercentage}%
+ {product?.price?.discountPercentage}%
</div>
<div className='text-gray_r-9 line-through text-caption-1'>
- {currencyFormat(lowestPrice?.price)}
+ {currencyFormat(product?.price?.price)}
</div>
<div className='text-danger-500 font-semibold text-xl'>
- {currencyFormat(lowestPrice?.priceDiscount)}
+ {currencyFormat(product?.price?.priceDiscount)}
</div>
</div>
<div className='text-gray_r-9 text-base font-normal mt-1'>
Termasuk PPN:{' '}
- {currencyFormat(lowestPrice?.priceDiscount * process.env.NEXT_PUBLIC_PPN)}
+ {currencyFormat(product?.price?.priceDiscount * process.env.NEXT_PUBLIC_PPN)}
</div>
</>
) : (
<h3 className='text-danger-500 font-semibold mt-1 text-title-md'>
- {lowestPrice?.price > 0 ? (
+ {product?.price?.price > 0 ? (
<>
- {currencyFormat(lowestPrice?.price)}
+ {currencyFormat(product?.price?.price)}
<div className='text-gray_r-9 text-base font-normal mt-1'>
Termasuk PPN:{' '}
- {currencyFormat(lowestPrice?.price * process.env.NEXT_PUBLIC_PPN)}
+ {currencyFormat(product?.price?.price * process.env.NEXT_PUBLIC_PPN)}
</div>
</>
) : (
diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx
index 8cdb631f..9888e482 100644
--- a/src/lib/product/components/Product/ProductMobileVariant.jsx
+++ b/src/lib/product/components/Product/ProductMobileVariant.jsx
@@ -29,7 +29,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
const [isLoadingSLA, setIsLoadingSLA] = useState(true)
const getLowestPrice = () => {
- const lowest = product.price
+ const lowest = product.lowestPrice
return lowest
}
@@ -40,7 +40,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
price: getLowestPrice(),
stock: product.stockTotal,
weight: product.weight,
- isFlashSale: product.isFlashsale
+ isFlashSale: product.isFlashSale
})
useEffect(() => {
@@ -50,9 +50,9 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
code: product.code,
name: product.name,
price: product.price,
- stock: product.stock,
+ stock: product.stockTotal,
weight: product.weight,
- isFlashSale: product.isFlashsale
+ isFlashSale: product.isFlashSale
})
}
}, [selectedVariant, product])
@@ -115,7 +115,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
return (
<MobileView>
<Image
- src={product.parent.image}
+ src={product.image}
alt={product.name}
className='h-72 object-contain object-center w-full border-b border-gray_r-4'
/>
@@ -141,7 +141,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
</div>
<h1 className='leading-6 font-medium mb-3'>{activeVariant?.name}</h1>
- {activeVariant.isFlashsale ? (
+ {activeVariant.isFlashSale && activeVariant?.price?.discountPercentage > 0 ? (
<>
<div className='flex gap-x-1 items-center'>
<div className='badge-solid-red'>{activeVariant?.price?.discountPercentage}%</div>
@@ -159,12 +159,12 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
</>
) : (
<h3 className='text-danger-500 font-semibold mt-1'>
- {activeVariant?.price?.priceDiscount > 0 ? (
+ {activeVariant?.price?.price > 0 ? (
<>
- {currencyFormat(activeVariant?.price?.priceDiscount)}
+ {currencyFormat(activeVariant?.price?.price)}
<div className='text-gray_r-9 text-base font-normal mt-1'>
Termasuk PPN:{' '}
- {currencyFormat(activeVariant?.price.priceDiscount * process.env.NEXT_PUBLIC_PPN)}
+ {currencyFormat(activeVariant?.price.price * process.env.NEXT_PUBLIC_PPN)}
</div>
</>
) : (
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 ba2a79d5..d0790249 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'
const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
@@ -15,9 +16,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