summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-01-18 16:24:54 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-01-18 16:24:54 +0700
commit5ac82c38ed3ec4db1fe4ae96e7493a55154716ef (patch)
treef493df6c4c9d96b6efa86896fd6d27d2995726c4 /src/utils
parent7298d8e811a68cb92c02a7d810f412498d1609d8 (diff)
Update product detail page
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/solrMapping.js94
1 files changed, 49 insertions, 45 deletions
diff --git a/src/utils/solrMapping.js b/src/utils/solrMapping.js
index 41d24b53..7e887253 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,48 @@ 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,
+ };
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 +88,33 @@ 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
- })
-}
+ name: parent.name_s || '',
+ };
+ 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,
+ };
+};