summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
commit2e3c726bc8217f3960cfecec44b81303b03de72b (patch)
tree1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src/utils
parent2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff)
parenta99bf6480eea556e53b85e6db45f3b8c2361e693 (diff)
Merge branch 'release' into development
# Conflicts: # src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/solrMapping.js101
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,
+ };
+};