Need createOrder function in imports/plugins/core/orders/server/no-meteor/mutations/createOrder.js to be broken down into smaller importable functions.
The end goal is to have a function that outputs finalFulfillmentGroups from a cart's fulfillmentFGroups as done inside the createOrder function but without creating an order and deleting the cart.
At least, export the functions that createOrder functions uses.
Or create a new function that accomplishes the end goal stated above.
Node: 10.10.0
NPM: 5.6.0
Meteor Node: 8.11.4
Meteor NPM: 6.4.1
Reaction CLI: 0.29.0
Reaction: 2.0.0
Reaction branch: master
Docker: 18.06.1-ce
Hey @ajporlante, I took a look at this ticket today and I think there could be some refactoring like you're suggesting. I feel like all "utility" functions in that file could be moved to their own files, similar to how the catalog plugin is organized. Also feel like the simple-schema const could be moved as well but I'll let @aldeed weigh in on the best place for those.
@ajporlante If you'd like to give this ticket a go feel free to create a PR and assign me as a reviewer, if not I can try to pick this one up sometime later next week.
@ajporlante Could you describe what the actual goal is? Where and how would you use them if they were exported?
You mention "cart", but this code is completely unaware of what a cart is, and we want to keep it that way. In the new paradigm, a cart is not even necessary to create an order (external systems could create them).
We do have a util function on the client for converting a cart into OrderInput, which maybe you are just needing that same function on the server?
The goal is that given a cart, I simply have to be able to identify the total amount need to be paid and the break down of the total into shipping price, tax, and item prices.
Can you help me find that code in the client so I can check if that's all I need to be put in server?
@ajporlante It's all on the cart.checkout object in GraphQL, so the quickest way would be to put the cart through that same transform.
import { xformCartCheckout } from "@reactioncommerce/reaction-graphql-xforms/cart";
// ...
const cart = // get cart somehow
const checkoutInfo = await xformCartCheckout(context.collections, cart);
console.log(checkout.summary);
I think longer term, the specific improvement here would be to break out the calculation of summary to a separate transform so that we can skip the fulfillment group transform, but this approach should be fine for now
This solves my problem. Thanks @aldeed !
@ajporlante Can we close this?
@zenweasel From my end, this can be closed. But I saw @aldeed move it to Icebox, so I think they might want to get back to this in the future.
Yes, I think the thing to do here is to centralize the summary object calculations in their own function. @willopez just had the same issue of needing only the summary. I'll leave it open but change the title.
@aldeed I think that some of the updates in #4821 takes care of this, what do you think?
Most helpful comment
This solves my problem. Thanks @aldeed !