feat(medusa,brightpearl,segment,webshipper): claims (#163)
* chore: create tests * chore: models * fix: passing initial tests * test: adds integration test * test: clean up integration implementation * fix: claims * fix: brightpearl + webshipper * tests: passing * fix: update claim items * fix: adds gitignore * fix: pr comments * fix: single migration * fix(medusa-plugin-segment): adds item claimed event to segment
This commit is contained in:
@@ -3,12 +3,55 @@ class OrderSubscriber {
|
||||
segmentService,
|
||||
eventBusService,
|
||||
orderService,
|
||||
claimService,
|
||||
returnService,
|
||||
}) {
|
||||
this.orderService_ = orderService
|
||||
|
||||
this.returnService_ = returnService
|
||||
|
||||
this.claimService_ = claimService
|
||||
|
||||
eventBusService.subscribe("claim.created", async ({ id }) => {
|
||||
const claim = await this.claimService_.retrieve(id, {
|
||||
relations: [
|
||||
"order",
|
||||
"claim_items",
|
||||
"claim_items.item",
|
||||
"claim_items.tags",
|
||||
"claim_items.variant",
|
||||
],
|
||||
})
|
||||
|
||||
for (const ci of claim.claim_items) {
|
||||
const price = ci.item.unit_price / 100
|
||||
const reporting_price = await segmentService.getReportingValue(
|
||||
claim.order.currency_code,
|
||||
price
|
||||
)
|
||||
const event = {
|
||||
event: "Item Claimed",
|
||||
userId: claim.order.customer_id,
|
||||
timestamp: claim.created_at,
|
||||
properties: {
|
||||
price,
|
||||
reporting_price,
|
||||
order_id: claim.order_id,
|
||||
claim_id: claim.id,
|
||||
claim_item_id: ci.id,
|
||||
type: claim.type,
|
||||
quantity: ci.quantity,
|
||||
variant: ci.variant.sku,
|
||||
product_id: ci.variant.product_id,
|
||||
reason: ci.reason,
|
||||
note: ci.note,
|
||||
tags: ci.tags.map((t) => ({ id: t.id, value: t.value })),
|
||||
},
|
||||
}
|
||||
await segmentService.track(event)
|
||||
}
|
||||
})
|
||||
|
||||
eventBusService.subscribe(
|
||||
"order.items_returned",
|
||||
async ({ id, return_id }) => {
|
||||
@@ -130,13 +173,12 @@ class OrderSubscriber {
|
||||
],
|
||||
})
|
||||
|
||||
const date = new Date(parseInt(order.created))
|
||||
const orderData = await segmentService.buildOrder(order)
|
||||
const orderEvent = {
|
||||
event: "Order Completed",
|
||||
userId: order.customer_id,
|
||||
properties: orderData,
|
||||
timestamp: date,
|
||||
timestamp: order.created_at,
|
||||
}
|
||||
|
||||
segmentService.track(orderEvent)
|
||||
|
||||
Reference in New Issue
Block a user