Comments (4)
Hi,
In this situation, if you don't throw, then the alternative is to return an empty array, in which case no allocations will be made. If that is not what you want to allow, then throwing is the best option as it indicates some exceptional circumstance that needs to be known and handled.
Other than that, is this issue OK to close now?
from vendure.
Hi,
In the storefront, when you execute this mutation, what is the result?
mutation Transition {
transitionOrderToState(state: "ArrangingPayment") {
... on Order {
id
code
state
total
}
... on ErrorResult {
errorCode
message
}
...on OrderStateTransitionError {
transitionError
fromState
toState
}
}
}
from vendure.
Hey there! I returned on this after some time adjusting these two methods as follow:
async getAvailableStock(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]): Promise<AvailableStock> {
await Promise.all(
stockLevels.map(async (sl) =>
this.entityHydrator.hydrate(ctx, sl, { relations: ["stockLocation.channels"] })
)
);
let stockOnHand = 0;
let stockAllocated = 0;
for (const stockLevel of stockLevels) {
let channels = stockLevel.stockLocation.channels.map((ch) => ch.id);
if (!channels.includes(ctx.channelId)) continue;
stockOnHand += stockLevel.stockOnHand;
stockAllocated += stockLevel.stockAllocated;
}
return { stockOnHand, stockAllocated };
}
async forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number): Promise<LocationWithQuantity[]> {
await Promise.all(
stockLocations.map(async (sl) =>
this.entityHydrator.hydrate(ctx, sl, { relations: ["channels"] })
)
);
let location = stockLocations.find((sl) =>
sl.channels.map((ch) => ch.id).includes(ctx.channelId)
);
if (!location) {
throw new InternalServerError("Location not found");
}
return [{ location, quantity }];
}
And it seems to work fine! I can complete the order process, and the quantity gets allocated from the correct stock location.
I'm not sure if throwing an error when the location is not found for allocation is the right approach, do you have any suggestion on that?
from vendure.
thanks Michael!
yes, we can close the issue
from vendure.
Related Issues (20)
- Vendure is not able to create all the db tables HOT 2
- Relational customfield causes other customfields to be nulled on partial update if omitted
- slugs are globally unique, not channel unique HOT 2
- `mime-type` set to `application/octet-stream` when uploading `.glb` files
- React Component is not working with Admin UI HOT 5
- Enhance EmailSendEvent with Metadata HOT 1
- Show the email in the chip of the customers HOT 2
- Stand-alone CLI script Error on Bootstrap Worker
- Unabled to create new Admin UI routes using React HOT 1
- Error: Could not load the "sharp" module using the linux-x64 runtime[Fixed] HOT 8
- SplitOrder not persisting shippingLines in SellerOrder HOT 1
- BUG: Failed to create a province! HOT 1
- Entity Hydrator randomly mixes nested relations
- Add eligible promotions query for active order HOT 1
- Zones in Channel Detail do not get updated after creating a new one
- throw new QueryRunnerAlreadyReleasedError() HOT 1
- OrderItemPriceCalculationStrategy is not used on order modification
- Extend AuthenticationMethod type to also return the externalIdentifier field from the DB table authentication_method
- [EmailPlugin] Cannot read properties of undefined (reading 'headers') in production HOT 2
- Extra allocation when canceling order HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vendure.