From 42fed2490fe537b46a717eafaf1b1e4a5e0a08c8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 18 Apr 2023 17:05:25 +0700 Subject: price tier --- src/pages/api/shop/search.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/pages/api/shop/search.js') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 19b9655a..4a237d47 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -57,7 +57,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,8 +88,19 @@ const escapeSolrQuery = (query) => { return escapedWords.join(' ') } -const productResponseMap = (products) => { +const productResponseMap = (products, pricelist) => { return products.map((product) => { + let priceDiscount = product.price_discount_f || 0 + let discount = 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) discount = pricelistDiscountPerc + } + let productMapped = { id: product.product_id_i || '', image: product.image_s || '', @@ -92,8 +108,8 @@ const productResponseMap = (products) => { name: product.name_s || '', lowestPrice: { price: product.price_f || 0, - priceDiscount: product.price_discount_f || 0, - discountPercentage: product.discount_f || 0 + priceDiscount: priceDiscount, + discountPercentage: discount }, variantTotal: product.variant_total_i || 0, stockTotal: product.stock_total_f || 0, -- cgit v1.2.3 From 5d8ad078bdc735e708654e278b226868dc3bc403 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 27 Apr 2023 16:45:05 +0700 Subject: flash sale mapping, mobile flash sale --- src/pages/api/shop/search.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/pages/api/shop/search.js') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 4a237d47..404da1b3 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -43,10 +43,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}`) @@ -90,15 +97,23 @@ const escapeSolrQuery = (query) => { const productResponseMap = (products, pricelist) => { return products.map((product) => { + let price = product.price_f || 0 let priceDiscount = product.price_discount_f || 0 - let discount = product.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) discount = pricelistDiscountPerc + 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 = { @@ -106,16 +121,16 @@ const productResponseMap = (products, pricelist) => { image: product.image_s || '', code: product.default_code_s || '', name: product.name_s || '', - lowestPrice: { - price: product.price_f || 0, - priceDiscount: priceDiscount, - discountPercentage: discount - }, + 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) { -- cgit v1.2.3 From 2d9ef5366a35e658bc060d8ff8778dfaa6b68b03 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Apr 2023 16:12:46 +0700 Subject: fix defat sort search --- src/pages/api/shop/search.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pages/api/shop/search.js') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 404da1b3..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 -- cgit v1.2.3