diff options
Diffstat (limited to 'src/pages/api')
| -rw-r--r-- | src/pages/api/shop/search.js | 37 |
1 files changed, 26 insertions, 11 deletions
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) { |
