release: next (#239)
* hotfix(medusa-plugin-brightpearl): Use order id in sales order endpoint * feat(medusa-plugin-sendgrid): adds localization option (#238) * chore(deps): bump y18n from 4.0.0 to 4.0.1 in /packages/medusa-cli (#226) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump y18n from 4.0.0 to 4.0.3 in /packages/medusa (#235) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.3. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/y18n-v4.0.3/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/compare/v4.0.0...y18n-v4.0.3) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump y18n from 4.0.0 to 4.0.1 in /e2e/prod-project (#225) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump y18n in /packages/medusa-core-utils (#224) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(medusa): Swaps on swaps (#229) Co-authored-by: Sebastian Rindom <skrindom@gmail.com> * chore: version bumps * chore: version bumps * chore(release): Publish - babel-preset-medusa-package@1.1.1 - @medusajs/medusa-cli@1.1.5 - medusa-core-utils@1.1.7 - medusa-dev-cli@0.0.6 - medusa-file-spaces@1.1.10 - medusa-fulfillment-manual@1.1.7 - medusa-fulfillment-webshipper@1.1.10 - medusa-interfaces@1.1.8 - medusa-payment-adyen@1.1.10 - medusa-payment-klarna@1.1.11 - medusa-payment-paypal@1.0.10 - medusa-payment-stripe@1.1.10 - medusa-plugin-add-ons@1.1.10 - medusa-plugin-brightpearl@1.1.13 - medusa-plugin-contentful@1.1.11 - medusa-plugin-discount-generator@1.1.1 - medusa-plugin-economic@1.1.10 - medusa-plugin-ip-lookup@1.1.1 - medusa-plugin-mailchimp@1.1.10 - medusa-plugin-permissions@1.1.10 - medusa-plugin-restock-notification@0.0.4 - medusa-plugin-segment@1.1.13 - medusa-plugin-sendgrid@1.1.11 - medusa-plugin-slack-notification@1.1.10 - medusa-plugin-twilio-sms@1.1.10 - medusa-plugin-wishlist@1.1.10 - medusa-test-utils@1.1.10 - @medusajs/medusa@1.1.20 * chore(release): Publish - babel-preset-medusa-package@1.1.2 - @medusajs/medusa-cli@1.1.6 - medusa-core-utils@1.1.8 - medusa-dev-cli@0.0.7 - medusa-file-spaces@1.1.11 - medusa-fulfillment-manual@1.1.8 - medusa-fulfillment-webshipper@1.1.11 - medusa-interfaces@1.1.9 - medusa-payment-adyen@1.1.11 - medusa-payment-klarna@1.1.12 - medusa-payment-paypal@1.0.11 - medusa-payment-stripe@1.1.11 - medusa-plugin-add-ons@1.1.11 - medusa-plugin-brightpearl@1.1.14 - medusa-plugin-contentful@1.1.12 - medusa-plugin-discount-generator@1.1.2 - medusa-plugin-economic@1.1.11 - medusa-plugin-ip-lookup@1.1.2 - medusa-plugin-mailchimp@1.1.11 - medusa-plugin-permissions@1.1.11 - medusa-plugin-restock-notification@0.0.5 - medusa-plugin-segment@1.1.14 - medusa-plugin-sendgrid@1.1.12 - medusa-plugin-slack-notification@1.1.11 - medusa-plugin-twilio-sms@1.1.11 - medusa-plugin-wishlist@1.1.11 - medusa-test-utils@1.1.11 - @medusajs/medusa@1.1.21 Co-authored-by: Sebastian Rindom <skrindom@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sebastian Rindom
parent
6b51c06c22
commit
7343a4e841
@@ -349,7 +349,11 @@ class BrightpearlService extends BaseService {
|
||||
const region = fromOrder.region
|
||||
const client = await this.getClient()
|
||||
const authData = await this.getAuthData()
|
||||
const orderId = fromOrder.metadata.brightpearl_sales_order_id
|
||||
|
||||
const orderIds = this.gatherOrders(fromOrder)
|
||||
const orderId = orderIds[0]
|
||||
const parentRows = await this.gatherRowsFromOrderIds(orderIds)
|
||||
|
||||
if (orderId) {
|
||||
const parentSo = await client.orders.retrieve(orderId)
|
||||
const order = {
|
||||
@@ -362,7 +366,7 @@ class BrightpearlService extends BaseService {
|
||||
delivery: parentSo.delivery,
|
||||
parentId: orderId,
|
||||
rows: fromReturn.items.map((i) => {
|
||||
const parentRow = parentSo.rows.find((row) => {
|
||||
const parentRow = parentRows.find((row) => {
|
||||
return row.externalRef === i.item_id
|
||||
})
|
||||
return {
|
||||
@@ -509,7 +513,9 @@ class BrightpearlService extends BaseService {
|
||||
const order = await client.orders.retrieve(salesOrderId)
|
||||
await client.warehouses
|
||||
.createReservation(order, this.options.warehouse)
|
||||
.catch(() => {})
|
||||
.catch((err) => {
|
||||
console.log("Failed to allocate for order:", salesOrderId)
|
||||
})
|
||||
return salesOrderId
|
||||
})
|
||||
.then((salesOrderId) => {
|
||||
@@ -610,7 +616,11 @@ class BrightpearlService extends BaseService {
|
||||
|
||||
return client.orders.create(order).then(async (salesOrderId) => {
|
||||
const order = await client.orders.retrieve(salesOrderId)
|
||||
await client.warehouses.createReservation(order, this.options.warehouse)
|
||||
await client.warehouses
|
||||
.createReservation(order, this.options.warehouse)
|
||||
.catch((err) => {
|
||||
console.log("Failed to allocate for order:", salesOrderId)
|
||||
})
|
||||
|
||||
const total = order.rows.reduce((acc, next) => {
|
||||
return acc + parseFloat(next.net) + parseFloat(next.tax)
|
||||
@@ -701,11 +711,43 @@ class BrightpearlService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
gatherOrders(fromOrder) {
|
||||
const ids = []
|
||||
if (fromOrder.metadata && fromOrder.metadata.brightpearl_sales_order_id) {
|
||||
ids.push(fromOrder.metadata.brightpearl_sales_order_id)
|
||||
}
|
||||
|
||||
if (fromOrder.swaps) {
|
||||
for (const s of fromOrder.swaps) {
|
||||
if (s.metadata && s.metadata.brightpearl_sales_order_id) {
|
||||
ids.push(s.metadata.brightpearl_sales_order_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
async gatherRowsFromOrderIds(ids) {
|
||||
const client = await this.getClient()
|
||||
const orders = await Promise.all(ids.map((i) => client.orders.retrieve(i)))
|
||||
|
||||
let rows = []
|
||||
for (const o of orders) {
|
||||
rows = rows.concat(o.rows)
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
async createSwapCredit(fromOrder, fromSwap) {
|
||||
const region = fromOrder.region
|
||||
const client = await this.getClient()
|
||||
const authData = await this.getAuthData()
|
||||
const orderId = fromOrder.metadata.brightpearl_sales_order_id
|
||||
|
||||
const orderIds = this.gatherOrders(fromOrder)
|
||||
const orderId = orderIds[0]
|
||||
const parentRows = await this.gatherRowsFromOrderIds(orderIds)
|
||||
const sIndex = fromOrder.swaps.findIndex((s) => fromSwap.id === s.id)
|
||||
|
||||
if (orderId) {
|
||||
@@ -720,7 +762,7 @@ class BrightpearlService extends BaseService {
|
||||
delivery: parentSo.delivery,
|
||||
parentId: orderId,
|
||||
rows: fromSwap.return_order.items.map((i) => {
|
||||
const parentRow = parentSo.rows.find((row) => {
|
||||
const parentRow = parentRows.find((row) => {
|
||||
return row.externalRef === i.item_id
|
||||
})
|
||||
return {
|
||||
@@ -984,7 +1026,11 @@ class BrightpearlService extends BaseService {
|
||||
.create(order)
|
||||
.then(async (salesOrderId) => {
|
||||
const order = await client.orders.retrieve(salesOrderId)
|
||||
await client.warehouses.createReservation(order, this.options.warehouse)
|
||||
await client.warehouses
|
||||
.createReservation(order, this.options.warehouse)
|
||||
.catch((err) => {
|
||||
console.log("Failed to allocate for order:", salesOrderId)
|
||||
})
|
||||
|
||||
const total = order.rows.reduce((acc, next) => {
|
||||
return acc + parseFloat(next.net) + parseFloat(next.tax)
|
||||
|
||||
@@ -39,7 +39,7 @@ class OrderSubscriber {
|
||||
"swap.payment_completed",
|
||||
this.registerSwapPayment
|
||||
)
|
||||
eventBusService.subscribe("order.swap_received", this.registerSwap)
|
||||
eventBusService.subscribe("swap.received", this.registerSwap)
|
||||
}
|
||||
|
||||
sendToBrightpearl = (data) => {
|
||||
@@ -55,13 +55,13 @@ class OrderSubscriber {
|
||||
}
|
||||
|
||||
registerSwap = async (data) => {
|
||||
const { id, swap_id } = data
|
||||
const { id } = data
|
||||
|
||||
if (!id && !swap_id) {
|
||||
if (!id) {
|
||||
return
|
||||
}
|
||||
|
||||
const fromSwap = await this.swapService_.retrieve(swap_id, {
|
||||
const fromSwap = await this.swapService_.retrieve(id, {
|
||||
relations: [
|
||||
"order",
|
||||
"order.payments",
|
||||
@@ -136,7 +136,7 @@ class OrderSubscriber {
|
||||
const { id, return_id } = data
|
||||
|
||||
const order = await this.orderService_.retrieve(id, {
|
||||
relations: ["region", "payments"],
|
||||
relations: ["region", "swaps", "payments"],
|
||||
})
|
||||
|
||||
const fromReturn = await this.returnService_.retrieve(return_id, {
|
||||
|
||||
Reference in New Issue
Block a user