diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/solrMapping.js | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/src/utils/solrMapping.js b/src/utils/solrMapping.js index 41d24b53..dd90ac7d 100644 --- a/src/utils/solrMapping.js +++ b/src/utils/solrMapping.js @@ -1,17 +1,18 @@ export const productMappingSolr = (products, pricelist) => { return products.map((product) => { - let price = product.price_tier1_v2_f || 0 - let priceDiscount = 0 - let discountPercentage = 0 + let price = product.price_tier1_v2_f || 0; + let priceDiscount = price; + let discountPercentage = 0; if (pricelist && product?.[`price_${pricelist}_f`] < price) { - price = product?.[`price_${pricelist}_f`] || 0 + price = product?.[`price_${pricelist}_f`] || 0; + priceDiscount = price; } - 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 + 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 = { @@ -29,48 +30,50 @@ export const productMappingSolr = (products, pricelist) => { categories: [], flashSale: { id: product?.flashsale_id_i, - remainingTime: flashsaleTime(product?.flashsale_end_date_s)?.remainingTime, + remainingTime: flashsaleTime(product?.flashsale_end_date_s) + ?.remainingTime, name: product?.product?.flashsale_name_s, - tag: product?.flashsale_tag_s || 'FLASH SALE' + tag: product?.flashsale_tag_s || 'FLASH SALE', }, - qtySold : product?.qty_sold_f || 0 - } + qtySold: product?.qty_sold_f || 0, + isTkdn:product?.tkdn_b || false, + isSni:product?.sni_b || false, + }; if (product.manufacture_id_i && product.manufacture_name_s) { productMapped.manufacture = { id: product.manufacture_id_i || '', name: product.manufacture_name_s || '', imagePromotion1: product.image_promotion_1_s || '', - imagePromotion2: product.image_promotion_2_s || '' - } + imagePromotion2: product.image_promotion_2_s || '', + }; } productMapped.categories = [ { id: product.category_id_i || '', - name: product.category_name_s || '' - } - ] - return productMapped - }) -} + name: product.category_name_s || '', + }, + ]; + return productMapped; + }); +}; export const variantsMappingSolr = (parent, products, pricelist) => { return products.map((product) => { - let price = product.price_tier1_v2_f || 0 - let priceDiscount = 0 - let discountPercentage = 0 + let price = product.price_tier1_v2_f || 0; + let priceDiscount = price; + let discountPercentage = 0; - if (pricelist) { - if (product?.[`price_${pricelist}_f`] < price) { - price = product?.[`price_${pricelist}_f`] || 0 - } + if (pricelist && product?.[`price_${pricelist}_f`] < price) { + price = product?.[`price_${pricelist}_f`] || 0; + priceDiscount = price; } if (product?.flashsale_id_i > 0 && product?.flashsale_price_f < price) { - price = product?.flashsale_base_price_f || 0 - priceDiscount = product?.flashsale_price_f || 0 - discountPercentage = product?.flashsale_discount_f || 0 + price = product?.flashsale_base_price_f || 0; + priceDiscount = product?.flashsale_price_f || 0; + discountPercentage = product?.flashsale_discount_f || 0; } let productMapped = { @@ -87,30 +90,34 @@ export const variantsMappingSolr = (parent, products, pricelist) => { weight: product.weight_f || 0, manufacture: {}, parent: {}, - qtySold : product?.qty_sold_f || 0 - } + qtySold: product?.qty_sold_f || 0, + }; if (product.manufacture_id_i && product.manufacture_name_s) { productMapped.manufacture = { id: product.manufacture_id_i || '', - name: product.manufacture_name_s || '' - } + name: product.manufacture_name_s || '', + }; } productMapped.parent = { - id: parent.product_id_i || '', - image: parent.image_s || '', - name: parent.name_s || '' - } - return productMapped - }) -} + id: parent[0]?.product_id_i || '', + image: parent[0]?.image_s || '', + name: parent[0]?.name_s || '', + description: parent[0]?.description_t || '', + }; + return productMapped; + }); +}; const flashsaleTime = (endDate) => { - const flashsaleEndDate = new Date(endDate) - const currentTime = new Date() + const flashsaleEndDate = new Date(endDate); + const currentTime = new Date(); - const timeDifferenceInMillis = flashsaleEndDate - currentTime - const timeDifferenceInSeconds = timeDifferenceInMillis / 1000 + const timeDifferenceInMillis = flashsaleEndDate - currentTime; + const timeDifferenceInSeconds = timeDifferenceInMillis / 1000; - return { remainingTime: timeDifferenceInSeconds, isFlashSale: flashsaleEndDate > currentTime } -} + return { + remainingTime: timeDifferenceInSeconds, + isFlashSale: flashsaleEndDate > currentTime, + }; +}; |
