Describe the bug
error.entity-with-id-not-found error is raised in some cases when a user is trying to place an order and pay via Stripe. It happens in the section below (service/services/order.service.js):
/**
* @description
* Transitions the Order to the given state.
*/
async transitionToState(ctx, orderId, state) {
// ---> ERROR IS TRIGGERED ON THE NEXT LINE.
const order = await this.getOrderOrThrow(ctx, orderId);
order.payments = await this.getOrderPayments(ctx, orderId);
const fromState = order.state;
let finalize;
try {
const result = await this.orderStateMachine.transition(ctx, order, state);
finalize = result.finalize;
}
Flow of when the error happens is below:
- A user comes to the website, they're automatically assigned to a channel (which is a country-specific channel for the same store)
- The user<->channel assignment may be incorrect for various reasons.
- When the user is finally read to purchase, they may be on a different channel
- When the payment is being processed, Vendure cannot find the order number (due to it being assigned to a different channel - that's our theory of why this happens).
Ways to mitigate this:
- Temporarily switch to the default channel when trying to find the order, then switch back to the "current" channel.
To Reproduce
Steps to reproduce the behavior:
This would normally happen when a store has several channels. If a user is assigned a certain channel (e.g. is assigned to a global store, since storefront has no info where the user comes from) then gets assigned to a different channel when the order is placed (e.g. a local, USA channel when we know where the user is at checkout).
Expected behavior
The error should not happen when an order can be found by ID or code within the same store even if in a different channel.
Environment (please complete the following information):
- @vendure/core version: 2.2
- Nodejs version: v20.5.0
- Database (mysql/postgres etc): postgres
Additional context
This was discussed on Discord below
https://discord.com/channels/1100672177260478564/1285979055312863263
The suggested fix was mentioned by @fainin_kev
Describe the bug
error.entity-with-id-not-found error is raised in some cases when a user is trying to place an order and pay via Stripe. It happens in the section below (service/services/order.service.js):
Flow of when the error happens is below:
Ways to mitigate this:
To Reproduce
Steps to reproduce the behavior:
This would normally happen when a store has several channels. If a user is assigned a certain channel (e.g. is assigned to a global store, since storefront has no info where the user comes from) then gets assigned to a different channel when the order is placed (e.g. a local, USA channel when we know where the user is at checkout).
Expected behavior
The error should not happen when an order can be found by ID or code within the same store even if in a different channel.
Environment (please complete the following information):
Additional context
This was discussed on Discord below
https://discord.com/channels/1100672177260478564/1285979055312863263
The suggested fix was mentioned by @fainin_kev