diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-05-08 16:44:09 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-05-08 16:44:09 +0700 |
| commit | 486f85a45fc7e0669576f59824a31be472ed25bb (patch) | |
| tree | 0268afa8efe48746e040611ba41ad2cafda7ad08 /src/pages/api | |
| parent | cff198277e14450f8d20d9e18548325e6f277682 (diff) | |
| parent | 30fc50600009ca54f085d594d838803c107e87f2 (diff) | |
Merge branch 'master' into development_tri/implementasi_raja_ongkir
# Conflicts:
# src/lib/checkout/components/Checkout.jsx
Diffstat (limited to 'src/pages/api')
| -rw-r--r-- | src/pages/api/shop/finish-checkout.js | 2 | ||||
| -rw-r--r-- | src/pages/api/shop/midtrans-payment.js | 15 | ||||
| -rw-r--r-- | src/pages/api/shop/search.js | 54 | ||||
| -rw-r--r-- | src/pages/api/shop/spell.js | 18 |
4 files changed, 66 insertions, 23 deletions
diff --git a/src/pages/api/shop/finish-checkout.js b/src/pages/api/shop/finish-checkout.js index 04e82118..9eaa36db 100644 --- a/src/pages/api/shop/finish-checkout.js +++ b/src/pages/api/shop/finish-checkout.js @@ -46,7 +46,7 @@ export default async function handler(req, res) { } } - const query = `name=${orderName.replaceAll('-', '/')}&limit=1` + const query = `name=${orderName.replaceAll('-', '/')}&limit=1&context=quotation` const searchTransaction = await odooApi( 'GET', `/api/v1/partner/${auth.partnerId}/sale_order?${query}`, diff --git a/src/pages/api/shop/midtrans-payment.js b/src/pages/api/shop/midtrans-payment.js index 1772e9e0..12aaa51f 100644 --- a/src/pages/api/shop/midtrans-payment.js +++ b/src/pages/api/shop/midtrans-payment.js @@ -22,6 +22,7 @@ export default async function handler(req, res) { {}, { Token: auth.token } ) + if (!transaction?.id) { return res.status(400).json({ error: 'No Data' }) } @@ -48,7 +49,7 @@ export default async function handler(req, res) { const parameter = { transaction_details: { order_id: transaction.name?.replaceAll('/', '-'), - gross_amount: transaction.amountTotal + gross_amount: Math.floor(transaction.amountTotal) }, credit_card: { secure: true @@ -56,17 +57,7 @@ export default async function handler(req, res) { customer_details: { first_name: transaction.address.customer.name, email: transaction.address.customer.email || '', - phone: transaction.address.customer.phone || '', - billing_address: { - first_name: transaction.address.invoice.name, - email: transaction.address.invoice.email || '', - phone: transaction.address.invoice.phone || '' - }, - shipping_address: { - first_name: transaction.address.shipping.name, - email: transaction.address.shipping.email || '', - phone: transaction.address.shipping.phone || '' - } + phone: transaction.address.customer.phone || '' } } diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 19b9655a..2e6764fd 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -29,6 +29,9 @@ export default async function handler(req, res) { case 'stock': paramOrderBy += 'stock_total_f DESC' break + default: + paramOrderBy += 'product_rating_f DESC, price_discount_f DESC' + break } let offset = (page - 1) * limit @@ -43,10 +46,17 @@ export default async function handler(req, res) { 'qf=name_s', `start=${offset}`, `rows=${limit}`, - `sort=${paramOrderBy}`, - `fq=price_discount_f:[${priceFrom == '' ? '*' : priceFrom} TO ${priceTo == '' ? '*' : priceTo}]` + `sort=${paramOrderBy}` ] + if (priceFrom > 0 || priceTo > 0) { + parameter.push( + `fq=price_discount_f:[${priceFrom == '' ? '*' : priceFrom} TO ${ + priceTo == '' ? '*' : priceTo + }]` + ) + } + if (brand) parameter.push(`fq=manufacture_name:${brand}`) if (category) parameter.push(`fq=category_name:${category}`) @@ -57,7 +67,12 @@ export default async function handler(req, res) { let result = await axios(process.env.SOLR_HOST + '/solr/product/select?' + parameter.join('&')) try { - result.data.response.products = productResponseMap(result.data.response.docs) + let { auth } = req.cookies + if (auth) auth = JSON.parse(auth) + result.data.response.products = productResponseMap( + result.data.response.docs, + auth?.pricelist || false + ) result.data.responseHeader.params.start = parseInt(result.data.responseHeader.params.start) result.data.responseHeader.params.rows = parseInt(result.data.responseHeader.params.rows) delete result.data.response.docs @@ -83,23 +98,42 @@ const escapeSolrQuery = (query) => { return escapedWords.join(' ') } -const productResponseMap = (products) => { +const productResponseMap = (products, pricelist) => { return products.map((product) => { + let price = product.price_f || 0 + let priceDiscount = product.price_discount_f || 0 + let discountPercentage = product.discount_f || 0 + + if (pricelist) { + const pricelistDiscount = product?.[`price_${pricelist}_f`] || false + const pricelistDiscountPerc = product?.[`discount_${pricelist}_f`] || false + + if (pricelistDiscount && pricelistDiscount > 0) priceDiscount = pricelistDiscount + if (pricelistDiscountPerc && pricelistDiscountPerc > 0) + discountPercentage = pricelistDiscountPerc + } + + if (product?.flashsale_id_i > 0) { + price = product?.flashsale_base_price_f || 0 + priceDiscount = product?.flashsale_price_f || 0 + discountPercentage = product?.flashsale_discount_f || 0 + } + let productMapped = { id: product.product_id_i || '', image: product.image_s || '', code: product.default_code_s || '', name: product.name_s || '', - lowestPrice: { - price: product.price_f || 0, - priceDiscount: product.price_discount_f || 0, - discountPercentage: product.discount_f || 0 - }, + lowestPrice: { price, priceDiscount, discountPercentage }, variantTotal: product.variant_total_i || 0, stockTotal: product.stock_total_f || 0, weight: product.weight_f || 0, manufacture: {}, - categories: [] + categories: [], + flashSale: { + id: product?.flashsale_id_i, + name: product?.product?.flashsale_name_s + } } if (product.manufacture_id_i && product.manufacture_name_s) { diff --git a/src/pages/api/shop/spell.js b/src/pages/api/shop/spell.js new file mode 100644 index 00000000..4c01765c --- /dev/null +++ b/src/pages/api/shop/spell.js @@ -0,0 +1,18 @@ +import axios from 'axios' + +export default async function handler(req, res) { + const { q = '' } = req.query + + let result = await axios( + process.env.SOLR_HOST + `/solr/product/spell?indent=true&q.op=AND&q=${q}` + ) + + try { + res.status(200).json(result.data) + } catch (error) { + res.status(400).json({ + numFound: 0, + suggestions: [] + }) + } +} |
