Merge remote-tracking branch 'origin/develop' into release/next
This commit is contained in:
@@ -22,10 +22,10 @@ export default (container) => {
|
||||
|
||||
app.post("/brightpearl/goods-out", bodyParser.json(), async (req, res) => {
|
||||
const { id, lifecycle_event } = req.body
|
||||
const brightpearlService = req.scope.resolve("brightpearlService")
|
||||
const eventBusService = req.scope.resolve("eventBusService")
|
||||
|
||||
if (lifecycle_event === "created") {
|
||||
await brightpearlService.createFulfillmentFromGoodsOut(id)
|
||||
eventBusService.emit("brightpearl.goods_out_note", { id })
|
||||
}
|
||||
|
||||
res.sendStatus(200)
|
||||
|
||||
@@ -1128,55 +1128,63 @@ class BrightpearlService extends BaseService {
|
||||
}
|
||||
|
||||
async createFulfillmentFromGoodsOut(id) {
|
||||
const client = await this.getClient()
|
||||
await this.manager_.transaction(async (m) => {
|
||||
const client = await this.getClient()
|
||||
|
||||
// Get goods out and associated order
|
||||
const goodsOut = await client.warehouses.retrieveGoodsOutNote(id)
|
||||
const order = await client.orders.retrieve(goodsOut.orderId)
|
||||
// Get goods out and associated order
|
||||
const goodsOut = await client.warehouses.retrieveGoodsOutNote(id)
|
||||
const order = await client.orders.retrieve(goodsOut.orderId)
|
||||
|
||||
// Only relevant for medusa orders check channel id
|
||||
if (order.channelId !== parseInt(this.options.channel_id)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Combine the line items that we are going to create a fulfillment for
|
||||
const lines = Object.keys(goodsOut.orderRows)
|
||||
.map((key) => {
|
||||
const row = order.rows.find((r) => r.id == key)
|
||||
if (row) {
|
||||
return {
|
||||
item_id: row.externalRef,
|
||||
|
||||
// Brightpearl sometimes gives multiple order row entries
|
||||
quantity: goodsOut.orderRows[key].reduce(
|
||||
(sum, next) => sum + next.quantity,
|
||||
0
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
})
|
||||
.filter((i) => !!i)
|
||||
|
||||
// Orders with a concatenated externalReference are swap orders
|
||||
const [_, partId] = order.externalRef.split(".")
|
||||
|
||||
if (partId) {
|
||||
if (partId.startsWith("claim")) {
|
||||
return this.claimService_.createFulfillment(partId, {
|
||||
goods_out_note: id,
|
||||
})
|
||||
} else {
|
||||
return this.swapService_.createFulfillment(partId, {
|
||||
goods_out_note: id,
|
||||
})
|
||||
// Only relevant for medusa orders check channel id
|
||||
if (order.channelId !== parseInt(this.options.channel_id)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return this.orderService_.createFulfillment(order.externalRef, lines, {
|
||||
goods_out_note: id,
|
||||
})
|
||||
// Combine the line items that we are going to create a fulfillment for
|
||||
const lines = Object.keys(goodsOut.orderRows)
|
||||
.map((key) => {
|
||||
const row = order.rows.find((r) => r.id == key)
|
||||
if (row) {
|
||||
return {
|
||||
item_id: row.externalRef,
|
||||
|
||||
// Brightpearl sometimes gives multiple order row entries
|
||||
quantity: goodsOut.orderRows[key].reduce(
|
||||
(sum, next) => sum + next.quantity,
|
||||
0
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
})
|
||||
.filter((i) => !!i)
|
||||
|
||||
// Orders with a concatenated externalReference are swap orders
|
||||
const [_, partId] = order.externalRef.split(".")
|
||||
|
||||
if (partId) {
|
||||
if (partId.startsWith("claim")) {
|
||||
return this.claimService_
|
||||
.withTransaction(m)
|
||||
.createFulfillment(partId, {
|
||||
goods_out_note: id,
|
||||
})
|
||||
} else {
|
||||
return this.swapService_
|
||||
.withTransaction(m)
|
||||
.createFulfillment(partId, {
|
||||
goods_out_note: id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return this.orderService_
|
||||
.withTransaction(m)
|
||||
.createFulfillment(order.externalRef, lines, {
|
||||
goods_out_note: id,
|
||||
})
|
||||
}, "SERIALIZABLE")
|
||||
}
|
||||
|
||||
async createCustomer(fromOrder) {
|
||||
|
||||
@@ -19,6 +19,11 @@ class OrderSubscriber {
|
||||
|
||||
eventBusService.subscribe("order.placed", this.sendToBrightpearl)
|
||||
|
||||
eventBusService.subscribe(
|
||||
"brightpearl.goods_out_note",
|
||||
this.createFulfillmentFromGoodsOut
|
||||
)
|
||||
|
||||
eventBusService.subscribe("claim.created", this.registerClaim)
|
||||
|
||||
eventBusService.subscribe("order.refund_created", this.registerRefund)
|
||||
@@ -50,6 +55,10 @@ class OrderSubscriber {
|
||||
return this.brightpearlService_.createPayment(id)
|
||||
}
|
||||
|
||||
createFulfillmentFromGoodsOut = ({ id }) => {
|
||||
return this.brightpearlService_.createFulfillmentFromGoodsOut(id)
|
||||
}
|
||||
|
||||
registerSwapPayment = async (data) => {
|
||||
return this.registerSwap({ id: data.id, swap_id: data.id })
|
||||
}
|
||||
|
||||
@@ -297,9 +297,6 @@ class ContentfulService extends BaseService {
|
||||
}
|
||||
)
|
||||
|
||||
// const ignoreIds = (await this.getIgnoreIds_("product_variant")) || []
|
||||
// ignoreIds.push(v.id)
|
||||
// this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds))
|
||||
return result
|
||||
} catch (error) {
|
||||
throw error
|
||||
@@ -311,7 +308,7 @@ class ContentfulService extends BaseService {
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
if (!hasType) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
try {
|
||||
const r = await this.regionService_.retrieve(region.id, {
|
||||
@@ -353,7 +350,7 @@ class ContentfulService extends BaseService {
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
if (!hasType) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const updateFields = [
|
||||
@@ -435,13 +432,13 @@ class ContentfulService extends BaseService {
|
||||
|
||||
const found = data.fields.find((f) => updateFields.includes(f))
|
||||
if (!found) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
try {
|
||||
const ignore = await this.shouldIgnore_(data.id, "contentful")
|
||||
if (ignore) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const p = await this.productService_.retrieve(data.id, {
|
||||
@@ -594,14 +591,14 @@ class ContentfulService extends BaseService {
|
||||
if (variant.fields) {
|
||||
const found = variant.fields.find((f) => updateFields.includes(f))
|
||||
if (!found) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const ignore = await this.shouldIgnore_(variant.id, "contentful")
|
||||
if (ignore) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const environment = await this.getContentfulEnvironment_()
|
||||
|
||||
@@ -19,6 +19,8 @@ class VariantSubscriber {
|
||||
.triggerRestock(id)
|
||||
)
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ class NotificationService extends BaseService {
|
||||
handleEvent(eventName, data) {
|
||||
const subs = this.subscribers_[eventName]
|
||||
if (!subs) {
|
||||
return
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
return Promise.all(
|
||||
|
||||
@@ -110,10 +110,13 @@ class OrderService extends BaseService {
|
||||
shippingOptionService: this.shippingOptionService_,
|
||||
shippingProfileService: this.shippingProfileService_,
|
||||
fulfillmentProviderService: this.fulfillmentProviderService_,
|
||||
fulfillmentService: this.fulfillmentService_,
|
||||
customerService: this.customerService_,
|
||||
discountService: this.discountService_,
|
||||
totalsService: this.totalsService_,
|
||||
cartService: this.cartService_,
|
||||
giftCardService: this.giftCardService_,
|
||||
addressRepository: this.addressRepository_,
|
||||
draftOrderService: this.draftOrderService_,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user