Facebook
From Rico Fajar Afandi, 3 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 86
  1. forEach(externalProduct.deals.tier, (item, index) => {
  2.             // console.log(item)
  3.             // console.log(index)
  4.             if(index != externalProduct.deals.tier.length-1){
  5.               if(externalProduct.deals.totalSold >= item.minSold && externalProduct.deals.totalSold < externalProduct.deals.tier[index+1].minSold){
  6.                 externalProduct.deals.indexCurrentTier = index
  7.               }
  8.             }else{
  9.               if(externalProduct.deals.totalSold >= item.minSold){
  10.                 externalProduct.deals.indexCurrentTier = index
  11.               }
  12.             }
  13.           })
  14.           externalProduct.deals.totalSold = 20
  15.           console.log(externalProduct.deals)
  16.           externalProduct.deals.currentPrice = deals.reduce((carry, item) => {
  17.             if (item.min_sold <= externalProduct.deals.totalSold) carry = item.deal_price * Number(itemRate.rate)
  18.             return carry
  19.           }, 0)
  20.           const regularPrice = commonHelper.$_currencyRound(Number(productDetails.regular_price) * Number(itemRate.rate))
  21.           externalProduct.deals.discount = ((regularPrice - externalProduct.deals.currentPrice) / regularPrice) * 100
  22.         }