fix: don't divide zero decimal currencies

This commit is contained in:
Sebastian Rindom
2021-03-22 10:31:22 +01:00
parent 2b282bd742
commit cfab2d408a
5 changed files with 95 additions and 24 deletions
@@ -1,6 +1,7 @@
import Analytics from "analytics-node"
import axios from "axios"
import { BaseService } from "medusa-interfaces"
import { humanizeAmount } from "medusa-core-utils"
class SegmentService extends BaseService {
/**
@@ -58,11 +59,13 @@ class SegmentService extends BaseService {
}
async buildOrder(order) {
const subtotal = order.subtotal / 100
const total = order.total / 100
const tax = order.tax_total / 100
const discount = order.discount_total / 100
const shipping = order.shipping_total / 100
const curr = order.currency_code
const subtotal = humanizeAmount(order.subtotal, curr)
const total = humanizeAmount(order.total, curr)
const tax = humanizeAmount(order.tax_total, curr)
const discount = humanizeAmount(order.discount_total, curr)
const shipping = humanizeAmount(order.shipping_total, curr)
const revenue = total - tax
let coupon
@@ -119,7 +122,7 @@ class SegmentService extends BaseService {
const revenue = await this.getReportingValue(
order.currency_code,
lineTotal / 100
humanizeAmount(lineTotal, curr)
)
let sku = ""
@@ -141,7 +144,7 @@ class SegmentService extends BaseService {
return {
name,
variant,
price: lineTotal / 100 / item.quantity,
price: humanizeAmount(lineTotal, curr) / item.quantity,
reporting_revenue: revenue,
product_id: item.variant.product_id,
category: product.collection?.title,